@opencode/ai 0.0.0-dev-21421 → 0.0.0-dev-21430

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.
@@ -7,6 +7,7 @@ export type RealtimeTransportInput = {
7
7
  } | {
8
8
  readonly type: "websocket";
9
9
  };
10
+ export type RealtimeTransportType = RealtimeTransportInput["type"];
10
11
  export type RealtimeTransport = {
11
12
  readonly type: "webrtc";
12
13
  readonly sdp: string;
@@ -23,25 +24,83 @@ export interface RealtimeConnectInput {
23
24
  readonly session?: RealtimeSession;
24
25
  readonly transport: RealtimeTransportInput;
25
26
  }
27
+ export declare const engines: readonly [{
28
+ readonly family: "gpt-live";
29
+ readonly model: "gpt-live-1";
30
+ readonly id: "openai-live";
31
+ readonly provider: "openai";
32
+ readonly transports: readonly ["webrtc"];
33
+ }, {
34
+ readonly family: "gpt-realtime";
35
+ readonly model: "gpt-realtime-2.1";
36
+ readonly id: "openai-realtime";
37
+ readonly provider: "openai";
38
+ readonly transports: readonly ["webrtc", "websocket"];
39
+ }, {
40
+ readonly family: "grok-voice";
41
+ readonly model: "grok-voice-3.0";
42
+ readonly id: "xai-realtime";
43
+ readonly provider: "xai";
44
+ readonly transports: readonly ["websocket"];
45
+ }, {
46
+ readonly family: "gemini-3.8-live";
47
+ readonly model: "gemini-3.8-live";
48
+ readonly id: "gemini-live";
49
+ readonly provider: "google";
50
+ readonly transports: readonly ["websocket"];
51
+ }];
26
52
  export declare const engine: (model: string) => {
27
53
  readonly family: "gpt-live";
54
+ readonly model: "gpt-live-1";
28
55
  readonly id: "openai-live";
29
56
  readonly provider: "openai";
57
+ readonly transports: readonly ["webrtc"];
30
58
  } | {
31
59
  readonly family: "gpt-realtime";
60
+ readonly model: "gpt-realtime-2.1";
32
61
  readonly id: "openai-realtime";
33
62
  readonly provider: "openai";
63
+ readonly transports: readonly ["webrtc", "websocket"];
34
64
  } | {
35
65
  readonly family: "grok-voice";
66
+ readonly model: "grok-voice-3.0";
36
67
  readonly id: "xai-realtime";
37
68
  readonly provider: "xai";
69
+ readonly transports: readonly ["websocket"];
38
70
  } | {
39
71
  readonly family: "gemini-3.8-live";
72
+ readonly model: "gemini-3.8-live";
40
73
  readonly id: "gemini-live";
41
74
  readonly provider: "google";
75
+ readonly transports: readonly ["websocket"];
42
76
  } | undefined;
43
77
  export declare const connect: (input: RealtimeConnectInput) => Effect.Effect<RealtimeTransport, AIError, import("../route/executor-service.js").RequestExecutorService>;
44
78
  export declare const Realtime: {
79
+ readonly engines: readonly [{
80
+ readonly family: "gpt-live";
81
+ readonly model: "gpt-live-1";
82
+ readonly id: "openai-live";
83
+ readonly provider: "openai";
84
+ readonly transports: readonly ["webrtc"];
85
+ }, {
86
+ readonly family: "gpt-realtime";
87
+ readonly model: "gpt-realtime-2.1";
88
+ readonly id: "openai-realtime";
89
+ readonly provider: "openai";
90
+ readonly transports: readonly ["webrtc", "websocket"];
91
+ }, {
92
+ readonly family: "grok-voice";
93
+ readonly model: "grok-voice-3.0";
94
+ readonly id: "xai-realtime";
95
+ readonly provider: "xai";
96
+ readonly transports: readonly ["websocket"];
97
+ }, {
98
+ readonly family: "gemini-3.8-live";
99
+ readonly model: "gemini-3.8-live";
100
+ readonly id: "gemini-live";
101
+ readonly provider: "google";
102
+ readonly transports: readonly ["websocket"];
103
+ }];
45
104
  readonly engine: typeof engine;
46
105
  readonly connect: (input: RealtimeConnectInput) => Effect.Effect<RealtimeTransport, AIError, import("../route/executor-service.js").RequestExecutorService>;
47
106
  };
@@ -6,11 +6,23 @@ import { encodeJson } from "../utils/json.js";
6
6
  const OPENAI_BASE_URL = "https://api.openai.com/v1";
7
7
  const XAI_BASE_URL = "https://api.x.ai/v1";
8
8
  const GOOGLE_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
9
- const engines = [
10
- { family: "gpt-live", id: "openai-live", provider: "openai" },
11
- { family: "gpt-realtime", id: "openai-realtime", provider: "openai" },
12
- { family: "grok-voice", id: "xai-realtime", provider: "xai" },
13
- { family: "gemini-3.8-live", id: "gemini-live", provider: "google" },
9
+ export const engines = [
10
+ { family: "gpt-live", model: "gpt-live-1", id: "openai-live", provider: "openai", transports: ["webrtc"] },
11
+ {
12
+ family: "gpt-realtime",
13
+ model: "gpt-realtime-2.1",
14
+ id: "openai-realtime",
15
+ provider: "openai",
16
+ transports: ["webrtc", "websocket"],
17
+ },
18
+ { family: "grok-voice", model: "grok-voice-3.0", id: "xai-realtime", provider: "xai", transports: ["websocket"] },
19
+ {
20
+ family: "gemini-3.8-live",
21
+ model: "gemini-3.8-live",
22
+ id: "gemini-live",
23
+ provider: "google",
24
+ transports: ["websocket"],
25
+ },
14
26
  ];
15
27
  // Matches the bare family name (`gpt-realtime`) and its versions (`gpt-realtime-2.1`, `gpt-realtime-mini`).
16
28
  export const engine = (model) => engines.find((item) => model === item.family || model.startsWith(`${item.family}-`));
@@ -18,11 +30,11 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
18
30
  const resolved = engine(input.model);
19
31
  if (!resolved)
20
32
  return yield* invalidRequest(`Unsupported voice model: ${input.model}`);
33
+ if (!resolved.transports.some((type) => type === input.transport.type))
34
+ return yield* invalidRequest(`${input.model} only supports ${resolved.transports.join(", ")} transport`);
21
35
  const session = { ...input.session, model: input.model };
22
36
  switch (resolved.id) {
23
37
  case "openai-live": {
24
- if (input.transport.type !== "webrtc")
25
- return yield* invalidRequest("OpenAI GPT-Live only supports WebRTC transport");
26
38
  const data = yield* post(resolved.id, `${OPENAI_BASE_URL}/live/sessions`, input.apiKey, { session, transport: input.transport }, LiveSessionResponse);
27
39
  return { type: "webrtc", sdp: data.transport.sdp };
28
40
  }
@@ -39,16 +51,11 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
39
51
  const sdp = yield* post(resolved.id, `${OPENAI_BASE_URL}/realtime/calls${query}`, input.apiKey, form, Schema.String);
40
52
  return { type: "webrtc", sdp };
41
53
  }
42
- case "xai-realtime": {
43
- if (input.transport.type !== "websocket")
44
- return yield* invalidRequest("xAI Grok Voice only supports WebSocket transport");
54
+ case "xai-realtime":
45
55
  return yield* clientSecret(resolved.id, XAI_BASE_URL, input.model, input.apiKey, {
46
56
  expires_after: { seconds: 60 },
47
57
  });
48
- }
49
58
  case "gemini-live": {
50
- if (input.transport.type !== "websocket")
51
- return yield* invalidRequest("Google Gemini Live only supports WebSocket transport");
52
59
  const now = yield* Clock.currentTimeMillis;
53
60
  const expiresAt = now + 60_000;
54
61
  const data = yield* post(resolved.id, `${GOOGLE_BASE_URL}/auth_tokens`, input.apiKey, {
@@ -67,6 +74,7 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
67
74
  }
68
75
  });
69
76
  export const Realtime = {
77
+ engines,
70
78
  engine,
71
79
  connect,
72
80
  };
@@ -2,4 +2,4 @@ export { EvaluationClient } from "./experimental/evaluation-client.js";
2
2
  export { BooleanAnswer, BooleanQuestion, ChoiceAnswer, ChoiceQuestion, Evaluation, EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationModelSchema, EvaluationQuestion, EvaluationRequest, EvaluationResponse, EvaluationRounding, ScoreAnswer, ScoreQuestion, } from "./experimental/evaluation.js";
3
3
  export type { AnswerFor, AnswersFor, EvaluationModelOptions, EvaluationOptions, EvaluationQuestions, EvaluationRequestFor, EvaluationRequestInput, EvaluationResponseFor, EvaluationRoute, } from "./experimental/evaluation.js";
4
4
  export { Realtime } from "./experimental/realtime.js";
5
- export type { RealtimeConnectInput, RealtimeSession, RealtimeTransport, RealtimeTransportInput, } from "./experimental/realtime.js";
5
+ export type { RealtimeConnectInput, RealtimeSession, RealtimeTransport, RealtimeTransportInput, RealtimeTransportType, } from "./experimental/realtime.js";
@@ -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
- }>, readonly [Schema.$Record<Schema.String, Schema.Any>]>;
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
- readonly [x: string]: any;
212
- readonly model: string;
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
- readonly tools?: readonly {
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
- readonly tool_choice?: "auto" | "none" | "required" | {
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
- readonly stream: true;
317
- readonly stream_options?: {
323
+ stream: true;
324
+ stream_options?: {
318
325
  readonly include_usage: boolean;
319
326
  } | undefined;
320
- readonly store?: boolean | undefined;
321
- readonly prompt_cache_key?: string | undefined;
322
- readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
323
- readonly tool_stream?: boolean | undefined;
324
- readonly max_completion_tokens?: number | undefined;
325
- readonly max_tokens?: number | undefined;
326
- readonly temperature?: number | undefined;
327
- readonly top_p?: number | undefined;
328
- readonly frequency_penalty?: number | undefined;
329
- readonly presence_penalty?: number | undefined;
330
- readonly seed?: number | undefined;
331
- readonly stop?: readonly string[] | undefined;
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
- readonly [x: string]: any;
407
- readonly model: string;
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
- readonly tools?: readonly {
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
- readonly tool_choice?: "auto" | "none" | "required" | {
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
- readonly stream: true;
512
- readonly stream_options?: {
535
+ stream: true;
536
+ stream_options?: {
513
537
  readonly include_usage: boolean;
514
538
  } | undefined;
515
- readonly store?: boolean | undefined;
516
- readonly prompt_cache_key?: string | undefined;
517
- readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
518
- readonly tool_stream?: boolean | undefined;
519
- readonly max_completion_tokens?: number | undefined;
520
- readonly max_tokens?: number | undefined;
521
- readonly temperature?: number | undefined;
522
- readonly top_p?: number | undefined;
523
- readonly frequency_penalty?: number | undefined;
524
- readonly presence_penalty?: number | undefined;
525
- readonly seed?: number | undefined;
526
- readonly stop?: readonly string[] | undefined;
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
- readonly [x: string]: any;
530
- readonly model: string;
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
- readonly tools?: readonly {
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
- readonly tool_choice?: "auto" | "none" | "required" | {
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
- readonly stream: true;
635
- readonly stream_options?: {
675
+ stream: true;
676
+ stream_options?: {
636
677
  readonly include_usage: boolean;
637
678
  } | undefined;
638
- readonly store?: boolean | undefined;
639
- readonly prompt_cache_key?: string | undefined;
640
- readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
641
- readonly tool_stream?: boolean | undefined;
642
- readonly max_completion_tokens?: number | undefined;
643
- readonly max_tokens?: number | undefined;
644
- readonly temperature?: number | undefined;
645
- readonly top_p?: number | undefined;
646
- readonly frequency_penalty?: number | undefined;
647
- readonly presence_penalty?: number | undefined;
648
- readonly seed?: number | undefined;
649
- readonly stop?: readonly string[] | undefined;
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 OpenRouterBody = Schema.StructWithRest(Schema.Struct(OpenAIChat.bodyFields), [
15
- Schema.Record(Schema.String, Schema.Any),
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, { cacheControl: cacheControl() }).pipe(Effect.map((body) => {
22
- const sourceAssistants = request.messages.filter((message) => message.role === "assistant");
23
- let assistantIndex = 0;
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 source = sourceAssistants[assistantIndex++];
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
- return {
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 { usage, models, provider, plugins, web_search_options, debug, user, reasoning, promptCacheKey, ...options } = openrouter;
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
- ...(usage === undefined || usage === true
61
- ? { usage: { include: true } }
62
- : usage === false
63
- ? { usage: { include: false } }
64
- : isRecord(usage)
65
- ? { usage }
66
- : {}),
67
- ...(Array.isArray(models) ? { models } : {}),
68
- ...(isRecord(provider) ? { provider } : {}),
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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-21421",
3
+ "version": "0.0.0-dev-21430",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@clack/prompts": "1.0.0-alpha.1",
36
36
  "@effect/platform-node": "4.0.1",
37
- "@opencode/http-recorder": "0.0.0-dev-21421",
37
+ "@opencode/http-recorder": "0.0.0-dev-21430",
38
38
  "@tsconfig/bun": "1.0.9",
39
39
  "@types/bun": "1.4.0",
40
40
  "@typescript/native": "npm:typescript@7.0.2",
@@ -44,7 +44,7 @@
44
44
  "@aws-sdk/credential-providers": "3.1057.0",
45
45
  "@smithy/eventstream-codec": "4.2.14",
46
46
  "@smithy/util-utf8": "4.2.2",
47
- "@opencode/schema": "0.0.0-dev-21421",
47
+ "@opencode/schema": "0.0.0-dev-21430",
48
48
  "aws4fetch": "1.0.20",
49
49
  "effect": "4.0.1",
50
50
  "google-auth-library": "10.5.0"