@jaypie/llm 1.2.16 → 1.2.18

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.
@@ -1681,6 +1681,11 @@ class GeminiAdapter extends BaseProviderAdapter {
1681
1681
  name: functionCall.name || "",
1682
1682
  arguments: functionCall.args || {},
1683
1683
  };
1684
+ // Preserve thoughtSignature for Gemini 3 models
1685
+ // Required to maintain tool call context between turns
1686
+ const metadata = part.thoughtSignature
1687
+ ? { thoughtSignature: part.thoughtSignature }
1688
+ : undefined;
1684
1689
  // Emit the function call immediately
1685
1690
  yield {
1686
1691
  type: exports.LlmStreamChunkType.ToolCall,
@@ -1688,6 +1693,7 @@ class GeminiAdapter extends BaseProviderAdapter {
1688
1693
  id: currentFunctionCall.id,
1689
1694
  name: currentFunctionCall.name,
1690
1695
  arguments: JSON.stringify(currentFunctionCall.arguments),
1696
+ metadata,
1691
1697
  },
1692
1698
  };
1693
1699
  currentFunctionCall = null;
@@ -2223,7 +2229,7 @@ class OpenAiAdapter extends BaseProviderAdapter {
2223
2229
  const model = request.model || this.defaultModel;
2224
2230
  const openaiRequest = {
2225
2231
  model,
2226
- input: request.messages,
2232
+ input: this.sanitizeInputItems(request.messages),
2227
2233
  };
2228
2234
  if (request.user) {
2229
2235
  openaiRequest.user = request.user;
@@ -2374,6 +2380,9 @@ class OpenAiAdapter extends BaseProviderAdapter {
2374
2380
  id: currentFunctionCall.callId,
2375
2381
  name: currentFunctionCall.name,
2376
2382
  arguments: currentFunctionCall.arguments,
2383
+ // Preserve the item ID (fc_...) separately from call_id (call_...)
2384
+ // OpenAI Responses API requires both with correct prefixes
2385
+ metadata: { itemId: currentFunctionCall.id },
2377
2386
  },
2378
2387
  };
2379
2388
  currentFunctionCall = null;
@@ -2568,6 +2577,31 @@ class OpenAiAdapter extends BaseProviderAdapter {
2568
2577
  //
2569
2578
  // Private Helpers
2570
2579
  //
2580
+ /**
2581
+ * Sanitize history items for the OpenAI Responses API.
2582
+ * Strips fields not accepted by specific item types (e.g., `name` on
2583
+ * function_call_output items) to prevent 400 "Unknown parameter" errors.
2584
+ */
2585
+ sanitizeInputItems(messages) {
2586
+ return messages.map((item) => {
2587
+ const typedItem = item;
2588
+ // function_call_output only accepts: type, call_id, output, id, status
2589
+ if (typedItem.type === exports.LlmMessageType.FunctionCallOutput) {
2590
+ const sanitized = {
2591
+ type: typedItem.type,
2592
+ call_id: typedItem.call_id,
2593
+ output: typedItem.output,
2594
+ };
2595
+ if (typedItem.id)
2596
+ sanitized.id = typedItem.id;
2597
+ if (typedItem.status)
2598
+ sanitized.status = typedItem.status;
2599
+ return sanitized;
2600
+ }
2601
+ // All other items pass through as-is
2602
+ return item;
2603
+ });
2604
+ }
2571
2605
  hasToolCalls(response) {
2572
2606
  if (!response.output || !Array.isArray(response.output)) {
2573
2607
  return false;
@@ -4793,13 +4827,22 @@ class StreamLoop {
4793
4827
  if (collectedToolCalls.length > 0 && state.toolkit && state.maxTurns > 1) {
4794
4828
  // Add tool calls to history
4795
4829
  for (const toolCall of collectedToolCalls) {
4796
- state.currentInput.push({
4830
+ // Extract provider-specific metadata from the stream chunk
4831
+ const metadata = toolCall.raw?.metadata;
4832
+ const historyItem = {
4797
4833
  type: exports.LlmMessageType.FunctionCall,
4798
4834
  name: toolCall.name,
4799
4835
  arguments: toolCall.arguments,
4800
4836
  call_id: toolCall.callId,
4801
- id: toolCall.callId,
4802
- });
4837
+ // Use provider item ID if available (e.g., OpenAI fc_... prefix),
4838
+ // otherwise fall back to callId
4839
+ id: metadata?.itemId || toolCall.callId,
4840
+ };
4841
+ // Preserve provider-specific fields (e.g., Gemini thoughtSignature)
4842
+ if (metadata?.thoughtSignature) {
4843
+ historyItem.thoughtSignature = metadata.thoughtSignature;
4844
+ }
4845
+ state.currentInput.push(historyItem);
4803
4846
  }
4804
4847
  return { shouldContinue: true, toolCalls: collectedToolCalls };
4805
4848
  }