@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.js CHANGED
@@ -5983,6 +5983,23 @@ function toOpenAiToolOutput(value) {
5983
5983
  }
5984
5984
  return mergeToolOutput(value);
5985
5985
  }
5986
+ function toChatGptToolOutput(value) {
5987
+ const toolOutput = toOpenAiToolOutput(value);
5988
+ if (typeof toolOutput === "string") {
5989
+ return toolOutput;
5990
+ }
5991
+ return toolOutput.map((item) => {
5992
+ if (item.type !== "input_image") {
5993
+ return item;
5994
+ }
5995
+ return {
5996
+ type: "input_image",
5997
+ ...item.file_id ? { file_id: item.file_id } : {},
5998
+ ...item.image_url ? { image_url: item.image_url } : {},
5999
+ ...item.detail ? { detail: item.detail } : {}
6000
+ };
6001
+ });
6002
+ }
5986
6003
  function toGeminiToolOutputItems(value) {
5987
6004
  if (isLlmToolOutputContentItem(value)) {
5988
6005
  return [value];
@@ -6150,6 +6167,9 @@ async function maybeSpillToolOutputItem(item, toolName, options) {
6150
6167
  return item;
6151
6168
  }
6152
6169
  async function maybeSpillToolOutput(value, toolName, options) {
6170
+ if (options?.provider === "chatgpt") {
6171
+ return value;
6172
+ }
6153
6173
  if (typeof value === "string") {
6154
6174
  if (options?.force !== true && Buffer5.byteLength(value, "utf8") <= TOOL_OUTPUT_SPILL_THRESHOLD_BYTES) {
6155
6175
  return value;
@@ -6203,7 +6223,7 @@ function estimateToolOutputPayloadBytes(value) {
6203
6223
  }
6204
6224
  return 0;
6205
6225
  }
6206
- async function maybeSpillCombinedToolCallOutputs(callResults) {
6226
+ async function maybeSpillCombinedToolCallOutputs(callResults, options) {
6207
6227
  const totalBytes = callResults.reduce(
6208
6228
  (sum, callResult) => sum + estimateToolOutputPayloadBytes(callResult.outputPayload),
6209
6229
  0
@@ -6220,7 +6240,8 @@ async function maybeSpillCombinedToolCallOutputs(callResults) {
6220
6240
  callResult.outputPayload,
6221
6241
  callResult.entry.toolName,
6222
6242
  {
6223
- force: true
6243
+ force: true,
6244
+ provider: options?.provider
6224
6245
  }
6225
6246
  );
6226
6247
  return {
@@ -6450,7 +6471,7 @@ function extractSpawnStartupMetrics(outputPayload) {
6450
6471
  };
6451
6472
  }
6452
6473
  async function executeToolCall(params) {
6453
- const { callKind, toolName, tool: tool2, rawInput, parseError } = params;
6474
+ const { callKind, toolName, tool: tool2, rawInput, parseError, provider } = params;
6454
6475
  const startedAtMs = Date.now();
6455
6476
  const finalize = (base, outputPayload, metrics) => {
6456
6477
  const completedAtMs = Date.now();
@@ -6485,7 +6506,7 @@ async function executeToolCall(params) {
6485
6506
  const input = typeof rawInput === "string" ? rawInput : String(rawInput ?? "");
6486
6507
  try {
6487
6508
  const output = await tool2.execute(input);
6488
- const outputPayload = await maybeSpillToolOutput(output, toolName);
6509
+ const outputPayload = await maybeSpillToolOutput(output, toolName, { provider });
6489
6510
  const metrics = toolName === "spawn_agent" ? extractSpawnStartupMetrics(outputPayload) : void 0;
6490
6511
  return finalize({ toolName, input, output: outputPayload }, outputPayload, metrics);
6491
6512
  } catch (error) {
@@ -6521,7 +6542,7 @@ async function executeToolCall(params) {
6521
6542
  }
6522
6543
  try {
6523
6544
  const output = await tool2.execute(parsed.data);
6524
- const outputPayload = await maybeSpillToolOutput(output, toolName);
6545
+ const outputPayload = await maybeSpillToolOutput(output, toolName, { provider });
6525
6546
  const metrics = toolName === "spawn_agent" ? extractSpawnStartupMetrics(outputPayload) : void 0;
6526
6547
  return finalize(
6527
6548
  { toolName, input: parsed.data, output: outputPayload },
@@ -8321,13 +8342,15 @@ async function runToolLoop(request) {
8321
8342
  toolName: entry.toolName,
8322
8343
  tool: request.tools[entry.toolName],
8323
8344
  rawInput: entry.value,
8324
- parseError: entry.parseError
8345
+ parseError: entry.parseError,
8346
+ provider: providerInfo.provider
8325
8347
  });
8326
8348
  return { entry, result, outputPayload };
8327
8349
  }
8328
8350
  );
8329
8351
  })
8330
- )
8352
+ ),
8353
+ { provider: providerInfo.provider }
8331
8354
  );
8332
8355
  const toolOutputs = [];
8333
8356
  let toolExecutionMs = 0;
@@ -8624,13 +8647,15 @@ async function runToolLoop(request) {
8624
8647
  toolName: entry.toolName,
8625
8648
  tool: request.tools[entry.toolName],
8626
8649
  rawInput: entry.value,
8627
- parseError: entry.parseError
8650
+ parseError: entry.parseError,
8651
+ provider: "chatgpt"
8628
8652
  });
8629
8653
  return { entry, result, outputPayload };
8630
8654
  }
8631
8655
  );
8632
8656
  })
