@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,171 @@
1
+ /**
2
+ * Tests for the M7 Phase 7 (Creator Studio) Story API client methods.
3
+ *
4
+ * Contract: the backend emits camelCase JSON keys verbatim (no remapping in
5
+ * client-core), so the parsed objects match the StorySummary / StoryDetail
6
+ * interfaces field-for-field. storyId === videoId (1:1) in P7, and posterUrl
7
+ * is always null today (optional + nullable in the type).
8
+ */
9
+ import { ApiClient } from '../api';
10
+ import type {
11
+ GetStoryResponse,
12
+ ListStoriesResponse,
13
+ } from '../api';
14
+
15
+ describe('ApiClient story methods (M7 P7)', () => {
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://api.example.com/chat',
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
+ it('listStories hits /api/v1/stories and returns parsed stories', async () => {
46
+ const body: ListStoriesResponse = {
47
+ traceId: 'trace-list',
48
+ stories: [
49
+ {
50
+ storyId: 'those-who-remain',
51
+ videoId: 'those-who-remain',
52
+ title: 'Those Who Remain',
53
+ updatedAt: '2026-05-20T18:04:11+00:00',
54
+ posterUrl: null,
55
+ },
56
+ ],
57
+ };
58
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
59
+
60
+ const result = await client.listStories();
61
+
62
+ expect(result.traceId).toBe('trace-list');
63
+ expect(result.stories).toHaveLength(1);
64
+ const story = result.stories[0];
65
+ // storyId === videoId (1:1) in P7.
66
+ expect(story.storyId).toBe('those-who-remain');
67
+ expect(story.videoId).toBe('those-who-remain');
68
+ expect(story.storyId).toBe(story.videoId);
69
+ expect(story.title).toBe('Those Who Remain');
70
+ expect(story.updatedAt).toBe('2026-05-20T18:04:11+00:00');
71
+ expect(story.posterUrl).toBeNull();
72
+
73
+ expect(fetchMock).toHaveBeenCalledTimes(1);
74
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
75
+ expect(calledUrl).toBe('https://api.example.com/api/v1/stories');
76
+ });
77
+
78
+ it('listStories returns an empty array when there are no stories', async () => {
79
+ const body: ListStoriesResponse = { traceId: 'trace-empty', stories: [] };
80
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
81
+
82
+ const result = await client.listStories();
83
+
84
+ expect(result.traceId).toBe('trace-empty');
85
+ expect(result.stories).toEqual([]);
86
+ });
87
+
88
+ it('getStory hits /api/v1/stories/{storyId} and returns the detail + counts', async () => {
89
+ const body: GetStoryResponse = {
90
+ traceId: 'trace-detail',
91
+ story: {
92
+ storyId: 'those-who-remain',
93
+ videoId: 'those-who-remain',
94
+ title: 'Those Who Remain',
95
+ updatedAt: '2026-05-20T18:04:11+00:00',
96
+ posterUrl: null,
97
+ counts: { acts: 3, scenes: 12, characters: 5, documents: 2 },
98
+ },
99
+ };
100
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
101
+
102
+ const result = await client.getStory('those-who-remain');
103
+
104
+ expect(result.traceId).toBe('trace-detail');
105
+ const story = result.story;
106
+ expect(story.storyId).toBe('those-who-remain');
107
+ expect(story.videoId).toBe('those-who-remain');
108
+ expect(story.title).toBe('Those Who Remain');
109
+ expect(story.updatedAt).toBe('2026-05-20T18:04:11+00:00');
110
+ expect(story.posterUrl).toBeNull();
111
+ expect(story.counts).toEqual({
112
+ acts: 3,
113
+ scenes: 12,
114
+ characters: 5,
115
+ documents: 2,
116
+ });
117
+
118
+ expect(fetchMock).toHaveBeenCalledTimes(1);
119
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
120
+ expect(calledUrl).toBe('https://api.example.com/api/v1/stories/those-who-remain');
121
+ });
122
+
123
+ it('getStory percent-encodes the id segment', async () => {
124
+ const body: GetStoryResponse = {
125
+ traceId: 'trace-enc',
126
+ story: {
127
+ storyId: 'a b/c',
128
+ videoId: 'a b/c',
129
+ title: 'a b/c',
130
+ updatedAt: '2026-05-20T18:04:11+00:00',
131
+ posterUrl: null,
132
+ counts: { acts: 0, scenes: 0, characters: 0, documents: 0 },
133
+ },
134
+ };
135
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
136
+
137
+ await client.getStory('a b/c');
138
+
139
+ const calledUrl = fetchMock.mock.calls[0][0] as string;
140
+ expect(calledUrl).toBe('https://api.example.com/api/v1/stories/a%20b%2Fc');
141
+ });
142
+
143
+ it('getStory surfaces a 404 as a thrown error', async () => {
144
+ fetchMock.mockResolvedValueOnce(
145
+ mockJsonResponse({ detail: 'Story not found' }, 404),
146
+ );
147
+
148
+ await expect(client.getStory('missing')).rejects.toThrow('Story not found');
149
+ });
150
+
151
+ it('tolerates posterUrl being absent (optional) in the parsed shape', async () => {
152
+ // The backend always emits posterUrl=null today, but the type is
153
+ // optional too. A payload that omits it must still type-check and parse.
154
+ const body = {
155
+ traceId: 'trace-noposter',
156
+ stories: [
157
+ {
158
+ storyId: 'v1',
159
+ videoId: 'v1',
160
+ title: 'v1',
161
+ updatedAt: '2026-05-20T18:04:11+00:00',
162
+ },
163
+ ],
164
+ } as ListStoriesResponse;
165
+ fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
166
+
167
+ const result = await client.listStories();
168
+
169
+ expect(result.stories[0].posterUrl).toBeUndefined();
170
+ });
171
+ });
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Unit tests for the pure storyGraph projection (originally M7 P7; lifted into
3
+ * client-core in Platform Restructure R8.1 — this is the re-homed canonical
4
+ * test, the web copy is now a thin shim-surface assertion). Runner: jest.
5
+ *
6
+ * Fixture graph mirrors the get_video_graph payload shape:
7
+ * node.id === elementId(n); edge.source/target === elementId of the endpoints.
8
+ * Business ids (sceneId/entityId/arcId) live in node.properties.
9
+ * Edge names match the real graph vocabulary: CONTAINS (act->scene, scene->shot),
10
+ * FEATURES (scene<->character), SET_IN (scene->location), ON_ARC (char->arc),
11
+ * RELATES_TO (char<->char). Scene/Shot times are startTime/endTime; Act is t0/t1.
12
+ */
13
+ import type { VideoGraphResponse } from '../api';
14
+ import { deriveScenes, deriveCast } from '../storyGraph';
15
+
16
+ function makeGraph(): VideoGraphResponse {
17
+ return {
18
+ traceId: 't-1',
19
+ videoId: 'v-1',
20
+ nodes: [
21
+ { id: 'n-act2', label: 'Act', properties: { actId: 'a2', title: 'Act Two', index: 2, t0: 200, t1: 400 } },
22
+ { id: 'n-act1', label: 'Act', properties: { actId: 'a1', title: 'Act One', index: 1, t0: 0, t1: 200 } },
23
+ { id: 'n-s2', label: 'Scene', properties: { sceneId: 's2', title: 'Scene Two', index: 2, startTime: 60, endTime: 120 } },
24
+ { id: 'n-s1', label: 'Scene', properties: { sceneId: 's1', title: 'Scene One', index: 1, startTime: 0, endTime: 60 } },
25
+ { id: 'n-s3', label: 'Scene', properties: { sceneId: 's3', title: 'Scene Three', index: 1, startTime: 200, endTime: 300 } },
26
+ { id: 'n-sh2', label: 'Shot', properties: { shotId: 'sh2', caption: 'Second shot', index: 2, startTime: 10, endTime: 20 } },
27
+ { id: 'n-sh1', label: 'Shot', properties: { shotId: 'sh1', caption: 'First shot', index: 1, startTime: 0, endTime: 10 } },
28
+ { id: 'n-char1', label: 'Entity', properties: { entityId: 'c1', name: 'Alice', type: 'character', aliases: ['Al'] } },
29
+ { id: 'n-char2', label: 'Entity', properties: { entityId: 'c2', name: 'Bob', type: 'character', aliases: [] } },
30
+ { id: 'n-loc1', label: 'Entity', properties: { entityId: 'l1', name: 'The Bunker', type: 'location' } },
31
+ { id: 'n-arc1', label: 'CharacterArc', properties: { arcId: 'arc1', title: "Alice's redemption", index: 1, characterId: 'c1', description: 'arc desc' } },
32
+ { id: 'n-pb1', label: 'PlotBeat', properties: { beatId: 'pb1', title: 'A beat', index: 1 } },
33
+ { id: 'n-video', label: 'Video', properties: { videoId: 'v-1', episodeTitle: 'Pilot' } },
34
+ ],
35
+ edges: [
36
+ { id: 'e1', source: 'n-act1', target: 'n-s1', type: 'CONTAINS', properties: {} },
37
+ { id: 'e2', source: 'n-act1', target: 'n-s2', type: 'CONTAINS', properties: {} },
38
+ { id: 'e3', source: 'n-act2', target: 'n-s3', type: 'CONTAINS', properties: {} },
39
+ { id: 'e4', source: 'n-s1', target: 'n-sh2', type: 'CONTAINS', properties: {} },
40
+ { id: 'e5', source: 'n-s1', target: 'n-sh1', type: 'CONTAINS', properties: {} },
41
+ { id: 'e6', source: 'n-s1', target: 'n-char1', type: 'FEATURES', properties: {} },
42
+ { id: 'e7', source: 'n-char2', target: 'n-s1', type: 'FEATURES', properties: {} },
43
+ { id: 'e8', source: 'n-s1', target: 'n-loc1', type: 'SET_IN', properties: {} },
44
+ { id: 'e9', source: 'n-char1', target: 'n-arc1', type: 'ON_ARC', properties: {} },
45
+ { id: 'e10', source: 'n-char1', target: 'n-char2', type: 'RELATES_TO', properties: { kind: 'ally' } },
46
+ ],
47
+ };
48
+ }
49
+
50
+ describe('deriveScenes', () => {
51
+ it('sorts scenes by act.index then scene.index', () => {
52
+ const scenes = deriveScenes(makeGraph());
53
+ expect(scenes.map((s) => s.sceneId)).toEqual(['s1', 's2', 's3']);
54
+ });
55
+
56
+ it('attaches act title/index and scene timecodes (startTime/endTime)', () => {
57
+ const s1 = deriveScenes(makeGraph())[0];
58
+ expect(s1.actTitle).toBe('Act One');
59
+ expect(s1.actIndex).toBe(1);
60
+ expect(s1.title).toBe('Scene One');
61
+ expect(s1.startTime).toBe(0);
62
+ expect(s1.endTime).toBe(60);
63
+ });
64
+
65
+ it('reads Scene time bounds from t0/t1 (the get_video_graph story shape)', () => {
66
+ // Real `detail=story` Scene nodes carry t0/t1 (MERGE_SCENE), not
67
+ // start/endTime — the codex R8.1 P2. t0/t1 must win.
68
+ const graph: VideoGraphResponse = {
69
+ traceId: 't',
70
+ videoId: 'v',
71
+ nodes: [
72
+ {
73
+ id: 'n-sc',
74
+ label: 'Scene',
75
+ properties: { sceneId: 'sc1', title: 'Opener', index: 1, t0: 12, t1: 48 },
76
+ },
77
+ ],
78
+ edges: [],
79
+ };
80
+ const [scene] = deriveScenes(graph);
81
+ expect(scene.startTime).toBe(12);
82
+ expect(scene.endTime).toBe(48);
83
+ });
84
+
85
+ it('collects featured characters regardless of edge direction', () => {
86
+ const s1 = deriveScenes(makeGraph())[0];
87
+ const ids = s1.featuredCharacters.map((c) => c.entityId).sort();
88
+ expect(ids).toEqual(['c1', 'c2']);
89
+ expect(s1.featuredCharacters[0].nodeId).toBeTruthy();
90
+ });
91
+
92
+ it('resolves the scene location via SET_IN', () => {
93
+ const scenes = deriveScenes(makeGraph());
94
+ expect(scenes[0].location?.name).toBe('The Bunker');
95
+ expect(scenes[1].location).toBeNull();
96
+ });
97
+
98
+ it('lists shots sorted by index with captions', () => {
99
+ const shots = deriveScenes(makeGraph())[0].shots;
100
+ expect(shots.map((sh) => sh.caption)).toEqual(['First shot', 'Second shot']);
101
+ });
102
+ });
103
+
104
+ describe('deriveCast', () => {
105
+ it('returns only character entities (no locations/plot beats/arcs)', () => {
106
+ const cast = deriveCast(makeGraph());
107
+ expect(cast.map((c) => c.entityId).sort()).toEqual(['c1', 'c2']);
108
+ });
109
+
110
+ it('carries name + aliases eagerly', () => {
111
+ const alice = deriveCast(makeGraph()).find((c) => c.entityId === 'c1')!;
112
+ expect(alice.name).toBe('Alice');
113
+ expect(alice.aliases).toEqual(['Al']);
114
+ });
115
+
116
+ it('collects character arcs via ON_ARC sorted by index', () => {
117
+ const alice = deriveCast(makeGraph()).find((c) => c.entityId === 'c1')!;
118
+ expect(alice.arcs.map((a) => a.title)).toEqual(["Alice's redemption"]);
119
+ expect(alice.arcs[0].description).toBe('arc desc');
120
+ });
121
+
122
+ it('collects RELATES_TO neighbours regardless of direction', () => {
123
+ const cast = deriveCast(makeGraph());
124
+ const alice = cast.find((c) => c.entityId === 'c1')!;
125
+ const bob = cast.find((c) => c.entityId === 'c2')!;
126
+ expect(alice.relatedCharacterIds).toContain('c2');
127
+ expect(bob.relatedCharacterIds).toContain('c1');
128
+ });
129
+
130
+ it('lists scenes the character is featured in', () => {
131
+ const alice = deriveCast(makeGraph()).find((c) => c.entityId === 'c1')!;
132
+ expect(alice.sceneIds).toContain('s1');
133
+ });
134
+ });
@@ -1,4 +1,4 @@
1
- import { formatTimestamp } from '../timeFormat';
1
+ import { formatTimestamp, formatCitationTimestamp } from '../timeFormat';
2
2
 
