@langchain/core 1.0.0-alpha.6 → 1.0.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 (245) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/LICENSE +6 -6
  3. package/README.md +2 -23
  4. package/dist/agents.d.ts.map +1 -1
  5. package/dist/caches/base.d.cts.map +1 -1
  6. package/dist/callbacks/base.d.cts.map +1 -1
  7. package/dist/callbacks/base.d.ts.map +1 -1
  8. package/dist/callbacks/manager.cjs +9 -64
  9. package/dist/callbacks/manager.cjs.map +1 -1
  10. package/dist/callbacks/manager.d.cts +1 -23
  11. package/dist/callbacks/manager.d.cts.map +1 -1
  12. package/dist/callbacks/manager.d.ts +1 -23
  13. package/dist/callbacks/manager.d.ts.map +1 -1
  14. package/dist/callbacks/manager.js +10 -63
  15. package/dist/callbacks/manager.js.map +1 -1
  16. package/dist/chat_history.cjs +0 -4
  17. package/dist/chat_history.cjs.map +1 -1
  18. package/dist/chat_history.d.cts +1 -3
  19. package/dist/chat_history.d.cts.map +1 -1
  20. package/dist/chat_history.d.ts +1 -3
  21. package/dist/chat_history.d.ts.map +1 -1
  22. package/dist/chat_history.js +0 -4
  23. package/dist/chat_history.js.map +1 -1
  24. package/dist/document_loaders/base.cjs +1 -13
  25. package/dist/document_loaders/base.cjs.map +1 -1
  26. package/dist/document_loaders/base.d.cts +0 -9
  27. package/dist/document_loaders/base.d.cts.map +1 -1
  28. package/dist/document_loaders/base.d.ts +0 -9
  29. package/dist/document_loaders/base.d.ts.map +1 -1
  30. package/dist/document_loaders/base.js +1 -13
  31. package/dist/document_loaders/base.js.map +1 -1
  32. package/dist/document_loaders/langsmith.d.cts +1 -1
  33. package/dist/language_models/base.cjs.map +1 -1
  34. package/dist/language_models/base.d.cts +0 -16
  35. package/dist/language_models/base.d.cts.map +1 -1
  36. package/dist/language_models/base.d.ts +0 -16
  37. package/dist/language_models/base.d.ts.map +1 -1
  38. package/dist/language_models/base.js.map +1 -1
  39. package/dist/language_models/chat_models.cjs +10 -83
  40. package/dist/language_models/chat_models.cjs.map +1 -1
  41. package/dist/language_models/chat_models.d.cts +21 -55
  42. package/dist/language_models/chat_models.d.cts.map +1 -1
  43. package/dist/language_models/chat_models.d.ts +21 -55
  44. package/dist/language_models/chat_models.d.ts.map +1 -1
  45. package/dist/language_models/chat_models.js +11 -83
  46. package/dist/language_models/chat_models.js.map +1 -1
  47. package/dist/language_models/llms.cjs +0 -56
  48. package/dist/language_models/llms.cjs.map +1 -1
  49. package/dist/language_models/llms.d.cts +1 -43
  50. package/dist/language_models/llms.d.cts.map +1 -1
  51. package/dist/language_models/llms.d.ts +1 -43
  52. package/dist/language_models/llms.d.ts.map +1 -1
  53. package/dist/language_models/llms.js +0 -56
  54. package/dist/language_models/llms.js.map +1 -1
  55. package/dist/load/import_map.cjs +1 -7
  56. package/dist/load/import_map.cjs.map +1 -1
  57. package/dist/load/import_map.js +1 -7
  58. package/dist/load/import_map.js.map +1 -1
  59. package/dist/messages/ai.cjs +4 -0
  60. package/dist/messages/ai.cjs.map +1 -1
  61. package/dist/messages/ai.js +4 -0
  62. package/dist/messages/ai.js.map +1 -1
  63. package/dist/messages/block_translators/anthropic.cjs +191 -144
  64. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  65. package/dist/messages/block_translators/anthropic.js +191 -144
  66. package/dist/messages/block_translators/anthropic.js.map +1 -1
  67. package/dist/messages/block_translators/index.cjs +2 -2
  68. package/dist/messages/block_translators/index.cjs.map +1 -1
  69. package/dist/messages/block_translators/index.js +4 -4
  70. package/dist/messages/block_translators/index.js.map +1 -1
  71. package/dist/messages/block_translators/openai.cjs +78 -22
  72. package/dist/messages/block_translators/openai.cjs.map +1 -1
  73. package/dist/messages/block_translators/openai.js +78 -22
  74. package/dist/messages/block_translators/openai.js.map +1 -1
  75. package/dist/messages/content/tools.cjs +1 -5
  76. package/dist/messages/content/tools.cjs.map +1 -1
  77. package/dist/messages/content/tools.d.cts +1 -85
  78. package/dist/messages/content/tools.d.cts.map +1 -1
  79. package/dist/messages/content/tools.d.ts +1 -85
  80. package/dist/messages/content/tools.d.ts.map +1 -1
  81. package/dist/messages/content/tools.js +1 -5
  82. package/dist/messages/content/tools.js.map +1 -1
  83. package/dist/messages/metadata.cjs.map +1 -1
  84. package/dist/messages/metadata.d.cts +3 -0
  85. package/dist/messages/metadata.d.cts.map +1 -1
  86. package/dist/messages/metadata.d.ts +3 -0
  87. package/dist/messages/metadata.d.ts.map +1 -1
  88. package/dist/messages/metadata.js.map +1 -1
  89. package/dist/messages/tool.cjs +2 -0
  90. package/dist/messages/tool.cjs.map +1 -1
  91. package/dist/messages/tool.d.cts +2 -0
  92. package/dist/messages/tool.d.cts.map +1 -1
  93. package/dist/messages/tool.d.ts +2 -0
  94. package/dist/messages/tool.d.ts.map +1 -1
  95. package/dist/messages/tool.js +2 -0
  96. package/dist/messages/tool.js.map +1 -1
  97. package/dist/output_parsers/json.cjs +5 -0
  98. package/dist/output_parsers/json.cjs.map +1 -1
  99. package/dist/output_parsers/json.d.cts +2 -0
  100. package/dist/output_parsers/json.d.cts.map +1 -1
  101. package/dist/output_parsers/json.d.ts +2 -0
  102. package/dist/output_parsers/json.d.ts.map +1 -1
  103. package/dist/output_parsers/json.js +5 -0
  104. package/dist/output_parsers/json.js.map +1 -1
  105. package/dist/prompts/base.cjs +0 -36
  106. package/dist/prompts/base.cjs.map +1 -1
  107. package/dist/prompts/base.d.cts +0 -16
  108. package/dist/prompts/base.d.cts.map +1 -1
  109. package/dist/prompts/base.d.ts +0 -16
  110. package/dist/prompts/base.d.ts.map +1 -1
  111. package/dist/prompts/base.js +0 -36
  112. package/dist/prompts/base.js.map +1 -1
  113. package/dist/prompts/chat.cjs +1 -5
  114. package/dist/prompts/chat.cjs.map +1 -1
  115. package/dist/prompts/chat.d.cts +1 -4
  116. package/dist/prompts/chat.d.cts.map +1 -1
  117. package/dist/prompts/chat.d.ts +1 -4
  118. package/dist/prompts/chat.d.ts.map +1 -1
  119. package/dist/prompts/chat.js +1 -5
  120. package/dist/prompts/chat.js.map +1 -1
  121. package/dist/prompts/dict.d.cts +1 -1
  122. package/dist/prompts/dict.d.ts +1 -1
  123. package/dist/prompts/few_shot.d.cts +2 -2
  124. package/dist/prompts/few_shot.d.ts +2 -2
  125. package/dist/prompts/image.d.cts +1 -1
  126. package/dist/prompts/image.d.ts +1 -1
  127. package/dist/prompts/index.d.cts +2 -2
  128. package/dist/prompts/index.d.ts +2 -2
  129. package/dist/prompts/pipeline.d.cts +1 -1
  130. package/dist/prompts/pipeline.d.ts +1 -1
  131. package/dist/prompts/prompt.d.cts +2 -2
  132. package/dist/prompts/prompt.d.ts +2 -2
  133. package/dist/retrievers/index.cjs +3 -18
  134. package/dist/retrievers/index.cjs.map +1 -1
  135. package/dist/retrievers/index.d.cts +2 -27
  136. package/dist/retrievers/index.d.cts.map +1 -1
  137. package/dist/retrievers/index.d.ts +2 -27
  138. package/dist/retrievers/index.d.ts.map +1 -1
  139. package/dist/retrievers/index.js +3 -18
  140. package/dist/retrievers/index.js.map +1 -1
  141. package/dist/runnables/base.cjs +24 -63
  142. package/dist/runnables/base.cjs.map +1 -1
  143. package/dist/runnables/base.d.cts +10 -39
  144. package/dist/runnables/base.d.cts.map +1 -1
  145. package/dist/runnables/base.d.ts +10 -39
  146. package/dist/runnables/base.d.ts.map +1 -1
  147. package/dist/runnables/base.js +24 -63
  148. package/dist/runnables/base.js.map +1 -1
  149. package/dist/runnables/graph.cjs +1 -1
  150. package/dist/runnables/graph.cjs.map +1 -1
  151. package/dist/runnables/graph.js +2 -2
  152. package/dist/runnables/graph.js.map +1 -1
  153. package/dist/runnables/graph_mermaid.cjs +1 -10
  154. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  155. package/dist/runnables/graph_mermaid.js +1 -10
  156. package/dist/runnables/graph_mermaid.js.map +1 -1
  157. package/dist/runnables/history.cjs +1 -1
  158. package/dist/runnables/history.cjs.map +1 -1
  159. package/dist/runnables/history.d.cts +2 -2
  160. package/dist/runnables/history.d.cts.map +1 -1
  161. package/dist/runnables/history.d.ts +2 -2
  162. package/dist/runnables/history.d.ts.map +1 -1
  163. package/dist/runnables/history.js +1 -1
  164. package/dist/runnables/history.js.map +1 -1
  165. package/dist/stores.cjs.map +1 -1
  166. package/dist/stores.d.cts +3 -29
  167. package/dist/stores.d.cts.map +1 -1
  168. package/dist/stores.d.ts +3 -29
  169. package/dist/stores.d.ts.map +1 -1
  170. package/dist/stores.js.map +1 -1
  171. package/dist/tools/index.cjs +12 -4
  172. package/dist/tools/index.cjs.map +1 -1
  173. package/dist/tools/index.js +12 -4
  174. package/dist/tools/index.js.map +1 -1
  175. package/dist/tools/types.cjs.map +1 -1
  176. package/dist/tools/types.d.cts +4 -0
  177. package/dist/tools/types.d.cts.map +1 -1
  178. package/dist/tools/types.d.ts +4 -0
  179. package/dist/tools/types.d.ts.map +1 -1
  180. package/dist/tools/types.js.map +1 -1
  181. package/dist/tracers/base.cjs +1 -1
  182. package/dist/tracers/base.cjs.map +1 -1
  183. package/dist/tracers/base.d.cts +1 -1
  184. package/dist/tracers/base.js +2 -2
  185. package/dist/tracers/base.js.map +1 -1
  186. package/dist/tracers/log_stream.d.cts +1 -1
  187. package/dist/tracers/log_stream.d.ts +1 -1
  188. package/dist/tracers/tracer_langchain.cjs +1 -0
  189. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  190. package/dist/tracers/tracer_langchain.d.cts +2 -2
  191. package/dist/tracers/tracer_langchain.js +1 -0
  192. package/dist/tracers/tracer_langchain.js.map +1 -1
  193. package/dist/utils/env.cjs +1 -9
  194. package/dist/utils/env.cjs.map +1 -1
  195. package/dist/utils/env.d.cts +2 -6
  196. package/dist/utils/env.d.cts.map +1 -1
  197. package/dist/utils/env.d.ts +2 -6
  198. package/dist/utils/env.d.ts.map +1 -1
  199. package/dist/utils/env.js +2 -9
  200. package/dist/utils/env.js.map +1 -1
  201. package/dist/utils/testing/message_history.cjs +1 -1
  202. package/dist/utils/testing/message_history.cjs.map +1 -1
  203. package/dist/utils/testing/message_history.d.cts +1 -1
  204. package/dist/utils/testing/message_history.d.cts.map +1 -1
  205. package/dist/utils/testing/message_history.d.ts +1 -1
  206. package/dist/utils/testing/message_history.d.ts.map +1 -1
  207. package/dist/utils/testing/message_history.js +1 -1
  208. package/dist/utils/testing/message_history.js.map +1 -1
  209. package/dist/utils/types/index.cjs +6 -0
  210. package/dist/utils/types/index.d.cts +2 -2
  211. package/dist/utils/types/index.d.ts +2 -2
  212. package/dist/utils/types/index.js +5 -2
  213. package/dist/utils/types/zod.cjs +23 -0
  214. package/dist/utils/types/zod.cjs.map +1 -1
  215. package/dist/utils/types/zod.d.cts +11 -1
  216. package/dist/utils/types/zod.d.cts.map +1 -1
  217. package/dist/utils/types/zod.d.ts +11 -1
  218. package/dist/utils/types/zod.d.ts.map +1 -1
  219. package/dist/utils/types/zod.js +21 -1
  220. package/dist/utils/types/zod.js.map +1 -1
  221. package/package.json +121 -154
  222. package/dist/runnables/remote.cjs +0 -399
  223. package/dist/runnables/remote.cjs.map +0 -1
  224. package/dist/runnables/remote.d.cts +0 -73
  225. package/dist/runnables/remote.d.cts.map +0 -1
  226. package/dist/runnables/remote.d.ts +0 -73
  227. package/dist/runnables/remote.d.ts.map +0 -1
  228. package/dist/runnables/remote.js +0 -393
  229. package/dist/runnables/remote.js.map +0 -1
  230. package/dist/tracers/initialize.cjs +0 -46
  231. package/dist/tracers/initialize.cjs.map +0 -1
  232. package/dist/tracers/initialize.d.cts +0 -26
  233. package/dist/tracers/initialize.d.cts.map +0 -1
  234. package/dist/tracers/initialize.d.ts +0 -26
  235. package/dist/tracers/initialize.d.ts.map +0 -1
  236. package/dist/tracers/initialize.js +0 -39
  237. package/dist/tracers/initialize.js.map +0 -1
  238. package/dist/tracers/tracer_langchain_v1.cjs +0 -168
  239. package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
  240. package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
  241. package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
  242. package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
  243. package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
  244. package/dist/tracers/tracer_langchain_v1.js +0 -162
  245. package/dist/tracers/tracer_langchain_v1.js.map +0 -1
