/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The role of the message author. Determines how the message is interpreted by the model. */ export const Role = { System: "system", User: "user", Assistant: "assistant", Tool: "tool", Developer: "developer", } as const; /** * The role of the message author. Determines how the message is interpreted by the model. */ export type Role = ClosedEnum; export type File2 = { /** * The unique identifier of a previously uploaded file */ fileId: string; /** * Optional filename override */ filename?: string | undefined; }; export type File1 = { /** * The name of the file */ filename: string; /** * Base64-encoded file data */ fileData: string; }; /** * The file to include in the message, either as raw data or by reference */ export type TwoFile = File1 | File2; export type Two4 = { /** * Content type identifier for file content */ type: "file"; /** * The file to include in the message, either as raw data or by reference */ file: File1 | File2; }; /** * The format of the encoded audio data */ export const TwoFormat = { Wav: "wav", Mp3: "mp3", } as const; /** * The format of the encoded audio data */ export type TwoFormat = ClosedEnum; export type TwoInputAudio = { /** * Base64-encoded audio data */ data: string; /** * The format of the encoded audio data */ format: TwoFormat; }; export type Two3 = { /** * Content type identifier for audio input content */ type: "input_audio"; inputAudio: TwoInputAudio; }; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ export const TwoDetail = { Auto: "auto", Low: "low", High: "high", } as const; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ export type TwoDetail = ClosedEnum; export type ImageUrl = { /** * The URL of the image, or a base64-encoded image data URL */ url: string; /** * The detail level of the image analysis. 'low' disables high-res mode, 'high' enables it, 'auto' lets the model decide. */ detail?: TwoDetail | undefined; }; export type Two2 = { /** * Content type identifier for image URL content */ type: "image_url"; imageUrl: ImageUrl; }; export type Two1 = { /** * Content type identifier for text content */ type: "text"; /** * The text content to include in the message */ text: string; }; /** * A content part that can be included in a message. Supports text, images, audio, and files. */ export type Two = Two1 | Two2 | Two3 | Two4; /** * The contents of the message. Can be a string, an array of content parts (for multimodal inputs), or null for assistant messages with tool calls. */ export type Content = string | Array; /** * The function to be called */ export type OpenAIRequestMessageFunction = { /** * The name of the function to call */ name: string; /** * The arguments to call the function with, as a JSON string */ arguments: string; }; export type ToolCalls = { /** * The ID of the tool call */ id: string; /** * The type of the tool. Currently only 'function' is supported. */ type: "function"; /** * The function to be called */ function: OpenAIRequestMessageFunction; }; /** * A message in the chat completion request. Represents a conversation turn from the user, assistant, system, or tool. */ export type OpenAIRequestMessage = { /** * The role of the message author. Determines how the message is interpreted by the model. */ role: Role; /** * An optional name for the participant. For tool role messages, this is the name of the function called. */ name?: string | undefined; /** * Tool call that this message is responding to. Required when role is 'tool'. */ toolCallId?: string | undefined; /** * The contents of the message. Can be a string, an array of content parts (for multimodal inputs), or null for assistant messages with tool calls. */ content: string | Array | null; /** * The tool calls generated by the model, such as function calls. Only present for assistant messages with tool calls. */ toolCalls?: Array | undefined; }; /** @internal */ export const Role$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Role, ); /** @internal */ export const Role$outboundSchema: z.ZodNativeEnum = Role$inboundSchema; /** @internal */ export const File2$inboundSchema: z.ZodType = z .object({ file_id: z.string(), filename: z.string().optional(), }).transform((v) => { return remap$(v, { "file_id": "fileId", }); }); /** @internal */ export type File2$Outbound = { file_id: string; filename?: string | undefined; }; /** @internal */ export const File2$outboundSchema: z.ZodType< File2$Outbound, z.ZodTypeDef, File2 > = z.object({ fileId: z.string(), filename: z.string().optional(), }).transform((v) => { return remap$(v, { fileId: "file_id", }); }); export function file2ToJSON(file2: File2): string { return JSON.stringify(File2$outboundSchema.parse(file2)); } export function file2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => File2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'File2' from JSON`, ); } /** @internal */ export const File1$inboundSchema: z.ZodType = z .object({ filename: z.string(), file_data: z.string(), }).transform((v) => { return remap$(v, { "file_data": "fileData", }); }); /** @internal */ export type File1$Outbound = { filename: string; file_data: string; }; /** @internal */ export const File1$outboundSchema: z.ZodType< File1$Outbound, z.ZodTypeDef, File1 > = z.object({ filename: z.string(), fileData: z.string(), }).transform((v) => { return remap$(v, { fileData: "file_data", }); }); export function file1ToJSON(file1: File1): string { return JSON.stringify(File1$outboundSchema.parse(file1)); } export function file1FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => File1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'File1' from JSON`, ); } /** @internal */ export const TwoFile$inboundSchema: z.ZodType = z.union([ z.lazy(() => File1$inboundSchema), z.lazy(() => File2$inboundSchema), ]); /** @internal */ export type TwoFile$Outbound = File1$Outbound | File2$Outbound; /** @internal */ export const TwoFile$outboundSchema: z.ZodType< TwoFile$Outbound, z.ZodTypeDef, TwoFile > = z.union([ z.lazy(() => File1$outboundSchema), z.lazy(() => File2$outboundSchema), ]); export function twoFileToJSON(twoFile: TwoFile): string { return JSON.stringify(TwoFile$outboundSchema.parse(twoFile)); } export function twoFileFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => TwoFile$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TwoFile' from JSON`, ); } /** @internal */ export const Two4$inboundSchema: z.ZodType = z .object({ type: z.literal("file"), file: z.union([ z.lazy(() => File1$inboundSchema), z.lazy(() => File2$inboundSchema), ]), }); /** @internal */ export type Two4$Outbound = { type: "file"; file: File1$Outbound | File2$Outbound; }; /** @internal */ export const Two4$outboundSchema: z.ZodType = z.object({ type: z.literal("file"), file: z.union([ z.lazy(() => File1$outboundSchema), z.lazy(() => File2$outboundSchema), ]), }); export function two4ToJSON(two4: Two4): string { return JSON.stringify(Two4$outboundSchema.parse(two4)); } export function two4FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two4$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two4' from JSON`, ); } /** @internal */ export const TwoFormat$inboundSchema: z.ZodNativeEnum = z .nativeEnum(TwoFormat); /** @internal */ export const TwoFormat$outboundSchema: z.ZodNativeEnum = TwoFormat$inboundSchema; /** @internal */ export const TwoInputAudio$inboundSchema: z.ZodType< TwoInputAudio, z.ZodTypeDef, unknown > = z.object({ data: z.string(), format: TwoFormat$inboundSchema, }); /** @internal */ export type TwoInputAudio$Outbound = { data: string; format: string; }; /** @internal */ export const TwoInputAudio$outboundSchema: z.ZodType< TwoInputAudio$Outbound, z.ZodTypeDef, TwoInputAudio > = z.object({ data: z.string(), format: TwoFormat$outboundSchema, }); export function twoInputAudioToJSON(twoInputAudio: TwoInputAudio): string { return JSON.stringify(TwoInputAudio$outboundSchema.parse(twoInputAudio)); } export function twoInputAudioFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => TwoInputAudio$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TwoInputAudio' from JSON`, ); } /** @internal */ export const Two3$inboundSchema: z.ZodType = z .object({ type: z.literal("input_audio"), input_audio: z.lazy(() => TwoInputAudio$inboundSchema), }).transform((v) => { return remap$(v, { "input_audio": "inputAudio", }); }); /** @internal */ export type Two3$Outbound = { type: "input_audio"; input_audio: TwoInputAudio$Outbound; }; /** @internal */ export const Two3$outboundSchema: z.ZodType = z.object({ type: z.literal("input_audio"), inputAudio: z.lazy(() => TwoInputAudio$outboundSchema), }).transform((v) => { return remap$(v, { inputAudio: "input_audio", }); }); export function two3ToJSON(two3: Two3): string { return JSON.stringify(Two3$outboundSchema.parse(two3)); } export function two3FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two3' from JSON`, ); } /** @internal */ export const TwoDetail$inboundSchema: z.ZodNativeEnum = z .nativeEnum(TwoDetail); /** @internal */ export const TwoDetail$outboundSchema: z.ZodNativeEnum = TwoDetail$inboundSchema; /** @internal */ export const ImageUrl$inboundSchema: z.ZodType< ImageUrl, z.ZodTypeDef, unknown > = z.object({ url: z.string(), detail: TwoDetail$inboundSchema.optional(), }); /** @internal */ export type ImageUrl$Outbound = { url: string; detail?: string | undefined; }; /** @internal */ export const ImageUrl$outboundSchema: z.ZodType< ImageUrl$Outbound, z.ZodTypeDef, ImageUrl > = z.object({ url: z.string(), detail: TwoDetail$outboundSchema.optional(), }); export function imageUrlToJSON(imageUrl: ImageUrl): string { return JSON.stringify(ImageUrl$outboundSchema.parse(imageUrl)); } export function imageUrlFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ImageUrl$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ImageUrl' from JSON`, ); } /** @internal */ export const Two2$inboundSchema: z.ZodType = z .object({ type: z.literal("image_url"), image_url: z.lazy(() => ImageUrl$inboundSchema), }).transform((v) => { return remap$(v, { "image_url": "imageUrl", }); }); /** @internal */ export type Two2$Outbound = { type: "image_url"; image_url: ImageUrl$Outbound; }; /** @internal */ export const Two2$outboundSchema: z.ZodType = z.object({ type: z.literal("image_url"), imageUrl: z.lazy(() => ImageUrl$outboundSchema), }).transform((v) => { return remap$(v, { imageUrl: "image_url", }); }); export function two2ToJSON(two2: Two2): string { return JSON.stringify(Two2$outboundSchema.parse(two2)); } export function two2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two2' from JSON`, ); } /** @internal */ export const Two1$inboundSchema: z.ZodType = z .object({ type: z.literal("text"), text: z.string(), }); /** @internal */ export type Two1$Outbound = { type: "text"; text: string; }; /** @internal */ export const Two1$outboundSchema: z.ZodType = z.object({ type: z.literal("text"), text: z.string(), }); export function two1ToJSON(two1: Two1): string { return JSON.stringify(Two1$outboundSchema.parse(two1)); } export function two1FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two1' from JSON`, ); } /** @internal */ export const Two$inboundSchema: z.ZodType = z.union( [ z.lazy(() => Two1$inboundSchema), z.lazy(() => Two2$inboundSchema), z.lazy(() => Two3$inboundSchema), z.lazy(() => Two4$inboundSchema), ], ); /** @internal */ export type Two$Outbound = | Two1$Outbound | Two2$Outbound | Two3$Outbound | Two4$Outbound; /** @internal */ export const Two$outboundSchema: z.ZodType = z .union([ z.lazy(() => Two1$outboundSchema), z.lazy(() => Two2$outboundSchema), z.lazy(() => Two3$outboundSchema), z.lazy(() => Two4$outboundSchema), ]); export function twoToJSON(two: Two): string { return JSON.stringify(Two$outboundSchema.parse(two)); } export function twoFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two' from JSON`, ); } /** @internal */ export const Content$inboundSchema: z.ZodType = z.union([ z.string(), z.array(z.union([ z.lazy(() => Two1$inboundSchema), z.lazy(() => Two2$inboundSchema), z.lazy(() => Two3$inboundSchema), z.lazy(() => Two4$inboundSchema), ])), ]); /** @internal */ export type Content$Outbound = | string | Array; /** @internal */ export const Content$outboundSchema: z.ZodType< Content$Outbound, z.ZodTypeDef, Content > = z.union([ z.string(), z.array(z.union([ z.lazy(() => Two1$outboundSchema), z.lazy(() => Two2$outboundSchema), z.lazy(() => Two3$outboundSchema), z.lazy(() => Two4$outboundSchema), ])), ]); export function contentToJSON(content: Content): string { return JSON.stringify(Content$outboundSchema.parse(content)); } export function contentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Content$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Content' from JSON`, ); } /** @internal */ export const OpenAIRequestMessageFunction$inboundSchema: z.ZodType< OpenAIRequestMessageFunction, z.ZodTypeDef, unknown > = z.object({ name: z.string(), arguments: z.string(), }); /** @internal */ export type OpenAIRequestMessageFunction$Outbound = { name: string; arguments: string; }; /** @internal */ export const OpenAIRequestMessageFunction$outboundSchema: z.ZodType< OpenAIRequestMessageFunction$Outbound, z.ZodTypeDef, OpenAIRequestMessageFunction > = z.object({ name: z.string(), arguments: z.string(), }); export function openAIRequestMessageFunctionToJSON( openAIRequestMessageFunction: OpenAIRequestMessageFunction, ): string { return JSON.stringify( OpenAIRequestMessageFunction$outboundSchema.parse( openAIRequestMessageFunction, ), ); } export function openAIRequestMessageFunctionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIRequestMessageFunction$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIRequestMessageFunction' from JSON`, ); } /** @internal */ export const ToolCalls$inboundSchema: z.ZodType< ToolCalls, z.ZodTypeDef, unknown > = z.object({ id: z.string(), type: z.literal("function"), function: z.lazy(() => OpenAIRequestMessageFunction$inboundSchema), }); /** @internal */ export type ToolCalls$Outbound = { id: string; type: "function"; function: OpenAIRequestMessageFunction$Outbound; }; /** @internal */ export const ToolCalls$outboundSchema: z.ZodType< ToolCalls$Outbound, z.ZodTypeDef, ToolCalls > = z.object({ id: z.string(), type: z.literal("function"), function: z.lazy(() => OpenAIRequestMessageFunction$outboundSchema), }); export function toolCallsToJSON(toolCalls: ToolCalls): string { return JSON.stringify(ToolCalls$outboundSchema.parse(toolCalls)); } export function toolCallsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ToolCalls$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ToolCalls' from JSON`, ); } /** @internal */ export const OpenAIRequestMessage$inboundSchema: z.ZodType< OpenAIRequestMessage, z.ZodTypeDef, unknown > = z.object({ role: Role$inboundSchema, name: z.string().optional(), tool_call_id: z.string().optional(), content: z.nullable( z.union([ z.string(), z.array(z.union([ z.lazy(() => Two1$inboundSchema), z.lazy(() => Two2$inboundSchema), z.lazy(() => Two3$inboundSchema), z.lazy(() => Two4$inboundSchema), ])), ]), ), tool_calls: z.array(z.lazy(() => ToolCalls$inboundSchema)).optional(), }).transform((v) => { return remap$(v, { "tool_call_id": "toolCallId", "tool_calls": "toolCalls", }); }); /** @internal */ export type OpenAIRequestMessage$Outbound = { role: string; name?: string | undefined; tool_call_id?: string | undefined; content: | string | Array | null; tool_calls?: Array | undefined; }; /** @internal */ export const OpenAIRequestMessage$outboundSchema: z.ZodType< OpenAIRequestMessage$Outbound, z.ZodTypeDef, OpenAIRequestMessage > = z.object({ role: Role$outboundSchema, name: z.string().optional(), toolCallId: z.string().optional(), content: z.nullable( z.union([ z.string(), z.array(z.union([ z.lazy(() => Two1$outboundSchema), z.lazy(() => Two2$outboundSchema), z.lazy(() => Two3$outboundSchema), z.lazy(() => Two4$outboundSchema), ])), ]), ), toolCalls: z.array(z.lazy(() => ToolCalls$outboundSchema)).optional(), }).transform((v) => { return remap$(v, { toolCallId: "tool_call_id", toolCalls: "tool_calls", }); }); export function openAIRequestMessageToJSON( openAIRequestMessage: OpenAIRequestMessage, ): string { return JSON.stringify( OpenAIRequestMessage$outboundSchema.parse(openAIRequestMessage), ); } export function openAIRequestMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OpenAIRequestMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OpenAIRequestMessage' from JSON`, ); }