@escapeaihq/client-core 0.12.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -7
- package/dist/adapters/capabilities.d.ts +10 -0
- package/dist/adapters/capabilities.d.ts.map +1 -0
- package/dist/adapters/capabilities.js +2 -0
- package/dist/adapters/capabilities.js.map +1 -0
- package/dist/adapters/chatAdapter.d.ts +38 -0
- package/dist/adapters/chatAdapter.d.ts.map +1 -0
- package/dist/adapters/chatAdapter.js +88 -0
- package/dist/adapters/chatAdapter.js.map +1 -0
- package/dist/adapters/directorAdapter.d.ts +62 -0
- package/dist/adapters/directorAdapter.d.ts.map +1 -0
- package/dist/adapters/directorAdapter.js +71 -0
- package/dist/adapters/directorAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +44 -0
- package/dist/adapters/imageAdapter.d.ts.map +1 -0
- package/dist/adapters/imageAdapter.js +73 -0
- package/dist/adapters/imageAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +47 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +41 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +98 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +106 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +142 -0
- package/dist/adapters/worldAdapter.d.ts.map +1 -0
- package/dist/adapters/worldAdapter.js +164 -0
- package/dist/adapters/worldAdapter.js.map +1 -0
- package/dist/admin.d.ts +323 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +198 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1512 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +820 -52
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +33 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +4 -1
- package/dist/audio.js.map +1 -1
- package/dist/castProjection.d.ts +35 -0
- package/dist/castProjection.d.ts.map +1 -0
- package/dist/castProjection.js +80 -0
- package/dist/castProjection.js.map +1 -0
- package/dist/conversation/binding.d.ts +77 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +57 -0
- package/dist/conversation/binding.js.map +1 -0
- package/dist/conversation/controller.d.ts +209 -0
- package/dist/conversation/controller.d.ts.map +1 -0
- package/dist/conversation/controller.js +350 -0
- package/dist/conversation/controller.js.map +1 -0
- package/dist/conversation/effectiveModel.d.ts +62 -0
- package/dist/conversation/effectiveModel.d.ts.map +1 -0
- package/dist/conversation/effectiveModel.js +73 -0
- package/dist/conversation/effectiveModel.js.map +1 -0
- package/dist/conversation/index.d.ts +27 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/participant.d.ts +66 -0
- package/dist/conversation/participant.d.ts.map +1 -0
- package/dist/conversation/participant.js +36 -0
- package/dist/conversation/participant.js.map +1 -0
- package/dist/conversation/presence.d.ts +56 -0
- package/dist/conversation/presence.d.ts.map +1 -0
- package/dist/conversation/presence.js +34 -0
- package/dist/conversation/presence.js.map +1 -0
- package/dist/conversation/presenceBus.d.ts +42 -0
- package/dist/conversation/presenceBus.d.ts.map +1 -0
- package/dist/conversation/presenceBus.js +81 -0
- package/dist/conversation/presenceBus.js.map +1 -0
- package/dist/conversation/presenceRegistry.d.ts +49 -0
- package/dist/conversation/presenceRegistry.d.ts.map +1 -0
- package/dist/conversation/presenceRegistry.js +59 -0
- package/dist/conversation/presenceRegistry.js.map +1 -0
- package/dist/conversation/roster.d.ts +72 -0
- package/dist/conversation/roster.d.ts.map +1 -0
- package/dist/conversation/roster.js +69 -0
- package/dist/conversation/roster.js.map +1 -0
- package/dist/conversation/rosterProjection.d.ts +52 -0
- package/dist/conversation/rosterProjection.d.ts.map +1 -0
- package/dist/conversation/rosterProjection.js +74 -0
- package/dist/conversation/rosterProjection.js.map +1 -0
- package/dist/conversation/router.d.ts +74 -0
- package/dist/conversation/router.d.ts.map +1 -0
- package/dist/conversation/router.js +58 -0
- package/dist/conversation/router.js.map +1 -0
- package/dist/conversation/runtime.d.ts +64 -0
- package/dist/conversation/runtime.d.ts.map +1 -0
- package/dist/conversation/runtime.js +172 -0
- package/dist/conversation/runtime.js.map +1 -0
- package/dist/conversation/types.d.ts +99 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +13 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/conversation/voice.d.ts +185 -0
- package/dist/conversation/voice.d.ts.map +1 -0
- package/dist/conversation/voice.js +307 -0
- package/dist/conversation/voice.js.map +1 -0
- package/dist/graphSchema.d.ts +201 -13
- package/dist/graphSchema.d.ts.map +1 -1
- package/dist/graphSchema.js +258 -9
- package/dist/graphSchema.js.map +1 -1
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +57 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/platformAssistant.d.ts +155 -0
- package/dist/platformAssistant.d.ts.map +1 -0
- package/dist/platformAssistant.js +256 -0
- package/dist/platformAssistant.js.map +1 -0
- package/dist/reactor/chunkDistribution.d.ts +43 -0
- package/dist/reactor/chunkDistribution.d.ts.map +1 -0
- package/dist/reactor/chunkDistribution.js +85 -0
- package/dist/reactor/chunkDistribution.js.map +1 -0
- package/dist/reactor/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +5 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/longLiveCommandDispatcher.js +87 -0
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
- package/dist/reactor/scenesFromEnrichment.js +2 -66
- package/dist/reactor/scenesFromEnrichment.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +6 -9
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +12 -13
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/storyTimeline.d.ts +44 -0
- package/dist/reactor/storyTimeline.d.ts.map +1 -0
- package/dist/reactor/storyTimeline.js +95 -0
- package/dist/reactor/storyTimeline.js.map +1 -0
- package/dist/storyGraph.d.ts +70 -0
- package/dist/storyGraph.d.ts.map +1 -0
- package/dist/storyGraph.js +178 -0
- package/dist/storyGraph.js.map +1 -0
- package/dist/vision/VisionSourceController.d.ts +127 -0
- package/dist/vision/VisionSourceController.d.ts.map +1 -0
- package/dist/vision/VisionSourceController.js +284 -0
- package/dist/vision/VisionSourceController.js.map +1 -0
- package/dist/vision/index.d.ts +4 -0
- package/dist/vision/index.d.ts.map +1 -1
- package/dist/vision/index.js +2 -0
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/sourceKinds.d.ts +65 -0
- package/dist/vision/sourceKinds.d.ts.map +1 -0
- package/dist/vision/sourceKinds.js +26 -0
- package/dist/vision/sourceKinds.js.map +1 -0
- package/dist/websocket.d.ts +92 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/adapters-capabilities.test.ts +46 -0
- package/src/__tests__/adapters-chat.test.ts +172 -0
- package/src/__tests__/adapters-director.test.ts +95 -0
- package/src/__tests__/adapters-image.test.ts +133 -0
- package/src/__tests__/adapters-platform.test.ts +95 -0
- package/src/__tests__/adapters-registry.test.ts +189 -0
- package/src/__tests__/adapters-world.test.ts +296 -0
- package/src/__tests__/admin.test.ts +312 -0
- package/src/__tests__/adventures-party.test.ts +219 -0
- package/src/__tests__/adventures.test.ts +282 -0
- package/src/__tests__/api-pollers.test.ts +4 -0
- package/src/__tests__/api.clip-lookup.test.ts +64 -0
- package/src/__tests__/api.list-images-filters.test.ts +103 -0
- package/src/__tests__/api.test.ts +553 -0
- package/src/__tests__/audio.test.ts +65 -0
- package/src/__tests__/cast.test.ts +95 -0
- package/src/__tests__/castProjection.test.ts +167 -0
- package/src/__tests__/conversation/binding.test.ts +62 -0
- package/src/__tests__/conversation/controller.test.ts +732 -0
- package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
- package/src/__tests__/conversation/headlessRenderer.ts +46 -0
- package/src/__tests__/conversation/presenceBus.test.ts +236 -0
- package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
- package/src/__tests__/conversation/roster.test.ts +100 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
- package/src/__tests__/conversation/router.test.ts +81 -0
- package/src/__tests__/conversation/runtime.test.ts +206 -0
- package/src/__tests__/conversation/voice.test.ts +440 -0
- package/src/__tests__/documents.test.ts +360 -0
- package/src/__tests__/graphSchema.test.ts +218 -9
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/monitoring.test.ts +162 -0
- package/src/__tests__/persona-generation.test.ts +352 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
- package/src/__tests__/regeneration.test.ts +486 -0
- package/src/__tests__/stories.test.ts +171 -0
- package/src/__tests__/storyGraph.test.ts +134 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket.test.ts +263 -0
- package/src/adapters/capabilities.ts +24 -0
- package/src/adapters/chatAdapter.ts +114 -0
- package/src/adapters/directorAdapter.ts +126 -0
- package/src/adapters/imageAdapter.ts +100 -0
- package/src/adapters/index.ts +67 -0
- package/src/adapters/registry.ts +159 -0
- package/src/adapters/worldAdapter.ts +272 -0
- package/src/admin.ts +517 -0
- package/src/api.ts +2215 -95
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +100 -0
- package/src/conversation/controller.ts +447 -0
- package/src/conversation/effectiveModel.ts +111 -0
- package/src/conversation/index.ts +27 -0
- package/src/conversation/participant.ts +71 -0
- package/src/conversation/presence.ts +60 -0
- package/src/conversation/presenceBus.ts +109 -0
- package/src/conversation/presenceRegistry.ts +83 -0
- package/src/conversation/roster.ts +111 -0
- package/src/conversation/rosterProjection.ts +98 -0
- package/src/conversation/router.ts +96 -0
- package/src/conversation/runtime.ts +188 -0
- package/src/conversation/types.ts +100 -0
- package/src/conversation/voice.ts +402 -0
- package/src/graphSchema.ts +396 -13
- package/src/http.ts +72 -0
- package/src/index.ts +9 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/index.ts +5 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +12 -13
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/index.ts +13 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/websocket.ts +99 -3
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
|
+
}
|