@escapeaihq/client-core 0.8.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 (106) 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 +122 -0
  70. package/dist/websocket.d.ts.map +1 -1
  71. package/dist/websocket.js +179 -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/api.ts +160 -47
  85. package/src/graphSchema.ts +149 -0
  86. package/src/index.ts +3 -0
  87. package/src/reactor/abortUtils.ts +22 -0
  88. package/src/reactor/applyScenePrompt.ts +136 -0
  89. package/src/reactor/heliosCommandDispatcher.ts +10 -18
  90. package/src/reactor/index.ts +2 -0
  91. package/src/reactor/sceneEntry.ts +104 -33
  92. package/src/reactor/seedImageOrchestrator.ts +201 -4
  93. package/src/timeFormat.ts +13 -0
  94. package/src/toolSchemas.ts +225 -0
  95. package/src/vision/VisionPublisher.ts +553 -0
  96. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
  97. package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
  98. package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
  99. package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
  100. package/src/vision/__tests__/visionScheduler.test.ts +149 -0
  101. package/src/vision/credentials.ts +39 -0
  102. package/src/vision/index.ts +31 -0
  103. package/src/vision/startVisionPublisher.ts +64 -0
  104. package/src/vision/types.ts +101 -0
  105. package/src/vision/visionScheduler.ts +102 -0
  106. package/src/websocket.ts +259 -1
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Tests for `applyScenePrompt` — the shared chunk-0-vs-running policy
3
+ * used by `dispatchHeliosCommand.handleSetScene` (chat tools) and the
4
+ * `HeliosWorldControls` React component (operator-driven submit).
5
+ *
6
+ * Coverage:
7
+ * - First prompt (isRunning=false): set_prompt + start, returns
8
+ * scheduledAtChunk=null.
9
+ * - Mid-stream prompt (isRunning=true): schedule_prompt at
10
+ * currentChunk + 2, returns scheduledAtChunk=currentChunk+2.
11
+ * - Upsample failure: falls back to the raw prompt, completes the
12
+ * dispatch.
13
+ * - Abort before sendCommand: throws AbortError, no commands fire.
14
+ * - Upsample abort: re-thrown (not silenced like the warn path).
15
+ */
16
+
17
+ import type { ApiClient } from '../../api';
18
+ import { applyScenePrompt } from '../../reactor/applyScenePrompt';
19
+
20
+ type AnyMock = jest.Mock;
21
+
22
+ function makeReactor() {
23
+ return {
24
+ sendCommand: jest.fn().mockResolvedValue(undefined) as AnyMock,
25
+ uploadFile: jest.fn().mockResolvedValue({}) as AnyMock,
26
+ };
27
+ }
28
+
29
+ function makeApiClient(overrides: Partial<Record<string, AnyMock>> = {}) {
30
+ return {
31
+ upsampleReactorPrompt: jest.fn().mockResolvedValue({
32
+ traceId: 't',
33
+ upsampledPrompt: 'UPSAMPLED',
34
+ }),
35
+ ...overrides,
36
+ } as unknown as ApiClient & Record<string, AnyMock>;
37
+ }
38
+
39
+ describe('applyScenePrompt', () => {
40
+ it('first prompt path: set_prompt + start, scheduledAtChunk=null', async () => {
41
+ const reactor = makeReactor();
42
+ const apiClient = makeApiClient();
43
+ const result = await applyScenePrompt({
44
+ prompt: 'wide shot of a city at dusk',
45
+ apiClient,
46
+ reactor,
47
+ currentChunk: 0,
48
+ isRunning: false,
49
+ });
50
+ expect(result.appliedPrompt).toBe('UPSAMPLED');
51
+ expect(result.scheduledAtChunk).toBeNull();
52
+ const calls = reactor.sendCommand.mock.calls;
53
+ expect(calls[0]).toEqual(['set_prompt', { prompt: 'UPSAMPLED' }]);
54
+ expect(calls[1]).toEqual(['start', {}]);
55
+ });
56
+
57
+ it('mid-stream path: schedule_prompt at currentChunk + 2', async () => {
58
+ const reactor = makeReactor();
59
+ const apiClient = makeApiClient();
60
+ const result = await applyScenePrompt({
61
+ prompt: 'rain on the pavement',
62
+ apiClient,
63
+ reactor,
64
+ currentChunk: 7,
65
+ isRunning: true,
66
+ });
67
+ expect(result.scheduledAtChunk).toBe(9);
68
+ expect(reactor.sendCommand).toHaveBeenCalledTimes(1);
69
+ expect(reactor.sendCommand).toHaveBeenCalledWith('schedule_prompt', {
70
+ prompt: 'UPSAMPLED',
71
+ chunk: 9,
72
+ });
73
+ });
74
+
75
+ it('shouldUpsample=false: skips the upsample call and sends prompt verbatim', async () => {
76
+ const reactor = makeReactor();
77
+ const apiClient = makeApiClient();
78
+ const result = await applyScenePrompt({
79
+ prompt: 'operator-authored verbatim text',
80
+ apiClient,
81
+ reactor,
82
+ currentChunk: 5,
83
+ isRunning: true,
84
+ shouldUpsample: false,
85
+ });
86
+ expect(result.appliedPrompt).toBe('operator-authored verbatim text');
87
+ expect(result.scheduledAtChunk).toBe(7);
88
+ expect(
89
+ (apiClient as unknown as Record<string, AnyMock>).upsampleReactorPrompt,
90
+ ).not.toHaveBeenCalled();
91
+ expect(reactor.sendCommand).toHaveBeenCalledWith('schedule_prompt', {
92
+ prompt: 'operator-authored verbatim text',
93
+ chunk: 7,
94
+ });
95
+ });
96
+
97
+ it('falls back to the raw prompt when upsample throws (non-abort)', async () => {
98
+ const reactor = makeReactor();
99
+ const upsampleErr = new Error('LLM down');
100
+ const apiClient = makeApiClient({
101
+ upsampleReactorPrompt: jest.fn().mockRejectedValue(upsampleErr),
102
+ });
103
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
104
+ const result = await applyScenePrompt({
105
+ prompt: 'raw prompt text',
106
+ apiClient,
107
+ reactor,
108
+ currentChunk: 0,
109
+ isRunning: false,
110
+ });
111
+ expect(result.appliedPrompt).toBe('raw prompt text');
112
+ expect(reactor.sendCommand.mock.calls[0]).toEqual([
113
+ 'set_prompt',
114
+ { prompt: 'raw prompt text' },
115
+ ]);
116
+ // The feature doc treats this warn as a diagnostic contract —
117
+ // operators tail console to confirm the fallback fired rather
118
+ // than the prompt landing un-grounded by mistake. Lock it down.
119
+ expect(warnSpy).toHaveBeenCalledWith(
120
+ expect.stringContaining('[applyScenePrompt] upsample failed'),
121
+ upsampleErr,
122
+ );
123
+ warnSpy.mockRestore();
124
+ });
125
+
126
+ it('throws AbortError when the signal is aborted before sendCommand', async () => {
127
+ const reactor = makeReactor();
128
+ const apiClient = makeApiClient({
129
+ // Abort during the upsample so the post-upsample guard fires.
130
+ upsampleReactorPrompt: jest.fn().mockImplementation(async () => {
131
+ controller.abort();
132
+ return { traceId: 't', upsampledPrompt: 'UPSAMPLED' };
133
+ }),
134
+ });
135
+ const controller = new AbortController();
136
+ await expect(
137
+ applyScenePrompt({
138
+ prompt: 'p',
139
+ apiClient,
140
+ reactor,
141
+ currentChunk: 0,
142
+ isRunning: false,
143
+ signal: controller.signal,
144
+ }),
145
+ ).rejects.toMatchObject({ name: 'AbortError' });
146
+ expect(reactor.sendCommand).not.toHaveBeenCalled();
147
+ });
148
+
149
+ it('re-throws AbortError from upsample without swallowing', async () => {
150
+ const reactor = makeReactor();
151
+ const abortErr = Object.assign(new Error('aborted'), { name: 'AbortError' });
152
+ const apiClient = makeApiClient({
153
+ upsampleReactorPrompt: jest.fn().mockRejectedValue(abortErr),
154
+ });
155
+ await expect(
156
+ applyScenePrompt({
157
+ prompt: 'p',
158
+ apiClient,
159
+ reactor,
160
+ currentChunk: 0,
161
+ isRunning: false,
162
+ }),
163
+ ).rejects.toMatchObject({ name: 'AbortError' });
164
+ expect(reactor.sendCommand).not.toHaveBeenCalled();
165
+ });
166
+
167
+ it('plumbs entity/persona/imageId/previousPrompt into the upsample', async () => {
168
+ const reactor = makeReactor();
169
+ const apiClient = makeApiClient();
170
+ await applyScenePrompt({
171
+ prompt: 'p',
172
+ apiClient,
173
+ reactor,
174
+ currentChunk: 5,
175
+ isRunning: true,
176
+ imageId: 'img-1',
177
+ entityContext: { name: 'Leo' },
178
+ personaContext: { name: 'Director', backstory: 'b' },
179
+ previousPrompt: 'earlier prompt',
180
+ });
181
+ expect(apiClient.upsampleReactorPrompt).toHaveBeenCalledWith(
182
+ {
183
+ prompt: 'p',
184
+ previousPrompt: 'earlier prompt',
185
+ imageId: 'img-1',
186
+ entityContext: { name: 'Leo' },
187
+ personaContext: { name: 'Director', backstory: 'b' },
188
+ },
189
+ { signal: undefined },
190
+ );
191
+ });
192
+ });
@@ -203,9 +203,10 @@ describe('dispatchHeliosCommand', () => {
203
203
  const setImage = reactor.sendCommand.mock.calls.find(
204
204
  c => c[0] === 'set_image',
205
205
  );
206
- expect(setImage?.[1]).toEqual(
207
- expect.objectContaining({ transition: 'blend' }),
208
- );
206
+ expect(setImage?.[1]).toEqual({
207
+ image: expect.objectContaining({ uploadId: 'u1' }),
208
+ transition: 'blend',
209
+ });
209
210
  expect(onSeedSwapped).toHaveBeenCalledTimes(1);
210
211
  expect(onSeedSwapped).toHaveBeenCalledWith(leo);
211
212
  });
