@jaypie/llm 1.2.16 → 1.2.17

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.
@@ -16,6 +16,8 @@ export interface LlmStreamChunkToolCall {
16
16
  id: string;
17
17
  name: string;
18
18
  arguments: string;
19
+ /** Provider-specific metadata preserved through tool-call roundtrip */
20
+ metadata?: Record<string, unknown>;
19
21
  };
20
22
  }
21
23
  export interface LlmStreamChunkToolResult {
package/dist/esm/index.js CHANGED
@@ -1679,6 +1679,11 @@ class GeminiAdapter extends BaseProviderAdapter {
1679
1679
  name: functionCall.name || "",
1680
1680
  arguments: functionCall.args || {},
1681
1681
  };
1682
+ // Preserve thoughtSignature for Gemini 3 models
1683
+ // Required to maintain tool call context between turns
1684
+ const metadata = part.thoughtSignature
1685
+ ? { thoughtSignature: part.thoughtSignature }
1686
+ : undefined;
1682
1687
  // Emit the function call immediately
1683
1688
  yield {
1684
1689
  type: LlmStreamChunkType.ToolCall,
@@ -1686,6 +1691,7 @@ class GeminiAdapter extends BaseProviderAdapter {
1686
1691
  id: currentFunctionCall.id,
1687
1692
  name: currentFunctionCall.name,
1688
1693
  arguments: JSON.stringify(currentFunctionCall.arguments),
1694
+ metadata,
1689
1695
  },
1690
1696
  };
1691
1697
  currentFunctionCall = null;
@@ -2372,6 +2378,9 @@ class OpenAiAdapter extends BaseProviderAdapter {
2372
2378
  id: currentFunctionCall.callId,
2373
2379
  name: currentFunctionCall.name,
2374
2380
  arguments: currentFunctionCall.arguments,
2381
+ // Preserve the item ID (fc_...) separately from call_id (call_...)
2382
+ // OpenAI Responses API requires both with correct prefixes
2383
+ metadata: { itemId: currentFunctionCall.id },
2375
2384
  },
2376
2385
  };
2377
2386
  currentFunctionCall = null;
@@ -4791,13 +4800,22 @@ class StreamLoop {
4791
4800
  if (collectedToolCalls.length > 0 && state.toolkit && state.maxTurns > 1) {
4792
4801
  // Add tool calls to history
4793
4802
  for (const toolCall of collectedToolCalls) {
4794
- state.currentInput.push({
4803
+ // Extract provider-specific metadata from the stream chunk
4804
+ const metadata = toolCall.raw?.metadata;
4805
+ const historyItem = {
4795
4806
  type: LlmMessageType.FunctionCall,
4796
4807
  name: toolCall.name,
4797
4808
  arguments: toolCall.arguments,
4798
4809
  call_id: toolCall.callId,
4799
- id: toolCall.callId,
4800
- });
4810
+ // Use provider item ID if available (e.g., OpenAI fc_... prefix),
4811
+ // otherwise fall back to callId
4812
+ id: metadata?.itemId || toolCall.callId,
4813
+ };
4814
+ // Preserve provider-specific fields (e.g., Gemini thoughtSignature)
4815
+ if (metadata?.thoughtSignature) {
4816
+ historyItem.thoughtSignature = metadata.thoughtSignature;
4817
+ }
4818
+ state.currentInput.push(historyItem);
4801
4819
  }
4802
4820
  return { shouldContinue: true, toolCalls: collectedToolCalls };
4803
4821
  }