@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 CHANGED
@@ -2828,9 +2828,12 @@ function convertToOpenRouterChatMessages(prompt) {
2828
2828
  return !!detail.signature;
2829
2829
  });
2830
2830
  if (validDetails.length < candidateReasoningDetails.length) {
2831
- console.warn(
2832
- "[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."
2833
- );
2831
+ const logger = globalThis.AI_SDK_LOG_WARNINGS;
2832
+ if (logger !== false && typeof logger !== "function") {
2833
+ console.warn(
2834
+ "[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."
2835
+ );
2836
+ }
2834
2837
  }
2835
2838
  const uniqueDetails = [];
2836
2839
  for (const detail of validDetails) {
@@ -3685,7 +3688,7 @@ var OpenRouterChatLanguageModel = class {
3685
3688
  const delta = choice.delta;
3686
3689
  const emitReasoningChunk = (chunkText, providerMetadata) => {
3687
3690
  if (!reasoningStarted) {
3688
- reasoningId = openrouterResponseId || generateId();
3691
+ reasoningId = generateId();
3689
3692
  controller.enqueue({
3690
3693
  providerMetadata,
3691
3694
  type: "reasoning-start",
@@ -3715,33 +3718,35 @@ var OpenRouterChatLanguageModel = class {
3715
3718
  accumulatedReasoningDetails.push(detail);
3716
3719
  }
3717
3720
  }
3718
- const reasoningMetadata = {
3719
- openrouter: {
3720
- reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3721
- }
3722
- };
3723
- for (const detail of delta.reasoning_details) {
3724
- switch (detail.type) {
3725
- case "reasoning.text" /* Text */: {
3726
- emitReasoningChunk(detail.text || "", reasoningMetadata);
3727
- break;
3728
- }
3729
- case "reasoning.encrypted" /* Encrypted */: {
3730
- break;
3721
+ if (!textStarted) {
3722
+ const reasoningMetadata = {
3723
+ openrouter: {
3724
+ reasoning_details: accumulatedReasoningDetails.map((d) => __spreadValues({}, d))
3731
3725
  }
3732
- case "reasoning.summary" /* Summary */: {
3733
- if (detail.summary) {
3734
- emitReasoningChunk(detail.summary, reasoningMetadata);
3726
+ };
3727
+ for (const detail of delta.reasoning_details) {
3728
+ switch (detail.type) {
3729
+ case "reasoning.text" /* Text */: {
3730
+ emitReasoningChunk(detail.text || "", reasoningMetadata);
3731
+ break;
3732
+ }
3733
+ case "reasoning.encrypted" /* Encrypted */: {
3734
+ break;
3735
+ }
3736
+ case "reasoning.summary" /* Summary */: {
3737
+ if (detail.summary) {
3738
+ emitReasoningChunk(detail.summary, reasoningMetadata);
3739
+ }
3740
+ break;
3741
+ }
3742
+ default: {
3743
+ detail;
3744
+ break;
3735
3745
  }
3736
- break;
3737
- }
3738
- default: {
3739
- detail;
3740
- break;
3741
3746
  }
3742
3747
  }
3743
3748
  }
3744
- } else if (delta.reasoning) {
3749
+ } else if (delta.reasoning && !textStarted) {
3745
3750
  emitReasoningChunk(delta.reasoning);
3746
3751
  }
3747
3752
  if (delta.content) {
@@ -3891,6 +3896,13 @@ var OpenRouterChatLanguageModel = class {
3891
3896
  id: toolCall.id,
3892
3897
  toolName: toolCall.function.name
3893
3898
  });
3899
+ if (toolCall.function.arguments) {
3900
+ controller.enqueue({
3901
+ type: "tool-input-delta",
3902
+ id: toolCall.id,
3903
+ delta: toolCall.function.arguments
3904
+ });
3905
+ }
3894
3906
  }
3895
3907
  if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
3896
3908
  toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
@@ -3901,6 +3913,10 @@ var OpenRouterChatLanguageModel = class {
3901
3913
  delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
3902
3914
  });
3903
3915
  if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
3916
+ controller.enqueue({
3917
+ type: "tool-input-end",
3918
+ id: toolCall.id
3919
+ });
3904
3920
  controller.enqueue({
3905
3921
  type: "tool-call",
3906
3922
  toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
@@ -3946,12 +3962,28 @@ var OpenRouterChatLanguageModel = class {
3946
3962
  if (finishReason.unified === "tool-calls") {
3947
3963
  for (const toolCall of toolCalls) {
3948
3964
  if (toolCall && !toolCall.sent) {
3965
+ const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
3966
+ if (!toolCall.inputStarted) {
3967
+ controller.enqueue({
3968
+ type: "tool-input-start",
3969
+ id: toolCall.id,
3970
+ toolName: toolCall.function.name
3971
+ });
3972
+ controller.enqueue({
3973
+ type: "tool-input-delta",
3974
+ id: toolCall.id,
3975
+ delta: input
3976
+ });
3977
+ }
3978
+ controller.enqueue({
3979
+ type: "tool-input-end",
3980
+ id: toolCall.id
3981
+ });
3949
3982
  controller.enqueue({
3950
3983
  type: "tool-call",
3951
3984
  toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
3952
3985
  toolName: toolCall.function.name,
3953
- // Coerce invalid arguments to an empty JSON object
3954
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
3986
+ input,
3955
3987
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3956
3988
  openrouter: {
3957
3989
  reasoning_details: accumulatedReasoningDetails
@@ -4781,7 +4813,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4781
4813
  }
4782
4814
 
4783
4815
  // src/version.ts
4784
- var VERSION2 = false ? "0.0.0-test" : "2.4.1";
4816
+ var VERSION2 = false ? "0.0.0-test" : "2.4.3";
4785
4817
 
4786
4818
  // src/provider.ts
4787
4819
  function createOpenRouter(options = {}) {