@yourgpt/llm-sdk 2.1.1 → 2.1.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/adapters/index.d.mts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js +34 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +34 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -2
- package/dist/index.mjs.map +1 -1
- package/dist/providers/anthropic/index.d.mts +1 -1
- package/dist/providers/anthropic/index.d.ts +1 -1
- package/dist/providers/anthropic/index.js +34 -1
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/anthropic/index.mjs +34 -1
- package/dist/providers/anthropic/index.mjs.map +1 -1
- package/dist/providers/azure/index.d.mts +1 -1
- package/dist/providers/azure/index.d.ts +1 -1
- package/dist/providers/google/index.d.mts +1 -1
- package/dist/providers/google/index.d.ts +1 -1
- package/dist/providers/ollama/index.d.mts +2 -2
- package/dist/providers/ollama/index.d.ts +2 -2
- package/dist/providers/openai/index.d.mts +1 -1
- package/dist/providers/openai/index.d.ts +1 -1
- package/dist/providers/openrouter/index.d.mts +1 -1
- package/dist/providers/openrouter/index.d.ts +1 -1
- package/dist/providers/xai/index.d.mts +1 -1
- package/dist/providers/xai/index.d.ts +1 -1
- package/dist/{types-C_f95PKp.d.mts → types-D20jKwJW.d.mts} +11 -0
- package/dist/{types-C_f95PKp.d.ts → types-D20jKwJW.d.ts} +11 -0
- package/package.json +1 -1
package/dist/adapters/index.mjs
CHANGED
|
@@ -523,6 +523,8 @@ var AnthropicAdapter = class {
|
|
|
523
523
|
convertToAnthropicMessages(rawMessages) {
|
|
524
524
|
const messages = [];
|
|
525
525
|
const pendingToolResults = [];
|
|
526
|
+
let lastToolCallIds = [];
|
|
527
|
+
let toolResultIndex = 0;
|
|
526
528
|
for (const msg of rawMessages) {
|
|
527
529
|
if (msg.role === "system") continue;
|
|
528
530
|
if (msg.role === "assistant") {
|
|
@@ -536,6 +538,8 @@ var AnthropicAdapter = class {
|
|
|
536
538
|
}))
|
|
537
539
|
});
|
|
538
540
|
pendingToolResults.length = 0;
|
|
541
|
+
lastToolCallIds = [];
|
|
542
|
+
toolResultIndex = 0;
|
|
539
543
|
}
|
|
540
544
|
const content = [];
|
|
541
545
|
if (msg.content && typeof msg.content === "string" && msg.content.trim()) {
|
|
@@ -543,6 +547,8 @@ var AnthropicAdapter = class {
|
|
|
543
547
|
}
|
|
544
548
|
const toolCalls = msg.tool_calls;
|
|
545
549
|
if (toolCalls && toolCalls.length > 0) {
|
|
550
|
+
lastToolCallIds = toolCalls.map((tc) => tc.id);
|
|
551
|
+
toolResultIndex = 0;
|
|
546
552
|
for (const tc of toolCalls) {
|
|
547
553
|
let input = {};
|
|
548
554
|
try {
|
|
@@ -561,8 +567,35 @@ var AnthropicAdapter = class {
|
|
|
561
567
|
messages.push({ role: "assistant", content });
|
|
562
568
|
}
|
|
563
569
|
} else if (msg.role === "tool") {
|
|
570
|
+
let toolCallId = msg.tool_call_id;
|
|
571
|
+
if (!toolCallId && lastToolCallIds.length > 0) {
|
|
572
|
+
toolCallId = lastToolCallIds[toolResultIndex];
|
|
573
|
+
toolResultIndex++;
|
|
574
|
+
console.warn(
|
|
575
|
+
`[llm-sdk] Tool message missing tool_call_id, inferred: ${toolCallId}`
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
if (!toolCallId) {
|
|
579
|
+
console.warn(
|
|
580
|
+
"[llm-sdk] Skipping tool message with missing tool_call_id (no inference possible):",
|
|
581
|
+
msg
|
|
582
|
+
);
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (lastToolCallIds.length === 0) {
|
|
586
|
+
console.warn(
|
|
587
|
+
`[llm-sdk] Skipping orphaned tool result (no pending tool_use): ${toolCallId}`
|
|
588
|
+
);
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
if (!lastToolCallIds.includes(toolCallId)) {
|
|
592
|
+
console.warn(
|
|
593
|
+
`[llm-sdk] Skipping tool result with unexpected tool_call_id: ${toolCallId}`
|
|
594
|
+
);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
564
597
|
pendingToolResults.push({
|
|
565
|
-
tool_use_id:
|
|
598
|
+
tool_use_id: toolCallId,
|
|
566
599
|
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
567
600
|
});
|
|
568
601
|
} else if (msg.role === "user") {
|