/* * 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 { Result as SafeParseResult } from "../../types/fp.js"; import * as components from "../components/index.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type CreateResponseRequest = { /** * Optional external end-user identifier forwarded by the API gateway. */ xOnBehalfOf?: string | undefined; responsesCreateRequest: components.ResponsesCreateRequest; }; /** * Successful response - returns either streaming events (SSE) or a complete response object (JSON) depending on the stream parameter */ export type CreateResponseResponseBody = { /** * 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 CreateResponseResponse = | components.ResponseObject | EventStream; /** @internal */ export const CreateResponseRequest$inboundSchema: z.ZodType< CreateResponseRequest, z.ZodTypeDef, unknown > = z.object({ "X-On-Behalf-Of": z.string().optional(), ResponsesCreateRequest: components.ResponsesCreateRequest$inboundSchema, }).transform((v) => { return remap$(v, { "X-On-Behalf-Of": "xOnBehalfOf", "ResponsesCreateRequest": "responsesCreateRequest", }); }); /** @internal */ export type CreateResponseRequest$Outbound = { "X-On-Behalf-Of"?: string | undefined; ResponsesCreateRequest: components.ResponsesCreateRequest$Outbound; }; /** @internal */ export const CreateResponseRequest$outboundSchema: z.ZodType< CreateResponseRequest$Outbound, z.ZodTypeDef, CreateResponseRequest > = z.object({ xOnBehalfOf: z.string().optional(), responsesCreateRequest: components.ResponsesCreateRequest$outboundSchema, }).transform((v) => { return remap$(v, { xOnBehalfOf: "X-On-Behalf-Of", responsesCreateRequest: "ResponsesCreateRequest", }); }); export function createResponseRequestToJSON( createResponseRequest: CreateResponseRequest, ): string { return JSON.stringify( CreateResponseRequest$outboundSchema.parse(createResponseRequest), ); } export function createResponseRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateResponseRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateResponseRequest' from JSON`, ); } /** @internal */ export const CreateResponseResponseBody$inboundSchema: z.ZodType< CreateResponseResponseBody, 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 CreateResponseResponseBody$Outbound = { event?: string | undefined; data: components.ResponseStreamingEvent$Outbound; id?: string | undefined; retry?: number | undefined; }; /** @internal */ export const CreateResponseResponseBody$outboundSchema: z.ZodType< CreateResponseResponseBody$Outbound, z.ZodTypeDef, CreateResponseResponseBody > = z.object({ event: z.string().optional(), data: components.ResponseStreamingEvent$outboundSchema, id: z.string().optional(), retry: z.number().int().optional(), }); export function createResponseResponseBodyToJSON( createResponseResponseBody: CreateResponseResponseBody, ): string { return JSON.stringify( CreateResponseResponseBody$outboundSchema.parse(createResponseResponseBody), ); } export function createResponseResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateResponseResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateResponseResponseBody' from JSON`, ); } /** @internal */ export const CreateResponseResponse$inboundSchema: z.ZodType< CreateResponseResponse, z.ZodTypeDef, unknown > = z.union([ components.ResponseObject$inboundSchema, z.instanceof(ReadableStream) .transform(stream => { return new EventStream(stream, rawEvent => { return { done: false, value: z.lazy(() => CreateResponseResponseBody$inboundSchema).parse( rawEvent, ), }; }); }), ]); /** @internal */ export type CreateResponseResponse$Outbound = | components.ResponseObject$Outbound | never; /** @internal */ export const CreateResponseResponse$outboundSchema: z.ZodType< CreateResponseResponse$Outbound, z.ZodTypeDef, CreateResponseResponse > = z.union([components.ResponseObject$outboundSchema, z.never()]); export function createResponseResponseToJSON( createResponseResponse: CreateResponseResponse, ): string { return JSON.stringify( CreateResponseResponse$outboundSchema.parse(createResponseResponse), ); } export function createResponseResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateResponseResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateResponseResponse' from JSON`, ); }