3
3
  describe('formatTimestamp — default m:ss', () => {
4
4
  it('formats whole minutes and seconds', () => {
@@ -78,3 +78,24 @@ describe('formatTimestamp — centiseconds for chat citations', () => {
78
78
  );
79
79
  });
80
80
  });
81
+
82
+ describe('formatCitationTimestamp — centiseconds preset', () => {
83
+ it('matches formatTimestamp(x, { centiseconds: true }) exactly', () => {
84
+ expect(formatCitationTimestamp(83.45)).toBe(
85
+ formatTimestamp(83.45, { centiseconds: true }),
86
+ );
87
+ expect(formatCitationTimestamp(0)).toBe(
88
+ formatTimestamp(0, { centiseconds: true }),
89
+ );
90
+ expect(formatCitationTimestamp(3725.5)).toBe(
91
+ formatTimestamp(3725.5, { centiseconds: true }),
92
+ );
93
+ });
94
+
95
+ it('returns the expected concrete strings', () => {
96
+ expect(formatCitationTimestamp(83.45)).toBe('1:23.45');
97
+ expect(formatCitationTimestamp(0)).toBe('0:00.00');
98
+ expect(formatCitationTimestamp(65.5)).toBe('1:05.50');
99
+ expect(formatCitationTimestamp(3725.5)).toBe('1:02:05.50');
100
+ });
101
+ });
@@ -0,0 +1,57 @@
1
+ import {
2
+ AGENT_TOOL_SCHEMAS,
3
+ AGENT_TOOL_NAMES,
4
+ getAgentToolSchema,
5
+ } from '../toolSchemas';
6
+
7
+ // Mirror of shared/tool_schemas.py — the backend single source of truth.
8
+ const EXPECTED_TOOL_NAMES = [
9
+ 'list_videos',
10
+ 'semantic_search',
11
+ 'events_for_range',
12
+ 'clip_lookup',
13
+ 'entity_timeline',
14
+ 'scene_neighbors',
15
+ 'dialog_search',
16
+ 'get_transcript',
17
+ 'speaker_dialog',
18
+ 'extract_image',
19
+ 'regenerate_image',
20
+ 'generate_character',
21
+ ] as const;
22
+
23
+ describe('AGENT_TOOL_SCHEMAS', () => {
24
+ it('mirrors the 12 backend tool names in canonical order', () => {
25
+ expect(AGENT_TOOL_NAMES).toEqual(EXPECTED_TOOL_NAMES);
26
+ expect(AGENT_TOOL_SCHEMAS).toHaveLength(12);
27
+ });
28
+
29
+ it('exposes a non-empty description and endpoint for every tool', () => {
30
+ for (const tool of AGENT_TOOL_SCHEMAS) {
31
+ expect(tool.description.length).toBeGreaterThan(0);
32
+ expect(tool.endpoint.startsWith('/api/v1/')).toBe(true);
33
+ expect(['GET', 'POST']).toContain(tool.httpMethod);
34
+ }
35
+ });
36
+
37
+ it('marks list_videos as a GET tool (mirrors http_method)', () => {
38
+ const listVideos = getAgentToolSchema('list_videos');
39
+ expect(listVideos?.httpMethod).toBe('GET');
40
+ });
41
+
42
+ it('encodes the semantic_search scope enum', () => {
43
+ const semanticSearch = getAgentToolSchema('semantic_search');
44
+ const scope = semanticSearch?.fields.find((f) => f.name === 'scope');
45
+ expect(scope?.enum).toEqual(['shots', 'videos', 'hybrid']);
46
+ });
47
+
48
+ it('marks required fields on a required-field tool', () => {
49
+ const clip = getAgentToolSchema('clip_lookup');
50
+ const required = clip?.fields.filter((f) => f.required).map((f) => f.name);
51
+ expect(required).toEqual(['videoId', 't0', 't1']);
52
+ });
53
+
54
+ it('returns undefined for an unknown tool name', () => {
55
+ expect(getAgentToolSchema('nope')).toBeUndefined();
56
+ });
57
+ });
@@ -217,3 +217,275 @@ describe('createPersonaCharacter', () => {
217
217
  ).rejects.toThrow('Persona not found: p-1');
218
218
  });
