@openrouter/ai-sdk-provider 2.0.0 → 2.0.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.
- package/dist/index.js +43 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -27
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +42 -26
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +42 -26
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -2442,7 +2442,7 @@ function getCacheControl(providerMetadata) {
|
|
|
2442
2442
|
return (_c = (_b16 = (_a16 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a16 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b16 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
2443
2443
|
}
|
|
2444
2444
|
function convertToOpenRouterChatMessages(prompt) {
|
|
2445
|
-
var _a16, _b16, _c, _d, _e, _f, _g
|
|
2445
|
+
var _a16, _b16, _c, _d, _e, _f, _g;
|
|
2446
2446
|
const messages = [];
|
|
2447
2447
|
for (const { role, content, providerOptions } of prompt) {
|
|
2448
2448
|
switch (role) {
|
|
@@ -2553,7 +2553,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2553
2553
|
let text = "";
|
|
2554
2554
|
let reasoning = "";
|
|
2555
2555
|
const toolCalls = [];
|
|
2556
|
-
const accumulatedReasoningDetails = [];
|
|
2557
2556
|
for (const part of content) {
|
|
2558
2557
|
switch (part.type) {
|
|
2559
2558
|
case "text": {
|
|
@@ -2561,12 +2560,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2561
2560
|
break;
|
|
2562
2561
|
}
|
|
2563
2562
|
case "tool-call": {
|
|
2564
|
-
const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
|
|
2565
|
-
if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
|
|
2566
|
-
accumulatedReasoningDetails.push(
|
|
2567
|
-
...partReasoningDetails.reasoning_details
|
|
2568
|
-
);
|
|
2569
|
-
}
|
|
2570
2563
|
toolCalls.push({
|
|
2571
2564
|
id: part.toolCallId,
|
|
2572
2565
|
type: "function",
|
|
@@ -2579,12 +2572,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2579
2572
|
}
|
|
2580
2573
|
case "reasoning": {
|
|
2581
2574
|
reasoning += part.text;
|
|
2582
|
-
const parsedPartProviderOptions = OpenRouterProviderOptionsSchema.safeParse(part.providerOptions);
|
|
2583
|
-
if (parsedPartProviderOptions.success && ((_e = (_d = parsedPartProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details)) {
|
|
2584
|
-
accumulatedReasoningDetails.push(
|
|
2585
|
-
...parsedPartProviderOptions.data.openrouter.reasoning_details
|
|
2586
|
-
);
|
|
2587
|
-
}
|
|
2588
2575
|
break;
|
|
2589
2576
|
}
|
|
2590
2577
|
case "file":
|
|
@@ -2595,9 +2582,9 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2595
2582
|
}
|
|
2596
2583
|
}
|
|
2597
2584
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
2598
|
-
const messageReasoningDetails = parsedProviderOptions.success ? (
|
|
2599
|
-
const messageAnnotations = parsedProviderOptions.success ? (
|
|
2600
|
-
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails :
|
|
2585
|
+
const messageReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
2586
|
+
const messageAnnotations = parsedProviderOptions.success ? (_f = (_e = parsedProviderOptions.data) == null ? void 0 : _e.openrouter) == null ? void 0 : _f.annotations : void 0;
|
|
2587
|
+
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
|
|
2601
2588
|
messages.push({
|
|
2602
2589
|
role: "assistant",
|
|
2603
2590
|
content: text,
|
|
@@ -2619,7 +2606,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2619
2606
|
role: "tool",
|
|
2620
2607
|
tool_call_id: toolResponse.toolCallId,
|
|
2621
2608
|
content: content2,
|
|
2622
|
-
cache_control: (
|
|
2609
|
+
cache_control: (_g = getCacheControl(providerOptions)) != null ? _g : getCacheControl(toolResponse.providerOptions)
|
|
2623
2610
|
});
|
|
2624
2611
|
}
|
|
2625
2612
|
break;
|
|
@@ -2645,6 +2632,29 @@ function getToolResultContent(input) {
|
|
|
2645
2632
|
return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
|
|
2646
2633
|
}
|
|
2647
2634
|
}
|
|
2635
|
+
function findFirstReasoningDetails(content) {
|
|
2636
|
+
var _a16, _b16, _c;
|
|
2637
|
+
for (const part of content) {
|
|
2638
|
+
if (part.type === "tool-call") {
|
|
2639
|
+
const openrouter = (_a16 = part.providerOptions) == null ? void 0 : _a16.openrouter;
|
|
2640
|
+
const details = openrouter == null ? void 0 : openrouter.reasoning_details;
|
|
2641
|
+
if (Array.isArray(details) && details.length > 0) {
|
|
2642
|
+
return details;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
for (const part of content) {
|
|
2647
|
+
if (part.type === "reasoning") {
|
|
2648
|
+
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
2649
|
+
part.providerOptions
|
|
2650
|
+
);
|
|
2651
|
+
if (parsed.success && ((_c = (_b16 = parsed.data) == null ? void 0 : _b16.openrouter) == null ? void 0 : _c.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
|
|
2652
|
+
return parsed.data.openrouter.reasoning_details;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
return void 0;
|
|
2657
|
+
}
|
|
2648
2658
|
|
|
2649
2659
|
// src/chat/get-tool-choice.ts
|
|
2650
2660
|
var import_v44 = require("zod/v4");
|
|
@@ -3108,18 +3118,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3108
3118
|
});
|
|
3109
3119
|
}
|
|
3110
3120
|
if (choice.message.tool_calls) {
|
|
3121
|
+
let reasoningDetailsAttachedToToolCall = false;
|
|
3111
3122
|
for (const toolCall of choice.message.tool_calls) {
|
|
3112
3123
|
content.push({
|
|
3113
3124
|
type: "tool-call",
|
|
3114
3125
|
toolCallId: (_h = toolCall.id) != null ? _h : generateId(),
|
|
3115
3126
|
toolName: toolCall.function.name,
|
|
3116
3127
|
input: toolCall.function.arguments,
|
|
3117
|
-
providerMetadata: {
|
|
3128
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3118
3129
|
openrouter: {
|
|
3119
3130
|
reasoning_details: reasoningDetails
|
|
3120
3131
|
}
|
|
3121
|
-
}
|
|
3132
|
+
} : void 0
|
|
3122
3133
|
});
|
|
3134
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3123
3135
|
}
|
|
3124
3136
|
}
|
|
3125
3137
|
if (choice.message.images) {
|
|
@@ -3238,6 +3250,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3238
3250
|
};
|
|
3239
3251
|
const openrouterUsage = {};
|
|
3240
3252
|
const accumulatedReasoningDetails = [];
|
|
3253
|
+
let reasoningDetailsAttachedToToolCall = false;
|
|
3241
3254
|
const accumulatedFileAnnotations = [];
|
|
3242
3255
|
let textStarted = false;
|
|
3243
3256
|
let reasoningStarted = false;
|
|
@@ -3486,12 +3499,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3486
3499
|
toolCallId: toolCall2.id,
|
|
3487
3500
|
toolName: toolCall2.function.name,
|
|
3488
3501
|
input: toolCall2.function.arguments,
|
|
3489
|
-
providerMetadata: {
|
|
3502
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3490
3503
|
openrouter: {
|
|
3491
3504
|
reasoning_details: accumulatedReasoningDetails
|
|
3492
3505
|
}
|
|
3493
|
-
}
|
|
3506
|
+
} : void 0
|
|
3494
3507
|
});
|
|
3508
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3495
3509
|
toolCall2.sent = true;
|
|
3496
3510
|
}
|
|
3497
3511
|
continue;
|
|
@@ -3529,12 +3543,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3529
3543
|
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
3530
3544
|
toolName: toolCall.function.name,
|
|
3531
3545
|
input: toolCall.function.arguments,
|
|
3532
|
-
providerMetadata: {
|
|
3546
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3533
3547
|
openrouter: {
|
|
3534
3548
|
reasoning_details: accumulatedReasoningDetails
|
|
3535
3549
|
}
|
|
3536
|
-
}
|
|
3550
|
+
} : void 0
|
|
3537
3551
|
});
|
|
3552
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3538
3553
|
toolCall.sent = true;
|
|
3539
3554
|
}
|
|
3540
3555
|
}
|
|
@@ -3567,12 +3582,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3567
3582
|
toolName: toolCall.function.name,
|
|
3568
3583
|
// Coerce invalid arguments to an empty JSON object
|
|
3569
3584
|
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
3570
|
-
providerMetadata: {
|
|
3585
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3571
3586
|
openrouter: {
|
|
3572
3587
|
reasoning_details: accumulatedReasoningDetails
|
|
3573
3588
|
}
|
|
3574
|
-
}
|
|
3589
|
+
} : void 0
|
|
3575
3590
|
});
|
|
3591
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3576
3592
|
toolCall.sent = true;
|
|
3577
3593
|
}
|
|
3578
3594
|
}
|