/* * 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"; import { OutputText, OutputText$inboundSchema, OutputText$Outbound, OutputText$outboundSchema, } from "./outputtext.js"; import { Refusal, Refusal$inboundSchema, Refusal$Outbound, Refusal$outboundSchema, } from "./refusal.js"; export type OutputMessageWithIdContent = | (OutputText & { type: "output_text" }) | (Refusal & { type: "refusal" }); /** * The processing status of this message (in_progress, completed, or incomplete). */ export const OutputMessageWithIdStatus = { InProgress: "in_progress", Completed: "completed", Incomplete: "incomplete", } as const; /** * The processing status of this message (in_progress, completed, or incomplete). */ export type OutputMessageWithIdStatus = ClosedEnum< typeof OutputMessageWithIdStatus >; /** * Labels an assistant message as intermediate commentary or the final answer. */ export const OutputMessageWithIdPhase = { Commentary: "commentary", FinalAnswer: "final_answer", } as const; /** * Labels an assistant message as intermediate commentary or the final answer. */ export type OutputMessageWithIdPhase = ClosedEnum< typeof OutputMessageWithIdPhase >; /** * Output message item: An assistant message containing generated text content or refusal content. */ export type OutputMessageWithId = { /** * The item type identifier for message outputs. */ type: "message"; /** * The unique ID of the message. */ id: string; /** * The role of the message sender. Always 'assistant' for model-generated messages. */ role: "assistant"; /** * Array of content items in the assistant's response. Can contain text outputs or refusal messages. */ content: Array< (OutputText & { type: "output_text" }) | (Refusal & { type: "refusal" }) >; /** * The processing status of this message (in_progress, completed, or incomplete). */ status: OutputMessageWithIdStatus; /** * Labels an assistant message as intermediate commentary or the final answer. */ phase?: OutputMessageWithIdPhase | undefined; /** * The ID of the response that created this item, if any. */ responseId?: string | null | undefined; /** * Metadata from the response that created this item, if any. */ metadata?: { [k: string]: string } | null | undefined; }; /** @internal */ export const OutputMessageWithIdContent$inboundSchema: z.ZodType< OutputMessageWithIdContent, z.ZodTypeDef, unknown > = z.union([ OutputText$inboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$inboundSchema.and(z.object({ type: z.literal("refusal") })), ]); /** @internal */ export type OutputMessageWithIdContent$Outbound = | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }); /** @internal */ export const OutputMessageWithIdContent$outboundSchema: z.ZodType< OutputMessageWithIdContent$Outbound, z.ZodTypeDef, OutputMessageWithIdContent > = z.union([ OutputText$outboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$outboundSchema.and(z.object({ type: z.literal("refusal") })), ]); export function outputMessageWithIdContentToJSON( outputMessageWithIdContent: OutputMessageWithIdContent, ): string { return JSON.stringify( OutputMessageWithIdContent$outboundSchema.parse(outputMessageWithIdContent), ); } export function outputMessageWithIdContentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OutputMessageWithIdContent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutputMessageWithIdContent' from JSON`, ); } /** @internal */ export const OutputMessageWithIdStatus$inboundSchema: z.ZodNativeEnum< typeof OutputMessageWithIdStatus > = z.nativeEnum(OutputMessageWithIdStatus); /** @internal */ export const OutputMessageWithIdStatus$outboundSchema: z.ZodNativeEnum< typeof OutputMessageWithIdStatus > = OutputMessageWithIdStatus$inboundSchema; /** @internal */ export const OutputMessageWithIdPhase$inboundSchema: z.ZodNativeEnum< typeof OutputMessageWithIdPhase > = z.nativeEnum(OutputMessageWithIdPhase); /** @internal */ export const OutputMessageWithIdPhase$outboundSchema: z.ZodNativeEnum< typeof OutputMessageWithIdPhase > = OutputMessageWithIdPhase$inboundSchema; /** @internal */ export const OutputMessageWithId$inboundSchema: z.ZodType< OutputMessageWithId, z.ZodTypeDef, unknown > = z.object({ type: z.literal("message"), id: z.string(), role: z.literal("assistant"), content: z.array( z.union([ OutputText$inboundSchema.and( z.object({ type: z.literal("output_text") }), ), Refusal$inboundSchema.and(z.object({ type: z.literal("refusal") })), ]), ), status: OutputMessageWithIdStatus$inboundSchema, phase: OutputMessageWithIdPhase$inboundSchema.optional(), response_id: z.nullable(z.string()).optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { "response_id": "responseId", }); }); /** @internal */ export type OutputMessageWithId$Outbound = { type: "message"; id: string; role: "assistant"; content: Array< | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }) >; status: string; phase?: string | undefined; response_id?: string | null | undefined; metadata?: { [k: string]: string } | null | undefined; }; /** @internal */ export const OutputMessageWithId$outboundSchema: z.ZodType< OutputMessageWithId$Outbound, z.ZodTypeDef, OutputMessageWithId > = z.object({ type: z.literal("message"), id: z.string(), role: z.literal("assistant"), content: z.array( z.union([ OutputText$outboundSchema.and( z.object({ type: z.literal("output_text") }), ), Refusal$outboundSchema.and(z.object({ type: z.literal("refusal") })), ]), ), status: OutputMessageWithIdStatus$outboundSchema, phase: OutputMessageWithIdPhase$outboundSchema.optional(), responseId: z.nullable(z.string()).optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { responseId: "response_id", }); }); export function outputMessageWithIdToJSON( outputMessageWithId: OutputMessageWithId, ): string { return JSON.stringify( OutputMessageWithId$outboundSchema.parse(outputMessageWithId), ); } export function outputMessageWithIdFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OutputMessageWithId$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutputMessageWithId' from JSON`, ); }