/* * 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 { 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 { ReasoningText, ReasoningText$inboundSchema, ReasoningText$Outbound, ReasoningText$outboundSchema, } from "./reasoningtext.js"; import { Refusal, Refusal$inboundSchema, Refusal$Outbound, Refusal$outboundSchema, } from "./refusal.js"; export type ResponseContentPartDoneEventPart = | (OutputText & { type: "output_text" }) | (Refusal & { type: "refusal" }) | (ReasoningText & { type: "reasoning_text" }); export type ResponseContentPartDoneEvent = { type: "response.content_part.done"; sequenceNumber: number; itemId: string; outputIndex: number; contentIndex: number; part: | (OutputText & { type: "output_text" }) | (Refusal & { type: "refusal" }) | (ReasoningText & { type: "reasoning_text" }); }; /** @internal */ export const ResponseContentPartDoneEventPart$inboundSchema: z.ZodType< ResponseContentPartDoneEventPart, z.ZodTypeDef, unknown > = z.union([ OutputText$inboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$inboundSchema.and(z.object({ type: z.literal("refusal") })), ReasoningText$inboundSchema.and( z.object({ type: z.literal("reasoning_text") }), ), ]); /** @internal */ export type ResponseContentPartDoneEventPart$Outbound = | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }) | (ReasoningText$Outbound & { type: "reasoning_text" }); /** @internal */ export const ResponseContentPartDoneEventPart$outboundSchema: z.ZodType< ResponseContentPartDoneEventPart$Outbound, z.ZodTypeDef, ResponseContentPartDoneEventPart > = z.union([ OutputText$outboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$outboundSchema.and(z.object({ type: z.literal("refusal") })), ReasoningText$outboundSchema.and( z.object({ type: z.literal("reasoning_text") }), ), ]); export function responseContentPartDoneEventPartToJSON( responseContentPartDoneEventPart: ResponseContentPartDoneEventPart, ): string { return JSON.stringify( ResponseContentPartDoneEventPart$outboundSchema.parse( responseContentPartDoneEventPart, ), ); } export function responseContentPartDoneEventPartFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ResponseContentPartDoneEventPart$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ResponseContentPartDoneEventPart' from JSON`, ); } /** @internal */ export const ResponseContentPartDoneEvent$inboundSchema: z.ZodType< ResponseContentPartDoneEvent, z.ZodTypeDef, unknown > = z.object({ type: z.literal("response.content_part.done"), sequence_number: z.number().int(), item_id: z.string(), output_index: z.number().int(), content_index: z.number().int(), part: z.union([ OutputText$inboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$inboundSchema.and(z.object({ type: z.literal("refusal") })), ReasoningText$inboundSchema.and( z.object({ type: z.literal("reasoning_text") }), ), ]), }).transform((v) => { return remap$(v, { "sequence_number": "sequenceNumber", "item_id": "itemId", "output_index": "outputIndex", "content_index": "contentIndex", }); }); /** @internal */ export type ResponseContentPartDoneEvent$Outbound = { type: "response.content_part.done"; sequence_number: number; item_id: string; output_index: number; content_index: number; part: | (OutputText$Outbound & { type: "output_text" }) | (Refusal$Outbound & { type: "refusal" }) | (ReasoningText$Outbound & { type: "reasoning_text" }); }; /** @internal */ export const ResponseContentPartDoneEvent$outboundSchema: z.ZodType< ResponseContentPartDoneEvent$Outbound, z.ZodTypeDef, ResponseContentPartDoneEvent > = z.object({ type: z.literal("response.content_part.done"), sequenceNumber: z.number().int(), itemId: z.string(), outputIndex: z.number().int(), contentIndex: z.number().int(), part: z.union([ OutputText$outboundSchema.and(z.object({ type: z.literal("output_text") })), Refusal$outboundSchema.and(z.object({ type: z.literal("refusal") })), ReasoningText$outboundSchema.and( z.object({ type: z.literal("reasoning_text") }), ), ]), }).transform((v) => { return remap$(v, { sequenceNumber: "sequence_number", itemId: "item_id", outputIndex: "output_index", contentIndex: "content_index", }); }); export function responseContentPartDoneEventToJSON( responseContentPartDoneEvent: ResponseContentPartDoneEvent, ): string { return JSON.stringify( ResponseContentPartDoneEvent$outboundSchema.parse( responseContentPartDoneEvent, ), ); } export function responseContentPartDoneEventFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ResponseContentPartDoneEvent$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ResponseContentPartDoneEvent' from JSON`, ); }