@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.
Files changed (242) hide show
  1. package/README.md +32 -7
  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 +323 -0
  31. package/dist/admin.d.ts.map +1 -0
  32. package/dist/admin.js +198 -0
  33. package/dist/admin.js.map +1 -0
  34. package/dist/api.d.ts +1512 -4
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +820 -52
  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 +77 -0
  47. package/dist/conversation/binding.d.ts.map +1 -0
  48. package/dist/conversation/binding.js +57 -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 +350 -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 +92 -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 +553 -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/binding.test.ts +62 -0
  179. package/src/__tests__/conversation/controller.test.ts +732 -0
  180. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  181. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  182. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  183. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  184. package/src/__tests__/conversation/roster.test.ts +100 -0
  185. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  186. package/src/__tests__/conversation/router.test.ts +81 -0
  187. package/src/__tests__/conversation/runtime.test.ts +206 -0
  188. package/src/__tests__/conversation/voice.test.ts +440 -0
  189. package/src/__tests__/documents.test.ts +360 -0
  190. package/src/__tests__/graphSchema.test.ts +218 -9
  191. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  192. package/src/__tests__/monitoring.test.ts +162 -0
  193. package/src/__tests__/persona-generation.test.ts +352 -0
  194. package/src/__tests__/platformAssistant.test.ts +484 -0
  195. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  196. package/src/__tests__/regeneration.test.ts +486 -0
  197. package/src/__tests__/stories.test.ts +171 -0
  198. package/src/__tests__/storyGraph.test.ts +134 -0
  199. package/src/__tests__/tools-wrappers.test.ts +272 -0
  200. package/src/__tests__/videoGraph.test.ts +94 -0
  201. package/src/__tests__/websocket.test.ts +263 -0
  202. package/src/adapters/capabilities.ts +24 -0
  203. package/src/adapters/chatAdapter.ts +114 -0
  204. package/src/adapters/directorAdapter.ts +126 -0
  205. package/src/adapters/imageAdapter.ts +100 -0
  206. package/src/adapters/index.ts +67 -0
  207. package/src/adapters/registry.ts +159 -0
  208. package/src/adapters/worldAdapter.ts +272 -0
  209. package/src/admin.ts +517 -0
  210. package/src/api.ts +2215 -95
  211. package/src/audio.ts +35 -0
  212. package/src/castProjection.ts +95 -0
  213. package/src/conversation/binding.ts +100 -0
  214. package/src/conversation/controller.ts +447 -0
  215. package/src/conversation/effectiveModel.ts +111 -0
  216. package/src/conversation/index.ts +27 -0
  217. package/src/conversation/participant.ts +71 -0
  218. package/src/conversation/presence.ts +60 -0
  219. package/src/conversation/presenceBus.ts +109 -0
  220. package/src/conversation/presenceRegistry.ts +83 -0
  221. package/src/conversation/roster.ts +111 -0
  222. package/src/conversation/rosterProjection.ts +98 -0
  223. package/src/conversation/router.ts +96 -0
  224. package/src/conversation/runtime.ts +188 -0
  225. package/src/conversation/types.ts +100 -0
  226. package/src/conversation/voice.ts +402 -0
  227. package/src/graphSchema.ts +396 -13
  228. package/src/http.ts +72 -0
  229. package/src/index.ts +9 -0
  230. package/src/platformAssistant.ts +347 -0
  231. package/src/reactor/chunkDistribution.ts +98 -0
  232. package/src/reactor/index.ts +5 -0
  233. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  234. package/src/reactor/scenesFromEnrichment.ts +11 -76
  235. package/src/reactor/seedImageOrchestrator.ts +12 -13
  236. package/src/reactor/storyTimeline.ts +127 -0
  237. package/src/storyGraph.ts +298 -0
  238. package/src/vision/VisionSourceController.ts +354 -0
  239. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  240. package/src/vision/index.ts +13 -0
  241. package/src/vision/sourceKinds.ts +75 -0
  242. package/src/websocket.ts +99 -3
@@ -8,14 +8,24 @@
8
8
  * against the same vocabulary the backend validates against.
9
9
  *
10
10
  * Scope discipline (mirrors the backend "no god-module" rule): this file
11
- * describes the **graph schema only** — node labels, relationship types, and
12
- * the two provenance vocabularies. It must NOT grow tool/MCP schemas or
13
- * request/response DTOs.
11
+ * describes the **graph schema only** — node labels, relationship types, the
12
+ * user-creation whitelists (M7 P3a: {@link userCreatableLabels} /
13
+ * {@link userCreatableEdges} / {@link allowedPairs}), and the two provenance
14
+ * vocabularies. It must NOT grow tool/MCP schemas or request/response DTOs.
14
15
  *
15
16
  * Keep this in lockstep with the Python module. The Python `NARRATIVE_NODE_LABELS`
