@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.mjs CHANGED
@@ -2795,9 +2795,12 @@ function convertToOpenRouterChatMessages(prompt) {
2795
2795
  return !!detail.signature;
2796
2796
  });
2797
2797
  if (validDetails.length < candidateReasoningDetails.length) {
2798
- console.warn(
2799
- "[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."
2800
- );
2798
+ const logger = globalThis.AI_SDK_LOG_WARNINGS;
2799
+ if (logger !== false && typeof logger !== "function") {
2800
+ console.warn(
2801
+ "[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."
2802
+ );
2803
+ }
2801
2804
  }
2802
2805
  const uniqueDetails = [];
2803
2806
  for (const detail of validDetails) {
@@ -3652,7 +3655,7 @@ var OpenRouterChatLanguageModel = class {
3652
3655
  const delta = choice.delta;
3653
3656
  const emitReasoningChunk = (chunkText, providerMetadata) => {
3654
3657
  if (!reasoningStarted) {
3655
- reasoningId = openrouterResponseId || generateId();
3658
+ reasoningId = generateId();
3656
3659
  controller.enqueue({
3657
3660
  providerMetadata,
3658
3661
  type: "reasoning-start",
@@ -3682,33 +3685,35 @@ var OpenRouterChatLanguageModel = class {
3682
3685
  accumulatedReasoningDetails.push(detail);
3683
3686
  }
3684
3687
  }
3685
- const reasoningMetadata = {
3686
- openrouter: {
3687
- reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3688
- }
3689
- };
3690
- for (const detail of delta.reasoning_details) {
3691
- switch (detail.type) {
3692
- case "reasoning.text" /* Text */: {
3693
- emitReasoningChunk(detail.text || "", reasoningMetadata);
3694
- break;
3695
- }
3696
- case "reasoning.encrypted" /* Encrypted */: {
3697
- break;
3688
+ if (!textStarted) {
3689
+ const reasoningMetadata = {
3690
+ openrouter: {
3691
+ reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3698
3692
  }
3699
- case "reasoning.summary" /* Summary */: {
3700
- if (detail.summary) {
3701
- emitReasoningChunk(detail.summary, reasoningMetadata);
3693
+ };
3694
+ for (const detail of delta.reasoning_details) {
3695
+ switch (detail.type) {
3696
+ case "reasoning.text" /* Text */: {
3697
+ emitReasoningChunk(detail.text || "", reasoningMetadata);
3698
+ break;
3699
+ }
3700
+ case "reasoning.encrypted" /* Encrypted */: {
3701
+ break;
3702
+ }
3703
+ case "reasoning.summary" /* Summary */: {
3704
+ if (detail.summary) {
3705
+ emitReasoningChunk(detail.summary, reasoningMetadata);
3706
+ }
3707
+ break;
3708
+ }
3709
+ default: {
3710
+ detail;
3711
+ break;
3702
3712
  }
3703
- break;
3704
- }
3705
- default: {
3706
- detail;
3707
- break;
3708
3713
  }
3709
3714
  }
3710
3715
  }
3711
- } else if (delta.reasoning) {
3716
+ } else if (delta.reasoning && !textStarted) {
3712
3717
  emitReasoningChunk(delta.reasoning);
3713
3718
  }
3714
3719
  if (delta.content) {
@@ -3858,6 +3863,13 @@ var OpenRouterChatLanguageModel = class {
3858
3863
  id: toolCall.id,
3859
3864
  toolName: toolCall.function.name
3860
3865
  });
3866
+ if (toolCall.function.arguments) {
3867
+ controller.enqueue({
3868
+ type: "tool-input-delta",
3869
+ id: toolCall.id,
3870
+ delta: toolCall.function.arguments
3871
+ });
3872
+ }
3861
3873
  }
3862
3874
  if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
3863
3875
  toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
@@ -3868,6 +3880,10 @@ var OpenRouterChatLanguageModel = class {
3868
3880
  delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
3869
3881
  });
3870
3882
  if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
3883
+ controller.enqueue({
3884
+ type: "tool-input-end",
3885
+ id: toolCall.id
3886
+ });
3871
3887
  controller.enqueue({
3872
3888
  type: "tool-call",
3873
3889
  toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
@@ -3913,12 +3929,28 @@ var OpenRouterChatLanguageModel = class {
3913
3929
  if (finishReason.unified === "tool-calls") {
3914
3930
  for (const toolCall of toolCalls) {
3915
3931
  if (toolCall && !toolCall.sent) {
3932
+ const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
3933
+ if (!toolCall.inputStarted) {
3934
+ controller.enqueue({
3935
+ type: "tool-input-start",
3936
+ id: toolCall.id,
3937
+ toolName: toolCall.function.name
3938
+ });
3939
+ controller.enqueue({
3940
+ type: "tool-input-delta",
3941
+ id: toolCall.id,
3942
+ delta: input
3943
+ });
3944
+ }
3945
+ controller.enqueue({
3946
+ type: "tool-input-end",
3947
+ id: toolCall.id
3948
+ });
3916
3949
  controller.enqueue({
3917
3950
  type: "tool-call",
3918
3951
  toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
3919
3952
  toolName: toolCall.function.name,
3920
- // Coerce invalid arguments to an empty JSON object
3921
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
3953
+ input,
3922
3954
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3923
3955
  openrouter: {
3924
3956
  reasoning_details: accumulatedReasoningDetails
@@ -4748,7 +4780,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4748
4780
  }
4749
4781
 
4750
4782
  // src/version.ts
4751
- var VERSION2 = false ? "0.0.0-test" : "2.4.1";
4783
+ var VERSION2 = false ? "0.0.0-test" : "2.4.3";
4752
4784
 
4753
4785
  // src/provider.ts
4754
4786
  function createOpenRouter(options = {}) {