@opencode/ai 2.2.2 → 2.2.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 (51) hide show
  1. package/README.md +92 -76
  2. package/dist/decision.d.ts +0 -1
  3. package/dist/effect.d.ts +2 -14
  4. package/dist/effect.js +1 -10
  5. package/dist/experimental/testing.d.ts +3 -0
  6. package/dist/experimental/testing.js +3 -0
  7. package/dist/experimental.d.ts +12 -0
  8. package/dist/experimental.js +9 -0
  9. package/dist/index.d.ts +340 -336
  10. package/dist/index.js +43 -41
  11. package/dist/llm.d.ts +2 -2
  12. package/dist/llm.js +19 -29
  13. package/dist/protocols/alibaba-responses.d.ts +2 -2
  14. package/dist/protocols/assemblyai-transcription.js +3 -3
  15. package/dist/protocols/meta-responses.d.ts +4 -4
  16. package/dist/protocols/open-responses.d.ts +18 -18
  17. package/dist/protocols/open-responses.js +4 -2
  18. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  19. package/dist/protocols/openai-responses.d.ts +12 -12
  20. package/dist/protocols/runway-video.js +2 -2
  21. package/dist/protocols/xai-responses.d.ts +2 -2
  22. package/dist/protocols/xai-video.js +2 -2
  23. package/dist/providers/alibaba.d.ts +2 -2
  24. package/dist/providers/amazon-bedrock-mantle.d.ts +2 -2
  25. package/dist/providers/azure.d.ts +4 -4
  26. package/dist/providers/cloudflare-ai-gateway.d.ts +4 -4
  27. package/dist/providers/digitalocean.d.ts +2 -2
  28. package/dist/providers/google-vertex-responses.d.ts +2 -2
  29. package/dist/providers/meta.d.ts +2 -2
  30. package/dist/providers/minimax.d.ts +2 -2
  31. package/dist/providers/moonshot.d.ts +2 -2
  32. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  33. package/dist/providers/openai.d.ts +2 -2
  34. package/dist/providers/openrouter/responses.d.ts +1 -2
  35. package/dist/providers/openrouter.d.ts +36 -23
  36. package/dist/providers/openrouter.js +29 -10
  37. package/dist/providers/venice.d.ts +2 -2
  38. package/dist/providers/zai-coding-plan.d.ts +2 -2
  39. package/dist/route/client.d.ts +3 -0
  40. package/dist/route/client.js +5 -4
  41. package/dist/route/media-protocol.d.ts +2 -3
  42. package/dist/route/media-protocol.js +2 -6
  43. package/dist/schema/errors.d.ts +6 -0
  44. package/dist/schema/errors.js +8 -0
  45. package/dist/schema/events.d.ts +2 -0
  46. package/dist/schema/events.js +4 -0
  47. package/dist/testing.d.ts +1 -4
  48. package/dist/testing.js +4 -12
  49. package/dist/tool.d.ts +40 -73
  50. package/dist/tool.js +27 -18
  51. package/package.json +7 -3
@@ -82,13 +82,13 @@ const fraction = (progress) => progress !== undefined && progress !== null && pr
82
82
  const decodeVideoStatus = route.decodeJson(VideoStatus);
83
83
  const decodeStatus = Effect.fn("XAIVideo.decodeStatus")(function* (response, context) {
84
84
  const output = yield* decodeVideoStatus(response);
85
- const status = yield* MediaProtocol.status(STATUS, output.value.status, output);
85
+ const status = MediaProtocol.status(STATUS, output.value.status);
86
86
  return { id: context.token.requestID, status, progress: fraction(output.value.progress) };
87
87
  });
