@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.js CHANGED
@@ -2707,7 +2707,7 @@ function convertToOpenRouterChatMessages(prompt) {
2707
2707
  }
2708
2708
  const contentParts = content.map(
2709
2709
  (part, index) => {
2710
- var _a17, _b17, _c2, _d2, _e2, _f2;
2710
+ var _a17, _b17, _c2, _d2, _e2, _f2, _g2;
2711
2711
  const isLastTextPart = part.type === "text" && index === lastTextPartIndex;
2712
2712
  const partCacheControl = getCacheControl(part.providerOptions);
2713
2713
  const cacheControl = part.type === "text" ? partCacheControl != null ? partCacheControl : isLastTextPart ? messageCacheControl : void 0 : partCacheControl;
@@ -2730,14 +2730,26 @@ function convertToOpenRouterChatMessages(prompt) {
2730
2730
  }
2731
2731
  }, cacheControl && { cache_control: cacheControl });
2732
2732
  }
2733
- if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("audio/")) {
2733
+ if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("video/")) {
2734
+ const url = getFileUrl({
2735
+ part,
2736
+ defaultMediaType: "video/mp4"
2737
+ });
2738
+ return __spreadValues({
2739
+ type: "video_url",
2740
+ video_url: {
2741
+ url
2742
+ }
2743
+ }, cacheControl && { cache_control: cacheControl });
2744
+ }
2745
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
2734
2746
  return __spreadValues({
2735
2747
  type: "input_audio",
2736
2748
  input_audio: getInputAudioData(part)
2737
2749
  }, cacheControl && { cache_control: cacheControl });
2738
2750
  }
2739
2751
  const fileName = String(
2740
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
2752
+ (_g2 = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g2 : ""
2741
2753
  );
2742
2754
  const fileData = getFileUrl({
2743
2755
  part,
@@ -2895,7 +2907,7 @@ function getToolResultContent(input) {
2895
2907
  }
2896
2908
  function mapToolResultContentParts(parts) {
2897
2909
  return parts.map((part) => {
2898
- var _a16, _b16, _c;
2910
+ var _a16, _b16, _c, _d;
2899
2911
  switch (part.type) {
2900
2912
  case "text":
2901
2913
  return { type: "text", text: part.text };
@@ -2927,7 +2939,13 @@ function mapToolResultContentParts(parts) {
2927
2939
  image_url: { url: dataUrl }
2928
2940
  };
2929
2941
  }
2930
- if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("audio/")) {
2942
+ if ((_b16 = part.mediaType) == null ? void 0 : _b16.startsWith("video/")) {
2943
+ return {
2944
+ type: "video_url",
2945
+ video_url: { url: dataUrl }
2946
+ };
2947
+ }
2948
+ if ((_c = part.mediaType) == null ? void 0 : _c.startsWith("audio/")) {
2931
2949
  const rawFormat = part.mediaType.replace("audio/", "");
2932
2950
  const format = MIME_TO_FORMAT[rawFormat];
2933
2951
  if (format !== void 0) {
@@ -2943,7 +2961,7 @@ function mapToolResultContentParts(parts) {
2943
2961
  return {
2944
2962
  type: "file",
2945
2963
  file: {
2946
- filename: (_c = part.filename) != null ? _c : "",
2964
+ filename: (_d = part.filename) != null ? _d : "",
2947
2965
  file_data: dataUrl
2948
2966
  }
2949
2967
  };
@@ -3552,7 +3570,8 @@ var OpenRouterChatLanguageModel = class {
3552
3570
  response: {
3553
3571
  id: response.id,
3554
3572
  modelId: response.model,
3555
- headers: responseHeaders
3573
+ headers: responseHeaders,
3574
+ body: response
3556
3575
  }
3557
3576
  };
3558
3577
  }
@@ -3896,6 +3915,13 @@ var OpenRouterChatLanguageModel = class {
3896
3915
  id: toolCall.id,
3897
3916
  toolName: toolCall.function.name
3898
3917
  });
3918
+ if (toolCall.function.arguments) {
3919
+ controller.enqueue({
3920
+ type: "tool-input-delta",
3921
+ id: toolCall.id,
3922
+ delta: toolCall.function.arguments
3923
+ });
3924
+ }
3899
3925
  }
3900
3926
  if (((_o = toolCallDelta.function) == null ? void 0 : _o.arguments) != null) {
3901
3927
  toolCall.function.arguments += (_q = (_p = toolCallDelta.function) == null ? void 0 : _p.arguments) != null ? _q : "";
@@ -3906,6 +3932,10 @@ var OpenRouterChatLanguageModel = class {
3906
3932
  delta: (_r = toolCallDelta.function.arguments) != null ? _r : ""
3907
3933
  });
3908
3934
  if (((_s = toolCall.function) == null ? void 0 : _s.name) != null && ((_t = toolCall.function) == null ? void 0 : _t.arguments) != null && isParsableJson(toolCall.function.arguments)) {
3935
+ controller.enqueue({
3936
+ type: "tool-input-end",
3937
+ id: toolCall.id
3938
+ });
3909
3939
  controller.enqueue({
3910
3940
  type: "tool-call",
3911
3941
  toolCallId: (_u = toolCall.id) != null ? _u : generateId(),
@@ -3951,12 +3981,28 @@ var OpenRouterChatLanguageModel = class {
3951
3981
  if (finishReason.unified === "tool-calls") {
3952
3982
  for (const toolCall of toolCalls) {
3953
3983
  if (toolCall && !toolCall.sent) {
3984
+ const input = isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}";
3985
+ if (!toolCall.inputStarted) {
3986
+ controller.enqueue({
3987
+ type: "tool-input-start",
3988
+ id: toolCall.id,
3989
+ toolName: toolCall.function.name
3990
+ });
3991
+ controller.enqueue({
3992
+ type: "tool-input-delta",
3993
+ id: toolCall.id,
3994
+ delta: input
3995
+ });
3996
+ }
3997
+ controller.enqueue({
3998
+ type: "tool-input-end",
3999
+ id: toolCall.id
4000
+ });
3954
4001
  controller.enqueue({
3955
4002
  type: "tool-call",
3956
4003
  toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
3957
4004
  toolName: toolCall.function.name,
3958
- // Coerce invalid arguments to an empty JSON object
3959
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
4005
+ input,
3960
4006
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3961
4007
  openrouter: {
3962
4008
  reasoning_details: accumulatedReasoningDetails
@@ -4786,7 +4832,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4786
4832
  }
4787
4833
 
4788
4834
  // src/version.ts
4789
- var VERSION2 = false ? "0.0.0-test" : "2.4.2";
4835
+ var VERSION2 = false ? "0.0.0-test" : "2.5.0";
4790
4836
 
4791
4837
  // src/provider.ts
4792
4838
  function createOpenRouter(options = {}) {