/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: d59a2fff599b
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  CodeInterpreterTool,
  CodeInterpreterTool$Outbound,
  CodeInterpreterTool$outboundSchema,
} from "./codeinterpretertool.js";
import {
  CompletionArgs,
  CompletionArgs$Outbound,
  CompletionArgs$outboundSchema,
} from "./completionargs.js";
import {
  ConversationInputs,
  ConversationInputs$Outbound,
  ConversationInputs$outboundSchema,
} from "./conversationinputs.js";
import {
  CustomConnector,
  CustomConnector$Outbound,
  CustomConnector$outboundSchema,
} from "./customconnector.js";
import {
  DocumentLibraryTool,
  DocumentLibraryTool$Outbound,
  DocumentLibraryTool$outboundSchema,
} from "./documentlibrarytool.js";
import {
  FunctionTool,
  FunctionTool$Outbound,
  FunctionTool$outboundSchema,
} from "./functiontool.js";
import {
  GuardrailConfig,
  GuardrailConfig$Outbound,
  GuardrailConfig$outboundSchema,
} from "./guardrailconfig.js";
import {
  ImageGenerationTool,
  ImageGenerationTool$Outbound,
  ImageGenerationTool$outboundSchema,
} from "./imagegenerationtool.js";
import {
  WebSearchPremiumTool,
  WebSearchPremiumTool$Outbound,
  WebSearchPremiumTool$outboundSchema,
} from "./websearchpremiumtool.js";
import {
  WebSearchTool,
  WebSearchTool$Outbound,
  WebSearchTool$outboundSchema,
} from "./websearchtool.js";

export const ConversationStreamRequestHandoffExecution = {
  Client: "client",
  Server: "server",
} as const;
export type ConversationStreamRequestHandoffExecution = ClosedEnum<
  typeof ConversationStreamRequestHandoffExecution
>;

export type ConversationStreamRequestTool =
  | CodeInterpreterTool
  | CustomConnector
  | DocumentLibraryTool
  | FunctionTool
  | ImageGenerationTool
  | WebSearchTool
  | WebSearchPremiumTool;

export type ConversationStreamRequestAgentVersion = string | number;

export type ConversationStreamRequest = {
  inputs: ConversationInputs;
  stream?: true | undefined;
  store?: boolean | null | undefined;
  handoffExecution?:
    | ConversationStreamRequestHandoffExecution
    | null
    | undefined;
  instructions?: string | null | undefined;
  tools?:
    | Array<
      | CodeInterpreterTool
      | CustomConnector
      | DocumentLibraryTool
      | FunctionTool
      | ImageGenerationTool
      | WebSearchTool
      | WebSearchPremiumTool
    >
    | null
    | undefined;
  completionArgs?: CompletionArgs | null | undefined;
  guardrails?: Array<GuardrailConfig> | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  agentId?: string | null | undefined;
  agentVersion?: string | number | null | undefined;
  model?: string | null | undefined;
};

/** @internal */
export const ConversationStreamRequestHandoffExecution$outboundSchema:
  z.ZodEnum<typeof ConversationStreamRequestHandoffExecution> = z.enum(
    ConversationStreamRequestHandoffExecution,
  );

/** @internal */
export type ConversationStreamRequestTool$Outbound =
  | CodeInterpreterTool$Outbound
  | CustomConnector$Outbound
  | DocumentLibraryTool$Outbound
  | FunctionTool$Outbound
  | ImageGenerationTool$Outbound
  | WebSearchTool$Outbound
  | WebSearchPremiumTool$Outbound;

/** @internal */
export const ConversationStreamRequestTool$outboundSchema: z.ZodType<
  ConversationStreamRequestTool$Outbound,
  ConversationStreamRequestTool
> = z.union([
  CodeInterpreterTool$outboundSchema,
  CustomConnector$outboundSchema,
  DocumentLibraryTool$outboundSchema,
  FunctionTool$outboundSchema,
  ImageGenerationTool$outboundSchema,
  WebSearchTool$outboundSchema,
  WebSearchPremiumTool$outboundSchema,
]);

export function conversationStreamRequestToolToJSON(
  conversationStreamRequestTool: ConversationStreamRequestTool,
): string {
  return JSON.stringify(
    ConversationStreamRequestTool$outboundSchema.parse(
      conversationStreamRequestTool,
    ),
  );
}

/** @internal */
export type ConversationStreamRequestAgentVersion$Outbound = string | number;

/** @internal */
export const ConversationStreamRequestAgentVersion$outboundSchema: z.ZodType<
  ConversationStreamRequestAgentVersion$Outbound,
  ConversationStreamRequestAgentVersion
> = smartUnion([z.string(), z.int()]);

export function conversationStreamRequestAgentVersionToJSON(
  conversationStreamRequestAgentVersion: ConversationStreamRequestAgentVersion,
): string {
  return JSON.stringify(
    ConversationStreamRequestAgentVersion$outboundSchema.parse(
      conversationStreamRequestAgentVersion,
    ),
  );
}

/** @internal */
export type ConversationStreamRequest$Outbound = {
  inputs: ConversationInputs$Outbound;
  stream: true;
  store?: boolean | null | undefined;
  handoff_execution?: string | null | undefined;
  instructions?: string | null | undefined;
  tools?:
    | Array<
      | CodeInterpreterTool$Outbound
      | CustomConnector$Outbound
      | DocumentLibraryTool$Outbound
      | FunctionTool$Outbound
      | ImageGenerationTool$Outbound
      | WebSearchTool$Outbound
      | WebSearchPremiumTool$Outbound
    >
    | null
    | undefined;
  completion_args?: CompletionArgs$Outbound | null | undefined;
  guardrails?: Array<GuardrailConfig$Outbound> | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  agent_id?: string | null | undefined;
  agent_version?: string | number | null | undefined;
  model?: string | null | undefined;
};

/** @internal */
export const ConversationStreamRequest$outboundSchema: z.ZodType<
  ConversationStreamRequest$Outbound,
  ConversationStreamRequest
> = z.object({
  inputs: ConversationInputs$outboundSchema,
  stream: z.literal(true).default(true as const),
  store: z.nullable(z.boolean()).optional(),
  handoffExecution: z.nullable(
    ConversationStreamRequestHandoffExecution$outboundSchema,
  ).optional(),
  instructions: z.nullable(z.string()).optional(),
  tools: z.nullable(
    z.array(
      z.union([
        CodeInterpreterTool$outboundSchema,
        CustomConnector$outboundSchema,
        DocumentLibraryTool$outboundSchema,
        FunctionTool$outboundSchema,
        ImageGenerationTool$outboundSchema,
        WebSearchTool$outboundSchema,
        WebSearchPremiumTool$outboundSchema,
      ]),
    ),
  ).optional(),
  completionArgs: z.nullable(CompletionArgs$outboundSchema).optional(),
  guardrails: z.nullable(z.array(GuardrailConfig$outboundSchema)).optional(),
  name: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  metadata: z.nullable(z.record(z.string(), z.any())).optional(),
  agentId: z.nullable(z.string()).optional(),
  agentVersion: z.nullable(smartUnion([z.string(), z.int()])).optional(),
  model: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    handoffExecution: "handoff_execution",
    completionArgs: "completion_args",
    agentId: "agent_id",
    agentVersion: "agent_version",
  });
});

export function conversationStreamRequestToJSON(
  conversationStreamRequest: ConversationStreamRequest,
): string {
  return JSON.stringify(
    ConversationStreamRequest$outboundSchema.parse(conversationStreamRequest),
  );
}
