@opencode/ai 0.0.0-dev-465 → 0.0.0-dev-468

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +27 -16
  2. package/dist/cache-policy.d.ts +1 -1
  3. package/dist/cache-policy.js +2 -2
  4. package/dist/decision-client.d.ts +3 -3
  5. package/dist/decision.d.ts +13 -120
  6. package/dist/decision.js +17 -13
  7. package/dist/effect.d.ts +8 -6
  8. package/dist/effect.js +4 -3
  9. package/dist/effort-updates.d.ts +1 -1
  10. package/dist/effort-updates.js +2 -2
  11. package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
  12. package/dist/experimental/cloudflare-run-extraction.js +4 -1
  13. package/dist/experimental/extraction.d.ts +12 -38
  14. package/dist/experimental/extraction.js +13 -11
  15. package/dist/experimental.d.ts +8 -8
  16. package/dist/experimental.js +4 -4
  17. package/dist/image-client.d.ts +11 -5
  18. package/dist/image-client.js +1 -1
  19. package/dist/image.d.ts +21 -62
  20. package/dist/image.js +16 -13
  21. package/dist/index.d.ts +20 -14
  22. package/dist/index.js +6 -3
  23. package/dist/llm.d.ts +60 -25
  24. package/dist/llm.js +126 -38
  25. package/dist/protocols/alibaba-images.d.ts +2 -2
  26. package/dist/protocols/alibaba-messages.js +3 -3
  27. package/dist/protocols/anthropic-messages.d.ts +1 -1
  28. package/dist/protocols/anthropic-messages.js +4 -3
  29. package/dist/protocols/assemblyai-transcription.d.ts +2 -2
  30. package/dist/protocols/cartesia-speech.d.ts +2 -2
  31. package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
  32. package/dist/protocols/deepgram-speech.d.ts +2 -2
  33. package/dist/protocols/deepgram-transcription.d.ts +2 -2
  34. package/dist/protocols/elevenlabs-speech.d.ts +2 -2
  35. package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
  36. package/dist/protocols/gemini.js +2 -8
  37. package/dist/protocols/google-images.d.ts +2 -2
  38. package/dist/protocols/google-speech.d.ts +2 -2
  39. package/dist/protocols/google-transcription.d.ts +2 -2
  40. package/dist/protocols/google-video.d.ts +2 -2
  41. package/dist/protocols/meta-images.d.ts +2 -2
  42. package/dist/protocols/meta-responses.js +4 -3
  43. package/dist/protocols/minimax-images.d.ts +2 -2
  44. package/dist/protocols/open-responses.d.ts +1 -21
  45. package/dist/protocols/openai-chat.d.ts +1 -21
  46. package/dist/protocols/openai-chat.js +7 -9
  47. package/dist/protocols/openai-decisions.js +1 -1
  48. package/dist/protocols/openai-images.d.ts +2 -2
  49. package/dist/protocols/openai-responses.js +0 -1
  50. package/dist/protocols/openai-speech.d.ts +2 -2
  51. package/dist/protocols/openai-transcription.d.ts +2 -2
  52. package/dist/protocols/runway-video.d.ts +2 -2
  53. package/dist/protocols/shared.d.ts +1 -1
  54. package/dist/protocols/shared.js +2 -2
  55. package/dist/protocols/system-one.d.ts +4 -4
  56. package/dist/protocols/utils/responses-checkpoint.js +1 -1
  57. package/dist/protocols/utils/responses-compaction.d.ts +1 -1
  58. package/dist/protocols/utils/responses-compaction.js +4 -3
  59. package/dist/protocols/utils/tool-stream.d.ts +3 -63
  60. package/dist/protocols/xai-images.d.ts +2 -2
  61. package/dist/protocols/xai-video.d.ts +2 -2
  62. package/dist/protocols/zai-images.d.ts +2 -2
  63. package/dist/protocols/zai-messages.js +3 -3
  64. package/dist/provider-error.js +4 -4
  65. package/dist/providers/vercel-ai-gateway.js +4 -3
  66. package/dist/route/client.d.ts +43 -19
  67. package/dist/route/client.js +30 -18
  68. package/dist/route/decision.d.ts +6 -6
  69. package/dist/schema/errors.d.ts +1 -2
  70. package/dist/schema/errors.js +1 -2
  71. package/dist/schema/events.d.ts +61 -769
  72. package/dist/schema/events.js +3 -30
  73. package/dist/schema/messages.d.ts +20 -92
  74. package/dist/schema/messages.js +1 -52
  75. package/dist/speech-client.d.ts +5 -5
  76. package/dist/speech.d.ts +17 -19
  77. package/dist/speech.js +16 -12
  78. package/dist/testing.d.ts +8 -168
  79. package/dist/tool-runtime.js +12 -30
  80. package/dist/transcription-client.d.ts +5 -5
  81. package/dist/transcription.d.ts +17 -19
  82. package/dist/transcription.js +16 -12
  83. package/dist/video-client.d.ts +5 -5
  84. package/dist/video-client.js +1 -1
  85. package/dist/video.d.ts +18 -20
  86. package/dist/video.js +16 -12
  87. package/package.json +3 -3
