@agentica/core 0.12.21 → 0.13.0

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 (205) hide show
  1. package/README.md +50 -47
  2. package/lib/Agentica.d.ts +9 -9
  3. package/lib/Agentica.js +23 -16
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
  6. package/lib/chatgpt/ChatGptAgent.js +17 -12
  7. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
  10. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
  13. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  14. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
  15. package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
  16. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
  18. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
  19. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  20. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
  21. package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
  22. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
  24. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
  25. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
  27. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
  28. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  29. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
  30. package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
  31. package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
  32. package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
  33. package/lib/context/AgenticaCancelPrompt.js +1 -1
  34. package/lib/context/AgenticaCancelPrompt.js.map +1 -1
  35. package/lib/context/AgenticaClassOperation.d.ts +1 -1
  36. package/lib/context/AgenticaClassOperation.js.map +1 -1
  37. package/lib/context/AgenticaContext.d.ts +9 -9
  38. package/lib/context/AgenticaHttpOperation.d.ts +1 -1
  39. package/lib/context/AgenticaHttpOperation.js.map +1 -1
  40. package/lib/context/AgenticaOperation.d.ts +4 -4
  41. package/lib/context/AgenticaOperationBase.d.ts +1 -1
  42. package/lib/context/AgenticaOperationCollection.d.ts +2 -2
  43. package/lib/context/AgenticaOperationSelection.d.ts +3 -3
  44. package/lib/context/AgenticaTokenUsage.d.ts +1 -1
  45. package/lib/context/AgenticaTokenUsage.js.map +1 -1
  46. package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
  47. package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
  48. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  49. package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
  50. package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
  51. package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
  52. package/lib/events/AgenticaCallEvent.d.ts +3 -3
  53. package/lib/events/AgenticaCancelEvent.d.ts +3 -3
  54. package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
  55. package/lib/events/AgenticaDescribeEvent.js +13 -2
  56. package/lib/events/AgenticaDescribeEvent.js.map +1 -1
  57. package/lib/events/AgenticaEvent.d.ts +12 -12
  58. package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
  59. package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
  60. package/lib/events/AgenticaRequestEvent.d.ts +3 -3
  61. package/lib/events/AgenticaRequestEvent.js.map +1 -1
  62. package/lib/events/AgenticaResponseEvent.d.ts +2 -2
  63. package/lib/events/AgenticaResponseEvent.js.map +1 -1
  64. package/lib/events/AgenticaSelectEvent.d.ts +3 -3
  65. package/lib/events/AgenticaSelectEvent.js.map +1 -1
  66. package/lib/events/AgenticaTextEvent.d.ts +1 -1
  67. package/lib/events/AgenticaTextEvent.js +12 -1
  68. package/lib/events/AgenticaTextEvent.js.map +1 -1
  69. package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
  70. package/lib/functional/assertHttpLlmApplication.js +9339 -9338
  71. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  72. package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
  73. package/lib/functional/validateHttpLlmApplication.js +19 -19
  74. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  75. package/lib/index.d.ts +19 -19
  76. package/lib/index.js +21 -21
  77. package/lib/index.js.map +1 -1
  78. package/lib/index.mjs +19211 -18997
  79. package/lib/index.mjs.map +1 -1
  80. package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
  81. package/lib/internal/AgenticaDefaultPrompt.js +39 -19
  82. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
  83. package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
  84. package/lib/internal/AgenticaOperationComposer.js +60 -59
  85. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  86. package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
  87. package/lib/internal/AgenticaSystemPrompt.js +9 -9
  88. package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
  89. package/lib/internal/AsyncQueue.d.ts +15 -0
  90. package/lib/internal/AsyncQueue.js +82 -0
  91. package/lib/internal/AsyncQueue.js.map +1 -0
  92. package/lib/internal/ByteArrayUtil.d.ts +1 -1
  93. package/lib/internal/ByteArrayUtil.js +3 -2
  94. package/lib/internal/ByteArrayUtil.js.map +1 -1
  95. package/lib/internal/MPSC.d.ts +10 -0
  96. package/lib/internal/MPSC.js +49 -0
  97. package/lib/internal/MPSC.js.map +1 -0
  98. package/lib/internal/Singleton.js +6 -5
  99. package/lib/internal/Singleton.js.map +1 -1
  100. package/lib/internal/StreamUtil.d.ts +16 -6
  101. package/lib/internal/StreamUtil.js +43 -29
  102. package/lib/internal/StreamUtil.js.map +1 -1
  103. package/lib/internal/__map_take.js +5 -5
  104. package/lib/internal/__map_take.js.map +1 -1
  105. package/lib/json/IAgenticaEventJson.d.ts +7 -7
  106. package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
  107. package/lib/json/IAgenticaPromptJson.d.ts +2 -2
  108. package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
  109. package/lib/prompts/AgenticaCancelPrompt.js +1 -1
  110. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
  111. package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
  112. package/lib/prompts/AgenticaDescribePrompt.js +1 -1
  113. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
  114. package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
  115. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
  116. package/lib/prompts/AgenticaPrompt.d.ts +6 -6
  117. package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
  118. package/lib/prompts/AgenticaSelectPrompt.js +1 -1
  119. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
  120. package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
  121. package/lib/structures/IAgenticaConfig.d.ts +5 -5
  122. package/lib/structures/IAgenticaController.d.ts +1 -1
  123. package/lib/structures/IAgenticaExecutor.d.ts +4 -4
  124. package/lib/structures/IAgenticaProps.d.ts +5 -5
  125. package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
  126. package/lib/structures/IAgenticaVendor.d.ts +1 -1
  127. package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
  128. package/lib/transformers/AgenticaEventTransformer.js +105 -58
  129. package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
  130. package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
  131. package/lib/transformers/AgenticaPromptTransformer.js +74 -45
  132. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
  133. package/package.json +20 -23
  134. package/prompts/cancel.md +1 -1
  135. package/prompts/common.md +1 -1
  136. package/prompts/describe.md +1 -1
  137. package/prompts/execute.md +1 -1
  138. package/prompts/initialize.md +1 -1
  139. package/prompts/select.md +1 -1
  140. package/src/Agentica.ts +41 -31
  141. package/src/chatgpt/ChatGptAgent.ts +63 -57
  142. package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
  143. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
  144. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
  145. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
  146. package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
  147. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
  148. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
  149. package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
  150. package/src/context/AgenticaCancelPrompt.ts +4 -4
  151. package/src/context/AgenticaClassOperation.ts +5 -5
  152. package/src/context/AgenticaContext.ts +15 -15
  153. package/src/context/AgenticaHttpOperation.ts +5 -5
  154. package/src/context/AgenticaOperation.ts +4 -4
  155. package/src/context/AgenticaOperationBase.ts +1 -1
  156. package/src/context/AgenticaOperationCollection.ts +2 -2
  157. package/src/context/AgenticaOperationSelection.ts +3 -3
  158. package/src/context/AgenticaTokenUsage.ts +4 -3
  159. package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
  160. package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
  161. package/src/context/internal/__IChatInitialApplication.ts +2 -2
  162. package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
  163. package/src/events/AgenticaCallEvent.ts +3 -3
  164. package/src/events/AgenticaCancelEvent.ts +3 -3
  165. package/src/events/AgenticaDescribeEvent.ts +5 -5
  166. package/src/events/AgenticaEvent.ts +12 -12
  167. package/src/events/AgenticaExecuteEvent.ts +7 -7
  168. package/src/events/AgenticaInitializeEvent.ts +1 -1
  169. package/src/events/AgenticaRequestEvent.ts +3 -3
  170. package/src/events/AgenticaResponseEvent.ts +2 -2
  171. package/src/events/AgenticaSelectEvent.ts +4 -4
  172. package/src/events/AgenticaTextEvent.ts +2 -2
  173. package/src/functional/assertHttpLlmApplication.ts +9 -6
  174. package/src/functional/validateHttpLlmApplication.ts +14 -8
  175. package/src/index.ts +24 -24
  176. package/src/internal/AgenticaDefaultPrompt.ts +42 -28
  177. package/src/internal/AgenticaOperationComposer.ts +63 -61
  178. package/src/internal/AgenticaSystemPrompt.ts +15 -14
  179. package/src/internal/AsyncQueue.ts +67 -0
  180. package/src/internal/ByteArrayUtil.ts +2 -2
  181. package/src/internal/MPSC.ts +40 -0
  182. package/src/internal/Singleton.ts +8 -6
  183. package/src/internal/StreamUtil.ts +62 -53
  184. package/src/internal/__map_take.ts +5 -7
  185. package/src/json/IAgenticaEventJson.ts +7 -8
  186. package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
  187. package/src/json/IAgenticaPromptJson.ts +2 -2
  188. package/src/prompts/AgenticaCancelPrompt.ts +4 -4
  189. package/src/prompts/AgenticaDescribePrompt.ts +4 -4
  190. package/src/prompts/AgenticaExecutePrompt.ts +6 -5
  191. package/src/prompts/AgenticaPrompt.ts +6 -6
  192. package/src/prompts/AgenticaSelectPrompt.ts +4 -4
  193. package/src/prompts/AgenticaTextPrompt.ts +1 -1
  194. package/src/structures/IAgenticaConfig.ts +5 -5
  195. package/src/structures/IAgenticaController.ts +14 -14
  196. package/src/structures/IAgenticaExecutor.ts +4 -4
  197. package/src/structures/IAgenticaProps.ts +5 -5
  198. package/src/structures/IAgenticaSystemPrompt.ts +4 -4
  199. package/src/structures/IAgenticaVendor.ts +1 -1
  200. package/src/transformers/AgenticaEventTransformer.ts +169 -136
  201. package/src/transformers/AgenticaPromptTransformer.ts +125 -103
  202. package/lib/internal/MPSCUtil.d.ts +0 -35
  203. package/lib/internal/MPSCUtil.js +0 -105
  204. package/lib/internal/MPSCUtil.js.map +0 -1
  205. package/src/internal/MPSCUtil.ts +0 -111
