@opencode/ai 2.1.2 → 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.
Files changed (87) hide show
  1. package/dist/cache-policy.js +6 -5
  2. package/dist/experimental/evaluation.d.ts +7 -6
  3. package/dist/experimental/evaluation.js +2 -3
  4. package/dist/experimental/realtime.d.ts +59 -0
  5. package/dist/experimental/realtime.js +21 -13
  6. package/dist/experimental.d.ts +1 -1
  7. package/dist/generation.js +1 -1
  8. package/dist/image-client.d.ts +3 -1
  9. package/dist/image.d.ts +10 -2
  10. package/dist/image.js +2 -2
  11. package/dist/llm.d.ts +2 -4
  12. package/dist/llm.js +2 -2
  13. package/dist/media-model.d.ts +2 -2
  14. package/dist/media-model.js +1 -1
  15. package/dist/promise.d.ts +1 -1
  16. package/dist/promise.js +3 -5
  17. package/dist/protocols/alibaba-chat.d.ts +6 -6
  18. package/dist/protocols/alibaba-chat.js +3 -3
  19. package/dist/protocols/alibaba-messages.d.ts +1 -1
  20. package/dist/protocols/alibaba-messages.js +1 -1
  21. package/dist/protocols/alibaba-responses.d.ts +3 -3
  22. package/dist/protocols/anthropic-messages.js +10 -12
  23. package/dist/protocols/bedrock-converse.d.ts +6 -53
  24. package/dist/protocols/bedrock-converse.js +4 -3
  25. package/dist/protocols/bedrock-event-stream.d.ts +6 -1
  26. package/dist/protocols/bedrock-event-stream.js +9 -8
  27. package/dist/protocols/cohere-chat.d.ts +6 -2
  28. package/dist/protocols/cohere-chat.js +2 -2
  29. package/dist/protocols/gemini.d.ts +12 -2
  30. package/dist/protocols/gemini.js +10 -13
  31. package/dist/protocols/google-interactions.d.ts +2 -1
  32. package/dist/protocols/google-interactions.js +14 -9
  33. package/dist/protocols/meta-responses.d.ts +6 -6
  34. package/dist/protocols/mistral-chat.js +1 -4
  35. package/dist/protocols/open-responses.d.ts +21 -21
  36. package/dist/protocols/open-responses.js +3 -3
  37. package/dist/protocols/openai-chat.d.ts +8 -7
  38. package/dist/protocols/openai-chat.js +4 -5
  39. package/dist/protocols/openai-compatible-responses.d.ts +3 -3
  40. package/dist/protocols/openai-responses.d.ts +18 -18
  41. package/dist/protocols/utils/open-responses-options.d.ts +8 -8
  42. package/dist/protocols/utils/open-responses-options.js +4 -6
  43. package/dist/protocols/utils/partial-json.js +5 -4
  44. package/dist/protocols/utils/tool-schema.d.ts +0 -3
  45. package/dist/protocols/utils/tool-schema.js +0 -4
  46. package/dist/protocols/xai-images.js +3 -4
  47. package/dist/protocols/xai-responses.d.ts +3 -3
  48. package/dist/provider-error.js +3 -4
  49. package/dist/providers/alibaba.d.ts +30 -30
  50. package/dist/providers/amazon-bedrock-mantle.d.ts +3 -3
  51. package/dist/providers/amazon-bedrock.d.ts +11 -8
  52. package/dist/providers/azure.d.ts +6 -6
  53. package/dist/providers/cloudflare-ai-gateway.d.ts +7 -7
  54. package/dist/providers/cloudflare-ai-gateway.js +2 -4
  55. package/dist/providers/cohere.d.ts +6 -2
  56. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  57. package/dist/providers/google-vertex-messages.d.ts +18 -18
  58. package/dist/providers/google-vertex-mistral.d.ts +3 -3
  59. package/dist/providers/google-vertex-responses.d.ts +3 -3
  60. package/dist/providers/google.d.ts +66 -66
  61. package/dist/providers/meta.d.ts +21 -21
  62. package/dist/providers/minimax.d.ts +195 -195
  63. package/dist/providers/moonshot.d.ts +3 -3
  64. package/dist/providers/openai-compatible-responses.d.ts +3 -3
  65. package/dist/providers/openai-options.d.ts +3 -3
  66. package/dist/providers/openai.d.ts +3 -3
  67. package/dist/providers/openrouter.d.ts +135 -76
  68. package/dist/providers/openrouter.js +40 -33
  69. package/dist/providers/zai-coding-plan.d.ts +3 -3
  70. package/dist/route/client.d.ts +0 -216
  71. package/dist/route/client.js +0 -3
  72. package/dist/route/transport/http.js +5 -8
  73. package/dist/schema/errors.d.ts +1 -1
  74. package/dist/schema/errors.js +1 -1
  75. package/dist/schema/messages.js +4 -7
  76. package/dist/speech-client.d.ts +3 -1
  77. package/dist/speech.d.ts +10 -2
  78. package/dist/speech.js +2 -2
  79. package/dist/transcription-client.d.ts +3 -1
  80. package/dist/transcription.d.ts +10 -2
  81. package/dist/transcription.js +2 -2
  82. package/dist/video-client.d.ts +3 -1
  83. package/dist/video.d.ts +10 -2
  84. package/dist/video.js +2 -2
  85. package/package.json +4 -4
  86. package/dist/protocols/utils/openai-options.d.ts +0 -16
  87. 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,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({
@@ -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("../protocols/utils/open-responses-options.js").ServiceTier | undefined;
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("../protocols/utils/open-responses-options.js").ResponseIncludable[] | undefined;
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("../protocols/utils/open-responses-options.js").TextVerbosity | undefined;
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;
@@ -214,222 +214,6 @@ export declare function stream(request: LLMRequest, options?: StreamOptions): St
214
214
  export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
215
215
  export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
216
216
  export declare function compact(request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, Service>;
217
- export declare const streamRequest: (request: LLMRequest, options?: StreamOptions) => Stream.Stream<{
218
- readonly type: "step-start";
219
- readonly index: number;
220
- } | {
221
- readonly type: "text-start";
222
- readonly id: string;
223
- readonly providerMetadata?: {
224
- readonly [x: string]: {
225
- readonly [x: string]: unknown;
226
- };
227
- } | undefined;
228
- } | {
229
- readonly type: "text-delta";
230
- readonly id: string;
231
- readonly text: string;
232
- readonly providerMetadata?: {
233
- readonly [x: string]: {
234
- readonly [x: string]: unknown;
235
- };
236
- } | undefined;
237
- } | {
238
- readonly type: "text-end";
239
- readonly id: string;
240
- readonly text?: string | undefined;
241
- readonly providerMetadata?: {
242
- readonly [x: string]: {
243
- readonly [x: string]: unknown;
244
- };
245
- } | undefined;
246
- } | {
247
- readonly type: "reasoning-start";
248
- readonly id: string;
249
- readonly providerMetadata?: {
250
- readonly [x: string]: {
251
- readonly [x: string]: unknown;
252
- };
253
- } | undefined;
254
- } | {
255
- readonly type: "reasoning-delta";
256
- readonly id: string;
257
- readonly text: string;
258
- readonly providerMetadata?: {
259
- readonly [x: string]: {
260
- readonly [x: string]: unknown;
261
- };
262
- } | undefined;
263
- } | {
264
- readonly type: "reasoning-end";
265
- readonly id: string;
266
- readonly text?: string | undefined;
267
- readonly providerMetadata?: {
268
- readonly [x: string]: {
269
- readonly [x: string]: unknown;
270
- };
271
- } | undefined;
272
- } | {
273
- readonly type: "tool-input-start";
274
- readonly id: string;
275
- readonly name: string;
276
- readonly namespace?: string | undefined;
277
- readonly providerExecuted?: boolean | undefined;
278
- readonly providerMetadata?: {
279
- readonly [x: string]: {
280
- readonly [x: string]: unknown;
281
- };
282
- } | undefined;
283
- } | {
284
- readonly type: "tool-input-delta";
285
- readonly id: string;
286
- readonly name: string;
287
- readonly namespace?: string | undefined;
288
- readonly text: string;
289
- readonly input?: unknown;
290
- } | {
291
- readonly type: "tool-input-end";
292
- readonly id: string;
293
- readonly name: string;
294
- readonly namespace?: string | undefined;
295
- readonly providerMetadata?: {
296
- readonly [x: string]: {
297
- readonly [x: string]: unknown;
298
- };
299
- } | undefined;
300
- } | {
301
- readonly type: "tool-input-error";
302
- readonly id: string;
303
- readonly name: string;
304
- readonly namespace?: string | undefined;
305
- readonly raw: string;
306
- } | {
307
- readonly type: "tool-call";
308
- readonly id: string;
309
- readonly name: string;
310
- readonly namespace?: string | undefined;
311
- readonly input: unknown;
312
- readonly providerExecuted?: boolean | undefined;
313
- readonly providerMetadata?: {
314
- readonly [x: string]: {
315
- readonly [x: string]: unknown;
316
- };
317
- } | undefined;
318
- } | {
319
- readonly type: "tool-result";
320
- readonly id: string;
321
- readonly name: string;
322
- readonly namespace?: string | undefined;
323
- readonly result: {
324
- readonly type: "json";
325
- readonly value: unknown;
326
- } | {
327
- readonly type: "text";
328
- readonly value: unknown;
329
- } | {
330
- readonly type: "error";
331
- readonly value: unknown;
332
- } | {
333
- readonly type: "content";
334
- readonly value: readonly ({
335
- readonly type: "text";
336
- readonly text: string;
337
- } | {
338
- readonly type: "file";
339
- readonly uri: string;
340
- readonly mime: string;
341
- readonly name?: string | undefined;
342
- })[];
343
- };
344
- readonly output?: {
345
- readonly structured: unknown;
346
- readonly content: readonly ({
347
- readonly type: "text";
348
- readonly text: string;
349
- } | {
350
- readonly type: "file";
351
- readonly uri: string;
352
- readonly mime: string;
353
- readonly name?: string | undefined;
354
- })[];
355
- } | undefined;
356
- readonly providerExecuted?: boolean | undefined;
357
- readonly providerMetadata?: {
358
- readonly [x: string]: {
359
- readonly [x: string]: unknown;
360
- };
361
- } | undefined;
362
- } | {
363
- readonly type: "tool-error";
364
- readonly id: string;
365
- readonly name: string;
366
- readonly namespace?: string | undefined;
367
- readonly message: string;
368
- readonly error?: unknown;
369
- readonly providerMetadata?: {
370
- readonly [x: string]: {
371
- readonly [x: string]: unknown;
372
- };
373
- } | undefined;
374
- } | {
375
- readonly type: "step-finish";
376
- readonly index: number;
377
- readonly reason: {
378
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
379
- readonly raw?: string | undefined;
380
- readonly category?: string | undefined;
381
- readonly explanation?: string | undefined;
382
- };
383
- readonly usage?: import("../schema/events.js").Usage | undefined;
384
- readonly providerMetadata?: {
385
- readonly [x: string]: {
386
- readonly [x: string]: unknown;
387
- };
388
- } | undefined;
389
- } | {
390
- readonly type: "finish";
391
- readonly reason: {
392
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
393
- readonly raw?: string | undefined;
394
- readonly category?: string | undefined;
395
- readonly explanation?: string | undefined;
396
- };
397
- readonly usage?: import("../schema/events.js").Usage | undefined;
398
- readonly providerMetadata?: {
399
- readonly [x: string]: {
400
- readonly [x: string]: unknown;
401
- };
402
- } | undefined;
403
- } | {
404
- readonly type: "media";
405
- readonly media: import("../media.js").Asset;
406
- readonly providerMetadata?: {
407
- readonly [x: string]: {
408
- readonly [x: string]: unknown;
409
- };
410
- } | undefined;
411
- } | {
412
- readonly type: "provider-error";
413
- readonly message: string;
414
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
415
- readonly providerMetadata?: {
416
- readonly [x: string]: {
417
- readonly [x: string]: unknown;
418
- };
419
- } | undefined;
420
- } | ({
421
- readonly type: "compaction";
422
- readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
423
- readonly id?: string | undefined;
424
- readonly encrypted?: string | undefined;
425
- readonly text?: string | null | undefined;
426
- } & ({
427
- readonly encrypted: string;
428
- readonly text?: never;
429
- } | {
430
- readonly text: string | null;
431
- readonly encrypted?: never;
432
- })), AIError, LLMClientService>;
433
217
  export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
434
218
  export declare const Route: {
435
219
  readonly make: typeof make;
@@ -271,9 +271,6 @@ export function compact(request, options) {
271
271
  return yield* unsupportedCompaction(request, options?.mechanism);
272
272
  });
273
273
  }
274
- export const streamRequest = (request, options) => Stream.unwrap(Effect.gen(function* () {
275
- return (yield* Service).stream(request, options);
276
- }));
277
274
  export const layer = Layer.effect(Service, Effect.gen(function* () {
278
275
  const executor = yield* RequestExecutor.Service;
279
276
  const stream = streamRequestWith({ http: executor });