@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.mjs
CHANGED
|
@@ -2410,7 +2410,7 @@ function getCacheControl(providerMetadata) {
|
|
|
2410
2410
|
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;
|
|
2411
2411
|
}
|
|
2412
2412
|
function convertToOpenRouterChatMessages(prompt) {
|
|
2413
|
-
var _a16, _b16, _c, _d, _e, _f, _g
|
|
2413
|
+
var _a16, _b16, _c, _d, _e, _f, _g;
|
|
2414
2414
|
const messages = [];
|
|
2415
2415
|
for (const { role, content, providerOptions } of prompt) {
|
|
2416
2416
|
switch (role) {
|
|
@@ -2521,7 +2521,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2521
2521
|
let text = "";
|
|
2522
2522
|
let reasoning = "";
|
|
2523
2523
|
const toolCalls = [];
|
|
2524
|
-
const accumulatedReasoningDetails = [];
|
|
2525
2524
|
for (const part of content) {
|
|
2526
2525
|
switch (part.type) {
|
|
2527
2526
|
case "text": {
|
|
@@ -2529,12 +2528,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2529
2528
|
break;
|
|
2530
2529
|
}
|
|
2531
2530
|
case "tool-call": {
|
|
2532
|
-
const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
|
|
2533
|
-
if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
|
|
2534
|
-
accumulatedReasoningDetails.push(
|
|
2535
|
-
...partReasoningDetails.reasoning_details
|
|
2536
|
-
);
|
|
2537
|
-
}
|
|
2538
2531
|
toolCalls.push({
|
|
2539
2532
|
id: part.toolCallId,
|
|
2540
2533
|
type: "function",
|
|
@@ -2547,12 +2540,6 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2547
2540
|
}
|
|
2548
2541
|
case "reasoning": {
|
|
2549
2542
|
reasoning += part.text;
|
|
2550
|
-
const parsedPartProviderOptions = OpenRouterProviderOptionsSchema.safeParse(part.providerOptions);
|
|
2551
|
-
if (parsedPartProviderOptions.success && ((_e = (_d = parsedPartProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details)) {
|
|
2552
|
-
accumulatedReasoningDetails.push(
|
|
2553
|
-
...parsedPartProviderOptions.data.openrouter.reasoning_details
|
|
2554
|
-
);
|
|
2555
|
-
}
|
|
2556
2543
|
break;
|
|
2557
2544
|
}
|
|
2558
2545
|
case "file":
|
|
@@ -2563,9 +2550,9 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2563
2550
|
}
|
|
2564
2551
|
}
|
|
2565
2552
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
2566
|
-
const messageReasoningDetails = parsedProviderOptions.success ? (
|
|
2567
|
-
const messageAnnotations = parsedProviderOptions.success ? (
|
|
2568
|
-
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails :
|
|
2553
|
+
const messageReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
2554
|
+
const messageAnnotations = parsedProviderOptions.success ? (_f = (_e = parsedProviderOptions.data) == null ? void 0 : _e.openrouter) == null ? void 0 : _f.annotations : void 0;
|
|
2555
|
+
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
|
|
2569
2556
|
messages.push({
|
|
2570
2557
|
role: "assistant",
|
|
2571
2558
|
content: text,
|
|
@@ -2587,7 +2574,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2587
2574
|
role: "tool",
|
|
2588
2575
|
tool_call_id: toolResponse.toolCallId,
|
|
2589
2576
|
content: content2,
|
|
2590
|
-
cache_control: (
|
|
2577
|
+
cache_control: (_g = getCacheControl(providerOptions)) != null ? _g : getCacheControl(toolResponse.providerOptions)
|
|
2591
2578
|
});
|
|
2592
2579
|
}
|
|
2593
2580
|
break;
|
|
@@ -2613,6 +2600,29 @@ function getToolResultContent(input) {
|
|
|
2613
2600
|
return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
|
|
2614
2601
|
}
|
|
2615
2602
|
}
|
|
2603
|
+
function findFirstReasoningDetails(content) {
|
|
2604
|
+
var _a16, _b16, _c;
|
|
2605
|
+
for (const part of content) {
|
|
2606
|
+
if (part.type === "tool-call") {
|
|
2607
|
+
const openrouter = (_a16 = part.providerOptions) == null ? void 0 : _a16.openrouter;
|
|
2608
|
+
const details = openrouter == null ? void 0 : openrouter.reasoning_details;
|
|
2609
|
+
if (Array.isArray(details) && details.length > 0) {
|
|
2610
|
+
return details;
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
for (const part of content) {
|
|
2615
|
+
if (part.type === "reasoning") {
|
|
2616
|
+
const parsed = OpenRouterProviderOptionsSchema.safeParse(
|
|
2617
|
+
part.providerOptions
|
|
2618
|
+
);
|
|
2619
|
+
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) {
|
|
2620
|
+
return parsed.data.openrouter.reasoning_details;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
return void 0;
|
|
2625
|
+
}
|
|
2616
2626
|
|
|
2617
2627
|
// src/chat/get-tool-choice.ts
|
|
2618
2628
|
import { z as z5 } from "zod/v4";
|
|
@@ -3076,18 +3086,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3076
3086
|
});
|
|
3077
3087
|
}
|
|
3078
3088
|
if (choice.message.tool_calls) {
|
|
3089
|
+
let reasoningDetailsAttachedToToolCall = false;
|
|
3079
3090
|
for (const toolCall of choice.message.tool_calls) {
|
|
3080
3091
|
content.push({
|
|
3081
3092
|
type: "tool-call",
|
|
3082
3093
|
toolCallId: (_h = toolCall.id) != null ? _h : generateId(),
|
|
3083
3094
|
toolName: toolCall.function.name,
|
|
3084
3095
|
input: toolCall.function.arguments,
|
|
3085
|
-
providerMetadata: {
|
|
3096
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3086
3097
|
openrouter: {
|
|
3087
3098
|
reasoning_details: reasoningDetails
|
|
3088
3099
|
}
|
|
3089
|
-
}
|
|
3100
|
+
} : void 0
|
|
3090
3101
|
});
|
|
3102
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3091
3103
|
}
|
|
3092
3104
|
}
|
|
3093
3105
|
if (choice.message.images) {
|
|
@@ -3206,6 +3218,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3206
3218
|
};
|
|
3207
3219
|
const openrouterUsage = {};
|
|
3208
3220
|
const accumulatedReasoningDetails = [];
|
|
3221
|
+
let reasoningDetailsAttachedToToolCall = false;
|
|
3209
3222
|
const accumulatedFileAnnotations = [];
|
|
3210
3223
|
let textStarted = false;
|
|
3211
3224
|
let reasoningStarted = false;
|
|
@@ -3454,12 +3467,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3454
3467
|
toolCallId: toolCall2.id,
|
|
3455
3468
|
toolName: toolCall2.function.name,
|
|
3456
3469
|
input: toolCall2.function.arguments,
|
|
3457
|
-
providerMetadata: {
|
|
3470
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3458
3471
|
openrouter: {
|
|
3459
3472
|
reasoning_details: accumulatedReasoningDetails
|
|
3460
3473
|
}
|
|
3461
|
-
}
|
|
3474
|
+
} : void 0
|
|
3462
3475
|
});
|
|
3476
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3463
3477
|
toolCall2.sent = true;
|
|
3464
3478
|
}
|
|
3465
3479
|
continue;
|
|
@@ -3497,12 +3511,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3497
3511
|
toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
|
|
3498
3512
|
toolName: toolCall.function.name,
|
|
3499
3513
|
input: toolCall.function.arguments,
|
|
3500
|
-
providerMetadata: {
|
|
3514
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3501
3515
|
openrouter: {
|
|
3502
3516
|
reasoning_details: accumulatedReasoningDetails
|
|
3503
3517
|
}
|
|
3504
|
-
}
|
|
3518
|
+
} : void 0
|
|
3505
3519
|
});
|
|
3520
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3506
3521
|
toolCall.sent = true;
|
|
3507
3522
|
}
|
|
3508
3523
|
}
|
|
@@ -3535,12 +3550,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3535
3550
|
toolName: toolCall.function.name,
|
|
3536
3551
|
// Coerce invalid arguments to an empty JSON object
|
|
3537
3552
|
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
3538
|
-
providerMetadata: {
|
|
3553
|
+
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3539
3554
|
openrouter: {
|
|
3540
3555
|
reasoning_details: accumulatedReasoningDetails
|
|
3541
3556
|
}
|
|
3542
|
-
}
|
|
3557
|
+
} : void 0
|
|
3543
3558
|
});
|
|
3559
|
+
reasoningDetailsAttachedToToolCall = true;
|
|
3544
3560
|
toolCall.sent = true;
|
|
3545
3561
|
}
|
|
3546
3562
|
}
|