@opencode/ai 2.1.1 → 2.1.3
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 +2 -3
- package/dist/experimental/realtime.d.ts +59 -0
- package/dist/experimental/realtime.js +32 -19
- package/dist/experimental/system-one.js +8 -8
- package/dist/experimental.d.ts +1 -1
- package/dist/generation.js +1 -1
- package/dist/image-client.d.ts +3 -1
- package/dist/image.d.ts +10 -2
- 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/media.js +3 -3
- package/dist/promise.d.ts +1 -1
- package/dist/promise.js +3 -5
- package/dist/protocols/alibaba-chat.d.ts +6 -6
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-messages.d.ts +1 -1
- package/dist/protocols/alibaba-messages.js +1 -1
- package/dist/protocols/alibaba-responses.d.ts +3 -3
- package/dist/protocols/anthropic-messages.js +10 -12
- package/dist/protocols/bedrock-converse.d.ts +6 -53
- package/dist/protocols/bedrock-converse.js +4 -3
- package/dist/protocols/bedrock-event-stream.d.ts +6 -1
- package/dist/protocols/bedrock-event-stream.js +9 -8
- package/dist/protocols/cohere-chat.d.ts +6 -2
- package/dist/protocols/cohere-chat.js +2 -2
- package/dist/protocols/gemini.d.ts +12 -2
- package/dist/protocols/gemini.js +10 -13
- package/dist/protocols/google-interactions.d.ts +2 -1
- package/dist/protocols/google-interactions.js +14 -9
- package/dist/protocols/meta-responses.d.ts +6 -6
- package/dist/protocols/mistral-chat.js +1 -4
- package/dist/protocols/open-responses.d.ts +21 -21
- package/dist/protocols/open-responses.js +3 -3
- package/dist/protocols/openai-chat.d.ts +8 -7
- package/dist/protocols/openai-chat.js +4 -5
- package/dist/protocols/openai-compatible-responses.d.ts +3 -3
- package/dist/protocols/openai-responses.d.ts +18 -18
- 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.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/venice-chat.js +6 -6
- package/dist/protocols/xai-images.js +3 -4
- package/dist/protocols/xai-responses.d.ts +3 -3
- package/dist/provider-error.js +4 -5
- package/dist/providers/alibaba.d.ts +30 -30
- package/dist/providers/amazon-bedrock-mantle.d.ts +3 -3
- package/dist/providers/amazon-bedrock.d.ts +11 -8
- package/dist/providers/azure.d.ts +6 -6
- package/dist/providers/cloudflare-ai-gateway.d.ts +7 -7
- package/dist/providers/cloudflare-ai-gateway.js +2 -4
- package/dist/providers/cohere.d.ts +6 -2
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +18 -18
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google.d.ts +66 -66
- package/dist/providers/meta.d.ts +21 -21
- package/dist/providers/minimax.d.ts +195 -195
- package/dist/providers/moonshot.d.ts +3 -3
- package/dist/providers/openai-compatible-responses.d.ts +3 -3
- package/dist/providers/openai-options.d.ts +3 -3
- package/dist/providers/openai.d.ts +3 -3
- package/dist/providers/openrouter.d.ts +135 -76
- package/dist/providers/openrouter.js +40 -33
- package/dist/providers/vercel-ai-gateway.js +7 -6
- package/dist/providers/zai-coding-plan.d.ts +3 -3
- package/dist/route/client.d.ts +0 -216
- package/dist/route/client.js +1 -5
- package/dist/route/executor-service.d.ts +6 -2
- package/dist/route/executor-service.js +7 -0
- package/dist/route/executor.d.ts +2 -3
- package/dist/route/executor.js +6 -11
- package/dist/route/media-protocol.d.ts +1 -1
- package/dist/route/media-protocol.js +3 -3
- package/dist/route/transport/http.js +5 -8
- package/dist/route/transport/websocket.d.ts +0 -24
- package/dist/route/transport/websocket.js +0 -50
- package/dist/schema/errors.d.ts +9 -8
- package/dist/schema/errors.js +9 -5
- package/dist/schema/messages.js +4 -7
- package/dist/speech-client.d.ts +3 -1
- package/dist/speech.d.ts +10 -2
- package/dist/speech.js +2 -2
- package/dist/transcription-client.d.ts +3 -1
- package/dist/transcription.d.ts +10 -2
- package/dist/transcription.js +2 -2
- package/dist/video-client.d.ts +3 -1
- package/dist/video.d.ts +10 -2
- package/dist/video.js +2 -2
- package/package.json +4 -4
- package/dist/protocols/utils/openai-options.d.ts +0 -16
- package/dist/protocols/utils/openai-options.js +0 -15
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ProviderOptions } from "../schema/index.js";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Options } from "../protocols/utils/open-responses-options.js";
|
|
2
|
+
import type { Options, ResponseIncludable, ServiceTier } from "../protocols/utils/open-responses-options.js";
|
|
4
3
|
import type { ContextManagement } from "../protocols/openai-responses.js";
|
|
5
|
-
export type
|
|
4
|
+
export type OpenAIResponseIncludable = ResponseIncludable;
|
|
5
|
+
export type OpenAIServiceTier = ServiceTier | "scale" | "fast" | "ultrafast";
|
|
6
6
|
export type OpenAIOptionsInput = Omit<Options, "serviceTier"> & {
|
|
7
7
|
/** Advanced in-band compaction. The caller owns checkpoint persistence and recovery. */
|
|
8
8
|
readonly contextManagement?: ContextManagement;
|
|
@@ -266,15 +266,15 @@ export declare const routes: (Route<{
|
|
|
266
266
|
} | undefined;
|
|
267
267
|
readonly top_logprobs?: number | undefined;
|
|
268
268
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
269
|
-
readonly service_tier?:
|
|
269
|
+
readonly service_tier?: OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
270
270
|
readonly prompt_cache_key?: string | undefined;
|
|
271
|
-
readonly include?: readonly
|
|
271
|
+
readonly include?: readonly OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
272
272
|
readonly reasoning?: {
|
|
273
273
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
274
274
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
275
275
|
} | undefined;
|
|
276
276
|
readonly text?: {
|
|
277
|
-
readonly verbosity?:
|
|
277
|
+
readonly verbosity?: OpenString<"high" | "low" | "medium"> | undefined;
|
|
278
278
|
} | undefined;
|
|
279
279
|
readonly max_output_tokens?: number | undefined;
|
|
280
280
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -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,34 +183,41 @@ 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
223
|
readonly type: "text";
|
|
@@ -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,9 +428,8 @@ 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
435
|
readonly type: "text";
|
|
@@ -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,33 +526,50 @@ 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
575
|
readonly type: "text";
|
|
@@ -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({
|
|
@@ -4,19 +4,20 @@ import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion,
|
|
|
4
4
|
import { AnthropicMessages } from "../protocols/anthropic-messages.js";
|
|
5
5
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
6
6
|
import { OpenResponses } from "../protocols/open-responses.js";
|
|
7
|
-
import { optionalNull, ProviderShared } from "../protocols/shared.js";
|
|
7
|
+
import { JsonObject, optionalNull, ProviderShared } from "../protocols/shared.js";
|
|
8
8
|
import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
|
|
9
9
|
import { Auth } from "../route/auth.js";
|
|
10
10
|
import { AuthOptions } from "../route/auth-options.js";
|
|
11
11
|
import { Route } from "../route/client.js";
|
|
12
12
|
import { Endpoint } from "../route/endpoint.js";
|
|
13
|
+
import { RequestExecutor } from "../route/executor.js";
|
|
13
14
|
import { Framing } from "../route/framing.js";
|
|
14
|
-
import { AIError,
|
|
15
|
+
import { AIError, HttpOptions, InvalidProviderOutputError, InvalidRequestError, LLMRequest, ModelID, ProviderID, ProviderMetadata, ProviderOptions, ReasoningEffort, Usage, } from "../schema/index.js";
|
|
15
16
|
export const id = ProviderID.make("vercel-ai-gateway");
|
|
16
17
|
const baseURL = "https://ai-gateway.vercel.sh/v1";
|
|
17
18
|
const GatewayOptionsSchema = Schema.Struct({
|
|
18
19
|
gateway: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
19
|
-
upstream: Schema.optional(
|
|
20
|
+
upstream: Schema.optional(ProviderMetadata),
|
|
20
21
|
reasoningEffort: Schema.optional(ReasoningEffort),
|
|
21
22
|
thinking: Schema.optional(Schema.Struct({
|
|
22
23
|
type: Schema.String,
|
|
@@ -110,8 +111,8 @@ const Request = Schema.StructWithRest(Schema.Struct({
|
|
|
110
111
|
model: Schema.String,
|
|
111
112
|
state: EvaluationInput,
|
|
112
113
|
questions: Schema.Record(Schema.String, EvaluationQuestion),
|
|
113
|
-
providerOptions: Schema.optional(
|
|
114
|
-
}), [
|
|
114
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
115
|
+
}), [JsonObject]);
|
|
115
116
|
const Response = Schema.Struct({
|
|
116
117
|
model: optionalNull(Schema.String),
|
|
117
118
|
answers: Schema.Record(Schema.String, EvaluationAnswer),
|
|
@@ -170,7 +171,7 @@ export const configure = (input = {}) => {
|
|
|
170
171
|
headers: Headers.fromInput({ ...input.headers, ...req.http?.headers }),
|
|
171
172
|
});
|
|
172
173
|
const res = yield* send(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(body, "application/json")));
|
|
173
|
-
const http =
|
|
174
|
+
const http = RequestExecutor.responseHttp(res);
|
|
174
175
|
const fail = (message, cause, body) => new AIError({
|
|
175
176
|
reason: new InvalidProviderOutputError({
|
|
176
177
|
route: "vercel-evaluation",
|
|
@@ -178,15 +178,15 @@ export declare const routes: (Route<{
|
|
|
178
178
|
} | undefined;
|
|
179
179
|
readonly top_logprobs?: number | undefined;
|
|
180
180
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
181
|
-
readonly service_tier?: import("../
|
|
181
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
182
182
|
readonly prompt_cache_key?: string | undefined;
|
|
183
|
-
readonly include?: readonly import("../
|
|
183
|
+
readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
184
184
|
readonly reasoning?: {
|
|
185
185
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
186
186
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
187
187
|
} | undefined;
|
|
188
188
|
readonly text?: {
|
|
189
|
-
readonly verbosity?: import("../
|
|
189
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
190
190
|
} | undefined;
|
|
191
191
|
readonly max_output_tokens?: number | undefined;
|
|
192
192
|
readonly max_tool_calls?: number | undefined;
|