@opencode/ai 0.0.0-dev-177 → 0.0.0-dev-187

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 (65) hide show
  1. package/README.md +13 -58
  2. package/dist/image-client.d.ts +45 -0
  3. package/dist/index.d.ts +36 -19
  4. package/dist/index.js +13 -2
  5. package/dist/media-client.d.ts +1 -0
  6. package/dist/media-client.js +1 -0
  7. package/dist/provider-error.js +0 -2
  8. package/dist/providers/digitalocean/responses.d.ts +4 -0
  9. package/dist/providers/digitalocean/responses.js +1 -0
  10. package/dist/providers/digitalocean.d.ts +206 -4
  11. package/dist/providers/digitalocean.js +17 -6
  12. package/dist/providers/index.d.ts +0 -4
  13. package/dist/providers/index.js +0 -4
  14. package/dist/providers/openrouter/responses.d.ts +4 -0
  15. package/dist/providers/openrouter/responses.js +1 -0
  16. package/dist/providers/openrouter.d.ts +207 -5
  17. package/dist/providers/openrouter.js +20 -11
  18. package/dist/providers/venice/responses.d.ts +4 -0
  19. package/dist/providers/venice/responses.js +1 -0
  20. package/dist/providers/venice.d.ts +206 -4
  21. package/dist/providers/venice.js +33 -17
  22. package/dist/route/auth.d.ts +1 -1
  23. package/dist/route/media-protocol.d.ts +2 -4
  24. package/dist/route/media.d.ts +1 -1
  25. package/dist/route/media.js +2 -4
  26. package/dist/speech-client.d.ts +48 -0
  27. package/dist/testing/decision.d.ts +16 -0
  28. package/dist/testing/decision.js +20 -0
  29. package/dist/testing/image.d.ts +14 -0
  30. package/dist/testing/image.js +12 -0
  31. package/dist/testing/media.d.ts +18 -0
  32. package/dist/testing/media.js +36 -0
  33. package/dist/testing/script.d.ts +28 -0
  34. package/dist/testing/script.js +60 -0
  35. package/dist/testing/speech.d.ts +14 -0
  36. package/dist/testing/speech.js +12 -0
  37. package/dist/testing/transcription.d.ts +14 -0
  38. package/dist/testing/transcription.js +12 -0
  39. package/dist/testing/video.d.ts +14 -0
  40. package/dist/testing/video.js +12 -0
  41. package/dist/testing.d.ts +10 -21
  42. package/dist/testing.js +11 -54
  43. package/dist/transcription-client.d.ts +64 -0
  44. package/dist/video-client.d.ts +41 -0
  45. package/package.json +14 -18
  46. package/dist/protocols/bfl-images.d.ts +0 -47
  47. package/dist/protocols/bfl-images.js +0 -155
  48. package/dist/protocols/fal-images.d.ts +0 -36
  49. package/dist/protocols/fal-images.js +0 -96
  50. package/dist/protocols/fal-video.d.ts +0 -29
  51. package/dist/protocols/fal-video.js +0 -73
  52. package/dist/protocols/replicate-images.d.ts +0 -28
  53. package/dist/protocols/replicate-images.js +0 -127
  54. package/dist/protocols/stability-images.d.ts +0 -44
  55. package/dist/protocols/stability-images.js +0 -131
  56. package/dist/protocols/utils/fal-queue.d.ts +0 -26
  57. package/dist/protocols/utils/fal-queue.js +0 -67
  58. package/dist/providers/black-forest-labs.d.ts +0 -21
  59. package/dist/providers/black-forest-labs.js +0 -23
  60. package/dist/providers/fal.d.ts +0 -24
  61. package/dist/providers/fal.js +0 -26
  62. package/dist/providers/replicate.d.ts +0 -21
  63. package/dist/providers/replicate.js +0 -17
  64. package/dist/providers/stability.d.ts +0 -23
  65. package/dist/providers/stability.js +0 -18
package/README.md CHANGED
@@ -206,7 +206,7 @@ const everything = AIClient.layerWith(logged) // or AI.make({ layer: logged })
206
206
  ## Venice AI
