@openrouter/ai-sdk-provider 2.2.0 → 2.2.2

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.d.mts CHANGED
@@ -21,6 +21,12 @@ type IdModeration = 'moderation';
21
21
  * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
22
22
  */
23
23
  type IdResponseHealing = 'response-healing';
24
+ /**
25
+ * Plugin identifier for auto-router model selection.
26
+ * Configures allowed models when using the openrouter/auto model.
27
+ * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
28
+ */
29
+ type IdAutoRouter = 'auto-router';
24
30
  /**
25
31
  * Search engine options for web search.
26
32
  * Open enum - accepts known values or any string for forward compatibility.
@@ -112,6 +118,17 @@ type OpenRouterChatSettings = {
112
118
  * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
113
119
  */
114
120
  id: IdResponseHealing;
121
+ } | {
122
+ /**
123
+ * Auto-router plugin - configures allowed models when using `openrouter/auto`.
124
+ *
125
+ * Use wildcard patterns to restrict which models the auto router can select from.
126
+ * When no `allowed_models` are specified, the auto router uses all supported models.
127
+ *
128
+ * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
129
+ */
130
+ id: IdAutoRouter;
131
+ allowed_models?: string[];
115
132
  }>;
116
133
  /**
117
134
  * Built-in web search options for models that support native web search
package/dist/index.d.ts CHANGED
@@ -21,6 +21,12 @@ type IdModeration = 'moderation';
21
21
  * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
22
22
  */
23
23
  type IdResponseHealing = 'response-healing';
24
+ /**
25
+ * Plugin identifier for auto-router model selection.
26
+ * Configures allowed models when using the openrouter/auto model.
27
+ * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
28
+ */
29
+ type IdAutoRouter = 'auto-router';
24
30
  /**
25
31
  * Search engine options for web search.
26
32
  * Open enum - accepts known values or any string for forward compatibility.
@@ -112,6 +118,17 @@ type OpenRouterChatSettings = {
112
118
  * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
113
119
  */
114
120
  id: IdResponseHealing;
121
+ } | {
122
+ /**
123
+ * Auto-router plugin - configures allowed models when using `openrouter/auto`.
124
+ *
125
+ * Use wildcard patterns to restrict which models the auto router can select from.
126
+ * When no `allowed_models` are specified, the auto router uses all supported models.
127
+ *
128
+ * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
129
+ */
130
+ id: IdAutoRouter;
131
+ allowed_models?: string[];
115
132
  }>;
116
133
  /**
117
134
  * Built-in web search options for models that support native web search
package/dist/index.js CHANGED
@@ -2430,23 +2430,34 @@ function isUrl({
2430
2430
  }
2431
2431
 
2432
2432
  // src/chat/file-url-utils.ts
2433
- function getFileUrl({
2434
- part,
2433
+ function buildFileDataUrl({
2434
+ data,
2435
+ mediaType,
2435
2436
  defaultMediaType
2436
2437
  }) {
2437
- var _a16, _b16;
2438
- if (part.data instanceof Uint8Array) {
2439
- const base64 = convertUint8ArrayToBase64(part.data);
2440
- return `data:${(_a16 = part.mediaType) != null ? _a16 : defaultMediaType};base64,${base64}`;
2438
+ if (data instanceof Uint8Array) {
2439
+ const base64 = convertUint8ArrayToBase64(data);
2440
+ return `data:${mediaType != null ? mediaType : defaultMediaType};base64,${base64}`;
2441
2441
  }
2442
- const stringUrl = part.data.toString();
2442
+ const stringData = data.toString();
2443
2443
  if (isUrl({
2444
- url: stringUrl,
2444
+ url: stringData,
2445
2445
  protocols: /* @__PURE__ */ new Set(["http:", "https:"])
2446
2446
  })) {
2447
- return stringUrl;
2447
+ return stringData;
2448
2448
  }
2449
- return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b16 = part.mediaType) != null ? _b16 : defaultMediaType};base64,${stringUrl}`;
2449
+ return stringData.startsWith("data:") ? stringData : `data:${mediaType != null ? mediaType : defaultMediaType};base64,${stringData}`;
2450
+ }
2451
+ function getFileUrl({
2452
+ part,
2453
+ defaultMediaType
2454
+ }) {
2455
+ const data = part.data instanceof URL ? part.data.toString() : part.data;
2456
+ return buildFileDataUrl({
2457
+ data,
2458
+ mediaType: part.mediaType,
2459
+ defaultMediaType
2460
+ });
2450
2461
  }
2451
2462
  function getMediaType(dataUrl, defaultMediaType) {
2452
2463
  var _a16;
@@ -4403,11 +4414,6 @@ var OpenRouterImageModel = class {
4403
4414
  } = options;
4404
4415
  const openrouterOptions = (providerOptions == null ? void 0 : providerOptions.openrouter) || {};
4405
4416
  const warnings = [];
4406
- if (files !== void 0 && files.length > 0) {
4407
- throw new UnsupportedFunctionalityError({
4408
- functionality: "image editing (files parameter)"
4409
- });
4410
- }
4411
4417
  if (mask !== void 0) {
4412
4418
  throw new UnsupportedFunctionalityError({
4413
4419
  functionality: "image inpainting (mask parameter)"
@@ -4428,12 +4434,19 @@ var OpenRouterImageModel = class {
4428
4434
  });
4429
4435
  }
4430
4436
  const imageConfig = aspectRatio !== void 0 ? { aspect_ratio: aspectRatio } : void 0;
4437
+ const hasFiles = files !== void 0 && files.length > 0;
4438
+ const userContent = hasFiles ? [
4439
+ ...files.map(
4440
+ (file) => convertImageFileToContentPart(file)
4441
+ ),
4442
+ { type: "text", text: prompt != null ? prompt : "" }
4443
+ ] : prompt != null ? prompt : "";
4431
4444
  const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
4432
4445
  model: this.modelId,
4433
4446
  messages: [
4434
4447
  {
4435
4448
  role: "user",
4436
- content: prompt != null ? prompt : ""
4449
+ content: userContent
4437
4450
  }
4438
4451
  ],
4439
4452
  modalities: ["image", "text"]
@@ -4484,6 +4497,24 @@ var OpenRouterImageModel = class {
4484
4497
  };
4485
4498
  }
4486
4499
  };
4500
+ var DEFAULT_IMAGE_MEDIA_TYPE = "image/png";
4501
+ function convertImageFileToContentPart(file) {
4502
+ if (file.type === "url") {
4503
+ return {
4504
+ type: "image_url",
4505
+ image_url: { url: file.url }
4506
+ };
4507
+ }
4508
+ const url = buildFileDataUrl({
4509
+ data: file.data,
4510
+ mediaType: file.mediaType,
4511
+ defaultMediaType: DEFAULT_IMAGE_MEDIA_TYPE
4512
+ });
4513
+ return {
4514
+ type: "image_url",
4515
+ image_url: { url }
4516
+ };
4517
+ }
4487
4518
 
4488
4519
  // src/utils/remove-undefined.ts
4489
4520
  function removeUndefinedEntries(record) {
@@ -4526,7 +4557,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4526
4557
  }
4527
4558
 
4528
4559
  // src/version.ts
4529
- var VERSION2 = false ? "0.0.0-test" : "2.2.0";
4560
+ var VERSION2 = false ? "0.0.0-test" : "2.2.2";
4530
4561
 
4531
4562
  // src/provider.ts
4532
4563
  function createOpenRouter(options = {}) {