@opencode/ai 2.2.0 → 2.2.2
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.
- package/README.md +66 -62
- package/dist/effect.d.ts +1 -1
- package/dist/effect.js +1 -1
- package/dist/image-client.d.ts +45 -0
- package/dist/image.d.ts +1 -0
- package/dist/index.d.ts +38 -20
- package/dist/index.js +14 -2
- package/dist/media-client.d.ts +1 -0
- package/dist/media-client.js +1 -0
- package/dist/protocols/alibaba-chat.d.ts +39 -4
- package/dist/protocols/alibaba-responses.d.ts +20 -3
- package/dist/protocols/google-images.js +3 -1
- package/dist/protocols/meta-responses.d.ts +40 -6
- package/dist/protocols/meta-responses.js +1 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +182 -27
- package/dist/protocols/open-responses.js +108 -36
- package/dist/protocols/openai-chat.d.ts +438 -46
- package/dist/protocols/openai-chat.js +121 -39
- package/dist/protocols/openai-compatible-chat.d.ts +35 -4
- package/dist/protocols/openai-compatible-responses.d.ts +20 -3
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +16 -1
- package/dist/protocols/openai-images.js +49 -17
- package/dist/protocols/openai-responses.d.ts +120 -18
- package/dist/protocols/openai-responses.js +17 -8
- package/dist/protocols/venice-chat.d.ts +39 -4
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +6 -0
- package/dist/protocols/xai-images.js +4 -5
- package/dist/protocols/xai-responses.d.ts +20 -3
- package/dist/protocols/xai-responses.js +2 -1
- package/dist/protocols/zai-chat.d.ts +39 -4
- package/dist/provider-error.js +5 -4
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba.d.ts +58 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +66 -11
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure.d.ts +79 -15
- package/dist/providers/baseten.d.ts +74 -12
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +73 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +113 -17
- package/dist/providers/cloudflare-workers-ai.d.ts +73 -11
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +73 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +73 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +73 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +320 -21
- package/dist/providers/digitalocean.js +18 -7
- package/dist/providers/fireworks.d.ts +73 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex-chat.d.ts +36 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +21 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +1 -1
- package/dist/providers/google.d.ts +2 -2
- package/dist/providers/google.js +1 -1
- package/dist/providers/groq.d.ts +77 -11
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +61 -12
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +63 -9
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +56 -8
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +21 -4
- package/dist/providers/openai-compatible.d.ts +38 -7
- package/dist/providers/openai-compatible.js +9 -2
- package/dist/providers/openai.d.ts +59 -11
- package/dist/providers/openai.js +4 -2
- package/dist/providers/opencode.d.ts +3 -3
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +356 -26
- package/dist/providers/openrouter.js +42 -13
- package/dist/providers/togetherai.d.ts +73 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai.d.ts +3 -3
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +242 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway.d.ts +8 -8
- package/dist/providers/vercel-ai-gateway.js +12 -2
- package/dist/providers/xai.d.ts +39 -8
- package/dist/providers/xai.js +1 -1
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +56 -8
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +37 -6
- package/dist/providers/zai.js +1 -1
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/media-protocol.d.ts +2 -4
- package/dist/route/media.d.ts +1 -1
- package/dist/route/media.js +2 -4
- package/dist/schema/events.d.ts +2 -0
- package/dist/schema/messages.d.ts +35 -1
- package/dist/schema/messages.js +20 -0
- package/dist/speech-client.d.ts +48 -0
- package/dist/speech.d.ts +1 -0
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +10 -21
- package/dist/testing.js +11 -54
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +64 -0
- package/dist/transcription.d.ts +1 -0
- package/dist/video-client.d.ts +41 -0
- package/dist/video.d.ts +1 -0
- package/package.json +24 -40
- package/dist/protocols/bfl-images.d.ts +0 -47
- package/dist/protocols/bfl-images.js +0 -155
- package/dist/protocols/fal-images.d.ts +0 -34
- package/dist/protocols/fal-images.js +0 -95
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -44
- package/dist/protocols/stability-images.js +0 -131
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
package/README.md
CHANGED
|
@@ -81,6 +81,27 @@ for await (const event of events) {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
### Freeform tools
|
|
85
|
+
|
|
86
|
+
A tool with exactly one required string parameter can set `freeform`, so the model writes that parameter as raw text
|
|
87
|
+
instead of JSON arguments: unconstrained `text`, or text matching a `regex` or `lark` grammar.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const run_code = AI.tool({
|
|
91
|
+
description: "Run JavaScript",
|
|
92
|
+
parameters: Schema.Struct({ code: Schema.String }),
|
|
93
|
+
freeform: { type: "lark", grammar: JS_GRAMMAR },
|
|
94
|
+
execute: ({ code }) => runCode(code),
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
OpenAI Responses and Chat Completions, and every provider that reuses them, send it as a
|
|
99
|
+
[custom tool](https://platform.openai.com/docs/guides/function-calling#custom-tools). Other protocols send the normal
|
|
100
|
+
JSON tool. Only set `freeform` for models that accept custom tools in that format; nothing checks this or falls back
|
|
101
|
+
to JSON, so an unsupported model returns the provider's error. Calls, tool input events, results and history always
|
|
102
|
+
use the `{ code }` object, and past calls replay the way the tool is declared in the current request, so the same
|
|
103
|
+
history works with or without `freeform`.
|
|
104
|
+
|
|
84
105
|
### Structured output
|
|
85
106
|
|
|
86
107
|
`generateObject` forces a tool call and decodes its input against `schema`; pass `jsonSchema` instead for an
|
|
@@ -185,7 +206,7 @@ const everything = AIClient.layerWith(logged) // or AI.make({ layer: logged })
|
|
|
185
206
|
## Venice AI
|
|
186
207
|
|
|
187
208
|
`Venice` provides native Chat Completions with streaming tools and reasoning. `model` and `chat`
|
|
188
|
-
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`.
|
|
189
210
|
|
|
190
211
|
```ts
|
|
191
212
|
import { LLM } from "@opencode/ai/effect"
|
|
@@ -214,8 +235,8 @@ signatures, including per-tool signatures. Venice's encrypted scalar trailers ar
|
|
|
214
235
|
reasoning but retained in provider metadata for replay. Cache affinity uses `promptCacheKey`, and cache-write
|
|
215
236
|
usage reads Venice's `cache_creation_input_tokens` field.
|
|
216
237
|
|
|
217
|
-
The native package
|
|
218
|
-
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.
|
|
219
240
|
|
|
220
241
|
## Decisions
|
|
221
242
|
|
|
@@ -565,7 +586,9 @@ M2.x models always think, even when a disabling option is supplied. For tool con
|
|
|
565
586
|
`response.message` in history before adding `Message.tool(...)` results; this preserves reasoning and any signatures.
|
|
566
587
|
|
|
567
588
|
The default API bases are `https://api.minimax.io/anthropic/v1` for Messages and `https://api.minimax.io/v1` for
|
|
568
|
-
Chat and
|
|
589
|
+
Chat, Responses and Images. `configure({ baseURL })` replaces the selected API's base, including its version prefix;
|
|
590
|
+
use `https://api.minimax.cn/v1` for the mainland China platform. `minimax.image("image-01")` (also
|
|
591
|
+
`@opencode/ai/providers/minimax/images`) generates images; see [MiniMax images](#minimax-images).
|
|
569
592
|
|
|
570
593
|
## Meta
|
|
571
594
|
|
|
@@ -678,17 +701,14 @@ table before swapping only the `model`:
|
|
|
678
701
|
| Provider | `n` | `aspect` | `resolution` | `images` | Moved to `providerOptions` |
|
|
679
702
|
| --------------------- | --- | -------------------- | --------------------- | -------------------------------- | -------------------------------------------------- |
|
|
680
703
|
| OpenAI | ✓¹ | nearest size | nearest size | ✓ | `size`, `outputFormat`, `mask` |
|
|
681
|
-
| Google (Gemini) | 1 | ✓ | ✓ (`
|
|
704
|
+
| Google (Gemini) | 1 | ✓ | ✓ (`0.5K` as `512`) | ✓ (no public URLs) | `seed` |
|
|
682
705
|
| xAI | ✓ | ✓ | `1k`/`2k` | ✓ | none |
|
|
683
706
|
| Meta | ✓ | ✓ (hint) | ignored | ✓ | `size`, `outputFormat` |
|
|
684
707
|
| Z.ai | ✗ | width × height | width × height | ✗ | `size` |
|
|
685
708
|
| Alibaba | ✓ | width × height | width × height | ✓ | `size`, `seed` |
|
|
686
|
-
|
|
|
687
|
-
| fal | ✓ | per model | per model | 1 (several on `/edit`, `/multi`) | `image_size`, `seed`, `output_format`, `mask` |
|
|
688
|
-
| Replicate | ✗ | ✗ | ✗ | ✗ (use `providerOptions`) | everything |
|
|
689
|
-
| Stability `image` | 1 | ✓ | ✗ | 1 (not on `core`) | `seed`, `output_format` |
|
|
690
|
-
| Stability `upscale()` | ✗ | ✗ | ✗ | exactly 1 (required) | `seed`, `output_format` |
|
|
709
|
+
| MiniMax | ✓ | preset or w × h⁴ | preset or w × h⁴ | 1 (portrait subject) | `aspect_ratio`, `width`, `height`, `seed` |
|
|
691
710
|
| Vercel AI Gateway | ✓ | as OpenAI³ | as OpenAI³ | per model | as OpenAI |
|
|
711
|
+
| OpenRouter | ✓ | ✓ (`aspect_ratio`) | tier⁵ | per model⁵ | `size`, `outputFormat` (no `mask`) |
|
|
692
712
|
| Cloudflare Workers AI | 1 | width × height² | width × height² | ✗ | `width`, `height`, `seed` |
|
|
693
713
|
|
|
694
714
|
✓ lowers natively; ✗ fails whenever the field is set (including `n: 1`); `1` means `n > 1` fails. "width × height"
|
|
@@ -698,7 +718,11 @@ fixed sizes. `providerOptions.size` replaces `aspect` and `resolution`, so setti
|
|
|
698
718
|
forwards `outputFormat` but does not apply it, so the returned bytes keep the upstream model's own format. ² Workers AI
|
|
699
719
|
`@cf/black-forest-labs/flux-1-schnell` takes no size, and the provider rejects it. ³ Non-OpenAI gateway models
|
|
700
720
|
(`bfl/flux-2-pro`) get a computed width × height, which the gateway passes through; models with a fixed list, such as
|
|
701
|
-
Recraft, reject sizes outside it.
|
|
721
|
+
Recraft, reject sizes outside it. Grok (`spacexai/*`, `xai/*`) ignores `size`, so it gets `providerOptions.xai`
|
|
722
|
+
`aspect_ratio` and `1k`/`2k` instead. ⁴ MiniMax sends its `aspect_ratio` preset for a preset aspect at about `1K` and an
|
|
723
|
+
exact width × height (512–2048 px, steps of 8) otherwise; `image-01-live` takes only the presets, minus `21:9`.
|
|
724
|
+
⁵ OpenRouter takes `512`, `768`, `1K`, `1.5K`, `2K` or `4K` rather than pixels; other values are left out. It has no
|
|
725
|
+
edits endpoint, so input images go to `/images/generations` as `input_references` (data URLs or http(s) URLs).
|
|
702
726
|
|
|
703
727
|
`Media.Asset` is the one asset type shared by image requests, image responses, LLM messages, and tool results.
|
|
704
728
|
`asset.source` is the serializable `Media.Source` (`bytes`, `base64`, `url`, or `ref`); `asset.bytes()`,
|
|
@@ -731,7 +755,7 @@ returns a ref yet, and `asset.bytes()` / `materialize()` on a ref fail by design
|
|
|
731
755
|
image inputs, avoiding ambiguity between base64, URLs, and provider IDs. Empty or omitted `images` uses text-to-image generation; a
|
|
732
756
|
non-empty array selects the provider's edit behavior (see the table above for routes that limit the count). OpenAI
|
|
733
757
|
uses multipart for byte/data-URL edits and its JSON reference body for URL or file-ID edits. Inpainting is a
|
|
734
|
-
provider option on the routes that support it (OpenAI
|
|
758
|
+
provider option on the routes that support it (OpenAI):
|
|
735
759
|
|
|
736
760
|
```ts
|
|
737
761
|
const inpainted = Image.generate({
|
|
@@ -770,7 +794,7 @@ const xai = Image.generate({
|
|
|
770
794
|
aspect: "16:9",
|
|
771
795
|
resolution: "1K",
|
|
772
796
|
providerOptions: {
|
|
773
|
-
responseFormat: "b64_json"
|
|
797
|
+
responseFormat: "url", // defaults to "b64_json" (inline bytes)
|
|
774
798
|
future_option: true,
|
|
775
799
|
},
|
|
776
800
|
http,
|
|
@@ -827,6 +851,26 @@ Z.ai does not include trustworthy MIME metadata for output URLs, so generated im
|
|
|
827
851
|
`application/octet-stream` until materialized. Output URLs expire after 30 days; call `asset.materialize()` and
|
|
828
852
|
persist the bytes promptly if they must remain available.
|
|
829
853
|
|
|
854
|
+
### MiniMax images
|
|
855
|
+
|
|
856
|
+
```ts
|
|
857
|
+
import { MiniMax } from "@opencode/ai/providers"
|
|
858
|
+
|
|
859
|
+
const minimax = Image.generate({
|
|
860
|
+
model: MiniMax.configure({ apiKey }).image("image-01"),
|
|
861
|
+
prompt,
|
|
862
|
+
n: 2,
|
|
863
|
+
aspect: "16:9",
|
|
864
|
+
images: [Media.url("https://example.com/portrait.jpg")], // optional subject reference
|
|
865
|
+
providerOptions: { promptOptimizer: true, seed: 42 },
|
|
866
|
+
})
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
The reference image is sent as a `character` subject, so it should be a single front-facing portrait. Images come
|
|
870
|
+
back inline (`responseFormat: "base64"` by default); `responseFormat: "url"` returns links that expire after 24 hours
|
|
871
|
+
and carry no MIME type until materialized. MiniMax status codes map to typed errors; code 1026 is a `ContentPolicy`
|
|
872
|
+
error.
|
|
873
|
+
|
|
830
874
|
### Partial images
|
|
831
875
|
|
|
832
876
|
OpenAI's GPT image models stream previews. `Image.stream` sends `stream: true` with `partialImages` (0–3, default 2)
|
|
@@ -845,49 +889,6 @@ const previews = Image.stream({
|
|
|
845
889
|
|
|
846
890
|
The provider may send fewer previews than requested when the final image is ready first.
|
|
847
891
|
|
|
848
|
-
### Queued image providers
|
|
849
|
-
|
|
850
|
-
Black Forest Labs, fal, Replicate, and Stability's creative upscaler are submit-then-poll routes. `Image.generate`
|
|
851
|
-
and `Image.stream` poll for you (pass `{ poll }` to tune the interval and timeout); `Image.start` returns a
|
|
852
|
-
`Generation` whose `token` is serializable JSON for `Image.resume` in another process:
|
|
853
|
-
|
|
854
|
-
```ts
|
|
855
|
-
import { BlackForestLabs, Stability } from "@opencode/ai/providers"
|
|
856
|
-
|
|
857
|
-
const bfl = BlackForestLabs.configure({ apiKey: process.env.BFL_API_KEY })
|
|
858
|
-
|
|
859
|
-
const submit = Effect.gen(function* () {
|
|
860
|
-
const generation = yield* Image.start({ model: bfl.image("flux-2-pro"), prompt, aspect: "4:3" })
|
|
861
|
-
persist({ provider: "black-forest-labs", modelID: "flux-2-pro", token: generation.token })
|
|
862
|
-
})
|
|
863
|
-
|
|
864
|
-
const finish = Effect.gen(function* () {
|
|
865
|
-
const saved = load()
|
|
866
|
-
const resumed = yield* Image.resume(bfl.image(saved.modelID), saved.token)
|
|
867
|
-
return yield* resumed.await({ poll: { interval: "2 seconds" } })
|
|
868
|
-
})
|
|
869
|
-
```
|
|
870
|
-
|
|
871
|
-
The token carries no route identity, so persist the provider and model ID alongside it: `resume` needs the model.
|
|
872
|
-
|
|
873
|
-
- **Black Forest Labs** — results are downloaded before returning, because `result.sample` expires in 10 minutes.
|
|
874
|
-
- **Replicate** — inputs are model-defined, so only `prompt` lowers: sizing, count, seed, format, and files go in
|
|
875
|
-
`providerOptions` under the model's names, with files as `Media.Asset` (data URLs up to 256 KB, larger by URL).
|
|
876
|
-
Outputs are removed an hour after the prediction completes. `Prefer: wait=60` in `headers` or `http.headers` holds
|
|
877
|
-
the submission open so a fast prediction costs one result read.
|
|
878
|
-
- **Stability** — `stability.image(id)` generates inline; `stability.upscale()` is the creative upscaler, queued:
|
|
879
|
-
|
|
880
|
-
```ts
|
|
881
|
-
const stability = Stability.configure({ apiKey: process.env.STABILITY_API_KEY })
|
|
882
|
-
const upscaled = Effect.gen(function* () {
|
|
883
|
-
const small = yield* Media.file("./small.png")
|
|
884
|
-
return yield* Image.generate(
|
|
885
|
-
{ model: stability.upscale(), prompt: "A lighthouse", images: [small] },
|
|
886
|
-
{ poll: { interval: "5 seconds" } },
|
|
887
|
-
)
|
|
888
|
-
})
|
|
889
|
-
```
|
|
890
|
-
|
|
891
892
|
Imagen is not available: Google shut it down on the Gemini API, and Vertex discontinued the Imagen 4 models on
|
|
892
893
|
2026-06-30. `Google.image(...)` uses Gemini-native image models.
|
|
893
894
|
|
|
@@ -912,7 +913,7 @@ The hosted result is represented as a provider-executed tool call and a tool res
|
|
|
912
913
|
## Video generation
|
|
913
914
|
|
|
914
915
|
Video mirrors `Image` with one difference: every provider is asynchronous, so the route is a submit-then-poll
|
|
915
|
-
`Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`,
|
|
916
|
+
`Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, and `Runway` facades.
|
|
916
917
|
Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`, `resolution`, `audio`, `n`, `seed`,
|
|
917
918
|
`negativePrompt`) lower natively or fail with a typed `AIError` before any network call; provider-native controls live
|
|
918
919
|
under `providerOptions`, inferred from the selected model.
|
|
@@ -947,7 +948,7 @@ const controlled = Effect.gen(function* () {
|
|
|
947
948
|
const generation = yield* Video.start({ model: google.video("veo-3.1-generate-preview"), prompt })
|
|
948
949
|
generation.id // provider operation / task / request id
|
|
949
950
|
generation.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
|
|
950
|
-
generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, `{ taskID }
|
|
951
|
+
generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, or `{ taskID }`
|
|
951
952
|
// The token carries no route identity: persist the provider and model ID alongside it, since `resume` needs the model.
|
|
952
953
|
const saved = JSON.stringify(generation.token)
|
|
953
954
|
|
|
@@ -977,9 +978,6 @@ Provider notes:
|
|
|
977
978
|
download, which the returned asset holds transiently (see above).
|
|
978
979
|
- **xAI** sends a `video` input to `/videos/edits`, or `/videos/extensions` with `providerOptions.mode: "extend"`.
|
|
979
980
|
`seed` and `negativePrompt` are not supported.
|
|
980
|
-
- **fal** endpoints are model-specific: `durationSeconds`, `references`, and `frames.last` fail typed and belong in
|
|
981
|
-
`providerOptions` under the model's own names (`duration: "8s"`, `end_image_url`, …). Auth is
|
|
982
|
-
`Authorization: Key <FAL_KEY>`.
|
|
983
981
|
- **Runway** expects pixel ratios in `aspect` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
|
|
984
982
|
`usage: { type: "credits" }`, and its output URLs expire after 24–48 hours.
|
|
985
983
|
|
|
@@ -1173,7 +1171,7 @@ Everything below is exported from `@opencode/ai/effect` unless noted.
|
|
|
1173
1171
|
- **`Transcription.request` / `generate` / `stream` / `start` / `resume`** — speech-to-text over inline, streaming, and queued routes; `TranscriptionClient` is its Effect service and layer.
|
|
1174
1172
|
- **`Decision.request` / `Decision.generate`** — typed predicate, choice, and score questions over text, JSON, and media input; `DecisionClient` is its Effect service and layer.
|
|
1175
1173
|
- **`AIClient.layer` / `AIClient.layerWith(executor)`** — every modality client plus the request executor in one layer.
|
|
1176
|
-
- **`@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.
|
|
1174
|
+
- **`@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.
|
|
1177
1175
|
- **`@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).
|
|
1178
1176
|
|
|
1179
1177
|
## Testing
|
|
@@ -1220,6 +1218,10 @@ For explicit compaction, script a `CompactionResponse` through `push`, `always`,
|
|
|
1220
1218
|
|
|
1221
1219
|
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.
|
|
1222
1220
|
|
|
1221
|
+
`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.
|
|
1222
|
+
|
|
1223
|
+
The Promise client accepts the same layers as `AI.make({ clients: TestImage.testLayer() })`; `ai.run(TestImage.Test.use(...))` reaches the controls.
|
|
1224
|
+
|
|
1223
1225
|
The published legacy `Service`, `layer`, `clientLayer`, and module-level controls remain available as adapters
|
|
1224
1226
|
over the same implementation, including the legacy live `requests` array. New tests should use `Test` and
|
|
1225
1227
|
`testLayer`.
|
|
@@ -1246,6 +1248,8 @@ const compacted = Effect.gen(function* () {
|
|
|
1246
1248
|
})
|
|
1247
1249
|
```
|
|
1248
1250
|
|
|
1251
|
+
From the Promise API, `await ai.llm.compact(request)` takes the same request and options (plus `signal`) and returns the same result.
|
|
1252
|
+
|
|
1249
1253
|
`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.
|
|
1250
1254
|
|
|
1251
1255
|
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.
|
package/dist/effect.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { Auth } from "./route/auth.js";
|
|
|
5
5
|
export { ProviderPackage } from "./provider-package.js";
|
|
6
6
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
7
7
|
export type { Interface as LLMClientShape, LLMClientService } from "./route/client.js";
|
|
8
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
8
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
9
9
|
export type { GenerationOptionsFields, GenerationOptionsInput, LanguageModelInput, LanguageModelProviderOptions, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, UsageInput, } from "./schema/index.js";
|
|
10
10
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
11
11
|
export type { ImageModelOptions, ImageOptions, ImageRequestFor, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
package/dist/effect.js
CHANGED
|
@@ -4,7 +4,7 @@ export { ImageClient } from "./image-client.js";
|
|
|
4
4
|
export { Auth } from "./route/auth.js";
|
|
5
5
|
export { ProviderPackage } from "./provider-package.js";
|
|
6
6
|
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
7
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
7
|
+
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
8
8
|
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
9
9
|
export { Image } from "./image.js";
|
|
10
10
|
export { VideoClient } from "./video-client.js";
|
package/dist/image-client.d.ts
CHANGED
|
@@ -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/image.d.ts
CHANGED
|
@@ -430,6 +430,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
430
430
|
}>]>>;
|
|
431
431
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
432
432
|
}>]> & {
|
|
433
|
+
readonly tag: "type";
|
|
433
434
|
readonly discriminants: readonly ["generation-queued", "generation-progress", "image-partial", "image", "finish"];
|
|
434
435
|
readonly cases: {
|
|
435
436
|
finish: Schema.Struct<{
|
package/dist/index.d.ts
CHANGED
|
@@ -5,21 +5,24 @@ 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";
|
|
13
|
-
import { Tool, type ToolExecuteContext, type ToolSchema } from "./tool.js";
|
|
14
|
+
import { Tool, type FreeformOption, type ToolExecuteContext, type ToolSchema } from "./tool.js";
|
|
14
15
|
import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
|
|
15
16
|
/**
|
|
16
17
|
* Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
|
|
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.
|
|
@@ -733,13 +741,14 @@ export type Client = ReturnType<typeof make>;
|
|
|
733
741
|
export declare const tool: <Parameters extends ToolSchema<any>>(config: {
|
|
734
742
|
readonly description: string;
|
|
735
743
|
readonly parameters: Parameters;
|
|
744
|
+
readonly freeform?: FreeformOption<Parameters>;
|
|
736
745
|
readonly execute: (params: Schema.Schema.Type<Parameters>, context: Partial<ToolExecuteContext> & {
|
|
737
746
|
readonly signal: AbortSignal;
|
|
738
747
|
}) => unknown;
|
|
739
748
|
}) => Tool.ExecutableTool<Parameters, Schema.Unknown>;
|
|
740
749
|
/** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
|
|
741
750
|
export declare const ai: {
|
|
742
|
-
run: <A, E>(effect: Effect.Effect<A, E,
|
|
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>;
|
|
743
752
|
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
744
753
|
bytes: (asset: Media.Asset, options?: RunOptions) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
745
754
|
base64: (asset: Media.Asset, options?: RunOptions) => Promise<string>;
|
|
@@ -751,8 +760,12 @@ export declare const ai: {
|
|
|
751
760
|
write: (asset: Media.Asset, path: string, options?: RunOptions) => Promise<void>;
|
|
752
761
|
llm: {
|
|
753
762
|
request: typeof LLM.request;
|
|
754
|
-
generate: <const Model extends LanguageModel>(input:
|
|
755
|
-
|
|
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<{
|
|
756
769
|
readonly type: "step-start";
|
|
757
770
|
readonly index: number;
|
|
758
771
|
} | {
|
|
@@ -1196,11 +1209,16 @@ export declare const ai: {
|
|
|
1196
1209
|
<const Model extends LanguageModel, S extends ToolSchema<any>>(input: GenerateObjectOptions<S, Model>, options?: RunOptions): Promise<GenerateObjectResponse<Schema.Schema.Type<S>>>;
|
|
1197
1210
|
<const Model extends LanguageModel>(input: GenerateObjectDynamicOptions<Model>, options?: RunOptions): Promise<GenerateObjectResponse<unknown>>;
|
|
1198
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
|
+
};
|
|
1199
1217
|
};
|
|
1200
1218
|
image: {
|
|
1201
1219
|
request: typeof import("./image.js").request;
|
|
1202
|
-
generate: <const Model extends ImageModel>(input: ImageRequestInput<Model
|
|
1203
|
-
stream: <const Model extends ImageModel>(input: ImageRequestInput<Model
|
|
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<{
|
|
1204
1222
|
readonly type: "image-partial";
|
|
1205
1223
|
readonly index: number;
|
|
1206
1224
|
readonly image: Media.Asset;
|
|
@@ -1245,15 +1263,15 @@ export declare const ai: {
|
|
|
1245
1263
|
};
|
|
1246
1264
|
} | undefined;
|
|
1247
1265
|
}>;
|
|
1248
|
-
start: <const Model extends ImageModel>(input: ImageRequestInput<Model
|
|
1266
|
+
start: <const Model extends ImageModel>(input: ImageRequest | ImageRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
|
|
1249
1267
|
resume: (model: ImageModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
|
|
1250
1268
|
};
|
|
1251
1269
|
video: {
|
|
1252
1270
|
request: typeof import("./video.js").request;
|
|
1253
|
-
start: <const Model extends VideoModel>(input: VideoRequestInput<Model
|
|
1254
|
-
generate: <const Model extends VideoModel>(input: VideoRequestInput<Model
|
|
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>;
|
|
1255
1273
|
resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
|
|
1256
|
-
stream: <const Model extends VideoModel>(input: VideoRequestInput<Model
|
|
1274
|
+
stream: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
|
|
1257
1275
|
readonly type: "video";
|
|
1258
1276
|
readonly index: number;
|
|
1259
1277
|
readonly video: Media.Asset;
|
|
@@ -1297,8 +1315,8 @@ export declare const ai: {
|
|
|
1297
1315
|
};
|
|
1298
1316
|
speech: {
|
|
1299
1317
|
request: typeof import("./speech.js").request;
|
|
1300
|
-
generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model
|
|
1301
|
-
stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model
|
|
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<{
|
|
1302
1320
|
readonly type: "audio-delta";
|
|
1303
1321
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
1304
1322
|
} | {
|
|
@@ -1349,8 +1367,8 @@ export declare const ai: {
|
|
|
1349
1367
|
};
|
|
1350
1368
|
transcription: {
|
|
1351
1369
|
request: typeof import("./transcription.js").request;
|
|
1352
|
-
generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model
|
|
1353
|
-
stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model
|
|
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<{
|
|
1354
1372
|
readonly type: "text-delta";
|
|
1355
1373
|
readonly delta: string;
|
|
1356
1374
|
} | {
|
|
@@ -1414,7 +1432,7 @@ export declare const ai: {
|
|
|
1414
1432
|
} | undefined;
|
|
1415
1433
|
readonly type: "finish";
|
|
1416
1434
|
}>;
|
|
1417
|
-
start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model
|
|
1435
|
+
start: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
1418
1436
|
resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
1419
1437
|
};
|
|
1420
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,
|
|
@@ -117,6 +128,7 @@ export const tool = (config) => Tool.make({
|
|
|
117
128
|
description: config.description,
|
|
118
129
|
parameters: config.parameters,
|
|
119
130
|
success: Schema.Unknown,
|
|
131
|
+
freeform: config.freeform,
|
|
120
132
|
execute: (params, context) => Effect.tryPromise({
|
|
121
133
|
try: async (signal) => (await config.execute(params, { ...context, signal })) ?? null,
|
|
122
134
|
catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
|
package/dist/media-client.d.ts
CHANGED
|
@@ -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>>;
|
package/dist/media-client.js
CHANGED
|
@@ -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({
|