207
207
 
208
208
  `Venice` provides native Chat Completions with streaming tools and reasoning. `model` and `chat`
209
- select the same API; credentials default to `VENICE_API_KEY`.
209
+ select the same API, and `responses` selects its Responses API; credentials default to `VENICE_API_KEY`.
210
210
 
211
211
  ```ts
212
212
  import { LLM } from "@opencode/ai/effect"
@@ -235,8 +235,8 @@ signatures, including per-tool signatures. Venice's encrypted scalar trailers ar
235
235
  reasoning but retained in provider metadata for replay. Cache affinity uses `promptCacheKey`, and cache-write
236
236
  usage reads Venice's `cache_creation_input_tokens` field.
237
237
 
238
- The native package entrypoint is `@opencode/ai/providers/venice`. Image generation, embeddings, Responses, and
239
- client-side E2EE are not implemented by this provider.
238
+ The native package entrypoints are `@opencode/ai/providers/venice` and `@opencode/ai/providers/venice/responses`.
239
+ Image generation, embeddings, and client-side E2EE are not implemented by this provider.
240
240
 
241
241
  ## Decisions
242
242
 
@@ -707,11 +707,6 @@ table before swapping only the `model`:
707
707
  | Z.ai | ✗ | width × height | width × height | ✗ | `size` |
708
708
  | Alibaba | ✓ | width × height | width × height | ✓ | `size`, `seed` |
709
709
  | MiniMax | ✓ | preset or w × h⁴ | preset or w × h⁴ | 1 (portrait subject) | `aspect_ratio`, `width`, `height`, `seed` |
710
- | Black Forest Labs | 1 | per model | width × height models | per model (1–8) | `width`, `height`, `seed`, `output_format`, `mask` |
711
- | fal | ✓ | per model | per model | 1 (several on `/edit`, `/multi`) | `image_size`, `seed`, `output_format`, `mask` |
712
- | Replicate | ✗ | ✗ | ✗ | ✗ (use `providerOptions`) | everything |
713
- | Stability `image` | 1 | ✓ | ✗ | 1 (not on `core`) | `seed`, `output_format` |
714
- | Stability `upscale()` | ✗ | ✗ | ✗ | exactly 1 (required) | `seed`, `output_format` |
715
710
  | Vercel AI Gateway | ✓ | as OpenAI³ | as OpenAI³ | per model | as OpenAI |
716
711
  | Cloudflare Workers AI | 1 | width × height² | width × height² | ✗ | `width`, `height`, `seed` |
717
712
 
@@ -756,7 +751,7 @@ returns a ref yet, and `asset.bytes()` / `materialize()` on a ref fail by design
756
751
  image inputs, avoiding ambiguity between base64, URLs, and provider IDs. Empty or omitted `images` uses text-to-image generation; a
757
752
  non-empty array selects the provider's edit behavior (see the table above for routes that limit the count). OpenAI
758
753
  uses multipart for byte/data-URL edits and its JSON reference body for URL or file-ID edits. Inpainting is a
759
- provider option on the routes that support it (OpenAI, fal, and BFL `flux-pro-1.0-fill`):
754
+ provider option on the routes that support it (OpenAI):
760
755
 
761
756
  ```ts
