@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
package/src/audio.ts CHANGED
@@ -394,6 +394,9 @@ export const buildHelloPayload = ({
394
394
  systemPromptOverride = false,
395
395
  modelId,
396
396
  ttsModelId,
397
+ entityId,
398
+ adventureSessionId,
399
+ partyPersonaIds,
397
400
  }: {
398
401
  videoId?: string;
399
402
  personaId?: string;
@@ -407,6 +410,35 @@ export const buildHelloPayload = ({
407
410
  systemPromptOverride?: boolean;
408
411
  modelId?: string;
409
412
  ttsModelId?: string;
413
+ /**
414
+ * Entity id of the character a bound persona portrays. When set, the
415
+ * voice session is scoped to this entity exactly like the text path.
416
+ * Omit (undefined) for unbound personas — the hello frame stays
417
+ * unchanged for them (land-dark). Frontend-resolved, same as
418
+ * `systemPrompt`. Matches `HelloMessage.entityId` in
419
+ * `shared/audio_protocol.py`.
420
+ */
421
+ entityId?: string;
422
+ /**
423
+ * Adventure session id the voice session runs inside (M9 Adventure Runtime
424
+ * Phase 8a). When set, the backend exposes the Dungeon-Master tool surface
425
+ * and threads the active adventure's state into the system prompt, exactly
426
+ * like the text path. Omit (undefined) for ordinary voice chat — the hello
427
+ * frame stays unchanged (land-dark). Matches `HelloMessage.adventureSessionId`
428
+ * in `shared/audio_protocol.py`.
429
+ */
430
+ adventureSessionId?: string;
431
+ /**
432
+ * Party persona ids for a multi-persona adventure (M10 Story Engine Phase
433
+ * 9a). Advisory / forward-compat only: the SERVER's
434
+ * `AdventureState.party_persona_ids` is authoritative for scene-orchestrator
435
+ * routing — the orchestrator loads the roster from `AdventureState`, NOT from
436
+ * this hello field (mirrors the M9 8a "bound session authoritative"
437
+ * decision). Omit / leave empty for ordinary chat and M9 single-DM
438
+ * (empty-party) adventures — the hello frame stays unchanged (land-dark).
439
+ * Matches `HelloMessage.partyPersonaIds` in `shared/audio_protocol.py`.
440
+ */
441
+ partyPersonaIds?: string[];
410
442
  }) => ({
411
443
  action: 'hello' as const,
412
444
  version: HELLO_VERSION,
@@ -421,6 +453,9 @@ export const buildHelloPayload = ({
421
453
  ...(systemPrompt ? { systemPrompt, systemPromptOverride } : {}),
422
454
  ...(modelId ? { modelId } : {}),
423
455
  ...(ttsModelId ? { ttsModelId } : {}),
456
+ ...(entityId ? { entityId } : {}),
457
+ ...(adventureSessionId ? { adventureSessionId } : {}),
458
+ ...(partyPersonaIds && partyPersonaIds.length > 0 ? { partyPersonaIds } : {}),
424
459
  });
425
460
 
426
461
  export type HelloPayload = ReturnType<typeof buildHelloPayload>;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * castProjection — pure normalizer over the R5a cast-with-persona payload
3
+ * (Platform Restructure R5c).
4
+ *
5
+ * `castWithPersona(response)` turns a `CastWithPersonaResponse` (the one-call
6
+ * `GET /api/v1/tools/videos/{videoId}/cast` server-side join) into the
7
+ * render-ready `CastEntry[]` a Cast view consumes: deterministically ordered
8
+ * (entries by display name, scenes by id, arcs by index) with every list
9
+ * field coalesced and display-name fallbacks applied, so a renderer never
10
+ * branches on missing data (deploy skew between an older backend and a newer
11
+ * client degrades to empty lists, not crashes).
12
+ *
13
+ * Framework-agnostic and side-effect free — React (the studio CastGrid) and
14
+ * any other consumer (the escape.ai Web-App, a game engine UI) share this ONE
15
+ * projection instead of re-joining `getVideoGraph` + `listPersonas` client
16
+ * side by `entity_id` string equality (the pre-R5c fragility this milestone
17
+ * removes). The function never mutates its input.
18
+ */
19
+
20
+ import type {
21
+ CastArc,
22
+ CastCharacter,
23
+ CastEntry,
24
+ CastPersonaSummary,
25
+ CastScene,
26
+ CastWithPersonaResponse,
27
+ } from './api';
28
+
29
+ /** Normalize one character: coalesce lists, apply display fallbacks, sort. */
30
+ function normalizeCharacter(character: CastCharacter): CastCharacter {
31
+ const entityId = character.entityId ?? '';
32
+ const scenes: CastScene[] = (character.scenes ?? [])
33
+ .map((scene) => ({
34
+ sceneId: scene.sceneId,
35
+ title: scene.title || scene.sceneId,
36
+ }))
37
+ .sort((a, b) => a.sceneId.localeCompare(b.sceneId));
38
+ const arcs: CastArc[] = (character.arcs ?? [])
39
+ .map((arc) => ({
40
+ arcId: arc.arcId,
41
+ title: arc.title || arc.arcId,
42
+ summary: arc.summary ?? null,
43
+ index: arc.index ?? 0,
44
+ }))
45
+ .sort((a, b) => a.index - b.index || a.arcId.localeCompare(b.arcId));
46
+ return {
47
+ entityId,
48
+ name: character.name || entityId,
49
+ aliases: [...(character.aliases ?? [])],
50
+ scenes,
51
+ arcs,
52
+ relatedCharacterIds: [...(character.relatedCharacterIds ?? [])],
53
+ };
54
+ }
55
+
56
+ /** Normalize the bound persona (or null when unbound). */
57
+ function normalizePersona(
58
+ persona: CastPersonaSummary | null | undefined,
59
+ ): CastPersonaSummary | null {
60
+ if (!persona) return null;
61
+ return {
62
+ personaId: persona.personaId,
63
+ name: persona.name || persona.personaId || '',
64
+ chatModelId: persona.chatModelId ?? '',
65
+ characterImageId: persona.characterImageId ?? null,
66
+ isDungeonMaster: persona.isDungeonMaster ?? false,
67
+ };
68
+ }
69
+
70
+ /**
71
+ * Project a `CastWithPersonaResponse` into render-ready `CastEntry[]`.
72
+ *
73
+ * Entries are sorted by character display name (`localeCompare`, entityId
74
+ * tie-break — the same order the legacy `deriveCast` client join rendered),
75
+ * with all nested list fields coalesced + deterministically sorted and the
76
+ * title/name fallbacks applied. Pure: the input response is not mutated.
77
+ *
78
+ * Name ordering is locale-aware via the RUNTIME's default locale
79
+ * (`localeCompare` with no locale argument) — deliberately matching the
80
+ * legacy `deriveCast` ordering rather than pinning a locale; two consumers in
81
+ * different locales may order accented names differently, but each render is
82
+ * internally deterministic (the entityId tie-break breaks equal names).
83
+ */
84
+ export function castWithPersona(response: CastWithPersonaResponse): CastEntry[] {
85
+ return (response.cast ?? [])
86
+ .map((entry) => ({
87
+ character: normalizeCharacter(entry.character),
88
+ persona: normalizePersona(entry.persona),
89
+ }))
90
+ .sort(
91
+ (a, b) =>
92
+ a.character.name.localeCompare(b.character.name) ||
93
+ a.character.entityId.localeCompare(b.character.entityId),
94
+ );
95
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Conversation context binding (R2.1).
3
+ *
4
+ * A `ConversationContextBinding` is the typed superset of everything
5
+ * `buildHelloPayload` (audio.ts) accepts for grounding a session: the Watch
6
+ * video, the Studio character/adventure session, and the advisory party roster.
7
+ * `toHelloArgs` maps it 1:1 onto `buildHelloPayload`'s argument object so there
8
+ * is exactly ONE place that shapes a hello (the cross-PR DRY rule) — the
9
+ * controller spreads the active participant's persona/model fields over this
10
+ * result and feeds the single `buildHelloPayload` call.
11
+ *
12
+ * `kind` is a frozen constant object (no inline string literals).
13
+ */
14
+
15
+ import type { buildHelloPayload } from '../audio';
16
+
17
+ /**
18
+ * What the conversation is bound to. `VIDEO` = the Watch surface (`videoId`);
19
+ * `STUDIO_SESSION` = a Studio cast/play surface (`entityId` and/or
20
+ * `adventureSessionId`); `PERSONA` = a standalone persona-face chat bound to a
21
+ * single `personaId` (the dashboard "Chat with a persona" floater — each
22
+ * persona is a DISTINCT binding so selecting a second persona rebinds/remounts
23
+ * rather than colliding on the generic `NONE` key, which is the originally
24
+ * specified switch-persona bug); `NONE` = an unbound general chat. The values
25
+ * are the `kind` discriminator carried on the binding.
26
+ */
27
+ export const ConversationContextKind = {
28
+ VIDEO: 'video',
29
+ STUDIO_SESSION: 'studio_session',
30
+ PERSONA: 'persona',
31
+ NONE: 'none',
32
+ } as const;
33
+
34
+ export type ConversationContextKind =
35
+ (typeof ConversationContextKind)[keyof typeof ConversationContextKind];
36
+
37
+ /**
38
+ * The bound context. Every field below is a `buildHelloPayload` arg, so the
39
+ * binding cannot drift from what the hello can carry. `partyPersonaIds` is the
40
+ * advisory roster (server `AdventureState.party_persona_ids` is authoritative —
41
+ * see `advisoryPartyPersonaIds` in `web/app/chat-ws/adventureMode.ts`); the
42
+ * controller re-derives it from the participant list on add/remove.
43
+ */
44
+ export interface ConversationContextBinding {
45
+ kind: ConversationContextKind;
46
+ videoId?: string;
47
+ /**
48
+ * The persona this conversation is bound to (a `ConversationContextKind.PERSONA`
49
+ * standalone persona-face chat). It makes each persona a DISTINCT binding key
50
+ * so `ConversationOverlayProvider.open()` rebinds when the user picks a second
51
+ * persona instead of short-circuiting on a shared `NONE` key. Like the other
52
+ * id fields it is also a `buildHelloPayload` arg, so the binding cannot drift
53
+ * from what the hello can carry; the controller still overlays the active
54
+ * participant's `personaId` on top, so a seat-level persona wins when present.
55
+ */
56
+ personaId?: string;
57
+ entityId?: string;
58
+ adventureSessionId?: string;
59
+ partyPersonaIds?: string[];
60
+ }
61
+
62
+ /**
63
+ * The exact argument object `buildHelloPayload` accepts. Derived from the
64
+ * function's own parameter type so this can never drift from audio.ts — there is
65
+ * one builder and one arg shape.
66
+ */
67
+ export type HelloArgs = Parameters<typeof buildHelloPayload>[0];
68
+
69
+ /**
70
+ * Map a binding onto the context subset of `buildHelloPayload`'s args. PURE — no
71
+ * I/O. Only the context-derived fields are set here; the controller overlays the
72
+ * active participant's `personaId` / `modelId` (and any audio knobs) before the
73
+ * single `buildHelloPayload` call. Returning a partial keeps every default in
74
+ * `buildHelloPayload` (the one place defaults live).
75
+ *
76
+ * An empty `partyPersonaIds` is dropped so the wire stays byte-identical for
77
+ * ordinary chat and single-DM adventures — same land-dark contract as
78
+ * `advisoryPartyPersonaIds`. The falsy-drop is INTENTIONAL across all three id
79
+ * fields too: an empty-string id is treated as "unset" (ids are real
80
+ * UUIDs/handles — an `''` is a caller mistake, not a value to send), keeping the
81
+ * hello free of meaningless empty fields.
82
+ */
83
+ export function toHelloArgs(
84
+ binding: ConversationContextBinding,
85
+ ): Pick<
86
+ HelloArgs,
87
+ 'videoId' | 'personaId' | 'entityId' | 'adventureSessionId' | 'partyPersonaIds'
88
+ > {
89
+ return {
90
+ ...(binding.videoId ? { videoId: binding.videoId } : {}),
91
+ ...(binding.personaId ? { personaId: binding.personaId } : {}),
92
+ ...(binding.entityId ? { entityId: binding.entityId } : {}),
93
+ ...(binding.adventureSessionId
94
+ ? { adventureSessionId: binding.adventureSessionId }
95
+ : {}),
96
+ ...(binding.partyPersonaIds && binding.partyPersonaIds.length > 0
97
+ ? { partyPersonaIds: [...binding.partyPersonaIds] }
98
+ : {}),
99
+ };
100
+ }