@@ -232,14 +232,35 @@ function convertToV1FromResponses(message) {
232
232
  name: toolCall.name,
233
233
  args: toolCall.args
234
234
  };
235
- if (require_utils._isObject(message.additional_kwargs) && require_utils._isArray(message.additional_kwargs.tool_outputs)) {
236
- for (const toolOutput of message.additional_kwargs.tool_outputs) if (require_utils._isContentBlock(toolOutput, "web_search_call")) continue;
237
- else if (require_utils._isContentBlock(toolOutput, "file_search_call")) continue;
238
- else if (require_utils._isContentBlock(toolOutput, "computer_call")) continue;
239
- else if (require_utils._isContentBlock(toolOutput, "code_interpreter_call")) {
235
+ if (require_utils._isObject(message.additional_kwargs) && require_utils._isArray(message.additional_kwargs.tool_outputs)) for (const toolOutput of message.additional_kwargs.tool_outputs) {
236
+ if (require_utils._isContentBlock(toolOutput, "web_search_call")) {
237
+ yield {
238
+ id: toolOutput.id,
239
+ type: "server_tool_call",
240
+ name: "web_search",
241
+ args: { query: toolOutput.query }
242
+ };
243
+ continue;
244
+ } else if (require_utils._isContentBlock(toolOutput, "file_search_call")) {
245
+ yield {
246
+ id: toolOutput.id,
247
+ type: "server_tool_call",
248
+ name: "file_search",
249
+ args: { query: toolOutput.query }
250
+ };
251
+ continue;
252
+ } else if (require_utils._isContentBlock(toolOutput, "computer_call")) {
253
+ yield {
254
+ type: "non_standard",
255
+ value: toolOutput
256
+ };
257
+ continue;
258
+ } else if (require_utils._isContentBlock(toolOutput, "code_interpreter_call")) {
240
259
  if (require_utils._isString(toolOutput.code)) yield {
241
- type: "code_interpreter_call",
242
- code: toolOutput.code
260
+ id: toolOutput.id,
261
+ type: "server_tool_call",
262
+ name: "code_interpreter",
263
+ args: { code: toolOutput.code }
243
264
  };
244
265
  if (require_utils._isArray(toolOutput.outputs)) {
245
266
  const returnCode = require_utils.iife(() => {
@@ -250,20 +271,55 @@ function convertToV1FromResponses(message) {
250
271
  if (toolOutput.status === "failed") return 1;
251
272
  return void 0;
252
273
  });
253
- for (const output of toolOutput.outputs) if (require_utils._isContentBlock(output, "logs")) yield {
254
- type: "code_interpreter_result",
255
- output: [{
256
- type: "code_interpreter_output",
257
- returnCode,
258
- stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
259
- stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
260
- }]
261
- };
274
+ for (const output of toolOutput.outputs) if (require_utils._isContentBlock(output, "logs")) {
275
+ yield {
276
+ type: "server_tool_call_result",
277
+ toolCallId: toolOutput.id ?? "",
278
+ status: "success",
279
+ output: {
280
+ type: "code_interpreter_output",
281
+ returnCode: returnCode ?? 0,
282
+ stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
283
+ stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
284
+ }
285
+ };
286
+ continue;
287
+ }
262
288
  }
263
- } else if (require_utils._isContentBlock(toolOutput, "mcp_call")) continue;
264
- else if (require_utils._isContentBlock(toolOutput, "mcp_list_tools")) continue;
265
- else if (require_utils._isContentBlock(toolOutput, "mcp_approval_request")) continue;
266
- else if (require_utils._isContentBlock(toolOutput, "image_generation_call")) continue;
289
+ continue;
290
+ } else if (require_utils._isContentBlock(toolOutput, "mcp_call")) {
291
+ yield {
292
+ id: toolOutput.id,
293
+ type: "server_tool_call",
294
+ name: "mcp_call",
295
+ args: toolOutput.input
296
+ };
297
+ continue;
298
+ } else if (require_utils._isContentBlock(toolOutput, "mcp_list_tools")) {
299
+ yield {
300
+ id: toolOutput.id,
301
+ type: "server_tool_call",
302
+ name: "mcp_list_tools",
303
+ args: toolOutput.input
304
+ };
305
+ continue;
306
+ } else if (require_utils._isContentBlock(toolOutput, "mcp_approval_request")) {
307
+ yield {
308
+ type: "non_standard",
309
+ value: toolOutput
310
+ };
311
+ continue;
312
+ } else if (require_utils._isContentBlock(toolOutput, "image_generation_call")) {
313
+ yield {
314
+ type: "non_standard",
315
+ value: toolOutput
316
+ };
317
+ continue;
318
+ }
319
+ if (require_utils._isObject(toolOutput)) yield {
320
+ type: "non_standard",
321
+ value: toolOutput
322
+ };
267
323
  }
268
324
  }
269
325
  return Array.from(iterateContent());
@@ -307,7 +363,7 @@ function convertToV1FromResponsesChunk(message) {
307
363
  }
308
364
  return Array.from(iterateContent());
309
365
  }
