@vellumai/assistant 0.11.9-dev.202609071714.989d877 → 0.11.9-dev.202609080319.eb4f1b0
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/package.json +1 -1
- package/src/__tests__/conversation-surfaces-point-at-budget.test.ts +38 -1
- package/src/__tests__/conversation-surfaces-point-at-capability.test.ts +161 -0
- package/src/__tests__/host-proxy-interface.test.ts +15 -0
- package/src/__tests__/host-proxy-preactivation.test.ts +60 -1
- package/src/calls/__tests__/voice-session-bridge.test.ts +166 -0
- package/src/calls/voice-session-bridge.ts +91 -0
- package/src/channels/types.ts +11 -2
- package/src/config/bundled-skills/screen-annotation/SKILL.md +5 -0
- package/src/daemon/__tests__/turn-actor.test.ts +68 -0
- package/src/daemon/conversation-messaging.ts +3 -2
- package/src/daemon/conversation-surfaces.ts +12 -56
- package/src/daemon/conversation.ts +36 -6
- package/src/daemon/host-cu-proxy.ts +9 -52
- package/src/daemon/host-cu-target.ts +139 -0
- package/src/daemon/host-proxy-preactivation.ts +29 -2
- package/src/daemon/turn-actor.ts +46 -0
- package/src/live-voice/__tests__/live-voice-session-guardian.test.ts +127 -0
- package/src/live-voice/live-voice-connection.ts +14 -1
- package/src/live-voice/live-voice-session-manager.ts +10 -1
- package/src/live-voice/live-voice-session.ts +119 -28
- package/src/runtime/auth/same-actor.ts +4 -3
- package/src/runtime/http-server.ts +23 -0
- package/src/runtime/routes/events-routes.ts +4 -0
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { describe, expect, mock, test } from "bun:test";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
2
|
|
|
3
3
|
import { POINT_AT_PROXY_TOOL } from "../tools/computer-use/skill-proxy-bridge.js";
|
|
4
|
+
import { clearHubClients, registerHubClient } from "./helpers/hub-clients.js";
|
|
4
5
|
import { asConversation } from "./helpers/mock-conversation.js";
|
|
5
6
|
|
|
6
7
|
const { surfaceProxyResolver } =
|
|
7
8
|
await import("../daemon/conversation-surfaces.js");
|
|
9
|
+
const { assistantEventHub } = await import("../runtime/assistant-event-hub.js");
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* A CU proxy that records what it was asked to account for. `recordAction` is
|
|
@@ -27,11 +29,29 @@ function proxyDouble() {
|
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
const ACTOR = "actor-1";
|
|
33
|
+
|
|
30
34
|
const context = (proxy: unknown) =>
|
|
31
35
|
asConversation({
|
|
32
36
|
conversationId: "conv-1",
|
|
33
37
|
hostCuProxy: proxy as never,
|
|
38
|
+
currentTurnSourceActorPrincipalId: ACTOR,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A client that can actually draw. Pointing resolves on `host_cu_annotate`
|
|
43
|
+
* and refuses outright when nothing holds it, so without this the requests
|
|
44
|
+
* below would never reach the proxy and the budget would go untested.
|
|
45
|
+
*/
|
|
46
|
+
function withAnnotationClient(): void {
|
|
47
|
+
registerHubClient({
|
|
48
|
+
hub: assistantEventHub,
|
|
49
|
+
clientId: "mac",
|
|
50
|
+
interfaceId: "macos",
|
|
51
|
+
capabilities: ["host_cu", "host_cu_annotate"],
|
|
52
|
+
actorPrincipalId: ACTOR,
|
|
34
53
|
});
|
|
54
|
+
}
|
|
35
55
|
|
|
36
56
|
/**
|
|
37
57
|
* Pointing at the screen drives nothing: the user does the acting, and a
|
|
@@ -40,6 +60,15 @@ const context = (proxy: unknown) =>
|
|
|
40
60
|
* instruction to call `computer_use_done`.
|
|
41
61
|
*/
|
|
42
62
|
describe("the computer-use step budget", () => {
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
clearHubClients(assistantEventHub);
|
|
65
|
+
withAnnotationClient();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
clearHubClients(assistantEventHub);
|
|
70
|
+
});
|
|
71
|
+
|
|
43
72
|
test("is not spent by pointing at the screen", async () => {
|
|
44
73
|
const { proxy, recordAction, request } = proxyDouble();
|
|
45
74
|
|
|
@@ -89,12 +118,20 @@ describe("the computer-use step budget", () => {
|
|
|
89
118
|
);
|
|
90
119
|
expect((spent as { content?: string }).content).toContain("Step limit");
|
|
91
120
|
|
|
121
|
+
// The actor is passed so resolution finds the annotation client and the
|
|
122
|
+
// step limit stays the only thing that could refuse this. Without it the
|
|
123
|
+
// request is turned back for having no client to draw on, which would
|
|
124
|
+
// pass this assertion for entirely the wrong reason.
|
|
92
125
|
const cleared = await settle(
|
|
93
126
|
proxy.request(
|
|
94
127
|
POINT_AT_PROXY_TOOL,
|
|
95
128
|
{ marks: [] },
|
|
96
129
|
"conv-1",
|
|
97
130
|
proxy.stepCount,
|
|
131
|
+
undefined,
|
|
132
|
+
undefined,
|
|
133
|
+
undefined,
|
|
134
|
+
ACTOR,
|
|
98
135
|
),
|
|
99
136
|
);
|
|
100
137
|
expect(cleared).toBe(pending);
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which capability answers a point-at request.
|
|
3
|
+
*
|
|
4
|
+
* Pointing rides the `computer_use_` wire so it reaches the same proxy as an
|
|
5
|
+
* action, but only a client that draws the overlay can serve it. Resolving it
|
|
6
|
+
* as plain `host_cu` would call a lone annotation-capable client ambiguous
|
|
7
|
+
* against a helper-backed one that could never have answered, and would
|
|
8
|
+
* accept an explicit helper target and forward it an action its helper does
|
|
9
|
+
* not have.
|
|
10
|
+
*/
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
12
|
+
|
|
13
|
+
import { POINT_AT_PROXY_TOOL } from "../tools/computer-use/skill-proxy-bridge.js";
|
|
14
|
+
import { clearHubClients, registerHubClient } from "./helpers/hub-clients.js";
|
|
15
|
+
import { asConversation } from "./helpers/mock-conversation.js";
|
|
16
|
+
|
|
17
|
+
const { surfaceProxyResolver } =
|
|
18
|
+
await import("../daemon/conversation-surfaces.js");
|
|
19
|
+
const { assistantEventHub } = await import("../runtime/assistant-event-hub.js");
|
|
20
|
+
|
|
21
|
+
const ACTOR = "actor-1";
|
|
22
|
+
|
|
23
|
+
/** A proxy that answers, so resolution is the only thing under test. */
|
|
24
|
+
function proxyDouble() {
|
|
25
|
+
const request = mock(async () => ({ content: "ok", isError: false }));
|
|
26
|
+
return {
|
|
27
|
+
request,
|
|
28
|
+
proxy: {
|
|
29
|
+
isAvailable: () => true,
|
|
30
|
+
recordAction: () => {},
|
|
31
|
+
request,
|
|
32
|
+
reset: () => {},
|
|
33
|
+
stepCount: 0,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const context = (proxy: unknown) =>
|
|
39
|
+
asConversation({
|
|
40
|
+
conversationId: "conv-1",
|
|
41
|
+
hostCuProxy: proxy as never,
|
|
42
|
+
currentTurnSourceActorPrincipalId: ACTOR,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const MARKS = { marks: [{ x: 0.1, y: 0.1, width: 0.1, height: 0.1 }] };
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
clearHubClients(assistantEventHub);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
clearHubClients(assistantEventHub);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("resolving a point-at request", () => {
|
|
56
|
+
/**
|
|
57
|
+
* The case Codex named: one client can draw and one cannot, and selecting on
|
|
58
|
+
* the transport makes that pair ambiguous even though only one answer was
|
|
59
|
+
* ever possible.
|
|
60
|
+
*/
|
|
61
|
+
test("is not made ambiguous by a client that cannot draw", async () => {
|
|
62
|
+
const { proxy, request } = proxyDouble();
|
|
63
|
+
registerHubClient({
|
|
64
|
+
hub: assistantEventHub,
|
|
65
|
+
clientId: "mac",
|
|
66
|
+
interfaceId: "macos",
|
|
67
|
+
capabilities: ["host_cu", "host_cu_annotate"],
|
|
68
|
+
actorPrincipalId: ACTOR,
|
|
69
|
+
});
|
|
70
|
+
registerHubClient({
|
|
71
|
+
hub: assistantEventHub,
|
|
72
|
+
clientId: "win",
|
|
73
|
+
interfaceId: "windows",
|
|
74
|
+
capabilities: ["host_cu"],
|
|
75
|
+
actorPrincipalId: ACTOR,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const result = await surfaceProxyResolver(
|
|
79
|
+
context(proxy),
|
|
80
|
+
POINT_AT_PROXY_TOOL,
|
|
81
|
+
MARKS,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(result.isError).toBeFalsy();
|
|
85
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The other half: an explicit target that cannot draw is refused here rather
|
|
90
|
+
* than forwarded to a helper with no such action.
|
|
91
|
+
*/
|
|
92
|
+
test("refuses an explicit target that cannot draw", async () => {
|
|
93
|
+
const { proxy, request } = proxyDouble();
|
|
94
|
+
registerHubClient({
|
|
95
|
+
hub: assistantEventHub,
|
|
96
|
+
clientId: "win",
|
|
97
|
+
interfaceId: "windows",
|
|
98
|
+
capabilities: ["host_cu"],
|
|
99
|
+
actorPrincipalId: ACTOR,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const result = await surfaceProxyResolver(
|
|
103
|
+
context(proxy),
|
|
104
|
+
POINT_AT_PROXY_TOOL,
|
|
105
|
+
{ ...MARKS, target_client_id: "win" },
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(result.isError).toBe(true);
|
|
109
|
+
expect(result.content).toContain("host_cu_annotate");
|
|
110
|
+
expect(request).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The annotation-capable client went away after the skill was already on the
|
|
115
|
+
* surface. Nothing left can draw, so the request is refused rather than
|
|
116
|
+
* broadcast: an untargeted point-at would otherwise be handed to whatever
|
|
117
|
+
* host_cu client was listening, which is the mis-routing this capability
|
|
118
|
+
* exists to prevent.
|
|
119
|
+
*/
|
|
120
|
+
test("refuses rather than broadcasting when nothing can draw", async () => {
|
|
121
|
+
const { proxy, request } = proxyDouble();
|
|
122
|
+
registerHubClient({
|
|
123
|
+
hub: assistantEventHub,
|
|
124
|
+
clientId: "win",
|
|
125
|
+
interfaceId: "windows",
|
|
126
|
+
capabilities: ["host_cu"],
|
|
127
|
+
actorPrincipalId: ACTOR,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const result = await surfaceProxyResolver(
|
|
131
|
+
context(proxy),
|
|
132
|
+
POINT_AT_PROXY_TOOL,
|
|
133
|
+
MARKS,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(result.isError).toBe(true);
|
|
137
|
+
expect(result.content).toContain("host_cu_annotate");
|
|
138
|
+
expect(request).not.toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/** An ordinary action still resolves on the transport it always did. */
|
|
142
|
+
test("leaves an ordinary computer-use action on host_cu", async () => {
|
|
143
|
+
const { proxy, request } = proxyDouble();
|
|
144
|
+
registerHubClient({
|
|
145
|
+
hub: assistantEventHub,
|
|
146
|
+
clientId: "win",
|
|
147
|
+
interfaceId: "windows",
|
|
148
|
+
capabilities: ["host_cu"],
|
|
149
|
+
actorPrincipalId: ACTOR,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const result = await surfaceProxyResolver(
|
|
153
|
+
context(proxy),
|
|
154
|
+
"computer_use_click",
|
|
155
|
+
{ x: 10, y: 10 },
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(result.isError).toBeFalsy();
|
|
159
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -51,6 +51,21 @@ describe("supportsHostProxy (runtime)", () => {
|
|
|
51
51
|
expect(supportsHostProxy("macos", "host_browser")).toBe(true);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The marks are drawn in a window the client opens for itself. Windows and
|
|
56
|
+
* Linux forward a CU request to a native helper whose action set has no
|
|
57
|
+
* such thing, so offering it there is offering a tool that cannot succeed.
|
|
58
|
+
*/
|
|
59
|
+
test("capability form grants screen annotation to macOS alone", () => {
|
|
60
|
+
expect(supportsHostProxy("macos", "host_cu_annotate")).toBe(true);
|
|
61
|
+
expect(supportsHostProxy("windows", "host_cu_annotate")).toBe(false);
|
|
62
|
+
expect(supportsHostProxy("linux", "host_cu_annotate")).toBe(false);
|
|
63
|
+
expect(supportsHostProxy("web", "host_cu_annotate")).toBe(false);
|
|
64
|
+
// The transport it rides is offered to all three, which is what makes the
|
|
65
|
+
// narrower capability necessary rather than redundant.
|
|
66
|
+
expect(supportsHostProxy("windows", "host_cu")).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
54
69
|
test("capability form withholds unimplemented Windows app control", () => {
|
|
55
70
|
expect(supportsHostProxy("windows", "host_bash")).toBe(true);
|
|
56
71
|
expect(supportsHostProxy("windows", "host_file")).toBe(true);
|
|
@@ -366,15 +366,42 @@ describe("preactivateHostProxySkills logging", () => {
|
|
|
366
366
|
expect(fields.sourceInterface).toBe("macos");
|
|
367
367
|
expect(fields.decisions).toEqual({
|
|
368
368
|
host_cu: { shouldAttach: true, reason: "native_support" },
|
|
369
|
+
// Negotiated on the connection rather than implied by the interface, so
|
|
370
|
+
// with no client advertising it there is nothing to draw on. See the
|
|
371
|
+
// case below for the same turn once one is connected.
|
|
372
|
+
host_cu_annotate: {
|
|
373
|
+
shouldAttach: false,
|
|
374
|
+
reason: "denied_no_clients",
|
|
375
|
+
clientCount: 0,
|
|
376
|
+
},
|
|
369
377
|
host_app_control: { shouldAttach: true, reason: "native_support" },
|
|
370
378
|
});
|
|
371
379
|
expect(fields.preactivatedSkillIds).toEqual([
|
|
372
380
|
"computer-use",
|
|
373
|
-
"screen-annotation",
|
|
374
381
|
"app-control",
|
|
375
382
|
]);
|
|
376
383
|
});
|
|
377
384
|
|
|
385
|
+
/**
|
|
386
|
+
* The interface table says macOS can draw, which is true of a client new
|
|
387
|
+
* enough to send the header and false of every build before it. Offering
|
|
388
|
+
* the skill on the table alone gave an older client a tool whose every call
|
|
389
|
+
* was refused for having nothing to draw on.
|
|
390
|
+
*/
|
|
391
|
+
test("offers screen annotation once a client advertises it", () => {
|
|
392
|
+
const target = makeTarget("conv-macos-annotate");
|
|
393
|
+
setCapableClient("host_cu_annotate", true);
|
|
394
|
+
|
|
395
|
+
preactivateHostProxySkills(target, "macos", "user-1");
|
|
396
|
+
|
|
397
|
+
const { fields } = loggedInfoCalls[0];
|
|
398
|
+
expect(
|
|
399
|
+
(fields.decisions as Record<string, { shouldAttach: boolean }>)
|
|
400
|
+
.host_cu_annotate.shouldAttach,
|
|
401
|
+
).toBe(true);
|
|
402
|
+
expect(fields.preactivatedSkillIds).toContain("screen-annotation");
|
|
403
|
+
});
|
|
404
|
+
|
|
378
405
|
test("log captures denied_no_interface for undefined sourceInterface (silent-gate diagnostic)", () => {
|
|
379
406
|
const target = makeTarget("conv-no-interface");
|
|
380
407
|
preactivateHostProxySkills(target, undefined);
|
|
@@ -385,6 +412,10 @@ describe("preactivateHostProxySkills logging", () => {
|
|
|
385
412
|
expect(fields.sourceInterface).toBeUndefined();
|
|
386
413
|
expect(fields.decisions).toEqual({
|
|
387
414
|
host_cu: { shouldAttach: false, reason: "denied_no_interface" },
|
|
415
|
+
host_cu_annotate: {
|
|
416
|
+
shouldAttach: false,
|
|
417
|
+
reason: "denied_no_interface",
|
|
418
|
+
},
|
|
388
419
|
host_app_control: { shouldAttach: false, reason: "denied_no_interface" },
|
|
389
420
|
});
|
|
390
421
|
expect(fields.preactivatedSkillIds).toEqual([]);
|
|
@@ -410,6 +441,34 @@ describe("preactivateHostProxySkills logging", () => {
|
|
|
410
441
|
reason: "denied_no_clients",
|
|
411
442
|
clientCount: 0,
|
|
412
443
|
});
|
|
444
|
+
// Computer use and nothing else. The marks are drawn in a window the
|
|
445
|
+
// client opens for itself, and a client advertising only the transport
|
|
446
|
+
// has no such window to draw in.
|
|
447
|
+
expect(loggedInfoCalls[0].fields.preactivatedSkillIds).toEqual([
|
|
448
|
+
"computer-use",
|
|
449
|
+
]);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* The case the annotation capability exists for: a web turn is routed to a
|
|
454
|
+
* desktop client, and only a client that says it can draw is offered the
|
|
455
|
+
* skill that draws.
|
|
456
|
+
*/
|
|
457
|
+
test("offers screen annotation to a web source once a client advertises it", () => {
|
|
458
|
+
setCapableClient("host_cu", true);
|
|
459
|
+
setCapableClient("host_cu_annotate", true);
|
|
460
|
+
const target = makeTarget();
|
|
461
|
+
preactivateHostProxySkills(target, "web", "user-1");
|
|
462
|
+
|
|
463
|
+
const decisions = loggedInfoCalls[0].fields.decisions as Record<
|
|
464
|
+
string,
|
|
465
|
+
unknown
|
|
466
|
+
>;
|
|
467
|
+
expect(decisions.host_cu_annotate).toEqual({
|
|
468
|
+
shouldAttach: true,
|
|
469
|
+
reason: "cross_client",
|
|
470
|
+
clientCount: 1,
|
|
471
|
+
});
|
|
413
472
|
expect(loggedInfoCalls[0].fields.preactivatedSkillIds).toEqual([
|
|
414
473
|
"computer-use",
|
|
415
474
|
"screen-annotation",
|
|
@@ -310,6 +310,7 @@ interface FakeTurnState {
|
|
|
310
310
|
assistantId: string | undefined;
|
|
311
311
|
callSessionId: string | undefined;
|
|
312
312
|
trustContext: unknown;
|
|
313
|
+
actorPrincipalId: string | undefined;
|
|
313
314
|
commandIntent: unknown;
|
|
314
315
|
turnChannelContext: unknown;
|
|
315
316
|
turnInterfaceContext: unknown;
|
|
@@ -332,6 +333,8 @@ function wireTurnState(
|
|
|
332
333
|
const conv = fake as FakeConversation & {
|
|
333
334
|
assistantId?: string;
|
|
334
335
|
trustContext?: unknown;
|
|
336
|
+
currentTurnSourceActorPrincipalId?: string;
|
|
337
|
+
currentTurnActorStampGeneration?: number;
|
|
335
338
|
commandIntent?: unknown;
|
|
336
339
|
channelCapabilities?: unknown;
|
|
337
340
|
voiceCallControlPrompt?: string;
|
|
@@ -341,6 +344,22 @@ function wireTurnState(
|
|
|
341
344
|
conv.assistantId = initial.assistantId;
|
|
342
345
|
conv.callSessionId = initial.callSessionId;
|
|
343
346
|
conv.trustContext = initial.trustContext;
|
|
347
|
+
// The real Conversation counts every write to the actor stamp behind an
|
|
348
|
+
// accessor (see `currentTurnActorStampGeneration`), which is what lets a
|
|
349
|
+
// turn tell its own stamp from a concurrent writer's. The fake counts them
|
|
350
|
+
// the same way, so the bridge's check is exercised here rather than being
|
|
351
|
+
// trivially true against a plain property.
|
|
352
|
+
let actorPrincipal = initial.actorPrincipalId;
|
|
353
|
+
conv.currentTurnActorStampGeneration = 0;
|
|
354
|
+
Object.defineProperty(conv, "currentTurnSourceActorPrincipalId", {
|
|
355
|
+
configurable: true,
|
|
356
|
+
get: () => actorPrincipal,
|
|
357
|
+
set: (value: string | undefined) => {
|
|
358
|
+
actorPrincipal = value;
|
|
359
|
+
conv.currentTurnActorStampGeneration =
|
|
360
|
+
(conv.currentTurnActorStampGeneration ?? 0) + 1;
|
|
361
|
+
},
|
|
362
|
+
});
|
|
344
363
|
conv.commandIntent = initial.commandIntent;
|
|
345
364
|
conv.channelCapabilities = initial.channelCapabilities;
|
|
346
365
|
conv.voiceCallControlPrompt = initial.voiceCallControlPrompt;
|
|
@@ -374,6 +393,7 @@ function wireTurnState(
|
|
|
374
393
|
assistantId: conv.assistantId,
|
|
375
394
|
callSessionId: conv.callSessionId,
|
|
376
395
|
trustContext: conv.trustContext,
|
|
396
|
+
actorPrincipalId: conv.currentTurnSourceActorPrincipalId,
|
|
377
397
|
commandIntent: conv.commandIntent,
|
|
378
398
|
turnChannelContext,
|
|
379
399
|
turnInterfaceContext,
|
|
@@ -393,6 +413,7 @@ function makeWinnerState(): FakeTurnState {
|
|
|
393
413
|
assistantId: "assistant-winner",
|
|
394
414
|
callSessionId: "session-winner",
|
|
395
415
|
trustContext: { sourceChannel: "imessage", trustClass: "trusted_contact" },
|
|
416
|
+
actorPrincipalId: "principal-winner",
|
|
396
417
|
commandIntent: undefined,
|
|
397
418
|
turnChannelContext: {
|
|
398
419
|
userMessageChannel: "imessage",
|
|
@@ -1489,6 +1510,103 @@ describe("startVoiceTurn queued-message drain race", () => {
|
|
|
1489
1510
|
});
|
|
1490
1511
|
});
|
|
1491
1512
|
|
|
1513
|
+
describe("startVoiceTurn actor principal", () => {
|
|
1514
|
+
// The turn's actor is what host proxies match connected desktop clients
|
|
1515
|
+
// against (`pickSameUserAutoResolve`). A turn that carries none matches no
|
|
1516
|
+
// client, so every computer-use call it makes is refused however healthy
|
|
1517
|
+
// the connected client is.
|
|
1518
|
+
|
|
1519
|
+
test("stamps the caller's actor for the duration of the turn", async () => {
|
|
1520
|
+
const statesAtPersist: FakeTurnState[] = [];
|
|
1521
|
+
const fake = makeFakeConversation({
|
|
1522
|
+
processing: false,
|
|
1523
|
+
onPersist: () => {
|
|
1524
|
+
statesAtPersist.push(readState());
|
|
1525
|
+
},
|
|
1526
|
+
});
|
|
1527
|
+
const readState = wireTurnState(fake.conversation, {});
|
|
1528
|
+
fakeConversation = fake.conversation;
|
|
1529
|
+
|
|
1530
|
+
await startVoiceTurn({
|
|
1531
|
+
...makeTurnOptions(undefined, "conv-actor-stamp"),
|
|
1532
|
+
actorPrincipalId: "principal-guardian",
|
|
1533
|
+
});
|
|
1534
|
+
|
|
1535
|
+
expect(statesAtPersist.length).toBe(1);
|
|
1536
|
+
expect(statesAtPersist[0]!.actorPrincipalId).toBe("principal-guardian");
|
|
1537
|
+
});
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* A phone caller is whoever dialled in. Resolving them to a desktop client
|
|
1541
|
+
* would hand an inbound caller the owner's machine, so the telephony path
|
|
1542
|
+
* passes no actor and the turn must not invent one.
|
|
1543
|
+
*/
|
|
1544
|
+
test("a turn with no caller actor leaves the conversation without one", async () => {
|
|
1545
|
+
const statesAtPersist: FakeTurnState[] = [];
|
|
1546
|
+
const fake = makeFakeConversation({
|
|
1547
|
+
processing: false,
|
|
1548
|
+
onPersist: () => {
|
|
1549
|
+
statesAtPersist.push(readState());
|
|
1550
|
+
},
|
|
1551
|
+
});
|
|
1552
|
+
const readState = wireTurnState(fake.conversation, {});
|
|
1553
|
+
fakeConversation = fake.conversation;
|
|
1554
|
+
|
|
1555
|
+
await startVoiceTurn(makeTurnOptions(undefined, "conv-actor-absent"));
|
|
1556
|
+
|
|
1557
|
+
expect(statesAtPersist.length).toBe(1);
|
|
1558
|
+
expect(statesAtPersist[0]!.actorPrincipalId).toBeUndefined();
|
|
1559
|
+
});
|
|
1560
|
+
|
|
1561
|
+
/** The stamp is the turn's, so it goes when the turn does. */
|
|
1562
|
+
test("releases the actor when the turn ends", async () => {
|
|
1563
|
+
const fake = makeFakeConversation({ processing: false });
|
|
1564
|
+
const readState = wireTurnState(fake.conversation, {});
|
|
1565
|
+
fakeConversation = fake.conversation;
|
|
1566
|
+
|
|
1567
|
+
const handle = await startVoiceTurn({
|
|
1568
|
+
...makeTurnOptions(undefined, "conv-actor-release"),
|
|
1569
|
+
actorPrincipalId: "principal-guardian",
|
|
1570
|
+
});
|
|
1571
|
+
handle.abort();
|
|
1572
|
+
await flushMicrotasks();
|
|
1573
|
+
|
|
1574
|
+
expect(readState().actorPrincipalId).toBeUndefined();
|
|
1575
|
+
});
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* The release is not unconditional. `runAgentLoopImpl` gives up the
|
|
1579
|
+
* processing claim before the turn-boundary commit is awaited, so a retry
|
|
1580
|
+
* can take the conversation and stamp its own actor while this turn is
|
|
1581
|
+
* still unwinding. The retry route installs no auth-context fallback, so a
|
|
1582
|
+
* clear on the way out would leave it with no actor at all and its
|
|
1583
|
+
* host-proxy calls refused.
|
|
1584
|
+
*/
|
|
1585
|
+
test("does not clear an actor another turn stamped while this one unwound", async () => {
|
|
1586
|
+
let conv: { currentTurnSourceActorPrincipalId?: string } | null = null;
|
|
1587
|
+
const fake = makeFakeConversation({
|
|
1588
|
+
processing: false,
|
|
1589
|
+
runAgentLoop: async () => {
|
|
1590
|
+
conv!.currentTurnSourceActorPrincipalId = "principal-retry";
|
|
1591
|
+
},
|
|
1592
|
+
});
|
|
1593
|
+
conv = fake.conversation as {
|
|
1594
|
+
currentTurnSourceActorPrincipalId?: string;
|
|
1595
|
+
};
|
|
1596
|
+
const readState = wireTurnState(fake.conversation, {});
|
|
1597
|
+
fakeConversation = fake.conversation;
|
|
1598
|
+
|
|
1599
|
+
const handle = await startVoiceTurn({
|
|
1600
|
+
...makeTurnOptions(undefined, "conv-actor-release-guard"),
|
|
1601
|
+
actorPrincipalId: "principal-guardian",
|
|
1602
|
+
});
|
|
1603
|
+
handle.abort();
|
|
1604
|
+
await flushMicrotasks();
|
|
1605
|
+
|
|
1606
|
+
expect(readState().actorPrincipalId).toBe("principal-retry");
|
|
1607
|
+
});
|
|
1608
|
+
});
|
|
1609
|
+
|
|
1492
1610
|
describe("startVoiceTurn race-loss state restore", () => {
|
|
1493
1611
|
// A busy persist means a concurrent turn (the lock winner) is running with
|
|
1494
1612
|
// per-turn state it installed. Every race-loss path must put the winner's
|
|
@@ -1547,6 +1665,54 @@ describe("startVoiceTurn race-loss state restore", () => {
|
|
|
1547
1665
|
expect(retryState.voiceCallControlPrompt).toContain("voice_call_control");
|
|
1548
1666
|
});
|
|
1549
1667
|
|
|
1668
|
+
/**
|
|
1669
|
+
* The winner here is an ordinary message turn, which stamps the actor
|
|
1670
|
+
* directly (`conversation-routes`, `conversation-process`) rather than
|
|
1671
|
+
* through this bridge. It shares the guardian, so it writes the identical
|
|
1672
|
+
* string this turn did and the field cannot say which of them wrote it.
|
|
1673
|
+
* Reverting on that would hand the winner a principal from an earlier turn,
|
|
1674
|
+
* and automatic host-client resolution would then go looking for that other
|
|
1675
|
+
* principal's desktop.
|
|
1676
|
+
*/
|
|
1677
|
+
test("an ordinary turn's actor stamp is not reverted by a losing voice turn", async () => {
|
|
1678
|
+
const statesDuringWait: FakeTurnState[] = [];
|
|
1679
|
+
const fake = makeFakeConversation({
|
|
1680
|
+
processing: false,
|
|
1681
|
+
waitForIdle: async () => {
|
|
1682
|
+
statesDuringWait.push(readState());
|
|
1683
|
+
fake.setProcessingFlag(false);
|
|
1684
|
+
return true;
|
|
1685
|
+
},
|
|
1686
|
+
onPersist: (attempt) => {
|
|
1687
|
+
if (attempt === 1) {
|
|
1688
|
+
// The winner takes the conversation and stamps the same guardian,
|
|
1689
|
+
// the way an ordinary turn does: a direct write, counted but
|
|
1690
|
+
// otherwise invisible to this bridge.
|
|
1691
|
+
(
|
|
1692
|
+
fake.conversation as { currentTurnSourceActorPrincipalId?: string }
|
|
1693
|
+
).currentTurnSourceActorPrincipalId = "principal-guardian";
|
|
1694
|
+
fake.setProcessingFlag(true);
|
|
1695
|
+
throw new Error("Conversation is already processing a message");
|
|
1696
|
+
}
|
|
1697
|
+
},
|
|
1698
|
+
});
|
|
1699
|
+
// What an earlier turn left resident, and what a value-based revert would
|
|
1700
|
+
// wrongly put back.
|
|
1701
|
+
const readState = wireTurnState(fake.conversation, {
|
|
1702
|
+
actorPrincipalId: "principal-other",
|
|
1703
|
+
});
|
|
1704
|
+
fakeConversation = fake.conversation;
|
|
1705
|
+
|
|
1706
|
+
await startVoiceTurn({
|
|
1707
|
+
...makeTurnOptions(undefined, "conv-race-ordinary-winner"),
|
|
1708
|
+
callSessionId: "session-voice-loser",
|
|
1709
|
+
actorPrincipalId: "principal-guardian",
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
expect(statesDuringWait.length).toBe(1);
|
|
1713
|
+
expect(statesDuringWait[0]!.actorPrincipalId).toBe("principal-guardian");
|
|
1714
|
+
});
|
|
1715
|
+
|
|
1550
1716
|
test("a busy persist whose retry wait exhausts the budget leaves the winner's values in place", async () => {
|
|
1551
1717
|
const winnerState = makeWinnerState();
|
|
1552
1718
|
const fake = makeFakeConversation({
|