88
88
  const decodeResult = Effect.fn("XAIVideo.decodeResult")(function* (response, context) {
89
89
  const output = yield* decodeVideoStatus(response);
90
90
  const decoded = output.value;
91
- const status = yield* MediaProtocol.status(STATUS, decoded.status, output);
91
+ const status = MediaProtocol.status(STATUS, decoded.status);
92
92
  if (status === "running")
93
93
  return yield* output.pending(context.token.requestID);
94
94
  if (status === "failed") {
@@ -543,7 +543,7 @@ export declare const routes: (Route<{
543
543
  readonly detail?: string | undefined;
544
544
  } | {
545
545
  readonly type: "input_file";
546
- readonly filename: string;
546
+ readonly filename?: string | undefined;
547
547
  readonly detail?: string | undefined;
548
548
  readonly file_data?: string | undefined;
549
549
  readonly file_url?: string | undefined;
@@ -575,7 +575,7 @@ export declare const routes: (Route<{
575
575
  readonly detail?: string | undefined;
576
576
  } | {
577
577
  readonly type: "input_file";
578
- readonly filename: string;
578
+ readonly filename?: string | undefined;
579
579
  readonly detail?: string | undefined;
580
580
  readonly file_data?: string | undefined;
581
581
  readonly file_url?: string | undefined;
@@ -374,7 +374,7 @@ export declare const routes: (Route<{
374
374
  readonly detail?: string | undefined;
375
375
  } | {
376
376
  readonly type: "input_file";
377
- readonly filename: string;
377
+ readonly filename?: string | undefined;
378
378
  readonly detail?: string | undefined;
379
379
  readonly file_data?: string | undefined;
380
380
  readonly file_url?: string | undefined;
@@ -406,7 +406,7 @@ export declare const routes: (Route<{
406
406
  readonly detail?: string | undefined;
407
407
  } | {
408
408
  readonly type: "input_file";
409
- readonly filename: string;
409
+ readonly filename?: string | undefined;
410
410
  readonly detail?: string | undefined;
411
411
  readonly file_data?: string | undefined;
412
412
  readonly file_url?: string | undefined;
@@ -50,7 +50,7 @@ declare const responsesRoute: Route<{
50
50
  readonly detail?: string | undefined;
51
51
  } | {
52
52
  readonly type: "input_file";
53
- readonly filename: string;
53
+ readonly filename?: string | undefined;
54
54
  readonly detail?: string | undefined;
55
55
  readonly file_data?: string | undefined;
56
56
  readonly file_url?: string | undefined;
@@ -82,7 +82,7 @@ declare const responsesRoute: Route<{
82
82
  readonly detail?: string | undefined;
83
83
  } | {
84
84
  readonly type: "input_file";
85
- readonly filename: string;
85
+ readonly filename?: string | undefined;
86
86
  readonly detail?: string | undefined;
87
87
  readonly file_data?: string | undefined;
88
88
  readonly file_url?: string | undefined;
@@ -455,7 +455,7 @@ export declare const routes: (Route<{
455
455
  readonly detail?: string | undefined;
456
456
  } | {
457
457
  readonly type: "input_file";
458
- readonly filename: string;
458
+ readonly filename?: string | undefined;
459
459
  readonly detail?: string | undefined;
460
460
  readonly file_data?: string | undefined;
461
461
  readonly file_url?: string | undefined;
@@ -487,7 +487,7 @@ export declare const routes: (Route<{
487
487
  readonly detail?: string | undefined;
488
488
  } | {
489
489
  readonly type: "input_file";
490
- readonly filename: string;
490
+ readonly filename?: string | undefined;
491
491
  readonly detail?: string | undefined;
492
492
  readonly file_data?: string | undefined;
493
493
  readonly file_url?: string | undefined;
@@ -59,7 +59,7 @@ export declare const responsesRoute: import("../route/client.js").Route<{
59
59
  readonly detail?: string | undefined;
60
60
  } | {
61
61
  readonly type: "input_file";
62
- readonly filename: string;
62
+ readonly filename?: string | undefined;
63
63
  readonly detail?: string | undefined;
64
64
  readonly file_data?: string | undefined;
65
65
  readonly file_url?: string | undefined;
@@ -91,7 +91,7 @@ export declare const responsesRoute: import("../route/client.js").Route<{
91
91
  readonly detail?: string | undefined;
92
92
  } | {
93
93
  readonly type: "input_file";
94
- readonly filename: string;
94
+ readonly filename?: string | undefined;
95
95
  readonly detail?: string | undefined;
96
96
  readonly file_data?: string | undefined;
97
97
  readonly file_url?: string | undefined;
@@ -1254,7 +1254,7 @@ export declare const routes: (import("../route/client.js").Route<{
1254
1254
  readonly detail?: string | undefined;
1255
1255
  } | {
1256
1256
  readonly type: "input_file";
1257
- readonly filename: string;
1257
+ readonly filename?: string | undefined;
1258
1258
  readonly detail?: string | undefined;
1259
1259
  readonly file_data?: string | undefined;
1260
1260
  readonly file_url?: string | undefined;
@@ -1286,7 +1286,7 @@ export declare const routes: (import("../route/client.js").Route<{
1286
1286
  readonly detail?: string | undefined;
1287
1287
  } | {
1288
1288
  readonly type: "input_file";
1289
- readonly filename: string;
1289
+ readonly filename?: string | undefined;
1290
1290
  readonly detail?: string | undefined;
1291
1291
  readonly file_data?: string | undefined;
1292
1292
  readonly file_url?: string | undefined;
@@ -468,7 +468,7 @@ export declare const routes: (Route<{
468
468
  readonly detail?: string | undefined;
469
469
  } | {
470
470
  readonly type: "input_file";
471
- readonly filename: string;
471
+ readonly filename?: string | undefined;
472
472
  readonly detail?: string | undefined;
473
473
  readonly file_data?: string | undefined;
474
474
  readonly file_url?: string | undefined;
@@ -500,7 +500,7 @@ export declare const routes: (Route<{
500
500
  readonly detail?: string | undefined;
501
501
  } | {
502
502
  readonly type: "input_file";
503
- readonly filename: string;
503
+ readonly filename?: string | undefined;
504
504
  readonly detail?: string | undefined;
505
505
  readonly file_data?: string | undefined;
506
506
  readonly file_url?: string | undefined;
@@ -47,7 +47,7 @@ export declare const routes: Route<{
47
47
  readonly detail?: string | undefined;
48
48
  } | {
49
49
  readonly type: "input_file";
50
- readonly filename: string;
50
+ readonly filename?: string | undefined;
51
51
  readonly detail?: string | undefined;
52
52
  readonly file_data?: string | undefined;
53
53
  readonly file_url?: string | undefined;
@@ -79,7 +79,7 @@ export declare const routes: Route<{
79
79
  readonly detail?: string | undefined;
80
80
  } | {
81
81
  readonly type: "input_file";
82
- readonly filename: string;
82
+ readonly filename?: string | undefined;
83
83
  readonly detail?: string | undefined;
84
84
  readonly file_data?: string | undefined;
85
85
  readonly file_url?: string | undefined;
@@ -68,7 +68,7 @@ export declare const routes: (Route<{
68
68
  readonly detail?: string | undefined;
69
69
  } | {
70
70
  readonly type: "input_file";
71
- readonly filename: string;
71
+ readonly filename?: string | undefined;
72
72
  readonly detail?: string | undefined;
73
73
  readonly file_data?: string | undefined;
74
74
  readonly file_url?: string | undefined;
@@ -100,7 +100,7 @@ export declare const routes: (Route<{
100
100
  readonly detail?: string | undefined;
101
101
  } | {
102
102
  readonly type: "input_file";
103
- readonly filename: string;
103
+ readonly filename?: string | undefined;
104
104
  readonly detail?: string | undefined;
105
105
  readonly file_data?: string | undefined;
106
106
  readonly file_url?: string | undefined;
@@ -372,7 +372,7 @@ export declare const routes: (Route<{
372
372
  readonly detail?: string | undefined;
373
373
  } | {
374
374
  readonly type: "input_file";
375
- readonly filename: string;
375
+ readonly filename?: string | undefined;
376
376
  readonly detail?: string | undefined;
377
377
  readonly file_data?: string | undefined;
378
378
  readonly file_url?: string | undefined;
@@ -404,7 +404,7 @@ export declare const routes: (Route<{
404
404
  readonly detail?: string | undefined;
405
405
  } | {
406
406
  readonly type: "input_file";
407
- readonly filename: string;
407
+ readonly filename?: string | undefined;
408
408
  readonly detail?: string | undefined;
409
409
  readonly file_data?: string | undefined;
410
410
  readonly file_url?: string | undefined;
@@ -368,7 +368,7 @@ export declare const routes: (Route<{
368
368
  readonly detail?: string | undefined;
369
369
  } | {
370
370
  readonly type: "input_file";
371
- readonly filename: string;
371
+ readonly filename?: string | undefined;
372
372
  readonly detail?: string | undefined;
373
373
  readonly file_data?: string | undefined;
374
374
  readonly file_url?: string | undefined;
@@ -400,7 +400,7 @@ export declare const routes: (Route<{
400
400
  readonly detail?: string | undefined;
401
401
  } | {
402
402
  readonly type: "input_file";
403
- readonly filename: string;
403
+ readonly filename?: string | undefined;
404
404
  readonly detail?: string | undefined;
405
405
  readonly file_data?: string | undefined;
406
406
  readonly file_url?: string | undefined;
@@ -45,7 +45,7 @@ export declare const routes: import("../route/client.js").Route<{
45
45
  readonly detail?: string | undefined;
46
46
  } | {
47
47
  readonly type: "input_file";
48
- readonly filename: string;
48
+ readonly filename?: string | undefined;
49
49
  readonly detail?: string | undefined;
50
50
  readonly file_data?: string | undefined;
51
51
  readonly file_url?: string | undefined;
@@ -77,7 +77,7 @@ export declare const routes: import("../route/client.js").Route<{
77
77
  readonly detail?: string | undefined;
78
78
  } | {
79
79
  readonly type: "input_file";
80
- readonly filename: string;
80
+ readonly filename?: string | undefined;
81
81
  readonly detail?: string | undefined;
82
82
  readonly file_data?: string | undefined;
83
83
  readonly file_url?: string | undefined;
@@ -214,7 +214,7 @@ export declare const routes: (Route<{
214
214
  readonly detail?: string | undefined;
215
215
  } | {
216
216
  readonly type: "input_file";
217
- readonly filename: string;
217
+ readonly filename?: string | undefined;
218
218
  readonly detail?: string | undefined;
219
219
  readonly file_data?: string | undefined;
220
220
  readonly file_url?: string | undefined;
@@ -246,7 +246,7 @@ export declare const routes: (Route<{
246
246
  readonly detail?: string | undefined;
247
247
  } | {
248
248
  readonly type: "input_file";
249
- readonly filename: string;
249
+ readonly filename?: string | undefined;
250
250
  readonly detail?: string | undefined;
251
251
  readonly file_data?: string | undefined;
252
252
  readonly file_url?: string | undefined;
@@ -1,4 +1,3 @@
1
- import type { OpenResponsesProviderOptionsInput } from "../open-responses-options.js";
2
1
  import type { OpenRouter } from "../openrouter.js";
3
2
  export { responsesModel as model } from "../openrouter.js";
4
- export type Settings = OpenRouter.Settings<OpenResponsesProviderOptionsInput>;
3
+ export type Settings = OpenRouter.Settings<OpenRouter.OpenRouterResponsesProviderOptionsInput>;
@@ -4,6 +4,7 @@ import { Protocol } from "../route/protocol.js";
4
4
  import { type ProviderAuthOption } from "../route/auth-options.js";
5
5
  import { type ModelID, type OpenString, type ProviderOptions } from "../schema/index.js";
6
6
  import type { ProviderPackage } from "../provider-package.js";
7
+ import { HttpTransport } from "../route/transport/index.js";
7
8
  import { OpenAIChat } from "../protocols/openai-chat.js";
8
9
  import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js";
9
10
  export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -73,6 +74,7 @@ export interface OpenRouterOptions {
73
74
  }>;
74
75
  }
75
76
  export type OpenRouterProviderOptionsInput = OpenRouterOptions;
77
+ export type OpenRouterResponsesProviderOptionsInput = OpenResponsesProviderOptionsInput & Pick<OpenRouterOptions, "debug" | "models" | "plugins" | "provider" | "user">;
76
78
  export interface OpenRouterDecisionOptions {
77
79
  readonly [key: string]: unknown;
78
80
  readonly provider?: OpenRouterProviderRouting;
@@ -82,7 +84,7 @@ export interface OpenRouterDecisionOptions {
82
84
  }
83
85
  export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
84
86
  readonly baseURL?: string;
85
- readonly providerOptions?: OpenRouterProviderOptionsInput | OpenResponsesProviderOptionsInput;
87
+ readonly providerOptions?: OpenRouterProviderOptionsInput | OpenRouterResponsesProviderOptionsInput;
86
88
  };
87
89
  export type Settings<Options = OpenRouterProviderOptionsInput> = ProviderPackage.Settings & Options & {
88
90
  readonly apiKey?: string;
@@ -259,9 +261,9 @@ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
259
261
  readonly models: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Array<Schema.String>>, never>>;
260
262
  readonly provider: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
261
263
  readonly plugins: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Array<Schema.$Record<Schema.String, Schema.Unknown>>>, never>>;
262
- readonly web_search_options: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
263
264
  readonly debug: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
264
265
  readonly user: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.String>, never>>;
266
+ readonly web_search_options: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
265
267
  readonly reasoning: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Record<Schema.String, Schema.Unknown>>, never>>;
266
268
  readonly usage: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
267
269
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
@@ -442,6 +444,10 @@ export declare const protocol: Protocol<{
442
444
  usage?: {
443
445
  readonly [x: string]: unknown;
444
446
  } | undefined;
447
+ web_search_options?: {
448
+ readonly [x: string]: unknown;
449
+ } | undefined;
450
+ reasoning?: Record<string, unknown> | undefined;
445
451
  models?: readonly string[] | undefined;
446
452
  provider?: {
447
453
  readonly [x: string]: unknown;
@@ -449,14 +455,10 @@ export declare const protocol: Protocol<{
449
455
  plugins?: readonly {
450
456
  readonly [x: string]: unknown;
451
457
  }[] | undefined;
452
- web_search_options?: {
453
- readonly [x: string]: unknown;
454
- } | undefined;
455
458
  debug?: {
456
459
  readonly [x: string]: unknown;
457
460
  } | undefined;
458
461
  user?: string | undefined;
459
- reasoning?: Record<string, unknown> | undefined;
460
462
  }, string, "[DONE]" | {
461
463
  readonly [x: string]: unknown;
462
464
  readonly choices?: readonly {
@@ -710,6 +712,10 @@ export declare const route: Route<{
710
712
  usage?: {
711
713
  readonly [x: string]: unknown;
712
714
  } | undefined;
715
+ web_search_options?: {
716
+ readonly [x: string]: unknown;
717
+ } | undefined;
718
+ reasoning?: Record<string, unknown> | undefined;
713
719
  models?: readonly string[] | undefined;
714
720
  provider?: {
715
721
  readonly [x: string]: unknown;
@@ -717,15 +723,11 @@ export declare const route: Route<{
717
723
  plugins?: readonly {
718
724
  readonly [x: string]: unknown;
719
725
  }[] | undefined;
720
- web_search_options?: {
721
- readonly [x: string]: unknown;
722
- } | undefined;
723
726
  debug?: {
724
727
  readonly [x: string]: unknown;
725
728
  } | undefined;
726
729
  user?: string | undefined;
727
- reasoning?: Record<string, unknown> | undefined;
728
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
730
+ }, HttpTransport.HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
729
731
  export declare const routes: (Route<{
730
732
  readonly model: string;
731
733
  readonly input: readonly ({
@@ -756,7 +758,7 @@ export declare const routes: (Route<{
756
758
  readonly detail?: string | undefined;
757
759
  } | {
758
760
  readonly type: "input_file";
759
- readonly filename: string;
761
+ readonly filename?: string | undefined;
760
762
  readonly detail?: string | undefined;
761
763
  readonly file_data?: string | undefined;
762
764
  readonly file_url?: string | undefined;
@@ -788,7 +790,7 @@ export declare const routes: (Route<{
788
790
  readonly detail?: string | undefined;
789
791
  } | {
790
792
  readonly type: "input_file";
791
- readonly filename: string;
793
+ readonly filename?: string | undefined;
792
794
  readonly detail?: string | undefined;
793
795
  readonly file_data?: string | undefined;
794
796
  readonly file_url?: string | undefined;
@@ -923,7 +925,18 @@ export declare const routes: (Route<{
923
925
  readonly presence_penalty?: number | undefined;
924
926
  readonly frequency_penalty?: number | undefined;
925
927
  readonly stream: true;
926
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
928
+ readonly models?: readonly string[] | undefined;
929
+ readonly provider?: {
930
+ readonly [x: string]: unknown;
931
+ } | undefined;
932
+ readonly plugins?: readonly {
933
+ readonly [x: string]: unknown;
934
+ }[] | undefined;
935
+ readonly debug?: {
936
+ readonly [x: string]: unknown;
937
+ } | undefined;
938
+ readonly user?: string | undefined;
939
+ }, HttpTransport.HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
927
940
  model: string;
928
941
  messages: readonly ({
929
942
  readonly role: "system";
@@ -1099,6 +1112,10 @@ export declare const routes: (Route<{
1099
1112
  usage?: {
1100
1113
  readonly [x: string]: unknown;
1101
1114
  } | undefined;
1115
+ web_search_options?: {
1116
+ readonly [x: string]: unknown;
1117
+ } | undefined;
1118
+ reasoning?: Record<string, unknown> | undefined;
1102
1119
  models?: readonly string[] | undefined;
1103
1120
  provider?: {
1104
1121
  readonly [x: string]: unknown;
@@ -1106,19 +1123,15 @@ export declare const routes: (Route<{
1106
1123
  plugins?: readonly {
1107
1124
  readonly [x: string]: unknown;
1108
1125
  }[] | undefined;
1109
- web_search_options?: {
1110
- readonly [x: string]: unknown;
1111
- } | undefined;
1112
1126
  debug?: {
1113
1127
  readonly [x: string]: unknown;
1114
1128
  } | undefined;
1115
1129
  user?: string | undefined;
1116
- reasoning?: Record<string, unknown> | undefined;
1117
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
1130
+ }, HttpTransport.HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
1118
1131
  export declare const configure: (input?: Config) => {
1119
1132
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
1120
1133
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
1121
- responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1134
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1122
1135
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
1123
1136
  decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
1124
1137
  configure: typeof configure;
@@ -1126,16 +1139,16 @@ export declare const configure: (input?: Config) => {
1126
1139
  export declare const provider: {
1127
1140
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
1128
1141
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
1129
- responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1142
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1130
1143
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
1131
1144
  decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
1132
1145
  configure: typeof configure;
1133
1146
  };
1134
1147
  export declare const decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
1135
1148
  export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
1136
- export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./open-responses-options.js").OpenResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1149
+ export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
1137
1150
  export declare const model: ProviderPackage.Model<Settings, OpenRouterProviderOptionsInput>;
1138
- export declare const responsesModel: ProviderPackage.Model<Settings<OpenResponsesProviderOptionsInput>, OpenResponsesProviderOptionsInput>;
1151
+ export declare const responsesModel: ProviderPackage.Model<Settings<OpenRouterResponsesProviderOptionsInput>, OpenRouterResponsesProviderOptionsInput>;
1139
1152
  export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
1140
1153
  export declare const decisionModel: (modelID: string, settings?: Settings) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
1141
1154
  export * as OpenRouter from "./openrouter.js";
@@ -7,6 +7,7 @@ import { ProviderID } from "../schema/index.js";
7
7
  import { SystemOne } from "../protocols/system-one.js";
8
8
  import { OpenAIImages } from "../protocols/openai-images.js";
9
9
  import { MediaRoute } from "../route/media.js";
10
+ import { HttpTransport } from "../route/transport/index.js";
10
11
  import { OpenAIChat } from "../protocols/openai-chat.js";
11
12
  import { OpenResponses } from "../protocols/open-responses.js";
12
13
  import { cacheControl } from "../protocols/utils/cache.js";
@@ -14,14 +15,17 @@ import { isRecord, JsonObject, lenient, ProviderShared } from "../protocols/shar
14
15
  export const id = ProviderID.make("openrouter");
15
16
  const baseURL = "https://openrouter.ai/api/v1";
16
17
  const ADAPTER = "openrouter";
17
- const Options = Schema.Struct({
18
- usage: lenient(Schema.Union([Schema.Boolean, JsonObject])),
18
+ const SharedOptions = Schema.Struct({
19
19
  models: lenient(Schema.Array(Schema.String)),
20
20
  provider: lenient(JsonObject),
21
21
  plugins: lenient(Schema.Array(JsonObject)),
22
- web_search_options: lenient(JsonObject),
23
22
  debug: lenient(JsonObject),
24
23
  user: lenient(Schema.String),
24
+ });
25
+ const Options = Schema.Struct({
26
+ ...SharedOptions.fields,
27
+ usage: lenient(Schema.Union([Schema.Boolean, JsonObject])),
28
+ web_search_options: lenient(JsonObject),
25
29
  reasoning: lenient(JsonObject),
26
30
  });
27
31
  const decodeOptions = Schema.decodeUnknownSync(Options);
@@ -74,12 +78,8 @@ const bodyOptions = (body, input, maxTokens) => {
74
78
  ...options,
75
79
  ...body,
76
80
  ...(usage !== undefined ? { usage } : {}),
77
- ...(known.models !== undefined ? { models: known.models } : {}),
78
- ...(known.provider !== undefined ? { provider: known.provider } : {}),
79
- ...(known.plugins !== undefined ? { plugins: known.plugins } : {}),
81
+ ...sharedOptions(known),
80
82
  ...(known.web_search_options !== undefined ? { web_search_options: known.web_search_options } : {}),
81
- ...(known.debug !== undefined ? { debug: known.debug } : {}),
82
- ...(known.user !== undefined ? { user: known.user } : {}),
83
83
  ...(known.reasoning !== undefined ? { reasoning: fitReasoning(known.reasoning, maxTokens) } : {}),
84
84
  };
85
85
  };
@@ -96,6 +96,25 @@ const imageSizing = (request) => {
96
96
  resolution: resolution !== undefined && IMAGE_RESOLUTIONS.has(resolution) ? resolution : undefined,
97
97
  };
98
98
  };
99
+ const sharedOptions = (known) => ({
100
+ ...(known.models !== undefined ? { models: known.models } : {}),
101
+ ...(known.provider !== undefined ? { provider: known.provider } : {}),
102
+ ...(known.plugins !== undefined ? { plugins: known.plugins } : {}),
103
+ ...(known.debug !== undefined ? { debug: known.debug } : {}),
104
+ ...(known.user !== undefined ? { user: known.user } : {}),
105
+ });
106
+ const OpenRouterResponsesBody = Schema.Struct({
107
+ ...OpenResponses.OpenResponsesBody.fields,
108
+ ...SharedOptions.fields,
109
+ });
110
+ const responsesProtocol = Protocol.make({
111
+ id: "openrouter-responses",
112
+ body: {
113
+ schema: OpenRouterResponsesBody,
114
+ from: (request) => OpenResponses.fromRequest(request).pipe(Effect.map((body) => ({ ...body, ...sharedOptions(decodeOptions(request.providerOptions ?? {})) }))),
115
+ },
116
+ stream: OpenResponses.protocol.stream,
117
+ });
99
118
  export const route = Route.make({
100
119
  id: ADAPTER,
101
120
  provider: id,
@@ -108,9 +127,9 @@ const responsesRoute = Route.make({
108
127
  id: "openrouter-responses",
109
128
  provider: id,
110
129
  providerMetadataKey: "openrouter",
111
- protocol: OpenResponses.protocol,
130
+ protocol: responsesProtocol,
112
131
  endpoint: Endpoint.path("/responses", { baseURL }),
113
- transport: OpenResponses.httpTransport,
132
+ transport: HttpTransport.sseJson.with(),
114
133
  defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
115
134
  });
116
135
  export const routes = [route, responsesRoute];
@@ -46,7 +46,7 @@ export declare const routes: (Route<{
46
46
  readonly detail?: string | undefined;
47
47
  } | {
48
48
  readonly type: "input_file";
49
- readonly filename: string;
49
+ readonly filename?: string | undefined;
50
50
  readonly detail?: string | undefined;
51
51
  readonly file_data?: string | undefined;
52
52
  readonly file_url?: string | undefined;
@@ -78,7 +78,7 @@ export declare const routes: (Route<{
78
78
  readonly detail?: string | undefined;
79
79
  } | {
80
80
  readonly type: "input_file";
81
- readonly filename: string;
81
+ readonly filename?: string | undefined;
82
82
  readonly detail?: string | undefined;
83
83
  readonly file_data?: string | undefined;
84
84
  readonly file_url?: string | undefined;
@@ -49,7 +49,7 @@ export declare const routes: (Route<{
49
49
  readonly detail?: string | undefined;
50
50
  } | {
51
51
  readonly type: "input_file";
52
- readonly filename: string;
52
+ readonly filename?: string | undefined;
53
53
  readonly detail?: string | undefined;
54
54
  readonly file_data?: string | undefined;
55
55
  readonly file_url?: string | undefined;
@@ -81,7 +81,7 @@ export declare const routes: (Route<{
81
81
  readonly detail?: string | undefined;
82
82
  } | {
83
83
  readonly type: "input_file";
84
- readonly filename: string;
84
+ readonly filename?: string | undefined;
85
85
  readonly detail?: string | undefined;
86
86
  readonly file_data?: string | undefined;
87
87
  readonly file_url?: string | undefined;
@@ -208,6 +208,9 @@ export declare const compileRequest: (request: LLMRequest<LanguageModel<{
208
208
  transport: string;
209
209
  };
210
210
  }, AIError, never>;
211
+ export declare const generateWith: (stream: Interface["stream"]) => (request: LLMRequest<LanguageModel<{
212
+ readonly [x: string]: unknown;
213
+ }, CompactionOperations | undefined>>, options?: StreamOptions | undefined) => Effect.Effect<LLMResponse, AIError, never>;
211
214
  export declare function stream(request: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
212
215
  export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
213
216
  export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
@@ -10,7 +10,7 @@ import { normalizeToolHistory } from "../tool-history.js";
10
10
  import { sanitizeSurrogates } from "../utils/sanitize.js";
11
11
  import * as ProviderShared from "../protocols/shared.js";
12
12
  import { ToolSchemaProjection } from "../protocols/utils/tool-schema.js";
13
- import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LLMEvent, InvalidProviderOutputError, ProviderConfigurationError, ProviderID, mergeGenerationOptions, mergeHttpOptions, mergeProviderOptions, } from "../schema/index.js";
13
+ import { AIError, CompactionResponse, CompactionCheckpointResponse, AIErrorReason, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LLMEvent, InvalidProviderOutputError, ProviderConfigurationError, ProviderID, mergeGenerationOptions, mergeHttpOptions, mergeProviderOptions, withPartial, } from "../schema/index.js";
14
14
  const makeRouteLanguageModel = (route, mapped) => {
15
15
  const provider = route.provider ?? ("provider" in mapped ? mapped.provider : undefined);
16
16
  if (!provider)
@@ -265,12 +265,13 @@ const streamRequestWith = (runtime) => (request, options) => Stream.unwrap(Effec
265
265
  const compiled = yield* compile(request, options);
266
266
  return compiled.route.streamPrepared(compiled.prepared, compiled.request, runtime, options);
267
267
  }));
268
- const generateWith = (stream) => Effect.fn("LLM.generate")(function* (request, options) {
269
- const state = yield* stream(request, options).pipe(Stream.runFold(LLMResponse.empty, LLMResponse.reduce));
268
+ export const generateWith = (stream) => Effect.fn("LLM.generate")(function* (request, options) {
269
+ let state = LLMResponse.empty();
270
+ yield* stream(request, options).pipe(Stream.runForEach((event) => Effect.sync(() => (state = LLMResponse.reduce(state, event)))), Effect.mapError((error) => withPartial(error, LLMResponse.partial(state))));
270
271
  const response = LLMResponse.complete(state);
271
272
  if (response)
272
273
  return response;
273
- return yield* incompleteStreamError(`${request.model.provider}/${request.model.route.id}`);
274
+ return yield* withPartial(incompleteStreamError(`${request.model.provider}/${request.model.route.id}`), LLMResponse.partial(state));
274
275
  });
275
276
  export function stream(request, options) {
276
277
  return Stream.unwrap(Effect.gen(function* () {
@@ -171,9 +171,8 @@ export declare const identity: (input: {
171
171
  unsupported: (operation: string, message: string) => AIError;
172
172
  };
173
173
  export type Identity = ReturnType<typeof identity>;
174
- export type Output = Effect.Success<ReturnType<Identity["text"]>>;
175
- /** Map a provider status string through the protocol's table; unknown values are an invalid provider document. */
176
- export declare const status: <Table extends Record<string, Status>>(table: Table, raw: string, output: Output) => Effect.Effect<Status, AIError>;
174
+ /** Map a provider status string through the protocol's table; unknown values keep the generation running. */
175
+ export declare const status: (table: Readonly<Record<string, Status>>, raw: string) => Status;
177
176
  /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
178
177
  export declare const failure: (table: Readonly<Record<string, Failure>>, code: string | number | undefined) => Failure;
179
178
  /** A `url` asset whose provider-declared retention window starts now. */
@@ -109,12 +109,8 @@ export const identity = (input) => {
109
109
  unsupported: (operation, message) => new AIError({ reason: new UnsupportedOperationError({ operation, provider, route: input.id, message }) }),
110
110
  };
111
111
  };
112
- /** Map a provider status string through the protocol's table; unknown values are an invalid provider document. */
113
- export const status = (table, raw, output) => {
114
- if (!Object.hasOwn(table, raw))
115
- return Effect.fail(output.invalid(`Unknown generation status "${raw}"`));
116
- return Effect.succeed(table[raw]);
117
- };
112
+ /** Map a provider status string through the protocol's table; unknown values keep the generation running. */
113
+ export const status = (table, raw) => Object.hasOwn(table, raw) ? table[raw] : "running";
118
114
  /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
119
115
  export const failure = (table, code) => code !== undefined && Object.hasOwn(table, code) ? table[code] : "ProviderInternal";
120
116
  /** A `url` asset whose provider-declared retention window starts now. */