@escapeaihq/client-core 0.8.0 → 0.42.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 +48 -4
- 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 +200 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +124 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1299 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +683 -95
- 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 +62 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +51 -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 +342 -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 +260 -0
- package/dist/graphSchema.d.ts.map +1 -0
- package/dist/graphSchema.js +354 -0
- package/dist/graphSchema.js.map +1 -0
- 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 +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -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/abortUtils.d.ts +16 -0
- package/dist/reactor/abortUtils.d.ts.map +1 -0
- package/dist/reactor/abortUtils.js +26 -0
- package/dist/reactor/abortUtils.js.map +1 -0
- package/dist/reactor/applyScenePrompt.d.ts +75 -0
- package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
- package/dist/reactor/applyScenePrompt.js +60 -0
- package/dist/reactor/applyScenePrompt.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/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +10 -15
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/index.d.ts +4 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +7 -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/sceneEntry.d.ts +40 -6
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +63 -24
- package/dist/reactor/sceneEntry.js.map +1 -1
- 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 +42 -2
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +173 -4
- 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/timeFormat.d.ts +10 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +12 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +370 -0
- package/dist/toolSchemas.d.ts.map +1 -0
- package/dist/toolSchemas.js +182 -0
- package/dist/toolSchemas.js.map +1 -0
- package/dist/vision/VisionPublisher.d.ts +115 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -0
- package/dist/vision/VisionPublisher.js +475 -0
- package/dist/vision/VisionPublisher.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/credentials.d.ts +22 -0
- package/dist/vision/credentials.d.ts.map +1 -0
- package/dist/vision/credentials.js +34 -0
- package/dist/vision/credentials.js.map +1 -0
- package/dist/vision/index.d.ts +18 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +13 -0
- package/dist/vision/index.js.map +1 -0
- 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/vision/startVisionPublisher.d.ts +38 -0
- package/dist/vision/startVisionPublisher.d.ts.map +1 -0
- package/dist/vision/startVisionPublisher.js +44 -0
- package/dist/vision/startVisionPublisher.js.map +1 -0
- package/dist/vision/types.d.ts +95 -0
- package/dist/vision/types.d.ts.map +1 -0
- package/dist/vision/types.js +12 -0
- package/dist/vision/types.js.map +1 -0
- package/dist/vision/visionScheduler.d.ts +63 -0
- package/dist/vision/visionScheduler.d.ts.map +1 -0
- package/dist/vision/visionScheduler.js +67 -0
- package/dist/vision/visionScheduler.js.map +1 -0
- package/dist/websocket.d.ts +195 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +179 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +11 -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 +104 -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 +470 -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__/chat-auth.test.ts +91 -0
- package/src/__tests__/conversation/controller.test.ts +697 -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 +326 -0
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
- package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
- 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__/timeFormat.test.ts +22 -1
- package/src/__tests__/toolSchemas.test.ts +57 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket-vision.test.ts +265 -0
- package/src/__tests__/websocket.test.ts +213 -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 +310 -0
- package/src/api.ts +1890 -162
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +81 -0
- package/src/conversation/controller.ts +439 -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 +532 -0
- package/src/http.ts +72 -0
- package/src/index.ts +12 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/abortUtils.ts +22 -0
- package/src/reactor/applyScenePrompt.ts +136 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/heliosCommandDispatcher.ts +10 -18
- package/src/reactor/index.ts +7 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/sceneEntry.ts +104 -33
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +200 -4
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/timeFormat.ts +13 -0
- package/src/toolSchemas.ts +225 -0
- package/src/vision/VisionPublisher.ts +553 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
- package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
- package/src/vision/__tests__/visionScheduler.test.ts +149 -0
- package/src/vision/credentials.ts +39 -0
- package/src/vision/index.ts +44 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/vision/startVisionPublisher.ts +64 -0
- package/src/vision/types.ts +101 -0
- package/src/vision/visionScheduler.ts +102 -0
- package/src/websocket.ts +334 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `resolveEffectiveModel` — the capability auto-switch matrix (R2.1).
|
|
3
|
+
*
|
|
4
|
+
* The registry is a REAL `AdapterRegistry<ChatAdapterDescriptor>` built from a
|
|
5
|
+
* stubbed `listChatModels` (the existing chat-adapter test pattern) — no
|
|
6
|
+
* network. Capability facts come ONLY from that registry, proving the helper
|
|
7
|
+
* never hardcodes which models are vision-capable.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { loadChatAdapterRegistry } from '../../adapters';
|
|
11
|
+
import {
|
|
12
|
+
resolveEffectiveModel,
|
|
13
|
+
EffectiveModelReason,
|
|
14
|
+
} from '../../conversation';
|
|
15
|
+
import type { ApiClient, ChatModelInfo, ChatModelsResponse } from '../../api';
|
|
16
|
+
|
|
17
|
+
const sonnetVision: ChatModelInfo = {
|
|
18
|
+
id: 'anthropic.claude-sonnet',
|
|
19
|
+
name: 'claude-sonnet',
|
|
20
|
+
displayName: 'Claude Sonnet',
|
|
21
|
+
provider: 'bedrock',
|
|
22
|
+
contextWindow: 200_000,
|
|
23
|
+
maxOutputTokens: 8_192,
|
|
24
|
+
capabilities: ['vision', 'tools', 'thinking'],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const haikuTextOnly: ChatModelInfo = {
|
|
28
|
+
id: 'anthropic.claude-haiku',
|
|
29
|
+
name: 'claude-haiku',
|
|
30
|
+
displayName: 'Claude Haiku',
|
|
31
|
+
provider: 'bedrock',
|
|
32
|
+
contextWindow: 200_000,
|
|
33
|
+
maxOutputTokens: 4_096,
|
|
34
|
+
capabilities: ['tools'],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const ALL: ChatModelInfo[] = [haikuTextOnly, sonnetVision];
|
|
38
|
+
|
|
39
|
+
function stubClient(resp: ChatModelsResponse): Pick<ApiClient, 'listChatModels'> {
|
|
40
|
+
return { listChatModels: jest.fn(async () => resp) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function buildRegistry() {
|
|
44
|
+
return loadChatAdapterRegistry(
|
|
45
|
+
stubClient({ models: ALL, defaultModelId: 'anthropic.claude-sonnet' }),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('resolveEffectiveModel', () => {
|
|
50
|
+
it("returns 'bound' when the bound model already satisfies the needed caps", async () => {
|
|
51
|
+
const registry = await buildRegistry();
|
|
52
|
+
const result = resolveEffectiveModel({
|
|
53
|
+
boundModelId: 'anthropic.claude-sonnet',
|
|
54
|
+
needed: ['vision'],
|
|
55
|
+
registry,
|
|
56
|
+
});
|
|
57
|
+
expect(result.reason).toBe(EffectiveModelReason.BOUND);
|
|
58
|
+
expect(result.modelId).toBe('anthropic.claude-sonnet');
|
|
59
|
+
expect(result.switchedFrom).toBeUndefined();
|
|
60
|
+
expect(result.needed).toEqual(['vision']);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("returns 'bound' when no caps are needed (un-gated)", async () => {
|
|
64
|
+
const registry = await buildRegistry();
|
|
65
|
+
const result = resolveEffectiveModel({
|
|
66
|
+
boundModelId: 'anthropic.claude-haiku',
|
|
67
|
+
needed: [],
|
|
68
|
+
registry,
|
|
69
|
+
});
|
|
70
|
+
expect(result.reason).toBe(EffectiveModelReason.BOUND);
|
|
71
|
+
expect(result.modelId).toBe('anthropic.claude-haiku');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("returns 'auto_switch' with switchedFrom when bound lacks vision and no override", async () => {
|
|
75
|
+
const registry = await buildRegistry();
|
|
76
|
+
const result = resolveEffectiveModel({
|
|
77
|
+
boundModelId: 'anthropic.claude-haiku',
|
|
78
|
+
needed: ['vision'],
|
|
79
|
+
registry,
|
|
80
|
+
});
|
|
81
|
+
expect(result.reason).toBe(EffectiveModelReason.AUTO_SWITCH);
|
|
82
|
+
// Picked from the registry's vision-capable models — NOT hardcoded.
|
|
83
|
+
expect(result.modelId).toBe('anthropic.claude-sonnet');
|
|
84
|
+
expect(result.switchedFrom).toBe('anthropic.claude-haiku');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("returns 'override' when an explicit override is present (wins over auto-switch)", async () => {
|
|
88
|
+
const registry = await buildRegistry();
|
|
89
|
+
const result = resolveEffectiveModel({
|
|
90
|
+
boundModelId: 'anthropic.claude-haiku',
|
|
91
|
+
needed: ['vision'],
|
|
92
|
+
override: 'anthropic.claude-haiku',
|
|
93
|
+
registry,
|
|
94
|
+
});
|
|
95
|
+
expect(result.reason).toBe(EffectiveModelReason.OVERRIDE);
|
|
96
|
+
expect(result.modelId).toBe('anthropic.claude-haiku');
|
|
97
|
+
expect(result.switchedFrom).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('fails soft to bound when no registered model can satisfy the needed cap', async () => {
|
|
101
|
+
// A registry with ZERO vision models — the gap is a config state, not a
|
|
102
|
+
// crash; the helper keeps the bound model so the panel can surface it.
|
|
103
|
+
const registry = await loadChatAdapterRegistry(
|
|
104
|
+
stubClient({ models: [haikuTextOnly], defaultModelId: 'anthropic.claude-haiku' }),
|
|
105
|
+
);
|
|
106
|
+
const result = resolveEffectiveModel({
|
|
107
|
+
boundModelId: 'anthropic.claude-haiku',
|
|
108
|
+
needed: ['vision'],
|
|
109
|
+
registry,
|
|
110
|
+
});
|
|
111
|
+
expect(result.reason).toBe(EffectiveModelReason.BOUND);
|
|
112
|
+
expect(result.modelId).toBe('anthropic.claude-haiku');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('auto-switches to a model that satisfies EVERY needed cap (not just the first)', async () => {
|
|
116
|
+
// visionOnly has vision but NOT audio; multimodal has both. With
|
|
117
|
+
// needed: ['vision','audio'] the helper must pick multimodal — a vision-only
|
|
118
|
+
// candidate would leave the audio gap unresolved (codex regression).
|
|
119
|
+
const visionOnly: ChatModelInfo = {
|
|
120
|
+
...sonnetVision,
|
|
121
|
+
id: 'vision-only',
|
|
122
|
+
displayName: 'Vision Only',
|
|
123
|
+
capabilities: ['vision', 'tools'],
|
|
124
|
+
};
|
|
125
|
+
const multimodal: ChatModelInfo = {
|
|
126
|
+
...sonnetVision,
|
|
127
|
+
id: 'multimodal',
|
|
128
|
+
displayName: 'Multimodal',
|
|
129
|
+
capabilities: ['vision', 'audio', 'tools'],
|
|
130
|
+
};
|
|
131
|
+
const registry = await loadChatAdapterRegistry(
|
|
132
|
+
// visionOnly sorts before multimodal so a "first vision model" bug would
|
|
133
|
+
// pick the wrong one.
|
|
134
|
+
stubClient({ models: [haikuTextOnly, visionOnly, multimodal], defaultModelId: 'multimodal' }),
|
|
135
|
+
);
|
|
136
|
+
const result = resolveEffectiveModel({
|
|
137
|
+
boundModelId: 'anthropic.claude-haiku',
|
|
138
|
+
needed: ['vision', 'audio'],
|
|
139
|
+
registry,
|
|
140
|
+
});
|
|
141
|
+
expect(result.reason).toBe(EffectiveModelReason.AUTO_SWITCH);
|
|
142
|
+
expect(result.modelId).toBe('multimodal');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('fails soft to bound when no single model satisfies the full multi-cap set', async () => {
|
|
146
|
+
// vision-capable and audio-capable models exist, but NONE has both — the
|
|
147
|
+
// helper must NOT settle for a partial match.
|
|
148
|
+
const visionOnly: ChatModelInfo = {
|
|
149
|
+
...sonnetVision,
|
|
150
|
+
id: 'vision-only',
|
|
151
|
+
capabilities: ['vision', 'tools'],
|
|
152
|
+
};
|
|
153
|
+
const audioOnly: ChatModelInfo = {
|
|
154
|
+
...sonnetVision,
|
|
155
|
+
id: 'audio-only',
|
|
156
|
+
capabilities: ['audio', 'tools'],
|
|
157
|
+
};
|
|
158
|
+
const registry = await loadChatAdapterRegistry(
|
|
159
|
+
stubClient({ models: [visionOnly, audioOnly], defaultModelId: 'vision-only' }),
|
|
160
|
+
);
|
|
161
|
+
const result = resolveEffectiveModel({
|
|
162
|
+
boundModelId: 'vision-only',
|
|
163
|
+
needed: ['vision', 'audio'],
|
|
164
|
+
registry,
|
|
165
|
+
});
|
|
166
|
+
expect(result.reason).toBe(EffectiveModelReason.BOUND);
|
|
167
|
+
expect(result.modelId).toBe('vision-only');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless conformance harness (R7.3): a fake `PresenceAdapter` that records
|
|
3
|
+
* every call into an ordered array. The presenceBus test feeds the cue-chain
|
|
4
|
+
* fixture through `ConversationRuntime` + `presenceBus` and asserts the fake
|
|
5
|
+
* adapter received the EXACT call sequence a real renderer (React 2D face or a
|
|
6
|
+
* PlayCanvas 3D avatar) would — in plain node, no DOM, no Bedrock, no WS. Any
|
|
7
|
+
* engine that implements `PresenceAdapter` against this recorded sequence is
|
|
8
|
+
* drive-able by the runtime unchanged: that is the portability proof.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { PresenceAdapter } from '../../conversation/presence';
|
|
12
|
+
import type { RosterParticipant } from '../../conversation/types';
|
|
13
|
+
import type { VisemeSymbol } from '../../visemeScheduler';
|
|
14
|
+
|
|
15
|
+
/** One recorded adapter call, as a readable tuple-ish record. */
|
|
16
|
+
export type RecordedPresenceCall =
|
|
17
|
+
| { method: 'mount'; personaId: string }
|
|
18
|
+
| { method: 'unmount'; personaId: string }
|
|
19
|
+
| { method: 'setActiveParticipant'; personaId: string | null }
|
|
20
|
+
| { method: 'setSpeaking'; personaId: string; speaking: boolean }
|
|
21
|
+
| { method: 'applyViseme'; personaId: string; viseme: VisemeSymbol };
|
|
22
|
+
|
|
23
|
+
/** Fake recording renderer — the conformance harness. */
|
|
24
|
+
export class RecordingPresenceAdapter implements PresenceAdapter {
|
|
25
|
+
readonly calls: RecordedPresenceCall[] = [];
|
|
26
|
+
|
|
27
|
+
mount(participant: RosterParticipant): void {
|
|
28
|
+
this.calls.push({ method: 'mount', personaId: participant.personaId });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unmount(personaId: string): void {
|
|
32
|
+
this.calls.push({ method: 'unmount', personaId });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setActiveParticipant(personaId: string | null): void {
|
|
36
|
+
this.calls.push({ method: 'setActiveParticipant', personaId });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setSpeaking(personaId: string, speaking: boolean): void {
|
|
40
|
+
this.calls.push({ method: 'setSpeaking', personaId, speaking });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
applyViseme(personaId: string, viseme: VisemeSymbol): void {
|
|
44
|
+
this.calls.push({ method: 'applyViseme', personaId, viseme });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `conversation/presenceBus.ts` (R7.3) — the renderer-agnostic glue
|
|
3
|
+
* between `ConversationRuntime` transitions and `PresenceAdapter` calls.
|
|
4
|
+
*
|
|
5
|
+
* THE PORTABILITY PROOF: the 3-participant cue-chain fixture is fed through
|
|
6
|
+
* the real runtime + bus into the fake recording adapter (headlessRenderer.ts)
|
|
7
|
+
* and the EXACT call sequence a real renderer would receive is asserted — in
|
|
8
|
+
* plain node, no DOM, no React, no Bedrock, no WS. A PlayCanvas host that
|
|
9
|
+
* implements `PresenceAdapter` is driven by this identical sequence.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { ChatWsEvent } from '../../websocket';
|
|
13
|
+
import { ConversationRuntime } from '../../conversation/runtime';
|
|
14
|
+
import { bindPresence } from '../../conversation/presenceBus';
|
|
15
|
+
import { presenceKindHasStage } from '../../conversation/presence';
|
|
16
|
+
import { PresenceKind } from '../../conversation/participant';
|
|
17
|
+
import type { RosterParticipant } from '../../conversation/types';
|
|
18
|
+
import { RecordingPresenceAdapter } from './headlessRenderer';
|
|
19
|
+
|
|
20
|
+
const SID = 'adv-session-1';
|
|
21
|
+
|
|
22
|
+
const DM: RosterParticipant = {
|
|
23
|
+
personaId: 'p-dm',
|
|
24
|
+
isDm: true,
|
|
25
|
+
displayName: 'The Narrator',
|
|
26
|
+
presence: PresenceKind.PRESENCE_FACE_2D,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const ARIA: RosterParticipant = {
|
|
30
|
+
personaId: 'p-aria',
|
|
31
|
+
isDm: false,
|
|
32
|
+
displayName: 'Aria',
|
|
33
|
+
entityId: 'e-aria',
|
|
34
|
+
presence: PresenceKind.PRESENCE_FACE_2D,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const BRYN: RosterParticipant = {
|
|
38
|
+
personaId: 'p-bryn',
|
|
39
|
+
isDm: false,
|
|
40
|
+
displayName: 'Bryn',
|
|
41
|
+
entityId: 'e-bryn',
|
|
42
|
+
presence: PresenceKind.PRESENCE_AVATAR_3D,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Text-only seat: must receive NO presence calls beyond mount/unmount. */
|
|
46
|
+
const SCRIBE: RosterParticipant = {
|
|
47
|
+
personaId: 'p-scribe',
|
|
48
|
+
isDm: false,
|
|
49
|
+
displayName: 'Scribe',
|
|
50
|
+
presence: PresenceKind.PRESENCE_NONE,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function turnChanged(personaId: string): ChatWsEvent {
|
|
54
|
+
return { type: 'turn_changed', personaId };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('presenceKindHasStage', () => {
|
|
58
|
+
it('is false only for PRESENCE_NONE', () => {
|
|
59
|
+
expect(presenceKindHasStage(PresenceKind.PRESENCE_NONE)).toBe(false);
|
|
60
|
+
expect(presenceKindHasStage(PresenceKind.PRESENCE_FACE_2D)).toBe(true);
|
|
61
|
+
expect(presenceKindHasStage(PresenceKind.PRESENCE_AVATAR_3D)).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('presenceBus — 3-participant cue-chain conformance (the portability proof)', () => {
|
|
66
|
+
it('drives the fake adapter with the exact call sequence a real renderer would receive', () => {
|
|
67
|
+
const rt = new ConversationRuntime({
|
|
68
|
+
boundPersonaId: DM.personaId,
|
|
69
|
+
adventureSessionId: SID,
|
|
70
|
+
participants: [DM, ARIA, BRYN],
|
|
71
|
+
});
|
|
72
|
+
const adapter = new RecordingPresenceAdapter();
|
|
73
|
+
const binding = bindPresence(rt, adapter);
|
|
74
|
+
|
|
75
|
+
// Cue chain: DM hands the turn to Aria, Aria to Bryn, Bryn back to the DM.
|
|
76
|
+
rt.applyFrame(turnChanged(ARIA.personaId));
|
|
77
|
+
rt.applyFrame(turnChanged(BRYN.personaId));
|
|
78
|
+
rt.applyFrame(turnChanged(DM.personaId));
|
|
79
|
+
binding.dispose();
|
|
80
|
+
|
|
81
|
+
expect(adapter.calls).toEqual([
|
|
82
|
+
// bind: mount the full roster, then stage the initial speaker.
|
|
83
|
+
{ method: 'mount', personaId: 'p-dm' },
|
|
84
|
+
{ method: 'mount', personaId: 'p-aria' },
|
|
85
|
+
{ method: 'mount', personaId: 'p-bryn' },
|
|
86
|
+
{ method: 'setActiveParticipant', personaId: 'p-dm' },
|
|
87
|
+
{ method: 'setSpeaking', personaId: 'p-dm', speaking: true },
|
|
88
|
+
// turn_changed → Aria
|
|
89
|
+
{ method: 'setActiveParticipant', personaId: 'p-aria' },
|
|
90
|
+
{ method: 'setSpeaking', personaId: 'p-dm', speaking: false },
|
|
91
|
+
{ method: 'setSpeaking', personaId: 'p-aria', speaking: true },
|
|
92
|
+
// turn_changed → Bryn
|
|
93
|
+
{ method: 'setActiveParticipant', personaId: 'p-bryn' },
|
|
94
|
+
{ method: 'setSpeaking', personaId: 'p-aria', speaking: false },
|
|
95
|
+
{ method: 'setSpeaking', personaId: 'p-bryn', speaking: true },
|
|
96
|
+
// turn_changed → back to the DM
|
|
97
|
+
{ method: 'setActiveParticipant', personaId: 'p-dm' },
|
|
98
|
+
{ method: 'setSpeaking', personaId: 'p-bryn', speaking: false },
|
|
99
|
+
{ method: 'setSpeaking', personaId: 'p-dm', speaking: true },
|
|
100
|
+
// dispose: unmount the full roster.
|
|
101
|
+
{ method: 'unmount', personaId: 'p-dm' },
|
|
102
|
+
{ method: 'unmount', personaId: 'p-aria' },
|
|
103
|
+
{ method: 'unmount', personaId: 'p-bryn' },
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('clears speaking and stages null on a host releaseTurn (R7.2 seam)', () => {
|
|
108
|
+
const rt = new ConversationRuntime({
|
|
109
|
+
boundPersonaId: DM.personaId,
|
|
110
|
+
adventureSessionId: SID,
|
|
111
|
+
participants: [DM, ARIA],
|
|
112
|
+
});
|
|
113
|
+
const adapter = new RecordingPresenceAdapter();
|
|
114
|
+
bindPresence(rt, adapter);
|
|
115
|
+
rt.applyFrame(turnChanged(ARIA.personaId));
|
|
116
|
+
adapter.calls.length = 0;
|
|
117
|
+
|
|
118
|
+
rt.releaseTurn(ARIA.personaId);
|
|
119
|
+
|
|
120
|
+
expect(adapter.calls).toEqual([
|
|
121
|
+
{ method: 'setActiveParticipant', personaId: null },
|
|
122
|
+
{ method: 'setSpeaking', personaId: 'p-aria', speaking: false },
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('presenceBus — land-dark single speaker (ordinary chat / M9 single-DM)', () => {
|
|
128
|
+
it('produces exactly one mount + one setActiveParticipant and zero turn-driven swaps', () => {
|
|
129
|
+
// No adventureSessionId ⇒ the turnChangedSpeakerId gate blocks every swap.
|
|
130
|
+
const rt = new ConversationRuntime({
|
|
131
|
+
boundPersonaId: DM.personaId,
|
|
132
|
+
participants: [DM],
|
|
133
|
+
});
|
|
134
|
+
const adapter = new RecordingPresenceAdapter();
|
|
135
|
+
bindPresence(rt, adapter);
|
|
136
|
+
|
|
137
|
+
// A stray turn_changed (no active adventure) plus an ordinary stream.
|
|
138
|
+
rt.applyFrame(turnChanged(ARIA.personaId));
|
|
139
|
+
const frames: ChatWsEvent[] = [
|
|
140
|
+
{ type: 'token', content: 'Hello' },
|
|
141
|
+
{ type: 'token', content: ' world' },
|
|
142
|
+
{ type: 'done' },
|
|
143
|
+
];
|
|
144
|
+
for (const f of frames) rt.applyFrame(f);
|
|
145
|
+
|
|
146
|
+
expect(adapter.calls.filter((c) => c.method === 'mount')).toHaveLength(1);
|
|
147
|
+
expect(adapter.calls.filter((c) => c.method === 'setActiveParticipant')).toEqual([
|
|
148
|
+
{ method: 'setActiveParticipant', personaId: 'p-dm' },
|
|
149
|
+
]);
|
|
150
|
+
// The lone speaker never stops speaking and nobody else ever starts.
|
|
151
|
+
expect(adapter.calls.filter((c) => c.method === 'setSpeaking')).toEqual([
|
|
152
|
+
{ method: 'setSpeaking', personaId: 'p-dm', speaking: true },
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('presenceBus — PRESENCE_NONE gating (text-only seats)', () => {
|
|
158
|
+
it("a 'none' participant receives no presence calls beyond mount/unmount", () => {
|
|
159
|
+
const rt = new ConversationRuntime({
|
|
160
|
+
boundPersonaId: SCRIBE.personaId,
|
|
161
|
+
adventureSessionId: SID,
|
|
162
|
+
participants: [SCRIBE, ARIA],
|
|
163
|
+
});
|
|
164
|
+
const adapter = new RecordingPresenceAdapter();
|
|
165
|
+
const binding = bindPresence(rt, adapter);
|
|
166
|
+
|
|
167
|
+
// Scribe holds the turn at bind, hands it to Aria, then gets it back.
|
|
168
|
+
rt.applyFrame(turnChanged(ARIA.personaId));
|
|
169
|
+
rt.applyFrame(turnChanged(SCRIBE.personaId));
|
|
170
|
+
binding.dispose();
|
|
171
|
+
|
|
172
|
+
const scribeCalls = adapter.calls.filter(
|
|
173
|
+
(c) => 'personaId' in c && c.personaId === SCRIBE.personaId,
|
|
174
|
+
);
|
|
175
|
+
expect(scribeCalls).toEqual([
|
|
176
|
+
{ method: 'mount', personaId: 'p-scribe' },
|
|
177
|
+
{ method: 'unmount', personaId: 'p-scribe' },
|
|
178
|
+
]);
|
|
179
|
+
// Aria still gets full staging when she takes / yields the turn.
|
|
180
|
+
expect(adapter.calls).toContainEqual({
|
|
181
|
+
method: 'setSpeaking',
|
|
182
|
+
personaId: 'p-aria',
|
|
183
|
+
speaking: true,
|
|
184
|
+
});
|
|
185
|
+
expect(adapter.calls).toContainEqual({
|
|
186
|
+
method: 'setSpeaking',
|
|
187
|
+
personaId: 'p-aria',
|
|
188
|
+
speaking: false,
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('applyViseme passes through for staged participants and is dropped for none-kind', () => {
|
|
193
|
+
const rt = new ConversationRuntime({
|
|
194
|
+
adventureSessionId: SID,
|
|
195
|
+
participants: [ARIA, SCRIBE],
|
|
196
|
+
});
|
|
197
|
+
const adapter = new RecordingPresenceAdapter();
|
|
198
|
+
const binding = bindPresence(rt, adapter);
|
|
199
|
+
adapter.calls.length = 0;
|
|
200
|
+
|
|
201
|
+
binding.applyViseme(ARIA.personaId, 'aei');
|
|
202
|
+
binding.applyViseme(SCRIBE.personaId, 'aei'); // dropped: no stage
|
|
203
|
+
binding.applyViseme('p-unknown', 'aei'); // dropped: not in the roster
|
|
204
|
+
|
|
205
|
+
expect(adapter.calls).toEqual([
|
|
206
|
+
{ method: 'applyViseme', personaId: 'p-aria', viseme: 'aei' },
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('presenceBus — lifecycle hygiene', () => {
|
|
212
|
+
it('dispose unsubscribes: later transitions produce no further adapter calls', () => {
|
|
213
|
+
const rt = new ConversationRuntime({
|
|
214
|
+
boundPersonaId: DM.personaId,
|
|
215
|
+
adventureSessionId: SID,
|
|
216
|
+
participants: [DM, ARIA],
|
|
217
|
+
});
|
|
218
|
+
const adapter = new RecordingPresenceAdapter();
|
|
219
|
+
const binding = bindPresence(rt, adapter);
|
|
220
|
+
binding.dispose();
|
|
221
|
+
adapter.calls.length = 0;
|
|
222
|
+
|
|
223
|
+
rt.applyFrame(turnChanged(ARIA.personaId));
|
|
224
|
+
expect(adapter.calls).toEqual([]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('dispose is idempotent', () => {
|
|
228
|
+
const rt = new ConversationRuntime({ participants: [DM] });
|
|
229
|
+
const adapter = new RecordingPresenceAdapter();
|
|
230
|
+
const binding = bindPresence(rt, adapter);
|
|
231
|
+
binding.dispose();
|
|
232
|
+
adapter.calls.length = 0;
|
|
233
|
+
binding.dispose();
|
|
234
|
+
expect(adapter.calls).toEqual([]);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the `PresenceRendererRegistry` (R2.1).
|
|
3
|
+
*
|
|
4
|
+
* Asserts the named-registry contract it inherits from the adapter registry:
|
|
5
|
+
* register/resolve/has, fail-loud on duplicate registration, and the fail-soft
|
|
6
|
+
* `PRESENCE_NONE` no-op for an unregistered kind (what lets the reserved
|
|
7
|
+
* `PRESENCE_AVATAR_3D` stub render nothing instead of throwing).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
PresenceRendererRegistry,
|
|
12
|
+
PresenceKind,
|
|
13
|
+
type PresenceHandle,
|
|
14
|
+
} from '../../conversation';
|
|
15
|
+
|
|
16
|
+
/** A spying handle factory so we can assert which factory `resolve` returned. */
|
|
17
|
+
function makeFactory(tag: string): { factory: () => PresenceHandle; mounted: string[] } {
|
|
18
|
+
const mounted: string[] = [];
|
|
19
|
+
const factory = (): PresenceHandle => ({
|
|
20
|
+
mount: () => mounted.push(tag),
|
|
21
|
+
update: () => {},
|
|
22
|
+
destroy: () => {},
|
|
23
|
+
});
|
|
24
|
+
return { factory, mounted };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('PresenceRendererRegistry', () => {
|
|
28
|
+
it('registers and resolves a factory for a kind', () => {
|
|
29
|
+
const registry = new PresenceRendererRegistry();
|
|
30
|
+
const { factory, mounted } = makeFactory('face');
|
|
31
|
+
registry.register(PresenceKind.PRESENCE_FACE_2D, factory);
|
|
32
|
+
|
|
33
|
+
expect(registry.has(PresenceKind.PRESENCE_FACE_2D)).toBe(true);
|
|
34
|
+
const resolved = registry.resolve(PresenceKind.PRESENCE_FACE_2D);
|
|
35
|
+
resolved().mount(null);
|
|
36
|
+
expect(mounted).toEqual(['face']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('has() is false for an unregistered kind', () => {
|
|
40
|
+
const registry = new PresenceRendererRegistry();
|
|
41
|
+
expect(registry.has(PresenceKind.PRESENCE_AVATAR_3D)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('throws on duplicate registration of the same kind (fail-loud)', () => {
|
|
45
|
+
const registry = new PresenceRendererRegistry();
|
|
46
|
+
const { factory } = makeFactory('first');
|
|
47
|
+
registry.register(PresenceKind.PRESENCE_FACE_2D, factory);
|
|
48
|
+
expect(() =>
|
|
49
|
+
registry.register(PresenceKind.PRESENCE_FACE_2D, makeFactory('second').factory),
|
|
50
|
+
).toThrow(/duplicate registration/i);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('resolves the PRESENCE_NONE no-op for an unregistered kind (fail-soft stub)', () => {
|
|
54
|
+
const registry = new PresenceRendererRegistry();
|
|
55
|
+
// The reserved 3D kind is unregistered — resolve must hand back a no-op
|
|
56
|
+
// handle whose lifecycle methods are safe to call and do nothing.
|
|
57
|
+
const handle = registry.resolve(PresenceKind.PRESENCE_AVATAR_3D)();
|
|
58
|
+
expect(() => {
|
|
59
|
+
handle.mount(null);
|
|
60
|
+
handle.update(null);
|
|
61
|
+
handle.destroy();
|
|
62
|
+
}).not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('the no-op factory is independent of any registered factory', () => {
|
|
66
|
+
const registry = new PresenceRendererRegistry();
|
|
67
|
+
const { factory, mounted } = makeFactory('face');
|
|
68
|
+
registry.register(PresenceKind.PRESENCE_FACE_2D, factory);
|
|
69
|
+
// Resolving an unregistered kind must NOT invoke the registered one.
|
|
70
|
+
registry.resolve(PresenceKind.PRESENCE_NONE)().mount(null);
|
|
71
|
+
expect(mounted).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `conversation/roster.ts` (R7.1) — the party/roster helpers lifted
|
|
3
|
+
* verbatim from `web/app/chat-ws/adventureMode.ts`. Assertions ported 1:1 from
|
|
4
|
+
* `web/app/chat-ws/__tests__/adventureMode.test.tsx` for regression parity.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
isAdventureMutationTool,
|
|
9
|
+
shouldRefreshAdventureRail,
|
|
10
|
+
ADVENTURE_MUTATION_TOOLS,
|
|
11
|
+
filterPartyCandidates,
|
|
12
|
+
type PartyCandidatePersona,
|
|
13
|
+
} from '../../conversation/roster';
|
|
14
|
+
|
|
15
|
+
describe('isAdventureMutationTool', () => {
|
|
16
|
+
it('returns true for each DM mutation tool', () => {
|
|
17
|
+
expect(isAdventureMutationTool('advance_story')).toBe(true);
|
|
18
|
+
expect(isAdventureMutationTool('set_flag')).toBe(true);
|
|
19
|
+
expect(isAdventureMutationTool('clear_flag')).toBe(true);
|
|
20
|
+
expect(isAdventureMutationTool('update_inventory')).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('returns false for read-only / unrelated tools', () => {
|
|
24
|
+
expect(isAdventureMutationTool('entity_timeline')).toBe(false);
|
|
25
|
+
expect(isAdventureMutationTool('speaker_dialog')).toBe(false);
|
|
26
|
+
expect(isAdventureMutationTool('semantic_search')).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('returns false for undefined / empty (no tool on the message)', () => {
|
|
30
|
+
expect(isAdventureMutationTool(undefined)).toBe(false);
|
|
31
|
+
expect(isAdventureMutationTool('')).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('is backed by exactly the four DM mutation tool names', () => {
|
|
35
|
+
// Guards against drift if someone edits the constant set: the rail-refresh
|
|
36
|
+
// trigger must stay scoped to state-mutating tools only.
|
|
37
|
+
expect([...ADVENTURE_MUTATION_TOOLS].sort()).toEqual(
|
|
38
|
+
['advance_story', 'clear_flag', 'set_flag', 'update_inventory'].sort(),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('shouldRefreshAdventureRail (land-dark gate)', () => {
|
|
44
|
+
it('is false for EVERY tool when there is no active adventure (land-dark)', () => {
|
|
45
|
+
for (const tool of [...ADVENTURE_MUTATION_TOOLS, 'entity_timeline', '']) {
|
|
46
|
+
expect(shouldRefreshAdventureRail(undefined, tool)).toBe(false);
|
|
47
|
+
}
|
|
48
|
+
expect(shouldRefreshAdventureRail(undefined, 'advance_story')).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('is true only for a mutation tool while an adventure is active', () => {
|
|
52
|
+
expect(shouldRefreshAdventureRail('adv-1', 'advance_story')).toBe(true);
|
|
53
|
+
expect(shouldRefreshAdventureRail('adv-1', 'set_flag')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('is false for a read-only / unrelated tool even with an active adventure', () => {
|
|
57
|
+
expect(shouldRefreshAdventureRail('adv-1', 'entity_timeline')).toBe(false);
|
|
58
|
+
expect(shouldRefreshAdventureRail('adv-1', undefined)).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('filterPartyCandidates (M10 Phase 9b)', () => {
|
|
63
|
+
function p(over: Partial<PartyCandidatePersona> = {}): PartyCandidatePersona {
|
|
64
|
+
return { persona_id: 'p-x', status: 'approved', entity_id: 'e-x', is_dungeon_master: false, ...over };
|
|
65
|
+
}
|
|
66
|
+
const dm = p({ persona_id: 'p-dm', is_dungeon_master: true, entity_id: null });
|
|
67
|
+
const aria = p({ persona_id: 'p-aria', entity_id: 'e-aria' });
|
|
68
|
+
const borin = p({ persona_id: 'p-borin', entity_id: 'e-borin' });
|
|
69
|
+
const unbound = p({ persona_id: 'p-unbound', entity_id: null });
|
|
70
|
+
const pending = p({ persona_id: 'p-pending', entity_id: 'e-pending', status: 'pending' });
|
|
71
|
+
const offStory = p({ persona_id: 'p-offstory', entity_id: 'e-elsewhere' });
|
|
72
|
+
const all = [dm, aria, borin, unbound, pending, offStory];
|
|
73
|
+
|
|
74
|
+
it('keeps only approved, character-bound, in-story, non-DM, non-excluded personas', () => {
|
|
75
|
+
const storyChars = new Set(['e-aria', 'e-borin', 'e-cedric']);
|
|
76
|
+
const result = filterPartyCandidates(all, ['p-dm'], storyChars);
|
|
77
|
+
expect(result.map((x) => x.persona_id)).toEqual(['p-aria', 'p-borin']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('excludes personas already in the party / the DM via excludePersonaIds', () => {
|
|
81
|
+
const storyChars = new Set(['e-aria', 'e-borin']);
|
|
82
|
+
const result = filterPartyCandidates(all, ['p-dm', 'p-borin'], storyChars);
|
|
83
|
+
expect(result.map((x) => x.persona_id)).toEqual(['p-aria']);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('relaxes the story-binding check to ANY bound persona when the char set is null (fallback)', () => {
|
|
87
|
+
const result = filterPartyCandidates(all, ['p-dm'], null);
|
|
88
|
+
expect(result.map((x) => x.persona_id)).toEqual(['p-aria', 'p-borin', 'p-offstory']);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('returns nothing when the story genuinely has no characters (empty set, not null)', () => {
|
|
92
|
+
expect(filterPartyCandidates(all, ['p-dm'], new Set())).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('treats a missing is_dungeon_master as not-a-DM (defensive superset)', () => {
|
|
96
|
+
const legacy = p({ persona_id: 'p-legacy', entity_id: 'e-legacy', is_dungeon_master: undefined });
|
|
97
|
+
const result = filterPartyCandidates([legacy], [], new Set(['e-legacy']));
|
|
98
|
+
expect(result.map((x) => x.persona_id)).toEqual(['p-legacy']);
|
|
99
|
+
});
|
|
100
|
+
});
|