@meetkai/mka1 0.54.7 → 0.54.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/bin/mcp-server.js +492 -368
  2. package/bin/mcp-server.js.map +35 -32
  3. package/dist/commonjs/hooks/multipartFilename.d.ts +12 -0
  4. package/dist/commonjs/hooks/multipartFilename.d.ts.map +1 -0
  5. package/dist/commonjs/hooks/multipartFilename.js +50 -0
  6. package/dist/commonjs/hooks/multipartFilename.js.map +1 -0
  7. package/dist/commonjs/hooks/registration.d.ts.map +1 -1
  8. package/dist/commonjs/hooks/registration.js +2 -1
  9. package/dist/commonjs/hooks/registration.js.map +1 -1
  10. package/dist/commonjs/lib/config.d.ts +2 -2
  11. package/dist/commonjs/lib/config.js +2 -2
  12. package/dist/commonjs/mcp-server/mcp-server.js +1 -1
  13. package/dist/commonjs/mcp-server/server.js +1 -1
  14. package/dist/commonjs/models/components/agentschedulespec.d.ts +2 -1
  15. package/dist/commonjs/models/components/agentschedulespec.d.ts.map +1 -1
  16. package/dist/commonjs/models/components/agentschedulespec.js +6 -5
  17. package/dist/commonjs/models/components/agentschedulespec.js.map +1 -1
  18. package/dist/commonjs/models/components/chunkingstrategy.d.ts +2 -1
  19. package/dist/commonjs/models/components/chunkingstrategy.d.ts.map +1 -1
  20. package/dist/commonjs/models/components/chunkingstrategy.js +6 -5
  21. package/dist/commonjs/models/components/chunkingstrategy.js.map +1 -1
  22. package/dist/commonjs/models/components/codeinterpreteroutput.d.ts +2 -1
  23. package/dist/commonjs/models/components/codeinterpreteroutput.d.ts.map +1 -1
  24. package/dist/commonjs/models/components/codeinterpreteroutput.js +5 -4
  25. package/dist/commonjs/models/components/codeinterpreteroutput.js.map +1 -1
  26. package/dist/commonjs/models/components/computeraction.d.ts +2 -1
  27. package/dist/commonjs/models/components/computeraction.d.ts.map +1 -1
  28. package/dist/commonjs/models/components/computeraction.js +12 -11
  29. package/dist/commonjs/models/components/computeraction.js.map +1 -1
  30. package/dist/commonjs/models/components/customtoolformat.d.ts +2 -1
  31. package/dist/commonjs/models/components/customtoolformat.d.ts.map +1 -1
  32. package/dist/commonjs/models/components/customtoolformat.js +5 -1
  33. package/dist/commonjs/models/components/customtoolformat.js.map +1 -1
  34. package/dist/commonjs/models/components/filesearchcompoundfilter.d.ts +3 -2
  35. package/dist/commonjs/models/components/filesearchcompoundfilter.d.ts.map +1 -1
  36. package/dist/commonjs/models/components/filesearchcompoundfilter.js +21 -20
  37. package/dist/commonjs/models/components/filesearchcompoundfilter.js.map +1 -1
  38. package/dist/commonjs/models/components/guardrailconfig.d.ts +2 -1
  39. package/dist/commonjs/models/components/guardrailconfig.d.ts.map +1 -1
  40. package/dist/commonjs/models/components/guardrailconfig.js +6 -5
  41. package/dist/commonjs/models/components/guardrailconfig.js.map +1 -1
  42. package/dist/commonjs/models/components/method.d.ts +6 -5
  43. package/dist/commonjs/models/components/method.d.ts.map +1 -1
  44. package/dist/commonjs/models/components/method.js +36 -35
  45. package/dist/commonjs/models/components/method.js.map +1 -1
  46. package/dist/commonjs/models/components/openaichatcompletionchoice.d.ts +4 -3
  47. package/dist/commonjs/models/components/openaichatcompletionchoice.d.ts.map +1 -1
  48. package/dist/commonjs/models/components/openaichatcompletionchoice.js +19 -18
  49. package/dist/commonjs/models/components/openaichatcompletionchoice.js.map +1 -1
  50. package/dist/commonjs/models/components/openaichatcompletionchunk.d.ts +4 -3
  51. package/dist/commonjs/models/components/openaichatcompletionchunk.d.ts.map +1 -1
  52. package/dist/commonjs/models/components/openaichatcompletionchunk.js +19 -18
  53. package/dist/commonjs/models/components/openaichatcompletionchunk.js.map +1 -1
  54. package/dist/commonjs/models/components/outputmessage.d.ts +3 -2
  55. package/dist/commonjs/models/components/outputmessage.d.ts.map +1 -1
  56. package/dist/commonjs/models/components/outputmessage.js +9 -8
  57. package/dist/commonjs/models/components/outputmessage.js.map +1 -1
  58. package/dist/commonjs/models/components/outputmessagewithid.d.ts +3 -2
  59. package/dist/commonjs/models/components/outputmessagewithid.d.ts.map +1 -1
  60. package/dist/commonjs/models/components/outputmessagewithid.js +9 -8
  61. package/dist/commonjs/models/components/outputmessagewithid.js.map +1 -1
  62. package/dist/commonjs/models/components/outputtext.d.ts +3 -2
  63. package/dist/commonjs/models/components/outputtext.d.ts.map +1 -1
  64. package/dist/commonjs/models/components/outputtext.js +13 -12
  65. package/dist/commonjs/models/components/outputtext.js.map +1 -1
  66. package/dist/commonjs/models/components/responsecontentpartaddedevent.d.ts +3 -2
  67. package/dist/commonjs/models/components/responsecontentpartaddedevent.d.ts.map +1 -1
  68. package/dist/commonjs/models/components/responsecontentpartaddedevent.js +11 -11
  69. package/dist/commonjs/models/components/responsecontentpartaddedevent.js.map +1 -1
  70. package/dist/commonjs/models/components/responsecontentpartdoneevent.d.ts +3 -2
  71. package/dist/commonjs/models/components/responsecontentpartdoneevent.d.ts.map +1 -1
  72. package/dist/commonjs/models/components/responsecontentpartdoneevent.js +11 -10
  73. package/dist/commonjs/models/components/responsecontentpartdoneevent.js.map +1 -1
  74. package/dist/commonjs/models/components/responseformat.d.ts +2 -1
  75. package/dist/commonjs/models/components/responseformat.d.ts.map +1 -1
  76. package/dist/commonjs/models/components/responseformat.js +6 -5
  77. package/dist/commonjs/models/components/responseformat.js.map +1 -1
  78. package/dist/commonjs/models/components/responseobject.d.ts +5 -4
  79. package/dist/commonjs/models/components/responseobject.d.ts.map +1 -1
  80. package/dist/commonjs/models/components/responseobject.js +41 -40
  81. package/dist/commonjs/models/components/responseobject.js.map +1 -1
  82. package/dist/commonjs/models/components/responsestreamingevent.d.ts +2 -1
  83. package/dist/commonjs/models/components/responsestreamingevent.d.ts.map +1 -1
  84. package/dist/commonjs/models/components/responsestreamingevent.js +68 -67
  85. package/dist/commonjs/models/components/responsestreamingevent.js.map +1 -1
  86. package/dist/commonjs/models/components/shellenvironment.d.ts +2 -1
  87. package/dist/commonjs/models/components/shellenvironment.d.ts.map +1 -1
  88. package/dist/commonjs/models/components/shellenvironment.js +5 -4
  89. package/dist/commonjs/models/components/shellenvironment.js.map +1 -1
  90. package/dist/commonjs/models/components/skillentry.d.ts +2 -1
  91. package/dist/commonjs/models/components/skillentry.d.ts.map +1 -1
  92. package/dist/commonjs/models/components/skillentry.js +5 -4
  93. package/dist/commonjs/models/components/skillentry.js.map +1 -1
  94. package/dist/commonjs/models/components/tooldefinition.d.ts +5 -4
  95. package/dist/commonjs/models/components/tooldefinition.d.ts.map +1 -1
  96. package/dist/commonjs/models/components/tooldefinition.js +29 -28
  97. package/dist/commonjs/models/components/tooldefinition.js.map +1 -1
  98. package/dist/commonjs/models/components/websearchaction.d.ts +2 -1
  99. package/dist/commonjs/models/components/websearchaction.d.ts.map +1 -1
  100. package/dist/commonjs/models/components/websearchaction.js +6 -5
  101. package/dist/commonjs/models/components/websearchaction.js.map +1 -1
  102. package/dist/commonjs/models/operations/createchatcompletionstream.d.ts +2 -1
  103. package/dist/commonjs/models/operations/createchatcompletionstream.d.ts.map +1 -1
  104. package/dist/commonjs/models/operations/createchatcompletionstream.js +6 -5
  105. package/dist/commonjs/models/operations/createchatcompletionstream.js.map +1 -1
  106. package/dist/commonjs/models/operations/uploadfile.d.ts +1 -1
  107. package/dist/commonjs/types/discriminatedUnion.d.ts +25 -0
  108. package/dist/commonjs/types/discriminatedUnion.d.ts.map +1 -0
  109. package/dist/commonjs/types/discriminatedUnion.js +94 -0
  110. package/dist/commonjs/types/discriminatedUnion.js.map +1 -0
  111. package/dist/esm/hooks/multipartFilename.d.ts +12 -0
  112. package/dist/esm/hooks/multipartFilename.d.ts.map +1 -0
  113. package/dist/esm/hooks/multipartFilename.js +46 -0
  114. package/dist/esm/hooks/multipartFilename.js.map +1 -0
  115. package/dist/esm/hooks/registration.d.ts.map +1 -1
  116. package/dist/esm/hooks/registration.js +2 -1
  117. package/dist/esm/hooks/registration.js.map +1 -1
  118. package/dist/esm/lib/config.d.ts +2 -2
  119. package/dist/esm/lib/config.js +2 -2
  120. package/dist/esm/mcp-server/mcp-server.js +1 -1
  121. package/dist/esm/mcp-server/server.js +1 -1
  122. package/dist/esm/models/components/agentschedulespec.d.ts +2 -1
  123. package/dist/esm/models/components/agentschedulespec.d.ts.map +1 -1
  124. package/dist/esm/models/components/agentschedulespec.js +6 -5
  125. package/dist/esm/models/components/agentschedulespec.js.map +1 -1
  126. package/dist/esm/models/components/chunkingstrategy.d.ts +2 -1
  127. package/dist/esm/models/components/chunkingstrategy.d.ts.map +1 -1
  128. package/dist/esm/models/components/chunkingstrategy.js +6 -5
  129. package/dist/esm/models/components/chunkingstrategy.js.map +1 -1
  130. package/dist/esm/models/components/codeinterpreteroutput.d.ts +2 -1
  131. package/dist/esm/models/components/codeinterpreteroutput.d.ts.map +1 -1
  132. package/dist/esm/models/components/codeinterpreteroutput.js +5 -4
  133. package/dist/esm/models/components/codeinterpreteroutput.js.map +1 -1
  134. package/dist/esm/models/components/computeraction.d.ts +2 -1
  135. package/dist/esm/models/components/computeraction.d.ts.map +1 -1
  136. package/dist/esm/models/components/computeraction.js +12 -11
  137. package/dist/esm/models/components/computeraction.js.map +1 -1
  138. package/dist/esm/models/components/customtoolformat.d.ts +2 -1
  139. package/dist/esm/models/components/customtoolformat.d.ts.map +1 -1
  140. package/dist/esm/models/components/customtoolformat.js +5 -1
  141. package/dist/esm/models/components/customtoolformat.js.map +1 -1
  142. package/dist/esm/models/components/filesearchcompoundfilter.d.ts +3 -2
  143. package/dist/esm/models/components/filesearchcompoundfilter.d.ts.map +1 -1
  144. package/dist/esm/models/components/filesearchcompoundfilter.js +21 -20
  145. package/dist/esm/models/components/filesearchcompoundfilter.js.map +1 -1
  146. package/dist/esm/models/components/guardrailconfig.d.ts +2 -1
  147. package/dist/esm/models/components/guardrailconfig.d.ts.map +1 -1
  148. package/dist/esm/models/components/guardrailconfig.js +6 -5
  149. package/dist/esm/models/components/guardrailconfig.js.map +1 -1
  150. package/dist/esm/models/components/method.d.ts +6 -5
  151. package/dist/esm/models/components/method.d.ts.map +1 -1
  152. package/dist/esm/models/components/method.js +36 -35
  153. package/dist/esm/models/components/method.js.map +1 -1
  154. package/dist/esm/models/components/openaichatcompletionchoice.d.ts +4 -3
  155. package/dist/esm/models/components/openaichatcompletionchoice.d.ts.map +1 -1
  156. package/dist/esm/models/components/openaichatcompletionchoice.js +19 -18
  157. package/dist/esm/models/components/openaichatcompletionchoice.js.map +1 -1
  158. package/dist/esm/models/components/openaichatcompletionchunk.d.ts +4 -3
  159. package/dist/esm/models/components/openaichatcompletionchunk.d.ts.map +1 -1
  160. package/dist/esm/models/components/openaichatcompletionchunk.js +19 -18
  161. package/dist/esm/models/components/openaichatcompletionchunk.js.map +1 -1
  162. package/dist/esm/models/components/outputmessage.d.ts +3 -2
  163. package/dist/esm/models/components/outputmessage.d.ts.map +1 -1
  164. package/dist/esm/models/components/outputmessage.js +9 -8
  165. package/dist/esm/models/components/outputmessage.js.map +1 -1
  166. package/dist/esm/models/components/outputmessagewithid.d.ts +3 -2
  167. package/dist/esm/models/components/outputmessagewithid.d.ts.map +1 -1
  168. package/dist/esm/models/components/outputmessagewithid.js +9 -8
  169. package/dist/esm/models/components/outputmessagewithid.js.map +1 -1
  170. package/dist/esm/models/components/outputtext.d.ts +3 -2
  171. package/dist/esm/models/components/outputtext.d.ts.map +1 -1
  172. package/dist/esm/models/components/outputtext.js +13 -12
  173. package/dist/esm/models/components/outputtext.js.map +1 -1
  174. package/dist/esm/models/components/responsecontentpartaddedevent.d.ts +3 -2
  175. package/dist/esm/models/components/responsecontentpartaddedevent.d.ts.map +1 -1
  176. package/dist/esm/models/components/responsecontentpartaddedevent.js +11 -11
  177. package/dist/esm/models/components/responsecontentpartaddedevent.js.map +1 -1
  178. package/dist/esm/models/components/responsecontentpartdoneevent.d.ts +3 -2
  179. package/dist/esm/models/components/responsecontentpartdoneevent.d.ts.map +1 -1
  180. package/dist/esm/models/components/responsecontentpartdoneevent.js +11 -10
  181. package/dist/esm/models/components/responsecontentpartdoneevent.js.map +1 -1
  182. package/dist/esm/models/components/responseformat.d.ts +2 -1
  183. package/dist/esm/models/components/responseformat.d.ts.map +1 -1
  184. package/dist/esm/models/components/responseformat.js +6 -5
  185. package/dist/esm/models/components/responseformat.js.map +1 -1
  186. package/dist/esm/models/components/responseobject.d.ts +5 -4
  187. package/dist/esm/models/components/responseobject.d.ts.map +1 -1
  188. package/dist/esm/models/components/responseobject.js +41 -40
  189. package/dist/esm/models/components/responseobject.js.map +1 -1
  190. package/dist/esm/models/components/responsestreamingevent.d.ts +2 -1
  191. package/dist/esm/models/components/responsestreamingevent.d.ts.map +1 -1
  192. package/dist/esm/models/components/responsestreamingevent.js +68 -67
  193. package/dist/esm/models/components/responsestreamingevent.js.map +1 -1
  194. package/dist/esm/models/components/shellenvironment.d.ts +2 -1
  195. package/dist/esm/models/components/shellenvironment.d.ts.map +1 -1
  196. package/dist/esm/models/components/shellenvironment.js +5 -4
  197. package/dist/esm/models/components/shellenvironment.js.map +1 -1
  198. package/dist/esm/models/components/skillentry.d.ts +2 -1
  199. package/dist/esm/models/components/skillentry.d.ts.map +1 -1
  200. package/dist/esm/models/components/skillentry.js +5 -4
  201. package/dist/esm/models/components/skillentry.js.map +1 -1
  202. package/dist/esm/models/components/tooldefinition.d.ts +5 -4
  203. package/dist/esm/models/components/tooldefinition.d.ts.map +1 -1
  204. package/dist/esm/models/components/tooldefinition.js +29 -28
  205. package/dist/esm/models/components/tooldefinition.js.map +1 -1
  206. package/dist/esm/models/components/websearchaction.d.ts +2 -1
  207. package/dist/esm/models/components/websearchaction.d.ts.map +1 -1
  208. package/dist/esm/models/components/websearchaction.js +6 -5
  209. package/dist/esm/models/components/websearchaction.js.map +1 -1
  210. package/dist/esm/models/operations/createchatcompletionstream.d.ts +2 -1
  211. package/dist/esm/models/operations/createchatcompletionstream.d.ts.map +1 -1
  212. package/dist/esm/models/operations/createchatcompletionstream.js +6 -5
  213. package/dist/esm/models/operations/createchatcompletionstream.js.map +1 -1
  214. package/dist/esm/models/operations/uploadfile.d.ts +1 -1
  215. package/dist/esm/types/discriminatedUnion.d.ts +25 -0
  216. package/dist/esm/types/discriminatedUnion.d.ts.map +1 -0
  217. package/dist/esm/types/discriminatedUnion.js +57 -0
  218. package/dist/esm/types/discriminatedUnion.js.map +1 -0
  219. package/jsr.json +1 -1
  220. package/package.json +1 -1
  221. package/src/hooks/multipartFilename.ts +60 -0
  222. package/src/hooks/registration.ts +2 -1
  223. package/src/lib/config.ts +2 -2
  224. package/src/mcp-server/mcp-server.ts +1 -1
  225. package/src/mcp-server/server.ts +1 -1
  226. package/src/models/components/agentschedulespec.ts +9 -6
  227. package/src/models/components/chunkingstrategy.ts +9 -6
  228. package/src/models/components/codeinterpreteroutput.ts +8 -5
  229. package/src/models/components/computeraction.ts +15 -12
  230. package/src/models/components/customtoolformat.ts +10 -2
  231. package/src/models/components/filesearchcompoundfilter.ts +41 -39
  232. package/src/models/components/guardrailconfig.ts +9 -6
  233. package/src/models/components/method.ts +75 -43
  234. package/src/models/components/openaichatcompletionchoice.ts +24 -21
  235. package/src/models/components/openaichatcompletionchunk.ts +24 -21
  236. package/src/models/components/outputmessage.ts +19 -10
  237. package/src/models/components/outputmessagewithid.ts +19 -10
  238. package/src/models/components/outputtext.ts +23 -16
  239. package/src/models/components/responsecontentpartaddedevent.ts +25 -13
  240. package/src/models/components/responsecontentpartdoneevent.ts +22 -12
  241. package/src/models/components/responseformat.ts +9 -6
  242. package/src/models/components/responseobject.ts +62 -48
  243. package/src/models/components/responsestreamingevent.ts +118 -68
  244. package/src/models/components/shellenvironment.ts +8 -5
  245. package/src/models/components/skillentry.ts +10 -5
  246. package/src/models/components/tooldefinition.ts +42 -31
  247. package/src/models/components/websearchaction.ts +12 -6
  248. package/src/models/operations/createchatcompletionstream.ts +12 -6
  249. package/src/models/operations/uploadfile.ts +1 -1
  250. package/src/types/discriminatedUnion.ts +96 -0
