@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
@@ -0,0 +1,67 @@
1
+ // Barrel for the framework-agnostic model-adapter registry (R1a).
2
+ // NO React / DOM / provider-SDK imports — same contract as reactor/ and vision/.
3
+ import type { ApiClient } from '../api';
4
+ import { loadChatAdapterRegistry, type ChatAdapterDescriptor } from './chatAdapter';
5
+ import { loadImageAdapterRegistry, type ImageAdapterDescriptor } from './imageAdapter';
6
+ import { createWorldRegistry, type WorldAdapterDescriptor } from './worldAdapter';
7
+ import {
8
+ createDirectorRegistry,
9
+ type DirectorAdapterDescriptor,
10
+ } from './directorAdapter';
11
+ import type { AdapterRegistry } from './registry';
12
+
13
+ export * from './capabilities';
14
+ export * from './registry';
15
+ export * from './chatAdapter';
16
+ export * from './imageAdapter';
17
+ export * from './worldAdapter';
18
+ export * from './directorAdapter';
19
+
20
+ /**
21
+ * The four R1 adapter registries, pre-wired — the showroom view of the
22
+ * platform's capability matrix. One per capability domain:
23
+ * - `chat` — delegates selection to `shared/model_router.py` (facade only).
24
+ * - `image` — the Gemini image catalogue (R1c).
25
+ * - `world` — step-into-video; Helios default, LongLive-v2 also registered.
26
+ * - `director` — timeline director; LongLive-v2 default (the Step-2/3 swap),
27
+ * Helios the fallback.
28
+ */
29
+ export interface PlatformRegistries {
30
+ chat: AdapterRegistry<ChatAdapterDescriptor>;
31
+ image: AdapterRegistry<ImageAdapterDescriptor>;
32
+ world: AdapterRegistry<WorldAdapterDescriptor>;
33
+ director: AdapterRegistry<DirectorAdapterDescriptor>;
34
+ }
35
+
36
+ /**
37
+ * Aggregate all four R1 adapter registries — the single entry every
38
+ * downstream wave (and the `/admin/adapters` showroom inspector) imports to
39
+ * get the platform's capability matrix pre-wired.
40
+ *
41
+ * `world` + `director` are SYNCHRONOUS seeds (no I/O): the Helios world
42
+ * default and the LongLive-v2 director default (post Step-2/3 swap) come from
43
+ * their factory functions. `chat` + `image` are loaded from their backend
44
+ * catalogues (`GET /api/v1/chat|images/models`) via the existing facades and
45
+ * resolved in PARALLEL; awaiting the returned promise yields all four
46
+ * registries ready.
47
+ *
48
+ * Like the facades it composes, this makes NO model-selection decision — chat
49
+ * selection stays server-side in `shared/model_router.py`; this only wires the
50
+ * registries together (DRY: it reuses `loadChatAdapterRegistry` /
51
+ * `loadImageAdapterRegistry` / `createWorldRegistry` / `createDirectorRegistry`
52
+ * rather than re-deriving any of them).
53
+ */
54
+ export async function createPlatformRegistries(
55
+ client: Pick<ApiClient, 'listChatModels' | 'listImageModels'>,
56
+ ): Promise<PlatformRegistries> {
57
+ const [chat, image] = await Promise.all([
58
+ loadChatAdapterRegistry(client),
59
+ loadImageAdapterRegistry(client),
60
+ ]);
61
+ return {
62
+ chat,
63
+ image,
64
+ world: createWorldRegistry(),
65
+ director: createDirectorRegistry(),
66
+ };
67
+ }
@@ -0,0 +1,159 @@
1
+ import type { Capability } from './capabilities';
2
+
3
+ /**
4
+ * Framework-agnostic model-adapter registry contract (R1a).
5
+ *
6
+ * The primitive every later R1 adapter (image / world / director domains)
7
+ * registers into. Deliberately free of React, DOM, and provider-SDK imports —
8
+ * mirror the discipline of the `reactor/` and `vision/` submodules. It carries
9
+ * descriptors and resolves named routes; it never invokes a model.
10
+ *
11
+ * The route/fallback semantics mirror the backend chat router
12
+ * (`shared/model_router.py:344-360`): a route whose adapter is unregistered
13
+ * degrades to the configured fallback route rather than throwing, keeping the
14
+ * resolution path crash-proof.
15
+ */
16
+
17
+ /**
18
+ * Named-route constants — the `ROUTE_*` analogue of
19
+ * `shared/model_router.py:56-59`. Use these at call sites instead of inline
20
+ * string literals so a route name can never be a raw string.
21
+ */
22
+ export const ROUTE_DEFAULT = 'default' as const;
23
+ export const ROUTE_FALLBACK = 'fallback' as const;
24
+ export const ROUTE_HIGH_QUALITY = 'high_quality' as const;
25
+
26
+ /**
27
+ * A single registered adapter. `id` is the stable lookup key; `capabilities`
28
+ * is the advertised {@link Capability} vocabulary. `metadata` is opaque and
29
+ * forward-compatible — the registry carries it untouched, never interpreting
30
+ * it, so adapters can stamp cost tier / cache policy / etc. without a contract
31
+ * change here.
32
+ */
33
+ export interface ModelAdapterDescriptor {
34
+ /** Stable lookup key, e.g. `'helios'`, `'gemini-3.1-flash-image-preview'`. */
35
+ id: string;
36
+ displayName: string;
37
+ /** Provider family, e.g. `'reactor' | 'gemini' | 'bedrock' | 'ollama'`. */
38
+ provider: string;
39
+ capabilities: readonly Capability[];
40
+ /** Opaque, forward-compat metadata (cost tier, cache policy) — carried, not interpreted. */
41
+ metadata?: Readonly<Record<string, unknown>>;
42
+ }
43
+
44
+ /**
45
+ * A named route binding — the `ROUTE_*` → adapter mapping. `name` is always a
46
+ * named-route constant, never a raw string at call sites.
47
+ */
48
+ export interface NamedRoute {
49
+ /**
50
+ * `ROUTE_*` analogue, never a raw string at call sites. Deliberately typed
51
+ * `string` (not a literal union of the known `ROUTE_*`) so downstream R1b–R1d
52
+ * PRs can register new routes without widening it back; `resolveRoute`
53
+ * degrades on an unknown name rather than rejecting it.
54
+ */
55
+ name: string;
56
+ adapterId: string;
57
+ reason: string;
58
+ }
59
+
60
+ /**
61
+ * Additive registry of {@link ModelAdapterDescriptor}s for a single domain.
62
+ *
63
+ * - {@link register} is additive and THROWS on a duplicate id (no silent
64
+ * overwrite).
65
+ * - {@link resolveRoute} degrades to the fallback route rather than throwing.
66
+ */
67
+ export class AdapterRegistry<TDescriptor extends ModelAdapterDescriptor> {
68
+ private readonly domain: string;
69
+ private readonly routes: ReadonlyMap<string, NamedRoute>;
70
+ private readonly fallbackRouteName: string;
71
+ private readonly descriptors = new Map<string, TDescriptor>();
72
+
73
+ constructor(opts: {
74
+ domain: string;
75
+ routes: readonly NamedRoute[];
76
+ fallbackRouteName: string;
77
+ }) {
78
+ // Eager guard: a fallbackRouteName absent from `routes` would make EVERY
79
+ // degrade silently return undefined (resolveRoute never throws). Fail at
80
+ // construction — the only place the misconfiguration is detectable.
81
+ if (!opts.routes.some((route) => route.name === opts.fallbackRouteName)) {
82
+ throw new Error(
83
+ `AdapterRegistry(${opts.domain}): fallbackRouteName "${opts.fallbackRouteName}" ` +
84
+ 'is not present in the routes array — configure a fallback route.',
85
+ );
86
+ }
87
+ this.domain = opts.domain;
88
+ this.fallbackRouteName = opts.fallbackRouteName;
89
+ this.routes = new Map(opts.routes.map((route) => [route.name, route]));
90
+ }
91
+
92
+ /** Register a descriptor. Additive — THROWS if `descriptor.id` already exists. */
93
+ register(descriptor: TDescriptor): void {
94
+ if (this.descriptors.has(descriptor.id)) {
95
+ throw new Error(
96
+ `AdapterRegistry(${this.domain}): duplicate adapter id "${descriptor.id}" — ` +
97
+ 'registration is additive and must not silently overwrite an existing adapter.',
98
+ );
99
+ }
100
+ this.descriptors.set(descriptor.id, descriptor);
101
+ }
102
+
103
+ /** Look up a descriptor by id, or `undefined` if unregistered. */
104
+ get(id: string): TDescriptor | undefined {
105
+ return this.descriptors.get(id);
106
+ }
107
+
108
+ /** All registered descriptors (registration order). */
109
+ list(): readonly TDescriptor[] {
110
+ return [...this.descriptors.values()];
111
+ }
112
+
113
+ /** Descriptors whose `capabilities` include `cap`. */
114
+ listWithCapability(cap: Capability): readonly TDescriptor[] {
115
+ return this.list().filter((descriptor) => descriptor.capabilities.includes(cap));
116
+ }
117
+
118
+ /**
119
+ * Resolve a named route to its adapter. If the route's `adapterId` is
120
+ * registered, return it. Otherwise (route unknown, or its adapter
121
+ * unregistered) degrade to the configured fallback route and return ITS
122
+ * adapter if registered. If even the fallback adapter is missing, return
123
+ * `undefined`. NEVER throws.
124
+ *
125
+ * Parity with `shared/model_router.py:344-360`.
126
+ */
127
+ resolveRoute(routeName: string): TDescriptor | undefined {
128
+ const direct = this.adapterForRoute(routeName);
129
+ if (direct !== undefined) {
130
+ return direct;
131
+ }
132
+ // Already tried the fallback route directly above — skip the second lookup.
133
+ if (routeName === this.fallbackRouteName) {
134
+ return undefined;
135
+ }
136
+ return this.adapterForRoute(this.fallbackRouteName);
137
+ }
138
+
139
+ /**
140
+ * True iff `id` is registered AND its descriptor advertises EVERY member of
141
+ * `required`. False for an unregistered id.
142
+ */
143
+ satisfies(id: string, required: readonly Capability[]): boolean {
144
+ const descriptor = this.descriptors.get(id);
145
+ if (descriptor === undefined) {
146
+ return false;
147
+ }
148
+ return required.every((cap) => descriptor.capabilities.includes(cap));
149
+ }
150
+
151
+ /** Resolve a route name to its REGISTERED adapter, or `undefined`. No fallback. */
152
+ private adapterForRoute(routeName: string): TDescriptor | undefined {
153
+ const route = this.routes.get(routeName);
154
+ if (route === undefined) {
155
+ return undefined;
156
+ }
157
+ return this.descriptors.get(route.adapterId);
158
+ }
159
+ }
@@ -0,0 +1,272 @@
1
+ import {
2
+ AdapterRegistry,
3
+ ROUTE_DEFAULT,
4
+ ROUTE_FALLBACK,
5
+ type NamedRoute,
6
+ type ModelAdapterDescriptor,
7
+ } from './registry';
8
+ import type { WorldCapability } from './capabilities';
9
+ import type {
10
+ HeliosCommand,
11
+ HeliosToolContext,
12
+ LongLiveCommand,
13
+ LongLiveToolContext,
14
+ } from '../reactor';
15
+ import { dispatchHeliosCommand, dispatchLongLiveCommand } from '../reactor';
16
+
17
+ /**
18
+ * World-domain (step-into-video) adapter registry — R1d, Helios seed.
19
+ *
20
+ * This is a capability GATE in FRONT of the existing, working Helios
21
+ * machinery, NOT a rewrite. Today the live `/interactive` pages dispatch
22
+ * through {@link dispatchHeliosCommand} against a structural
23
+ * `HeliosReactorBridge`; the `modelName="helios"` literal is hard-coded in
24
+ * those React pages. R1d wraps that one model behind a
25
+ * {@link WorldAdapterDescriptor} + {@link AdapterRegistry} so later waves
26
+ * (R7 flagship DM, R8 Director/Interactive rewire) can register sibling
27
+ * adapters and swap them. The 'helios' model-name literal is CENTRALIZED
28
+ * here so the R8 rewire stops hard-coding it in the pages.
29
+ *
30
+ * LAND-DARK: the live Helios path is UNCHANGED. {@link dispatchWorldCommand}
31
+ * only gates in front of {@link dispatchHeliosCommand} and delegates with
32
+ * IDENTICAL arguments. The adapters/ submodule stays SDK-free — it reuses
33
+ * the structural `HeliosReactorBridge` via {@link HeliosToolContext} and
34
+ * takes NO `@reactor-team/js-sdk` dependency.
35
+ */
36
+
37
+ /**
38
+ * A world adapter descriptor — a {@link ModelAdapterDescriptor} that also
39
+ * declares the world commands it accepts. `supportedCommands` is deliberately
40
+ * `readonly string[]` (model-agnostic), NOT locked to the {@link HeliosCommand}
41
+ * variant set: the registry's purpose is to hold heterogeneous world models,
42
+ * and a sibling model (e.g. a Reactor LongLive adapter) has its OWN command
43
+ * vocabulary (`set_shot`/`scene_cut`/`schedule_shot`/…) that is not a
44
+ * `HeliosCommand`. Each adapter declares its own command strings here; the
45
+ * Helios seed below declares the `HeliosCommand` variant names.
46
+ */
47
+ export interface WorldAdapterDescriptor extends ModelAdapterDescriptor {
48
+ /**
49
+ * The world commands this adapter accepts (each model's own vocabulary).
50
+ *
51
+ * Distinct axis from the inherited `capabilities`: `capabilities` (e.g.
52
+ * `'world_stream'`/`'pause_resume'`) is the **registry** axis that
53
+ * `listWithCapability`/`satisfies` filter and gate on; `supportedCommands`
54
+ * (e.g. `'set_scene'`/`'reset_world'`) is **advisory metadata** naming the
55
+ * command strings the adapter's dispatcher understands. The dispatch gate
56
+ * routes on `id` + (when a 2nd adapter lands) `capabilities`, NOT on this
57
+ * array.
58
+ */
59
+ supportedCommands: readonly string[];
60
+ }
61
+
62
+ /**
63
+ * The one world model that exists today. Helios drives the live
64
+ * step-into-video stream over the structural Reactor bridge. Its
65
+ * `supportedCommands` is the EXACT {@link HeliosCommand} variant set
66
+ * (`reactor/heliosTools.ts:32-37`).
67
+ *
68
+ * The 'helios' id is the single source of truth for the model name — the
69
+ * R8 rewire reads it from here instead of re-spelling the literal in the
70
+ * `/interactive` pages.
71
+ */
72
+ // `as const satisfies` (NOT a `: WorldAdapterDescriptor` annotation) so `.id`
73
+ // keeps its literal type `'helios'` — `dispatchWorldCommand`'s overloads key on
74
+ // `typeof heliosWorldAdapter.id`, which would widen to `string` (defeating the
75
+ // cmd/adapter discrimination) under a plain type annotation.
76
+ export const heliosWorldAdapter = {
77
+ id: 'helios',
78
+ displayName: 'Helios',
79
+ provider: 'reactor',
80
+ capabilities: ['world_stream', 'set_scene', 'swap_seed', 'pause_resume'],
81
+ supportedCommands: [
82
+ 'set_scene',
83
+ 'swap_seed',
84
+ 'pause_world',
85
+ 'resume_world',
86
+ 'reset_world',
87
+ ],
88
+ } as const satisfies WorldAdapterDescriptor;
89
+
90
+ /**
91
+ * The second world model — Reactor LongLive-v2. SAME Reactor transport as
92
+ * Helios (only the `modelName` differs on the bridge); its OWN command
93
+ * vocabulary (`set_shot`/`scene_cut`/`schedule_shot`/… — the
94
+ * {@link LongLiveCommand} variant set, not a `HeliosCommand`).
95
+ *
96
+ * ASYMMETRIC capability matrix vs Helios: LongLive is text-to-video with NO
97
+ * image conditioning, so it LACKS `swap_seed`; but it ADDS `scene_cut` (a
98
+ * hard, memory-purging transition) which Helios — a continuous morph — lacks.
99
+ * That asymmetry is exactly what `registry.satisfies` lets the Step-3 director
100
+ * UI query (hide the seed-image UI when the resolved world is LongLive).
101
+ */
102
+ // `as const satisfies` (see heliosWorldAdapter) so `.id` stays `'longlive-v2'`
103
+ // for the dispatchWorldCommand overload discrimination.
104
+ export const longLiveWorldAdapter = {
105
+ id: 'longlive-v2',
106
+ displayName: 'LongLive 2.0',
107
+ provider: 'reactor',
108
+ // 'set_scene' here is the ABSTRACT scene-steering capability (not a 1:1
109
+ // command name) — LongLive fulfills it via its `set_shot` command, where
110
+ // Helios uses `set_scene`. So satisfies(id,['set_scene']) is true for both
111
+ // adapters even though their underlying commands differ.
112
+ // NO 'swap_seed' (no image conditioning); HAS 'scene_cut' (hard transition).
113
+ // 'set_seed' (numeric noise seed, read once at start) is in supportedCommands
114
+ // but is internal session tooling — NOT a surfaced capability like Helios's
115
+ // image-based swap_seed, so it intentionally has no WorldCapability entry.
116
+ capabilities: ['world_stream', 'set_scene', 'scene_cut', 'pause_resume'],
117
+ supportedCommands: [
118
+ 'set_shot',
119
+ 'scene_cut',
120
+ 'schedule_shot',
121
+ 'schedule_scene_cut',
122
+ 'pause',
123
+ 'resume',
124
+ 'reset',
125
+ 'set_seed',
126
+ ],
127
+ } as const satisfies WorldAdapterDescriptor;
128
+
129
+ /**
130
+ * Build a world {@link AdapterRegistry} pre-registered with the Helios seed.
131
+ * Each call returns a FRESH instance (the factory is synchronous + free) —
132
+ * callers that dispatch repeatedly should memoize one registry rather than
133
+ * rebuild it per call.
134
+ *
135
+ * Both `ROUTE_DEFAULT` and `ROUTE_FALLBACK` STAY pointed at the Helios id —
136
+ * Helios remains the WORLD default (plain `/interactive` is unchanged). The
137
+ * LongLive adapter is registered + resolvable by id (`get('longlive-v2')`)
138
+ * and by capability (`listWithCapability('scene_cut')`), but it is NOT the
139
+ * world default. The DIRECTOR registry is where LongLive becomes the default
140
+ * (see `createDirectorRegistry`). The R1a constructor guard REQUIRES the
141
+ * `fallbackRouteName` to be present by name in `routes`.
142
+ */
143
+ export function createWorldRegistry(): AdapterRegistry<WorldAdapterDescriptor> {
144
+ const routes: NamedRoute[] = [
145
+ {
146
+ name: ROUTE_DEFAULT,
147
+ adapterId: heliosWorldAdapter.id,
148
+ reason: 'Helios stays the world default (plain /interactive unchanged)',
149
+ },
150
+ {
151
+ name: ROUTE_FALLBACK,
152
+ adapterId: heliosWorldAdapter.id,
153
+ reason: 'Helios is the world fallback',
154
+ },
155
+ ];
156
+
157
+ const registry = new AdapterRegistry<WorldAdapterDescriptor>({
158
+ domain: 'world',
159
+ routes,
160
+ fallbackRouteName: ROUTE_FALLBACK,
161
+ });
162
+ registry.register(heliosWorldAdapter);
163
+ registry.register(longLiveWorldAdapter);
164
+ return registry;
165
+ }
166
+
167
+ /**
168
+ * Pure mapping from a world command to the {@link WorldCapability} an
169
+ * adapter must advertise to accept it. Mirrors the dispatcher's
170
+ * exhaustive-switch idiom (`reactor/heliosCommandDispatcher.ts:114-142`) so
171
+ * a new {@link HeliosCommand} variant fails to compile until mapped here.
172
+ */
173
+ export function requiredCapabilityForCommand(cmd: HeliosCommand): WorldCapability {
174
+ switch (cmd.type) {
175
+ case 'set_scene':
176
+ return 'set_scene';
177
+ case 'swap_seed':
178
+ return 'swap_seed';
179
+ case 'pause_world':
180
+ case 'resume_world':
181
+ return 'pause_resume';
182
+ case 'reset_world':
183
+ // 'world_stream' is used as the base/lifecycle capability here — there is
184
+ // no reset-specific WorldCapability, and any adapter that can stream a
185
+ // world can reset it. A future replay-only adapter that omits
186
+ // 'world_stream' would (correctly) be gated out of reset_world.
187
+ return 'world_stream';
188
+ default: {
189
+ // Exhaustiveness check — TS complains at compile time if a new
190
+ // HeliosCommand variant is added without mapping it here.
191
+ const _exhaustive: never = cmd;
192
+ throw new Error(
193
+ `requiredCapabilityForCommand: unmapped world command ${JSON.stringify(_exhaustive)}`,
194
+ );
195
+ }
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Thrown by {@link dispatchWorldCommand} when an adapter id has no real world
201
+ * transport wired (anything other than the Helios or LongLive seeds). Typed
202
+ * so callers can distinguish "no transport for this adapter" from a transient
203
+ * Reactor failure (which the underlying dispatchers swallow). Carries the
204
+ * offending `adapterId`.
205
+ */
206
+ export class UnsupportedWorldAdapterError extends Error {
207
+ readonly adapterId: string;
208
+
209
+ constructor(adapterId: string) {
210
+ // No class-name prefix in the message — `this.name` already supplies it,
211
+ // so `error.toString()` / stack traces don't render it twice. Generic
212
+ // (no enumeration of which adapters ARE wired) so it doesn't go stale as
213
+ // sibling adapters register.
214
+ super(
215
+ `World adapter "${adapterId}" has no dispatch transport wired in dispatchWorldCommand.`,
216
+ );
217
+ this.name = 'UnsupportedWorldAdapterError';
218
+ this.adapterId = adapterId;
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Per-adapter dispatch of a single world command, routed by `adapterId`.
224
+ *
225
+ * (a) `heliosWorldAdapter.id` → delegate to the EXISTING
226
+ * {@link dispatchHeliosCommand} with IDENTICAL arguments. The Helios path
227
+ * is UNCHANGED — this only routes in front of it (LAND-DARK). This branch
228
+ * is BYTE-IDENTICAL to the R1d single-adapter body; the LongLive branch is
229
+ * purely ADDITIVE.
230
+ * (b) `longLiveWorldAdapter.id` → delegate to {@link dispatchLongLiveCommand}
231
+ * over the SAME structural Reactor bridge.
232
+ * (c) Any other id → throw a typed {@link UnsupportedWorldAdapterError}
233
+ * WITHOUT touching the bridge (no other adapter has a real transport).
234
+ *
235
+ * Compile-time safety is enforced by the FUNCTION OVERLOADS below — each
236
+ * `(adapterId, cmd, ctx)` triple must agree (a `LongLiveCommand` cannot be
237
+ * passed under the Helios id, and vice versa). So NO per-command runtime
238
+ * capability gate is added here (the R1d review removed the unreachable
239
+ * `satisfies` scaffolding): the overloads enforce the cmd/adapter match at the
240
+ * type level, and the capability INFO (the asymmetric matrix — helios
241
+ * `swap_seed` not `scene_cut`; longlive `scene_cut` not `swap_seed`) is
242
+ * consumed via `registry.satisfies()` by the Step-3 director UI (to hide the
243
+ * seed-image control for LongLive), NOT by a runtime dispatch gate. Resolves
244
+ * tech-debt #414.
245
+ */
246
+ export async function dispatchWorldCommand(
247
+ adapterId: typeof heliosWorldAdapter.id,
248
+ cmd: HeliosCommand,
249
+ ctx: HeliosToolContext,
250
+ ): Promise<void>;
251
+ export async function dispatchWorldCommand(
252
+ adapterId: typeof longLiveWorldAdapter.id,
253
+ cmd: LongLiveCommand,
254
+ ctx: LongLiveToolContext,
255
+ ): Promise<void>;
256
+ export async function dispatchWorldCommand(
257
+ adapterId: string,
258
+ cmd: HeliosCommand | LongLiveCommand,
259
+ ctx: HeliosToolContext | LongLiveToolContext,
260
+ ): Promise<void> {
261
+ if (adapterId === heliosWorldAdapter.id) {
262
+ // Delegate to the existing dispatcher — IDENTICAL args, no rewrite.
263
+ await dispatchHeliosCommand(cmd as HeliosCommand, ctx as HeliosToolContext);
264
+ } else if (adapterId === longLiveWorldAdapter.id) {
265
+ await dispatchLongLiveCommand(
266
+ cmd as LongLiveCommand,
267
+ ctx as LongLiveToolContext,
268
+ );
269
+ } else {
270
+ throw new UnsupportedWorldAdapterError(adapterId);
271
+ }
272
+ }