@escapeaihq/client-core 0.12.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -7
- package/dist/adapters/capabilities.d.ts +10 -0
- package/dist/adapters/capabilities.d.ts.map +1 -0
- package/dist/adapters/capabilities.js +2 -0
- package/dist/adapters/capabilities.js.map +1 -0
- package/dist/adapters/chatAdapter.d.ts +38 -0
- package/dist/adapters/chatAdapter.d.ts.map +1 -0
- package/dist/adapters/chatAdapter.js +88 -0
- package/dist/adapters/chatAdapter.js.map +1 -0
- package/dist/adapters/directorAdapter.d.ts +62 -0
- package/dist/adapters/directorAdapter.d.ts.map +1 -0
- package/dist/adapters/directorAdapter.js +71 -0
- package/dist/adapters/directorAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +44 -0
- package/dist/adapters/imageAdapter.d.ts.map +1 -0
- package/dist/adapters/imageAdapter.js +73 -0
- package/dist/adapters/imageAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +47 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +41 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +98 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +106 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +142 -0
- package/dist/adapters/worldAdapter.d.ts.map +1 -0
- package/dist/adapters/worldAdapter.js +164 -0
- package/dist/adapters/worldAdapter.js.map +1 -0
- package/dist/admin.d.ts +323 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +198 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1512 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +820 -52
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +33 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +4 -1
- package/dist/audio.js.map +1 -1
- package/dist/castProjection.d.ts +35 -0
- package/dist/castProjection.d.ts.map +1 -0
- package/dist/castProjection.js +80 -0
- package/dist/castProjection.js.map +1 -0
- package/dist/conversation/binding.d.ts +77 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +57 -0
- package/dist/conversation/binding.js.map +1 -0
- package/dist/conversation/controller.d.ts +209 -0
- package/dist/conversation/controller.d.ts.map +1 -0
- package/dist/conversation/controller.js +350 -0
- package/dist/conversation/controller.js.map +1 -0
- package/dist/conversation/effectiveModel.d.ts +62 -0
- package/dist/conversation/effectiveModel.d.ts.map +1 -0
- package/dist/conversation/effectiveModel.js +73 -0
- package/dist/conversation/effectiveModel.js.map +1 -0
- package/dist/conversation/index.d.ts +27 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/participant.d.ts +66 -0
- package/dist/conversation/participant.d.ts.map +1 -0
- package/dist/conversation/participant.js +36 -0
- package/dist/conversation/participant.js.map +1 -0
- package/dist/conversation/presence.d.ts +56 -0
- package/dist/conversation/presence.d.ts.map +1 -0
- package/dist/conversation/presence.js +34 -0
- package/dist/conversation/presence.js.map +1 -0
- package/dist/conversation/presenceBus.d.ts +42 -0
- package/dist/conversation/presenceBus.d.ts.map +1 -0
- package/dist/conversation/presenceBus.js +81 -0
- package/dist/conversation/presenceBus.js.map +1 -0
- package/dist/conversation/presenceRegistry.d.ts +49 -0
- package/dist/conversation/presenceRegistry.d.ts.map +1 -0
- package/dist/conversation/presenceRegistry.js +59 -0
- package/dist/conversation/presenceRegistry.js.map +1 -0
- package/dist/conversation/roster.d.ts +72 -0
- package/dist/conversation/roster.d.ts.map +1 -0
- package/dist/conversation/roster.js +69 -0
- package/dist/conversation/roster.js.map +1 -0
- package/dist/conversation/rosterProjection.d.ts +52 -0
- package/dist/conversation/rosterProjection.d.ts.map +1 -0
- package/dist/conversation/rosterProjection.js +74 -0
- package/dist/conversation/rosterProjection.js.map +1 -0
- package/dist/conversation/router.d.ts +74 -0
- package/dist/conversation/router.d.ts.map +1 -0
- package/dist/conversation/router.js +58 -0
- package/dist/conversation/router.js.map +1 -0
- package/dist/conversation/runtime.d.ts +64 -0
- package/dist/conversation/runtime.d.ts.map +1 -0
- package/dist/conversation/runtime.js +172 -0
- package/dist/conversation/runtime.js.map +1 -0
- package/dist/conversation/types.d.ts +99 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +13 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/conversation/voice.d.ts +185 -0
- package/dist/conversation/voice.d.ts.map +1 -0
- package/dist/conversation/voice.js +307 -0
- package/dist/conversation/voice.js.map +1 -0
- package/dist/graphSchema.d.ts +201 -13
- package/dist/graphSchema.d.ts.map +1 -1
- package/dist/graphSchema.js +258 -9
- package/dist/graphSchema.js.map +1 -1
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +57 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/platformAssistant.d.ts +155 -0
- package/dist/platformAssistant.d.ts.map +1 -0
- package/dist/platformAssistant.js +256 -0
- package/dist/platformAssistant.js.map +1 -0
- package/dist/reactor/chunkDistribution.d.ts +43 -0
- package/dist/reactor/chunkDistribution.d.ts.map +1 -0
- package/dist/reactor/chunkDistribution.js +85 -0
- package/dist/reactor/chunkDistribution.js.map +1 -0
- package/dist/reactor/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +5 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/longLiveCommandDispatcher.js +87 -0
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
- package/dist/reactor/scenesFromEnrichment.js +2 -66
- package/dist/reactor/scenesFromEnrichment.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +6 -9
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +12 -13
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/storyTimeline.d.ts +44 -0
- package/dist/reactor/storyTimeline.d.ts.map +1 -0
- package/dist/reactor/storyTimeline.js +95 -0
- package/dist/reactor/storyTimeline.js.map +1 -0
- package/dist/storyGraph.d.ts +70 -0
- package/dist/storyGraph.d.ts.map +1 -0
- package/dist/storyGraph.js +178 -0
- package/dist/storyGraph.js.map +1 -0
- package/dist/vision/VisionSourceController.d.ts +127 -0
- package/dist/vision/VisionSourceController.d.ts.map +1 -0
- package/dist/vision/VisionSourceController.js +284 -0
- package/dist/vision/VisionSourceController.js.map +1 -0
- package/dist/vision/index.d.ts +4 -0
- package/dist/vision/index.d.ts.map +1 -1
- package/dist/vision/index.js +2 -0
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/sourceKinds.d.ts +65 -0
- package/dist/vision/sourceKinds.d.ts.map +1 -0
- package/dist/vision/sourceKinds.js +26 -0
- package/dist/vision/sourceKinds.js.map +1 -0
- package/dist/websocket.d.ts +92 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/adapters-capabilities.test.ts +46 -0
- package/src/__tests__/adapters-chat.test.ts +172 -0
- package/src/__tests__/adapters-director.test.ts +95 -0
- package/src/__tests__/adapters-image.test.ts +133 -0
- package/src/__tests__/adapters-platform.test.ts +95 -0
- package/src/__tests__/adapters-registry.test.ts +189 -0
- package/src/__tests__/adapters-world.test.ts +296 -0
- package/src/__tests__/admin.test.ts +312 -0
- package/src/__tests__/adventures-party.test.ts +219 -0
- package/src/__tests__/adventures.test.ts +282 -0
- package/src/__tests__/api-pollers.test.ts +4 -0
- package/src/__tests__/api.clip-lookup.test.ts +64 -0
- package/src/__tests__/api.list-images-filters.test.ts +103 -0
- package/src/__tests__/api.test.ts +553 -0
- package/src/__tests__/audio.test.ts +65 -0
- package/src/__tests__/cast.test.ts +95 -0
- package/src/__tests__/castProjection.test.ts +167 -0
- package/src/__tests__/conversation/binding.test.ts +62 -0
- package/src/__tests__/conversation/controller.test.ts +732 -0
- package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
- package/src/__tests__/conversation/headlessRenderer.ts +46 -0
- package/src/__tests__/conversation/presenceBus.test.ts +236 -0
- package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
- package/src/__tests__/conversation/roster.test.ts +100 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
- package/src/__tests__/conversation/router.test.ts +81 -0
- package/src/__tests__/conversation/runtime.test.ts +206 -0
- package/src/__tests__/conversation/voice.test.ts +440 -0
- package/src/__tests__/documents.test.ts +360 -0
- package/src/__tests__/graphSchema.test.ts +218 -9
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/monitoring.test.ts +162 -0
- package/src/__tests__/persona-generation.test.ts +352 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
- package/src/__tests__/regeneration.test.ts +486 -0
- package/src/__tests__/stories.test.ts +171 -0
- package/src/__tests__/storyGraph.test.ts +134 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket.test.ts +263 -0
- package/src/adapters/capabilities.ts +24 -0
- package/src/adapters/chatAdapter.ts +114 -0
- package/src/adapters/directorAdapter.ts +126 -0
- package/src/adapters/imageAdapter.ts +100 -0
- package/src/adapters/index.ts +67 -0
- package/src/adapters/registry.ts +159 -0
- package/src/adapters/worldAdapter.ts +272 -0
- package/src/admin.ts +517 -0
- package/src/api.ts +2215 -95
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +100 -0
- package/src/conversation/controller.ts +447 -0
- package/src/conversation/effectiveModel.ts +111 -0
- package/src/conversation/index.ts +27 -0
- package/src/conversation/participant.ts +71 -0
- package/src/conversation/presence.ts +60 -0
- package/src/conversation/presenceBus.ts +109 -0
- package/src/conversation/presenceRegistry.ts +83 -0
- package/src/conversation/roster.ts +111 -0
- package/src/conversation/rosterProjection.ts +98 -0
- package/src/conversation/router.ts +96 -0
- package/src/conversation/runtime.ts +188 -0
- package/src/conversation/types.ts +100 -0
- package/src/conversation/voice.ts +402 -0
- package/src/graphSchema.ts +396 -13
- package/src/http.ts +72 -0
- package/src/index.ts +9 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/index.ts +5 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +12 -13
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/index.ts +13 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/websocket.ts +99 -3
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the R5b `getVideoGraph` detail arg — the `detail=story|raw` query
|
|
3
|
+
* param on `GET /api/v1/tools/graph/{videoId}`. The land-dark contract is the
|
|
4
|
+
* load-bearing case: omitting `detail` must produce a request byte-identical
|
|
5
|
+
* to the pre-R5b call (NO query string), so every existing caller is
|
|
6
|
+
* untouched. Same global-fetch-mock pattern as `cast.test.ts`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ApiClient, GRAPH_DETAIL, type VideoGraphResponse } from '../api';
|
|
10
|
+
|
|
11
|
+
const TEST_BASE_URL = 'http://test.local';
|
|
12
|
+
const TEST_CHAT_BASE_URL = 'http://test.local/chat';
|
|
13
|
+
|
|
14
|
+
const makeClient = (sessionToken: string = 'test-token') =>
|
|
15
|
+
new ApiClient(TEST_BASE_URL, sessionToken, TEST_CHAT_BASE_URL);
|
|
16
|
+
|
|
17
|
+
const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
if (originalFetch === undefined) {
|
|
21
|
+
delete (globalThis as { fetch?: typeof fetch }).fetch;
|
|
22
|
+
} else {
|
|
23
|
+
(globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
|
|
24
|
+
}
|
|
25
|
+
jest.restoreAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const buildResponse = (): VideoGraphResponse => ({
|
|
29
|
+
traceId: 'trace-graph',
|
|
30
|
+
videoId: 'video-1',
|
|
31
|
+
nodes: [
|
|
32
|
+
{
|
|
33
|
+
id: 'Scene:sceneId:sc-1',
|
|
34
|
+
label: 'Scene',
|
|
35
|
+
// R5b: story-mode Scene nodes carry the read-time shotCount in the
|
|
36
|
+
// generic properties bag (no schema fork).
|
|
37
|
+
properties: { sceneId: 'sc-1', shotCount: 4 },
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
edges: [],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const mockFetch = (): jest.Mock => {
|
|
44
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
45
|
+
ok: true,
|
|
46
|
+
status: 200,
|
|
47
|
+
json: async () => buildResponse(),
|
|
48
|
+
});
|
|
49
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
50
|
+
return fetchMock;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe('getVideoGraph detail param (R5b)', () => {
|
|
54
|
+
it('omits the query string entirely when detail is not passed (land-dark)', async () => {
|
|
55
|
+
const fetchMock = mockFetch();
|
|
56
|
+
await makeClient().getVideoGraph('video-1');
|
|
57
|
+
|
|
58
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
59
|
+
const url = fetchMock.mock.calls[0][0] as string;
|
|
60
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1`);
|
|
61
|
+
expect(url).not.toContain('detail');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('sends detail=story for GRAPH_DETAIL.STORY', async () => {
|
|
65
|
+
const fetchMock = mockFetch();
|
|
66
|
+
const response = await makeClient().getVideoGraph('video-1', GRAPH_DETAIL.STORY);
|
|
67
|
+
|
|
68
|
+
const url = fetchMock.mock.calls[0][0] as string;
|
|
69
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1?detail=story`);
|
|
70
|
+
expect(response.nodes[0]?.properties.shotCount).toBe(4);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('sends detail=raw for GRAPH_DETAIL.RAW', async () => {
|
|
74
|
+
const fetchMock = mockFetch();
|
|
75
|
+
await makeClient().getVideoGraph('video-1', GRAPH_DETAIL.RAW);
|
|
76
|
+
|
|
77
|
+
const url = fetchMock.mock.calls[0][0] as string;
|
|
78
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/tools/graph/video-1?detail=raw`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('URI-encodes the videoId ahead of the query param', async () => {
|
|
82
|
+
const fetchMock = mockFetch();
|
|
83
|
+
await makeClient().getVideoGraph('video/1 x', GRAPH_DETAIL.STORY);
|
|
84
|
+
|
|
85
|
+
const url = fetchMock.mock.calls[0][0] as string;
|
|
86
|
+
expect(url).toBe(
|
|
87
|
+
`${TEST_BASE_URL}/api/v1/tools/graph/video%2F1%20x?detail=story`,
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('exposes exactly the story/raw literal set (mirror of shared GraphDetail)', () => {
|
|
92
|
+
expect(GRAPH_DETAIL).toEqual({ STORY: 'story', RAW: 'raw' });
|
|
93
|
+
});
|
|
94
|
+
});
|