@yourgpt/llm-sdk 2.1.1 → 2.1.2

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.
@@ -1,5 +1,5 @@
1
- import { L as LLMAdapter, W as WebSearchConfig, P as ChatCompletionRequest, g as StreamEvent, aj as CompletionResult, a2 as OllamaModelOptions } from '../types-C_f95PKp.mjs';
2
- export { Q as AdapterFactory, av as AnthropicContentBlock, aw as OpenAIContentBlock, at as attachmentToAnthropicDocument, as as attachmentToAnthropicImage, au as attachmentToOpenAIImage, ak as formatMessages, am as formatMessagesForAnthropic, an as formatMessagesForOpenAI, al as formatTools, aq as hasImageAttachments, ar as hasMediaAttachments, ao as messageToAnthropicContent, ap as messageToOpenAIContent } from '../types-C_f95PKp.mjs';
1
+ import { L as LLMAdapter, W as WebSearchConfig, P as ChatCompletionRequest, g as StreamEvent, aj as CompletionResult, a2 as OllamaModelOptions } from '../types-D20jKwJW.mjs';
2
+ export { Q as AdapterFactory, av as AnthropicContentBlock, aw as OpenAIContentBlock, at as attachmentToAnthropicDocument, as as attachmentToAnthropicImage, au as attachmentToOpenAIImage, ak as formatMessages, am as formatMessagesForAnthropic, an as formatMessagesForOpenAI, al as formatTools, aq as hasImageAttachments, ar as hasMediaAttachments, ao as messageToAnthropicContent, ap as messageToOpenAIContent } from '../types-D20jKwJW.mjs';
3
3
  import 'zod';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { L as LLMAdapter, W as WebSearchConfig, P as ChatCompletionRequest, g as StreamEvent, aj as CompletionResult, a2 as OllamaModelOptions } from '../types-C_f95PKp.js';
2
- export { Q as AdapterFactory, av as AnthropicContentBlock, aw as OpenAIContentBlock, at as attachmentToAnthropicDocument, as as attachmentToAnthropicImage, au as attachmentToOpenAIImage, ak as formatMessages, am as formatMessagesForAnthropic, an as formatMessagesForOpenAI, al as formatTools, aq as hasImageAttachments, ar as hasMediaAttachments, ao as messageToAnthropicContent, ap as messageToOpenAIContent } from '../types-C_f95PKp.js';
1
+ import { L as LLMAdapter, W as WebSearchConfig, P as ChatCompletionRequest, g as StreamEvent, aj as CompletionResult, a2 as OllamaModelOptions } from '../types-D20jKwJW.js';
2
+ export { Q as AdapterFactory, av as AnthropicContentBlock, aw as OpenAIContentBlock, at as attachmentToAnthropicDocument, as as attachmentToAnthropicImage, au as attachmentToOpenAIImage, ak as formatMessages, am as formatMessagesForAnthropic, an as formatMessagesForOpenAI, al as formatTools, aq as hasImageAttachments, ar as hasMediaAttachments, ao as messageToAnthropicContent, ap as messageToOpenAIContent } from '../types-D20jKwJW.js';
3
3
  import 'zod';
4
4
 
5
5
  /**
@@ -525,6 +525,8 @@ var AnthropicAdapter = class {
525
525
  convertToAnthropicMessages(rawMessages) {
526
526
  const messages = [];
527
527
  const pendingToolResults = [];
528
+ let lastToolCallIds = [];
529
+ let toolResultIndex = 0;
528
530
  for (const msg of rawMessages) {
529
531
  if (msg.role === "system") continue;
530
532
  if (msg.role === "assistant") {
@@ -538,6 +540,8 @@ var AnthropicAdapter = class {
538
540
  }))
539
541
  });
540
542
  pendingToolResults.length = 0;
543
+ lastToolCallIds = [];
544
+ toolResultIndex = 0;
541
545
  }
542
546
  const content = [];
543
547
  if (msg.content && typeof msg.content === "string" && msg.content.trim()) {
@@ -545,6 +549,8 @@ var AnthropicAdapter = class {
545
549
  }
546
550
  const toolCalls = msg.tool_calls;
547
551
  if (toolCalls && toolCalls.length > 0) {
552
+ lastToolCallIds = toolCalls.map((tc) => tc.id);
553
+ toolResultIndex = 0;
548
554
  for (const tc of toolCalls) {
549
555
  let input = {};
550
556
  try {
@@ -563,8 +569,35 @@ var AnthropicAdapter = class {
563
569
  messages.push({ role: "assistant", content });
564
570
  }
565
571
  } else if (msg.role === "tool") {
572
+ let toolCallId = msg.tool_call_id;
573
+ if (!toolCallId && lastToolCallIds.length > 0) {
574
+ toolCallId = lastToolCallIds[toolResultIndex];
575
+ toolResultIndex++;
576
+ console.warn(
577
+ `[llm-sdk] Tool message missing tool_call_id, inferred: ${toolCallId}`
578
+ );
579
+ }
580
+ if (!toolCallId) {
581
+ console.warn(
582
+ "[llm-sdk] Skipping tool message with missing tool_call_id (no inference possible):",
583
+ msg
584
+ );
585
+ continue;
586
+ }
587
+ if (lastToolCallIds.length === 0) {
588
+ console.warn(
589
+ `[llm-sdk] Skipping orphaned tool result (no pending tool_use): ${toolCallId}`
590
+ );
591
+ continue;
592
+ }
593
+ if (!lastToolCallIds.includes(toolCallId)) {
594
+ console.warn(
595
+ `[llm-sdk] Skipping tool result with unexpected tool_call_id: ${toolCallId}`
596
+ );
597
+ continue;
598
+ }
566
599
  pendingToolResults.push({
567
- tool_use_id: msg.tool_call_id,
600
+ tool_use_id: toolCallId,
568
601
  content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
569
602
  });
570
603
  } else if (msg.role === "user") {