762
757
  const inpainted = Image.generate({
@@ -890,49 +885,6 @@ const previews = Image.stream({
890
885
 
891
886
  The provider may send fewer previews than requested when the final image is ready first.
892
887
 
893
- ### Queued image providers
894
-
895
- Black Forest Labs, fal, Replicate, and Stability's creative upscaler are submit-then-poll routes. `Image.generate`
896
- and `Image.stream` poll for you (pass `{ poll }` to tune the interval and timeout); `Image.start` returns a
897
- `Generation` whose `token` is serializable JSON for `Image.resume` in another process:
898
-
899
- ```ts
900
- import { BlackForestLabs, Stability } from "@opencode/ai/providers"
901
-
902
- const bfl = BlackForestLabs.configure({ apiKey: process.env.BFL_API_KEY })
903
-
904
- const submit = Effect.gen(function* () {
905
- const generation = yield* Image.start({ model: bfl.image("flux-2-pro"), prompt, aspect: "4:3" })
906
- persist({ provider: "black-forest-labs", modelID: "flux-2-pro", token: generation.token })
907
- })
908
-
909
- const finish = Effect.gen(function* () {
910
- const saved = load()
911
- const resumed = yield* Image.resume(bfl.image(saved.modelID), saved.token)
912
- return yield* resumed.await({ poll: { interval: "2 seconds" } })
913
- })
914
- ```
915
-
916
- The token carries no route identity, so persist the provider and model ID alongside it: `resume` needs the model.
917
-
918
- - **Black Forest Labs** — results are downloaded before returning, because `result.sample` expires in 10 minutes.
919
- - **Replicate** — inputs are model-defined, so only `prompt` lowers: sizing, count, seed, format, and files go in
920
- `providerOptions` under the model's names, with files as `Media.Asset` (data URLs up to 256 KB, larger by URL).
921
- Outputs are removed an hour after the prediction completes. `Prefer: wait=60` in `headers` or `http.headers` holds
922
- the submission open so a fast prediction costs one result read.
923
- - **Stability** — `stability.image(id)` generates inline; `stability.upscale()` is the creative upscaler, queued:
924
-
925
- ```ts
926
- const stability = Stability.configure({ apiKey: process.env.STABILITY_API_KEY })
927
- const upscaled = Effect.gen(function* () {
928
- const small = yield* Media.file("./small.png")
929
- return yield* Image.generate(
930
- { model: stability.upscale(), prompt: "A lighthouse", images: [small] },
931
- { poll: { interval: "5 seconds" } },
932
- )
933
- })
934
- ```
935
-
936
888
  Imagen is not available: Google shut it down on the Gemini API, and Vertex discontinued the Imagen 4 models on
937
889
  2026-06-30. `Google.image(...)` uses Gemini-native image models.
938
890
 
@@ -957,7 +909,7 @@ The hosted result is represented as a provider-executed tool call and a tool res
957
909
  ## Video generation
958
910
 
959
911
  Video mirrors `Image` with one difference: every provider is asynchronous, so the route is a submit-then-poll
960
- `Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, `Fal`, and `Runway` facades.
912
+ `Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, and `Runway` facades.
961
913
  Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`, `resolution`, `audio`, `n`, `seed`,
962
914
  `negativePrompt`) lower natively or fail with a typed `AIError` before any network call; provider-native controls live
963
915
  under `providerOptions`, inferred from the selected model.
@@ -992,7 +944,7 @@ const controlled = Effect.gen(function* () {
992
944
  const generation = yield* Video.start({ model: google.video("veo-3.1-generate-preview"), prompt })
993
945
  generation.id // provider operation / task / request id
994
946
  generation.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
995
- generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, `{ taskID }`, or fal's follow-up URLs
947
+ generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, or `{ taskID }`
996
948
  // The token carries no route identity: persist the provider and model ID alongside it, since `resume` needs the model.
997
949
  const saved = JSON.stringify(generation.token)
998
950
 
@@ -1022,9 +974,6 @@ Provider notes:
1022
974
  download, which the returned asset holds transiently (see above).
1023
975
  - **xAI** sends a `video` input to `/videos/edits`, or `/videos/extensions` with `providerOptions.mode: "extend"`.
1024
976
  `seed` and `negativePrompt` are not supported.
1025
- - **fal** endpoints are model-specific: `durationSeconds`, `references`, and `frames.last` fail typed and belong in
1026
- `providerOptions` under the model's own names (`duration: "8s"`, `end_image_url`, …). Auth is
1027
- `Authorization: Key <FAL_KEY>`.
1028
977
  - **Runway** expects pixel ratios in `aspect` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
1029
978
  `usage: { type: "credits" }`, and its output URLs expire after 24–48 hours.
1030
979
 
@@ -1218,7 +1167,7 @@ Everything below is exported from `@opencode/ai/effect` unless noted.
1218
1167
  - **`Transcription.request` / `generate` / `stream` / `start` / `resume`** — speech-to-text over inline, streaming, and queued routes; `TranscriptionClient` is its Effect service and layer.
1219
1168
  - **`Decision.request` / `Decision.generate`** — typed predicate, choice, and score questions over text, JSON, and media input; `DecisionClient` is its Effect service and layer.
1220
1169
  - **`AIClient.layer` / `AIClient.layerWith(executor)`** — every modality client plus the request executor in one layer.
1221
- - **`@opencode/ai`** (Promise root) — `AI.make({ layer? })` and a default `ai` client exposing `llm`, `image`, `video`, `speech`, `transcription`, and `decision` as Promise / `AsyncIterable` APIs, `run(effect)` for any package Effect, plus `file`, `write`, `bytes`, `base64`, and `materialize` for assets.
1170
+ - **`@opencode/ai`** (Promise root) — `AI.make({ layer?, clients? })` and a default `ai` client exposing `llm`, `image`, `video`, `speech`, `transcription`, and `decision` as Promise / `AsyncIterable` APIs, `run(effect)` for any package Effect, plus `file`, `write`, `bytes`, `base64`, and `materialize` for assets.
1222
1171
  - **`@opencode/ai/experimental`** — APIs that may still change: `Extraction` (typed values read out of text) and `Realtime` (`Realtime.connect` starts an OpenAI, xAI, or Gemini voice session and returns a WebRTC answer SDP or a short-lived WebSocket URL and token).
1223
1172
 
1224
1173
  ## Testing
@@ -1265,6 +1214,10 @@ For explicit compaction, script a `CompactionResponse` through `push`, `always`,
1265
1214
 
1266
1215
  For `compact(request, { mechanism: "trigger" })`, script a `CompactionCheckpointResponse` instead. It carries `checkpoint`, `responseID`, and optional `usage`. Endpoint and trigger calls reject each other's fixtures; both share the same queue, gates, lazy recording, and fallback controls.
1267
1216
 
1217
+ `TestImage`, `TestVideo`, `TestSpeech`, `TestTranscription`, and `TestDecision` follow the same pattern: `testLayer()` provides the modality's client and `Test`, with the same `push`, `always`, `serve`, `requests`, `wait`, and `gate` controls. Script an `ImageResponse` (or the modality's response) or an `AIError`. `stream` expands the response into its events, and `start` returns an already finished generation that `resume` accepts by token. Decision responses are returned as scripted, without checking the answers against the questions.
1218
+
1219
+ The Promise client accepts the same layers as `AI.make({ clients: TestImage.testLayer() })`; `ai.run(TestImage.Test.use(...))` reaches the controls.
1220
+
1268
1221
  The published legacy `Service`, `layer`, `clientLayer`, and module-level controls remain available as adapters
1269
1222
  over the same implementation, including the legacy live `requests` array. New tests should use `Test` and
1270
1223
  `testLayer`.
@@ -1291,6 +1244,8 @@ const compacted = Effect.gen(function* () {
1291
1244
  })
1292
1245
  ```
1293
1246
 
1247
+ From the Promise API, `await ai.llm.compact(request)` takes the same request and options (plus `signal`) and returns the same result.
1248
+
1294
1249
  `replacement` replaces the complete input window. Do not append it to the original transcript or extract only the encrypted item: the provider may retain additional messages in its output. Retained user and assistant messages remain ordinary messages with typed text, media, or reasoning parts, in their original order. Provider-specific message IDs, status, and phase use `providerMetadata`, not a raw output array hidden in an assistant message. Unsupported returned item types fail explicitly.
1295
1250
 
1296
1251
  The selected model carries explicit-compaction capability through request construction and updates. Calls using unsupported routes fail type checking. When the model is selected dynamically, narrow the request with `LLMClient.canCompact(request)` before calling `LLMClient.compact`; a model or route switch does not inherit the old capability. Runtime validation still rejects unsupported calls from untyped consumers. Capability describes the route's API, not whether every model or custom deployment supports the operation.
@@ -8,6 +8,51 @@ export declare class ImageClientService extends ImageClientService_base {
8
8
  export declare const Service: typeof ImageClientService;
9
9
  export type Service = ImageClientService;
10
10
  export declare const ImageClient: {
11
+ readonly responseEvents: (response: ImageResponse) => readonly ({
12
+ readonly type: "image-partial";
13
+ readonly index: number;
14
+ readonly image: import("./media.js").Asset;
15
+ } | {
16
+ readonly type: "image";
17
+ readonly index: number;
18
+ readonly image: import("./media.js").Asset;
19
+ } | {
20
+ readonly type: "generation-queued";
21
+ readonly id: string;
22
+ readonly position?: number | undefined;
23
+ } | {
24
+ readonly type: "generation-progress";
25
+ readonly id: string;
26
+ readonly progress?: number | undefined;
27
+ } | {
28
+ readonly type: "finish";
29
+ readonly usage?: {
30
+ readonly type: "seconds";
31
+ readonly seconds: number;
32
+ } | {
33
+ readonly type: "characters";
34
+ readonly characters: number;
35
+ } | {
36
+ readonly type: "credits";
37
+ readonly credits: number;
38
+ } | {
39
+ readonly type: "compute";
40
+ readonly seconds: number;
41
+ } | {
42
+ readonly type: "tokens";
43
+ readonly input?: number | undefined;
44
+ readonly output?: number | undefined;
45
+ readonly total?: number | undefined;
46
+ readonly details?: {
47
+ readonly [x: string]: unknown;
48
+ } | undefined;
49
+ } | undefined;
50
+ readonly providerMetadata?: {
51
+ readonly [x: string]: {
52
+ readonly [x: string]: unknown;
53
+ };
54
+ } | undefined;
55
+ })[];
11
56
  readonly layer: import("effect/Layer").Layer<ImageClientService, never, import("./route.js").RequestExecutorService>;
12
57
  readonly generate: (request: ImageRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<ImageResponse, import("./effect.js").AIError, ImageClientService>;
13
58
  readonly stream: (request: ImageRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
package/dist/index.d.ts CHANGED
@@ -5,8 +5,9 @@ import type { AwaitOptions, Event, Snapshot } from "./generation.js";
5
5
  import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./image.js";
6
6
  import { LLM } from "./effect.js";
7
7
  import { Media } from "./media.js";
8
+ import { type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type TriggerCompactOptions } from "./route/client.js";
8
9
  import { RequestExecutor } from "./route/executor.js";
9
- import { LanguageModel, type LLMRequest } from "./schema/index.js";
10
+ import { LanguageModel, type CompactionCheckpointResponse, type CompactionResponse, type LLMRequest } from "./schema/index.js";
10
11
  import type { GenerateObjectDynamicOptions, GenerateObjectOptions, GenerateObjectResponse, LoopInput, RequestInput } from "./llm.js";
11
12
  import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
12
13
  import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionRequestInput } from "./transcription.js";
@@ -17,9 +18,11 @@ import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./vi
17
18
  * transcription and decision clients over a request executor; every method runs the corresponding Effect API and rethrows
18
19
  * `AIError` unchanged. `file` and `write` load `node:fs/promises` on first use, so importing this module does not.
19
20
  */
20
- export interface Options {
21
+ export interface Options<R = never> {
21
22
  /** Executor layer; defaults to `RequestExecutor.fetchLayer`. Inject a recorder or `RequestExecutor.middleware(fn)` here. */
22
23
  readonly layer?: Layer.Layer<RequestExecutor.Service>;
24
+ /** Replaces default clients, for example with `TestImage.testLayer()`; its other services are available to `run`. */
25
+ readonly clients?: Layer.Layer<R>;
23
26
  }
24
27
  export interface RunOptions {
25
28
  readonly signal?: AbortSignal;
@@ -40,8 +43,8 @@ export type GenerationHandle<Response> = Snapshot & {
40
43
  readonly refresh: (options?: RunOptions) => Promise<GenerationHandle<Response>>;
41
44
  readonly cancel: (options?: RunOptions) => Promise<void>;
42
45
  };
43
- export declare const make: (options?: Options) => {
44
- run: <A, E>(effect: Effect.Effect<A, E, Services>, options?: RunOptions) => Promise<A>;
46
+ export declare const make: <R = never>(options?: Options<R>) => {
47
+ run: <A, E>(effect: Effect.Effect<A, E, Services | R>, options?: RunOptions) => Promise<A>;
45
48
  /** Decoded asset bytes, downloading `url` sources through the executor. */
46
49
  bytes: (asset: Media.Asset, options?: RunOptions) => Promise<Uint8Array<ArrayBufferLike>>;
47
50
  base64: (asset: Media.Asset, options?: RunOptions) => Promise<string>;
@@ -498,6 +501,11 @@ export declare const make: (options?: Options) => {
498
501
  <const Model extends LanguageModel, S extends ToolSchema<any>>(input: GenerateObjectOptions<S, Model>, options?: RunOptions): Promise<GenerateObjectResponse<Schema.Schema.Type<S>>>;
499
502
  <const Model extends LanguageModel>(input: GenerateObjectDynamicOptions<Model>, options?: RunOptions): Promise<GenerateObjectResponse<unknown>>;
500
503
  };
504
+ /** Compact a Responses request like `LLMClient.compact`: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
505
+ compact: {
506
+ (request: CheckpointRequest, options: TriggerCompactOptions & RunOptions): Promise<CompactionCheckpointResponse>;
507
+ (request: CompactionRequest, options?: EndpointCompactOptions & RunOptions): Promise<CompactionResponse>;
508
+ };
501
509
  };
502
510
  image: {
503
511
  request: typeof import("./image.js").request;
@@ -725,7 +733,7 @@ export declare const make: (options?: Options) => {
725
733
  };
726
734
  dispose: () => Promise<void>;
727
735
  };
728
- export type Client = ReturnType<typeof make>;
736
+ export type Client<R = never> = ReturnType<typeof make<R>>;
729
737
  /**
730
738
  * Promise counterpart of `Tool.make` for `ai.llm.loop`. A throw or rejection becomes the error result the model sees, the
731
739
  * returned value is sent unvalidated (`undefined` as `null`), and `signal` aborts when the loop is interrupted.
@@ -740,7 +748,7 @@ export declare const tool: <Parameters extends ToolSchema<any>>(config: {
740
748
  }) => Tool.ExecutableTool<Parameters, Schema.Unknown>;
741
749
  /** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
742
750
  export declare const ai: {
743
- run: <A, E>(effect: Effect.Effect<A, E, Services>, options?: RunOptions) => Promise<A>;
751
+ run: <A, E>(effect: Effect.Effect<A, E, import("./image-client.js").ImageClientService | import("./effect.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService>, options?: RunOptions) => Promise<A>;
744
752
  /** Decoded asset bytes, downloading `url` sources through the executor. */
745
753
  bytes: (asset: Media.Asset, options?: RunOptions) => Promise<Uint8Array<ArrayBufferLike>>;
746
754
  base64: (asset: Media.Asset, options?: RunOptions) => Promise<string>;
@@ -752,8 +760,12 @@ export declare const ai: {
752
760
  write: (asset: Media.Asset, path: string, options?: RunOptions) => Promise<void>;
753
761
  llm: {
754
762
  request: typeof LLM.request;
755
- generate: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: RunOptions) => Promise<import("./effect.js").LLMResponse>;
756
- stream: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: RunOptions) => AsyncIterable<{
763
+ generate: <const Model extends LanguageModel>(input: LLMRequest<LanguageModel<{
764
+ readonly [x: string]: unknown;
765
+ }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: RunOptions) => Promise<import("./effect.js").LLMResponse>;
766
+ stream: <const Model extends LanguageModel>(input: LLMRequest<LanguageModel<{
767
+ readonly [x: string]: unknown;
768
+ }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: RunOptions) => AsyncIterable<{
757
769
  readonly type: "step-start";
758
770
  readonly index: number;
759
771
  } | {
@@ -1197,11 +1209,16 @@ export declare const ai: {
1197
1209
  <const Model extends LanguageModel, S extends ToolSchema<any>>(input: GenerateObjectOptions<S, Model>, options?: RunOptions): Promise<GenerateObjectResponse<Schema.Schema.Type<S>>>;
1198
1210
  <const Model extends LanguageModel>(input: GenerateObjectDynamicOptions<Model>, options?: RunOptions): Promise<GenerateObjectResponse<unknown>>;
1199
1211
  };
1212
+ /** Compact a Responses request like `LLMClient.compact`: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
1213
+ compact: {
1214
+ (request: CheckpointRequest, options: TriggerCompactOptions & RunOptions): Promise<CompactionCheckpointResponse>;
1215
+ (request: CompactionRequest, options?: EndpointCompactOptions & RunOptions): Promise<CompactionResponse>;
1216
+ };
1200
1217
  };
1201
1218
  image: {
1202
1219
  request: typeof import("./image.js").request;
1203
- generate: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => Promise<import("./image.js").ImageResponse>;
1204
- stream: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1220
+ generate: <const Model extends ImageModel>(input: ImageRequest | ImageRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./image.js").ImageResponse>;
1221
+ stream: <const Model extends ImageModel>(input: ImageRequest | ImageRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1205
1222
  readonly type: "image-partial";
1206
1223
  readonly index: number;
1207
1224
  readonly image: Media.Asset;
@@ -1246,15 +1263,15 @@ export declare const ai: {
1246
1263
  };
1247
1264
  } | undefined;
1248
1265
  }>;
1249
- start: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
1266
+ start: <const Model extends ImageModel>(input: ImageRequest | ImageRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
1250
1267
  resume: (model: ImageModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
1251
1268
  };
1252
1269
  video: {
1253
1270
  request: typeof import("./video.js").request;
1254
- start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1255
- generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
1271
+ start: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1272
+ generate: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
1256
1273
  resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1257
- stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1274
+ stream: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1258
1275
  readonly type: "video";
1259
1276
  readonly index: number;
1260
1277
  readonly video: Media.Asset;
@@ -1298,8 +1315,8 @@ export declare const ai: {
1298
1315
  };
1299
1316
  speech: {
1300
1317
  request: typeof import("./speech.js").request;
1301
- generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
1302
- stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => AsyncIterable<{
1318
+ generate: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
1319
+ stream: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => AsyncIterable<{
1303
1320
  readonly type: "audio-delta";
1304
1321
  readonly chunk: Uint8Array<ArrayBufferLike>;
1305
1322
  } | {
@@ -1350,8 +1367,8 @@ export declare const ai: {
1350
1367
  };
1351
1368
  transcription: {
1352
1369
  request: typeof import("./transcription.js").request;
1353
- generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
1354
- stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1370
+ generate: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
1371
+ stream: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1355
1372
  readonly type: "text-delta";
1356
1373
  readonly delta: string;
1357
1374
  } | {
@@ -1415,7 +1432,7 @@ export declare const ai: {
1415
1432
  } | undefined;
1416
1433
  readonly type: "finish";
1417
1434
  }>;
1418
- start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1435
+ start: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1419
1436
  resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1420
1437
  };
1421
1438
  decision: {
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ import { Decision } from "./decision.js";
4
4
  import { Image } from "./image.js";
5
5
  import { LLM } from "./effect.js";
6
6
  import { Media } from "./media.js";
7
+ import { LLMClient, } from "./route/client.js";
7
8
  import { RequestExecutor } from "./route/executor.js";
8
- import { AIError, InvalidRequestError, LanguageModel } from "./schema/index.js";
9
+ import { AIError, InvalidRequestError, LanguageModel, } from "./schema/index.js";
9
10
  import { Speech } from "./speech.js";
10
11
  import { Transcription, } from "./transcription.js";
11
12
  import { Tool, ToolFailure } from "./tool.js";
@@ -24,13 +25,21 @@ const abortEffect = (signal) => signal === undefined
24
25
  return Effect.sync(() => signal.removeEventListener("abort", onAbort));
25
26
  });
26
27
  export const make = (options = {}) => {
27
- const runtime = ManagedRuntime.make(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer));
28
+ const runtime = ManagedRuntime.make(Layer.merge(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer),
29
+ // `R` is only inferred from `clients`, so it is `never` whenever `clients` is omitted.
30
+ (options.clients ?? Layer.empty)));
28
31
  /** Run any package Effect (for example `LLMClient.compact(...)`) inside this runtime. */
29
32
  const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
30
33
  const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
31
34
  function generateObject(input, options) {
32
35
  return run("schema" in input ? LLM.generateObject(input) : LLM.generateObject(input), options);
33
36
  }
37
+ // The overloads pair each request type with its mechanism; `LLMClient.compact` checks the route's capability at runtime.
38
+ function compact(request, options) {
39
+ return options?.mechanism === "trigger"
40
+ ? run(LLMClient.compact(request, options), options)
41
+ : run(LLMClient.compact(request, options), options);
42
+ }
34
43
  const handle = (generation) => ({
35
44
  ...generation.snapshot,
36
45
  token: generation.token,
@@ -74,6 +83,8 @@ export const make = (options = {}) => {
74
83
  loop: (input, options) => iterate(LLM.loop(input), options),
75
84
  /** Decode the model's output against `schema` (or `jsonSchema`, unvalidated) like `LLM.generateObject`. */
76
85
  generateObject,
86
+ /** Compact a Responses request like `LLMClient.compact`: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
87
+ compact,
77
88
  },
78
89
  image: {
79
90
  request: Image.request,
@@ -22,6 +22,7 @@ export declare const make: <Self, Req extends RoutedRequest<Req, Event, Response
22
22
  /** A completed response expanded into the streaming event shape. */
23
23
  readonly responseEvents: (response: Response) => ReadonlyArray<Event>;
24
24
  }) => {
25
+ responseEvents: (response: Response) => ReadonlyArray<Event>;
25
26
  layer: Layer.Layer<Self, never, RequestExecutor.RequestExecutorService>;
26
27
  generate: (request: Req, options?: AwaitOptions) => Effect.Effect<Response, AIError, Self>;
27
28
  stream: (request: Req, options?: AwaitOptions) => Stream.Stream<Event | Observation, AIError, Exclude<Self, import("effect/Scope").Scope>>;
@@ -4,6 +4,7 @@ import { RequestExecutor } from "./route/executor.js";
4
4
  import { AIError, UnsupportedOperationError } from "./schema/index.js";
5
5
  /** One modality's layer and service accessors, dispatching each request on its route's `kind`. */
6
6
  export const make = (service, input) => ({
7
+ responseEvents: input.responseEvents,
7
8
  layer: Layer.effect(service, Effect.gen(function* () {
8
9
  const executor = yield* RequestExecutor.Service;
9
10
  const notQueued = (route, operation) => new AIError({
@@ -263,8 +263,6 @@ function providerCodes(value) {
263
263
  decoded.code,
264
264
  ...awsErrorType(decoded.__type),
265
265
  ...awsErrorType(decoded.code),
266
- // Stability's `{ id, name, errors }` bodies carry the code in `name`.
267
- Array.isArray(decoded.errors) ? decoded.name : undefined,
268
266
  decoded.error_type,
269
267
  error?.code,
270
268
  error?.type,
@@ -0,0 +1,4 @@
1
+ import type { OpenResponsesProviderOptionsInput } from "../open-responses-options.js";
2
+ import type { DigitalOcean } from "../digitalocean.js";
3
+ export { responsesModel as model } from "../digitalocean.js";
4
+ export type Settings = DigitalOcean.Settings<OpenResponsesProviderOptionsInput>;
@@ -0,0 +1 @@
1
+ export { responsesModel as model } from "../digitalocean.js";