310
- const openaiTranslator = {
366
+ const ChatOpenAITranslator = {
311
367
  translateContent: (message) => {
312
368
  if (typeof message.content === "string") return convertToV1FromChatCompletions(message);
313
369
  return convertToV1FromResponses(message);
@@ -319,6 +375,6 @@ const openaiTranslator = {
319
375
  };
320
376
 
321
377
  //#endregion
378
+ exports.ChatOpenAITranslator = ChatOpenAITranslator;
322
379
  exports.convertToV1FromChatCompletionsInput = convertToV1FromChatCompletionsInput;
323
- exports.openaiTranslator = openaiTranslator;
324
380
  //# sourceMappingURL=openai.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","isOpenAIDataBlock","convertToV1FromOpenAIDataBlock","annotation: ContentBlock","_isObject","_isArray","_isString","_isContentBlock","iife","message: AIMessageChunk","openaiTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n type: \"code_interpreter_call\",\n code: toolOutput.code,\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"code_interpreter_result\",\n output: [\n {\n type: \"code_interpreter_output\",\n returnCode,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n ],\n };\n }\n }\n }\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n continue;\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const openaiTranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAEtE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,SAAgB,oCACdD,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAItE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BD,SAAgB,oCACdC,QAC8B;CAC9B,MAAMC,kBAAgD,CAAE;AACxD,MAAK,MAAM,SAAS,OAClB,KAAIC,+BAAkB,MAAM,EAC1B,gBAAgB,KAAKC,4CAA+B,MAAM,CAAC;MAE3D,gBAAgB,KAAK,MAA+B;AAGxD,QAAO;AACR;AAED,SAAS,2BACPC,YACsC;AACtC,KAAI,WAAW,SAAS,gBAAgB;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,QAAQ;AACxC,OAAK,MAAM,iBAAiB,QAAQ,oBAAoB,CAAE,GACxD,MAAM;GACJ,MAAM;GACN,IAAI,cAAc;GAClB,MAAM,cAAc;GACpB,MAAM,cAAc;EACrB;CAEJ;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,mBAAmD;CAC9D,kBAAkB,CAAC,YAAY;AAC7B,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,+BAA+B,QAAQ;AAEhD,SAAO,yBAAyB,QAAQ;CACzC;CACD,uBAAuB,CAAC,YAAY;AAClC,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,oCAAoC,QAAQ;AAErD,SAAO,8BAA8B,QAAQ;CAC9C;AACF"}
1
+ {"version":3,"file":"openai.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","isOpenAIDataBlock","convertToV1FromOpenAIDataBlock","annotation: ContentBlock","_isObject","_isArray","_isString","_isContentBlock","iife","message: AIMessageChunk","ChatOpenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"file_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"code_interpreter\",\n args: { code: toolOutput.code },\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"server_tool_call_result\",\n toolCallId: toolOutput.id ?? \"\",\n status: \"success\",\n output: {\n type: \"code_interpreter_output\",\n returnCode: returnCode ?? 0,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n };\n continue;\n }\n }\n }\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_call\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_list_tools\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n }\n if (_isObject(toolOutput)) {\n yield { type: \"non_standard\", value: toolOutput };\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatOpenAITranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAEtE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,SAAgB,oCACdD,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAItE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,M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AgB,CAAC;AACpC;AAED,MAAaC,uBAAuD;CAClE,kBAAkB,CAAC,YAAY;AAC7B,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,+BAA+B,QAAQ;AAEhD,SAAO,yBAAyB,QAAQ;CACzC;CACD,uBAAuB,CAAC,YAAY;AAClC,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,oCAAoC,QAAQ;AAErD,SAAO,8BAA8B,QAAQ;CAC9C;AACF"}
@@ -232,14 +232,35 @@ function convertToV1FromResponses(message) {
232
232
  name: toolCall.name,
233
233
  args: toolCall.args
234
234
  };
235
- if (_isObject(message.additional_kwargs) && _isArray(message.additional_kwargs.tool_outputs)) {
236
- for (const toolOutput of message.additional_kwargs.tool_outputs) if (_isContentBlock(toolOutput, "web_search_call")) continue;
237
- else if (_isContentBlock(toolOutput, "file_search_call")) continue;
238
- else if (_isContentBlock(toolOutput, "computer_call")) continue;
239
- else if (_isContentBlock(toolOutput, "code_interpreter_call")) {
235
+ if (_isObject(message.additional_kwargs) && _isArray(message.additional_kwargs.tool_outputs)) for (const toolOutput of message.additional_kwargs.tool_outputs) {
236
+ if (_isContentBlock(toolOutput, "web_search_call")) {
237
+ yield {
238
+ id: toolOutput.id,
239
+ type: "server_tool_call",
240
+ name: "web_search",
241
+ args: { query: toolOutput.query }
242
+ };
243
+ continue;
244
+ } else if (_isContentBlock(toolOutput, "file_search_call")) {
245
+ yield {
246
+ id: toolOutput.id,
247
+ type: "server_tool_call",
248
+ name: "file_search",
249
+ args: { query: toolOutput.query }
250
+ };
251
+ continue;
252
+ } else if (_isContentBlock(toolOutput, "computer_call")) {
253
+ yield {
254
+ type: "non_standard",
255
+ value: toolOutput
256
+ };
257
+ continue;
258
+ } else if (_isContentBlock(toolOutput, "code_interpreter_call")) {
240
259
  if (_isString(toolOutput.code)) yield {
241
- type: "code_interpreter_call",
242
- code: toolOutput.code
260
+ id: toolOutput.id,
261
+ type: "server_tool_call",
262
+ name: "code_interpreter",
263
+ args: { code: toolOutput.code }
243
264
  };
244
265
  if (_isArray(toolOutput.outputs)) {
245
266
  const returnCode = iife(() => {
@@ -250,20 +271,55 @@ function convertToV1FromResponses(message) {
250
271
  if (toolOutput.status === "failed") return 1;
251
272
  return void 0;
252
273
  });
253
- for (const output of toolOutput.outputs) if (_isContentBlock(output, "logs")) yield {
254
- type: "code_interpreter_result",
255
- output: [{
256
- type: "code_interpreter_output",
257
- returnCode,
258
- stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
259
- stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
260
- }]
261
- };
274
+ for (const output of toolOutput.outputs) if (_isContentBlock(output, "logs")) {
275
+ yield {
276
+ type: "server_tool_call_result",
277
+ toolCallId: toolOutput.id ?? "",
278
+ status: "success",
279
+ output: {
280
+ type: "code_interpreter_output",
281
+ returnCode: returnCode ?? 0,
282
+ stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
283
+ stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
284
+ }
285
+ };
286
+ continue;
287
+ }
262
288
  }
263
- } else if (_isContentBlock(toolOutput, "mcp_call")) continue;
264
- else if (_isContentBlock(toolOutput, "mcp_list_tools")) continue;
265
- else if (_isContentBlock(toolOutput, "mcp_approval_request")) continue;
266
- else if (_isContentBlock(toolOutput, "image_generation_call")) continue;
289
+ continue;
290
+ } else if (_isContentBlock(toolOutput, "mcp_call")) {
291
+ yield {
292
+ id: toolOutput.id,
293
+ type: "server_tool_call",
294
+ name: "mcp_call",
295
+ args: toolOutput.input
296
+ };
297
+ continue;
298
+ } else if (_isContentBlock(toolOutput, "mcp_list_tools")) {
299
+ yield {
300
+ id: toolOutput.id,
301
+ type: "server_tool_call",
302
+ name: "mcp_list_tools",
303
+ args: toolOutput.input
304
+ };
305
+ continue;
306
+ } else if (_isContentBlock(toolOutput, "mcp_approval_request")) {
307
+ yield {
308
+ type: "non_standard",
309
+ value: toolOutput
310
+ };
311
+ continue;
312
+ } else if (_isContentBlock(toolOutput, "image_generation_call")) {
313
+ yield {
314
+ type: "non_standard",
315
+ value: toolOutput
316
+ };
317
+ continue;
318
+ }
319
+ if (_isObject(toolOutput)) yield {
320
+ type: "non_standard",
321
+ value: toolOutput
322
+ };
267
323
  }
268
324
  }
269
325
  return Array.from(iterateContent());
@@ -307,7 +363,7 @@ function convertToV1FromResponsesChunk(message) {
307
363
  }
308
364
  return Array.from(iterateContent());
309
365
  }
310
- const openaiTranslator = {
366
+ const ChatOpenAITranslator = {
311
367
  translateContent: (message) => {
312
368
  if (typeof message.content === "string") return convertToV1FromChatCompletions(message);
313
369
  return convertToV1FromResponses(message);
@@ -319,5 +375,5 @@ const openaiTranslator = {
319
375
  };
320
376
 
321
377
  //#endregion
322
- export { convertToV1FromChatCompletionsInput, openaiTranslator };
378
+ export { ChatOpenAITranslator, convertToV1FromChatCompletionsInput };
323
379
  //# sourceMappingURL=openai.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","annotation: ContentBlock","message: AIMessageChunk","openaiTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n type: \"code_interpreter_call\",\n code: toolOutput.code,\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"code_interpreter_result\",\n output: [\n {\n type: \"code_interpreter_output\",\n returnCode,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n ],\n };\n }\n }\n }\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n continue;\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const openaiTranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mapp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AAgB,CAAC;AACpC;AAED,MAAaC,mBAAmD;CAC9D,kBAAkB,CAAC,YAAY;AAC7B,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,+BAA+B,QAAQ;AAEhD,SAAO,yBAAyB,QAAQ;CACzC;CACD,uBAAuB,CAAC,YAAY;AAClC,MAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,oCAAoC,QAAQ;AAErD,SAAO,8BAA8B,QAAQ;CAC9C;AACF"}
1
+ {"version":3,"file":"openai.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","blocks: Array<ContentBlock>","convertedBlocks: Array<ContentBlock.Standard>","annotation: ContentBlock","message: AIMessageChunk","ChatOpenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/openai.ts"],"sourcesContent":["import type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { convertToV1FromOpenAIDataBlock, isOpenAIDataBlock } from \"./data.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isObject,\n _isString,\n iife,\n} from \"./utils.js\";\n\n/**\n * Converts a ChatOpenAICompletions message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from ChatOpenAICompletions API format\n * and converts it to the standardized v1 content block format. It handles both\n * string content and structured content blocks, as well as tool calls.\n *\n * @param message - The AI message containing ChatOpenAICompletions formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage(\"Hello world\");\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns: [{ type: \"text\", text: \"Hello world\" }]\n * ```\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ]);\n * message.tool_calls = [\n * { id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletions(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" },\n * // { type: \"tool_call\", id: \"call_123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletions(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts a ChatOpenAICompletions message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk from OpenAI's chat completions API and converts\n * it to the standardized v1 content block format. It handles both string and array content,\n * as well as tool calls that may be present in the chunk.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage(\"Hello\");\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns: [{ type: \"text\", text: \"Hello\" }]\n * ```\n *\n * @example\n * ```typescript\n * const chunk = new AIMessage([\n * { type: \"text\", text: \"Processing...\" }\n * ]);\n * chunk.tool_calls = [\n * { id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsChunk(chunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Processing...\" },\n * // { type: \"tool_call\", id: \"call_456\", name: \"search\", args: { query: \"test\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsChunk(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n if (typeof message.content === \"string\") {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n } else {\n blocks.push(...convertToV1FromChatCompletionsInput(message.content));\n }\n\n // TODO: parse chunk position information\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n return blocks;\n}\n\n/**\n * Converts an array of ChatOpenAICompletions content blocks to v1 standard content blocks.\n *\n * This function processes content blocks from OpenAI's Chat Completions API format\n * and converts them to the standardized v1 content block format. It handles both\n * OpenAI-specific data blocks (which require conversion) and standard blocks\n * (which are passed through with type assertion).\n *\n * @param blocks - Array of content blocks in ChatOpenAICompletions format\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const openaiBlocks = [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image_url\", image_url: { url: \"https://example.com/image.png\" } }\n * ];\n *\n * const standardBlocks = convertToV1FromChatCompletionsInput(openaiBlocks);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"image\", url: \"https://example.com/image.png\" }\n * // ]\n * ```\n */\nexport function convertToV1FromChatCompletionsInput(\n blocks: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n const convertedBlocks: Array<ContentBlock.Standard> = [];\n for (const block of blocks) {\n if (isOpenAIDataBlock(block)) {\n convertedBlocks.push(convertToV1FromOpenAIDataBlock(block));\n } else {\n convertedBlocks.push(block as ContentBlock.Standard);\n }\n }\n return convertedBlocks;\n}\n\nfunction convertResponsesAnnotation(\n annotation: ContentBlock\n): ContentBlock | ContentBlock.Citation {\n if (annotation.type === \"url_citation\") {\n const { url, title, start_index, end_index } = annotation;\n return {\n type: \"citation\",\n url,\n title,\n startIndex: start_index,\n endIndex: end_index,\n };\n }\n if (annotation.type === \"file_citation\") {\n const { file_id, filename, index } = annotation;\n return {\n type: \"citation\",\n title: filename,\n startIndex: index,\n endIndex: index,\n fileId: file_id,\n };\n }\n return annotation;\n}\n\n/**\n * Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing OpenAI Responses-specific content blocks\n * and converts them to the standardized v1 content block format. It handles reasoning summaries,\n * text content with annotations, tool calls, and various tool outputs including code interpreter,\n * web search, file search, computer calls, and MCP-related blocks.\n *\n * @param message - The AI message containing OpenAI Responses-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: [{ type: \"text\", text: \"Hello world\", annotations: [] }],\n * tool_calls: [{ id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }],\n * additional_kwargs: {\n * reasoning: { summary: [{ text: \"Let me calculate this...\" }] },\n * tool_outputs: [\n * {\n * type: \"code_interpreter_call\",\n * code: \"print('hello')\",\n * outputs: [{ type: \"logs\", logs: \"hello\" }]\n * }\n * ]\n * }\n * });\n *\n * const standardBlocks = convertToV1FromResponses(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me calculate this...\" },\n * // { type: \"text\", text: \"Hello world\", annotations: [] },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } },\n * // { type: \"code_interpreter_call\", code: \"print('hello')\" },\n * // { type: \"code_interpreter_result\", output: [{ type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" }] }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const summary =\n message.additional_kwargs.reasoning.summary.reduce<string>(\n (acc, item) => {\n if (_isObject(item) && _isString(item.text)) {\n return `${acc}${item.text}`;\n }\n return acc;\n },\n \"\"\n );\n yield {\n type: \"reasoning\",\n reasoning: summary,\n };\n }\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\")) {\n const { text, annotations, ...rest } = block;\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text: String(text),\n };\n }\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n };\n }\n if (\n _isObject(message.additional_kwargs) &&\n _isArray(message.additional_kwargs.tool_outputs)\n ) {\n for (const toolOutput of message.additional_kwargs.tool_outputs) {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"file_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"file_search\",\n args: { query: toolOutput.query },\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"computer_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"code_interpreter_call\")) {\n if (_isString(toolOutput.code)) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"code_interpreter\",\n args: { code: toolOutput.code },\n };\n }\n if (_isArray(toolOutput.outputs)) {\n const returnCode = iife(() => {\n if (toolOutput.status === \"in_progress\") return undefined;\n if (toolOutput.status === \"completed\") return 0;\n if (toolOutput.status === \"incomplete\") return 127;\n if (toolOutput.status === \"interpreting\") return undefined;\n if (toolOutput.status === \"failed\") return 1;\n return undefined;\n });\n for (const output of toolOutput.outputs) {\n if (_isContentBlock(output, \"logs\")) {\n yield {\n type: \"server_tool_call_result\",\n toolCallId: toolOutput.id ?? \"\",\n status: \"success\",\n output: {\n type: \"code_interpreter_output\",\n returnCode: returnCode ?? 0,\n stderr: [0, undefined].includes(returnCode)\n ? undefined\n : String(output.logs),\n stdout: [0, undefined].includes(returnCode)\n ? String(output.logs)\n : undefined,\n },\n };\n continue;\n }\n }\n }\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_call\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_list_tools\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"mcp_list_tools\",\n args: toolOutput.input,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n continue;\n }\n if (_isObject(toolOutput)) {\n yield { type: \"non_standard\", value: toolOutput };\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.\n *\n * This function processes an AI message chunk containing OpenAI-specific content blocks\n * and converts them to the standardized v1 content block format. It handles both the\n * regular message content and tool call chunks that are specific to streaming responses.\n *\n * @param message - The AI message chunk containing OpenAI-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const messageChunk = new AIMessageChunk({\n * content: [{ type: \"text\", text: \"Hello\" }],\n * tool_call_chunks: [\n * { id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * ]\n * });\n *\n * const standardBlocks = convertToV1FromResponsesChunk(messageChunk);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello\" },\n * // { type: \"tool_call_chunk\", id: \"call_123\", name: \"calculator\", args: '{\"a\": 1' }\n * // ]\n * ```\n */\nexport function convertToV1FromResponsesChunk(\n message: AIMessageChunk\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n yield* convertToV1FromResponses(message);\n for (const toolCallChunk of message.tool_call_chunks ?? []) {\n yield {\n type: \"tool_call_chunk\",\n id: toolCallChunk.id,\n name: toolCallChunk.name,\n args: toolCallChunk.args,\n };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatOpenAITranslator: StandardContentBlockTranslator = {\n translateContent: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletions(message);\n }\n return convertToV1FromResponses(message);\n },\n translateContentChunk: (message) => {\n if (typeof message.content === \"string\") {\n return convertToV1FromChatCompletionsChunk(message);\n }\n return convertToV1FromResponsesChunk(message);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAEtE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,SAAgB,oCACdD,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;AAC/C,KAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,KAAK;EACV,MAAM;EACN,MAAM,QAAQ;CACf,EAAC;MAEF,OAAO,KAAK,GAAG,oCAAoC,QAAQ,QAAQ,CAAC;AAItE,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAEJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BD,SAAgB,oCACdC,QAC8B;CAC9B,MAAMC,kBAAgD,CAAE;AACxD,MAAK,MAAM,SAAS,OAClB,KAAI,kBAAkB,MAAM,EAC1B,gBAAgB,KAAK,+BAA+B,MAAM,CAAC;MAE3D,gBAAgB,KA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CAC9C;AACF"}
@@ -6,11 +6,7 @@ const KNOWN_BLOCK_TYPES = [
6
6
  "invalid_tool_call",
7
7
  "server_tool_call",
8
8
  "server_tool_call_chunk",
9
- "server_tool_call_result",
10
- "web_search_call",
11
- "web_search_result",
12
- "code_interpreter",
13
- "code_interpreter_result"
9
+ "server_tool_call_result"
14
10
  ];
15
11
 
16
12
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tools.cjs","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"server_tool_call\",\n \"server_tool_call_chunk\",\n \"server_tool_call_result\",\n \"web_search_call\",\n \"web_search_result\",\n \"code_interpreter\",\n \"code_interpreter_result\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n export interface ToolCall<TName extends string = string, TArgs = unknown>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n /** Content block to represent partial data of a tool call */\n export interface ToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n\n /** Content block to represent an invalid tool call */\n export interface InvalidToolCall<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n\n export interface ServerToolCall<\n TName extends string = string,\n TArgs = unknown\n > extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n export interface ServerToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n\n export interface ServerToolCallResult<TOutput = Record<string, unknown>>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n\n /**\n * Content block for a built-in web search tool call.\n * @deprecated Use ServerToolCall instead\n */\n export interface WebSearchCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_call\";\n /**\n * The search query used in the web search tool call\n */\n query?: string;\n }\n\n /**\n * Content block for the result of a built-in search tool call\n * @deprecated Use ServerToolCallResult instead\n */\n export interface WebSearchResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_result\";\n /**\n * List of URLs returned by the web search tool call\n */\n urls?: string[];\n }\n\n /**\n * Content block for a built-in code interpreter tool call.\n * @deprecated Use ServerToolCall instead\n */\n export interface CodeInterpreterCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_call\";\n /**\n * The language of the code executed by the code interpreter tool call\n */\n language?: string;\n /**\n * The code to be executed by the code interpreter\n */\n code?: string;\n }\n\n /**\n * Content block for the output of a singular code interpreter tool call\n * @deprecated Use ServerToolCallResult instead\n */\n export interface CodeInterpreterOutput {\n readonly type: \"code_interpreter_output\";\n /**\n * The return code of the code interpreter tool call\n * Example: 0 for success, non-zero for failure\n */\n returnCode?: number;\n /**\n * Standard error output of the executed code\n */\n stderr?: string;\n /**\n * Standard output of the executed code\n */\n stdout?: string;\n /**\n * File IDs of the files created by the code interpreter tool call\n */\n fileIds?: string[];\n }\n\n /**\n * Content block for the result of a code interpreter tool call\n * @deprecated Use ServerToolCallResult instead\n */\n export interface CodeInterpreterResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_result\";\n /**\n * The result of the code interpreter tool call\n */\n output: CodeInterpreterOutput[];\n }\n\n export type Standard =\n | ToolCall\n | ToolCallChunk\n | InvalidToolCall\n | ServerToolCall\n | ServerToolCallChunk\n | ServerToolCallResult\n | WebSearchCall\n | WebSearchResult\n | CodeInterpreterCall\n | CodeInterpreterResult;\n}\n"],"mappings":";;AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
1
+ {"version":3,"file":"tools.cjs","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"server_tool_call\",\n \"server_tool_call_chunk\",\n \"server_tool_call_result\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n export interface ToolCall<TName extends string = string, TArgs = unknown>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n /** Content block to represent partial data of a tool call */\n export interface ToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n\n /** Content block to represent an invalid tool call */\n export interface InvalidToolCall<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n\n export interface ServerToolCall<\n TName extends string = string,\n TArgs = unknown\n > extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n export interface ServerToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n\n export interface ServerToolCallResult<TOutput = Record<string, unknown>>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n\n export type Standard =\n | ToolCall\n | ToolCallChunk\n | InvalidToolCall\n | ServerToolCall\n | ServerToolCallChunk\n | ServerToolCallResult;\n}\n"],"mappings":";;AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;AACD"}
@@ -121,91 +121,7 @@ declare namespace Tools {
121
121
  */
122
122
  output: TOutput;
123
123
  }
124
- /**
125
- * Content block for a built-in web search tool call.
126
- * @deprecated Use ServerToolCall instead
127
- */
128
- interface WebSearchCall extends BaseContentBlock {
129
- /**
130
- * Type of the content block
131
- */
132
- readonly type: "web_search_call";
133
- /**
134
- * The search query used in the web search tool call
135
- */
136
- query?: string;
137
- }
138
- /**
139
- * Content block for the result of a built-in search tool call
140
- * @deprecated Use ServerToolCallResult instead
141
- */
142
- interface WebSearchResult extends BaseContentBlock {
143
- /**
144
- * Type of the content block
145
- */
146
- readonly type: "web_search_result";
147
- /**
148
- * List of URLs returned by the web search tool call
149
- */
150
- urls?: string[];
151
- }
152
- /**
153
- * Content block for a built-in code interpreter tool call.
154
- * @deprecated Use ServerToolCall instead
155
- */
156
- interface CodeInterpreterCall extends BaseContentBlock {
157
- /**
158
- * Type of the content block
159
- */
160
- readonly type: "code_interpreter_call";
161
- /**
162
- * The language of the code executed by the code interpreter tool call
163
- */
164
- language?: string;
165
- /**
166
- * The code to be executed by the code interpreter
167
- */
168
- code?: string;
169
- }
170
- /**
171
- * Content block for the output of a singular code interpreter tool call
172
- * @deprecated Use ServerToolCallResult instead
173
- */
174
- interface CodeInterpreterOutput {
175
- readonly type: "code_interpreter_output";
176
- /**
177
- * The return code of the code interpreter tool call
178
- * Example: 0 for success, non-zero for failure
179
- */
180
- returnCode?: number;
181
- /**
182
- * Standard error output of the executed code
183
- */
184
- stderr?: string;
185
- /**
186
- * Standard output of the executed code
187
- */
188
- stdout?: string;
189
- /**
190
- * File IDs of the files created by the code interpreter tool call
191
- */
192
- fileIds?: string[];
193
- }
194
- /**
195
- * Content block for the result of a code interpreter tool call
196
- * @deprecated Use ServerToolCallResult instead
197
- */
198
- interface CodeInterpreterResult extends BaseContentBlock {
199
- /**
200
- * Type of the content block
201
- */
202
- readonly type: "code_interpreter_result";
203
- /**
204
- * The result of the code interpreter tool call
205
- */
206
- output: CodeInterpreterOutput[];
207
- }
208
- type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult | WebSearchCall | WebSearchResult | CodeInterpreterCall | CodeInterpreterResult;
124
+ type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;
209
125
  }
210
126
  //#endregion
211
127
  export { Tools };
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.cts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","Record","TOutput","CodeInterpreterOutput","ToolCall","ToolCallChunk","InvalidToolCall","ServerToolCall","ServerToolCallChunk","ServerToolCallResult","WebSearchCall","WebSearchResult","CodeInterpreterCall","CodeInterpreterResult"],"sources":["../../../src/messages/content/tools.d.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\nexport type Tools = never;\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n interface ToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n /** Content block to represent partial data of a tool call */\n interface ToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n /** Content block to represent an invalid tool call */\n interface InvalidToolCall<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n /**\n * Content block for a built-in web search tool call.\n * @deprecated Use ServerToolCall instead\n */\n interface WebSearchCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_call\";\n /**\n * The search query used in the web search tool call\n */\n query?: string;\n }\n /**\n * Content block for the result of a built-in search tool call\n * @deprecated Use ServerToolCallResult instead\n */\n interface WebSearchResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_result\";\n /**\n * List of URLs returned by the web search tool call\n */\n urls?: string[];\n }\n /**\n * Content block for a built-in code interpreter tool call.\n * @deprecated Use ServerToolCall instead\n */\n interface CodeInterpreterCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_call\";\n /**\n * The language of the code executed by the code interpreter tool call\n */\n language?: string;\n /**\n * The code to be executed by the code interpreter\n */\n code?: string;\n }\n /**\n * Content block for the output of a singular code interpreter tool call\n * @deprecated Use ServerToolCallResult instead\n */\n interface CodeInterpreterOutput {\n readonly type: \"code_interpreter_output\";\n /**\n * The return code of the code interpreter tool call\n * Example: 0 for success, non-zero for failure\n */\n returnCode?: number;\n /**\n * Standard error output of the executed code\n */\n stderr?: string;\n /**\n * Standard output of the executed code\n */\n stdout?: string;\n /**\n * File IDs of the files created by the code interpreter tool call\n */\n fileIds?: string[];\n }\n /**\n * Content block for the result of a code interpreter tool call\n * @deprecated Use ServerToolCallResult instead\n */\n interface CodeInterpreterResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_result\";\n /**\n * The result of the code interpreter tool call\n */\n output: CodeInterpreterOutput[];\n }\n type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult | WebSearchCall | WebSearchResult | CodeInterpreterCall | CodeInterpreterResult;\n}\n"],"mappings":";;;KACYC,KAAAA;AAAZ;AAGyBA,kBAAAA,KAAAA,CAAK;EAAA;;;;;;;;;;;;;;;EAoHP,UAhBuDD,QAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,EAAAA,QAAAA,OAAAA,CAAAA,SApFCA,gBAoFDA,CAAAA;IAsB1CA;;;IA8EpBO,SAAAA,IAAAA,EAAAA,WAAAA;IAR4BP;;;IAUGU,IAAAA,EAlLjCP,KAkLiCO;IAAkBC;;;IAA8DG,IAAAA,EA9KjHV,KA8KiHU;EAAa;EAAkB;EAAsB,UAAGG,aAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,CAAAA,SA3KpHjB,gBA2KoHiB,CAAAA;IAAqB;;;;;;;WAnK7Ld;;;;;;;;;;;mEAWsDH;;;;;;;;WAQtDG;;;;;;;;;;;;;;mFAcsEH;;;;;;;;UAQvEG;;;;UAIAC;;uEAE2DJ;;;;;;;;WAQ1DG;;;;;;2CAM8BE,iCAAiCL;;;;;;;;;;;;;;;;YAgB9DM;;;;;;kCAMoBN;;;;;;;;;;;;;;oCAcEA;;;;;;;;;;;;;;wCAcIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0CEA;;;;;;;;YAQ5BO;;kBAEIC,WAAWC,gBAAgBC,kBAAkBC,iBAAiBC,sBAAsBC,uBAAuBC,gBAAgBC,kBAAkBC,sBAAsBC"}
1
+ {"version":3,"file":"tools.d.cts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","Record","TOutput","ToolCall","ToolCallChunk","InvalidToolCall","ServerToolCall","ServerToolCallChunk","ServerToolCallResult"],"sources":["../../../src/messages/content/tools.d.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\nexport type Tools = never;\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n interface ToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n /** Content block to represent partial data of a tool call */\n interface ToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n /** Content block to represent an invalid tool call */\n interface InvalidToolCall<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;\n}\n"],"mappings":";;;KACYC,KAAAA;AAAZ;AAGyBA,kBAAAA,KAAAA,CAAK;EAAA;;;;;;;;;;;;;;;EAoHP,UAhBuDD,QAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,EAAAA,QAAAA,OAAAA,CAAAA,SApFCA,gBAoFDA,CAAAA;IAkB1DO;;;IAA6CG,SAAAA,IAAAA,EAAAA,WAAAA;IAAiBC;;AAA0C;UA9F9GR;;;;UAIAC;;;iEAGqDJ;;;;;;;;WAQpDG;;;;;;;;;;;mEAWsDH;;;;;;;;WAQtDG;;;;;;;;;;;;;;mFAcsEH;;;;;;;;UAQvEG;;;;UAIAC;;uEAE2DJ;;;;;;;;WAQ1DG;;;;;;2CAM8BE,iCAAiCL;;;;;;;;;;;;;;;;YAgB9DM;;kBAEIC,WAAWC,gBAAgBC,kBAAkBC,iBAAiBC,sBAAsBC"}