{"version":3,"sources":["../src/message/roles.ts","../src/message/content/image-content.ts","../src/message/content/reasoning-content.ts","../src/message/content/text-content.ts","../src/message/content/tool-call-content.ts","../src/message/content/tool-response-content.ts","../src/message/content/content.ts","../src/message/content/token-content.ts","../src/message/message.ts","../src/chat/chat-response.ts","../src/config/config.ts","../src/config/response-schema.config.ts","../src/embedding/embedding-requests.ts","../src/embedding/embedding-response.ts","../src/errors/gateway-base.error.ts","../src/pricing/pricing-tiers.ts","../src/tool/function-tool.ts","../src/tool/tool.ts","../src/utils/create-message.ts","../src/utils/merge-partial-messages.ts"],"names":["SystemRoleLiteral","UserRoleLiteral","AssistantRoleLiteral","ToolRoleLiteral","RoleLiterals","RoleEnum","z","PartialRoleLiterals","PartialRoleEnum","ImageModalityLiteral","Base64ImageContentTypeLiteral","Base64ImageContentMediaTypeLiterals","Base64ImageContentValue","UrlImageContentTypeLiteral","UrlImageContentValue","ImageContentValue","ImageContentDetails","ImageContentDetailsLiteral","ImageContent","Metadata","ReasoningModalityLiteral","PartialReasoningModalityLiteral","ReasoningContentTypeLiteral","RedactedReasoningContentTypeLiteral","ReasoningContentValue","RedactedReasoningContentValue","ReasoningContentValueUnion","ReasoningContent","PartialReasoningContentValue","PartialReasoningContentValueUnion","PartialReasoningContent","TextModalityLiteral","TextContent","PartialTextModalityLiteral","PartialTextContent","ToolCallModalityLiteral","ToolCallContent","PartialToolCallModalityLiteral","PartialToolCallContent","ToolResponseModalityLiteral","ToolResponseContent","ModalityLiterals","ModalityEnum","Content","TextContentMetadata","ImageContentMetadata","ToolCallContentMetadata","ToolResponseContentMetadata","ReasoningContentMetadata","PartialModalityLiterals","PartialModalityEnum","PartialContent","PartialTextContentMetadata","PartialToolCallContentMetadata","PartialReasoningContentMetadata","TokenModalityLiteral","TokenContent","Message","Role","MessageMetadata","PartialMessage","ChatUsage","ChatBaseLogProb","ChatLogProb","ChatLogProbs","ChatResponse","PartialChatUsage","PartialChatResponse","Config","ResponseSchemaTypes","ResponseSchemaTypesLiteral","ResponseSchemaProperty","ResponseSchemaStructure","ResponseSchema","EmbeddingTextModalityLiteral","EmbeddingTokenModalityLiteral","EmbeddingModalityLiterals","EmbeddingModalityEnum","TextEmbeddingRequests","TokenEmbeddingRequests","EmbeddingRequests","FloatEmbeddingLiteral","FloatEmbedding","Base64EmbeddingLiteral","Base64Embedding","EmbeddingsUsage","EmbeddingResponse","safeStringify","obj","seen","key","value","getErrorMessage","error","GatewayBaseErrorLiteral","GatewayBaseError","_GatewayBaseError","info","cause","name","ChatModelTokenPairPrice","ChatModelTokenTypePrice","ChatModelTokenRangePrice","t","ChatModelPrice","data","ctx","tokenRanges","i","prev","curr","last","FunctionToolLiteral","FunctionParameterTypes","FunctionParameterTypesLiteral","FunctionParameter","FunctionParameters","Function","ToolTypes","ToolTypesLiteral","FunctionTool","ToolLiterals","ToolEnum","Tool","FunctionToolMetadata","createTextContent","content","createToolCallContent","index","id","args","createTextMessage","role","createUrlImageMessage","url","detail","createBase64ImageMessage","base64","createToolCallMessage","createToolResponseMessage","createPartialTextMessage","createPartialToolCallMessage","createReasoningContent","thinking","signature","createReasoningMessage","createRedactedReasoningContent","createRedactedReasoningMessage","createPartialReasoningMessage","createPartialRedactedReasoningMessage","mergePartialMessages","response","_a","finalizedResponse","mergedContents","lastModality","lastReasoningType","lastToolCallIndex","currentTextValue","currentToolCall","currentReasoning","finalizePreviousBlock","finalizedContent","chatChunk","chunkIndex","message","messageIndex","_b","_c","_d","_e","_f","_g","_h","_i","_j","_k","_l","currentContent","currentModality","currentReasoningType","currentToolCallIndex","textPart","toolCallPart","valuePart","firstPrompt","lastPrompt","totalCompletion","usageFound","aggregatedUsage","chunk","u"],"mappings":";;AAEA,IAAMA,EAAoB,CAAA,QAAA,CACpBC,GAAkB,MAClBC,CAAAA,CAAAA,CAAuB,YACvBC,EAAkB,CAAA,MAAA,CAElBC,GAAe,CAACJ,EAAAA,CAAmBC,EAAiBC,CAAAA,CAAAA,CAAsBC,EAAe,CACzFE,CAA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AMvJ,CACN,CAAA,OAAA,CAASwJ,CACX,CACF,CAAA,CAIA,IAAI+B,EACAC,CAAAA,CAAAA,CACAC,EAAkB,CAAA,CAAA,CAClBC,EAAa,CAAA,CAAA,CAAA,CAEXC,EAAiC,CACrC,YAAA,CAAc,CACd,CAAA,gBAAA,CAAkB,CAClB,CAAA,WAAA,CAAa,CACf,CAEA,CAAA,IAAA,IAAWC,CAASvC,IAAAA,CAAAA,CAAU,CAC5B,IAAMwC,EAAID,CAAM,CAAA,KAAA,CACXC,IAELH,EAAa,CAAA,CAAA,CAAA,CAGTG,EAAE,YAAgB,EAAA,IAAA,GAChBN,EAAgB,GAAA,KAAA,CAAA,GAClBA,EAAcM,CAAAA,CAAAA,CAAE,cAElBL,CAAaK,CAAAA,CAAAA,CAAE,cAIbA,CAAE,CAAA,gBAAA,EAAoB,OACxBJ,EAAmBI,EAAAA,CAAAA,CAAE,gBAEzB,CAAA,EAAA,CAEA,OAAIH,EAAAA,EAEFC,EAAgB,YAAerC,CAAAA,CAAAA,EAAAA,CAAAkC,GAAA,IAAAA,CAAAA,CAAAA,CAAcD,KAAd,IAAAjC,CAAAA,EAAAA,CAA6B,CAC5DqC,CAAAA,CAAAA,CAAgB,gBAAmBF,CAAAA,EAAAA,CACnCE,EAAgB,WAAcA,CAAAA,CAAAA,CAAgB,YAAeA,CAAAA,CAAAA,CAAgB,gBAE7EpC,CAAAA,CAAAA,CAAkB,MAAQoC,CAE1BpC,EAAAA,CAAAA,CAAkB,KAAQ,CAAA,KAAA,CAAA,CAErBA,CACT","file":"index.mjs","sourcesContent":["import { z } from \"zod\";\n\nconst SystemRoleLiteral = \"system\" as const;\nconst UserRoleLiteral = \"user\" as const;\nconst AssistantRoleLiteral = \"assistant\" as const;\nconst ToolRoleLiteral = \"tool\" as const;\n\nconst RoleLiterals = [SystemRoleLiteral, UserRoleLiteral, AssistantRoleLiteral, ToolRoleLiteral] as const;\nconst RoleEnum = z.enum(RoleLiterals);\ntype RoleEnumType = z.infer<typeof RoleEnum>;\n\nconst PartialRoleLiterals = [AssistantRoleLiteral] as const;\nconst PartialRoleEnum = z.enum(PartialRoleLiterals);\ntype PartialRoleEnumType = z.infer<typeof PartialRoleEnum>;\n\nexport {\n  UserRoleLiteral,\n  ToolRoleLiteral,\n  SystemRoleLiteral,\n  AssistantRoleLiteral,\n  RoleEnum,\n  RoleLiterals,\n  PartialRoleEnum,\n  PartialRoleLiterals,\n  type RoleEnumType,\n  type PartialRoleEnumType,\n};\n","import { z } from \"zod\";\n\nconst ImageModalityLiteral = \"image\" as const;\n\nconst Base64ImageContentTypeLiteral = \"base64\" as const;\nconst Base64ImageContentMediaTypeLiterals = [\"png\", \"jpeg\", \"webp\", \"gif\"] as const;\nconst Base64ImageContentValue = z.object({\n  type: z.literal(Base64ImageContentTypeLiteral),\n  base64: z.string(),\n  mediaType: z.enum(Base64ImageContentMediaTypeLiterals),\n});\ntype Base64ImageContentValueType = z.infer<typeof Base64ImageContentValue>;\n\nconst UrlImageContentTypeLiteral = \"url\" as const;\nconst UrlImageContentValue = z.object({\n  type: z.literal(UrlImageContentTypeLiteral),\n  url: z.string(),\n});\ntype UrlImageContentValueType = z.infer<typeof UrlImageContentValue>;\n\nconst ImageContentValue = z.discriminatedUnion(\"type\", [Base64ImageContentValue, UrlImageContentValue]);\ntype ImageContentValueType = z.infer<typeof ImageContentValue>;\n\nconst ImageContentDetails = [\"low\", \"medium\", \"high\", \"auto\"] as const;\nconst ImageContentDetailsLiteral = z.enum(ImageContentDetails);\ntype ImageContentDetailsLiteralType = z.infer<typeof ImageContentDetailsLiteral>;\nconst ImageContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(ImageModalityLiteral),\n    detail: ImageContentDetailsLiteral,\n    value: ImageContentValue,\n    metadata: Metadata,\n  });\ntype ImageContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof ImageContent<M>>>;\n\nexport {\n  Base64ImageContentValue,\n  ImageContent,\n  ImageContentDetails,\n  ImageContentDetailsLiteral,\n  ImageModalityLiteral,\n  UrlImageContentValue,\n  UrlImageContentTypeLiteral,\n  Base64ImageContentTypeLiteral,\n  Base64ImageContentMediaTypeLiterals,\n  type Base64ImageContentValueType,\n  type ImageContentDetailsLiteralType,\n  type ImageContentType,\n  type ImageContentValueType,\n  type UrlImageContentValueType,\n};\n","import { z } from \"zod\";\n\nconst ReasoningModalityLiteral = \"reasoning\" as const;\nconst PartialReasoningModalityLiteral = \"partial-reasoning\" as const;\n\nconst ReasoningContentTypeLiteral = \"thinking\" as const;\nconst RedactedReasoningContentTypeLiteral = \"redacted\" as const;\n\nconst ReasoningContentValue = z.object({\n  type: z.literal(ReasoningContentTypeLiteral),\n  thinking: z.string(),\n  signature: z.string(),\n});\ntype ReasoningContentValueType = z.infer<typeof ReasoningContentValue>;\n\nconst RedactedReasoningContentValue = z.object({\n  type: z.literal(RedactedReasoningContentTypeLiteral),\n  data: z.string()\n});\ntype RedactedReasoningContentValueType = z.infer<typeof RedactedReasoningContentValue>;\n\nconst ReasoningContentValueUnion = z.discriminatedUnion(\"type\", [ ReasoningContentValue, RedactedReasoningContentValue ]);\ntype ReasoningContentValueUnionType = z.infer<typeof ReasoningContentValueUnion>;\n\nconst ReasoningContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(ReasoningModalityLiteral),\n    value: ReasoningContentValueUnion,\n    metadata: Metadata,\n  });\n\ntype ReasoningContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof ReasoningContent<M>>>;\n\nconst PartialReasoningContentValue = z.object({\n  type: z.literal(ReasoningContentTypeLiteral),\n  thinking: ReasoningContentValue.shape.thinking.optional(),\n  signature: ReasoningContentValue.shape.signature.optional(),\n});\nconst PartialReasoningContentValueUnion = z.discriminatedUnion(\"type\", [ \n  PartialReasoningContentValue, \n  RedactedReasoningContentValue \n]);\n\nconst PartialReasoningContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(PartialReasoningModalityLiteral),\n    value: PartialReasoningContentValueUnion,\n    metadata: Metadata,\n  });\ntype PartialReasoningContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof PartialReasoningContent<M>>>;\n\nexport {\n  ReasoningContent,\n  PartialReasoningContent,\n  PartialReasoningModalityLiteral,\n  ReasoningContentTypeLiteral,\n  ReasoningContentValue,\n  PartialReasoningContentValue,\n  ReasoningContentValueUnion,\n  PartialReasoningContentValueUnion,\n  ReasoningModalityLiteral,\n  RedactedReasoningContentTypeLiteral,\n  RedactedReasoningContentValue,\n  type PartialReasoningContentType,\n  type ReasoningContentType,\n  type ReasoningContentValueType,\n  type ReasoningContentValueUnionType,\n  type RedactedReasoningContentValueType,\n};\n","import { z } from \"zod\";\n\nconst TextModalityLiteral = \"text\" as const;\n\nconst TextContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(TextModalityLiteral),\n    value: z.string(),\n    metadata: Metadata,\n  });\ntype TextContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof TextContent<M>>>;\nconst PartialTextModalityLiteral = \"partial-text\" as const;\n\nconst PartialTextContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(PartialTextModalityLiteral),\n    value: z.string(),\n    metadata: Metadata,\n  });\ntype PartialTextContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof PartialTextContent<M>>>;\n\nexport {\n  TextContent,\n  PartialTextContent,\n  TextModalityLiteral,\n  PartialTextModalityLiteral,\n  type TextContentType,\n  type PartialTextContentType,\n};\n","import { z } from \"zod\";\n\nconst ToolCallModalityLiteral = \"tool-call\" as const;\n\nconst ToolCallContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(ToolCallModalityLiteral),\n    index: z.number().int().nonnegative(),\n    id: z.string().min(1),\n    name: z.string().min(1),\n    arguments: z.string(),\n    metadata: Metadata,\n  });\ntype ToolCallContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof ToolCallContent<M>>>;\nconst PartialToolCallModalityLiteral = \"partial-tool-call\" as const;\n\nconst PartialToolCallContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(PartialToolCallModalityLiteral),\n    index: z.number().int().nonnegative(),\n    id: z.string().optional(),\n    name: z.string().optional(),\n    arguments: z.string().optional(),\n    metadata: Metadata,\n  });\ntype PartialToolCallContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof PartialToolCallContent<M>>>;\n\nexport {\n  ToolCallContent,\n  PartialToolCallContent,\n  ToolCallModalityLiteral,\n  PartialToolCallModalityLiteral,\n  type ToolCallContentType,\n  type PartialToolCallContentType,\n};\n","import { z } from \"zod\";\n\nconst ToolResponseModalityLiteral = \"tool-response\" as const;\n\nconst ToolResponseContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(ToolResponseModalityLiteral),\n    index: z.number().int().nonnegative(),\n    id: z.string().min(1),\n    name: z.string().min(1),\n    data: z.string(),\n    metadata: Metadata,\n  });\ntype ToolResponseContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof ToolResponseContent<M>>>;\n\nexport { ToolResponseContent, ToolResponseModalityLiteral, type ToolResponseContentType };\n","import { z } from \"zod\";\n\nimport { ImageContent, ImageModalityLiteral } from \"./image-content\";\nimport { PartialReasoningContent, PartialReasoningModalityLiteral, ReasoningContent, ReasoningModalityLiteral } from \"./reasoning-content\";\nimport { PartialTextContent, PartialTextModalityLiteral, TextContent, TextModalityLiteral } from \"./text-content\";\nimport { PartialToolCallContent, PartialToolCallModalityLiteral, ToolCallContent, ToolCallModalityLiteral } from \"./tool-call-content\";\nimport { ToolResponseContent, ToolResponseModalityLiteral } from \"./tool-response-content\";\n\nconst ModalityLiterals = [\n  TextModalityLiteral,\n  ImageModalityLiteral,\n  ToolCallModalityLiteral,\n  ToolResponseModalityLiteral,\n  ReasoningModalityLiteral,\n] as const;\nconst ModalityEnum = z.enum(ModalityLiterals);\ntype ModalityEnumType = z.infer<typeof ModalityEnum>;\n\nconst Content = <\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  ICM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  RCM extends z.ZodTypeAny = z.ZodUndefined,\n  TCCM extends z.ZodTypeAny = z.ZodUndefined,\n>(\n  TextContentMetadata: TCM = z.undefined() as TCM,\n  ImageContentMetadata: ICM = z.undefined() as ICM,\n  ToolCallContentMetadata: CCM = z.undefined() as CCM,\n  ToolResponseContentMetadata: RCM = z.undefined() as RCM,\n  ReasoningContentMetadata: TCCM = z.undefined() as TCCM\n) =>\n  z.discriminatedUnion(\"modality\", [\n    TextContent(TextContentMetadata),\n    ImageContent(ImageContentMetadata),\n    ToolCallContent(ToolCallContentMetadata),\n    ToolResponseContent(ToolResponseContentMetadata),\n    ReasoningContent(ReasoningContentMetadata),\n  ]);\ntype ContentType<\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  ICM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  RCM extends z.ZodTypeAny = z.ZodUndefined,\n> = z.infer<ReturnType<typeof Content<TCM, ICM, CCM, RCM>>>;\n\nconst PartialModalityLiterals = [PartialTextModalityLiteral, PartialToolCallModalityLiteral, PartialReasoningModalityLiteral] as const;\nconst PartialModalityEnum = z.enum(PartialModalityLiterals);\ntype PartialModalityEnumType = z.infer<typeof PartialModalityEnum>;\n\nconst PartialContent = <\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  RCM extends z.ZodTypeAny = z.ZodUndefined,\n>(\n  PartialTextContentMetadata: TCM = z.undefined() as TCM,\n  PartialToolCallContentMetadata: CCM = z.undefined() as CCM,\n  PartialReasoningContentMetadata: z.ZodTypeAny = z.undefined() as z.ZodTypeAny as RCM\n) =>\n  z.discriminatedUnion(\"modality\", [\n    PartialTextContent(PartialTextContentMetadata),\n    PartialToolCallContent(PartialToolCallContentMetadata),\n    PartialReasoningContent(PartialReasoningContentMetadata),\n  ]);\ntype PartialContentType<TCM extends z.ZodTypeAny = z.ZodUndefined, CCM extends z.ZodTypeAny = z.ZodUndefined> = z.infer<\n  ReturnType<typeof PartialContent<TCM, CCM>>\n>;\n\nexport {\n  Content,\n  ModalityEnum,\n  ModalityLiterals,\n  PartialContent,\n  PartialModalityEnum,\n  PartialModalityLiterals,\n  type ContentType,\n  type ModalityEnumType,\n  type PartialContentType,\n  type PartialModalityEnumType,\n};\n","import { z } from \"zod\";\n\nconst TokenModalityLiteral = \"token\" as const;\n\nconst TokenContent = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.object({\n    modality: z.literal(TokenModalityLiteral),\n    value: z.array(z.number().int().nonnegative()),\n    metadata: Metadata,\n  });\ntype TokenContentType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof TokenContent<M>>>;\n\nexport { TokenContent, TokenModalityLiteral, type TokenContentType };\n","import { z } from \"zod\";\n\nimport { Content, PartialContent } from \"./content\";\nimport { PartialRoleEnum, RoleEnum } from \"./roles\";\n\nconst Message = <\n  R extends z.ZodEnum<[string, ...string[]]> = typeof RoleEnum,\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  ICM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  RCM extends z.ZodTypeAny = z.ZodUndefined,\n  MM extends z.ZodTypeAny = z.ZodUndefined,\n  RTCM extends z.ZodTypeAny = z.ZodUndefined,\n>(\n  Role: R = RoleEnum as unknown as R,\n  TextContentMetadata: TCM = z.undefined() as TCM,\n  ImageContentMetadata: ICM = z.undefined() as ICM,\n  ToolCallContentMetadata: CCM = z.undefined() as CCM,\n  ToolResponseContentMetadata: RCM = z.undefined() as RCM,\n  MessageMetadata: MM = z.undefined() as MM,\n  ReasoningContentMetadata: z.ZodTypeAny = z.undefined() as RTCM\n) =>\n  z.object({\n    role: Role,\n    content: z.array(\n      Content(TextContentMetadata, ImageContentMetadata, ToolCallContentMetadata, ToolResponseContentMetadata, ReasoningContentMetadata)\n    ),\n    metadata: MessageMetadata,\n  });\ntype MessageType<\n  R extends z.ZodEnum<[string, ...string[]]> = typeof RoleEnum,\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  ICM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  RCM extends z.ZodTypeAny = z.ZodUndefined,\n  MM extends z.ZodTypeAny = z.ZodUndefined,\n  RTCM extends z.ZodTypeAny = z.ZodUndefined,\n> = z.infer<ReturnType<typeof Message<R, TCM, ICM, CCM, RCM, MM, RTCM>>>;\n\n// const PartialMessage = <\n//   R extends z.ZodEnum<[string, ...string[]]> = typeof PartialRoleEnum,\n//   TCM extends z.ZodTypeAny = z.ZodUndefined,\n//   CCM extends z.ZodTypeAny = z.ZodUndefined,\n//   MM extends z.ZodTypeAny = z.ZodUndefined,\n// >(\n//   Role: R = PartialRoleEnum as unknown as R,\n//   TextContentMetadata: TCM = z.undefined() as TCM,\n//   ToolCallContentMetadata: CCM = z.undefined() as CCM,\n//   MessageMetadata: MM = z.undefined() as MM,\n// ) => Message(\n//   Role,\n//   TextContentMetadata,\n//   undefined,\n//   ToolCallContentMetadata,\n//   undefined,\n//   MessageMetadata\n// ).omit({ content: true }).merge(z.object({\n//   partialContent: PartialContent(TextContentMetadata, ToolCallContentMetadata),\n// }));\nconst PartialMessage = <\n  R extends z.ZodEnum<[string, ...string[]]> = typeof PartialRoleEnum,\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  MM extends z.ZodTypeAny = z.ZodUndefined,\n  RTCM extends z.ZodTypeAny = z.ZodUndefined,\n>(\n  Role: R = PartialRoleEnum as unknown as R,\n  TextContentMetadata: TCM = z.undefined() as TCM,\n  ToolCallContentMetadata: CCM = z.undefined() as CCM,\n  ReasoningContentMetadata: z.ZodTypeAny = z.undefined() as RTCM,\n  MessageMetadata: MM = z.undefined() as MM\n) =>\n  z.object({\n    role: Role,\n    partialContent: PartialContent(TextContentMetadata, ToolCallContentMetadata, ReasoningContentMetadata),\n    metadata: MessageMetadata,\n  });\ntype PartialMessageType<\n  R extends z.ZodEnum<[string, ...string[]]> = typeof PartialRoleEnum,\n  TCM extends z.ZodTypeAny = z.ZodUndefined,\n  CCM extends z.ZodTypeAny = z.ZodUndefined,\n  MM extends z.ZodTypeAny = z.ZodUndefined,\n> = z.infer<ReturnType<typeof PartialMessage<R, TCM, CCM, MM>>>;\n\nexport { Message, PartialMessage, type MessageType, type PartialMessageType };\n","import { z } from \"zod\";\n\nimport { Message, PartialMessage } from \"./../message\";\n\nconst ChatUsage = z.object({\n  promptTokens: z.number().nonnegative(),\n  completionTokens: z.number().nonnegative(),\n  totalTokens: z.number().nonnegative(),\n});\ntype ChatUsageType = z.infer<typeof ChatUsage>;\n\nconst ChatBaseLogProb = z.object({\n  token: z.string(),\n  logProb: z.number(),\n  bytes: z.array(z.number().int()).nullable(),\n});\ntype ChatBaseLogProbType = z.infer<typeof ChatBaseLogProb>;\n\nconst ChatLogProb = ChatBaseLogProb.extend({\n  topLogProbs: z.array(ChatBaseLogProb),\n});\ntype ChatLogProbType = z.infer<typeof ChatLogProb>;\n\nconst ChatLogProbs = z.array(ChatLogProb);\ntype ChatLogProbsType = z.infer<typeof ChatLogProbs>;\n\nconst ChatResponse = z.object({\n  messages: z.array(Message()),\n  usage: ChatUsage.optional(),\n  logProbs: ChatLogProbs.optional(),\n});\ntype ChatResponseType = z.infer<typeof ChatResponse>;\n\nconst PartialChatUsage = z.object({\n  promptTokens: z.number().nonnegative().optional(),\n  completionTokens: z.number().nonnegative().optional(),\n  totalTokens: z.number().nonnegative().optional(),\n});\n\ntype PartialChatUsageType = z.infer<typeof PartialChatUsage>;\n\nconst PartialChatResponse = z.object({\n  partialMessages: z.array(PartialMessage()),\n  usage: PartialChatUsage.optional(),\n  logProbs: ChatLogProbs.optional(),\n});\ntype PartialChatResponseType = z.infer<typeof PartialChatResponse>;\n\nexport {\n  ChatBaseLogProb,\n  ChatLogProb,\n  ChatLogProbs,\n  ChatResponse,\n  ChatUsage,\n  PartialChatResponse,\n  PartialChatUsage,\n  type ChatBaseLogProbType,\n  type ChatLogProbsType,\n  type ChatLogProbType,\n  type ChatResponseType,\n  type ChatUsageType,\n  type PartialChatResponseType,\n  type PartialChatUsageType,\n};\n","import { z } from \"zod\";\n\nconst Config = <C extends z.ZodRecord<z.ZodString, z.ZodAny> = z.ZodRecord<z.ZodString, z.ZodAny>>(\n  Config: C = z.record(z.string(), z.any()).optional() as unknown as C\n) => Config;\ntype ConfigType<C extends z.ZodRecord<z.ZodString, z.ZodAny> = z.ZodRecord<z.ZodString, z.ZodAny>> = z.infer<ReturnType<typeof Config<C>>>;\n\nexport { Config, type ConfigType };\n","import { z } from \"zod\";\n\n// TODO: move to json schema 7 type and validator when implemented for tool types\nconst ResponseSchemaTypes = [\"object\", \"array\", \"number\", \"string\", \"boolean\", \"enum\"] as const;\nconst ResponseSchemaTypesLiteral = z.enum(ResponseSchemaTypes);\ntype ResponseSchemaTypesType = z.infer<typeof ResponseSchemaTypesLiteral>;\n\nconst ResponseSchemaProperty = z.object({\n  anyOf: z.array(z.any()).optional(),\n  type: z.union([ResponseSchemaTypesLiteral, z.array(z.union([ResponseSchemaTypesLiteral, z.literal(\"null\")]))]).optional(),\n  default: z.any().optional(),\n  title: z.string().optional(),\n  description: z.string().max(4096).optional(),\n  properties: z.record(z.any()).optional(),\n  required: z.array(z.string()).optional(),\n  minItems: z.number().int().min(0).optional(),\n  maxItems: z.number().int().optional(),\n  items: z.record(z.any()).optional(), // Recursive structure to handle nested arrays and objects\n  enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(), // Enum for allowed values\n  minimum: z.number().optional(), // Minimum value for number\n  maximum: z.number().optional(), // Maximum value for number\n  minLength: z.number().int().min(0).optional(), // Minimum length for string\n  maxLength: z.number().int().optional(), // Maximum length for string\n  $ref: z.string().optional(), // Reference to another schema\n});\ntype ResponseSchemaPropertyType = z.infer<typeof ResponseSchemaProperty>;\n\nconst ResponseSchemaStructure = z.object({\n  type: z.enum([\"object\"]),\n  required: z.array(z.string()),\n  $defs: z.record(z.any()).optional(),\n  properties: z.record(ResponseSchemaProperty),\n  additionalProperties: z.literal(false),\n});\ntype ResponseSchemaStructureType = z.infer<typeof ResponseSchemaStructure>;\n\nconst ResponseSchema = z\n  .object({\n    name: z\n      .string()\n      .regex(/^[a-zA-Z0-9_]{1,64}$/)\n      .max(64),\n    description: z.string().max(4096),\n    strict: z.boolean().optional(),\n    schema: ResponseSchemaStructure,\n  })\n  .optional();\ntype ResponseSchemaType = z.infer<typeof ResponseSchema>;\n\nexport {\n  ResponseSchema,\n  ResponseSchemaProperty,\n  ResponseSchemaStructure,\n  ResponseSchemaTypes,\n  ResponseSchemaTypesLiteral,\n  type ResponseSchemaTypesType,\n  type ResponseSchemaType,\n  type ResponseSchemaPropertyType,\n  type ResponseSchemaStructureType,\n};\n","import { z } from \"zod\";\n\nconst EmbeddingTextModalityLiteral = \"text\" as const;\nconst EmbeddingTokenModalityLiteral = \"token\" as const;\n\nconst EmbeddingModalityLiterals = [EmbeddingTextModalityLiteral, EmbeddingTokenModalityLiteral] as const;\nconst EmbeddingModalityEnum = z.enum(EmbeddingModalityLiterals);\ntype EmbeddingModalityEnumType = z.infer<typeof EmbeddingModalityEnum>;\n\nconst TextEmbeddingRequests = z.array(z.string().min(1));\ntype TextEmbeddingRequestsType = z.infer<typeof TextEmbeddingRequests>;\n\nconst TokenEmbeddingRequests = z.array(z.array(z.number().int().nonnegative()));\ntype TokenEmbeddingRequestsType = z.infer<typeof TokenEmbeddingRequests>;\n\nconst EmbeddingRequests = <M extends z.ZodTypeAny = z.ZodUndefined>(Metadata: M = z.undefined() as M) =>\n  z.discriminatedUnion(\"modality\", [\n    z.object({\n      modality: z.literal(EmbeddingTextModalityLiteral),\n      metadata: Metadata,\n      requests: TextEmbeddingRequests,\n    }),\n    z.object({\n      modality: z.literal(EmbeddingTokenModalityLiteral),\n      metadata: Metadata,\n      requests: TokenEmbeddingRequests,\n    }),\n  ]);\ntype EmbeddingRequestsType<M extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof EmbeddingRequests<M>>>;\n\nexport {\n  EmbeddingTextModalityLiteral,\n  EmbeddingTokenModalityLiteral,\n  EmbeddingModalityLiterals,\n  EmbeddingModalityEnum,\n  TextEmbeddingRequests,\n  TokenEmbeddingRequests,\n  EmbeddingRequests,\n  type EmbeddingRequestsType,\n  type EmbeddingModalityEnumType,\n  type TextEmbeddingRequestsType,\n  type TokenEmbeddingRequestsType,\n};\n","import { z } from \"zod\";\n\nconst FloatEmbeddingLiteral = \"float\" as const;\nconst FloatEmbedding = z.object({\n  index: z.number().int().nonnegative(),\n  embedding: z.array(z.number()),\n});\ntype FloatEmbeddingType = z.infer<typeof FloatEmbedding>;\n\nconst Base64EmbeddingLiteral = \"base64\" as const;\nconst Base64Embedding = z.object({\n  index: z.number().int().nonnegative(),\n  embedding: z.string().base64(),\n});\ntype Base64EmbeddingType = z.infer<typeof Base64Embedding>;\n\nconst EmbeddingsUsage = z.object({\n  totalTokens: z.number().int().nonnegative(),\n});\ntype EmbeddingsUsageType = z.infer<typeof EmbeddingsUsage>;\n\nconst EmbeddingResponse = z.discriminatedUnion(\"encodingFormat\", [\n  z.object({\n    encodingFormat: z.literal(FloatEmbeddingLiteral),\n    embeddings: z.array(FloatEmbedding),\n    usage: EmbeddingsUsage.optional(),\n  }),\n  z.object({\n    encodingFormat: z.literal(Base64EmbeddingLiteral),\n    embeddings: z.array(Base64Embedding),\n    usage: EmbeddingsUsage.optional(),\n  }),\n]);\ntype EmbeddingResponseType = z.infer<typeof EmbeddingResponse>;\n\nexport {\n  FloatEmbeddingLiteral,\n  Base64EmbeddingLiteral,\n  FloatEmbedding,\n  Base64Embedding,\n  EmbeddingsUsage,\n  EmbeddingResponse,\n  type FloatEmbeddingType,\n  type Base64EmbeddingType,\n  type EmbeddingsUsageType,\n  type EmbeddingResponseType,\n};\n","const safeStringify = (obj: unknown) => {\n  const seen = new WeakSet();\n  return JSON.stringify(obj, (key, value) => {\n    if (typeof value === \"object\" && value !== null) {\n      if (seen.has(value)) {\n        return; // Skip circular reference\n      }\n      seen.add(value);\n    }\n    return value;\n  });\n};\n\nconst getErrorMessage = (error: unknown | undefined): string => {\n  if (error == null) return \"unknown error\";\n  if (typeof error === \"string\") return error;\n  if (error instanceof Error) return error.message;\n  return safeStringify(error);\n};\n\nconst GatewayBaseErrorLiteral = \"GatewayBaseError\" as const;\nclass GatewayBaseError extends Error {\n  readonly name: string = GatewayBaseErrorLiteral;\n  readonly info: string;\n  readonly cause: unknown;\n\n  constructor({ info, cause }: { info: string; cause: unknown }, name?: string) {\n    super(`[${name ?? GatewayBaseErrorLiteral}]: ${info}\\nMessage: ${getErrorMessage(cause)}`);\n    this.info = info;\n    this.cause = cause;\n    this.name = name ?? GatewayBaseErrorLiteral;\n    Object.setPrototypeOf(this, new.target.prototype);\n  }\n\n  static isGatewayBaseError(error: unknown): error is GatewayBaseError {\n    return error instanceof GatewayBaseError;\n  }\n\n  toJSON(): object {\n    return {\n      name: this.name,\n      info: this.info,\n      cause: this.cause,\n      message: this.message,\n      stack: this.stack,\n    };\n  }\n}\n\nexport { GatewayBaseError };\n","import { z } from \"zod\";\n\n/**\n * A pair of per‑million‑token rates for a single price category (e.g., base input/output).\n * Represents the input and output cost for 1 million tokens within a specific category (like 'base') of a pricing tier.\n */\nconst ChatModelTokenPairPrice = z\n  .object({\n    inputPricePerMillion: z.number().nonnegative().describe(\"Price per 1M input tokens\"),\n    outputPricePerMillion: z.number().nonnegative().describe(\"Price per 1M output tokens\"),\n  })\n  .describe(\"Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier.\");\n\ntype ChatModelTokenPairPriceType = z.infer<typeof ChatModelTokenPairPrice>;\n\n/**\n * Defines the price categories (e.g., base) applicable within a single pricing tier (`ChatModelTokenRangePrice`).\n * Each category holds a `ChatModelTokenPairPrice`.\n */\nconst ChatModelTokenTypePrice = z\n  .object({\n    base: ChatModelTokenPairPrice.describe(\"Base (uncached, non‑reasoning) rates\"),\n    // Add optional 'cached' and 'reasoning' here if they become standard\n  })\n  .describe(\"Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier.\");\n\ntype ChatModelTokenTypePriceType = z.infer<typeof ChatModelTokenTypePrice>;\n\n/**\n * Defines a single tier in a model's pricing schedule (`ChatModelPrice`), based on token count range.\n * - `minTokens`: inclusive lower bound (integer ≥ 0).\n * - `maxTokens`: exclusive upper bound (integer > minTokens), or `null` for ∞.\n * - `prices`: the `ChatModelTokenTypePrice` (categories and their rates) applicable to this tier.\n */\nconst ChatModelTokenRangePrice = z\n  .object({\n    minTokens: z.number().int().nonnegative().describe(\"Inclusive lower token bound for this tier.\"),\n    maxTokens: z.number().int().nullable().optional().describe(\"Exclusive upper token bound; `null` means ∞.\"),\n    prices: ChatModelTokenTypePrice.describe(\"Price categories and rates for this specific token range.\"),\n  })\n  .refine((t) => t.maxTokens === null || (typeof t.maxTokens === \"number\" && t.maxTokens > t.minTokens), {\n    message: \"maxTokens must be > minTokens (or null for infinite).\",\n    path: [\"maxTokens\"],\n  })\n  .describe(\"A single pricing tier defined by a token range and associated prices.\");\n\ntype ChatModelTokenRangePriceType = z.infer<typeof ChatModelTokenRangePrice>;\n\n/**\n * Full pricing schedule for a specific chat model, potentially with multiple `ChatModelTokenRangePrice` tiers.\n * Ensures tiers are contiguous and cover the full range from 0 to infinity.\n * - First tier must start at 0 tokens.\n * - `tokenRanges` must be contiguous: each tier.minTokens === previous.maxTokens.\n * - Last `tokenRange` must have maxTokens = null (infinite).\n */\nconst ChatModelPrice = z\n  .object({\n    modelName: z.string().describe(\"Model name this schedule applies to.\"),\n    currency: z.string().default(\"USD\").describe(\"Currency code (e.g., USD).\"),\n    tokenRanges: z\n      .array(ChatModelTokenRangePrice)\n      .min(1)\n      .describe(\"Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.\"),\n  })\n  .superRefine((data, ctx) => {\n    const { tokenRanges } = data;\n\n    // 1) First tier starts at 0\n    if (tokenRanges[0].minTokens !== 0) {\n      ctx.addIssue({\n        code: z.ZodIssueCode.custom,\n        path: [\"tokenRanges\", 0, \"minTokens\"],\n        message: \"The first tier must have minTokens = 0.\",\n      });\n    }\n\n    // 2) tokenRanges must be sorted and contiguous\n    for (let i = 1; i < tokenRanges.length; i++) {\n      const prev = tokenRanges[i - 1];\n      const curr = tokenRanges[i];\n\n      if (prev.maxTokens === null) {\n        ctx.addIssue({\n          code: z.ZodIssueCode.custom,\n          path: [\"tokenRanges\", i - 1, \"maxTokens\"],\n          message: \"Cannot define any tokenRanges after an infinite tier (maxTokens = null).\",\n        });\n        break; // Stop further checks if structure is already invalid\n      }\n\n      if (curr.minTokens !== prev.maxTokens) {\n        ctx.addIssue({\n          code: z.ZodIssueCode.custom,\n          path: [\"tokenRanges\", i, \"minTokens\"],\n          message: `Tier ${i} minTokens (${curr.minTokens}) must equal previous tier's maxTokens (${prev.maxTokens}) for contiguity.`,\n        });\n      }\n\n      // Ensure sorting (although contiguity check often implies this)\n      if (curr.minTokens < prev.minTokens) {\n        ctx.addIssue({\n          code: z.ZodIssueCode.custom,\n          path: [\"tokenRanges\", i, \"minTokens\"],\n          message: `tokenRanges must be sorted by ascending minTokens. Tier ${i} (${curr.minTokens}) starts before Tier ${i - 1} (${prev.minTokens}).`,\n        });\n      }\n    }\n\n    // 3) Last tier must be infinite\n    const last = tokenRanges[tokenRanges.length - 1];\n    // Check last.maxTokens only if the loop didn't break early due to a previous infinite tier\n    if (tokenRanges.every((t) => t.maxTokens !== null || t === last) && last.maxTokens !== null) {\n      ctx.addIssue({\n        code: z.ZodIssueCode.custom,\n        path: [\"tokenRanges\", tokenRanges.length - 1, \"maxTokens\"],\n        message: \"The final tier must have maxTokens = null (representing infinity).\",\n      });\n    }\n  })\n  .describe(\"Complete pricing schedule for a single chat model, including all its token-based tiers.\");\n\ntype ChatModelPriceType = z.infer<typeof ChatModelPrice>;\n\n// Export the schemas and types\nexport { ChatModelPrice, ChatModelTokenPairPrice, ChatModelTokenRangePrice, ChatModelTokenTypePrice };\nexport type { ChatModelPriceType, ChatModelTokenPairPriceType, ChatModelTokenRangePriceType, ChatModelTokenTypePriceType };\n","// import { JSONSchema7 } from \"json-schema\";\n// import { Validator } from \"jsonschema\";\nimport { z } from \"zod\";\n\nconst FunctionToolLiteral = \"function\" as const;\n\n// TODO: fix 'name' property not allowed in JSONSchema7\n// const FunctionTool = z.object({\n//   type: z.literal(FunctionToolLiteral),\n//   definition: z.object({\n//     schema: z.object({}).refine((schema) => {\n//       const validator = new Validator();\n//       return validator.validate(schema, { type: \"object\" }).valid;\n//     }),\n//   }),\n//   callback: z.function().args(z.string().min(0)).returns(z.promise(z.any())).optional(),\n// });\n\n// const FunctionTool = z.object({\n//   type: z.literal(FunctionToolLiteral),\n//   definition: z.object({\n//     schema: z.object({}),\n//   }),\n//   callback: z.function().args(z.string().min(0)).returns(z.promise(z.any())).optional(),\n// });\n// type FunctionToolType = z.infer<typeof FunctionTool>;\n\nconst FunctionParameterTypes = [\"object\", \"array\", \"number\", \"string\", \"boolean\", \"null\"];\nconst FunctionParameterTypesLiteral = z.enum([\"object\", \"array\", \"number\", \"string\", \"boolean\", \"null\"]);\ntype FunctionParameterTypesType = z.infer<typeof FunctionParameterTypesLiteral>;\n\n// TODO: make a proper fix here\nconst FunctionParameter = z.object({\n  anyOf: z.array(z.any()).optional(),\n  type: FunctionParameterTypesLiteral.optional(),\n  default: z.any().optional(),\n  title: z.string().optional(),\n  description: z.string().max(4096).optional(),\n  properties: z.record(z.any()).optional(),\n  required: z.array(z.string()).optional(),\n  minItems: z.number().int().min(0).optional(),\n  maxItems: z.number().int().optional(),\n  items: z.record(z.any()).optional(), // Recursive structure to handle nested arrays and objects\n  enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(), // Enum for allowed values\n  minimum: z.number().optional(), // Minimum value for number\n  maximum: z.number().optional(), // Maximum value for number\n  minLength: z.number().int().min(0).optional(), // Minimum length for string\n  maxLength: z.number().int().optional(), // Maximum length for string\n});\ntype FunctionParameterType = z.infer<typeof FunctionParameter>;\n\nconst FunctionParameters = z.object({\n  type: z.enum([\"object\"]),\n  title: z.string().optional(),\n  $defs: z.record(z.any()).optional(),\n  properties: z.record(FunctionParameter).optional(),\n  required: z.array(z.string()).optional(),\n});\ntype FunctionParametersType = z.infer<typeof FunctionParameters>;\n\nconst Function = z.object({\n  name: z\n    .string()\n    .regex(/^[a-zA-Z0-9_]{1,64}$/)\n    .max(64),\n  description: z.string().max(4096),\n  parameters: z.any(),\n  strict: z.boolean().optional(),\n});\ntype FunctionType = z.infer<typeof Function>;\n\nconst ToolTypes = [\"function\"];\nconst ToolTypesLiteral = z.enum([\"function\"]);\ntype ToolTypesType = z.infer<typeof ToolTypesLiteral>;\n\nconst FunctionTool = z.object({\n  type: ToolTypesLiteral,\n  definition: z.object({\n    schema: Function, // TODO: convert to union with more tool types\n  }),\n});\ntype FunctionToolType = z.infer<typeof FunctionTool>;\n\n// const Tools = z.array(Tool).nonempty().optional();\n// type ToolsType = z.infer<typeof Tools>;\n\nexport {\n  Function,\n  FunctionParameter,\n  FunctionParameters,\n  FunctionParameterTypes,\n  FunctionParameterTypesLiteral,\n  ToolTypes,\n  ToolTypesLiteral,\n  type FunctionParametersType,\n  type FunctionParameterType,\n  type FunctionParameterTypesType,\n  type FunctionType,\n  type ToolTypesType,\n};\n\nexport { FunctionTool, FunctionToolLiteral, type FunctionToolType };\n","import { z } from \"zod\";\n\nimport { FunctionTool, FunctionToolLiteral } from \"./function-tool\";\n\nconst ToolLiterals = [FunctionToolLiteral] as const;\nconst ToolEnum = z.enum(ToolLiterals);\ntype ToolEnumType = z.infer<typeof ToolEnum>;\n\nconst Tool = <FTM extends z.ZodTypeAny>(FunctionToolMetadata: FTM = z.undefined() as FTM) =>\n  z.discriminatedUnion(\"type\", [FunctionTool.extend({ metadata: FunctionToolMetadata })]);\ntype ToolType<FTM extends z.ZodTypeAny = z.ZodUndefined> = z.infer<ReturnType<typeof Tool<FTM>>>;\n\nexport { Tool, ToolEnum, ToolLiterals, type ToolEnumType, type ToolType };\n","import {\n  Base64ImageContentTypeLiteral,\n  ContentType,\n  ImageContent,\n  ImageContentDetailsLiteralType,\n  ImageModalityLiteral,\n  Message,\n  MessageType,\n  PartialMessage,\n  PartialMessageType,\n  PartialReasoningContent,\n  PartialReasoningModalityLiteral,\n  PartialTextContent,\n  PartialTextModalityLiteral,\n  PartialToolCallContent,\n  PartialToolCallModalityLiteral,\n  ReasoningContent,\n  ReasoningContentTypeLiteral,\n  ReasoningModalityLiteral,\n  RedactedReasoningContentTypeLiteral,\n  RoleEnumType,\n  TextContent,\n  TextModalityLiteral,\n  ToolCallContent,\n  ToolCallModalityLiteral,\n  ToolResponseContent,\n  ToolResponseModalityLiteral,\n  UrlImageContentTypeLiteral,\n} from \"./../message\";\n\nconst createTextContent = (content: string): ContentType => {\n  return TextContent().parse({\n    modality: TextModalityLiteral,\n    value: content,\n  });\n};\n\nconst createToolCallContent = (index: number, id: string, name: string, args: string): ContentType => {\n  return ToolCallContent().parse({\n    modality: ToolCallModalityLiteral,\n    index: index,\n    id: id,\n    name: name,\n    arguments: args,\n  });\n};\n\nconst createTextMessage = (role: RoleEnumType, content: string): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      TextContent().parse({\n        modality: TextModalityLiteral,\n        value: content,\n      }),\n    ],\n  });\n};\n\nconst createUrlImageMessage = (role: RoleEnumType, url: string, detail: ImageContentDetailsLiteralType): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ImageContent().parse({\n        modality: ImageModalityLiteral,\n        detail: detail,\n        value: {\n          type: UrlImageContentTypeLiteral,\n          url: url,\n        },\n      }),\n    ],\n  });\n};\n\nconst createBase64ImageMessage = (role: RoleEnumType, base64: string, detail: ImageContentDetailsLiteralType): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ImageContent().parse({\n        modality: ImageModalityLiteral,\n        detail: detail,\n        value: {\n          type: Base64ImageContentTypeLiteral,\n          base64: base64,\n        },\n      }),\n    ],\n  });\n};\n\nconst createToolCallMessage = (role: RoleEnumType, index: number, id: string, name: string, args: string): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ToolCallContent().parse({\n        modality: ToolCallModalityLiteral,\n        index: index,\n        id: id,\n        name: name,\n        arguments: args,\n      }),\n    ],\n  });\n};\n\nconst createToolResponseMessage = (role: RoleEnumType, index: number, id: string, name: string, data: string): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ToolResponseContent().parse({\n        modality: ToolResponseModalityLiteral,\n        index: index,\n        id: id,\n        name: name,\n        data: data,\n      }),\n    ],\n  });\n};\n\nconst createPartialTextMessage = (role: RoleEnumType, content: string): PartialMessageType => {\n  return PartialMessage().parse({\n    role: role,\n    partialContent: PartialTextContent().parse({\n      modality: PartialTextModalityLiteral,\n      value: content,\n    }),\n  });\n};\n\nconst createPartialToolCallMessage = (role: RoleEnumType, index: number, id?: string, name?: string, args?: string): PartialMessageType => {\n  return PartialMessage().parse({\n    role: role,\n    partialContent: PartialToolCallContent().parse({\n      modality: PartialToolCallModalityLiteral,\n      index: index,\n      id: id,\n      name: name,\n      arguments: args,\n    }),\n  });\n};\n\nconst createReasoningContent = (thinking: string, signature: string): ContentType => {\n  return ReasoningContent().parse({\n    modality: ReasoningModalityLiteral,\n    value: {\n      type: ReasoningContentTypeLiteral,\n      thinking,\n      signature,\n    },\n  });\n};\n\nconst createReasoningMessage = (role: RoleEnumType, thinking: string, signature: string): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ReasoningContent().parse({\n        modality: ReasoningModalityLiteral,\n        value: {\n          type: ReasoningContentTypeLiteral,\n          thinking,\n          signature,\n        },\n      }),\n    ],\n  });\n};\n// Redacted Reasoning Content\nconst createRedactedReasoningContent = (data: string): ContentType => {\n  return ReasoningContent().parse({\n    modality: ReasoningModalityLiteral,\n    value: {\n      type: RedactedReasoningContentTypeLiteral,\n      data,\n    },\n  });\n};\n\nconst createRedactedReasoningMessage = (role: RoleEnumType, data: string): MessageType => {\n  return Message().parse({\n    role: role,\n    content: [\n      ReasoningContent().parse({\n        modality: ReasoningModalityLiteral,\n        value: {\n          type: RedactedReasoningContentTypeLiteral,\n          data,\n        },\n      }),\n    ],\n  });\n};\n\nconst createPartialReasoningMessage = (role: RoleEnumType, thinking?: string, signature?: string): PartialMessageType => {\n  return PartialMessage().parse({\n    role: role,\n    partialContent: PartialReasoningContent().parse({\n      modality: PartialReasoningModalityLiteral,\n      value: {\n        type: ReasoningContentTypeLiteral,\n        thinking,\n        signature,\n      },\n      // metadata is optional; omit or provide if needed\n    }),\n  });\n};\n\n// Create a partial redacted reasoning message\nconst createPartialRedactedReasoningMessage = (role: RoleEnumType, data: string): PartialMessageType => {\n  return PartialMessage().parse({\n    role: role,\n    partialContent: PartialReasoningContent().parse({\n      modality: PartialReasoningModalityLiteral,\n      value: {\n        type: RedactedReasoningContentTypeLiteral,\n        data,\n      },\n      // metadata is optional; omit or provide if needed\n    }),\n  });\n};\n\nexport {\n  createBase64ImageMessage,\n  createPartialReasoningMessage,\n  createPartialRedactedReasoningMessage,\n  createPartialTextMessage,\n  createPartialToolCallMessage,\n  createReasoningContent,\n  createReasoningMessage,\n  createRedactedReasoningContent,\n  createRedactedReasoningMessage,\n  createTextContent,\n  createTextMessage,\n  createToolCallContent,\n  createToolCallMessage,\n  createToolResponseMessage,\n  createUrlImageMessage,\n};\n","import { GatewayBaseError } from \"../errors/gateway-base.error\";\nimport { ChatResponseType, ChatUsageType, PartialChatResponseType } from \"./../chat/chat-response\";\nimport {\n  AssistantRoleLiteral,\n  ContentType,\n  MessageType,\n  PartialContentType,\n  PartialReasoningContentType,\n  PartialReasoningModalityLiteral,\n  PartialTextContentType,\n  PartialTextModalityLiteral,\n  PartialToolCallContentType,\n  PartialToolCallModalityLiteral,\n  ReasoningContentTypeLiteral,\n  ReasoningContentValueUnionType,\n  ReasoningModalityLiteral,\n  RedactedReasoningContentTypeLiteral,\n  TextModalityLiteral,\n  ToolCallModalityLiteral,\n} from \"./../message\";\n\nconst mergePartialMessages = (response: PartialChatResponseType[]): ChatResponseType => {\n  let finalizedResponse: ChatResponseType = { messages: [] };\n\n  if (!response || response.length === 0) {\n    return finalizedResponse;\n  }\n  const mergedContents: ContentType[] = [];\n\n  // Accumulators for the content *currently being streamed*\n  let lastModality: PartialContentType[\"modality\"] | null = null;\n  let lastReasoningType: ReasoningContentValueUnionType[\"type\"] | null = null; // Track 'thinking' vs 'redacted'\n  let lastToolCallIndex: number | undefined = undefined;\n\n  let currentTextValue: string | null = null;\n  let currentToolCall: { index?: number; id: string; name: string; arguments: string } | null = null;\n  let currentReasoning: PartialReasoningContentType[\"value\"] | null = null; // Store the partial value directly\n\n  // --- Helper Function to Finalize and Add the previous block ---\n  const finalizePreviousBlock = () => {\n    let finalizedContent: ContentType | null = null;\n\n    if (lastModality === PartialTextModalityLiteral && currentTextValue !== null) {\n      finalizedContent = {\n        modality: TextModalityLiteral,\n        value: currentTextValue,\n      };\n    } else if (lastModality === PartialToolCallModalityLiteral && currentToolCall) {\n      // Ensure required fields are present for the final ToolCall\n      if (currentToolCall.id && currentToolCall.name && currentToolCall.arguments !== undefined && currentToolCall.index) {\n        finalizedContent = {\n          modality: ToolCallModalityLiteral,\n          index: currentToolCall.index,\n          id: currentToolCall.id,\n          name: currentToolCall.name,\n          arguments: currentToolCall.arguments,\n        };\n      } else {\n        throw new GatewayBaseError({\n          info: \"Incomplete tool call data encountered during finalization. Required fields (id, name, arguments, index) were missing or incomplete.\",\n          cause: { currentToolCall },\n        });\n      }\n    } else if (lastModality === PartialReasoningModalityLiteral && currentReasoning) {\n      if (currentReasoning.type === ReasoningContentTypeLiteral) {\n        if (currentReasoning.thinking !== undefined && currentReasoning.signature !== undefined) {\n          finalizedContent = {\n            modality: ReasoningModalityLiteral,\n            value: {\n              type: ReasoningContentTypeLiteral,\n              thinking: currentReasoning.thinking,\n              signature: currentReasoning.signature,\n            },\n          };\n        } else {\n          throw new GatewayBaseError({\n            info: \"Incomplete 'thinking' reasoning data encountered during finalization. Required fields (thinking, signature) were missing or incomplete.\",\n            cause: { currentReasoning },\n          });\n        }\n      } else if (currentReasoning.type === RedactedReasoningContentTypeLiteral) {\n        if (currentReasoning.data !== undefined) {\n          finalizedContent = {\n            modality: ReasoningModalityLiteral,\n            value: {\n              type: RedactedReasoningContentTypeLiteral,\n              data: currentReasoning.data,\n            },\n          };\n        } else {\n          throw new GatewayBaseError({\n            info: \"Incomplete 'redacted' reasoning data encountered during finalization. Required field (data) was missing or incomplete.\",\n            cause: { currentReasoning },\n          });\n        }\n      }\n    }\n\n    // If content was successfully finalized, add it as a separate message\n    if (finalizedContent) {\n      mergedContents.push(finalizedContent);\n    }\n\n    // Reset accumulators for the *next* block\n    currentTextValue = null;\n    currentToolCall = null;\n    currentReasoning = null;\n    lastModality = null; // Reset modality marker\n    lastReasoningType = null; // Reset reasoning type marker\n    lastToolCallIndex = undefined; // Reset tool call index marker\n  };\n\n  // --- Main Processing Loop ---\n  response.forEach((chatChunk, chunkIndex) => {\n    if (!chatChunk.partialMessages) return;\n\n    chatChunk.partialMessages.forEach((message, messageIndex) => {\n      if (message.role !== AssistantRoleLiteral) {\n        throw new GatewayBaseError({\n          info: `Unexpected message role encountered while merging partial messages. Expected '${AssistantRoleLiteral}'.`,\n          cause: { role: message.role, chunkIndex, messageIndex, message },\n        });\n      }\n\n      const currentContent = message.partialContent;\n      const currentModality = currentContent.modality;\n      let currentReasoningType: ReasoningContentValueUnionType[\"type\"] | null = null;\n      let currentToolCallIndex: number | undefined = undefined;\n\n      if (currentModality === PartialReasoningModalityLiteral) {\n        currentReasoningType = (currentContent as PartialReasoningContentType).value.type;\n      }\n      if (currentModality === PartialToolCallModalityLiteral) {\n        currentToolCallIndex = (currentContent as PartialToolCallContentType).index;\n      }\n\n      // --- Check for Block Change ---\n      // A new block starts if:\n      // 1. Modality changes.\n      // 2. Modality is Reasoning, and the *type* of reasoning changes.\n      // 3. Modality is ToolCall, and the *index* changes.\n      const modalityChanged = currentModality !== lastModality;\n      const reasoningTypeChanged =\n        currentModality === PartialReasoningModalityLiteral &&\n        lastModality === PartialReasoningModalityLiteral &&\n        currentReasoningType !== lastReasoningType;\n      const toolCallIndexChanged =\n        currentModality === PartialToolCallModalityLiteral &&\n        lastModality === PartialToolCallModalityLiteral &&\n        currentToolCallIndex !== lastToolCallIndex;\n\n      // If a boundary is detected and we were accumulating something, finalize the previous block.\n      if ((modalityChanged || reasoningTypeChanged || toolCallIndexChanged) && lastModality !== null) {\n        finalizePreviousBlock();\n      }\n\n      // --- Update State & Accumulate Current Part ---\n      // Set the markers for the block *now* being processed\n      if (lastModality === null) {\n        // Only set if we just finalized or it's the first part\n        lastModality = currentModality;\n        if (currentModality === PartialReasoningModalityLiteral) {\n          lastReasoningType = currentReasoningType;\n        }\n        if (currentModality === PartialToolCallModalityLiteral) {\n          lastToolCallIndex = currentToolCallIndex;\n        }\n      }\n\n      // Accumulate based on current modality\n      if (currentModality === PartialTextModalityLiteral) {\n        const textPart = currentContent as PartialTextContentType;\n        currentTextValue = (currentTextValue ?? \"\") + (textPart.value ?? \"\");\n      } else if (currentModality === PartialToolCallModalityLiteral) {\n        const toolCallPart = currentContent as PartialToolCallContentType;\n        if (!currentToolCall) {\n          // Initialize if starting a new tool call block\n          currentToolCall = {\n            index: toolCallPart.index,\n            id: toolCallPart.id ?? \"\",\n            name: toolCallPart.name ?? \"\",\n            arguments: toolCallPart.arguments ?? \"\",\n          };\n        } else {\n          // Append to existing tool call block (same index)\n          currentToolCall.id += toolCallPart.id || \"\";\n          currentToolCall.name += toolCallPart.name || \"\";\n          currentToolCall.arguments += toolCallPart.arguments || \"\";\n        }\n      } else if (currentModality === PartialReasoningModalityLiteral) {\n        const reasoningPart = currentContent as PartialReasoningContentType;\n        const valuePart = reasoningPart.value;\n\n        if (!currentReasoning) {\n          // Initialize if starting a new reasoning block\n          if (valuePart.type === ReasoningContentTypeLiteral) {\n            currentReasoning = {\n              type: ReasoningContentTypeLiteral,\n              thinking: valuePart.thinking ?? \"\",\n              signature: valuePart.signature ?? \"\",\n            };\n          } else if (valuePart.type === RedactedReasoningContentTypeLiteral) {\n            currentReasoning = {\n              type: RedactedReasoningContentTypeLiteral,\n              data: valuePart.data ?? \"\",\n            };\n          } else {\n            throw new GatewayBaseError({\n              info: `Unknown reasoning type encountered during initialization. Expected '${ReasoningContentTypeLiteral}' or '${RedactedReasoningContentTypeLiteral}'.`,\n              cause: { valuePart, chunkIndex, messageIndex },\n            });\n          }\n        } else {\n          // For redacted reasoning, do not accumulate subsequent parts;\n          // finalize the existing block and start a new one.\n          if (currentReasoning.type === RedactedReasoningContentTypeLiteral && valuePart.type === RedactedReasoningContentTypeLiteral) {\n            finalizePreviousBlock();\n            // Start a new redacted reasoning block immediately\n            currentReasoning = {\n              type: RedactedReasoningContentTypeLiteral,\n              data: valuePart.data ?? \"\",\n            };\n            // Since we finalized, update the state markers accordingly\n            lastModality = currentModality;\n            lastReasoningType = valuePart.type;\n          } else if (currentReasoning.type === ReasoningContentTypeLiteral && valuePart.type === ReasoningContentTypeLiteral) {\n            // Accumulate for \"thinking\" type reasoning normally\n            currentReasoning.thinking = (currentReasoning.thinking ?? \"\") + (valuePart.thinking ?? \"\");\n            currentReasoning.signature = (currentReasoning.signature ?? \"\") + (valuePart.signature ?? \"\");\n          } else {\n            throw new GatewayBaseError({\n              info: \"Logic error: Mismatched reasoning types during accumulation.\",\n              cause: { currentReasoning, valuePart, chunkIndex, messageIndex },\n            });\n          }\n        }\n      }\n    });\n  });\n\n  // Finalize any remaining accumulated content after the loops finish\n  finalizePreviousBlock();\n\n  finalizedResponse.messages = [\n    {\n      role: AssistantRoleLiteral,\n      content: mergedContents,\n    },\n  ] as MessageType[];\n\n  // Usage\n  // Initialize accumulators\n  let firstPrompt: number | undefined;\n  let lastPrompt: number | undefined;\n  let totalCompletion = 0;\n  let usageFound = false;\n\n  const aggregatedUsage: ChatUsageType = {\n    promptTokens: 0,\n    completionTokens: 0,\n    totalTokens: 0,\n  };\n\n  for (const chunk of response) {\n    const u = chunk.usage;\n    if (!u) continue;\n\n    usageFound = true;\n\n    // Track first & last promptTokens\n    if (u.promptTokens != null) {\n      if (firstPrompt === undefined) {\n        firstPrompt = u.promptTokens;\n      }\n      lastPrompt = u.promptTokens;\n    }\n\n    // Sum completionTokens\n    if (u.completionTokens != null) {\n      totalCompletion += u.completionTokens;\n    }\n  }\n\n  if (usageFound) {\n    // Use the latest promptTokens if we saw one, otherwise the first\n    aggregatedUsage.promptTokens = lastPrompt ?? firstPrompt ?? 0;\n    aggregatedUsage.completionTokens = totalCompletion;\n    aggregatedUsage.totalTokens = aggregatedUsage.promptTokens + aggregatedUsage.completionTokens;\n\n    finalizedResponse.usage = aggregatedUsage;\n  } else {\n    finalizedResponse.usage = undefined;\n  }\n  return finalizedResponse;\n};\n\nexport { mergePartialMessages };\n"]}