@openrouter/ai-sdk-provider 0.5.0 → 0.7.0-alpha.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/README.md +6 -4
- package/dist/index.d.mts +21 -19
- package/dist/index.d.ts +21 -19
- package/dist/index.js +243 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -100
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +33 -31
- package/dist/internal/index.d.ts +33 -31
- package/dist/internal/index.js +243 -100
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +243 -100
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +15 -14
package/dist/internal/index.d.ts
CHANGED
|
@@ -56,8 +56,8 @@ type OpenRouterUsageAccounting = {
|
|
|
56
56
|
cost?: number;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
type
|
|
60
|
-
type
|
|
59
|
+
type OpenRouterCompletionModelId = string;
|
|
60
|
+
type OpenRouterCompletionSettings = {
|
|
61
61
|
/**
|
|
62
62
|
Modify the likelihood of specified tokens appearing in the completion.
|
|
63
63
|
|
|
@@ -71,7 +71,7 @@ type OpenRouterChatSettings = {
|
|
|
71
71
|
|
|
72
72
|
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
73
73
|
token from being generated.
|
|
74
|
-
|
|
74
|
+
*/
|
|
75
75
|
logitBias?: Record<number, number>;
|
|
76
76
|
/**
|
|
77
77
|
Return the log probabilities of the tokens. Including logprobs will increase
|
|
@@ -83,20 +83,15 @@ type OpenRouterChatSettings = {
|
|
|
83
83
|
|
|
84
84
|
Setting to a number will return the log probabilities of the top n
|
|
85
85
|
tokens that were generated.
|
|
86
|
-
|
|
86
|
+
*/
|
|
87
87
|
logprobs?: boolean | number;
|
|
88
88
|
/**
|
|
89
|
-
|
|
89
|
+
The suffix that comes after a completion of inserted text.
|
|
90
90
|
*/
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
A unique identifier representing your end-user, which can help OpenRouter to
|
|
94
|
-
monitor and detect abuse. Learn more.
|
|
95
|
-
*/
|
|
96
|
-
user?: string;
|
|
91
|
+
suffix?: string;
|
|
97
92
|
} & OpenRouterSharedSettings;
|
|
98
93
|
|
|
99
|
-
type
|
|
94
|
+
type OpenRouterCompletionConfig = {
|
|
100
95
|
provider: string;
|
|
101
96
|
compatibility: 'strict' | 'compatible';
|
|
102
97
|
headers: () => Record<string, string | undefined>;
|
|
@@ -107,21 +102,21 @@ type OpenRouterChatConfig = {
|
|
|
107
102
|
fetch?: typeof fetch;
|
|
108
103
|
extraBody?: Record<string, unknown>;
|
|
109
104
|
};
|
|
110
|
-
declare class
|
|
105
|
+
declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
|
|
111
106
|
readonly specificationVersion = "v1";
|
|
112
|
-
readonly defaultObjectGenerationMode
|
|
113
|
-
readonly modelId:
|
|
114
|
-
readonly settings:
|
|
107
|
+
readonly defaultObjectGenerationMode: undefined;
|
|
108
|
+
readonly modelId: OpenRouterCompletionModelId;
|
|
109
|
+
readonly settings: OpenRouterCompletionSettings;
|
|
115
110
|
private readonly config;
|
|
116
|
-
constructor(modelId:
|
|
111
|
+
constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
|
|
117
112
|
get provider(): string;
|
|
118
113
|
private getArgs;
|
|
119
114
|
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
|
120
115
|
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
|
121
116
|
}
|
|
122
117
|
|
|
123
|
-
type
|
|
124
|
-
type
|
|
118
|
+
type OpenRouterChatModelId = string;
|
|
119
|
+
type OpenRouterChatSettings = {
|
|
125
120
|
/**
|
|
126
121
|
Modify the likelihood of specified tokens appearing in the completion.
|
|
127
122
|
|
|
@@ -135,7 +130,7 @@ type OpenRouterCompletionSettings = {
|
|
|
135
130
|
|
|
136
131
|
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
137
132
|
token from being generated.
|
|
138
|
-
|
|
133
|
+
*/
|
|
139
134
|
logitBias?: Record<number, number>;
|
|
140
135
|
/**
|
|
141
136
|
Return the log probabilities of the tokens. Including logprobs will increase
|
|
@@ -147,15 +142,20 @@ type OpenRouterCompletionSettings = {
|
|
|
147
142
|
|
|
148
143
|
Setting to a number will return the log probabilities of the top n
|
|
149
144
|
tokens that were generated.
|
|
150
|
-
|
|
145
|
+
*/
|
|
151
146
|
logprobs?: boolean | number;
|
|
152
147
|
/**
|
|
153
|
-
|
|
148
|
+
Whether to enable parallel function calling during tool use. Default to true.
|
|
154
149
|
*/
|
|
155
|
-
|
|
150
|
+
parallelToolCalls?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
A unique identifier representing your end-user, which can help OpenRouter to
|
|
153
|
+
monitor and detect abuse. Learn more.
|
|
154
|
+
*/
|
|
155
|
+
user?: string;
|
|
156
156
|
} & OpenRouterSharedSettings;
|
|
157
157
|
|
|
158
|
-
type
|
|
158
|
+
type OpenRouterChatConfig = {
|
|
159
159
|
provider: string;
|
|
160
160
|
compatibility: 'strict' | 'compatible';
|
|
161
161
|
headers: () => Record<string, string | undefined>;
|
|
@@ -166,17 +166,19 @@ type OpenRouterCompletionConfig = {
|
|
|
166
166
|
fetch?: typeof fetch;
|
|
167
167
|
extraBody?: Record<string, unknown>;
|
|
168
168
|
};
|
|
169
|
-
|
|
169
|
+
type DoGenerateOutput = Awaited<ReturnType<LanguageModelV1['doGenerate']>>;
|
|
170
|
+
type DoStreamOutput = Awaited<ReturnType<LanguageModelV1['doStream']>>;
|
|
171
|
+
declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
170
172
|
readonly specificationVersion = "v1";
|
|
171
|
-
readonly defaultObjectGenerationMode
|
|
172
|
-
readonly modelId:
|
|
173
|
-
readonly settings:
|
|
173
|
+
readonly defaultObjectGenerationMode = "tool";
|
|
174
|
+
readonly modelId: OpenRouterChatModelId;
|
|
175
|
+
readonly settings: OpenRouterChatSettings;
|
|
174
176
|
private readonly config;
|
|
175
|
-
constructor(modelId:
|
|
177
|
+
constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
|
|
176
178
|
get provider(): string;
|
|
177
179
|
private getArgs;
|
|
178
|
-
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<
|
|
179
|
-
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<
|
|
180
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<DoGenerateOutput>;
|
|
181
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<DoStreamOutput>;
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, type OpenRouterLanguageModel, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
|
package/dist/internal/index.js
CHANGED
|
@@ -54,10 +54,36 @@ __export(index_exports, {
|
|
|
54
54
|
});
|
|
55
55
|
module.exports = __toCommonJS(index_exports);
|
|
56
56
|
|
|
57
|
+
// src/schemas/reasoning-details.ts
|
|
58
|
+
var import_zod = require("zod");
|
|
59
|
+
var ReasoningDetailSummarySchema = import_zod.z.object({
|
|
60
|
+
type: import_zod.z.literal("reasoning.summary" /* Summary */),
|
|
61
|
+
summary: import_zod.z.string()
|
|
62
|
+
});
|
|
63
|
+
var ReasoningDetailEncryptedSchema = import_zod.z.object({
|
|
64
|
+
type: import_zod.z.literal("reasoning.encrypted" /* Encrypted */),
|
|
65
|
+
data: import_zod.z.string()
|
|
66
|
+
});
|
|
67
|
+
var ReasoningDetailTextSchema = import_zod.z.object({
|
|
68
|
+
type: import_zod.z.literal("reasoning.text" /* Text */),
|
|
69
|
+
text: import_zod.z.string().nullish(),
|
|
70
|
+
signature: import_zod.z.string().nullish()
|
|
71
|
+
});
|
|
72
|
+
var ReasoningDetailUnionSchema = import_zod.z.union([
|
|
73
|
+
ReasoningDetailSummarySchema,
|
|
74
|
+
ReasoningDetailEncryptedSchema,
|
|
75
|
+
ReasoningDetailTextSchema
|
|
76
|
+
]);
|
|
77
|
+
var ReasoningDetailsWithUnknownSchema = import_zod.z.union([
|
|
78
|
+
ReasoningDetailUnionSchema,
|
|
79
|
+
import_zod.z.unknown().transform(() => null)
|
|
80
|
+
]);
|
|
81
|
+
var ReasoningDetailArraySchema = import_zod.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
82
|
+
|
|
57
83
|
// src/openrouter-chat-language-model.ts
|
|
58
84
|
var import_provider = require("@ai-sdk/provider");
|
|
59
85
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
60
|
-
var
|
|
86
|
+
var import_zod3 = require("zod");
|
|
61
87
|
|
|
62
88
|
// src/convert-to-openrouter-chat-messages.ts
|
|
63
89
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -92,14 +118,15 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
92
118
|
const messageCacheControl = getCacheControl(providerMetadata);
|
|
93
119
|
const contentParts = content.map(
|
|
94
120
|
(part) => {
|
|
95
|
-
var _a2, _b2, _c2, _d
|
|
121
|
+
var _a2, _b2, _c2, _d;
|
|
122
|
+
const cacheControl = (_a2 = getCacheControl(part.providerMetadata)) != null ? _a2 : messageCacheControl;
|
|
96
123
|
switch (part.type) {
|
|
97
124
|
case "text":
|
|
98
125
|
return {
|
|
99
126
|
type: "text",
|
|
100
127
|
text: part.text,
|
|
101
128
|
// For text parts, only use part-specific cache control
|
|
102
|
-
cache_control:
|
|
129
|
+
cache_control: cacheControl
|
|
103
130
|
};
|
|
104
131
|
case "image":
|
|
105
132
|
return {
|
|
@@ -110,18 +137,18 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
110
137
|
)}`
|
|
111
138
|
},
|
|
112
139
|
// For image parts, use part-specific or message-level cache control
|
|
113
|
-
cache_control:
|
|
140
|
+
cache_control: cacheControl
|
|
114
141
|
};
|
|
115
142
|
case "file":
|
|
116
143
|
return {
|
|
117
144
|
type: "file",
|
|
118
145
|
file: {
|
|
119
146
|
filename: String(
|
|
120
|
-
(
|
|
147
|
+
(_d = (_c2 = part.providerMetadata) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename
|
|
121
148
|
),
|
|
122
149
|
file_data: part.data instanceof Uint8Array ? `data:${part.mimeType};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.data)}` : `data:${part.mimeType};base64,${part.data}`
|
|
123
150
|
},
|
|
124
|
-
cache_control:
|
|
151
|
+
cache_control: cacheControl
|
|
125
152
|
};
|
|
126
153
|
default: {
|
|
127
154
|
const _exhaustiveCheck = part;
|
|
@@ -140,6 +167,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
140
167
|
}
|
|
141
168
|
case "assistant": {
|
|
142
169
|
let text = "";
|
|
170
|
+
let reasoning = "";
|
|
171
|
+
const reasoningDetails = [];
|
|
143
172
|
const toolCalls = [];
|
|
144
173
|
for (const part of content) {
|
|
145
174
|
switch (part.type) {
|
|
@@ -158,9 +187,23 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
158
187
|
});
|
|
159
188
|
break;
|
|
160
189
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
190
|
+
case "reasoning": {
|
|
191
|
+
reasoning += part.text;
|
|
192
|
+
reasoningDetails.push({
|
|
193
|
+
type: "reasoning.text" /* Text */,
|
|
194
|
+
text: part.text,
|
|
195
|
+
signature: part.signature
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "redacted-reasoning": {
|
|
200
|
+
reasoningDetails.push({
|
|
201
|
+
type: "reasoning.encrypted" /* Encrypted */,
|
|
202
|
+
data: part.data
|
|
203
|
+
});
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case "file":
|
|
164
207
|
break;
|
|
165
208
|
default: {
|
|
166
209
|
const _exhaustiveCheck = part;
|
|
@@ -172,6 +215,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
172
215
|
role: "assistant",
|
|
173
216
|
content: text,
|
|
174
217
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
218
|
+
reasoning: reasoning || void 0,
|
|
219
|
+
reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
|
|
175
220
|
cache_control: getCacheControl(providerMetadata)
|
|
176
221
|
});
|
|
177
222
|
break;
|
|
@@ -228,13 +273,13 @@ function mapOpenRouterFinishReason(finishReason) {
|
|
|
228
273
|
|
|
229
274
|
// src/openrouter-error.ts
|
|
230
275
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
231
|
-
var
|
|
232
|
-
var OpenRouterErrorResponseSchema =
|
|
233
|
-
error:
|
|
234
|
-
message:
|
|
235
|
-
type:
|
|
236
|
-
param:
|
|
237
|
-
code:
|
|
276
|
+
var import_zod2 = require("zod");
|
|
277
|
+
var OpenRouterErrorResponseSchema = import_zod2.z.object({
|
|
278
|
+
error: import_zod2.z.object({
|
|
279
|
+
message: import_zod2.z.string(),
|
|
280
|
+
type: import_zod2.z.string(),
|
|
281
|
+
param: import_zod2.z.any().nullable(),
|
|
282
|
+
code: import_zod2.z.string().nullable()
|
|
238
283
|
})
|
|
239
284
|
});
|
|
240
285
|
var openrouterFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
@@ -381,13 +426,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
381
426
|
};
|
|
382
427
|
}
|
|
383
428
|
const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
|
|
429
|
+
const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
|
|
430
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
431
|
+
var _a2;
|
|
432
|
+
switch (detail.type) {
|
|
433
|
+
case "reasoning.text" /* Text */: {
|
|
434
|
+
if (detail.text) {
|
|
435
|
+
return {
|
|
436
|
+
type: "text",
|
|
437
|
+
text: detail.text,
|
|
438
|
+
signature: (_a2 = detail.signature) != null ? _a2 : void 0
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
case "reasoning.summary" /* Summary */: {
|
|
444
|
+
if (detail.summary) {
|
|
445
|
+
return {
|
|
446
|
+
type: "text",
|
|
447
|
+
text: detail.summary
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
case "reasoning.encrypted" /* Encrypted */: {
|
|
453
|
+
if (detail.data) {
|
|
454
|
+
return {
|
|
455
|
+
type: "redacted",
|
|
456
|
+
data: detail.data
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
default: {
|
|
462
|
+
detail;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return null;
|
|
466
|
+
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
467
|
+
{
|
|
468
|
+
type: "text",
|
|
469
|
+
text: choice.message.reasoning
|
|
470
|
+
}
|
|
471
|
+
] : [];
|
|
384
472
|
return __spreadValues({
|
|
385
473
|
response: {
|
|
386
474
|
id: response.id,
|
|
387
475
|
modelId: response.model
|
|
388
476
|
},
|
|
389
|
-
text: (
|
|
390
|
-
reasoning
|
|
477
|
+
text: (_i = choice.message.content) != null ? _i : void 0,
|
|
478
|
+
reasoning,
|
|
391
479
|
toolCalls: (_j = choice.message.tool_calls) == null ? void 0 : _j.map((toolCall) => {
|
|
392
480
|
var _a2;
|
|
393
481
|
return {
|
|
@@ -506,11 +594,56 @@ var OpenRouterChatLanguageModel = class {
|
|
|
506
594
|
textDelta: delta.reasoning
|
|
507
595
|
});
|
|
508
596
|
}
|
|
597
|
+
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
598
|
+
for (const detail of delta.reasoning_details) {
|
|
599
|
+
switch (detail.type) {
|
|
600
|
+
case "reasoning.text" /* Text */: {
|
|
601
|
+
if (detail.text) {
|
|
602
|
+
controller.enqueue({
|
|
603
|
+
type: "reasoning",
|
|
604
|
+
textDelta: detail.text
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (detail.signature) {
|
|
608
|
+
controller.enqueue({
|
|
609
|
+
type: "reasoning-signature",
|
|
610
|
+
signature: detail.signature
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
case "reasoning.encrypted" /* Encrypted */: {
|
|
616
|
+
if (detail.data) {
|
|
617
|
+
controller.enqueue({
|
|
618
|
+
type: "redacted-reasoning",
|
|
619
|
+
data: detail.data
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
case "reasoning.summary" /* Summary */: {
|
|
625
|
+
if (detail.summary) {
|
|
626
|
+
controller.enqueue({
|
|
627
|
+
type: "reasoning",
|
|
628
|
+
textDelta: detail.summary
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
default: {
|
|
634
|
+
detail;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
509
640
|
const mappedLogprobs = mapOpenRouterChatLogProbsOutput(
|
|
510
641
|
choice == null ? void 0 : choice.logprobs
|
|
511
642
|
);
|
|
512
643
|
if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
|
|
513
|
-
if (logprobs === void 0)
|
|
644
|
+
if (logprobs === void 0) {
|
|
645
|
+
logprobs = [];
|
|
646
|
+
}
|
|
514
647
|
logprobs.push(...mappedLogprobs);
|
|
515
648
|
}
|
|
516
649
|
if (delta.tool_calls != null) {
|
|
@@ -633,95 +766,97 @@ var OpenRouterChatLanguageModel = class {
|
|
|
633
766
|
};
|
|
634
767
|
}
|
|
635
768
|
};
|
|
636
|
-
var OpenRouterChatCompletionBaseResponseSchema =
|
|
637
|
-
id:
|
|
638
|
-
model:
|
|
639
|
-
usage:
|
|
640
|
-
prompt_tokens:
|
|
641
|
-
prompt_tokens_details:
|
|
642
|
-
cached_tokens:
|
|
769
|
+
var OpenRouterChatCompletionBaseResponseSchema = import_zod3.z.object({
|
|
770
|
+
id: import_zod3.z.string().optional(),
|
|
771
|
+
model: import_zod3.z.string().optional(),
|
|
772
|
+
usage: import_zod3.z.object({
|
|
773
|
+
prompt_tokens: import_zod3.z.number(),
|
|
774
|
+
prompt_tokens_details: import_zod3.z.object({
|
|
775
|
+
cached_tokens: import_zod3.z.number()
|
|
643
776
|
}).optional(),
|
|
644
|
-
completion_tokens:
|
|
645
|
-
completion_tokens_details:
|
|
646
|
-
reasoning_tokens:
|
|
777
|
+
completion_tokens: import_zod3.z.number(),
|
|
778
|
+
completion_tokens_details: import_zod3.z.object({
|
|
779
|
+
reasoning_tokens: import_zod3.z.number()
|
|
647
780
|
}).optional(),
|
|
648
|
-
total_tokens:
|
|
649
|
-
cost:
|
|
781
|
+
total_tokens: import_zod3.z.number(),
|
|
782
|
+
cost: import_zod3.z.number().optional()
|
|
650
783
|
}).nullish()
|
|
651
784
|
});
|
|
652
785
|
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
653
|
-
choices:
|
|
654
|
-
|
|
655
|
-
message:
|
|
656
|
-
role:
|
|
657
|
-
content:
|
|
658
|
-
reasoning:
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
786
|
+
choices: import_zod3.z.array(
|
|
787
|
+
import_zod3.z.object({
|
|
788
|
+
message: import_zod3.z.object({
|
|
789
|
+
role: import_zod3.z.literal("assistant"),
|
|
790
|
+
content: import_zod3.z.string().nullable().optional(),
|
|
791
|
+
reasoning: import_zod3.z.string().nullable().optional(),
|
|
792
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
793
|
+
tool_calls: import_zod3.z.array(
|
|
794
|
+
import_zod3.z.object({
|
|
795
|
+
id: import_zod3.z.string().optional().nullable(),
|
|
796
|
+
type: import_zod3.z.literal("function"),
|
|
797
|
+
function: import_zod3.z.object({
|
|
798
|
+
name: import_zod3.z.string(),
|
|
799
|
+
arguments: import_zod3.z.string()
|
|
666
800
|
})
|
|
667
801
|
})
|
|
668
802
|
).optional()
|
|
669
803
|
}),
|
|
670
|
-
index:
|
|
671
|
-
logprobs:
|
|
672
|
-
content:
|
|
673
|
-
|
|
674
|
-
token:
|
|
675
|
-
logprob:
|
|
676
|
-
top_logprobs:
|
|
677
|
-
|
|
678
|
-
token:
|
|
679
|
-
logprob:
|
|
804
|
+
index: import_zod3.z.number(),
|
|
805
|
+
logprobs: import_zod3.z.object({
|
|
806
|
+
content: import_zod3.z.array(
|
|
807
|
+
import_zod3.z.object({
|
|
808
|
+
token: import_zod3.z.string(),
|
|
809
|
+
logprob: import_zod3.z.number(),
|
|
810
|
+
top_logprobs: import_zod3.z.array(
|
|
811
|
+
import_zod3.z.object({
|
|
812
|
+
token: import_zod3.z.string(),
|
|
813
|
+
logprob: import_zod3.z.number()
|
|
680
814
|
})
|
|
681
815
|
)
|
|
682
816
|
})
|
|
683
817
|
).nullable()
|
|
684
818
|
}).nullable().optional(),
|
|
685
|
-
finish_reason:
|
|
819
|
+
finish_reason: import_zod3.z.string().optional().nullable()
|
|
686
820
|
})
|
|
687
821
|
)
|
|
688
822
|
});
|
|
689
|
-
var OpenRouterStreamChatCompletionChunkSchema =
|
|
823
|
+
var OpenRouterStreamChatCompletionChunkSchema = import_zod3.z.union([
|
|
690
824
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
691
|
-
choices:
|
|
692
|
-
|
|
693
|
-
delta:
|
|
694
|
-
role:
|
|
695
|
-
content:
|
|
696
|
-
reasoning:
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
825
|
+
choices: import_zod3.z.array(
|
|
826
|
+
import_zod3.z.object({
|
|
827
|
+
delta: import_zod3.z.object({
|
|
828
|
+
role: import_zod3.z.enum(["assistant"]).optional(),
|
|
829
|
+
content: import_zod3.z.string().nullish(),
|
|
830
|
+
reasoning: import_zod3.z.string().nullish().optional(),
|
|
831
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
832
|
+
tool_calls: import_zod3.z.array(
|
|
833
|
+
import_zod3.z.object({
|
|
834
|
+
index: import_zod3.z.number(),
|
|
835
|
+
id: import_zod3.z.string().nullish(),
|
|
836
|
+
type: import_zod3.z.literal("function").optional(),
|
|
837
|
+
function: import_zod3.z.object({
|
|
838
|
+
name: import_zod3.z.string().nullish(),
|
|
839
|
+
arguments: import_zod3.z.string().nullish()
|
|
705
840
|
})
|
|
706
841
|
})
|
|
707
842
|
).nullish()
|
|
708
843
|
}).nullish(),
|
|
709
|
-
logprobs:
|
|
710
|
-
content:
|
|
711
|
-
|
|
712
|
-
token:
|
|
713
|
-
logprob:
|
|
714
|
-
top_logprobs:
|
|
715
|
-
|
|
716
|
-
token:
|
|
717
|
-
logprob:
|
|
844
|
+
logprobs: import_zod3.z.object({
|
|
845
|
+
content: import_zod3.z.array(
|
|
846
|
+
import_zod3.z.object({
|
|
847
|
+
token: import_zod3.z.string(),
|
|
848
|
+
logprob: import_zod3.z.number(),
|
|
849
|
+
top_logprobs: import_zod3.z.array(
|
|
850
|
+
import_zod3.z.object({
|
|
851
|
+
token: import_zod3.z.string(),
|
|
852
|
+
logprob: import_zod3.z.number()
|
|
718
853
|
})
|
|
719
854
|
)
|
|
720
855
|
})
|
|
721
856
|
).nullable()
|
|
722
857
|
}).nullish(),
|
|
723
|
-
finish_reason:
|
|
724
|
-
index:
|
|
858
|
+
finish_reason: import_zod3.z.string().nullable().optional(),
|
|
859
|
+
index: import_zod3.z.number()
|
|
725
860
|
})
|
|
726
861
|
)
|
|
727
862
|
}),
|
|
@@ -781,7 +916,7 @@ function prepareToolsAndToolChoice(mode) {
|
|
|
781
916
|
// src/openrouter-completion-language-model.ts
|
|
782
917
|
var import_provider3 = require("@ai-sdk/provider");
|
|
783
918
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
784
|
-
var
|
|
919
|
+
var import_zod4 = require("zod");
|
|
785
920
|
|
|
786
921
|
// src/convert-to-openrouter-completion-prompt.ts
|
|
787
922
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -860,6 +995,11 @@ ${userMessage}
|
|
|
860
995
|
functionality: "redacted reasoning messages"
|
|
861
996
|
});
|
|
862
997
|
}
|
|
998
|
+
case "file": {
|
|
999
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
1000
|
+
functionality: "file attachments"
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
863
1003
|
default: {
|
|
864
1004
|
const _exhaustiveCheck = part;
|
|
865
1005
|
throw new Error(
|
|
@@ -1106,7 +1246,9 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
1106
1246
|
choice == null ? void 0 : choice.logprobs
|
|
1107
1247
|
);
|
|
1108
1248
|
if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
|
|
1109
|
-
if (logprobs === void 0)
|
|
1249
|
+
if (logprobs === void 0) {
|
|
1250
|
+
logprobs = [];
|
|
1251
|
+
}
|
|
1110
1252
|
logprobs.push(...mappedLogprobs);
|
|
1111
1253
|
}
|
|
1112
1254
|
},
|
|
@@ -1126,26 +1268,27 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
1126
1268
|
};
|
|
1127
1269
|
}
|
|
1128
1270
|
};
|
|
1129
|
-
var OpenRouterCompletionChunkSchema =
|
|
1130
|
-
|
|
1131
|
-
id:
|
|
1132
|
-
model:
|
|
1133
|
-
choices:
|
|
1134
|
-
|
|
1135
|
-
text:
|
|
1136
|
-
reasoning:
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1271
|
+
var OpenRouterCompletionChunkSchema = import_zod4.z.union([
|
|
1272
|
+
import_zod4.z.object({
|
|
1273
|
+
id: import_zod4.z.string().optional(),
|
|
1274
|
+
model: import_zod4.z.string().optional(),
|
|
1275
|
+
choices: import_zod4.z.array(
|
|
1276
|
+
import_zod4.z.object({
|
|
1277
|
+
text: import_zod4.z.string(),
|
|
1278
|
+
reasoning: import_zod4.z.string().nullish().optional(),
|
|
1279
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1280
|
+
finish_reason: import_zod4.z.string().nullish(),
|
|
1281
|
+
index: import_zod4.z.number(),
|
|
1282
|
+
logprobs: import_zod4.z.object({
|
|
1283
|
+
tokens: import_zod4.z.array(import_zod4.z.string()),
|
|
1284
|
+
token_logprobs: import_zod4.z.array(import_zod4.z.number()),
|
|
1285
|
+
top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
|
|
1143
1286
|
}).nullable().optional()
|
|
1144
1287
|
})
|
|
1145
1288
|
),
|
|
1146
|
-
usage:
|
|
1147
|
-
prompt_tokens:
|
|
1148
|
-
completion_tokens:
|
|
1289
|
+
usage: import_zod4.z.object({
|
|
1290
|
+
prompt_tokens: import_zod4.z.number(),
|
|
1291
|
+
completion_tokens: import_zod4.z.number()
|
|
1149
1292
|
}).optional().nullable()
|
|
1150
1293
|
}),
|
|
1151
1294
|
OpenRouterErrorResponseSchema
|