@opencode/ai 2.0.19 → 2.0.20

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 (37) hide show
  1. package/dist/cache-policy.js +6 -0
  2. package/dist/llm.d.ts +1 -1
  3. package/dist/promise.d.ts +2 -2
  4. package/dist/protocols/alibaba-responses.d.ts +14 -14
  5. package/dist/protocols/anthropic-messages.js +2 -15
  6. package/dist/protocols/bedrock-converse.d.ts +1 -1
  7. package/dist/protocols/bedrock-converse.js +38 -12
  8. package/dist/protocols/meta-messages.d.ts +5 -1
  9. package/dist/protocols/meta-messages.js +11 -4
  10. package/dist/protocols/meta-responses.d.ts +16 -16
  11. package/dist/protocols/mistral-chat.d.ts +6 -0
  12. package/dist/protocols/mistral-chat.js +8 -5
  13. package/dist/protocols/open-responses.d.ts +31 -31
  14. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  15. package/dist/protocols/openai-responses.d.ts +22 -22
  16. package/dist/protocols/utils/claude-model.d.ts +8 -0
  17. package/dist/protocols/utils/claude-model.js +15 -0
  18. package/dist/protocols/utils/tool-stream.d.ts +3 -3
  19. package/dist/protocols/xai-responses.d.ts +14 -14
  20. package/dist/provider-error.d.ts +1 -0
  21. package/dist/provider-error.js +19 -1
  22. package/dist/providers/alibaba.d.ts +2 -2
  23. package/dist/providers/amazon-bedrock-mantle.d.ts +2 -2
  24. package/dist/providers/azure.d.ts +4 -4
  25. package/dist/providers/cloudflare-ai-gateway.d.ts +4 -4
  26. package/dist/providers/google-vertex-responses.d.ts +2 -2
  27. package/dist/providers/meta.d.ts +7 -3
  28. package/dist/providers/minimax.d.ts +2 -2
  29. package/dist/providers/moonshot.d.ts +2 -2
  30. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  31. package/dist/providers/openai.d.ts +2 -2
  32. package/dist/providers/zai-coding-plan.d.ts +2 -2
  33. package/dist/route/client.d.ts +1 -1
  34. package/dist/route/executor.js +12 -8
  35. package/dist/schema/events.d.ts +30 -30
  36. package/dist/testing.d.ts +8 -8
  37. package/package.json +3 -3
