@openrouter/ai-sdk-provider 2.4.1 → 2.4.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/index.js +61 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +60 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +60 -28
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -2794,9 +2794,12 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
2794
2794
|
return !!detail.signature;
|
|
2795
2795
|
});
|
|
2796
2796
|
if (validDetails.length < candidateReasoningDetails.length) {
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2797
|
+
const logger = globalThis.AI_SDK_LOG_WARNINGS;
|
|
2798
|
+
if (logger !== false && typeof logger !== "function") {
|
|
2799
|
+
console.warn(
|
|
2800
|
+
"[openrouter] Some reasoning_details entries were removed because they were missing signatures. See https://github.com/OpenRouterTeam/ai-sdk-provider/issues/423 for more details."
|
|
2801
|
+
);
|
|
2802
|
+
}
|
|
2800
2803
|
}
|
|
2801
2804
|
const uniqueDetails = [];
|
|
2802
2805
|
for (const detail of validDetails) {
|
|
@@ -3651,7 +3654,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3651
3654
|
const delta = choice.delta;
|
|
3652
3655
|
const emitReasoningChunk = (chunkText, providerMetadata) => {
|
|
3653
3656
|
if (!reasoningStarted) {
|
|
3654
|
-
reasoningId =
|
|
3657
|
+
reasoningId = generateId();
|
|
3655
3658
|
controller.enqueue({
|
|
3656
3659
|
providerMetadata,
|
|
3657
3660
|
type: "reasoning-start",
|
|
@@ -3681,33 +3684,35 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3681
3684
|
accumulatedReasoningDetails.push(detail);
|
|
3682
3685
|
}
|
|
3683
3686
|
}
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
};
|
|
3689
|
-
for (const detail of delta.reasoning_details) {
|
|
3690
|
-
switch (detail.type) {
|
|
3691
|
-
case "reasoning.text" /* Text */: {
|
|
3692
|
-
emitReasoningChunk(detail.text || "", reasoningMetadata);
|
|
3693
|
-
break;
|
|
3694
|
-
}
|
|
3695
|
-
case "reasoning.encrypted" /* Encrypted */: {
|
|
3696
|
-
break;
|
|
3687
|
+
if (!textStarted) {
|
|
3688
|
+
const reasoningMetadata = {
|
|
3689
|
+
openrouter: {
|
|
3690
|
+
reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
|
|
3697
3691
|
}
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3692
|
+
};
|
|
3693
|
+
for (const detail of delta.reasoning_details) {
|
|
3694
|
+
switch (detail.type) {
|
|
3695
|
+
case "reasoning.text" /* Text */: {
|
|
3696
|
+
emitReasoningChunk(detail.text || "", reasoningMetadata);
|
|
3697
|
+
break;
|
|
3698
|
+
}
|
|
3699
|
+
case "reasoning.encrypted" /* Encrypted */: {
|
|
3700
|
+
break;
|
|
3701
|
+
}
|
|
3702
|
+
case "reasoning.summary" /* Summary */: {
|
|
3703
|
+
if (detail.summary) {
|
|
3704
|
+
emitReasoningChunk(detail.summary, reasoningMetadata);
|
|
3705
|
+
}
|
|
3706
|
+
break;
|
|
3707
|
+
}
|
|
3708
|
+
default: {
|
|
3709
|
+
detail;
|
|
3710
|
+
break;
|
|
3701
3711
|
}
|
|
3702
|
-
break;
|
|
3703
|
-
}
|
|
3704
|
-
default: {
|
|
3705
|
-
detail;
|
|
3706
|
-
break;
|
|
3707
3712
|
}
|
|
3708
3713
|
}
|
|
3709
3714
|
}
|
|
3710
|
-
} else if (delta.reasoning) {
|
|
3715
|
+
} else if (delta.reasoning && !textStarted) {
|
|
3711
3716
|
emitReasoningChunk(delta.reasoning);
|
|
3712
3717
|
}
|
|
3713
3718
|
if (delta.content) {
|
|
@@ -3857,6 +3862,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3857
3862
|
id: toolCall.id,
|
|
3858
3863
|
toolName: toolCall.function.name
|
|
3859
3864
|
});
|
|
3865
|
+
if (toolCall.function.arguments) {
|
|
3866
|
+
controller.enqueue({
|
|
3867
|
+
type: "tool-input-delta",
|
|
3868
|
+
id: toolCall.id,
|
|
3869
|
+
delta: toolCall.function.arguments
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3860
3872
|
}
|
|
3861
3873
|
if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
|
|
3862
3874
|
toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
|
|
@@ -3867,6 +3879,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3867
3879
|
delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
|
|
3868
3880
|
});
|
|
3869
3881
|
if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
3882
|
+
controller.enqueue({
|
|
3883
|
+
type: "tool-input-end",
|
|
3884
|
+
id: toolCall.id
|
|
3885
|
+
});
|
|
3870
3886
|
controller.enqueue({
|
|
3871
3887
|
type: "tool-call",
|
|
3872
3888
|
toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
|
|
@@ -3912,12 +3928,28 @@ var OpenRouterChatLanguageModel = class {
|
|
|
3912
3928
|
if (finishReason.unified === "tool-calls") {
|
|
3913
3929
|
for (const toolCall of toolCalls) {
|
|
3914
3930
|
if (toolCall && !toolCall.sent) {
|
|
3931
|
+
const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
|
|
3932
|
+
if (!toolCall.inputStarted) {
|
|
3933
|
+
controller.enqueue({
|
|
3934
|
+
type: "tool-input-start",
|
|
3935
|
+
id: toolCall.id,
|
|
3936
|
+
toolName: toolCall.function.name
|
|
3937
|
+
});
|
|
3938
|
+
controller.enqueue({
|
|
3939
|
+
type: "tool-input-delta",
|
|
3940
|
+
id: toolCall.id,
|
|
3941
|
+
delta: input
|
|
3942
|
+
});
|
|
3943
|
+
}
|
|
3944
|
+
controller.enqueue({
|
|
3945
|
+
type: "tool-input-end",
|
|
3946
|
+
id: toolCall.id
|
|
3947
|
+
});
|
|
3915
3948
|
controller.enqueue({
|
|
3916
3949
|
type: "tool-call",
|
|
3917
3950
|
toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
|
|
3918
3951
|
toolName: toolCall.function.name,
|
|
3919
|
-
|
|
3920
|
-
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
3952
|
+
input,
|
|
3921
3953
|
providerMetadata: !reasoningDetailsAttachedToToolCall ? {
|
|
3922
3954
|
openrouter: {
|
|
3923
3955
|
reasoning_details: accumulatedReasoningDetails
|