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