@@ -291,8 +291,8 @@ export declare const protocol: Protocol<{
291
291
  } | {
292
292
  readonly type: "input_file";
293
293
  readonly filename: string;
294
- readonly file_data?: string | undefined;
295
294
  readonly detail?: string | undefined;
295
+ readonly file_data?: string | undefined;
296
296
  readonly file_url?: string | undefined;
297
297
  } | {
298
298
  readonly type: "input_text";
@@ -328,8 +328,8 @@ export declare const protocol: Protocol<{
328
328
  } | {
329
329
  readonly type: "input_file";
330
330
  readonly filename: string;
331
- readonly file_data?: string | undefined;
332
331
  readonly detail?: string | undefined;
332
+ readonly file_data?: string | undefined;
333
333
  readonly file_url?: string | undefined;
334
334
  } | {
335
335
  readonly type: "input_text";
@@ -450,21 +450,10 @@ export declare const protocol: Protocol<{
450
450
  readonly [x: string]: unknown;
451
451
  readonly type: string;
452
452
  readonly status?: unknown;
453
- readonly code?: unknown;
454
453
  readonly message?: unknown;
454
+ readonly code?: unknown;
455
455
  readonly text?: string | undefined;
456
456
  readonly error?: unknown;
457
- readonly item?: {
458
- readonly [x: string]: unknown;
459
- readonly type: string;
460
- readonly id?: string | undefined;
461
- readonly name?: string | undefined;
462
- readonly namespace?: string | undefined;
463
- readonly arguments?: string | undefined;
464
- readonly encrypted_content?: string | null | undefined;
465
- readonly call_id?: string | undefined;
466
- } | null | undefined;
467
- readonly delta?: string | undefined;
468
457
  readonly response?: {
469
458
  readonly [x: string]: unknown;
470
459
  readonly id?: string | undefined;
@@ -496,6 +485,17 @@ export declare const protocol: Protocol<{
496
485
  readonly reason?: string | undefined;
497
486
  } | null | undefined;
498
487
  } | undefined;
488
+ readonly item?: {
489
+ readonly [x: string]: unknown;
490
+ readonly type: string;
491
+ readonly id?: string | undefined;
492
+ readonly name?: string | undefined;
493
+ readonly namespace?: string | undefined;
494
+ readonly arguments?: string | undefined;
495
+ readonly encrypted_content?: string | null | undefined;
496
+ readonly call_id?: string | undefined;
497
+ } | null | undefined;
498
+ readonly delta?: string | undefined;
499
499
  readonly arguments?: string | undefined;
500
500
  readonly item_id?: string | undefined;
501
501
  readonly output_index?: number | undefined;
@@ -574,8 +574,8 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
574
574
  } | {
575
575
  readonly type: "input_file";
576
576
  readonly filename: string;
577
- readonly file_data?: string | undefined;
578
577
  readonly detail?: string | undefined;
578
+ readonly file_data?: string | undefined;
579
579
  readonly file_url?: string | undefined;
580
580
  } | {
581
581
  readonly type: "input_text";
@@ -611,8 +611,8 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
611
611
  } | {
612
612
  readonly type: "input_file";
613
613
  readonly filename: string;
614
- readonly file_data?: string | undefined;
615
614
  readonly detail?: string | undefined;
615
+ readonly file_data?: string | undefined;
616
616
  readonly file_url?: string | undefined;
617
617
  } | {
618
618
  readonly type: "input_text";
@@ -802,8 +802,8 @@ export declare const channelTransport: (options: import("./open-responses-channe
802
802
  } | {
803
803
  readonly type: "input_file";
804
804
  readonly filename: string;
805
- readonly file_data?: string | undefined;
806
805
  readonly detail?: string | undefined;
806
+ readonly file_data?: string | undefined;
807
807
  readonly file_url?: string | undefined;
808
808
  } | {
809
809
  readonly type: "input_text";
@@ -839,8 +839,8 @@ export declare const channelTransport: (options: import("./open-responses-channe
839
839
  } | {
840
840
  readonly type: "input_file";
841
841
  readonly filename: string;
842
- readonly file_data?: string | undefined;
843
842
  readonly detail?: string | undefined;
843
+ readonly file_data?: string | undefined;
844
844
  readonly file_url?: string | undefined;
845
845
  } | {
846
846
  readonly type: "input_text";
@@ -1030,8 +1030,8 @@ export declare const transport: import("../route/transport/index.js").Transport<
1030
1030
  } | {
1031
1031
  readonly type: "input_file";
1032
1032
  readonly filename: string;
1033
- readonly file_data?: string | undefined;
1034
1033
  readonly detail?: string | undefined;
1034
+ readonly file_data?: string | undefined;
1035
1035
  readonly file_url?: string | undefined;
1036
1036
  } | {
1037
1037
  readonly type: "input_text";
@@ -1067,8 +1067,8 @@ export declare const transport: import("../route/transport/index.js").Transport<
1067
1067
  } | {
1068
1068
  readonly type: "input_file";
1069
1069
  readonly filename: string;
1070
- readonly file_data?: string | undefined;
1071
1070
  readonly detail?: string | undefined;
1071
+ readonly file_data?: string | undefined;
1072
1072
  readonly file_url?: string | undefined;
1073
1073
  } | {
1074
1074
  readonly type: "input_text";
@@ -1258,8 +1258,8 @@ export declare const route: Route<{
1258
1258
  } | {
1259
1259
  readonly type: "input_file";
1260
1260
  readonly filename: string;
1261
- readonly file_data?: string | undefined;
1262
1261
  readonly detail?: string | undefined;
1262
+ readonly file_data?: string | undefined;
1263
1263
  readonly file_url?: string | undefined;
1264
1264
  } | {
1265
1265
  readonly type: "input_text";
@@ -1295,8 +1295,8 @@ export declare const route: Route<{
1295
1295
  } | {
1296
1296
  readonly type: "input_file";
1297
1297
  readonly filename: string;
1298
- readonly file_data?: string | undefined;
1299
1298
  readonly detail?: string | undefined;
1299
+ readonly file_data?: string | undefined;
1300
1300
  readonly file_url?: string | undefined;
1301
1301
  } | {
1302
1302
  readonly type: "input_text";
@@ -0,0 +1,8 @@
1
+ import type { LLMRequest } from "../../schema/index.js";
2
+ export declare const THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
3
+ export declare const claudeVersion: (id: string) => {
4
+ family: string;
5
+ major: number;
6
+ minor: number;
7
+ } | undefined;
8
+ export declare const supportsThinkingBlockBinding: (model: LLMRequest["model"]) => boolean;
@@ -0,0 +1,15 @@
1
+ export const THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
2
+ // Accept gateway namespaces and Vertex suffixes without treating a snapshot date as a minor version.
3
+ export const claudeVersion = (id) => {
4
+ const match = /(?:^|[./])claude-(?<family>[a-z]+)-(?<major>\d+)(?:[.-](?<minor>\d{1,2}))?(?:$|[-:@])/.exec(id.toLowerCase())?.groups;
5
+ if (!match)
6
+ return undefined;
7
+ return { family: match.family, major: Number(match.major), minor: Number(match.minor ?? 0) };
8
+ };
9
+ export const supportsThinkingBlockBinding = (model) => {
10
+ const override = model.compatibility?.supportsThinkingBlockBinding;
11
+ if (override !== undefined)
12
+ return override;
13
+ const version = claudeVersion(model.id);
14
+ return version !== undefined && (version.major > 5 || (version.major === 5 && version.minor >= 1));
15
+ };
@@ -236,8 +236,8 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
236
236
  } | {
237
237
  readonly id: string;
238
238
  readonly type: "tool-error";
239
- readonly name: string;
240
239
  readonly message: string;
240
+ readonly name: string;
241
241
  readonly error?: unknown;
242
242
  readonly providerMetadata?: {
243
243
  readonly [x: string]: {
@@ -459,8 +459,8 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
459
459
  } | {
460
460
  readonly id: string;
461
461
  readonly type: "tool-error";
462
- readonly name: string;
463
462
  readonly message: string;
463
+ readonly name: string;
464
464
  readonly error?: unknown;
465
465
  readonly providerMetadata?: {
466
466
  readonly [x: string]: {
@@ -679,8 +679,8 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
679
679
  } | {
680
680
  readonly id: string;
681
681
  readonly type: "tool-error";
682
- readonly name: string;
683
682
  readonly message: string;
683
+ readonly name: string;
684
684
  readonly error?: unknown;
685
685
  readonly providerMetadata?: {
686
686
  readonly [x: string]: {
@@ -67,8 +67,8 @@ export declare const protocol: Protocol<{
67
67
  } | {
68
68
  readonly type: "input_file";
69
69
  readonly filename: string;
70
- readonly file_data?: string | undefined;
71
70
  readonly detail?: string | undefined;
71
+ readonly file_data?: string | undefined;
72
72
  readonly file_url?: string | undefined;
73
73
  } | {
74
74
  readonly type: "input_text";
@@ -104,8 +104,8 @@ export declare const protocol: Protocol<{
104
104
  } | {
105
105
  readonly type: "input_file";
106
106
  readonly filename: string;
107
- readonly file_data?: string | undefined;
108
107
  readonly detail?: string | undefined;
108
+ readonly file_data?: string | undefined;
109
109
  readonly file_url?: string | undefined;
110
110
  } | {
111
111
  readonly type: "input_text";
@@ -184,21 +184,10 @@ export declare const protocol: Protocol<{
184
184
  readonly [x: string]: unknown;
185
185
  readonly type: string;
186
186
  readonly status?: unknown;
187
- readonly code?: unknown;
188
187
  readonly message?: unknown;
188
+ readonly code?: unknown;
189
189
  readonly text?: string | undefined;
190
190
  readonly error?: unknown;
191
- readonly item?: {
192
- readonly [x: string]: unknown;
193
- readonly type: string;
194
- readonly id?: string | undefined;
195
- readonly name?: string | undefined;
196
- readonly namespace?: string | undefined;
197
- readonly arguments?: string | undefined;
198
- readonly encrypted_content?: string | null | undefined;
199
- readonly call_id?: string | undefined;
200
- } | null | undefined;
201
- readonly delta?: string | undefined;
202
191
  readonly response?: {
203
192
  readonly [x: string]: unknown;
204
193
  readonly id?: string | undefined;
@@ -230,6 +219,17 @@ export declare const protocol: Protocol<{
230
219
  readonly reason?: string | undefined;
231
220
  } | null | undefined;
232
221
  } | undefined;
222
+ readonly item?: {
223
+ readonly [x: string]: unknown;
224
+ readonly type: string;
225
+ readonly id?: string | undefined;
226
+ readonly name?: string | undefined;
227
+ readonly namespace?: string | undefined;
228
+ readonly arguments?: string | undefined;
229
+ readonly encrypted_content?: string | null | undefined;
230
+ readonly call_id?: string | undefined;
231
+ } | null | undefined;
232
+ readonly delta?: string | undefined;
233
233
  readonly arguments?: string | undefined;
234
234
  readonly item_id?: string | undefined;
235
235
  readonly output_index?: number | undefined;
@@ -7,6 +7,7 @@ export declare const isContextOverflowFailure: (failure: unknown) => boolean;
7
7
  * not deliver an accepted write, and unrecognized failures. Callers decide which calls are safe to repeat.
8
8
  */
9
9
  export declare const isRetryable: (error: AIError) => boolean;
10
+ export declare const providerErrorMessage: (body: string) => string | undefined;
10
11
  export interface ProviderFailure {
11
12
  readonly message: string;
12
13
  readonly status?: number | undefined;
@@ -1,4 +1,4 @@
1
- import { Option, Schema } from "effect";
1
+ import { Option, Schema, SchemaGetter } from "effect";
2
2
  import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
3
  const patterns = [
4
4
  /prompt is too long/i,
@@ -130,6 +130,24 @@ const QUOTA_TEXT = /insufficient[-_\s]?quota|quota[-_\s]?exceeded|budget exceede
130
130
  // under `invalid_request_error`.
131
131
  const CONTENT_POLICY_TEXT = /violating our usage policy|blocked by content filtering policy|content[-_\s]?policy|rejected as a result of our safety system/i;
132
132
  const SERVER_ERROR_TEXT = /\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i;
133
+ const Message = Schema.String.check(Schema.isPattern(/\S/));
134
+ const messageAt = (fields, message) => Schema.Struct(fields).pipe(Schema.decodeTo(Schema.String, {
135
+ decode: SchemaGetter.transform(message),
136
+ encode: SchemaGetter.forbidden(() => "Provider error messages are decode-only"),
137
+ }));
138
+ // Common error body layouts that carry a human-readable message, in priority order.
139
+ // Provider-specific layouts belong in their protocol.
140
+ const decodeMessage = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Union([
141
+ messageAt({ error: Schema.Struct({ message: Message }) }, (body) => body.error.message),
142
+ messageAt({ error: Message }, (body) => body.error),
143
+ messageAt({ message: Message }, (body) => body.message),
144
+ // AWS services
145
+ messageAt({ Message: Message }, (body) => body.Message),
146
+ // RFC 9457 problem details
147
+ messageAt({ detail: Message }, (body) => body.detail),
148
+ messageAt({ errors: Schema.NonEmptyArray(Schema.Struct({ message: Message })) }, (body) => body.errors[0].message),
149
+ ])));
150
+ export const providerErrorMessage = (body) => Option.getOrUndefined(decodeMessage(body));
133
151
  // Classification records affirmative evidence about a failure. Deterministic
134
152
  // failures need positive identification (a 4xx status, quota/auth/policy
135
153
  // signals); anything unrecognized stays UnknownProvider, which the session
@@ -487,8 +487,8 @@ export declare const routes: (Route<{
487
487
  } | {
488
488
  readonly type: "input_file";
489
489
  readonly filename: string;
490
- readonly file_data?: string | undefined;
491
490
  readonly detail?: string | undefined;
491
+ readonly file_data?: string | undefined;
492
492
  readonly file_url?: string | undefined;
493
493
  } | {
494
494
  readonly type: "input_text";
@@ -524,8 +524,8 @@ export declare const routes: (Route<{
524
524
  } | {
525
525
  readonly type: "input_file";
526
526
  readonly filename: string;
527
- readonly file_data?: string | undefined;
528
527
  readonly detail?: string | undefined;
528
+ readonly file_data?: string | undefined;
529
529
  readonly file_url?: string | undefined;
530
530
  } | {
531
531
  readonly type: "input_text";
@@ -208,8 +208,8 @@ export declare const routes: (Route<{
208
208
  } | {
209
209
  readonly type: "input_file";
210
210
  readonly filename: string;
211
- readonly file_data?: string | undefined;
212
211
  readonly detail?: string | undefined;
212
+ readonly file_data?: string | undefined;
213
213
  readonly file_url?: string | undefined;
214
214
  } | {
215
215
  readonly type: "input_text";
@@ -245,8 +245,8 @@ export declare const routes: (Route<{
245
245
  } | {
246
246
  readonly type: "input_file";
247
247
  readonly filename: string;
248
- readonly file_data?: string | undefined;
249
248
  readonly detail?: string | undefined;
249
+ readonly file_data?: string | undefined;
250
250
  readonly file_url?: string | undefined;
251
251
  } | {
252
252
  readonly type: "input_text";
@@ -93,8 +93,8 @@ declare const responsesRoute: Route<{
93
93
  } | {
94
94
  readonly type: "input_file";
95
95
  readonly filename: string;
96
- readonly file_data?: string | undefined;
97
96
  readonly detail?: string | undefined;
97
+ readonly file_data?: string | undefined;
98
98
  readonly file_url?: string | undefined;
99
99
  } | {
100
100
  readonly type: "input_text";
@@ -130,8 +130,8 @@ declare const responsesRoute: Route<{
130
130
  } | {
131
131
  readonly type: "input_file";
132
132
  readonly filename: string;
133
- readonly file_data?: string | undefined;
134
133
  readonly detail?: string | undefined;
134
+ readonly file_data?: string | undefined;
135
135
  readonly file_url?: string | undefined;
136
136
  } | {
137
137
  readonly type: "input_text";
@@ -438,8 +438,8 @@ export declare const routes: (Route<{
438
438
  } | {
439
439
  readonly type: "input_file";
440
440
  readonly filename: string;
441
- readonly file_data?: string | undefined;
442
441
  readonly detail?: string | undefined;
442
+ readonly file_data?: string | undefined;
443
443
  readonly file_url?: string | undefined;
444
444
  } | {
445
445
  readonly type: "input_text";
@@ -475,8 +475,8 @@ export declare const routes: (Route<{
475
475
  } | {
476
476
  readonly type: "input_file";
477
477
  readonly filename: string;
478
- readonly file_data?: string | undefined;
479
478
  readonly detail?: string | undefined;
479
+ readonly file_data?: string | undefined;
480
480
  readonly file_url?: string | undefined;
481
481
  } | {
482
482
  readonly type: "input_text";
@@ -99,8 +99,8 @@ export declare const responsesRoute: import("../route/client.js").Route<{
99
99
  } | {
100
100
  readonly type: "input_file";
101
101
  readonly filename: string;
102
- readonly file_data?: string | undefined;
103
102
  readonly detail?: string | undefined;
103
+ readonly file_data?: string | undefined;
104
104
  readonly file_url?: string | undefined;
105
105
  } | {
106
106
  readonly type: "input_text";
@@ -136,8 +136,8 @@ export declare const responsesRoute: import("../route/client.js").Route<{
136
136
  } | {
137
137
  readonly type: "input_file";
138
138
  readonly filename: string;
139
- readonly file_data?: string | undefined;
140
139
  readonly detail?: string | undefined;
140
+ readonly file_data?: string | undefined;
141
141
  readonly file_url?: string | undefined;
142
142
  } | {
143
143
  readonly type: "input_text";
@@ -1106,8 +1106,8 @@ export declare const routes: (import("../route/client.js").Route<{
1106
1106
  } | {
1107
1107
  readonly type: "input_file";
1108
1108
  readonly filename: string;
1109
- readonly file_data?: string | undefined;
1110
1109
  readonly detail?: string | undefined;
1110
+ readonly file_data?: string | undefined;
1111
1111
  readonly file_url?: string | undefined;
1112
1112
  } | {
1113
1113
  readonly type: "input_text";
@@ -1143,8 +1143,8 @@ export declare const routes: (import("../route/client.js").Route<{
1143
1143
  } | {
1144
1144
  readonly type: "input_file";
1145
1145
  readonly filename: string;
1146
- readonly file_data?: string | undefined;
1147
1146
  readonly detail?: string | undefined;
1147
+ readonly file_data?: string | undefined;
1148
1148
  readonly file_url?: string | undefined;
1149
1149
  } | {
1150
1150
  readonly type: "input_text";
@@ -84,8 +84,8 @@ export declare const routes: Route<{
84
84
  } | {
85
85
  readonly type: "input_file";
86
86
  readonly filename: string;
87
- readonly file_data?: string | undefined;
88
87
  readonly detail?: string | undefined;
88
+ readonly file_data?: string | undefined;
89
89
  readonly file_url?: string | undefined;
90
90
  } | {
91
91
  readonly type: "input_text";
@@ -121,8 +121,8 @@ export declare const routes: Route<{
121
121
  } | {
122
122
  readonly type: "input_file";
123
123
  readonly filename: string;
124
- readonly file_data?: string | undefined;
125
124
  readonly detail?: string | undefined;
125
+ readonly file_data?: string | undefined;
126
126
  readonly file_url?: string | undefined;
127
127
  } | {
128
128
  readonly type: "input_text";
@@ -220,8 +220,8 @@ export declare const routes: (Route<{
220
220
  } | {
221
221
  readonly type: "input_file";
222
222
  readonly filename: string;
223
- readonly file_data?: string | undefined;
224
223
  readonly detail?: string | undefined;
224
+ readonly file_data?: string | undefined;
225
225
  readonly file_url?: string | undefined;
226
226
  } | {
227
227
  readonly type: "input_text";
@@ -257,8 +257,8 @@ export declare const routes: (Route<{
257
257
  } | {
258
258
  readonly type: "input_file";
259
259
  readonly filename: string;
260
- readonly file_data?: string | undefined;
261
260
  readonly detail?: string | undefined;
261
+ readonly file_data?: string | undefined;
262
262
  readonly file_url?: string | undefined;
263
263
  } | {
264
264
  readonly type: "input_text";
@@ -547,11 +547,15 @@ export declare const routes: (Route<{
547
547
  readonly timezone?: string | undefined;
548
548
  } | undefined;
549
549
  } | {
550
- readonly name: string;
551
550
  readonly description: string;
551
+ readonly name: string;
552
552
  readonly input_schema: {
553
553
  readonly [x: string]: unknown;
554
554
  };
555
+ readonly cache_control?: {
556
+ readonly type: "ephemeral";
557
+ readonly ttl?: "1h" | "5m" | undefined;
558
+ } | undefined;
555
559
  })[] | undefined;
556
560
  readonly system?: readonly {
557
561
  readonly type: "text";
@@ -372,8 +372,8 @@ export declare const routes: (Route<{
372
372
  } | {
373
373
  readonly type: "input_file";
374
374
  readonly filename: string;
375
- readonly file_data?: string | undefined;
376
375
  readonly detail?: string | undefined;
376
+ readonly file_data?: string | undefined;
377
377
  readonly file_url?: string | undefined;
378
378
  } | {
379
379
  readonly type: "input_text";
@@ -409,8 +409,8 @@ export declare const routes: (Route<{
409
409
  } | {
410
410
  readonly type: "input_file";
411
411
  readonly filename: string;
412
- readonly file_data?: string | undefined;
413
412
  readonly detail?: string | undefined;
413
+ readonly file_data?: string | undefined;
414
414
  readonly file_url?: string | undefined;
415
415
  } | {
416
416
  readonly type: "input_text";
@@ -370,8 +370,8 @@ export declare const routes: (Route<{
370
370
  } | {
371
371
  readonly type: "input_file";
372
372
  readonly filename: string;
373
- readonly file_data?: string | undefined;
374
373
  readonly detail?: string | undefined;
374
+ readonly file_data?: string | undefined;
375
375
  readonly file_url?: string | undefined;
376
376
  } | {
377
377
  readonly type: "input_text";
@@ -407,8 +407,8 @@ export declare const routes: (Route<{
407
407
  } | {
408
408
  readonly type: "input_file";
409
409
  readonly filename: string;
410
- readonly file_data?: string | undefined;
411
410
  readonly detail?: string | undefined;
411
+ readonly file_data?: string | undefined;
412
412
  readonly file_url?: string | undefined;
413
413
  } | {
414
414
  readonly type: "input_text";
@@ -82,8 +82,8 @@ export declare const routes: import("../route/client.js").Route<{
82
82
  } | {
83
83
  readonly type: "input_file";
84
84
  readonly filename: string;
85
- readonly file_data?: string | undefined;
86
85
  readonly detail?: string | undefined;
86
+ readonly file_data?: string | undefined;
87
87
  readonly file_url?: string | undefined;
88
88
  } | {
89
89
  readonly type: "input_text";
@@ -119,8 +119,8 @@ export declare const routes: import("../route/client.js").Route<{
119
119
  } | {
120
120
  readonly type: "input_file";
121
121
  readonly filename: string;
122
- readonly file_data?: string | undefined;
123
122
  readonly detail?: string | undefined;
123
+ readonly file_data?: string | undefined;
124
124
  readonly file_url?: string | undefined;
125
125
  } | {
126
126
  readonly type: "input_text";
@@ -196,8 +196,8 @@ export declare const routes: (Route<{
196
196
  } | {
197
197
  readonly type: "input_file";
198
198
  readonly filename: string;
199
- readonly file_data?: string | undefined;
200
199
  readonly detail?: string | undefined;
200
+ readonly file_data?: string | undefined;
201
201
  readonly file_url?: string | undefined;
202
202
  } | {
203
203
  readonly type: "input_text";
@@ -233,8 +233,8 @@ export declare const routes: (Route<{
233
233
  } | {
234
234
  readonly type: "input_file";
235
235
  readonly filename: string;
236
- readonly file_data?: string | undefined;
237
236
  readonly detail?: string | undefined;
237
+ readonly file_data?: string | undefined;
238
238
  readonly file_url?: string | undefined;
239
239
  } | {
240
240
  readonly type: "input_text";
@@ -86,8 +86,8 @@ export declare const routes: (Route<{
86
86
  } | {
87
87
  readonly type: "input_file";
88
88
  readonly filename: string;
89
- readonly file_data?: string | undefined;
90
89
  readonly detail?: string | undefined;
90
+ readonly file_data?: string | undefined;
91
91
  readonly file_url?: string | undefined;
92
92
  } | {
93
93
  readonly type: "input_text";
@@ -123,8 +123,8 @@ export declare const routes: (Route<{
123
123
  } | {
124
124
  readonly type: "input_file";
125
125
  readonly filename: string;
126
- readonly file_data?: string | undefined;
127
126
  readonly detail?: string | undefined;
127
+ readonly file_data?: string | undefined;
128
128
  readonly file_url?: string | undefined;
129
129
  } | {
130
130
  readonly type: "input_text";
@@ -374,8 +374,8 @@ export declare const streamRequest: (request: LLMRequest, options?: StreamOption
374
374
  } | {
375
375
  readonly id: string;
376
376
  readonly type: "tool-error";
377
- readonly name: string;
378
377
  readonly message: string;
378
+ readonly name: string;
379
379
  readonly error?: unknown;
380
380
  readonly providerMetadata?: {
381
381
  readonly [x: string]: {
@@ -1,7 +1,7 @@
1
1
  import { Cause, Effect, Layer, Option, Schema, Stream } from "effect";
2
2
  import { FetchHttpClient, Headers, HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse, } from "effect/unstable/http";
3
3
  import { HttpContext, HttpRateLimitDetails, AIError, TransportError } from "../schema/index.js";
4
- import { classifyProviderFailure } from "../provider-error.js";
4
+ import { classifyProviderFailure, providerErrorMessage } from "../provider-error.js";
5
5
  import { Service } from "./executor-service.js";
6
6
  export { Service } from "./executor-service.js";
7
7
  const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)]));
@@ -65,14 +65,18 @@ export const responseHttp = (response) => new HttpContext({
65
65
  status: response.status,
66
66
  headers: headerDetails(response.headers),
67
67
  });
68
- const decodeProviderBody = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Struct({
69
- message: Schema.optionalKey(Schema.String),
70
- error: Schema.optionalKey(Schema.Struct({ message: Schema.optionalKey(Schema.String) })),
71
- })));
68
+ const MAX_BODY_CHARS = 2000;
69
+ // Without a recognized message, show the raw body so the provider's explanation is never dropped.
72
70
  const providerMessage = (status, body) => {
73
- const decoded = body === undefined ? undefined : Option.getOrUndefined(decodeProviderBody(body));
74
- return ([decoded?.error?.message, decoded?.message].find((message) => message?.trim()) ??
75
- `Provider request failed with HTTP ${status}`);
71
+ const fallback = `Provider request failed with HTTP ${status}`;
72
+ const text = body?.trim() ?? "";
73
+ const message = providerErrorMessage(text);
74
+ if (message)
75
+ return message;
76
+ // Gateway and proxy HTML error pages are markup, not an explanation.
77
+ if (!text || /^<(?:!doctype|html)/i.test(text))
78
+ return fallback;
79
+ return `${fallback}: ${text.length > MAX_BODY_CHARS ? `${text.slice(0, MAX_BODY_CHARS)}…` : text}`;
76
80
  };
77
81
  const statusError = (response) => Effect.gen(function* () {
78
82
  if (response.status < 400)