@opencode/ai 2.2.6 → 2.3.0
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 +208 -98
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/decision.d.ts +10 -0
- package/dist/decision.js +2 -0
- package/dist/effect.d.ts +14 -7
- package/dist/effect.js +6 -1
- package/dist/embedding-client.d.ts +21 -0
- package/dist/embedding-client.js +30 -0
- package/dist/embedding.d.ts +111 -0
- package/dist/embedding.js +75 -0
- package/dist/experimental.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/image-client.d.ts +1 -1
- package/dist/image-client.js +2 -6
- package/dist/image.d.ts +0 -1
- package/dist/image.js +0 -3
- package/dist/index.d.ts +18 -50
- package/dist/index.js +35 -13
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +9 -3
- package/dist/media.js +27 -7
- package/dist/protocols/alibaba-chat.d.ts +4 -0
- package/dist/protocols/anthropic-messages.js +3 -3
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-embed-content.d.ts +34 -0
- package/dist/protocols/google-embed-content.js +110 -0
- package/dist/protocols/google-interactions-video.d.ts +43 -0
- package/dist/protocols/google-interactions-video.js +186 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
- package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
- package/dist/protocols/index.d.ts +4 -0
- package/dist/protocols/index.js +4 -0
- package/dist/protocols/minimax-video.d.ts +54 -0
- package/dist/protocols/minimax-video.js +292 -0
- package/dist/protocols/open-responses.d.ts +1 -1
- package/dist/protocols/open-responses.js +31 -8
- package/dist/protocols/openai-chat.d.ts +24 -0
- package/dist/protocols/openai-chat.js +37 -11
- package/dist/protocols/openai-compatible-chat.d.ts +1 -0
- package/dist/protocols/openai-decisions.js +14 -1
- package/dist/protocols/openai-embeddings.d.ts +16 -0
- package/dist/protocols/openai-embeddings.js +76 -0
- package/dist/protocols/openrouter-video.d.ts +41 -0
- package/dist/protocols/openrouter-video.js +138 -0
- package/dist/protocols/seedance-video.d.ts +50 -0
- package/dist/protocols/seedance-video.js +216 -0
- package/dist/protocols/shared.d.ts +13 -3
- package/dist/protocols/shared.js +27 -4
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +50 -8
- package/dist/protocols/utils/responses-compaction.js +1 -1
- package/dist/protocols/venice-chat.d.ts +4 -0
- package/dist/protocols/xai-video.d.ts +8 -2
- package/dist/protocols/xai-video.js +20 -15
- package/dist/protocols/zai-chat.d.ts +4 -0
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba/embeddings.d.ts +2 -0
- package/dist/providers/alibaba/embeddings.js +1 -0
- package/dist/providers/alibaba.d.ts +3 -0
- package/dist/providers/alibaba.js +14 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +1 -0
- package/dist/providers/azure/embeddings.d.ts +2 -0
- package/dist/providers/azure/embeddings.js +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.js +15 -0
- package/dist/providers/baseten.d.ts +2 -0
- 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/cerebras.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +2 -0
- package/dist/providers/cohere/embeddings.d.ts +2 -0
- package/dist/providers/cohere/embeddings.js +1 -0
- package/dist/providers/cohere.d.ts +8 -0
- package/dist/providers/cohere.js +17 -1
- package/dist/providers/deepinfra/embeddings.d.ts +2 -0
- package/dist/providers/deepinfra/embeddings.js +1 -0
- package/dist/providers/deepinfra.d.ts +6 -1
- package/dist/providers/deepinfra.js +15 -1
- package/dist/providers/deepseek.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.d.ts +2 -0
- package/dist/providers/digitalocean/embeddings.js +1 -0
- package/dist/providers/digitalocean.d.ts +10 -0
- package/dist/providers/digitalocean.js +15 -0
- package/dist/providers/fireworks/embeddings.d.ts +2 -0
- package/dist/providers/fireworks/embeddings.js +1 -0
- package/dist/providers/fireworks.d.ts +6 -1
- package/dist/providers/fireworks.js +15 -1
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/embeddings.d.ts +2 -0
- package/dist/providers/google/embeddings.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/embeddings.d.ts +2 -0
- package/dist/providers/google-vertex/embeddings.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +1 -0
- package/dist/providers/google-vertex.d.ts +7 -0
- package/dist/providers/google-vertex.js +52 -0
- package/dist/providers/google.d.ts +17 -4
- package/dist/providers/google.js +27 -3
- package/dist/providers/groq.d.ts +5 -0
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/meta.d.ts +1 -0
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +7 -1
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/moonshot.d.ts +1 -0
- package/dist/providers/openai/embeddings.d.ts +2 -0
- package/dist/providers/openai/embeddings.js +1 -0
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
- package/dist/providers/openai-compatible/embeddings.js +1 -0
- package/dist/providers/openai-compatible.d.ts +6 -0
- package/dist/providers/openai-compatible.js +27 -0
- package/dist/providers/openai.d.ts +7 -0
- package/dist/providers/openai.js +14 -0
- package/dist/providers/openrouter/embeddings.d.ts +2 -0
- package/dist/providers/openrouter/embeddings.js +1 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +21 -0
- package/dist/providers/openrouter.js +23 -0
- package/dist/providers/togetherai.d.ts +2 -0
- package/dist/providers/venice.d.ts +1 -0
- package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +4 -0
- package/dist/providers/vercel-ai-gateway.js +15 -1
- 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.d.ts +1 -0
- package/dist/providers/zai-coding-plan.d.ts +1 -0
- package/dist/providers/zai.d.ts +1 -0
- package/dist/public.d.ts +4 -0
- package/dist/public.js +2 -0
- package/dist/route/embedding.d.ts +61 -0
- package/dist/route/embedding.js +88 -0
- package/dist/route/executor-service.d.ts +6 -0
- package/dist/route/executor-service.js +7 -0
- package/dist/route/executor.d.ts +7 -1
- package/dist/route/executor.js +7 -2
- package/dist/route/media-protocol.d.ts +12 -11
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +31 -22
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/messages.d.ts +1 -1
- package/dist/schema/messages.js +1 -5
- package/dist/schema/options.d.ts +8 -0
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +1 -1
- package/dist/speech-client.js +4 -4
- package/dist/transcription-client.d.ts +1 -1
- package/dist/transcription-client.js +1 -2
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +28 -13
- package/dist/video.d.ts +56 -1072
- package/dist/video.js +28 -65
- package/package.json +355 -255
- 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,
|
|
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:
|
|
@@ -16,7 +16,7 @@ const input = { model: openai.responses("gpt-4o-mini"), prompt: "Say hello." }
|
|
|
16
16
|
const response = await ai.generate(input)
|
|
17
17
|
console.log(response.text)
|
|
18
18
|
const generated = await ai.image.generate({ model: openai.image("gpt-image-2"), prompt: "A lighthouse" })
|
|
19
|
-
await ai.write(generated.
|
|
19
|
+
await ai.write(generated.images[0], "./lighthouse.png") // also ai.file(path), ai.bytes(asset), ai.base64(asset), ai.materialize(asset)
|
|
20
20
|
for await (const event of ai.stream(ai.request(input))) {
|
|
21
21
|
// LLMEvent
|
|
22
22
|
}
|
|
@@ -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
|
|
@@ -226,7 +226,7 @@ const image = Effect.gen(function* () {
|
|
|
226
226
|
resolution: "1K",
|
|
227
227
|
providerOptions: { quality: "high" }, // typed per image model
|
|
228
228
|
})
|
|
229
|
-
yield* Media.write(response.
|
|
229
|
+
yield* Media.write(response.images[0], "./garden.png")
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
// `Media.file` / `Media.write` use the Effect `FileSystem` service; provide your platform's layer.
|
|
@@ -322,6 +322,8 @@ const [refund, department] = response.answers
|
|
|
322
322
|
```
|
|
323
323
|
|
|
324
324
|
`input` is a JSON object or an ordered list of `text`, `json` and `media` parts. Answers come back in question order.
|
|
325
|
+
A `predicate` can say what counts as true and as false with `criteria: { true, false }`; hosts without a criteria field
|
|
326
|
+
read them appended to the instructions.
|
|
325
327
|
A question the host declines is `{ name, type: "error", reason, message? }`, with `reason` such as `"refusal"`; the
|
|
326
328
|
other answers still come back.
|
|
327
329
|
`response.usage` has `inputTokens`, `outputTokens`, `totalTokens` and the host's reported `cost` when it sends one;
|
|
@@ -355,6 +357,95 @@ CloudflareAIGateway.configure({ accountId }).decision("typesafe/jev")
|
|
|
355
357
|
OpenAI and Vercel AI Gateway use OpenAI's `/v1/decisions` API. TypeSafe, OpenCode, OpenRouter, Baseten and
|
|
356
358
|
DigitalOcean use System One (`/systemone`), and Cloudflare sends the System One body through `/ai/run`.
|
|
357
359
|
|
|
360
|
+
## Embeddings
|
|
361
|
+
|
|
362
|
+
Embedding models turn each value into a vector, returned in value order.
|
|
363
|
+
|
|
364
|
+
```ts
|
|
365
|
+
import { ai } from "@opencode/ai"
|
|
366
|
+
import { OpenAI } from "@opencode/ai/providers"
|
|
367
|
+
|
|
368
|
+
const response = await ai.embedding.generate({
|
|
369
|
+
model: OpenAI.configure().embedding("text-embedding-3-small"),
|
|
370
|
+
values: ["I was charged twice.", "How do I reset my password?"],
|
|
371
|
+
dimensions: 256,
|
|
372
|
+
inputType: "document",
|
|
373
|
+
})
|
|
374
|
+
const [charge, password] = response.embeddings
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
A string value is text; media values are an `Asset` (or bytes or a URL) for hosts that embed images or documents.
|
|
378
|
+
`dimensions` asks models that can shorten their vectors for that length. `inputType` says whether the values are
|
|
379
|
+
search queries or stored documents; hosts with no such field (OpenAI's `/embeddings` API) ignore it, and host-specific
|
|
380
|
+
task types go in `providerOptions` (NVIDIA's `input_type: "passage"`). `response.usage.inputTokens` is the host's
|
|
381
|
+
token count, and its raw usage stays in `providerMetadata`. Media values fail the call on hosts that only embed text.
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
import {
|
|
385
|
+
Alibaba,
|
|
386
|
+
Azure,
|
|
387
|
+
Cohere,
|
|
388
|
+
DeepInfra,
|
|
389
|
+
DigitalOcean,
|
|
390
|
+
Fireworks,
|
|
391
|
+
OpenAICompatible,
|
|
392
|
+
OpenRouter,
|
|
393
|
+
VercelAIGateway,
|
|
394
|
+
} from "@opencode/ai/providers"
|
|
395
|
+
|
|
396
|
+
OpenRouter.configure().embedding("openai/text-embedding-3-small")
|
|
397
|
+
VercelAIGateway.configure().embedding("openai/text-embedding-3-small")
|
|
398
|
+
Cohere.configure().embedding("embed-v4.0")
|
|
399
|
+
DeepInfra.configure().embedding("BAAI/bge-m3")
|
|
400
|
+
Fireworks.configure().embedding("nomic-ai/nomic-embed-text-v1.5")
|
|
401
|
+
DigitalOcean.configure().embedding("bge-m3")
|
|
402
|
+
Alibaba.configure({ region: "ap-southeast-1" }).embedding("text-embedding-v4")
|
|
403
|
+
Azure.configure({ resourceName }).embedding("text-embedding-3-small")
|
|
404
|
+
OpenAICompatible.configure({ provider: "nvidia", baseURL: "https://integrate.api.nvidia.com/v1" }).embedding(
|
|
405
|
+
"nvidia/nemotron-3.5-embed-1b",
|
|
406
|
+
)
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Every host here uses OpenAI's `/embeddings` API; Cohere through its compatibility API
|
|
410
|
+
(`https://api.cohere.ai/compatibility/v1`). Package entry points are `@opencode/ai/providers/<provider>/embeddings`.
|
|
411
|
+
|
|
412
|
+
Google embeds through `embedContent`, which also takes images, audio, video and PDFs on `gemini-embedding-2`. Each
|
|
413
|
+
value is its own content and gets its own vector (several parts in one content would be averaged into one). `dimensions`
|
|
414
|
+
is `outputDimensionality`, `inputType` becomes `taskType` `RETRIEVAL_QUERY` or `RETRIEVAL_DOCUMENT`, and `taskType` or
|
|
415
|
+
`title` in `providerOptions` replace or add to it. `gemini-embedding-2` ignores task types; Google recommends writing the
|
|
416
|
+
task into the text instead (`task: search result | query: …`, `title: none | text: …`).
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
import { Google, GoogleVertex } from "@opencode/ai/providers"
|
|
420
|
+
|
|
421
|
+
const response = await ai.embedding.generate({
|
|
422
|
+
model: Google.configure().embedding("gemini-embedding-2"),
|
|
423
|
+
values: [await ai.file("./receipt.png"), "A receipt for two coffees."],
|
|
424
|
+
dimensions: 768,
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
GoogleVertex.configure({ project, location: "global" }).embedding("gemini-embedding-2")
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
`GoogleVertex.configure().embedding(id)` picks the API from the model id: `gemini-embedding-2*` uses `embedContent`,
|
|
431
|
+
and every other model (`gemini-embedding-001`, `text-embedding-005`, `text-multilingual-embedding-002`) uses the
|
|
432
|
+
text-only `:predict` API, which also works with Express Mode keys. On `:predict`, `inputType` and the `taskType` and
|
|
433
|
+
`title` options go on each instance (`task_type`, `title`), and `dimensions`, `autoTruncate` and other options go under
|
|
434
|
+
`parameters`.
|
|
435
|
+
|
|
436
|
+
```ts
|
|
437
|
+
GoogleVertex.configure({ apiKey }).embedding("text-embedding-005")
|
|
438
|
+
GoogleVertex.configure({ apiKey }).embedding("gemini-embedding-001")
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
The Gemini API sends up to 100 values per `batchEmbedContents` request, and Vertex `:predict` up to 250 per request
|
|
442
|
+
(one for `gemini-embedding-001`, as Google documents). Vertex `embedContent` takes one value per request, so a call
|
|
443
|
+
sends one request per value, four at a time, and needs project credentials: Vertex Express Mode API keys can't call
|
|
444
|
+
`embedContent`. `gemini-embedding-2` runs in the `global`, `us` and `eu` Vertex locations. When a call
|
|
445
|
+
is split into several requests, the vectors stay in value order, `usage.inputTokens` is their sum, and each request's
|
|
446
|
+
metadata is listed in order under `providerMetadata.<provider>.responses`. The package entry points are
|
|
447
|
+
`@opencode/ai/providers/google/embeddings` and `@opencode/ai/providers/google-vertex/embeddings`.
|
|
448
|
+
|
|
358
449
|
## Alibaba Cloud Model Studio
|
|
359
450
|
|
|
360
451
|
`Alibaba` provides standard Model Studio inference. Configure a region explicitly, then select
|
|
@@ -940,6 +1031,111 @@ const program = Effect.gen(function* () {
|
|
|
940
1031
|
|
|
941
1032
|
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.
|
|
942
1033
|
|
|
1034
|
+
## Video generation
|
|
1035
|
+
|
|
1036
|
+
Video generation is a job: `start` submits it and returns at once, and the caller decides when to read its `status`,
|
|
1037
|
+
fetch its `result`, or `cancel` it. Nothing polls for you. Every call after `start` takes the model and the job's
|
|
1038
|
+
`token`, plain JSON you can store and read back from another process, so recovering after a restart is the same call
|
|
1039
|
+
as a normal status read. Models come from `.video(...)` selectors on the `XAI`, `OpenRouter`, `Volcengine`,
|
|
1040
|
+
`BytePlus`, `MiniMax` and `Google` facades.
|
|
1041
|
+
|
|
1042
|
+
```ts
|
|
1043
|
+
import { Effect } from "effect"
|
|
1044
|
+
import { ai, Media } from "@opencode/ai/effect"
|
|
1045
|
+
import { XAI } from "@opencode/ai/providers"
|
|
1046
|
+
|
|
1047
|
+
const model = XAI.configure({ apiKey: process.env.XAI_API_KEY }).video("grok-imagine-video-1.5")
|
|
1048
|
+
|
|
1049
|
+
const program = Effect.gen(function* () {
|
|
1050
|
+
const job = yield* ai.video.start({
|
|
1051
|
+
model,
|
|
1052
|
+
prompt: "Panning wide shot of a calico kitten sleeping in the sunshine",
|
|
1053
|
+
start: "https://example.com/first-frame.png", // exact first frame; `end` pins the last one
|
|
1054
|
+
references: [], // images, videos or audio that guide subject or style
|
|
1055
|
+
duration: "8 seconds",
|
|
1056
|
+
aspect: "16:9", // or "auto" to follow the start image
|
|
1057
|
+
resolution: "720p", // 480p | 720p | 1080p | 4k, or any provider value
|
|
1058
|
+
sound: false,
|
|
1059
|
+
})
|
|
1060
|
+
job.token // `{ requestID }` for xAI: store it with the provider and model ID
|
|
1061
|
+
|
|
1062
|
+
const status = yield* ai.video.status(model, job.token)
|
|
1063
|
+
status.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
|
|
1064
|
+
status.progress // 0..1, only when the provider reports it
|
|
1065
|
+
|
|
1066
|
+
const response = yield* ai.video.result(model, job.token)
|
|
1067
|
+
yield* Media.write(response.video, "./kitten.mp4") // streams the download to disk
|
|
1068
|
+
})
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
The shared fields are `prompt`, `start`, `end`, `references`, `duration`, `aspect`, `resolution` and `sound`;
|
|
1072
|
+
everything else is provider-specific and goes under `providerOptions`, typed from the selected model. A request only
|
|
1073
|
+
fails before sending when its protocol has no way to express it, such as a reference video on xAI. Values the provider
|
|
1074
|
+
may reject, like an unsupported duration or too many references, go to the provider, and its error comes back typed.
|
|
1075
|
+
|
|
1076
|
+
`status` is one read; `result` fails with an `InvalidRequest` reason when the job hasn't finished, and with the
|
|
1077
|
+
provider's reason (and terminal document on `reason.body`) when it failed, was cancelled or expired. Moderation
|
|
1078
|
+
outcomes (xAI `respect_moderation`) fail with a `ContentPolicy` reason when no video comes back. Status and result reads
|
|
1079
|
+
retry transient failures (rate limits, provider 5xx, network errors) with backoff that honors `retry-after`; `start`
|
|
1080
|
+
and `cancel` never retry. `cancel` fails with an `UnsupportedOperation` reason on providers without a cancel endpoint,
|
|
1081
|
+
such as xAI, where the job keeps running and billing. Finished videos are usually URLs that expire (`expiresAt` when the
|
|
1082
|
+
provider documents it): download them with `Media.write`, `asset.stream()` or `materialize()` before then.
|
|
1083
|
+
|
|
1084
|
+
Provider notes:
|
|
1085
|
+
|
|
1086
|
+
- **xAI** maps `start` to `image`, `end` to `last_frame`, image references to `reference_images`, audio references to
|
|
1087
|
+
`reference_audios`, and `sound` to `generate_audio`, and leaves `aspect: "auto"` out when a start frame sets the
|
|
1088
|
+
shape. It has no reference video input. `providerOptions.mode: "edit" | "extend"` sends a native `video: { url }`
|
|
1089
|
+
source to `/videos/edits` or `/videos/extensions`.
|
|
1090
|
+
- **OpenRouter** (`OpenRouter.configure(...).video("google/veo-3.1")`) maps `start` and `end` to `frame_images`,
|
|
1091
|
+
references to `input_references` by kind (`image_url`, `video_url`, `audio_url`), `sound` to `generate_audio`, and
|
|
1092
|
+
`resolution` to its spelling (`4k` → `4K`), and leaves `aspect: "auto"` out so models that can follow the input image do.
|
|
1093
|
+
Frames and references are both sent; when both are present OpenRouter keeps the frames and drops the references. It
|
|
1094
|
+
rejects reference videos or audio that aren't http(s) URLs (inline images work). Routing and upstream parameters go under `providerOptions.provider` (`only`, `order`,
|
|
1095
|
+
`options: { <slug>: {...} }`), and `providerOptions.previous_job_id` edits or extends a finished job. Results are
|
|
1096
|
+
OpenRouter content URLs that download with the API key, which the asset carries; there is no cancel endpoint.
|
|
1097
|
+
- **Seedance** (`Volcengine.configure(...).video(...)` with `ARK_API_KEY`, `BytePlus.configure(...).video(...)` with
|
|
1098
|
+
`BYTEPLUS_API_KEY`) builds Ark's `content[]`: the prompt as a `text` item, `start` and `end` as `image_url` items
|
|
1099
|
+
with roles `first_frame` and `last_frame`, and references as `reference_image`, `reference_video` or
|
|
1100
|
+
`reference_audio` by kind. Your own `Media.ref(...)` assets go as `asset://<id>`. `duration` goes to `duration`,
|
|
1101
|
+
`aspect` to `ratio` (`auto` becomes `adaptive`), `resolution` to `resolution` and `sound` to `generate_audio`. Ark
|
|
1102
|
+
doesn't allow frames and references in one task; that combination is sent and the provider's error comes back.
|
|
1103
|
+
`providerOptions.draft_task: { id }` adds a `draft_task` item; `frames`, `seed`, `watermark`, `output_format`,
|
|
1104
|
+
`omni_reference_task_type`, `return_last_frame` and the rest go into the body as-is. `cancel` sends `DELETE`, which
|
|
1105
|
+
only cancels a queued task: Ark refuses it for a running one and deletes the record of a finished one. Video URLs
|
|
1106
|
+
expire 24 hours after the task finished.
|
|
1107
|
+
- **MiniMax** (`MiniMax.configure(...).video(id)`, or `@opencode/ai/providers/minimax/videos`) serves two APIs and picks
|
|
1108
|
+
one by model family: Hailuo and `*-01` models use v1, everything else (H3) uses v2. Video builds its `/v1` and `/v2`
|
|
1109
|
+
paths on the API host, so a `baseURL` shared with images or chat (`https://api.minimax.cn/v1`) loses its trailing
|
|
1110
|
+
`/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` /
|
|
1111
|
+
`reference_video` / `reference_audio` roles, MiniMax file refs become `mm_file://` URLs, `aspect: "auto"` becomes
|
|
1112
|
+
`ratio: "adaptive"`, and `resolution` is uppercased (`480P`, `2K`). H3 requires `resolution` and `duration`, plus a
|
|
1113
|
+
`ratio` for text-only prompts; nothing is filled in, so MiniMax rejects a request without them. H3 always has sound,
|
|
1114
|
+
so `sound: false` fails before sending. On Hailuo, `start` and `end` map to `first_frame_image` and
|
|
1115
|
+
`last_frame_image`, image references to `subject_reference`, and the result looks up the file's download URL, which
|
|
1116
|
+
expires after one hour. Hailuo is silent and has no aspect field, so `sound: true`, an explicit `aspect`, and video
|
|
1117
|
+
or audio references fail before sending. Cancel works on H3 (only while queued); Hailuo has no cancel. Native fields
|
|
1118
|
+
such as `extra.prompt_expansion_mode` (H3), `prompt_optimizer` (Hailuo) and `callback_url` go under `providerOptions`.
|
|
1119
|
+
- **Google** (`Google.video("gemini-omni-1.2-flash")`) starts a background Gemini Omni interaction. Omni has no
|
|
1120
|
+
role field for media, so `start`, `end` and `references` go into `input` in that order (images, plus video
|
|
1121
|
+
references), and `generation_config.video_config.task` is set to `image_to_video` for frames only or
|
|
1122
|
+
`reference_to_video` for references only; with both, the prompt decides. `duration` becomes
|
|
1123
|
+
`response_format.duration` (`"3s"`), and `aspect` and `resolution` go to `response_format` as is (resolution
|
|
1124
|
+
lowercased); `aspect: "auto"` leaves the ratio out. It rejects `end` without `start` (a lone image reads as the
|
|
1125
|
+
first frame) and `sound: false` (Omni always generates audio). Videos come back as inline bytes. `cancel` posts to
|
|
1126
|
+
`/interactions/{id}/cancel`. `providerOptions` takes native Interactions fields, such as `previous_interaction_id`
|
|
1127
|
+
to edit or extend a generated video, `generation_config.video_config.task`, `service_tier` and `webhook_config`.
|
|
1128
|
+
|
|
1129
|
+
The promise client has the same calls, each accepting `{ signal }`:
|
|
1130
|
+
|
|
1131
|
+
```ts
|
|
1132
|
+
import { ai } from "@opencode/ai"
|
|
1133
|
+
|
|
1134
|
+
const job = await ai.video.start({ model, prompt })
|
|
1135
|
+
const status = await ai.video.status(model, job.token)
|
|
1136
|
+
if (status.status === "completed") await ai.write((await ai.video.result(model, job.token)).video, "./kite.mp4")
|
|
1137
|
+
```
|
|
1138
|
+
|
|
943
1139
|
## Public API
|
|
944
1140
|
|
|
945
1141
|
Everything below is exported from `@opencode/ai/effect` unless noted.
|
|
@@ -953,116 +1149,30 @@ Everything below is exported from `@opencode/ai/effect` unless noted.
|
|
|
953
1149
|
- **`LLMEvent.is.*`** — typed guards (`is.textDelta`, `is.toolCall`, `is.finish`, …) for filtering streams.
|
|
954
1150
|
- **`ai.image.request` / `generate` / `stream` / `start` / `resume`** — images over inline, streaming (partial previews), and queued routes through a provider-neutral request and response model.
|
|
955
1151
|
- **`ImageClient`** — Effect service and layer for image execution, parallel to `LLMClient`.
|
|
1152
|
+
- **`ai.video.request` / `start` / `status` / `result` / `cancel`** — video generation as a job addressed by a stored token; see [Video generation](#video-generation). `VideoClient` is its Effect service and layer.
|
|
956
1153
|
- **`Media`** — the shared asset type (`Media.Asset`, `Media.Source`) and constructors used by messages, tool results, and media requests.
|
|
957
1154
|
- **`Generation`** — provider-neutral handle for an in-flight media generation (`await`, `refresh`, `cancel`, `events`) used by queued media routes.
|
|
958
1155
|
- **`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.
|
|
1156
|
+
- **`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.
|
|
959
1157
|
- **`AIClient.layer` / `AIClient.layerWith(executor)`** — every modality client plus the request executor in one layer.
|
|
960
|
-
- **`@opencode/ai`** (Promise root) — a default `ai` with the text calls (`request`, `generate`, `stream`, `loop`, `compact`, `canCompact`) at the top level plus `image` and `
|
|
961
|
-
- **`@opencode/ai/experimental`** — APIs that may change without compatibility guarantees: `
|
|
1158
|
+
- **`@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`.
|
|
1159
|
+
- **`@opencode/ai/experimental`** — APIs that may change without compatibility guarantees: `Speech`, `Transcription`, `Extraction`, and `Realtime`. See [Experimental](#experimental).
|
|
962
1160
|
|
|
963
1161
|
## Experimental
|
|
964
1162
|
|
|
965
1163
|
These APIs may change without compatibility guarantees. The Effect API is exported from `@opencode/ai/experimental`,
|
|
966
1164
|
and the Promise client exposes it under `ai.experimental`.
|
|
967
1165
|
|
|
968
|
-
- **`
|
|
969
|
-
`
|
|
970
|
-
`.transcription`.
|
|
1166
|
+
- **`Speech`** and **`Transcription`** — speech generation and speech-to-text, with `SpeechClient` and
|
|
1167
|
+
`TranscriptionClient` as their Effect services. Promise: `ai.experimental.speech` and `.transcription`.
|
|
971
1168
|
- **`Extraction`** — typed values read out of text.
|
|
972
1169
|
- **`Realtime`** — `Realtime.connect` starts an OpenAI, xAI, or Gemini voice session and returns a WebRTC answer SDP or
|
|
973
1170
|
a short-lived WebSocket URL and token.
|
|
974
1171
|
|
|
975
|
-
The provider selectors for these modalities (`.
|
|
1172
|
+
The provider selectors for these modalities (`.speech(...)`, `.transcription(...)`,
|
|
976
1173
|
`.experimental.extraction(...)`) and their protocol entrypoints (such as `@opencode/ai/protocols/openai-speech`) are
|
|
977
1174
|
part of the same experimental surface.
|
|
978
1175
|
|
|
979
|
-
### Video generation
|
|
980
|
-
|
|
981
|
-
Video mirrors `Image` with one difference: every provider is asynchronous, so the route is a submit-then-poll
|
|
982
|
-
`Generation`. Models come from `.video(...)` selectors on the `Google` (Veo), `XAI`, and `Runway` facades.
|
|
983
|
-
Common fields (`frames`, `references`, `video`, `durationSeconds`, `aspect`, `resolution`, `audio`, `n`, `seed`,
|
|
984
|
-
`negativePrompt`) lower natively or fail with a typed `AIError` before any network call; provider-native controls live
|
|
985
|
-
under `providerOptions`, inferred from the selected model.
|
|
986
|
-
|
|
987
|
-
```ts
|
|
988
|
-
import { Video } from "@opencode/ai/experimental"
|
|
989
|
-
import { Google, Runway } from "@opencode/ai/providers"
|
|
990
|
-
|
|
991
|
-
const google = Google.configure({ apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY })
|
|
992
|
-
|
|
993
|
-
// Simple: submit and wait.
|
|
994
|
-
const program = Effect.gen(function* () {
|
|
995
|
-
const response = yield* Video.generate(
|
|
996
|
-
{
|
|
997
|
-
model: google.video("veo-3.1-generate-preview"),
|
|
998
|
-
prompt: "Panning wide shot of a calico kitten sleeping in the sunshine",
|
|
999
|
-
aspect: "16:9",
|
|
1000
|
-
resolution: "1080p",
|
|
1001
|
-
durationSeconds: 8,
|
|
1002
|
-
providerOptions: { personGeneration: "allow_adult" },
|
|
1003
|
-
},
|
|
1004
|
-
{ poll: { interval: "10 seconds", timeout: "10 minutes" } },
|
|
1005
|
-
)
|
|
1006
|
-
// Veo serves files for two days behind the API key. The asset knows the deadline (`expiresAt`) and carries the
|
|
1007
|
-
// download credentials only on the live instance (`asset.headers`), never in `source` or JSON: materialize
|
|
1008
|
-
// before persisting, or the persisted URL cannot be fetched again.
|
|
1009
|
-
return yield* response.video.materialize()
|
|
1010
|
-
})
|
|
1011
|
-
|
|
1012
|
-
// Explicit control: keep the handle, persist the token, resume elsewhere.
|
|
1013
|
-
const controlled = Effect.gen(function* () {
|
|
1014
|
-
const generation = yield* Video.start({ model: google.video("veo-3.1-generate-preview"), prompt })
|
|
1015
|
-
generation.id // provider operation / task / request id
|
|
1016
|
-
generation.status // "queued" | "running" | "completed" | "failed" | "cancelled" | "expired"
|
|
1017
|
-
generation.token // route-owned JSON: `{ operation }`, `{ requestID }`, or `{ taskID }`
|
|
1018
|
-
// The token carries no route identity: persist the provider and model ID alongside it, since `resume` needs the model.
|
|
1019
|
-
const saved = JSON.stringify(generation.token)
|
|
1020
|
-
|
|
1021
|
-
const resumed = yield* Video.resume(google.video("veo-3.1-generate-preview"), JSON.parse(saved))
|
|
1022
|
-
return yield* resumed.await({ poll: { interval: "10 seconds" } })
|
|
1023
|
-
})
|
|
1024
|
-
|
|
1025
|
-
// Progress as a stream: generation-queued | generation-progress | video | finish.
|
|
1026
|
-
const events = Video.stream({ model: Runway.configure({ apiKey }).video("gen4.5"), prompt }, { poll })
|
|
1027
|
-
```
|
|
1028
|
-
|
|
1029
|
-
Status polls, result fetches, cancels, and asset downloads all run through the same request executor with the route's
|
|
1030
|
-
auth. `Generation.await` and `Generation.events` fail with a
|
|
1031
|
-
`Timeout` reason when `poll.timeout` (default 10 minutes) elapses. Status polls and result fetches retry transient
|
|
1032
|
-
failures (rate limits, provider 5xx, network errors) with backoff that honors `retry-after`, always within
|
|
1033
|
-
`poll.timeout`; submits and cancels never retry. Interrupting a wait (or aborting its `signal`) does not cancel the
|
|
1034
|
-
provider job, which keeps running and billing: call `cancel()` to stop it. Failed,
|
|
1035
|
-
cancelled, and expired generations fail typed with the provider's terminal document on `reason.body`; moderation
|
|
1036
|
-
outcomes (Veo `raiMediaFilteredReasons`, xAI `respect_moderation`, Runway `SAFETY.*` codes) fail with a
|
|
1037
|
-
`ContentPolicy` reason when no video comes back; when one still does, Veo and xAI keep the raw outcome in
|
|
1038
|
-
`providerMetadata`.
|
|
1039
|
-
|
|
1040
|
-
Provider notes:
|
|
1041
|
-
|
|
1042
|
-
- **Google Veo** takes inline bytes only (materialize `url` assets first); `frames.last` requires `frames.first`;
|
|
1043
|
-
audio is always on, so `audio: false` fails typed; one video per request. Output URLs need the API key to
|
|
1044
|
-
download, which the returned asset holds transiently (see above).
|
|
1045
|
-
- **xAI** sends a `video` input to `/videos/edits`, or `/videos/extensions` with `providerOptions.mode: "extend"`.
|
|
1046
|
-
`seed` and `negativePrompt` are not supported.
|
|
1047
|
-
- **Runway** expects pixel ratios in `aspect` for most models (`"1280:720"`), pins `X-Runway-Version`, reports
|
|
1048
|
-
`usage: { type: "credits" }`, and its output URLs expire after 24–48 hours.
|
|
1049
|
-
|
|
1050
|
-
The promise client exposes the same surface: `ai.experimental.video.start(...)` resolves to a handle with `await`, `events`,
|
|
1051
|
-
`result`, `refresh`, `cancel`, and `token`; `ai.experimental.video.generate`, `ai.experimental.video.resume(model, token)`, and
|
|
1052
|
-
`ai.experimental.video.stream` mirror the Effect API. The handle's `status` and `progress` are a snapshot from when it was
|
|
1053
|
-
created; `refresh()` resolves to a new handle. Every promise method and stream accepts `{ signal }`: like `fetch`,
|
|
1054
|
-
aborting rejects the Promise or throws from the `for await` loop with `signal.reason` (an `AbortError` `DOMException`
|
|
1055
|
-
unless `abort(reason)` passed one), while `break` stops a stream without throwing.
|
|
1056
|
-
|
|
1057
|
-
```ts
|
|
1058
|
-
import { ai } from "@opencode/ai"
|
|
1059
|
-
|
|
1060
|
-
const generation = await ai.experimental.video.start({ model, prompt })
|
|
1061
|
-
for await (const event of generation.events({ poll: { interval: 10_000 } })) console.log(event.type)
|
|
1062
|
-
const video = await generation.result({ signal })
|
|
1063
|
-
await ai.write(video.video, "./kite.mp4")
|
|
1064
|
-
```
|
|
1065
|
-
|
|
1066
1176
|
### Speech generation
|
|
1067
1177
|
|
|
1068
1178
|
Speech (text-to-speech) is one request whose response is parsed incrementally, so every route supports both
|
package/dist/ai-client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { RequestExecutor } from "./route/executor.js";
|
|
3
3
|
/** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
|
|
4
|
-
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
|
|
4
|
+
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./embedding-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
|
|
5
5
|
/** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
|
|
6
|
-
export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
|
|
6
|
+
export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./embedding-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
|
|
7
7
|
export type Services = Layer.Success<typeof layer>;
|
|
8
8
|
export * as AIClient from "./ai-client.js";
|
package/dist/ai-client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { DecisionClient } from "./decision-client.js";
|
|
3
|
+
import { EmbeddingClient } from "./embedding-client.js";
|
|
3
4
|
import { ImageClient } from "./image-client.js";
|
|
4
5
|
import { LLMClient } from "./route/client.js";
|
|
5
6
|
import { RequestExecutor } from "./route/executor.js";
|
|
@@ -7,7 +8,7 @@ import { SpeechClient } from "./speech-client.js";
|
|
|
7
8
|
import { TranscriptionClient } from "./transcription-client.js";
|
|
8
9
|
import { VideoClient } from "./video-client.js";
|
|
9
10
|
/** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
|
|
10
|
-
export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer, DecisionClient.layer).pipe(Layer.provideMerge(executor));
|
|
11
|
+
export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer, DecisionClient.layer, EmbeddingClient.layer).pipe(Layer.provideMerge(executor));
|
|
11
12
|
/** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
|
|
12
13
|
export const layer = layerWith(RequestExecutor.fetchLayer);
|
|
13
14
|
export * as AIClient from "./ai-client.js";
|
package/dist/decision.d.ts
CHANGED
|
@@ -104,6 +104,11 @@ export declare const PredicateQuestion: Schema.Struct<{
|
|
|
104
104
|
readonly name: Schema.String;
|
|
105
105
|
readonly type: Schema.Literal<"predicate">;
|
|
106
106
|
readonly instructions: Schema.String;
|
|
107
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
108
|
+
readonly criteria: Schema.optional<Schema.Struct<{
|
|
109
|
+
readonly true: Schema.optional<Schema.String>;
|
|
110
|
+
readonly false: Schema.optional<Schema.String>;
|
|
111
|
+
}>>;
|
|
107
112
|
}>;
|
|
108
113
|
export type PredicateQuestion = Schema.Schema.Type<typeof PredicateQuestion>;
|
|
109
114
|
export declare const ChoiceQuestion: Schema.Struct<{
|
|
@@ -130,6 +135,11 @@ export declare const DecisionQuestion: Schema.toTaggedUnion<"type", readonly [Sc
|
|
|
130
135
|
readonly name: Schema.String;
|
|
131
136
|
readonly type: Schema.Literal<"predicate">;
|
|
132
137
|
readonly instructions: Schema.String;
|
|
138
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
139
|
+
readonly criteria: Schema.optional<Schema.Struct<{
|
|
140
|
+
readonly true: Schema.optional<Schema.String>;
|
|
141
|
+
readonly false: Schema.optional<Schema.String>;
|
|
142
|
+
}>>;
|
|
133
143
|
}>, Schema.Struct<{
|
|
134
144
|
readonly name: Schema.String;
|
|
135
145
|
readonly type: Schema.Literal<"choice">;
|
package/dist/decision.js
CHANGED
|
@@ -23,6 +23,8 @@ export const PredicateQuestion = Schema.Struct({
|
|
|
23
23
|
name: Schema.String,
|
|
24
24
|
type: Schema.Literal("predicate"),
|
|
25
25
|
instructions: Schema.String,
|
|
26
|
+
/** What counts as true and as false, for statements the instructions alone leave ambiguous. */
|
|
27
|
+
criteria: Schema.optional(Schema.Struct({ true: Schema.optional(Schema.String), false: Schema.optional(Schema.String) })),
|
|
26
28
|
});
|
|
27
29
|
export const ChoiceQuestion = Schema.Struct({
|
|
28
30
|
name: Schema.String,
|
package/dist/effect.d.ts
CHANGED
|
@@ -19,6 +19,17 @@ export declare const ai: {
|
|
|
19
19
|
readonly request: typeof import("./decision.js").request;
|
|
20
20
|
readonly generate: typeof import("./decision.js").generate;
|
|
21
21
|
};
|
|
22
|
+
readonly embedding: {
|
|
23
|
+
readonly request: typeof import("./embedding.js").request;
|
|
24
|
+
readonly generate: typeof import("./embedding.js").generate;
|
|
25
|
+
};
|
|
26
|
+
readonly video: {
|
|
27
|
+
readonly request: typeof import("./video.js").request;
|
|
28
|
+
readonly start: typeof import("./video.js").start;
|
|
29
|
+
readonly status: typeof import("./video.js").status;
|
|
30
|
+
readonly result: typeof import("./video.js").result;
|
|
31
|
+
readonly cancel: typeof import("./video.js").cancel;
|
|
32
|
+
};
|
|
22
33
|
/** Experimental: may change without compatibility guarantees. */
|
|
23
34
|
readonly experimental: {
|
|
24
35
|
readonly speech: {
|
|
@@ -33,23 +44,19 @@ export declare const ai: {
|
|
|
33
44
|
readonly start: typeof import("./transcription.js").start;
|
|
34
45
|
readonly resume: typeof import("./transcription.js").resume;
|
|
35
46
|
};
|
|
36
|
-
readonly video: {
|
|
37
|
-
readonly request: typeof import("./video.js").request;
|
|
38
|
-
readonly start: typeof import("./video.js").start;
|
|
39
|
-
readonly generate: typeof import("./video.js").generate;
|
|
40
|
-
readonly resume: typeof import("./video.js").resume;
|
|
41
|
-
readonly stream: typeof import("./video.js").stream;
|
|
42
|
-
};
|
|
43
47
|
};
|
|
44
48
|
};
|
|
45
49
|
export { AIClient } from "./ai-client.js";
|
|
46
50
|
export { LLMClient } from "./route/client.js";
|
|
47
51
|
export { ImageClient } from "./image-client.js";
|
|
52
|
+
export { VideoClient } from "./video-client.js";
|
|
48
53
|
export { Auth } from "./route/auth.js";
|
|
49
54
|
export { ProviderPackage } from "./provider-package.js";
|
|
50
55
|
export type { LLMClientService } from "./route/client.js";
|
|
51
56
|
export { DecisionClient } from "./decision-client.js";
|
|
52
57
|
export { DecisionRoute } from "./route/decision.js";
|
|
58
|
+
export { EmbeddingClient } from "./embedding-client.js";
|
|
59
|
+
export { EmbeddingRoute } from "./route/embedding.js";
|
|
53
60
|
export { Generation } from "./generation.js";
|
|
54
61
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
55
62
|
export { ToolRuntime } from "./tool-runtime.js";
|
package/dist/effect.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Decision } from "./decision.js";
|
|
2
|
+
import { Embedding } from "./embedding.js";
|
|
2
3
|
import { Image } from "./image.js";
|
|
3
4
|
import { LLM } from "./llm.js";
|
|
4
5
|
import { Speech } from "./speech.js";
|
|
@@ -15,20 +16,24 @@ export const ai = {
|
|
|
15
16
|
canCompact: LLM.canCompact,
|
|
16
17
|
image: Image,
|
|
17
18
|
decision: Decision,
|
|
19
|
+
embedding: Embedding,
|
|
20
|
+
video: Video,
|
|
18
21
|
/** Experimental: may change without compatibility guarantees. */
|
|
19
22
|
experimental: {
|
|
20
23
|
speech: Speech,
|
|
21
24
|
transcription: Transcription,
|
|
22
|
-
video: Video,
|
|
23
25
|
},
|
|
24
26
|
};
|
|
25
27
|
export { AIClient } from "./ai-client.js";
|
|
26
28
|
export { LLMClient } from "./route/client.js";
|
|
27
29
|
export { ImageClient } from "./image-client.js";
|
|
30
|
+
export { VideoClient } from "./video-client.js";
|
|
28
31
|
export { Auth } from "./route/auth.js";
|
|
29
32
|
export { ProviderPackage } from "./provider-package.js";
|
|
30
33
|
export { DecisionClient } from "./decision-client.js";
|
|
31
34
|
export { DecisionRoute } from "./route/decision.js";
|
|
35
|
+
export { EmbeddingClient } from "./embedding-client.js";
|
|
36
|
+
export { EmbeddingRoute } from "./route/embedding.js";
|
|
32
37
|
export { Generation } from "./generation.js";
|
|
33
38
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
34
39
|
export { ToolRuntime } from "./tool-runtime.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import type { EmbeddingModel, EmbeddingOptions, EmbeddingRequest, EmbeddingResponse } from "./embedding.js";
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import { AIError } from "./schema/index.js";
|
|
5
|
+
export type Execute = RequestExecutor.Interface["execute"];
|
|
6
|
+
export interface Interface {
|
|
7
|
+
readonly generate: <Options extends EmbeddingOptions>(request: EmbeddingRequest<EmbeddingModel<Options>>) => Effect.Effect<EmbeddingResponse, AIError>;
|
|
8
|
+
}
|
|
9
|
+
declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/EmbeddingClient", Interface>;
|
|
10
|
+
export declare class Service extends Service_base {
|
|
11
|
+
}
|
|
12
|
+
export declare const generate: <Options extends EmbeddingOptions>(request: EmbeddingRequest<EmbeddingModel<Options>>) => Effect.Effect<EmbeddingResponse, AIError, Service>;
|
|
13
|
+
export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
|
|
14
|
+
export declare const fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
|
|
15
|
+
export declare const EmbeddingClient: {
|
|
16
|
+
readonly Service: typeof Service;
|
|
17
|
+
readonly layer: Layer.Layer<Service, never, RequestExecutor.RequestExecutorService>;
|
|
18
|
+
readonly fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
|
|
19
|
+
readonly generate: typeof generate;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
2
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
3
|
+
import { AIError, InvalidProviderOutputError } from "./schema/index.js";
|
|
4
|
+
export class Service extends Context.Service()("@opencode/AI/EmbeddingClient") {
|
|
5
|
+
}
|
|
6
|
+
export const generate = (request) => Effect.flatMap(Service, (client) => client.generate(request));
|
|
7
|
+
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
8
|
+
const executor = yield* RequestExecutor.Service;
|
|
9
|
+
return Service.of({
|
|
10
|
+
generate: Effect.fnUntraced(function* (request) {
|
|
11
|
+
const route = request.model.route;
|
|
12
|
+
const response = yield* route.generate(request, executor.execute);
|
|
13
|
+
if (response.embeddings.length === request.values.length)
|
|
14
|
+
return response;
|
|
15
|
+
return yield* new AIError({
|
|
16
|
+
reason: new InvalidProviderOutputError({
|
|
17
|
+
route: route.id,
|
|
18
|
+
message: `Expected ${request.values.length} embeddings, got ${response.embeddings.length}`,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
export const fetchLayer = layer.pipe(Layer.provideMerge(RequestExecutor.fetchLayer));
|
|
25
|
+
export const EmbeddingClient = {
|
|
26
|
+
Service,
|
|
27
|
+
layer,
|
|
28
|
+
fetchLayer,
|
|
29
|
+
generate,
|
|
30
|
+
};
|