@langchain/core 1.2.10 → 1.2.11
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.
- package/CHANGELOG.md +14 -0
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/chat_models.cjs +12 -12
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +13 -13
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/messages/block_translators/openai.cjs +212 -164
- package/dist/messages/block_translators/openai.cjs.map +1 -1
- package/dist/messages/block_translators/openai.js +212 -164
- package/dist/messages/block_translators/openai.js.map +1 -1
- package/package.json +2 -2
|
@@ -158,6 +158,164 @@ function convertResponsesAnnotation(annotation) {
|
|
|
158
158
|
}
|
|
159
159
|
return annotation;
|
|
160
160
|
}
|
|
161
|
+
/** Builds a reasoning content block, including id/encrypted_content when present. */
|
|
162
|
+
function mapReasoningItemToV1(item) {
|
|
163
|
+
if (!_isArray(item.summary)) return void 0;
|
|
164
|
+
return {
|
|
165
|
+
type: "reasoning",
|
|
166
|
+
reasoning: item.summary.reduce((acc, part) => {
|
|
167
|
+
if (_isObject(part) && _isString(part.text)) return `${acc}${part.text}`;
|
|
168
|
+
return acc;
|
|
169
|
+
}, ""),
|
|
170
|
+
..._isString(item.id) ? { id: item.id } : {},
|
|
171
|
+
..._isString(item.encrypted_content) ? { encrypted_content: item.encrypted_content } : {}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function* mapToolOutputToV1Blocks(toolOutput) {
|
|
175
|
+
if (_isContentBlock(toolOutput, "web_search_call")) {
|
|
176
|
+
const webSearchArgs = {};
|
|
177
|
+
if (_isObject(toolOutput.action) && _isString(toolOutput.action.query)) webSearchArgs.query = toolOutput.action.query;
|
|
178
|
+
yield {
|
|
179
|
+
id: toolOutput.id,
|
|
180
|
+
type: "server_tool_call",
|
|
181
|
+
name: "web_search",
|
|
182
|
+
args: webSearchArgs
|
|
183
|
+
};
|
|
184
|
+
if (toolOutput.status === "completed" || toolOutput.status === "failed") {
|
|
185
|
+
const output = {};
|
|
186
|
+
if (_isObject(toolOutput.action)) output.action = toolOutput.action;
|
|
187
|
+
yield {
|
|
188
|
+
type: "server_tool_call_result",
|
|
189
|
+
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
190
|
+
status: toolOutput.status === "completed" ? "success" : "error",
|
|
191
|
+
output
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (_isContentBlock(toolOutput, "file_search_call")) {
|
|
197
|
+
yield {
|
|
198
|
+
id: toolOutput.id,
|
|
199
|
+
type: "server_tool_call",
|
|
200
|
+
name: "file_search",
|
|
201
|
+
args: { queries: _isArray(toolOutput.queries) ? toolOutput.queries : [] }
|
|
202
|
+
};
|
|
203
|
+
if (toolOutput.status === "completed" || toolOutput.status === "failed") yield {
|
|
204
|
+
type: "server_tool_call_result",
|
|
205
|
+
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
206
|
+
status: toolOutput.status === "completed" ? "success" : "error",
|
|
207
|
+
output: _isArray(toolOutput.results) ? { results: toolOutput.results } : {}
|
|
208
|
+
};
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (_isContentBlock(toolOutput, "computer_call")) {
|
|
212
|
+
yield {
|
|
213
|
+
type: "non_standard",
|
|
214
|
+
value: toolOutput
|
|
215
|
+
};
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (_isContentBlock(toolOutput, "code_interpreter_call")) {
|
|
219
|
+
if (_isString(toolOutput.code)) yield {
|
|
220
|
+
id: toolOutput.id,
|
|
221
|
+
type: "server_tool_call",
|
|
222
|
+
name: "code_interpreter",
|
|
223
|
+
args: { code: toolOutput.code }
|
|
224
|
+
};
|
|
225
|
+
if (_isArray(toolOutput.outputs)) {
|
|
226
|
+
const returnCode = iife(() => {
|
|
227
|
+
if (toolOutput.status === "in_progress") return void 0;
|
|
228
|
+
if (toolOutput.status === "completed") return 0;
|
|
229
|
+
if (toolOutput.status === "incomplete") return 127;
|
|
230
|
+
if (toolOutput.status === "interpreting") return void 0;
|
|
231
|
+
if (toolOutput.status === "failed") return 1;
|
|
232
|
+
});
|
|
233
|
+
for (const output of toolOutput.outputs) if (_isContentBlock(output, "logs")) yield {
|
|
234
|
+
type: "server_tool_call_result",
|
|
235
|
+
toolCallId: toolOutput.id ?? "",
|
|
236
|
+
status: "success",
|
|
237
|
+
output: {
|
|
238
|
+
type: "code_interpreter_output",
|
|
239
|
+
returnCode: returnCode ?? 0,
|
|
240
|
+
stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
|
|
241
|
+
stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (_isContentBlock(toolOutput, "mcp_call")) {
|
|
248
|
+
yield {
|
|
249
|
+
id: toolOutput.id,
|
|
250
|
+
type: "server_tool_call",
|
|
251
|
+
name: "mcp_call",
|
|
252
|
+
args: toolOutput.input
|
|
253
|
+
};
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (_isContentBlock(toolOutput, "mcp_list_tools")) {
|
|
257
|
+
yield {
|
|
258
|
+
id: toolOutput.id,
|
|
259
|
+
type: "server_tool_call",
|
|
260
|
+
name: "mcp_list_tools",
|
|
261
|
+
args: toolOutput.input
|
|
262
|
+
};
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (_isContentBlock(toolOutput, "mcp_approval_request")) {
|
|
266
|
+
yield {
|
|
267
|
+
type: "non_standard",
|
|
268
|
+
value: toolOutput
|
|
269
|
+
};
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (_isContentBlock(toolOutput, "tool_search_call")) {
|
|
273
|
+
const toolSearchArgs = {};
|
|
274
|
+
if (_isObject(toolOutput.arguments)) Object.assign(toolSearchArgs, toolOutput.arguments);
|
|
275
|
+
const toolSearchCallExtras = {};
|
|
276
|
+
if (_isString(toolOutput.execution)) toolSearchCallExtras.execution = toolOutput.execution;
|
|
277
|
+
if (_isString(toolOutput.status)) toolSearchCallExtras.status = toolOutput.status;
|
|
278
|
+
if (_isString(toolOutput.call_id)) toolSearchCallExtras.call_id = toolOutput.call_id;
|
|
279
|
+
yield {
|
|
280
|
+
id: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
281
|
+
type: "server_tool_call",
|
|
282
|
+
name: "tool_search",
|
|
283
|
+
args: toolSearchArgs,
|
|
284
|
+
...Object.keys(toolSearchCallExtras).length > 0 ? { extras: toolSearchCallExtras } : {}
|
|
285
|
+
};
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (_isContentBlock(toolOutput, "tool_search_output")) {
|
|
289
|
+
const toolSearchOutputExtras = { name: "tool_search" };
|
|
290
|
+
if (_isString(toolOutput.execution)) toolSearchOutputExtras.execution = toolOutput.execution;
|
|
291
|
+
yield {
|
|
292
|
+
type: "server_tool_call_result",
|
|
293
|
+
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
294
|
+
status: toolOutput.status === "completed" ? "success" : toolOutput.status === "failed" ? "error" : "success",
|
|
295
|
+
output: { tools: _isArray(toolOutput.tools) ? toolOutput.tools : [] },
|
|
296
|
+
extras: toolSearchOutputExtras
|
|
297
|
+
};
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (_isContentBlock(toolOutput, "image_generation_call")) {
|
|
301
|
+
if (_isString(toolOutput.result)) yield {
|
|
302
|
+
type: "image",
|
|
303
|
+
mimeType: "image/png",
|
|
304
|
+
data: toolOutput.result,
|
|
305
|
+
id: _isString(toolOutput.id) ? toolOutput.id : void 0,
|
|
306
|
+
metadata: { status: _isString(toolOutput.status) ? toolOutput.status : void 0 }
|
|
307
|
+
};
|
|
308
|
+
yield {
|
|
309
|
+
type: "non_standard",
|
|
310
|
+
value: toolOutput
|
|
311
|
+
};
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (_isObject(toolOutput)) yield {
|
|
315
|
+
type: "non_standard",
|
|
316
|
+
value: toolOutput
|
|
317
|
+
};
|
|
318
|
+
}
|
|
161
319
|
/**
|
|
162
320
|
* Converts a ChatOpenAIResponses message to an array of v1 standard content blocks.
|
|
163
321
|
*
|
|
@@ -166,6 +324,14 @@ function convertResponsesAnnotation(annotation) {
|
|
|
166
324
|
* text content with annotations, tool calls, and various tool outputs including code interpreter,
|
|
167
325
|
* web search, file search, computer calls, and MCP-related blocks.
|
|
168
326
|
*
|
|
327
|
+
* A response can hold more than one reasoning item (e.g. multiple tool calls
|
|
328
|
+
* in one turn, common on GPT-5.6-class models). When `response_metadata.output`
|
|
329
|
+
* is available, each item's own `id`/`encrypted_content` is preserved and
|
|
330
|
+
* blocks are sorted back into original order, so replay under Zero Data
|
|
331
|
+
* Retention interleaves reasoning and tool calls correctly. Without it (e.g.
|
|
332
|
+
* a hand-built message), falls back to a single reasoning block from
|
|
333
|
+
* `additional_kwargs.reasoning`, as before.
|
|
334
|
+
*
|
|
169
335
|
* @param message - The AI message containing OpenAI Responses-formatted content blocks
|
|
170
336
|
* @returns Array of content blocks in v1 standard format
|
|
171
337
|
*
|
|
@@ -192,20 +358,38 @@ function convertResponsesAnnotation(annotation) {
|
|
|
192
358
|
* // { type: "reasoning", reasoning: "Let me calculate this..." },
|
|
193
359
|
* // { type: "text", text: "Hello world", annotations: [] },
|
|
194
360
|
* // { type: "tool_call", id: "123", name: "calculator", args: { a: 1, b: 2 } },
|
|
195
|
-
* // { type: "
|
|
196
|
-
* // { type: "
|
|
361
|
+
* // { type: "server_tool_call", name: "code_interpreter", args: { code: "print('hello')" } },
|
|
362
|
+
* // { type: "server_tool_call_result", toolCallId: "", status: "success", output: { type: "code_interpreter_output", returnCode: 0, stdout: "hello" } }
|
|
197
363
|
* // ]
|
|
198
364
|
* ```
|
|
199
365
|
*/
|
|
200
366
|
function convertToV1FromResponses(message) {
|
|
367
|
+
const rawOutput = message.response_metadata?.output;
|
|
368
|
+
const hasRawOutput = _isArray(rawOutput) && rawOutput.length > 0;
|
|
369
|
+
const positionByKey = /* @__PURE__ */ new Map();
|
|
370
|
+
let messageItemCount = 0;
|
|
371
|
+
let onlyMessageItemIndex;
|
|
372
|
+
if (hasRawOutput) rawOutput.forEach((rawItem, index) => {
|
|
373
|
+
if (!_isObject(rawItem) || !_isString(rawItem.type)) return;
|
|
374
|
+
if (rawItem.type === "reasoning" && _isString(rawItem.id)) positionByKey.set(`reasoning:${rawItem.id}`, index);
|
|
375
|
+
else if ((rawItem.type === "function_call" || rawItem.type === "custom_tool_call" || rawItem.type === "computer_call") && _isString(rawItem.call_id)) positionByKey.set(`tool_call:${rawItem.call_id}`, index);
|
|
376
|
+
else if (rawItem.type === "message") {
|
|
377
|
+
messageItemCount += 1;
|
|
378
|
+
onlyMessageItemIndex = index;
|
|
379
|
+
} else if (_isString(rawItem.id)) positionByKey.set(`other:${rawItem.type}:${rawItem.id}`, index);
|
|
380
|
+
});
|
|
381
|
+
const textBlockKey = messageItemCount === 1 && onlyMessageItemIndex != null ? `message:${onlyMessageItemIndex}` : void 0;
|
|
382
|
+
if (textBlockKey != null) positionByKey.set(textBlockKey, onlyMessageItemIndex);
|
|
201
383
|
function* iterateContent() {
|
|
202
|
-
if (
|
|
203
|
-
type
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
384
|
+
if (hasRawOutput) {
|
|
385
|
+
for (const rawItem of rawOutput) if (_isObject(rawItem) && rawItem.type === "reasoning") {
|
|
386
|
+
const block = mapReasoningItemToV1(rawItem);
|
|
387
|
+
if (block) yield [block, _isString(rawItem.id) ? `reasoning:${rawItem.id}` : void 0];
|
|
388
|
+
}
|
|
389
|
+
} else if (_isObject(message.additional_kwargs?.reasoning) && _isArray(message.additional_kwargs.reasoning.summary)) {
|
|
390
|
+
const block = mapReasoningItemToV1(message.additional_kwargs.reasoning);
|
|
391
|
+
if (block) yield [block, void 0];
|
|
392
|
+
}
|
|
209
393
|
const content = typeof message.content === "string" ? [{
|
|
210
394
|
type: "text",
|
|
211
395
|
text: message.content
|
|
@@ -215,173 +399,37 @@ function convertToV1FromResponses(message) {
|
|
|
215
399
|
const extras = _isObject(existingExtras) ? { ...existingExtras } : {};
|
|
216
400
|
if (_isString(phase)) extras.phase = phase;
|
|
217
401
|
const extrasSpread = Object.keys(extras).length > 0 ? { extras } : {};
|
|
218
|
-
|
|
402
|
+
yield [{
|
|
219
403
|
...rest,
|
|
220
404
|
...extrasSpread,
|
|
221
405
|
type: "text",
|
|
222
406
|
text: String(text),
|
|
223
|
-
annotations: annotations.map(convertResponsesAnnotation)
|
|
224
|
-
};
|
|
225
|
-
else yield {
|
|
226
|
-
...rest,
|
|
227
|
-
...extrasSpread,
|
|
228
|
-
type: "text",
|
|
229
|
-
text: String(text)
|
|
230
|
-
};
|
|
407
|
+
...Array.isArray(annotations) ? { annotations: annotations.map(convertResponsesAnnotation) } : {}
|
|
408
|
+
}, textBlockKey];
|
|
231
409
|
}
|
|
232
|
-
for (const toolCall of message.tool_calls ?? []) yield {
|
|
410
|
+
for (const toolCall of message.tool_calls ?? []) yield [{
|
|
233
411
|
type: "tool_call",
|
|
234
412
|
id: toolCall.id,
|
|
235
413
|
name: toolCall.name,
|
|
236
414
|
args: toolCall.args
|
|
237
|
-
};
|
|
415
|
+
}, toolCall.id ? `tool_call:${toolCall.id}` : void 0];
|
|
238
416
|
if (_isObject(message.additional_kwargs) && _isArray(message.additional_kwargs.tool_outputs)) for (const toolOutput of message.additional_kwargs.tool_outputs) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
* Build args from available action data.
|
|
242
|
-
* The ResponseFunctionWebSearch base type only has id, status, type.
|
|
243
|
-
* The action field (with query, sources, etc.) may be present at
|
|
244
|
-
* runtime when the `include` parameter includes "web_search_call.action.sources".
|
|
245
|
-
*/
|
|
246
|
-
const webSearchArgs = {};
|
|
247
|
-
if (_isObject(toolOutput.action) && _isString(toolOutput.action.query)) webSearchArgs.query = toolOutput.action.query;
|
|
248
|
-
yield {
|
|
249
|
-
id: toolOutput.id,
|
|
250
|
-
type: "server_tool_call",
|
|
251
|
-
name: "web_search",
|
|
252
|
-
args: webSearchArgs
|
|
253
|
-
};
|
|
254
|
-
if (toolOutput.status === "completed" || toolOutput.status === "failed") {
|
|
255
|
-
const output = {};
|
|
256
|
-
if (_isObject(toolOutput.action)) output.action = toolOutput.action;
|
|
257
|
-
yield {
|
|
258
|
-
type: "server_tool_call_result",
|
|
259
|
-
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
260
|
-
status: toolOutput.status === "completed" ? "success" : "error",
|
|
261
|
-
output
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
continue;
|
|
265
|
-
} else if (_isContentBlock(toolOutput, "file_search_call")) {
|
|
266
|
-
yield {
|
|
267
|
-
id: toolOutput.id,
|
|
268
|
-
type: "server_tool_call",
|
|
269
|
-
name: "file_search",
|
|
270
|
-
args: { queries: _isArray(toolOutput.queries) ? toolOutput.queries : [] }
|
|
271
|
-
};
|
|
272
|
-
if (toolOutput.status === "completed" || toolOutput.status === "failed") yield {
|
|
273
|
-
type: "server_tool_call_result",
|
|
274
|
-
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
275
|
-
status: toolOutput.status === "completed" ? "success" : "error",
|
|
276
|
-
output: _isArray(toolOutput.results) ? { results: toolOutput.results } : {}
|
|
277
|
-
};
|
|
278
|
-
continue;
|
|
279
|
-
} else if (_isContentBlock(toolOutput, "computer_call")) {
|
|
280
|
-
yield {
|
|
281
|
-
type: "non_standard",
|
|
282
|
-
value: toolOutput
|
|
283
|
-
};
|
|
284
|
-
continue;
|
|
285
|
-
} else if (_isContentBlock(toolOutput, "code_interpreter_call")) {
|
|
286
|
-
if (_isString(toolOutput.code)) yield {
|
|
287
|
-
id: toolOutput.id,
|
|
288
|
-
type: "server_tool_call",
|
|
289
|
-
name: "code_interpreter",
|
|
290
|
-
args: { code: toolOutput.code }
|
|
291
|
-
};
|
|
292
|
-
if (_isArray(toolOutput.outputs)) {
|
|
293
|
-
const returnCode = iife(() => {
|
|
294
|
-
if (toolOutput.status === "in_progress") return void 0;
|
|
295
|
-
if (toolOutput.status === "completed") return 0;
|
|
296
|
-
if (toolOutput.status === "incomplete") return 127;
|
|
297
|
-
if (toolOutput.status === "interpreting") return void 0;
|
|
298
|
-
if (toolOutput.status === "failed") return 1;
|
|
299
|
-
});
|
|
300
|
-
for (const output of toolOutput.outputs) if (_isContentBlock(output, "logs")) {
|
|
301
|
-
yield {
|
|
302
|
-
type: "server_tool_call_result",
|
|
303
|
-
toolCallId: toolOutput.id ?? "",
|
|
304
|
-
status: "success",
|
|
305
|
-
output: {
|
|
306
|
-
type: "code_interpreter_output",
|
|
307
|
-
returnCode: returnCode ?? 0,
|
|
308
|
-
stderr: [0, void 0].includes(returnCode) ? void 0 : String(output.logs),
|
|
309
|
-
stdout: [0, void 0].includes(returnCode) ? String(output.logs) : void 0
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
continue;
|
|
316
|
-
} else if (_isContentBlock(toolOutput, "mcp_call")) {
|
|
317
|
-
yield {
|
|
318
|
-
id: toolOutput.id,
|
|
319
|
-
type: "server_tool_call",
|
|
320
|
-
name: "mcp_call",
|
|
321
|
-
args: toolOutput.input
|
|
322
|
-
};
|
|
323
|
-
continue;
|
|
324
|
-
} else if (_isContentBlock(toolOutput, "mcp_list_tools")) {
|
|
325
|
-
yield {
|
|
326
|
-
id: toolOutput.id,
|
|
327
|
-
type: "server_tool_call",
|
|
328
|
-
name: "mcp_list_tools",
|
|
329
|
-
args: toolOutput.input
|
|
330
|
-
};
|
|
331
|
-
continue;
|
|
332
|
-
} else if (_isContentBlock(toolOutput, "mcp_approval_request")) {
|
|
333
|
-
yield {
|
|
334
|
-
type: "non_standard",
|
|
335
|
-
value: toolOutput
|
|
336
|
-
};
|
|
337
|
-
continue;
|
|
338
|
-
} else if (_isContentBlock(toolOutput, "tool_search_call")) {
|
|
339
|
-
const toolSearchArgs = {};
|
|
340
|
-
if (_isObject(toolOutput.arguments)) Object.assign(toolSearchArgs, toolOutput.arguments);
|
|
341
|
-
const toolSearchCallExtras = {};
|
|
342
|
-
if (_isString(toolOutput.execution)) toolSearchCallExtras.execution = toolOutput.execution;
|
|
343
|
-
if (_isString(toolOutput.status)) toolSearchCallExtras.status = toolOutput.status;
|
|
344
|
-
if (_isString(toolOutput.call_id)) toolSearchCallExtras.call_id = toolOutput.call_id;
|
|
345
|
-
yield {
|
|
346
|
-
id: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
347
|
-
type: "server_tool_call",
|
|
348
|
-
name: "tool_search",
|
|
349
|
-
args: toolSearchArgs,
|
|
350
|
-
...Object.keys(toolSearchCallExtras).length > 0 ? { extras: toolSearchCallExtras } : {}
|
|
351
|
-
};
|
|
352
|
-
continue;
|
|
353
|
-
} else if (_isContentBlock(toolOutput, "tool_search_output")) {
|
|
354
|
-
const toolSearchOutputExtras = { name: "tool_search" };
|
|
355
|
-
if (_isString(toolOutput.execution)) toolSearchOutputExtras.execution = toolOutput.execution;
|
|
356
|
-
yield {
|
|
357
|
-
type: "server_tool_call_result",
|
|
358
|
-
toolCallId: _isString(toolOutput.id) ? toolOutput.id : "",
|
|
359
|
-
status: toolOutput.status === "completed" ? "success" : toolOutput.status === "failed" ? "error" : "success",
|
|
360
|
-
output: { tools: _isArray(toolOutput.tools) ? toolOutput.tools : [] },
|
|
361
|
-
extras: toolSearchOutputExtras
|
|
362
|
-
};
|
|
363
|
-
continue;
|
|
364
|
-
} else if (_isContentBlock(toolOutput, "image_generation_call")) {
|
|
365
|
-
if (_isString(toolOutput.result)) yield {
|
|
366
|
-
type: "image",
|
|
367
|
-
mimeType: "image/png",
|
|
368
|
-
data: toolOutput.result,
|
|
369
|
-
id: _isString(toolOutput.id) ? toolOutput.id : void 0,
|
|
370
|
-
metadata: { status: _isString(toolOutput.status) ? toolOutput.status : void 0 }
|
|
371
|
-
};
|
|
372
|
-
yield {
|
|
373
|
-
type: "non_standard",
|
|
374
|
-
value: toolOutput
|
|
375
|
-
};
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
if (_isObject(toolOutput)) yield {
|
|
379
|
-
type: "non_standard",
|
|
380
|
-
value: toolOutput
|
|
381
|
-
};
|
|
417
|
+
const key = _isObject(toolOutput) && _isString(toolOutput.type) && _isString(toolOutput.id) ? `other:${toolOutput.type}:${toolOutput.id}` : void 0;
|
|
418
|
+
for (const block of mapToolOutputToV1Blocks(toolOutput)) yield [block, key];
|
|
382
419
|
}
|
|
383
420
|
}
|
|
384
|
-
|
|
421
|
+
const withKeys = Array.from(iterateContent());
|
|
422
|
+
if (!hasRawOutput) return withKeys.map(([block]) => block);
|
|
423
|
+
return withKeys.map(([block, key], pushIndex) => ({
|
|
424
|
+
block,
|
|
425
|
+
pushIndex,
|
|
426
|
+
position: key != null ? positionByKey.get(key) : void 0
|
|
427
|
+
})).sort((a, b) => {
|
|
428
|
+
const aPos = a.position ?? Number.POSITIVE_INFINITY;
|
|
429
|
+
const bPos = b.position ?? Number.POSITIVE_INFINITY;
|
|
430
|
+
if (aPos !== bPos) return aPos - bPos;
|
|
431
|
+
return a.pushIndex - b.pushIndex;
|
|
432
|
+
}).map((entry) => entry.block);
|
|
385
433
|
}
|
|
386
434
|
/**
|
|
387
435
|
* Converts a ChatOpenAIResponses message chunk to an array of v1 standard content blocks.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","names":[],"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 // Only add text block if content is non-empty\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\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 // Only add text block if content is non-empty\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\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 {\n text,\n annotations,\n phase,\n extras: existingExtras,\n ...rest\n } = block;\n const extras: Record<string, unknown> = _isObject(existingExtras)\n ? { ...(existingExtras as Record<string, unknown>) }\n : {};\n if (_isString(phase)) {\n extras.phase = phase;\n }\n const extrasSpread = Object.keys(extras).length > 0 ? { extras } : {};\n if (Array.isArray(annotations)) {\n yield {\n ...rest,\n ...extrasSpread,\n type: \"text\",\n text: String(text),\n annotations: annotations.map(convertResponsesAnnotation),\n };\n } else {\n yield {\n ...rest,\n ...extrasSpread,\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 /**\n * Build args from available action data.\n * The ResponseFunctionWebSearch base type only has id, status, type.\n * The action field (with query, sources, etc.) may be present at\n * runtime when the `include` parameter includes \"web_search_call.action.sources\".\n */\n const webSearchArgs: Record<string, unknown> = {};\n if (\n _isObject(toolOutput.action) &&\n _isString(toolOutput.action.query)\n ) {\n webSearchArgs.query = toolOutput.action.query;\n }\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: webSearchArgs,\n };\n // Emit a server_tool_call_result when the search has completed or failed\n if (\n toolOutput.status === \"completed\" ||\n toolOutput.status === \"failed\"\n ) {\n const output: Record<string, unknown> = {};\n if (_isObject(toolOutput.action)) {\n output.action = toolOutput.action;\n }\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n output,\n };\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: {\n queries: _isArray(toolOutput.queries) ? toolOutput.queries : [],\n },\n };\n // Emit a server_tool_call_result when results are available\n if (\n toolOutput.status === \"completed\" ||\n toolOutput.status === \"failed\"\n ) {\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n output: _isArray(toolOutput.results)\n ? { results: toolOutput.results }\n : {},\n };\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, \"tool_search_call\")) {\n const toolSearchArgs: Record<string, unknown> = {};\n if (_isObject(toolOutput.arguments)) {\n Object.assign(toolSearchArgs, toolOutput.arguments);\n }\n const toolSearchCallExtras: Record<string, unknown> = {};\n if (_isString(toolOutput.execution)) {\n toolSearchCallExtras.execution = toolOutput.execution;\n }\n if (_isString(toolOutput.status)) {\n toolSearchCallExtras.status = toolOutput.status;\n }\n if (_isString(toolOutput.call_id)) {\n toolSearchCallExtras.call_id = toolOutput.call_id;\n }\n yield {\n id: _isString(toolOutput.id) ? toolOutput.id : \"\",\n type: \"server_tool_call\",\n name: \"tool_search\",\n args: toolSearchArgs,\n ...(Object.keys(toolSearchCallExtras).length > 0\n ? { extras: toolSearchCallExtras }\n : {}),\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"tool_search_output\")) {\n const toolSearchOutputExtras: Record<string, unknown> = {\n name: \"tool_search\",\n };\n if (_isString(toolOutput.execution)) {\n toolSearchOutputExtras.execution = toolOutput.execution;\n }\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status:\n toolOutput.status === \"completed\"\n ? \"success\"\n : toolOutput.status === \"failed\"\n ? \"error\"\n : \"success\",\n output: {\n tools: _isArray(toolOutput.tools) ? toolOutput.tools : [],\n },\n extras: toolSearchOutputExtras,\n };\n continue;\n } else if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n // Convert image_generation_call to proper image content block if result is available\n if (_isString(toolOutput.result)) {\n yield {\n type: \"image\",\n mimeType: \"image/png\",\n data: toolOutput.result,\n id: _isString(toolOutput.id) ? toolOutput.id : undefined,\n metadata: {\n status: _isString(toolOutput.status)\n ? toolOutput.status\n : undefined,\n },\n };\n }\n // Also yield as non_standard for backwards compatibility\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,+BACd,SAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,IAAI,OAAO,QAAQ,YAAY,UAEzB;MAAA,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EAChB,CAAC;CAAA,OAGH,OAAO,KAAK,GAAG,oCAAoC,QAAQ,OAAO,CAAC;CAErE,KAAK,MAAM,YAAY,QAAQ,cAAc,CAAC,GAC5C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CACjB,CAAC;CAEH,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,oCACd,SAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,IAAI,OAAO,QAAQ,YAAY,UAEzB;MAAA,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EAChB,CAAC;CAAA,OAGH,OAAO,KAAK,GAAG,o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D,QACE,WAAW,WAAW,cAClB,YACA,WAAW,WAAW,WACpB,UACA;KACR,QAAQ,EACN,OAAO,SAAS,WAAW,KAAK,IAAI,WAAW,QAAQ,CAAC,EAC1D;KACA,QAAQ;IACV;IACA;GACF,OAAO,IAAI,gBAAgB,YAAY,uBAAuB,GAAG;IAE/D,IAAI,UAAU,WAAW,MAAM,GAC7B,MAAM;KACJ,MAAM;KACN,UAAU;KACV,MAAM,WAAW;KACjB,IAAI,UAAU,WAAW,EAAE,IAAI,WAAW,KAAK,KAAA;KAC/C,UAAU,EACR,QAAQ,UAAU,WAAW,MAAM,IAC/B,WAAW,SACX,KAAA,EACN;IACF;IAGF,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAW;IAChD;GACF;GACA,IAAI,UAAU,UAAU,GACtB,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAW;EAEpD;CAEJ;CACA,OAAO,MAAM,KAAK,eAAe,CAAC;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,8BACd,SAC8B;CAC9B,UAAU,iBAAkD;EAC1D,OAAO,yBAAyB,OAAO;EACvC,KAAK,MAAM,iBAAiB,QAAQ,oBAAoB,CAAC,GACvD,MAAM;GACJ,MAAM;GACN,IAAI,cAAc;GAClB,MAAM,cAAc;GACpB,MAAM,cAAc;EACtB;CAEJ;CACA,OAAO,MAAM,KAAK,eAAe,CAAC;AACpC;AAEA,MAAa,uBAAuD;CAClE,mBAAmB,YAAY;EAC7B,IAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,+BAA+B,OAAO;EAE/C,OAAO,yBAAyB,OAAO;CACzC;CACA,wBAAwB,YAAY;EAClC,IAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,oCAAoC,OAAO;EAEpD,OAAO,8BAA8B,OAAO;CAC9C;AACF"}
|
|
1
|
+
{"version":3,"file":"openai.js","names":[],"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 // Only add text block if content is non-empty\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\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 // Only add text block if content is non-empty\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\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/** Builds a reasoning content block, including id/encrypted_content when present. */\nfunction mapReasoningItemToV1(\n item: Record<string, unknown>\n): ContentBlock.Standard | undefined {\n if (!_isArray(item.summary)) return undefined;\n const summary = item.summary.reduce<string>((acc, part) => {\n if (_isObject(part) && _isString(part.text)) {\n return `${acc}${part.text}`;\n }\n return acc;\n }, \"\");\n return {\n type: \"reasoning\",\n reasoning: summary,\n ...(_isString(item.id) ? { id: item.id } : {}),\n ...(_isString(item.encrypted_content)\n ? { encrypted_content: item.encrypted_content }\n : {}),\n } as ContentBlock.Standard;\n}\n\n// Converts a single built-in tool call/result entry into v1 content blocks.\nfunction* mapToolOutputToV1Blocks(\n toolOutput: unknown\n): Iterable<ContentBlock.Standard> {\n if (_isContentBlock(toolOutput, \"web_search_call\")) {\n const webSearchArgs: Record<string, unknown> = {};\n if (_isObject(toolOutput.action) && _isString(toolOutput.action.query)) {\n webSearchArgs.query = toolOutput.action.query;\n }\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: webSearchArgs,\n };\n // Emit a server_tool_call_result when the search has completed or failed\n if (toolOutput.status === \"completed\" || toolOutput.status === \"failed\") {\n const output: Record<string, unknown> = {};\n if (_isObject(toolOutput.action)) {\n output.action = toolOutput.action;\n }\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n output,\n };\n }\n return;\n }\n if (_isContentBlock(toolOutput, \"file_search_call\")) {\n yield {\n id: toolOutput.id,\n type: \"server_tool_call\",\n name: \"file_search\",\n args: {\n queries: _isArray(toolOutput.queries) ? toolOutput.queries : [],\n },\n };\n // Emit a server_tool_call_result when results are available\n if (toolOutput.status === \"completed\" || toolOutput.status === \"failed\") {\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status: toolOutput.status === \"completed\" ? \"success\" : \"error\",\n output: _isArray(toolOutput.results)\n ? { results: toolOutput.results }\n : {},\n };\n }\n return;\n }\n if (_isContentBlock(toolOutput, \"computer_call\")) {\n yield { type: \"non_standard\", value: toolOutput };\n return;\n }\n 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 }\n }\n }\n return;\n }\n 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 return;\n }\n 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 return;\n }\n if (_isContentBlock(toolOutput, \"mcp_approval_request\")) {\n yield { type: \"non_standard\", value: toolOutput };\n return;\n }\n if (_isContentBlock(toolOutput, \"tool_search_call\")) {\n const toolSearchArgs: Record<string, unknown> = {};\n if (_isObject(toolOutput.arguments)) {\n Object.assign(toolSearchArgs, toolOutput.arguments);\n }\n const toolSearchCallExtras: Record<string, unknown> = {};\n if (_isString(toolOutput.execution)) {\n toolSearchCallExtras.execution = toolOutput.execution;\n }\n if (_isString(toolOutput.status)) {\n toolSearchCallExtras.status = toolOutput.status;\n }\n if (_isString(toolOutput.call_id)) {\n toolSearchCallExtras.call_id = toolOutput.call_id;\n }\n yield {\n id: _isString(toolOutput.id) ? toolOutput.id : \"\",\n type: \"server_tool_call\",\n name: \"tool_search\",\n args: toolSearchArgs,\n ...(Object.keys(toolSearchCallExtras).length > 0\n ? { extras: toolSearchCallExtras }\n : {}),\n };\n return;\n }\n if (_isContentBlock(toolOutput, \"tool_search_output\")) {\n const toolSearchOutputExtras: Record<string, unknown> = {\n name: \"tool_search\",\n };\n if (_isString(toolOutput.execution)) {\n toolSearchOutputExtras.execution = toolOutput.execution;\n }\n yield {\n type: \"server_tool_call_result\",\n toolCallId: _isString(toolOutput.id) ? toolOutput.id : \"\",\n status:\n toolOutput.status === \"completed\"\n ? \"success\"\n : toolOutput.status === \"failed\"\n ? \"error\"\n : \"success\",\n output: {\n tools: _isArray(toolOutput.tools) ? toolOutput.tools : [],\n },\n extras: toolSearchOutputExtras,\n };\n return;\n }\n if (_isContentBlock(toolOutput, \"image_generation_call\")) {\n // Convert image_generation_call to proper image content block if result is available\n if (_isString(toolOutput.result)) {\n yield {\n type: \"image\",\n mimeType: \"image/png\",\n data: toolOutput.result,\n id: _isString(toolOutput.id) ? toolOutput.id : undefined,\n metadata: {\n status: _isString(toolOutput.status) ? toolOutput.status : undefined,\n },\n };\n }\n // Also yield as non_standard for backwards compatibility\n yield { type: \"non_standard\", value: toolOutput };\n return;\n }\n if (_isObject(toolOutput)) {\n yield { type: \"non_standard\", value: toolOutput };\n }\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 * A response can hold more than one reasoning item (e.g. multiple tool calls\n * in one turn, common on GPT-5.6-class models). When `response_metadata.output`\n * is available, each item's own `id`/`encrypted_content` is preserved and\n * blocks are sorted back into original order, so replay under Zero Data\n * Retention interleaves reasoning and tool calls correctly. Without it (e.g.\n * a hand-built message), falls back to a single reasoning block from\n * `additional_kwargs.reasoning`, as before.\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: \"server_tool_call\", name: \"code_interpreter\", args: { code: \"print('hello')\" } },\n * // { type: \"server_tool_call_result\", toolCallId: \"\", status: \"success\", output: { type: \"code_interpreter_output\", returnCode: 0, stdout: \"hello\" } }\n * // ]\n * ```\n */\nexport function convertToV1FromResponses(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const rawOutput = message.response_metadata?.output;\n const hasRawOutput = _isArray(rawOutput) && rawOutput.length > 0;\n\n // Maps a per-item key (namespaced by type, since ids aren't globally unique) to its original response.output position.\n const positionByKey = new Map<string, number>();\n let messageItemCount = 0;\n let onlyMessageItemIndex: number | undefined;\n if (hasRawOutput) {\n (rawOutput as unknown[]).forEach((rawItem, index) => {\n if (!_isObject(rawItem) || !_isString(rawItem.type)) return;\n if (rawItem.type === \"reasoning\" && _isString(rawItem.id)) {\n positionByKey.set(`reasoning:${rawItem.id}`, index);\n } else if (\n // These three types all become tool_call blocks keyed by call_id.\n (rawItem.type === \"function_call\" ||\n rawItem.type === \"custom_tool_call\" ||\n rawItem.type === \"computer_call\") &&\n _isString(rawItem.call_id)\n ) {\n positionByKey.set(`tool_call:${rawItem.call_id}`, index);\n } else if (rawItem.type === \"message\") {\n messageItemCount += 1;\n onlyMessageItemIndex = index;\n } else if (_isString(rawItem.id)) {\n positionByKey.set(`other:${rawItem.type}:${rawItem.id}`, index);\n }\n });\n }\n // Text isn't keyed to a specific \"message\" item, so only position it when exactly one exists (an unambiguous match).\n const textBlockKey =\n messageItemCount === 1 && onlyMessageItemIndex != null\n ? `message:${onlyMessageItemIndex}`\n : undefined;\n if (textBlockKey != null) {\n positionByKey.set(textBlockKey, onlyMessageItemIndex as number);\n }\n\n function* iterateContent(): Iterable<\n [block: ContentBlock.Standard, key: string | undefined]\n > {\n if (hasRawOutput) {\n for (const rawItem of rawOutput as unknown[]) {\n if (_isObject(rawItem) && rawItem.type === \"reasoning\") {\n const block = mapReasoningItemToV1(rawItem);\n if (block) {\n yield [\n block,\n _isString(rawItem.id) ? `reasoning:${rawItem.id}` : undefined,\n ];\n }\n }\n }\n } else if (\n _isObject(message.additional_kwargs?.reasoning) &&\n _isArray(message.additional_kwargs.reasoning.summary)\n ) {\n const block = mapReasoningItemToV1(message.additional_kwargs.reasoning);\n if (block) yield [block, undefined];\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 {\n text,\n annotations,\n phase,\n extras: existingExtras,\n ...rest\n } = block;\n const extras: Record<string, unknown> = _isObject(existingExtras)\n ? { ...(existingExtras as Record<string, unknown>) }\n : {};\n if (_isString(phase)) {\n extras.phase = phase;\n }\n const extrasSpread = Object.keys(extras).length > 0 ? { extras } : {};\n yield [\n {\n ...rest,\n ...extrasSpread,\n type: \"text\",\n text: String(text),\n ...(Array.isArray(annotations)\n ? { annotations: annotations.map(convertResponsesAnnotation) }\n : {}),\n },\n textBlockKey,\n ];\n }\n }\n for (const toolCall of message.tool_calls ?? []) {\n yield [\n {\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n },\n toolCall.id ? `tool_call:${toolCall.id}` : undefined,\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 // All blocks from one tool output share this key -- fine since the API returns a call and its result as one item.\n const key =\n _isObject(toolOutput) &&\n _isString(toolOutput.type) &&\n _isString(toolOutput.id)\n ? `other:${toolOutput.type}:${toolOutput.id}`\n : undefined;\n for (const block of mapToolOutputToV1Blocks(toolOutput)) {\n yield [block, key];\n }\n }\n }\n }\n\n const withKeys = Array.from(iterateContent());\n if (!hasRawOutput) {\n return withKeys.map(([block]) => block);\n }\n // Stable sort by original position; unkeyed blocks sort last, in push order.\n return withKeys\n .map(([block, key], pushIndex) => ({\n block,\n pushIndex,\n position: key != null ? positionByKey.get(key) : undefined,\n }))\n .sort((a, b) => {\n const aPos = a.position ?? Number.POSITIVE_INFINITY;\n const bPos = b.position ?? Number.POSITIVE_INFINITY;\n if (aPos !== bPos) return aPos - bPos;\n return a.pushIndex - b.pushIndex;\n })\n .map((entry) => entry.block);\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,+BACd,SAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,IAAI,OAAO,QAAQ,YAAY,UAEzB;MAAA,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EAChB,CAAC;CAAA,OAGH,OAAO,KAAK,GAAG,oCAAoC,QAAQ,OAAO,CAAC;CAErE,KAAK,MAAM,YAAY,QAAQ,cAAc,CAAC,GAC5C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CACjB,CAAC;CAEH,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,oCACd,SAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,IAAI,OAAO,QAAQ,YAAY,UAEzB;MAAA,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EAChB,CAAC;CAAA,OAGH,OAAO,KAAK,GAAG,oCAAoC,QAAQ,OAAO,CAAC;CAIrE,KAAK,MAAM,YAAY,QAAQ,cAAc,CAAC,GAC5C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CACjB,CAAC;CAEH,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,oCACd,QAC8B;CAC9B,MAAM,kBAAgD,CAAC;CACvD,KAAK,MAAM,SAAS,QAClB,IAAI,kBAAkB,KAAK,GACzB,gBAAgB,KAAK,+BAA+B,KAAK,CAAC;MAE1D,gBAAgB,KAAK,KAA8B;CAGvD,OAAO;AACT;AAEA,SAAS,2BACP,YACsC;CACtC,IA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AAO,+BAA+B,OAAO;EAE/C,OAAO,yBAAyB,OAAO;CACzC;CACA,wBAAwB,YAAY;EAClC,IAAI,OAAO,QAAQ,YAAY,UAC7B,OAAO,oCAAoC,OAAO;EAEpD,OAAO,8BAA8B,OAAO;CAC9C;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"ml-matrix": "^6.15.0",
|
|
33
33
|
"rimraf": "^6.1.3",
|
|
34
34
|
"typescript": "~7.0.2",
|
|
35
|
-
"vitest": "^4.1.
|
|
35
|
+
"vitest": "^4.1.11",
|
|
36
36
|
"web-streams-polyfill": "^4.3.0",
|
|
37
37
|
"@langchain/tsconfig": "0.0.1"
|
|
38
38
|
},
|