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