@escapeaihq/client-core 0.6.1 → 0.7.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.
Files changed (103) hide show
  1. package/README.md +27 -2
  2. package/dist/api.d.ts +102 -2
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/api.js +92 -0
  5. package/dist/api.js.map +1 -1
  6. package/dist/audio.d.ts +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/reactor/entityContext.d.ts +34 -0
  12. package/dist/reactor/entityContext.d.ts.map +1 -0
  13. package/dist/reactor/entityContext.js +119 -0
  14. package/dist/reactor/entityContext.js.map +1 -0
  15. package/dist/reactor/entitySearch.d.ts +71 -0
  16. package/dist/reactor/entitySearch.d.ts.map +1 -0
  17. package/dist/reactor/entitySearch.js +93 -0
  18. package/dist/reactor/entitySearch.js.map +1 -0
  19. package/dist/reactor/heliosCommandDispatcher.d.ts +98 -0
  20. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -0
  21. package/dist/reactor/heliosCommandDispatcher.js +181 -0
  22. package/dist/reactor/heliosCommandDispatcher.js.map +1 -0
  23. package/dist/reactor/heliosTools.d.ts +156 -0
  24. package/dist/reactor/heliosTools.d.ts.map +1 -0
  25. package/dist/reactor/heliosTools.js +241 -0
  26. package/dist/reactor/heliosTools.js.map +1 -0
  27. package/dist/reactor/index.d.ts +17 -0
  28. package/dist/reactor/index.d.ts.map +1 -0
  29. package/dist/reactor/index.js +17 -0
  30. package/dist/reactor/index.js.map +1 -0
  31. package/dist/reactor/promptAddonRegistry.d.ts +37 -0
  32. package/dist/reactor/promptAddonRegistry.d.ts.map +1 -0
  33. package/dist/reactor/promptAddonRegistry.js +38 -0
  34. package/dist/reactor/promptAddonRegistry.js.map +1 -0
  35. package/dist/reactor/regenTemplate.d.ts +23 -0
  36. package/dist/reactor/regenTemplate.d.ts.map +1 -0
  37. package/dist/reactor/regenTemplate.js +103 -0
  38. package/dist/reactor/regenTemplate.js.map +1 -0
  39. package/dist/reactor/sceneEntry.d.ts +79 -0
  40. package/dist/reactor/sceneEntry.d.ts.map +1 -0
  41. package/dist/reactor/sceneEntry.js +177 -0
  42. package/dist/reactor/sceneEntry.js.map +1 -0
  43. package/dist/reactor/scenesFromEnrichment.d.ts +67 -0
  44. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -0
  45. package/dist/reactor/scenesFromEnrichment.js +344 -0
  46. package/dist/reactor/scenesFromEnrichment.js.map +1 -0
  47. package/dist/reactor/seedImageOrchestrator.d.ts +81 -0
  48. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -0
  49. package/dist/reactor/seedImageOrchestrator.js +79 -0
  50. package/dist/reactor/seedImageOrchestrator.js.map +1 -0
  51. package/dist/reactor/toolPromptAddon.d.ts +44 -0
  52. package/dist/reactor/toolPromptAddon.d.ts.map +1 -0
  53. package/dist/reactor/toolPromptAddon.js +129 -0
  54. package/dist/reactor/toolPromptAddon.js.map +1 -0
  55. package/dist/reactor/toolPromptAddonId.d.ts +10 -0
  56. package/dist/reactor/toolPromptAddonId.d.ts.map +1 -0
  57. package/dist/reactor/toolPromptAddonId.js +10 -0
  58. package/dist/reactor/toolPromptAddonId.js.map +1 -0
  59. package/dist/reactor/types.d.ts +149 -0
  60. package/dist/reactor/types.d.ts.map +1 -0
  61. package/dist/reactor/types.js +2 -0
  62. package/dist/reactor/types.js.map +1 -0
  63. package/dist/reactor/upsamplePrompt.d.ts +30 -0
  64. package/dist/reactor/upsamplePrompt.d.ts.map +1 -0
  65. package/dist/reactor/upsamplePrompt.js +118 -0
  66. package/dist/reactor/upsamplePrompt.js.map +1 -0
  67. package/dist/timeFormat.d.ts +28 -0
  68. package/dist/timeFormat.d.ts.map +1 -0
  69. package/dist/timeFormat.js +48 -0
  70. package/dist/timeFormat.js.map +1 -0
  71. package/package.json +1 -1
  72. package/src/__tests__/reactor/__snapshots__/regenTemplate.test.ts.snap +5 -0
  73. package/src/__tests__/reactor/__snapshots__/scenesFromEnrichment.test.ts.snap +34 -0
  74. package/src/__tests__/reactor/api-reactor.test.ts +253 -0
  75. package/src/__tests__/reactor/entityContext.test.ts +237 -0
  76. package/src/__tests__/reactor/entitySearch.test.ts +223 -0
  77. package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +438 -0
  78. package/src/__tests__/reactor/heliosTools.test.ts +164 -0
  79. package/src/__tests__/reactor/promptAddonRegistry.test.ts +40 -0
  80. package/src/__tests__/reactor/regenTemplate.test.ts +156 -0
  81. package/src/__tests__/reactor/sceneEntry.test.ts +342 -0
  82. package/src/__tests__/reactor/scenesFromEnrichment.test.ts +760 -0
  83. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +139 -0
  84. package/src/__tests__/reactor/toolPromptAddon.test.ts +104 -0
  85. package/src/__tests__/reactor/upsamplePrompt.test.ts +245 -0
  86. package/src/__tests__/timeFormat.test.ts +80 -0
  87. package/src/api.ts +170 -2
  88. package/src/index.ts +2 -0
  89. package/src/reactor/entityContext.ts +147 -0
  90. package/src/reactor/entitySearch.ts +139 -0
  91. package/src/reactor/heliosCommandDispatcher.ts +293 -0
  92. package/src/reactor/heliosTools.ts +260 -0
  93. package/src/reactor/index.ts +17 -0
  94. package/src/reactor/promptAddonRegistry.ts +52 -0
  95. package/src/reactor/regenTemplate.ts +142 -0
  96. package/src/reactor/sceneEntry.ts +267 -0
  97. package/src/reactor/scenesFromEnrichment.ts +393 -0
  98. package/src/reactor/seedImageOrchestrator.ts +132 -0
  99. package/src/reactor/toolPromptAddon.ts +135 -0
  100. package/src/reactor/toolPromptAddonId.ts +9 -0
  101. package/src/reactor/types.ts +158 -0
  102. package/src/reactor/upsamplePrompt.ts +154 -0
  103. package/src/timeFormat.ts +57 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Aggregators that map Seer's wire types (ImageRecord, EnrichmentRecord,
