@reactor-models/lingbot 0.2.18

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 ADDED
@@ -0,0 +1,968 @@
1
+ # @reactor-models/lingbot
2
+
3
+ > Typed JavaScript + React SDK for the **Lingbot** model on [Reactor](https://reactor.inc). Version **v0.2.18**.
4
+
5
+ ---
6
+
7
+ ## Install
8
+
9
+ ```shell
10
+ npm install @reactor-models/lingbot
11
+ ```
12
+
13
+ ```shell
14
+ pnpm add @reactor-models/lingbot
15
+ ```
16
+
17
+ The package exports a plain-JavaScript client and a set of React bindings. Import whichever you need from `@reactor-models/lingbot`:
18
+
19
+ ```typescript
20
+ import { LingbotModel } from "@reactor-models/lingbot";
21
+ ```
22
+
23
+ ```typescript
24
+ import { LingbotProvider, useLingbot } from "@reactor-models/lingbot";
25
+ ```
26
+
27
+ React 18 or later is required when using the provider and hooks.
28
+
29
+ ---
30
+
31
+ ## Authenticate
32
+
33
+ Reactor uses short-lived JWTs for session auth. You hold your API key on your server, mint a token on demand, and the client never sees the raw key. Tokens are valid for **6 hours** — if one leaks, it expires on its own.
34
+
35
+ Mint a JWT with **`POST https://api.reactor.inc/tokens`** and the **`Reactor-API-Key`** header; the response JSON is `{ "jwt": "..." }`.
36
+
37
+ ### JavaScript (Next.js route handler)
38
+
39
+ ```typescript
40
+ // app/api/reactor/token/route.ts
41
+ import { NextResponse } from "next/server";
42
+
43
+ export async function POST() {
44
+ const res = await fetch("https://api.reactor.inc/tokens", {
45
+ method: "POST",
46
+ headers: { "Reactor-API-Key": process.env.REACTOR_API_KEY! },
47
+ });
48
+ const { jwt } = await res.json();
49
+ return NextResponse.json({ jwt });
50
+ }
51
+ ```
52
+
53
+ ### React (provider)
54
+
55
+ Call the `/api/reactor/token` route above from a client component and pass the result to the provider:
56
+
57
+ ```tsx
58
+ "use client";
59
+ import { useEffect, useState } from "react";
60
+ import { LingbotProvider } from "@reactor-models/lingbot";
61
+ import { ReactorView } from "@reactor-team/js-sdk";
62
+
63
+ export default function App() {
64
+ const [jwt, setJwt] = useState<string | null>(null);
65
+
66
+ useEffect(() => {
67
+ fetch("/api/reactor/token", { method: "POST" })
68
+ .then((r) => r.json())
69
+ .then((d) => setJwt(d.jwt));
70
+ }, []);
71
+
72
+ if (!jwt) return null;
73
+
74
+ return (
75
+ <LingbotProvider jwtToken={jwt} connectOptions={{ autoConnect: true }}>
76
+ <ReactorView className="w-full aspect-video" />
77
+ </LingbotProvider>
78
+ );
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Connect
85
+
86
+ ### JavaScript
87
+
88
+ ```typescript
89
+ import { LingbotModel } from "@reactor-models/lingbot";
90
+
91
+ const lingbot = new LingbotModel();
92
+ await lingbot.connect(jwt);
93
+ ```
94
+
95
+ ### React
96
+
97
+ The provider takes the JWT as a prop; fetch it from the same `/api/reactor/token` route the Authenticate example mints.
98
+
99
+ ```tsx
100
+ "use client";
101
+ import { useEffect, useState } from "react";
102
+ import { LingbotProvider, useLingbot } from "@reactor-models/lingbot";
103
+
104
+ function Controller() {
105
+ const { status } = useLingbot();
106
+ return <span>Status: {status}</span>;
107
+ }
108
+
109
+ export default function App() {
110
+ const [jwt, setJwt] = useState<string | null>(null);
111
+
112
+ useEffect(() => {
113
+ fetch("/api/reactor/token", { method: "POST" })
114
+ .then((r) => r.json())
115
+ .then((d) => setJwt(d.jwt));
116
+ }, []);
117
+
118
+ if (!jwt) return null;
119
+
120
+ return (
121
+ <LingbotProvider jwtToken={jwt}>
122
+ <Controller />
123
+ </LingbotProvider>
124
+ );
125
+ }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Events
131
+
132
+ Client-to-model commands. The typed surface is `LingbotModel` (one method per event) in plain JS, and `useLingbot()` in React — every field name below matches the parameter name the method accepts.
133
+
134
+ ### `pause`
135
+
136
+ Pause generation after the current chunk finishes. Frames stop streaming on `main_video` until [`resume`](#resume) is called. Requires generation to be active. Emits [`generation_paused`](#generation_paused) and [`state`](#state) on success, or [`command_error`](#command_error) if not generating or already paused.
137
+
138
+ Emits: [`generation_paused`](#generation_paused), [`state`](#state), [`command_error`](#command_error)
139
+
140
+ _No parameters._
141
+
142
+ #### JavaScript
143
+
144
+ ```typescript
145
+ import { LingbotModel } from "@reactor-models/lingbot";
146
+
147
+ const lingbot = new LingbotModel();
148
+ await lingbot.connect(jwt);
149
+
150
+ await lingbot.pause();
151
+ ```
152
+
153
+ #### React
154
+
155
+ ```tsx
156
+ "use client";
157
+ import { useLingbot } from "@reactor-models/lingbot";
158
+
159
+ function Example() {
160
+ const { pause } = useLingbot();
161
+
162
+ return <button onClick={() => pause()}>pause</button>;
163
+ }
164
+ ```
165
+
166
+ ### `reset`
167
+
168
+ Abort the current run, clear the active prompt and reference image, and return to the waiting state. Valid at any time. After [`reset`](#reset), call [`set_prompt`](#setprompt) and [`set_image`](#setimage) again before [`start`](#start) to begin a new session. Emits [`generation_reset`](#generation_reset) and [`state`](#state).
169
+
170
+ Emits: [`generation_reset`](#generation_reset), [`state`](#state)
171
+
172
+ _No parameters._
173
+
174
+ #### JavaScript
175
+
176
+ ```typescript
177
+ import { LingbotModel } from "@reactor-models/lingbot";
178
+
179
+ const lingbot = new LingbotModel();
180
+ await lingbot.connect(jwt);
181
+
182
+ await lingbot.reset();
183
+ ```
184
+
185
+ #### React
186
+
187
+ ```tsx
188
+ "use client";
189
+ import { useLingbot } from "@reactor-models/lingbot";
190
+
191
+ function Example() {
192
+ const { reset } = useLingbot();
193
+
194
+ return <button onClick={() => reset()}>reset</button>;
195
+ }
196
+ ```
197
+
198
+ ### `start`
199
+
200
+ Begin generating video on `main_video`. Requires both a prompt (via [`set_prompt`](#setprompt)) and a reference image (via [`set_image`](#setimage)). Emits [`generation_started`](#generation_started) and [`state`](#state) on success, or [`command_error`](#command_error) if a precondition is missing. Has no effect while already generating.
201
+
202
+ Emits: [`generation_started`](#generation_started), [`state`](#state), [`command_error`](#command_error)
203
+
204
+ _No parameters._
205
+
206
+ #### JavaScript
207
+
208
+ ```typescript
209
+ import { LingbotModel } from "@reactor-models/lingbot";
210
+
211
+ const lingbot = new LingbotModel();
212
+ await lingbot.connect(jwt);
213
+
214
+ await lingbot.start();
215
+ ```
216
+
217
+ #### React
218
+
219
+ ```tsx
220
+ "use client";
221
+ import { useLingbot } from "@reactor-models/lingbot";
222
+
223
+ function Example() {
224
+ const { start } = useLingbot();
225
+
226
+ return <button onClick={() => start()}>start</button>;
227
+ }
228
+ ```
229
+
230
+ ### `resume`
231
+
232
+ Resume generation from a previous [`pause`](#pause). Requires the session to be paused. Emits [`generation_resumed`](#generation_resumed) and [`state`](#state) on success, or [`command_error`](#command_error) if not paused.
233
+
234
+ Emits: [`generation_resumed`](#generation_resumed), [`state`](#state), [`command_error`](#command_error)
235
+
236
+ _No parameters._
237
+
238
+ #### JavaScript
239
+
240
+ ```typescript
241
+ import { LingbotModel } from "@reactor-models/lingbot";
242
+
243
+ const lingbot = new LingbotModel();
244
+ await lingbot.connect(jwt);
245
+
246
+ await lingbot.resume();
247
+ ```
248
+
249
+ #### React
250
+
251
+ ```tsx
252
+ "use client";
253
+ import { useLingbot } from "@reactor-models/lingbot";
254
+
255
+ function Example() {
256
+ const { resume } = useLingbot();
257
+
258
+ return <button onClick={() => resume()}>resume</button>;
259
+ }
260
+ ```
261
+
262
+ ### `setSeed`
263
+
264
+ Set seed
265
+
266
+ | Parameter | Type | Required | Description |
267
+ |---|---|---|---|
268
+ | `seed` | `number` | | Seed for the random generator used to sample the initial noise. Must be a non-negative integer; the model never draws its own random seed — pick one explicitly (or keep the default) for reproducible runs. Read once when [`start`](#start) fires; later changes take effect only after [`reset`](#reset) followed by a new [`start`](#start). _(min 0, default `42`)_ |
269
+
270
+ #### JavaScript
271
+
272
+ ```typescript
273
+ import { LingbotModel } from "@reactor-models/lingbot";
274
+
275
+ const lingbot = new LingbotModel();
276
+ await lingbot.connect(jwt);
277
+
278
+ await lingbot.setSeed({ seed: 42 });
279
+ ```
280
+
281
+ #### React
282
+
283
+ ```tsx
284
+ "use client";
285
+ import { useLingbot } from "@reactor-models/lingbot";
286
+
287
+ function Example() {
288
+ const { setSeed } = useLingbot();
289
+
290
+ return <button onClick={() => setSeed({ seed: 42 })}>setSeed</button>;
291
+ }
292
+ ```
293
+
294
+ ### `setImage`
295
+
296
+ Provide a reference image that anchors generation (image-to-video). Call before [`start`](#start); the image is required for generation to begin. Changes during generation have no effect until [`reset`](#reset) is issued and [`start`](#start) is called again. Emits [`image_accepted`](#image_accepted), [`conditions_ready`](#conditions_ready), and [`state`](#state) on success, or [`command_error`](#command_error) if the file is missing, not an image, or cannot be decoded.
297
+
298
+ Emits: [`image_accepted`](#image_accepted), [`conditions_ready`](#conditions_ready), [`state`](#state), [`command_error`](#command_error)
299
+
300
+ | Parameter | Type | Required | Description |
301
+ |---|---|---|---|
302
+ | `image` | `FileRef` | | Reference to a file uploaded via the Reactor presigned-URL protocol. _(default `null`)_ |
303
+
304
+ #### JavaScript
305
+
306
+ ```typescript
307
+ import { LingbotModel } from "@reactor-models/lingbot";
308
+
309
+ const lingbot = new LingbotModel();
310
+ await lingbot.connect(jwt);
311
+
312
+ const fileRef = await lingbot.uploadFile(blob);
313
+ await lingbot.setImage({ image: fileRef });
314
+ ```
315
+
316
+ #### React
317
+
318
+ ```tsx
319
+ "use client";
320
+ import { useLingbot } from "@reactor-models/lingbot";
321
+
322
+ function Example() {
323
+ const { setImage, uploadFile } = useLingbot();
324
+
325
+ async function handlePick(file: File) {
326
+ const ref = await uploadFile(file);
327
+ await setImage({ image: ref });
328
+ }
329
+
330
+ return <input type="file" onChange={(e) => handlePick(e.target.files![0])} />;
331
+ }
332
+ ```
333
+
334
+ ### `setPrompt`
335
+
336
+ Set the scene prompt. Valid at any time — call before [`start`](#start) to arm generation, or hot-swap during generation to steer the next chunk. Emits [`prompt_accepted`](#prompt_accepted), [`conditions_ready`](#conditions_ready), and [`state`](#state) on success.
337
+
338
+ Emits: [`prompt_accepted`](#prompt_accepted), [`conditions_ready`](#conditions_ready), [`state`](#state)
339
+
340
+ | Parameter | Type | Required | Description |
341
+ |---|---|---|---|
342
+ | `prompt` | `string` | | Natural-language description of the scene to generate. Replaces the previously active prompt. Applied on the next chunk when generating; otherwise takes effect when [`start`](#start) fires. _(default `""`)_ |
343
+
344
+ #### JavaScript
345
+
346
+ ```typescript
347
+ import { LingbotModel } from "@reactor-models/lingbot";
348
+
349
+ const lingbot = new LingbotModel();
350
+ await lingbot.connect(jwt);
351
+
352
+ await lingbot.setPrompt({ prompt: "A sunset over the ocean" });
353
+ ```
354
+
355
+ #### React
356
+
357
+ ```tsx
358
+ "use client";
359
+ import { useLingbot } from "@reactor-models/lingbot";
360
+
361
+ function Example() {
362
+ const { setPrompt } = useLingbot();
363
+
364
+ return <button onClick={() => setPrompt({ prompt: "A sunset over the ocean" })}>setPrompt</button>;
365
+ }
366
+ ```
367
+
368
+ ### `setMovement`
369
+
370
+ Set movement
371
+
372
+ | Parameter | Type | Required | Description |
373
+ |---|---|---|---|
374
+ | `movement` | `"idle" \| "forward" \| "back" \| "strafe_left" \| "strafe_right"` | | Character movement in the generated scene. `idle` holds the character stationary; `forward` / `back` translate along the look axis; `strafe_left` / `strafe_right` translate sideways. Can be changed at any time; the new value applies to the next chunk. _(default `"idle"`)_ |
375
+
376
+ #### JavaScript
377
+
378
+ ```typescript
379
+ import { LingbotModel } from "@reactor-models/lingbot";
380
+
381
+ const lingbot = new LingbotModel();
382
+ await lingbot.connect(jwt);
383
+
384
+ await lingbot.setMovement({ movement: "idle" });
385
+ ```
386
+
387
+ #### React
388
+
389
+ ```tsx
390
+ "use client";
391
+ import { useLingbot } from "@reactor-models/lingbot";
392
+
393
+ function Example() {
394
+ const { setMovement } = useLingbot();
395
+
396
+ return <button onClick={() => setMovement({ movement: "idle" })}>setMovement</button>;
397
+ }
398
+ ```
399
+
400
+ ### `setLookVertical`
401
+
402
+ Set look_vertical
403
+
404
+ | Parameter | Type | Required | Description |
405
+ |---|---|---|---|
406
+ | `look_vertical` | `"idle" \| "up" \| "down"` | | Vertical (pitch) camera rotation. `idle` holds pitch steady; `up` / `down` rotate the camera at the rate given by `rotation_speed_deg`. Can be changed at any time; the new value applies to the next chunk. _(default `"idle"`)_ |
407
+
408
+ #### JavaScript
409
+
410
+ ```typescript
411
+ import { LingbotModel } from "@reactor-models/lingbot";
412
+
413
+ const lingbot = new LingbotModel();
414
+ await lingbot.connect(jwt);
415
+
416
+ await lingbot.setLookVertical({ look_vertical: "idle" });
417
+ ```
418
+
419
+ #### React
420
+
421
+ ```tsx
422
+ "use client";
423
+ import { useLingbot } from "@reactor-models/lingbot";
424
+
425
+ function Example() {
426
+ const { setLookVertical } = useLingbot();
427
+
428
+ return <button onClick={() => setLookVertical({ look_vertical: "idle" })}>setLookVertical</button>;
429
+ }
430
+ ```
431
+
432
+ ### `setLookHorizontal`
433
+
434
+ Set look_horizontal
435
+
436
+ | Parameter | Type | Required | Description |
437
+ |---|---|---|---|
438
+ | `look_horizontal` | `"idle" \| "left" \| "right"` | | Horizontal (yaw) camera rotation. `idle` holds yaw steady; `left` / `right` rotate the camera at the rate given by `rotation_speed_deg`. Can be changed at any time; the new value applies to the next chunk. _(default `"idle"`)_ |
439
+
440
+ #### JavaScript
441
+
442
+ ```typescript
443
+ import { LingbotModel } from "@reactor-models/lingbot";
444
+
445
+ const lingbot = new LingbotModel();
446
+ await lingbot.connect(jwt);
447
+
448
+ await lingbot.setLookHorizontal({ look_horizontal: "idle" });
449
+ ```
450
+
451
+ #### React
452
+
453
+ ```tsx
454
+ "use client";
455
+ import { useLingbot } from "@reactor-models/lingbot";
456
+
457
+ function Example() {
458
+ const { setLookHorizontal } = useLingbot();
459
+
460
+ return <button onClick={() => setLookHorizontal({ look_horizontal: "idle" })}>setLookHorizontal</button>;
461
+ }
462
+ ```
463
+
464
+ ### `setRotationSpeedDeg`
465
+
466
+ Set rotation_speed_deg
467
+
468
+ | Parameter | Type | Required | Description |
469
+ |---|---|---|---|
470
+ | `rotation_speed_deg` | `number` | | Camera rotation speed in degrees per latent frame, applied when `look_horizontal` or `look_vertical` is not `idle`. Range 0.0 – 30.0. Ignored when both look axes are `idle`. Can be changed at any time; the new value applies to the next chunk. _(min 0, max 30, default `5`)_ |
471
+
472
+ #### JavaScript
473
+
474
+ ```typescript
475
+ import { LingbotModel } from "@reactor-models/lingbot";
476
+
477
+ const lingbot = new LingbotModel();
478
+ await lingbot.connect(jwt);
479
+
480
+ await lingbot.setRotationSpeedDeg({ rotation_speed_deg: 5 });
481
+ ```
482
+
483
+ #### React
484
+
485
+ ```tsx
486
+ "use client";
487
+ import { useLingbot } from "@reactor-models/lingbot";
488
+
489
+ function Example() {
490
+ const { setRotationSpeedDeg } = useLingbot();
491
+
492
+ return <button onClick={() => setRotationSpeedDeg({ rotation_speed_deg: 5 })}>setRotationSpeedDeg</button>;
493
+ }
494
+ ```
495
+
496
+ ## Messages
497
+
498
+ Model-to-client messages. Register a typed listener with `on…` on `LingbotModel`, or a `useLingbot…` hook in React, to receive only the messages you care about.
499
+
500
+ ### `state`
501
+
502
+ Snapshot of the session's observable state.
503
+
504
+ Emitted on connect, after every command that mutates session state ([`set_prompt`](#setprompt), [`set_image`](#setimage), [`start`](#start), [`pause`](#pause), [`resume`](#resume), [`reset`](#reset), and the auto-generated `set_<field>` setters), and after each [`chunk_complete`](#chunk_complete). Clients can treat this as the single source of truth for driving UI, without having to track every individual command and message themselves.
505
+
506
+ Listener: `onState` · React hook: `useLingbotState`
507
+
508
+ | Field | Type | Description |
509
+ |---|---|---|
510
+ | `seed` | `number` | Current value of the `seed` input field. The seed that was actually used by the running generation was captured when [`start`](#start) fired — later changes to `seed` only take effect after [`reset`](#reset) and a new [`start`](#start). |
511
+ | `paused` | `boolean` | True while generation is paused via [`pause`](#pause). |
512
+ | `running` | `boolean` | True while the chunk loop is actively producing frames — equivalent to `started and not paused`. `False` both before [`start`](#start) and while paused; read `started` to disambiguate. |
513
+ | `started` | `boolean` | True once [`start`](#start) has been accepted. Remains true while paused; reset to false by [`reset`](#reset) or after [`generation_complete`](#generation_complete) when the session is not auto-restarting. |
514
+ | `movement` | `string` | Current value of the `movement` input field. |
515
+ | `has_image` | `boolean` | True once a reference image has been set for the session. |
516
+ | `has_prompt` | `boolean` | True once a prompt has been set for the session. |
517
+ | `current_chunk` | `number` | Zero-based index of the last completed chunk. `0` before the first chunk has completed, and resets to `0` on [`reset`](#reset). |
518
+ | `look_vertical` | `string` | Current value of the `look_vertical` input field. |
519
+ | `current_action` | `string` | Composite action string derived from `movement`, `look_horizontal`, and `look_vertical` — a `+`-joined combination of `w`/`s`/`a`/`d` and `left`/`right`/`up`/`down`, or `still` when idle. |
520
+ | `current_prompt` | `unknown` | The prompt currently driving generation, or `null` if no prompt has been set for the session. |
521
+ | `look_horizontal` | `string` | Current value of the `look_horizontal` input field. |
522
+ | `rotation_speed_deg` | `number` | Current value of the `rotation_speed_deg` input field (0.0 – 30.0). |
523
+
524
+ #### JavaScript
525
+
526
+ ```typescript
527
+ import { LingbotModel } from "@reactor-models/lingbot";
528
+
529
+ const lingbot = new LingbotModel();
530
+ lingbot.onState((msg) => {
531
+ console.log(
532
+ "state",
533
+ msg.seed,
534
+ msg.paused,
535
+ msg.running,
536
+ msg.started,
537
+ msg.movement,
538
+ msg.has_image,
539
+ msg.has_prompt,
540
+ msg.current_chunk,
541
+ msg.look_vertical,
542
+ msg.current_action,
543
+ msg.current_prompt,
544
+ msg.look_horizontal,
545
+ msg.rotation_speed_deg,
546
+ );
547
+ });
548
+ await lingbot.connect(jwt);
549
+ ```
550
+
551
+ #### React
552
+
553
+ ```tsx
554
+ import { useLingbotState } from "@reactor-models/lingbot";
555
+
556
+ // Inside a React component wrapped by <LingbotProvider>:
557
+ useLingbotState((msg) => {
558
+ console.log(
559
+ "state",
560
+ msg.seed,
561
+ msg.paused,
562
+ msg.running,
563
+ msg.started,
564
+ msg.movement,
565
+ msg.has_image,
566
+ msg.has_prompt,
567
+ msg.current_chunk,
568
+ msg.look_vertical,
569
+ msg.current_action,
570
+ msg.current_prompt,
571
+ msg.look_horizontal,
572
+ msg.rotation_speed_deg,
573
+ );
574
+ });
575
+ ```
576
+
577
+ ### `command_error`
578
+
579
+ Emitted when a command is rejected because preconditions are not met or its arguments could not be processed.
580
+
581
+ Listener: `onCommandError` · React hook: `useLingbotCommandError`
582
+
583
+ | Field | Type | Description |
584
+ |---|---|---|
585
+ | `reason` | `string` | Human-readable explanation of why the command was rejected. |
586
+ | `command` | `string` | Name of the command that was rejected. |
587
+
588
+ #### JavaScript
589
+
590
+ ```typescript
591
+ import { LingbotModel } from "@reactor-models/lingbot";
592
+
593
+ const lingbot = new LingbotModel();
594
+ lingbot.onCommandError((msg) => {
595
+ console.log("command_error", msg.reason, msg.command);
596
+ });
597
+ await lingbot.connect(jwt);
598
+ ```
599
+
600
+ #### React
601
+
602
+ ```tsx
603
+ import { useLingbotCommandError } from "@reactor-models/lingbot";
604
+
605
+ // Inside a React component wrapped by <LingbotProvider>:
606
+ useLingbotCommandError((msg) => {
607
+ console.log("command_error", msg.reason, msg.command);
608
+ });
609
+ ```
610
+
611
+ ### `chunk_complete`
612
+
613
+ Emitted once per completed chunk of `main_video`.
614
+
615
+ Listener: `onChunkComplete` · React hook: `useLingbotChunkComplete`
616
+
617
+ | Field | Type | Description |
618
+ |---|---|---|
619
+ | `chunk_index` | `number` | Zero-based index of the chunk that just completed. |
620
+ | `active_action` | `string` | The composite action string used to drive this chunk — a `+`-joined combination of movement (`w`/`s`/`a`/`d`) and look directions (`left`/`right`/`up`/`down`), or `still` when the character is idle with no camera rotation. |
621
+ | `active_prompt` | `string` | The prompt that was active while this chunk was generated. |
622
+ | `frames_emitted` | `number` | Number of pixel frames emitted by this chunk. |
623
+
624
+ #### JavaScript
625
+
626
+ ```typescript
627
+ import { LingbotModel } from "@reactor-models/lingbot";
628
+
629
+ const lingbot = new LingbotModel();
630
+ lingbot.onChunkComplete((msg) => {
631
+ console.log(
632
+ "chunk_complete",
633
+ msg.chunk_index,
634
+ msg.active_action,
635
+ msg.active_prompt,
636
+ msg.frames_emitted,
637
+ );
638
+ });
639
+ await lingbot.connect(jwt);
640
+ ```
641
+
642
+ #### React
643
+
644
+ ```tsx
645
+ import { useLingbotChunkComplete } from "@reactor-models/lingbot";
646
+
647
+ // Inside a React component wrapped by <LingbotProvider>:
648
+ useLingbotChunkComplete((msg) => {
649
+ console.log(
650
+ "chunk_complete",
651
+ msg.chunk_index,
652
+ msg.active_action,
653
+ msg.active_prompt,
654
+ msg.frames_emitted,
655
+ );
656
+ });
657
+ ```
658
+
659
+ ### `image_accepted`
660
+
661
+ Emitted after [`set_image`](#setimage) successfully decodes the uploaded file.
662
+
663
+ Listener: `onImageAccepted` · React hook: `useLingbotImageAccepted`
664
+
665
+ | Field | Type | Description |
666
+ |---|---|---|
667
+ | `width` | `number` | Width in pixels of the decoded reference image. |
668
+ | `height` | `number` | Height in pixels of the decoded reference image. |
669
+
670
+ #### JavaScript
671
+
672
+ ```typescript
673
+ import { LingbotModel } from "@reactor-models/lingbot";
674
+
675
+ const lingbot = new LingbotModel();
676
+ lingbot.onImageAccepted((msg) => {
677
+ console.log("image_accepted", msg.width, msg.height);
678
+ });
679
+ await lingbot.connect(jwt);
680
+ ```
681
+
682
+ #### React
683
+
684
+ ```tsx
685
+ import { useLingbotImageAccepted } from "@reactor-models/lingbot";
686
+
687
+ // Inside a React component wrapped by <LingbotProvider>:
688
+ useLingbotImageAccepted((msg) => {
689
+ console.log("image_accepted", msg.width, msg.height);
690
+ });
691
+ ```
692
+
693
+ ### `prompt_accepted`
694
+
695
+ Emitted after [`set_prompt`](#setprompt) is accepted.
696
+
697
+ Listener: `onPromptAccepted` · React hook: `useLingbotPromptAccepted`
698
+
699
+ | Field | Type | Description |
700
+ |---|---|---|
701
+ | `prompt` | `string` | The prompt text that was accepted. |
702
+
703
+ #### JavaScript
704
+
705
+ ```typescript
706
+ import { LingbotModel } from "@reactor-models/lingbot";
707
+
708
+ const lingbot = new LingbotModel();
709
+ lingbot.onPromptAccepted((msg) => {
710
+ console.log("prompt_accepted", msg.prompt);
711
+ });
712
+ await lingbot.connect(jwt);
713
+ ```
714
+
715
+ #### React
716
+
717
+ ```tsx
718
+ import { useLingbotPromptAccepted } from "@reactor-models/lingbot";
719
+
720
+ // Inside a React component wrapped by <LingbotProvider>:
721
+ useLingbotPromptAccepted((msg) => {
722
+ console.log("prompt_accepted", msg.prompt);
723
+ });
724
+ ```
725
+
726
+ ### `conditions_ready`
727
+
728
+ Emitted after [`set_prompt`](#setprompt) or [`set_image`](#setimage) so the client can tell at a glance whether [`start`](#start) will succeed.
729
+
730
+ Listener: `onConditionsReady` · React hook: `useLingbotConditionsReady`
731
+
732
+ | Field | Type | Description |
733
+ |---|---|---|
734
+ | `has_image` | `boolean` | True once a reference image has been set for the session. |
735
+ | `has_prompt` | `boolean` | True once a prompt has been set for the session. |
736
+
737
+ #### JavaScript
738
+
739
+ ```typescript
740
+ import { LingbotModel } from "@reactor-models/lingbot";
741
+
742
+ const lingbot = new LingbotModel();
743
+ lingbot.onConditionsReady((msg) => {
744
+ console.log("conditions_ready", msg.has_image, msg.has_prompt);
745
+ });
746
+ await lingbot.connect(jwt);
747
+ ```
748
+
749
+ #### React
750
+
751
+ ```tsx
752
+ import { useLingbotConditionsReady } from "@reactor-models/lingbot";
753
+
754
+ // Inside a React component wrapped by <LingbotProvider>:
755
+ useLingbotConditionsReady((msg) => {
756
+ console.log("conditions_ready", msg.has_image, msg.has_prompt);
757
+ });
758
+ ```
759
+
760
+ ### `generation_reset`
761
+
762
+ Emitted after [`reset`](#reset) clears session state and returns to the waiting state.
763
+
764
+ Listener: `onGenerationReset` · React hook: `useLingbotGenerationReset`
765
+
766
+ | Field | Type | Description |
767
+ |---|---|---|
768
+ | `reason` | `string` | Short human-readable reason the reset was issued. |
769
+
770
+ #### JavaScript
771
+
772
+ ```typescript
773
+ import { LingbotModel } from "@reactor-models/lingbot";
774
+
775
+ const lingbot = new LingbotModel();
776
+ lingbot.onGenerationReset((msg) => {
777
+ console.log("generation_reset", msg.reason);
778
+ });
779
+ await lingbot.connect(jwt);
780
+ ```
781
+
782
+ #### React
783
+
784
+ ```tsx
785
+ import { useLingbotGenerationReset } from "@reactor-models/lingbot";
786
+
787
+ // Inside a React component wrapped by <LingbotProvider>:
788
+ useLingbotGenerationReset((msg) => {
789
+ console.log("generation_reset", msg.reason);
790
+ });
791
+ ```
792
+
793
+ ### `generation_paused`
794
+
795
+ Emitted in response to [`pause`](#pause), once the current chunk finishes.
796
+
797
+ Listener: `onGenerationPaused` · React hook: `useLingbotGenerationPaused`
798
+
799
+ | Field | Type | Description |
800
+ |---|---|---|
801
+ | `chunk_index` | `number` | Index of the last completed chunk before pausing. |
802
+
803
+ #### JavaScript
804
+
805
+ ```typescript
806
+ import { LingbotModel } from "@reactor-models/lingbot";
807
+
808
+ const lingbot = new LingbotModel();
809
+ lingbot.onGenerationPaused((msg) => {
810
+ console.log("generation_paused", msg.chunk_index);
811
+ });
812
+ await lingbot.connect(jwt);
813
+ ```
814
+
815
+ #### React
816
+
817
+ ```tsx
818
+ import { useLingbotGenerationPaused } from "@reactor-models/lingbot";
819
+
820
+ // Inside a React component wrapped by <LingbotProvider>:
821
+ useLingbotGenerationPaused((msg) => {
822
+ console.log("generation_paused", msg.chunk_index);
823
+ });
824
+ ```
825
+
826
+ ### `generation_resumed`
827
+
828
+ Emitted in response to [`resume`](#resume) when leaving the paused state.
829
+
830
+ Listener: `onGenerationResumed` · React hook: `useLingbotGenerationResumed`
831
+
832
+ | Field | Type | Description |
833
+ |---|---|---|
834
+ | `chunk_index` | `number` | Index of the last completed chunk before resuming. |
835
+
836
+ #### JavaScript
837
+
838
+ ```typescript
839
+ import { LingbotModel } from "@reactor-models/lingbot";
840
+
841
+ const lingbot = new LingbotModel();
842
+ lingbot.onGenerationResumed((msg) => {
843
+ console.log("generation_resumed", msg.chunk_index);
844
+ });
845
+ await lingbot.connect(jwt);
846
+ ```
847
+
848
+ #### React
849
+
850
+ ```tsx
851
+ import { useLingbotGenerationResumed } from "@reactor-models/lingbot";
852
+
853
+ // Inside a React component wrapped by <LingbotProvider>:
854
+ useLingbotGenerationResumed((msg) => {
855
+ console.log("generation_resumed", msg.chunk_index);
856
+ });
857
+ ```
858
+
859
+ ### `generation_started`
860
+
861
+ Emitted once when [`start`](#start) succeeds and frames begin streaming.
862
+
863
+ Listener: `onGenerationStarted` · React hook: `useLingbotGenerationStarted`
864
+
865
+ | Field | Type | Description |
866
+ |---|---|---|
867
+ | `prompt` | `string` | The prompt active at the start of generation. |
868
+ | `chunk_num` | `number` | Total number of chunks the run will produce before [`generation_complete`](#generation_complete) fires. |
869
+ | `frame_num` | `number` | Total number of pixel frames the run will emit on `main_video` before [`generation_complete`](#generation_complete). |
870
+
871
+ #### JavaScript
872
+
873
+ ```typescript
874
+ import { LingbotModel } from "@reactor-models/lingbot";
875
+
876
+ const lingbot = new LingbotModel();
877
+ lingbot.onGenerationStarted((msg) => {
878
+ console.log(
879
+ "generation_started",
880
+ msg.prompt,
881
+ msg.chunk_num,
882
+ msg.frame_num,
883
+ );
884
+ });
885
+ await lingbot.connect(jwt);
886
+ ```
887
+
888
+ #### React
889
+
890
+ ```tsx
891
+ import { useLingbotGenerationStarted } from "@reactor-models/lingbot";
892
+
893
+ // Inside a React component wrapped by <LingbotProvider>:
894
+ useLingbotGenerationStarted((msg) => {
895
+ console.log(
896
+ "generation_started",
897
+ msg.prompt,
898
+ msg.chunk_num,
899
+ msg.frame_num,
900
+ );
901
+ });
902
+ ```
903
+
904
+ ### `generation_complete`
905
+
906
+ Emitted when all `chunk_num` chunks of a run have streamed. If the session is still `started`, a new run kicks off immediately with the same prompt and image; call [`reset`](#reset) to stop.
907
+
908
+ Listener: `onGenerationComplete` · React hook: `useLingbotGenerationComplete`
909
+
910
+ | Field | Type | Description |
911
+ |---|---|---|
912
+ | `total_chunks` | `number` | Total number of chunks produced by the run. |
913
+
914
+ #### JavaScript
915
+
916
+ ```typescript
917
+ import { LingbotModel } from "@reactor-models/lingbot";
918
+
919
+ const lingbot = new LingbotModel();
920
+ lingbot.onGenerationComplete((msg) => {
921
+ console.log("generation_complete", msg.total_chunks);
922
+ });
923
+ await lingbot.connect(jwt);
924
+ ```
925
+
926
+ #### React
927
+
928
+ ```tsx
929
+ import { useLingbotGenerationComplete } from "@reactor-models/lingbot";
930
+
931
+ // Inside a React component wrapped by <LingbotProvider>:
932
+ useLingbotGenerationComplete((msg) => {
933
+ console.log("generation_complete", msg.total_chunks);
934
+ });
935
+ ```
936
+
937
+ ## Tracks
938
+
939
+ Named media channels between your app and the Lingbot model. Use the typed helpers below — `LingbotModel.publish<Track>` / `on<Track>` in plain JS, and `useLingbotTrack` or the per-track `<Lingbot<Track>View>` components in React — so track names are checked at compile time.
940
+
941
+ ### `main_video`
942
+
943
+ A video channel you subscribe to — the model publishes this for your app to render.
944
+
945
+ #### JavaScript
946
+
947
+ ```typescript
948
+ import { LingbotModel } from "@reactor-models/lingbot";
949
+
950
+ const lingbot = new LingbotModel();
951
+ lingbot.onMainVideo((track, stream) => {
952
+ // attach to a <video> element, pipe to a canvas, etc.
953
+ videoEl.srcObject = stream;
954
+ });
955
+ await lingbot.connect(jwt);
956
+ ```
957
+
958
+ #### React
959
+
960
+ ```tsx
961
+ "use client";
962
+ import { LingbotMainVideoView } from "@reactor-models/lingbot";
963
+
964
+ // Inside a component wrapped by <LingbotProvider>:
965
+ export function Example() {
966
+ return <LingbotMainVideoView className="w-full aspect-video" />;
967
+ }
968
+ ```