@escapeaihq/client-core 0.7.0 → 0.12.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 (107) hide show
  1. package/README.md +22 -3
  2. package/dist/api.d.ts +114 -0
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/api.js +62 -47
  5. package/dist/api.js.map +1 -1
  6. package/dist/graphSchema.d.ts +72 -0
  7. package/dist/graphSchema.d.ts.map +1 -0
  8. package/dist/graphSchema.js +105 -0
  9. package/dist/graphSchema.js.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/reactor/abortUtils.d.ts +16 -0
  15. package/dist/reactor/abortUtils.d.ts.map +1 -0
  16. package/dist/reactor/abortUtils.js +26 -0
  17. package/dist/reactor/abortUtils.js.map +1 -0
  18. package/dist/reactor/applyScenePrompt.d.ts +75 -0
  19. package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
  20. package/dist/reactor/applyScenePrompt.js +60 -0
  21. package/dist/reactor/applyScenePrompt.js.map +1 -0
  22. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  23. package/dist/reactor/heliosCommandDispatcher.js +10 -15
  24. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  25. package/dist/reactor/index.d.ts +2 -0
  26. package/dist/reactor/index.d.ts.map +1 -1
  27. package/dist/reactor/index.js +2 -0
  28. package/dist/reactor/index.js.map +1 -1
  29. package/dist/reactor/sceneEntry.d.ts +40 -6
  30. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  31. package/dist/reactor/sceneEntry.js +63 -24
  32. package/dist/reactor/sceneEntry.js.map +1 -1
  33. package/dist/reactor/seedImageOrchestrator.d.ts +45 -2
  34. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  35. package/dist/reactor/seedImageOrchestrator.js +174 -4
  36. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  37. package/dist/timeFormat.d.ts +10 -0
  38. package/dist/timeFormat.d.ts.map +1 -1
  39. package/dist/timeFormat.js +12 -0
  40. package/dist/timeFormat.js.map +1 -1
  41. package/dist/toolSchemas.d.ts +370 -0
  42. package/dist/toolSchemas.d.ts.map +1 -0
  43. package/dist/toolSchemas.js +182 -0
  44. package/dist/toolSchemas.js.map +1 -0
  45. package/dist/vision/VisionPublisher.d.ts +115 -0
  46. package/dist/vision/VisionPublisher.d.ts.map +1 -0
  47. package/dist/vision/VisionPublisher.js +475 -0
  48. package/dist/vision/VisionPublisher.js.map +1 -0
  49. package/dist/vision/credentials.d.ts +22 -0
  50. package/dist/vision/credentials.d.ts.map +1 -0
  51. package/dist/vision/credentials.js +34 -0
  52. package/dist/vision/credentials.js.map +1 -0
  53. package/dist/vision/index.d.ts +14 -0
  54. package/dist/vision/index.d.ts.map +1 -0
  55. package/dist/vision/index.js +11 -0
  56. package/dist/vision/index.js.map +1 -0
  57. package/dist/vision/startVisionPublisher.d.ts +38 -0
  58. package/dist/vision/startVisionPublisher.d.ts.map +1 -0
  59. package/dist/vision/startVisionPublisher.js +44 -0
  60. package/dist/vision/startVisionPublisher.js.map +1 -0
  61. package/dist/vision/types.d.ts +95 -0
  62. package/dist/vision/types.d.ts.map +1 -0
  63. package/dist/vision/types.js +12 -0
  64. package/dist/vision/types.js.map +1 -0
  65. package/dist/vision/visionScheduler.d.ts +63 -0
  66. package/dist/vision/visionScheduler.d.ts.map +1 -0
  67. package/dist/vision/visionScheduler.js +67 -0
  68. package/dist/vision/visionScheduler.js.map +1 -0
  69. package/dist/websocket.d.ts +153 -0
  70. package/dist/websocket.d.ts.map +1 -1
  71. package/dist/websocket.js +199 -1
  72. package/dist/websocket.js.map +1 -1
  73. package/package.json +11 -1
  74. package/src/__tests__/api-pollers.test.ts +100 -0
  75. package/src/__tests__/chat-auth.test.ts +91 -0
  76. package/src/__tests__/graphSchema.test.ts +117 -0
  77. package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
  78. package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
  79. package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
  80. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
  81. package/src/__tests__/timeFormat.test.ts +22 -1
  82. package/src/__tests__/toolSchemas.test.ts +57 -0
  83. package/src/__tests__/websocket-vision.test.ts +265 -0
  84. package/src/__tests__/websocket.test.ts +75 -0
  85. package/src/api.ts +160 -47
  86. package/src/graphSchema.ts +149 -0
  87. package/src/index.ts +3 -0
  88. package/src/reactor/abortUtils.ts +22 -0
  89. package/src/reactor/applyScenePrompt.ts +136 -0
  90. package/src/reactor/heliosCommandDispatcher.ts +10 -18
  91. package/src/reactor/index.ts +2 -0
  92. package/src/reactor/sceneEntry.ts +104 -33
  93. package/src/reactor/seedImageOrchestrator.ts +201 -4
  94. package/src/timeFormat.ts +13 -0
  95. package/src/toolSchemas.ts +225 -0
  96. package/src/vision/VisionPublisher.ts +553 -0
  97. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
  98. package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
  99. package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
  100. package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
  101. package/src/vision/__tests__/visionScheduler.test.ts +149 -0
  102. package/src/vision/credentials.ts +39 -0
  103. package/src/vision/index.ts +31 -0
  104. package/src/vision/startVisionPublisher.ts +64 -0
  105. package/src/vision/types.ts +101 -0
  106. package/src/vision/visionScheduler.ts +102 -0
  107. package/src/websocket.ts +301 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reactor/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reactor/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