3
+ * PersonaConfig) into the LLM-agnostic `EntityContext` / `PersonaContext`
4
+ * shapes consumed by `buildUpsamplePrompt` and `buildRegenPrompt`.
5
+ *
6
+ * Defensive by design — `EnrichmentRecord.result` is typed as
7
+ * `Record<string, unknown>` because the Pegasus output format isn't
8
+ * locked at the client. We probe a few common shapes (`{scenes: [...]}`,
9
+ * `{summary: string}`) and fall back to `undefined` when nothing matches.
10
+ * We never throw — a missing or mismatched scene just means the
11
+ * upsampler runs without the scene-context section.
12
+ */
13
+ /** Cap for `PersonaContext.backstory` so prompt budgets stay sane. */
14
+ const BACKSTORY_MAX_CHARS = 400;
15
+ /**
16
+ * Derive a short display label from an `ImageRecord` when `source_entity`
17
+ * is absent. The s3_key tends to look like `extracted/foo.png` — strip
18
+ * the directory and extension and use what's left, falling back to a
19
+ * generic "unknown entity" label.
20
+ */
21
+ function labelFromImageRecord(record) {
22
+ if (record.source_entity && record.source_entity.trim()) {
23
+ return record.source_entity.trim();
24
+ }
25
+ const key = record.s3_key ?? '';
26
+ const basename = key.split('/').pop() ?? '';
27
+ const stem = basename.replace(/\.[^.]+$/, '').trim();
28
+ return stem || 'unknown entity';
29
+ }
30
+ function asNumber(v) {
31
+ return typeof v === 'number' && Number.isFinite(v) ? v : undefined;
32
+ }
33
+ function asString(v) {
34
+ return typeof v === 'string' && v.trim() ? v.trim() : undefined;
35
+ }
36
+ /**
37
+ * Probe a Pegasus enrichment `result` blob for a scene that brackets the
38
+ * given timestamp. Tolerates the two shapes we've seen in practice:
39
+ * - `{scenes: [{start, end, description}, ...]}` — the structured form
40
+ * - `{summary: "..."}` — flat summary fallback (no timestamp matching)
41
+ *
42
+ * Returns the matched scene description, or `undefined` if no match.
43
+ */
44
+ function findSceneContext(result, timestamp) {
45
+ if (!result)
46
+ return undefined;
47
+ // Shape A — `{scenes: [...]}`. Only useful if we have a timestamp to
48
+ // bracket against.
49
+ const scenesRaw = result.scenes;
50
+ if (Array.isArray(scenesRaw) && typeof timestamp === 'number') {
51
+ for (const sceneRaw of scenesRaw) {
52
+ if (!sceneRaw || typeof sceneRaw !== 'object')
53
+ continue;
54
+ const scene = sceneRaw;
55
+ const start = asNumber(scene.start);
56
+ const end = asNumber(scene.end);
57
+ const description = asString(scene.description);
58
+ if (description === undefined)
59
+ continue;
60
+ if (start === undefined || end === undefined)
61
+ continue;
62
+ if (timestamp >= start && timestamp <= end) {
63
+ return description;
64
+ }
65
+ }
66
+ }
67
+ // Shape B — flat `{summary: "..."}`. Used when we have no timestamp
68
+ // match (or no timestamp at all). The summary is a video-level
69
+ // description, so it's strictly worse than a per-scene match but
70
+ // still better than nothing.
71
+ const summary = asString(result.summary);
72
+ if (summary)
73
+ return summary;
74
+ return undefined;
75
+ }
76
+ /**
77
+ * Build an `EntityContext` from an `ImageRecord`, optional matching
78
+ * `EnrichmentRecord`, and optional `PersonaConfig`. Never throws —
79
+ * missing fields collapse to `undefined`.
80
+ */
81
+ export function aggregateEntityContext(input) {
82
+ const { imageRecord, enrichment } = input;
83
+ const name = labelFromImageRecord(imageRecord);
84
+ const sourceVideoId = imageRecord.source_video_id ?? undefined;
85
+ const sourceTimestamp = typeof imageRecord.source_timestamp === 'number'
86
+ ? imageRecord.source_timestamp
87
+ : undefined;
88
+ const sceneContext = findSceneContext(enrichment?.result, sourceTimestamp);
89
+ const out = { name };
90
+ if (sceneContext !== undefined)
91
+ out.sceneContext = sceneContext;
92
+ if (sourceVideoId !== undefined)
93
+ out.sourceVideoId = sourceVideoId;
94
+ if (sourceTimestamp !== undefined)
95
+ out.sourceTimestamp = sourceTimestamp;
96
+ return out;
97
+ }
98
+ /**
99
+ * Build a `PersonaContext` from a `PersonaConfig`. Pulls `name` and
100
+ * `custom_system_prompt`, truncating the backstory to
101
+ * `BACKSTORY_MAX_CHARS` (default 400) so prompt budgets stay sane.
102
+ * Returns `null` when no backstory is set — callers should treat that
103
+ * as "no persona context" rather than feeding an empty backstory to
104
+ * the upsampler.
105
+ */
106
+ export function aggregatePersonaContext(persona) {
107
+ const raw = persona.custom_system_prompt ?? '';
108
+ const trimmed = raw.trim();
109
+ if (!trimmed)
110
+ return null;
111
+ const backstory = trimmed.length > BACKSTORY_MAX_CHARS
112
+ ? trimmed.slice(0, BACKSTORY_MAX_CHARS).trimEnd() + '…'
113
+ : trimmed;
114
+ return {
115
+ name: persona.name,
116
+ backstory,
117
+ };
118
+ }
119
+ //# sourceMappingURL=entityContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityContext.js","sourceRoot":"","sources":["../../src/reactor/entityContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,sEAAsE;AACtE,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAmB;IAC/C,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC;QACxD,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrD,OAAO,IAAI,IAAI,gBAAgB,CAAC;AAClC,CAAC;AAQD,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,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Command`'s SWAP_SEED branch so the search
5
+ * can be reused by the Vue web-app and any other client-core consumer
6
+ * that needs "name a character, get its seed image."
7
+ *
8
+ * Search order: `extracted` first (the primary catalogue), then
9
+ * `character` (the highest-quality fallback for personas with rest-pose
10
+ * PNGs). Short-circuits on first match — most videos resolve from
11
+ * `extracted` alone, so the second `listImages` round-trip only fires
12
+ * when the entity isn't found there.
13
+ *
14
+ * Match policy: case-insensitive equality after trim on
15
+ * `source_entity`. The Helios steering addon hints "case sensitive" to
16
+ * the model, but that's a guidance hint rather than a hard contract; we
17
+ * accept whichever casing the model emits.
18
+ *
19
+ * Caching (per #119): the result lists from `listImages` are cached
20
+ * per `(videoId, category, limit)` tuple in an in-process map. The
21
+ * cache lives for the lifetime of the JS realm — a page reload clears
22
+ * it. Subsequent SWAP_SEED commands against the same video reuse the
23
+ * cached catalogue with zero round-trips. Pass `forceRefresh: true` to
24
+ * bust the cache for the current call (e.g. after a video re-ingest).
25
+ * The whole cache can also be cleared via `clearEntitySearchCache()`.
26
+ *
27
+ * Failure modes (per category):
28
+ * - `listImages` throws → log + continue to the next category. The
29
+ * failure is NOT cached, so a transient API blip won't poison the
30
+ * catalogue.
31
+ * - No match in any category → resolve with `undefined`. The empty
32
+ * result IS cached — a name the model invented once is likely to be
33
+ * invented again, and we don't want to re-query both categories.
34
+ */
35
+ import type { ApiClient } from '../api';
36
+ import type { ImageCategory, ImageRecord } from '../api';
37
+ /** Image categories searched in priority order when no override is passed. */
38
+ export declare const DEFAULT_SEED_SEARCH_CATEGORIES: readonly ImageCategory[];
39
+ export interface FindEntityImageOptions {
40
+ /** Override the default category search order. */
41
+ categories?: readonly ImageCategory[];
42
+ /** Per-category result cap forwarded to `listImages`. Default 50 —
43
+ * matches the original SWAP_SEED behaviour and is plenty for any
44
+ * realistic single-video entity count. */
45
+ limit?: number;
46
+ /** Skip the in-process cache for this call. Re-fetches both
47
+ * categories from the API and refreshes the cache entry. Use after
48
+ * a video re-ingest or when a user manually adds an entity. */
49
+ forceRefresh?: boolean;
50
+ }
51
+ /**
52
+ * Clear the entire entity-search cache.
53
+ *
54
+ * @internal — exported for test setup (`beforeEach`) only. Production
55
+ * callers should use `forceRefresh: true` on a specific
56
+ * `findEntityImageBySeedName` call to invalidate a single entry
57
+ * instead of nuking the whole cache. Marked `@internal` rather than
58
+ * removed because Jest's `resetModules()` is too heavy-handed for the
59
+ * test setup pattern (re-imports every module).
60
+ */
61
+ export declare function clearEntitySearchCache(): void;
62
+ /**
63
+ * Resolve an entity name to its `ImageRecord` in a given video.
64
+ *
65
+ * Returns `undefined` when the entity isn't found in any category;
66
+ * callers decide how to surface that (warning toast, fallback image,
67
+ * etc.). Returns `undefined` for empty / whitespace-only `entityName`
68
+ * without calling the API.
69
+ */
70
+ export declare function findEntityImageBySeedName(apiClient: ApiClient, videoId: string, entityName: string, options?: FindEntityImageOptions): Promise<ImageRecord | undefined>;
71
+ //# sourceMappingURL=entitySearch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitySearch.d.ts","sourceRoot":"","sources":["../../src/reactor/entitySearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEzD,8EAA8E;AAC9E,eAAO,MAAM,8BAA8B,EAAE,SAAS,aAAa,EAGlE,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,kDAAkD;IAClD,UAAU,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACtC;;+CAE2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;oEAEgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA8BlC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Look up an `ImageRecord` for a named entity in a given source video.
3
+ *
4
+ * Lifted from `dispatchHeliosCommand`'s SWAP_SEED branch so the search
5
+ * can be reused by the Vue web-app and any other client-core consumer
6
+ * that needs "name a character, get its seed image."
7
+ *
8
+ * Search order: `extracted` first (the primary catalogue), then
9
+ * `character` (the highest-quality fallback for personas with rest-pose
10
+ * PNGs). Short-circuits on first match — most videos resolve from
11
+ * `extracted` alone, so the second `listImages` round-trip only fires
12
+ * when the entity isn't found there.
13
+ *
14
+ * Match policy: case-insensitive equality after trim on
15
+ * `source_entity`. The Helios steering addon hints "case sensitive" to
16
+ * the model, but that's a guidance hint rather than a hard contract; we
17
+ * accept whichever casing the model emits.
18
+ *
19
+ * Caching (per #119): the result lists from `listImages` are cached
20
+ * per `(videoId, category, limit)` tuple in an in-process map. The
21
+ * cache lives for the lifetime of the JS realm — a page reload clears
22
+ * it. Subsequent SWAP_SEED commands against the same video reuse the
23
+ * cached catalogue with zero round-trips. Pass `forceRefresh: true` to
24
+ * bust the cache for the current call (e.g. after a video re-ingest).
25
+ * The whole cache can also be cleared via `clearEntitySearchCache()`.
26
+ *
27
+ * Failure modes (per category):
28
+ * - `listImages` throws → log + continue to the next category. The
29
+ * failure is NOT cached, so a transient API blip won't poison the
30
+ * catalogue.
31
+ * - No match in any category → resolve with `undefined`. The empty
32
+ * result IS cached — a name the model invented once is likely to be
33
+ * invented again, and we don't want to re-query both categories.
34
+ */
35
+ /** Image categories searched in priority order when no override is passed. */
36
+ export const DEFAULT_SEED_SEARCH_CATEGORIES = [
37
+ 'extracted',
38
+ 'character',
39
+ ];
40
+ const cache = new Map();
41
+ function makeKey(videoId, category, limit) {
42
+ return `${videoId}::${category}::${limit}`;
43
+ }
44
+ /**
45
+ * Clear the entire entity-search cache.
46
+ *
47
+ * @internal — exported for test setup (`beforeEach`) only. Production
48
+ * callers should use `forceRefresh: true` on a specific
49
+ * `findEntityImageBySeedName` call to invalidate a single entry
50
+ * instead of nuking the whole cache. Marked `@internal` rather than
51
+ * removed because Jest's `resetModules()` is too heavy-handed for the
52
+ * test setup pattern (re-imports every module).
53
+ */
54
+ export function clearEntitySearchCache() {
55
+ cache.clear();
56
+ }
57
+ /**
58
+ * Resolve an entity name to its `ImageRecord` in a given video.
59
+ *
60
+ * Returns `undefined` when the entity isn't found in any category;
61
+ * callers decide how to surface that (warning toast, fallback image,
62
+ * etc.). Returns `undefined` for empty / whitespace-only `entityName`
63
+ * without calling the API.
64
+ */
65
+ export async function findEntityImageBySeedName(apiClient, videoId, entityName, options = {}) {
66
+ const needle = entityName.trim().toLowerCase();
67
+ if (!needle)
68
+ return undefined;
69
+ const categories = options.categories ?? DEFAULT_SEED_SEARCH_CATEGORIES;
70
+ const limit = options.limit ?? 50;
71
+ const isMatch = (img) => (img.source_entity ?? '').trim().toLowerCase() === needle;
72
+ for (const category of categories) {
73
+ const key = makeKey(videoId, category, limit);
74
+ let images = !options.forceRefresh ? cache.get(key) : undefined;
75
+ if (!images) {
76
+ try {
77
+ const res = await apiClient.listImages({ videoId, category, limit });
78
+ images = res.images ?? [];
79
+ cache.set(key, images);
80
+ }
81
+ catch (err) {
82
+ console.warn(`[findEntityImageBySeedName] listImages(${category}) failed`, err);
83
+ // Don't cache the failure — let the next call retry.
84
+ continue;
85
+ }
86
+ }
87
+ const match = images.find(isMatch);
88
+ if (match)
89
+ return match;
90
+ }
91
+ return undefined;
92
+ }
93
+ //# sourceMappingURL=entitySearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitySearch.js","sourceRoot":"","sources":["../../src/reactor/entitySearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG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AAC,UAAU,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;gBACrE,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;gBAC1B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CACV,0CAA0C,QAAQ,UAAU,EAC5D,GAAG,CACJ,CAAC;gBACF,qDAAqD;gBACrD,SAAS;YACX,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Translate parsed Helios commands into `reactor.sendCommand` calls.
3
+ *
4
+ * Pure framework-agnostic helper: no React imports, no DOM globals
5
+ * beyond `Blob` / `File` (which Vue, Node 22+, and React all expose).
6
+ * Originally lived in `web/app/interactive/chat/heliosToolHandler.ts`
7
+ * for Phase 3; lifted to client-core so the Vue web-app and any other
8
+ * consumer can reuse the same dispatcher.
9
+ *
10
+ * Failure policy: every command is wrapped in a try/catch. A bad
11
+ * command (e.g. SWAP_SEED for an entity the user never showed) is
12
+ * logged and skipped — never propagates back to the chat loop. The
13
+ * chat session must keep working even if the world stream is
14
+ * unreachable or the entity catalogue doesn't match.
15
+ */
16
+ import type { ApiClient, ImageRecord } from '../api';
17
+ import type { HeliosCommand } from './heliosTools';
18
+ import type { EntityContext, PersonaContext } from './types';
19
+ /**
20
+ * Minimal Reactor surface the dispatcher needs. We accept a structural
21
+ * type rather than the JS-SDK's concrete `useReactorStore` shapes so
22
+ * this stays trivially mockable AND so client-core doesn't take a
23
+ * runtime dependency on `@reactor-team/js-sdk`.
24
+ *
25
+ * `uploadFile`'s return is typed as `unknown` here — the dispatcher
26
+ * never inspects it, only threads it back into `sendCommand('set_image',
27
+ * { image: ref })`. Callers using the real SDK assign their
28
+ * `Promise<FileRef>` to this slot via structural subtyping.
29
+ */
30
+ export interface HeliosReactorBridge {
31
+ sendCommand: (command: string, data: unknown) => Promise<void>;
32
+ uploadFile: (file: File | Blob, options?: {
33
+ name?: string;
34
+ }) => Promise<unknown>;
35
+ }
36
+ /**
37
+ * Inputs the dispatcher needs beyond the command itself: an
38
+ * authenticated API client (for SWAP_SEED entity lookups and seed-image
39
+ * bytes), the Reactor bridge (sendCommand / uploadFile), the active
40
+ * video so SWAP_SEED knows where to search, and the live `currentChunk`
41
+ * from the Reactor state so SET_SCENE schedules the prompt at chunk+2
42
+ * (the same convention `InteractiveController.tsx` uses).
43
+ */
44
+ export interface HeliosToolContext {
45
+ apiClient: ApiClient;
46
+ reactor: HeliosReactorBridge;
47
+ /** Currently selected source video — required for SWAP_SEED catalog
48
+ * lookups. SET_SCENE doesn't need it. */
49
+ videoId: string | null;
50
+ /** Live `current_chunk` from the Reactor state. Used to schedule
51
+ * SET_SCENE prompts at `currentChunk + 2`. Treated as 0 (= first
52
+ * prompt) when undefined. */
53
+ currentChunk?: number;
54
+ /** Whether the page has already issued a `start` command in this
55
+ * session. SET_SCENE at chunk 0 needs to know: if false, fire
56
+ * set_prompt + start (this is the first prompt); if true, fire
57
+ * set_prompt only (re-emitting start while running is undocumented
58
+ * Reactor behavior — defensive to skip it). Page clears this on
59
+ * RESET_WORLD. */
60
+ hasStarted?: boolean;
61
+ /** Optional context to thread into upsample requests for SET_SCENE. */
62
+ entityContext?: EntityContext;
63
+ personaContext?: PersonaContext;
64
+ /** Active seed image id — passed to upsample so it can ground the
65
+ * prompt on a thumbnail. Optional. */
66
+ imageId?: string;
67
+ /** Optional UI-feedback callback. The dispatcher calls this with a
68
+ * short human-readable message when a command fails in a way the
69
+ * user would benefit from seeing (e.g. SWAP_SEED entity not found).
70
+ * Silent (console-only) when omitted. */
71
+ onUserWarning?: (message: string) => void;
72
+ /** Optional callback fired after a successful SWAP_SEED so the page
73
+ * can keep its selection refs in sync with the live Helios stream.
74
+ * Without this, subsequent SET_SCENE upsample calls still ground
75
+ * on the OLD entity's context. */
76
+ onSeedSwapped?: (image: ImageRecord) => void;
77
+ /** Optional `AbortSignal` that cancels in-flight API requests when
78
+ * the caller no longer cares about the result (page unmount, new
79
+ * user message arriving mid-dispatch, etc.). Threaded into
80
+ * `upsampleReactorPrompt` (SET_SCENE) and `getSeedImageBlob`
81
+ * (SWAP_SEED). Reactor `sendCommand` / `uploadFile` are NOT aborted
82
+ * — the SDK has no signal surface today and rebuilding it would
83
+ * require an SDK wrapper. The pre-`sendCommand` portion is the
84
+ * expensive part anyway. */
85
+ signal?: AbortSignal;
86
+ }
87
+ /**
88
+ * Dispatch a single `HeliosCommand` to the live Reactor session.
89
+ * Resolves with no value on both success and failure — the caller
90
+ * just awaits the dispatch and continues to the next command.
91
+ *
92
+ * When `ctx.signal` is provided and gets aborted (before or during
93
+ * dispatch), the function returns silently without invoking any further
94
+ * `apiClient` / `sendCommand` calls. Callers don't need to inspect the
95
+ * return value to distinguish abort from completion.
96
+ */
97
+ export declare function dispatchHeliosCommand(cmd: HeliosCommand, ctx: HeliosToolContext): Promise<void>;
98
+ //# sourceMappingURL=heliosCommandDispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heliosCommandDispatcher.d.ts","sourceRoot":"","sources":["../../src/reactor/heliosCommandDispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAKnD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,UAAU,EAAE,CACV,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KACxB,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,mBAAmB,CAAC;IAC7B;8CAC0C;IAC1C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;kCAE8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;uBAKmB;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;2CACuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;8CAG0C;IAC1C,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C;;;uCAGmC;IACnC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7C;;;;;;;iCAO6B;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAmBD;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,iBAAiB,GACrB,OAAO,CAAC,IAAI,CAAC,CAyCf"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Translate parsed Helios commands into `reactor.sendCommand` calls.
3
+ *
4
+ * Pure framework-agnostic helper: no React imports, no DOM globals
5
+ * beyond `Blob` / `File` (which Vue, Node 22+, and React all expose).
6
+ * Originally lived in `web/app/interactive/chat/heliosToolHandler.ts`
7
+ * for Phase 3; lifted to client-core so the Vue web-app and any other
8
+ * consumer can reuse the same dispatcher.
9
+ *
10
+ * Failure policy: every command is wrapped in a try/catch. A bad
11
+ * command (e.g. SWAP_SEED for an entity the user never showed) is
12
+ * logged and skipped — never propagates back to the chat loop. The
13
+ * chat session must keep working even if the world stream is
14
+ * unreachable or the entity catalogue doesn't match.
15
+ */
16
+ import { findEntityImageBySeedName } from './entitySearch.js';
17
+ import { loadSeedImageFile, sendSeedFileToReactor, } from './seedImageOrchestrator.js';
18
+ /**
19
+ * Dispatch a single `HeliosCommand` to the live Reactor session.
20
+ * Resolves with no value on both success and failure — the caller
21
+ * just awaits the dispatch and continues to the next command.
22
+ */
23
+ /** True when `err` is an `AbortError` (or carries that name). Browsers
24
+ * emit `DOMException('AbortError')`; fetch + apiClient already pass
25
+ * this through unchanged. The `code === 'ABORT_ERR'` branch covers
26
+ * custom error classes some libraries use; the `name` check handles
27
+ * every browser DOMException + standard polyfill. */
28
+ function isAbortError(err) {
29
+ return (err instanceof Error &&
30
+ (err.name === 'AbortError' || err.code === 'ABORT_ERR'));
31
+ }
32
+ /**
33
+ * Dispatch a single `HeliosCommand` to the live Reactor session.
34
+ * Resolves with no value on both success and failure — the caller
35
+ * just awaits the dispatch and continues to the next command.
36
+ *
37
+ * When `ctx.signal` is provided and gets aborted (before or during
38
+ * dispatch), the function returns silently without invoking any further
39
+ * `apiClient` / `sendCommand` calls. Callers don't need to inspect the
40
+ * return value to distinguish abort from completion.
41
+ */
42
+ export async function dispatchHeliosCommand(cmd, ctx) {
43
+ if (ctx.signal?.aborted)
44
+ return;
45
+ try {
46
+ switch (cmd.type) {
47
+ case 'set_scene':
48
+ await handleSetScene(cmd.prompt, ctx);
49
+ return;
50
+ case 'swap_seed':
51
+ await handleSwapSeed(cmd.entityName, ctx);
52
+ return;
53
+ case 'pause_world':
54
+ await ctx.reactor.sendCommand('pause', {});
55
+ return;
56
+ case 'resume_world':
57
+ await ctx.reactor.sendCommand('resume', {});
58
+ return;
59
+ case 'reset_world':
60
+ await ctx.reactor.sendCommand('reset', {});
61
+ return;
62
+ default: {
63
+ // Exhaustiveness check — TS will complain at compile time if a
64
+ // new HeliosCommand variant is added without updating this
65
+ // switch. The runtime branch is unreachable but keeps the
66
+ // narrowing honest.
67
+ const _exhaustive = cmd;
68
+ console.warn('[heliosCommandDispatcher] unknown command type', _exhaustive);
69
+ return;
70
+ }
71
+ }
72
+ }
73
+ catch (err) {
74
+ // Abort is a clean signal — silent and stop here.
75
+ if (isAbortError(err))
76
+ return;
77
+ console.warn('[heliosCommandDispatcher] command failed; skipping', cmd, err);
78
+ }
79
+ }
80
+ /**
81
+ * SET_SCENE: knowledge-grounded upsample then a prompt change.
82
+ *
83
+ * Mirrors `InteractiveController.handleSubmit`:
84
+ * - chunk 0 (no frames rendered yet) → `set_prompt`
85
+ * - mid-stream → `schedule_prompt` at `currentChunk + 2`
86
+ *
87
+ * Upsample failure falls back to the raw model-emitted prompt rather
88
+ * than aborting — the model is already doing the Helios prompt-guide
89
+ * shaping; upsample just adds knowledge-graph grounding.
90
+ */
91
+ async function handleSetScene(modelPrompt, ctx) {
92
+ let prompt = modelPrompt;
93
+ try {
94
+ const res = await ctx.apiClient.upsampleReactorPrompt({
95
+ prompt: modelPrompt,
96
+ imageId: ctx.imageId,
97
+ entityContext: ctx.entityContext,
98
+ personaContext: ctx.personaContext,
99
+ }, { signal: ctx.signal });
100
+ if (res?.upsampledPrompt)
101
+ prompt = res.upsampledPrompt;
102
+ }
103
+ catch (err) {
104
+ // Non-fatal: the model's prompt is already 80-120 word Helios-quality
105
+ // per the addon prose, so falling back is safe. Abort is also routed
106
+ // through this branch — that's intentional, we want abort to skip the
107
+ // rest of the dispatch.
108
+ if (isAbortError(err)) {
109
+ // Silent on abort — the caller asked for cancellation.
110
+ throw err;
111
+ }
112
+ console.warn('[heliosCommandDispatcher] set_scene upsample failed; using raw prompt', err);
113
+ }
114
+ if (ctx.signal?.aborted)
115
+ return;
116
+ const chunk = ctx.currentChunk ?? 0;
117
+ if (chunk === 0) {
118
+ await ctx.reactor.sendCommand('set_prompt', { prompt });
119
+ // Only emit `start` when the page hasn't fired it yet — re-emitting
120
+ // start while the model is already running is undocumented Reactor
121
+ // behavior and could in theory restart the stream from frame 0.
122
+ // Defensive guard: when ctx.hasStarted is true, we just refresh the
123
+ // prompt without a fresh start.
124
+ if (!ctx.hasStarted) {
125
+ await ctx.reactor.sendCommand('start', {});
126
+ }
127
+ }
128
+ else {
129
+ await ctx.reactor.sendCommand('schedule_prompt', {
130
+ prompt,
131
+ chunk: chunk + 2,
132
+ });
133
+ }
134
+ }
135
+ /**
136
+ * SWAP_SEED: replace the active seed image with a different entity
137
+ * from the current video. Entity resolution is delegated to
138
+ * `findEntityImageBySeedName` (also in client-core) so the lookup
139
+ * logic is reusable on its own.
140
+ *
141
+ * If nothing matches: log a warning + invoke `onUserWarning` and exit.
142
+ * The chat keeps working; the user can ask the assistant for an exact
143
+ * entity name.
144
+ */
145
+ async function handleSwapSeed(entityName, ctx) {
146
+ if (!ctx.videoId) {
147
+ console.warn('[heliosCommandDispatcher] swap_seed requested but no video selected');
148
+ ctx.onUserWarning?.('Cannot swap seed — no video selected. Pick a video first.');
149
+ return;
150
+ }
151
+ const trimmed = entityName.trim();
152
+ if (!trimmed) {
153
+ console.warn('[heliosCommandDispatcher] swap_seed has empty entity name');
154
+ return;
155
+ }
156
+ const match = await findEntityImageBySeedName(ctx.apiClient, ctx.videoId, trimmed);
157
+ if (!match) {
158
+ console.warn(`[heliosCommandDispatcher] swap_seed: no entity matching "${entityName}" ` +
159
+ `in video ${ctx.videoId}`);
160
+ ctx.onUserWarning?.(`Couldn't find an entity named "${entityName}" in this video. ` +
161
+ 'Try the exact name from the entity picker.');
162
+ return;
163
+ }
164
+ // Use the shared orchestrator (#116) so PNG/JPEG extension handling
165
+ // and the upload→set_image sequence stay in one place. `swap-seed`
166
+ // stem distinguishes SWAP_SEED uploads from initial-seed uploads in
167
+ // server logs.
168
+ const file = await loadSeedImageFile(match.image_id, ctx.apiClient, {
169
+ signal: ctx.signal,
170
+ filenameStem: 'swap-seed',
171
+ });
172
+ if (ctx.signal?.aborted)
173
+ return;
174
+ await sendSeedFileToReactor(file, ctx.reactor, { transition: 'blend' });
175
+ // Tell the page so subsequent SET_SCENE upsample calls see the
176
+ // RIGHT entity's context. Without this, the Helios stream visually
177
+ // swaps but the model continues grounding prompts on the previous
178
+ // entity.
179
+ ctx.onSeedSwapped?.(match);
180
+ }
181
+ //# sourceMappingURL=heliosCommandDispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heliosCommandDispatcher.js","sourceRoot":"","sources":["../../src/reactor/heliosCommandDispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AA0EjC;;;;GAIG;AACH;;;;sDAIsD;AACtD,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,CACL,GAAG,YAAY,KAAK;QACpB,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY,IAAK,GAAiC,CAAC,IAAI,KAAK,WAAW,CAAC,CACvF,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,GAAkB,EAClB,GAAsB;IAEtB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO;IAChC,IAAI,CAAC;QACH,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,KAAK,WAAW;gBACd,MAAM,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACtC,OAAO;YACT,KAAK,WAAW;gBACd,MAAM,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;gBAC1C,OAAO;YACT,KAAK,aAAa;gBAChB,MAAM,GAAG,CAAC,OAAO,CAAC,WA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