/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { EventStream } from "../../lib/event-streams.js"; 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 * as components from "../components/index.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export const Include = { WebSearchCallActionSources: "web_search_call.action.sources", CodeInterpreterCallOutputs: "code_interpreter_call.outputs", ComputerCallOutputOutputImageUrl: "computer_call_output.output.image_url", FileSearchCallResults: "file_search_call.results", MessageInputImageImageUrl: "message.input_image.image_url", MessageOutputTextLogprobs: "message.output_text.logprobs", ReasoningEncryptedContent: "reasoning.encrypted_content", } as const; export type Include = ClosedEnum; export type GetResponseRequest = { responseId: string; include?: Array | undefined; includeObfuscation?: boolean | undefined; startingAfter?: number | undefined; stream?: boolean | undefined; /** * Optional external end-user identifier forwarded by the API gateway. */ xOnBehalfOf?: string | undefined; }; /** * Successful response - returns either streaming events (SSE) when stream=true or a complete response object (JSON) when stream=false or omitted */ export type GetResponseResponseBody = { /** * The event type (optional in SSE) */ event?: string | undefined; data: components.ResponseStreamingEvent; /** * Optional event ID for reconnection */ id?: string | undefined; /** * Optional reconnection time in milliseconds */ retry?: number | undefined; }; export type GetResponseResponse = | components.ResponseObject | EventStream; /** @internal */ export const Include$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Include); /** @internal */ export const Include$outboundSchema: z.ZodNativeEnum = Include$inboundSchema; /** @internal */ export const GetResponseRequest$inboundSchema: z.ZodType< GetResponseRequest, z.ZodTypeDef, unknown > = z.object({ response_id: z.string(), include: z.array(Include$inboundSchema).optional(), include_obfuscation: z.boolean().optional(), starting_after: z.number().int().optional(), stream: z.boolean().optional(), "X-On-Behalf-Of": z.string().optional(), }).transform((v) => { return remap$(v, { "response_id": "responseId", "include_obfuscation": "includeObfuscation", "starting_after": "startingAfter", "X-On-Behalf-Of": "xOnBehalfOf", }); }); /** @internal */ export type GetResponseRequest$Outbound = { response_id: string; include?: Array | undefined; include_obfuscation?: boolean | undefined; starting_after?: number | undefined; stream?: boolean | undefined; "X-On-Behalf-Of"?: string | undefined; }; /** @internal */ export const GetResponseRequest$outboundSchema: z.ZodType< GetResponseRequest$Outbound, z.ZodTypeDef, GetResponseRequest > = z.object({ responseId: z.string(), include: z.array(Include$outboundSchema).optional(), includeObfuscation: z.boolean().optional(), startingAfter: z.number().int().optional(), stream: z.boolean().optional(), xOnBehalfOf: z.string().optional(), }).transform((v) => { return remap$(v, { responseId: "response_id", includeObfuscation: "include_obfuscation", startingAfter: "starting_after", xOnBehalfOf: "X-On-Behalf-Of", }); }); export function getResponseRequestToJSON( getResponseRequest: GetResponseRequest, ): string { return JSON.stringify( GetResponseRequest$outboundSchema.parse(getResponseRequest), ); } export function getResponseRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetResponseRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetResponseRequest' from JSON`, ); } /** @internal */ export const GetResponseResponseBody$inboundSchema: z.ZodType< GetResponseResponseBody, z.ZodTypeDef, unknown > = z.object({ event: z.string().optional(), data: z.unknown().transform((v, ctx) => { if (typeof v !== "string") return v; try { return JSON.parse(v); } catch (err) { ctx.addIssue({ code: "custom", message: `malformed json: ${err}` }); return z.NEVER; } }).pipe(components.ResponseStreamingEvent$inboundSchema), id: z.string().optional(), retry: z.number().int().optional(), }); /** @internal */ export type GetResponseResponseBody$Outbound = { event?: string | undefined; data: components.ResponseStreamingEvent$Outbound; id?: string | undefined; retry?: number | undefined; }; /** @internal */ export const GetResponseResponseBody$outboundSchema: z.ZodType< GetResponseResponseBody$Outbound, z.ZodTypeDef, GetResponseResponseBody > = z.object({ event: z.string().optional(), data: components.ResponseStreamingEvent$outboundSchema, id: z.string().optional(), retry: z.number().int().optional(), }); export function getResponseResponseBodyToJSON( getResponseResponseBody: GetResponseResponseBody, ): string { return JSON.stringify( GetResponseResponseBody$outboundSchema.parse(getResponseResponseBody), ); } export function getResponseResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetResponseResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetResponseResponseBody' from JSON`, ); } /** @internal */ export const GetResponseResponse$inboundSchema: z.ZodType< GetResponseResponse, z.ZodTypeDef, unknown > = z.union([ components.ResponseObject$inboundSchema, z.instanceof(ReadableStream) .transform(stream => { return new EventStream(stream, rawEvent => { return { done: false, value: z.lazy(() => GetResponseResponseBody$inboundSchema).parse( rawEvent, ), }; }); }), ]); /** @internal */ export type GetResponseResponse$Outbound = | components.ResponseObject$Outbound | never; /** @internal */ export const GetResponseResponse$outboundSchema: z.ZodType< GetResponseResponse$Outbound, z.ZodTypeDef, GetResponseResponse > = z.union([components.ResponseObject$outboundSchema, z.never()]); export function getResponseResponseToJSON( getResponseResponse: GetResponseResponse, ): string { return JSON.stringify( GetResponseResponse$outboundSchema.parse(getResponseResponse), ); } export function getResponseResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetResponseResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetResponseResponse' from JSON`, ); }