@escapeaihq/client-core 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +27 -2
  2. package/dist/api.d.ts +102 -2
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/api.js +92 -0
  5. package/dist/api.js.map +1 -1
  6. package/dist/audio.d.ts +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/reactor/entityContext.d.ts +34 -0
  12. package/dist/reactor/entityContext.d.ts.map +1 -0
  13. package/dist/reactor/entityContext.js +119 -0
  14. package/dist/reactor/entityContext.js.map +1 -0
  15. package/dist/reactor/entitySearch.d.ts +71 -0
  16. package/dist/reactor/entitySearch.d.ts.map +1 -0
  17. package/dist/reactor/entitySearch.js +93 -0
  18. package/dist/reactor/entitySearch.js.map +1 -0
  19. package/dist/reactor/heliosCommandDispatcher.d.ts +98 -0
  20. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -0
  21. package/dist/reactor/heliosCommandDispatcher.js +181 -0
  22. package/dist/reactor/heliosCommandDispatcher.js.map +1 -0
  23. package/dist/reactor/heliosTools.d.ts +156 -0
  24. package/dist/reactor/heliosTools.d.ts.map +1 -0
  25. package/dist/reactor/heliosTools.js +241 -0
  26. package/dist/reactor/heliosTools.js.map +1 -0
  27. package/dist/reactor/index.d.ts +17 -0
  28. package/dist/reactor/index.d.ts.map +1 -0
  29. package/dist/reactor/index.js +17 -0
  30. package/dist/reactor/index.js.map +1 -0
  31. package/dist/reactor/promptAddonRegistry.d.ts +37 -0
  32. package/dist/reactor/promptAddonRegistry.d.ts.map +1 -0
  33. package/dist/reactor/promptAddonRegistry.js +38 -0
  34. package/dist/reactor/promptAddonRegistry.js.map +1 -0
  35. package/dist/reactor/regenTemplate.d.ts +23 -0
  36. package/dist/reactor/regenTemplate.d.ts.map +1 -0
  37. package/dist/reactor/regenTemplate.js +103 -0
  38. package/dist/reactor/regenTemplate.js.map +1 -0
  39. package/dist/reactor/sceneEntry.d.ts +79 -0
  40. package/dist/reactor/sceneEntry.d.ts.map +1 -0
  41. package/dist/reactor/sceneEntry.js +177 -0
  42. package/dist/reactor/sceneEntry.js.map +1 -0
  43. package/dist/reactor/scenesFromEnrichment.d.ts +67 -0
  44. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -0
  45. package/dist/reactor/scenesFromEnrichment.js +344 -0
  46. package/dist/reactor/scenesFromEnrichment.js.map +1 -0
  47. package/dist/reactor/seedImageOrchestrator.d.ts +81 -0
  48. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -0
  49. package/dist/reactor/seedImageOrchestrator.js +79 -0
  50. package/dist/reactor/seedImageOrchestrator.js.map +1 -0
  51. package/dist/reactor/toolPromptAddon.d.ts +44 -0
  52. package/dist/reactor/toolPromptAddon.d.ts.map +1 -0
  53. package/dist/reactor/toolPromptAddon.js +129 -0
  54. package/dist/reactor/toolPromptAddon.js.map +1 -0
  55. package/dist/reactor/toolPromptAddonId.d.ts +10 -0
  56. package/dist/reactor/toolPromptAddonId.d.ts.map +1 -0
  57. package/dist/reactor/toolPromptAddonId.js +10 -0
  58. package/dist/reactor/toolPromptAddonId.js.map +1 -0
  59. package/dist/reactor/types.d.ts +149 -0
  60. package/dist/reactor/types.d.ts.map +1 -0
  61. package/dist/reactor/types.js +2 -0
  62. package/dist/reactor/types.js.map +1 -0
  63. package/dist/reactor/upsamplePrompt.d.ts +30 -0
  64. package/dist/reactor/upsamplePrompt.d.ts.map +1 -0
  65. package/dist/reactor/upsamplePrompt.js +118 -0
  66. package/dist/reactor/upsamplePrompt.js.map +1 -0
  67. package/dist/timeFormat.d.ts +28 -0
  68. package/dist/timeFormat.d.ts.map +1 -0
  69. package/dist/timeFormat.js +48 -0
  70. package/dist/timeFormat.js.map +1 -0
  71. package/package.json +1 -1
  72. package/src/__tests__/reactor/__snapshots__/regenTemplate.test.ts.snap +5 -0
  73. package/src/__tests__/reactor/__snapshots__/scenesFromEnrichment.test.ts.snap +34 -0
  74. package/src/__tests__/reactor/api-reactor.test.ts +253 -0
  75. package/src/__tests__/reactor/entityContext.test.ts +237 -0
  76. package/src/__tests__/reactor/entitySearch.test.ts +223 -0
  77. package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +438 -0
  78. package/src/__tests__/reactor/heliosTools.test.ts +164 -0
  79. package/src/__tests__/reactor/promptAddonRegistry.test.ts +40 -0
  80. package/src/__tests__/reactor/regenTemplate.test.ts +156 -0
  81. package/src/__tests__/reactor/sceneEntry.test.ts +342 -0
  82. package/src/__tests__/reactor/scenesFromEnrichment.test.ts +760 -0
  83. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +139 -0
  84. package/src/__tests__/reactor/toolPromptAddon.test.ts +104 -0
  85. package/src/__tests__/reactor/upsamplePrompt.test.ts +245 -0
  86. package/src/__tests__/timeFormat.test.ts +80 -0
  87. package/src/api.ts +170 -2
  88. package/src/index.ts +2 -0
  89. package/src/reactor/entityContext.ts +147 -0
  90. package/src/reactor/entitySearch.ts +139 -0
  91. package/src/reactor/heliosCommandDispatcher.ts +293 -0
  92. package/src/reactor/heliosTools.ts +260 -0
  93. package/src/reactor/index.ts +17 -0
  94. package/src/reactor/promptAddonRegistry.ts +52 -0
  95. package/src/reactor/regenTemplate.ts +142 -0
  96. package/src/reactor/sceneEntry.ts +267 -0
  97. package/src/reactor/scenesFromEnrichment.ts +393 -0
  98. package/src/reactor/seedImageOrchestrator.ts +132 -0
  99. package/src/reactor/toolPromptAddon.ts +135 -0
  100. package/src/reactor/toolPromptAddonId.ts +9 -0
  101. package/src/reactor/types.ts +158 -0
  102. package/src/reactor/upsamplePrompt.ts +154 -0
  103. package/src/timeFormat.ts +57 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Tests for the Helios marker parser/stripper used by Phase 3.
