@escapeaihq/client-core 0.8.0 → 0.42.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 +48 -4
- package/dist/adapters/capabilities.d.ts +10 -0
- package/dist/adapters/capabilities.d.ts.map +1 -0
- package/dist/adapters/capabilities.js +2 -0
- package/dist/adapters/capabilities.js.map +1 -0
- package/dist/adapters/chatAdapter.d.ts +38 -0
- package/dist/adapters/chatAdapter.d.ts.map +1 -0
- package/dist/adapters/chatAdapter.js +88 -0
- package/dist/adapters/chatAdapter.js.map +1 -0
- package/dist/adapters/directorAdapter.d.ts +62 -0
- package/dist/adapters/directorAdapter.d.ts.map +1 -0
- package/dist/adapters/directorAdapter.js +71 -0
- package/dist/adapters/directorAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +44 -0
- package/dist/adapters/imageAdapter.d.ts.map +1 -0
- package/dist/adapters/imageAdapter.js +73 -0
- package/dist/adapters/imageAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +47 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +41 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +98 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +106 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +142 -0
- package/dist/adapters/worldAdapter.d.ts.map +1 -0
- package/dist/adapters/worldAdapter.js +164 -0
- package/dist/adapters/worldAdapter.js.map +1 -0
- package/dist/admin.d.ts +200 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +124 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1299 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +683 -95
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +33 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +4 -1
- package/dist/audio.js.map +1 -1
- package/dist/castProjection.d.ts +35 -0
- package/dist/castProjection.d.ts.map +1 -0
- package/dist/castProjection.js +80 -0
- package/dist/castProjection.js.map +1 -0
- package/dist/conversation/binding.d.ts +62 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +51 -0
- package/dist/conversation/binding.js.map +1 -0
- package/dist/conversation/controller.d.ts +209 -0
- package/dist/conversation/controller.d.ts.map +1 -0
- package/dist/conversation/controller.js +342 -0
- package/dist/conversation/controller.js.map +1 -0
- package/dist/conversation/effectiveModel.d.ts +62 -0
- package/dist/conversation/effectiveModel.d.ts.map +1 -0
- package/dist/conversation/effectiveModel.js +73 -0
- package/dist/conversation/effectiveModel.js.map +1 -0
- package/dist/conversation/index.d.ts +27 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/participant.d.ts +66 -0
- package/dist/conversation/participant.d.ts.map +1 -0
- package/dist/conversation/participant.js +36 -0
- package/dist/conversation/participant.js.map +1 -0
- package/dist/conversation/presence.d.ts +56 -0
- package/dist/conversation/presence.d.ts.map +1 -0
- package/dist/conversation/presence.js +34 -0
- package/dist/conversation/presence.js.map +1 -0
- package/dist/conversation/presenceBus.d.ts +42 -0
- package/dist/conversation/presenceBus.d.ts.map +1 -0
- package/dist/conversation/presenceBus.js +81 -0
- package/dist/conversation/presenceBus.js.map +1 -0
- package/dist/conversation/presenceRegistry.d.ts +49 -0
- package/dist/conversation/presenceRegistry.d.ts.map +1 -0
- package/dist/conversation/presenceRegistry.js +59 -0
- package/dist/conversation/presenceRegistry.js.map +1 -0
- package/dist/conversation/roster.d.ts +72 -0
- package/dist/conversation/roster.d.ts.map +1 -0
- package/dist/conversation/roster.js +69 -0
- package/dist/conversation/roster.js.map +1 -0
- package/dist/conversation/rosterProjection.d.ts +52 -0
- package/dist/conversation/rosterProjection.d.ts.map +1 -0
- package/dist/conversation/rosterProjection.js +74 -0
- package/dist/conversation/rosterProjection.js.map +1 -0
- package/dist/conversation/router.d.ts +74 -0
- package/dist/conversation/router.d.ts.map +1 -0
- package/dist/conversation/router.js +58 -0
- package/dist/conversation/router.js.map +1 -0
- package/dist/conversation/runtime.d.ts +64 -0
- package/dist/conversation/runtime.d.ts.map +1 -0
- package/dist/conversation/runtime.js +172 -0
- package/dist/conversation/runtime.js.map +1 -0
- package/dist/conversation/types.d.ts +99 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +13 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/conversation/voice.d.ts +185 -0
- package/dist/conversation/voice.d.ts.map +1 -0
- package/dist/conversation/voice.js +307 -0
- package/dist/conversation/voice.js.map +1 -0
- package/dist/graphSchema.d.ts +260 -0
- package/dist/graphSchema.d.ts.map +1 -0
- package/dist/graphSchema.js +354 -0
- package/dist/graphSchema.js.map +1 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +57 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/platformAssistant.d.ts +155 -0
- package/dist/platformAssistant.d.ts.map +1 -0
- package/dist/platformAssistant.js +256 -0
- package/dist/platformAssistant.js.map +1 -0
- package/dist/reactor/abortUtils.d.ts +16 -0
- package/dist/reactor/abortUtils.d.ts.map +1 -0
- package/dist/reactor/abortUtils.js +26 -0
- package/dist/reactor/abortUtils.js.map +1 -0
- package/dist/reactor/applyScenePrompt.d.ts +75 -0
- package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
- package/dist/reactor/applyScenePrompt.js +60 -0
- package/dist/reactor/applyScenePrompt.js.map +1 -0
- package/dist/reactor/chunkDistribution.d.ts +43 -0
- package/dist/reactor/chunkDistribution.d.ts.map +1 -0
- package/dist/reactor/chunkDistribution.js +85 -0
- package/dist/reactor/chunkDistribution.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +10 -15
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/index.d.ts +4 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +7 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/longLiveCommandDispatcher.js +87 -0
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
- package/dist/reactor/sceneEntry.d.ts +40 -6
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +63 -24
- package/dist/reactor/sceneEntry.js.map +1 -1
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
- package/dist/reactor/scenesFromEnrichment.js +2 -66
- package/dist/reactor/scenesFromEnrichment.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +42 -2
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +173 -4
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/storyTimeline.d.ts +44 -0
- package/dist/reactor/storyTimeline.d.ts.map +1 -0
- package/dist/reactor/storyTimeline.js +95 -0
- package/dist/reactor/storyTimeline.js.map +1 -0
- package/dist/storyGraph.d.ts +70 -0
- package/dist/storyGraph.d.ts.map +1 -0
- package/dist/storyGraph.js +178 -0
- package/dist/storyGraph.js.map +1 -0
- package/dist/timeFormat.d.ts +10 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +12 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +370 -0
- package/dist/toolSchemas.d.ts.map +1 -0
- package/dist/toolSchemas.js +182 -0
- package/dist/toolSchemas.js.map +1 -0
- package/dist/vision/VisionPublisher.d.ts +115 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -0
- package/dist/vision/VisionPublisher.js +475 -0
- package/dist/vision/VisionPublisher.js.map +1 -0
- package/dist/vision/VisionSourceController.d.ts +127 -0
- package/dist/vision/VisionSourceController.d.ts.map +1 -0
- package/dist/vision/VisionSourceController.js +284 -0
- package/dist/vision/VisionSourceController.js.map +1 -0
- package/dist/vision/credentials.d.ts +22 -0
- package/dist/vision/credentials.d.ts.map +1 -0
- package/dist/vision/credentials.js +34 -0
- package/dist/vision/credentials.js.map +1 -0
- package/dist/vision/index.d.ts +18 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +13 -0
- package/dist/vision/index.js.map +1 -0
- package/dist/vision/sourceKinds.d.ts +65 -0
- package/dist/vision/sourceKinds.d.ts.map +1 -0
- package/dist/vision/sourceKinds.js +26 -0
- package/dist/vision/sourceKinds.js.map +1 -0
- package/dist/vision/startVisionPublisher.d.ts +38 -0
- package/dist/vision/startVisionPublisher.d.ts.map +1 -0
- package/dist/vision/startVisionPublisher.js +44 -0
- package/dist/vision/startVisionPublisher.js.map +1 -0
- package/dist/vision/types.d.ts +95 -0
- package/dist/vision/types.d.ts.map +1 -0
- package/dist/vision/types.js +12 -0
- package/dist/vision/types.js.map +1 -0
- package/dist/vision/visionScheduler.d.ts +63 -0
- package/dist/vision/visionScheduler.d.ts.map +1 -0
- package/dist/vision/visionScheduler.js +67 -0
- package/dist/vision/visionScheduler.js.map +1 -0
- package/dist/websocket.d.ts +195 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +179 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +11 -1
- package/src/__tests__/adapters-capabilities.test.ts +46 -0
- package/src/__tests__/adapters-chat.test.ts +172 -0
- package/src/__tests__/adapters-director.test.ts +95 -0
- package/src/__tests__/adapters-image.test.ts +133 -0
- package/src/__tests__/adapters-platform.test.ts +95 -0
- package/src/__tests__/adapters-registry.test.ts +189 -0
- package/src/__tests__/adapters-world.test.ts +296 -0
- package/src/__tests__/admin.test.ts +312 -0
- package/src/__tests__/adventures-party.test.ts +219 -0
- package/src/__tests__/adventures.test.ts +282 -0
- package/src/__tests__/api-pollers.test.ts +104 -0
- package/src/__tests__/api.clip-lookup.test.ts +64 -0
- package/src/__tests__/api.list-images-filters.test.ts +103 -0
- package/src/__tests__/api.test.ts +470 -0
- package/src/__tests__/audio.test.ts +65 -0
- package/src/__tests__/cast.test.ts +95 -0
- package/src/__tests__/castProjection.test.ts +167 -0
- package/src/__tests__/chat-auth.test.ts +91 -0
- package/src/__tests__/conversation/controller.test.ts +697 -0
- package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
- package/src/__tests__/conversation/headlessRenderer.ts +46 -0
- package/src/__tests__/conversation/presenceBus.test.ts +236 -0
- package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
- package/src/__tests__/conversation/roster.test.ts +100 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
- package/src/__tests__/conversation/router.test.ts +81 -0
- package/src/__tests__/conversation/runtime.test.ts +206 -0
- package/src/__tests__/conversation/voice.test.ts +440 -0
- package/src/__tests__/documents.test.ts +360 -0
- package/src/__tests__/graphSchema.test.ts +326 -0
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
- package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
- package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
- package/src/__tests__/regeneration.test.ts +486 -0
- package/src/__tests__/stories.test.ts +171 -0
- package/src/__tests__/storyGraph.test.ts +134 -0
- package/src/__tests__/timeFormat.test.ts +22 -1
- package/src/__tests__/toolSchemas.test.ts +57 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket-vision.test.ts +265 -0
- package/src/__tests__/websocket.test.ts +213 -0
- package/src/adapters/capabilities.ts +24 -0
- package/src/adapters/chatAdapter.ts +114 -0
- package/src/adapters/directorAdapter.ts +126 -0
- package/src/adapters/imageAdapter.ts +100 -0
- package/src/adapters/index.ts +67 -0
- package/src/adapters/registry.ts +159 -0
- package/src/adapters/worldAdapter.ts +272 -0
- package/src/admin.ts +310 -0
- package/src/api.ts +1890 -162
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +81 -0
- package/src/conversation/controller.ts +439 -0
- package/src/conversation/effectiveModel.ts +111 -0
- package/src/conversation/index.ts +27 -0
- package/src/conversation/participant.ts +71 -0
- package/src/conversation/presence.ts +60 -0
- package/src/conversation/presenceBus.ts +109 -0
- package/src/conversation/presenceRegistry.ts +83 -0
- package/src/conversation/roster.ts +111 -0
- package/src/conversation/rosterProjection.ts +98 -0
- package/src/conversation/router.ts +96 -0
- package/src/conversation/runtime.ts +188 -0
- package/src/conversation/types.ts +100 -0
- package/src/conversation/voice.ts +402 -0
- package/src/graphSchema.ts +532 -0
- package/src/http.ts +72 -0
- package/src/index.ts +12 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/abortUtils.ts +22 -0
- package/src/reactor/applyScenePrompt.ts +136 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/heliosCommandDispatcher.ts +10 -18
- package/src/reactor/index.ts +7 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/sceneEntry.ts +104 -33
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +200 -4
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/timeFormat.ts +13 -0
- package/src/toolSchemas.ts +225 -0
- package/src/vision/VisionPublisher.ts +553 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
- package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
- package/src/vision/__tests__/visionScheduler.test.ts +149 -0
- package/src/vision/credentials.ts +39 -0
- package/src/vision/index.ts +44 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/vision/startVisionPublisher.ts +64 -0
- package/src/vision/types.ts +101 -0
- package/src/vision/visionScheduler.ts +102 -0
- package/src/websocket.ts +334 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translate parsed LongLive-v2 commands into `reactor.sendCommand` calls.
|
|
3
|
+
*
|
|
4
|
+
* The {@link dispatchHeliosCommand} analogue for the Reactor LongLive-v2
|
|
5
|
+
* world model. SAME Reactor transport (JWT / `main_video` track) as Helios —
|
|
6
|
+
* only the `modelName` string differs on the bridge. The COMMAND VOCABULARY
|
|
7
|
+
* differs: LongLive is text-to-video with a hard `scene_cut` (a
|
|
8
|
+
* memory-purging transition Helios lacks) and NO image conditioning (there is
|
|
9
|
+
* NO `uploadFile` / `set_image` / `swap_seed` equivalent — text-only).
|
|
10
|
+
*
|
|
11
|
+
* Pure framework-agnostic helper: no React imports, no `@reactor-team/js-sdk`
|
|
12
|
+
* dependency. It reuses the structural {@link HeliosReactorBridge}
|
|
13
|
+
* `sendCommand` surface via `Pick` (no rename — additive-only) but takes NO
|
|
14
|
+
* `uploadFile` (LongLive has no image path).
|
|
15
|
+
*
|
|
16
|
+
* Failure policy mirrors the Helios dispatcher: every command is wrapped in a
|
|
17
|
+
* try/catch. A clean abort is silent; any other failure is logged and skipped
|
|
18
|
+
* so the chat session keeps working even when the world stream is unreachable.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { isAbortError } from './abortUtils';
|
|
22
|
+
import type { HeliosReactorBridge } from './heliosCommandDispatcher';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Discriminated union of every LongLive-v2 world-steering action.
|
|
26
|
+
*
|
|
27
|
+
* Wire vocabulary (Reactor `sendCommand`):
|
|
28
|
+
* - `set_shot` — soft transition (also the OPENING shot before `start`).
|
|
29
|
+
* - `scene_cut` — HARD transition: purges memory + resets the per-scene chunk
|
|
30
|
+
* counter (Helios has no equivalent).
|
|
31
|
+
* - `schedule_shot` / `schedule_scene_cut` — schedule at a CUMULATIVE
|
|
32
|
+
* `session_chunk` index (snake_case `at_session_chunk` on the wire).
|
|
33
|
+
* Presumes a STARTED session (the dispatcher only emits `start` from the
|
|
34
|
+
* opening `set_shot`); Step 3's director schedules only after the opening
|
|
35
|
+
* shot, so a schedule before `start` is a caller error, not handled here.
|
|
36
|
+
* - `pause` / `resume` / `reset` — lifecycle.
|
|
37
|
+
* - `set_seed` — deterministic seed.
|
|
38
|
+
*
|
|
39
|
+
* NOTE: there is deliberately NO `swap_seed` variant — LongLive is
|
|
40
|
+
* text-to-video and has no image-conditioning surface.
|
|
41
|
+
*/
|
|
42
|
+
export type LongLiveCommand =
|
|
43
|
+
| { type: 'set_shot'; prompt: string }
|
|
44
|
+
| { type: 'scene_cut'; prompt: string }
|
|
45
|
+
| { type: 'schedule_shot'; prompt: string; atSessionChunk: number }
|
|
46
|
+
| { type: 'schedule_scene_cut'; prompt: string; atSessionChunk: number }
|
|
47
|
+
| { type: 'pause' }
|
|
48
|
+
| { type: 'resume' }
|
|
49
|
+
| { type: 'reset' }
|
|
50
|
+
| { type: 'set_seed'; seed: number };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Inputs the LongLive dispatcher needs beyond the command itself.
|
|
54
|
+
*
|
|
55
|
+
* Reuses the structural {@link HeliosReactorBridge} `sendCommand` slot via
|
|
56
|
+
* `Pick` so client-core takes NO runtime SDK dependency and the same mockable
|
|
57
|
+
* bridge works for both dispatchers. Deliberately NARROWER than
|
|
58
|
+
* `HeliosToolContext`: no `apiClient` (no upsample/entity lookup here), no
|
|
59
|
+
* `uploadFile` (no image path), no `videoId` / `imageId` / `entityContext`
|
|
60
|
+
* (text-to-video, no `swap_seed`).
|
|
61
|
+
*/
|
|
62
|
+
export interface LongLiveToolContext {
|
|
63
|
+
reactor: Pick<HeliosReactorBridge, 'sendCommand'>;
|
|
64
|
+
/** Whether the page has already issued a `start` command in this session.
|
|
65
|
+
* `set_shot` at the opening shot needs to know: if false, fire
|
|
66
|
+
* `set_shot` + `start` (this is the first shot); if true, fire `set_shot`
|
|
67
|
+
* only (re-emitting `start` while running is undocumented Reactor
|
|
68
|
+
* behavior — defensive to skip it). Mirrors the Helios `set_scene`
|
|
69
|
+
* chunk-0 + `hasStarted` guard.
|
|
70
|
+
*
|
|
71
|
+
* CALLER CONTRACT (the dispatcher does NOT mutate `ctx`): the caller MUST
|
|
72
|
+
* set this to `true` after the first `set_shot` dispatches, and clear it to
|
|
73
|
+
* `false` on `reset`. A caller that reuses one context object without
|
|
74
|
+
* updating `hasStarted` will re-fire `start` on every `set_shot`. (Step 3's
|
|
75
|
+
* director tracks this on its session state.) */
|
|
76
|
+
hasStarted?: boolean;
|
|
77
|
+
/** Optional `AbortSignal`: when aborted (before dispatch), the function
|
|
78
|
+
* returns silently without invoking `sendCommand`. Reactor `sendCommand`
|
|
79
|
+
* is NOT itself aborted (the SDK has no signal surface) — but a clean
|
|
80
|
+
* abort thrown from within is routed silently through `isAbortError`. */
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Dispatch a single {@link LongLiveCommand} to the live Reactor session.
|
|
86
|
+
* Resolves with no value on both success and failure — the caller just awaits
|
|
87
|
+
* and continues to the next command (mirrors {@link dispatchHeliosCommand}).
|
|
88
|
+
*
|
|
89
|
+
* When `ctx.signal` is already aborted, returns silently without invoking
|
|
90
|
+
* `sendCommand`. A clean abort thrown mid-dispatch is also silent.
|
|
91
|
+
*/
|
|
92
|
+
export async function dispatchLongLiveCommand(
|
|
93
|
+
cmd: LongLiveCommand,
|
|
94
|
+
ctx: LongLiveToolContext,
|
|
95
|
+
): Promise<void> {
|
|
96
|
+
if (ctx.signal?.aborted) return;
|
|
97
|
+
try {
|
|
98
|
+
switch (cmd.type) {
|
|
99
|
+
case 'set_shot':
|
|
100
|
+
await ctx.reactor.sendCommand('set_shot', { prompt: cmd.prompt });
|
|
101
|
+
// Opening-shot-then-start: only emit `start` when the page hasn't
|
|
102
|
+
// fired it yet (re-emitting `start` while running is undocumented
|
|
103
|
+
// Reactor behavior). Mirrors the Helios set_scene chunk-0 guard.
|
|
104
|
+
if (!ctx.hasStarted) {
|
|
105
|
+
await ctx.reactor.sendCommand('start', {});
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
case 'scene_cut':
|
|
109
|
+
await ctx.reactor.sendCommand('scene_cut', { prompt: cmd.prompt });
|
|
110
|
+
return;
|
|
111
|
+
case 'schedule_shot':
|
|
112
|
+
await ctx.reactor.sendCommand('schedule_shot', {
|
|
113
|
+
prompt: cmd.prompt,
|
|
114
|
+
at_session_chunk: cmd.atSessionChunk,
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
case 'schedule_scene_cut':
|
|
118
|
+
await ctx.reactor.sendCommand('schedule_scene_cut', {
|
|
119
|
+
prompt: cmd.prompt,
|
|
120
|
+
at_session_chunk: cmd.atSessionChunk,
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
case 'pause':
|
|
124
|
+
await ctx.reactor.sendCommand('pause', {});
|
|
125
|
+
return;
|
|
126
|
+
case 'resume':
|
|
127
|
+
await ctx.reactor.sendCommand('resume', {});
|
|
128
|
+
return;
|
|
129
|
+
case 'reset':
|
|
130
|
+
await ctx.reactor.sendCommand('reset', {});
|
|
131
|
+
return;
|
|
132
|
+
case 'set_seed':
|
|
133
|
+
await ctx.reactor.sendCommand('set_seed', { seed: cmd.seed });
|
|
134
|
+
return;
|
|
135
|
+
default: {
|
|
136
|
+
// Exhaustiveness check — TS complains at compile time if a new
|
|
137
|
+
// LongLiveCommand variant is added without updating this switch. The
|
|
138
|
+
// runtime branch is unreachable but keeps the narrowing honest.
|
|
139
|
+
const _exhaustive: never = cmd;
|
|
140
|
+
console.warn(
|
|
141
|
+
'[longLiveCommandDispatcher] unknown command type',
|
|
142
|
+
_exhaustive,
|
|
143
|
+
);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch (err) {
|
|
148
|
+
// Abort is a clean signal — silent and stop here.
|
|
149
|
+
if (isAbortError(err)) return;
|
|
150
|
+
console.warn(
|
|
151
|
+
'[longLiveCommandDispatcher] command failed; skipping',
|
|
152
|
+
cmd,
|
|
153
|
+
err,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
ImageRecord,
|
|
22
22
|
PersonaConfig,
|
|
23
23
|
} from '../api';
|
|
24
|
+
import { isAbortError } from './abortUtils';
|
|
24
25
|
import {
|
|
25
26
|
aggregateEntityContext,
|
|
26
27
|
aggregatePersonaContext,
|
|
@@ -30,22 +31,39 @@ import {
|
|
|
30
31
|
sendSeedFileToReactor,
|
|
31
32
|
type SeedImageReactorBridge,
|
|
32
33
|
} from './seedImageOrchestrator';
|
|
34
|
+
import type { EntityContext, PersonaContext } from './types';
|
|
33
35
|
|
|
34
36
|
export interface SceneEntryInput {
|
|
35
37
|
/** The Seer video the user is watching. */
|
|
36
38
|
videoId: string;
|
|
37
39
|
/** Playhead position at the moment Step Into Scene was clicked. */
|
|
38
40
|
timestamp: number;
|
|
39
|
-
/** Caption for the bracketing shot, if enrichment is loaded.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
/** Caption for the bracketing shot, if enrichment is loaded. Only
|
|
42
|
+
* used when `includeCaption: true` — the default image-first path
|
|
43
|
+
* ignores it because Helios already sees the seed frame via
|
|
44
|
+
* `set_image`. */
|
|
43
45
|
shotCaption?: string | null;
|
|
46
|
+
/** When `true`, the upsampler runs with `shotCaption` (or a fallback)
|
|
47
|
+
* as the input prompt and the resulting Helios paragraph is sent as
|
|
48
|
+
* `set_prompt`. Defaults to `false`, in which case the upsample step
|
|
49
|
+
* is bypassed entirely and `IMAGE_FIRST_DIRECTIVE` is sent as
|
|
50
|
+
* `set_prompt` instead — instructing Helios to continue the seed
|
|
51
|
+
* image faithfully with only natural motion. Ignored when
|
|
52
|
+
* `customPrompt` is also provided. */
|
|
53
|
+
includeCaption?: boolean;
|
|
54
|
+
/** Operator-authored prompt that overrides BOTH the IMAGE_FIRST_DIRECTIVE
|
|
55
|
+
* default and the caption-upsample path. When provided, this string is
|
|
56
|
+
* sent verbatim as the initial `set_prompt`. Enables the watch-page
|
|
57
|
+
* prompt-editor surface where the user previews and tweaks the prompt
|
|
58
|
+
* before stepping into a scene. Trim externally — empty / whitespace-only
|
|
59
|
+
* strings fall back to the includeCaption-driven defaults. */
|
|
60
|
+
customPrompt?: string | null;
|
|
44
61
|
/** Most-recent SUCCEEDED Pegasus enrichment for the video, used to
|
|
45
|
-
* derive `sceneContext` inside the entity grounding.
|
|
62
|
+
* derive `sceneContext` inside the entity grounding. Only consulted
|
|
63
|
+
* on the caption-driven path. */
|
|
46
64
|
enrichment: EnrichmentRecord | null;
|
|
47
65
|
/** Active persona on the watch page. `null` means "no persona
|
|
48
|
-
* grounding"
|
|
66
|
+
* grounding". Only consulted on the caption-driven path. */
|
|
49
67
|
persona: PersonaConfig | null;
|
|
50
68
|
apiClient: ApiClient;
|
|
51
69
|
signal?: AbortSignal;
|
|
@@ -63,13 +81,42 @@ export interface SceneEntryPayload {
|
|
|
63
81
|
* (or any consumer) deep-link to `/images/{imageId}` for inspection
|
|
64
82
|
* or wire a "View in gallery" affordance. */
|
|
65
83
|
imageId: string;
|
|
84
|
+
/** Aggregated entity grounding for the extracted frame. Surfaced so
|
|
85
|
+
* in-modal prompt resubmits (via `applyScenePrompt`) ground on the
|
|
86
|
+
* same scene context that the initial upsample used. */
|
|
87
|
+
entityContext: EntityContext;
|
|
88
|
+
/** Persona grounding, when the operator had a persona selected.
|
|
89
|
+
* `null` means "no persona". Mirrors `prepareSceneEntry`'s
|
|
90
|
+
* internal calculation so consumers don't recompute it. */
|
|
91
|
+
personaContext: PersonaContext | null;
|
|
66
92
|
}
|
|
67
93
|
|
|
68
|
-
/** Fallback shot caption when
|
|
69
|
-
*
|
|
70
|
-
* prompts so the LLM doesn't
|
|
94
|
+
/** Fallback shot caption when `includeCaption: true` is set but
|
|
95
|
+
* enrichment is absent or the playhead is outside any shot. Matches
|
|
96
|
+
* the cadence of the upsample's training prompts so the LLM doesn't
|
|
97
|
+
* reject a one-word input. */
|
|
71
98
|
const FALLBACK_SHOT_CAPTION = 'Step into this moment';
|
|
72
99
|
|
|
100
|
+
/** Default `set_prompt` for the image-first path. The seed frame is
|
|
101
|
+
* already loaded into Helios via `set_image`, so this prompt only
|
|
102
|
+
* needs to (a) tell the model to continue what it sees and (b)
|
|
103
|
+
* preserve the visual specifics. Written as a Helios-quality dense
|
|
104
|
+
* paragraph (~95 words) so we can send it directly without the
|
|
105
|
+
* upsampler round-trip. Follows the same prompt-guide rules
|
|
106
|
+
* encoded in `upsamplePrompt.ts::BASE_SYSTEM_RULES`: camera framing
|
|
107
|
+
* named explicitly, light by its effect, behavior over emotion. */
|
|
108
|
+
export const IMAGE_FIRST_DIRECTIVE =
|
|
109
|
+
'Static medium shot, matching the seed image exactly. Preserve the ' +
|
|
110
|
+
'subject\'s identity, position, posture, and wardrobe. Preserve the ' +
|
|
111
|
+
'environment, depth, palette, and the way light falls across surfaces — ' +
|
|
112
|
+
'the same shadows, the same highlights, the same atmospheric texture. ' +
|
|
113
|
+
'Hold the original camera framing and lens character; the operator ' +
|
|
114
|
+
'chose this exact moment. Apply only subtle natural motion: gentle ' +
|
|
115
|
+
'breathing, slight weight shifts, ambient air moving fabric or hair, ' +
|
|
116
|
+
'soft eye movement. No new actions, no new objects, no scene cuts, no ' +
|
|
117
|
+
'introduced characters. Let the world settle into the frame the way it ' +
|
|
118
|
+
'was captured and continue from there.';
|
|
119
|
+
|
|
73
120
|
/** Sentinel entity name for the `ExtractImageRequest`. The backend
|
|
74
121
|
* endpoint requires this field but uses `timestamp` for the actual
|
|
75
122
|
* frame extraction when both are provided — `entity` survives only as
|
|
@@ -89,11 +136,14 @@ export async function prepareSceneEntry(
|
|
|
89
136
|
videoId,
|
|
90
137
|
timestamp,
|
|
91
138
|
shotCaption,
|
|
139
|
+
includeCaption = false,
|
|
140
|
+
customPrompt,
|
|
92
141
|
enrichment,
|
|
93
142
|
persona,
|
|
94
143
|
apiClient,
|
|
95
144
|
signal,
|
|
96
145
|
} = input;
|
|
146
|
+
const customPromptTrimmed = customPrompt?.trim() || null;
|
|
97
147
|
|
|
98
148
|
// Step 1 — extract the frame server-side. The endpoint uses ffmpeg
|
|
99
149
|
// against the source video's presigned URL and persists an
|
|
@@ -114,28 +164,37 @@ export async function prepareSceneEntry(
|
|
|
114
164
|
);
|
|
115
165
|
}
|
|
116
166
|
|
|
117
|
-
// Step 2 —
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// is richer than single-frame visual would be); the blob proxy and
|
|
121
|
-
// upsample are independent so running them serially would add ~1.5s
|
|
122
|
-
// of round-trip latency for no benefit.
|
|
167
|
+
// Step 2 — build entity/persona context (cheap, always run so the
|
|
168
|
+
// returned payload carries them for follow-up prompts via
|
|
169
|
+
// HeliosWorldControls).
|
|
123
170
|
const entityContext = aggregateEntityContext({
|
|
124
171
|
imageRecord: synthesizeImageRecord(videoId, extract),
|
|
125
172
|
enrichment: enrichment ?? undefined,
|
|
126
173
|
});
|
|
127
174
|
const personaContext = persona ? aggregatePersonaContext(persona) : null;
|
|
128
|
-
const promptInput = shotCaption?.trim() || FALLBACK_SHOT_CAPTION;
|
|
129
175
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
176
|
+
// Step 3 — fan out the frame-blob fetch alongside the prompt
|
|
177
|
+
// resolution. Three paths, in priority order:
|
|
178
|
+
// 1. customPrompt: operator-authored, sent verbatim. No upsample.
|
|
179
|
+
// 2. includeCaption: legacy caption-upsample (Bedrock round-trip).
|
|
180
|
+
// 3. default image-first: send IMAGE_FIRST_DIRECTIVE verbatim.
|
|
181
|
+
const promptPromise: Promise<string> = customPromptTrimmed
|
|
182
|
+
? Promise.resolve(customPromptTrimmed)
|
|
183
|
+
: includeCaption
|
|
184
|
+
? apiClient
|
|
185
|
+
.upsampleReactorPrompt(
|
|
186
|
+
{
|
|
187
|
+
prompt: shotCaption?.trim() || FALLBACK_SHOT_CAPTION,
|
|
188
|
+
entityContext,
|
|
189
|
+
...(personaContext ? { personaContext } : {}),
|
|
190
|
+
},
|
|
191
|
+
{ signal },
|
|
192
|
+
)
|
|
193
|
+
.then(res => res.upsampledPrompt)
|
|
194
|
+
: Promise.resolve(IMAGE_FIRST_DIRECTIVE);
|
|
195
|
+
|
|
196
|
+
const [upsampledPrompt, frameFile] = await Promise.all([
|
|
197
|
+
promptPromise,
|
|
139
198
|
loadSeedImageFile(extract.imageId, apiClient, {
|
|
140
199
|
signal,
|
|
141
200
|
filenameStem: 'scene',
|
|
@@ -144,9 +203,11 @@ export async function prepareSceneEntry(
|
|
|
144
203
|
|
|
145
204
|
return {
|
|
146
205
|
frameFile,
|
|
147
|
-
upsampledPrompt
|
|
206
|
+
upsampledPrompt,
|
|
148
207
|
sourceTimestamp: extract.sourceTimestamp,
|
|
149
208
|
imageId: extract.imageId,
|
|
209
|
+
entityContext,
|
|
210
|
+
personaContext,
|
|
150
211
|
};
|
|
151
212
|
}
|
|
152
213
|
|
|
@@ -171,7 +232,9 @@ export async function prepareSceneEntry(
|
|
|
171
232
|
export async function bootstrapSceneInReactor(
|
|
172
233
|
payload: SceneEntryPayload,
|
|
173
234
|
bridge: SeedImageReactorBridge,
|
|
174
|
-
options: {
|
|
235
|
+
options: {
|
|
236
|
+
signal?: AbortSignal;
|
|
237
|
+
} = {},
|
|
175
238
|
): Promise<void> {
|
|
176
239
|
// Abort is an *expected* terminal state for this flow (user clicked
|
|
177
240
|
// Back to video, modal unmounted, etc.). Internally we use exceptions
|
|
@@ -181,8 +244,21 @@ export async function bootstrapSceneInReactor(
|
|
|
181
244
|
// shouldn't have to ALSO distinguish AbortError from real errors.
|
|
182
245
|
try {
|
|
183
246
|
if (options.signal?.aborted) return;
|
|
247
|
+
// Match the docs sample exactly (file-uploads.md:33,
|
|
248
|
+
// image-to-video-player.md:94): uploadFile → set_image →
|
|
249
|
+
// set_prompt → start back-to-back, no wait between commands.
|
|
250
|
+
// Per `scripts/spikes/helios_set_image_spike.py`, Helios emits
|
|
251
|
+
// `image_accepted` AFTER `start` fires (during chunk 0), so any
|
|
252
|
+
// wait between set_image and start deadlocks. Chunk 0 is
|
|
253
|
+
// text-only briefly; chunks 1+ render with the seed.
|
|
254
|
+
// No transition on the first seed of a session — matches the
|
|
255
|
+
// working JS spike (helios_set_image_spike.html) verbatim. The
|
|
256
|
+
// docs (helios-overview.md) say first-call transition is a no-op,
|
|
257
|
+
// and empirically including `'cut'` here correlated with the
|
|
258
|
+
// image never taking effect in the React app even though the
|
|
259
|
+
// spike (no transition) reliably loads the seed.
|
|
184
260
|
await raceWithAbort(
|
|
185
|
-
sendSeedFileToReactor(payload.frameFile, bridge, {
|
|
261
|
+
sendSeedFileToReactor(payload.frameFile, bridge, {}),
|
|
186
262
|
options.signal,
|
|
187
263
|
);
|
|
188
264
|
if (options.signal?.aborted) return;
|
|
@@ -198,11 +274,6 @@ export async function bootstrapSceneInReactor(
|
|
|
198
274
|
}
|
|
199
275
|
}
|
|
200
276
|
|
|
201
|
-
function isAbortError(err: unknown): boolean {
|
|
202
|
-
if (err instanceof DOMException && err.name === 'AbortError') return true;
|
|
203
|
-
return err instanceof Error && err.name === 'AbortError';
|
|
204
|
-
}
|
|
205
|
-
|
|
206
277
|
/**
|
|
207
278
|
* Race a promise against an `AbortSignal`. When the signal fires, the
|
|
208
279
|
* returned promise rejects with `AbortError` even if the underlying
|
|
@@ -34,6 +34,12 @@
|
|
|
34
34
|
|
|
35
35
|
import type { EnrichmentRecord } from '../api';
|
|
36
36
|
import { ENRICHMENT_STATUS_SUCCEEDED } from '../api';
|
|
37
|
+
import {
|
|
38
|
+
DEFAULT_MAX_CHUNKS,
|
|
39
|
+
DEFAULT_MIN_CHUNK_SPACING,
|
|
40
|
+
computeChunkIndices,
|
|
41
|
+
enforceSpacing,
|
|
42
|
+
} from './chunkDistribution';
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
45
|
* A single beat on the director timeline. One beat = one
|
|
@@ -68,8 +74,10 @@ export interface MapEnrichmentOptions {
|
|
|
68
74
|
styleHint?: string;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
// DEFAULT_MAX_CHUNKS / DEFAULT_MIN_CHUNK_SPACING and the chunk-distribution
|
|
78
|
+
// helpers (computeChunkIndices / enforceSpacing) now live in
|
|
79
|
+
// `./chunkDistribution` so `deriveStoryTimeline` shares the SAME algorithm (R8.1
|
|
80
|
+
// DRY — one place can break). They are imported above.
|
|
73
81
|
|
|
74
82
|
interface RawScene {
|
|
75
83
|
start?: number;
|
|
@@ -265,79 +273,6 @@ function extractScenes(
|
|
|
265
273
|
return undefined;
|
|
266
274
|
}
|
|
267
275
|
|
|
268
|
-
/**
|
|
269
|
-
* Compute the chunk index for each scene. When all scenes have valid
|
|
270
|
-
* `start` timings and the time span is positive, scale proportionally.
|
|
271
|
-
* Otherwise distribute evenly across `[0, maxChunks)`.
|
|
272
|
-
*/
|
|
273
|
-
function computeChunkIndices(
|
|
274
|
-
scenes: RawScene[],
|
|
275
|
-
maxChunks: number,
|
|
276
|
-
): number[] {
|
|
277
|
-
if (scenes.length === 0) return [];
|
|
278
|
-
if (scenes.length === 1) return [0];
|
|
279
|
-
|
|
280
|
-
const allTimed = scenes.every(
|
|
281
|
-
(s) => typeof s.start === 'number' && typeof s.end === 'number',
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
// If timings are present and meaningful (positive span), scale.
|
|
285
|
-
if (allTimed) {
|
|
286
|
-
const starts = scenes.map((s) => s.start as number);
|
|
287
|
-
const ends = scenes.map((s) => s.end as number);
|
|
288
|
-
const minStart = Math.min(...starts);
|
|
289
|
-
const maxEnd = Math.max(...ends);
|
|
290
|
-
const span = maxEnd - minStart;
|
|
291
|
-
if (span > 0) {
|
|
292
|
-
return scenes.map((s, i) => {
|
|
293
|
-
if (i === 0) return 0;
|
|
294
|
-
const start = s.start as number;
|
|
295
|
-
const frac = (start - minStart) / span;
|
|
296
|
-
const chunk = Math.round(frac * (maxChunks - 1));
|
|
297
|
-
// Clamp into [0, maxChunks - 1].
|
|
298
|
-
return Math.max(0, Math.min(maxChunks - 1, chunk));
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Fallback — even distribution. First beat at 0, last beat at
|
|
304
|
-
// maxChunks - 1, with linear spacing between.
|
|
305
|
-
return scenes.map((_, i) => {
|
|
306
|
-
if (i === 0) return 0;
|
|
307
|
-
const frac = i / (scenes.length - 1);
|
|
308
|
-
return Math.round(frac * (maxChunks - 1));
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Apply `minChunkSpacing`. Walks in order, always keeps the first beat
|
|
314
|
-
* (forced to chunk 0), drops any beat whose chunk is closer than
|
|
315
|
-
* `minChunkSpacing` to the previously-kept beat.
|
|
316
|
-
*/
|
|
317
|
-
function enforceSpacing(
|
|
318
|
-
scenes: RawScene[],
|
|
319
|
-
chunks: number[],
|
|
320
|
-
minSpacing: number,
|
|
321
|
-
): { scene: RawScene; chunk: number; index: number }[] {
|
|
322
|
-
const kept: { scene: RawScene; chunk: number; index: number }[] = [];
|
|
323
|
-
for (let i = 0; i < scenes.length; i++) {
|
|
324
|
-
const scene = scenes[i];
|
|
325
|
-
let chunk = chunks[i];
|
|
326
|
-
if (kept.length === 0) {
|
|
327
|
-
// First beat is always pinned to chunk 0.
|
|
328
|
-
chunk = 0;
|
|
329
|
-
kept.push({ scene, chunk, index: i });
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
const prev = kept[kept.length - 1].chunk;
|
|
333
|
-
if (chunk - prev < minSpacing) {
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
kept.push({ scene, chunk, index: i });
|
|
337
|
-
}
|
|
338
|
-
return kept;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
276
|
export function mapEnrichmentToTimeline(
|
|
342
277
|
enrichment: EnrichmentRecord,
|
|
343
278
|
opts: MapEnrichmentOptions = {},
|
|
@@ -378,7 +313,7 @@ export function mapEnrichmentToTimeline(
|
|
|
378
313
|
const chunks = computeChunkIndices(scenes, maxChunks);
|
|
379
314
|
const kept = enforceSpacing(scenes, chunks, minChunkSpacing);
|
|
380
315
|
|
|
381
|
-
return kept.map(({ scene, chunk, index }) => {
|
|
316
|
+
return kept.map(({ item: scene, chunk, index }) => {
|
|
382
317
|
const description = scene.description as string; // coerced non-empty
|
|
383
318
|
const prompt = styleHint ? `${styleHint} ${description}` : description;
|
|
384
319
|
const beat: TimelineBeat = {
|