@ljoukov/llm 5.0.0 → 5.0.3
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/dist/index.cjs +44 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6097,6 +6097,23 @@ function toOpenAiToolOutput(value) {
|
|
|
6097
6097
|
}
|
|
6098
6098
|
return mergeToolOutput(value);
|
|
6099
6099
|
}
|
|
6100
|
+
function toChatGptToolOutput(value) {
|
|
6101
|
+
const toolOutput = toOpenAiToolOutput(value);
|
|
6102
|
+
if (typeof toolOutput === "string") {
|
|
6103
|
+
return toolOutput;
|
|
6104
|
+
}
|
|
6105
|
+
return toolOutput.map((item) => {
|
|
6106
|
+
if (item.type !== "input_image") {
|
|
6107
|
+
return item;
|
|
6108
|
+
}
|
|
6109
|
+
return {
|
|
6110
|
+
type: "input_image",
|
|
6111
|
+
...item.file_id ? { file_id: item.file_id } : {},
|
|
6112
|
+
...item.image_url ? { image_url: item.image_url } : {},
|
|
6113
|
+
...item.detail ? { detail: item.detail } : {}
|
|
6114
|
+
};
|
|
6115
|
+
});
|
|
6116
|
+
}
|
|
6100
6117
|
function toGeminiToolOutputItems(value) {
|
|
6101
6118
|
if (isLlmToolOutputContentItem(value)) {
|
|
6102
6119
|
return [value];
|
|
@@ -6264,6 +6281,9 @@ async function maybeSpillToolOutputItem(item, toolName, options) {
|
|
|
6264
6281
|
return item;
|
|
6265
6282
|
}
|
|
6266
6283
|
async function maybeSpillToolOutput(value, toolName, options) {
|
|
6284
|
+
if (options?.provider === "chatgpt") {
|
|
6285
|
+
return value;
|
|
6286
|
+
}
|
|
6267
6287
|
if (typeof value === "string") {
|
|
6268
6288
|
if (options?.force !== true && import_node_buffer4.Buffer.byteLength(value, "utf8") <= TOOL_OUTPUT_SPILL_THRESHOLD_BYTES) {
|
|
6269
6289
|
return value;
|
|
@@ -6317,7 +6337,7 @@ function estimateToolOutputPayloadBytes(value) {
|
|
|
6317
6337
|
}
|
|
6318
6338
|
return 0;
|
|
6319
6339
|
}
|
|
6320
|
-
async function maybeSpillCombinedToolCallOutputs(callResults) {
|
|
6340
|
+
async function maybeSpillCombinedToolCallOutputs(callResults, options) {
|
|
6321
6341
|
const totalBytes = callResults.reduce(
|
|
6322
6342
|
(sum, callResult) => sum + estimateToolOutputPayloadBytes(callResult.outputPayload),
|
|
6323
6343
|
0
|
|
@@ -6334,7 +6354,8 @@ async function maybeSpillCombinedToolCallOutputs(callResults) {
|
|
|
6334
6354
|
callResult.outputPayload,
|
|
6335
6355
|
callResult.entry.toolName,
|
|
6336
6356
|
{
|
|
6337
|
-
force: true
|
|
6357
|
+
force: true,
|
|
6358
|
+
provider: options?.provider
|
|
6338
6359
|
}
|
|
6339
6360
|
);
|
|
6340
6361
|
return {
|
|
@@ -6564,7 +6585,7 @@ function extractSpawnStartupMetrics(outputPayload) {
|
|
|
6564
6585
|
};
|
|
6565
6586
|
}
|
|
6566
6587
|
async function executeToolCall(params) {
|
|
6567
|
-
const { callKind, toolName, tool: tool2, rawInput, parseError } = params;
|
|
6588
|
+
const { callKind, toolName, tool: tool2, rawInput, parseError, provider } = params;
|
|
6568
6589
|
const startedAtMs = Date.now();
|
|
6569
6590
|
const finalize = (base, outputPayload, metrics) => {
|
|
6570
6591
|
const completedAtMs = Date.now();
|
|
@@ -6599,7 +6620,7 @@ async function executeToolCall(params) {
|
|
|
6599
6620
|
const input = typeof rawInput === "string" ? rawInput : String(rawInput ?? "");
|
|
6600
6621
|
try {
|
|
6601
6622
|
const output = await tool2.execute(input);
|
|
6602
|
-
const outputPayload = await maybeSpillToolOutput(output, toolName);
|
|
6623
|
+
const outputPayload = await maybeSpillToolOutput(output, toolName, { provider });
|
|
6603
6624
|
const metrics = toolName === "spawn_agent" ? extractSpawnStartupMetrics(outputPayload) : void 0;
|
|
6604
6625
|
return finalize({ toolName, input, output: outputPayload }, outputPayload, metrics);
|
|
6605
6626
|
} catch (error) {
|
|
@@ -6635,7 +6656,7 @@ async function executeToolCall(params) {
|
|
|
6635
6656
|
}
|
|
6636
6657
|
try {
|
|
6637
6658
|
const output = await tool2.execute(parsed.data);
|
|
6638
|
-
const outputPayload = await maybeSpillToolOutput(output, toolName);
|
|
6659
|
+
const outputPayload = await maybeSpillToolOutput(output, toolName, { provider });
|
|
6639
6660
|
const metrics = toolName === "spawn_agent" ? extractSpawnStartupMetrics(outputPayload) : void 0;
|
|
6640
6661
|
return finalize(
|
|
6641
6662
|
{ toolName, input: parsed.data, output: outputPayload },
|
|
@@ -8435,13 +8456,15 @@ async function runToolLoop(request) {
|
|
|
8435
8456
|
toolName: entry.toolName,
|
|
8436
8457
|
tool: request.tools[entry.toolName],
|
|
8437
8458
|
rawInput: entry.value,
|
|
8438
|
-
parseError: entry.parseError
|
|
8459
|
+
parseError: entry.parseError,
|
|
8460
|
+
provider: providerInfo.provider
|
|
8439
8461
|
});
|
|
8440
8462
|
return { entry, result, outputPayload };
|
|
8441
8463
|
}
|
|
8442
8464
|
);
|
|
8443
8465
|
})
|
|
8444
|
-
)
|
|
8466
|
+
),
|
|
8467
|
+
{ provider: providerInfo.provider }
|
|
8445
8468
|
);
|
|
8446
8469
|
const toolOutputs = [];
|
|
8447
8470
|
let toolExecutionMs = 0;
|
|
@@ -8738,13 +8761,15 @@ async function runToolLoop(request) {
|
|
|
8738
8761
|
toolName: entry.toolName,
|
|
8739
8762
|
tool: request.tools[entry.toolName],
|
|
8740
8763
|
rawInput: entry.value,
|
|
8741
|
-
parseError: entry.parseError
|
|
8764
|
+
parseError: entry.parseError,
|
|
8765
|
+
provider: "chatgpt"
|
|
8742
8766
|
});
|
|
8743
8767
|
return { entry, result, outputPayload };
|
|
8744
8768
|
}
|
|
8745
8769
|
);
|
|
8746
8770
|
})
|
|
8747
|
-
)
|
|
8771
|
+
),
|
|
8772
|
+
{ provider: "chatgpt" }
|
|
8748
8773
|
);
|
|
8749
8774
|
let toolExecutionMs = 0;
|
|
8750
8775
|
let waitToolMs = 0;
|
|
@@ -8781,7 +8806,7 @@ async function runToolLoop(request) {
|
|
|
8781
8806
|
toolOutputs.push({
|
|
8782
8807
|
type: "custom_tool_call_output",
|
|
8783
8808
|
call_id: entry.ids.callId,
|
|
8784
|
-
output:
|
|
8809
|
+
output: toChatGptToolOutput(outputPayload)
|
|
8785
8810
|
});
|
|
8786
8811
|
} else {
|
|
8787
8812
|
toolOutputs.push({
|
|
@@ -8795,7 +8820,7 @@ async function runToolLoop(request) {
|
|
|
8795
8820
|
toolOutputs.push({
|
|
8796
8821
|
type: "function_call_output",
|
|
8797
8822
|
call_id: entry.ids.callId,
|
|
8798
|
-
output:
|
|
8823
|
+
output: toChatGptToolOutput(outputPayload)
|
|
8799
8824
|
});
|
|
8800
8825
|
}
|
|
8801
8826
|
}
|
|
@@ -9032,13 +9057,15 @@ async function runToolLoop(request) {
|
|
|
9032
9057
|
toolName: entry.toolName,
|
|
9033
9058
|
tool: request.tools[entry.toolName],
|
|
9034
9059
|
rawInput: entry.value,
|
|
9035
|
-
parseError: entry.parseError
|
|
9060
|
+
parseError: entry.parseError,
|
|
9061
|
+
provider: providerInfo.provider
|
|
9036
9062
|
});
|
|
9037
9063
|
return { entry, result, outputPayload };
|
|
9038
9064
|
}
|
|
9039
9065
|
);
|
|
9040
9066
|
})
|
|
9041
|
-
)
|
|
9067
|
+
),
|
|
9068
|
+
{ provider: providerInfo.provider }
|
|
9042
9069
|
);
|
|
9043
9070
|
const assistantToolCalls = [];
|
|
9044
9071
|
const toolMessages = [];
|
|
@@ -9385,13 +9412,15 @@ async function runToolLoop(request) {
|
|
|
9385
9412
|
callKind: "function",
|
|
9386
9413
|
toolName: entry.toolName,
|
|
9387
9414
|
tool: request.tools[entry.toolName],
|
|
9388
|
-
rawInput: entry.rawInput
|
|
9415
|
+
rawInput: entry.rawInput,
|
|
9416
|
+
provider: "gemini"
|
|
9389
9417
|
});
|
|
9390
9418
|
return { entry, result, outputPayload };
|
|
9391
9419
|
}
|
|
9392
9420
|
);
|
|
9393
9421
|
})
|
|
9394
|
-
)
|
|
9422
|
+
),
|
|
9423
|
+
{ provider: "gemini" }
|
|
9395
9424
|
);
|
|
9396
9425
|
let toolExecutionMs = 0;
|
|
9397
9426
|
let waitToolMs = 0;
|