@warlock.js/ai-live 4.6.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/cjs/index.cjs +257 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/contracts/realtime.contract.d.mts +104 -0
- package/esm/contracts/realtime.contract.d.mts.map +1 -0
- package/esm/contracts/video.contract.d.mts +72 -0
- package/esm/contracts/video.contract.d.mts.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.d.mts.map +1 -0
- package/esm/index.mjs +12 -0
- package/esm/index.mjs.map +1 -0
- package/esm/mock/index.d.mts +52 -0
- package/esm/mock/index.d.mts.map +1 -0
- package/esm/mock/index.mjs +74 -0
- package/esm/mock/index.mjs.map +1 -0
- package/esm/realtime/realtime.d.mts +29 -0
- package/esm/realtime/realtime.d.mts.map +1 -0
- package/esm/realtime/realtime.mjs +61 -0
- package/esm/realtime/realtime.mjs.map +1 -0
- package/esm/video/video.d.mts +59 -0
- package/esm/video/video.d.mts.map +1 -0
- package/esm/video/video.mjs +118 -0
- package/esm/video/video.mjs.map +1 -0
- package/llms-full.txt +210 -0
- package/llms.txt +9 -0
- package/package.json +34 -0
- package/skills/use-ai-live/SKILL.md +200 -0
package/llms.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Warlock AI Live
|
|
2
|
+
|
|
3
|
+
> Package: `@warlock.js/ai-live`
|
|
4
|
+
|
|
5
|
+
> Live & generative rich-media for @warlock.js/ai — ai.realtime() duplex voice sessions and ai.video() text-to-video. The heavy, demand-gated modalities, kept out of core so text/image/speech stay dependency-light.
|
|
6
|
+
|
|
7
|
+
## Skills
|
|
8
|
+
|
|
9
|
+
- [use-ai-live](@warlock.js/ai-live/use-ai-live/SKILL.md): Live & generative rich-media add-on for @warlock.js/ai. A side-effect import `import "@warlock.js/ai-live"` mounts two heavy modalities onto the shared `ai.*` facade: `ai.video({ model, prompt })` — text-to-video (Sora / Veo / Kling-class), the async submit→poll job hidden behind the same uniform never-throws `{ data, error, usage, report }` envelope as `ai.image`, with per-second cost-truth folded into `Usage.cost`; and `ai.realtime({ transport, model })` — a stateful duplex VOICE SESSION over a pluggable `RealtimeTransport` (sendAudio / sendText / events() / close()→RealtimeReport). Videos are a discriminated `GeneratedVideo = { type: "url" } | { type: "base64" }`; session output is a `RealtimeEvent` union (audio | transcript | tool-call | error | done). Ships `MockVideoModel` + `MockRealtimeTransport` for HTTP-free tests. Triggers: `ai.video`, `ai.realtime`, `VideoModelContract`, `GeneratedVideo`, `VideoModelPricing`, `RealtimeSession`, `RealtimeTransport`, `RealtimeEvent`, `RealtimeReport`, `MockVideoModel`, `MockRealtimeTransport`; 'generate a video', 'text to video', 'sora', 'veo', 'realtime voice', 'duplex voice session', 'live voice agent', 'barge-in', 'per-second video cost'; typical import `import "@warlock.js/ai-live"` + `import { ai } from "@warlock.js/ai"`. Skip: still-image OUTPUT — [[generate-images]]; text-to-speech / transcription (one-shot audio, not a session) — [[generate-speech]]; chat agents / tools / workflows — `@warlock.js/ai/run-ai-agent/SKILL.md`.
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@warlock.js/ai-live",
|
|
3
|
+
"description": "Live & generative rich-media for @warlock.js/ai — ai.realtime() duplex voice sessions and ai.video() text-to-video. The heavy, demand-gated modalities, kept out of core so text/image/speech stay dependency-light.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"ai",
|
|
6
|
+
"realtime",
|
|
7
|
+
"voice",
|
|
8
|
+
"video",
|
|
9
|
+
"warlock"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@warlock.js/logger": "4.6.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@warlock.js/ai": "4.6.0"
|
|
17
|
+
},
|
|
18
|
+
"version": "4.6.0",
|
|
19
|
+
"main": "./cjs/index.cjs",
|
|
20
|
+
"module": "./esm/index.mjs",
|
|
21
|
+
"types": "./esm/index.d.mts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./esm/index.d.mts",
|
|
26
|
+
"default": "./esm/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./esm/index.d.mts",
|
|
30
|
+
"default": "./cjs/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: use-ai-live
|
|
3
|
+
description: 'Live & generative rich-media add-on for @warlock.js/ai. A side-effect import `import "@warlock.js/ai-live"` mounts two heavy modalities onto the shared `ai.*` facade: `ai.video({ model, prompt })` — text-to-video (Sora / Veo / Kling-class), the async submit→poll job hidden behind the same uniform never-throws `{ data, error, usage, report }` envelope as `ai.image`, with per-second cost-truth folded into `Usage.cost`; and `ai.realtime({ transport, model })` — a stateful duplex VOICE SESSION over a pluggable `RealtimeTransport` (sendAudio / sendText / events() / close()→RealtimeReport). Videos are a discriminated `GeneratedVideo = { type: "url" } | { type: "base64" }`; session output is a `RealtimeEvent` union (audio | transcript | tool-call | error | done). Ships `MockVideoModel` + `MockRealtimeTransport` for HTTP-free tests. Triggers: `ai.video`, `ai.realtime`, `VideoModelContract`, `GeneratedVideo`, `VideoModelPricing`, `RealtimeSession`, `RealtimeTransport`, `RealtimeEvent`, `RealtimeReport`, `MockVideoModel`, `MockRealtimeTransport`; ''generate a video'', ''text to video'', ''sora'', ''veo'', ''realtime voice'', ''duplex voice session'', ''live voice agent'', ''barge-in'', ''per-second video cost''; typical import `import "@warlock.js/ai-live"` + `import { ai } from "@warlock.js/ai"`. Skip: still-image OUTPUT — [[generate-images]]; text-to-speech / transcription (one-shot audio, not a session) — [[generate-speech]]; chat agents / tools / workflows — `@warlock.js/ai/run-ai-agent/SKILL.md`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Live rich-media — `ai.video` + `ai.realtime` (`@warlock.js/ai-live`)
|
|
7
|
+
|
|
8
|
+
`@warlock.js/ai` ships the synchronous modality verbs (`ai.agent`, `ai.image`, `ai.speech`, `ai.transcribe`). `ai-live` adds the two that need heavyweight, demand-gated machinery — a **long-running job** (video) and a **persistent network session** (realtime voice) — kept in their own package so the core stays dependency-light.
|
|
9
|
+
|
|
10
|
+
Both mount onto the same `ai.*` facade by a **side-effect import**:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import "@warlock.js/ai-live"; // lights up ai.video + ai.realtime on the shared Ai facade
|
|
14
|
+
import { ai } from "@warlock.js/ai";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The mount mirrors how `@warlock.js/ai-tools` mounts `ai.mcp` and `@warlock.js/ai-workspace` mounts `ai.workspace`: a `declare module "@warlock.js/ai"` interface-merge plus `ai.video = video; ai.realtime = realtime` at load. Forget the side-effect import and `ai.video` is a compile-time `undefined` — not a silent runtime miss.
|
|
18
|
+
|
|
19
|
+
## `ai.video` — text-to-video, uniform envelope
|
|
20
|
+
|
|
21
|
+
Prompt in / one video out. The adapter hides the provider's async **submit→poll** lifecycle and resolves only when the clip is ready, so the verb returns the framework's uniform **never-throws** `{ data, error, usage, report }` — the exact shape `ai.image` returns, so video spend and traces fold into the same dashboards.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { ai } from "@warlock.js/ai";
|
|
25
|
+
|
|
26
|
+
const { data, error, usage, report } = await ai.video({
|
|
27
|
+
model: sora.video({ name: "sora-2", pricing: { perSecond: 0.1 } }), // VideoModelContract
|
|
28
|
+
prompt: "a timelapse of a city skyline at dusk, cinematic",
|
|
29
|
+
durationSeconds: 8,
|
|
30
|
+
aspectRatio: "16:9",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (error) {
|
|
34
|
+
console.warn(error.code); // typed AIError — NEVER thrown
|
|
35
|
+
} else {
|
|
36
|
+
const clip = data.video; // GeneratedVideo (discriminated)
|
|
37
|
+
if (clip.type === "url") download(clip.url);
|
|
38
|
+
else save(Buffer.from(clip.base64, "base64"), clip.mediaType);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Shape
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
type VideoResult = ExecuteResult<VideoData> & { type: "video"; report: VideoReport };
|
|
46
|
+
type VideoData = { video: GeneratedVideo };
|
|
47
|
+
|
|
48
|
+
type GeneratedVideo =
|
|
49
|
+
| { type: "url"; url: string; mediaType?: string }
|
|
50
|
+
| { type: "base64"; base64: string; mediaType: string };
|
|
51
|
+
|
|
52
|
+
// VideoParams (provider-neutral) — the model is the only required field beyond prompt:
|
|
53
|
+
await ai.video({
|
|
54
|
+
model, // VideoModelContract from an adapter's video({ name })
|
|
55
|
+
prompt: "...",
|
|
56
|
+
durationSeconds: 8, // requested clip length
|
|
57
|
+
aspectRatio: "9:16",
|
|
58
|
+
resolution: "1080p", // hint
|
|
59
|
+
negativePrompt: "blurry, watermark",
|
|
60
|
+
signal, // AbortSignal → status "cancelled"
|
|
61
|
+
observe: collector, // route the report to an Observer (panoptic), like agents
|
|
62
|
+
sessionId: "campaign-42",
|
|
63
|
+
name: "hero-clip", // report node name (defaults to "video")
|
|
64
|
+
options: { seed: 7 }, // provider-specific escape hatch, forwarded verbatim
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`VideoModelContract` is the moving-image sibling of `ImageModelContract` — `{ name, provider, pricing?, generate(prompt, options) }` — produced by an adapter's `video()` factory. An adapter with no video API simply doesn't define `video()`.
|
|
69
|
+
|
|
70
|
+
## Video cost-truth — per-second first
|
|
71
|
+
|
|
72
|
+
`VideoModelPricing` carries `{ perSecond?, input?, output? }`. Per-second wins when set (video is metered by clip length): `usage.cost = { input: 0, output: durationSeconds × perSecond }`, attributed to `cost.output`. A token-metered model falls back to the standard `computeCost` against reported tokens. No usable pricing → `usage.cost` stays `undefined` (honest "cost unknown", never a false zero). A pre-priced adapter response is honored, not overwritten. The final `durationSeconds` from the provider (not just the requested one) drives the math and lands on `report.durationSeconds`.
|
|
73
|
+
|
|
74
|
+
## `ai.realtime` — a duplex voice SESSION (not a one-shot)
|
|
75
|
+
|
|
76
|
+
Unlike every other `ai.*` verb, `ai.realtime()` returns a **stateful, long-lived session** — its closest sibling is `ai.orchestrator`. You open it over a pluggable **`RealtimeTransport`** (the low-level connection to the provider's realtime endpoint), push microphone audio / text turns in, consume an async **event stream** out, and `close()` to end it and receive a `RealtimeReport` for the cost/observability surfaces.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { ai } from "@warlock.js/ai";
|
|
80
|
+
|
|
81
|
+
const session = await ai.realtime({
|
|
82
|
+
transport: openAiRealtime({ apiKey }), // RealtimeTransport (own adapter)
|
|
83
|
+
model: "gpt-realtime",
|
|
84
|
+
voice: "alloy",
|
|
85
|
+
instructions: "You are a friendly phone receptionist.",
|
|
86
|
+
sessionId: "call-8891",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
session.sendAudio(micChunkBase64, "audio/pcm"); // push mic audio upstream
|
|
90
|
+
session.sendText("Please hold for one moment."); // or a text turn
|
|
91
|
+
|
|
92
|
+
for await (const event of session.events()) { // duplex output
|
|
93
|
+
switch (event.type) {
|
|
94
|
+
case "audio": speaker.write(event.base64); break;
|
|
95
|
+
case "transcript": if (event.final) log(event.role, event.text); break;
|
|
96
|
+
case "tool-call": await handleTool(event.name, event.input); break;
|
|
97
|
+
case "error": console.warn(event.error.code); break;
|
|
98
|
+
case "done": break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const report = await session.close(); // RealtimeReport — idempotent
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Session contract & event union
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
interface RealtimeSession {
|
|
109
|
+
sendAudio(base64: string, mediaType: string): void;
|
|
110
|
+
sendText(text: string): void;
|
|
111
|
+
events(): AsyncIterable<RealtimeEvent>;
|
|
112
|
+
close(): Promise<RealtimeReport>; // idempotent — second close() returns the first report
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type RealtimeEvent =
|
|
116
|
+
| { type: "audio"; base64: string; mediaType: string }
|
|
117
|
+
| { type: "transcript"; role: "user" | "assistant"; text: string; final: boolean }
|
|
118
|
+
| { type: "tool-call"; id: string; name: string; input: unknown }
|
|
119
|
+
| { type: "error"; error: AIError } // typed, non-fatal
|
|
120
|
+
| { type: "done" }; // server ended the session
|
|
121
|
+
|
|
122
|
+
type RealtimeReport = {
|
|
123
|
+
runId: string; rootRunId: string; type: "realtime";
|
|
124
|
+
name: string; status: "completed" | "failed" | "cancelled";
|
|
125
|
+
startedAt: string; endedAt: string; duration: number; sessionId?: string;
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The transport seam is what lets `ai-live` ship the session surface without hard-wiring `ws` (it's an optional peer). A concrete transport implements just two interfaces: `RealtimeTransport.connect(config) → RealtimeConnection` (with `sendAudio` / `sendText` / `events()` / `close()`).
|
|
130
|
+
|
|
131
|
+
## Pattern — a live phone receptionist over a channel
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import "@warlock.js/ai-live";
|
|
135
|
+
import { ai } from "@warlock.js/ai";
|
|
136
|
+
|
|
137
|
+
async function handleCall(caller: PhoneChannel, transport: RealtimeTransport) {
|
|
138
|
+
const session = await ai.realtime({
|
|
139
|
+
transport,
|
|
140
|
+
model: "gpt-realtime",
|
|
141
|
+
voice: "alloy",
|
|
142
|
+
instructions: "Greet the caller and route them to the right department.",
|
|
143
|
+
sessionId: caller.id,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Pump caller audio → session (fire-and-forget).
|
|
147
|
+
caller.onAudio((chunk) => session.sendAudio(chunk, "audio/pcm"));
|
|
148
|
+
|
|
149
|
+
// Pump session output → caller, until the model signals done.
|
|
150
|
+
for await (const event of session.events()) {
|
|
151
|
+
if (event.type === "audio") caller.playAudio(event.base64);
|
|
152
|
+
if (event.type === "done") break;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const report = await session.close();
|
|
156
|
+
metrics.record({ runId: report.runId, seconds: report.duration / 1000 });
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Testing — mocks, no HTTP, no sockets
|
|
161
|
+
|
|
162
|
+
`@warlock.js/ai-live` exports deterministic doubles so both verbs test offline.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { ai } from "@warlock.js/ai";
|
|
166
|
+
import { MockVideoModel, MockRealtimeTransport } from "@warlock.js/ai-live";
|
|
167
|
+
|
|
168
|
+
// Video — script the returned clip / usage / duration; assert cost math + recorded calls.
|
|
169
|
+
const model = new MockVideoModel("mock-video", [{ durationSeconds: 8 }], { perSecond: 0.1 });
|
|
170
|
+
const { data, usage } = await ai.video({ model, prompt: "x", durationSeconds: 8 });
|
|
171
|
+
// data.video → { type: "url", url: "https://mock/video.mp4", ... }
|
|
172
|
+
// usage.cost.output === 0.8 (8 × 0.1)
|
|
173
|
+
// model.calls[0] → { prompt: "x", options: { durationSeconds: 8, ... } }
|
|
174
|
+
|
|
175
|
+
// Realtime — script the outbound event stream; assert what the session sent.
|
|
176
|
+
const transport = new MockRealtimeTransport([
|
|
177
|
+
{ type: "transcript", role: "assistant", text: "Hi!", final: true },
|
|
178
|
+
{ type: "done" },
|
|
179
|
+
]);
|
|
180
|
+
const session = await ai.realtime({ transport, model: "mock-realtime" });
|
|
181
|
+
session.sendText("hello");
|
|
182
|
+
for await (const e of session.events()) { /* ... */ }
|
|
183
|
+
const report = await session.close();
|
|
184
|
+
// transport.lastConnection.sentText → ["hello"]
|
|
185
|
+
// transport.connectConfigs[0] → { model: "mock-realtime", ... }
|
|
186
|
+
// report.status === "completed"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Feed `MockVideoModel` an `{ error }` response and `ai.video` lands it on `result.error` (never throws), setting `report.status` to `"failed"` (or `"cancelled"` when the signal aborted).
|
|
190
|
+
|
|
191
|
+
## Status — contracts now, transports next
|
|
192
|
+
|
|
193
|
+
`4.6.0` introduces the package: the `VideoModelContract` / `RealtimeSession` contracts, the `ai.video()` verb (uniform envelope + per-second cost-truth, tested against `MockVideoModel`), and the `ai.realtime()` session primitive over a pluggable transport (tested against `MockRealtimeTransport`). The first **concrete provider transports** — an OpenAI Realtime **WebSocket** for `ai.realtime`, and **Sora / Veo** video adapters for `ai.video` — are the next implementation step; the seams are defined so they drop in without changing the verb surface.
|
|
194
|
+
|
|
195
|
+
## See also
|
|
196
|
+
|
|
197
|
+
- [[generate-images]] — still-image OUTPUT (`ai.image`), the synchronous sibling `ai.video` mirrors.
|
|
198
|
+
- [[generate-speech]] — one-shot text-to-speech / transcription (`ai.speech` / `ai.transcribe`); use `ai.realtime` instead when you need a live duplex conversation, not a single audio render.
|
|
199
|
+
- `@warlock.js/ai/observe-ai-flows/SKILL.md` — the `observe` seam both verbs route their reports through.
|
|
200
|
+
- `@warlock.js/ai/run-orchestrator/SKILL.md` — the other session-shaped primitive `ai.realtime` resembles.
|