/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; 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 OutputMessageContent = | (OutputText & { type: "output_text" }) | (Refusal & { type: "refusal" }); /** * The processing status of this message (in_progress, completed, or incomplete). */ export const OutputMessageStatus = { InProgress: "in_progress", Completed: "completed", Incomplete: "incomplete", } as const; /** * The processing status of this message (in_progress, completed, or incomplete). */ export type OutputMessageStatus = ClosedEnum; /** * Labels an assistant message as intermediate commentary or the final answer. */ export const Phase = { Commentary: "commentary", FinalAnswer: "final_answer", } as const; /** * Labels an assistant message as intermediate commentary or the final answer. */ export type Phase = ClosedEnum; /** * Output message item: An assistant message containing generated text content or refusal content. */ export type OutputMessage = { /** * The item type identifier for message outputs. */ type: "message"; /** * The unique identifier for this output 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: OutputMessageStatus; /** * Labels an assistant message as intermediate commentary or the final answer. */ phase?: Phase | undefined; }; /** @internal */ export const OutputMessageContent$inboundSchema: z.ZodType< OutputMessageContent, 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 OutputMessageContent$Outbound = | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }); /** @internal */ export const OutputMessageContent$outboundSchema: z.ZodType< OutputMessageContent$Outbound, z.ZodTypeDef, OutputMessageContent > = z.union([ OutputText$outboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$outboundSchema.and(z.object({ type: z.literal("refusal") })), ]); export function outputMessageContentToJSON( outputMessageContent: OutputMessageContent, ): string { return JSON.stringify( OutputMessageContent$outboundSchema.parse(outputMessageContent), ); } export function outputMessageContentFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OutputMessageContent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutputMessageContent' from JSON`, ); } /** @internal */ export const OutputMessageStatus$inboundSchema: z.ZodNativeEnum< typeof OutputMessageStatus > = z.nativeEnum(OutputMessageStatus); /** @internal */ export const OutputMessageStatus$outboundSchema: z.ZodNativeEnum< typeof OutputMessageStatus > = OutputMessageStatus$inboundSchema; /** @internal */ export const Phase$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Phase, ); /** @internal */ export const Phase$outboundSchema: z.ZodNativeEnum = Phase$inboundSchema; /** @internal */ export const OutputMessage$inboundSchema: z.ZodType< OutputMessage, 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: OutputMessageStatus$inboundSchema, phase: Phase$inboundSchema.optional(), }); /** @internal */ export type OutputMessage$Outbound = { type: "message"; id: string; role: "assistant"; content: Array< | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }) >; status: string; phase?: string | undefined; }; /** @internal */ export const OutputMessage$outboundSchema: z.ZodType< OutputMessage$Outbound, z.ZodTypeDef, OutputMessage > = 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: OutputMessageStatus$outboundSchema, phase: Phase$outboundSchema.optional(), }); export function outputMessageToJSON(outputMessage: OutputMessage): string { return JSON.stringify(OutputMessage$outboundSchema.parse(outputMessage)); } export function outputMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OutputMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutputMessage' from JSON`, ); }