@@ -4,8 +4,13 @@
4
4
  *
5
5
  * Coverage:
6
6
  * - prepareSceneEntry calls extractImage with timestamp + sentinel entity
7
- * - prepareSceneEntry feeds the upsampler the shot caption as the prompt
8
- * - prepareSceneEntry falls back to the generic caption when none is given
7
+ * - prepareSceneEntry by default skips the upsampler and uses
8
+ * `IMAGE_FIRST_DIRECTIVE` as the prompt (the seed image is
9
+ * authoritative)
10
+ * - prepareSceneEntry with `includeCaption: true` feeds the caption to
11
+ * the upsampler and uses its output as the prompt
12
+ * - prepareSceneEntry with `includeCaption: true` falls back to the
13
+ * generic caption when none is given
9
14
  * - prepareSceneEntry fetches the frame via getSeedImageBlob (proxy)
10
15
  * rather than a direct presigned S3 fetch (browser CORS)
11
16
  * - prepareSceneEntry omits personaContext when persona is null
@@ -20,6 +25,7 @@
20
25
  import type { ApiClient, ExtractImageResponse, PersonaConfig } from '../../api';
21
26
  import {
22
27
  bootstrapSceneInReactor,
28
+ IMAGE_FIRST_DIRECTIVE,
23
29
  prepareSceneEntry,
24
30
  } from '../../reactor/sceneEntry';