@@ -1893,18 +1893,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
1893
1893
  readonly [x: string]: unknown;
1894
1894
  };
1895
1895
  } | undefined;
1896
- } | {
1897
- readonly type: "tool-error";
1898
- readonly id: string;
1899
- readonly name: string;
1900
- readonly namespace?: string | undefined;
1901
- readonly message: string;
1902
- readonly error?: unknown;
1903
- readonly providerMetadata?: {
1904
- readonly [x: string]: {
1905
- readonly [x: string]: unknown;
1906
- };
1907
- } | undefined;
1908
1896
  } | {
1909
1897
  readonly type: "step-finish";
1910
1898
  readonly index: number;
@@ -1929,6 +1917,7 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
1929
1917
  readonly explanation?: string | undefined;
1930
1918
  };
1931
1919
  readonly usage?: Usage | undefined;
1920
+ readonly message?: import("../schema/messages.js").Message | undefined;
1932
1921
  readonly providerMetadata?: {
1933
1922
  readonly [x: string]: {
1934
1923
  readonly [x: string]: unknown;
@@ -1942,15 +1931,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
1942
1931
  readonly [x: string]: unknown;
1943
1932
  };
1944
1933
  } | undefined;
1945
- } | {
1946
- readonly type: "provider-error";
1947
- readonly message: string;
1948
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
1949
- readonly providerMetadata?: {
1950
- readonly [x: string]: {
1951
- readonly [x: string]: unknown;
1952
- };
1953
- } | undefined;
1954
1934
  } | ({
1955
1935
  readonly type: "compaction";
1956
1936
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -95,7 +95,11 @@ const OpenRouterDetailFields = {
95
95
  signature: Schema.optional(Schema.NullOr(Schema.String)),
96
96
  };
97
97
  const ReasoningDetail = Schema.Union([
98
- Schema.StructWithRest(Schema.Struct({ type: Schema.Literal("reasoning.text"), text: Schema.optional(Schema.String), ...OpenRouterDetailFields }), [Schema.Record(Schema.String, Schema.Unknown)]),
98
+ Schema.StructWithRest(Schema.Struct({
99
+ type: Schema.Literal("reasoning.text"),
100
+ text: Schema.optional(Schema.String),
101
+ ...OpenRouterDetailFields,
102
+ }), [Schema.Record(Schema.String, Schema.Unknown)]),
99
103
  Schema.StructWithRest(Schema.Struct({
100
104
  type: Schema.Literal("reasoning.summary"),
101
105
  summary: Schema.optional(Schema.String),
@@ -526,10 +530,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
526
530
  if (pendingAttachments.length > 0) {
527
531
  messages.push({
528
532
  role: "user",
529
- content: [
530
- ...pendingAttachments.splice(0),
531
- { type: "text", text: part.text, cache_control: cacheControl },
532
- ],
533
+ content: [...pendingAttachments.splice(0), { type: "text", text: part.text, cache_control: cacheControl }],
533
534
  });
534
535
  continue;
535
536
  }
@@ -547,10 +548,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
547
548
  else if (previous?.role === "user" && Array.isArray(previous.content))
548
549
  messages[messages.length - 1] = {
549
550
  role: "user",
550
- content: [
551
- ...previous.content,
552
- { type: "text", text: part.text, cache_control: cacheControl },
553
- ],
551
+ content: [...previous.content, { type: "text", text: part.text, cache_control: cacheControl }],
554
552
  };
555
553
  else
556
554
  messages.push(cacheControl
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { DecisionResponse, DecisionUsage } from "../decision.js";
2
+ import { DecisionResponse, DecisionUsage, } from "../decision.js";
3
3
  import { DecisionRoute } from "../route/decision.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
5
  import { MediaProtocol } from "../route/media-protocol.js";
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "effect";
2
- import { ImageModel, type ImageRequestFor } from "../image.js";
2
+ import { ImageModel, type ImageRequest } from "../image.js";
3
3
  import { Media } from "../media.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
@@ -21,7 +21,7 @@ export type OpenAIImageOptions = {
21
21
  /** Previews sent before the final image when streaming (default 2); ignored by `Image.generate`. */
22
22
  readonly partialImages?: number;
23
23
  } & Record<string, unknown>;
24
- export type Request = ImageRequestFor<OpenAIImageOptions>;
24
+ export type Request = ImageRequest<ImageModel<OpenAIImageOptions>>;
25
25
  declare const Usage: Schema.Struct<{
26
26
  readonly input_tokens: Schema.optional<Schema.Number>;
27
27
  readonly output_tokens: Schema.optional<Schema.Number>;
@@ -6,7 +6,6 @@ import { Auth } from "../route/auth.js";
6
6
  import { Endpoint } from "../route/endpoint.js";
7
7
  import { Protocol } from "../route/protocol.js";
8
8
  import { HttpTransport } from "../route/transport/index.js";
9
- import { LLMRequest } from "../schema/index.js";
10
9
  import { requestTTL } from "../cache-policy.js";
11
10
  import { resolveEffortUpdates } from "../effort-updates.js";
12
11
  import { OpenResponses } from "./open-responses.js";
@@ -1,7 +1,7 @@
1
1
  import { MediaProtocol } from "../route/media-protocol.js";
2
2
  import { MediaRoute } from "../route/media.js";
3
3
  import { type MediaUsage } from "../schema/index.js";
4
- import { SpeechModel, type SpeechRequestFor } from "../speech.js";
4
+ import { SpeechModel, type SpeechRequest } from "../speech.js";
5
5
  import { SpeechStream } from "./utils/speech-stream.js";
6
6
  export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
7
7
  export declare const PATH = "/audio/speech";
@@ -10,7 +10,7 @@ export type OpenAISpeechOptions = {
10
10
  /** Defaults to `"sse"` in `stream` mode on models that support it; the merged value selects the response framing. */
11
11
  readonly stream_format?: "sse" | "audio";
12
12
  } & Record<string, unknown>;
13
- export type Request = SpeechRequestFor<OpenAISpeechOptions>;
13
+ export type Request = SpeechRequest<SpeechModel<OpenAISpeechOptions>>;
14
14
  interface State extends SpeechStream.Audio {
15
15
  readonly done: boolean;
16
16
  readonly usage?: MediaUsage;
@@ -1,7 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
- import { TranscriptionModel, type TranscriptionRequestFor, type TranscriptionSegment } from "../transcription.js";
4
+ import { TranscriptionModel, type TranscriptionRequest, type TranscriptionSegment } from "../transcription.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
6
6
  export declare const PATH = "/audio/transcriptions";
7
7
  export type OpenAITranscriptionOptions = {
@@ -17,7 +17,7 @@ export type OpenAITranscriptionOptions = {
17
17
  readonly known_speaker_references?: ReadonlyArray<string>;
18
18
  readonly temperature?: number;
19
19
  } & Record<string, unknown>;
20
- export type Request = TranscriptionRequestFor<OpenAITranscriptionOptions>;
20
+ export type Request = TranscriptionRequest<TranscriptionModel<OpenAITranscriptionOptions>>;
21
21
  declare const Transcript: Schema.Struct<{
22
22
  text: Schema.String;
23
23
  language: Schema.optional<Schema.String>;
@@ -2,7 +2,7 @@ import { Schema } from "effect";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
5
- import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
5
+ import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
6
6
  export declare const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
7
7
  /** Every Runway request must pin the API version. */
8
8
  export declare const API_VERSION = "2024-11-06";
@@ -21,7 +21,7 @@ export type RunwayVideoOptions = {
21
21
  };
22
22
  readonly outputFormat?: OpenString<"mp4" | "prores" | "png_sequence">;
23
23
  } & Record<string, unknown>;
24
- export type Request = VideoRequestFor<RunwayVideoOptions>;
24
+ export type Request = VideoRequest<VideoModel<RunwayVideoOptions>>;
25
25
  export declare const Token: Schema.Struct<{
26
26
  readonly taskID: Schema.String;
27
27
  }>;
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
2
2
  import { Effect, Schema } from "effect";
3
3
  import { Headers, HttpClientRequest } from "effect/http";
4
4
  import { Media } from "../media.js";
5
- import { AIError, LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
5
+ import { AIError, type LLMRequest, Message, ToolDefinition, type ContentPart, type MediaPart, type OpenString, type ProviderID, type RequestEncoding, type ToolEntry, type ToolResultPart } from "../schema/index.js";
6
6
  import { Json, decodeJson, encodeJson } from "../utils/json.js";
7
7
  import { isRecord } from "../utils/record.js";
8
8
  export { Json, decodeJson, encodeJson, isRecord };
@@ -2,7 +2,7 @@ import { Tool } from "@opencode/schema/tool";
2
2
  import { Effect, Option, Predicate, Schema, SchemaGetter, SchemaTransformation } from "effect";
3
3
  import { Headers, HttpClientRequest } from "effect/http";
4
4
  import { Media } from "../media.js";
5
- import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, LLMRequest, Message, ToolDefinition, } from "../schema/index.js";
5
+ import { InvalidProviderOutputError, InvalidRequestError, UnsupportedOperationError, AIError, Message, ToolDefinition, } from "../schema/index.js";
6
6
  import { Json, decodeJson, encodeJson } from "../utils/json.js";
7
7
  import { isRecord } from "../utils/record.js";
8
8
  export { Json, decodeJson, encodeJson, isRecord };
@@ -273,7 +273,7 @@ export const flattenToolRequest = (request) => {
273
273
  tools: flattenTools(request.tools),
274
274
  request: messages.every((message, index) => message === request.messages[index])
275
275
  ? request
276
- : LLMRequest.update(request, { messages }),
276
+ : { ...request, messages },
277
277
  };
278
278
  };
279
279
  export const matchToolChoice = (route, toolChoice, cases) => Effect.gen(function* () {
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { DecisionResponse, type DecisionModelCompatibility, type DecisionRequestFor } from "../decision.js";
2
+ import { DecisionResponse, type DecisionModelCompatibility, type DecisionRequest } from "../decision.js";
3
3
  import { DecisionRoute } from "../route/decision.js";
4
4
  import { AIError } from "../schema/index.js";
5
5
  export declare const DEFAULT_PATH = "/systemone";
@@ -33,7 +33,7 @@ export declare const Response: Schema.Struct<{
33
33
  }>;
34
34
  export type Response = Schema.Schema.Type<typeof Response>;
35
35
  /** The System One body without `model`; media goes where the model's `mediaInput` says, else `fallback`. */
36
- export declare const encodeBody: (request: DecisionRequestFor, fallback: MediaInput) => Effect.Effect<{
36
+ export declare const encodeBody: (request: DecisionRequest<import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>, import("../decision.js").DecisionQuestions>, fallback: MediaInput) => Effect.Effect<{
37
37
  questions: any;
38
38
  state: unknown;
39
39
  assets?: undefined;
@@ -49,7 +49,7 @@ export declare const encodeBody: (request: DecisionRequestFor, fallback: MediaIn
49
49
  };
50
50
  }, AIError, never>;
51
51
  /** Map System One's answers, keyed by question name, back to the request's question order. */
52
- export declare const toResponse: (data: Response, request: DecisionRequestFor, providerMetadataKey: string, invalid: (message: string) => AIError) => Effect.Effect<never, AIError, never> | Effect.Effect<DecisionResponse, never, never>;
52
+ export declare const toResponse: (data: Response, request: DecisionRequest, providerMetadataKey: string, invalid: (message: string) => AIError) => Effect.Effect<never, AIError, never> | Effect.Effect<DecisionResponse, never, never>;
53
53
  export declare const protocol: DecisionRoute.Protocol;
54
54
  /** TypeSafe's API, the reference System One host; other hosts change the endpoint and auth with `route.with(...)`. */
55
55
  export declare const route: DecisionRoute.Route;
@@ -79,7 +79,7 @@ export declare const SystemOne: {
79
79
  readonly provider: Schema.optional<Schema.String>;
80
80
  readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
81
81
  }>;
82
- readonly encodeBody: (request: DecisionRequestFor, fallback: MediaInput) => Effect.Effect<{
82
+ readonly encodeBody: (request: DecisionRequest<import("../decision.js").DecisionModel<import("../decision.js").DecisionOptions>, import("../decision.js").DecisionQuestions>, fallback: MediaInput) => Effect.Effect<{
83
83
  questions: any;
84
84
  state: unknown;
85
85
  assets?: undefined;
@@ -1,7 +1,7 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
2
  import { Route } from "../../route/client.js";
3
3
  import { Protocol } from "../../route/protocol.js";
4
- import { CompactionCheckpointResponse, LLMEvent, LLMRequest } from "../../schema/index.js";
4
+ import { CompactionCheckpointResponse, LLMEvent } from "../../schema/index.js";
5
5
  import { OpenResponses } from "../open-responses.js";
6
6
  import { ProviderShared } from "../shared.js";
7
7
  const onOutputItem = Effect.fnUntraced(function* (state, input) {
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { AIError, LLMRequest } from "../../schema/index.js";
2
+ import { AIError, type LLMRequest } from "../../schema/index.js";
3
3
  import type { CompactOperation } from "../../route/client.js";
4
4
  import { OpenResponses } from "../open-responses.js";
5
5
  export declare const make: (adapter: OpenResponses.ProviderAdapter, lowerTools: (request: LLMRequest) => Effect.Effect<ReadonlyArray<Record<string, unknown>>, AIError>) => CompactOperation;
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
- import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, HttpOptions, LLMRequest, Message, mergeJsonRecords, } from "../../schema/index.js";
2
+ import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, HttpOptions, Message, mergeJsonRecords, } from "../../schema/index.js";
3
3
  import { stripEffortUpdates } from "../../effort-updates.js";
4
4
  import { Endpoint } from "../../route/endpoint.js";
5
5
  import { RequestExecutor } from "../../route/executor.js";
@@ -79,9 +79,10 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
79
79
  const url = Endpoint.render(route.endpoint, { request, body: native });
80
80
  url.pathname = `${url.pathname.replace(/\/$/, "")}/compact`;
81
81
  const parts = yield* HttpTransport.jsonRequestParts({
82
- request: LLMRequest.update(request, {
82
+ request: {
83
+ ...request,
83
84
  http: request.http === undefined ? undefined : new HttpOptions({ ...request.http, body: undefined }),
84
- }),
85
+ },
85
86
  body,
86
87
  endpoint: Endpoint.path(url.toString()),
87
88
  auth: route.auth,
@@ -224,18 +224,6 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
224
224
  readonly [x: string]: unknown;
225
225
  };
226
226
  } | undefined;
227
- } | {
228
- readonly type: "tool-error";
229
- readonly id: string;
230
- readonly name: string;
231
- readonly namespace?: string | undefined;
232
- readonly message: string;
233
- readonly error?: unknown;
234
- readonly providerMetadata?: {
235
- readonly [x: string]: {
236
- readonly [x: string]: unknown;
237
- };
238
- } | undefined;
239
227
  } | {
240
228
  readonly type: "step-finish";
241
229
  readonly index: number;
@@ -260,6 +248,7 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
260
248
  readonly explanation?: string | undefined;
261
249
  };
262
250
  readonly usage?: import("../../schema/events.js").Usage | undefined;
251
+ readonly message?: import("../../schema/messages.js").Message | undefined;
263
252
  readonly providerMetadata?: {
264
253
  readonly [x: string]: {
265
254
  readonly [x: string]: unknown;
@@ -273,15 +262,6 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
273
262
  readonly [x: string]: unknown;
274
263
  };
275
264
  } | undefined;
276
- } | {
277
- readonly type: "provider-error";
278
- readonly message: string;
279
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
280
- readonly providerMetadata?: {
281
- readonly [x: string]: {
282
- readonly [x: string]: unknown;
283
- };
284
- } | undefined;
285
265
  } | ({
286
266
  readonly type: "compaction";
287
267
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -454,18 +434,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
454
434
  readonly [x: string]: unknown;
455
435
  };
456
436
  } | undefined;
457
- } | {
458
- readonly type: "tool-error";
459
- readonly id: string;
460
- readonly name: string;
461
- readonly namespace?: string | undefined;
462
- readonly message: string;
463
- readonly error?: unknown;
464
- readonly providerMetadata?: {
465
- readonly [x: string]: {
466
- readonly [x: string]: unknown;
467
- };
468
- } | undefined;
469
437
  } | {
470
438
  readonly type: "step-finish";
471
439
  readonly index: number;
@@ -490,6 +458,7 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
490
458
  readonly explanation?: string | undefined;
491
459
  };
492
460
  readonly usage?: import("../../schema/events.js").Usage | undefined;
461
+ readonly message?: import("../../schema/messages.js").Message | undefined;
493
462
  readonly providerMetadata?: {
494
463
  readonly [x: string]: {
495
464
  readonly [x: string]: unknown;
@@ -503,15 +472,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
503
472
  readonly [x: string]: unknown;
504
473
  };
505
474
  } | undefined;
506
- } | {
507
- readonly type: "provider-error";
508
- readonly message: string;
509
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
510
- readonly providerMetadata?: {
511
- readonly [x: string]: {
512
- readonly [x: string]: unknown;
513
- };
514
- } | undefined;
515
475
  } | ({
516
476
  readonly type: "compaction";
517
477
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -681,18 +641,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
681
641
  readonly [x: string]: unknown;
682
642
  };
683
643
  } | undefined;
684
- } | {
685
- readonly type: "tool-error";
686
- readonly id: string;
687
- readonly name: string;
688
- readonly namespace?: string | undefined;
689
- readonly message: string;
690
- readonly error?: unknown;
691
- readonly providerMetadata?: {
692
- readonly [x: string]: {
693
- readonly [x: string]: unknown;
694
- };
695
- } | undefined;
696
644
  } | {
697
645
  readonly type: "step-finish";
698
646
  readonly index: number;
@@ -717,6 +665,7 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
717
665
  readonly explanation?: string | undefined;
718
666
  };
719
667
  readonly usage?: import("../../schema/events.js").Usage | undefined;
668
+ readonly message?: import("../../schema/messages.js").Message | undefined;
720
669
  readonly providerMetadata?: {
721
670
  readonly [x: string]: {
722
671
  readonly [x: string]: unknown;
@@ -730,15 +679,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
730
679
  readonly [x: string]: unknown;
731
680
  };
732
681
  } | undefined;
733
- } | {
734
- readonly type: "provider-error";
735
- readonly message: string;
736
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
737
- readonly providerMetadata?: {
738
- readonly [x: string]: {
739
- readonly [x: string]: unknown;
740
- };
741
- } | undefined;
742
682
  } | ({
743
683
  readonly type: "compaction";
744
684
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -1,4 +1,4 @@
1
- import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
1
+ import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
@@ -11,7 +11,7 @@ export type XAIImageOptions = {
11
11
  readonly responseFormat?: OpenString<"url" | "b64_json">;
12
12
  readonly response_format?: OpenString<"url" | "b64_json">;
13
13
  } & Record<string, unknown>;
14
- export type Request = ImageRequestFor<XAIImageOptions>;
14
+ export type Request = ImageRequest<ImageModel<XAIImageOptions>>;
15
15
  /** xAI renders `1k` or `2k`; other tiers use the nearest one. */
16
16
  export declare const resolution: (request: {
17
17
  readonly resolution?: string;
@@ -1,7 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
- import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
4
+ import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://api.x.ai/v1";
6
6
  export declare const PATH = "/videos/generations";
7
7
  export declare const EDIT_PATH = "/videos/edits";
@@ -17,7 +17,7 @@ export type XAIVideoOptions = {
17
17
  readonly voice_id: string;
18
18
  }>;
19
19
  } & Record<string, unknown>;
20
- export type Request = VideoRequestFor<XAIVideoOptions>;
20
+ export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
21
21
  export declare const Token: Schema.Struct<{
22
22
  readonly requestID: Schema.String;
23
23
  }>;
@@ -1,4 +1,4 @@
1
- import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
1
+ import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
@@ -11,7 +11,7 @@ export type ZAIImageOptions = {
11
11
  readonly quality?: OpenString<"hd" | "standard">;
12
12
  readonly userID?: string;
13
13
  } & Record<string, unknown>;
14
- export type Request = ImageRequestFor<ZAIImageOptions>;
14
+ export type Request = ImageRequest<ImageModel<ZAIImageOptions>>;
15
15
  export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
16
16
  export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ZAIImageOptions>;
17
17
  export declare const ZAIImages: {
@@ -1,6 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
- import { LLMRequest } from "../schema/index.js";
4
3
  import { AnthropicMessages } from "./anthropic-messages.js";
5
4
  import { ProviderShared } from "./shared.js";
6
5
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
@@ -15,9 +14,10 @@ const Body = Schema.Struct({
15
14
  const fromRequest = Effect.fn("ZAIMessages.fromRequest")(function* (request) {
16
15
  const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
17
16
  // Z.AI accepts enabled thinking without Anthropic's mandatory token budget.
18
- const body = yield* AnthropicMessages.protocol.body.from(LLMRequest.update(request, {
17
+ const body = yield* AnthropicMessages.protocol.body.from({
18
+ ...request,
19
19
  providerOptions: { ...request.providerOptions, thinking: undefined },
20
- }));
20
+ });
21
21
  return { ...body, thinking: options.thinking };
22
22
  });
23
23
  export const protocol = Protocol.make({
@@ -1,5 +1,5 @@
1
1
  import { Option, Schema, SchemaGetter } from "effect";
2
- import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
2
+ import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
3
  import { Json } from "./utils/json.js";
4
4
  import { isRecord } from "./utils/record.js";
5
5
  const patterns = [
@@ -58,9 +58,9 @@ const exclusions = [
58
58
  export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
59
59
  (patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
60
60
  const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
61
- export const isContextOverflowFailure = (failure) => failure instanceof AIError
62
- ? failure.reason._tag === "InvalidRequest" && failure.reason.classification === "context-overflow"
63
- : Schema.is(ProviderErrorEvent)(failure) && failure.classification === "context-overflow";
61
+ export const isContextOverflowFailure = (failure) => failure instanceof AIError &&
62
+ failure.reason._tag === "InvalidRequest" &&
63
+ failure.reason.classification === "context-overflow";
64
64
  /**
65
65
  * Whether a failed call may succeed when sent again: rate limits, provider-side failures, transport failures that did
66
66
  * not deliver an accepted write, and unrecognized failures. Callers decide which calls are safe to repeat.
@@ -12,7 +12,7 @@ import { Route } from "../route/client.js";
12
12
  import { Endpoint } from "../route/endpoint.js";
13
13
  import { Framing } from "../route/framing.js";
14
14
  import { MediaRoute } from "../route/media.js";
15
- import { LLMRequest, ModelID, ProviderID, ProviderMetadata, ReasoningEffort, } from "../schema/index.js";
15
+ import { ModelID, ProviderID, ProviderMetadata, ReasoningEffort, } from "../schema/index.js";
16
16
  export const id = ProviderID.make("vercel-ai-gateway");
17
17
  const baseURL = "https://ai-gateway.vercel.sh/v1";
18
18
  const GatewayOptionsSchema = Schema.Struct({
@@ -44,13 +44,14 @@ const prepare = (api) => Effect.fnUntraced(function* (request) {
44
44
  return { request, body: { providerOptions } };
45
45
  const enabled = effort !== "none";
46
46
  const thinking = request.providerOptions?.thinking ?? { type: enabled ? "adaptive" : "disabled" };
47
- const next = LLMRequest.update(request, {
47
+ const next = {
48
+ ...request,
48
49
  providerOptions: {
49
50
  ...request.providerOptions,
50
51
  effort: enabled ? effort : undefined,
51
52
  thinking,
52
53
  },
53
- });
54
+ };
54
55
  return { request: next, body: { providerOptions } };
55
56
  }
56
57
  case "responses":
@@ -7,7 +7,8 @@ import { HttpTransport } from "./transport/index.js";
7
7
  import type { HttpMiddleware, Transport, TransportRuntime, WebSocketChannelExecutor } from "./transport/index.js";
8
8
  import type { Protocol } from "./protocol.js";
9
9
  import type { LanguageModelSanitizerCompatibility, ProtocolID, ProviderOptions } from "../schema/index.js";
10
- import { AIError, CompactionResponse, CompactionCheckpointResponse, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LLMEvent, ProviderID } from "../schema/index.js";
10
+ import type { LLMRequestInput } from "../llm.js";
11
+ import { AIError, CompactionResponse, CompactionCheckpointResponse, GenerationOptions, HttpOptions, LLMResponse, LanguageModel, LLMEvent, ProviderID, type LLMRequest } from "../schema/index.js";
11
12
  export interface RouteBody<Body> {
12
13
  /** Schema for the validated provider-native body sent as the JSON request. */
13
14
  readonly schema: Schema.Codec<Body, unknown>;
@@ -99,26 +100,49 @@ export interface EndpointCompactOptions extends Pick<StreamOptions, "http"> {
99
100
  export interface TriggerCompactOptions extends StreamOptions {
100
101
  readonly mechanism: "trigger";
101
102
  }
102
- export type CompactionRequest = LLMRequest & {
103
- readonly model: LanguageModel<ProviderOptions, {
104
- readonly endpoint: CompactOperation;
105
- }>;
103
+ type EndpointModel = LanguageModel<ProviderOptions, {
104
+ readonly endpoint: CompactOperation;
105
+ }>;
106
+ type TriggerModel = LanguageModel<ProviderOptions, {
107
+ readonly trigger: TriggerCompactOperation;
108
+ }>;
109
+ /** A text request whose model supports explicit compaction. */
110
+ export type CompactionRequest = LLMRequestInput & {
111
+ readonly model: EndpointModel;
106
112
  };
107
- export type CheckpointRequest = LLMRequest & {
108
- readonly model: LanguageModel<ProviderOptions, {
109
- readonly trigger: TriggerCompactOperation;
110
- }>;
113
+ /** A text request whose model supports trigger compaction checkpoints. */
114
+ export type CheckpointRequest = LLMRequestInput & {
115
+ readonly model: TriggerModel;
111
116
  };
112
117
  export interface CompactMethod<R = never> {
113
- (request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, R>;
114
- (request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, R>;
115
- }
116
- export declare function canCompact(request: LLMRequest, options?: {
117
- readonly mechanism?: "endpoint";
118
- }): request is CompactionRequest;
119
- export declare function canCompact(request: LLMRequest, options: {
118
+ (request: LLMRequest & {
119
+ readonly model: TriggerModel;
120
+ }, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, R>;
121
+ (request: LLMRequest & {
122
+ readonly model: EndpointModel;
123
+ }, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, R>;
124
+ }
125
+ /** Whether a model, or a text request's model, supports compaction through the given mechanism. */
126
+ export declare function canCompact<Model extends LanguageModel>(model: Model, options: {
120
127
  readonly mechanism: "trigger";
121
- }): request is CheckpointRequest;
128
+ }): model is Model & TriggerModel;
129
+ export declare function canCompact<Request extends {
130
+ readonly model: LanguageModel;
131
+ }>(request: Request, options: {
132
+ readonly mechanism: "trigger";
133
+ }): request is Request & {
134
+ readonly model: TriggerModel;
135
+ };
136
+ export declare function canCompact<Model extends LanguageModel>(model: Model, options?: {
137
+ readonly mechanism?: "endpoint";
138
+ }): model is Model & EndpointModel;
139
+ export declare function canCompact<Request extends {
140
+ readonly model: LanguageModel;
141
+ }>(request: Request, options?: {
142
+ readonly mechanism?: "endpoint";
143
+ }): request is Request & {
144
+ readonly model: EndpointModel;
145
+ };
122
146
  declare const LLMClientService_base: Context.ServiceClass<LLMClientService, "@opencode/LLMClient", Interface>;
123
147
  export declare class LLMClientService extends LLMClientService_base {
124
148
  }
@@ -213,8 +237,8 @@ export declare const generateWith: (stream: Interface["stream"]) => (request: LL
213
237
  }, CompactionOperations | undefined>>, options?: StreamOptions | undefined) => Effect.Effect<LLMResponse, AIError, never>;
214
238
  export declare function stream(request: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
215
239
  export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
216
- export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
217
- export declare function compact(request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, Service>;
240
+ /** Compact through the client for `options.mechanism`, failing typed when the request's route does not support it. */
241
+ export declare function compactRequest(request: LLMRequest, options?: EndpointCompactOptions | TriggerCompactOptions): Effect.Effect<CompactionResponse | CompactionCheckpointResponse, AIError, Service>;
218
242
  export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
219
243
  export declare const Route: {
220
244
  readonly make: typeof make;