8633
- )
8657
+ ),
8658
+ { provider: "chatgpt" }
8634
8659
  );
8635
8660
  let toolExecutionMs = 0;
8636
8661
  let waitToolMs = 0;
@@ -8667,7 +8692,7 @@ async function runToolLoop(request) {
8667
8692
  toolOutputs.push({
8668
8693
  type: "custom_tool_call_output",
8669
8694
  call_id: entry.ids.callId,
8670
- output: toOpenAiToolOutput(outputPayload)
8695
+ output: toChatGptToolOutput(outputPayload)
8671
8696
  });
8672
8697
  } else {
8673
8698
  toolOutputs.push({
@@ -8681,7 +8706,7 @@ async function runToolLoop(request) {
8681
8706
  toolOutputs.push({
8682
8707
  type: "function_call_output",
8683
8708
  call_id: entry.ids.callId,
8684
- output: toOpenAiToolOutput(outputPayload)
8709
+ output: toChatGptToolOutput(outputPayload)
8685
8710
  });
8686
8711
  }
8687
8712
  }
@@ -8918,13 +8943,15 @@ async function runToolLoop(request) {
8918
8943
  toolName: entry.toolName,
8919
8944
  tool: request.tools[entry.toolName],
8920
8945
  rawInput: entry.value,
8921
- parseError: entry.parseError
8946
+ parseError: entry.parseError,
8947
+ provider: providerInfo.provider
8922
8948
  });
8923
8949
  return { entry, result, outputPayload };
8924
8950
  }
8925
8951
  );
8926
8952
  })
8927
- )
8953
+ ),
8954
+ { provider: providerInfo.provider }
8928
8955
  );
8929
8956
  const assistantToolCalls = [];
8930
8957
  const toolMessages = [];
@@ -9271,13 +9298,15 @@ async function runToolLoop(request) {
9271
9298
  callKind: "function",
9272
9299
  toolName: entry.toolName,
9273
9300
  tool: request.tools[entry.toolName],
9274
- rawInput: entry.rawInput
9301
+ rawInput: entry.rawInput,
9302
+ provider: "gemini"
9275
9303
  });
9276
9304
  return { entry, result, outputPayload };
9277
9305
  }
9278
9306
  );
9279
9307
  })
9280
- )
9308
+ ),
9309
+ { provider: "gemini" }
9281
9310
  );
9282
9311
  let toolExecutionMs = 0;
9283
9312
  let waitToolMs = 0;