@opencode/ai 2.2.7 → 2.3.1
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 +164 -99
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +11 -8
- package/dist/effect.js +2 -1
- package/dist/experimental.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -12
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +31 -68
- package/dist/index.js +54 -30
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +26 -4
- package/dist/media.js +52 -11
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-interactions-video.d.ts +38 -0
- package/dist/protocols/google-interactions-video.js +185 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +45 -0
- package/dist/protocols/minimax-video.js +290 -0
- package/dist/protocols/open-responses.d.ts +250 -24
- package/dist/protocols/open-responses.js +40 -24
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +36 -0
- package/dist/protocols/openrouter-video.js +139 -0
- package/dist/protocols/seedance-video.d.ts +45 -0
- package/dist/protocols/seedance-video.js +217 -0
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +42 -7
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +8 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +12 -11
- package/dist/protocols/xai-video.js +33 -24
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +26 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +11 -4
- package/dist/providers/google.js +16 -3
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +56 -3
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai-compatible.d.ts +2 -0
- package/dist/providers/openai-compatible.js +14 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +31 -0
- package/dist/providers/openrouter.js +8 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +26 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +7 -4
- package/dist/public.js +2 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +20 -1
- package/dist/route/executor-service.js +35 -1
- package/dist/route/executor.d.ts +11 -2
- package/dist/route/executor.js +25 -5
- package/dist/route/media-protocol.d.ts +21 -15
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +40 -22
- package/dist/route/protocol.d.ts +3 -0
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +25 -2
- package/dist/schema/messages.js +27 -7
- package/dist/schema/options.d.ts +18 -2
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +6 -6
- package/dist/speech-client.js +4 -4
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +6 -6
- package/dist/transcription-client.js +1 -2
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +30 -13
- package/dist/video.d.ts +54 -1126
- package/dist/video.js +29 -65
- package/package.json +59 -7
- package/dist/protocols/google-video.d.ts +0 -26
- package/dist/protocols/google-video.js +0 -146
- package/dist/protocols/runway-video.d.ts +0 -38
- package/dist/protocols/runway-video.js +0 -141
- package/dist/providers/runway.d.ts +0 -20
- package/dist/providers/runway.js +0 -17
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @opencode/ai
|
|
2
2
|
|
|
3
|
-
Schema-first APIs for text, images, decisions, and embeddings, built with Effect.
|
|
4
|
-
realtime voice are [experimental](#experimental).
|
|
3
|
+
Schema-first APIs for text, images, video, decisions, and embeddings, built with Effect. Speech, transcription,
|
|
4
|
+
extraction, and realtime voice are [experimental](#experimental).
|
|
5
5
|
|
|
6
6
|
`@opencode/ai` is the Promise API: one managed runtime behind the LLM and media methods, plus asset helpers. `ai.file`
|
|
7
7
|
and `ai.write` load `node:fs/promises` on first use, so no Effect `FileSystem` is needed:
|
|
@@ -211,7 +211,7 @@ Raw usage is preserved in `usage.providerMetadata.google`. `inputTokens` follows
|
|
|
211
211
|
`contextTokens` uses its full `raw_prompt_token` count when supplied. These can differ substantially with server-side
|
|
212
212
|
continuation. Explicit caches, hosted tools, and generated media are not supported by this initial protocol.
|
|
213
213
|
|
|
214
|
-
The same configured facade names image models (and the experimental
|
|
214
|
+
The same configured facade names image and video models (and the experimental speech and transcription models).
|
|
215
215
|
`ai.image.generate` resolves the provider's image route from the model and returns `Media.Asset`s with lazily decoded bytes:
|
|
216
216
|
|
|
217
217
|
```ts
|
|
@@ -249,6 +249,29 @@ const logged = RequestExecutor.middleware((request, next) =>
|
|
|
249
249
|
const everything = AIClient.layerWith(logged) // or AI.make({ layer: logged })
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
+
To hook only some calls, such as adding a per-user header, scope middleware to them. It runs on every provider request
|
|
253
|
+
they make, whatever the modality: submits, polls, results and cancels. Executor-wide middleware wraps it.
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
const signed: HttpMiddleware = (request, next) => next(HttpClientRequest.setHeader(request, "x-user", "user-1"))
|
|
257
|
+
|
|
258
|
+
// Effect: an Effect or a Stream
|
|
259
|
+
const video =
|
|
260
|
+
yield *
|
|
261
|
+
Effect.gen(function* () {
|
|
262
|
+
const job = yield* ai.video.start({ model, prompt: "A red balloon floats up" })
|
|
263
|
+
return yield* ai.video.result(model, job.id)
|
|
264
|
+
}).pipe(RequestExecutor.withMiddleware(signed))
|
|
265
|
+
|
|
266
|
+
// Promise: `http` on any call's options; a handle it returns keeps it
|
|
267
|
+
await AI.ai.video.start({ model, prompt: "A red balloon floats up" }, { http: signed })
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Downloading a `url` asset never uses the caller's scoped middleware, so hooks that add credentials can't reach another
|
|
271
|
+
host such as a CDN or a presigned storage URL. A result URL on the provider's own origin carries the middleware of the
|
|
272
|
+
call that returned it (`asset.middleware`), so it downloads the same way later. Set `middleware` yourself with
|
|
273
|
+
`Media.url(url, { middleware })`.
|
|
274
|
+
|
|
252
275
|
## Venice AI
|
|
253
276
|
|
|
254
277
|
`Venice` provides native Chat Completions with streaming tools and reasoning. `model` and `chat`
|
|
@@ -1031,6 +1054,135 @@ const program = Effect.gen(function* () {
|
|
|
1031
1054
|
|
|
1032
1055
|
The hosted result is represented as a provider-executed tool call and a tool result whose content carries the generated image as a file. Gemini image-capable models instead emit a first-class `media` `LLMEvent` for inline image output (`response.message` then carries a `media` part). Retaining `response.message` preserves the generated image for continuation on both routes.
|
|
1033
1056
|
|
|
1057
|
+
### Image jobs
|
|
1058
|
+
|
|
1059
|
+
`ai.image.generate` and `ai.image.stream` poll a queued image route for you. To manage the job yourself, use the same
|
|
1060
|
+
calls as video: `start` submits it and returns `{ id }` at once, the provider's job ID as a string you can store and
|
|
1061
|
+
read back from another process, and `status`, `result` and `cancel` take the model and that `id`. `status` is one read;
|
|
1062
|
+
`result` fails with an `InvalidRequest` reason while the job is still running; `cancel` fails with an
|
|
1063
|
+
`UnsupportedOperation` reason when the provider has no cancel endpoint. No shipped image route is queued yet, so on
|
|
1064
|
+
every image model today all four fail with an `UnsupportedOperation` reason before sending anything.
|
|
1065
|
+
|
|
1066
|
+
```ts
|
|
1067
|
+
const program = Effect.gen(function* () {
|
|
1068
|
+
const job = yield* ai.image.start({ model, prompt: "A lighthouse" })
|
|
1069
|
+
const status = yield* ai.image.status(model, job.id) // { status, progress? }
|
|
1070
|
+
if (status.status === "completed") return yield* ai.image.result(model, job.id)
|
|
1071
|
+
})
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
## Video generation
|
|
1075
|
+
|
|
1076
|
+
Video generation is a job: `start` submits it and returns at once, and the caller decides when to read its `status`,
|
|
1077
|
+
fetch its `result`, or `cancel` it. Nothing polls for you. Every call after `start` takes the model and the job's
|
|
1078
|
+
`id`, the provider's job ID as a string you can store and read back from another process, so recovering after a restart
|
|
1079
|
+
is the same call as a normal status read. Models come from `.video(...)` selectors on the `XAI`, `OpenRouter`, `Volcengine`,
|
|
1080
|
+
`BytePlus`, `MiniMax` and `Google` facades.
|
|
1081
|
+
|
|
1082
|
+
```ts
|
|
1083
|
+
import { Effect } from "effect"
|
|
1084
|
+
import { ai, Media } from "@opencode/ai/effect"
|
|
1085
|
+
import { XAI } from "@opencode/ai/providers"
|
|
1086
|
+
|
|
1087
|
+
const model = XAI.configure({ apiKey: process.env.XAI_API_KEY }).video("grok-imagine-video-1.5")
|
|
1088
|
+
|
|
1089
|
+
const program = Effect.gen(function* () {
|
|
1090
|
+
const job = yield* ai.video.start({
|
|
1091
|
+
model,
|
|
1092
|
+
prompt: "Panning wide shot of a calico kitten sleeping in the sunshine",
|
|
1093
|
+
start: "https://example.com/first-frame.png", // exact first frame; `end` pins the last one
|
|
1094
|
+
references: [], // images, videos or audio that guide subject or style
|
|
1095
|
+
duration: "8 seconds",
|
|
1096
|
+
aspect: "16:9", // or "auto" to follow the start image
|
|
1097
|
+
resolution: "720p", // 480p | 720p | 1080p | 4k, or any provider value
|
|
1098
|
+
sound: false,
|
|
1099
|
+
})
|
|
1100
|
+
job.id // the provider's job ID: store it with the provider and model ID
|
|
1101
|
+
|
|
1102
|
+
const status = yield* ai.video.status(model, job.id)
|
|
1103
|
+
status.status // "running" | "completed" | "error"
|
|
1104
|
+
status.reason // "failed" | "cancelled" | "expired", only when status is "error"
|
|
1105
|
+
status.progress // 0..1, only when the provider reports it
|
|
1106
|
+
|
|
1107
|
+
const response = yield* ai.video.result(model, job.id)
|
|
1108
|
+
yield* Media.write(response.video, "./kitten.mp4") // streams the download to disk
|
|
1109
|
+
})
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
The shared fields are `prompt`, `start`, `end`, `references`, `duration`, `aspect`, `resolution` and `sound`;
|
|
1113
|
+
everything else is provider-specific and goes under `providerOptions`, typed from the selected model. A request only
|
|
1114
|
+
fails before sending when its protocol has no way to express it, such as a reference video on xAI. `sound` is the
|
|
1115
|
+
exception: on models whose sound can't be switched (MiniMax H3 and Gemini Omni always have it, Hailuo never does) it
|
|
1116
|
+
isn't sent, and the model's own behavior applies. Values the provider
|
|
1117
|
+
may reject, like an unsupported duration or too many references, go to the provider, and its error comes back typed.
|
|
1118
|
+
|
|
1119
|
+
`start` and `end` are images. They take a URL, data URL, base64 string or bytes, or an asset built with
|
|
1120
|
+
`Media.image(...)`, which rejects assets known to be video, audio or documents; URLs and provider file references
|
|
1121
|
+
whose type isn't stated are sent and checked by the provider. `references` take any kind.
|
|
1122
|
+
|
|
1123
|
+
`status` is one read; `result` fails with an `InvalidRequest` reason when the job hasn't finished, and with the
|
|
1124
|
+
provider's reason (and terminal document on `reason.body`) when it failed, was cancelled or expired. Moderation
|
|
1125
|
+
outcomes (xAI `respect_moderation`) fail with a `ContentPolicy` reason when no video comes back. Status and result reads
|
|
1126
|
+
retry transient failures (rate limits, provider 5xx, network errors) with backoff that honors `retry-after`; `start`
|
|
1127
|
+
and `cancel` never retry. `cancel` fails with an `UnsupportedOperation` reason on providers without a cancel endpoint,
|
|
1128
|
+
such as xAI, where the job keeps running and billing. Finished videos are usually URLs that expire (`expiresAt` when the
|
|
1129
|
+
provider documents it): download them with `Media.write`, `asset.stream()` or `materialize()` before then.
|
|
1130
|
+
|
|
1131
|
+
Provider notes:
|
|
1132
|
+
|
|
1133
|
+
- **xAI** maps `start` to `image`, `end` to `last_frame`, image references to `reference_images`, audio references to
|
|
1134
|
+
`reference_audios`, and `sound` to `generate_audio`, and leaves `aspect: "auto"` out when a start frame sets the
|
|
1135
|
+
shape. It has no reference video input. `providerOptions.mode: "edit" | "extend"` sends a native `video: { url }`
|
|
1136
|
+
source to `/videos/edits` or `/videos/extensions`.
|
|
1137
|
+
- **OpenRouter** (`OpenRouter.configure(...).video("google/veo-3.1")`) maps `start` and `end` to `frame_images`,
|
|
1138
|
+
references to `input_references` by kind (`image_url`, `video_url`, `audio_url`), `sound` to `generate_audio`, and
|
|
1139
|
+
`resolution` to its spelling (`4k` → `4K`), and leaves `aspect: "auto"` out so models that can follow the input image do.
|
|
1140
|
+
Frames and references are both sent; when both are present OpenRouter keeps the frames and drops the references. It
|
|
1141
|
+
rejects reference videos or audio that aren't http(s) URLs (inline images work). Routing and upstream parameters go under `providerOptions.provider` (`only`, `order`,
|
|
1142
|
+
`options: { <slug>: {...} }`), and `providerOptions.previous_job_id` edits or extends a finished job. Results are
|
|
1143
|
+
OpenRouter content URLs that download with the API key, which the asset carries; there is no cancel endpoint.
|
|
1144
|
+
- **Seedance** (`Volcengine.configure(...).video(...)` with `ARK_API_KEY`, `BytePlus.configure(...).video(...)` with
|
|
1145
|
+
`BYTEPLUS_API_KEY`) builds Ark's `content[]`: the prompt as a `text` item, `start` and `end` as `image_url` items
|
|
1146
|
+
with roles `first_frame` and `last_frame`, and references as `reference_image`, `reference_video` or
|
|
1147
|
+
`reference_audio` by kind. Your own `Media.ref(...)` assets go as `asset://<id>`. `duration` goes to `duration`,
|
|
1148
|
+
`aspect` to `ratio` (`auto` becomes `adaptive`), `resolution` to `resolution` and `sound` to `generate_audio`. Ark
|
|
1149
|
+
doesn't allow frames and references in one task; that combination is sent and the provider's error comes back.
|
|
1150
|
+
`providerOptions.draft_task: { id }` adds a `draft_task` item; `frames`, `seed`, `watermark`, `output_format`,
|
|
1151
|
+
`omni_reference_task_type`, `return_last_frame` and the rest go into the body as-is. `cancel` sends `DELETE`, which
|
|
1152
|
+
only cancels a queued task: Ark refuses it for a running one and deletes the record of a finished one. Video URLs
|
|
1153
|
+
expire 24 hours after the task finished.
|
|
1154
|
+
- **MiniMax** (`MiniMax.configure(...).video(id)`, or `@opencode/ai/providers/minimax/videos`) serves two APIs and picks
|
|
1155
|
+
one by model family: Hailuo and `*-01` models use v1, everything else (H3) uses v2. Video builds its `/v1` and `/v2`
|
|
1156
|
+
paths on the API host, so a `baseURL` shared with images or chat (`https://api.minimax.cn/v1`) loses its trailing
|
|
1157
|
+
`/v1`, and a bare host (`https://api.minimax.io`) works as is. On H3, `start`, `end` and `references` become `content[]` items with `first_frame`, `last_frame` and `reference_image` /
|
|
1158
|
+
`reference_video` / `reference_audio` roles, MiniMax file refs become `mm_file://` URLs, `aspect: "auto"` becomes
|
|
1159
|
+
`ratio: "adaptive"`, and `resolution` is uppercased (`480P`, `2K`). H3 requires `resolution` and `duration`, plus a
|
|
1160
|
+
`ratio` for text-only prompts; nothing is filled in, so MiniMax rejects a request without them. H3 always has sound
|
|
1161
|
+
and has no field for it, so `sound` isn't sent. On Hailuo, `start` and `end` map to `first_frame_image` and
|
|
1162
|
+
`last_frame_image`, image references to `subject_reference`, and the result looks up the file's download URL, which
|
|
1163
|
+
expires after one hour. Hailuo is always silent, so `sound` isn't sent; it has no aspect field, so an explicit
|
|
1164
|
+
`aspect` and video or audio references fail before sending. Cancel works on H3 (only while queued); Hailuo has no cancel. Native fields
|
|
1165
|
+
such as `extra.prompt_expansion_mode` (H3), `prompt_optimizer` (Hailuo) and `callback_url` go under `providerOptions`.
|
|
1166
|
+
- **Google** (`Google.video("gemini-omni-1.2-flash")`) starts a background Gemini Omni interaction. Omni has no
|
|
1167
|
+
role field for media, so `start`, `end` and `references` go into `input` in that order (images, plus video
|
|
1168
|
+
references), and `generation_config.video_config.task` is set to `image_to_video` for frames only or
|
|
1169
|
+
`reference_to_video` for references only; with both, the prompt decides. `duration` becomes
|
|
1170
|
+
`response_format.duration` (`"3s"`), and `aspect` and `resolution` go to `response_format` as is (resolution
|
|
1171
|
+
lowercased); `aspect: "auto"` leaves the ratio out. It rejects `end` without `start` (a lone image reads as the
|
|
1172
|
+
first frame). Omni always generates audio and has no field for it, so `sound` isn't sent. Videos come back as inline bytes. `cancel` posts to
|
|
1173
|
+
`/interactions/{id}/cancel`. `providerOptions` takes native Interactions fields, such as `previous_interaction_id`
|
|
1174
|
+
to edit or extend a generated video, `generation_config.video_config.task`, `service_tier` and `webhook_config`.
|
|
1175
|
+
|
|
1176
|
+
The promise client has the same calls, each accepting `{ signal }`:
|
|
1177
|
+
|
|
1178
|
+
```ts
|
|
1179
|
+
import { ai } from "@opencode/ai"
|
|
1180
|
+
|
|
1181
|
+
const job = await ai.video.start({ model, prompt })
|
|
1182
|
+
const status = await ai.video.status(model, job.id)
|
|
1183
|
+
if (status.status === "completed") await ai.write((await ai.video.result(model, job.id)).video, "./kite.mp4")
|
|
1184
|
+
```
|
|
1185
|
+
|
|
1034
1186
|
## Public API
|
|
1035
1187
|
|
|
1036
1188
|
Everything below is exported from `@opencode/ai/effect` unless noted.
|
|
@@ -1042,119 +1194,32 @@ Everything below is exported from `@opencode/ai/effect` unless noted.
|
|
|
1042
1194
|
- **`Message.user(...)` / `Message.assistant(...)` / `Message.tool(...)`** — message constructors from the canonical schema model.
|
|
1043
1195
|
- **`LanguageModel.make(...)` / `ToolCallPart.make(...)` / `ToolResultPart.make(...)` / `ToolDefinition.make(...)`** — model and tool-related constructors from the canonical schema model.
|
|
1044
1196
|
- **`LLMEvent.is.*`** — typed guards (`is.textDelta`, `is.toolCall`, `is.finish`, …) for filtering streams.
|
|
1045
|
-
- **`ai.image.request` / `generate` / `stream` / `start` / `
|
|
1197
|
+
- **`ai.image.request` / `generate` / `stream` / `start` / `status` / `result` / `cancel`** — images over inline, streaming (partial previews), and queued routes through a provider-neutral request and response model. `start`, `status`, `result` and `cancel` address a queued job by the provider's job ID, like video; see [Image jobs](#image-jobs).
|
|
1046
1198
|
- **`ImageClient`** — Effect service and layer for image execution, parallel to `LLMClient`.
|
|
1199
|
+
- **`ai.video.request` / `start` / `status` / `result` / `cancel`** — video generation as a job addressed by the provider's job ID; see [Video generation](#video-generation). `VideoClient` is its Effect service and layer.
|
|
1047
1200
|
- **`Media`** — the shared asset type (`Media.Asset`, `Media.Source`) and constructors used by messages, tool results, and media requests.
|
|
1048
1201
|
- **`Generation`** — provider-neutral handle for an in-flight media generation (`await`, `refresh`, `cancel`, `events`) used by queued media routes.
|
|
1049
1202
|
- **`ai.decision.request` / `ai.decision.generate`** — typed predicate, choice, and score questions over text, JSON, and media input; `DecisionClient` is its Effect service and layer.
|
|
1050
1203
|
- **`ai.embedding.request` / `ai.embedding.generate`** — one vector per text or media value, with optional `dimensions` and `inputType`; `EmbeddingClient` is its Effect service and layer.
|
|
1051
1204
|
- **`AIClient.layer` / `AIClient.layerWith(executor)`** — every modality client plus the request executor in one layer.
|
|
1052
|
-
- **`@opencode/ai`** (Promise root) — a default `ai` with the text calls (`request`, `generate`, `stream`, `loop`, `compact`, `canCompact`) at the top level plus `image`, `decision` and `
|
|
1053
|
-
- **`@opencode/ai/experimental`** — APIs that may change without compatibility guarantees: `
|
|
1205
|
+
- **`@opencode/ai`** (Promise root) — a default `ai` with the text calls (`request`, `generate`, `stream`, `loop`, `compact`, `canCompact`) at the top level plus `image`, `decision`, `embedding` and `video` (plus `experimental.speech` and `experimental.transcription`) as Promise / `AsyncIterable` APIs, `run(effect)` for any package Effect, plus `file`, `write`, `bytes`, `base64`, and `materialize` for assets. `AI.make({ layer? })` builds a client over a custom executor. The same `ai` from `@opencode/ai/effect` returns `Effect` and `Stream`.
|
|
1206
|
+
- **`@opencode/ai/experimental`** — APIs that may change without compatibility guarantees: `Speech`, `Transcription`, `Extraction`, and `Realtime`. See [Experimental](#experimental).
|
|
1054
1207
|
|
|
1055
1208
|
## Experimental
|
|
1056
1209
|
|
|
1057
1210
|
These APIs may change without compatibility guarantees. The Effect API is exported from `@opencode/ai/experimental`,
|
|
1058
1211
|
and the Promise client exposes it under `ai.experimental`.
|
|
1059
1212
|
|
|
1060
|
-
- **`
|
|
1061
|
-
`
|
|
1062
|
-
`.transcription`.
|
|
1213
|
+
- **`Speech`** and **`Transcription`** — speech generation and speech-to-text, with `SpeechClient` and
|
|
1214
|
+
`TranscriptionClient` as their Effect services. Promise: `ai.experimental.speech` and `.transcription`.
|
|
1063
1215
|
- **`Extraction`** — typed values read out of text.
|
|
1064
1216
|
- **`Realtime`** — `Realtime.connect` starts an OpenAI, xAI, or Gemini voice session and returns a WebRTC answer SDP or
|
|
1065
1217
|
a short-lived WebSocket URL and token.
|
|
1066
1218
|
|
|
1067
|
-
The provider selectors for these modalities (`.
|
|
1219
|
+
The provider selectors for these modalities (`.speech(...)`, `.transcription(...)`,
|
|
1068
1220
|
`.experimental.extraction(...)`) and their protocol entrypoints (such as `@opencode/ai/protocols/openai-speech`) are
|
|
1069
1221
|
part of the same experimental surface.
|
|
1070
1222
|
|
|
1071
|
-
### Video generation
|
|
1072
|
-
|
|
1073
|
-
Video mirrors `Image` with one difference: every provider is asynchronous, so the route is a submit-then-poll
|
|
1074
|
-
`Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, and `Runway` facades.
|
|
1075
|
-
Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`, `resolution`, `audio`, `n`, `seed`,
|
|
1076
|
-
`negativePrompt`) lower natively or fail with a typed `AIError` before any network call; provider-native controls live
|
|
1077
|
-
under `providerOptions`, inferred from the selected model.
|
|
1078
|
-
|
|
1079
|
-
```ts
|
|
1080
|
-
import { Video } from "@opencode/ai/experimental"
|
|
1081
|
-
import { Google, Runway } from "@opencode/ai/providers"
|
|
1082
|
-
|
|
1083
|
-
const google = Google.configure({ apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY })
|
|
1084
|
-
|
|
1085
|
-
// Simple: submit and wait.
|
|
1086
|
-
const program = Effect.gen(function* () {
|
|
1087
|
-
const response = yield* Video.generate(
|
|
1088
|
-
{
|
|
1089
|
-
model: google.video("veo-3.1-generate-preview"),
|
|
1090
|
-
prompt: "Panning wide shot of a calico kitten sleeping in the sunshine",
|
|
1091
|
-
aspect: "16:9",
|
|
1092
|
-
resolution: "1080p",
|
|
1093
|
-
durationSeconds: 8,
|
|
1094
|
-
providerOptions: { personGeneration: "allow_adult" },
|
|
1095
|
-
},
|
|
1096
|
-
{ poll: { interval: "10 seconds", timeout: "10 minutes" } },
|
|
1097
|
-
)
|
|
1098
|
-
// Veo serves files for two days behind the API key. The asset knows the deadline (`expiresAt`) and carries the
|
|
1099
|
-
// download credentials only on the live instance (`asset.headers`), never in `source` or JSON: materialize
|
|
1100
|
-
// before persisting, or the persisted URL cannot be fetched again.
|
|
1101
|
-
return yield* response.video.materialize()
|
|
1102
|
-
})
|
|
1103
|
-
|
|
1104
|
-
// Explicit control: keep the handle, persist the token, resume elsewhere.
|
|
1105
|
-
const controlled = Effect.gen(function* () {
|
|
1106
|
-
const generation = yield* Video.start({ model: google.video("veo-3.1-generate-preview"), prompt })
|
|
1107
|
-
generation.id // provider operation / task / request id
|
|
1108
|
-
generation.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
|
|
1109
|
-
generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, or `{ taskID }`
|
|
1110
|
-
// The token carries no route identity: persist the provider and model ID alongside it, since `resume` needs the model.
|
|
1111
|
-
const saved = JSON.stringify(generation.token)
|
|
1112
|
-
|
|
1113
|
-
const resumed = yield* Video.resume(google.video("veo-3.1-generate-preview"), JSON.parse(saved))
|
|
1114
|
-
return yield* resumed.await({ poll: { interval: "10 seconds" } })
|
|
1115
|
-
})
|
|
1116
|
-
|
|
1117
|
-
// Progress as a stream: generation-queued | generation-progress | video | finish.
|
|
1118
|
-
const events = Video.stream({ model: Runway.configure({ apiKey }).video("gen4.5"), prompt }, { poll })
|
|
1119
|
-
```
|
|
1120
|
-
|
|
1121
|
-
Status polls, result fetches, cancels, and asset downloads all run through the same request executor with the route's
|
|
1122
|
-
auth. `Generation.await` and `Generation.events` fail with a
|
|
1123
|
-
`Timeout` reason when `poll.timeout` (default 10 minutes) elapses. Status polls and result fetches retry transient
|
|
1124
|
-
failures (rate limits, provider 5xx, network errors) with backoff that honors `retry-after`, always within
|
|
1125
|
-
`poll.timeout`; submits and cancels never retry. Interrupting a wait (or aborting its `signal`) does not cancel the
|
|
1126
|
-
provider job, which keeps running and billing: call `cancel()` to stop it. Failed,
|
|
1127
|
-
cancelled, and expired generations fail typed with the provider's terminal document on `reason.body`; moderation
|
|
1128
|
-
outcomes (Veo `raiMediaFilteredReasons`, xAI `respect_moderation`, Runway `SAFETY.*` codes) fail with a
|
|
1129
|
-
`ContentPolicy` reason when no video comes back; when one still does, Veo and xAI keep the raw outcome in
|
|
1130
|
-
`providerMetadata`.
|
|
1131
|
-
|
|
1132
|
-
Provider notes:
|
|
1133
|
-
|
|
1134
|
-
- **Google Veo** takes inline bytes only (materialize `url` assets first); `frames.last` requires `frames.first`;
|
|
1135
|
-
audio is always on, so `audio: false` fails typed; one video per request. Output URLs need the API key to
|
|
1136
|
-
download, which the returned asset holds transiently (see above).
|
|
1137
|
-
- **xAI** sends a `video` input to `/videos/edits`, or `/videos/extensions` with `providerOptions.mode: "extend"`.
|
|
1138
|
-
`seed` and `negativePrompt` are not supported.
|
|
1139
|
-
- **Runway** expects pixel ratios in `aspect` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
|
|
1140
|
-
`usage: { type: "credits" }`, and its output URLs expire after 24–48 hours.
|
|
1141
|
-
|
|
1142
|
-
The promise client exposes the same surface: `ai.experimental.video.start(...)` resolves to a handle with `await`, `events`,
|
|
1143
|
-
`result`, `refresh`, `cancel`, and `token`; `ai.experimental.video.generate`, `ai.experimental.video.resume(model, token)`, and
|
|
1144
|
-
`ai.experimental.video.stream` mirror the Effect API. The handle's `status` and `progress` are a snapshot from when it was
|
|
1145
|
-
created; `refresh()` resolves to a new handle. Every promise method and stream accepts `{ signal }`: like `fetch`,
|
|
1146
|
-
aborting rejects the Promise or throws from the `for await` loop with `signal.reason` (an `AbortError` `DOMException`
|
|
1147
|
-
unless `abort(reason)` passed one), while `break` stops a stream without throwing.
|
|
1148
|
-
|
|
1149
|
-
```ts
|
|
1150
|
-
import { ai } from "@opencode/ai"
|
|
1151
|
-
|
|
1152
|
-
const generation = await ai.experimental.video.start({ model, prompt })
|
|
1153
|
-
for await (const event of generation.events({ poll: { interval: 10_000 } })) console.log(event.type)
|
|
1154
|
-
const video = await generation.result({ signal })
|
|
1155
|
-
await ai.write(video.video, "./kite.mp4")
|
|
1156
|
-
```
|
|
1157
|
-
|
|
1158
1223
|
### Speech generation
|
|
1159
1224
|
|
|
1160
1225
|
Speech (text-to-speech) is one request whose response is parsed incrementally, so every route supports both
|
|
@@ -1287,8 +1352,8 @@ const program = Effect.gen(function* () {
|
|
|
1287
1352
|
})
|
|
1288
1353
|
```
|
|
1289
1354
|
|
|
1290
|
-
Inline routes emit only `finish` from `stream` (no faked deltas); queued routes emit `generation-
|
|
1291
|
-
|
|
1355
|
+
Inline routes emit only `finish` from `stream` (no faked deltas); queued routes emit `generation-progress`
|
|
1356
|
+
before it.
|
|
1292
1357
|
|
|
1293
1358
|
Provider notes:
|
|
1294
1359
|
|
package/dist/cache-policy.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { CacheHint } from "./schema/options.js";
|
|
14
14
|
import { AssistantMessage, SystemMessage, ToolDefinition, ToolMessage, UserMessage, } from "./schema/messages.js";
|
|
15
15
|
import { effortUpdate } from "./effort-updates.js";
|
|
16
|
+
import { toolsUpdate } from "./tool-updates.js";
|
|
16
17
|
const AUTO = {
|
|
17
18
|
tools: true,
|
|
18
19
|
system: true,
|
|
@@ -151,15 +152,16 @@ const markMessages = (messages, strategy, hint, budget) => {
|
|
|
151
152
|
let remaining = strategy.tail;
|
|
152
153
|
while (remaining > 0 && start > 0) {
|
|
153
154
|
start -= 1;
|
|
154
|
-
if (
|
|
155
|
+
if (!isMarker(messages[start]))
|
|
155
156
|
remaining -= 1;
|
|
156
157
|
}
|
|
157
158
|
let next = messages;
|
|
158
159
|
for (let i = start; i < messages.length; i++)
|
|
159
|
-
if (
|
|
160
|
+
if (!isMarker(messages[i]))
|
|
160
161
|
next = markMessageAt(next, i, hint, budget);
|
|
161
162
|
return next;
|
|
162
163
|
};
|
|
164
|
+
const isMarker = (message) => effortUpdate(message) !== undefined || toolsUpdate(message) !== undefined;
|
|
163
165
|
const countHints = (request) => countToolHints(request.tools) +
|
|
164
166
|
request.system.reduce((count, part) => count + (part.cache === undefined ? 0 : 1), 0) +
|
|
165
167
|
request.messages.reduce((count, message) => count +
|
package/dist/effect.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export declare const ai: {
|
|
|
13
13
|
readonly generate: typeof import("./image.js").generate;
|
|
14
14
|
readonly stream: typeof import("./image.js").stream;
|
|
15
15
|
readonly start: typeof import("./image.js").start;
|
|
16
|
-
readonly
|
|
16
|
+
readonly status: typeof import("./image.js").status;
|
|
17
|
+
readonly result: typeof import("./image.js").result;
|
|
18
|
+
readonly cancel: typeof import("./image.js").cancel;
|
|
17
19
|
};
|
|
18
20
|
readonly decision: {
|
|
19
21
|
readonly request: typeof import("./decision.js").request;
|
|
@@ -23,6 +25,13 @@ export declare const ai: {
|
|
|
23
25
|
readonly request: typeof import("./embedding.js").request;
|
|
24
26
|
readonly generate: typeof import("./embedding.js").generate;
|
|
25
27
|
};
|
|
28
|
+
readonly video: {
|
|
29
|
+
readonly request: typeof import("./video.js").request;
|
|
30
|
+
readonly start: typeof import("./video.js").start;
|
|
31
|
+
readonly status: typeof import("./video.js").status;
|
|
32
|
+
readonly result: typeof import("./video.js").result;
|
|
33
|
+
readonly cancel: typeof import("./video.js").cancel;
|
|
34
|
+
};
|
|
26
35
|
/** Experimental: may change without compatibility guarantees. */
|
|
27
36
|
readonly experimental: {
|
|
28
37
|
readonly speech: {
|
|
@@ -37,18 +46,12 @@ export declare const ai: {
|
|
|
37
46
|
readonly start: typeof import("./transcription.js").start;
|
|
38
47
|
readonly resume: typeof import("./transcription.js").resume;
|
|
39
48
|
};
|
|
40
|
-
readonly video: {
|
|
41
|
-
readonly request: typeof import("./video.js").request;
|
|
42
|
-
readonly start: typeof import("./video.js").start;
|
|
43
|
-
readonly generate: typeof import("./video.js").generate;
|
|
44
|
-
readonly resume: typeof import("./video.js").resume;
|
|
45
|
-
readonly stream: typeof import("./video.js").stream;
|
|
46
|
-
};
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
export { AIClient } from "./ai-client.js";
|
|
50
52
|
export { LLMClient } from "./route/client.js";
|
|
51
53
|
export { ImageClient } from "./image-client.js";
|
|
54
|
+
export { VideoClient } from "./video-client.js";
|
|
52
55
|
export { Auth } from "./route/auth.js";
|
|
53
56
|
export { ProviderPackage } from "./provider-package.js";
|
|
54
57
|
export type { LLMClientService } from "./route/client.js";
|
package/dist/effect.js
CHANGED
|
@@ -17,16 +17,17 @@ export const ai = {
|
|
|
17
17
|
image: Image,
|
|
18
18
|
decision: Decision,
|
|
19
19
|
embedding: Embedding,
|
|
20
|
+
video: Video,
|
|
20
21
|
/** Experimental: may change without compatibility guarantees. */
|
|
21
22
|
experimental: {
|
|
22
23
|
speech: Speech,
|
|
23
24
|
transcription: Transcription,
|
|
24
|
-
video: Video,
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
export { AIClient } from "./ai-client.js";
|
|
28
28
|
export { LLMClient } from "./route/client.js";
|
|
29
29
|
export { ImageClient } from "./image-client.js";
|
|
30
|
+
export { VideoClient } from "./video-client.js";
|
|
30
31
|
export { Auth } from "./route/auth.js";
|
|
31
32
|
export { ProviderPackage } from "./provider-package.js";
|
|
32
33
|
export { DecisionClient } from "./decision-client.js";
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
-
export type { VideoModelOptions, VideoOptions, VideoRequest, VideoRequestInput, VideoResolution, VideoRoute, } from "./video.js";
|
|
4
|
-
export { Video } from "./video.js";
|
|
5
1
|
export { SpeechClient } from "./speech-client.js";
|
|
6
2
|
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
7
3
|
export type { SpeechFormat, SpeechModelOptions, SpeechOptions, SpeechRequest, SpeechRequestInput, SpeechRoute, } from "./speech.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
-
export { Video } from "./video.js";
|
|
4
1
|
export { SpeechClient } from "./speech-client.js";
|
|
5
2
|
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
6
3
|
export { Speech } from "./speech.js";
|
package/dist/generation.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Duration, Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError } from "./schema/errors.js";
|
|
3
|
-
export declare const Status: Schema.Literals<readonly ["
|
|
3
|
+
export declare const Status: Schema.Literals<readonly ["running", "completed", "error"]>;
|
|
4
4
|
export type Status = Schema.Schema.Type<typeof Status>;
|
|
5
|
+
/** Why a generation ended in `error`. */
|
|
6
|
+
export declare const Reason: Schema.Literals<readonly ["failed", "cancelled", "expired"]>;
|
|
7
|
+
export type Reason = Schema.Schema.Type<typeof Reason>;
|
|
5
8
|
/** Provider-neutral view of one generation observation. */
|
|
6
9
|
export interface Snapshot {
|
|
7
10
|
readonly id: string;
|
|
8
11
|
readonly status: Status;
|
|
12
|
+
/** Set when `status` is `error`. */
|
|
13
|
+
readonly reason?: Reason;
|
|
9
14
|
/** Normalized 0..1 when the provider reports progress. */
|
|
10
15
|
readonly progress?: number;
|
|
11
|
-
readonly position?: number;
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
18
|
* Route-owned generation operations for one generation. The media route decodes its serializable token once (from the
|
|
@@ -26,31 +30,27 @@ export interface Poll {
|
|
|
26
30
|
export interface AwaitOptions {
|
|
27
31
|
readonly poll?: Poll;
|
|
28
32
|
}
|
|
29
|
-
export declare const QueuedEvent: Schema.Struct<{
|
|
30
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
31
|
-
readonly id: Schema.String;
|
|
32
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
33
|
-
}>;
|
|
34
33
|
export declare const ProgressEvent: Schema.Struct<{
|
|
35
34
|
readonly type: Schema.tag<"generation-progress">;
|
|
36
35
|
readonly id: Schema.String;
|
|
37
36
|
readonly progress: Schema.optional<Schema.Number>;
|
|
38
37
|
}>;
|
|
39
|
-
export type Observation = Schema.Schema.Type<typeof
|
|
38
|
+
export type Observation = Schema.Schema.Type<typeof ProgressEvent>;
|
|
40
39
|
export type Event = Observation | {
|
|
41
40
|
readonly type: "generation-finished";
|
|
42
41
|
readonly id: string;
|
|
43
42
|
readonly status: Status;
|
|
43
|
+
readonly reason?: Reason;
|
|
44
44
|
};
|
|
45
|
-
export declare const isTerminal: (status: Status) =>
|
|
45
|
+
export declare const isTerminal: (status: Status) => status is "completed" | "error";
|
|
46
46
|
export declare class Generation<Response> {
|
|
47
47
|
readonly route: Route<Response>;
|
|
48
48
|
/** Route-owned serializable JSON; pass it to the modality's `resume` from another process. */
|
|
49
49
|
readonly token: unknown;
|
|
50
50
|
readonly id: string;
|
|
51
51
|
readonly status: Status;
|
|
52
|
+
readonly reason?: Reason;
|
|
52
53
|
readonly progress?: number;
|
|
53
|
-
readonly position?: number;
|
|
54
54
|
constructor(route: Route<Response>,
|
|
55
55
|
/** Route-owned serializable JSON; pass it to the modality's `resume` from another process. */
|
|
56
56
|
token: unknown, snapshot: Snapshot);
|
package/dist/generation.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { Clock, Duration, Effect, Schedule, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError, TimeoutError } from "./schema/errors.js";
|
|
3
|
-
export const Status = Schema.Literals(["
|
|
3
|
+
export const Status = Schema.Literals(["running", "completed", "error"]);
|
|
4
|
+
/** Why a generation ended in `error`. */
|
|
5
|
+
export const Reason = Schema.Literals(["failed", "cancelled", "expired"]);
|
|
4
6
|
const DEFAULT_POLL_INTERVAL = Duration.seconds(5);
|
|
5
7
|
const DEFAULT_POLL_TIMEOUT = Duration.minutes(10);
|
|
6
|
-
export const QueuedEvent = Schema.Struct({
|
|
7
|
-
type: Schema.tag("generation-queued"),
|
|
8
|
-
id: Schema.String,
|
|
9
|
-
position: Schema.optional(Schema.Number),
|
|
10
|
-
}).annotate({ identifier: "Generation.Event.Queued" });
|
|
11
8
|
export const ProgressEvent = Schema.Struct({
|
|
12
9
|
type: Schema.tag("generation-progress"),
|
|
13
10
|
id: Schema.String,
|
|
14
11
|
progress: Schema.optional(Schema.Number),
|
|
15
12
|
}).annotate({ identifier: "Generation.Event.Progress" });
|
|
16
|
-
const
|
|
17
|
-
export const isTerminal = (status) => TERMINAL.has(status);
|
|
13
|
+
export const isTerminal = (status) => status !== "running";
|
|
18
14
|
export class Generation {
|
|
19
15
|
route;
|
|
20
16
|
token;
|
|
21
17
|
id;
|
|
22
18
|
status;
|
|
19
|
+
reason;
|
|
23
20
|
progress;
|
|
24
|
-
position;
|
|
25
21
|
constructor(route,
|
|
26
22
|
/** Route-owned serializable JSON; pass it to the modality's `resume` from another process. */
|
|
27
23
|
token, snapshot) {
|
|
@@ -29,15 +25,15 @@ export class Generation {
|
|
|
29
25
|
this.token = token;
|
|
30
26
|
this.id = snapshot.id;
|
|
31
27
|
this.status = snapshot.status;
|
|
28
|
+
this.reason = snapshot.reason;
|
|
32
29
|
this.progress = snapshot.progress;
|
|
33
|
-
this.position = snapshot.position;
|
|
34
30
|
}
|
|
35
31
|
get snapshot() {
|
|
36
32
|
return {
|
|
37
33
|
id: this.id,
|
|
38
34
|
status: this.status,
|
|
35
|
+
reason: this.reason,
|
|
39
36
|
progress: this.progress,
|
|
40
|
-
position: this.position,
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
39
|
get terminal() {
|
|
@@ -80,9 +76,7 @@ export class Generation {
|
|
|
80
76
|
}
|
|
81
77
|
event() {
|
|
82
78
|
if (this.terminal)
|
|
83
|
-
return { type: "generation-finished", id: this.id, status: this.status };
|
|
84
|
-
if (this.status === "queued")
|
|
85
|
-
return { type: "generation-queued", id: this.id, position: this.position };
|
|
79
|
+
return { type: "generation-finished", id: this.id, status: this.status, reason: this.reason };
|
|
86
80
|
return { type: "generation-progress", id: this.id, progress: this.progress };
|
|
87
81
|
}
|
|
88
82
|
poll(poll) {
|