219
219
  });
220
+
221
+ describe('graph editor API — M7 P1a auth-floor + ownership-seam wiring', () => {
222
+ describe('getGraphSchema', () => {
223
+ const buildResponse = () => ({
224
+ traceId: 'trace-schema',
225
+ labels: {
226
+ Video: { pk: 'videoId', editable: ['episodeTitle', 'fileName'] },
227
+ Shot: { pk: 'shotId', editable: ['caption'] },
228
+ },
229
+ edges: {
230
+ MENTIONS: { editable: ['confidence'] },
231
+ },
232
+ });
233
+
234
+ it('GETs /api/v1/tools/graph/schema on the tools base URL with no body', async () => {
235
+ const fetchMock = jest.fn().mockResolvedValue({
236
+ ok: true,
237
+ status: 200,
238
+ json: async () => buildResponse(),
239
+ });
240
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
241
+
242
+ const result = await makeClient().getGraphSchema();
243
+
244
+ expect(fetchMock).toHaveBeenCalledTimes(1);
245
+ const [url, init] = fetchMock.mock.calls[0];
246
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/schema`);
247
+ // GET — no method override means undefined (fetch defaults to GET) and no body.
248
+ expect(init.method).toBeUndefined();
249
+ expect(init.body).toBeUndefined();
250
+ expect(result.labels.Video.pk).toBe('videoId');
251
+ expect(result.edges.MENTIONS.editable).toEqual(['confidence']);
252
+ expect(result.traceId).toBe('trace-schema');
253
+ });
254
+ });
255
+
256
+ describe('updateGraphNode', () => {
257
+ it('PATCHes /api/v1/tools/graph/nodes with body that carries NO idProperty', async () => {
258
+ const fetchMock = jest.fn().mockResolvedValue({
259
+ ok: true,
260
+ status: 200,
261
+ json: async () => ({ traceId: 't', properties: { name: 'Rey' } }),
262
+ });
263
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
264
+
265
+ await makeClient().updateGraphNode({
266
+ nodeLabel: 'Entity',
267
+ idValue: 'entity-1',
268
+ properties: { name: 'Rey' },
269
+ });
270
+
271
+ const [url, init] = fetchMock.mock.calls[0];
272
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/nodes`);
273
+ expect(init.method).toBe('PATCH');
274
+ const body = JSON.parse(init.body);
275
+ expect(body).toEqual({
276
+ nodeLabel: 'Entity',
277
+ idValue: 'entity-1',
278
+ properties: { name: 'Rey' },
279
+ });
280
+ // idProperty was dropped from the wire contract (backend derives the PK).
281
+ expect('idProperty' in body).toBe(false);
282
+ });
283
+ });
284
+
285
+ describe('deleteGraphNode', () => {
286
+ it('DELETEs via query params (nodeLabel + idValue) with NO request body', async () => {
287
+ const fetchMock = jest.fn().mockResolvedValue({
288
+ ok: true,
289
+ status: 200,
290
+ json: async () => ({ traceId: 't', deleted: 1 }),
291
+ });
292
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
293
+
294
+ const result = await makeClient().deleteGraphNode({
295
+ nodeLabel: 'Entity',
296
+ idValue: 'entity 1/with weird chars',
297
+ });
298
+
299
+ const [url, init] = fetchMock.mock.calls[0];
300
+ expect(init.method).toBe('DELETE');
301
+ expect(init.body).toBeUndefined();
302
+ const parsed = new URL(url);
303
+ expect(parsed.pathname).toBe('/api/v1/tools/graph/nodes');
304
+ expect(parsed.searchParams.get('nodeLabel')).toBe('Entity');
305
+ expect(parsed.searchParams.get('idValue')).toBe('entity 1/with weird chars');
306
+ expect(result.deleted).toBe(1);
307
+ });
308
+ });
309
+
310
+ describe('deleteGraphEdge', () => {
311
+ it('DELETEs via query params (sourceId + targetId + relType) with NO body', async () => {
312
+ const fetchMock = jest.fn().mockResolvedValue({
313
+ ok: true,
314
+ status: 200,
315
+ json: async () => ({ traceId: 't', deleted: 1 }),
316
+ });
317
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
318
+
319
+ const result = await makeClient().deleteGraphEdge({
320
+ sourceId: 'Shot:shotId:s-1',
321
+ targetId: 'Entity:entityId:e-1',
322
+ relType: 'MENTIONS',
323
+ });
324
+
325
+ const [url, init] = fetchMock.mock.calls[0];
326
+ expect(init.method).toBe('DELETE');
327
+ expect(init.body).toBeUndefined();
328
+ const parsed = new URL(url);
329
+ expect(parsed.pathname).toBe('/api/v1/tools/graph/edges');
330
+ expect(parsed.searchParams.get('sourceId')).toBe('Shot:shotId:s-1');
331
+ expect(parsed.searchParams.get('targetId')).toBe('Entity:entityId:e-1');
332
+ expect(parsed.searchParams.get('relType')).toBe('MENTIONS');
333
+ expect(result.deleted).toBe(1);
334
+ });
335
+ });
336
+
337
+ describe('updateGraphEdge (unchanged — still body-based PATCH)', () => {
338
+ it('PATCHes /api/v1/tools/graph/edges with the relationship body', async () => {
339
+ const fetchMock = jest.fn().mockResolvedValue({
340
+ ok: true,
341
+ status: 200,
342
+ json: async () => ({ traceId: 't', properties: { confidence: 0.9 } }),
343
+ });
344
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
345
+
346
+ await makeClient().updateGraphEdge({
347
+ sourceId: 'Shot:shotId:s-1',
348
+ targetId: 'Entity:entityId:e-1',
349
+ relType: 'MENTIONS',
350
+ properties: { confidence: 0.9 },
351
+ });
352
+
353
+ const [url, init] = fetchMock.mock.calls[0];
354
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/edges`);
355
+ expect(init.method).toBe('PATCH');
356
+ expect(JSON.parse(init.body)).toEqual({
357
+ sourceId: 'Shot:shotId:s-1',
358
+ targetId: 'Entity:entityId:e-1',
359
+ relType: 'MENTIONS',
360
+ properties: { confidence: 0.9 },
361
+ });
362
+ });
363
+ });
364
+
365
+ describe('createGraphNode (M7 P3a — POST, 201)', () => {
366
+ it('POSTs /api/v1/tools/graph/nodes with the JSON body and parses the 201 body', async () => {
367
+ const fetchMock = jest.fn().mockResolvedValue({
368
+ ok: true,
369
+ status: 201,
370
+ json: async () => ({
371
+ traceId: 'trace-node',
372
+ nodeId: 'PlotBeat:beatId:01HX',
373
+ properties: { label: 'Inciting incident', provenance: 'user' },
374
+ }),
375
+ });
376
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
377
+
378
+ const result = await makeClient().createGraphNode({
379
+ videoId: 'video-1',
380
+ label: 'PlotBeat',
381
+ properties: { label: 'Inciting incident' },
382
+ });
383
+
384
+ const [url, init] = fetchMock.mock.calls[0];
385
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/nodes`);
386
+ expect(init.method).toBe('POST');
387
+ expect(JSON.parse(init.body)).toEqual({
388
+ videoId: 'video-1',
389
+ label: 'PlotBeat',
390
+ properties: { label: 'Inciting incident' },
391
+ });
392
+ // The 201 body is parsed (only 204 is bodyless in makeRequest).
393
+ expect(result.nodeId).toBe('PlotBeat:beatId:01HX');
394
+ expect(result.properties.provenance).toBe('user');
395
+ expect(result.traceId).toBe('trace-node');
396
+ });
397
+
398
+ it('surfaces a 422 FastAPI detail (e.g. label not user-creatable) as a thrown Error', async () => {
399
+ const fetchMock = jest.fn().mockResolvedValue({
400
+ ok: false,
401
+ status: 422,
402
+ statusText: 'Unprocessable Entity',
403
+ json: async () => ({ detail: 'Label not user-creatable' }),
404
+ });
405
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
406
+
407
+ await expect(
408
+ makeClient().createGraphNode({
409
+ videoId: 'video-1',
410
+ label: 'Act',
411
+ properties: {},
412
+ }),
413
+ ).rejects.toThrow('Label not user-creatable');
414
+ });
415
+ });
416
+
417
+ describe('createGraphEdge (M7 P3a — POST, 201)', () => {
418
+ it('POSTs /api/v1/tools/graph/edges with the JSON body and parses the 201 body', async () => {
419
+ const fetchMock = jest.fn().mockResolvedValue({
420
+ ok: true,
421
+ status: 201,
422
+ json: async () => ({
423
+ traceId: 'trace-edge',
424
+ edgeId: 'Entity:entityId:e-1|RELATES_TO|Entity:entityId:e-2',
425
+ properties: { kind: 'rival', confidence: 1.0 },
426
+ }),
427
+ });
428
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
429
+
430
+ const result = await makeClient().createGraphEdge({
431
+ videoId: 'video-1',
432
+ sourceId: 'Entity:entityId:e-1',
433
+ targetId: 'Entity:entityId:e-2',
434
+ type: 'RELATES_TO',
435
+ properties: { kind: 'rival' },
436
+ });
437
+
438
+ const [url, init] = fetchMock.mock.calls[0];
439
+ expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/edges`);
440
+ expect(init.method).toBe('POST');
441
+ expect(JSON.parse(init.body)).toEqual({
442
+ videoId: 'video-1',
443
+ sourceId: 'Entity:entityId:e-1',
444
+ targetId: 'Entity:entityId:e-2',
445
+ type: 'RELATES_TO',
446
+ properties: { kind: 'rival' },
447
+ });
448
+ expect(result.edgeId).toBe('Entity:entityId:e-1|RELATES_TO|Entity:entityId:e-2');
449
+ expect(result.properties.kind).toBe('rival');
450
+ expect(result.traceId).toBe('trace-edge');
451
+ });
452
+
453
+ it('omits properties from the body when not provided (optional field)', async () => {
454
+ const fetchMock = jest.fn().mockResolvedValue({
455
+ ok: true,
456
+ status: 201,
457
+ json: async () => ({ traceId: 't', edgeId: 'e', properties: {} }),
458
+ });
459
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
460
+
461
+ await makeClient().createGraphEdge({
462
+ videoId: 'video-1',
463
+ sourceId: 'PlotBeat:beatId:b-1',
464
+ targetId: 'PlotBeat:beatId:b-2',
465
+ type: 'LEADS_TO',
466
+ });
467
+
468
+ const body = JSON.parse(fetchMock.mock.calls[0][1].body);
469
+ expect('properties' in body).toBe(false);
470
+ });
471
+
472
+ it('surfaces a 422 FastAPI detail (invalid endpoint pair) as a thrown Error', async () => {
473
+ const fetchMock = jest.fn().mockResolvedValue({
474
+ ok: false,
475
+ status: 422,
476
+ statusText: 'Unprocessable Entity',
477
+ json: async () => ({ detail: 'Invalid endpoint labels for RELATES_TO' }),
478
+ });
479
+ (globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
480
+
481
+ await expect(
482
+ makeClient().createGraphEdge({
483
+ videoId: 'video-1',
484
+ sourceId: 'Shot:shotId:s-1',
485
+ targetId: 'Shot:shotId:s-2',
486
+ type: 'RELATES_TO',
487
+ }),
488
+ ).rejects.toThrow('Invalid endpoint labels for RELATES_TO');
489
+ });
490
+ });
491
+ });