@@ -4,6 +4,8 @@
4
4
 
5
5
  import * as z from "zod/v3";
6
6
  import { safeParse } from "../../lib/schemas.js";
7
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
8
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
7
9
  import { Result as SafeParseResult } from "../../types/fp.js";
8
10
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
11
  import {
@@ -462,80 +464,128 @@ export type ResponseStreamingEvent =
462
464
  | ResponseCustomToolCallInputDeltaEvent
463
465
  | ResponseCustomToolCallInputDoneEvent
464
466
  | ResponseOutputTextAnnotationAddedEvent
465
- | ErrorEvent;
467
+ | ErrorEvent
468
+ | discriminatedUnionTypes.Unknown<"type">;
466
469
 
467
470
  /** @internal */
468
471
  export const ResponseStreamingEvent$inboundSchema: z.ZodType<
469
472
  ResponseStreamingEvent,
470
473
  z.ZodTypeDef,
471
474
  unknown
472
- > = z.union([
473
- ResponseCreatedEvent$inboundSchema,
474
- ResponseInProgressEvent$inboundSchema,
475
- ResponseCompletedEvent$inboundSchema,
476
- ResponseFailedEvent$inboundSchema,
477
- ResponseIncompleteEvent$inboundSchema,
478
- ResponseQueuedEvent$inboundSchema,
479
- ResponseCancelledEvent$inboundSchema,
480
- ResponseOutputItemAddedEvent$inboundSchema,
481
- ResponseOutputItemDoneEvent$inboundSchema,
482
- ResponseContentPartAddedEvent$inboundSchema,
483
- ResponseContentPartDoneEvent$inboundSchema,
484
- ResponseOutputTextDeltaEvent$inboundSchema,
485
- ResponseOutputTextDoneEvent$inboundSchema,
486
- ResponseRefusalDeltaEvent$inboundSchema,
487
- ResponseRefusalDoneEvent$inboundSchema,
488
- ResponseFunctionCallArgumentsDeltaEvent$inboundSchema,
489
- ResponseFunctionCallArgumentsDoneEvent$inboundSchema,
490
- ResponseFileSearchCallInProgressEvent$inboundSchema,
491
- ResponseFileSearchCallSearchingEvent$inboundSchema,
492
- ResponseFileSearchCallCompletedEvent$inboundSchema,
493
- ResponseWebSearchCallInProgressEvent$inboundSchema,
494
- ResponseWebSearchCallSearchingEvent$inboundSchema,
495
- ResponseWebSearchCallCompletedEvent$inboundSchema,
496
- ResponseHistoryCallInProgressEvent$inboundSchema,
497
- ResponseHistoryCallSearchingEvent$inboundSchema,
498
- ResponseHistoryCallCompletedEvent$inboundSchema,
499
- ResponseSleepCallInProgressEvent$inboundSchema,
500
- ResponseSleepCallSleepingEvent$inboundSchema,
501
- ResponseSleepCallCompletedEvent$inboundSchema,
502
- ResponseToolSearchCallInProgressEvent$inboundSchema,
503
- ResponseToolSearchCallSearchingEvent$inboundSchema,
504
- ResponseToolSearchCallCompletedEvent$inboundSchema,
505
- ResponseReasoningSummaryPartAddedEvent$inboundSchema,
506
- ResponseReasoningSummaryPartDoneEvent$inboundSchema,
507
- ResponseReasoningSummaryTextDeltaEvent$inboundSchema,
508
- ResponseReasoningSummaryTextDoneEvent$inboundSchema,
509
- ResponseReasoningTextDeltaEvent$inboundSchema,
510
- ResponseReasoningTextDoneEvent$inboundSchema,
511
- ResponseImageGenerationCallInProgressEvent$inboundSchema,
512
- ResponseImageGenerationCallGeneratingEvent$inboundSchema,
513
- ResponseImageGenerationCallCompletedEvent$inboundSchema,
514
- ResponseImageGenerationCallPartialImageEvent$inboundSchema,
515
- ResponseMCPCallArgumentsDeltaEvent$inboundSchema,
516
- ResponseMCPCallArgumentsDoneEvent$inboundSchema,
517
- ResponseMCPCallInProgressEvent$inboundSchema,
518
- ResponseMCPCallCompletedEvent$inboundSchema,
519
- ResponseMCPCallFailedEvent$inboundSchema,
520
- ResponseMCPListToolsInProgressEvent$inboundSchema,
521
- ResponseMCPListToolsCompletedEvent$inboundSchema,
522
- ResponseMCPListToolsFailedEvent$inboundSchema,
523
- ResponseReadFileCallInProgressEvent$inboundSchema,
524
- ResponseReadFileCallReadingEvent$inboundSchema,
525
- ResponseReadFileCallCompletedEvent$inboundSchema,
526
- ResponseCodeInterpreterCallInProgressEvent$inboundSchema,
527
- ResponseCodeInterpreterCallInterpretingEvent$inboundSchema,
528
- ResponseCodeInterpreterCallCompletedEvent$inboundSchema,
529
- ResponseCodeInterpreterCallCodeDeltaEvent$inboundSchema,
530
- ResponseCodeInterpreterCallCodeDoneEvent$inboundSchema,
531
- ResponseShellCallInProgressEvent$inboundSchema,
532
- ResponseShellCallExecutingEvent$inboundSchema,
533
- ResponseShellCallCompletedEvent$inboundSchema,
534
- ResponseCustomToolCallInputDeltaEvent$inboundSchema,
535
- ResponseCustomToolCallInputDoneEvent$inboundSchema,
536
- ResponseOutputTextAnnotationAddedEvent$inboundSchema,
537
- ErrorEvent$inboundSchema,
538
- ]);
475
+ > = discriminatedUnion("type", {
476
+ ["response.created"]: ResponseCreatedEvent$inboundSchema,
477
+ ["response.in_progress"]: ResponseInProgressEvent$inboundSchema,
478
+ ["response.completed"]: ResponseCompletedEvent$inboundSchema,
479
+ ["response.failed"]: ResponseFailedEvent$inboundSchema,
480
+ ["response.incomplete"]: ResponseIncompleteEvent$inboundSchema,
481
+ ["response.queued"]: ResponseQueuedEvent$inboundSchema,
482
+ ["response.cancelled"]: ResponseCancelledEvent$inboundSchema,
483
+ ["response.output_item.added"]: ResponseOutputItemAddedEvent$inboundSchema,
484
+ ["response.output_item.done"]: ResponseOutputItemDoneEvent$inboundSchema,
485
+ ["response.content_part.added"]: ResponseContentPartAddedEvent$inboundSchema,
486
+ ["response.content_part.done"]: ResponseContentPartDoneEvent$inboundSchema,
487
+ ["response.output_text.delta"]: ResponseOutputTextDeltaEvent$inboundSchema,
488
+ ["response.output_text.done"]: ResponseOutputTextDoneEvent$inboundSchema,
489
+ ["response.refusal.delta"]: ResponseRefusalDeltaEvent$inboundSchema,
490
+ ["response.refusal.done"]: ResponseRefusalDoneEvent$inboundSchema,
491
+ ["response.function_call_arguments.delta"]:
492
+ ResponseFunctionCallArgumentsDeltaEvent$inboundSchema,
493
+ ["response.function_call_arguments.done"]:
494
+ ResponseFunctionCallArgumentsDoneEvent$inboundSchema,
495
+ ["response.file_search_call.in_progress"]:
496
+ ResponseFileSearchCallInProgressEvent$inboundSchema,
497
+ ["response.file_search_call.searching"]:
498
+ ResponseFileSearchCallSearchingEvent$inboundSchema,
499
+ ["response.file_search_call.completed"]:
500
+ ResponseFileSearchCallCompletedEvent$inboundSchema,
501
+ ["response.web_search_call.in_progress"]:
502
+ ResponseWebSearchCallInProgressEvent$inboundSchema,
503
+ ["response.web_search_call.searching"]:
504
+ ResponseWebSearchCallSearchingEvent$inboundSchema,
505
+ ["response.web_search_call.completed"]:
506
+ ResponseWebSearchCallCompletedEvent$inboundSchema,
507
+ ["response.history_call.in_progress"]:
508
+ ResponseHistoryCallInProgressEvent$inboundSchema,
509
+ ["response.history_call.searching"]:
510
+ ResponseHistoryCallSearchingEvent$inboundSchema,
511
+ ["response.history_call.completed"]:
512
+ ResponseHistoryCallCompletedEvent$inboundSchema,
513
+ ["response.sleep_call.in_progress"]:
514
+ ResponseSleepCallInProgressEvent$inboundSchema,
515
+ ["response.sleep_call.sleeping"]:
516
+ ResponseSleepCallSleepingEvent$inboundSchema,
517
+ ["response.sleep_call.completed"]:
518
+ ResponseSleepCallCompletedEvent$inboundSchema,
519
+ ["response.tool_search_call.in_progress"]:
520
+ ResponseToolSearchCallInProgressEvent$inboundSchema,
521
+ ["response.tool_search_call.searching"]:
522
+ ResponseToolSearchCallSearchingEvent$inboundSchema,
523
+ ["response.tool_search_call.completed"]:
524
+ ResponseToolSearchCallCompletedEvent$inboundSchema,
525
+ ["response.reasoning_summary_part.added"]:
526
+ ResponseReasoningSummaryPartAddedEvent$inboundSchema,
527
+ ["response.reasoning_summary_part.done"]:
528
+ ResponseReasoningSummaryPartDoneEvent$inboundSchema,
529
+ ["response.reasoning_summary_text.delta"]:
530
+ ResponseReasoningSummaryTextDeltaEvent$inboundSchema,
531
+ ["response.reasoning_summary_text.done"]:
532
+ ResponseReasoningSummaryTextDoneEvent$inboundSchema,
533
+ ["response.reasoning_text.delta"]:
534
+ ResponseReasoningTextDeltaEvent$inboundSchema,
535
+ ["response.reasoning_text.done"]:
536
+ ResponseReasoningTextDoneEvent$inboundSchema,
537
+ ["response.image_generation_call.in_progress"]:
538
+ ResponseImageGenerationCallInProgressEvent$inboundSchema,
539
+ ["response.image_generation_call.generating"]:
540
+ ResponseImageGenerationCallGeneratingEvent$inboundSchema,
541
+ ["response.image_generation_call.completed"]:
542
+ ResponseImageGenerationCallCompletedEvent$inboundSchema,
543
+ ["response.image_generation_call.partial_image"]:
544
+ ResponseImageGenerationCallPartialImageEvent$inboundSchema,
545
+ ["response.mcp_call_arguments.delta"]:
546
+ ResponseMCPCallArgumentsDeltaEvent$inboundSchema,
547
+ ["response.mcp_call_arguments.done"]:
548
+ ResponseMCPCallArgumentsDoneEvent$inboundSchema,
549
+ ["response.mcp_call.in_progress"]:
550
+ ResponseMCPCallInProgressEvent$inboundSchema,
551
+ ["response.mcp_call.completed"]: ResponseMCPCallCompletedEvent$inboundSchema,
552
+ ["response.mcp_call.failed"]: ResponseMCPCallFailedEvent$inboundSchema,
553
+ ["response.mcp_list_tools.in_progress"]:
554
+ ResponseMCPListToolsInProgressEvent$inboundSchema,
555
+ ["response.mcp_list_tools.completed"]:
556
+ ResponseMCPListToolsCompletedEvent$inboundSchema,
557
+ ["response.mcp_list_tools.failed"]:
558
+ ResponseMCPListToolsFailedEvent$inboundSchema,
559
+ ["response.read_file_call.in_progress"]:
560
+ ResponseReadFileCallInProgressEvent$inboundSchema,
561
+ ["response.read_file_call.reading"]:
562
+ ResponseReadFileCallReadingEvent$inboundSchema,
563
+ ["response.read_file_call.completed"]:
564
+ ResponseReadFileCallCompletedEvent$inboundSchema,
565
+ ["response.code_interpreter_call.in_progress"]:
566
+ ResponseCodeInterpreterCallInProgressEvent$inboundSchema,
567
+ ["response.code_interpreter_call.interpreting"]:
568
+ ResponseCodeInterpreterCallInterpretingEvent$inboundSchema,
569
+ ["response.code_interpreter_call.completed"]:
570
+ ResponseCodeInterpreterCallCompletedEvent$inboundSchema,
571
+ ["response.code_interpreter_call_code.delta"]:
572
+ ResponseCodeInterpreterCallCodeDeltaEvent$inboundSchema,
573
+ ["response.code_interpreter_call_code.done"]:
574
+ ResponseCodeInterpreterCallCodeDoneEvent$inboundSchema,
575
+ ["response.shell_call.in_progress"]:
576
+ ResponseShellCallInProgressEvent$inboundSchema,
577
+ ["response.shell_call.executing"]:
578
+ ResponseShellCallExecutingEvent$inboundSchema,
579
+ ["response.shell_call.completed"]:
580
+ ResponseShellCallCompletedEvent$inboundSchema,
581
+ ["response.custom_tool_call_input.delta"]:
582
+ ResponseCustomToolCallInputDeltaEvent$inboundSchema,
583
+ ["response.custom_tool_call_input.done"]:
584
+ ResponseCustomToolCallInputDoneEvent$inboundSchema,
585
+ ["response.output_text.annotation.added"]:
586
+ ResponseOutputTextAnnotationAddedEvent$inboundSchema,
587
+ error: ErrorEvent$inboundSchema,
588
+ });
539
589
  /** @internal */
540
590
  export type ResponseStreamingEvent$Outbound =
541
591
  | ResponseCreatedEvent$Outbound
@@ -4,6 +4,8 @@
4
4
 
5
5
  import * as z from "zod/v3";
6
6
  import { safeParse } from "../../lib/schemas.js";
7
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
8
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
7
9
  import { Result as SafeParseResult } from "../../types/fp.js";
8
10
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
11
  import {
@@ -21,17 +23,18 @@ import {
21
23
 
22
24
  export type ShellEnvironment =
23
25
  | ShellEnvironmentContainerAuto
24
- | ShellEnvironmentContainerReference;
26
+ | ShellEnvironmentContainerReference
27
+ | discriminatedUnionTypes.Unknown<"type">;
25
28
 
26
29
  /** @internal */
27
30
  export const ShellEnvironment$inboundSchema: z.ZodType<
28
31
  ShellEnvironment,
29
32
  z.ZodTypeDef,
30
33
  unknown
31
- > = z.union([
32
- ShellEnvironmentContainerAuto$inboundSchema,
33
- ShellEnvironmentContainerReference$inboundSchema,
34
- ]);
34
+ > = discriminatedUnion("type", {
35
+ container_auto: ShellEnvironmentContainerAuto$inboundSchema,
36
+ container_reference: ShellEnvironmentContainerReference$inboundSchema,
37
+ });
35
38
  /** @internal */
36
39
  export type ShellEnvironment$Outbound =
37
40
  | ShellEnvironmentContainerAuto$Outbound
@@ -4,6 +4,8 @@
4
4
 
5
5
  import * as z from "zod/v3";
6
6
  import { safeParse } from "../../lib/schemas.js";
7
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
8
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
7
9
  import { Result as SafeParseResult } from "../../types/fp.js";
8
10
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
11
  import {
@@ -19,17 +21,20 @@ import {
19
21
  SkillReference$outboundSchema,
20
22
  } from "./skillreference.js";
21
23
 
22
- export type SkillEntry = SkillReference | PreconfiguredSkillReference;
24
+ export type SkillEntry =
25
+ | SkillReference
26
+ | PreconfiguredSkillReference
27
+ | discriminatedUnionTypes.Unknown<"type">;
23
28
 
24
29
  /** @internal */
25
30
  export const SkillEntry$inboundSchema: z.ZodType<
26
31
  SkillEntry,
27
32
  z.ZodTypeDef,
28
33
  unknown
29
- > = z.union([
30
- SkillReference$inboundSchema,
31
- PreconfiguredSkillReference$inboundSchema,
32
- ]);
34
+ > = discriminatedUnion("type", {
35
+ skill_reference: SkillReference$inboundSchema,
36
+ preconfigured: PreconfiguredSkillReference$inboundSchema,
37
+ });
33
38
  /** @internal */
34
39
  export type SkillEntry$Outbound =
35
40
  | SkillReference$Outbound
@@ -5,6 +5,8 @@
5
5
  import * as z from "zod/v3";
6
6
  import { remap as remap$ } from "../../lib/primitives.js";
7
7
  import { safeParse } from "../../lib/schemas.js";
8
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
9
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
8
10
  import { ClosedEnum } from "../../types/enums.js";
9
11
  import { Result as SafeParseResult } from "../../types/fp.js";
10
12
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
@@ -83,11 +85,18 @@ export type Environment1 = {
83
85
  memoryStores?: Array<MemoryStores> | undefined;
84
86
  };
85
87
 
86
- export type Environment = Environment1 | Environment2;
88
+ export type Environment =
89
+ | Environment1
90
+ | Environment2
91
+ | discriminatedUnionTypes.Unknown<"type">;
87
92
 
88
93
  export type Seven = {
89
94
  type: ToolDefinition7Type;
90
- environment?: Environment1 | Environment2 | undefined;
95
+ environment?:
96
+ | Environment1
97
+ | Environment2
98
+ | discriminatedUnionTypes.Unknown<"type">
99
+ | undefined;
91
100
  };
92
101
 
93
102
  export const ToolDefinition6Type = {
@@ -124,7 +133,8 @@ export type ToolDefinition4Filters =
124
133
  | (FileSearchComparisonFilter & { type: "lt" })
125
134
  | (FileSearchComparisonFilter & { type: "lte" })
126
135
  | (FileSearchCompoundFilter & { type: "and" })
127
- | (FileSearchCompoundFilter & { type: "or" });
136
+ | (FileSearchCompoundFilter & { type: "or" })
137
+ | discriminatedUnionTypes.Unknown<"type">;
128
138
 
129
139
  export type ToolDefinitionRankingOptions = {
130
140
  ranker?: string | undefined;
@@ -143,6 +153,7 @@ export type ToolDefinition4 = {
143
153
  | (FileSearchComparisonFilter & { type: "lte" })
144
154
  | (FileSearchCompoundFilter & { type: "and" })
145
155
  | (FileSearchCompoundFilter & { type: "or" })
156
+ | discriminatedUnionTypes.Unknown<"type">
146
157
  | undefined;
147
158
  maxNumResults?: number | undefined;
148
159
  rankingOptions?: ToolDefinitionRankingOptions | undefined;
@@ -549,10 +560,10 @@ export const Environment$inboundSchema: z.ZodType<
549
560
  Environment,
550
561
  z.ZodTypeDef,
551
562
  unknown
552
- > = z.union([
553
- z.lazy(() => Environment1$inboundSchema),
554
- z.lazy(() => Environment2$inboundSchema),
555
- ]);
563
+ > = discriminatedUnion("type", {
564
+ container_auto: z.lazy(() => Environment1$inboundSchema),
565
+ container_reference: z.lazy(() => Environment2$inboundSchema),
566
+ });
556
567
  /** @internal */
557
568
  export type Environment$Outbound =
558
569
  | Environment1$Outbound
@@ -585,10 +596,10 @@ export function environmentFromJSON(
585
596
  export const Seven$inboundSchema: z.ZodType<Seven, z.ZodTypeDef, unknown> = z
586
597
  .object({
587
598
  type: ToolDefinition7Type$inboundSchema,
588
- environment: z.union([
589
- z.lazy(() => Environment1$inboundSchema),
590
- z.lazy(() => Environment2$inboundSchema),
591
- ]).optional(),
599
+ environment: discriminatedUnion("type", {
600
+ container_auto: z.lazy(() => Environment1$inboundSchema),
601
+ container_reference: z.lazy(() => Environment2$inboundSchema),
602
+ }).optional(),
592
603
  });
593
604
  /** @internal */
594
605
  export type Seven$Outbound = {
@@ -728,32 +739,32 @@ export const ToolDefinition4Filters$inboundSchema: z.ZodType<
728
739
  ToolDefinition4Filters,
729
740
  z.ZodTypeDef,
730
741
  unknown
731
- > = z.union([
732
- FileSearchComparisonFilter$inboundSchema.and(
742
+ > = discriminatedUnion("type", {
743
+ eq: FileSearchComparisonFilter$inboundSchema.and(
733
744
  z.object({ type: z.literal("eq") }),
734
745
  ),
735
- FileSearchComparisonFilter$inboundSchema.and(
746
+ ne: FileSearchComparisonFilter$inboundSchema.and(
736
747
  z.object({ type: z.literal("ne") }),
737
748
  ),
738
- FileSearchComparisonFilter$inboundSchema.and(
749
+ gt: FileSearchComparisonFilter$inboundSchema.and(
739
750
  z.object({ type: z.literal("gt") }),
740
751
  ),
741
- FileSearchComparisonFilter$inboundSchema.and(
752
+ gte: FileSearchComparisonFilter$inboundSchema.and(
742
753
  z.object({ type: z.literal("gte") }),
743
754
  ),
744
- FileSearchComparisonFilter$inboundSchema.and(
755
+ lt: FileSearchComparisonFilter$inboundSchema.and(
745
756
  z.object({ type: z.literal("lt") }),
746
757
  ),
747
- FileSearchComparisonFilter$inboundSchema.and(
758
+ lte: FileSearchComparisonFilter$inboundSchema.and(
748
759
  z.object({ type: z.literal("lte") }),
749
760
  ),
750
- FileSearchCompoundFilter$inboundSchema.and(
761
+ and: FileSearchCompoundFilter$inboundSchema.and(
751
762
  z.object({ type: z.literal("and") }),
752
763
  ),
753
- FileSearchCompoundFilter$inboundSchema.and(
764
+ or: FileSearchCompoundFilter$inboundSchema.and(
754
765
  z.object({ type: z.literal("or") }),
755
766
  ),
756
- ]);
767
+ });
757
768
  /** @internal */
758
769
  export type ToolDefinition4Filters$Outbound =
759
770
  | (FileSearchComparisonFilter$Outbound & { type: "eq" })
@@ -874,32 +885,32 @@ export const ToolDefinition4$inboundSchema: z.ZodType<
874
885
  > = z.object({
875
886
  type: ToolDefinition4Type$inboundSchema,
876
887
  vector_store_ids: z.array(z.string()),
877
- filters: z.union([
878
- FileSearchComparisonFilter$inboundSchema.and(
888
+ filters: discriminatedUnion("type", {
889
+ eq: FileSearchComparisonFilter$inboundSchema.and(
879
890
  z.object({ type: z.literal("eq") }),
880
891
  ),
881
- FileSearchComparisonFilter$inboundSchema.and(
892
+ ne: FileSearchComparisonFilter$inboundSchema.and(
882
893
  z.object({ type: z.literal("ne") }),
883
894
  ),
884
- FileSearchComparisonFilter$inboundSchema.and(
895
+ gt: FileSearchComparisonFilter$inboundSchema.and(
885
896
  z.object({ type: z.literal("gt") }),
886
897
  ),
887
- FileSearchComparisonFilter$inboundSchema.and(
898
+ gte: FileSearchComparisonFilter$inboundSchema.and(
888
899
  z.object({ type: z.literal("gte") }),
889
900
  ),
890
- FileSearchComparisonFilter$inboundSchema.and(
901
+ lt: FileSearchComparisonFilter$inboundSchema.and(
891
902
  z.object({ type: z.literal("lt") }),
892
903
  ),
893
- FileSearchComparisonFilter$inboundSchema.and(
904
+ lte: FileSearchComparisonFilter$inboundSchema.and(
894
905
  z.object({ type: z.literal("lte") }),
895
906
  ),
896
- FileSearchCompoundFilter$inboundSchema.and(
907
+ and: FileSearchCompoundFilter$inboundSchema.and(
897
908
  z.object({ type: z.literal("and") }),
898
909
  ),
899
- FileSearchCompoundFilter$inboundSchema.and(
910
+ or: FileSearchCompoundFilter$inboundSchema.and(
900
911
  z.object({ type: z.literal("or") }),
901
912
  ),
902
- ]).optional(),
913
+ }).optional(),
903
914
  max_num_results: z.number().int().optional(),
904
915
  ranking_options: z.lazy(() => ToolDefinitionRankingOptions$inboundSchema)
905
916
  .optional(),
@@ -4,6 +4,8 @@
4
4
 
5
5
  import * as z from "zod/v3";
6
6
  import { safeParse } from "../../lib/schemas.js";
7
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
8
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
7
9
  import { Result as SafeParseResult } from "../../types/fp.js";
8
10
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
11
  import {
@@ -25,18 +27,22 @@ import {
25
27
  SearchAction$outboundSchema,
26
28
  } from "./searchaction.js";
27
29
 
28
- export type WebSearchAction = SearchAction | OpenPageAction | FindAction;
30
+ export type WebSearchAction =
31
+ | SearchAction
32
+ | OpenPageAction
33
+ | FindAction
34
+ | discriminatedUnionTypes.Unknown<"type">;
29
35
 
30
36
  /** @internal */
31
37
  export const WebSearchAction$inboundSchema: z.ZodType<
32
38
  WebSearchAction,
33
39
  z.ZodTypeDef,
34
40
  unknown
35
- > = z.union([
36
- SearchAction$inboundSchema,
37
- OpenPageAction$inboundSchema,
38
- FindAction$inboundSchema,
39
- ]);
41
+ > = discriminatedUnion("type", {
42
+ search: SearchAction$inboundSchema,
43
+ open_page: OpenPageAction$inboundSchema,
44
+ find: FindAction$inboundSchema,
45
+ });
40
46
  /** @internal */
41
47
  export type WebSearchAction$Outbound =
42
48
  | SearchAction$Outbound
@@ -5,6 +5,8 @@
5
5
  import * as z from "zod/v3";
6
6
  import { remap as remap$ } from "../../lib/primitives.js";
7
7
  import { safeParse } from "../../lib/schemas.js";
8
+ import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
9
+ import { discriminatedUnion } from "../../types/discriminatedUnion.js";
8
10
  import { Result as SafeParseResult } from "../../types/fp.js";
9
11
  import * as components from "../components/index.js";
10
12
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
@@ -45,7 +47,11 @@ export type One = {
45
47
  /**
46
48
  * OK
47
49
  */
48
- export type CreateChatCompletionStreamResponseBody = One | Two | Three;
50
+ export type CreateChatCompletionStreamResponseBody =
51
+ | One
52
+ | Two
53
+ | Three
54
+ | discriminatedUnionTypes.Unknown<"event">;
49
55
 
50
56
  /** @internal */
51
57
  export const CreateChatCompletionStreamRequest$inboundSchema: z.ZodType<
@@ -234,11 +240,11 @@ export const CreateChatCompletionStreamResponseBody$inboundSchema: z.ZodType<
234
240
  CreateChatCompletionStreamResponseBody,
235
241
  z.ZodTypeDef,
236
242
  unknown
237
- > = z.union([
238
- z.lazy(() => One$inboundSchema),
239
- z.lazy(() => Two$inboundSchema),
240
- z.lazy(() => Three$inboundSchema),
241
- ]);
243
+ > = discriminatedUnion("event", {
244
+ message: z.lazy(() => One$inboundSchema),
245
+ done: z.lazy(() => Two$inboundSchema),
246
+ error: z.lazy(() => Three$inboundSchema),
247
+ });
242
248
  /** @internal */
243
249
  export type CreateChatCompletionStreamResponseBody$Outbound =
244
250
  | One$Outbound
@@ -33,7 +33,7 @@ export type Purpose = ClosedEnum<typeof Purpose>;
33
33
 
34
34
  export type UploadFileRequestBody = {
35
35
  /**
36
- * The file to upload
36
+ * The file to upload. Multipart file parts must include a nonblank filename; the lowercase WHATWG placeholder filename "blob" is treated as missing.
37
37
  */
38
38
  file: FileT | Blob;
39
39
  /**
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { startCountingUnrecognized } from "./unrecognized.js";
7
+
8
+ const UNKNOWN = Symbol("UNKNOWN");
9
+
10
+ export type Unknown<Discriminator extends string, UnknownValue = "UNKNOWN"> =
11
+ & {
12
+ [K in Discriminator]: UnknownValue;
13
+ }
14
+ & {
15
+ raw: unknown;
16
+ isUnknown: true;
17
+ };
18
+
19
+ export function isUnknown<Discriminator extends string>(
20
+ value: unknown,
21
+ ): value is Unknown<Discriminator> {
22
+ return typeof value === "object" && value !== null && UNKNOWN in value;
23
+ }
24
+
25
+ /**
26
+ * Forward-compatible discriminated union parser.
27
+ *
28
+ * If the input does not match one of the predefined options, it will be
29
+ * captured and available as `{ raw: <original input>, [discriminator]: "UNKNOWN", isUnknown: true }`.
30
+ *
31
+ * @param inputPropertyName - The discriminator property name in the input payload
32
+ * @param options - Map of discriminator values to their corresponding schemas
33
+ * @param opts - Optional configuration object
34
+ * @param opts.unknownValue - The value to use for the discriminator when the input is unknown (default: "UNKNOWN")
35
+ * @param opts.outputPropertyName - Output property name if the sanitized (camelCase) property name differs from inputPropertyName
36
+ */
37
+ export function discriminatedUnion<
38
+ InputDiscriminator extends string,
39
+ TOptions extends Readonly<Record<string, z.ZodType>>,
40
+ UnknownValue extends string = "UNKNOWN",
41
+ OutputDiscriminator extends string = InputDiscriminator,
42
+ >(
43
+ inputPropertyName: InputDiscriminator,
44
+ options: TOptions,
45
+ opts: {
46
+ unknownValue?: UnknownValue;
47
+ outputPropertyName?: OutputDiscriminator;
48
+ } = {},
49
+ ): z.ZodType<
50
+ | z.output<TOptions[keyof TOptions]>
51
+ | Unknown<OutputDiscriminator, UnknownValue>,
52
+ z.ZodTypeDef,
53
+ unknown
54
+ > {
55
+ const { unknownValue = "UNKNOWN" as UnknownValue, outputPropertyName } = opts;
56
+ return z.unknown().transform((input) => {
57
+ const fallback = Object.defineProperties(
58
+ {
59
+ raw: input,
60
+ [outputPropertyName ?? inputPropertyName]: unknownValue,
61
+ isUnknown: true as const,
62
+ },
63
+ { [UNKNOWN]: { value: true, enumerable: false, configurable: false } },
64
+ );
65
+
66
+ const isObject = typeof input === "object" && input !== null;
67
+ if (!isObject) return fallback;
68
+
69
+ const discriminator = input[inputPropertyName as keyof typeof input];
70
+ if (typeof discriminator !== "string") return fallback;
71
+ if (!(discriminator in options)) return fallback;
72
+
73
+ const schema = options[discriminator];
74
+ if (!schema) return fallback;
75
+
76
+ // Start counters before parsing to track nested unrecognized/zeroDefault values
77
+ const unrecognizedCtr = startCountingUnrecognized();
78
+
79
+ const result = schema.safeParse(input);
80
+ if (!result.success) {
81
+ // Parse failed - don't propagate any counts from the failed attempt
82
+ unrecognizedCtr.end(0);
83
+
84
+ return fallback;
85
+ }
86
+
87
+ // Parse succeeded - propagate the actual counts
88
+ unrecognizedCtr.end();
89
+
90
+ if (outputPropertyName) {
91
+ (result.data as any)[outputPropertyName] = discriminator;
92
+ }
93
+
94
+ return result.data;
95
+ }) as any;
96
+ }