@escapeaihq/client-core 0.8.0 → 0.42.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 (307) hide show
  1. package/README.md +48 -4
  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 +200 -0
  31. package/dist/admin.d.ts.map +1 -0
  32. package/dist/admin.js +124 -0
  33. package/dist/admin.js.map +1 -0
  34. package/dist/api.d.ts +1299 -3
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +683 -95
  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 +62 -0
  47. package/dist/conversation/binding.d.ts.map +1 -0
  48. package/dist/conversation/binding.js +51 -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 +342 -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 +260 -0
  103. package/dist/graphSchema.d.ts.map +1 -0
  104. package/dist/graphSchema.js +354 -0
  105. package/dist/graphSchema.js.map +1 -0
  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 +9 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +12 -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/abortUtils.d.ts +16 -0
  119. package/dist/reactor/abortUtils.d.ts.map +1 -0
  120. package/dist/reactor/abortUtils.js +26 -0
  121. package/dist/reactor/abortUtils.js.map +1 -0
  122. package/dist/reactor/applyScenePrompt.d.ts +75 -0
  123. package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
  124. package/dist/reactor/applyScenePrompt.js +60 -0
  125. package/dist/reactor/applyScenePrompt.js.map +1 -0
  126. package/dist/reactor/chunkDistribution.d.ts +43 -0
  127. package/dist/reactor/chunkDistribution.d.ts.map +1 -0
  128. package/dist/reactor/chunkDistribution.js +85 -0
  129. package/dist/reactor/chunkDistribution.js.map +1 -0
  130. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  131. package/dist/reactor/heliosCommandDispatcher.js +10 -15
  132. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  133. package/dist/reactor/index.d.ts +4 -0
  134. package/dist/reactor/index.d.ts.map +1 -1
  135. package/dist/reactor/index.js +7 -0
  136. package/dist/reactor/index.js.map +1 -1
  137. package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
  138. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
  139. package/dist/reactor/longLiveCommandDispatcher.js +87 -0
  140. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
  141. package/dist/reactor/sceneEntry.d.ts +40 -6
  142. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  143. package/dist/reactor/sceneEntry.js +63 -24
  144. package/dist/reactor/sceneEntry.js.map +1 -1
  145. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
  146. package/dist/reactor/scenesFromEnrichment.js +2 -66
  147. package/dist/reactor/scenesFromEnrichment.js.map +1 -1
  148. package/dist/reactor/seedImageOrchestrator.d.ts +42 -2
  149. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  150. package/dist/reactor/seedImageOrchestrator.js +173 -4
  151. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  152. package/dist/reactor/storyTimeline.d.ts +44 -0
  153. package/dist/reactor/storyTimeline.d.ts.map +1 -0
  154. package/dist/reactor/storyTimeline.js +95 -0
  155. package/dist/reactor/storyTimeline.js.map +1 -0
  156. package/dist/storyGraph.d.ts +70 -0
  157. package/dist/storyGraph.d.ts.map +1 -0
  158. package/dist/storyGraph.js +178 -0
  159. package/dist/storyGraph.js.map +1 -0
  160. package/dist/timeFormat.d.ts +10 -0
  161. package/dist/timeFormat.d.ts.map +1 -1
  162. package/dist/timeFormat.js +12 -0
  163. package/dist/timeFormat.js.map +1 -1
  164. package/dist/toolSchemas.d.ts +370 -0
  165. package/dist/toolSchemas.d.ts.map +1 -0
  166. package/dist/toolSchemas.js +182 -0
  167. package/dist/toolSchemas.js.map +1 -0
  168. package/dist/vision/VisionPublisher.d.ts +115 -0
  169. package/dist/vision/VisionPublisher.d.ts.map +1 -0
  170. package/dist/vision/VisionPublisher.js +475 -0
  171. package/dist/vision/VisionPublisher.js.map +1 -0
  172. package/dist/vision/VisionSourceController.d.ts +127 -0
  173. package/dist/vision/VisionSourceController.d.ts.map +1 -0
  174. package/dist/vision/VisionSourceController.js +284 -0
  175. package/dist/vision/VisionSourceController.js.map +1 -0
  176. package/dist/vision/credentials.d.ts +22 -0
  177. package/dist/vision/credentials.d.ts.map +1 -0
  178. package/dist/vision/credentials.js +34 -0
  179. package/dist/vision/credentials.js.map +1 -0
  180. package/dist/vision/index.d.ts +18 -0
  181. package/dist/vision/index.d.ts.map +1 -0
  182. package/dist/vision/index.js +13 -0
  183. package/dist/vision/index.js.map +1 -0
  184. package/dist/vision/sourceKinds.d.ts +65 -0
  185. package/dist/vision/sourceKinds.d.ts.map +1 -0
  186. package/dist/vision/sourceKinds.js +26 -0
  187. package/dist/vision/sourceKinds.js.map +1 -0
  188. package/dist/vision/startVisionPublisher.d.ts +38 -0
  189. package/dist/vision/startVisionPublisher.d.ts.map +1 -0
  190. package/dist/vision/startVisionPublisher.js +44 -0
  191. package/dist/vision/startVisionPublisher.js.map +1 -0
  192. package/dist/vision/types.d.ts +95 -0
  193. package/dist/vision/types.d.ts.map +1 -0
  194. package/dist/vision/types.js +12 -0
  195. package/dist/vision/types.js.map +1 -0
  196. package/dist/vision/visionScheduler.d.ts +63 -0
  197. package/dist/vision/visionScheduler.d.ts.map +1 -0
  198. package/dist/vision/visionScheduler.js +67 -0
  199. package/dist/vision/visionScheduler.js.map +1 -0
  200. package/dist/websocket.d.ts +195 -0
  201. package/dist/websocket.d.ts.map +1 -1
  202. package/dist/websocket.js +179 -1
  203. package/dist/websocket.js.map +1 -1
  204. package/package.json +11 -1
  205. package/src/__tests__/adapters-capabilities.test.ts +46 -0
  206. package/src/__tests__/adapters-chat.test.ts +172 -0
  207. package/src/__tests__/adapters-director.test.ts +95 -0
  208. package/src/__tests__/adapters-image.test.ts +133 -0
  209. package/src/__tests__/adapters-platform.test.ts +95 -0
  210. package/src/__tests__/adapters-registry.test.ts +189 -0
  211. package/src/__tests__/adapters-world.test.ts +296 -0
  212. package/src/__tests__/admin.test.ts +312 -0
  213. package/src/__tests__/adventures-party.test.ts +219 -0
  214. package/src/__tests__/adventures.test.ts +282 -0
  215. package/src/__tests__/api-pollers.test.ts +104 -0
  216. package/src/__tests__/api.clip-lookup.test.ts +64 -0
  217. package/src/__tests__/api.list-images-filters.test.ts +103 -0
  218. package/src/__tests__/api.test.ts +470 -0
  219. package/src/__tests__/audio.test.ts +65 -0
  220. package/src/__tests__/cast.test.ts +95 -0
  221. package/src/__tests__/castProjection.test.ts +167 -0
  222. package/src/__tests__/chat-auth.test.ts +91 -0
  223. package/src/__tests__/conversation/controller.test.ts +697 -0
  224. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  225. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  226. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  227. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  228. package/src/__tests__/conversation/roster.test.ts +100 -0
  229. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  230. package/src/__tests__/conversation/router.test.ts +81 -0
  231. package/src/__tests__/conversation/runtime.test.ts +206 -0
  232. package/src/__tests__/conversation/voice.test.ts +440 -0
  233. package/src/__tests__/documents.test.ts +360 -0
  234. package/src/__tests__/graphSchema.test.ts +326 -0
  235. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  236. package/src/__tests__/platformAssistant.test.ts +484 -0
  237. package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
  238. package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
  239. package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
  240. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
  241. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  242. package/src/__tests__/regeneration.test.ts +486 -0
  243. package/src/__tests__/stories.test.ts +171 -0
  244. package/src/__tests__/storyGraph.test.ts +134 -0
  245. package/src/__tests__/timeFormat.test.ts +22 -1
  246. package/src/__tests__/toolSchemas.test.ts +57 -0
  247. package/src/__tests__/tools-wrappers.test.ts +272 -0
  248. package/src/__tests__/videoGraph.test.ts +94 -0
  249. package/src/__tests__/websocket-vision.test.ts +265 -0
  250. package/src/__tests__/websocket.test.ts +213 -0
  251. package/src/adapters/capabilities.ts +24 -0
  252. package/src/adapters/chatAdapter.ts +114 -0
  253. package/src/adapters/directorAdapter.ts +126 -0
  254. package/src/adapters/imageAdapter.ts +100 -0
  255. package/src/adapters/index.ts +67 -0
  256. package/src/adapters/registry.ts +159 -0
  257. package/src/adapters/worldAdapter.ts +272 -0
  258. package/src/admin.ts +310 -0
  259. package/src/api.ts +1890 -162
  260. package/src/audio.ts +35 -0
  261. package/src/castProjection.ts +95 -0
  262. package/src/conversation/binding.ts +81 -0
  263. package/src/conversation/controller.ts +439 -0
  264. package/src/conversation/effectiveModel.ts +111 -0
  265. package/src/conversation/index.ts +27 -0
  266. package/src/conversation/participant.ts +71 -0
  267. package/src/conversation/presence.ts +60 -0
  268. package/src/conversation/presenceBus.ts +109 -0
  269. package/src/conversation/presenceRegistry.ts +83 -0
  270. package/src/conversation/roster.ts +111 -0
  271. package/src/conversation/rosterProjection.ts +98 -0
  272. package/src/conversation/router.ts +96 -0
  273. package/src/conversation/runtime.ts +188 -0
  274. package/src/conversation/types.ts +100 -0
  275. package/src/conversation/voice.ts +402 -0
  276. package/src/graphSchema.ts +532 -0
  277. package/src/http.ts +72 -0
  278. package/src/index.ts +12 -0
  279. package/src/platformAssistant.ts +347 -0
  280. package/src/reactor/abortUtils.ts +22 -0
  281. package/src/reactor/applyScenePrompt.ts +136 -0
  282. package/src/reactor/chunkDistribution.ts +98 -0
  283. package/src/reactor/heliosCommandDispatcher.ts +10 -18
  284. package/src/reactor/index.ts +7 -0
  285. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  286. package/src/reactor/sceneEntry.ts +104 -33
  287. package/src/reactor/scenesFromEnrichment.ts +11 -76
  288. package/src/reactor/seedImageOrchestrator.ts +200 -4
  289. package/src/reactor/storyTimeline.ts +127 -0
  290. package/src/storyGraph.ts +298 -0
  291. package/src/timeFormat.ts +13 -0
  292. package/src/toolSchemas.ts +225 -0
  293. package/src/vision/VisionPublisher.ts +553 -0
  294. package/src/vision/VisionSourceController.ts +354 -0
  295. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
  296. package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
  297. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  298. package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
  299. package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
  300. package/src/vision/__tests__/visionScheduler.test.ts +149 -0
  301. package/src/vision/credentials.ts +39 -0
  302. package/src/vision/index.ts +44 -0
  303. package/src/vision/sourceKinds.ts +75 -0
  304. package/src/vision/startVisionPublisher.ts +64 -0
  305. package/src/vision/types.ts +101 -0
  306. package/src/vision/visionScheduler.ts +102 -0
  307. package/src/websocket.ts +334 -4
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Tests for the R5b `getVideoGraph` detail arg — the `detail=story|raw` query
3
+ * param on `GET /api/v1/tools/graph/{videoId}`. The land-dark contract is the
4
+ * load-bearing case: omitting `detail` must produce a request byte-identical
5
+ * to the pre-R5b call (NO query string), so every existing caller is
6
+ * untouched. Same global-fetch-mock pattern as `cast.test.ts`.
7
+ */
8
+
9
+ import { ApiClient, GRAPH_DETAIL, type VideoGraphResponse } from '../api';
10
+
11
+ const TEST_BASE_URL = 'http://test.local';
12
+ const TEST_CHAT_BASE_URL = 'http://test.local/chat';
13
+
14
+ const makeClient = (sessionToken: string = 'test-token') =>
15
+ new ApiClient(TEST_BASE_URL, sessionToken, TEST_CHAT_BASE_URL);
16
+
17
+ const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
18
+
19
+ afterEach(() => {
20
+ if (originalFetch === undefined) {
21
+ delete (globalThis as { fetch?: typeof fetch }).fetch;
22
+ } else {
23
+ (globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
24
+ }
25
+ jest.restoreAllMocks();
26
+ });
27
+
28
+ const buildResponse = (): VideoGraphResponse => ({
29
+ traceId: 'trace-graph',
30
+ videoId: 'video-1',
31
+ nodes: [
32
+ {
33
+ id: 'Scene:sceneId:sc-1',
34
+ label: 'Scene',
35
+ // R5b: story-mode Scene nodes carry the read-time shotCount in the
36
+ // generic properties bag (no schema fork).
37
+ properties: { sceneId: 'sc-1', shotCount: 4 },
38
+ },
39
+ ],
40
+ edges: [],
41
+ });
42
+
43
+ const mockFetch = (): jest.Mock => {
44
+ const fetchMock = jest.fn().mockResolvedValue({
45
+ ok: true,
46
+ status: 200,
47
+ json: async () => buildResponse(),
48
+ });
49
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
50
+ return fetchMock;
51
+ };
52
+
53
+ describe('getVideoGraph detail param (R5b)', () => {
54
+ it('omits the query string entirely when detail is not passed (land-dark)', async () => {
55
+ const fetchMock = mockFetch();
56
+ await makeClient().getVideoGraph('video-1');
57
+
58
+ expect(fetchMock).toHaveBeenCalledTimes(1);
59
+ const url = fetchMock.mock.calls[0][0] as string;
60
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1`);
61
+ expect(url).not.toContain('detail');
62
+ });
63
+
64
+ it('sends detail=story for GRAPH_DETAIL.STORY', async () => {
65
+ const fetchMock = mockFetch();
66
+ const response = await makeClient().getVideoGraph('video-1', GRAPH_DETAIL.STORY);
67
+
68
+ const url = fetchMock.mock.calls[0][0] as string;
69
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1?detail=story`);
70
+ expect(response.nodes[0]?.properties.shotCount).toBe(4);
71
+ });
72
+
73
+ it('sends detail=raw for GRAPH_DETAIL.RAW', async () => {
74
+ const fetchMock = mockFetch();
75
+ await makeClient().getVideoGraph('video-1', GRAPH_DETAIL.RAW);
76
+
77
+ const url = fetchMock.mock.calls[0][0] as string;
78
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1?detail=raw`);
79
+ });
80
+
81
+ it('URI-encodes the videoId ahead of the query param', async () => {
82
+ const fetchMock = mockFetch();
83
+ await makeClient().getVideoGraph('video/1 x', GRAPH_DETAIL.STORY);
84
+
85
+ const url = fetchMock.mock.calls[0][0] as string;
86
+ expect(url).toBe(
87
+ `${TEST_BASE_URL}/api/v1/tools/graph/video%2F1%20x?detail=story`,
88
+ );
89
+ });
90
+
91
+ it('exposes exactly the story/raw literal set (mirror of shared GraphDetail)', () => {
92
+ expect(GRAPH_DETAIL).toEqual({ STORY: 'story', RAW: 'raw' });
93
+ });
94
+ });
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Tests for the vision-signaling additions to `ChatWebSocket`:
3
+ * - `sendVisionOffer` / `sendVisionIce` / `sendVisionClose` outbound
4
+ * send methods.
5
+ * - `on(event, handler)` / `off(event, handler)` typed event dispatch
6
+ * for inbound `vision_answer` / `vision_ice` / `vision_status`.
7
+ *
8
+ * Mirrors the StubWebSocket pattern used by `websocket.test.ts` —
9
+ * jsdom's WebSocket actually dials, so we replace the constructor with
10
+ * a stub that records sends and lets each test drive open/message/close
11
+ * synchronously.
12
+ *
13
+ * Wire-shape source of truth: `shared/vision_protocol.py`. The outbound
14
+ * `vision_ice` payload converts camel-case (`sdpMid` / `sdpMLineIndex`)
15
+ * to snake_case (`sdp_mid` / `sdp_m_line_index`); the inbound dispatcher
16
+ * converts the reverse direction so listeners always see camel-case.
17
+ */
18
+
19
+ import { ChatWebSocket } from '../websocket';
20
+ import type {
21
+ VisionAnswerEvent,
22
+ VisionIceEvent,
23
+ VisionStatusEvent,
24
+ } from '../websocket';
25
+
26
+ interface FakeWebSocket {
27
+ url: string;
28
+ readyState: number;
29
+ binaryType: string;
30
+ sent: string[];
31
+ onopen?: () => void;
32
+ onerror?: (err: Event) => void;
33
+ onmessage?: (event: MessageEvent) => void;
34
+ onclose?: () => void;
35
+ close: () => void;
36
+ send: (data: string | ArrayBuffer | Uint8Array) => void;
37
+ simulateOpen: () => void;
38
+ simulateMessage: (data: string) => void;
39
+ }
40
+
41
+ const instances: FakeWebSocket[] = [];
42
+
43
+ class StubWebSocket {
44
+ static CONNECTING = 0;
45
+ static OPEN = 1;
46
+ static CLOSING = 2;
47
+ static CLOSED = 3;
48
+
49
+ url: string;
50
+ readyState = StubWebSocket.CONNECTING;
51
+ binaryType = 'blob';
52
+ sent: string[] = [];
53
+ onopen?: () => void;
54
+ onerror?: (err: Event) => void;
55
+ onmessage?: (event: MessageEvent) => void;
56
+ onclose?: () => void;
57
+
58
+ constructor(url: string) {
59
+ this.url = url;
60
+ const ref = this as unknown as FakeWebSocket;
61
+ ref.close = () => {
62
+ this.readyState = StubWebSocket.CLOSED;
63
+ };
64
+ ref.send = (data: string | ArrayBuffer | Uint8Array) => {
65
+ if (typeof data === 'string') {
66
+ this.sent.push(data);
67
+ }
68
+ };
69
+ ref.simulateOpen = () => {
70
+ this.readyState = StubWebSocket.OPEN;
71
+ this.onopen?.();
72
+ };
73
+ ref.simulateMessage = (data: string) => {
74
+ this.onmessage?.({ data } as MessageEvent);
75
+ };
76
+ instances.push(ref);
77
+ }
78
+ }
79
+
80
+ const originalWebSocket = globalThis.WebSocket;
81
+
82
+ const flushMicrotasks = async (): Promise<void> => {
83
+ await Promise.resolve();
84
+ await Promise.resolve();
85
+ };
86
+
87
+ const lastSocket = (): FakeWebSocket => {
88
+ const last = instances[instances.length - 1];
89
+ if (!last) throw new Error('No WebSocket has been constructed yet');
90
+ return last;
91
+ };
92
+
93
+ beforeEach(() => {
94
+ instances.length = 0;
95
+ (globalThis as unknown as { WebSocket: typeof StubWebSocket }).WebSocket =
96
+ StubWebSocket;
97
+ });
98
+
99
+ afterEach(() => {
100
+ jest.useRealTimers();
101
+ (globalThis as { WebSocket?: typeof WebSocket }).WebSocket = originalWebSocket;
102
+ });
103
+
104
+ const openSocket = async (): Promise<ChatWebSocket> => {
105
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
106
+ const connectPromise = ws.connect();
107
+ await flushMicrotasks();
108
+ lastSocket().simulateOpen();
109
+ await connectPromise;
110
+ return ws;
111
+ };
112
+
113
+ describe('ChatWebSocket — vision outbound signaling', () => {
114
+ it('sendVisionOffer serializes the exact wire shape', async () => {
115
+ const ws = await openSocket();
116
+ ws.sendVisionOffer({
117
+ action: 'vision_offer',
118
+ sdp: 'v=0\r\no=- 123 ...',
119
+ fps: 1.5,
120
+ });
121
+ expect(lastSocket().sent).toHaveLength(1);
122
+ expect(JSON.parse(lastSocket().sent[0])).toEqual({
123
+ action: 'vision_offer',
124
+ sdp: 'v=0\r\no=- 123 ...',
125
+ fps: 1.5,
126
+ });
127
+ });
128
+
129
+ it('sendVisionIce converts camelCase to snake_case on the wire', async () => {
130
+ const ws = await openSocket();
131
+ ws.sendVisionIce({
132
+ action: 'vision_ice',
133
+ candidate: 'candidate:1 1 udp 2113937151 192.0.2.1 50000 typ host',
134
+ sdpMid: '0',
135
+ sdpMLineIndex: 0,
136
+ });
137
+ expect(JSON.parse(lastSocket().sent[0])).toEqual({
138
+ action: 'vision_ice',
139
+ candidate: 'candidate:1 1 udp 2113937151 192.0.2.1 50000 typ host',
140
+ sdp_mid: '0',
141
+ sdp_m_line_index: 0,
142
+ });
143
+ });
144
+
145
+ it('sendVisionIce serializes the end-of-candidates sentinel as null', async () => {
146
+ const ws = await openSocket();
147
+ ws.sendVisionIce({ action: 'vision_ice', candidate: null });
148
+ expect(JSON.parse(lastSocket().sent[0])).toEqual({
149
+ action: 'vision_ice',
150
+ candidate: null,
151
+ sdp_mid: null,
152
+ sdp_m_line_index: null,
153
+ });
154
+ });
155
+
156
+ it('sendVisionClose sends the vision_close action', async () => {
157
+ const ws = await openSocket();
158
+ ws.sendVisionClose();
159
+ expect(JSON.parse(lastSocket().sent[0])).toEqual({ action: 'vision_close' });
160
+ });
161
+
162
+ it('vision sends drop silently when the socket is not OPEN', () => {
163
+ // No connect() — there's no underlying socket. All three send methods
164
+ // are best-effort; they must early-return rather than throw, mirroring
165
+ // sendPlaybackState semantics.
166
+ const ws = new ChatWebSocket({ url: 'ws://test/chat' });
167
+ expect(() =>
168
+ ws.sendVisionOffer({ action: 'vision_offer', sdp: 'x', fps: 1 }),
169
+ ).not.toThrow();
170
+ expect(() =>
171
+ ws.sendVisionIce({ action: 'vision_ice', candidate: null }),
172
+ ).not.toThrow();
173
+ expect(() => ws.sendVisionClose()).not.toThrow();
174
+ expect(instances).toHaveLength(0);
175
+ });
176
+ });
177
+
178
+ describe('ChatWebSocket — inbound vision event dispatch', () => {
179
+ it('routes vision_answer to listeners registered via on()', async () => {
180
+ const ws = await openSocket();
181
+ const handler = jest.fn();
182
+ ws.on('vision_answer', handler);
183
+ lastSocket().simulateMessage(
184
+ JSON.stringify({ type: 'vision_answer', sdp: 'fake-answer-sdp' }),
185
+ );
186
+ expect(handler).toHaveBeenCalledTimes(1);
187
+ const received = handler.mock.calls[0]?.[0] as VisionAnswerEvent;
188
+ expect(received).toEqual({ type: 'vision_answer', sdp: 'fake-answer-sdp' });
189
+ });
190
+
191
+ it('routes vision_ice and converts snake_case to camelCase for listeners', async () => {
192
+ const ws = await openSocket();
193
+ const handler = jest.fn();
194
+ ws.on('vision_ice', handler);
195
+ lastSocket().simulateMessage(
196
+ JSON.stringify({
197
+ action: 'vision_ice',
198
+ candidate: 'candidate:remote ...',
199
+ sdp_mid: '0',
200
+ sdp_m_line_index: 0,
201
+ }),
202
+ );
203
+ const received = handler.mock.calls[0]?.[0] as VisionIceEvent;
204
+ expect(received).toEqual({
205
+ action: 'vision_ice',
206
+ candidate: 'candidate:remote ...',
207
+ sdpMid: '0',
208
+ sdpMLineIndex: 0,
209
+ });
210
+ });
211
+
212
+ it('routes vision_status with camelCase shape ready for the HUD', async () => {
213
+ const ws = await openSocket();
214
+ const handler = jest.fn();
215
+ ws.on('vision_status', handler);
216
+ lastSocket().simulateMessage(
217
+ JSON.stringify({
218
+ type: 'vision_status',
219
+ buffered_frames: 2,
220
+
221
+ processing_paused: false,
222
+ }),
223
+ );
224
+ const received = handler.mock.calls[0]?.[0] as VisionStatusEvent;
225
+ expect(received).toEqual({
226
+ type: 'vision_status',
227
+ bufferedFrames: 2,
228
+
229
+ processingPaused: false,
230
+ });
231
+ });
232
+
233
+ it('off() removes the typed listener', async () => {
234
+ const ws = await openSocket();
235
+ const handler = jest.fn();
236
+ ws.on('vision_answer', handler);
237
+ ws.off('vision_answer', handler);
238
+ lastSocket().simulateMessage(
239
+ JSON.stringify({ type: 'vision_answer', sdp: 'x' }),
240
+ );
241
+ expect(handler).not.toHaveBeenCalled();
242
+ });
243
+
244
+ it('preserves back-compat: typed messages still reach onMessage handlers', async () => {
245
+ const ws = await openSocket();
246
+ const onMessageHandler = jest.fn();
247
+ ws.onMessage(onMessageHandler);
248
+ lastSocket().simulateMessage(
249
+ JSON.stringify({ type: 'vision_answer', sdp: 'x' }),
250
+ );
251
+ // The legacy onMessage path still fires so existing consumers
252
+ // observing every raw message keep working.
253
+ expect(onMessageHandler).toHaveBeenCalledTimes(1);
254
+ });
255
+
256
+ it('typed dispatch ignores messages that are not vision events', async () => {
257
+ const ws = await openSocket();
258
+ const visionHandler = jest.fn();
259
+ ws.on('vision_answer', visionHandler);
260
+ lastSocket().simulateMessage(
261
+ JSON.stringify({ type: 'token', content: 'hello' }),
262
+ );
263
+ expect(visionHandler).not.toHaveBeenCalled();
264
+ });
265
+ });
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import { ChatWebSocket } from '../websocket';
14
+ import type { ChatWsEvent } from '../websocket';
14
15
 
15
16
  interface FakeWebSocket {
16
17
  url: string;
@@ -351,3 +352,215 @@ describe('ChatWebSocket — back-compat with static authToken', () => {
351
352
  expect(lastSocket().url).toBe('ws://test/chat');
352
353
  });
353
354
  });
355
+
356
+ describe('ChatWebSocket — send() entityId (persona↔character binding)', () => {
357
+ it('serializes entityId into the send frame when a bound persona is active', async () => {
358
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
359
+ const connectPromise = ws.connect();
360
+ await flushMicrotasks();
361
+ lastSocket().simulateOpen();
362
+ await connectPromise;
363
+
364
+ ws.send('hello', { videoId: 'v1', entityId: 'ent-123' });
365
+
366
+ expect(lastSocket().sent).toHaveLength(1);
367
+ const frame = JSON.parse(lastSocket().sent[0] as string);
368
+ expect(frame).toMatchObject({
369
+ action: 'send',
370
+ prompt: 'hello',
371
+ videoId: 'v1',
372
+ entityId: 'ent-123',
373
+ });
374
+ });
375
+
376
+ it('omits entityId from the send frame when the persona is unbound (land-dark)', async () => {
377
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
378
+ const connectPromise = ws.connect();
379
+ await flushMicrotasks();
380
+ lastSocket().simulateOpen();
381
+ await connectPromise;
382
+
383
+ ws.send('hello', { videoId: 'v1' });
384
+
385
+ const frame = JSON.parse(lastSocket().sent[0] as string);
386
+ expect(frame).not.toHaveProperty('entityId');
387
+ });
388
+ });
389
+
390
+ describe('ChatWebSocket — send() personaId (M8 Phase D memory namespace)', () => {
391
+ it('serializes personaId into the send frame when a persona is active', async () => {
392
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
393
+ const connectPromise = ws.connect();
394
+ await flushMicrotasks();
395
+ lastSocket().simulateOpen();
396
+ await connectPromise;
397
+
398
+ ws.send('hello', { videoId: 'v1', personaId: 'persona-42' });
399
+
400
+ const frame = JSON.parse(lastSocket().sent[0] as string);
401
+ expect(frame).toMatchObject({
402
+ action: 'send',
403
+ prompt: 'hello',
404
+ videoId: 'v1',
405
+ personaId: 'persona-42',
406
+ });
407
+ });
408
+
409
+ it('omits personaId from the send frame when no persona is active (land-dark)', async () => {
410
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
411
+ const connectPromise = ws.connect();
412
+ await flushMicrotasks();
413
+ lastSocket().simulateOpen();
414
+ await connectPromise;
415
+
416
+ ws.send('hello', { videoId: 'v1' });
417
+
418
+ const frame = JSON.parse(lastSocket().sent[0] as string);
419
+ expect(frame).not.toHaveProperty('personaId');
420
+ });
421
+ });
422
+
423
+ describe('ChatWebSocket — send() adventureSessionId (M9 Adventure Runtime Phase 8a)', () => {
424
+ it('serializes adventureSessionId into the send frame when an adventure is active', async () => {
425
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
426
+ const connectPromise = ws.connect();
427
+ await flushMicrotasks();
428
+ lastSocket().simulateOpen();
429
+ await connectPromise;
430
+
431
+ ws.send('I open the door', {
432
+ videoId: 'v1',
433
+ personaId: 'dm-1',
434
+ adventureSessionId: 'adv-123',
435
+ });
436
+
437
+ const frame = JSON.parse(lastSocket().sent[0] as string);
438
+ expect(frame).toMatchObject({
439
+ action: 'send',
440
+ prompt: 'I open the door',
441
+ videoId: 'v1',
442
+ personaId: 'dm-1',
443
+ adventureSessionId: 'adv-123',
444
+ });
445
+ });
446
+
447
+ it('omits adventureSessionId from the send frame when no adventure is active (land-dark)', async () => {
448
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
449
+ const connectPromise = ws.connect();
450
+ await flushMicrotasks();
451
+ lastSocket().simulateOpen();
452
+ await connectPromise;
453
+
454
+ ws.send('hello', { videoId: 'v1' });
455
+
456
+ const frame = JSON.parse(lastSocket().sent[0] as string);
457
+ expect(frame).not.toHaveProperty('adventureSessionId');
458
+ });
459
+ });
460
+
461
+ describe('ChatWebSocket — send() partyPersonaIds (M10 Story Engine Phase 9a)', () => {
462
+ it('serializes partyPersonaIds into the send frame when a party is present', async () => {
463
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
464
+ const connectPromise = ws.connect();
465
+ await flushMicrotasks();
466
+ lastSocket().simulateOpen();
467
+ await connectPromise;
468
+
469
+ ws.send('I open the door', {
470
+ videoId: 'v1',
471
+ personaId: 'dm-1',
472
+ adventureSessionId: 'adv-123',
473
+ partyPersonaIds: ['aragorn', 'legolas'],
474
+ });
475
+
476
+ const frame = JSON.parse(lastSocket().sent[0] as string);
477
+ expect(frame).toMatchObject({
478
+ action: 'send',
479
+ adventureSessionId: 'adv-123',
480
+ partyPersonaIds: ['aragorn', 'legolas'],
481
+ });
482
+ });
483
+
484
+ it('omits partyPersonaIds from the send frame when no party is provided (land-dark)', async () => {
485
+ const ws = new ChatWebSocket({ url: 'ws://test/chat', authToken: 'tok' });
486
+ const connectPromise = ws.connect();
487
+ await flushMicrotasks();
488
+ lastSocket().simulateOpen();
489
+ await connectPromise;
490
+
491
+ ws.send('hello', { videoId: 'v1' });
492
+
493
+ const frame = JSON.parse(lastSocket().sent[0] as string);
494
+ expect(frame).not.toHaveProperty('partyPersonaIds');
495
+ });
496
+ });
497
+
498
+ describe('ChatWsEvent — M10 9a multi-persona protocol additions', () => {
499
+ it('narrows a turn_changed event to its personaId / previousPersonaId fields', () => {
500
+ const event: ChatWsEvent = {
501
+ type: 'turn_changed',
502
+ timestamp: 1.5,
503
+ personaId: 'aragorn',
504
+ previousPersonaId: 'dm-1',
505
+ };
506
+
507
+ // Exhaustive narrowing: only the turn_changed case carries personaId
508
+ // as a required field alongside previousPersonaId.
509
+ expect(event.type).toBe('turn_changed');
510
+ if (event.type === 'turn_changed') {
511
+ expect(event.personaId).toBe('aragorn');
512
+ expect(event.previousPersonaId).toBe('dm-1');
513
+ }
514
+ });
515
+
516
+ it('allows the first-turn turn_changed without a previousPersonaId', () => {
517
+ const event: ChatWsEvent = {
518
+ type: 'turn_changed',
519
+ personaId: 'dm-1',
520
+ };
521
+ if (event.type === 'turn_changed') {
522
+ expect(event.previousPersonaId).toBeUndefined();
523
+ }
524
+ });
525
+
526
+ it('allows an optional personaId on token / done / citation / image / audio_chunk frames', () => {
527
+ const token: ChatWsEvent = { type: 'token', content: 'hi', personaId: 'aragorn' };
528
+ const done: ChatWsEvent = { type: 'done', personaId: 'aragorn' };
529
+ const citation: ChatWsEvent = {
530
+ type: 'citation',
531
+ citation: { videoId: 'v1', t0: 0, t1: 1 },
532
+ personaId: 'aragorn',
533
+ };
534
+ const image: ChatWsEvent = {
535
+ type: 'image',
536
+ imageUrl: 'https://x/i.png',
537
+ personaId: 'aragorn',
538
+ };
539
+ const audio: ChatWsEvent = {
540
+ type: 'audio_chunk',
541
+ audio: 'AAAA',
542
+ format: 'mp3',
543
+ personaId: 'aragorn',
544
+ };
545
+
546
+ for (const ev of [token, done, citation, image, audio]) {
547
+ if (
548
+ ev.type === 'token' ||
549
+ ev.type === 'done' ||
550
+ ev.type === 'citation' ||
551
+ ev.type === 'image' ||
552
+ ev.type === 'audio_chunk'
553
+ ) {
554
+ expect(ev.personaId).toBe('aragorn');
555
+ }
556
+ }
557
+ });
558
+
559
+ it('keeps personaId optional (land-dark: existing frames omit it)', () => {
560
+ // No personaId — the existing non-orchestrated shape still type-checks.
561
+ const token: ChatWsEvent = { type: 'token', content: 'hi' };
562
+ if (token.type === 'token') {
563
+ expect(token.personaId).toBeUndefined();
564
+ }
565
+ });
566
+ });
@@ -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;