@opencode/ai 2.0.18 → 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 (94) hide show
  1. package/README.md +24 -12
  2. package/dist/cache-policy.js +7 -0
  3. package/dist/experimental/evaluation.d.ts +7 -0
  4. package/dist/experimental/evaluation.js +2 -0
  5. package/dist/experimental/system-one.js +10 -7
  6. package/dist/generation.d.ts +1 -1
  7. package/dist/generation.js +23 -18
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/llm.d.ts +1 -1
  11. package/dist/promise.d.ts +3 -3
  12. package/dist/promise.js +4 -3
  13. package/dist/protocols/alibaba-chat.d.ts +8 -2
  14. package/dist/protocols/alibaba-responses.d.ts +14 -14
  15. package/dist/protocols/anthropic-messages.js +2 -15
  16. package/dist/protocols/bedrock-converse.d.ts +1 -1
  17. package/dist/protocols/bedrock-converse.js +38 -12
  18. package/dist/protocols/deepgram-speech.js +9 -7
  19. package/dist/protocols/deepgram-transcription.js +4 -10
  20. package/dist/protocols/elevenlabs-transcription.d.ts +28 -0
  21. package/dist/protocols/elevenlabs-transcription.js +137 -0
  22. package/dist/protocols/gemini.js +1 -10
  23. package/dist/protocols/google-speech.js +9 -2
  24. package/dist/protocols/google-transcription.js +4 -0
  25. package/dist/protocols/google-video.js +11 -2
  26. package/dist/protocols/meta-messages.d.ts +5 -1
  27. package/dist/protocols/meta-messages.js +11 -4
  28. package/dist/protocols/meta-responses.d.ts +16 -16
  29. package/dist/protocols/mistral-chat.d.ts +6 -0
  30. package/dist/protocols/mistral-chat.js +8 -5
  31. package/dist/protocols/open-responses.d.ts +31 -31
  32. package/dist/protocols/openai-chat.d.ts +53 -10
  33. package/dist/protocols/openai-chat.js +21 -8
  34. package/dist/protocols/openai-compatible-chat.d.ts +7 -2
  35. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  36. package/dist/protocols/openai-responses.d.ts +22 -22
  37. package/dist/protocols/openai-speech.js +6 -1
  38. package/dist/protocols/openai-transcription.js +1 -1
  39. package/dist/protocols/runway-video.js +2 -1
  40. package/dist/protocols/utils/claude-model.d.ts +8 -0
  41. package/dist/protocols/utils/claude-model.js +15 -0
  42. package/dist/protocols/utils/gemini-generate-content.d.ts +6 -0
  43. package/dist/protocols/utils/gemini-generate-content.js +33 -0
  44. package/dist/protocols/utils/media-input.d.ts +4 -3
  45. package/dist/protocols/utils/media-input.js +5 -4
  46. package/dist/protocols/utils/speaker-turns.d.ts +3 -0
  47. package/dist/protocols/utils/speaker-turns.js +9 -0
  48. package/dist/protocols/utils/speech-stream.d.ts +1 -0
  49. package/dist/protocols/utils/speech-stream.js +1 -0
  50. package/dist/protocols/utils/tool-stream.d.ts +4 -3
  51. package/dist/protocols/utils/tool-stream.js +1 -1
  52. package/dist/protocols/xai-responses.d.ts +14 -14
  53. package/dist/protocols/xai-video.js +7 -1
  54. package/dist/protocols/zai-chat.d.ts +8 -2
  55. package/dist/provider-error.d.ts +6 -0
  56. package/dist/provider-error.js +65 -2
  57. package/dist/providers/alibaba.d.ts +9 -4
  58. package/dist/providers/amazon-bedrock-mantle.d.ts +9 -4
  59. package/dist/providers/anthropic-compatible.js +3 -2
  60. package/dist/providers/azure.d.ts +11 -6
  61. package/dist/providers/baseten.d.ts +14 -4
  62. package/dist/providers/cerebras.d.ts +14 -4
  63. package/dist/providers/cloudflare-ai-gateway.d.ts +18 -8
  64. package/dist/providers/cloudflare-workers-ai.d.ts +14 -4
  65. package/dist/providers/deepinfra.d.ts +14 -4
  66. package/dist/providers/deepseek.d.ts +14 -4
  67. package/dist/providers/elevenlabs.d.ts +5 -0
  68. package/dist/providers/elevenlabs.js +4 -0
  69. package/dist/providers/fireworks.d.ts +14 -4
  70. package/dist/providers/google-vertex-chat.d.ts +7 -2
  71. package/dist/providers/google-vertex-responses.d.ts +2 -2
  72. package/dist/providers/groq.d.ts +15 -4
  73. package/dist/providers/meta.d.ts +14 -5
  74. package/dist/providers/minimax.d.ts +9 -4
  75. package/dist/providers/moonshot.d.ts +9 -4
  76. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  77. package/dist/providers/openai-compatible.d.ts +7 -2
  78. package/dist/providers/openai.d.ts +9 -4
  79. package/dist/providers/openrouter.d.ts +27 -6
  80. package/dist/providers/togetherai.d.ts +14 -4
  81. package/dist/providers/xai.d.ts +7 -2
  82. package/dist/providers/xai.js +3 -3
  83. package/dist/providers/zai-coding-plan.d.ts +9 -4
  84. package/dist/providers/zai.d.ts +7 -2
  85. package/dist/route/client.d.ts +1 -1
  86. package/dist/route/executor.js +12 -8
  87. package/dist/route/media-protocol.d.ts +13 -3
  88. package/dist/route/media-protocol.js +16 -6
  89. package/dist/route/media.js +18 -4
  90. package/dist/schema/events.d.ts +30 -30
  91. package/dist/testing.d.ts +8 -8
  92. package/dist/transcription.d.ts +1 -1
  93. package/dist/transcription.js +1 -1
  94. package/package.json +3 -3
