@escapeaihq/client-core 0.12.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 (239) hide show
  1. package/README.md +31 -6
  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 +1185 -3
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +624 -51
  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 +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 +73 -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 +470 -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/controller.test.ts +697 -0
  179. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  180. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  181. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  182. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  183. package/src/__tests__/conversation/roster.test.ts +100 -0
  184. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  185. package/src/__tests__/conversation/router.test.ts +81 -0
  186. package/src/__tests__/conversation/runtime.test.ts +206 -0
  187. package/src/__tests__/conversation/voice.test.ts +440 -0
  188. package/src/__tests__/documents.test.ts +360 -0
  189. package/src/__tests__/graphSchema.test.ts +218 -9
  190. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  191. package/src/__tests__/platformAssistant.test.ts +484 -0
  192. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  193. package/src/__tests__/regeneration.test.ts +486 -0
  194. package/src/__tests__/stories.test.ts +171 -0
  195. package/src/__tests__/storyGraph.test.ts +134 -0
  196. package/src/__tests__/tools-wrappers.test.ts +272 -0
  197. package/src/__tests__/videoGraph.test.ts +94 -0
  198. package/src/__tests__/websocket.test.ts +213 -0
  199. package/src/adapters/capabilities.ts +24 -0
  200. package/src/adapters/chatAdapter.ts +114 -0
  201. package/src/adapters/directorAdapter.ts +126 -0
  202. package/src/adapters/imageAdapter.ts +100 -0
  203. package/src/adapters/index.ts +67 -0
  204. package/src/adapters/registry.ts +159 -0
  205. package/src/adapters/worldAdapter.ts +272 -0
  206. package/src/admin.ts +310 -0
  207. package/src/api.ts +1731 -116
  208. package/src/audio.ts +35 -0
  209. package/src/castProjection.ts +95 -0
  210. package/src/conversation/binding.ts +81 -0
  211. package/src/conversation/controller.ts +439 -0
  212. package/src/conversation/effectiveModel.ts +111 -0
  213. package/src/conversation/index.ts +27 -0
  214. package/src/conversation/participant.ts +71 -0
  215. package/src/conversation/presence.ts +60 -0
  216. package/src/conversation/presenceBus.ts +109 -0
  217. package/src/conversation/presenceRegistry.ts +83 -0
  218. package/src/conversation/roster.ts +111 -0
  219. package/src/conversation/rosterProjection.ts +98 -0
  220. package/src/conversation/router.ts +96 -0
  221. package/src/conversation/runtime.ts +188 -0
  222. package/src/conversation/types.ts +100 -0
  223. package/src/conversation/voice.ts +402 -0
  224. package/src/graphSchema.ts +396 -13
  225. package/src/http.ts +72 -0
  226. package/src/index.ts +9 -0
  227. package/src/platformAssistant.ts +347 -0
  228. package/src/reactor/chunkDistribution.ts +98 -0
  229. package/src/reactor/index.ts +5 -0
  230. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  231. package/src/reactor/scenesFromEnrichment.ts +11 -76
  232. package/src/reactor/seedImageOrchestrator.ts +12 -13
  233. package/src/reactor/storyTimeline.ts +127 -0
  234. package/src/storyGraph.ts +298 -0
  235. package/src/vision/VisionSourceController.ts +354 -0
  236. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  237. package/src/vision/index.ts +13 -0
  238. package/src/vision/sourceKinds.ts +75 -0
  239. package/src/websocket.ts +75 -3
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Tests for the M10 Story Engine Phase 9a (multi-persona scene orchestrator)
3
+ * party-mutation API client methods on `ApiClient`: `addPartyMember` /
4
+ * `removePartyMember`, plus `startAdventure` forwarding `partyPersonaIds`.
5
+ *
6
+ * Contract (PLAN_9A_CONTRACT §2f/§2h): the party PATCH hits
7
+ * `PATCH /api/v1/adventures/{sessionId}/party` with
8
+ * `{ action: 'add' | 'remove', personaId }` and returns the updated
9
+ * `GetAdventureResponse` (the same 200 shape as `GET adventure`). camelCase
10
+ * keys verbatim; the session id segment is percent-encoded like the other
11
+ * adventure methods.
12
+ */
13
+ import { ApiClient, PARTY_ACTION } from '../api';
14
+ import type {
15
+ AdventureState,
16
+ GetAdventureResponse,
17
+ PartyUpdateRequest,
18
+ StartAdventureRequest,
19
+ } from '../api';
20
+
21
+ describe('ApiClient party methods (M10 Phase 9a)', () => {
22
+ let client: ApiClient;
23
+ let fetchMock: jest.Mock;
24
+
25
+ beforeEach(() => {
26
+ client = new ApiClient(
27
+ 'https://api.example.com',
28
+ 'test-token',
29
+ 'https://api.example.com/chat',
30
+ );
31
+ fetchMock = jest.fn();
32
+ global.fetch = fetchMock as unknown as typeof fetch;
33
+ });
34
+
35
+ afterEach(() => {
36
+ jest.restoreAllMocks();
37
+ });
38
+
39
+ function mockJsonResponse(body: unknown, status = 200): Response {
40
+ return {
41
+ ok: status >= 200 && status < 300,
42
+ status,
43
+ statusText: 'OK',
44
+ headers: {
45
+ get: (name: string) =>
46
+ name.toLowerCase() === 'content-type' ? 'application/json' : null,
47
+ },
48
+ json: async () => body,
49
+ } as unknown as Response;
50
+ }
51
+
52
+ const sampleState: AdventureState = {
53
+ sessionId: 'adv-1',
54
+ ownerUserId: 'user-1',
55
+ storyId: 'those-who-remain',
56
+ videoId: 'those-who-remain',
57
+ dmPersonaId: 'dm-1',
58
+ partyPersonaIds: [],
59
+ currentBeatId: null,
60
+ visitedBeatIds: [],
61
+ flags: {},
62
+ inventory: [],
63
+ turnHistory: [],
64
+ createdAt: '2026-06-03T12:00:00+00:00',
65
+ updatedAt: '2026-06-03T12:00:00+00:00',
66
+ };
67
+
68
+ it('PARTY_ACTION exposes the add/remove wire literals', () => {
69
+ expect(PARTY_ACTION.ADD).toBe('add');
70
+ expect(PARTY_ACTION.REMOVE).toBe('remove');
71
+ });
72
+
73
+ it('addPartyMember PATCHes party with action=add and returns the updated state', async () => {
74
+ const body: GetAdventureResponse = {
75
+ traceId: 'trace-add',
76
+ state: { ...sampleState, partyPersonaIds: ['aragorn'] },
77
+ };
78
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
79
+
80
+ const result = await client.addPartyMember('adv-1', 'aragorn');
81
+
82
+ expect(result.traceId).toBe('trace-add');
83
+ expect(result.state.partyPersonaIds).toEqual(['aragorn']);
84
+
85
+ expect(fetchMock).toHaveBeenCalledTimes(1);
86
+ const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [
87
+ string,
88
+ RequestInit,
89
+ ];
90
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1/party');
91
+ expect(calledInit.method).toBe('PATCH');
92
+ const sentBody = JSON.parse(calledInit.body as string) as PartyUpdateRequest;
93
+ expect(sentBody).toEqual({ action: 'add', personaId: 'aragorn' });
94
+ });
95
+
96
+ it('removePartyMember PATCHes party with action=remove and returns the updated state', async () => {
97
+ const body: GetAdventureResponse = {
98
+ traceId: 'trace-remove',
99
+ state: { ...sampleState, partyPersonaIds: [] },
100
+ };
101
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
102
+
103
+ const result = await client.removePartyMember('adv-1', 'aragorn');
104
+
105
+ expect(result.traceId).toBe('trace-remove');
106
+ expect(result.state.partyPersonaIds).toEqual([]);
107
+
108
+ const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [
109
+ string,
110
+ RequestInit,
111
+ ];
112
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1/party');
113
+ expect(calledInit.method).toBe('PATCH');
114
+ const sentBody = JSON.parse(calledInit.body as string) as PartyUpdateRequest;
115
+ expect(sentBody).toEqual({ action: 'remove', personaId: 'aragorn' });
116
+ });
117
+
118
+ it('percent-encodes the session id segment in the party path', async () => {
119
+ fetchMock.mockResolvedValueOnce(
120
+ mockJsonResponse({ traceId: 't', state: sampleState }),
121
+ );
122
+
123
+ await client.addPartyMember('a b/c', 'p-1');
124
+
125
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
126
+ expect(calledUrl).toBe(
127
+ 'https://api.example.com/api/v1/adventures/a%20b%2Fc/party',
128
+ );
129
+ });
130
+
131
+ it('addPartyMember surfaces a 422 (persona is a DM) as a thrown error', async () => {
132
+ fetchMock.mockResolvedValueOnce(
133
+ mockJsonResponse({ detail: 'Persona is a Dungeon Master' }, 422),
134
+ );
135
+
136
+ await expect(
137
+ client.addPartyMember('adv-1', 'dm-1'),
138
+ ).rejects.toThrow('Persona is a Dungeon Master');
139
+ });
140
+
141
+ it('addPartyMember surfaces a 404 (adventure not found) as a thrown error', async () => {
142
+ fetchMock.mockResolvedValueOnce(
143
+ mockJsonResponse({ detail: 'Adventure not found' }, 404),
144
+ );
145
+
146
+ await expect(
147
+ client.addPartyMember('missing', 'p-1'),
148
+ ).rejects.toThrow('Adventure not found');
149
+ });
150
+
151
+ it('removePartyMember is idempotent on the client (200 no-op returns current state)', async () => {
152
+ const body: GetAdventureResponse = {
153
+ traceId: 'trace-noop',
154
+ state: { ...sampleState, partyPersonaIds: ['legolas'] },
155
+ };
156
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
157
+
158
+ const result = await client.removePartyMember('adv-1', 'absent-member');
159
+
160
+ expect(result.state.partyPersonaIds).toEqual(['legolas']);
161
+ });
162
+
163
+ it('threads an AbortSignal into the underlying fetch for the party methods', async () => {
164
+ const controller = new AbortController();
165
+ fetchMock.mockResolvedValue(
166
+ mockJsonResponse({ traceId: 't', state: sampleState }),
167
+ );
168
+
169
+ await client.addPartyMember('adv-1', 'p-1', { signal: controller.signal });
170
+
171
+ const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
172
+ expect(calledInit.signal).toBe(controller.signal);
173
+ });
174
+
175
+ it('startAdventure forwards partyPersonaIds when provided (M10 9a)', async () => {
176
+ const request: StartAdventureRequest = {
177
+ storyId: 's1',
178
+ videoId: 's1',
179
+ dmPersonaId: 'dm-1',
180
+ partyPersonaIds: ['aragorn', 'legolas'],
181
+ };
182
+ fetchMock.mockResolvedValueOnce(
183
+ mockJsonResponse(
184
+ {
185
+ traceId: 't',
186
+ sessionId: 'adv-2',
187
+ state: { ...sampleState, partyPersonaIds: ['aragorn', 'legolas'] },
188
+ },
189
+ 201,
190
+ ),
191
+ );
192
+
193
+ await client.startAdventure(request);
194
+
195
+ const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
196
+ expect(JSON.parse(calledInit.body as string)).toEqual(request);
197
+ });
198
+
199
+ it('startAdventure omits partyPersonaIds when not provided (land-dark)', async () => {
200
+ const request: StartAdventureRequest = {
201
+ storyId: 's1',
202
+ videoId: 's1',
203
+ dmPersonaId: 'dm-1',
204
+ };
205
+ fetchMock.mockResolvedValueOnce(
206
+ mockJsonResponse(
207
+ { traceId: 't', sessionId: 'adv-3', state: sampleState },
208
+ 201,
209
+ ),
210
+ );
211
+
212
+ await client.startAdventure(request);
213
+
214
+ const sentBody = JSON.parse(
215
+ fetchMock.mock.calls[0][1].body as string,
216
+ ) as Record<string, unknown>;
217
+ expect(sentBody).not.toHaveProperty('partyPersonaIds');
218
+ });
219
+ });
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Tests for the M9 Story Engine Phase 8a (Adventure Runtime) API client
3
+ * methods on `ApiClient`.
4
+ *
5
+ * Contract: the backend emits camelCase JSON keys verbatim (no remapping in
6
+ * client-core), so the parsed objects match the AdventureState / AdventureResponse
7
+ * interfaces field-for-field. `startAdventure` POSTs the request body and yields
8
+ * a 201 envelope; `getAdventure` GETs the current state; `deleteAdventure` is a
9
+ * 204 that resolves to `undefined`.
10
+ */
11
+ import { ApiClient } from '../api';
12
+ import type {
13
+ AdventureResponse,
14
+ AdventureState,
15
+ GetAdventureResponse,
16
+ ListAdventuresResponse,
17
+ StartAdventureRequest,
18
+ } from '../api';
19
+
20
+ describe('ApiClient adventure methods (M9 Phase 8a)', () => {
21
+ let client: ApiClient;
22
+ let fetchMock: jest.Mock;
23
+
24
+ beforeEach(() => {
25
+ client = new ApiClient(
26
+ 'https://api.example.com',
27
+ 'test-token',
28
+ 'https://api.example.com/chat',
29
+ );
30
+ fetchMock = jest.fn();
31
+ global.fetch = fetchMock as unknown as typeof fetch;
32
+ });
33
+
34
+ afterEach(() => {
35
+ jest.restoreAllMocks();
36
+ });
37
+
38
+ function mockJsonResponse(body: unknown, status = 200): Response {
39
+ return {
40
+ ok: status >= 200 && status < 300,
41
+ status,
42
+ statusText: 'OK',
43
+ headers: {
44
+ get: (name: string) =>
45
+ name.toLowerCase() === 'content-type' ? 'application/json' : null,
46
+ },
47
+ json: async () => body,
48
+ } as unknown as Response;
49
+ }
50
+
51
+ function mockNoContentResponse(): Response {
52
+ return {
53
+ ok: true,
54
+ status: 204,
55
+ statusText: 'No Content',
56
+ headers: { get: () => null },
57
+ json: async () => {
58
+ throw new Error('204 has no body');
59
+ },
60
+ } as unknown as Response;
61
+ }
62
+
63
+ const sampleState: AdventureState = {
64
+ sessionId: 'adv-1',
65
+ ownerUserId: 'user-1',
66
+ storyId: 'those-who-remain',
67
+ videoId: 'those-who-remain',
68
+ dmPersonaId: 'dm-1',
69
+ partyPersonaIds: [],
70
+ currentBeatId: null,
71
+ visitedBeatIds: [],
72
+ flags: {},
73
+ inventory: [],
74
+ turnHistory: [],
75
+ createdAt: '2026-06-03T12:00:00+00:00',
76
+ updatedAt: '2026-06-03T12:00:00+00:00',
77
+ };
78
+
79
+ it('startAdventure POSTs the request body to /api/v1/adventures and returns the 201 envelope', async () => {
80
+ const request: StartAdventureRequest = {
81
+ storyId: 'those-who-remain',
82
+ videoId: 'those-who-remain',
83
+ dmPersonaId: 'dm-1',
84
+ };
85
+ const body: AdventureResponse = {
86
+ traceId: 'trace-start',
87
+ sessionId: 'adv-1',
88
+ state: sampleState,
89
+ };
90
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body, 201));
91
+
92
+ const result = await client.startAdventure(request);
93
+
94
+ expect(result.traceId).toBe('trace-start');
95
+ expect(result.sessionId).toBe('adv-1');
96
+ expect(result.state.dmPersonaId).toBe('dm-1');
97
+ expect(result.state.currentBeatId).toBeNull();
98
+
99
+ expect(fetchMock).toHaveBeenCalledTimes(1);
100
+ const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [string, RequestInit];
101
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures');
102
+ expect(calledInit.method).toBe('POST');
103
+ expect(JSON.parse(calledInit.body as string)).toEqual(request);
104
+ });
105
+
106
+ it('startAdventure forwards initialBeatId when provided', async () => {
107
+ const request: StartAdventureRequest = {
108
+ storyId: 's1',
109
+ videoId: 's1',
110
+ dmPersonaId: 'dm-1',
111
+ initialBeatId: 'beat-0',
112
+ };
113
+ fetchMock.mockResolvedValueOnce(
114
+ mockJsonResponse(
115
+ { traceId: 't', sessionId: 'adv-2', state: sampleState },
116
+ 201,
117
+ ),
118
+ );
119
+
120
+ await client.startAdventure(request);
121
+
122
+ const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
123
+ expect(JSON.parse(calledInit.body as string)).toEqual(request);
124
+ });
125
+
126
+ it('startAdventure surfaces a 422 (persona is not a DM) as a thrown error', async () => {
127
+ fetchMock.mockResolvedValueOnce(
128
+ mockJsonResponse({ detail: 'Persona is not a Dungeon Master' }, 422),
129
+ );
130
+
131
+ await expect(
132
+ client.startAdventure({ storyId: 's', videoId: 's', dmPersonaId: 'p' }),
133
+ ).rejects.toThrow('Persona is not a Dungeon Master');
134
+ });
135
+
136
+ it('getAdventure GETs /api/v1/adventures/{sessionId} and returns the parsed state', async () => {
137
+ const body: GetAdventureResponse = {
138
+ traceId: 'trace-get',
139
+ state: {
140
+ ...sampleState,
141
+ currentBeatId: 'beat-3',
142
+ visitedBeatIds: ['beat-0', 'beat-3'],
143
+ flags: { door: 'open' },
144
+ inventory: ['torch'],
145
+ turnHistory: [{ turn: 1, beatId: 'beat-3', summary: 'opened the door' }],
146
+ },
147
+ };
148
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
149
+
150
+ const result = await client.getAdventure('adv-1');
151
+
152
+ expect(result.traceId).toBe('trace-get');
153
+ expect(result.state.currentBeatId).toBe('beat-3');
154
+ expect(result.state.visitedBeatIds).toEqual(['beat-0', 'beat-3']);
155
+ expect(result.state.flags).toEqual({ door: 'open' });
156
+ expect(result.state.inventory).toEqual(['torch']);
157
+ expect(result.state.turnHistory[0]).toEqual({
158
+ turn: 1,
159
+ beatId: 'beat-3',
160
+ summary: 'opened the door',
161
+ });
162
+
163
+ expect(fetchMock).toHaveBeenCalledTimes(1);
164
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
165
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1');
166
+ });
167
+
168
+ it('getAdventure percent-encodes the session id segment', async () => {
169
+ fetchMock.mockResolvedValueOnce(
170
+ mockJsonResponse({ traceId: 't', state: sampleState }),
171
+ );
172
+
173
+ await client.getAdventure('a b/c');
174
+
175
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
176
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/a%20b%2Fc');
177
+ });
178
+
179
+ it('getAdventure surfaces a 404 as a thrown error', async () => {
180
+ fetchMock.mockResolvedValueOnce(
181
+ mockJsonResponse({ detail: 'Adventure not found' }, 404),
182
+ );
183
+
184
+ await expect(client.getAdventure('missing')).rejects.toThrow(
185
+ 'Adventure not found',
186
+ );
187
+ });
188
+
189
+ it('deleteAdventure DELETEs the session and resolves (204 → undefined)', async () => {
190
+ fetchMock.mockResolvedValueOnce(mockNoContentResponse());
191
+
192
+ const result = await client.deleteAdventure('adv-1');
193
+
194
+ expect(result).toBeUndefined();
195
+ expect(fetchMock).toHaveBeenCalledTimes(1);
196
+ const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [string, RequestInit];
197
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1');
198
+ expect(calledInit.method).toBe('DELETE');
199
+ });
200
+
201
+ it('deleteAdventure surfaces a 404 as a thrown error', async () => {
202
+ fetchMock.mockResolvedValueOnce(
203
+ mockJsonResponse({ detail: 'Adventure not found' }, 404),
204
+ );
205
+
206
+ await expect(client.deleteAdventure('missing')).rejects.toThrow(
207
+ 'Adventure not found',
208
+ );
209
+ });
210
+
211
+ it('listAdventures GETs /api/v1/adventures with no query and returns the parsed adventures', async () => {
212
+ const body: ListAdventuresResponse = {
213
+ traceId: 'trace-list',
214
+ adventures: [
215
+ sampleState,
216
+ { ...sampleState, sessionId: 'adv-2', currentBeatId: 'beat-3' },
217
+ ],
218
+ };
219
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
220
+
221
+ const result = await client.listAdventures();
222
+
223
+ expect(result.traceId).toBe('trace-list');
224
+ expect(result.adventures).toHaveLength(2);
225
+ expect(result.adventures[0].sessionId).toBe('adv-1');
226
+ expect(result.adventures[1].sessionId).toBe('adv-2');
227
+ expect(result.adventures[1].currentBeatId).toBe('beat-3');
228
+
229
+ expect(fetchMock).toHaveBeenCalledTimes(1);
230
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
231
+ expect(calledUrl).toBe('https://api.example.com/api/v1/adventures');
232
+ });
233
+
234
+ it('listAdventures forwards and encodes storyId when provided', async () => {
235
+ fetchMock.mockResolvedValueOnce(
236
+ mockJsonResponse({ traceId: 't', adventures: [] }),
237
+ );
238
+
239
+ await client.listAdventures('a b/c');
240
+
241
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
242
+ expect(calledUrl).toBe(
243
+ 'https://api.example.com/api/v1/adventures?storyId=a+b%2Fc',
244
+ );
245
+ });
246
+
247
+ it('listAdventures surfaces an error response as a thrown error', async () => {
248
+ fetchMock.mockResolvedValueOnce(
249
+ mockJsonResponse({ detail: 'Unauthorized' }, 401),
250
+ );
251
+
252
+ await expect(client.listAdventures()).rejects.toThrow('Unauthorized');
253
+ });
254
+
255
+ it('listAdventures handles an empty adventures array', async () => {
256
+ fetchMock.mockResolvedValueOnce(
257
+ mockJsonResponse({ traceId: 'trace-empty', adventures: [] }),
258
+ );
259
+
260
+ const result = await client.listAdventures('those-who-remain');
261
+
262
+ expect(result.traceId).toBe('trace-empty');
263
+ expect(result.adventures).toEqual([]);
264
+
265
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
266
+ expect(calledUrl).toBe(
267
+ 'https://api.example.com/api/v1/adventures?storyId=those-who-remain',
268
+ );
269
+ });
270
+
271
+ it('threads an AbortSignal into the underlying fetch for each method', async () => {
272
+ const controller = new AbortController();
273
+ fetchMock.mockResolvedValue(
274
+ mockJsonResponse({ traceId: 't', state: sampleState }),
275
+ );
276
+
277
+ await client.getAdventure('adv-1', { signal: controller.signal });
278
+
279
+ const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
280
+ expect(calledInit.signal).toBe(controller.signal);
281
+ });
282
+ });
@@ -438,6 +438,7 @@ describe('extractImage / regenerateImage', () => {
438
438
 
439
439
  const buildRegenerateResponse = () => ({
440
440
  ...buildExtractResponse(),
441
+ imageId: 'img-regen-1',
441
442
  imageUrl: 'https://s3.example/regen.png?sig=def',
442
443
  imageS3Key: 'regenerated/def.png',
443
444
  prompt: 'cyberpunk style',
@@ -516,6 +517,9 @@ describe('extractImage / regenerateImage', () => {
516
517
  model: 'gemini-2.5-flash-image',
517
518
  });
518
519
  expect(result.prompt).toBe('cyberpunk style');
520
+ // R8.4 / tech-debt #110: the response carries the new ImageRecord id so
521
+ // /interactive can auto-select the regenerated seed (was absent pre-R8.4).
522
+ expect(result.imageId).toBe('img-regen-1');
519
523
  });
520
524
 
521
525
  it('forwards an AbortSignal to fetch for both wrappers', async () => {
@@ -0,0 +1,64 @@
1
+ /**
2
+ * clip-lookup client binding tests (M7 P7 — studio Scene inspector). The backend
3
+ * `ClipLookupRequest`/`ClipLookupResponse` use camelCase wire keys (BaseSchema
4
+ * `# noqa: N815` literal fields), but the request body the client sends mirrors
5
+ * the backend request model field names. This suite asserts the method POSTs to
6
+ * the existing tools endpoint and returns the parsed response.
7
+ *
8
+ * Runner: jest (client-core uses jest, not vitest).
9
+ */
10
+ import { ApiClient } from '../api';
11
+
12
+ describe('ApiClient clipLookup (M7 P7)', () => {
13
+ let client: ApiClient;
14
+ let fetchMock: jest.Mock;
15
+
16
+ beforeEach(() => {
17
+ client = new ApiClient(
18
+ 'https://api.example.com',
19
+ 'test-token',
20
+ 'https://api.example.com/chat',
21
+ );
22
+ fetchMock = jest.fn();
23
+ global.fetch = fetchMock as unknown as typeof fetch;
24
+ });
25
+
26
+ afterEach(() => {
27
+ jest.restoreAllMocks();
28
+ });
29
+
30
+ function mockJsonResponse(body: unknown, status = 200): Response {
31
+ return {
32
+ ok: status >= 200 && status < 300,
33
+ status,
34
+ headers: {
35
+ get: (name: string) =>
36
+ name.toLowerCase() === 'content-type' ? 'application/json' : null,
37
+ },
38
+ json: async () => body,
39
+ } as unknown as Response;
40
+ }
41
+
42
+ it('POSTs /api/v1/tools/clip-lookup and returns the parsed clip url', async () => {
43
+ const body = {
44
+ traceId: 't1',
45
+ url: 'https://signed/clip.mp4',
46
+ expiresIn: 3600,
47
+ citation: { videoId: 'v1', t0: 0, t1: 30 },
48
+ source: { system: 'tools' },
49
+ };
50
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
51
+
52
+ const res = await client.clipLookup({ videoId: 'v1', t0: 0, t1: 30 });
53
+
54
+ expect(res.url).toBe('https://signed/clip.mp4');
55
+ expect(res.expiresIn).toBe(3600);
56
+ expect(res.traceId).toBe('t1');
57
+
58
+ expect(fetchMock).toHaveBeenCalledTimes(1);
59
+ const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
60
+ expect(url).toBe('https://api.example.com/api/v1/tools/clip-lookup');
61
+ expect(init.method).toBe('POST');
62
+ expect(JSON.parse(init.body as string)).toEqual({ videoId: 'v1', t0: 0, t1: 30 });
63
+ });
64
+ });
@@ -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
+ });