@escapeaihq/client-core 0.12.0 → 0.49.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 (242) hide show
  1. package/README.md +32 -7
  2. package/dist/adapters/capabilities.d.ts +10 -0
  3. package/dist/adapters/capabilities.d.ts.map +1 -0
  4. package/dist/adapters/capabilities.js +2 -0
  5. package/dist/adapters/capabilities.js.map +1 -0
  6. package/dist/adapters/chatAdapter.d.ts +38 -0
  7. package/dist/adapters/chatAdapter.d.ts.map +1 -0
  8. package/dist/adapters/chatAdapter.js +88 -0
  9. package/dist/adapters/chatAdapter.js.map +1 -0
  10. package/dist/adapters/directorAdapter.d.ts +62 -0
  11. package/dist/adapters/directorAdapter.d.ts.map +1 -0
  12. package/dist/adapters/directorAdapter.js +71 -0
  13. package/dist/adapters/directorAdapter.js.map +1 -0
  14. package/dist/adapters/imageAdapter.d.ts +44 -0
  15. package/dist/adapters/imageAdapter.d.ts.map +1 -0
  16. package/dist/adapters/imageAdapter.js +73 -0
  17. package/dist/adapters/imageAdapter.js.map +1 -0
  18. package/dist/adapters/index.d.ts +47 -0
  19. package/dist/adapters/index.d.ts.map +1 -0
  20. package/dist/adapters/index.js +41 -0
  21. package/dist/adapters/index.js.map +1 -0
  22. package/dist/adapters/registry.d.ts +98 -0
  23. package/dist/adapters/registry.d.ts.map +1 -0
  24. package/dist/adapters/registry.js +106 -0
  25. package/dist/adapters/registry.js.map +1 -0
  26. package/dist/adapters/worldAdapter.d.ts +142 -0
  27. package/dist/adapters/worldAdapter.d.ts.map +1 -0
  28. package/dist/adapters/worldAdapter.js +164 -0
  29. package/dist/adapters/worldAdapter.js.map +1 -0
  30. package/dist/admin.d.ts +323 -0
  31. package/dist/admin.d.ts.map +1 -0
  32. package/dist/admin.js +198 -0
  33. package/dist/admin.js.map +1 -0
  34. package/dist/api.d.ts +1512 -4
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +820 -52
  37. package/dist/api.js.map +1 -1
  38. package/dist/audio.d.ts +33 -1
  39. package/dist/audio.d.ts.map +1 -1
  40. package/dist/audio.js +4 -1
  41. package/dist/audio.js.map +1 -1
  42. package/dist/castProjection.d.ts +35 -0
  43. package/dist/castProjection.d.ts.map +1 -0
  44. package/dist/castProjection.js +80 -0
  45. package/dist/castProjection.js.map +1 -0
  46. package/dist/conversation/binding.d.ts +77 -0
  47. package/dist/conversation/binding.d.ts.map +1 -0
  48. package/dist/conversation/binding.js +57 -0
  49. package/dist/conversation/binding.js.map +1 -0
  50. package/dist/conversation/controller.d.ts +209 -0
  51. package/dist/conversation/controller.d.ts.map +1 -0
  52. package/dist/conversation/controller.js +350 -0
  53. package/dist/conversation/controller.js.map +1 -0
  54. package/dist/conversation/effectiveModel.d.ts +62 -0
  55. package/dist/conversation/effectiveModel.d.ts.map +1 -0
  56. package/dist/conversation/effectiveModel.js +73 -0
  57. package/dist/conversation/effectiveModel.js.map +1 -0
  58. package/dist/conversation/index.d.ts +27 -0
  59. package/dist/conversation/index.d.ts.map +1 -0
  60. package/dist/conversation/index.js +27 -0
  61. package/dist/conversation/index.js.map +1 -0
  62. package/dist/conversation/participant.d.ts +66 -0
  63. package/dist/conversation/participant.d.ts.map +1 -0
  64. package/dist/conversation/participant.js +36 -0
  65. package/dist/conversation/participant.js.map +1 -0
  66. package/dist/conversation/presence.d.ts +56 -0
  67. package/dist/conversation/presence.d.ts.map +1 -0
  68. package/dist/conversation/presence.js +34 -0
  69. package/dist/conversation/presence.js.map +1 -0
  70. package/dist/conversation/presenceBus.d.ts +42 -0
  71. package/dist/conversation/presenceBus.d.ts.map +1 -0
  72. package/dist/conversation/presenceBus.js +81 -0
  73. package/dist/conversation/presenceBus.js.map +1 -0
  74. package/dist/conversation/presenceRegistry.d.ts +49 -0
  75. package/dist/conversation/presenceRegistry.d.ts.map +1 -0
  76. package/dist/conversation/presenceRegistry.js +59 -0
  77. package/dist/conversation/presenceRegistry.js.map +1 -0
  78. package/dist/conversation/roster.d.ts +72 -0
  79. package/dist/conversation/roster.d.ts.map +1 -0
  80. package/dist/conversation/roster.js +69 -0
  81. package/dist/conversation/roster.js.map +1 -0
  82. package/dist/conversation/rosterProjection.d.ts +52 -0
  83. package/dist/conversation/rosterProjection.d.ts.map +1 -0
  84. package/dist/conversation/rosterProjection.js +74 -0
  85. package/dist/conversation/rosterProjection.js.map +1 -0
  86. package/dist/conversation/router.d.ts +74 -0
  87. package/dist/conversation/router.d.ts.map +1 -0
  88. package/dist/conversation/router.js +58 -0
  89. package/dist/conversation/router.js.map +1 -0
  90. package/dist/conversation/runtime.d.ts +64 -0
  91. package/dist/conversation/runtime.d.ts.map +1 -0
  92. package/dist/conversation/runtime.js +172 -0
  93. package/dist/conversation/runtime.js.map +1 -0
  94. package/dist/conversation/types.d.ts +99 -0
  95. package/dist/conversation/types.d.ts.map +1 -0
  96. package/dist/conversation/types.js +13 -0
  97. package/dist/conversation/types.js.map +1 -0
  98. package/dist/conversation/voice.d.ts +185 -0
  99. package/dist/conversation/voice.d.ts.map +1 -0
  100. package/dist/conversation/voice.js +307 -0
  101. package/dist/conversation/voice.js.map +1 -0
  102. package/dist/graphSchema.d.ts +201 -13
  103. package/dist/graphSchema.d.ts.map +1 -1
  104. package/dist/graphSchema.js +258 -9
  105. package/dist/graphSchema.js.map +1 -1
  106. package/dist/http.d.ts +20 -0
  107. package/dist/http.d.ts.map +1 -0
  108. package/dist/http.js +57 -0
  109. package/dist/http.js.map +1 -0
  110. package/dist/index.d.ts +6 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +9 -0
  113. package/dist/index.js.map +1 -1
  114. package/dist/platformAssistant.d.ts +155 -0
  115. package/dist/platformAssistant.d.ts.map +1 -0
  116. package/dist/platformAssistant.js +256 -0
  117. package/dist/platformAssistant.js.map +1 -0
  118. package/dist/reactor/chunkDistribution.d.ts +43 -0
  119. package/dist/reactor/chunkDistribution.d.ts.map +1 -0
  120. package/dist/reactor/chunkDistribution.js +85 -0
  121. package/dist/reactor/chunkDistribution.js.map +1 -0
  122. package/dist/reactor/index.d.ts +2 -0
  123. package/dist/reactor/index.d.ts.map +1 -1
  124. package/dist/reactor/index.js +5 -0
  125. package/dist/reactor/index.js.map +1 -1
  126. package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
  127. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
  128. package/dist/reactor/longLiveCommandDispatcher.js +87 -0
  129. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
  130. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
  131. package/dist/reactor/scenesFromEnrichment.js +2 -66
  132. package/dist/reactor/scenesFromEnrichment.js.map +1 -1
  133. package/dist/reactor/seedImageOrchestrator.d.ts +6 -9
  134. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  135. package/dist/reactor/seedImageOrchestrator.js +12 -13
  136. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  137. package/dist/reactor/storyTimeline.d.ts +44 -0
  138. package/dist/reactor/storyTimeline.d.ts.map +1 -0
  139. package/dist/reactor/storyTimeline.js +95 -0
  140. package/dist/reactor/storyTimeline.js.map +1 -0
  141. package/dist/storyGraph.d.ts +70 -0
  142. package/dist/storyGraph.d.ts.map +1 -0
  143. package/dist/storyGraph.js +178 -0
  144. package/dist/storyGraph.js.map +1 -0
  145. package/dist/vision/VisionSourceController.d.ts +127 -0
  146. package/dist/vision/VisionSourceController.d.ts.map +1 -0
  147. package/dist/vision/VisionSourceController.js +284 -0
  148. package/dist/vision/VisionSourceController.js.map +1 -0
  149. package/dist/vision/index.d.ts +4 -0
  150. package/dist/vision/index.d.ts.map +1 -1
  151. package/dist/vision/index.js +2 -0
  152. package/dist/vision/index.js.map +1 -1
  153. package/dist/vision/sourceKinds.d.ts +65 -0
  154. package/dist/vision/sourceKinds.d.ts.map +1 -0
  155. package/dist/vision/sourceKinds.js +26 -0
  156. package/dist/vision/sourceKinds.js.map +1 -0
  157. package/dist/websocket.d.ts +92 -0
  158. package/dist/websocket.d.ts.map +1 -1
  159. package/dist/websocket.js.map +1 -1
  160. package/package.json +1 -1
  161. package/src/__tests__/adapters-capabilities.test.ts +46 -0
  162. package/src/__tests__/adapters-chat.test.ts +172 -0
  163. package/src/__tests__/adapters-director.test.ts +95 -0
  164. package/src/__tests__/adapters-image.test.ts +133 -0
  165. package/src/__tests__/adapters-platform.test.ts +95 -0
  166. package/src/__tests__/adapters-registry.test.ts +189 -0
  167. package/src/__tests__/adapters-world.test.ts +296 -0
  168. package/src/__tests__/admin.test.ts +312 -0
  169. package/src/__tests__/adventures-party.test.ts +219 -0
  170. package/src/__tests__/adventures.test.ts +282 -0
  171. package/src/__tests__/api-pollers.test.ts +4 -0
  172. package/src/__tests__/api.clip-lookup.test.ts +64 -0
  173. package/src/__tests__/api.list-images-filters.test.ts +103 -0
  174. package/src/__tests__/api.test.ts +553 -0
  175. package/src/__tests__/audio.test.ts +65 -0
  176. package/src/__tests__/cast.test.ts +95 -0
  177. package/src/__tests__/castProjection.test.ts +167 -0
  178. package/src/__tests__/conversation/binding.test.ts +62 -0
  179. package/src/__tests__/conversation/controller.test.ts +732 -0
  180. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  181. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  182. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  183. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  184. package/src/__tests__/conversation/roster.test.ts +100 -0
  185. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  186. package/src/__tests__/conversation/router.test.ts +81 -0
  187. package/src/__tests__/conversation/runtime.test.ts +206 -0
  188. package/src/__tests__/conversation/voice.test.ts +440 -0
  189. package/src/__tests__/documents.test.ts +360 -0
  190. package/src/__tests__/graphSchema.test.ts +218 -9
  191. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  192. package/src/__tests__/monitoring.test.ts +162 -0
  193. package/src/__tests__/persona-generation.test.ts +352 -0
  194. package/src/__tests__/platformAssistant.test.ts +484 -0
  195. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  196. package/src/__tests__/regeneration.test.ts +486 -0
  197. package/src/__tests__/stories.test.ts +171 -0
  198. package/src/__tests__/storyGraph.test.ts +134 -0
  199. package/src/__tests__/tools-wrappers.test.ts +272 -0
  200. package/src/__tests__/videoGraph.test.ts +94 -0
  201. package/src/__tests__/websocket.test.ts +263 -0
  202. package/src/adapters/capabilities.ts +24 -0
  203. package/src/adapters/chatAdapter.ts +114 -0
  204. package/src/adapters/directorAdapter.ts +126 -0
  205. package/src/adapters/imageAdapter.ts +100 -0
  206. package/src/adapters/index.ts +67 -0
  207. package/src/adapters/registry.ts +159 -0
  208. package/src/adapters/worldAdapter.ts +272 -0
  209. package/src/admin.ts +517 -0
  210. package/src/api.ts +2215 -95
  211. package/src/audio.ts +35 -0
  212. package/src/castProjection.ts +95 -0
  213. package/src/conversation/binding.ts +100 -0
  214. package/src/conversation/controller.ts +447 -0
  215. package/src/conversation/effectiveModel.ts +111 -0
  216. package/src/conversation/index.ts +27 -0
  217. package/src/conversation/participant.ts +71 -0
  218. package/src/conversation/presence.ts +60 -0
  219. package/src/conversation/presenceBus.ts +109 -0
  220. package/src/conversation/presenceRegistry.ts +83 -0
  221. package/src/conversation/roster.ts +111 -0
  222. package/src/conversation/rosterProjection.ts +98 -0
  223. package/src/conversation/router.ts +96 -0
  224. package/src/conversation/runtime.ts +188 -0
  225. package/src/conversation/types.ts +100 -0
  226. package/src/conversation/voice.ts +402 -0
  227. package/src/graphSchema.ts +396 -13
  228. package/src/http.ts +72 -0
  229. package/src/index.ts +9 -0
  230. package/src/platformAssistant.ts +347 -0
  231. package/src/reactor/chunkDistribution.ts +98 -0
  232. package/src/reactor/index.ts +5 -0
  233. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  234. package/src/reactor/scenesFromEnrichment.ts +11 -76
  235. package/src/reactor/seedImageOrchestrator.ts +12 -13
  236. package/src/reactor/storyTimeline.ts +127 -0
  237. package/src/storyGraph.ts +298 -0
  238. package/src/vision/VisionSourceController.ts +354 -0
  239. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  240. package/src/vision/index.ts +13 -0
  241. package/src/vision/sourceKinds.ts +75 -0
  242. package/src/websocket.ts +99 -3
