@opencode/ai 2.1.2 → 2.1.4
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/cache-policy.js +6 -5
- package/dist/experimental/evaluation.d.ts +7 -6
- package/dist/experimental/evaluation.js +3 -11
- package/dist/experimental/realtime.d.ts +59 -0
- package/dist/experimental/realtime.js +21 -13
- package/dist/experimental.d.ts +1 -1
- package/dist/generation.js +1 -1
- package/dist/image-client.d.ts +11 -9
- package/dist/image.d.ts +158 -150
- package/dist/image.js +2 -2
- package/dist/llm.d.ts +2 -4
- package/dist/llm.js +2 -2
- package/dist/media-model.d.ts +2 -2
- package/dist/media-model.js +1 -1
- package/dist/promise.d.ts +121 -121
- package/dist/promise.js +3 -5
- package/dist/protocols/alibaba-chat.d.ts +18 -18
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-messages.d.ts +12 -12
- package/dist/protocols/alibaba-messages.js +1 -1
- package/dist/protocols/alibaba-responses.d.ts +38 -38
- package/dist/protocols/anthropic-messages.d.ts +40 -44
- package/dist/protocols/anthropic-messages.js +13 -15
- package/dist/protocols/bedrock-converse.d.ts +36 -85
- package/dist/protocols/bedrock-converse.js +6 -6
- package/dist/protocols/bedrock-event-stream.d.ts +6 -1
- package/dist/protocols/bedrock-event-stream.js +9 -8
- package/dist/protocols/cartesia-speech.d.ts +32 -32
- package/dist/protocols/cohere-chat.d.ts +13 -10
- package/dist/protocols/cohere-chat.js +2 -2
- package/dist/protocols/deepgram-speech.d.ts +32 -32
- package/dist/protocols/elevenlabs-speech.d.ts +32 -32
- package/dist/protocols/gemini.d.ts +46 -36
- package/dist/protocols/gemini.js +12 -15
- package/dist/protocols/google-interactions.d.ts +14 -13
- package/dist/protocols/google-interactions.js +16 -11
- package/dist/protocols/google-speech.d.ts +32 -32
- package/dist/protocols/google-transcription.d.ts +32 -32
- package/dist/protocols/meta-messages.d.ts +23 -23
- package/dist/protocols/meta-responses.d.ts +84 -84
- package/dist/protocols/mistral-chat.d.ts +81 -78
- package/dist/protocols/mistral-chat.js +3 -5
- package/dist/protocols/open-responses-channel.js +47 -46
- package/dist/protocols/open-responses-continuation.d.ts +8 -2
- package/dist/protocols/open-responses-continuation.js +3 -1
- package/dist/protocols/open-responses.d.ts +419 -419
- package/dist/protocols/open-responses.js +11 -10
- package/dist/protocols/openai-chat.d.ts +68 -67
- package/dist/protocols/openai-chat.js +7 -8
- package/dist/protocols/openai-compatible-chat.d.ts +13 -14
- package/dist/protocols/openai-compatible-responses.d.ts +39 -40
- package/dist/protocols/openai-images.d.ts +32 -32
- package/dist/protocols/openai-responses.d.ts +253 -253
- package/dist/protocols/openai-responses.js +1 -1
- package/dist/protocols/openai-speech.d.ts +32 -32
- package/dist/protocols/openai-transcription.d.ts +32 -32
- package/dist/protocols/openai-transcription.js +12 -7
- package/dist/protocols/utils/open-responses-options.d.ts +8 -8
- package/dist/protocols/utils/open-responses-options.js +4 -6
- package/dist/protocols/utils/partial-json-options.d.ts +0 -1
- package/dist/protocols/utils/partial-json-options.js +0 -1
- package/dist/protocols/utils/partial-json.js +5 -4
- package/dist/protocols/utils/tool-schema.d.ts +0 -3
- package/dist/protocols/utils/tool-schema.js +0 -4
- package/dist/protocols/utils/tool-stream.d.ts +1 -1
- package/dist/protocols/venice-chat.d.ts +52 -53
- package/dist/protocols/venice-chat.js +6 -5
- package/dist/protocols/xai-images.js +3 -4
- package/dist/protocols/xai-responses.d.ts +81 -81
- package/dist/protocols/zai-chat.d.ts +33 -30
- package/dist/protocols/zai-chat.js +8 -3
- package/dist/protocols/zai-messages.d.ts +21 -19
- package/dist/protocols/zai-messages.js +3 -2
- package/dist/provider-error.js +8 -7
- package/dist/providers/alibaba.d.ts +74 -74
- package/dist/providers/amazon-bedrock-mantle.d.ts +202 -202
- package/dist/providers/amazon-bedrock.d.ts +16 -13
- package/dist/providers/anthropic-compatible.d.ts +13 -13
- package/dist/providers/anthropic.d.ts +13 -13
- package/dist/providers/azure.d.ts +112 -112
- package/dist/providers/baseten.d.ts +24 -24
- package/dist/providers/cerebras.d.ts +24 -24
- package/dist/providers/cloudflare-ai-gateway.d.ts +237 -234
- package/dist/providers/cloudflare-ai-gateway.js +3 -6
- package/dist/providers/cloudflare-workers-ai.d.ts +24 -24
- package/dist/providers/cohere.d.ts +78 -74
- package/dist/providers/deepinfra.d.ts +24 -24
- package/dist/providers/deepseek.d.ts +24 -24
- package/dist/providers/digitalocean.d.ts +36 -36
- package/dist/providers/fireworks.d.ts +24 -24
- package/dist/providers/google-vertex-chat.d.ts +12 -12
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +20 -20
- package/dist/providers/google-vertex-mistral.d.ts +14 -14
- package/dist/providers/google-vertex-responses.d.ts +38 -38
- package/dist/providers/google-vertex.d.ts +17 -17
- package/dist/providers/google-vertex.js +2 -2
- package/dist/providers/google.d.ts +79 -79
- package/dist/providers/groq.d.ts +24 -24
- package/dist/providers/meta.d.ts +189 -189
- package/dist/providers/minimax.d.ts +202 -202
- package/dist/providers/mistral.d.ts +28 -28
- package/dist/providers/moonshot.d.ts +202 -202
- package/dist/providers/open-responses-options.d.ts +0 -1
- package/dist/providers/open-responses-options.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +38 -38
- package/dist/providers/openai-compatible.d.ts +12 -12
- package/dist/providers/openai-compatible.js +1 -1
- package/dist/providers/openai-options.d.ts +3 -4
- package/dist/providers/openai-options.js +0 -1
- package/dist/providers/openai.d.ts +103 -103
- package/dist/providers/openrouter.d.ts +171 -112
- package/dist/providers/openrouter.js +40 -33
- package/dist/providers/togetherai.d.ts +24 -24
- package/dist/providers/venice.d.ts +195 -20
- package/dist/providers/xai.d.ts +12 -12
- package/dist/providers/zai-coding-plan.d.ts +152 -72
- package/dist/providers/zai.d.ts +84 -19
- package/dist/route/auth-options.d.ts +0 -3
- package/dist/route/auth.d.ts +0 -2
- package/dist/route/auth.js +0 -2
- package/dist/route/client.d.ts +0 -218
- package/dist/route/client.js +3 -7
- package/dist/route/executor-service.js +1 -1
- package/dist/route/transport/http.js +5 -8
- package/dist/schema/errors.d.ts +1 -1
- package/dist/schema/errors.js +1 -1
- package/dist/schema/messages.js +4 -7
- package/dist/speech-client.d.ts +11 -9
- package/dist/speech.d.ts +158 -150
- package/dist/speech.js +2 -2
- package/dist/transcription-client.d.ts +11 -9
- package/dist/transcription.d.ts +158 -150
- package/dist/transcription.js +2 -2
- package/dist/video-client.d.ts +11 -9
- package/dist/video.d.ts +124 -116
- package/dist/video.js +2 -2
- package/package.json +7 -6
- package/dist/protocols/utils/openai-options.d.ts +0 -16
- package/dist/protocols/utils/openai-options.js +0 -15
|
@@ -88,8 +88,8 @@ export type Settings = ProviderPackage.Settings & OpenRouterProviderOptionsInput
|
|
|
88
88
|
readonly baseURL?: string;
|
|
89
89
|
};
|
|
90
90
|
declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
91
|
-
model: Schema.String;
|
|
92
|
-
messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
|
|
91
|
+
readonly model: Schema.String;
|
|
92
|
+
readonly messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
|
|
93
93
|
readonly role: Schema.Literal<"system">;
|
|
94
94
|
readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
95
95
|
readonly type: Schema.Literal<"text">;
|
|
@@ -170,7 +170,7 @@ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
|
170
170
|
}>>;
|
|
171
171
|
}>>]>;
|
|
172
172
|
}>]>>;
|
|
173
|
-
tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
173
|
+
readonly tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
174
174
|
readonly type: Schema.tag<"function">;
|
|
175
175
|
readonly function: Schema.Struct<{
|
|
176
176
|
readonly name: Schema.String;
|
|
@@ -183,43 +183,43 @@ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
|
183
183
|
readonly ttl: Schema.optional<Schema.String>;
|
|
184
184
|
}>>;
|
|
185
185
|
}>>>;
|
|
186
|
-
tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
186
|
+
readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
187
187
|
readonly type: Schema.tag<"function">;
|
|
188
188
|
readonly function: Schema.Struct<{
|
|
189
189
|
readonly name: Schema.String;
|
|
190
190
|
}>;
|
|
191
191
|
}>]>>;
|
|
192
|
-
stream: Schema.Literal<true>;
|
|
193
|
-
stream_options: Schema.optional<Schema.Struct<{
|
|
192
|
+
readonly stream: Schema.Literal<true>;
|
|
193
|
+
readonly stream_options: Schema.optional<Schema.Struct<{
|
|
194
194
|
readonly include_usage: Schema.Boolean;
|
|
195
195
|
}>>;
|
|
196
|
-
store: Schema.optional<Schema.Boolean>;
|
|
197
|
-
prompt_cache_key: Schema.optional<Schema.String>;
|
|
198
|
-
reasoning_effort: Schema.optional<Schema.declare<import("../schema/options.js").ReasoningEffort, import("../schema/options.js").ReasoningEffort>>;
|
|
199
|
-
tool_stream: Schema.optional<Schema.Boolean>;
|
|
200
|
-
max_completion_tokens: Schema.optional<Schema.Number>;
|
|
201
|
-
max_tokens: Schema.optional<Schema.Number>;
|
|
202
|
-
temperature: Schema.optional<Schema.Number>;
|
|
203
|
-
top_p: Schema.optional<Schema.Number>;
|
|
204
|
-
frequency_penalty: Schema.optional<Schema.Number>;
|
|
205
|
-
presence_penalty: Schema.optional<Schema.Number>;
|
|
206
|
-
seed: Schema.optional<Schema.Number>;
|
|
207
|
-
stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
208
|
-
|
|
196
|
+
readonly store: Schema.optional<Schema.Boolean>;
|
|
197
|
+
readonly prompt_cache_key: Schema.optional<Schema.String>;
|
|
198
|
+
readonly reasoning_effort: Schema.optional<Schema.declare<import("../schema/options.js").ReasoningEffort, import("../schema/options.js").ReasoningEffort>>;
|
|
199
|
+
readonly tool_stream: Schema.optional<Schema.Boolean>;
|
|
200
|
+
readonly max_completion_tokens: Schema.optional<Schema.Number>;
|
|
201
|
+
readonly max_tokens: Schema.optional<Schema.Number>;
|
|
202
|
+
readonly temperature: Schema.optional<Schema.Number>;
|
|
203
|
+
readonly top_p: Schema.optional<Schema.Number>;
|
|
204
|
+
readonly frequency_penalty: Schema.optional<Schema.Number>;
|
|
205
|
+
readonly presence_penalty: Schema.optional<Schema.Number>;
|
|
206
|
+
readonly seed: Schema.optional<Schema.Number>;
|
|
207
|
+
readonly stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
208
|
+
readonly models: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Array<Schema.String>>, never>>;
|
|
209
|
+
readonly provider: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
|
|
210
|
+
readonly plugins: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Array<Schema.$Record<Schema.String, Schema.Unknown>>>, never>>;
|
|
211
|
+
readonly web_search_options: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
|
|
212
|
+
readonly debug: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
|
|
213
|
+
readonly user: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.String>, never>>;
|
|
214
|
+
readonly reasoning: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
|
|
215
|
+
readonly usage: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
216
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
209
217
|
export type OpenRouterBody = Schema.Schema.Type<typeof OpenRouterBody>;
|
|
210
218
|
export declare const protocol: Protocol<{
|
|
211
|
-
|
|
212
|
-
readonly
|
|
213
|
-
readonly messages: readonly ({
|
|
219
|
+
model: string;
|
|
220
|
+
messages: readonly ({
|
|
214
221
|
readonly role: "system";
|
|
215
222
|
readonly content: string | readonly ({
|
|
216
|
-
readonly type: "text";
|
|
217
|
-
readonly text: string;
|
|
218
|
-
readonly cache_control?: {
|
|
219
|
-
readonly type: "ephemeral";
|
|
220
|
-
readonly ttl?: string | undefined;
|
|
221
|
-
} | undefined;
|
|
222
|
-
} | {
|
|
223
223
|
readonly type: "image_url";
|
|
224
224
|
readonly image_url: {
|
|
225
225
|
readonly url: string;
|
|
@@ -230,17 +230,17 @@ export declare const protocol: Protocol<{
|
|
|
230
230
|
readonly filename: string;
|
|
231
231
|
readonly file_data: string;
|
|
232
232
|
};
|
|
233
|
-
}
|
|
234
|
-
} | {
|
|
235
|
-
readonly role: "user";
|
|
236
|
-
readonly content: string | readonly ({
|
|
233
|
+
} | {
|
|
237
234
|
readonly type: "text";
|
|
238
235
|
readonly text: string;
|
|
239
236
|
readonly cache_control?: {
|
|
240
237
|
readonly type: "ephemeral";
|
|
241
238
|
readonly ttl?: string | undefined;
|
|
242
239
|
} | undefined;
|
|
243
|
-
}
|
|
240
|
+
})[];
|
|
241
|
+
} | {
|
|
242
|
+
readonly role: "user";
|
|
243
|
+
readonly content: string | readonly ({
|
|
244
244
|
readonly type: "image_url";
|
|
245
245
|
readonly image_url: {
|
|
246
246
|
readonly url: string;
|
|
@@ -251,6 +251,13 @@ export declare const protocol: Protocol<{
|
|
|
251
251
|
readonly filename: string;
|
|
252
252
|
readonly file_data: string;
|
|
253
253
|
};
|
|
254
|
+
} | {
|
|
255
|
+
readonly type: "text";
|
|
256
|
+
readonly text: string;
|
|
257
|
+
readonly cache_control?: {
|
|
258
|
+
readonly type: "ephemeral";
|
|
259
|
+
readonly ttl?: string | undefined;
|
|
260
|
+
} | undefined;
|
|
254
261
|
})[];
|
|
255
262
|
} | {
|
|
256
263
|
readonly role: "tool";
|
|
@@ -292,7 +299,7 @@ export declare const protocol: Protocol<{
|
|
|
292
299
|
readonly reasoning_text?: string | undefined;
|
|
293
300
|
readonly reasoning_details?: unknown;
|
|
294
301
|
})[];
|
|
295
|
-
|
|
302
|
+
tools?: readonly {
|
|
296
303
|
readonly type: "function";
|
|
297
304
|
readonly function: {
|
|
298
305
|
readonly name: string;
|
|
@@ -307,28 +314,46 @@ export declare const protocol: Protocol<{
|
|
|
307
314
|
readonly ttl?: string | undefined;
|
|
308
315
|
} | undefined;
|
|
309
316
|
}[] | undefined;
|
|
310
|
-
|
|
317
|
+
tool_choice?: "auto" | "none" | "required" | {
|
|
311
318
|
readonly type: "function";
|
|
312
319
|
readonly function: {
|
|
313
320
|
readonly name: string;
|
|
314
321
|
};
|
|
315
322
|
} | undefined;
|
|
316
|
-
|
|
317
|
-
|
|
323
|
+
stream: true;
|
|
324
|
+
stream_options?: {
|
|
318
325
|
readonly include_usage: boolean;
|
|
319
326
|
} | undefined;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
327
|
+
store?: boolean | undefined;
|
|
328
|
+
prompt_cache_key?: string | undefined;
|
|
329
|
+
reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
330
|
+
tool_stream?: boolean | undefined;
|
|
331
|
+
max_completion_tokens?: number | undefined;
|
|
332
|
+
max_tokens?: number | undefined;
|
|
333
|
+
temperature?: number | undefined;
|
|
334
|
+
top_p?: number | undefined;
|
|
335
|
+
frequency_penalty?: number | undefined;
|
|
336
|
+
presence_penalty?: number | undefined;
|
|
337
|
+
seed?: number | undefined;
|
|
338
|
+
stop?: readonly string[] | undefined;
|
|
339
|
+
usage?: {
|
|
340
|
+
readonly [x: string]: unknown;
|
|
341
|
+
} | undefined;
|
|
342
|
+
models?: readonly string[] | undefined;
|
|
343
|
+
provider?: {
|
|
344
|
+
readonly [x: string]: unknown;
|
|
345
|
+
} | undefined;
|
|
346
|
+
plugins?: readonly {
|
|
347
|
+
readonly [x: string]: unknown;
|
|
348
|
+
}[] | undefined;
|
|
349
|
+
web_search_options?: {
|
|
350
|
+
readonly [x: string]: unknown;
|
|
351
|
+
} | undefined;
|
|
352
|
+
debug?: {
|
|
353
|
+
readonly [x: string]: unknown;
|
|
354
|
+
} | undefined;
|
|
355
|
+
user?: string | undefined;
|
|
356
|
+
reasoning?: Record<string, unknown> | undefined;
|
|
332
357
|
}, string, "[DONE]" | {
|
|
333
358
|
readonly [x: string]: unknown;
|
|
334
359
|
readonly choices?: readonly {
|
|
@@ -403,18 +428,10 @@ export declare const protocol: Protocol<{
|
|
|
403
428
|
} | null | undefined;
|
|
404
429
|
}, OpenAIChat.ParserState>;
|
|
405
430
|
export declare const route: Route<{
|
|
406
|
-
|
|
407
|
-
readonly
|
|
408
|
-
readonly messages: readonly ({
|
|
431
|
+
model: string;
|
|
432
|
+
messages: readonly ({
|
|
409
433
|
readonly role: "system";
|
|
410
434
|
readonly content: string | readonly ({
|
|
411
|
-
readonly type: "text";
|
|
412
|
-
readonly text: string;
|
|
413
|
-
readonly cache_control?: {
|
|
414
|
-
readonly type: "ephemeral";
|
|
415
|
-
readonly ttl?: string | undefined;
|
|
416
|
-
} | undefined;
|
|
417
|
-
} | {
|
|
418
435
|
readonly type: "image_url";
|
|
419
436
|
readonly image_url: {
|
|
420
437
|
readonly url: string;
|
|
@@ -425,17 +442,17 @@ export declare const route: Route<{
|
|
|
425
442
|
readonly filename: string;
|
|
426
443
|
readonly file_data: string;
|
|
427
444
|
};
|
|
428
|
-
}
|
|
429
|
-
} | {
|
|
430
|
-
readonly role: "user";
|
|
431
|
-
readonly content: string | readonly ({
|
|
445
|
+
} | {
|
|
432
446
|
readonly type: "text";
|
|
433
447
|
readonly text: string;
|
|
434
448
|
readonly cache_control?: {
|
|
435
449
|
readonly type: "ephemeral";
|
|
436
450
|
readonly ttl?: string | undefined;
|
|
437
451
|
} | undefined;
|
|
438
|
-
}
|
|
452
|
+
})[];
|
|
453
|
+
} | {
|
|
454
|
+
readonly role: "user";
|
|
455
|
+
readonly content: string | readonly ({
|
|
439
456
|
readonly type: "image_url";
|
|
440
457
|
readonly image_url: {
|
|
441
458
|
readonly url: string;
|
|
@@ -446,6 +463,13 @@ export declare const route: Route<{
|
|
|
446
463
|
readonly filename: string;
|
|
447
464
|
readonly file_data: string;
|
|
448
465
|
};
|
|
466
|
+
} | {
|
|
467
|
+
readonly type: "text";
|
|
468
|
+
readonly text: string;
|
|
469
|
+
readonly cache_control?: {
|
|
470
|
+
readonly type: "ephemeral";
|
|
471
|
+
readonly ttl?: string | undefined;
|
|
472
|
+
} | undefined;
|
|
449
473
|
})[];
|
|
450
474
|
} | {
|
|
451
475
|
readonly role: "tool";
|
|
@@ -487,7 +511,7 @@ export declare const route: Route<{
|
|
|
487
511
|
readonly reasoning_text?: string | undefined;
|
|
488
512
|
readonly reasoning_details?: unknown;
|
|
489
513
|
})[];
|
|
490
|
-
|
|
514
|
+
tools?: readonly {
|
|
491
515
|
readonly type: "function";
|
|
492
516
|
readonly function: {
|
|
493
517
|
readonly name: string;
|
|
@@ -502,42 +526,52 @@ export declare const route: Route<{
|
|
|
502
526
|
readonly ttl?: string | undefined;
|
|
503
527
|
} | undefined;
|
|
504
528
|
}[] | undefined;
|
|
505
|
-
|
|
529
|
+
tool_choice?: "auto" | "none" | "required" | {
|
|
506
530
|
readonly type: "function";
|
|
507
531
|
readonly function: {
|
|
508
532
|
readonly name: string;
|
|
509
533
|
};
|
|
510
534
|
} | undefined;
|
|
511
|
-
|
|
512
|
-
|
|
535
|
+
stream: true;
|
|
536
|
+
stream_options?: {
|
|
513
537
|
readonly include_usage: boolean;
|
|
514
538
|
} | undefined;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
539
|
+
store?: boolean | undefined;
|
|
540
|
+
prompt_cache_key?: string | undefined;
|
|
541
|
+
reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
542
|
+
tool_stream?: boolean | undefined;
|
|
543
|
+
max_completion_tokens?: number | undefined;
|
|
544
|
+
max_tokens?: number | undefined;
|
|
545
|
+
temperature?: number | undefined;
|
|
546
|
+
top_p?: number | undefined;
|
|
547
|
+
frequency_penalty?: number | undefined;
|
|
548
|
+
presence_penalty?: number | undefined;
|
|
549
|
+
seed?: number | undefined;
|
|
550
|
+
stop?: readonly string[] | undefined;
|
|
551
|
+
usage?: {
|
|
552
|
+
readonly [x: string]: unknown;
|
|
553
|
+
} | undefined;
|
|
554
|
+
models?: readonly string[] | undefined;
|
|
555
|
+
provider?: {
|
|
556
|
+
readonly [x: string]: unknown;
|
|
557
|
+
} | undefined;
|
|
558
|
+
plugins?: readonly {
|
|
559
|
+
readonly [x: string]: unknown;
|
|
560
|
+
}[] | undefined;
|
|
561
|
+
web_search_options?: {
|
|
562
|
+
readonly [x: string]: unknown;
|
|
563
|
+
} | undefined;
|
|
564
|
+
debug?: {
|
|
565
|
+
readonly [x: string]: unknown;
|
|
566
|
+
} | undefined;
|
|
567
|
+
user?: string | undefined;
|
|
568
|
+
reasoning?: Record<string, unknown> | undefined;
|
|
527
569
|
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
528
570
|
export declare const routes: Route<{
|
|
529
|
-
|
|
530
|
-
readonly
|
|
531
|
-
readonly messages: readonly ({
|
|
571
|
+
model: string;
|
|
572
|
+
messages: readonly ({
|
|
532
573
|
readonly role: "system";
|
|
533
574
|
readonly content: string | readonly ({
|
|
534
|
-
readonly type: "text";
|
|
535
|
-
readonly text: string;
|
|
536
|
-
readonly cache_control?: {
|
|
537
|
-
readonly type: "ephemeral";
|
|
538
|
-
readonly ttl?: string | undefined;
|
|
539
|
-
} | undefined;
|
|
540
|
-
} | {
|
|
541
575
|
readonly type: "image_url";
|
|
542
576
|
readonly image_url: {
|
|
543
577
|
readonly url: string;
|
|
@@ -548,17 +582,17 @@ export declare const routes: Route<{
|
|
|
548
582
|
readonly filename: string;
|
|
549
583
|
readonly file_data: string;
|
|
550
584
|
};
|
|
551
|
-
}
|
|
552
|
-
} | {
|
|
553
|
-
readonly role: "user";
|
|
554
|
-
readonly content: string | readonly ({
|
|
585
|
+
} | {
|
|
555
586
|
readonly type: "text";
|
|
556
587
|
readonly text: string;
|
|
557
588
|
readonly cache_control?: {
|
|
558
589
|
readonly type: "ephemeral";
|
|
559
590
|
readonly ttl?: string | undefined;
|
|
560
591
|
} | undefined;
|
|
561
|
-
}
|
|
592
|
+
})[];
|
|
593
|
+
} | {
|
|
594
|
+
readonly role: "user";
|
|
595
|
+
readonly content: string | readonly ({
|
|
562
596
|
readonly type: "image_url";
|
|
563
597
|
readonly image_url: {
|
|
564
598
|
readonly url: string;
|
|
@@ -569,6 +603,13 @@ export declare const routes: Route<{
|
|
|
569
603
|
readonly filename: string;
|
|
570
604
|
readonly file_data: string;
|
|
571
605
|
};
|
|
606
|
+
} | {
|
|
607
|
+
readonly type: "text";
|
|
608
|
+
readonly text: string;
|
|
609
|
+
readonly cache_control?: {
|
|
610
|
+
readonly type: "ephemeral";
|
|
611
|
+
readonly ttl?: string | undefined;
|
|
612
|
+
} | undefined;
|
|
572
613
|
})[];
|
|
573
614
|
} | {
|
|
574
615
|
readonly role: "tool";
|
|
@@ -610,7 +651,7 @@ export declare const routes: Route<{
|
|
|
610
651
|
readonly reasoning_text?: string | undefined;
|
|
611
652
|
readonly reasoning_details?: unknown;
|
|
612
653
|
})[];
|
|
613
|
-
|
|
654
|
+
tools?: readonly {
|
|
614
655
|
readonly type: "function";
|
|
615
656
|
readonly function: {
|
|
616
657
|
readonly name: string;
|
|
@@ -625,28 +666,46 @@ export declare const routes: Route<{
|
|
|
625
666
|
readonly ttl?: string | undefined;
|
|
626
667
|
} | undefined;
|
|
627
668
|
}[] | undefined;
|
|
628
|
-
|
|
669
|
+
tool_choice?: "auto" | "none" | "required" | {
|
|
629
670
|
readonly type: "function";
|
|
630
671
|
readonly function: {
|
|
631
672
|
readonly name: string;
|
|
632
673
|
};
|
|
633
674
|
} | undefined;
|
|
634
|
-
|
|
635
|
-
|
|
675
|
+
stream: true;
|
|
676
|
+
stream_options?: {
|
|
636
677
|
readonly include_usage: boolean;
|
|
637
678
|
} | undefined;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
679
|
+
store?: boolean | undefined;
|
|
680
|
+
prompt_cache_key?: string | undefined;
|
|
681
|
+
reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
682
|
+
tool_stream?: boolean | undefined;
|
|
683
|
+
max_completion_tokens?: number | undefined;
|
|
684
|
+
max_tokens?: number | undefined;
|
|
685
|
+
temperature?: number | undefined;
|
|
686
|
+
top_p?: number | undefined;
|
|
687
|
+
frequency_penalty?: number | undefined;
|
|
688
|
+
presence_penalty?: number | undefined;
|
|
689
|
+
seed?: number | undefined;
|
|
690
|
+
stop?: readonly string[] | undefined;
|
|
691
|
+
usage?: {
|
|
692
|
+
readonly [x: string]: unknown;
|
|
693
|
+
} | undefined;
|
|
694
|
+
models?: readonly string[] | undefined;
|
|
695
|
+
provider?: {
|
|
696
|
+
readonly [x: string]: unknown;
|
|
697
|
+
} | undefined;
|
|
698
|
+
plugins?: readonly {
|
|
699
|
+
readonly [x: string]: unknown;
|
|
700
|
+
}[] | undefined;
|
|
701
|
+
web_search_options?: {
|
|
702
|
+
readonly [x: string]: unknown;
|
|
703
|
+
} | undefined;
|
|
704
|
+
debug?: {
|
|
705
|
+
readonly [x: string]: unknown;
|
|
706
|
+
} | undefined;
|
|
707
|
+
user?: string | undefined;
|
|
708
|
+
reasoning?: Record<string, unknown> | undefined;
|
|
650
709
|
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
651
710
|
export declare const configure: (input?: LanguageModelOptions) => {
|
|
652
711
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -7,25 +7,36 @@ import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
|
7
7
|
import { SystemOne } from "../experimental/system-one.js";
|
|
8
8
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
9
9
|
import { cacheControl } from "../protocols/utils/cache.js";
|
|
10
|
-
import { isRecord, ProviderShared } from "../protocols/shared.js";
|
|
10
|
+
import { isRecord, JsonObject, lenient, ProviderShared } from "../protocols/shared.js";
|
|
11
11
|
export const id = ProviderID.make("openrouter");
|
|
12
12
|
const baseURL = "https://openrouter.ai/api/v1";
|
|
13
13
|
const ADAPTER = "openrouter";
|
|
14
|
-
const
|
|
15
|
-
Schema.
|
|
16
|
-
|
|
14
|
+
const Options = Schema.Struct({
|
|
15
|
+
usage: lenient(Schema.Union([Schema.Boolean, JsonObject])),
|
|
16
|
+
models: lenient(Schema.Array(Schema.String)),
|
|
17
|
+
provider: lenient(JsonObject),
|
|
18
|
+
plugins: lenient(Schema.Array(JsonObject)),
|
|
19
|
+
web_search_options: lenient(JsonObject),
|
|
20
|
+
debug: lenient(JsonObject),
|
|
21
|
+
user: lenient(Schema.String),
|
|
22
|
+
reasoning: lenient(JsonObject),
|
|
23
|
+
});
|
|
24
|
+
const decodeOptions = Schema.decodeUnknownSync(Options);
|
|
25
|
+
const OpenRouterBody = Schema.StructWithRest(Schema.Struct({
|
|
26
|
+
...OpenAIChat.bodyFields,
|
|
27
|
+
...Options.fields,
|
|
28
|
+
usage: Schema.optional(JsonObject),
|
|
29
|
+
}), [JsonObject]);
|
|
17
30
|
export const protocol = Protocol.make({
|
|
18
31
|
id: "openrouter-chat",
|
|
19
32
|
body: {
|
|
20
33
|
schema: OpenRouterBody,
|
|
21
|
-
from: (request) => OpenAIChat.fromRequest(request, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const messages = body.messages.map((message) => {
|
|
34
|
+
from: (request) => OpenAIChat.fromRequest(request, {
|
|
35
|
+
cacheControl: cacheControl(),
|
|
36
|
+
assistant: (source, message) => {
|
|
25
37
|
if (message.role !== "assistant")
|
|
26
38
|
return message;
|
|
27
|
-
const
|
|
28
|
-
const reasoning = source?.content
|
|
39
|
+
const reasoning = source.content
|
|
29
40
|
.filter((part) => part.type === "reasoning")
|
|
30
41
|
.map((part) => part.text)
|
|
31
42
|
.join("");
|
|
@@ -37,13 +48,8 @@ export const protocol = Protocol.make({
|
|
|
37
48
|
reasoning: reasoning && reasoningDetails && reasoningDetails.length > 0 ? reasoning : undefined,
|
|
38
49
|
reasoning_details: reasoningDetails,
|
|
39
50
|
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
...body,
|
|
43
|
-
messages,
|
|
44
|
-
...bodyOptions(request.providerOptions, request.generation?.maxTokens),
|
|
45
|
-
};
|
|
46
|
-
})),
|
|
51
|
+
},
|
|
52
|
+
}).pipe(Effect.map((body) => bodyOptions(body, request.providerOptions, request.generation?.maxTokens))),
|
|
47
53
|
},
|
|
48
54
|
stream: OpenAIChat.protocol.stream,
|
|
49
55
|
});
|
|
@@ -52,25 +58,26 @@ export const protocol = Protocol.make({
|
|
|
52
58
|
const fitReasoning = (reasoning, maxTokens) => typeof reasoning.max_tokens === "number"
|
|
53
59
|
? { ...reasoning, max_tokens: ProviderShared.fitThinkingBudget(reasoning.max_tokens, maxTokens, 1_024) }
|
|
54
60
|
: reasoning;
|
|
55
|
-
const bodyOptions = (input, maxTokens) => {
|
|
61
|
+
const bodyOptions = (body, input, maxTokens) => {
|
|
56
62
|
const openrouter = isRecord(input) ? input : {};
|
|
57
|
-
const
|
|
63
|
+
const options = Object.fromEntries(Object.entries(openrouter).filter(([key]) => !(key in Options.fields) && key !== "promptCacheKey"));
|
|
64
|
+
const known = decodeOptions(openrouter);
|
|
65
|
+
const usage = openrouter.usage === undefined || known.usage === true
|
|
66
|
+
? { include: true }
|
|
67
|
+
: known.usage === false
|
|
68
|
+
? { include: false }
|
|
69
|
+
: known.usage;
|
|
58
70
|
return {
|
|
59
71
|
...options,
|
|
60
|
-
...
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
...(
|
|
68
|
-
...(
|
|
69
|
-
...(Array.isArray(plugins) ? { plugins } : {}),
|
|
70
|
-
...(isRecord(web_search_options) ? { web_search_options } : {}),
|
|
71
|
-
...(isRecord(debug) ? { debug } : {}),
|
|
72
|
-
...(typeof user === "string" ? { user } : {}),
|
|
73
|
-
...(isRecord(reasoning) ? { reasoning: fitReasoning(reasoning, maxTokens) } : {}),
|
|
72
|
+
...body,
|
|
73
|
+
...(usage !== undefined ? { usage } : {}),
|
|
74
|
+
...(known.models !== undefined ? { models: known.models } : {}),
|
|
75
|
+
...(known.provider !== undefined ? { provider: known.provider } : {}),
|
|
76
|
+
...(known.plugins !== undefined ? { plugins: known.plugins } : {}),
|
|
77
|
+
...(known.web_search_options !== undefined ? { web_search_options: known.web_search_options } : {}),
|
|
78
|
+
...(known.debug !== undefined ? { debug: known.debug } : {}),
|
|
79
|
+
...(known.user !== undefined ? { user: known.user } : {}),
|
|
80
|
+
...(known.reasoning !== undefined ? { reasoning: fitReasoning(known.reasoning, maxTokens) } : {}),
|
|
74
81
|
};
|
|
75
82
|
};
|
|
76
83
|
export const route = Route.make({
|
|
@@ -17,13 +17,6 @@ export declare const route: Route<{
|
|
|
17
17
|
readonly messages: readonly ({
|
|
18
18
|
readonly role: "system";
|
|
19
19
|
readonly content: string | readonly ({
|
|
20
|
-
readonly type: "text";
|
|
21
|
-
readonly text: string;
|
|
22
|
-
readonly cache_control?: {
|
|
23
|
-
readonly type: "ephemeral";
|
|
24
|
-
readonly ttl?: string | undefined;
|
|
25
|
-
} | undefined;
|
|
26
|
-
} | {
|
|
27
20
|
readonly type: "image_url";
|
|
28
21
|
readonly image_url: {
|
|
29
22
|
readonly url: string;
|
|
@@ -34,17 +27,17 @@ export declare const route: Route<{
|
|
|
34
27
|
readonly filename: string;
|
|
35
28
|
readonly file_data: string;
|
|
36
29
|
};
|
|
37
|
-
}
|
|
38
|
-
} | {
|
|
39
|
-
readonly role: "user";
|
|
40
|
-
readonly content: string | readonly ({
|
|
30
|
+
} | {
|
|
41
31
|
readonly type: "text";
|
|
42
32
|
readonly text: string;
|
|
43
33
|
readonly cache_control?: {
|
|
44
34
|
readonly type: "ephemeral";
|
|
45
35
|
readonly ttl?: string | undefined;
|
|
46
36
|
} | undefined;
|
|
47
|
-
}
|
|
37
|
+
})[];
|
|
38
|
+
} | {
|
|
39
|
+
readonly role: "user";
|
|
40
|
+
readonly content: string | readonly ({
|
|
48
41
|
readonly type: "image_url";
|
|
49
42
|
readonly image_url: {
|
|
50
43
|
readonly url: string;
|
|
@@ -55,6 +48,13 @@ export declare const route: Route<{
|
|
|
55
48
|
readonly filename: string;
|
|
56
49
|
readonly file_data: string;
|
|
57
50
|
};
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "text";
|
|
53
|
+
readonly text: string;
|
|
54
|
+
readonly cache_control?: {
|
|
55
|
+
readonly type: "ephemeral";
|
|
56
|
+
readonly ttl?: string | undefined;
|
|
57
|
+
} | undefined;
|
|
58
58
|
})[];
|
|
59
59
|
} | {
|
|
60
60
|
readonly role: "tool";
|
|
@@ -139,13 +139,6 @@ export declare const routes: Route<{
|
|
|
139
139
|
readonly messages: readonly ({
|
|
140
140
|
readonly role: "system";
|
|
141
141
|
readonly content: string | readonly ({
|
|
142
|
-
readonly type: "text";
|
|
143
|
-
readonly text: string;
|
|
144
|
-
readonly cache_control?: {
|
|
145
|
-
readonly type: "ephemeral";
|
|
146
|
-
readonly ttl?: string | undefined;
|
|
147
|
-
} | undefined;
|
|
148
|
-
} | {
|
|
149
142
|
readonly type: "image_url";
|
|
150
143
|
readonly image_url: {
|
|
151
144
|
readonly url: string;
|
|
@@ -156,17 +149,17 @@ export declare const routes: Route<{
|
|
|
156
149
|
readonly filename: string;
|
|
157
150
|
readonly file_data: string;
|
|
158
151
|
};
|
|
159
|
-
}
|
|
160
|
-
} | {
|
|
161
|
-
readonly role: "user";
|
|
162
|
-
readonly content: string | readonly ({
|
|
152
|
+
} | {
|
|
163
153
|
readonly type: "text";
|
|
164
154
|
readonly text: string;
|
|
165
155
|
readonly cache_control?: {
|
|
166
156
|
readonly type: "ephemeral";
|
|
167
157
|
readonly ttl?: string | undefined;
|
|
168
158
|
} | undefined;
|
|
169
|
-
}
|
|
159
|
+
})[];
|
|
160
|
+
} | {
|
|
161
|
+
readonly role: "user";
|
|
162
|
+
readonly content: string | readonly ({
|
|
170
163
|
readonly type: "image_url";
|
|
171
164
|
readonly image_url: {
|
|
172
165
|
readonly url: string;
|
|
@@ -177,6 +170,13 @@ export declare const routes: Route<{
|
|
|
177
170
|
readonly filename: string;
|
|
178
171
|
readonly file_data: string;
|
|
179
172
|
};
|
|
173
|
+
} | {
|
|
174
|
+
readonly type: "text";
|
|
175
|
+
readonly text: string;
|
|
176
|
+
readonly cache_control?: {
|
|
177
|
+
readonly type: "ephemeral";
|
|
178
|
+
readonly ttl?: string | undefined;
|
|
179
|
+
} | undefined;
|
|
180
180
|
})[];
|
|
181
181
|
} | {
|
|
182
182
|
readonly role: "tool";
|