25
31
 
@@ -97,12 +103,30 @@ describe('prepareSceneEntry', () => {
97
103
  });
98
104
  });
99
105
 
100
- it('feeds the upsampler the shot caption as the prompt', async () => {
106
+ it('image-first by default: skips the upsampler and uses IMAGE_FIRST_DIRECTIVE', async () => {
107
+ const apiClient = makeApiClient();
108
+ const payload = await prepareSceneEntry({
109
+ videoId: 'vid-1',
110
+ timestamp: 10,
111
+ shotCaption: 'A specific caption.',
112
+ enrichment: null,
113
+ persona: null,
114
+ apiClient,
115
+ });
116
+ // Upsample was bypassed entirely.
117
+ expect(
118
+ (apiClient as unknown as Record<string, AnyMock>).upsampleReactorPrompt,
119
+ ).not.toHaveBeenCalled();
120
+ expect(payload.upsampledPrompt).toBe(IMAGE_FIRST_DIRECTIVE);
121
+ });
122
+
123
+ it('caption mode: feeds the upsampler the shot caption when includeCaption=true', async () => {
101
124
  const apiClient = makeApiClient();
102
125
  await prepareSceneEntry({
103
126
  videoId: 'vid-1',
104
127
  timestamp: 10,
105
128
  shotCaption: 'A specific caption.',
129
+ includeCaption: true,
106
130
  enrichment: null,
107
131
  persona: null,
108
132
  apiClient,
@@ -112,12 +136,63 @@ describe('prepareSceneEntry', () => {
112
136
  expect(call?.[0].prompt).toBe('A specific caption.');
113
137
  });
114
138
 
115
- it('falls back to the generic caption when none is given', async () => {
139
+ it('customPrompt takes priority: bypasses both IMAGE_FIRST_DIRECTIVE and the upsampler', async () => {
140
+ const apiClient = makeApiClient();
141
+ const payload = await prepareSceneEntry({
142
+ videoId: 'vid-1',
143
+ timestamp: 10,
144
+ shotCaption: 'A specific caption.',
145
+ // Even with includeCaption=true, customPrompt wins.
146
+ includeCaption: true,
147
+ customPrompt: 'Operator-written prompt verbatim.',
148
+ enrichment: null,
149
+ persona: null,
150
+ apiClient,
151
+ });
152
+ expect(payload.upsampledPrompt).toBe('Operator-written prompt verbatim.');
153
+ expect(
154
+ (apiClient as unknown as Record<string, AnyMock>).upsampleReactorPrompt,
155
+ ).not.toHaveBeenCalled();
156
+ });
157
+
158
+ it('customPrompt: whitespace-only string falls back to default path', async () => {
159
+ const apiClient = makeApiClient();
160
+ const payload = await prepareSceneEntry({
161
+ videoId: 'vid-1',
162
+ timestamp: 10,
163
+ shotCaption: null,
164
+ customPrompt: ' \n\t ',
165
+ enrichment: null,
166
+ persona: null,
167
+ apiClient,
168
+ });
169
+ // Empty after trim → image-first default kicks in.
170
+ expect(payload.upsampledPrompt).toBe(IMAGE_FIRST_DIRECTIVE);
171
+ });
172
+
173
+ it('customPrompt: trimmed before use', async () => {
174
+ const apiClient = makeApiClient();
175
+ const payload = await prepareSceneEntry({
176
+ videoId: 'vid-1',
177
+ timestamp: 10,
178
+ shotCaption: null,
179
+ customPrompt: ' leading and trailing whitespace stripped ',
180
+ enrichment: null,
181
+ persona: null,
182
+ apiClient,
183
+ });
184
+ expect(payload.upsampledPrompt).toBe(
185
+ 'leading and trailing whitespace stripped',
186
+ );
187
+ });
188
+
189
+ it('caption mode: falls back to the generic caption when none is given', async () => {
116
190
  const apiClient = makeApiClient();
117
191
  await prepareSceneEntry({
118
192
  videoId: 'vid-1',
119
193
  timestamp: 10,
120
194
  shotCaption: null,
195
+ includeCaption: true,
121
196
  enrichment: null,
122
197
  persona: null,
123
198
  apiClient,
@@ -127,12 +202,13 @@ describe('prepareSceneEntry', () => {
127
202
  expect(call?.[0].prompt).toBe('Step into this moment');
128
203
  });
129
204
 
130
- it('omits personaContext when persona is null', async () => {
205
+ it('caption mode: omits personaContext when persona is null', async () => {
131
206
  const apiClient = makeApiClient();
132
207
  await prepareSceneEntry({
133
208
  videoId: 'vid-1',
134
209
  timestamp: 10,
135
210
  shotCaption: 'caption',
211
+ includeCaption: true,
136
212
  enrichment: null,
137
213
  persona: null,
138
214
  apiClient,
@@ -142,12 +218,13 @@ describe('prepareSceneEntry', () => {
142
218
  expect(call?.[0].personaContext).toBeUndefined();
143
219
  });
144
220
 
145
- it('includes personaContext when persona has a backstory', async () => {
221
+ it('caption mode: includes personaContext when persona has a backstory', async () => {
146
222
  const apiClient = makeApiClient();
147
223
  await prepareSceneEntry({
148
224
  videoId: 'vid-1',
149
225
  timestamp: 10,
150
226
  shotCaption: 'caption',
227
+ includeCaption: true,
151
228
  enrichment: null,
152
229
  persona: makePersona(),
153
230
  apiClient,
@@ -172,7 +249,7 @@ describe('prepareSceneEntry', () => {
172
249
  expect(call?.[0]).toBe('img-scene-1');
173
250
  });
174
251
 
175
- it('returns the upsampled prompt, source timestamp, imageId, and a frame File', async () => {
252
+ it('caption mode: returns the upsampled prompt, source timestamp, imageId, and a frame File', async () => {
176
253
  const apiClient = makeApiClient({
177
254
  upsampledPrompt: 'The expanded paragraph.',
178
255
  seedBlob: new Blob(['frame-bytes'], { type: 'image/png' }),
@@ -180,7 +257,8 @@ describe('prepareSceneEntry', () => {
180
257
  const payload = await prepareSceneEntry({
181
258
  videoId: 'vid-1',
182
259
  timestamp: 42,
183
- shotCaption: null,
260
+ shotCaption: 'A specific caption.',
261
+ includeCaption: true,
184
262
  enrichment: null,
185
263
  persona: null,
186
264
  apiClient,
@@ -193,13 +271,58 @@ describe('prepareSceneEntry', () => {
193
271
  expect(payload.frameFile.name).toBe('scene.png');
194
272
  });
195
273
 
274
+ it('payload always carries entityContext for follow-up prompts', async () => {
275
+ const apiClient = makeApiClient();
276
+ const payload = await prepareSceneEntry({
277
+ videoId: 'vid-1',
278
+ timestamp: 10,
279
+ shotCaption: null,
280
+ enrichment: null,
281
+ persona: null,
282
+ apiClient,
283
+ });
284
+ // The shape, not just name — guards against a future refactor
285
+ // that drops entityContext from the return.
286
+ expect(payload.entityContext).toEqual(
287
+ expect.objectContaining({ name: expect.any(String) }),
288
+ );
289
+ });
290
+
291
+ it('payload personaContext is null when persona is null', async () => {
292
+ const apiClient = makeApiClient();
293
+ const payload = await prepareSceneEntry({
294
+ videoId: 'vid-1',
295
+ timestamp: 10,
296
+ shotCaption: null,
297
+ enrichment: null,
298
+ persona: null,
299
+ apiClient,
300
+ });
301
+ expect(payload.personaContext).toBeNull();
302
+ });
303
+
304
+ it('payload personaContext is populated when persona has a backstory', async () => {
305
+ const apiClient = makeApiClient();
306
+ const payload = await prepareSceneEntry({
307
+ videoId: 'vid-1',
308
+ timestamp: 10,
309
+ shotCaption: null,
310
+ enrichment: null,
311
+ persona: makePersona(),
312
+ apiClient,
313
+ });
314
+ expect(payload.personaContext?.name).toBe('Test Persona');
315
+ expect(payload.personaContext?.backstory).toBeTruthy();
316
+ });
317
+
196
318
  it('threads the signal into extractImage, upsample, and getSeedImageBlob', async () => {
197
319
  const apiClient = makeApiClient();
198
320
  const controller = new AbortController();
199
321
  await prepareSceneEntry({
200
322
  videoId: 'vid-1',
201
323
  timestamp: 10,
202
- shotCaption: null,
324
+ shotCaption: 'caption',
325
+ includeCaption: true,
203
326
  enrichment: null,
204
327
  persona: null,
205
328
  apiClient,
@@ -255,6 +378,8 @@ describe('bootstrapSceneInReactor', () => {
255
378
  upsampledPrompt: 'Helios paragraph.',
256
379
  sourceTimestamp: 42,
257
380
  imageId: 'img-scene-1',
381
+ entityContext: { name: 'scene' },
382
+ personaContext: null,
258
383
  };
259
384
  }
260
385
 
@@ -266,7 +391,6 @@ describe('bootstrapSceneInReactor', () => {
266
391
  expect(bridge.sendCommand.mock.calls[0][0]).toBe('set_image');
267
392
  expect(bridge.sendCommand.mock.calls[0][1]).toEqual({
268
393
  image: { uploadId: 'u-frame' },
269
- transition: 'cut',
270
394
  });
271
395
  expect(bridge.sendCommand.mock.calls[1][0]).toBe('set_prompt');
272
396
  expect(bridge.sendCommand.mock.calls[1][1]).toEqual({
@@ -16,6 +16,7 @@
16
16
 
17
17
  import type { ApiClient } from '../../api';
18
18
  import {
19
+ downscaleImageForDataChannel,
19
20
  loadAndApplySeedImage,
20
21
  loadSeedImageFile,
21
22
  sendSeedFileToReactor,
@@ -70,24 +71,25 @@ describe('loadSeedImageFile', () => {
70
71
  });
71
72
 
72
73
  describe('sendSeedFileToReactor', () => {
73
- it('uploads then set_image with the requested transition', async () => {
74
+ it('uploads the file then sends set_image with only the FileRef by default', async () => {
74
75
  const reactor = makeReactor();
75
- const file = new File(['x'], 'seed.jpg', { type: 'image/jpeg' });
76
- await sendSeedFileToReactor(file, reactor, { transition: 'blend' });
76
+ const file = new File(['hello'], 'seed.jpg', { type: 'image/jpeg' });
77
+ await sendSeedFileToReactor(file, reactor);
77
78
  expect(reactor.uploadFile).toHaveBeenCalledWith(file);
78
79
  const cmd = reactor.sendCommand.mock.calls[0];
79
80
  expect(cmd[0]).toBe('set_image');
80
- expect(cmd[1]).toEqual({ image: { uploadId: 'u1' }, transition: 'blend' });
81
+ // Matches the working JS spike verbatim — `{ image: ref }` with no
82
+ // `transition` field. Adding `transition: 'cut'` correlated with
83
+ // the seed never taking effect in the React app.
84
+ expect(cmd[1]).toEqual({ image: { uploadId: 'u1' } });
81
85
  });
82
86
 
83
- it('defaults transition to "cut"', async () => {
87
+ it('sends transition only when explicitly provided', async () => {
84
88
  const reactor = makeReactor();
85
89
  const file = new File(['x'], 'seed.jpg', { type: 'image/jpeg' });
86
- await sendSeedFileToReactor(file, reactor);
90
+ await sendSeedFileToReactor(file, reactor, { transition: 'blend' });
87
91
  const cmd = reactor.sendCommand.mock.calls[0];
88
- expect(cmd[1]).toEqual(
89
- expect.objectContaining({ transition: 'cut' }),
90
- );
92
+ expect(cmd[1]).toEqual({ image: { uploadId: 'u1' }, transition: 'blend' });
91
93
  });
92
94
 
93
95
  it('awaits waitForImageReady when provided', async () => {
@@ -103,17 +105,14 @@ describe('loadAndApplySeedImage', () => {
103
105
  it('chains load + upload + set_image', async () => {
104
106
  const apiClient = makeApiClient(new Blob(['x'], { type: 'image/png' }));
105
107
  const reactor = makeReactor();
106
- await loadAndApplySeedImage('img-1', apiClient, reactor, {
107
- transition: 'cut',
108
- });
108
+ await loadAndApplySeedImage('img-1', apiClient, reactor);
109
109
  expect(
110
110
  (apiClient as unknown as Record<string, AnyMock>).getSeedImageBlob,
111
111
  ).toHaveBeenCalledWith('img-1', expect.anything());
112
112
  expect(reactor.uploadFile).toHaveBeenCalled();
113
- expect(reactor.sendCommand).toHaveBeenCalledWith(
114
- 'set_image',
115
- expect.objectContaining({ transition: 'cut' }),
116
- );
113
+ expect(reactor.sendCommand).toHaveBeenCalledWith('set_image', {
114
+ image: { uploadId: 'u1' },
115
+ });
117
116
  });
118
117
 
119
118
  it('returns without uploading when aborted between load and apply', async () => {
@@ -137,3 +136,39 @@ describe('loadAndApplySeedImage', () => {
137
136
  expect(reactor.sendCommand).not.toHaveBeenCalled();
138
137
  });
139
138
  });
139
+
140
+ describe('downscaleImageForDataChannel', () => {
141
+ it('returns the original blob unchanged when it already fits the budget', async () => {
142
+ const small = new Blob(['tiny content'], { type: 'image/jpeg' });
143
+ const result = await downscaleImageForDataChannel(small);
144
+ expect(result).toBe(small);
145
+ });
146
+
147
+ it('falls back to the original blob when canvas is unavailable (jsdom)', async () => {
148
+ // jsdom returns a canvas element but its getContext('2d') is null —
149
+ // the helper must pass through rather than throw. Construct a blob
150
+ // that exceeds the default budget so the size-check short-circuit
151
+ // doesn't kick in.
152
+ const bytes = new Uint8Array(50 * 1024);
153
+ const big = new Blob([bytes], { type: 'image/png' });
154
+ const result = await downscaleImageForDataChannel(big);
155
+ // jsdom path returns the original. In a real browser this would be
156
+ // a re-encoded smaller JPEG. The unit test environment can't
157
+ // exercise that branch without a canvas backend; the diagnostic
158
+ // log in sendSeedFileToReactor covers the in-browser case.
159
+ expect(result).toBe(big);
160
+ });
161
+
162
+ it('respects a custom budget threshold', async () => {
163
+ const blob = new Blob([new Uint8Array(100)], { type: 'image/jpeg' });
164
+ // 100 bytes is well below the default 45KB → already-fits path.
165
+ // With a budget of 50 bytes, it would NOT pass the size check and
166
+ // would enter the canvas path (which is no-op under jsdom).
167
+ expect(await downscaleImageForDataChannel(blob, { maxRawBytes: 50 })).toBe(
168
+ blob,
169
+ );
170
+ expect(
171
+ await downscaleImageForDataChannel(blob, { maxRawBytes: 200 }),
172
+ ).toBe(blob);
173
+ });
174
+ });
@@ -1,4 +1,4 @@
1
- import { formatTimestamp } from '../timeFormat';
1
+ import { formatTimestamp, formatCitationTimestamp } from '../timeFormat';
2
2
 
3
3
  describe('formatTimestamp — default m:ss', () => {
4
4
  it('formats whole minutes and seconds', () => {
@@ -78,3 +78,24 @@ describe('formatTimestamp — centiseconds for chat citations', () => {
78
78
  );
79
79
  });
80
80
  });
81
+
82
+ describe('formatCitationTimestamp — centiseconds preset', () => {
83
+ it('matches formatTimestamp(x, { centiseconds: true }) exactly', () => {
84
+ expect(formatCitationTimestamp(83.45)).toBe(
85
+ formatTimestamp(83.45, { centiseconds: true }),
86
+ );
87
+ expect(formatCitationTimestamp(0)).toBe(
88
+ formatTimestamp(0, { centiseconds: true }),
89
+ );
90
+ expect(formatCitationTimestamp(3725.5)).toBe(
91
+ formatTimestamp(3725.5, { centiseconds: true }),
92
+ );
93
+ });
94
+
95
+ it('returns the expected concrete strings', () => {
96
+ expect(formatCitationTimestamp(83.45)).toBe('1:23.45');
97
+ expect(formatCitationTimestamp(0)).toBe('0:00.00');
98
+ expect(formatCitationTimestamp(65.5)).toBe('1:05.50');
99
+ expect(formatCitationTimestamp(3725.5)).toBe('1:02:05.50');
100
+ });
101
+ });
@@ -0,0 +1,57 @@
1
+ import {
2
+ AGENT_TOOL_SCHEMAS,
3
+ AGENT_TOOL_NAMES,
4
+ getAgentToolSchema,
5
+ } from '../toolSchemas';
6
+
7
+ // Mirror of shared/tool_schemas.py — the backend single source of truth.
8
+ const EXPECTED_TOOL_NAMES = [
9
+ 'list_videos',
10
+ 'semantic_search',
11
+ 'events_for_range',
12
+ 'clip_lookup',
13
+ 'entity_timeline',
14
+ 'scene_neighbors',
15
+ 'dialog_search',
16
+ 'get_transcript',
17
+ 'speaker_dialog',
18
+ 'extract_image',
19
+ 'regenerate_image',
20
+ 'generate_character',
21
+ ] as const;
22
+
23
+ describe('AGENT_TOOL_SCHEMAS', () => {
24
+ it('mirrors the 12 backend tool names in canonical order', () => {
25
+ expect(AGENT_TOOL_NAMES).toEqual(EXPECTED_TOOL_NAMES);
26
+ expect(AGENT_TOOL_SCHEMAS).toHaveLength(12);
27
+ });
28
+
29
+ it('exposes a non-empty description and endpoint for every tool', () => {
30
+ for (const tool of AGENT_TOOL_SCHEMAS) {
31
+ expect(tool.description.length).toBeGreaterThan(0);
32
+ expect(tool.endpoint.startsWith('/api/v1/')).toBe(true);
33
+ expect(['GET', 'POST']).toContain(tool.httpMethod);
34
+ }
35
+ });
36
+
37
+ it('marks list_videos as a GET tool (mirrors http_method)', () => {
38
+ const listVideos = getAgentToolSchema('list_videos');
39
+ expect(listVideos?.httpMethod).toBe('GET');
40
+ });
41
+
42
+ it('encodes the semantic_search scope enum', () => {
43
+ const semanticSearch = getAgentToolSchema('semantic_search');
44
+ const scope = semanticSearch?.fields.find((f) => f.name === 'scope');
45
+ expect(scope?.enum).toEqual(['shots', 'videos', 'hybrid']);
46
+ });
47
+
48
+ it('marks required fields on a required-field tool', () => {
49
+ const clip = getAgentToolSchema('clip_lookup');
50
+ const required = clip?.fields.filter((f) => f.required).map((f) => f.name);
51
+ expect(required).toEqual(['videoId', 't0', 't1']);
52
+ });
53
+
54
+ it('returns undefined for an unknown tool name', () => {
55
+ expect(getAgentToolSchema('nope')).toBeUndefined();
56
+ });
57
+ });