3
+ *
4
+ * Coverage matrix:
5
+ * - parseHeliosCommands:
6
+ * - happy path: single SET_SCENE marker
7
+ * - multiple markers — extracted in order
8
+ * - case-insensitive marker name
9
+ * - whitespace tolerance around brackets / colon / argument
10
+ * - zero-arg marker (PAUSE_WORLD)
11
+ * - prose around markers does not interfere
12
+ * - unknown marker silently dropped
13
+ * - malformed markers (no closing bracket / missing quotes for an arg)
14
+ * silently dropped
15
+ * - empty string → []
16
+ * - stripHeliosCommands:
17
+ * - removes markers, preserves surrounding text
18
+ * - collapses extra whitespace introduced by the removal
19
+ * - no markers → unchanged
20
+ * - multiple markers cleanly removed
21
+ */
22
+
23
+ import {
24
+ parseHeliosCommands,
25
+ stripHeliosCommands,
26
+ } from '../../reactor/heliosTools';
27
+
28
+ describe('parseHeliosCommands', () => {
29
+ it('extracts a single SET_SCENE marker', () => {
30
+ const out = parseHeliosCommands(
31
+ 'Sure, switching the world. [SET_SCENE: "a quiet beach at dawn"]',
32
+ );
33
+ expect(out).toEqual([
34
+ { type: 'set_scene', prompt: 'a quiet beach at dawn' },
35
+ ]);
36
+ });
37
+
38
+ it('extracts multiple markers in source order', () => {
39
+ const out = parseHeliosCommands(
40
+ 'Pausing first. [PAUSE_WORLD] Then resuming. [RESUME_WORLD]',
41
+ );
42
+ expect(out).toEqual([
43
+ { type: 'pause_world' },
44
+ { type: 'resume_world' },
45
+ ]);
46
+ });
47
+
48
+ it('is case-insensitive on the marker name', () => {
49
+ const lower = parseHeliosCommands('[set_scene: "x"]');
50
+ const upper = parseHeliosCommands('[SET_SCENE: "x"]');
51
+ const mixed = parseHeliosCommands('[Set_Scene: "x"]');
52
+ expect(lower).toEqual([{ type: 'set_scene', prompt: 'x' }]);
53
+ expect(upper).toEqual([{ type: 'set_scene', prompt: 'x' }]);
54
+ expect(mixed).toEqual([{ type: 'set_scene', prompt: 'x' }]);
55
+ });
56
+
57
+ it('tolerates whitespace around brackets, colon, and argument', () => {
58
+ const out = parseHeliosCommands('[ SET_SCENE : "x" ]');
59
+ expect(out).toEqual([{ type: 'set_scene', prompt: 'x' }]);
60
+ });
61
+
62
+ it('parses PAUSE_WORLD with no argument', () => {
63
+ const out = parseHeliosCommands('[PAUSE_WORLD]');
64
+ expect(out).toEqual([{ type: 'pause_world' }]);
65
+ });
66
+
67
+ it('ignores prose around markers', () => {
68
+ const out = parseHeliosCommands(
69
+ 'Pulling the warmth out of the light. [SET_SCENE: "rainy night"] ' +
70
+ 'Let me know if you want something else.',
71
+ );
72
+ expect(out).toEqual([
73
+ { type: 'set_scene', prompt: 'rainy night' },
74
+ ]);
75
+ });
76
+
77
+ it('silently drops unknown markers', () => {
78
+ const out = parseHeliosCommands(
79
+ 'real one: [PAUSE_WORLD] fake: [FOO: "bar"] another fake: [BAZ]',
80
+ );
81
+ expect(out).toEqual([{ type: 'pause_world' }]);
82
+ });
83
+
84
+ it('silently drops malformed markers (unclosed bracket)', () => {
85
+ const out = parseHeliosCommands('[SET_SCENE: "no close');
86
+ expect(out).toEqual([]);
87
+ });
88
+
89
+ it('silently drops set_scene with missing quoted argument', () => {
90
+ // SET_SCENE requires an arg; bracket-only form is not enough.
91
+ const out = parseHeliosCommands('[SET_SCENE]');
92
+ expect(out).toEqual([]);
93
+ });
94
+
95
+ it('silently drops set_scene with empty arg', () => {
96
+ const out = parseHeliosCommands('[SET_SCENE: ""]');
97
+ expect(out).toEqual([]);
98
+ });
99
+
100
+ it('parses SWAP_SEED with an entity name argument', () => {
101
+ const out = parseHeliosCommands('[SWAP_SEED: "Leo"]');
102
+ expect(out).toEqual([{ type: 'swap_seed', entityName: 'Leo' }]);
103
+ });
104
+
105
+ it('parses RESET_WORLD with no argument', () => {
106
+ const out = parseHeliosCommands('starting fresh [RESET_WORLD]');
107
+ expect(out).toEqual([{ type: 'reset_world' }]);
108
+ });
109
+
110
+ it('returns [] for empty input', () => {
111
+ expect(parseHeliosCommands('')).toEqual([]);
112
+ });
113
+
114
+ it('returns [] when the regex is reused across calls (no state leak)', () => {
115
+ // Sanity check that the module-level regex doesn't carry lastIndex
116
+ // state between invocations.
117
+ parseHeliosCommands('[PAUSE_WORLD] [RESUME_WORLD]');
118
+ const second = parseHeliosCommands('[PAUSE_WORLD]');
119
+ expect(second).toEqual([{ type: 'pause_world' }]);
120
+ });
121
+ });
122
+
123
+ describe('stripHeliosCommands', () => {
124
+ it('removes a single marker and preserves surrounding text', () => {
125
+ const out = stripHeliosCommands('Sure. [PAUSE_WORLD] Done.');
126
+ expect(out).toBe('Sure. Done.'.replace(/\s{2,}/g, ' '));
127
+ });
128
+
129
+ it('returns the input unchanged when there are no markers', () => {
130
+ const input = "Hello there, general.";
131
+ expect(stripHeliosCommands(input)).toBe(input);
132
+ });
133
+
134
+ it('removes multiple markers cleanly', () => {
135
+ const out = stripHeliosCommands(
136
+ 'First [PAUSE_WORLD] then [RESUME_WORLD] last.',
137
+ );
138
+ expect(out).toBe('First then last.'.replace(/ {2,}/g, ' '));
139
+ });
140
+
141
+ it('removes a SET_SCENE marker with a long argument', () => {
142
+ const long =
143
+ '[SET_SCENE: "wide cinematic shot, a man in a long coat on a ' +
144
+ 'cobblestone bridge in a slow grey downpour, single sodium ' +
145
+ 'streetlamp, medium tracking shot, mood: melancholy"]';
146
+ const out = stripHeliosCommands(`Pulling the warmth. ${long}`);
147
+ expect(out).toBe('Pulling the warmth. ');
148
+ });
149
+
150
+ it('drops unknown markers too (user should not see [FOO: "bar"])', () => {
151
+ const out = stripHeliosCommands('answer text [FOO: "bar"] tail');
152
+ expect(out).toBe('answer text tail'.replace(/ {2,}/g, ' '));
153
+ });
154
+
155
+ it('collapses 3+ consecutive newlines to 2 after marker removal', () => {
156
+ const out = stripHeliosCommands('intro\n\n\n[PAUSE_WORLD]\n\n\nouttro');
157
+ // The marker line evaporates, leaving extra newlines; we cap at 2.
158
+ expect(out).toBe('intro\n\nouttro');
159
+ });
160
+
161
+ it('returns empty string for empty input', () => {
162
+ expect(stripHeliosCommands('')).toBe('');
163
+ });
164
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Tests for the prompt-addon registry — guards against accidental
3
+ * deletion of entries that the persona UI relies on.
4
+ */
5
+
6
+ import { HELIOS_WORLD_STEERING_ADDON_ID } from '../../reactor/toolPromptAddonId';
7
+ import {
8
+ KNOWN_PROMPT_ADDONS,
9
+ getPromptAddonDescriptor,
10
+ } from '../../reactor/promptAddonRegistry';
11
+
12
+ describe('KNOWN_PROMPT_ADDONS', () => {
13
+ it('contains the Helios world-steering addon', () => {
14
+ const ids = KNOWN_PROMPT_ADDONS.map(a => a.id);
15
+ expect(ids).toContain(HELIOS_WORLD_STEERING_ADDON_ID);
16
+ });
17
+
18
+ it('every entry has a non-empty label + description', () => {
19
+ for (const addon of KNOWN_PROMPT_ADDONS) {
20
+ expect(addon.label.trim()).not.toBe('');
21
+ expect(addon.description.trim()).not.toBe('');
22
+ }
23
+ });
24
+
25
+ it('ids are unique', () => {
26
+ const ids = KNOWN_PROMPT_ADDONS.map(a => a.id);
27
+ expect(new Set(ids).size).toBe(ids.length);
28
+ });
29
+ });
30
+
31
+ describe('getPromptAddonDescriptor', () => {
32
+ it('returns the descriptor for a known id', () => {
33
+ const d = getPromptAddonDescriptor(HELIOS_WORLD_STEERING_ADDON_ID);
34
+ expect(d?.label).toBe('Helios world steering');
35
+ });
36
+
37
+ it('returns undefined for an unknown id', () => {
38
+ expect(getPromptAddonDescriptor('not-a-real-addon')).toBeUndefined();
39
+ });
40
+ });
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Tests for `buildRegenPrompt` — the pure, deterministic regen-prompt
3
+ * builder consumed by the live RegenForm preview.
4
+ *
5
+ * Coverage:
6
+ * - Persona-present and persona-absent cases (persona snippet injection)
7
+ * - Custom-style happy path + throw-on-missing-customStyle invariant
8
+ * - identity preservation toggle changes the opening sentence
9
+ * - Creative direction is appended verbatim at the end
10
+ * - Framing / lighting keywords surface in the output
11
+ * - Snapshot a couple of representative outputs
12
+ */
13
+
14
+ import { buildRegenPrompt } from '../../reactor/regenTemplate';
15
+ import type { RegenTemplateInput } from '../../reactor/types';
16
+
17
+ const baseInput = (overrides: Partial<RegenTemplateInput> = {}): RegenTemplateInput => ({
18
+ aspectRatio: '16:9',
19
+ preserveIdentity: true,
20
+ framing: 'medium',
21
+ lighting: 'cinematic',
22
+ styleFamily: 'photoreal',
23
+ entity: { name: 'Leo', sceneContext: 'standing on a rocky outcrop in the jungle' },
24
+ ...overrides,
25
+ });
26
+
27
+ describe('buildRegenPrompt', () => {
28
+ it('opens with "Reframe {name} as a wide 16:9" when preserveIdentity is true', () => {
29
+ const out = buildRegenPrompt(baseInput({ preserveIdentity: true }));
30
+ expect(out.startsWith('Reframe Leo as a wide 16:9 cinematic shot')).toBe(true);
31
+ expect(out).toContain('preserving their distinctive features');
32
+ });
33
+
34
+ it('opens with "Reinterpret" when preserveIdentity is false', () => {
35
+ const out = buildRegenPrompt(baseInput({ preserveIdentity: false }));
36
+ expect(out.startsWith('Reinterpret Leo as a wide 16:9 cinematic shot')).toBe(true);
37
+ expect(out).toContain('taking creative liberties');
38
+ });
39
+
40
+ it('always restates the 16:9 framing requirement', () => {
41
+ const out = buildRegenPrompt(baseInput());
42
+ expect(out).toContain('16:9 framing required');
43
+ });
44
+
45
+ it('includes framing and lighting keyword phrases', () => {
46
+ const out = buildRegenPrompt(
47
+ baseInput({ framing: 'close-up', lighting: 'golden-hour' }),
48
+ );
49
+ expect(out).toContain('close-up');
50
+ expect(out).toContain('golden-hour');
51
+ });
52
+
53
+ it('with persona — injects the persona backstory line', () => {
54
+ const out = buildRegenPrompt(
55
+ baseInput({
56
+ persona: { name: 'Leo', backstory: 'A noble jungle king who lost his pride.' },
57
+ }),
58
+ );
59
+ expect(out).toContain('Persona backstory for Leo');
60
+ expect(out).toContain('A noble jungle king who lost his pride.');
61
+ });
62
+
63
+ it('without persona — omits the persona section entirely', () => {
64
+ const out = buildRegenPrompt(baseInput());
65
+ expect(out).not.toContain('Persona backstory');
66
+ });
67
+
68
+ it('custom style — uses customStyle text in place of a preset', () => {
69
+ const out = buildRegenPrompt(
70
+ baseInput({
71
+ styleFamily: 'custom',
72
+ customStyle: 'shot on hand-painted celluloid with visible brush strokes',
73
+ }),
74
+ );
75
+ expect(out).toContain('hand-painted celluloid');
76
+ // None of the preset descriptors leak through.
77
+ expect(out).not.toContain('photorealistic style');
78
+ });
79
+
80
+ it('custom style — throws when customStyle is missing', () => {
81
+ expect(() =>
82
+ buildRegenPrompt(baseInput({ styleFamily: 'custom' })),
83
+ ).toThrow(/customStyle required/);
84
+ });
85
+
86
+ it('custom style — throws when customStyle is empty/whitespace', () => {
87
+ expect(() =>
88
+ buildRegenPrompt(
89
+ baseInput({ styleFamily: 'custom', customStyle: ' ' }),
90
+ ),
91
+ ).toThrow(/customStyle required/);
92
+ });
93
+
94
+ it('creative direction — appended verbatim at the end', () => {
95
+ const direction = 'Make it feel like a Studio Ghibli summer afternoon, please.';
96
+ const out = buildRegenPrompt(baseInput({ creativeDirection: direction }));
97
+ expect(out.endsWith(direction)).toBe(true);
98
+ });
99
+
100
+ it('clothing and pose overrides surface when present, skipped when blank', () => {
101
+ const withOverrides = buildRegenPrompt(
102
+ baseInput({
103
+ clothingOverride: 'crimson velvet cloak with gold trim',
104
+ poseOverride: 'mid-leap with arms outstretched',
105
+ }),
106
+ );
107
+ expect(withOverrides).toContain('Wardrobe: crimson velvet cloak');
108
+ expect(withOverrides).toContain('Pose / action: mid-leap with arms outstretched');
109
+
110
+ const without = buildRegenPrompt(
111
+ baseInput({ clothingOverride: '', poseOverride: ' ' }),
112
+ );
113
+ expect(without).not.toContain('Wardrobe:');
114
+ expect(without).not.toContain('Pose / action:');
115
+ });
116
+
117
+ it('entity scene context — included when present, skipped when absent', () => {
118
+ const withContext = buildRegenPrompt(baseInput());
119
+ expect(withContext).toContain('rocky outcrop in the jungle');
120
+
121
+ const noContext = buildRegenPrompt(
122
+ baseInput({ entity: { name: 'Leo' } }),
123
+ );
124
+ expect(noContext).not.toContain('Character context');
125
+ });
126
+
127
+ it('is deterministic — repeated calls return identical strings', () => {
128
+ const input = baseInput({
129
+ persona: { name: 'Leo', backstory: 'jungle king' },
130
+ creativeDirection: 'add fireflies',
131
+ });
132
+ expect(buildRegenPrompt(input)).toBe(buildRegenPrompt(input));
133
+ });
134
+
135
+ it('snapshot — full prompt with persona, overrides, creative direction', () => {
136
+ const out = buildRegenPrompt(
137
+ baseInput({
138
+ framing: 'medium-close-up',
139
+ lighting: 'golden-hour',
140
+ styleFamily: 'film-35mm',
141
+ persona: {
142
+ name: 'Leo',
143
+ backstory: 'A noble jungle king who lost his pride to poachers years ago.',
144
+ },
145
+ clothingOverride: 'weathered leather mantle',
146
+ creativeDirection: 'Lean into wistful melancholy.',
147
+ }),
148
+ );
149
+ expect(out).toMatchSnapshot();
150
+ });
151
+
152
+ it('snapshot — minimal input (no persona, no overrides)', () => {
153
+ const out = buildRegenPrompt(baseInput());
154
+ expect(out).toMatchSnapshot();
155
+ });
156
+ });