@@ -14,4 +14,6 @@ export * from './heliosCommandDispatcher.js';
14
14
  export * from './seedImageOrchestrator.js';
15
15
  export * from './promptAddonRegistry.js';
16
16
  export * from './sceneEntry.js';
17
+ export * from './applyScenePrompt.js';
18
+ export * from './abortUtils.js';
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reactor/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reactor/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
@@ -16,21 +16,38 @@
16
16
  */
17
17
  import type { ApiClient, EnrichmentRecord, PersonaConfig } from '../api';
18
18
  import { type SeedImageReactorBridge } from './seedImageOrchestrator';
19
+ import type { EntityContext, PersonaContext } from './types';
19
20
  export interface SceneEntryInput {
20
21
  /** The Seer video the user is watching. */
21
22
  videoId: string;
22
23
  /** Playhead position at the moment Step Into Scene was clicked. */
23
24
  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. */
25
+ /** Caption for the bracketing shot, if enrichment is loaded. Only
26
+ * used when `includeCaption: true` — the default image-first path
27
+ * ignores it because Helios already sees the seed frame via
28
+ * `set_image`. */
28
29
  shotCaption?: string | null;
30
+ /** When `true`, the upsampler runs with `shotCaption` (or a fallback)
31
+ * as the input prompt and the resulting Helios paragraph is sent as
32
+ * `set_prompt`. Defaults to `false`, in which case the upsample step
33
+ * is bypassed entirely and `IMAGE_FIRST_DIRECTIVE` is sent as
34
+ * `set_prompt` instead — instructing Helios to continue the seed
35
+ * image faithfully with only natural motion. Ignored when
36
+ * `customPrompt` is also provided. */
37
+ includeCaption?: boolean;
38
+ /** Operator-authored prompt that overrides BOTH the IMAGE_FIRST_DIRECTIVE
39
+ * default and the caption-upsample path. When provided, this string is
40
+ * sent verbatim as the initial `set_prompt`. Enables the watch-page
41
+ * prompt-editor surface where the user previews and tweaks the prompt
42
+ * before stepping into a scene. Trim externally — empty / whitespace-only
43
+ * strings fall back to the includeCaption-driven defaults. */
44
+ customPrompt?: string | null;
29
45
  /** Most-recent SUCCEEDED Pegasus enrichment for the video, used to
30
- * derive `sceneContext` inside the entity grounding. */
46
+ * derive `sceneContext` inside the entity grounding. Only consulted
47
+ * on the caption-driven path. */
31
48
  enrichment: EnrichmentRecord | null;
32
49
  /** Active persona on the watch page. `null` means "no persona
33
- * grounding" — the upsample runs with entity-only context. */
50
+ * grounding". Only consulted on the caption-driven path. */
34
51
  persona: PersonaConfig | null;
35
52
  apiClient: ApiClient;
36
53
  signal?: AbortSignal;
@@ -47,7 +64,24 @@ export interface SceneEntryPayload {
47
64
  * (or any consumer) deep-link to `/images/{imageId}` for inspection
48
65
  * or wire a "View in gallery" affordance. */
49
66
  imageId: string;
67
+ /** Aggregated entity grounding for the extracted frame. Surfaced so
68
+ * in-modal prompt resubmits (via `applyScenePrompt`) ground on the
69
+ * same scene context that the initial upsample used. */
70
+ entityContext: EntityContext;
71
+ /** Persona grounding, when the operator had a persona selected.
72
+ * `null` means "no persona". Mirrors `prepareSceneEntry`'s
73
+ * internal calculation so consumers don't recompute it. */
74
+ personaContext: PersonaContext | null;
50
75
  }
76
+ /** Default `set_prompt` for the image-first path. The seed frame is
77
+ * already loaded into Helios via `set_image`, so this prompt only
78
+ * needs to (a) tell the model to continue what it sees and (b)
79
+ * preserve the visual specifics. Written as a Helios-quality dense
80
+ * paragraph (~95 words) so we can send it directly without the
81
+ * upsampler round-trip. Follows the same prompt-guide rules
82
+ * encoded in `upsamplePrompt.ts::BASE_SYSTEM_RULES`: camera framing
83
+ * named explicitly, light by its effect, behavior over emotion. */
84
+ export declare const IMAGE_FIRST_DIRECTIVE: string;
51
85
  /**
52
86
  * Run the extract + upsample + frame-fetch pipeline. Resolves with a
53
87
  * `SceneEntryPayload` ready to feed into `bootstrapSceneInReactor`. The
@@ -1 +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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qB,QAUO,CAAC;AAQ1C;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,iBAAiB,CAAC,CA8E5B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,WAAW,CAAC;CACjB,GACL,OAAO,CAAC,IAAI,CAAC,CAqCf"}
@@ -14,12 +14,32 @@
14
14
  * state while the payload is being prepared, *before* the ReactorProvider
15
15
  * has connected — the bootstrap call then runs once the SDK reports ready.
16
16
  */
17
+ import { isAbortError } from './abortUtils.js';
17
18
  import { aggregateEntityContext, aggregatePersonaContext, } from './entityContext.js';
18
19
  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. */
20
+ /** Fallback shot caption when `includeCaption: true` is set but
21
+ * enrichment is absent or the playhead is outside any shot. Matches
22
+ * the cadence of the upsample's training prompts so the LLM doesn't
23
+ * reject a one-word input. */
22
24
  const FALLBACK_SHOT_CAPTION = 'Step into this moment';
25
+ /** Default `set_prompt` for the image-first path. The seed frame is
26
+ * already loaded into Helios via `set_image`, so this prompt only
27
+ * needs to (a) tell the model to continue what it sees and (b)
28
+ * preserve the visual specifics. Written as a Helios-quality dense
29
+ * paragraph (~95 words) so we can send it directly without the
30
+ * upsampler round-trip. Follows the same prompt-guide rules
31
+ * encoded in `upsamplePrompt.ts::BASE_SYSTEM_RULES`: camera framing
32
+ * named explicitly, light by its effect, behavior over emotion. */
33
+ export const IMAGE_FIRST_DIRECTIVE = 'Static medium shot, matching the seed image exactly. Preserve the ' +
34
+ 'subject\'s identity, position, posture, and wardrobe. Preserve the ' +
35
+ 'environment, depth, palette, and the way light falls across surfaces — ' +
36
+ 'the same shadows, the same highlights, the same atmospheric texture. ' +
37
+ 'Hold the original camera framing and lens character; the operator ' +
38
+ 'chose this exact moment. Apply only subtle natural motion: gentle ' +
39
+ 'breathing, slight weight shifts, ambient air moving fabric or hair, ' +
40
+ 'soft eye movement. No new actions, no new objects, no scene cuts, no ' +
41
+ 'introduced characters. Let the world settle into the frame the way it ' +
42
+ 'was captured and continue from there.';
23
43
  /** Sentinel entity name for the `ExtractImageRequest`. The backend
24
44
  * endpoint requires this field but uses `timestamp` for the actual
25
45
  * frame extraction when both are provided — `entity` survives only as
@@ -32,7 +52,8 @@ const SCENE_ENTITY_LABEL = 'scene';
32
52
  * so an unmount mid-pipeline cancels cleanly.
33
53
  */
34
54
  export async function prepareSceneEntry(input) {
35
- const { videoId, timestamp, shotCaption, enrichment, persona, apiClient, signal, } = input;
55
+ const { videoId, timestamp, shotCaption, includeCaption = false, customPrompt, enrichment, persona, apiClient, signal, } = input;
56
+ const customPromptTrimmed = customPrompt?.trim() || null;
36
57
  // Step 1 — extract the frame server-side. The endpoint uses ffmpeg
37
58
  // against the source video's presigned URL and persists an
38
59
  // ImageRecord that shows up in the user's gallery (free bookmark).
@@ -45,24 +66,32 @@ export async function prepareSceneEntry(input) {
45
66
  if (!extract.imageId) {
46
67
  throw new Error('extract-image did not return an imageId — the ImageRecord write failed and the frame is unreachable from the browser.');
47
68
  }
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.
69
+ // Step 2 — build entity/persona context (cheap, always run so the
70
+ // returned payload carries them for follow-up prompts via
71
+ // HeliosWorldControls).
54
72
  const entityContext = aggregateEntityContext({
55
73
  imageRecord: synthesizeImageRecord(videoId, extract),
56
74
  enrichment: enrichment ?? undefined,
57
75
  });
58
76
  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 }),
77
+ // Step 3 — fan out the frame-blob fetch alongside the prompt
78
+ // resolution. Three paths, in priority order:
79
+ // 1. customPrompt: operator-authored, sent verbatim. No upsample.
80
+ // 2. includeCaption: legacy caption-upsample (Bedrock round-trip).
81
+ // 3. default image-first: send IMAGE_FIRST_DIRECTIVE verbatim.
82
+ const promptPromise = customPromptTrimmed
83
+ ? Promise.resolve(customPromptTrimmed)
84
+ : includeCaption
85
+ ? apiClient
86
+ .upsampleReactorPrompt({
87
+ prompt: shotCaption?.trim() || FALLBACK_SHOT_CAPTION,
88
+ entityContext,
89
+ ...(personaContext ? { personaContext } : {}),
90
+ }, { signal })
91
+ .then(res => res.upsampledPrompt)
92
+ : Promise.resolve(IMAGE_FIRST_DIRECTIVE);
93
+ const [upsampledPrompt, frameFile] = await Promise.all([
94
+ promptPromise,
66
95
  loadSeedImageFile(extract.imageId, apiClient, {
67
96
  signal,
68
97
  filenameStem: 'scene',
@@ -70,9 +99,11 @@ export async function prepareSceneEntry(input) {
70
99
  ]);
71
100
  return {
72
101
  frameFile,
73
- upsampledPrompt: upsample.upsampledPrompt,
102
+ upsampledPrompt,
74
103
  sourceTimestamp: extract.sourceTimestamp,
75
104
  imageId: extract.imageId,
105
+ entityContext,
106
+ personaContext,
76
107
  };
77
108
  }
78
109
  /**
@@ -103,7 +134,20 @@ export async function bootstrapSceneInReactor(payload, bridge, options = {}) {
103
134
  try {
104
135
  if (options.signal?.aborted)
105
136
  return;
106
- await raceWithAbort(sendSeedFileToReactor(payload.frameFile, bridge, { transition: 'cut' }), options.signal);
137
+ // Match the docs sample exactly (file-uploads.md:33,
138
+ // image-to-video-player.md:94): uploadFile → set_image →
139
+ // set_prompt → start back-to-back, no wait between commands.
140
+ // Per `scripts/spikes/helios_set_image_spike.py`, Helios emits
141
+ // `image_accepted` AFTER `start` fires (during chunk 0), so any
142
+ // wait between set_image and start deadlocks. Chunk 0 is
143
+ // text-only briefly; chunks 1+ render with the seed.
144
+ // No transition on the first seed of a session — matches the
145
+ // working JS spike (helios_set_image_spike.html) verbatim. The
146
+ // docs (helios-overview.md) say first-call transition is a no-op,
147
+ // and empirically including `'cut'` here correlated with the
148
+ // image never taking effect in the React app even though the
149
+ // spike (no transition) reliably loads the seed.
150
+ await raceWithAbort(sendSeedFileToReactor(payload.frameFile, bridge, {}), options.signal);
107
151
  if (options.signal?.aborted)
108
152
  return;
109
153
  await raceWithAbort(bridge.sendCommand('set_prompt', { prompt: payload.upsampledPrompt }), options.signal);
@@ -117,11 +161,6 @@ export async function bootstrapSceneInReactor(payload, bridge, options = {}) {
117
161
  throw err;
118
162
  }
119
163
  }
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
164
  /**
126
165
  * Race a promise against an `AbortSignal`. When the signal fires, the
127
166
  * returned promise rejects with `AbortError` even if the underlying
@@ -1 +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,WA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AY,EAAE,WAAW;QACzB,eAAe,EAAE,OAAO;QACxB,aAAa,EAAE,OAAO,CAAC,MAAM;QAC7B,gBAAgB,EAAE,OAAO,CAAC,eAAe;QACzC,UAAU,EAAE,GAAG;QACf,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC"}
@@ -1,17 +1,36 @@
1
1
  /**
2
2
  * Pure async orchestration of the "selected image → Reactor seed" flow.
3
3
  *
4
+ * Wire shape: Helios's `set_image` command expects `{ image: <FileRef>,
5
+ * transition? }`. The FileRef comes from `reactor.uploadFile()`, which
6
+ * uploads the bytes via HTTP to Reactor's object store and returns a
7
+ * cheap reference. The command channel only carries the reference, so
8
+ * image size is decoupled from the 64KB-per-message data channel cap.
9
+ *
10
+ * Authoritative docs:
11
+ * - `ai_docs/reference/reactor/helios-overview.md:217` — set_image
12
+ * parameter table
13
+ * - `ai_docs/reference/reactor/file-uploads.md:33-54` — canonical
14
+ * uploadFile + set_image pattern
15
+ * - `ai_docs/reference/reactor/image-to-video-player.md:94` — full
16
+ * image-to-video example
17
+ *
18
+ * The shorter `ai_docs/reference/reactor/llms.txt:558` summary line
19
+ * lists `image_b64: string` for this command — that is misleading /
20
+ * out of date; the detailed reference pages above are authoritative.
21
+ *
4
22
  * Lifted from three React copies (#116):
5
23
  * - `web/app/interactive/InteractiveController.tsx` (Phase 1)
6
24
  * - `web/app/interactive/director/useSeedImageEffect.ts` (Phase 2)
7
25
  * - `web/app/interactive/chat/page.tsx` (Phase 3)
8
26
  *
9
- * The three copies were structurally identical:
27
+ * Flow:
10
28
  * load blob from `apiClient.getSeedImageBlob`
11
29
  * → wrap as `File` with extension derived from MIME (round 14 fix)
12
30
  * → `reactor.uploadFile(file)` → `FileRef`
13
31
  * → `reactor.sendCommand('set_image', { image: ref, transition })`
14
- * → optionally await `waitForImageReady()` (model echoes `conditions_ready`)
32
+ * → optionally await `waitForImageReady()` (model echoes `image_set`
33
+ * with width/height)
15
34
  *
16
35
  * The pending-file queue (selected image arrived before the session was
17
36
  * ready) lives in the React hook on top of this — it's UI-lifecycle
@@ -25,6 +44,13 @@ import type { ApiClient } from '../api';
25
44
  * Minimal Reactor surface needed by the orchestrator. Same shape used
26
45
  * by `HeliosReactorBridge` in `heliosCommandDispatcher.ts` — the
27
46
  * dispatcher and orchestrator share the bridge by structural typing.
47
+ *
48
+ * `uploadFile` must return a real `FileRef` instance (or a structural
49
+ * equivalent the SDK recognises). The SDK detects FileRef values in
50
+ * the `data` argument of `sendCommand` and lifts them into a separate
51
+ * `uploads` envelope section before transmitting — that's the only
52
+ * way image bytes reach Helios. Passing a plain object that looks
53
+ * like a FileRef but lacks the class identity will silently no-op.
28
54
  */
29
55
  export interface SeedImageReactorBridge {
30
56
  sendCommand: (command: string, data: unknown) => Promise<void>;
@@ -32,6 +58,23 @@ export interface SeedImageReactorBridge {
32
58
  name?: string;
33
59
  }) => Promise<unknown>;
34
60
  }
61
+ export interface DownscaleOptions {
62
+ /** Upper bound on the post-encode raw byte size. Default ~45 KB so
63
+ * the resulting base64 string fits within Reactor's 64 KB data
64
+ * channel message cap with envelope overhead to spare. */
65
+ maxRawBytes?: number;
66
+ /** Cap on the longer image dimension. Default 512 (covers 16:9
67
+ * 512×288 etc.). Helios's image encoder downsamples internally so
68
+ * going larger gains nothing for conditioning. */
69
+ maxDimension?: number;
70
+ }
71
+ export declare function downscaleImageForDataChannel(blob: Blob, options?: DownscaleOptions): Promise<Blob>;
72
+ /**
73
+ * Read a blob's bytes and base64-encode them. Uses FileReader (available
74
+ * in browsers AND jsdom) and strips the data-URL prefix so the output
75
+ * is the bare base64 payload, which is what Helios expects.
76
+ */
77
+ export declare function fileToBase64(file: Blob): Promise<string>;
35
78
  export interface ApplySeedImageOptions {
36
79
  /** `'cut'` (default) for the first seed in a session, `'blend'` for
37
80
  * subsequent swaps so the model smooths the visual transition.
@@ -1 +1 @@
1
- {"version":3,"file":"seedImageOrchestrator.d.ts","sourceRoot":"","sources":["../../src/reactor/seedImageOrchestrator.ts"],"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sB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,EACpB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5D,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,sBAAsB,EAC/B,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,cAAc,CAAM,GACnE,OAAO,CAAC,IAAI,CAAC,CA0Cf;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,sBAAsB,EAC/B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAUf"}
@@ -1,17 +1,36 @@
1
1
  /**
2
2
  * Pure async orchestration of the "selected image → Reactor seed" flow.
3
3
  *
4
+ * Wire shape: Helios's `set_image` command expects `{ image: <FileRef>,
5
+ * transition? }`. The FileRef comes from `reactor.uploadFile()`, which
6
+ * uploads the bytes via HTTP to Reactor's object store and returns a
7
+ * cheap reference. The command channel only carries the reference, so
8
+ * image size is decoupled from the 64KB-per-message data channel cap.
9
+ *
10
+ * Authoritative docs:
11
+ * - `ai_docs/reference/reactor/helios-overview.md:217` — set_image
12
+ * parameter table
13
+ * - `ai_docs/reference/reactor/file-uploads.md:33-54` — canonical
14
+ * uploadFile + set_image pattern
15
+ * - `ai_docs/reference/reactor/image-to-video-player.md:94` — full
16
+ * image-to-video example
17
+ *
18
+ * The shorter `ai_docs/reference/reactor/llms.txt:558` summary line
19
+ * lists `image_b64: string` for this command — that is misleading /
20
+ * out of date; the detailed reference pages above are authoritative.
21
+ *
4
22
  * Lifted from three React copies (#116):
5
23
  * - `web/app/interactive/InteractiveController.tsx` (Phase 1)
6
24
  * - `web/app/interactive/director/useSeedImageEffect.ts` (Phase 2)
7
25
  * - `web/app/interactive/chat/page.tsx` (Phase 3)
8
26
  *
9
- * The three copies were structurally identical:
27
+ * Flow:
10
28
  * load blob from `apiClient.getSeedImageBlob`
11
29
  * → wrap as `File` with extension derived from MIME (round 14 fix)
12
30
  * → `reactor.uploadFile(file)` → `FileRef`
13
31
  * → `reactor.sendCommand('set_image', { image: ref, transition })`
14
- * → optionally await `waitForImageReady()` (model echoes `conditions_ready`)
32
+ * → optionally await `waitForImageReady()` (model echoes `image_set`
33
+ * with width/height)
15
34
  *
16
35
  * The pending-file queue (selected image arrived before the session was
17
36
  * ready) lives in the React hook on top of this — it's UI-lifecycle
@@ -20,6 +39,119 @@
20
39
  * Framework-free so the Vue web-app can drop the same orchestrator
21
40
  * behind a composable.
22
41
  */
42
+ /**
43
+ * Reactor's WebRTC data channel rejects messages over 65,536 bytes
44
+ * (the SDK enforces this client-side before send). A 1080p PNG from
45
+ * the extract-image endpoint is ~1.27 MB raw → ~1.69 MB base64 → the
46
+ * whole `set_image` envelope blows past the limit and the SDK throws
47
+ * "Data channel message too large". We have to keep the base64
48
+ * payload below ~64 KB, which means raw bytes ≤ ~48 KB.
49
+ *
50
+ * Strategy: load the blob into an HTMLImageElement, draw to canvas
51
+ * at a clamped dimension, encode as JPEG with a quality ramp until
52
+ * the result fits the budget. We don't lose meaningful conditioning
53
+ * fidelity — Helios's image encoder downsamples internally to a
54
+ * fixed latent resolution regardless of input size.
55
+ *
56
+ * Falls back to the original blob in environments without a canvas
57
+ * backend (jsdom in tests). Browser callers always exercise the
58
+ * downscale path.
59
+ */
60
+ const DEFAULT_MAX_RAW_BYTES = 45 * 1024;
61
+ const DEFAULT_MAX_DIMENSION = 512;
62
+ export async function downscaleImageForDataChannel(blob, options = {}) {
63
+ const maxRawBytes = options.maxRawBytes ?? DEFAULT_MAX_RAW_BYTES;
64
+ const maxDimension = options.maxDimension ?? DEFAULT_MAX_DIMENSION;
65
+ // Already small enough — short-circuit. (The "already small" fast
66
+ // path also lets character-image thumbnails through unchanged.)
67
+ if (blob.size <= maxRawBytes)
68
+ return blob;
69
+ // jsdom / SSR — no canvas backend available. Pass through so unit
70
+ // tests don't have to mock canvas; browser code never hits this.
71
+ if (typeof document === 'undefined')
72
+ return blob;
73
+ const canvas = document.createElement('canvas');
74
+ const ctx = canvas.getContext('2d');
75
+ if (!ctx)
76
+ return blob;
77
+ let img;
78
+ try {
79
+ img = await loadBlobAsImage(blob);
80
+ }
81
+ catch {
82
+ // Image decode failed — return the original. The downstream
83
+ // sendCommand will surface the data-channel-too-large error
84
+ // instead of a misleading decode error.
85
+ return blob;
86
+ }
87
+ const width = img.naturalWidth || img.width;
88
+ const height = img.naturalHeight || img.height;
89
+ if (!width || !height)
90
+ return blob;
91
+ const scale = Math.min(1, maxDimension / Math.max(width, height));
92
+ const w = Math.max(1, Math.round(width * scale));
93
+ const h = Math.max(1, Math.round(height * scale));
94
+ canvas.width = w;
95
+ canvas.height = h;
96
+ ctx.drawImage(img, 0, 0, w, h);
97
+ for (const quality of [0.85, 0.75, 0.65, 0.55, 0.45, 0.35]) {
98
+ const encoded = await canvasToBlob(canvas, 'image/jpeg', quality);
99
+ if (!encoded)
100
+ continue;
101
+ if (encoded.size <= maxRawBytes)
102
+ return encoded;
103
+ }
104
+ // Last-ditch: take whatever the lowest quality yields. Even if it
105
+ // exceeds the budget, the SDK will surface the same data-channel
106
+ // error and the operator can pick a smaller frame.
107
+ const lastResort = await canvasToBlob(canvas, 'image/jpeg', 0.3);
108
+ return lastResort ?? blob;
109
+ }
110
+ function loadBlobAsImage(blob) {
111
+ return new Promise((resolve, reject) => {
112
+ const url = URL.createObjectURL(blob);
113
+ const img = new Image();
114
+ img.onload = () => {
115
+ URL.revokeObjectURL(url);
116
+ resolve(img);
117
+ };
118
+ img.onerror = () => {
119
+ URL.revokeObjectURL(url);
120
+ reject(new Error('image decode failed'));
121
+ };
122
+ img.src = url;
123
+ });
124
+ }
125
+ function canvasToBlob(canvas, type, quality) {
126
+ return new Promise(resolve => {
127
+ canvas.toBlob(b => resolve(b), type, quality);
128
+ });
129
+ }
130
+ /**
131
+ * Read a blob's bytes and base64-encode them. Uses FileReader (available
132
+ * in browsers AND jsdom) and strips the data-URL prefix so the output
133
+ * is the bare base64 payload, which is what Helios expects.
134
+ */
135
+ export async function fileToBase64(file) {
136
+ return await new Promise((resolve, reject) => {
137
+ const reader = new FileReader();
138
+ reader.onload = () => {
139
+ const result = reader.result;
140
+ if (typeof result !== 'string') {
141
+ reject(new Error('FileReader yielded non-string result'));
142
+ return;
143
+ }
144
+ const commaIdx = result.indexOf(',');
145
+ if (commaIdx === -1 || !result.startsWith('data:')) {
146
+ reject(new Error('Unexpected FileReader data-URL shape'));
147
+ return;
148
+ }
149
+ resolve(result.slice(commaIdx + 1));
150
+ };
151
+ reader.onerror = () => reject(reader.error ?? new Error('FileReader error'));
152
+ reader.readAsDataURL(file);
153
+ });
154
+ }
23
155
  /** Derive a filename extension from a blob MIME type. PNG character
24
156
  * images shouldn't masquerade as JPEG (round 14 fix). Falls back to
25
157
  * `jpg` for unknown / missing MIME. Normalises `jpeg → jpg` because
@@ -52,9 +184,47 @@ export async function loadSeedImageFile(imageId, apiClient, options = {}) {
52
184
  * a file ahead of the `ready` transition and flush it later.
53
185
  */
54
186
  export async function sendSeedFileToReactor(file, reactor, options = {}) {
55
- const transition = options.transition ?? 'cut';
187
+ // Canonical Helios image-to-video pattern (file-uploads.md:33,
188
+ // image-to-video-player.md:94): uploadFile → FileRef → set_image
189
+ // with `{ image: ref, transition? }`. Bytes go via HTTP to Reactor's
190
+ // object store; the command channel carries only the ref.
191
+ //
192
+ // **Transition is opt-in.** The JS spike that reliably reproduced
193
+ // image-to-video (`scripts/spikes/helios_set_image_spike.html`) sends
194
+ // `{ image: ref }` with NO `transition` field, matching the docs
195
+ // imperative sample verbatim. We default to omitting it; the
196
+ // InteractiveController seed-swap path passes `'blend'` explicitly
197
+ // when swapping mid-stream.
198
+ //
199
+ // **Do not wait for an ack here.** The standalone Python spike
200
+ // (`scripts/spikes/helios_set_image_spike.py`) confirmed that the
201
+ // success event is `image_accepted` (NOT `image_set` as
202
+ // helios-overview.md:441 claims — those docs are wrong) and it
203
+ // only fires AFTER `start` is issued, during chunk 0 generation.
204
+ // Any wait between set_image and the subsequent set_prompt+start
205
+ // therefore deadlocks for `waitForImageReady`-timeout milliseconds
206
+ // and produces no value. Match the docs sample's back-to-back
207
+ // sequence.
208
+ //
209
+ // `waitForImageReady` is kept on the options surface for back-compat
210
+ // with InteractiveController's pending-seed flush (which DOES want
211
+ // to know when the seed has landed before letting the operator
212
+ // submit a prompt). Callers like bootstrapSceneInReactor that
213
+ // chain `start` right after should NOT pass it.
214
+ const uploadStart = Date.now();
56
215
  const ref = await reactor.uploadFile(file);
57
- await reactor.sendCommand('set_image', { image: ref, transition });
216
+ console.info('[seedImage] uploaded', {
217
+ bytes: file.size,
218
+ mime: file.type,
219
+ ref,
220
+ elapsedMs: Date.now() - uploadStart,
221
+ });
222
+ const setImageData = {
223
+ image: ref,
224
+ };
225
+ if (options.transition)
226
+ setImageData.transition = options.transition;
227
+ await reactor.sendCommand('set_image', setImageData);
58
228
  if (options.waitForImageReady)
59
229
  await options.waitForImageReady();
60
230
  }
@@ -1 +1 @@
1
- {"version":3,"file":"seedImageOrchestrator.js","sourceRoot":"","sources":["../../src/reactor/seedImageOrchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAyCH;;;;;cAKc;AACd,SAAS,gBAAgB,CAAC,IAAwB;IAChD,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;IAC5C,OAAO,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,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AAI,OAAO,CAAC,UAAU;QAAE,YAAY,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACrE,MAAM,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACrD,IAAI,OAAO,CAAC,iBAAiB;QAAE,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAe,EACf,SAAoB,EACpB,OAA+B,EAC/B,UAAiC,EAAE;IAEnC,MAAM,IAAI,GAAG,MAAM,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE;QACvD,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC,CAAC;IACH,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO;IACpC,MAAM,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE;QACzC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;KAC7C,CAAC,CAAC;AACL,CAAC"}
@@ -25,4 +25,14 @@ export declare function formatTimestamp(seconds: number | null | undefined, opti
25
25
  centiseconds?: boolean;
26
26
  fallback?: string;
27
27
  }): string;
28
+ /**
29
+ * Preset of {@link formatTimestamp} with `centiseconds: true` — the format
30
+ * used for citation timestamps in chat surfaces where sub-second word/turn
31
+ * boundaries are load-bearing.
32
+ *
33
+ * @example
34
+ * formatCitationTimestamp(83.45) // "1:23.45"
35
+ * formatCitationTimestamp(0) // "0:00.00"
36
+ */
37
+ export declare function formatCitationTimestamp(seconds: number): string;
28
38
  //# sourceMappingURL=timeFormat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeFormat.d.ts","sourceRoot":"","sources":["../src/timeFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1D,MAAM,CA8BR"}
1
+ {"version":3,"file":"timeFormat.d.ts","sourceRoot":"","sources":["../src/timeFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1D,MAAM,CA8BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D"}
@@ -45,4 +45,16 @@ export function formatTimestamp(seconds, options = {}) {
45
45
  }
46
46
  return base;
47
47
  }
48
+ /**
49
+ * Preset of {@link formatTimestamp} with `centiseconds: true` — the format
50
+ * used for citation timestamps in chat surfaces where sub-second word/turn
51
+ * boundaries are load-bearing.
52
+ *
53
+ * @example
54
+ * formatCitationTimestamp(83.45) // "1:23.45"
55
+ * formatCitationTimestamp(0) // "0:00.00"
56
+ */
57
+ export function formatCitationTimestamp(seconds) {
58
+ return formatTimestamp(seconds, { centiseconds: true });
59
+ }
48
60
  //# sourceMappingURL=timeFormat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeFormat.js","sourceRoot":"","sources":["../src/timeFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAkC,EAClC,UAAyD,EAAE;IAE3D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC;IAC5C,IACE,OAAO,KAAK,IAAI;QAChB,OAAO,KAAK,SAAS;QACrB,CAAC,MA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