@escapeaihq/client-core 0.6.1 → 0.8.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 +28 -3
- package/dist/api.d.ts +102 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +92 -0
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reactor/entityContext.d.ts +34 -0
- package/dist/reactor/entityContext.d.ts.map +1 -0
- package/dist/reactor/entityContext.js +119 -0
- package/dist/reactor/entityContext.js.map +1 -0
- package/dist/reactor/entitySearch.d.ts +71 -0
- package/dist/reactor/entitySearch.d.ts.map +1 -0
- package/dist/reactor/entitySearch.js +93 -0
- package/dist/reactor/entitySearch.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts +98 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.js +181 -0
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -0
- package/dist/reactor/heliosTools.d.ts +156 -0
- package/dist/reactor/heliosTools.d.ts.map +1 -0
- package/dist/reactor/heliosTools.js +241 -0
- package/dist/reactor/heliosTools.js.map +1 -0
- package/dist/reactor/index.d.ts +17 -0
- package/dist/reactor/index.d.ts.map +1 -0
- package/dist/reactor/index.js +17 -0
- package/dist/reactor/index.js.map +1 -0
- package/dist/reactor/promptAddonRegistry.d.ts +37 -0
- package/dist/reactor/promptAddonRegistry.d.ts.map +1 -0
- package/dist/reactor/promptAddonRegistry.js +38 -0
- package/dist/reactor/promptAddonRegistry.js.map +1 -0
- package/dist/reactor/regenTemplate.d.ts +23 -0
- package/dist/reactor/regenTemplate.d.ts.map +1 -0
- package/dist/reactor/regenTemplate.js +103 -0
- package/dist/reactor/regenTemplate.js.map +1 -0
- package/dist/reactor/sceneEntry.d.ts +79 -0
- package/dist/reactor/sceneEntry.d.ts.map +1 -0
- package/dist/reactor/sceneEntry.js +177 -0
- package/dist/reactor/sceneEntry.js.map +1 -0
- package/dist/reactor/scenesFromEnrichment.d.ts +67 -0
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -0
- package/dist/reactor/scenesFromEnrichment.js +344 -0
- package/dist/reactor/scenesFromEnrichment.js.map +1 -0
- package/dist/reactor/seedImageOrchestrator.d.ts +81 -0
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -0
- package/dist/reactor/seedImageOrchestrator.js +79 -0
- package/dist/reactor/seedImageOrchestrator.js.map +1 -0
- package/dist/reactor/toolPromptAddon.d.ts +44 -0
- package/dist/reactor/toolPromptAddon.d.ts.map +1 -0
- package/dist/reactor/toolPromptAddon.js +129 -0
- package/dist/reactor/toolPromptAddon.js.map +1 -0
- package/dist/reactor/toolPromptAddonId.d.ts +10 -0
- package/dist/reactor/toolPromptAddonId.d.ts.map +1 -0
- package/dist/reactor/toolPromptAddonId.js +10 -0
- package/dist/reactor/toolPromptAddonId.js.map +1 -0
- package/dist/reactor/types.d.ts +149 -0
- package/dist/reactor/types.d.ts.map +1 -0
- package/dist/reactor/types.js +2 -0
- package/dist/reactor/types.js.map +1 -0
- package/dist/reactor/upsamplePrompt.d.ts +30 -0
- package/dist/reactor/upsamplePrompt.d.ts.map +1 -0
- package/dist/reactor/upsamplePrompt.js +118 -0
- package/dist/reactor/upsamplePrompt.js.map +1 -0
- package/dist/timeFormat.d.ts +28 -0
- package/dist/timeFormat.d.ts.map +1 -0
- package/dist/timeFormat.js +48 -0
- package/dist/timeFormat.js.map +1 -0
- package/dist/websocket.d.ts +31 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +20 -0
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/reactor/__snapshots__/regenTemplate.test.ts.snap +5 -0
- package/src/__tests__/reactor/__snapshots__/scenesFromEnrichment.test.ts.snap +34 -0
- package/src/__tests__/reactor/api-reactor.test.ts +253 -0
- package/src/__tests__/reactor/entityContext.test.ts +237 -0
- package/src/__tests__/reactor/entitySearch.test.ts +223 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +438 -0
- package/src/__tests__/reactor/heliosTools.test.ts +164 -0
- package/src/__tests__/reactor/promptAddonRegistry.test.ts +40 -0
- package/src/__tests__/reactor/regenTemplate.test.ts +156 -0
- package/src/__tests__/reactor/sceneEntry.test.ts +342 -0
- package/src/__tests__/reactor/scenesFromEnrichment.test.ts +760 -0
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +139 -0
- package/src/__tests__/reactor/toolPromptAddon.test.ts +104 -0
- package/src/__tests__/reactor/upsamplePrompt.test.ts +245 -0
- package/src/__tests__/timeFormat.test.ts +80 -0
- package/src/__tests__/websocket.test.ts +75 -0
- package/src/api.ts +170 -2
- package/src/index.ts +2 -0
- package/src/reactor/entityContext.ts +147 -0
- package/src/reactor/entitySearch.ts +139 -0
- package/src/reactor/heliosCommandDispatcher.ts +293 -0
- package/src/reactor/heliosTools.ts +260 -0
- package/src/reactor/index.ts +17 -0
- package/src/reactor/promptAddonRegistry.ts +52 -0
- package/src/reactor/regenTemplate.ts +142 -0
- package/src/reactor/sceneEntry.ts +267 -0
- package/src/reactor/scenesFromEnrichment.ts +393 -0
- package/src/reactor/seedImageOrchestrator.ts +132 -0
- package/src/reactor/toolPromptAddon.ts +135 -0
- package/src/reactor/toolPromptAddonId.ts +9 -0
- package/src/reactor/types.ts +158 -0
- package/src/reactor/upsamplePrompt.ts +154 -0
- package/src/timeFormat.ts +57 -0
- package/src/websocket.ts +42 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildRegenPrompt` — pure, deterministic prompt builder for the
|
|
3
|
+
* optional Gemini Flash Image regen step.
|
|
4
|
+
*
|
|
5
|
+
* Encodes the locked guarantees (16:9, identity preservation when
|
|
6
|
+
* requested, entity grounding) plus structured creative choices
|
|
7
|
+
* (framing, lighting, style) plus the user's free-form creative
|
|
8
|
+
* direction. The output is a single string suitable for
|
|
9
|
+
* `services/image_regeneration`'s `prompt` field.
|
|
10
|
+
*
|
|
11
|
+
* **Determinism matters.** The output of this function is shown
|
|
12
|
+
* verbatim in the RegenForm's live preview — a hidden non-determinism
|
|
13
|
+
* (e.g. `Date.now()` interpolation, randomization) would make the
|
|
14
|
+
* preview lie about the prompt that's actually generated.
|
|
15
|
+
*
|
|
16
|
+
* Throws `Error("customStyle required when styleFamily is 'custom'")`
|
|
17
|
+
* when the invariant is violated. The TS type can't express this
|
|
18
|
+
* cleanly without a discriminated union, so it's checked at runtime
|
|
19
|
+
* (the consuming UI also validates pre-submit).
|
|
20
|
+
*/
|
|
21
|
+
const FRAMING_PHRASES = {
|
|
22
|
+
wide: 'wide shot capturing the full environment',
|
|
23
|
+
medium: 'medium shot framing the full figure',
|
|
24
|
+
'medium-close-up': 'medium close-up framing the face and upper body',
|
|
25
|
+
'close-up': 'close-up emphasising fine facial detail',
|
|
26
|
+
};
|
|
27
|
+
const LIGHTING_PHRASES = {
|
|
28
|
+
cinematic: 'cinematic lighting with deep shadows, sculpted key light, and a soft cool fill',
|
|
29
|
+
'golden-hour': 'warm golden-hour light, low sun raking across the subject, long soft shadows',
|
|
30
|
+
noir: 'high-contrast noir lighting, hard key light from a single source, dramatic shadow falloff',
|
|
31
|
+
natural: 'soft natural daylight, gentle directional shadows, balanced ambient fill',
|
|
32
|
+
studio: 'clean three-point studio lighting, even exposure, controlled highlights',
|
|
33
|
+
};
|
|
34
|
+
const STYLE_PHRASES = {
|
|
35
|
+
photoreal: 'photorealistic style, naturalistic textures and skin, lifelike depth of field',
|
|
36
|
+
anime: 'modern cinematic anime style, clean line art, painterly cel-shaded colour, expressive eyes',
|
|
37
|
+
watercolor: 'soft watercolour painting style, visible pigment edges, gentle paper texture',
|
|
38
|
+
pixar: 'stylised Pixar-quality 3D animation, polished subsurface scattering, warm rendered look',
|
|
39
|
+
'film-35mm': '35mm film stock aesthetic, subtle grain, organic colour science, slight halation',
|
|
40
|
+
};
|
|
41
|
+
export function buildRegenPrompt(input) {
|
|
42
|
+
if (input.styleFamily === 'custom') {
|
|
43
|
+
const custom = (input.customStyle ?? '').trim();
|
|
44
|
+
if (!custom) {
|
|
45
|
+
throw new Error("customStyle required when styleFamily is 'custom'");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const stylePhrase = input.styleFamily === 'custom'
|
|
49
|
+
? (input.customStyle ?? '').trim()
|
|
50
|
+
: STYLE_PHRASES[input.styleFamily];
|
|
51
|
+
const framingPhrase = FRAMING_PHRASES[input.framing];
|
|
52
|
+
const lightingPhrase = LIGHTING_PHRASES[input.lighting];
|
|
53
|
+
const segments = [];
|
|
54
|
+
// Opener — re-frame or reinterpret based on identity-preservation toggle.
|
|
55
|
+
// The 16:9 aspect ratio is always called out explicitly because the
|
|
56
|
+
// downstream Helios reference-image check rejects non-16:9 inputs.
|
|
57
|
+
if (input.preserveIdentity) {
|
|
58
|
+
segments.push(`Reframe ${input.entity.name} as a wide 16:9 cinematic shot while preserving their distinctive features, proportions, and identity from the reference image.`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
segments.push(`Reinterpret ${input.entity.name} as a wide 16:9 cinematic shot, taking creative liberties with appearance while keeping them recognisably the same character.`);
|
|
62
|
+
}
|
|
63
|
+
// 16:9 guarantee — restated as a hard requirement so the model
|
|
64
|
+
// doesn't drift to vertical or square outputs.
|
|
65
|
+
segments.push('16:9 framing required — the output must be a landscape composition.');
|
|
66
|
+
// Framing keyword.
|
|
67
|
+
segments.push(`Use a ${framingPhrase}.`);
|
|
68
|
+
// Lighting keyword.
|
|
69
|
+
segments.push(`Light the scene with ${lightingPhrase}.`);
|
|
70
|
+
// Style descriptor.
|
|
71
|
+
segments.push(`Render in ${stylePhrase}.`);
|
|
72
|
+
// Entity grounding — name + scene context if available. Trim the
|
|
73
|
+
// sceneContext and ensure it ends with terminal punctuation so the
|
|
74
|
+
// next segment (typically the persona backstory) doesn't run on into
|
|
75
|
+
// the previous sentence.
|
|
76
|
+
if (input.entity.sceneContext) {
|
|
77
|
+
const scene = input.entity.sceneContext.trim();
|
|
78
|
+
const punctuated = /[.!?]$/.test(scene) ? scene : `${scene}.`;
|
|
79
|
+
segments.push(`Character context: ${input.entity.name} is grounded in the source scene — ${punctuated}`);
|
|
80
|
+
}
|
|
81
|
+
// Persona backstory — character grounding when provided. Same
|
|
82
|
+
// trailing-period treatment so creative direction (or any later
|
|
83
|
+
// segment) starts cleanly.
|
|
84
|
+
if (input.persona) {
|
|
85
|
+
const backstory = input.persona.backstory.trim();
|
|
86
|
+
const punctuated = /[.!?]$/.test(backstory) ? backstory : `${backstory}.`;
|
|
87
|
+
segments.push(`Persona backstory for ${input.persona.name}: ${punctuated}`);
|
|
88
|
+
}
|
|
89
|
+
// Structured overrides — only included when populated.
|
|
90
|
+
if (input.clothingOverride && input.clothingOverride.trim()) {
|
|
91
|
+
segments.push(`Wardrobe: ${input.clothingOverride.trim()}.`);
|
|
92
|
+
}
|
|
93
|
+
if (input.poseOverride && input.poseOverride.trim()) {
|
|
94
|
+
segments.push(`Pose / action: ${input.poseOverride.trim()}.`);
|
|
95
|
+
}
|
|
96
|
+
// Creative direction — appended verbatim, last, so the human voice
|
|
97
|
+
// sits closest to the model's most-recent-tokens attention bias.
|
|
98
|
+
if (input.creativeDirection && input.creativeDirection.trim()) {
|
|
99
|
+
segments.push(input.creativeDirection.trim());
|
|
100
|
+
}
|
|
101
|
+
return segments.join(' ');
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=regenTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regenTemplate.js","sourceRoot":"","sources":["../../src/reactor/regenTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,eAAe,GAAkD;IACrE,IAAI,EAAE,0CAA0C;IAChD,MAAM,EAAE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CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAC7D,CAAC;IACJ,CAAC;IAED,uDAAuD;IACvD,IAAI,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5D,QAAQ,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC;QACpD,QAAQ,CAAC,IAAI,CAAC,kBAAkB,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;IAED,mEAAmE;IACnE,iEAAiE;IACjE,IAAI,KAAK,CAAC,iBAAiB,IAAI,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9D,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Step Into Scene" orchestrator: turns a (videoId, timestamp) into a
|
|
3
|
+
* fully-bootstrapped Helios world seeded with the extracted frame and
|
|
4
|
+
* primed with a Pegasus-grounded scene prompt.
|
|
5
|
+
*
|
|
6
|
+
* Framework-agnostic. Consumed by:
|
|
7
|
+
* - seer-agent React `/watch/[videoId]` page (PR 1 + PR 2 of #200)
|
|
8
|
+
* - Vue web-app's existing video watching surface (post-tag, in web-app repo)
|
|
9
|
+
*
|
|
10
|
+
* The orchestrator is two pure functions split at the seam between
|
|
11
|
+
* "network work that produces a payload" (prepareSceneEntry) and
|
|
12
|
+
* "issue Reactor commands against a live session" (bootstrapSceneInReactor).
|
|
13
|
+
* Splitting at the seam lets the React modal render a "Materializing…"
|
|
14
|
+
* state while the payload is being prepared, *before* the ReactorProvider
|
|
15
|
+
* has connected — the bootstrap call then runs once the SDK reports ready.
|
|
16
|
+
*/
|
|
17
|
+
import type { ApiClient, EnrichmentRecord, PersonaConfig } from '../api';
|
|
18
|
+
import { type SeedImageReactorBridge } from './seedImageOrchestrator';
|
|
19
|
+
export interface SceneEntryInput {
|
|
20
|
+
/** The Seer video the user is watching. */
|
|
21
|
+
videoId: string;
|
|
22
|
+
/** Playhead position at the moment Step Into Scene was clicked. */
|
|
23
|
+
timestamp: number;
|
|
24
|
+
/** Caption for the bracketing shot, if enrichment is loaded. Feeds the
|
|
25
|
+
* upsample as the user-supplied prompt — Pegasus's narrative summary
|
|
26
|
+
* of THIS moment is a stronger upsample input than the entity name
|
|
27
|
+
* alone. Falls back to a generic seed when absent. */
|
|
28
|
+
shotCaption?: string | null;
|
|
29
|
+
/** Most-recent SUCCEEDED Pegasus enrichment for the video, used to
|
|
30
|
+
* derive `sceneContext` inside the entity grounding. */
|
|
31
|
+
enrichment: EnrichmentRecord | null;
|
|
32
|
+
/** Active persona on the watch page. `null` means "no persona
|
|
33
|
+
* grounding" — the upsample runs with entity-only context. */
|
|
34
|
+
persona: PersonaConfig | null;
|
|
35
|
+
apiClient: ApiClient;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
export interface SceneEntryPayload {
|
|
39
|
+
/** The captured frame, wrapped as a `File` ready for `reactor.uploadFile`. */
|
|
40
|
+
frameFile: File;
|
|
41
|
+
/** Helios-quality scene paragraph from the upsample call. */
|
|
42
|
+
upsampledPrompt: string;
|
|
43
|
+
/** Pass-through for callers that want to render "from shot N at 0:42"
|
|
44
|
+
* in the modal header. */
|
|
45
|
+
sourceTimestamp: number;
|
|
46
|
+
/** Tracked `ImageRecord` id for the extracted frame. Lets the modal
|
|
47
|
+
* (or any consumer) deep-link to `/images/{imageId}` for inspection
|
|
48
|
+
* or wire a "View in gallery" affordance. */
|
|
49
|
+
imageId: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Run the extract + upsample + frame-fetch pipeline. Resolves with a
|
|
53
|
+
* `SceneEntryPayload` ready to feed into `bootstrapSceneInReactor`. The
|
|
54
|
+
* `signal` is plumbed through both API calls AND the frame-blob fetch
|
|
55
|
+
* so an unmount mid-pipeline cancels cleanly.
|
|
56
|
+
*/
|
|
57
|
+
export declare function prepareSceneEntry(input: SceneEntryInput): Promise<SceneEntryPayload>;
|
|
58
|
+
/**
|
|
59
|
+
* Apply the prepared payload to a live Reactor session. Composes
|
|
60
|
+
* `sendSeedFileToReactor` (from #199's orchestrator) with the
|
|
61
|
+
* `set_prompt` + `start` commands that turn a seeded session into a
|
|
62
|
+
* generating world.
|
|
63
|
+
*
|
|
64
|
+
* Use `transition: 'cut'` because this is always the first seed of a
|
|
65
|
+
* new session (closing the modal disconnects, so re-opens are fresh).
|
|
66
|
+
*
|
|
67
|
+
* **Abort behaviour.** The Reactor SDK's `uploadFile` and `sendCommand`
|
|
68
|
+
* don't accept an `AbortSignal` today, so we can't actually *cancel*
|
|
69
|
+
* an in-flight upload. Instead we race each phase against the signal:
|
|
70
|
+
* if the user closes the modal mid-upload the awaiting promise
|
|
71
|
+
* rejects with `AbortError` immediately, leaving the bridge to finish
|
|
72
|
+
* (or fail when `<ReactorProvider>` unmounts and tears down the
|
|
73
|
+
* session). Without the race the modal would appear frozen for the
|
|
74
|
+
* full upload duration even though the user has clicked "Back".
|
|
75
|
+
*/
|
|
76
|
+
export declare function bootstrapSceneInReactor(payload: SceneEntryPayload, bridge: SeedImageReactorBridge, options?: {
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
//# sourceMappingURL=sceneEntry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneEntry.d.ts","sourceRoot":"","sources":["../../src/reactor/sceneEntry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAEhB,aAAa,EACd,MAAM,QAAQ,CAAC;AAKhB,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB;;;2DAGuD;IACvD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B;6DACyD;IACzD,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACpC;mEAC+D;IAC/D,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,SAAS,EAAE,IAAI,CAAC;IAChB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;IACxB;+BAC2B;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB;;kDAE8C;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;AAaD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAgE5B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACrC,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Step Into Scene" orchestrator: turns a (videoId, timestamp) into a
|
|
3
|
+
* fully-bootstrapped Helios world seeded with the extracted frame and
|
|
4
|
+
* primed with a Pegasus-grounded scene prompt.
|
|
5
|
+
*
|
|
6
|
+
* Framework-agnostic. Consumed by:
|
|
7
|
+
* - seer-agent React `/watch/[videoId]` page (PR 1 + PR 2 of #200)
|
|
8
|
+
* - Vue web-app's existing video watching surface (post-tag, in web-app repo)
|
|
9
|
+
*
|
|
10
|
+
* The orchestrator is two pure functions split at the seam between
|
|
11
|
+
* "network work that produces a payload" (prepareSceneEntry) and
|
|
12
|
+
* "issue Reactor commands against a live session" (bootstrapSceneInReactor).
|
|
13
|
+
* Splitting at the seam lets the React modal render a "Materializing…"
|
|
14
|
+
* state while the payload is being prepared, *before* the ReactorProvider
|
|
15
|
+
* has connected — the bootstrap call then runs once the SDK reports ready.
|
|
16
|
+
*/
|
|
17
|
+
import { aggregateEntityContext, aggregatePersonaContext, } from './entityContext.js';
|
|
18
|
+
import { loadSeedImageFile, sendSeedFileToReactor, } from './seedImageOrchestrator.js';
|
|
19
|
+
/** Fallback shot caption when enrichment is absent or the playhead is
|
|
20
|
+
* outside any shot. Matches the cadence of the upsample's training
|
|
21
|
+
* prompts so the LLM doesn't reject a one-word input. */
|
|
22
|
+
const FALLBACK_SHOT_CAPTION = 'Step into this moment';
|
|
23
|
+
/** Sentinel entity name for the `ExtractImageRequest`. The backend
|
|
24
|
+
* endpoint requires this field but uses `timestamp` for the actual
|
|
25
|
+
* frame extraction when both are provided — `entity` survives only as
|
|
26
|
+
* a label on the resulting ImageRecord. */
|
|
27
|
+
const SCENE_ENTITY_LABEL = 'scene';
|
|
28
|
+
/**
|
|
29
|
+
* Run the extract + upsample + frame-fetch pipeline. Resolves with a
|
|
30
|
+
* `SceneEntryPayload` ready to feed into `bootstrapSceneInReactor`. The
|
|
31
|
+
* `signal` is plumbed through both API calls AND the frame-blob fetch
|
|
32
|
+
* so an unmount mid-pipeline cancels cleanly.
|
|
33
|
+
*/
|
|
34
|
+
export async function prepareSceneEntry(input) {
|
|
35
|
+
const { videoId, timestamp, shotCaption, enrichment, persona, apiClient, signal, } = input;
|
|
36
|
+
// Step 1 — extract the frame server-side. The endpoint uses ffmpeg
|
|
37
|
+
// against the source video's presigned URL and persists an
|
|
38
|
+
// ImageRecord that shows up in the user's gallery (free bookmark).
|
|
39
|
+
const extract = await apiClient.extractImage({ videoId, entity: SCENE_ENTITY_LABEL, timestamp }, { signal });
|
|
40
|
+
// The seed-image proxy is the only browser-safe path to the frame
|
|
41
|
+
// bytes (the raw S3 bucket has no CORS rules). If best-effort
|
|
42
|
+
// persistence failed and we got back an extract response with no
|
|
43
|
+
// imageId, we can't seed Reactor at all — fail loudly here rather
|
|
44
|
+
// than later, where the user has already seen "Materializing…".
|
|
45
|
+
if (!extract.imageId) {
|
|
46
|
+
throw new Error('extract-image did not return an imageId — the ImageRecord write failed and the frame is unreachable from the browser.');
|
|
47
|
+
}
|
|
48
|
+
// Step 2 — fan out the upsample call, blob fetch (through the
|
|
49
|
+
// same-origin seed-image proxy), and the entity-grounding build in
|
|
50
|
+
// parallel. Upsample uses text-only grounding (Pegasus scene context
|
|
51
|
+
// is richer than single-frame visual would be); the blob proxy and
|
|
52
|
+
// upsample are independent so running them serially would add ~1.5s
|
|
53
|
+
// of round-trip latency for no benefit.
|
|
54
|
+
const entityContext = aggregateEntityContext({
|
|
55
|
+
imageRecord: synthesizeImageRecord(videoId, extract),
|
|
56
|
+
enrichment: enrichment ?? undefined,
|
|
57
|
+
});
|
|
58
|
+
const personaContext = persona ? aggregatePersonaContext(persona) : null;
|
|
59
|
+
const promptInput = shotCaption?.trim() || FALLBACK_SHOT_CAPTION;
|
|
60
|
+
const [upsample, frameFile] = await Promise.all([
|
|
61
|
+
apiClient.upsampleReactorPrompt({
|
|
62
|
+
prompt: promptInput,
|
|
63
|
+
entityContext,
|
|
64
|
+
...(personaContext ? { personaContext } : {}),
|
|
65
|
+
}, { signal }),
|
|
66
|
+
loadSeedImageFile(extract.imageId, apiClient, {
|
|
67
|
+
signal,
|
|
68
|
+
filenameStem: 'scene',
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
return {
|
|
72
|
+
frameFile,
|
|
73
|
+
upsampledPrompt: upsample.upsampledPrompt,
|
|
74
|
+
sourceTimestamp: extract.sourceTimestamp,
|
|
75
|
+
imageId: extract.imageId,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Apply the prepared payload to a live Reactor session. Composes
|
|
80
|
+
* `sendSeedFileToReactor` (from #199's orchestrator) with the
|
|
81
|
+
* `set_prompt` + `start` commands that turn a seeded session into a
|
|
82
|
+
* generating world.
|
|
83
|
+
*
|
|
84
|
+
* Use `transition: 'cut'` because this is always the first seed of a
|
|
85
|
+
* new session (closing the modal disconnects, so re-opens are fresh).
|
|
86
|
+
*
|
|
87
|
+
* **Abort behaviour.** The Reactor SDK's `uploadFile` and `sendCommand`
|
|
88
|
+
* don't accept an `AbortSignal` today, so we can't actually *cancel*
|
|
89
|
+
* an in-flight upload. Instead we race each phase against the signal:
|
|
90
|
+
* if the user closes the modal mid-upload the awaiting promise
|
|
91
|
+
* rejects with `AbortError` immediately, leaving the bridge to finish
|
|
92
|
+
* (or fail when `<ReactorProvider>` unmounts and tears down the
|
|
93
|
+
* session). Without the race the modal would appear frozen for the
|
|
94
|
+
* full upload duration even though the user has clicked "Back".
|
|
95
|
+
*/
|
|
96
|
+
export async function bootstrapSceneInReactor(payload, bridge, options = {}) {
|
|
97
|
+
// Abort is an *expected* terminal state for this flow (user clicked
|
|
98
|
+
// Back to video, modal unmounted, etc.). Internally we use exceptions
|
|
99
|
+
// for fast unwind, but the public contract is "returns void on
|
|
100
|
+
// success or abort, throws only on a real Reactor failure". Callers
|
|
101
|
+
// already check `signal.aborted` to decide what to render — they
|
|
102
|
+
// shouldn't have to ALSO distinguish AbortError from real errors.
|
|
103
|
+
try {
|
|
104
|
+
if (options.signal?.aborted)
|
|
105
|
+
return;
|
|
106
|
+
await raceWithAbort(sendSeedFileToReactor(payload.frameFile, bridge, { transition: 'cut' }), options.signal);
|
|
107
|
+
if (options.signal?.aborted)
|
|
108
|
+
return;
|
|
109
|
+
await raceWithAbort(bridge.sendCommand('set_prompt', { prompt: payload.upsampledPrompt }), options.signal);
|
|
110
|
+
if (options.signal?.aborted)
|
|
111
|
+
return;
|
|
112
|
+
await raceWithAbort(bridge.sendCommand('start', {}), options.signal);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (isAbortError(err))
|
|
116
|
+
return;
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function isAbortError(err) {
|
|
121
|
+
if (err instanceof DOMException && err.name === 'AbortError')
|
|
122
|
+
return true;
|
|
123
|
+
return err instanceof Error && err.name === 'AbortError';
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Race a promise against an `AbortSignal`. When the signal fires, the
|
|
127
|
+
* returned promise rejects with `AbortError` even if the underlying
|
|
128
|
+
* promise hasn't resolved — useful when the underlying operation
|
|
129
|
+
* (Reactor SDK calls in this case) can't be cancelled directly. The
|
|
130
|
+
* underlying operation still runs to completion in the background;
|
|
131
|
+
* the race only lets the caller stop awaiting it.
|
|
132
|
+
*/
|
|
133
|
+
function raceWithAbort(promise, signal) {
|
|
134
|
+
if (!signal)
|
|
135
|
+
return promise;
|
|
136
|
+
if (signal.aborted) {
|
|
137
|
+
return Promise.reject(new DOMException('Aborted', 'AbortError'));
|
|
138
|
+
}
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
const onAbort = () => {
|
|
141
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
142
|
+
};
|
|
143
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
144
|
+
promise.then(value => {
|
|
145
|
+
signal.removeEventListener('abort', onAbort);
|
|
146
|
+
resolve(value);
|
|
147
|
+
}, err => {
|
|
148
|
+
signal.removeEventListener('abort', onAbort);
|
|
149
|
+
reject(err);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build a minimal `ImageRecord` from an `ExtractImageResponse` so the
|
|
155
|
+
* existing `aggregateEntityContext` helper can compute scene grounding
|
|
156
|
+
* without us having to round-trip a `listImages` call for the new
|
|
157
|
+
* record's ID. Only `source_timestamp` and `source_video_id` are read
|
|
158
|
+
* by the aggregator; the other fields are filled with safe defaults so
|
|
159
|
+
* the resulting object satisfies the TypeScript shape.
|
|
160
|
+
*/
|
|
161
|
+
function synthesizeImageRecord(videoId, extract) {
|
|
162
|
+
const now = new Date().toISOString();
|
|
163
|
+
return {
|
|
164
|
+
image_id: '',
|
|
165
|
+
user_id: '',
|
|
166
|
+
s3_key: extract.imageS3Key,
|
|
167
|
+
s3_bucket: '',
|
|
168
|
+
category: 'extracted',
|
|
169
|
+
content_type: 'image/png',
|
|
170
|
+
source_video_id: videoId,
|
|
171
|
+
source_entity: extract.entity,
|
|
172
|
+
source_timestamp: extract.sourceTimestamp,
|
|
173
|
+
created_at: now,
|
|
174
|
+
updated_at: now,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=sceneEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneEntry.js","sourceRoot":"","sources":["../../src/reactor/sceneEntry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAoCjC;;0DAE0D;AAC1D,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD;;;4CAG4C;AAC5C,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAsB;IAEtB,MAAM,EACJ,OAAO,EACP,SAAS,EACT,WAAW,EACX,UAAU,EACV,OAAO,EACP,SAAS,EACT,MAAM,GACP,GAAG,K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CAAC,MAAM;QAC7B,gBAAgB,EAAE,OAAO,CAAC,eAAe;QACzC,UAAU,EAAE,GAAG;QACf,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mapEnrichmentToTimeline` — maps a Pegasus video-enrichment result into
|
|
3
|
+
* an ordered array of `TimelineBeat`s that can be scheduled onto a Helios
|
|
4
|
+
* session via `sendCommand("schedule_prompt", {prompt, chunk})`.
|
|
5
|
+
*
|
|
6
|
+
* Defensive by design. `EnrichmentRecord.result` is typed as
|
|
7
|
+
* `Record<string, unknown>` because Pegasus's output shape isn't locked
|
|
8
|
+
* at the client. We probe the shapes we've observed in practice and fall
|
|
9
|
+
* back to `[]` for anything we can't parse:
|
|
10
|
+
* - Shape A: `{scenes: [{start, end, description, title?}, ...]}` —
|
|
11
|
+
* the preferred per-scene timeline form.
|
|
12
|
+
* - Shape B: `{narrative: {acts: [{scenes: [...]}]}}` — alternate
|
|
13
|
+
* narrative-tree form. We flatten across acts in order.
|
|
14
|
+
* - Shape C: `{summary: "..."}` — degenerate; returns a single beat at
|
|
15
|
+
* chunk 0.
|
|
16
|
+
* - Anything else: `[]`.
|
|
17
|
+
*
|
|
18
|
+
* Chunk distribution rules:
|
|
19
|
+
* - When all scenes have valid `start`/`end` timings, beat chunks are
|
|
20
|
+
* scaled proportionally across `maxChunks` using each scene's `start`
|
|
21
|
+
* relative to the total video span (max scene `end`).
|
|
22
|
+
* - When scenes lack timings, beats are distributed evenly.
|
|
23
|
+
* - `minChunkSpacing` enforces a minimum chunk gap between consecutive
|
|
24
|
+
* beats — beats that would collide with the previous one are dropped.
|
|
25
|
+
* The first beat is always pinned to chunk 0.
|
|
26
|
+
* - `maxChunks` clamps the maximum chunk index. Beats whose computed
|
|
27
|
+
* chunk exceeds `maxChunks - 1` are clamped to `maxChunks - 1`, then
|
|
28
|
+
* deduplicated by the spacing rule.
|
|
29
|
+
*
|
|
30
|
+
* `styleHint` (when non-empty) is prepended to every beat's prompt with a
|
|
31
|
+
* single space separator. No trailing punctuation is added — the caller
|
|
32
|
+
* controls phrasing.
|
|
33
|
+
*/
|
|
34
|
+
import type { EnrichmentRecord } from '../api';
|
|
35
|
+
/**
|
|
36
|
+
* A single beat on the director timeline. One beat = one
|
|
37
|
+
* `schedule_prompt` call at the indicated chunk.
|
|
38
|
+
*/
|
|
39
|
+
export interface TimelineBeat {
|
|
40
|
+
/** Chunk index where this prompt should fire (0-based, monotonically increasing). */
|
|
41
|
+
chunk: number;
|
|
42
|
+
/** Helios scene prompt for this beat (will be sent to `schedule_prompt`). */
|
|
43
|
+
prompt: string;
|
|
44
|
+
/** Source-video time range this beat corresponds to, for UI display. */
|
|
45
|
+
sourceStart?: number;
|
|
46
|
+
sourceEnd?: number;
|
|
47
|
+
/** Free-text label for the UI (typically the scene number or title). */
|
|
48
|
+
label?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Caller-tunable options for `mapEnrichmentToTimeline`. All have defaults
|
|
52
|
+
* picked to match the Helios prototype's chunk budget (~33 fpc, 30 chunks
|
|
53
|
+
* ≈ 16s of generated video).
|
|
54
|
+
*/
|
|
55
|
+
export interface MapEnrichmentOptions {
|
|
56
|
+
/** Total chunks to fit. Beats are distributed evenly when source timings
|
|
57
|
+
* aren't available, or scaled proportionally if they are. */
|
|
58
|
+
maxChunks?: number;
|
|
59
|
+
/** Skip beats shorter than this many chunks. Prevents the model getting
|
|
60
|
+
* whiplashed by sub-chunk scene transitions. */
|
|
61
|
+
minChunkSpacing?: number;
|
|
62
|
+
/** A free-text prefix the caller wants to inject into every beat
|
|
63
|
+
* (e.g. "cinematic 16:9, golden hour"). Empty by default. */
|
|
64
|
+
styleHint?: string;
|
|
65
|
+
}
|
|
66
|
+
export declare function mapEnrichmentToTimeline(enrichment: EnrichmentRecord, opts?: MapEnrichmentOptions): TimelineBeat[];
|
|
67
|
+
//# sourceMappingURL=scenesFromEnrichment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenesFromEnrichment.d.ts","sourceRoot":"","sources":["../../src/reactor/scenesFromEnrichment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG/C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;kEAC8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;qDACiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;kEAC8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgRD,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,gBAAgB,EAC5B,IAAI,GAAE,oBAAyB,GAC9B,YAAY,EAAE,CAiDhB"}
|