@openrouter/ai-sdk-provider 2.2.5 → 2.3.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
@@ -3146,7 +3146,9 @@ var OpenRouterChatLanguageModel = class {
3146
3146
  // Provider routing settings:
3147
3147
  provider: this.settings.provider,
3148
3148
  // Debug settings:
3149
- debug: this.settings.debug
3149
+ debug: this.settings.debug,
3150
+ // Anthropic automatic caching:
3151
+ cache_control: this.settings.cache_control
3150
3152
  }, this.config.extraBody), this.settings.extraBody);
3151
3153
  if (tools && tools.length > 0) {
3152
3154
  const mappedTools = tools.filter(
@@ -3167,10 +3169,11 @@ var OpenRouterChatLanguageModel = class {
3167
3169
  return baseArgs;
3168
3170
  }
3169
3171
  async doGenerate(options) {
3170
- var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
3172
+ var _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3171
3173
  const providerOptions = options.providerOptions || {};
3172
3174
  const openrouterOptions = providerOptions.openrouter || {};
3173
- const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
3175
+ const _a16 = openrouterOptions, { cacheControl } = _a16, restOpenrouterOptions = __objRest(_a16, ["cacheControl"]);
3176
+ const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
3174
3177
  const { value: responseValue, responseHeaders } = await postJsonToApi({
3175
3178
  url: this.config.url({
3176
3179
  path: "/chat/completions",
@@ -3207,7 +3210,7 @@ var OpenRouterChatLanguageModel = class {
3207
3210
  });
3208
3211
  }
3209
3212
  const usageInfo = response.usage ? computeTokenUsage(response.usage) : emptyUsage();
3210
- const reasoningDetails = (_a16 = choice.message.reasoning_details) != null ? _a16 : [];
3213
+ const reasoningDetails = (_b16 = choice.message.reasoning_details) != null ? _b16 : [];
3211
3214
  const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
3212
3215
  switch (detail.type) {
3213
3216
  case "reasoning.text" /* Text */: {
@@ -3276,9 +3279,9 @@ var OpenRouterChatLanguageModel = class {
3276
3279
  for (const toolCall of choice.message.tool_calls) {
3277
3280
  content.push({
3278
3281
  type: "tool-call",
3279
- toolCallId: (_b16 = toolCall.id) != null ? _b16 : generateId(),
3282
+ toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
3280
3283
  toolName: toolCall.function.name,
3281
- input: (_c = toolCall.function.arguments) != null ? _c : "{}",
3284
+ input: (_d = toolCall.function.arguments) != null ? _d : "{}",
3282
3285
  providerMetadata: !reasoningDetailsAttachedToToolCall ? {
3283
3286
  openrouter: {
3284
3287
  reasoning_details: reasoningDetails
@@ -3305,19 +3308,19 @@ var OpenRouterChatLanguageModel = class {
3305
3308
  sourceType: "url",
3306
3309
  id: annotation.url_citation.url,
3307
3310
  url: annotation.url_citation.url,
3308
- title: (_d = annotation.url_citation.title) != null ? _d : "",
3311
+ title: (_e = annotation.url_citation.title) != null ? _e : "",
3309
3312
  providerMetadata: {
3310
3313
  openrouter: {
3311
- content: (_e = annotation.url_citation.content) != null ? _e : "",
3312
- startIndex: (_f = annotation.url_citation.start_index) != null ? _f : 0,
3313
- endIndex: (_g = annotation.url_citation.end_index) != null ? _g : 0
3314
+ content: (_f = annotation.url_citation.content) != null ? _f : "",
3315
+ startIndex: (_g = annotation.url_citation.start_index) != null ? _g : 0,
3316
+ endIndex: (_h = annotation.url_citation.end_index) != null ? _h : 0
3314
3317
  }
3315
3318
  }
3316
3319
  });
3317
3320
  }
3318
3321
  }
3319
3322
  }
3320
- const fileAnnotations = (_h = choice.message.annotations) == null ? void 0 : _h.filter(
3323
+ const fileAnnotations = (_i = choice.message.annotations) == null ? void 0 : _i.filter(
3321
3324
  (a) => a.type === "file"
3322
3325
  );
3323
3326
  const hasToolCalls = choice.message.tool_calls && choice.message.tool_calls.length > 0;
@@ -3325,7 +3328,7 @@ var OpenRouterChatLanguageModel = class {
3325
3328
  (d) => d.type === "reasoning.encrypted" /* Encrypted */ && d.data
3326
3329
  );
3327
3330
  const shouldOverrideFinishReason = hasToolCalls && hasEncryptedReasoning && choice.finish_reason === "stop";
3328
- const effectiveFinishReason = shouldOverrideFinishReason ? createFinishReason("tool-calls", (_i = choice.finish_reason) != null ? _i : void 0) : mapOpenRouterFinishReason(choice.finish_reason);
3331
+ const effectiveFinishReason = shouldOverrideFinishReason ? createFinishReason("tool-calls", (_j = choice.finish_reason) != null ? _j : void 0) : mapOpenRouterFinishReason(choice.finish_reason);
3329
3332
  return {
3330
3333
  content,
3331
3334
  finishReason: effectiveFinishReason,
@@ -3333,22 +3336,22 @@ var OpenRouterChatLanguageModel = class {
3333
3336
  warnings: [],
3334
3337
  providerMetadata: {
3335
3338
  openrouter: OpenRouterProviderMetadataSchema.parse({
3336
- provider: (_j = response.provider) != null ? _j : "",
3337
- reasoning_details: (_k = choice.message.reasoning_details) != null ? _k : [],
3339
+ provider: (_k = response.provider) != null ? _k : "",
3340
+ reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
3338
3341
  annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
3339
3342
  usage: __spreadValues(__spreadValues(__spreadValues(__spreadValues({
3340
- promptTokens: (_l = usageInfo.inputTokens.total) != null ? _l : 0,
3341
- completionTokens: (_m = usageInfo.outputTokens.total) != null ? _m : 0,
3342
- totalTokens: ((_n = usageInfo.inputTokens.total) != null ? _n : 0) + ((_o = usageInfo.outputTokens.total) != null ? _o : 0)
3343
- }, ((_p = response.usage) == null ? void 0 : _p.cost) != null ? { cost: response.usage.cost } : {}), ((_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? {
3343
+ promptTokens: (_m = usageInfo.inputTokens.total) != null ? _m : 0,
3344
+ completionTokens: (_n = usageInfo.outputTokens.total) != null ? _n : 0,
3345
+ totalTokens: ((_o = usageInfo.inputTokens.total) != null ? _o : 0) + ((_p = usageInfo.outputTokens.total) != null ? _p : 0)
3346
+ }, ((_q = response.usage) == null ? void 0 : _q.cost) != null ? { cost: response.usage.cost } : {}), ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
3344
3347
  promptTokensDetails: {
3345
3348
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
3346
3349
  }
3347
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
3350
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
3348
3351
  completionTokensDetails: {
3349
3352
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
3350
3353
  }
3351
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
3354
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
3352
3355
  costDetails: {
3353
3356
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
3354
3357
  }
@@ -3364,10 +3367,11 @@ var OpenRouterChatLanguageModel = class {
3364
3367
  };
3365
3368
  }
3366
3369
  async doStream(options) {
3367
- var _a16;
3370
+ var _b16;
3368
3371
  const providerOptions = options.providerOptions || {};
3369
3372
  const openrouterOptions = providerOptions.openrouter || {};
3370
- const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
3373
+ const _a16 = openrouterOptions, { cacheControl } = _a16, restOpenrouterOptions = __objRest(_a16, ["cacheControl"]);
3374
+ const args = __spreadValues(__spreadValues(__spreadValues({}, this.getArgs(options)), restOpenrouterOptions), cacheControl != null && !("cache_control" in restOpenrouterOptions) ? { cache_control: cacheControl } : {});
3371
3375
  const { value: response, responseHeaders } = await postJsonToApi({
3372
3376
  url: this.config.url({
3373
3377
  path: "/chat/completions",
@@ -3379,7 +3383,7 @@ var OpenRouterChatLanguageModel = class {
3379
3383
  // only include stream_options when in strict compatibility mode:
3380
3384
  stream_options: this.config.compatibility === "strict" ? __spreadValues({
3381
3385
  include_usage: true
3382
- }, ((_a16 = this.settings.usage) == null ? void 0 : _a16.include) ? { include_usage: true } : {}) : void 0
3386
+ }, ((_b16 = this.settings.usage) == null ? void 0 : _b16.include) ? { include_usage: true } : {}) : void 0
3383
3387
  }),
3384
3388
  failedResponseHandler: openrouterFailedResponseHandler,
3385
3389
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -3419,7 +3423,7 @@ var OpenRouterChatLanguageModel = class {
3419
3423
  stream: response.pipeThrough(
3420
3424
  new TransformStream({
3421
3425
  transform(chunk, controller) {
3422
- var _a17, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
3426
+ var _a17, _b17, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
3423
3427
  if (options.includeRawChunks) {
3424
3428
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3425
3429
  }
@@ -3456,7 +3460,7 @@ var OpenRouterChatLanguageModel = class {
3456
3460
  Object.assign(usage.outputTokens, computed.outputTokens);
3457
3461
  rawUsage = value.usage;
3458
3462
  const promptTokens = (_a17 = value.usage.prompt_tokens) != null ? _a17 : 0;
3459
- const completionTokens = (_b16 = value.usage.completion_tokens) != null ? _b16 : 0;
3463
+ const completionTokens = (_b17 = value.usage.completion_tokens) != null ? _b17 : 0;
3460
3464
  openrouterUsage.promptTokens = promptTokens;
3461
3465
  if (value.usage.prompt_tokens_details) {
3462
3466
  openrouterUsage.promptTokensDetails = {
@@ -4572,7 +4576,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4572
4576
  }
4573
4577
 
4574
4578
  // src/version.ts
4575
- var VERSION2 = false ? "0.0.0-test" : "2.2.5";
4579
+ var VERSION2 = false ? "0.0.0-test" : "2.3.0";
4576
4580
 
4577
4581
  // src/provider.ts
4578
4582
  function createOpenRouter(options = {}) {