@@ -34,503 +34,513 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.ChatGptCompletionMessageUtil = void 0;
37
+ exports.transformCompletionChunk = transformCompletionChunk;
38
+ exports.accumulate = accumulate;
39
+ exports.merge = merge;
40
+ exports.mergeChoice = mergeChoice;
41
+ exports.mergeToolCalls = mergeToolCalls;
37
42
  const __typia_transform__assertGuard = __importStar(require("typia/lib/internal/_assertGuard.js"));
38
43
  const typia_1 = require("typia");
39
44
  const ByteArrayUtil_1 = require("../internal/ByteArrayUtil");
40
45
  const ChatGptUsageAggregator_1 = require("./ChatGptUsageAggregator");
41
- var ChatGptCompletionMessageUtil;
42
- (function (ChatGptCompletionMessageUtil) {
43
- ChatGptCompletionMessageUtil.transformCompletionChunk = (source) => {
44
- const str = source instanceof Uint8Array ? ByteArrayUtil_1.ByteArrayUtil.toUtf8(source) : source;
45
- return (() => { const _io0 = input => "string" === typeof input.id && (Array.isArray(input.choices) && input.choices.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "number" === typeof input.created && "string" === typeof input.model && "chat.completion.chunk" === input.object && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint) && (null === input.usage || undefined === input.usage || "object" === typeof input.usage && null !== input.usage && _io9(input.usage)); const _io1 = input => "object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) && _io2(input.delta) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason) && "number" === typeof input.index && (null === input.logprobs || undefined === input.logprobs || "object" === typeof input.logprobs && null !== input.logprobs && _io6(input.logprobs)); const _io2 = input => (null === input.content || undefined === input.content || "string" === typeof input.content) && (undefined === input.function_call || "object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) && _io3(input.function_call)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role) && (undefined === input.tool_calls || Array.isArray(input.tool_calls) && input.tool_calls.every(elem => "object" === typeof elem && null !== elem && _io4(elem))); const _io3 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io4 = input => "number" === typeof input.index && (undefined === input.id || "string" === typeof input.id) && (undefined === input["function"] || "object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) && _io5(input["function"])) && (undefined === input.type || "function" === input.type); const _io5 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io6 = input => (null === input.content || Array.isArray(input.content) && input.content.every(elem => "object" === typeof elem && null !== elem && _io7(elem))) && (null === input.refusal || Array.isArray(input.refusal) && input.refusal.every(elem => "object" === typeof elem && null !== elem && _io7(elem))); const _io7 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob && (Array.isArray(input.top_logprobs) && input.top_logprobs.every(elem => "object" === typeof elem && null !== elem && _io8(elem))); const _io8 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob; const _io9 = input => "number" === typeof input.completion_tokens && "number" === typeof input.prompt_tokens && "number" === typeof input.total_tokens && (undefined === input.completion_tokens_details || "object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) && _io10(input.completion_tokens_details)) && (undefined === input.prompt_tokens_details || "object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) && _io11(input.prompt_tokens_details)); const _io10 = input => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens); const _io11 = input => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens); const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
46
- method: "json.assertParse",
47
- path: _path + ".id",
48
- expected: "string",
49
- value: input.id
50
- }, _errorFactory)) && ((Array.isArray(input.choices) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
51
- method: "json.assertParse",
52
- path: _path + ".choices",
53
- expected: "Array<ChatCompletionChunk.Choice>",
54
- value: input.choices
55
- }, _errorFactory)) && input.choices.every((elem, _index8) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
56
- method: "json.assertParse",
57
- path: _path + ".choices[" + _index8 + "]",
58
- expected: "ChatCompletionChunk.Choice",
59
- value: elem
60
- }, _errorFactory)) && _ao1(elem, _path + ".choices[" + _index8 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
61
- method: "json.assertParse",
62
- path: _path + ".choices[" + _index8 + "]",
63
- expected: "ChatCompletionChunk.Choice",
64
- value: elem
65
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
66
- method: "json.assertParse",
67
- path: _path + ".choices",
68
- expected: "Array<ChatCompletionChunk.Choice>",
69
- value: input.choices
70
- }, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
71
- method: "json.assertParse",
72
- path: _path + ".created",
73
- expected: "number",
74
- value: input.created
75
- }, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
76
- method: "json.assertParse",
77
- path: _path + ".model",
78
- expected: "string",
79
- value: input.model
80
- }, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
81
- method: "json.assertParse",
82
- path: _path + ".object",
83
- expected: "\"chat.completion.chunk\"",
84
- value: input.object
85
- }, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
86
- method: "json.assertParse",
87
- path: _path + ".service_tier",
88
- expected: "(\"default\" | \"scale\" | null | undefined)",
89
- value: input.service_tier
90
- }, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
91
- method: "json.assertParse",
92
- path: _path + ".system_fingerprint",
93
- expected: "(string | undefined)",
94
- value: input.system_fingerprint
95
- }, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
96
- method: "json.assertParse",
97
- path: _path + ".usage",
98
- expected: "(CompletionUsage | null | undefined)",
99
- value: input.usage
100
- }, _errorFactory)) && _ao9(input.usage, _path + ".usage", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
101
- method: "json.assertParse",
102
- path: _path + ".usage",
103
- expected: "(CompletionUsage | null | undefined)",
104
- value: input.usage
105
- }, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
106
- method: "json.assertParse",
107
- path: _path + ".delta",
108
- expected: "ChatCompletionChunk.Choice.Delta",
109
- value: input.delta
110
- }, _errorFactory)) && _ao2(input.delta, _path + ".delta", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
111
- method: "json.assertParse",
112
- path: _path + ".delta",
113
- expected: "ChatCompletionChunk.Choice.Delta",
114
- value: input.delta
115
- }, _errorFactory)) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason || __typia_transform__assertGuard._assertGuard(_exceptionable, {
116
- method: "json.assertParse",
117
- path: _path + ".finish_reason",
118
- expected: "(\"content_filter\" | \"function_call\" | \"length\" | \"stop\" | \"tool_calls\" | null)",
119
- value: input.finish_reason
120
- }, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
121
- method: "json.assertParse",
122
- path: _path + ".index",
123
- expected: "number",
124
- value: input.index
125
- }, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
126
- method: "json.assertParse",
127
- path: _path + ".logprobs",
128
- expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
129
- value: input.logprobs
130
- }, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
131
- method: "json.assertParse",
132
- path: _path + ".logprobs",
133
- expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
134
- value: input.logprobs
135
- }, _errorFactory)); const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
136
- method: "json.assertParse",
137
- path: _path + ".content",
138
- expected: "(null | string | undefined)",
139
- value: input.content
140
- }, _errorFactory)) && (undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
141
- method: "json.assertParse",
142
- path: _path + ".function_call",
143
- expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
144
- value: input.function_call
145
- }, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
146
- method: "json.assertParse",
147
- path: _path + ".function_call",
148
- expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
149
- value: input.function_call
150
- }, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
151
- method: "json.assertParse",
152
- path: _path + ".refusal",
153
- expected: "(null | string | undefined)",
154
- value: input.refusal
155
- }, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
156
- method: "json.assertParse",
157
- path: _path + ".role",
158
- expected: "(\"assistant\" | \"developer\" | \"system\" | \"tool\" | \"user\" | undefined)",
159
- value: input.role
160
- }, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
161
- method: "json.assertParse",
162
- path: _path + ".tool_calls",
163
- expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
164
- value: input.tool_calls
165
- }, _errorFactory)) && input.tool_calls.every((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
166
- method: "json.assertParse",
167
- path: _path + ".tool_calls[" + _index9 + "]",
168
- expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
169
- value: elem
170
- }, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
171
- method: "json.assertParse",
172
- path: _path + ".tool_calls[" + _index9 + "]",
173
- expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
174
- value: elem
175
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
176
- method: "json.assertParse",
177
- path: _path + ".tool_calls",
178
- expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
179
- value: input.tool_calls
180
- }, _errorFactory)); const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
181
- method: "json.assertParse",
182
- path: _path + ".arguments",
183
- expected: "(string | undefined)",
184
- value: input.arguments
185
- }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
186
- method: "json.assertParse",
187
- path: _path + ".name",
188
- expected: "(string | undefined)",
189
- value: input.name
190
- }, _errorFactory)); const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
191
- method: "json.assertParse",
192
- path: _path + ".index",
193
- expected: "number",
194
- value: input.index
195
- }, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
196
- method: "json.assertParse",
197
- path: _path + ".id",
198
- expected: "(string | undefined)",
199
- value: input.id
200
- }, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
201
- method: "json.assertParse",
202
- path: _path + "[\"function\"]",
203
- expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
204
- value: input["function"]
205
- }, _errorFactory)) && _ao5(input["function"], _path + "[\"function\"]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
206
- method: "json.assertParse",
207
- path: _path + "[\"function\"]",
208
- expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
209
- value: input["function"]
210
- }, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
211
- method: "json.assertParse",
212
- path: _path + ".type",
213
- expected: "(\"function\" | undefined)",
214
- value: input.type
215
- }, _errorFactory)); const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
216
- method: "json.assertParse",
217
- path: _path + ".arguments",
218
- expected: "(string | undefined)",
219
- value: input.arguments
220
- }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
221
- method: "json.assertParse",
222
- path: _path + ".name",
223
- expected: "(string | undefined)",
224
- value: input.name
225
- }, _errorFactory)); const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
226
- method: "json.assertParse",
227
- path: _path + ".content",
228
- expected: "(Array<ChatCompletionTokenLogprob> | null)",
229
- value: input.content
230
- }, _errorFactory)) && input.content.every((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
231
- method: "json.assertParse",
232
- path: _path + ".content[" + _index10 + "]",
233
- expected: "ChatCompletionTokenLogprob",
234
- value: elem
235
- }, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
236
- method: "json.assertParse",
237
- path: _path + ".content[" + _index10 + "]",
238
- expected: "ChatCompletionTokenLogprob",
239
- value: elem
240
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
241
- method: "json.assertParse",
242
- path: _path + ".content",
243
- expected: "(Array<ChatCompletionTokenLogprob> | null)",
244
- value: input.content
245
- }, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
246
- method: "json.assertParse",
247
- path: _path + ".refusal",
248
- expected: "(Array<ChatCompletionTokenLogprob> | null)",
249
- value: input.refusal
250
- }, _errorFactory)) && input.refusal.every((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
251
- method: "json.assertParse",
252
- path: _path + ".refusal[" + _index11 + "]",
253
- expected: "ChatCompletionTokenLogprob",
254
- value: elem
255
- }, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
256
- method: "json.assertParse",
257
- path: _path + ".refusal[" + _index11 + "]",
258
- expected: "ChatCompletionTokenLogprob",
259
- value: elem
260
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
261
- method: "json.assertParse",
262
- path: _path + ".refusal",
263
- expected: "(Array<ChatCompletionTokenLogprob> | null)",
264
- value: input.refusal
265
- }, _errorFactory)); const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
266
- method: "json.assertParse",
267
- path: _path + ".token",
268
- expected: "string",
269
- value: input.token
270
- }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
271
- method: "json.assertParse",
272
- path: _path + ".bytes",
273
- expected: "(Array<number> | null)",
274
- value: input.bytes
275
- }, _errorFactory)) && input.bytes.every((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
276
- method: "json.assertParse",
277
- path: _path + ".bytes[" + _index12 + "]",
278
- expected: "number",
279
- value: elem
280
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
281
- method: "json.assertParse",
282
- path: _path + ".bytes",
283
- expected: "(Array<number> | null)",
284
- value: input.bytes
285
- }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
286
- method: "json.assertParse",
287
- path: _path + ".logprob",
288
- expected: "number",
289
- value: input.logprob
290
- }, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
291
- method: "json.assertParse",
292
- path: _path + ".top_logprobs",
293
- expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
294
- value: input.top_logprobs
295
- }, _errorFactory)) && input.top_logprobs.every((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
296
- method: "json.assertParse",
297
- path: _path + ".top_logprobs[" + _index13 + "]",
298
- expected: "ChatCompletionTokenLogprob.TopLogprob",
299
- value: elem
300
- }, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
301
- method: "json.assertParse",
302
- path: _path + ".top_logprobs[" + _index13 + "]",
303
- expected: "ChatCompletionTokenLogprob.TopLogprob",
304
- value: elem
305
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
306
- method: "json.assertParse",
307
- path: _path + ".top_logprobs",
308
- expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
309
- value: input.top_logprobs
310
- }, _errorFactory)); const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
311
- method: "json.assertParse",
312
- path: _path + ".token",
313
- expected: "string",
314
- value: input.token
315
- }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
316
- method: "json.assertParse",
317
- path: _path + ".bytes",
318
- expected: "(Array<number> | null)",
319
- value: input.bytes
320
- }, _errorFactory)) && input.bytes.every((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
321
- method: "json.assertParse",
322
- path: _path + ".bytes[" + _index14 + "]",
323
- expected: "number",
324
- value: elem
325
- }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
326
- method: "json.assertParse",
327
- path: _path + ".bytes",
328
- expected: "(Array<number> | null)",
329
- value: input.bytes
330
- }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
331
- method: "json.assertParse",
332
- path: _path + ".logprob",
333
- expected: "number",
334
- value: input.logprob
335
- }, _errorFactory)); const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
336
- method: "json.assertParse",
337
- path: _path + ".completion_tokens",
338
- expected: "number",
339
- value: input.completion_tokens
340
- }, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
341
- method: "json.assertParse",
342
- path: _path + ".prompt_tokens",
343
- expected: "number",
344
- value: input.prompt_tokens
345
- }, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
346
- method: "json.assertParse",
347
- path: _path + ".total_tokens",
348
- expected: "number",
349
- value: input.total_tokens
350
- }, _errorFactory)) && (undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
351
- method: "json.assertParse",
352
- path: _path + ".completion_tokens_details",
353
- expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
354
- value: input.completion_tokens_details
355
- }, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
356
- method: "json.assertParse",
357
- path: _path + ".completion_tokens_details",
358
- expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
359
- value: input.completion_tokens_details
360
- }, _errorFactory)) && (undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
361
- method: "json.assertParse",
362
- path: _path + ".prompt_tokens_details",
363
- expected: "(CompletionUsage.PromptTokensDetails | undefined)",
364
- value: input.prompt_tokens_details
365
- }, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
366
- method: "json.assertParse",
367
- path: _path + ".prompt_tokens_details",
368
- expected: "(CompletionUsage.PromptTokensDetails | undefined)",
369
- value: input.prompt_tokens_details
370
- }, _errorFactory)); const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
371
- method: "json.assertParse",
372
- path: _path + ".accepted_prediction_tokens",
373
- expected: "(number | undefined)",
374
- value: input.accepted_prediction_tokens
375
- }, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
376
- method: "json.assertParse",
377
- path: _path + ".audio_tokens",
378
- expected: "(number | undefined)",
379
- value: input.audio_tokens
380
- }, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
381
- method: "json.assertParse",
382
- path: _path + ".reasoning_tokens",
383
- expected: "(number | undefined)",
384
- value: input.reasoning_tokens
385
- }, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
386
- method: "json.assertParse",
387
- path: _path + ".rejected_prediction_tokens",
388
- expected: "(number | undefined)",
389
- value: input.rejected_prediction_tokens
390
- }, _errorFactory)); const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
391
- method: "json.assertParse",
392
- path: _path + ".audio_tokens",
393
- expected: "(number | undefined)",
394
- value: input.audio_tokens
395
- }, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
396
- method: "json.assertParse",
397
- path: _path + ".cached_tokens",
398
- expected: "(number | undefined)",
399
- value: input.cached_tokens
400
- }, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; const __assert = (input, errorFactory) => {
401
- if (false === __is(input)) {
402
- _errorFactory = errorFactory;
403
- ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
404
- method: "json.assertParse",
405
- path: _path + "",
406
- expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
407
- value: input
408
- }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
409
- method: "json.assertParse",
410
- path: _path + "",
411
- expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
412
- value: input
413
- }, _errorFactory))(input, "$input", true);
414
- }
415
- return input;
416
- }; return (input, errorFactory) => __assert(JSON.parse(input), errorFactory); })()(str);
417
- };
418
- ChatGptCompletionMessageUtil.accumulate = (origin, chunk) => {
419
- const choices = origin.choices;
420
- chunk.choices.forEach((choice) => {
421
- var _a, _b, _c, _d;
422
- const accChoice = choices[choice.index];
423
- if (accChoice) {
424
- choices[choice.index] = ChatGptCompletionMessageUtil.mergeChoice(accChoice, choice);
425
- return;
426
- }
427
- choices[choice.index] = {
428
- index: choice.index,
429
- finish_reason: (_a = choice.finish_reason) !== null && _a !== void 0 ? _a : null,
430
- logprobs: (_b = choice.logprobs) !== null && _b !== void 0 ? _b : null,
431
- message: {
432
- tool_calls: choice.delta.tool_calls
433
- ? choice.delta.tool_calls.reduce((acc, cur) => {
434
- var _a, _b, _c, _d, _e;
435
- acc[cur.index] = {
436
- id: (_a = cur.id) !== null && _a !== void 0 ? _a : "",
437
- type: "function",
438
- function: {
439
- name: (_c = (_b = cur.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
440
- arguments: (_e = (_d = cur.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
441
- },
442
- };
443
- return acc;
444
- }, [])
445
- : undefined,
446
- content: (_c = choice.delta.content) !== null && _c !== void 0 ? _c : null,
447
- refusal: (_d = choice.delta.refusal) !== null && _d !== void 0 ? _d : null,
448
- role: "assistant",
449
- },
450
- };
451
- });
452
- const usage = (() => {
453
- if (!chunk.usage) {
454
- return origin.usage;
455
- }
456
- if (!origin.usage) {
457
- return chunk.usage;
458
- }
459
- return ChatGptUsageAggregator_1.ChatGptUsageAggregator.sum(origin.usage, chunk.usage);
460
- })();
461
- return Object.assign(Object.assign({}, origin), { choices,
462
- usage });
463
- };
464
- ChatGptCompletionMessageUtil.merge = (chunks) => {
465
- const firstChunk = chunks[0];
466
- if (!firstChunk)
467
- throw new Error("No chunks received");
468
- return chunks.reduce(ChatGptCompletionMessageUtil.accumulate, {
469
- id: firstChunk.id,
470
- choices: [],
471
- created: firstChunk.created,
472
- model: firstChunk.model,
473
- object: "chat.completion",
474
- usage: undefined,
475
- service_tier: firstChunk.service_tier,
476
- system_fingerprint: firstChunk.system_fingerprint,
477
- });
478
- };
479
- ChatGptCompletionMessageUtil.mergeChoice = (acc, cur) => {
480
- var _a;
481
- var _b;
482
- if (!acc.finish_reason && cur.finish_reason) {
483
- acc.finish_reason = cur.finish_reason;
46
+ function transformCompletionChunk(source) {
47
+ const str = source instanceof Uint8Array ? ByteArrayUtil_1.ByteArrayUtil.toUtf8(source) : source;
48
+ return (() => { const _io0 = input => "string" === typeof input.id && (Array.isArray(input.choices) && input.choices.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "number" === typeof input.created && "string" === typeof input.model && "chat.completion.chunk" === input.object && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint) && (null === input.usage || undefined === input.usage || "object" === typeof input.usage && null !== input.usage && _io9(input.usage)); const _io1 = input => "object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) && _io2(input.delta) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason) && "number" === typeof input.index && (null === input.logprobs || undefined === input.logprobs || "object" === typeof input.logprobs && null !== input.logprobs && _io6(input.logprobs)); const _io2 = input => (null === input.content || undefined === input.content || "string" === typeof input.content) && (undefined === input.function_call || "object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) && _io3(input.function_call)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role) && (undefined === input.tool_calls || Array.isArray(input.tool_calls) && input.tool_calls.every(elem => "object" === typeof elem && null !== elem && _io4(elem))); const _io3 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io4 = input => "number" === typeof input.index && (undefined === input.id || "string" === typeof input.id) && (undefined === input["function"] || "object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) && _io5(input["function"])) && (undefined === input.type || "function" === input.type); const _io5 = input => (undefined === input.arguments || "string" === typeof input.arguments) && (undefined === input.name || "string" === typeof input.name); const _io6 = input => (null === input.content || Array.isArray(input.content) && input.content.every(elem => "object" === typeof elem && null !== elem && _io7(elem))) && (null === input.refusal || Array.isArray(input.refusal) && input.refusal.every(elem => "object" === typeof elem && null !== elem && _io7(elem))); const _io7 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob && (Array.isArray(input.top_logprobs) && input.top_logprobs.every(elem => "object" === typeof elem && null !== elem && _io8(elem))); const _io8 = input => "string" === typeof input.token && (null === input.bytes || Array.isArray(input.bytes) && input.bytes.every(elem => "number" === typeof elem)) && "number" === typeof input.logprob; const _io9 = input => "number" === typeof input.completion_tokens && "number" === typeof input.prompt_tokens && "number" === typeof input.total_tokens && (undefined === input.completion_tokens_details || "object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) && _io10(input.completion_tokens_details)) && (undefined === input.prompt_tokens_details || "object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) && _io11(input.prompt_tokens_details)); const _io10 = input => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens); const _io11 = input => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens); const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
49
+ method: "json.assertParse",
50
+ path: _path + ".id",
51
+ expected: "string",
52
+ value: input.id
53
+ }, _errorFactory)) && ((Array.isArray(input.choices) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
54
+ method: "json.assertParse",
55
+ path: _path + ".choices",
56
+ expected: "Array<ChatCompletionChunk.Choice>",
57
+ value: input.choices
58
+ }, _errorFactory)) && input.choices.every((elem, _index8) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
59
+ method: "json.assertParse",
60
+ path: _path + ".choices[" + _index8 + "]",
61
+ expected: "ChatCompletionChunk.Choice",
62
+ value: elem
63
+ }, _errorFactory)) && _ao1(elem, _path + ".choices[" + _index8 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
64
+ method: "json.assertParse",
65
+ path: _path + ".choices[" + _index8 + "]",
66
+ expected: "ChatCompletionChunk.Choice",
67
+ value: elem
68
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
69
+ method: "json.assertParse",
70
+ path: _path + ".choices",
71
+ expected: "Array<ChatCompletionChunk.Choice>",
72
+ value: input.choices
73
+ }, _errorFactory)) && ("number" === typeof input.created || __typia_transform__assertGuard._assertGuard(_exceptionable, {
74
+ method: "json.assertParse",
75
+ path: _path + ".created",
76
+ expected: "number",
77
+ value: input.created
78
+ }, _errorFactory)) && ("string" === typeof input.model || __typia_transform__assertGuard._assertGuard(_exceptionable, {
79
+ method: "json.assertParse",
80
+ path: _path + ".model",
81
+ expected: "string",
82
+ value: input.model
83
+ }, _errorFactory)) && ("chat.completion.chunk" === input.object || __typia_transform__assertGuard._assertGuard(_exceptionable, {
84
+ method: "json.assertParse",
85
+ path: _path + ".object",
86
+ expected: "\"chat.completion.chunk\"",
87
+ value: input.object
88
+ }, _errorFactory)) && (null === input.service_tier || undefined === input.service_tier || "scale" === input.service_tier || "default" === input.service_tier || __typia_transform__assertGuard._assertGuard(_exceptionable, {
89
+ method: "json.assertParse",
90
+ path: _path + ".service_tier",
91
+ expected: "(\"default\" | \"scale\" | null | undefined)",
92
+ value: input.service_tier
93
+ }, _errorFactory)) && (undefined === input.system_fingerprint || "string" === typeof input.system_fingerprint || __typia_transform__assertGuard._assertGuard(_exceptionable, {
94
+ method: "json.assertParse",
95
+ path: _path + ".system_fingerprint",
96
+ expected: "(string | undefined)",
97
+ value: input.system_fingerprint
98
+ }, _errorFactory)) && (null === input.usage || undefined === input.usage || ("object" === typeof input.usage && null !== input.usage || __typia_transform__assertGuard._assertGuard(_exceptionable, {
99
+ method: "json.assertParse",
100
+ path: _path + ".usage",
101
+ expected: "(CompletionUsage | null | undefined)",
102
+ value: input.usage
103
+ }, _errorFactory)) && _ao9(input.usage, _path + ".usage", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
104
+ method: "json.assertParse",
105
+ path: _path + ".usage",
106
+ expected: "(CompletionUsage | null | undefined)",
107
+ value: input.usage
108
+ }, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => (("object" === typeof input.delta && null !== input.delta && false === Array.isArray(input.delta) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
109
+ method: "json.assertParse",
110
+ path: _path + ".delta",
111
+ expected: "ChatCompletionChunk.Choice.Delta",
112
+ value: input.delta
113
+ }, _errorFactory)) && _ao2(input.delta, _path + ".delta", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
114
+ method: "json.assertParse",
115
+ path: _path + ".delta",
116
+ expected: "ChatCompletionChunk.Choice.Delta",
117
+ value: input.delta
118
+ }, _errorFactory)) && (null === input.finish_reason || "function_call" === input.finish_reason || "stop" === input.finish_reason || "length" === input.finish_reason || "tool_calls" === input.finish_reason || "content_filter" === input.finish_reason || __typia_transform__assertGuard._assertGuard(_exceptionable, {
119
+ method: "json.assertParse",
120
+ path: _path + ".finish_reason",
121
+ expected: "(\"content_filter\" | \"function_call\" | \"length\" | \"stop\" | \"tool_calls\" | null)",
122
+ value: input.finish_reason
123
+ }, _errorFactory)) && ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
124
+ method: "json.assertParse",
125
+ path: _path + ".index",
126
+ expected: "number",
127
+ value: input.index
128
+ }, _errorFactory)) && (null === input.logprobs || undefined === input.logprobs || ("object" === typeof input.logprobs && null !== input.logprobs || __typia_transform__assertGuard._assertGuard(_exceptionable, {
129
+ method: "json.assertParse",
130
+ path: _path + ".logprobs",
131
+ expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
132
+ value: input.logprobs
133
+ }, _errorFactory)) && _ao6(input.logprobs, _path + ".logprobs", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
134
+ method: "json.assertParse",
135
+ path: _path + ".logprobs",
136
+ expected: "(ChatCompletionChunk.Choice.Logprobs | null | undefined)",
137
+ value: input.logprobs
138
+ }, _errorFactory)); const _ao2 = (input, _path, _exceptionable = true) => (null === input.content || undefined === input.content || "string" === typeof input.content || __typia_transform__assertGuard._assertGuard(_exceptionable, {
139
+ method: "json.assertParse",
140
+ path: _path + ".content",
141
+ expected: "(null | string | undefined)",
142
+ value: input.content
143
+ }, _errorFactory)) && (undefined === input.function_call || ("object" === typeof input.function_call && null !== input.function_call && false === Array.isArray(input.function_call) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
144
+ method: "json.assertParse",
145
+ path: _path + ".function_call",
146
+ expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
147
+ value: input.function_call
148
+ }, _errorFactory)) && _ao3(input.function_call, _path + ".function_call", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
149
+ method: "json.assertParse",
150
+ path: _path + ".function_call",
151
+ expected: "(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",
152
+ value: input.function_call
153
+ }, _errorFactory)) && (null === input.refusal || undefined === input.refusal || "string" === typeof input.refusal || __typia_transform__assertGuard._assertGuard(_exceptionable, {
154
+ method: "json.assertParse",
155
+ path: _path + ".refusal",
156
+ expected: "(null | string | undefined)",
157
+ value: input.refusal
158
+ }, _errorFactory)) && (undefined === input.role || "assistant" === input.role || "user" === input.role || "developer" === input.role || "system" === input.role || "tool" === input.role || __typia_transform__assertGuard._assertGuard(_exceptionable, {
159
+ method: "json.assertParse",
160
+ path: _path + ".role",
161
+ expected: "(\"assistant\" | \"developer\" | \"system\" | \"tool\" | \"user\" | undefined)",
162
+ value: input.role
163
+ }, _errorFactory)) && (undefined === input.tool_calls || (Array.isArray(input.tool_calls) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
164
+ method: "json.assertParse",
165
+ path: _path + ".tool_calls",
166
+ expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
167
+ value: input.tool_calls
168
+ }, _errorFactory)) && input.tool_calls.every((elem, _index9) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
169
+ method: "json.assertParse",
170
+ path: _path + ".tool_calls[" + _index9 + "]",
171
+ expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
172
+ value: elem
173
+ }, _errorFactory)) && _ao4(elem, _path + ".tool_calls[" + _index9 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
174
+ method: "json.assertParse",
175
+ path: _path + ".tool_calls[" + _index9 + "]",
176
+ expected: "ChatCompletionChunk.Choice.Delta.ToolCall",
177
+ value: elem
178
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
179
+ method: "json.assertParse",
180
+ path: _path + ".tool_calls",
181
+ expected: "(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",
182
+ value: input.tool_calls
183
+ }, _errorFactory)); const _ao3 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
184
+ method: "json.assertParse",
185
+ path: _path + ".arguments",
186
+ expected: "(string | undefined)",
187
+ value: input.arguments
188
+ }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
189
+ method: "json.assertParse",
190
+ path: _path + ".name",
191
+ expected: "(string | undefined)",
192
+ value: input.name
193
+ }, _errorFactory)); const _ao4 = (input, _path, _exceptionable = true) => ("number" === typeof input.index || __typia_transform__assertGuard._assertGuard(_exceptionable, {
194
+ method: "json.assertParse",
195
+ path: _path + ".index",
196
+ expected: "number",
197
+ value: input.index
198
+ }, _errorFactory)) && (undefined === input.id || "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
199
+ method: "json.assertParse",
200
+ path: _path + ".id",
201
+ expected: "(string | undefined)",
202
+ value: input.id
203
+ }, _errorFactory)) && (undefined === input["function"] || ("object" === typeof input["function"] && null !== input["function"] && false === Array.isArray(input["function"]) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
204
+ method: "json.assertParse",
205
+ path: _path + "[\"function\"]",
206
+ expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
207
+ value: input["function"]
208
+ }, _errorFactory)) && _ao5(input["function"], _path + "[\"function\"]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
209
+ method: "json.assertParse",
210
+ path: _path + "[\"function\"]",
211
+ expected: "(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",
212
+ value: input["function"]
213
+ }, _errorFactory)) && (undefined === input.type || "function" === input.type || __typia_transform__assertGuard._assertGuard(_exceptionable, {
214
+ method: "json.assertParse",
215
+ path: _path + ".type",
216
+ expected: "(\"function\" | undefined)",
217
+ value: input.type
218
+ }, _errorFactory)); const _ao5 = (input, _path, _exceptionable = true) => (undefined === input.arguments || "string" === typeof input.arguments || __typia_transform__assertGuard._assertGuard(_exceptionable, {
219
+ method: "json.assertParse",
220
+ path: _path + ".arguments",
221
+ expected: "(string | undefined)",
222
+ value: input.arguments
223
+ }, _errorFactory)) && (undefined === input.name || "string" === typeof input.name || __typia_transform__assertGuard._assertGuard(_exceptionable, {
224
+ method: "json.assertParse",
225
+ path: _path + ".name",
226
+ expected: "(string | undefined)",
227
+ value: input.name
228
+ }, _errorFactory)); const _ao6 = (input, _path, _exceptionable = true) => (null === input.content || (Array.isArray(input.content) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
229
+ method: "json.assertParse",
230
+ path: _path + ".content",
231
+ expected: "(Array<ChatCompletionTokenLogprob> | null)",
232
+ value: input.content
233
+ }, _errorFactory)) && input.content.every((elem, _index10) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
234
+ method: "json.assertParse",
235
+ path: _path + ".content[" + _index10 + "]",
236
+ expected: "ChatCompletionTokenLogprob",
237
+ value: elem
238
+ }, _errorFactory)) && _ao7(elem, _path + ".content[" + _index10 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
239
+ method: "json.assertParse",
240
+ path: _path + ".content[" + _index10 + "]",
241
+ expected: "ChatCompletionTokenLogprob",
242
+ value: elem
243
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
244
+ method: "json.assertParse",
245
+ path: _path + ".content",
246
+ expected: "(Array<ChatCompletionTokenLogprob> | null)",
247
+ value: input.content
248
+ }, _errorFactory)) && (null === input.refusal || (Array.isArray(input.refusal) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
249
+ method: "json.assertParse",
250
+ path: _path + ".refusal",
251
+ expected: "(Array<ChatCompletionTokenLogprob> | null)",
252
+ value: input.refusal
253
+ }, _errorFactory)) && input.refusal.every((elem, _index11) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
254
+ method: "json.assertParse",
255
+ path: _path + ".refusal[" + _index11 + "]",
256
+ expected: "ChatCompletionTokenLogprob",
257
+ value: elem
258
+ }, _errorFactory)) && _ao7(elem, _path + ".refusal[" + _index11 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
259
+ method: "json.assertParse",
260
+ path: _path + ".refusal[" + _index11 + "]",
261
+ expected: "ChatCompletionTokenLogprob",
262
+ value: elem
263
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
264
+ method: "json.assertParse",
265
+ path: _path + ".refusal",
266
+ expected: "(Array<ChatCompletionTokenLogprob> | null)",
267
+ value: input.refusal
268
+ }, _errorFactory)); const _ao7 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
269
+ method: "json.assertParse",
270
+ path: _path + ".token",
271
+ expected: "string",
272
+ value: input.token
273
+ }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
274
+ method: "json.assertParse",
275
+ path: _path + ".bytes",
276
+ expected: "(Array<number> | null)",
277
+ value: input.bytes
278
+ }, _errorFactory)) && input.bytes.every((elem, _index12) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
279
+ method: "json.assertParse",
280
+ path: _path + ".bytes[" + _index12 + "]",
281
+ expected: "number",
282
+ value: elem
283
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
284
+ method: "json.assertParse",
285
+ path: _path + ".bytes",
286
+ expected: "(Array<number> | null)",
287
+ value: input.bytes
288
+ }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
289
+ method: "json.assertParse",
290
+ path: _path + ".logprob",
291
+ expected: "number",
292
+ value: input.logprob
293
+ }, _errorFactory)) && ((Array.isArray(input.top_logprobs) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
294
+ method: "json.assertParse",
295
+ path: _path + ".top_logprobs",
296
+ expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
297
+ value: input.top_logprobs
298
+ }, _errorFactory)) && input.top_logprobs.every((elem, _index13) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
299
+ method: "json.assertParse",
300
+ path: _path + ".top_logprobs[" + _index13 + "]",
301
+ expected: "ChatCompletionTokenLogprob.TopLogprob",
302
+ value: elem
303
+ }, _errorFactory)) && _ao8(elem, _path + ".top_logprobs[" + _index13 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
304
+ method: "json.assertParse",
305
+ path: _path + ".top_logprobs[" + _index13 + "]",
306
+ expected: "ChatCompletionTokenLogprob.TopLogprob",
307
+ value: elem
308
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
309
+ method: "json.assertParse",
310
+ path: _path + ".top_logprobs",
311
+ expected: "Array<ChatCompletionTokenLogprob.TopLogprob>",
312
+ value: input.top_logprobs
313
+ }, _errorFactory)); const _ao8 = (input, _path, _exceptionable = true) => ("string" === typeof input.token || __typia_transform__assertGuard._assertGuard(_exceptionable, {
314
+ method: "json.assertParse",
315
+ path: _path + ".token",
316
+ expected: "string",
317
+ value: input.token
318
+ }, _errorFactory)) && (null === input.bytes || (Array.isArray(input.bytes) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
319
+ method: "json.assertParse",
320
+ path: _path + ".bytes",
321
+ expected: "(Array<number> | null)",
322
+ value: input.bytes
323
+ }, _errorFactory)) && input.bytes.every((elem, _index14) => "number" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
324
+ method: "json.assertParse",
325
+ path: _path + ".bytes[" + _index14 + "]",
326
+ expected: "number",
327
+ value: elem
328
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
329
+ method: "json.assertParse",
330
+ path: _path + ".bytes",
331
+ expected: "(Array<number> | null)",
332
+ value: input.bytes
333
+ }, _errorFactory)) && ("number" === typeof input.logprob || __typia_transform__assertGuard._assertGuard(_exceptionable, {
334
+ method: "json.assertParse",
335
+ path: _path + ".logprob",
336
+ expected: "number",
337
+ value: input.logprob
338
+ }, _errorFactory)); const _ao9 = (input, _path, _exceptionable = true) => ("number" === typeof input.completion_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
339
+ method: "json.assertParse",
340
+ path: _path + ".completion_tokens",
341
+ expected: "number",
342
+ value: input.completion_tokens
343
+ }, _errorFactory)) && ("number" === typeof input.prompt_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
344
+ method: "json.assertParse",
345
+ path: _path + ".prompt_tokens",
346
+ expected: "number",
347
+ value: input.prompt_tokens
348
+ }, _errorFactory)) && ("number" === typeof input.total_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
349
+ method: "json.assertParse",
350
+ path: _path + ".total_tokens",
351
+ expected: "number",
352
+ value: input.total_tokens
353
+ }, _errorFactory)) && (undefined === input.completion_tokens_details || ("object" === typeof input.completion_tokens_details && null !== input.completion_tokens_details && false === Array.isArray(input.completion_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
354
+ method: "json.assertParse",
355
+ path: _path + ".completion_tokens_details",
356
+ expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
357
+ value: input.completion_tokens_details
358
+ }, _errorFactory)) && _ao10(input.completion_tokens_details, _path + ".completion_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
359
+ method: "json.assertParse",
360
+ path: _path + ".completion_tokens_details",
361
+ expected: "(CompletionUsage.CompletionTokensDetails | undefined)",
362
+ value: input.completion_tokens_details
363
+ }, _errorFactory)) && (undefined === input.prompt_tokens_details || ("object" === typeof input.prompt_tokens_details && null !== input.prompt_tokens_details && false === Array.isArray(input.prompt_tokens_details) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
364
+ method: "json.assertParse",
365
+ path: _path + ".prompt_tokens_details",
366
+ expected: "(CompletionUsage.PromptTokensDetails | undefined)",
367
+ value: input.prompt_tokens_details
368
+ }, _errorFactory)) && _ao11(input.prompt_tokens_details, _path + ".prompt_tokens_details", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
369
+ method: "json.assertParse",
370
+ path: _path + ".prompt_tokens_details",
371
+ expected: "(CompletionUsage.PromptTokensDetails | undefined)",
372
+ value: input.prompt_tokens_details
373
+ }, _errorFactory)); const _ao10 = (input, _path, _exceptionable = true) => (undefined === input.accepted_prediction_tokens || "number" === typeof input.accepted_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
374
+ method: "json.assertParse",
375
+ path: _path + ".accepted_prediction_tokens",
376
+ expected: "(number | undefined)",
377
+ value: input.accepted_prediction_tokens
378
+ }, _errorFactory)) && (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
379
+ method: "json.assertParse",
380
+ path: _path + ".audio_tokens",
381
+ expected: "(number | undefined)",
382
+ value: input.audio_tokens
383
+ }, _errorFactory)) && (undefined === input.reasoning_tokens || "number" === typeof input.reasoning_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
384
+ method: "json.assertParse",
385
+ path: _path + ".reasoning_tokens",
386
+ expected: "(number | undefined)",
387
+ value: input.reasoning_tokens
388
+ }, _errorFactory)) && (undefined === input.rejected_prediction_tokens || "number" === typeof input.rejected_prediction_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
389
+ method: "json.assertParse",
390
+ path: _path + ".rejected_prediction_tokens",
391
+ expected: "(number | undefined)",
392
+ value: input.rejected_prediction_tokens
393
+ }, _errorFactory)); const _ao11 = (input, _path, _exceptionable = true) => (undefined === input.audio_tokens || "number" === typeof input.audio_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
394
+ method: "json.assertParse",
395
+ path: _path + ".audio_tokens",
396
+ expected: "(number | undefined)",
397
+ value: input.audio_tokens
398
+ }, _errorFactory)) && (undefined === input.cached_tokens || "number" === typeof input.cached_tokens || __typia_transform__assertGuard._assertGuard(_exceptionable, {
399
+ method: "json.assertParse",
400
+ path: _path + ".cached_tokens",
401
+ expected: "(number | undefined)",
402
+ value: input.cached_tokens
403
+ }, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; const __assert = (input, errorFactory) => {
404
+ if (false === __is(input)) {
405
+ _errorFactory = errorFactory;
406
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
407
+ method: "json.assertParse",
408
+ path: _path + "",
409
+ expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
410
+ value: input
411
+ }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
412
+ method: "json.assertParse",
413
+ path: _path + "",
414
+ expected: "ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",
415
+ value: input
416
+ }, _errorFactory))(input, "$input", true);
484
417
  }