@@ -11,6 +11,10 @@
11
11
  */
12
12
 
13
13
  import { ChatWebSocket } from '../websocket';
14
+ import type { ChatWsEvent } from '../websocket';
15
+ import type { DmDirectiveEvent, DmDirectiveKind } from '../api';
16
+ import { ConversationRuntime } from '../conversation/runtime';
17
+ import { PresenceKind } from '../conversation/participant';
14
18
 
15
19
  interface FakeWebSocket {
16
20
  url: string;
@@ -351,3 +355,262 @@ describe('ChatWebSocket — back-compat with static authToken', () => {
351
355
  expect(lastSocket().url).toBe('ws://test/chat');
352
356
  });
353
357
  });
358
+
359
+ describe('ChatWebSocket — send() entityId (persona↔character binding)', () => {
360
+ it('serializes entityId into the send frame when a bound persona is active', async () => {
361
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
362
+ const connectPromise = ws.connect();
363
+ await flushMicrotasks();
364
+ lastSocket().simulateOpen();
365
+ await connectPromise;
366
+
367
+ ws.send('hello', { videoId: 'v1', entityId: 'ent-123' });
368
+
369
+ expect(lastSocket().sent).toHaveLength(1);
370
+ const frame = JSON.parse(lastSocket().sent[0] as string);
371
+ expect(frame).toMatchObject({
372
+ action: 'send',
373
+ prompt: 'hello',
374
+ videoId: 'v1',
375
+ entityId: 'ent-123',
376
+ });
377
+ });
378
+
379
+ it('omits entityId from the send frame when the persona is unbound (land-dark)', async () => {
380
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
381
+ const connectPromise = ws.connect();
382
+ await flushMicrotasks();
383
+ lastSocket().simulateOpen();
384
+ await connectPromise;
385
+
386
+ ws.send('hello', { videoId: 'v1' });
387
+
388
+ const frame = JSON.parse(lastSocket().sent[0] as string);
389
+ expect(frame).not.toHaveProperty('entityId');
390
+ });
391
+ });
392
+
393
+ describe('ChatWebSocket — send() personaId (M8 Phase D memory namespace)', () => {
394
+ it('serializes personaId into the send frame when a persona is active', async () => {
395
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
396
+ const connectPromise = ws.connect();
397
+ await flushMicrotasks();
398
+ lastSocket().simulateOpen();
399
+ await connectPromise;
400
+
401
+ ws.send('hello', { videoId: 'v1', personaId: 'persona-42' });
402
+
403
+ const frame = JSON.parse(lastSocket().sent[0] as string);
404
+ expect(frame).toMatchObject({
405
+ action: 'send',
406
+ prompt: 'hello',
407
+ videoId: 'v1',
408
+ personaId: 'persona-42',
409
+ });
410
+ });
411
+
412
+ it('omits personaId from the send frame when no persona is active (land-dark)', async () => {
413
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
414
+ const connectPromise = ws.connect();
415
+ await flushMicrotasks();
416
+ lastSocket().simulateOpen();
417
+ await connectPromise;
418
+
419
+ ws.send('hello', { videoId: 'v1' });
420
+
421
+ const frame = JSON.parse(lastSocket().sent[0] as string);
422
+ expect(frame).not.toHaveProperty('personaId');
423
+ });
424
+ });
425
+
426
+ describe('ChatWebSocket — send() adventureSessionId (M9 Adventure Runtime Phase 8a)', () => {
427
+ it('serializes adventureSessionId into the send frame when an adventure is active', async () => {
428
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
429
+ const connectPromise = ws.connect();
430
+ await flushMicrotasks();
431
+ lastSocket().simulateOpen();
432
+ await connectPromise;
433
+
434
+ ws.send('I open the door', {
435
+ videoId: 'v1',
436
+ personaId: 'dm-1',
437
+ adventureSessionId: 'adv-123',
438
+ });
439
+
440
+ const frame = JSON.parse(lastSocket().sent[0] as string);
441
+ expect(frame).toMatchObject({
442
+ action: 'send',
443
+ prompt: 'I open the door',
444
+ videoId: 'v1',
445
+ personaId: 'dm-1',
446
+ adventureSessionId: 'adv-123',
447
+ });
448
+ });
449
+
450
+ it('omits adventureSessionId from the send frame when no adventure is active (land-dark)', async () => {
451
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
452
+ const connectPromise = ws.connect();
453
+ await flushMicrotasks();
454
+ lastSocket().simulateOpen();
455
+ await connectPromise;
456
+
457
+ ws.send('hello', { videoId: 'v1' });
458
+
459
+ const frame = JSON.parse(lastSocket().sent[0] as string);
460
+ expect(frame).not.toHaveProperty('adventureSessionId');
461
+ });
462
+ });
463
+
464
+ describe('ChatWebSocket — send() partyPersonaIds (M10 Story Engine Phase 9a)', () => {
465
+ it('serializes partyPersonaIds into the send frame when a party is present', async () => {
466
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
467
+ const connectPromise = ws.connect();
468
+ await flushMicrotasks();
469
+ lastSocket().simulateOpen();
470
+ await connectPromise;
471
+
472
+ ws.send('I open the door', {
473
+ videoId: 'v1',
474
+ personaId: 'dm-1',
475
+ adventureSessionId: 'adv-123',
476
+ partyPersonaIds: ['aragorn', 'legolas'],
477
+ });
478
+
479
+ const frame = JSON.parse(lastSocket().sent[0] as string);
480
+ expect(frame).toMatchObject({
481
+ action: 'send',
482
+ adventureSessionId: 'adv-123',
483
+ partyPersonaIds: ['aragorn', 'legolas'],
484
+ });
485
+ });
486
+
487
+ it('omits partyPersonaIds from the send frame when no party is provided (land-dark)', async () => {
488
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
489
+ const connectPromise = ws.connect();
490
+ await flushMicrotasks();
491
+ lastSocket().simulateOpen();
492
+ await connectPromise;
493
+
494
+ ws.send('hello', { videoId: 'v1' });
495
+
496
+ const frame = JSON.parse(lastSocket().sent[0] as string);
497
+ expect(frame).not.toHaveProperty('partyPersonaIds');
498
+ });
499
+ });
500
+
501
+ describe('ChatWsEvent — M10 9a multi-persona protocol additions', () => {
502
+ it('narrows a turn_changed event to its personaId / previousPersonaId fields', () => {
503
+ const event: ChatWsEvent = {
504
+ type: 'turn_changed',
505
+ timestamp: 1.5,
506
+ personaId: 'aragorn',
507
+ previousPersonaId: 'dm-1',
508
+ };
509
+
510
+ // Exhaustive narrowing: only the turn_changed case carries personaId
511
+ // as a required field alongside previousPersonaId.
512
+ expect(event.type).toBe('turn_changed');
513
+ if (event.type === 'turn_changed') {
514
+ expect(event.personaId).toBe('aragorn');
515
+ expect(event.previousPersonaId).toBe('dm-1');
516
+ }
517
+ });
518
+
519
+ it('allows the first-turn turn_changed without a previousPersonaId', () => {
520
+ const event: ChatWsEvent = {
521
+ type: 'turn_changed',
522
+ personaId: 'dm-1',
523
+ };
524
+ if (event.type === 'turn_changed') {
525
+ expect(event.previousPersonaId).toBeUndefined();
526
+ }
527
+ });
528
+
529
+ it('allows an optional personaId on token / done / citation / image / audio_chunk frames', () => {
530
+ const token: ChatWsEvent = { type: 'token', content: 'hi', personaId: 'aragorn' };
531
+ const done: ChatWsEvent = { type: 'done', personaId: 'aragorn' };
532
+ const citation: ChatWsEvent = {
533
+ type: 'citation',
534
+ citation: { videoId: 'v1', t0: 0, t1: 1 },
535
+ personaId: 'aragorn',
536
+ };
537
+ const image: ChatWsEvent = {
538
+ type: 'image',
539
+ imageUrl: 'https://x/i.png',
540
+ personaId: 'aragorn',
541
+ };
542
+ const audio: ChatWsEvent = {
543
+ type: 'audio_chunk',
544
+ audio: 'AAAA',
545
+ format: 'mp3',
546
+ personaId: 'aragorn',
547
+ };
548
+
549
+ for (const ev of [token, done, citation, image, audio]) {
550
+ if (
551
+ ev.type === 'token' ||
552
+ ev.type === 'done' ||
553
+ ev.type === 'citation' ||
554
+ ev.type === 'image' ||
555
+ ev.type === 'audio_chunk'
556
+ ) {
557
+ expect(ev.personaId).toBe('aragorn');
558
+ }
559
+ }
560
+ });
561
+
562
+ it('keeps personaId optional (land-dark: existing frames omit it)', () => {
563
+ // No personaId — the existing non-orchestrated shape still type-checks.
564
+ const token: ChatWsEvent = { type: 'token', content: 'hi' };
565
+ if (token.type === 'token') {
566
+ expect(token.personaId).toBeUndefined();
567
+ }
568
+ });
569
+ });
570
+
571
+ describe('ChatWsEvent — Dashboard Spec A dm_directive (A-DM0, land-dark)', () => {
572
+ it('narrows a dm_directive event to its directive / params fields', () => {
573
+ const event: ChatWsEvent = {
574
+ type: 'dm_directive',
575
+ timestamp: 2.0,
576
+ directive: 'enter_world',
577
+ params: { prompt: 'Walk into the fog' },
578
+ };
579
+ expect(event.type).toBe('dm_directive');
580
+ if (event.type === 'dm_directive') {
581
+ expect(event.directive).toBe('enter_world');
582
+ expect(event.params.prompt).toBe('Walk into the fog');
583
+ }
584
+ });
585
+
586
+ it('accepts each allowlisted directive kind (single-sourced with the backend)', () => {
587
+ const kinds: DmDirectiveKind[] = [
588
+ 'enter_world',
589
+ 'exit_world',
590
+ 'seek_video',
591
+ 'set_experience_source',
592
+ ];
593
+ for (const directive of kinds) {
594
+ const event: DmDirectiveEvent = { type: 'dm_directive', directive, params: {} };
595
+ expect(event.directive).toBe(directive);
596
+ }
597
+ });
598
+
599
+ it('is dropped by ConversationRuntime.applyFrame (default arm, no state change)', () => {
600
+ const rt = new ConversationRuntime({
601
+ boundPersonaId: 'p-dm',
602
+ participants: [
603
+ {
604
+ personaId: 'p-dm',
605
+ isDm: true,
606
+ displayName: 'The Narrator',
607
+ presence: PresenceKind.PRESENCE_FACE_2D,
608
+ },
609
+ ],
610
+ });
611
+ const before = rt.getState();
612
+ rt.applyFrame({ type: 'dm_directive', directive: 'exit_world', params: {} });
613
+ // Behavior-preserving: the runtime state is untouched (no consumer wired).
614
+ expect(rt.getState()).toEqual(before);
615
+ });
616
+ });
@@ -0,0 +1,24 @@
1
+ import type { ChatModelCapability } from '../api';
2
+ // ChatModelCapability ('tools'|'vision'|'audio'|'thinking', api.ts:499) is the single
3
+ // source of truth for chat caps; it mirrors shared/model_config.py CAPABILITY_* (:32-44).
4
+ // R1 REUSES it rather than re-declaring those four strings.
5
+
6
+ /** Net-new capabilities introduced by R1's image/world/director domains.
7
+ * No backend chat-enum equivalent yet; TS-only. */
8
+ export type ImageCapability = 'image_gen' | 'image_edit' | 'identity_preserve';
9
+ // NOTE: 'set_scene' / 'swap_seed' are string-identical to HeliosCommand WS
10
+ // markers (reactor/heliosTools.ts) by coincidence only — these are adapter
11
+ // *capability* advertisements, not the browser→Reactor command vocabulary.
12
+ // They are deliberately NOT unified with HeliosCommand.
13
+ // 'scene_cut' is a HARD, memory-purging transition that LongLive-v2 supports
14
+ // (purges per-scene memory + resets the per-scene chunk counter) and Helios
15
+ // does NOT — Helios only continuously MORPHS the scene (its `set_scene`).
16
+ // Additive member: the helios adapter omits it, the longlive adapter adds it,
17
+ // yielding the asymmetric capability matrix (helios swap_seed-not-scene_cut;
18
+ // longlive scene_cut-not-swap_seed).
19
+ export type WorldCapability = 'world_stream' | 'set_scene' | 'swap_seed' | 'pause_resume' | 'scene_cut';
20
+ export type DirectorCapability = 'timeline_schedule' | 'enrichment_driven';
21
+
22
+ /** Registry capability vocabulary = the EXISTING chat union EXTENDED with the
23
+ * net-new domains. One union; no parallel CAPABILITY map. */
24
+ export type Capability = ChatModelCapability | ImageCapability | WorldCapability | DirectorCapability;
@@ -0,0 +1,114 @@
1
+ import {
2
+ AdapterRegistry,
3
+ ROUTE_DEFAULT,
4
+ ROUTE_FALLBACK,
5
+ type NamedRoute,
6
+ type ModelAdapterDescriptor,
7
+ } from './registry';
8
+ import type { ApiClient, ChatModelInfo } from '../api';
9
+
10
+ /**
11
+ * Chat-domain adapter descriptor — a {@link ModelAdapterDescriptor} carrying
12
+ * the two chat-only sizing fields the picker UI wants to surface. Everything
13
+ * else (id / displayName / provider / capabilities) is inherited unchanged.
14
+ */
15
+ export interface ChatAdapterDescriptor extends ModelAdapterDescriptor {
16
+ contextWindow: number;
17
+ maxOutputTokens: number;
18
+ }
19
+
20
+ /**
21
+ * Map one {@link ChatModelInfo} from `GET /api/v1/chat/models` to a
22
+ * {@link ChatAdapterDescriptor}. PURE — no I/O, no mutation of `info`.
23
+ *
24
+ * `capabilities` is copied VERBATIM (a fresh array, same members/order) — the
25
+ * backend (`shared/model_config.py:CAPABILITY_*`) is the single source of
26
+ * truth for what a model can do. This layer never re-derives them.
27
+ */
28
+ export function chatModelInfoToDescriptor(info: ChatModelInfo): ChatAdapterDescriptor {
29
+ return {
30
+ id: info.id,
31
+ displayName: info.displayName,
32
+ provider: info.provider,
33
+ // VERBATIM copy — defensive clone so the descriptor can't alias the
34
+ // response array, but NO re-derivation of which caps are present.
35
+ capabilities: [...info.capabilities],
36
+ contextWindow: info.contextWindow,
37
+ maxOutputTokens: info.maxOutputTokens,
38
+ // Opaque, forward-compat — the registry carries `metadata` untouched.
39
+ metadata: { name: info.name },
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Comparator matching the backend's deterministic ordering at
45
+ * `api/chat/app.py:666` — `sorted(..., key=lambda c: (c.provider, c.id))`.
46
+ * Used only for the null/absent-`defaultModelId` tiebreak so the client's
47
+ * "first model" agrees with the server's `models[0]`.
48
+ */
49
+ function byProviderThenId(a: ChatModelInfo, b: ChatModelInfo): number {
50
+ if (a.provider !== b.provider) {
51
+ return a.provider < b.provider ? -1 : 1;
52
+ }
53
+ if (a.id !== b.id) {
54
+ return a.id < b.id ? -1 : 1;
55
+ }
56
+ return 0;
57
+ }
58
+
59
+ /**
60
+ * Build a chat {@link AdapterRegistry} from the live backend model list.
61
+ *
62
+ * This is a FACADE over the backend — it makes NO model-selection decision of
63
+ * its own. The route decision stays server-side in `shared/model_router.py`;
64
+ * this loader only mirrors the catalogue so the UI can list / filter /
65
+ * auto-switch. There is deliberately no `route()` method and no client-side
66
+ * selection table.
67
+ *
68
+ * Default resolution mirrors `api/chat/app.py:686-697`: use
69
+ * `resp.defaultModelId` when it is set AND present in `models`; otherwise the
70
+ * first model by the backend's `(provider, id)` sort. With no models there is
71
+ * no default — a `''` sentinel (never registered) seeds both routes so the
72
+ * R1a constructor guard (`ROUTE_FALLBACK` must be present in `routes`) still
73
+ * passes and `resolveRoute` degrades to `undefined` rather than throwing.
74
+ */
75
+ export async function loadChatAdapterRegistry(
76
+ client: Pick<ApiClient, 'listChatModels'>,
77
+ ): Promise<AdapterRegistry<ChatAdapterDescriptor>> {
78
+ const resp = await client.listChatModels();
79
+ const models = resp.models;
80
+
81
+ const modelIds = new Set(models.map((m) => m.id));
82
+ const configuredDefault = resp.defaultModelId ?? '';
83
+ // Parity with the backend: a configured default that isn't in the active
84
+ // registry is discarded, then we fall back to the first-sorted model.
85
+ let defaultId = configuredDefault && modelIds.has(configuredDefault) ? configuredDefault : '';
86
+ if (!defaultId && models.length > 0) {
87
+ // Re-apply the backend's (provider, id) sort so the tiebreak agrees with
88
+ // the server's models[0] even if the payload arrives out of order.
89
+ defaultId = [...models].sort(byProviderThenId)[0].id;
90
+ }
91
+
92
+ // ROUTE_FALLBACK must always be present by name or the R1a constructor
93
+ // throws; both routes mirror the same id (selection is server-side).
94
+ const routes: NamedRoute[] = [
95
+ { name: ROUTE_DEFAULT, adapterId: defaultId, reason: 'backend defaultModelId' },
96
+ {
97
+ name: ROUTE_FALLBACK,
98
+ adapterId: defaultId,
99
+ reason: 'selection is server-side; fallback mirrors default',
100
+ },
101
+ ];
102
+
103
+ const registry = new AdapterRegistry<ChatAdapterDescriptor>({
104
+ domain: 'chat',
105
+ routes,
106
+ fallbackRouteName: ROUTE_FALLBACK,
107
+ });
108
+
109
+ for (const info of models) {
110
+ registry.register(chatModelInfoToDescriptor(info));
111
+ }
112
+
113
+ return registry;
114
+ }
@@ -0,0 +1,126 @@
1
+ import {
2
+ AdapterRegistry,
3
+ ROUTE_DEFAULT,
4
+ ROUTE_FALLBACK,
5
+ type NamedRoute,
6
+ type ModelAdapterDescriptor,
7
+ } from './registry';
8
+ import type { Capability, DirectorCapability } from './capabilities';
9
+ import { heliosWorldAdapter, longLiveWorldAdapter } from './worldAdapter';
10
+
11
+ /**
12
+ * Director-domain adapter registry — R1d, Helios seed.
13
+ *
14
+ * A director adapter schedules timeline/enrichment-driven steering over a
15
+ * WORLD adapter's transport. It "backs onto" a world adapter via
16
+ * {@link DirectorAdapterDescriptor.worldAdapterId} and inherits that world
17
+ * adapter's capabilities on top of the director-only members
18
+ * (`'timeline_schedule'` / `'enrichment_driven'`). The Helios director backs
19
+ * onto the Helios world seed; the LongLive director backs onto the LongLive
20
+ * world adapter.
21
+ *
22
+ * LAND-DARK: this only seeds the registry + flips the DIRECTOR `ROUTE_DEFAULT`
23
+ * to LongLive — the live `/interactive/director` page is UNCHANGED (its
24
+ * `modelName="helios"` literal stays; Step 3 wires the web director to read
25
+ * the flipped default).
26
+ */
27
+
28
+ /**
29
+ * A director adapter descriptor — a {@link ModelAdapterDescriptor} that
30
+ * names the world adapter it backs onto. Its `capabilities` are the
31
+ * director members PLUS the world caps it inherits from the backing world
32
+ * adapter.
33
+ */
34
+ export interface DirectorAdapterDescriptor extends ModelAdapterDescriptor {
35
+ /**
36
+ * The id of the world adapter this director backs its transport onto.
37
+ * **Advisory** — not validated at construction against the world registry;
38
+ * a mistyped id won't fail until something tries to resolve it. (Both seeds
39
+ * — `helios-director`→`helios`, `longlive-director`→`longlive-v2` — point at
40
+ * registered world adapters; a cross-registry existence check is a low-pri
41
+ * candidate invariant tracked in tech-debt #416.)
42
+ */
43
+ worldAdapterId: string;
44
+ }
45
+
46
+ /**
47
+ * Build the director capability set: the director members FIRST, then the
48
+ * world caps inherited from the backing world adapter, de-duplicated so a
49
+ * cap shared by both domains appears once.
50
+ */
51
+ function directorCapabilities(
52
+ directorCaps: readonly DirectorCapability[],
53
+ inheritedWorldCaps: readonly Capability[],
54
+ ): readonly Capability[] {
55
+ return [...new Set<Capability>([...directorCaps, ...inheritedWorldCaps])];
56
+ }
57
+
58
+ /**
59
+ * The one director that exists today — backs onto the Helios world seed.
60
+ * `capabilities` = the two director members plus every world cap
61
+ * `heliosWorldAdapter` advertises (deduped). The stable id is
62
+ * `'helios-director'` so the R8 rewire reads it from here.
63
+ */
64
+ export const heliosDirectorAdapter: DirectorAdapterDescriptor = {
65
+ id: 'helios-director',
66
+ displayName: 'Helios Director',
67
+ provider: 'reactor',
68
+ worldAdapterId: heliosWorldAdapter.id,
69
+ capabilities: directorCapabilities(
70
+ ['timeline_schedule', 'enrichment_driven'],
71
+ heliosWorldAdapter.capabilities,
72
+ ),
73
+ };
74
+
75
+ /**
76
+ * The LongLive-v2 director — backs onto the LongLive world adapter. Its
77
+ * `capabilities` are the two director members PLUS every world cap
78
+ * `longLiveWorldAdapter` advertises (deduped), so it INHERITS `scene_cut`
79
+ * and does NOT carry `swap_seed` — the same asymmetric matrix as the world
80
+ * adapter, surfaced at the director level for the Step-3 UI's
81
+ * `registry.satisfies` queries. The stable id is `'longlive-director'`.
82
+ */
83
+ export const longLiveDirectorAdapter: DirectorAdapterDescriptor = {
84
+ id: 'longlive-director',
85
+ displayName: 'LongLive Director',
86
+ provider: 'reactor',
87
+ worldAdapterId: longLiveWorldAdapter.id,
88
+ capabilities: directorCapabilities(
89
+ ['timeline_schedule', 'enrichment_driven'],
90
+ longLiveWorldAdapter.capabilities,
91
+ ),
92
+ };
93
+
94
+ /**
95
+ * Build a director {@link AdapterRegistry} pre-registered with BOTH director
96
+ * adapters. THE DIRECTOR-DEFAULT FLIP: `ROUTE_DEFAULT` → `longlive-director`
97
+ * (LongLive becomes the director default), `ROUTE_FALLBACK` →
98
+ * `helios-director` (Helios is the director fallback). LAND-DARK — nothing
99
+ * reads this route until Step 3 wires the web director page. The WORLD
100
+ * registry default stays Helios (plain `/interactive` is unchanged); only the
101
+ * DIRECTOR default flips here. The R1a constructor guard REQUIRES the
102
+ * `fallbackRouteName` present by name in `routes`.
103
+ */
104
+ export function createDirectorRegistry(): AdapterRegistry<DirectorAdapterDescriptor> {
105
+ const routes: NamedRoute[] = [
106
+ {
107
+ name: ROUTE_DEFAULT,
108
+ adapterId: longLiveDirectorAdapter.id,
109
+ reason: 'LongLive-v2 is the director default (the Step-2 flip)',
110
+ },
111
+ {
112
+ name: ROUTE_FALLBACK,
113
+ adapterId: heliosDirectorAdapter.id,
114
+ reason: 'Helios director is the fallback',
115
+ },
116
+ ];
117
+
118
+ const registry = new AdapterRegistry<DirectorAdapterDescriptor>({
119
+ domain: 'director',
120
+ routes,
121
+ fallbackRouteName: ROUTE_FALLBACK,
122
+ });
123
+ registry.register(heliosDirectorAdapter);
124
+ registry.register(longLiveDirectorAdapter);
125
+ return registry;
126
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ AdapterRegistry,
3
+ ROUTE_DEFAULT,
4
+ ROUTE_FALLBACK,
5
+ type NamedRoute,
6
+ type ModelAdapterDescriptor,
7
+ } from './registry';
8
+ import type { Capability } from './capabilities';
9
+ import type { ApiClient, ImageModelInfo } from '../api';
10
+
11
+ /**
12
+ * Image-domain adapter descriptor — a {@link ModelAdapterDescriptor} carrying
13
+ * the image-only flags the catalogue UI wants to surface (default / fallback).
14
+ * Everything else (id / displayName / provider / capabilities) is inherited
15
+ * unchanged.
16
+ */
17
+ export interface ImageAdapterDescriptor extends ModelAdapterDescriptor {
18
+ isDefault: boolean;
19
+ isFallback: boolean;
20
+ }
21
+
22
+ /**
23
+ * Map one {@link ImageModelInfo} from `GET /api/v1/images/models` to an
24
+ * {@link ImageAdapterDescriptor}. PURE — no I/O, no mutation of `info`.
25
+ *
26
+ * `capabilities` is copied VERBATIM (a fresh array, same members/order) — the
27
+ * backend image registry (`shared/image_model_registry.py`) is the single
28
+ * source of truth for what an image model can do; this layer never re-derives
29
+ * them from id/provider. The wire type is `string[]`; the backend emits only
30
+ * image caps so the cast to `Capability[]` is safe.
31
+ */
32
+ export function imageModelInfoToDescriptor(info: ImageModelInfo): ImageAdapterDescriptor {
33
+ return {
34
+ id: info.id,
35
+ displayName: info.displayName,
36
+ provider: info.provider,
37
+ // VERBATIM copy — defensive clone so the descriptor can't alias the
38
+ // response array, but NO re-derivation of which caps are present.
39
+ capabilities: [...info.capabilities] as Capability[],
40
+ isDefault: info.isDefault,
41
+ isFallback: info.isFallback,
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Build an image {@link AdapterRegistry} from the live backend model list.
47
+ *
48
+ * This is a FACADE over the backend — it makes NO model-selection decision of
49
+ * its own. Image generation still resolves to Gemini in the pipeline unchanged
50
+ * (R1c is land-dark); this loader only mirrors the catalogue so a future UI (R6)
51
+ * can list / filter image models. There is deliberately no `route()` method and
52
+ * no client-side selection table.
53
+ *
54
+ * Default resolution: the `isDefault`-flagged model id; if none is flagged,
55
+ * the first model by id (deterministic tiebreak). `ROUTE_FALLBACK` resolves to
56
+ * the `isFallback`-flagged model (the registry's real fallback), or the default
57
+ * when none is flagged. With no models there is no default — a `''` sentinel
58
+ * (never registered) seeds both routes so the R1a constructor guard
59
+ * (`ROUTE_FALLBACK` must be present in `routes`) still passes and `resolveRoute`
60
+ * degrades to `undefined` rather than throwing. This loader still makes no
61
+ * model-selection decision — it only mirrors the registry's default/fallback
62
+ * markers so `resolveRoute` reflects them.
63
+ */
64
+ export async function loadImageAdapterRegistry(
65
+ client: Pick<ApiClient, 'listImageModels'>,
66
+ ): Promise<AdapterRegistry<ImageAdapterDescriptor>> {
67
+ const resp = await client.listImageModels();
68
+ const models = resp.models;
69
+
70
+ // Default = the isDefault-flagged model; else first by id (deterministic).
71
+ let defaultId = models.find((m) => m.isDefault)?.id ?? '';
72
+ if (!defaultId && models.length > 0) {
73
+ defaultId = [...models].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))[0].id;
74
+ }
75
+ // Fallback = the isFallback-flagged model (the registry's real fallback);
76
+ // mirror the default when none is flagged.
77
+ const fallbackId = models.find((m) => m.isFallback)?.id ?? defaultId;
78
+
79
+ // ROUTE_FALLBACK must always be present by name or the R1a constructor throws.
80
+ const routes: NamedRoute[] = [
81
+ { name: ROUTE_DEFAULT, adapterId: defaultId, reason: 'image registry default model' },
82
+ {
83
+ name: ROUTE_FALLBACK,
84
+ adapterId: fallbackId,
85
+ reason: 'image registry fallback model (mirrors default if none flagged)',
86
+ },
87
+ ];
88
+
89
+ const registry = new AdapterRegistry<ImageAdapterDescriptor>({
90
+ domain: 'image',
91
+ routes,
92
+ fallbackRouteName: ROUTE_FALLBACK,
93
+ });
94
+
95
+ for (const info of models) {
96
+ registry.register(imageModelInfoToDescriptor(info));
97
+ }
98
+
99
+ return registry;
100
+ }