@openrouter/ai-sdk-provider 2.4.2 → 2.5.0

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.
@@ -2673,7 +2673,7 @@ function convertToOpenRouterChatMessages(prompt) {
2673
2673
  }
2674
2674
  const contentParts = content.map(
2675
2675
  (part, index) => {
2676
- var _a17, _b17, _c2, _d2, _e2, _f2;
2676
+ var _a17, _b17, _c2, _d2, _e2, _f2, _g2;
2677
2677
  const isLastTextPart = part.type === "text" && index === lastTextPartIndex;
2678
2678
  const partCacheControl = getCacheControl(part.providerOptions);
2679
2679
  const cacheControl = part.type === "text" ? partCacheControl != null ? partCacheControl : isLastTextPart ? messageCacheControl : void 0 : partCacheControl;
@@ -2696,14 +2696,26 @@ function convertToOpenRouterChatMessages(prompt) {
2696
2696
  }
2697
2697
  }, cacheControl && { cache_control: cacheControl });
2698
2698
  }
2699
- if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("audio/")) {
2699
+ if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("video/")) {
2700
+ const url = getFileUrl({
2701
+ part,
2702
+ defaultMediaType: "video/mp4"
2703
+ });
2704
+ return __spreadValues({
2705
+ type: "video_url",
2706
+ video_url: {
2707
+ url
2708
+ }
2709
+ }, cacheControl && { cache_control: cacheControl });
2710
+ }
2711
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
2700
2712
  return __spreadValues({
2701
2713
  type: "input_audio",
2702
2714
  input_audio: getInputAudioData(part)
2703
2715
  }, cacheControl && { cache_control: cacheControl });
2704
2716
  }
2705
2717
  const fileName = String(
2706
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
2718
+ (_g2 = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g2 : ""
2707
2719
  );
2708
2720
  const fileData = getFileUrl({
2709
2721
  part,
@@ -2861,7 +2873,7 @@ function getToolResultContent(input) {
2861
2873
  }
2862
2874
  function mapToolResultContentParts(parts) {
2863
2875
  return parts.map((part) => {
2864
- var _a16, _b16, _c;
2876
+ var _a16, _b16, _c, _d;
2865
2877
  switch (part.type) {
2866
2878
  case "text":
2867
2879
  return { type: "text", text: part.text };
@@ -2893,7 +2905,13 @@ function mapToolResultContentParts(parts) {
2893
2905
  image_url: { url: dataUrl }
2894
2906
  };
2895
2907
  }
2896
- if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("audio/")) {
2908
+ if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("video/")) {
2909
+ return {
2910
+ type: "video_url",
2911
+ video_url: { url: dataUrl }
2912
+ };
2913
+ }
2914
+ if ((_c = part.mediaType) == null ? void 0 : _c.startsWith("audio/")) {
2897
2915
  const rawFormat = part.mediaType.replace("audio/", "");
2898
2916
  const format = MIME_TO_FORMAT[rawFormat];
2899
2917
  if (format !== void 0) {
@@ -2909,7 +2927,7 @@ function mapToolResultContentParts(parts) {
2909
2927
  return {
2910
2928
  type: "file",
2911
2929
  file: {
2912
- filename: (_c = part.filename) != null ? _c : "",
2930
+ filename: (_d = part.filename) != null ? _d : "",
2913
2931
  file_data: dataUrl
2914
2932
  }
2915
2933
  };
@@ -3518,7 +3536,8 @@ var OpenRouterChatLanguageModel = class {
3518
3536
  response: {
3519
3537
  id: response.id,
3520
3538
  modelId: response.model,
3521
- headers: responseHeaders
3539
+ headers: responseHeaders,
3540
+ body: response
3522
3541
  }
3523
3542
  };
3524
3543
  }
@@ -3862,6 +3881,13 @@ var OpenRouterChatLanguageModel = class {
3862
3881
  id: toolCall.id,
3863
3882
  toolName: toolCall.function.name
3864
3883
  });
3884
+ if (toolCall.function.arguments) {
3885
+ controller.enqueue({
3886
+ type: "tool-input-delta",
3887
+ id: toolCall.id,
3888
+ delta: toolCall.function.arguments
3889
+ });
3890
+ }
3865
3891
  }
3866
3892
  if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
3867
3893
  toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
@@ -3872,6 +3898,10 @@ var OpenRouterChatLanguageModel = class {
3872
3898
  delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
3873
3899
  });
3874
3900
  if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
3901
+ controller.enqueue({
3902
+ type: "tool-input-end",
3903
+ id: toolCall.id
3904
+ });
3875
3905
  controller.enqueue({
3876
3906
  type: "tool-call",
3877
3907
  toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
@@ -3917,12 +3947,28 @@ var OpenRouterChatLanguageModel = class {
3917
3947
  if (finishReason.unified === "tool-calls") {
3918
3948
  for (const toolCall of toolCalls) {
3919
3949
  if (toolCall && !toolCall.sent) {
3950
+ const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
3951
+ if (!toolCall.inputStarted) {
3952
+ controller.enqueue({
3953
+ type: "tool-input-start",
3954
+ id: toolCall.id,
3955
+ toolName: toolCall.function.name
3956
+ });
3957
+ controller.enqueue({
3958
+ type: "tool-input-delta",
3959
+ id: toolCall.id,
3960
+ delta: input
3961
+ });
3962
+ }
3963
+ controller.enqueue({
3964
+ type: "tool-input-end",
3965
+ id: toolCall.id
3966
+ });
3920
3967
  controller.enqueue({
3921
3968
  type: "tool-call",
3922
3969
  toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
3923
3970
  toolName: toolCall.function.name,
3924
- // Coerce invalid arguments to an empty JSON object
3925
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
3971
+ input,
3926
3972
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3927
3973
  openrouter: {
3928
3974
  reasoning_details: accumulatedReasoningDetails