@@ -68,12 +68,17 @@ export declare const route: Route<{
68
68
  readonly ttl?: string | undefined;
69
69
  } | undefined;
70
70
  readonly tool_calls?: readonly {
71
- readonly id: string;
72
- readonly type: "function";
73
71
  readonly function: {
74
72
  readonly name: string;
75
73
  readonly arguments: string;
76
74
  };
75
+ readonly id: string;
76
+ readonly type: "function";
77
+ readonly extra_content?: {
78
+ readonly google: {
79
+ readonly thought_signature: string;
80
+ };
81
+ } | undefined;
77
82
  }[] | undefined;
78
83
  readonly reasoning_details?: unknown;
79
84
  } | {
@@ -179,12 +184,17 @@ export declare const routes: Route<{
179
184
  readonly ttl?: string | undefined;
180
185
  } | undefined;
181
186
  readonly tool_calls?: readonly {
182
- readonly id: string;
183
- readonly type: "function";
184
187
  readonly function: {
185
188
  readonly name: string;
186
189
  readonly arguments: string;
187
190
  };
191
+ readonly id: string;
192
+ readonly type: "function";
193
+ readonly extra_content?: {
194
+ readonly google: {
195
+ readonly thought_signature: string;
196
+ };
197
+ } | undefined;
188
198
  }[] | undefined;
189
199
  readonly reasoning_details?: unknown;
190
200
  } | {
@@ -76,12 +76,17 @@ export declare const routes: (Route<{
76
76
  readonly ttl?: string | undefined;
77
77
  } | undefined;
78
78
  readonly tool_calls?: readonly {
79
- readonly id: string;
80
- readonly type: "function";
81
79
  readonly function: {
82
80
  readonly name: string;
83
81
  readonly arguments: string;
84
82
  };
83
+ readonly id: string;
84
+ readonly type: "function";
85
+ readonly extra_content?: {
86
+ readonly google: {
87
+ readonly thought_signature: string;
88
+ };
89
+ } | undefined;
85
90
  }[] | undefined;
86
91
  readonly reasoning_details?: unknown;
87
92
  } | {
@@ -13,13 +13,13 @@ const baseURL = "https://api.x.ai/v1";
13
13
  const RESPONSES_WEBSOCKET_ROTATE_AFTER_MS = 24 * 60 * 1000;
14
14
  const responsesRoute = Route.make({
15
15
  compact: { endpoint: XAIResponses.compact },
16
- id: "openai-responses",
16
+ id: "xai-responses",
17
17
  provider: id,
18
18
  providerMetadataKey: "xai",
19
19
  protocol: XAIResponses.protocol,
20
20
  endpoint: Endpoint.path("/responses", { baseURL }),
21
21
  transport: OpenResponsesChannel.transport({
22
- id: "openai-responses",
22
+ id: "xai-responses",
23
23
  name: "xAI Responses",
24
24
  rotateAfterMs: RESPONSES_WEBSOCKET_ROTATE_AFTER_MS,
25
25
  // xAI continues a chain only from stored responses: with `store: false` (the route default) `previous_response_id`
@@ -30,7 +30,7 @@ const responsesRoute = Route.make({
30
30
  defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
31
31
  });
32
32
  const chatRoute = Route.make({
33
- id: "openai-compatible-chat",
33
+ id: "xai-chat",
34
34
  provider: id,
35
35
  providerMetadataKey: "xai",
36
36
  protocol: OpenAIChat.protocol,
@@ -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";
@@ -240,12 +240,17 @@ export declare const routes: (Route<{
240
240
  readonly ttl?: string | undefined;
241
241
  } | undefined;
242
242
  readonly tool_calls?: readonly {
243
- readonly id: string;
244
- readonly type: "function";
245
243
  readonly function: {
246
244
  readonly name: string;
247
245
  readonly arguments: string;
248
246
  };
247
+ readonly id: string;
248
+ readonly type: "function";
249
+ readonly extra_content?: {
250
+ readonly google: {
251
+ readonly thought_signature: string;
252
+ };
253
+ } | undefined;
249
254
  }[] | undefined;
250
255
  readonly reasoning_details?: unknown;
251
256
  } | {
@@ -70,12 +70,17 @@ export declare const routes: Route<{
70
70
  readonly ttl?: string | undefined;
71
71
  } | undefined;
72
72
  readonly tool_calls?: readonly {
73
- readonly id: string;
74
- readonly type: "function";
75
73
  readonly function: {
76
74
  readonly name: string;
77
75
  readonly arguments: string;
78
76
  };
77
+ readonly id: string;
78
+ readonly type: "function";
79
+ readonly extra_content?: {
80
+ readonly google: {
81
+ readonly thought_signature: string;
82
+ };
83
+ } | undefined;
79
84
  }[] | undefined;
80
85
  readonly reasoning_details?: unknown;
81
86
  } | {
@@ -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)
@@ -3,7 +3,7 @@ import { HttpClientResponse } from "effect/unstable/http";
3
3
  import type { Snapshot, Status } from "../generation.js";
4
4
  import { Media } from "../media.js";
5
5
  import type { AuthInput } from "./auth.js";
6
- import { AIError, HttpContext, ProviderID } from "../schema/index.js";
6
+ import { AIError, AuthenticationError, HttpContext, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError } from "../schema/index.js";
7
7
  /** Array values become repeated parameters (`keyterm=a&keyterm=b`). */
8
8
  export type Query = Readonly<Record<string, string | ReadonlyArray<string>>>;
9
9
  /** `query` is appended to the endpoint URL before the route and caller `http.query` overlays. */
@@ -128,6 +128,14 @@ export interface Streamed<Request, Event, Frame, State> {
128
128
  readonly finish: (state: State, context: ResponseContext<Request>) => Effect.Effect<ReadonlyArray<Event>, AIError>;
129
129
  }
130
130
  export declare const stream: <Request, Event, Frame, State>(route: Identity, input: Omit<Streamed<Request, Event, Frame, State>, "kind" | "id" | "provider">) => Streamed<Request, Event, Frame, State>;
131
+ /** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
132
+ declare const FAILURES: {
133
+ InvalidRequest: typeof InvalidRequestError;
134
+ Authentication: typeof AuthenticationError;
135
+ RateLimit: typeof RateLimitError;
136
+ ProviderInternal: typeof ProviderInternalError;
137
+ };
138
+ export type Failure = keyof typeof FAILURES;
131
139
  /** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
132
140
  export declare const identity: (input: {
133
141
  readonly id: string;
@@ -141,7 +149,7 @@ export declare const identity: (input: {
141
149
  body: string;
142
150
  http: HttpContext;
143
151
  invalid: (message: string, cause?: unknown) => AIError;
144
- ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string) => AIError;
152
+ ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string, failure?: Failure) => AIError;
145
153
  pending: (id: string) => AIError;
146
154
  contentPolicy: (message: string) => AIError;
147
155
  }, AIError, never>;
@@ -150,7 +158,7 @@ export declare const identity: (input: {
150
158
  body: string;
151
159
  http: HttpContext;
152
160
  invalid: (message: string, cause?: unknown) => AIError;
153
- ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string) => AIError;
161
+ ended: (status: Exclude<Status, "queued" | "running" | "completed">, message: string, failure?: Failure) => AIError;
154
162
  pending: (id: string) => AIError;
155
163
  contentPolicy: (message: string) => AIError;
156
164
  }, AIError, never>;
@@ -167,6 +175,8 @@ export type Identity = ReturnType<typeof identity>;
167
175
  export type Output = Effect.Success<ReturnType<Identity["text"]>>;
168
176
  /** Map a provider status string through the protocol's table; unknown values are an invalid provider document. */
169
177
  export declare const status: <Table extends Record<string, Status>>(table: Table, raw: string, output: Output) => Effect.Effect<Status, AIError>;
178
+ /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
179
+ export declare const failure: (table: Readonly<Record<string, Failure>>, code: string | number | undefined) => Failure;
170
180
  /** A `url` asset whose provider-declared retention window starts now. */
171
181
  export declare const expiringUrl: (url: string, retention: Duration.Duration, options?: Parameters<typeof Media.url>[1]) => Effect.Effect<Media.Asset, never, never>;
172
182
  export * as MediaProtocol from "./media-protocol.js";
@@ -1,7 +1,7 @@
1
1
  import { Clock, Duration, Effect, Schema } from "effect";
2
2
  import { HttpClientResponse } from "effect/unstable/http";
3
3
  import { Media } from "../media.js";
4
- import { AIError, ContentPolicyError, HttpContext, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, UnsupportedOperationError, } from "../schema/index.js";
4
+ import { AIError, AuthenticationError, ContentPolicyError, HttpContext, InvalidProviderOutputError, InvalidRequestError, ProviderID, ProviderInternalError, RateLimitError, UnsupportedOperationError, } from "../schema/index.js";
5
5
  export const json = (value, query) => ({
6
6
  type: "json",
7
7
  value,
@@ -20,6 +20,13 @@ export const stream = (route, input) => ({ kind: "stream", id: route.id, provide
20
20
  // ---------------------------------------------------------------------------
21
21
  // Response helpers
22
22
  // ---------------------------------------------------------------------------
23
+ /** Reasons a provider can report for a `failed` generation; anything it does not classify is `ProviderInternal`. */
24
+ const FAILURES = {
25
+ InvalidRequest: InvalidRequestError,
26
+ Authentication: AuthenticationError,
27
+ RateLimit: RateLimitError,
28
+ ProviderInternal: ProviderInternalError,
29
+ };
23
30
  const context = (response) => new HttpContext({ url: response.request.url, status: response.status, headers: response.headers });
24
31
  /** One protocol's route id, display name, and provider, with the decoders and errors that carry them. */
25
32
  export const identity = (input) => {
@@ -27,9 +34,10 @@ export const identity = (input) => {
27
34
  const frameError = (message, body, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, cause }) });
28
35
  /**
29
36
  * Read a text body while retaining the original payload and HTTP context on every downstream error. `invalid` is a
30
- * malformed provider document; `ended` is a generation that reached a terminal status without output (`failed` is
31
- * provider-side, `cancelled`/`expired` mean the result will never exist); `pending` is a `result()` read before the
32
- * generation finished, which is caller misuse; `contentPolicy` is a moderated result.
37
+ * malformed provider document; `ended` is a generation that reached a terminal status without output (`failed`
38
+ * carries the provider's classification, defaulting to `ProviderInternal`; `cancelled`/`expired` mean the result
39
+ * will never exist); `pending` is a `result()` read before the generation finished, which is caller misuse;
40
+ * `contentPolicy` is a moderated result.
33
41
  */
34
42
  const text = Effect.fn("MediaProtocol.text")(function* (response) {
35
43
  const http = context(response);
@@ -45,9 +53,9 @@ export const identity = (input) => {
45
53
  body,
46
54
  http,
47
55
  invalid: (message, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, http, cause }) }),
48
- ended: (status, message) => new AIError({
56
+ ended: (status, message, failure = "ProviderInternal") => new AIError({
49
57
  reason: status === "failed"
50
- ? new ProviderInternalError({ message, body, http })
58
+ ? new FAILURES[failure]({ message, body, http })
51
59
  : new InvalidRequestError({ message, body, http }),
52
60
  }),
53
61
  pending: (id) => new AIError({
@@ -103,6 +111,8 @@ export const status = (table, raw, output) => {
103
111
  return Effect.fail(output.invalid(`Unknown generation status "${raw}"`));
104
112
  return Effect.succeed(table[raw]);
105
113
  };
114
+ /** Map a provider error code through the protocol's table; missing or unmapped codes are `ProviderInternal`. */
115
+ export const failure = (table, code) => code !== undefined && Object.hasOwn(table, code) ? table[code] : "ProviderInternal";
106
116
  /** A `url` asset whose provider-declared retention window starts now. */
107
117
  export const expiringUrl = (url, retention, options) => Clock.currentTimeMillis.pipe(Effect.map((now) => Media.url(url, { ...options, expiresAt: now + Duration.toMillis(retention) })));
108
118
  export * as MediaProtocol from "./media-protocol.js";
@@ -1,4 +1,4 @@
1
- import { Effect, Schema, Stream } from "effect";
1
+ import { Duration, Effect, Schedule, Schema, Stream } from "effect";
2
2
  import { Headers, HttpClientRequest } from "effect/unstable/http";
3
3
  import { Auth } from "./auth.js";
4
4
  import { Endpoint } from "./endpoint.js";
@@ -6,6 +6,7 @@ import { RequestExecutorService } from "./executor-service.js";
6
6
  import { RequestExecutor } from "./executor.js";
7
7
  import { MediaProtocol } from "./media-protocol.js";
8
8
  import { Generation, isTerminal } from "../generation.js";
9
+ import { isRetryable } from "../provider-error.js";
9
10
  import { AIError, AIErrorReason, HttpOptions, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeHttpOptions, } from "../schema/index.js";
10
11
  import { encodeJson } from "../utils/json.js";
11
12
  import { sanitizeSurrogates } from "../utils/sanitize.js";
@@ -35,6 +36,19 @@ export const inline = (input) => {
35
36
  }),
36
37
  };
37
38
  };
39
+ const READ_RETRY_MAX_DELAY = Duration.seconds(30);
40
+ /**
41
+ * Status and result reads retry transient failures; `start` and `cancel` never do. Gaps grow exponentially from 1s,
42
+ * jittered, up to 30s each, for at most 8 retries (about two minutes when every attempt fails), so a direct
43
+ * `Generation.result()` stays bounded; `await` and `events` also cut retries off at `poll.timeout`. A provider
44
+ * `retryAfterMs` raises the gap, still capped at 30s.
45
+ */
46
+ const READ_RETRY = Schedule.max([
47
+ Schedule.min([Schedule.exponential("1 second"), Schedule.spaced(READ_RETRY_MAX_DELAY)]),
48
+ Schedule.recurs(8),
49
+ ]).pipe(Schedule.jittered, Schedule.setInputType(), Schedule.modifyDelay(({ input, duration }) => Effect.succeed(Duration.min(input.reason._tag === "RateLimit" || input.reason._tag === "ProviderInternal"
50
+ ? Duration.max(duration, Duration.millis(input.reason.retryAfterMs ?? 0))
51
+ : duration, READ_RETRY_MAX_DELAY))));
38
52
  /**
39
53
  * Compose a queued media protocol the same way, adding `start`/`resume` handles whose polls reuse the route's auth,
40
54
  * deployment headers, and (for `start`) the request's `http` overlay. The token is decoded once at the boundary and
@@ -48,9 +62,9 @@ export const queued = (input) => {
48
62
  const encodeToken = Schema.encodeSync(protocol.token);
49
63
  const generationRoute = (token, http, execute) => {
50
64
  const materialize = (asset) => asset.materialize().pipe(Effect.provideService(RequestExecutorService, { execute }));
51
- const poll = (operation) => transport
52
- .call("GET", operation.path(token), http, execute)
53
- .pipe(Effect.flatMap((sent) => operation.decode(sent.response, { token, auth: sent.auth, materialize })));
65
+ // Only the GET exchange retries: a decoded terminal failure (`output.ended`) can be a `ProviderInternal` too, and
66
+ // re-reading it would spin until the caller's deadline.
67
+ const poll = (operation) => transport.call("GET", operation.path(token), http, execute).pipe(Effect.retry({ schedule: READ_RETRY, while: isRetryable }), Effect.flatMap((sent) => operation.decode(sent.response, { token, auth: sent.auth, materialize })));
54
68
  const status = poll(protocol.status);
55
69
  const cancel = protocol.cancel;
56
70
  const send = cancel === undefined
@@ -1266,8 +1266,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1266
1266
  } | {
1267
1267
  readonly id: string;
1268
1268
  readonly type: "tool-error";
1269
- readonly name: string;
1270
1269
  readonly message: string;
1270
+ readonly name: string;
1271
1271
  readonly error?: unknown;
1272
1272
  readonly providerMetadata?: {
1273
1273
  readonly [x: string]: {
@@ -1513,8 +1513,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1513
1513
  }> | Extract<{
1514
1514
  readonly id: string;
1515
1515
  readonly type: "tool-error";
1516
- readonly name: string;
1517
1516
  readonly message: string;
1517
+ readonly name: string;
1518
1518
  readonly error?: unknown;
1519
1519
  readonly providerMetadata?: {
1520
1520
  readonly [x: string]: {
@@ -1750,8 +1750,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1750
1750
  "tool-error": (u: unknown) => u is {
1751
1751
  readonly id: string;
1752
1752
  readonly type: "tool-error";
1753
- readonly name: string;
1754
1753
  readonly message: string;
1754
+ readonly name: string;
1755
1755
  readonly error?: unknown;
1756
1756
  readonly providerMetadata?: {
1757
1757
  readonly [x: string]: {
@@ -1983,8 +1983,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1983
1983
  "tool-error": (value: {
1984
1984
  readonly id: string;
1985
1985
  readonly type: "tool-error";
1986
- readonly name: string;
1987
1986
  readonly message: string;
1987
+ readonly name: string;
1988
1988
  readonly error?: unknown;
1989
1989
  readonly providerMetadata?: {
1990
1990
  readonly [x: string]: {
@@ -2199,8 +2199,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2199
2199
  } | {
2200
2200
  readonly id: string;
2201
2201
  readonly type: "tool-error";
2202
- readonly name: string;
2203
2202
  readonly message: string;
2203
+ readonly name: string;
2204
2204
  readonly error?: unknown;
2205
2205
  readonly providerMetadata?: {
2206
2206
  readonly [x: string]: {
@@ -2426,8 +2426,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2426
2426
  "tool-error": (value: {
2427
2427
  readonly id: string;
2428
2428
  readonly type: "tool-error";
2429
- readonly name: string;
2430
2429
  readonly message: string;
2430
+ readonly name: string;
2431
2431
  readonly error?: unknown;
2432
2432
  readonly providerMetadata?: {
2433
2433
  readonly [x: string]: {
@@ -2642,8 +2642,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2642
2642
  } | {
2643
2643
  readonly id: string;
2644
2644
  readonly type: "tool-error";
2645
- readonly name: string;
2646
2645
  readonly message: string;
2646
+ readonly name: string;
2647
2647
  readonly error?: unknown;
2648
2648
  readonly providerMetadata?: {
2649
2649
  readonly [x: string]: {
@@ -2871,8 +2871,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2871
2871
  "tool-error"?: ((value: {
2872
2872
  readonly id: string;
2873
2873
  readonly type: "tool-error";
2874
- readonly name: string;
2875
2874
  readonly message: string;
2875
+ readonly name: string;
2876
2876
  readonly error?: unknown;
2877
2877
  readonly providerMetadata?: {
2878
2878
  readonly [x: string]: {
@@ -3123,8 +3123,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3123
3123
  }> | Exclude<{
3124
3124
  readonly id: string;
3125
3125
  readonly type: "tool-error";
3126
- readonly name: string;
3127
3126
  readonly message: string;
3127
+ readonly name: string;
3128
3128
  readonly error?: unknown;
3129
3129
  readonly providerMetadata?: {
3130
3130
  readonly [x: string]: {
@@ -3344,8 +3344,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3344
3344
  } | {
3345
3345
  readonly id: string;
3346
3346
  readonly type: "tool-error";
3347
- readonly name: string;
3348
3347
  readonly message: string;
3348
+ readonly name: string;
3349
3349
  readonly error?: unknown;
3350
3350
  readonly providerMetadata?: {
3351
3351
  readonly [x: string]: {
@@ -3571,8 +3571,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3571
3571
  "tool-error"?: ((value: {
3572
3572
  readonly id: string;
3573
3573
  readonly type: "tool-error";
3574
- readonly name: string;
3575
3574
  readonly message: string;
3575
+ readonly name: string;
3576
3576
  readonly error?: unknown;
3577
3577
  readonly providerMetadata?: {
3578
3578
  readonly [x: string]: {
@@ -3823,8 +3823,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3823
3823
  }> | Exclude<{
3824
3824
  readonly id: string;
3825
3825
  readonly type: "tool-error";
3826
- readonly name: string;
3827
3826
  readonly message: string;
3827
+ readonly name: string;
3828
3828
  readonly error?: unknown;
3829
3829
  readonly providerMetadata?: {
3830
3830
  readonly [x: string]: {
@@ -4044,8 +4044,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
4044
4044
  } | {
4045
4045
  readonly id: string;
4046
4046
  readonly type: "tool-error";
4047
- readonly name: string;
4048
4047
  readonly message: string;
4048
+ readonly name: string;
4049
4049
  readonly error?: unknown;
4050
4050
  readonly providerMetadata?: {
4051
4051
  readonly [x: string]: {
@@ -4287,8 +4287,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
4287
4287
  toolError: (input: WithID<ToolError, ToolCallID>) => {
4288
4288
  readonly id: string;
4289
4289
  readonly type: "tool-error";
4290
- readonly name: string;
4291
4290
  readonly message: string;
4291
+ readonly name: string;
4292
4292
  readonly error?: unknown;
4293
4293
  readonly providerMetadata?: {
4294
4294
  readonly [x: string]: {
@@ -4535,8 +4535,8 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
4535
4535
  toolError: (u: unknown) => u is {
4536
4536
  readonly id: string;
4537
4537
  readonly type: "tool-error";
4538
- readonly name: string;
4539
4538
  readonly message: string;
4539
+ readonly name: string;
4540
4540
  readonly error?: unknown;
4541
4541
  readonly providerMetadata?: {
4542
4542
  readonly [x: string]: {
@@ -5249,8 +5249,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5249
5249
  } | {
5250
5250
  readonly id: string;
5251
5251
  readonly type: "tool-error";
5252
- readonly name: string;
5253
5252
  readonly message: string;
5253
+ readonly name: string;
5254
5254
  readonly error?: unknown;
5255
5255
  readonly providerMetadata?: {
5256
5256
  readonly [x: string]: {
@@ -5496,8 +5496,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5496
5496
  }> | Extract<{
5497
5497
  readonly id: string;
5498
5498
  readonly type: "tool-error";
5499
- readonly name: string;
5500
5499
  readonly message: string;
5500
+ readonly name: string;
5501
5501
  readonly error?: unknown;
5502
5502
  readonly providerMetadata?: {
5503
5503
  readonly [x: string]: {
@@ -5733,8 +5733,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5733
5733
  "tool-error": (u: unknown) => u is {
5734
5734
  readonly id: string;
5735
5735
  readonly type: "tool-error";
5736
- readonly name: string;
5737
5736
  readonly message: string;
5737
+ readonly name: string;
5738
5738
  readonly error?: unknown;
5739
5739
  readonly providerMetadata?: {
5740
5740
  readonly [x: string]: {
@@ -5966,8 +5966,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5966
5966
  "tool-error": (value: {
5967
5967
  readonly id: string;
5968
5968
  readonly type: "tool-error";
5969
- readonly name: string;
5970
5969
  readonly message: string;
5970
+ readonly name: string;
5971
5971
  readonly error?: unknown;
5972
5972
  readonly providerMetadata?: {
5973
5973
  readonly [x: string]: {
@@ -6182,8 +6182,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6182
6182
  } | {
6183
6183
  readonly id: string;
6184
6184
  readonly type: "tool-error";
6185
- readonly name: string;
6186
6185
  readonly message: string;
6186
+ readonly name: string;
6187
6187
  readonly error?: unknown;
6188
6188
  readonly providerMetadata?: {
6189
6189
  readonly [x: string]: {
@@ -6409,8 +6409,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6409
6409
  "tool-error": (value: {
6410
6410
  readonly id: string;
6411
6411
  readonly type: "tool-error";
6412
- readonly name: string;
6413
6412
  readonly message: string;
6413
+ readonly name: string;
6414
6414
  readonly error?: unknown;
6415
6415
  readonly providerMetadata?: {
6416
6416
  readonly [x: string]: {
@@ -6625,8 +6625,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6625
6625
  } | {
6626
6626
  readonly id: string;
6627
6627
  readonly type: "tool-error";
6628
- readonly name: string;
6629
6628
  readonly message: string;
6629
+ readonly name: string;
6630
6630
  readonly error?: unknown;
6631
6631
  readonly providerMetadata?: {
6632
6632
  readonly [x: string]: {
@@ -6854,8 +6854,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6854
6854
  "tool-error"?: ((value: {
6855
6855
  readonly id: string;
6856
6856
  readonly type: "tool-error";
6857
- readonly name: string;
6858
6857
  readonly message: string;
6858
+ readonly name: string;
6859
6859
  readonly error?: unknown;
6860
6860
  readonly providerMetadata?: {
6861
6861
  readonly [x: string]: {
@@ -7106,8 +7106,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7106
7106
  }> | Exclude<{
7107
7107
  readonly id: string;
7108
7108
  readonly type: "tool-error";
7109
- readonly name: string;
7110
7109
  readonly message: string;
7110
+ readonly name: string;
7111
7111
  readonly error?: unknown;
7112
7112
  readonly providerMetadata?: {
7113
7113
  readonly [x: string]: {
@@ -7327,8 +7327,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7327
7327
  } | {
7328
7328
  readonly id: string;
7329
7329
  readonly type: "tool-error";
7330
- readonly name: string;
7331
7330
  readonly message: string;
7331
+ readonly name: string;
7332
7332
  readonly error?: unknown;
7333
7333
  readonly providerMetadata?: {
7334
7334
  readonly [x: string]: {
@@ -7554,8 +7554,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7554
7554
  "tool-error"?: ((value: {
7555
7555
  readonly id: string;
7556
7556
  readonly type: "tool-error";
7557
- readonly name: string;
7558
7557
  readonly message: string;
7558
+ readonly name: string;
7559
7559
  readonly error?: unknown;
7560
7560
  readonly providerMetadata?: {
7561
7561
  readonly [x: string]: {
@@ -7806,8 +7806,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7806
7806
  }> | Exclude<{
7807
7807
  readonly id: string;
7808
7808
  readonly type: "tool-error";
7809
- readonly name: string;
7810
7809
  readonly message: string;
7810
+ readonly name: string;
7811
7811
  readonly error?: unknown;
7812
7812
  readonly providerMetadata?: {
7813
7813
  readonly [x: string]: {
@@ -8027,8 +8027,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
8027
8027
  } | {
8028
8028
  readonly id: string;
8029
8029
  readonly type: "tool-error";
8030
- readonly name: string;
8031
8030
  readonly message: string;
8031
+ readonly name: string;
8032
8032
  readonly error?: unknown;
8033
8033
  readonly providerMetadata?: {
8034
8034
  readonly [x: string]: {
@@ -8270,8 +8270,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
8270
8270
  toolError: (input: WithID<ToolError, ToolCallID>) => {
8271
8271
  readonly id: string;
8272
8272
  readonly type: "tool-error";
8273
- readonly name: string;
8274
8273
  readonly message: string;
8274
+ readonly name: string;
8275
8275
  readonly error?: unknown;
8276
8276
  readonly providerMetadata?: {
8277
8277
  readonly [x: string]: {
@@ -8518,8 +8518,8 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
8518
8518
  toolError: (u: unknown) => u is {
8519
8519
  readonly id: string;
8520
8520
  readonly type: "tool-error";
8521
- readonly name: string;
8522
8521
  readonly message: string;
8522
+ readonly name: string;
8523
8523
  readonly error?: unknown;
8524
8524
  readonly providerMetadata?: {
8525
8525
  readonly [x: string]: {