@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,103 @@
1
+ /**
2
+ * listImages filter-param tests (R6b — image filtering API params).
3
+ *
4
+ * R6b adds optional `model` + `status` filters to `listImages`, mirroring the
5
+ * new `GET /api/v1/images` query params. These tests assert the params are
6
+ * appended to the request URL (and omitted when absent, so existing callers
7
+ * stay byte-identical), and that `status` reuses the `ImageStatus` union (no
8
+ * parallel status enum). The request goes through `chatRequest` →
9
+ * `chatApiBaseUrl`.
10
+ *
11
+ * Runner: jest (client-core uses jest, not vitest).
12
+ */
13
+ import { ApiClient } from '../api';
14
+
15
+ describe('ApiClient.listImages filter params (R6b)', () => {
16
+ let client: ApiClient;
17
+ let fetchMock: jest.Mock;
18
+
19
+ beforeEach(() => {
20
+ client = new ApiClient(
21
+ 'https://api.example.com',
22
+ 'test-token',
23
+ 'https://chat.example.com',
24
+ );
25
+ fetchMock = jest.fn();
26
+ global.fetch = fetchMock as unknown as typeof fetch;
27
+ });
28
+
29
+ afterEach(() => {
30
+ jest.restoreAllMocks();
31
+ });
32
+
33
+ function mockJsonResponse(body: unknown, status = 200): Response {
34
+ return {
35
+ ok: status >= 200 && status < 300,
36
+ status,
37
+ headers: {
38
+ get: (name: string) =>
39
+ name.toLowerCase() === 'content-type' ? 'application/json' : null,
40
+ },
41
+ json: async () => body,
42
+ } as unknown as Response;
43
+ }
44
+
45
+ function requestedUrl(): string {
46
+ expect(fetchMock).toHaveBeenCalledTimes(1);
47
+ const [url] = fetchMock.mock.calls[0] as [string, RequestInit];
48
+ return url;
49
+ }
50
+
51
+ it('omits model + status when not provided (byte-identical to pre-R6b)', async () => {
52
+ fetchMock.mockResolvedValueOnce(
53
+ mockJsonResponse({ images: [], total: 0, next_token: null }),
54
+ );
55
+
56
+ await client.listImages({ videoId: 'v1' });
57
+
58
+ const url = requestedUrl();
59
+ expect(url).toBe('https://chat.example.com/api/v1/images?videoId=v1');
60
+ expect(url).not.toContain('model=');
61
+ expect(url).not.toContain('status=');
62
+ });
63
+
64
+ it('appends the model filter', async () => {
65
+ fetchMock.mockResolvedValueOnce(
66
+ mockJsonResponse({ images: [], total: 0, next_token: null }),
67
+ );
68
+
69
+ await client.listImages({ model: 'gemini-3.1-flash-image-preview' });
70
+
71
+ expect(requestedUrl()).toContain(
72
+ 'model=gemini-3.1-flash-image-preview',
73
+ );
74
+ });
75
+
76
+ it('appends the status filter (reusing the ImageStatus union)', async () => {
77
+ fetchMock.mockResolvedValueOnce(
78
+ mockJsonResponse({ images: [], total: 0, next_token: null }),
79
+ );
80
+
81
+ await client.listImages({ status: 'failed' });
82
+
83
+ expect(requestedUrl()).toContain('status=failed');
84
+ });
85
+
86
+ it('appends model + status + category together', async () => {
87
+ fetchMock.mockResolvedValueOnce(
88
+ mockJsonResponse({ images: [], total: 0, next_token: null }),
89
+ );
90
+
91
+ await client.listImages({
92
+ category: 'character',
93
+ model: 'amazon.nova-canvas-v1:0',
94
+ status: 'complete',
95
+ });
96
+
97
+ const url = requestedUrl();
98
+ expect(url).toContain('category=character');
99
+ // URLSearchParams percent-encodes the ':' in the Bedrock id.
100
+ expect(url).toContain('model=amazon.nova-canvas-v1%3A0');
101
+ expect(url).toContain('status=complete');
102
+ });
103
+ });
@@ -0,0 +1,470 @@
1
+ /**
2
+ * Tests for the R4a Platform Assistant client-core additions:
3
+ * - `ApiClient.streamAssistant(request, signal)` POSTs to
4
+ * `/api/v1/assistant/stream` on the chat base URL with the
5
+ * `AssistantStreamRequest` body (prompt / messages / modelId /
6
+ * routeContext, and crucially NO `videoId` — the assistant is not
7
+ * video-scoped).
8
+ * - The returned `ReadableStreamDefaultReader` is the SAME SSE plumbing
9
+ * `streamChat` returns (both route through the shared `readSseStream`
10
+ * body-reader helper), so a streamed `suggestion` SSE event decodes +
11
+ * `JSON.parse`s into the new `AssistantStreamEvent` `suggestion` union
12
+ * variant `{ type: 'suggestion'; targetForm; fields; rationale? }`.
13
+ *
14
+ * Mirrors the global-fetch mock + save/restore discipline from
15
+ * chat-auth.test.ts (jest.restoreAllMocks only unwinds spyOn, not direct
16
+ * assignment to globalThis.fetch).
17
+ */
18
+
19
+ // jest-environment-jsdom does not expose TextEncoder/TextDecoder as globals,
20
+ // so pull them from Node's `util` to build/decode the byte stream the SSE
21
+ // reader returns (hermetic — no reliance on an environment global).
22
+ import { TextEncoder, TextDecoder } from 'node:util';
23
+
24
+ import { ApiClient } from '../api';
25
+ import type {
26
+ AssistantStreamEvent,
27
+ AssistantStreamRequest,
28
+ FormSchemaResponse,
29
+ ToolReference,
30
+ ToolReferenceListResponse,
31
+ ToolReferenceResponse,
32
+ } from '../api';
33
+
34
+ const TEST_BASE_URL = 'http://test.local';
35
+ const TEST_CHAT_BASE_URL = 'http://test.local/chat';
36
+
37
+ const makeAuthedClient = (sessionToken: string = 'test-token') =>
38
+ new ApiClient(TEST_BASE_URL, sessionToken, TEST_CHAT_BASE_URL);
39
+
40
+ const makeUnauthedClient = () =>
41
+ new ApiClient(TEST_BASE_URL, undefined, TEST_CHAT_BASE_URL);
42
+
43
+ const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
44
+
45
+ afterEach(() => {
46
+ if (originalFetch === undefined) {
47
+ delete (globalThis as { fetch?: typeof fetch }).fetch;
48
+ } else {
49
+ (globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
50
+ }
51
+ jest.restoreAllMocks();
52
+ });
53
+
54
+ /**
55
+ * Build a Response-like object whose `body.getReader()` streams the given
56
+ * SSE text as a single UTF-8 chunk then closes. Matches what `fetch`
57
+ * returns for an `text/event-stream` response so `streamAssistant` can
58
+ * hand back the underlying reader.
59
+ */
60
+ const sseResponse = (sseText: string, init?: { ok?: boolean; status?: number }) => {
61
+ const encoder = new TextEncoder();
62
+ let sent = false;
63
+ const reader: ReadableStreamDefaultReader<Uint8Array> = {
64
+ read: async () => {
65
+ if (sent) return { done: true, value: undefined };
66
+ sent = true;
67
+ return { done: false, value: encoder.encode(sseText) };
68
+ },
69
+ releaseLock: () => undefined,
70
+ cancel: async () => undefined,
71
+ closed: Promise.resolve(undefined),
72
+ } as unknown as ReadableStreamDefaultReader<Uint8Array>;
73
+
74
+ return {
75
+ ok: init?.ok ?? true,
76
+ status: init?.status ?? 200,
77
+ statusText: 'OK',
78
+ headers: { get: (h: string) => (h.toLowerCase() === 'content-type' ? 'text/event-stream' : null) },
79
+ body: { getReader: () => reader },
80
+ json: async () => ({}),
81
+ };
82
+ };
83
+
84
+ /** Drain a reader into a decoded string (the consumer-side SSE decode path). */
85
+ const drainReader = async (reader: ReadableStreamDefaultReader<Uint8Array>): Promise<string> => {
86
+ const decoder = new TextDecoder();
87
+ let out = '';
88
+ for (;;) {
89
+ const { done, value } = await reader.read();
90
+ if (done) break;
91
+ if (value) out += decoder.decode(value, { stream: true });
92
+ }
93
+ out += decoder.decode();
94
+ return out;
95
+ };
96
+
97
+ describe('streamAssistant', () => {
98
+ const buildRequest = (): AssistantStreamRequest => ({
99
+ prompt: 'propose fields for a brooding detective persona',
100
+ messages: [{ role: 'user', content: 'hello' }],
101
+ modelId: 'local-tool-model',
102
+ routeContext: { surface: 'studio/cast', formId: 'persona', entityId: 'story-1' },
103
+ });
104
+
105
+ it('POSTs to /api/v1/assistant/stream on the chat base URL with the request body', async () => {
106
+ const fetchMock = jest.fn().mockResolvedValue(sseResponse('data: [DONE]\n\n'));
107
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
108
+
109
+ const req = buildRequest();
110
+ await makeAuthedClient().streamAssistant(req);
111
+
112
+ expect(fetchMock).toHaveBeenCalledTimes(1);
113
+ const [url, init] = fetchMock.mock.calls[0];
114
+ // chatApiBaseUrl, not baseURL — the assistant stream lives on the chat service.
115
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/assistant/stream`);
116
+ expect(init.method).toBe('POST');
117
+ expect(init.headers).toMatchObject({ 'Content-Type': 'application/json' });
118
+
119
+ const sentBody = JSON.parse(init.body as string);
120
+ expect(sentBody).toEqual({
121
+ prompt: req.prompt,
122
+ messages: req.messages,
123
+ modelId: req.modelId,
124
+ routeContext: { surface: 'studio/cast', formId: 'persona', entityId: 'story-1' },
125
+ });
126
+ // The assistant is not video-scoped: the request carries no videoId.
127
+ expect(sentBody).not.toHaveProperty('videoId');
128
+ });
129
+
130
+ it('includes the Authorization header when a sessionToken is set', async () => {
131
+ const fetchMock = jest.fn().mockResolvedValue(sseResponse('data: [DONE]\n\n'));
132
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
133
+
134
+ await makeAuthedClient('user-jwt-abc').streamAssistant(buildRequest());
135
+
136
+ const [, init] = fetchMock.mock.calls[0];
137
+ expect(init.headers).toMatchObject({ Authorization: 'Bearer user-jwt-abc' });
138
+ });
139
+
140
+ it('omits the Authorization header when sessionToken is undefined', async () => {
141
+ const fetchMock = jest.fn().mockResolvedValue(sseResponse('data: [DONE]\n\n'));
142
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
143
+
144
+ await makeUnauthedClient().streamAssistant(buildRequest());
145
+
146
+ const [, init] = fetchMock.mock.calls[0];
147
+ expect(init.headers).not.toHaveProperty('Authorization');
148
+ });
149
+
150
+ it('threads the AbortSignal through to fetch so the caller can cancel the stream', async () => {
151
+ const fetchMock = jest.fn().mockResolvedValue(sseResponse('data: [DONE]\n\n'));
152
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
153
+
154
+ const controller = new AbortController();
155
+ await makeAuthedClient().streamAssistant(buildRequest(), controller.signal);
156
+
157
+ const [, init] = fetchMock.mock.calls[0];
158
+ expect(init.signal).toBe(controller.signal);
159
+ });
160
+
161
+ it('returns the SSE reader so suggestion + tool_result events decode into the typed variants', async () => {
162
+ const suggestionFrame = {
163
+ type: 'suggestion',
164
+ targetForm: 'persona',
165
+ fields: { name: 'Cole Tarrant', systemPrompt: 'A weary, brooding detective.' },
166
+ rationale: 'Matches the noir brief.',
167
+ };
168
+ // The dispatcher emits a tool_result frame after EVERY assistant tool call
169
+ // (parity with the executor path) — here it follows the propose_form_fields
170
+ // suggestion. The union must carry it so exhaustive consumers don't drop it.
171
+ const toolResultFrame = {
172
+ type: 'tool_result',
173
+ tool: 'propose_form_fields',
174
+ toolUseId: 'tu-1',
175
+ result: { status: 'proposed', fieldCount: 2 },
176
+ };
177
+ const sse = `data: ${JSON.stringify(suggestionFrame)}\n\ndata: ${JSON.stringify(toolResultFrame)}\n\ndata: [DONE]\n\n`;
178
+ const fetchMock = jest.fn().mockResolvedValue(sseResponse(sse));
179
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
180
+
181
+ const reader = await makeAuthedClient().streamAssistant(buildRequest());
182
+ const text = await drainReader(reader);
183
+
184
+ const dataLines = text
185
+ .split('\n')
186
+ .filter((l) => l.startsWith('data: '))
187
+ .map((l) => l.slice(6))
188
+ .filter((d) => d !== '[DONE]');
189
+
190
+ const events: AssistantStreamEvent[] = dataLines.map((d) => JSON.parse(d) as AssistantStreamEvent);
191
+ const suggestion = events.find((e): e is Extract<AssistantStreamEvent, { type: 'suggestion' }> =>
192
+ e.type === 'suggestion',
193
+ );
194
+
195
+ expect(suggestion).toBeDefined();
196
+ // Type-narrowed access proves the union variant carries the wire contract.
197
+ expect(suggestion!.targetForm).toBe('persona');
198
+ expect(suggestion!.fields).toEqual({
199
+ name: 'Cole Tarrant',
200
+ systemPrompt: 'A weary, brooding detective.',
201
+ });
202
+ expect(suggestion!.rationale).toBe('Matches the noir brief.');
203
+
204
+ const toolResult = events.find((e): e is Extract<AssistantStreamEvent, { type: 'tool_result' }> =>
205
+ e.type === 'tool_result',
206
+ );
207
+ expect(toolResult).toBeDefined();
208
+ expect(toolResult!.tool).toBe('propose_form_fields');
209
+ expect(toolResult!.toolUseId).toBe('tu-1');
210
+ expect(toolResult!.result).toEqual({ status: 'proposed', fieldCount: 2 });
211
+ });
212
+
213
+ it('propagates non-2xx responses as Errors with the backend detail', async () => {
214
+ const fetchMock = jest.fn().mockResolvedValue({
215
+ ok: false,
216
+ status: 401,
217
+ statusText: 'Unauthorized',
218
+ json: async () => ({ detail: 'Authentication required' }),
219
+ });
220
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
221
+
222
+ await expect(makeAuthedClient().streamAssistant(buildRequest())).rejects.toThrow(
223
+ 'Authentication required',
224
+ );
225
+ });
226
+ });
227
+
228
+ describe('AssistantStreamEvent suggestion variant typing', () => {
229
+ it('narrows the suggestion variant alongside the existing variants without replacing them', () => {
230
+ // Compile-time guarantee: the suggestion variant coexists with the
231
+ // streamed text/tool/citation/error/done variants (never replaces one).
232
+ const render = (event: AssistantStreamEvent): string => {
233
+ switch (event.type) {
234
+ case 'suggestion':
235
+ return `${event.targetForm}:${Object.keys(event.fields).join(',')}`;
236
+ case 'tool_result':
237
+ return `${event.tool}:${event.toolUseId}`;
238
+ default:
239
+ return event.type;
240
+ }
241
+ };
242
+
243
+ const suggestion: AssistantStreamEvent = {
244
+ type: 'suggestion',
245
+ targetForm: 'persona',
246
+ fields: { name: 'Cole' },
247
+ };
248
+ expect(render(suggestion)).toBe('persona:name');
249
+
250
+ const toolResult: AssistantStreamEvent = {
251
+ type: 'tool_result',
252
+ tool: 'describe_tool',
253
+ toolUseId: 'tu-9',
254
+ result: { status: 'pending_reference_api' },
255
+ };
256
+ expect(render(toolResult)).toBe('describe_tool:tu-9');
257
+ });
258
+ });
259
+
260
+ /**
261
+ * R4b — the read-only Platform Assistant reference API:
262
+ * - `ApiClient.getFormSchema(form)` GETs `/api/v1/schema/{form}` on the CHAT
263
+ * base URL (the assistant router lives there, like `streamAssistant`) and
264
+ * parses `{ form, fields: [{ name, type, required, description,
265
+ * constraints?, examples? }], traceId }`.
266
+ * - `ApiClient.listToolReferences()` GETs `/api/v1/tools/reference` → `{ tools:
267
+ * [{ name, description, params }], traceId }`.
268
+ * - `ApiClient.getToolReference(name)` GETs `/api/v1/tools/reference/{name}`
269
+ * → `{ name, description, params, traceId }`.
270
+ * Each reuses the same authed `chatRequest`/`requestJson` JSON helper the other
271
+ * chat-base GETs use (the Authorization header is present iff a session token
272
+ * is set) — no forked fetch path.
273
+ */
274
+ const jsonResponse = (payload: unknown, init?: { ok?: boolean; status?: number }) => ({
275
+ ok: init?.ok ?? true,
276
+ status: init?.status ?? 200,
277
+ statusText: 'OK',
278
+ headers: { get: () => 'application/json' },
279
+ json: async () => payload,
280
+ });
281
+
282
+ describe('getFormSchema', () => {
283
+ const personaSchema: FormSchemaResponse = {
284
+ form: 'personas',
285
+ fields: [
286
+ {
287
+ name: 'name',
288
+ type: 'string',
289
+ required: true,
290
+ description: 'Display name of the persona',
291
+ },
292
+ {
293
+ name: 'systemPrompt',
294
+ type: 'string',
295
+ required: true,
296
+ description: 'The persona system prompt',
297
+ constraints: { maxLength: 8000 },
298
+ examples: ['A weary, brooding detective.'],
299
+ },
300
+ {
301
+ name: 'voiceId',
302
+ type: 'string',
303
+ required: false,
304
+ description: 'Optional TTS voice id',
305
+ },
306
+ ],
307
+ traceId: 'trace-form-1',
308
+ };
309
+
310
+ it('GETs /api/v1/schema/{form} on the chat base URL and parses the typed response', async () => {
311
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(personaSchema));
312
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
313
+
314
+ const result = await makeAuthedClient().getFormSchema('personas');
315
+
316
+ expect(fetchMock).toHaveBeenCalledTimes(1);
317
+ const [url, init] = fetchMock.mock.calls[0];
318
+ // chat base URL — the assistant/reference router lives on the chat service.
319
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/schema/personas`);
320
+ expect(init.method ?? 'GET').toBe('GET');
321
+
322
+ expect(result).toEqual(personaSchema);
323
+ expect(result.form).toBe('personas');
324
+ expect(result.fields.map((f) => f.name)).toEqual(['name', 'systemPrompt', 'voiceId']);
325
+ expect(result.fields[1].constraints).toEqual({ maxLength: 8000 });
326
+ expect(result.fields[1].examples).toEqual(['A weary, brooding detective.']);
327
+ expect(result.traceId).toBe('trace-form-1');
328
+ });
329
+
330
+ it('url-encodes the form id', async () => {
331
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(personaSchema));
332
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
333
+
334
+ await makeAuthedClient().getFormSchema('a/b');
335
+
336
+ const [url] = fetchMock.mock.calls[0];
337
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/schema/a%2Fb`);
338
+ });
339
+
340
+ it('includes the Authorization header when a sessionToken is set', async () => {
341
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(personaSchema));
342
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
343
+
344
+ await makeAuthedClient('user-jwt-form').getFormSchema('personas');
345
+
346
+ const [, init] = fetchMock.mock.calls[0];
347
+ expect(init.headers).toMatchObject({ Authorization: 'Bearer user-jwt-form' });
348
+ });
349
+
350
+ it('omits the Authorization header when sessionToken is undefined', async () => {
351
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(personaSchema));
352
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
353
+
354
+ await makeUnauthedClient().getFormSchema('personas');
355
+
356
+ const [, init] = fetchMock.mock.calls[0];
357
+ expect(init.headers).not.toHaveProperty('Authorization');
358
+ });
359
+ });
360
+
361
+ describe('listToolReferences', () => {
362
+ const toolList: ToolReferenceListResponse = {
363
+ tools: [
364
+ {
365
+ name: 'propose_form_fields',
366
+ description: 'Propose values for the fields of the current form.',
367
+ params: {
368
+ targetForm: { type: 'string', required: true },
369
+ fields: { type: 'object', required: true },
370
+ rationale: { type: 'string', required: false },
371
+ },
372
+ },
373
+ {
374
+ name: 'describe_tool',
375
+ description: 'Describe a single platform tool.',
376
+ params: { toolName: { type: 'string', required: true } },
377
+ },
378
+ ],
379
+ traceId: 'trace-tools-1',
380
+ };
381
+
382
+ it('GETs /api/v1/tools/reference on the chat base URL and parses the typed list', async () => {
383
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(toolList));
384
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
385
+
386
+ const result = await makeAuthedClient().listToolReferences();
387
+
388
+ expect(fetchMock).toHaveBeenCalledTimes(1);
389
+ const [url, init] = fetchMock.mock.calls[0];
390
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/tools/reference`);
391
+ expect(init.method ?? 'GET').toBe('GET');
392
+
393
+ expect(result).toEqual(toolList);
394
+ expect(result.tools.map((t) => t.name)).toEqual(['propose_form_fields', 'describe_tool']);
395
+ expect(result.traceId).toBe('trace-tools-1');
396
+ });
397
+
398
+ it('includes the Authorization header when a sessionToken is set', async () => {
399
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(toolList));
400
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
401
+
402
+ await makeAuthedClient('user-jwt-tools').listToolReferences();
403
+
404
+ const [, init] = fetchMock.mock.calls[0];
405
+ expect(init.headers).toMatchObject({ Authorization: 'Bearer user-jwt-tools' });
406
+ });
407
+ });
408
+
409
+ describe('getToolReference', () => {
410
+ // The backend nests the tool under `tool` (ToolReferenceDetailResponse), with
411
+ // traceId at the top level — like the list's { tools, traceId } shape.
412
+ const toolRef: ToolReferenceResponse = {
413
+ tool: {
414
+ name: 'propose_form_fields',
415
+ description: 'Propose values for the fields of the current form.',
416
+ params: {
417
+ targetForm: { type: 'string', required: true },
418
+ fields: { type: 'object', required: true },
419
+ rationale: { type: 'string', required: false },
420
+ },
421
+ },
422
+ traceId: 'trace-tool-1',
423
+ };
424
+
425
+ it('GETs /api/v1/tools/reference/{name} on the chat base URL and parses the nested tool', async () => {
426
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(toolRef));
427
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
428
+
429
+ const result = await makeAuthedClient().getToolReference('propose_form_fields');
430
+
431
+ expect(fetchMock).toHaveBeenCalledTimes(1);
432
+ const [url, init] = fetchMock.mock.calls[0];
433
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/tools/reference/propose_form_fields`);
434
+ expect(init.method ?? 'GET').toBe('GET');
435
+
436
+ expect(result).toEqual(toolRef);
437
+ expect(result.tool.name).toBe('propose_form_fields');
438
+ expect(result.tool.params.targetForm).toEqual({ type: 'string', required: true });
439
+ expect(result.traceId).toBe('trace-tool-1');
440
+ });
441
+
442
+ it('url-encodes the tool name', async () => {
443
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(toolRef));
444
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
445
+
446
+ await makeAuthedClient().getToolReference('weird/name');
447
+
448
+ const [url] = fetchMock.mock.calls[0];
449
+ expect(url).toBe(`${TEST_CHAT_BASE_URL}/api/v1/tools/reference/weird%2Fname`);
450
+ });
451
+
452
+ it('propagates a 404 for an unknown tool as an Error with the backend detail', async () => {
453
+ const fetchMock = jest.fn().mockResolvedValue(
454
+ jsonResponse({ detail: 'Unknown tool: nope' }, { ok: false, status: 404 }),
455
+ );
456
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
457
+
458
+ await expect(makeAuthedClient().getToolReference('nope')).rejects.toThrow('Unknown tool: nope');
459
+ });
460
+
461
+ it('includes the Authorization header when a sessionToken is set', async () => {
462
+ const fetchMock = jest.fn().mockResolvedValue(jsonResponse(toolRef));
463
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
464
+
465
+ await makeAuthedClient('user-jwt-tool').getToolReference('propose_form_fields');
466
+
467
+ const [, init] = fetchMock.mock.calls[0];
468
+ expect(init.headers).toMatchObject({ Authorization: 'Bearer user-jwt-tool' });
469
+ });
470
+ });
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import { TAG_AI, encodeAudioFrame, FRAME_BYTES } from '../audioProtocol';
10
+ import { buildHelloPayload } from '../audio';
10
11
 
11
12
  // ─────────────────────────────────────────────────────────────
12
13
  // Minimal AudioContext mock — covers the surface AudioFramePlayer uses
@@ -761,3 +762,67 @@ describe('AudioPipeline.handleBinaryFrame suspended-context flow', () => {
761
762
  expect(pipeline.sessionClient!.getPlaybackTracker().getPosition()).toBe(1.5);
762
763
  });
763
764
  });
765
+
766
+ // ─────────────────────────────────────────────────────────────
767
+ // buildHelloPayload — entityId (persona↔character binding)
768
+ // ─────────────────────────────────────────────────────────────
769
+
770
+ describe('buildHelloPayload entityId', () => {
771
+ it('includes entityId in the hello frame when a bound persona provides one', () => {
772
+ const payload = buildHelloPayload({ videoId: 'v1', entityId: 'ent-123' });
773
+ expect(payload).toMatchObject({ entityId: 'ent-123' });
774
+ });
775
+
776
+ it('omits entityId from the hello frame when the persona is unbound (land-dark)', () => {
777
+ const payload = buildHelloPayload({ videoId: 'v1' });
778
+ expect(payload).not.toHaveProperty('entityId');
779
+ });
780
+ });
781
+
782
+ // ─────────────────────────────────────────────────────────────
783
+ // buildHelloPayload — adventureSessionId (M9 Adventure Runtime Phase 8a)
784
+ // ─────────────────────────────────────────────────────────────
785
+
786
+ describe('buildHelloPayload adventureSessionId', () => {
787
+ it('includes adventureSessionId in the hello frame when an adventure is active', () => {
788
+ const payload = buildHelloPayload({
789
+ videoId: 'v1',
790
+ adventureSessionId: 'adv-123',
791
+ });
792
+ expect(payload).toMatchObject({ adventureSessionId: 'adv-123' });
793
+ });
794
+
795
+ it('omits adventureSessionId from the hello frame when no adventure is active (land-dark)', () => {
796
+ const payload = buildHelloPayload({ videoId: 'v1' });
797
+ expect(payload).not.toHaveProperty('adventureSessionId');
798
+ });
799
+ });
800
+
801
+ // ─────────────────────────────────────────────────────────────
802
+ // buildHelloPayload — partyPersonaIds (M10 Story Engine Phase 9a)
803
+ // ─────────────────────────────────────────────────────────────
804
+
805
+ describe('buildHelloPayload partyPersonaIds', () => {
806
+ it('includes partyPersonaIds in the hello frame when a party is present', () => {
807
+ const payload = buildHelloPayload({
808
+ videoId: 'v1',
809
+ adventureSessionId: 'adv-1',
810
+ partyPersonaIds: ['aragorn', 'legolas'],
811
+ });
812
+ expect(payload).toMatchObject({ partyPersonaIds: ['aragorn', 'legolas'] });
813
+ });
814
+
815
+ it('omits partyPersonaIds when the party is empty (M9 single-DM, land-dark)', () => {
816
+ const payload = buildHelloPayload({
817
+ videoId: 'v1',
818
+ adventureSessionId: 'adv-1',
819
+ partyPersonaIds: [],
820
+ });
821
+ expect(payload).not.toHaveProperty('partyPersonaIds');
822
+ });
823
+
824
+ it('omits partyPersonaIds when not provided (land-dark)', () => {
825
+ const payload = buildHelloPayload({ videoId: 'v1' });
826
+ expect(payload).not.toHaveProperty('partyPersonaIds');
827
+ });
828
+ });