16
- * static extension point (for Story-Engine narrative nodes like `Act`) has no
17
- * runtime equivalent here — a phase that adds a narrative label widens these
18
- * unions in the same change.
17
+ * static extension point (for Story-Engine narrative nodes like `Act` /
18
+ * `Scene` / `PlotBeat` / `CharacterArc`) has no runtime equivalent here — a
19
+ * phase that adds a narrative label widens these unions in the same change.
20
+ * M7 P3a added `Scene` / `PlotBeat` / `CharacterArc` to the node vocabulary and
21
+ * the six story edges to the relationship vocabulary.
22
+ *
23
+ * Read-surface vs create-surface (mirrors the backend split): the `GRAPH_*`
24
+ * unions/tuples are the READ-SURFACE — the full vocabulary a viewer can
25
+ * encounter (every node label, every edge type on `getVideoGraph` edges). The
26
+ * `userCreatable*` exports are the strict CREATE-SURFACE subset authorized by
27
+ * `POST /graph/{nodes,edges}`. Widening the read-surface is additive — the
28
+ * public exports are pinned by the sibling Vue Web-App and must never shrink.
19
29
  */
20
30
  /** Runtime tuple of all node labels (mirrors `VALID_NODE_LABELS`). */
21
31
  export const GRAPH_NODE_LABELS = [
@@ -24,8 +34,18 @@ export const GRAPH_NODE_LABELS = [
24
34
  'Entity',
25
35
  'Event',
26
36
  'DialogLine',
37
+ 'Act',
38
+ 'Scene',
39
+ 'PlotBeat',
40
+ 'CharacterArc',
41
+ 'SourceDoc',
42
+ 'Persona',
27
43
  ];
28
- /** Runtime tuple of all relationship types (mirrors `VALID_RELATIONSHIP_TYPES`). */
44
+ /**
45
+ * Runtime tuple of the READ-SURFACE relationship vocabulary — every edge type a
46
+ * viewer can encounter on `getVideoGraph` edges. SUPERSET of the original
47
+ * pipeline edges (additive). The create-surface subset is {@link userCreatableEdges}.
48
+ */
29
49
  export const GRAPH_RELATIONSHIP_TYPES = [
30
50
  'HAS_SHOT',
31
51
  'MENTIONS',
@@ -33,6 +53,22 @@ export const GRAPH_RELATIONSHIP_TYPES = [
33
53
  'HAS_DIALOG',
34
54
  'SPOKEN_BY',
35
55
  'NEXT',
56
+ 'HAS_ACT',
57
+ 'IN_ACT',
58
+ 'CONTAINS',
59
+ 'INCLUDES',
60
+ 'RELATES_TO',
61
+ 'CAUSES',
62
+ 'SET_IN',
63
+ 'FEATURES',
64
+ 'ON_ARC',
65
+ 'LEADS_TO',
66
+ // M7 Phase 4: pipeline-written SourceDoc-[:ANNOTATES]->(Entity|Scene) edge
67
+ // (read-surface only; NOT in the user-creatable subset).
68
+ 'ANNOTATES',
69
+ // M7 Phase 5: pipeline-only Persona-[:PORTRAYS]->Entity edge (read-surface
70
+ // only; NOT in the user-creatable subset).
71
+ 'PORTRAYS',
36
72
  ];
37
73
  /**
38
74
  * Primary-key property per node label (mirrors `PRIMARY_KEY`).
@@ -48,14 +84,124 @@ export const GRAPH_PRIMARY_KEY = {
48
84
  Entity: 'entityId',
49
85
  Event: 'eventId',
50
86
  DialogLine: 'dialogId',
87
+ Act: 'actId',
88
+ Scene: 'sceneId',
89
+ PlotBeat: 'beatId',
90
+ CharacterArc: 'arcId',
91
+ SourceDoc: 'docId',
92
+ Persona: 'personaId',
93
+ };
94
+ /**
95
+ * Story Engine Phase 5 — the node label for graph entities. Single source for
96
+ * the ``'Entity'`` label string so call sites (e.g. the persona↔character
97
+ * binding affordance) don't hardcode it. Mirrors
98
+ * ``shared/neo4j_queries.py:LABEL_ENTITY``.
99
+ */
100
+ export const GRAPH_ENTITY_LABEL = 'Entity';
101
+ /**
102
+ * Story Engine Phase 5 — the ``Entity.type`` property value identifying a
103
+ * character (vs. location / object / organization). Mirrors backend
104
+ * ``shared/models.py:EntityType.CHARACTER``. Used to gate character-only UI
105
+ * without hardcoding the literal at call sites.
106
+ */
107
+ export const ENTITY_TYPE_CHARACTER = 'character';
108
+ // ---------------------------------------------------------------------------
109
+ // Studio read-surface vocabulary — the node-label, edge-type, and node-property
110
+ // string constants the pure `storyGraph` projection (and the studio Scene
111
+ // inspector / Cast grid) match against when filtering a `get_video_graph`
112
+ // payload. Lifted into client-core (Platform Restructure R8.1) so the
113
+ // framework-agnostic `storyGraph` projection — now consumed by BOTH Studio
114
+ // (`web/app/components/studio/`) and the Director timeline mapper — has a single
115
+ // source for this vocabulary. The web `graphVocabulary.ts` module re-exports
116
+ // these (keeping its web-only `GRAPH_DETAIL_QUERY_PARAM` URL concern local).
117
+ //
118
+ // These mirror the backend (`shared/neo4j_queries.py`, `shared/graph_schema.py`)
119
+ // and the graph editor. `ACT`/`SHOT`/`CHARACTER_ARC` are read-only at runtime —
120
+ // `Act` is intentionally absent from the {@link GraphNodeLabel} create-surface
121
+ // union but DOES appear at read time, so these are plain string literals (the
122
+ // read-surface is wider than the typed create-surface union).
123
+ // ---------------------------------------------------------------------------
124
+ /** Node labels the studio read-surface (and `storyGraph`) match. */
125
+ export const STUDIO_NODE_LABELS = {
126
+ /** 'Act' — read-only at runtime; not in the create-surface union. */
127
+ ACT: 'Act',
128
+ SCENE: 'Scene',
129
+ SHOT: 'Shot',
130
+ ENTITY: GRAPH_ENTITY_LABEL,
131
+ CHARACTER_ARC: 'CharacterArc',
132
+ };
133
+ /** Edge (relationship) types the studio read-surface (and `storyGraph`) traverse. */
134
+ export const STUDIO_EDGE_TYPES = {
135
+ /** Structural containment: Act→Scene and Scene→Shot. */
136
+ CONTAINS: 'CONTAINS',
137
+ /** Alternate structural containment used by some pipeline writers. */
138
+ INCLUDES: 'INCLUDES',
139
+ /** Scene⇄character feature edge. */
140
+ FEATURES: 'FEATURES',
141
+ /** Scene→location edge (the location an entity is set in). */
142
+ SET_IN: 'SET_IN',
143
+ /** Character→CharacterArc edge. */
144
+ ON_ARC: 'ON_ARC',
145
+ /** Character⇄character relationship edge. */
146
+ RELATES_TO: 'RELATES_TO',
51
147
  };
52
- /** User-editable properties per node label (mirrors `EDITABLE_NODE_PROPERTIES`). */
148
+ /**
149
+ * Node `properties` keys as they appear in the `get_video_graph` payload's
150
+ * `properties` map (mirrors the backend MERGE_* SET clauses).
151
+ */
152
+ export const STUDIO_NODE_PROPERTIES = {
153
+ TITLE: 'title',
154
+ INDEX: 'index',
155
+ SUMMARY: 'summary',
156
+ DESCRIPTION: 'description',
157
+ /** Scene/Shot time bounds (numeric seconds) — MERGE_SCENE / MERGE_SHOT. */
158
+ START_TIME: 'startTime',
159
+ END_TIME: 'endTime',
160
+ /** Act time bounds (numeric seconds) — MERGE_ACT uses t0/t1, not start/endTime. */
161
+ T0: 't0',
162
+ T1: 't1',
163
+ NAME: 'name',
164
+ ENTITY_TYPE: 'type',
165
+ ALIASES: 'aliases',
166
+ ENTITY_ID: 'entityId',
167
+ SCENE_ID: 'sceneId',
168
+ SHOT_ID: 'shotId',
169
+ ARC_ID: 'arcId',
170
+ CAPTION: 'caption',
171
+ };
172
+ /** The `Entity.type` value identifying a character (single source). */
173
+ export const STUDIO_CHARACTER_TYPE = ENTITY_TYPE_CHARACTER;
174
+ /**
175
+ * User-editable properties per node label (mirrors `EDITABLE_NODE_PROPERTIES`).
176
+ *
177
+ * RUNTIME SOURCE OF TRUTH: the graph editor's live editable-property /
178
+ * primary-key whitelists now come from the fetched `GET /graph/schema` payload
179
+ * (see {@link fetchGraphSchema} and `web/app/jobs/[videoId]/graph/page.tsx`), so
180
+ * a backend whitelist change auto-propagates with no TS edit. These static
181
+ * `GRAPH_*` constants remain as the COMPILE-TIME typed vocabulary and a
182
+ * back-compat fallback (used while the schema is in flight, and imported by the
183
+ * sibling Vue Web-App). Keep them mirrored with the backend; do not treat them
184
+ * as the runtime authority for the editor.
185
+ */
53
186
  export const GRAPH_EDITABLE_NODE_PROPERTIES = {
54
- Video: ['fileName', 'episodeTitle'],
187
+ // M7 Phase 1b added `themes` to the editable Video narrative props.
188
+ Video: ['fileName', 'episodeTitle', 'themes'],
55
189
  Shot: ['caption'],
56
190
  Entity: ['name', 'type'],
57
191
  Event: ['label', 'category'],
58
192
  DialogLine: ['text', 'speaker'],
193
+ // M7 Phase 1b: Act title/summary are creator-editable (the narrative is
194
+ // regeneratable, so only the human-authored fields are exposed).
195
+ Act: ['title', 'summary'],
196
+ Scene: ['title', 'summary'],
197
+ PlotBeat: ['label', 'summary'],
198
+ CharacterArc: ['label', 'summary'],
199
+ // M7 Phase 4: only the human-readable SourceDoc title is editable; the
200
+ // processor-owned provenance (kind/s3Key/contentHash/pageCount) is immutable.
201
+ SourceDoc: ['title'],
202
+ // M7 Phase 5: Persona is pipeline-only (graph_sync writer manages it) and is
203
+ // never editable through the graph editor — so it has no editable props.
204
+ Persona: [],
59
205
  };
60
206
  /**
61
207
  * Editable relationship properties (mirrors `EDITABLE_RELATIONSHIP_PROPERTIES`).
@@ -65,6 +211,74 @@ export const GRAPH_EDITABLE_NODE_PROPERTIES = {
65
211
  export const GRAPH_EDITABLE_RELATIONSHIP_PROPERTIES = [
66
212
  'confidence',
67
213
  ];
214
+ // ---------------------------------------------------------------------------
215
+ // User-creatable vocabulary — M7 Phase 3a (POST /graph/nodes + /graph/edges)
216
+ // ---------------------------------------------------------------------------
217
+ //
218
+ // COMPILE-TIME MIRROR of the backend `shared/graph_schema.py` creation
219
+ // whitelists: `user_creatable_labels`, `user_creatable_edges`, and
220
+ // `_VALID_EDGE_PAIRS`. Unlike the editable-property whitelist (which the
221
+ // frontend reads live from `GET /graph/schema` — see {@link fetchGraphSchema}),
222
+ // the `GET /graph/schema` payload does NOT yet serialize these creation sets
223
+ // (`GraphSchemaResponse` carries only `labels`/`edges`). So — exactly as the
224
+ // `GRAPH_*` constants above mirror the read whitelists — these are authored
225
+ // here as the compile-time mirror for the Phase-3b creation UI. Keep them in
226
+ // lockstep with the Python source; if a later phase extends the wire payload
227
+ // with creation sets, switch the UI to the fetched copy and demote these to a
228
+ // fallback (same pattern as the editable-property migration).
229
+ /**
230
+ * Node labels a creator may instantiate via `POST /graph/nodes`
231
+ * (mirrors `user_creatable_labels`). `Act` is pipeline-only (creators edit but
232
+ * do not create it); `Video`/`Shot`/`Entity`/`Event`/`DialogLine` are never
233
+ * user-creatable.
234
+ */
235
+ export const userCreatableLabels = [
236
+ 'Scene',
237
+ 'PlotBeat',
238
+ 'CharacterArc',
239
+ ];
240
+ /**
241
+ * CREATE-SURFACE: relationship types a creator may instantiate via
242
+ * `POST /graph/edges` (mirrors `user_creatable_edges`, identical to the
243
+ * backend's `VALID_RELATIONSHIP_TYPES`). A strict subset of the read-surface
244
+ * {@link GRAPH_RELATIONSHIP_TYPES}: the read-only pipeline / narrative-structural
245
+ * edges (`MENTIONS` / `HAS_*` / `CONTAINS` / `INCLUDES`, etc.) are encounterable
246
+ * on `getVideoGraph` but NOT creatable — the backend 422s them.
247
+ */
248
+ export const userCreatableEdges = [
249
+ 'RELATES_TO',
250
+ 'CAUSES',
251
+ 'SET_IN',
252
+ 'FEATURES',
253
+ 'ON_ARC',
254
+ 'LEADS_TO',
255
+ ];
256
+ /**
257
+ * Allowed `(sourceLabel, targetLabel)` endpoint pairs per user-creatable edge
258
+ * type (mirrors `_VALID_EDGE_PAIRS`). The backend rejects any edge whose
259
+ * endpoint labels are not listed here (422); for `SET_IN` / `FEATURES` the
260
+ * target `Entity.type` (location / character) is validated separately by a
261
+ * server-side read. Keyed by {@link UserCreatableEdge} (the create-surface only,
262
+ * not the full read-surface), valued by readonly `[GraphNodeLabel, GraphNodeLabel]`
263
+ * pairs.
264
+ */
265
+ export const allowedPairs = {
266
+ RELATES_TO: [['Entity', 'Entity']],
267
+ CAUSES: [['Event', 'Event']],
268
+ SET_IN: [['Scene', 'Entity']],
269
+ FEATURES: [['Scene', 'Entity']],
270
+ ON_ARC: [['PlotBeat', 'CharacterArc']],
271
+ LEADS_TO: [['PlotBeat', 'PlotBeat']],
272
+ };
273
+ /** Runtime tuple of {@link RelationshipKindValue} (mirrors `RelationshipKind`). */
274
+ export const RELATIONSHIP_KIND_VALUES = [
275
+ 'ally',
276
+ 'rival',
277
+ 'family',
278
+ 'romantic',
279
+ 'mentor',
280
+ 'custom',
281
+ ];
68
282
  /** Runtime tuple of story-graph provenance values. */
69
283
  export const STORY_GRAPH_PROVENANCE_VALUES = [
70
284
  'pegasus',
@@ -102,4 +316,39 @@ export function isStoryGraphProvenance(value) {
102
316
  export function isMemoryFactProvenance(value) {
103
317
  return MEMORY_FACT_PROVENANCE_VALUES.includes(value);
104
318
  }
319
+ /**
320
+ * Module-scoped memoization slot. Holds the in-flight OR resolved promise so
321
+ * concurrent callers and re-renders share one network round-trip per session.
322
+ * Reset to `null` on rejection so a failed fetch can be retried.
323
+ */
324
+ let _graphSchemaPromise = null;
325
+ /**
326
+ * Session-scoped memoized fetch of `GET /graph/schema`. The first call kicks
327
+ * off the request; every subsequent call (concurrent or later) awaits the same
328
+ * cached promise — so `client.getGraphSchema()` runs exactly once per session.
329
+ *
330
+ * On rejection the cache is cleared so the next call retries rather than
331
+ * permanently surfacing a stale error (a transient network blip must not brick
332
+ * the editor for the rest of the session).
333
+ *
334
+ * Call `__resetGraphSchemaCache()` in tests (or on logout) to drop the cache.
335
+ */
336
+ export function fetchGraphSchema(client) {
337
+ if (_graphSchemaPromise === null) {
338
+ _graphSchemaPromise = client.getGraphSchema().catch((err) => {
339
+ // Clear the slot so a subsequent call refetches instead of replaying the
340
+ // rejection forever. Re-throw so the awaiting caller still sees the error.
341
+ _graphSchemaPromise = null;
342
+ throw err;
343
+ });
344
+ }
345
+ return _graphSchemaPromise;
346
+ }
347
+ /**
348
+ * Test hook: drop the memoized schema promise so the next `fetchGraphSchema`
349
+ * starts fresh. Also usable on logout / session reset.
350
+ */
351
+ export function __resetGraphSchemaCache() {
352
+ _graphSchemaPromise = null;
353
+ }
105
354
  //# sourceMappingURL=graphSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphSchema.js","sourceRoot":"","sources":["../src/graphSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAkBH,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,YAAY;CACJ,CAAC;AAEX,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAqC;IACxE,UAAU;IACV,UAAU;IACV,WAAW;IACX,YAAY;IACZ,WAAW;IACX,MAAM;CACE,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA6C;IACzE,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,UAAU;IAClB,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,UAAU;CACd,CAAC;AAEX,oFAAoF;AACpF,MAAM,CAAC,MAAM,8BAA8B,GAEvC;IACF,KAAK,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC;IACnC,IAAI,EAAE,CAAC,SAAS,CAAC;IACjB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;IAC5B,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;CACvB,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAsB;IACvE,YAAY;CACJ,CAAC;AAkBX,sDAAsD;AACtD,MAAM,CAAC,MAAM,6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IACN,UAAU;IACV,aAAa;CACL,CAAC;AAEX,sDAAsD;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAoC;IAC5E,MAAM;IACN,UAAU;IACV,QAAQ;IACR,aAAa;CACL,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAsC,IAAI,GAAG,CAAC;IAClF,MAAM;IACN,UAAU;CACX,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAsC,IAAI,GAAG,CAAC;IACnF,QAAQ;IACR,UAAU;CACX,CAAC,CAAC;AAEH,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,OAAQ,6BAAmD,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,OAAQ,6BAAmD,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AA2BD;;;;GAIG;AACH,IAAI,mBAAmB,GAAwC,IAAI,CAAC;AAEpE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAyB;IAEzB,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC;QACjC,mBAAmB,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YAC1D,yEAAyE;YACzE,2EAA2E;YAC3E,mBAAmB,GAAG,IAAI,CAAC;YAC3B,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,mBAAmB,GAAG,IAAI,CAAC;AAC7B,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Shared JSON fetch helper for the Seer API clients.
3
+ *
4
+ * Single source for the bearer-auth + FastAPI-error-shaping fetch wrapper used
5
+ * by both `ApiClient` (which delegates `makeRequest` here) and the additive
6
+ * `AdminClient`. Kept internal (not re-exported from `index.ts`) so the public
7
+ * package surface is unchanged — it is an implementation detail shared across
8
+ * the client classes, not a new export.
9
+ */
10
+ /**
11
+ * Issue a JSON request, injecting the bearer token and shaping FastAPI errors.
12
+ *
13
+ * - Adds `Authorization: Bearer <token>` when `sessionToken` is set (anonymous
14
+ * otherwise, for land-dark endpoints).
15
+ * - On a non-2xx response, throws an `Error` whose message is the FastAPI
16
+ * `detail` (validation arrays are flattened to `loc: msg; …`).
17
+ * - A `204 No Content` resolves to `undefined`.
18
+ */
19
+ export declare function requestJson<T>(baseUrl: string, endpoint: string, sessionToken: string | undefined, options?: RequestInit): Promise<T>;
20
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,CAAC,CAAC,CA0CZ"}
package/dist/http.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Shared JSON fetch helper for the Seer API clients.
3
+ *
4
+ * Single source for the bearer-auth + FastAPI-error-shaping fetch wrapper used
5
+ * by both `ApiClient` (which delegates `makeRequest` here) and the additive
6
+ * `AdminClient`. Kept internal (not re-exported from `index.ts`) so the public
7
+ * package surface is unchanged — it is an implementation detail shared across
8
+ * the client classes, not a new export.
9
+ */
10
+ /**
11
+ * Issue a JSON request, injecting the bearer token and shaping FastAPI errors.
12
+ *
13
+ * - Adds `Authorization: Bearer <token>` when `sessionToken` is set (anonymous
14
+ * otherwise, for land-dark endpoints).
15
+ * - On a non-2xx response, throws an `Error` whose message is the FastAPI
16
+ * `detail` (validation arrays are flattened to `loc: msg; …`).
17
+ * - A `204 No Content` resolves to `undefined`.
18
+ */
19
+ export async function requestJson(baseUrl, endpoint, sessionToken, options = {}) {
20
+ const url = `${baseUrl}${endpoint}`;
21
+ const headers = {
22
+ 'Content-Type': 'application/json',
23
+ ...options.headers,
24
+ };
25
+ if (sessionToken) {
26
+ headers['Authorization'] = `Bearer ${sessionToken}`;
27
+ }
28
+ try {
29
+ const response = await fetch(url, { ...options, headers });
30
+ if (!response.ok) {
31
+ const error = await response.json().catch(() => ({
32
+ detail: `HTTP ${response.status}: ${response.statusText}`,
33
+ }));
34
+ const detail = error.detail;
35
+ let message;
36
+ if (Array.isArray(detail)) {
37
+ message = detail
38
+ .map((e) => e.msg ? `${(e.loc || []).slice(-1).join('.')}: ${e.msg}` : String(e))
39
+ .join('; ');
40
+ }
41
+ else {
42
+ message = detail || `Request failed: ${response.status}`;
43
+ }
44
+ throw new Error(message);
45
+ }
46
+ // 204 No Content returns no body.
47
+ if (response.status === 204) {
48
+ return undefined;
49
+ }
50
+ return (await response.json());
51
+ }
52
+ catch (error) {
53
+ console.error('API request failed:', error);
54
+ throw error;
55
+ }
56
+ }
57
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,QAAgB,EAChB,YAAgC,EAChC,UAAuB,EAAE;IAEzB,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;IAEpC,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;QAClC,GAAI,OAAO,CAAC,OAAkC;KAC/C,CAAC;IACF,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,YAAY,EAAE,CAAC;IACtD,CAAC;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AAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -25,9 +25,15 @@ export * from './visemeScheduler';
25
25
  export * from './visemeGeometry';
26
26
  export * from './websocket';
27
27
  export * from './api';
28
+ export * from './castProjection';
29
+ export * from './admin';
28
30
  export * from './reactor';
29
31
  export * from './timeFormat';
30
32
  export * from './toolSchemas';
31
33
  export * from './vision';
32
34
  export * from './graphSchema';
35
+ export * from './storyGraph';
36
+ export * from './adapters';
37
+ export * from './conversation';
38
+ export * from './platformAssistant';
33
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAI9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -25,9 +25,18 @@ export * from './visemeScheduler.js';
25
25
  export * from './visemeGeometry.js';
26
26
  export * from './websocket.js';
27
27
  export * from './api.js';
28
+ export * from './castProjection.js';
29
+ export * from './admin.js';
28
30
  export * from './reactor.js';
29
31
  export * from './timeFormat.js';
30
32
  export * from './toolSchemas.js';
31
33
  export * from './vision.js';
32
34
  export * from './graphSchema.js';
35
+ // R8.1 — pure story-graph projections (deriveScenes/deriveCast + SceneView/
36
+ // CharacterView). Grepped src/ for these names first per the collision warning
37
+ // above: no existing export owns them. The web studio module re-exports these.
38
+ export * from './storyGraph.js';
39
+ export * from './adapters.js';
40
+ export * from './conversation.js';
41
+ export * from './platformAssistant.js';
33
42
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Headless Platform Assistant controller (R4c).
3
+ *
4
+ * The framework-agnostic owner of a Platform Assistant conversation: it holds
5
+ * the running message list + the current `routeContext`, calls
6
+ * `ApiClient.streamAssistant`, parses the returned SSE event stream, and fans
7
+ * the decoded `AssistantStreamEvent` variants out to host-provided callbacks.
8
+ * It has ZERO framework imports — React (R4c web overlay), Vue, and PlayCanvas
9
+ * all drive this same controller (mirrors the R2.1 `ConversationController`
10
+ * decoupling mandate). A test reads this source and asserts no UI-framework
11
+ * import.
12
+ *
13
+ * It does NOT re-implement transport or the SSE wire: it delegates the fetch +
14
+ * body-reader to `ApiClient.streamAssistant` (the single SSE plumbing shared
15
+ * with `streamChat`) and decodes each `data: {…}\n\n` frame exactly the way the
16
+ * existing chat consumer does (TextDecoder streaming + line buffering +
17
+ * `[DONE]` terminator) — no second decoder.
18
+ *
19
+ * It performs NO mutation: a `suggestion` event is surfaced verbatim to
20
+ * `onSuggestion`; the HOST page that owns the form decides whether to apply it.
21
+ */
22
+ import type { ApiClient, AssistantRouteContext, ChatMessage } from './api';
23
+ /**
24
+ * A `propose_form_fields` suggestion surfaced to the host. Mirrors the
25
+ * `suggestion` variant of `AssistantStreamEvent` (the wire contract shared with
26
+ * `api/assistant`), re-exported as a named type so the host overlay imports it
27
+ * verbatim rather than re-deriving the `Extract<…>`.
28
+ */
29
+ export interface PlatformAssistantSuggestion {
30
+ /** The target form id the proposed fields belong to (e.g. `persona`). */
31
+ targetForm: string;
32
+ /** The proposed `{ fieldName: value }` map the host reviews + applies. */
33
+ fields: Record<string, string>;
34
+ /** Optional human-readable rationale for the proposal. */
35
+ rationale?: string;
36
+ }
37
+ /**
38
+ * Host callbacks the controller invokes as the corresponding
39
+ * `AssistantStreamEvent` variants arrive. All optional — a host wires only the
40
+ * variants it renders. `token` -> onTextDelta, `suggestion` -> onSuggestion,
41
+ * `error` -> onError, `done` -> onDone. The `tool_use` / `tool_result` /
42
+ * `citation` variants are intentionally not surfaced (minimal assistant
43
+ * surface); a future PR can add callbacks for them additively.
44
+ */
45
+ export interface PlatformAssistantCallbacks {
46
+ /** A streamed answer token (append to the in-flight assistant message). */
47
+ onTextDelta?: (text: string) => void;
48
+ /** A `propose_form_fields` suggestion the host maps onto its own form. */
49
+ onSuggestion?: (suggestion: PlatformAssistantSuggestion) => void;
50
+ /** A streamed error message (the turn failed server-side). */
51
+ onError?: (message: string) => void;
52
+ /**
53
+ * The turn ended. Fires once whenever the stream CLOSES — a `done`/`[DONE]`
54
+ * terminator, a self-abort, OR the connection simply dropping. So for a
55
+ * server-side SSE `error` frame, BOTH onError and onDone fire (error surfaced,
56
+ * then the stream closed); for a TRANSPORT error (the request itself throws)
57
+ * only onError fires. Treat onDone as "stop showing the spinner", not "success".
58
+ */
59
+ onDone?: () => void;
60
+ }
61
+ export interface PlatformAssistantControllerOptions {
62
+ /** The client-core API client whose `streamAssistant` the controller drives. */
63
+ apiClient: Pick<ApiClient, 'streamAssistant'>;
64
+ /** The route the assistant is summoned on (scopes its suggestions). */
65
+ routeContext: AssistantRouteContext;
66
+ /** Host callbacks for the streamed events. */
67
+ callbacks: PlatformAssistantCallbacks;
68
+ /**
69
+ * Optional explicit model pin. Omitted = the server resolves the model via
70
+ * the same `resolve_model_id` -> `shared/model_router.py` seam the chat uses.
71
+ */
72
+ modelId?: string;
73
+ }
74
+ /**
75
+ * Per-turn options for {@link PlatformAssistantController.ask} (R11.2). Optional
76
+ * + additive — `ask(prompt)` is unchanged. `documentContext` carries a large
77
+ * "operate on this document" draft (e.g. a long prompt to refine) that the
78
+ * server places in MODEL CONTEXT, never the user turn, so the small `prompt`
79
+ * cap keeps its prompt-injection floor.
80
+ */
81
+ export interface PlatformAssistantAskOptions {
82
+ /** A large document/draft for the assistant to operate ON (model context). */
83
+ documentContext?: string;
84
+ }
85
+ export declare class PlatformAssistantController {
86
+ private readonly apiClient;
87
+ private readonly callbacks;
88
+ private readonly modelId?;
89
+ private routeContext;
90
+ /** The running conversation history threaded into each `ask`. */
91
+ private messages;
92
+ /** Abort controller for the in-flight `ask` stream (so `abort()` cancels it). */
93
+ private inflight;
94
+ /** Set by `dispose()` — guards against driving a new stream after teardown. */
95
+ private disposed;
96
+ constructor(opts: PlatformAssistantControllerOptions);
97
+ /** Point the assistant at a new surface/form (the host re-binds on navigation). */
98
+ setRouteContext(routeContext: AssistantRouteContext): void;
99
+ /** A defensive copy of the running message history (host-render convenience). */
100
+ getMessages(): ChatMessage[];
101
+ /**
102
+ * Send a user prompt: append it to the history, stream the assistant reply
103
+ * via `ApiClient.streamAssistant` (threading the running history + the current
104
+ * `routeContext`), and fan the decoded events out to the host callbacks. The
105
+ * accumulated assistant text is appended to the history on completion so the
106
+ * NEXT `ask` carries the full transcript.
107
+ *
108
+ * Resolves when the stream completes (or aborts). A single `ask` is allowed
109
+ * in flight at a time — calling `ask` again before the previous resolves
110
+ * aborts the prior stream first (so only one stream owns the callbacks).
111
+ *
112
+ * NEVER rejects: a transport/network error is surfaced via the `onError`
113
+ * callback (the same channel as SSE `error` frames) and a self-abort resolves
114
+ * silently — so framework-agnostic callers need not wrap `ask` in try/catch.
115
+ *
116
+ * `options.documentContext` (R11.2, optional) threads a large draft into the
117
+ * request's `documentContext` field — the server places it in model context,
118
+ * not the user turn. Omitted ⇒ the request carries no `documentContext`
119
+ * (byte-identical to the pre-R11.2 wire payload).
120
+ */
121
+ ask(prompt: string, options?: PlatformAssistantAskOptions): Promise<void>;
122
+ /** Abort the in-flight stream (no-op when nothing is streaming). */
123
+ abort(): void;
124
+ /** Tear down: abort any in-flight stream and reject further `ask` calls. */
125
+ dispose(): void;
126
+ /**
127
+ * Drain the SSE reader, decoding each `data: {…}\n\n` frame into an
128
+ * `AssistantStreamEvent` and dispatching it to the host callbacks. Returns the
129
+ * concatenated `token` text so the caller can persist the assistant turn.
130
+ *
131
+ * Reuses the EXACT decode discipline the web chat consumer uses (TextDecoder
132
+ * with `{ stream: true }`, line buffering with a trailing-partial carry-over,
133
+ * `data: ` prefix slice, `[DONE]` terminator) — no second SSE decoder.
134
+ */
135
+ private consume;
136
+ /**
137
+ * Decode one buffered SSE line into an `AssistantStreamEvent`, dispatch it to
138
+ * the host callbacks, and return the `token` text the line contributed (empty
139
+ * for a non-token frame, the `[DONE]` sentinel, a non-`data:` line, or a
140
+ * malformed frame — a single bad line is SKIPPED, never aborting the stream).
141
+ *
142
+ * The single line-parse path shared by the streaming loop and the final-buffer
143
+ * flush in `consume`, so the loop and the close-time tail can never decode a
144
+ * frame differently.
145
+ */
146
+ private handleLine;
147
+ /**
148
+ * Dispatch one decoded event to the matching host callback. `done` needs no
149
+ * handling here — `consume` fires `onDone` once when the reader closes (the
150
+ * close is the completion signal). `tool_use` / `tool_result` / `citation` are
151
+ * intentionally ignored (minimal surface).
152
+ */
153
+ private dispatch;
154
+ }
155
+ //# sourceMappingURL=platformAssistant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformAssistant.d.ts","sourceRoot":"","sources":["../src/platformAssistant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,WAAW,EACZ,MAAM,OAAO,CAAC;AAMf;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,MAAM,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