@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.
@@ -2760,9 +2760,12 @@ function convertToOpenRouterChatMessages(prompt) {
2760
2760
  return !!detail.signature;
2761
2761
  });
2762
2762
  if (validDetails.length < candidateReasoningDetails.length) {
2763
- console.warn(
2764
- "[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."
2765
- );
2763
+ const logger = globalThis.AI_SDK_LOG_WARNINGS;
2764
+ if (logger !== false && typeof logger !== "function") {
2765
+ console.warn(
2766
+ "[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."
2767
+ );
2768
+ }
2766
2769
  }
2767
2770
  const uniqueDetails = [];
2768
2771
  for (const detail of validDetails) {
@@ -3617,7 +3620,7 @@ var OpenRouterChatLanguageModel = class {
3617
3620
  const delta = choice.delta;
3618
3621
  const emitReasoningChunk = (chunkText, providerMetadata) => {
3619
3622
  if (!reasoningStarted) {
3620
- reasoningId = openrouterResponseId || generateId();
3623
+ reasoningId = generateId();
3621
3624
  controller.enqueue({
3622
3625
  providerMetadata,
3623
3626
  type: "reasoning-start",
@@ -3647,33 +3650,35 @@ var OpenRouterChatLanguageModel = class {
3647
3650
  accumulatedReasoningDetails.push(detail);
3648
3651
  }
3649
3652
  }
3650
- const reasoningMetadata = {
3651
- openrouter: {
3652
- reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3653
- }
3654
- };
3655
- for (const detail of delta.reasoning_details) {
3656
- switch (detail.type) {
3657
- case "reasoning.text" /* Text */: {
3658
- emitReasoningChunk(detail.text || "", reasoningMetadata);
3659
- break;
3660
- }
3661
- case "reasoning.encrypted" /* Encrypted */: {
3662
- break;
3653
+ if (!textStarted) {
3654
+ const reasoningMetadata = {
3655
+ openrouter: {
3656
+ reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3663
3657
  }
3664
- case "reasoning.summary" /* Summary */: {
3665
- if (detail.summary) {
3666
- emitReasoningChunk(detail.summary, reasoningMetadata);
3658
+ };
3659
+ for (const detail of delta.reasoning_details) {
3660
+ switch (detail.type) {
3661
+ case "reasoning.text" /* Text */: {
3662
+ emitReasoningChunk(detail.text || "", reasoningMetadata);
3663
+ break;
3664
+ }
3665
+ case "reasoning.encrypted" /* Encrypted */: {
3666
+ break;
3667
+ }
3668
+ case "reasoning.summary" /* Summary */: {
3669
+ if (detail.summary) {
3670
+ emitReasoningChunk(detail.summary, reasoningMetadata);
3671
+ }
3672
+ break;
3673
+ }
3674
+ default: {
3675
+ detail;
3676
+ break;
3667
3677
  }
3668
- break;
3669
- }
3670
- default: {
3671
- detail;
3672
- break;
3673
3678
  }
3674
3679
  }
3675
3680
  }
3676
- } else if (delta.reasoning) {
3681
+ } else if (delta.reasoning && !textStarted) {
3677
3682
  emitReasoningChunk(delta.reasoning);
3678
3683
  }
3679
3684
  if (delta.content) {
@@ -3823,6 +3828,13 @@ var OpenRouterChatLanguageModel = class {
3823
3828
  id: toolCall.id,
3824
3829
  toolName: toolCall.function.name
3825
3830
  });
3831
+ if (toolCall.function.arguments) {
3832
+ controller.enqueue({
3833
+ type: "tool-input-delta",
3834
+ id: toolCall.id,
3835
+ delta: toolCall.function.arguments
3836
+ });
3837
+ }
3826
3838
  }
3827
3839
  if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
3828
3840
  toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
@@ -3833,6 +3845,10 @@ var OpenRouterChatLanguageModel = class {
3833
3845
  delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
3834
3846
  });
3835
3847
  if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
3848
+ controller.enqueue({
3849
+ type: "tool-input-end",
3850
+ id: toolCall.id
3851
+ });
3836
3852
  controller.enqueue({
3837
3853
  type: "tool-call",
3838
3854
  toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
@@ -3878,12 +3894,28 @@ var OpenRouterChatLanguageModel = class {
3878
3894
  if (finishReason.unified === "tool-calls") {
3879
3895
  for (const toolCall of toolCalls) {
3880
3896
  if (toolCall && !toolCall.sent) {
3897
+ const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
3898
+ if (!toolCall.inputStarted) {
3899
+ controller.enqueue({
3900
+ type: "tool-input-start",
3901
+ id: toolCall.id,
3902
+ toolName: toolCall.function.name
3903
+ });
3904
+ controller.enqueue({
3905
+ type: "tool-input-delta",
3906
+ id: toolCall.id,
3907
+ delta: input
3908
+ });
3909
+ }
3910
+ controller.enqueue({
3911
+ type: "tool-input-end",
3912
+ id: toolCall.id
3913
+ });
3881
3914
  controller.enqueue({
3882
3915
  type: "tool-call",
3883
3916
  toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
3884
3917
  toolName: toolCall.function.name,
3885
- // Coerce invalid arguments to an empty JSON object
3886
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
3918
+ input,
3887
3919
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3888
3920
  openrouter: {
3889
3921
  reasoning_details: accumulatedReasoningDetails