485
- if (!acc.logprobs && cur.logprobs) {
486
- acc.logprobs = cur.logprobs;
418
+ return input;
419
+ }; return (input, errorFactory) => __assert(JSON.parse(input), errorFactory); })()(str);
420
+ }
421
+ function accumulate(origin, chunk) {
422
+ const choices = origin.choices;
423
+ chunk.choices.forEach((choice) => {
424
+ var _a, _b, _c, _d;
425
+ const accChoice = choices[choice.index];
426
+ if (accChoice != null) {
427
+ choices[choice.index] = mergeChoice(accChoice, choice);
428
+ return;
487
429
  }
488
- if (cur.delta.content) {
489
- if (!acc.message.content) {
490
- acc.message.content = cur.delta.content;
491
- }
492
- else {
493
- acc.message.content += cur.delta.content;
494
- }
430
+ choices[choice.index] = {
431
+ index: choice.index,
432
+ finish_reason: (_a = choice.finish_reason) !== null && _a !== void 0 ? _a : null,
433
+ logprobs: (_b = choice.logprobs) !== null && _b !== void 0 ? _b : null,
434
+ message: {
435
+ tool_calls: choice.delta.tool_calls !== undefined
436
+ ? choice.delta.tool_calls.reduce((acc, cur) => {
437
+ var _a, _b, _c, _d, _e;
438
+ acc[cur.index] = {
439
+ id: (_a = cur.id) !== null && _a !== void 0 ? _a : "",
440
+ type: "function",
441
+ function: {
442
+ name: (_c = (_b = cur.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
443
+ arguments: (_e = (_d = cur.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
444
+ },
445
+ };
446
+ return acc;
447
+ }, [])
448
+ : undefined,
449
+ content: (_c = choice.delta.content) !== null && _c !== void 0 ? _c : null,
450
+ refusal: (_d = choice.delta.refusal) !== null && _d !== void 0 ? _d : null,
451
+ role: "assistant",
452
+ },
453
+ };
454
+ });
455
+ const usage = (() => {
456
+ if (chunk.usage == null) {
457
+ return origin.usage;
495
458
  }
496
- if (cur.delta.refusal) {
497
- if (!acc.message.refusal) {
498
- acc.message.refusal = cur.delta.refusal;
499
- }
500
- else {
501
- acc.message.refusal += cur.delta.refusal;
502
- }
459
+ if (origin.usage == null) {
460
+ return chunk.usage;
503
461
  }
504
- if (cur.delta.tool_calls) {
505
- (_a = (_b = acc.message).tool_calls) !== null && _a !== void 0 ? _a : (_b.tool_calls = []);
506
- const toolCalls = acc.message.tool_calls;
507
- cur.delta.tool_calls.forEach((toolCall) => {
508
- var _a, _b, _c, _d, _e;
509
- const existingToolCall = toolCalls[toolCall.index];
510
- if (existingToolCall) {
511
- toolCalls[toolCall.index] = ChatGptCompletionMessageUtil.mergeToolCalls(existingToolCall, toolCall);
512
- return;
513
- }
514
- toolCalls[toolCall.index] = {
515
- id: (_a = toolCall.id) !== null && _a !== void 0 ? _a : "",
516
- type: "function",
517
- function: {
518
- name: (_c = (_b = toolCall.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
519
- arguments: (_e = (_d = toolCall.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
520
- },
521
- };
522
- });
462
+ return ChatGptUsageAggregator_1.ChatGptUsageAggregator.sum(origin.usage, chunk.usage);
463
+ })();
464
+ return Object.assign(Object.assign({}, origin), { choices,
465
+ usage });
466
+ }
467
+ function merge(chunks) {
468
+ const firstChunk = chunks[0];
469
+ if (firstChunk === undefined) {
470
+ throw new Error("No chunks received");
471
+ }
472
+ return chunks.reduce(accumulate, {
473
+ id: firstChunk.id,
474
+ choices: [],
475
+ created: firstChunk.created,
476
+ model: firstChunk.model,
477
+ object: "chat.completion",
478
+ usage: undefined,
479
+ service_tier: firstChunk.service_tier,
480
+ system_fingerprint: firstChunk.system_fingerprint,
481
+ });
482
+ }
483
+ function mergeChoice(acc, cur) {
484
+ var _a;
485
+ var _b;
486
+ if (acc.finish_reason == null && cur.finish_reason != null) {
487
+ acc.finish_reason = cur.finish_reason;
488
+ }
489
+ if (acc.logprobs == null && cur.logprobs != null) {
490
+ acc.logprobs = cur.logprobs;
491
+ }
492
+ if (cur.delta.content != null) {
493
+ if (acc.message.content == null) {
494
+ acc.message.content = cur.delta.content;
523
495
  }
524
- return acc;
525
- };
526
- ChatGptCompletionMessageUtil.mergeToolCalls = (acc, cur) => {
527
- var _a, _b, _c;
528
- if (cur.function) {
529
- acc.function.arguments += (_a = cur.function.arguments) !== null && _a !== void 0 ? _a : "";
530
- acc.function.name += (_b = cur.function.name) !== null && _b !== void 0 ? _b : "";
496
+ else {
497
+ acc.message.content += cur.delta.content;
531
498
  }
532
- acc.id += (_c = cur.id) !== null && _c !== void 0 ? _c : "";
533
- return acc;
534
- };
535
- })(ChatGptCompletionMessageUtil || (exports.ChatGptCompletionMessageUtil = ChatGptCompletionMessageUtil = {}));
499
+ }
500
+ if (cur.delta.refusal != null) {
501
+ if (acc.message.refusal == null) {
502
+ acc.message.refusal = cur.delta.refusal;
503
+ }
504
+ else {
505
+ acc.message.refusal += cur.delta.refusal;
506
+ }
507
+ }
508
+ if (cur.delta.tool_calls != null) {
509
+ (_a = (_b = acc.message).tool_calls) !== null && _a !== void 0 ? _a : (_b.tool_calls = []);
510
+ const toolCalls = acc.message.tool_calls;
511
+ cur.delta.tool_calls.forEach((toolCall) => {
512
+ var _a, _b, _c, _d, _e;
513
+ const existingToolCall = toolCalls[toolCall.index];
514
+ if (existingToolCall != null) {
515
+ toolCalls[toolCall.index] = mergeToolCalls(existingToolCall, toolCall);
516
+ return;
517
+ }
518
+ toolCalls[toolCall.index] = {
519
+ id: (_a = toolCall.id) !== null && _a !== void 0 ? _a : "",
520
+ type: "function",
521
+ function: {
522
+ name: (_c = (_b = toolCall.function) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "",
523
+ arguments: (_e = (_d = toolCall.function) === null || _d === void 0 ? void 0 : _d.arguments) !== null && _e !== void 0 ? _e : "",
524
+ },
525
+ };
526
+ });
527
+ }
528
+ return acc;
529
+ }
530
+ function mergeToolCalls(acc, cur) {
531
+ var _a, _b, _c;
532
+ if (cur.function != null) {
533
+ acc.function.arguments += (_a = cur.function.arguments) !== null && _a !== void 0 ? _a : "";
534
+ acc.function.name += (_b = cur.function.name) !== null && _b !== void 0 ? _b : "";
535
+ }
536
+ acc.id += (_c = cur.id) !== null && _c !== void 0 ? _c : "";
537
+ return acc;
538
+ }
539
+ exports.ChatGptCompletionMessageUtil = {
540
+ transformCompletionChunk,
541
+ accumulate,
542
+ merge,
543
+ mergeChoice,
544
+ mergeToolCalls,
545
+ };
536
546
  //# sourceMappingURL=ChatGptCompletionMessageUtil.js.map