@escapeaihq/client-core 0.6.0 → 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.
- package/README.md +27 -2
- package/dist/api.d.ts +180 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +134 -0
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reactor/entityContext.d.ts +34 -0
- package/dist/reactor/entityContext.d.ts.map +1 -0
- package/dist/reactor/entityContext.js +119 -0
- package/dist/reactor/entityContext.js.map +1 -0
- package/dist/reactor/entitySearch.d.ts +71 -0
- package/dist/reactor/entitySearch.d.ts.map +1 -0
- package/dist/reactor/entitySearch.js +93 -0
- package/dist/reactor/entitySearch.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts +98 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.js +181 -0
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -0
- package/dist/reactor/heliosTools.d.ts +156 -0
- package/dist/reactor/heliosTools.d.ts.map +1 -0
- package/dist/reactor/heliosTools.js +241 -0
- package/dist/reactor/heliosTools.js.map +1 -0
- package/dist/reactor/index.d.ts +17 -0
- package/dist/reactor/index.d.ts.map +1 -0
- package/dist/reactor/index.js +17 -0
- package/dist/reactor/index.js.map +1 -0
- package/dist/reactor/promptAddonRegistry.d.ts +37 -0
- package/dist/reactor/promptAddonRegistry.d.ts.map +1 -0
- package/dist/reactor/promptAddonRegistry.js +38 -0
- package/dist/reactor/promptAddonRegistry.js.map +1 -0
- package/dist/reactor/regenTemplate.d.ts +23 -0
- package/dist/reactor/regenTemplate.d.ts.map +1 -0
- package/dist/reactor/regenTemplate.js +103 -0
- package/dist/reactor/regenTemplate.js.map +1 -0
- package/dist/reactor/sceneEntry.d.ts +79 -0
- package/dist/reactor/sceneEntry.d.ts.map +1 -0
- package/dist/reactor/sceneEntry.js +177 -0
- package/dist/reactor/sceneEntry.js.map +1 -0
- package/dist/reactor/scenesFromEnrichment.d.ts +67 -0
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -0
- package/dist/reactor/scenesFromEnrichment.js +344 -0
- package/dist/reactor/scenesFromEnrichment.js.map +1 -0
- package/dist/reactor/seedImageOrchestrator.d.ts +81 -0
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -0
- package/dist/reactor/seedImageOrchestrator.js +79 -0
- package/dist/reactor/seedImageOrchestrator.js.map +1 -0
- package/dist/reactor/toolPromptAddon.d.ts +44 -0
- package/dist/reactor/toolPromptAddon.d.ts.map +1 -0
- package/dist/reactor/toolPromptAddon.js +129 -0
- package/dist/reactor/toolPromptAddon.js.map +1 -0
- package/dist/reactor/toolPromptAddonId.d.ts +10 -0
- package/dist/reactor/toolPromptAddonId.d.ts.map +1 -0
- package/dist/reactor/toolPromptAddonId.js +10 -0
- package/dist/reactor/toolPromptAddonId.js.map +1 -0
- package/dist/reactor/types.d.ts +149 -0
- package/dist/reactor/types.d.ts.map +1 -0
- package/dist/reactor/types.js +2 -0
- package/dist/reactor/types.js.map +1 -0
- package/dist/reactor/upsamplePrompt.d.ts +30 -0
- package/dist/reactor/upsamplePrompt.d.ts.map +1 -0
- package/dist/reactor/upsamplePrompt.js +118 -0
- package/dist/reactor/upsamplePrompt.js.map +1 -0
- package/dist/timeFormat.d.ts +28 -0
- package/dist/timeFormat.d.ts.map +1 -0
- package/dist/timeFormat.js +48 -0
- package/dist/timeFormat.js.map +1 -0
- package/dist/visemeGeometry.d.ts +15 -0
- package/dist/visemeGeometry.d.ts.map +1 -1
- package/dist/visemeGeometry.js +26 -0
- package/dist/visemeGeometry.js.map +1 -1
- package/dist/visemeScheduler.d.ts +12 -0
- package/dist/visemeScheduler.d.ts.map +1 -1
- package/dist/visemeScheduler.js +24 -0
- package/dist/visemeScheduler.js.map +1 -1
- package/dist/websocket.d.ts +51 -3
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +52 -7
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/reactor/__snapshots__/regenTemplate.test.ts.snap +5 -0
- package/src/__tests__/reactor/__snapshots__/scenesFromEnrichment.test.ts.snap +34 -0
- package/src/__tests__/reactor/api-reactor.test.ts +253 -0
- package/src/__tests__/reactor/entityContext.test.ts +237 -0
- package/src/__tests__/reactor/entitySearch.test.ts +223 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +438 -0
- package/src/__tests__/reactor/heliosTools.test.ts +164 -0
- package/src/__tests__/reactor/promptAddonRegistry.test.ts +40 -0
- package/src/__tests__/reactor/regenTemplate.test.ts +156 -0
- package/src/__tests__/reactor/sceneEntry.test.ts +342 -0
- package/src/__tests__/reactor/scenesFromEnrichment.test.ts +760 -0
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +139 -0
- package/src/__tests__/reactor/toolPromptAddon.test.ts +104 -0
- package/src/__tests__/reactor/upsamplePrompt.test.ts +245 -0
- package/src/__tests__/timeFormat.test.ts +80 -0
- package/src/__tests__/tools-wrappers.test.ts +219 -0
- package/src/__tests__/websocket.test.ts +278 -0
- package/src/api.ts +279 -2
- package/src/index.ts +2 -0
- package/src/reactor/entityContext.ts +147 -0
- package/src/reactor/entitySearch.ts +139 -0
- package/src/reactor/heliosCommandDispatcher.ts +293 -0
- package/src/reactor/heliosTools.ts +260 -0
- package/src/reactor/index.ts +17 -0
- package/src/reactor/promptAddonRegistry.ts +52 -0
- package/src/reactor/regenTemplate.ts +142 -0
- package/src/reactor/sceneEntry.ts +267 -0
- package/src/reactor/scenesFromEnrichment.ts +393 -0
- package/src/reactor/seedImageOrchestrator.ts +132 -0
- package/src/reactor/toolPromptAddon.ts +135 -0
- package/src/reactor/toolPromptAddonId.ts +9 -0
- package/src/reactor/types.ts +158 -0
- package/src/reactor/upsamplePrompt.ts +154 -0
- package/src/timeFormat.ts +57 -0
- package/src/visemeGeometry.ts +30 -0
- package/src/visemeScheduler.ts +25 -0
- package/src/websocket.ts +86 -7
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the seed-image orchestrator — `loadSeedImageFile`,
|
|
3
|
+
* `sendSeedFileToReactor`, and the convenience `loadAndApplySeedImage`.
|
|
4
|
+
*
|
|
5
|
+
* Coverage:
|
|
6
|
+
* - loadSeedImageFile derives the filename extension from blob MIME
|
|
7
|
+
* - loadSeedImageFile threads the signal into getSeedImageBlob
|
|
8
|
+
* - loadSeedImageFile applies a custom filenameStem
|
|
9
|
+
* - sendSeedFileToReactor uploads then sends set_image with the
|
|
10
|
+
* requested transition
|
|
11
|
+
* - sendSeedFileToReactor awaits waitForImageReady when provided
|
|
12
|
+
* - sendSeedFileToReactor defaults transition to 'cut'
|
|
13
|
+
* - loadAndApplySeedImage chains both halves
|
|
14
|
+
* - loadAndApplySeedImage returns early after the load when aborted
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { ApiClient } from '../../api';
|
|
18
|
+
import {
|
|
19
|
+
loadAndApplySeedImage,
|
|
20
|
+
loadSeedImageFile,
|
|
21
|
+
sendSeedFileToReactor,
|
|
22
|
+
} from '../../reactor/seedImageOrchestrator';
|
|
23
|
+
|
|
24
|
+
type AnyMock = jest.Mock;
|
|
25
|
+
|
|
26
|
+
function makeReactor() {
|
|
27
|
+
return {
|
|
28
|
+
sendCommand: jest.fn().mockResolvedValue(undefined) as AnyMock,
|
|
29
|
+
uploadFile: jest.fn().mockResolvedValue({ uploadId: 'u1' }) as AnyMock,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function makeApiClient(blob: Blob) {
|
|
34
|
+
return {
|
|
35
|
+
getSeedImageBlob: jest.fn().mockResolvedValue(blob),
|
|
36
|
+
} as unknown as ApiClient;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('loadSeedImageFile', () => {
|
|
40
|
+
it('derives the filename extension from the blob MIME (PNG)', async () => {
|
|
41
|
+
const apiClient = makeApiClient(new Blob(['x'], { type: 'image/png' }));
|
|
42
|
+
const file = await loadSeedImageFile('img-1', apiClient);
|
|
43
|
+
expect(file.name).toBe('seed.png');
|
|
44
|
+
expect(file.type).toBe('image/png');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('falls back to jpg when blob MIME is empty', async () => {
|
|
48
|
+
const apiClient = makeApiClient(new Blob(['x']));
|
|
49
|
+
const file = await loadSeedImageFile('img-1', apiClient);
|
|
50
|
+
expect(file.name).toBe('seed.jpg');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('threads the signal into getSeedImageBlob', async () => {
|
|
54
|
+
const apiClient = makeApiClient(new Blob(['x'], { type: 'image/jpeg' }));
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
await loadSeedImageFile('img-1', apiClient, { signal: controller.signal });
|
|
57
|
+
const call = (apiClient as unknown as Record<string, AnyMock>)
|
|
58
|
+
.getSeedImageBlob.mock.calls[0];
|
|
59
|
+
expect(call?.[0]).toBe('img-1');
|
|
60
|
+
expect(call?.[1]).toEqual({ signal: controller.signal });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('respects a custom filenameStem', async () => {
|
|
64
|
+
const apiClient = makeApiClient(new Blob(['x'], { type: 'image/png' }));
|
|
65
|
+
const file = await loadSeedImageFile('img-1', apiClient, {
|
|
66
|
+
filenameStem: 'swap-seed',
|
|
67
|
+
});
|
|
68
|
+
expect(file.name).toBe('swap-seed.png');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('sendSeedFileToReactor', () => {
|
|
73
|
+
it('uploads then set_image with the requested transition', async () => {
|
|
74
|
+
const reactor = makeReactor();
|
|
75
|
+
const file = new File(['x'], 'seed.jpg', { type: 'image/jpeg' });
|
|
76
|
+
await sendSeedFileToReactor(file, reactor, { transition: 'blend' });
|
|
77
|
+
expect(reactor.uploadFile).toHaveBeenCalledWith(file);
|
|
78
|
+
const cmd = reactor.sendCommand.mock.calls[0];
|
|
79
|
+
expect(cmd[0]).toBe('set_image');
|
|
80
|
+
expect(cmd[1]).toEqual({ image: { uploadId: 'u1' }, transition: 'blend' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('defaults transition to "cut"', async () => {
|
|
84
|
+
const reactor = makeReactor();
|
|
85
|
+
const file = new File(['x'], 'seed.jpg', { type: 'image/jpeg' });
|
|
86
|
+
await sendSeedFileToReactor(file, reactor);
|
|
87
|
+
const cmd = reactor.sendCommand.mock.calls[0];
|
|
88
|
+
expect(cmd[1]).toEqual(
|
|
89
|
+
expect.objectContaining({ transition: 'cut' }),
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('awaits waitForImageReady when provided', async () => {
|
|
94
|
+
const reactor = makeReactor();
|
|
95
|
+
const file = new File(['x'], 'seed.jpg', { type: 'image/jpeg' });
|
|
96
|
+
const waitForImageReady = jest.fn().mockResolvedValue(undefined);
|
|
97
|
+
await sendSeedFileToReactor(file, reactor, { waitForImageReady });
|
|
98
|
+
expect(waitForImageReady).toHaveBeenCalledTimes(1);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('loadAndApplySeedImage', () => {
|
|
103
|
+
it('chains load + upload + set_image', async () => {
|
|
104
|
+
const apiClient = makeApiClient(new Blob(['x'], { type: 'image/png' }));
|
|
105
|
+
const reactor = makeReactor();
|
|
106
|
+
await loadAndApplySeedImage('img-1', apiClient, reactor, {
|
|
107
|
+
transition: 'cut',
|
|
108
|
+
});
|
|
109
|
+
expect(
|
|
110
|
+
(apiClient as unknown as Record<string, AnyMock>).getSeedImageBlob,
|
|
111
|
+
).toHaveBeenCalledWith('img-1', expect.anything());
|
|
112
|
+
expect(reactor.uploadFile).toHaveBeenCalled();
|
|
113
|
+
expect(reactor.sendCommand).toHaveBeenCalledWith(
|
|
114
|
+
'set_image',
|
|
115
|
+
expect.objectContaining({ transition: 'cut' }),
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns without uploading when aborted between load and apply', async () => {
|
|
120
|
+
const apiClient = makeApiClient(new Blob(['x'], { type: 'image/png' }));
|
|
121
|
+
const reactor = makeReactor();
|
|
122
|
+
const controller = new AbortController();
|
|
123
|
+
// Simulate the load resolving, then signal flipping aborted before
|
|
124
|
+
// upload. The orchestrator checks the signal after loadSeedImageFile.
|
|
125
|
+
(
|
|
126
|
+
apiClient as unknown as Record<string, AnyMock>
|
|
127
|
+
).getSeedImageBlob.mockImplementation(() => {
|
|
128
|
+
controller.abort();
|
|
129
|
+
return Promise.resolve(new Blob(['x'], { type: 'image/png' }));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await loadAndApplySeedImage('img-1', apiClient, reactor, {
|
|
133
|
+
signal: controller.signal,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(reactor.uploadFile).not.toHaveBeenCalled();
|
|
137
|
+
expect(reactor.sendCommand).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the Helios world-steering prompt addon.
|
|
3
|
+
*
|
|
4
|
+
* Coverage:
|
|
5
|
+
* - HELIOS_WORLD_STEERING_ADDON_ID is the expected literal (so the
|
|
6
|
+
* Python constant in `shared/persona_addon_ids.py` and any
|
|
7
|
+
* `PersonaConfig.prompt_addon_ids` value can be cross-checked).
|
|
8
|
+
* - getHeliosSteeringAddonText returns a non-empty string mentioning
|
|
9
|
+
* all five marker names plus the 80-120 word target — protects
|
|
10
|
+
* against partial-deletes during future refactors.
|
|
11
|
+
* - buildHeliosSteeringSystemPrompt is idempotent: applying twice
|
|
12
|
+
* produces the same output as one application.
|
|
13
|
+
* - An empty/whitespace-only base prompt is allowed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { parseHeliosCommands } from '../../reactor/heliosTools';
|
|
17
|
+
import {
|
|
18
|
+
HELIOS_WORLD_STEERING_ADDON_ID,
|
|
19
|
+
buildHeliosSteeringSystemPrompt,
|
|
20
|
+
getHeliosSteeringAddonText,
|
|
21
|
+
} from '../../reactor/toolPromptAddon';
|
|
22
|
+
|
|
23
|
+
describe('HELIOS_WORLD_STEERING_ADDON_ID', () => {
|
|
24
|
+
it('is the canonical string id used by PersonaConfig.prompt_addon_ids', () => {
|
|
25
|
+
expect(HELIOS_WORLD_STEERING_ADDON_ID).toBe('helios-world-steering');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('getHeliosSteeringAddonText', () => {
|
|
30
|
+
it('returns a non-empty string', () => {
|
|
31
|
+
const text = getHeliosSteeringAddonText();
|
|
32
|
+
expect(typeof text).toBe('string');
|
|
33
|
+
expect(text.length).toBeGreaterThan(0);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('mentions all five marker names', () => {
|
|
37
|
+
const text = getHeliosSteeringAddonText();
|
|
38
|
+
expect(text).toMatch(/SET_SCENE/);
|
|
39
|
+
expect(text).toMatch(/SWAP_SEED/);
|
|
40
|
+
expect(text).toMatch(/PAUSE_WORLD/);
|
|
41
|
+
expect(text).toMatch(/RESUME_WORLD/);
|
|
42
|
+
expect(text).toMatch(/RESET_WORLD/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('mentions the 80-120 word target', () => {
|
|
46
|
+
const text = getHeliosSteeringAddonText();
|
|
47
|
+
expect(text).toMatch(/80-120 word/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// PR #193 round 10 regression — the example assistant turn embedded
|
|
51
|
+
// in the addon was missing its closing `]`. Models trained on a
|
|
52
|
+
// malformed example tend to emit malformed markers in production,
|
|
53
|
+
// which both parseHeliosCommands and stripHeliosCommands silently
|
|
54
|
+
// drop (parse) or pass through (strip — leaks raw brackets into the
|
|
55
|
+
// user-facing transcript). Round-trip the example through the actual
|
|
56
|
+
// parser as the source-of-truth marker validity check.
|
|
57
|
+
it('embedded marker examples are parseable by the actual parser', () => {
|
|
58
|
+
const text = getHeliosSteeringAddonText();
|
|
59
|
+
const commands = parseHeliosCommands(text);
|
|
60
|
+
// The addon's exemplar shows SET_SCENE (the heaviest command),
|
|
61
|
+
// SWAP_SEED, PAUSE/RESUME, and RESET in prose. At minimum, the
|
|
62
|
+
// SET_SCENE example MUST parse — that's the marker with the
|
|
63
|
+
// bracket structure most prone to malformation.
|
|
64
|
+
const setSceneExamples = commands.filter(c => c.type === 'set_scene');
|
|
65
|
+
expect(setSceneExamples.length).toBeGreaterThanOrEqual(1);
|
|
66
|
+
// And whatever example we shipped has a real (non-empty) prompt.
|
|
67
|
+
for (const cmd of setSceneExamples) {
|
|
68
|
+
if (cmd.type === 'set_scene') {
|
|
69
|
+
expect(cmd.prompt.length).toBeGreaterThan(0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('buildHeliosSteeringSystemPrompt', () => {
|
|
76
|
+
it('appends the addon to a non-empty base prompt', () => {
|
|
77
|
+
const out = buildHeliosSteeringSystemPrompt('You are Leo.');
|
|
78
|
+
expect(out.startsWith('You are Leo.')).toBe(true);
|
|
79
|
+
expect(out).toContain('SET_SCENE');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('returns just the addon for an empty base prompt', () => {
|
|
83
|
+
const out = buildHeliosSteeringSystemPrompt('');
|
|
84
|
+
expect(out).toBe(getHeliosSteeringAddonText());
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns just the addon for a whitespace-only base prompt', () => {
|
|
88
|
+
const out = buildHeliosSteeringSystemPrompt(' \n ');
|
|
89
|
+
expect(out).toBe(getHeliosSteeringAddonText());
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('is idempotent: applying twice equals applying once', () => {
|
|
93
|
+
const base = 'You are Leo, a retired sailor from County Cork.';
|
|
94
|
+
const once = buildHeliosSteeringSystemPrompt(base);
|
|
95
|
+
const twice = buildHeliosSteeringSystemPrompt(once);
|
|
96
|
+
expect(twice).toBe(once);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('is idempotent even on empty base', () => {
|
|
100
|
+
const once = buildHeliosSteeringSystemPrompt('');
|
|
101
|
+
const twice = buildHeliosSteeringSystemPrompt(once);
|
|
102
|
+
expect(twice).toBe(once);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `buildUpsamplePrompt` — the LLM-agnostic system/user
|
|
3
|
+
* message-pair builder for the prompt-upsample step.
|
|
4
|
+
*
|
|
5
|
+
* Coverage:
|
|
6
|
+
* - System prompt encodes Helios prompt-guide rules + 80-120 word target
|
|
7
|
+
* - Empty / minimal inputs (just userPrompt)
|
|
8
|
+
* - Entity-only / entity+persona / entity+persona+previousPrompt
|
|
9
|
+
* - Thumbnail variants — image block must appear FIRST when present
|
|
10
|
+
* - User block ordering: context → previous-prompt hint → image-hint → userPrompt
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { buildUpsamplePrompt } from '../../reactor/upsamplePrompt';
|
|
14
|
+
import type { UpsampleInput } from '../../reactor/types';
|
|
15
|
+
|
|
16
|
+
const PNG_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
|
|
17
|
+
|
|
18
|
+
describe('buildUpsamplePrompt — sync with Python twin', () => {
|
|
19
|
+
// Cheap drift detector for the Python/TypeScript prompt twin.
|
|
20
|
+
// `api/reactor/app.py::_build_system_prompt()` and this file's
|
|
21
|
+
// BASE_SYSTEM_RULES both encode the Helios prompt-guide rules but are
|
|
22
|
+
// independently maintained. If a future prompt-engineering change
|
|
23
|
+
// adjusts the word-count target or the canonical rule phrasing in
|
|
24
|
+
// ONE place, this test catches the drift before the LLM behavior
|
|
25
|
+
// silently changes for one of the two transports.
|
|
26
|
+
//
|
|
27
|
+
// Assertions are deliberately narrow (just the load-bearing
|
|
28
|
+
// constants), not full-text snapshots — the two files use different
|
|
29
|
+
// markdown formatting and that's fine. What MUST match is the
|
|
30
|
+
// numbers and a handful of canonical phrases the Helios SDK depends
|
|
31
|
+
// on the model emitting.
|
|
32
|
+
it('contains the canonical 80–120 word target', () => {
|
|
33
|
+
const { system } = buildUpsamplePrompt({ userPrompt: 'a man walking' });
|
|
34
|
+
expect(system).toContain('80–120 words');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('contains the "output only" / no-preamble directive', () => {
|
|
38
|
+
const { system } = buildUpsamplePrompt({ userPrompt: 'a man walking' });
|
|
39
|
+
expect(system.toLowerCase()).toContain('output only');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('contains the "one new narrative beat" continuity directive when previousPrompt is set', () => {
|
|
43
|
+
const { system } = buildUpsamplePrompt({
|
|
44
|
+
userPrompt: 'he turns and runs',
|
|
45
|
+
previousPrompt: 'a man walks through a forest',
|
|
46
|
+
});
|
|
47
|
+
expect(system.toLowerCase()).toContain('one new narrative beat');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('buildUpsamplePrompt — system prompt', () => {
|
|
52
|
+
it('first-prompt mode encodes the base Helios rules', () => {
|
|
53
|
+
// No previousPrompt — system message is the base ruleset only,
|
|
54
|
+
// matching the Python twin's `has_previous=False` behavior.
|
|
55
|
+
const { system } = buildUpsamplePrompt({ userPrompt: 'a man walking' });
|
|
56
|
+
|
|
57
|
+
// 80-120 word target + complete-sentence guarantee
|
|
58
|
+
expect(system).toMatch(/80\D{1,3}120/);
|
|
59
|
+
expect(system.toLowerCase()).toContain('complete sentence');
|
|
60
|
+
|
|
61
|
+
// Base Helios rules — at least one phrase from each.
|
|
62
|
+
expect(system.toLowerCase()).toContain('subject');
|
|
63
|
+
expect(system.toLowerCase()).toContain('environment');
|
|
64
|
+
expect(system.toLowerCase()).toContain('camera');
|
|
65
|
+
expect(system.toLowerCase()).toContain('framing');
|
|
66
|
+
expect(system.toLowerCase()).toContain('re-anchor');
|
|
67
|
+
// Light by effect, not label
|
|
68
|
+
expect(system.toLowerCase()).toContain('light');
|
|
69
|
+
// Emotion through behavior
|
|
70
|
+
expect(system.toLowerCase()).toContain('behavior');
|
|
71
|
+
// Physical specificity
|
|
72
|
+
expect(system.toLowerCase()).toMatch(/textur|material|physical/);
|
|
73
|
+
// Output-only directive
|
|
74
|
+
expect(system.toLowerCase()).toContain('output only');
|
|
75
|
+
|
|
76
|
+
// Continuity rules should NOT be present in first-prompt mode.
|
|
77
|
+
expect(system.toLowerCase()).not.toContain('one new narrative beat');
|
|
78
|
+
expect(system.toLowerCase()).not.toContain('visual continuity');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('follow-up mode appends the continuity rules', () => {
|
|
82
|
+
// previousPrompt provided — system message includes the
|
|
83
|
+
// continuity section ("one new beat per follow-up"), matching the
|
|
84
|
+
// Python twin's `has_previous=True` behavior.
|
|
85
|
+
const { system } = buildUpsamplePrompt({
|
|
86
|
+
userPrompt: 'he turns and runs',
|
|
87
|
+
previousPrompt: 'a man walking through a forest',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Base rules still present.
|
|
91
|
+
expect(system.toLowerCase()).toContain('camera');
|
|
92
|
+
expect(system.toLowerCase()).toContain('framing');
|
|
93
|
+
// Continuity directives now included.
|
|
94
|
+
expect(system.toLowerCase()).toContain('one new narrative beat');
|
|
95
|
+
expect(system.toLowerCase()).toContain('visual continuity');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('buildUpsamplePrompt — user blocks (text only)', () => {
|
|
100
|
+
it('minimal input — single text block with just the user prompt', () => {
|
|
101
|
+
const { user } = buildUpsamplePrompt({ userPrompt: 'a man walking' });
|
|
102
|
+
expect(user).toHaveLength(1);
|
|
103
|
+
expect(user[0].type).toBe('text');
|
|
104
|
+
if (user[0].type === 'text') {
|
|
105
|
+
expect(user[0].text).toContain('a man walking');
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('entity-only — includes entity name and scene context, no persona section', () => {
|
|
110
|
+
const { user } = buildUpsamplePrompt({
|
|
111
|
+
userPrompt: 'he turns and runs',
|
|
112
|
+
entity: { name: 'Leo', sceneContext: 'standing on a rocky outcrop in the jungle' },
|
|
113
|
+
});
|
|
114
|
+
const text = (user[0] as { type: 'text'; text: string }).text;
|
|
115
|
+
expect(text).toContain('Leo');
|
|
116
|
+
expect(text).toContain('source video');
|
|
117
|
+
expect(text).toContain('rocky outcrop');
|
|
118
|
+
expect(text).not.toContain('Persona backstory');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('entity-only without scene context — emits a bare name line, no source-scene phrasing', () => {
|
|
122
|
+
const { user } = buildUpsamplePrompt({
|
|
123
|
+
userPrompt: 'he turns and runs',
|
|
124
|
+
entity: { name: 'Leo' },
|
|
125
|
+
});
|
|
126
|
+
const text = (user[0] as { type: 'text'; text: string }).text;
|
|
127
|
+
expect(text).toContain('This is Leo.');
|
|
128
|
+
expect(text).not.toContain('source video');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('entity + persona — both grounding sections present', () => {
|
|
132
|
+
const { user } = buildUpsamplePrompt({
|
|
133
|
+
userPrompt: 'a quiet moment',
|
|
134
|
+
entity: { name: 'Leo', sceneContext: 'standing on a rocky outcrop' },
|
|
135
|
+
persona: { name: 'Leo', backstory: 'A noble jungle king who lost his pride.' },
|
|
136
|
+
});
|
|
137
|
+
const text = (user[0] as { type: 'text'; text: string }).text;
|
|
138
|
+
expect(text).toContain('Leo');
|
|
139
|
+
expect(text).toContain('rocky outcrop');
|
|
140
|
+
expect(text).toContain('Persona backstory for Leo');
|
|
141
|
+
expect(text).toContain('A noble jungle king');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('previousPrompt — emits continuity instruction and one-new-beat directive', () => {
|
|
145
|
+
const { user } = buildUpsamplePrompt({
|
|
146
|
+
userPrompt: 'he sniffs a butterfly',
|
|
147
|
+
previousPrompt: 'Leo stands on the outcrop, mane catching the sun.',
|
|
148
|
+
});
|
|
149
|
+
const text = (user[0] as { type: 'text'; text: string }).text;
|
|
150
|
+
expect(text).toContain('The previous scene was:');
|
|
151
|
+
expect(text).toContain('Leo stands on the outcrop');
|
|
152
|
+
expect(text.toLowerCase()).toContain('one new beat');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('buildUpsamplePrompt — thumbnail handling', () => {
|
|
157
|
+
it('thumbnail present — image block comes first, text block last', () => {
|
|
158
|
+
const { user } = buildUpsamplePrompt({
|
|
159
|
+
userPrompt: 'a man walking',
|
|
160
|
+
thumbnailBase64: PNG_BASE64,
|
|
161
|
+
});
|
|
162
|
+
expect(user).toHaveLength(2);
|
|
163
|
+
expect(user[0].type).toBe('image');
|
|
164
|
+
expect(user[1].type).toBe('text');
|
|
165
|
+
if (user[0].type === 'image') {
|
|
166
|
+
expect(user[0].mediaType).toBe('image/jpeg');
|
|
167
|
+
expect(user[0].base64).toBe(PNG_BASE64);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('thumbnail with explicit mediaType — overrides the jpeg default', () => {
|
|
172
|
+
const { user } = buildUpsamplePrompt({
|
|
173
|
+
userPrompt: 'a man walking',
|
|
174
|
+
thumbnailBase64: PNG_BASE64,
|
|
175
|
+
thumbnailMediaType: 'image/png',
|
|
176
|
+
});
|
|
177
|
+
const img = user[0] as { type: 'image'; mediaType: string; base64: string };
|
|
178
|
+
expect(img.mediaType).toBe('image/png');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('thumbnail data URL prefix — stripped from the base64 payload', () => {
|
|
182
|
+
const dataUrl = `data:image/jpeg;base64,${PNG_BASE64}`;
|
|
183
|
+
const { user } = buildUpsamplePrompt({
|
|
184
|
+
userPrompt: 'a man walking',
|
|
185
|
+
thumbnailBase64: dataUrl,
|
|
186
|
+
});
|
|
187
|
+
const img = user[0] as { type: 'image'; base64: string };
|
|
188
|
+
expect(img.base64).toBe(PNG_BASE64);
|
|
189
|
+
expect(img.base64.startsWith('data:')).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('thumbnail present — text block adds the "attached image is a reference" hint', () => {
|
|
193
|
+
const { user } = buildUpsamplePrompt({
|
|
194
|
+
userPrompt: 'a man walking',
|
|
195
|
+
thumbnailBase64: PNG_BASE64,
|
|
196
|
+
});
|
|
197
|
+
const text = (user[1] as { type: 'text'; text: string }).text;
|
|
198
|
+
expect(text.toLowerCase()).toContain('attached image');
|
|
199
|
+
expect(text.toLowerCase()).toContain('reference');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('no thumbnail — text block does NOT mention the attached-image reference', () => {
|
|
203
|
+
const { user } = buildUpsamplePrompt({ userPrompt: 'a man walking' });
|
|
204
|
+
const text = (user[0] as { type: 'text'; text: string }).text;
|
|
205
|
+
expect(text.toLowerCase()).not.toContain('attached image');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('all-up — image first, entity, persona, previousPrompt, image hint, user prompt in order', () => {
|
|
209
|
+
const { user } = buildUpsamplePrompt({
|
|
210
|
+
userPrompt: 'he sniffs a butterfly',
|
|
211
|
+
previousPrompt: 'Leo stands on the outcrop.',
|
|
212
|
+
entity: { name: 'Leo', sceneContext: 'standing on a rocky outcrop' },
|
|
213
|
+
persona: { name: 'Leo', backstory: 'A noble jungle king.' },
|
|
214
|
+
thumbnailBase64: PNG_BASE64,
|
|
215
|
+
});
|
|
216
|
+
expect(user[0].type).toBe('image');
|
|
217
|
+
expect(user[1].type).toBe('text');
|
|
218
|
+
const text = (user[1] as { type: 'text'; text: string }).text;
|
|
219
|
+
// Ordering check via index positions
|
|
220
|
+
const iEntity = text.indexOf('This is Leo');
|
|
221
|
+
const iPersona = text.indexOf('Persona backstory');
|
|
222
|
+
const iPrev = text.indexOf('The previous scene was');
|
|
223
|
+
const iImgHint = text.indexOf('attached image');
|
|
224
|
+
const iPrompt = text.indexOf('he sniffs a butterfly');
|
|
225
|
+
expect(iEntity).toBeGreaterThanOrEqual(0);
|
|
226
|
+
expect(iPersona).toBeGreaterThan(iEntity);
|
|
227
|
+
expect(iPrev).toBeGreaterThan(iPersona);
|
|
228
|
+
expect(iImgHint).toBeGreaterThan(iPrev);
|
|
229
|
+
expect(iPrompt).toBeGreaterThan(iImgHint);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe('buildUpsamplePrompt — determinism', () => {
|
|
234
|
+
it('identical input produces identical output', () => {
|
|
235
|
+
const input: UpsampleInput = {
|
|
236
|
+
userPrompt: 'a quiet moment',
|
|
237
|
+
entity: { name: 'Leo' },
|
|
238
|
+
persona: { name: 'Leo', backstory: 'jungle king' },
|
|
239
|
+
};
|
|
240
|
+
const a = buildUpsamplePrompt(input);
|
|
241
|
+
const b = buildUpsamplePrompt(input);
|
|
242
|
+
expect(a.system).toBe(b.system);
|
|
243
|
+
expect(a.user).toEqual(b.user);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { formatTimestamp } from '../timeFormat';
|
|
2
|
+
|
|
3
|
+
describe('formatTimestamp — default m:ss', () => {
|
|
4
|
+
it('formats whole minutes and seconds', () => {
|
|
5
|
+
expect(formatTimestamp(0)).toBe('0:00');
|
|
6
|
+
expect(formatTimestamp(5)).toBe('0:05');
|
|
7
|
+
expect(formatTimestamp(65)).toBe('1:05');
|
|
8
|
+
expect(formatTimestamp(125)).toBe('2:05');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('truncates fractional seconds (does not round up)', () => {
|
|
12
|
+
expect(formatTimestamp(59.9)).toBe('0:59');
|
|
13
|
+
expect(formatTimestamp(60.5)).toBe('1:00');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('formatTimestamp — auto h:mm:ss past 60 min', () => {
|
|
18
|
+
it('emits h:mm:ss when seconds >= 3600', () => {
|
|
19
|
+
expect(formatTimestamp(3600)).toBe('1:00:00');
|
|
20
|
+
expect(formatTimestamp(3725)).toBe('1:02:05');
|
|
21
|
+
expect(formatTimestamp(5400)).toBe('1:30:00');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('pads minutes and seconds to two digits in h:mm:ss form', () => {
|
|
25
|
+
expect(formatTimestamp(3661)).toBe('1:01:01');
|
|
26
|
+
expect(formatTimestamp(7322)).toBe('2:02:02');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('stays in m:ss form just under the hour boundary', () => {
|
|
30
|
+
expect(formatTimestamp(3599)).toBe('59:59');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('formatTimestamp — fallback for invalid inputs', () => {
|
|
35
|
+
it('defaults to "0:00"', () => {
|
|
36
|
+
expect(formatTimestamp(NaN)).toBe('0:00');
|
|
37
|
+
expect(formatTimestamp(Infinity)).toBe('0:00');
|
|
38
|
+
expect(formatTimestamp(-Infinity)).toBe('0:00');
|
|
39
|
+
expect(formatTimestamp(-5)).toBe('0:00');
|
|
40
|
+
expect(formatTimestamp(null)).toBe('0:00');
|
|
41
|
+
expect(formatTimestamp(undefined)).toBe('0:00');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('uses a custom fallback when provided', () => {
|
|
45
|
+
expect(formatTimestamp(null, { fallback: '-' })).toBe('-');
|
|
46
|
+
expect(formatTimestamp(undefined, { fallback: '—' })).toBe('—');
|
|
47
|
+
expect(formatTimestamp(NaN, { fallback: '' })).toBe('');
|
|
48
|
+
// The fallback only kicks in for invalid inputs — a valid 0
|
|
49
|
+
// still produces "0:00".
|
|
50
|
+
expect(formatTimestamp(0, { fallback: '-' })).toBe('0:00');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('formatTimestamp — centiseconds for chat citations', () => {
|
|
55
|
+
it('appends .cc when centiseconds: true', () => {
|
|
56
|
+
expect(formatTimestamp(42.34, { centiseconds: true })).toBe('0:42.34');
|
|
57
|
+
expect(formatTimestamp(0, { centiseconds: true })).toBe('0:00.00');
|
|
58
|
+
expect(formatTimestamp(65.5, { centiseconds: true })).toBe('1:05.50');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('pads centiseconds to two digits', () => {
|
|
62
|
+
expect(formatTimestamp(1.01, { centiseconds: true })).toBe('0:01.01');
|
|
63
|
+
expect(formatTimestamp(1.1, { centiseconds: true })).toBe('0:01.10');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('truncates sub-centisecond precision', () => {
|
|
67
|
+
expect(formatTimestamp(0.999, { centiseconds: true })).toBe('0:00.99');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('combines with h:mm:ss when past the hour boundary', () => {
|
|
71
|
+
expect(formatTimestamp(3725.5, { centiseconds: true })).toBe('1:02:05.50');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns fallback unchanged for invalid inputs even with centiseconds', () => {
|
|
75
|
+
expect(formatTimestamp(NaN, { centiseconds: true })).toBe('0:00');
|
|
76
|
+
expect(formatTimestamp(null, { centiseconds: true, fallback: '-' })).toBe(
|
|
77
|
+
'-',
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
});
|