@vellumai/assistant 0.10.9-dev.202607152225.ec6fdbf → 0.10.9-dev.202607160032.a12042f
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-action-delivery.test.ts +0 -130
- package/src/__tests__/navigate-settings-tab.test.ts +1 -0
- package/src/__tests__/voice-session-bridge.test.ts +216 -84
- package/src/calls/__tests__/voice-session-bridge.test.ts +47 -51
- package/src/calls/voice-session-bridge.ts +65 -80
- package/src/cli/commands/__tests__/inference-providers.test.ts +270 -33
- package/src/cli/commands/inference-providers.ts +168 -107
- package/src/cli/commands/inference.help.ts +116 -44
- package/src/config/bundled-skills/settings/TOOLS.json +1 -0
- package/src/config/bundled-skills/settings/tools/navigate-settings-tab.ts +1 -0
- package/src/daemon/conversation-surfaces.ts +1 -52
- package/src/live-voice/__tests__/live-voice-events.test.ts +14 -2
- package/src/live-voice/live-voice-session.ts +5 -161
- package/src/providers/inference/__tests__/adapter-factory-openai-compatible.test.ts +29 -4
- package/src/providers/inference/__tests__/connection-availability-keyless.test.ts +78 -0
- package/src/providers/inference/adapter-factory.ts +12 -3
- package/src/providers/inference/auth.ts +6 -1
- package/src/providers/inference/connection-availability.ts +3 -2
- package/src/providers/inference/resolve-auth.ts +9 -1
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +34 -0
- package/src/runtime/routes/inference-provider-connection-routes.ts +4 -4
- package/src/live-voice/__tests__/live-voice-resume-registry.test.ts +0 -58
- package/src/live-voice/__tests__/live-voice-resume-turn.test.ts +0 -280
- package/src/live-voice/live-voice-resume-registry.ts +0 -54
package/package.json
CHANGED
|
@@ -12,8 +12,6 @@ mock.module("../runtime/assistant-event-hub.js", () => ({
|
|
|
12
12
|
const { createSurfaceMutex, handleSurfaceAction, surfaceProxyResolver } =
|
|
13
13
|
await import("../daemon/conversation-surfaces.js");
|
|
14
14
|
|
|
15
|
-
const { registerVoiceResumeHandler, unregisterVoiceResumeHandler } =
|
|
16
|
-
await import("../live-voice/live-voice-resume-registry.js");
|
|
17
15
|
import type { SurfaceConversationContext } from "../daemon/conversation-surfaces.js";
|
|
18
16
|
import type {
|
|
19
17
|
SurfaceData,
|
|
@@ -21,10 +19,6 @@ import type {
|
|
|
21
19
|
UiSurfaceShow,
|
|
22
20
|
} from "../daemon/message-protocol.js";
|
|
23
21
|
import type { UserMessageAttachment } from "../daemon/message-types/shared.js";
|
|
24
|
-
import type {
|
|
25
|
-
VoiceResumeHandler,
|
|
26
|
-
VoiceResumeOptions,
|
|
27
|
-
} from "../live-voice/live-voice-resume-registry.js";
|
|
28
22
|
|
|
29
23
|
interface ProcessMessageCall {
|
|
30
24
|
content: string;
|
|
@@ -518,131 +512,7 @@ describe("surface action delivery to assistant", () => {
|
|
|
518
512
|
expect(completeMsg?.conversationId).toBe("conv-1");
|
|
519
513
|
expect(completeMsg?.summary).toBe("Connected Google: user@example.com");
|
|
520
514
|
expect(ctx.pendingSurfaceActions.has(surfaceId)).toBe(false);
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
test("oauth_connect routes to the voice resume handler (spoken) and skips processMessage when a live-voice session owns the conversation", async () => {
|
|
524
|
-
const sent: ServerMessage[] = [];
|
|
525
|
-
const ctx = makeContext(sent);
|
|
526
|
-
|
|
527
|
-
const resumeCalls: Array<{
|
|
528
|
-
content: string;
|
|
529
|
-
opts?: VoiceResumeOptions;
|
|
530
|
-
}> = [];
|
|
531
|
-
const handler: VoiceResumeHandler = {
|
|
532
|
-
resumeWithText: (content, opts) => resumeCalls.push({ content, opts }),
|
|
533
|
-
};
|
|
534
|
-
registerVoiceResumeHandler(ctx.conversationId, handler);
|
|
535
|
-
|
|
536
|
-
try {
|
|
537
|
-
await surfaceProxyResolver(ctx, "ui_show", {
|
|
538
|
-
surface_type: "oauth_connect",
|
|
539
|
-
title: "Connect Google",
|
|
540
|
-
data: { providerKey: "google", displayName: "Google" },
|
|
541
|
-
});
|
|
542
|
-
const showMessage = sent.find(
|
|
543
|
-
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
544
|
-
) as UiSurfaceShow;
|
|
545
|
-
const surfaceId = showMessage.surfaceId;
|
|
546
|
-
expect(ctx.pendingSurfaceActions.has(surfaceId)).toBe(true);
|
|
547
|
-
|
|
548
|
-
await handleSurfaceAction(ctx, surfaceId, "connect", {
|
|
549
|
-
status: "connected",
|
|
550
|
-
providerKey: "google",
|
|
551
|
-
providerLabel: "Google",
|
|
552
|
-
accountLabel: "user@example.com",
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
// Routed to the spoken resume, not the silent text pipeline.
|
|
556
|
-
expect(resumeCalls).toHaveLength(1);
|
|
557
|
-
// The accepted surface is threaded so the resumed turn re-injects its
|
|
558
|
-
// active-surface context (parity with the text path's activeSurfaceId).
|
|
559
|
-
expect(resumeCalls[0].opts?.activeSurfaceId).toBe(surfaceId);
|
|
560
|
-
expect(ctx.processMessageCalls).toHaveLength(0);
|
|
561
|
-
// The one-shot surface still completes and the pending guard is cleared.
|
|
562
|
-
expect(ctx.pendingSurfaceActions.has(surfaceId)).toBe(false);
|
|
563
|
-
expect(
|
|
564
|
-
broadcastedMessages.some(
|
|
565
|
-
(msg) =>
|
|
566
|
-
msg.type === "ui_surface_complete" && msg.surfaceId === surfaceId,
|
|
567
|
-
),
|
|
568
|
-
).toBe(true);
|
|
569
|
-
} finally {
|
|
570
|
-
unregisterVoiceResumeHandler(ctx.conversationId, handler);
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
test("relayed-prompt voice resume emits no pre-echo (single user bubble comes from the resume turn)", async () => {
|
|
575
|
-
const sent: ServerMessage[] = [];
|
|
576
|
-
const ctx = makeContext(sent);
|
|
577
|
-
|
|
578
|
-
const resumeCalls: Array<{
|
|
579
|
-
content: string;
|
|
580
|
-
opts?: VoiceResumeOptions;
|
|
581
|
-
}> = [];
|
|
582
|
-
const handler: VoiceResumeHandler = {
|
|
583
|
-
resumeWithText: (content, opts) => resumeCalls.push({ content, opts }),
|
|
584
|
-
};
|
|
585
|
-
registerVoiceResumeHandler(ctx.conversationId, handler);
|
|
586
|
-
|
|
587
|
-
try {
|
|
588
|
-
const surfaceId = "card-relay-1";
|
|
589
|
-
ctx.pendingSurfaceActions.set(surfaceId, { surfaceType: "card" });
|
|
590
|
-
ctx.surfaceState.set(surfaceId, {
|
|
591
|
-
surfaceType: "card",
|
|
592
|
-
data: { title: "Ready?" } as SurfaceData,
|
|
593
|
-
actions: [
|
|
594
|
-
{
|
|
595
|
-
id: "relay_prompt",
|
|
596
|
-
label: "Do it",
|
|
597
|
-
data: { prompt: "Do the thing" },
|
|
598
|
-
},
|
|
599
|
-
],
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
await handleSurfaceAction(ctx, surfaceId, "relay_prompt");
|
|
603
|
-
|
|
604
|
-
// Routed to the spoken resume with the relayed prompt as content.
|
|
605
|
-
expect(resumeCalls).toHaveLength(1);
|
|
606
|
-
expect(resumeCalls[0].content).toBe("Do the thing");
|
|
607
|
-
expect(resumeCalls[0].opts?.activeSurfaceId).toBe(surfaceId);
|
|
608
|
-
expect(ctx.processMessageCalls).toHaveLength(0);
|
|
609
|
-
|
|
610
|
-
// The resume turn's own startVoiceTurn broadcasts the single
|
|
611
|
-
// user_message_echo, so handleSurfaceAction must not pre-echo here —
|
|
612
|
-
// otherwise the click renders two user bubbles.
|
|
613
|
-
expect(
|
|
614
|
-
broadcastedMessages.filter((msg) => msg.type === "user_message_echo"),
|
|
615
|
-
).toHaveLength(0);
|
|
616
|
-
} finally {
|
|
617
|
-
unregisterVoiceResumeHandler(ctx.conversationId, handler);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
test("oauth_connect falls back to processMessage when no voice resume handler is registered", async () => {
|
|
622
|
-
const sent: ServerMessage[] = [];
|
|
623
|
-
const ctx = makeContext(sent);
|
|
624
|
-
// The prior voice test unregisters its handler, so "conv-1" has no handler.
|
|
625
|
-
|
|
626
|
-
await surfaceProxyResolver(ctx, "ui_show", {
|
|
627
|
-
surface_type: "oauth_connect",
|
|
628
|
-
title: "Connect Google",
|
|
629
|
-
data: { providerKey: "google", displayName: "Google" },
|
|
630
|
-
});
|
|
631
|
-
const showMessage = sent.find(
|
|
632
|
-
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
633
|
-
) as UiSurfaceShow;
|
|
634
|
-
const surfaceId = showMessage.surfaceId;
|
|
635
|
-
|
|
636
|
-
await handleSurfaceAction(ctx, surfaceId, "connect", {
|
|
637
|
-
status: "connected",
|
|
638
|
-
providerKey: "google",
|
|
639
|
-
providerLabel: "Google",
|
|
640
|
-
accountLabel: "user@example.com",
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
// Byte-for-byte the prior behavior: text pipeline runs, guard cleared.
|
|
644
515
|
expect(ctx.processMessageCalls).toHaveLength(1);
|
|
645
|
-
expect(ctx.pendingSurfaceActions.has(surfaceId)).toBe(false);
|
|
646
516
|
});
|
|
647
517
|
|
|
648
518
|
test("table surface does NOT broadcast ui_surface_complete (not one-shot)", async () => {
|
|
@@ -36,8 +36,10 @@ import {
|
|
|
36
36
|
} from "../persistence/conversation-crud.js";
|
|
37
37
|
import { getDb } from "../persistence/db-connection.js";
|
|
38
38
|
import { initializeDb } from "../persistence/db-init.js";
|
|
39
|
-
import {
|
|
40
|
-
|
|
39
|
+
import {
|
|
40
|
+
assistantEventHub,
|
|
41
|
+
broadcastMessage,
|
|
42
|
+
} from "../runtime/assistant-event-hub.js";
|
|
41
43
|
|
|
42
44
|
await initializeDb();
|
|
43
45
|
|
|
@@ -161,7 +163,6 @@ describe("voice-session-bridge", () => {
|
|
|
161
163
|
const db = getDb();
|
|
162
164
|
db.run("DELETE FROM messages");
|
|
163
165
|
db.run("DELETE FROM conversations");
|
|
164
|
-
pendingInteractions.clear();
|
|
165
166
|
});
|
|
166
167
|
|
|
167
168
|
test("throws when deps not injected", async () => {
|
|
@@ -479,13 +480,15 @@ describe("voice-session-bridge", () => {
|
|
|
479
480
|
|
|
480
481
|
await startVoiceTurn({
|
|
481
482
|
conversationId: conversation.id,
|
|
482
|
-
voiceSessionId: "
|
|
483
|
+
voiceSessionId: "live-voice-session-1",
|
|
483
484
|
userMessageChannel: "vellum",
|
|
484
485
|
assistantMessageChannel: "vellum",
|
|
485
486
|
userMessageInterface: "macos",
|
|
486
487
|
assistantMessageInterface: "macos",
|
|
487
|
-
|
|
488
|
-
|
|
488
|
+
// Synthetic fixture — this test only asserts pass-through of a
|
|
489
|
+
// caller-supplied prompt, not the production live-voice prompt (that
|
|
490
|
+
// string is pinned in live-voice-events.test.ts).
|
|
491
|
+
voiceControlPrompt: "test control prompt",
|
|
489
492
|
content: "Hello from local live voice",
|
|
490
493
|
isInbound: true,
|
|
491
494
|
callbacks: {
|
|
@@ -503,10 +506,8 @@ describe("voice-session-bridge", () => {
|
|
|
503
506
|
|
|
504
507
|
await new Promise((r) => setTimeout(r, 50));
|
|
505
508
|
|
|
506
|
-
expect(capturedVoiceSessionId).toBe("
|
|
507
|
-
expect(capturedPrompts[0]).toBe(
|
|
508
|
-
"You are speaking in a local live voice session. Keep replies brief and conversational.",
|
|
509
|
-
);
|
|
509
|
+
expect(capturedVoiceSessionId).toBe("live-voice-session-1");
|
|
510
|
+
expect(capturedPrompts[0]).toBe("test control prompt");
|
|
510
511
|
expect(textDeltaEvents).toEqual([events[0]]);
|
|
511
512
|
expect(completeEvents).toEqual([events[1]]);
|
|
512
513
|
expect(persistedAssistantMessageId).toBe("assistant-msg-1");
|
|
@@ -763,17 +764,23 @@ describe("voice-session-bridge", () => {
|
|
|
763
764
|
expect(handleConfirmationCalls[0].decision).toBe("deny");
|
|
764
765
|
expect(handleConfirmationCalls[0].decisionContext).toContain("voice call");
|
|
765
766
|
expect(handleConfirmationCalls[0].decisionContext).toContain("host_bash");
|
|
767
|
+
// Phone callers get the guardian-access framing, not the local-session
|
|
768
|
+
// could-not-verify copy.
|
|
769
|
+
expect(handleConfirmationCalls[0].decisionContext).toContain(
|
|
770
|
+
"requires guardian-level access",
|
|
771
|
+
);
|
|
766
772
|
});
|
|
767
773
|
|
|
768
|
-
test("auto-denies
|
|
774
|
+
test("auto-denies with could-not-verify copy for local live-voice (vellum) turns", async () => {
|
|
769
775
|
const conversation = createConversation(
|
|
770
|
-
"voice bridge auto-deny
|
|
776
|
+
"voice bridge auto-deny vellum copy test",
|
|
771
777
|
);
|
|
772
778
|
|
|
773
779
|
let clientHandler: (msg: ServerMessage) => void = () => {};
|
|
774
780
|
const handleConfirmationCalls: Array<{
|
|
775
781
|
requestId: string;
|
|
776
782
|
decision: string;
|
|
783
|
+
decisionContext?: string;
|
|
777
784
|
}> = [];
|
|
778
785
|
|
|
779
786
|
const session = {
|
|
@@ -796,30 +803,40 @@ describe("voice-session-bridge", () => {
|
|
|
796
803
|
runAgentLoop: async () => {
|
|
797
804
|
clientHandler({
|
|
798
805
|
type: "confirmation_request",
|
|
799
|
-
requestId: "req-voice-
|
|
800
|
-
toolName: "
|
|
801
|
-
input: {
|
|
806
|
+
requestId: "req-voice-vellum",
|
|
807
|
+
toolName: "host_bash",
|
|
808
|
+
input: { command: "touch /tmp/x" },
|
|
802
809
|
riskLevel: "medium",
|
|
803
810
|
allowlistOptions: [],
|
|
804
811
|
scopeOptions: [],
|
|
805
812
|
} as ServerMessage);
|
|
806
813
|
},
|
|
807
|
-
handleConfirmationResponse: (
|
|
808
|
-
|
|
814
|
+
handleConfirmationResponse: (
|
|
815
|
+
requestId: string,
|
|
816
|
+
decision: string,
|
|
817
|
+
options?: { decisionContext?: string },
|
|
818
|
+
) => {
|
|
819
|
+
handleConfirmationCalls.push({
|
|
820
|
+
requestId,
|
|
821
|
+
decision,
|
|
822
|
+
decisionContext: options?.decisionContext,
|
|
823
|
+
});
|
|
809
824
|
},
|
|
810
825
|
abort: () => {},
|
|
811
826
|
} as unknown as Conversation;
|
|
812
827
|
|
|
813
828
|
injectDeps(() => session);
|
|
814
829
|
|
|
830
|
+
// No trustContext: the local session's guardian trust could not be
|
|
831
|
+
// resolved (fresh install, gateway unreachable). The turn is still the
|
|
832
|
+
// device owner's own client, so the deny copy must say verification
|
|
833
|
+
// failed rather than implying they lack guardian access.
|
|
815
834
|
await startVoiceTurn({
|
|
816
835
|
conversationId: conversation.id,
|
|
817
|
-
|
|
836
|
+
userMessageChannel: "vellum",
|
|
837
|
+
userMessageInterface: "macos",
|
|
838
|
+
content: "run a command",
|
|
818
839
|
isInbound: true,
|
|
819
|
-
trustContext: {
|
|
820
|
-
sourceChannel: "phone",
|
|
821
|
-
trustClass: "unknown",
|
|
822
|
-
},
|
|
823
840
|
onTextDelta: () => {},
|
|
824
841
|
onComplete: () => {},
|
|
825
842
|
onError: () => {},
|
|
@@ -828,13 +845,19 @@ describe("voice-session-bridge", () => {
|
|
|
828
845
|
await new Promise((r) => setTimeout(r, 50));
|
|
829
846
|
|
|
830
847
|
expect(handleConfirmationCalls.length).toBe(1);
|
|
831
|
-
expect(handleConfirmationCalls[0].requestId).toBe("req-voice-2");
|
|
832
848
|
expect(handleConfirmationCalls[0].decision).toBe("deny");
|
|
849
|
+
expect(handleConfirmationCalls[0].decisionContext).toContain(
|
|
850
|
+
"could not be verified for this voice session",
|
|
851
|
+
);
|
|
852
|
+
expect(handleConfirmationCalls[0].decisionContext).toContain("text chat");
|
|
853
|
+
expect(handleConfirmationCalls[0].decisionContext).not.toContain(
|
|
854
|
+
"requires guardian-level access",
|
|
855
|
+
);
|
|
833
856
|
});
|
|
834
857
|
|
|
835
|
-
test("auto-denies confirmation requests
|
|
858
|
+
test("auto-denies confirmation requests for unverified_channel voice turns", async () => {
|
|
836
859
|
const conversation = createConversation(
|
|
837
|
-
"voice bridge auto-deny
|
|
860
|
+
"voice bridge auto-deny unverified test",
|
|
838
861
|
);
|
|
839
862
|
|
|
840
863
|
let clientHandler: (msg: ServerMessage) => void = () => {};
|
|
@@ -863,9 +886,9 @@ describe("voice-session-bridge", () => {
|
|
|
863
886
|
runAgentLoop: async () => {
|
|
864
887
|
clientHandler({
|
|
865
888
|
type: "confirmation_request",
|
|
866
|
-
requestId: "req-voice-
|
|
867
|
-
toolName: "
|
|
868
|
-
input: {
|
|
889
|
+
requestId: "req-voice-2",
|
|
890
|
+
toolName: "network_request",
|
|
891
|
+
input: { url: "https://evil.com" },
|
|
869
892
|
riskLevel: "medium",
|
|
870
893
|
allowlistOptions: [],
|
|
871
894
|
scopeOptions: [],
|
|
@@ -881,8 +904,12 @@ describe("voice-session-bridge", () => {
|
|
|
881
904
|
|
|
882
905
|
await startVoiceTurn({
|
|
883
906
|
conversationId: conversation.id,
|
|
884
|
-
content: "
|
|
907
|
+
content: "Make a request",
|
|
885
908
|
isInbound: true,
|
|
909
|
+
trustContext: {
|
|
910
|
+
sourceChannel: "phone",
|
|
911
|
+
trustClass: "unknown",
|
|
912
|
+
},
|
|
886
913
|
onTextDelta: () => {},
|
|
887
914
|
onComplete: () => {},
|
|
888
915
|
onError: () => {},
|
|
@@ -891,13 +918,13 @@ describe("voice-session-bridge", () => {
|
|
|
891
918
|
await new Promise((r) => setTimeout(r, 50));
|
|
892
919
|
|
|
893
920
|
expect(handleConfirmationCalls.length).toBe(1);
|
|
894
|
-
expect(handleConfirmationCalls[0].requestId).toBe("req-voice-
|
|
921
|
+
expect(handleConfirmationCalls[0].requestId).toBe("req-voice-2");
|
|
895
922
|
expect(handleConfirmationCalls[0].decision).toBe("deny");
|
|
896
923
|
});
|
|
897
924
|
|
|
898
|
-
test("
|
|
925
|
+
test("auto-denies confirmation requests when guardian context is missing", async () => {
|
|
899
926
|
const conversation = createConversation(
|
|
900
|
-
"voice bridge
|
|
927
|
+
"voice bridge auto-deny unknown actor test",
|
|
901
928
|
);
|
|
902
929
|
|
|
903
930
|
let clientHandler: (msg: ServerMessage) => void = () => {};
|
|
@@ -905,16 +932,6 @@ describe("voice-session-bridge", () => {
|
|
|
905
932
|
requestId: string;
|
|
906
933
|
decision: string;
|
|
907
934
|
}> = [];
|
|
908
|
-
const publishedMessages: ServerMessage[] = [];
|
|
909
|
-
const subscription = assistantEventHub.subscribe({
|
|
910
|
-
type: "process",
|
|
911
|
-
filter: {
|
|
912
|
-
conversationId: conversation.id,
|
|
913
|
-
},
|
|
914
|
-
callback: (event) => {
|
|
915
|
-
publishedMessages.push(event.message);
|
|
916
|
-
},
|
|
917
|
-
});
|
|
918
935
|
|
|
919
936
|
const session = {
|
|
920
937
|
isProcessing: () => false,
|
|
@@ -936,13 +953,12 @@ describe("voice-session-bridge", () => {
|
|
|
936
953
|
runAgentLoop: async () => {
|
|
937
954
|
clientHandler({
|
|
938
955
|
type: "confirmation_request",
|
|
939
|
-
requestId: "req-
|
|
956
|
+
requestId: "req-voice-unknown",
|
|
940
957
|
toolName: "host_bash",
|
|
941
|
-
input: { command: "
|
|
942
|
-
riskLevel: "
|
|
958
|
+
input: { command: "touch /tmp/x" },
|
|
959
|
+
riskLevel: "medium",
|
|
943
960
|
allowlistOptions: [],
|
|
944
961
|
scopeOptions: [],
|
|
945
|
-
conversationId: conversation.id,
|
|
946
962
|
} as ServerMessage);
|
|
947
963
|
},
|
|
948
964
|
handleConfirmationResponse: (requestId: string, decision: string) => {
|
|
@@ -951,47 +967,22 @@ describe("voice-session-bridge", () => {
|
|
|
951
967
|
abort: () => {},
|
|
952
968
|
} as unknown as Conversation;
|
|
953
969
|
|
|
954
|
-
|
|
955
|
-
injectDeps(() => session);
|
|
970
|
+
injectDeps(() => session);
|
|
956
971
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
guardianExternalUserId: "+12125550142",
|
|
966
|
-
guardianChatId: "+12125550142",
|
|
967
|
-
},
|
|
968
|
-
onTextDelta: () => {},
|
|
969
|
-
onComplete: () => {},
|
|
970
|
-
onError: () => {},
|
|
971
|
-
});
|
|
972
|
+
await startVoiceTurn({
|
|
973
|
+
conversationId: conversation.id,
|
|
974
|
+
content: "run a command",
|
|
975
|
+
isInbound: true,
|
|
976
|
+
onTextDelta: () => {},
|
|
977
|
+
onComplete: () => {},
|
|
978
|
+
onError: () => {},
|
|
979
|
+
});
|
|
972
980
|
|
|
973
|
-
|
|
981
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
974
982
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
(message) =>
|
|
979
|
-
message.type === "confirmation_request" &&
|
|
980
|
-
message.requestId === "req-local-live-voice",
|
|
981
|
-
),
|
|
982
|
-
).toBe(true);
|
|
983
|
-
expect(pendingInteractions.get("req-local-live-voice")).toMatchObject({
|
|
984
|
-
conversationId: conversation.id,
|
|
985
|
-
kind: "confirmation",
|
|
986
|
-
confirmationDetails: {
|
|
987
|
-
toolName: "host_bash",
|
|
988
|
-
riskLevel: "low",
|
|
989
|
-
},
|
|
990
|
-
});
|
|
991
|
-
} finally {
|
|
992
|
-
pendingInteractions.resolve("req-local-live-voice");
|
|
993
|
-
subscription.dispose();
|
|
994
|
-
}
|
|
983
|
+
expect(handleConfirmationCalls.length).toBe(1);
|
|
984
|
+
expect(handleConfirmationCalls[0].requestId).toBe("req-voice-unknown");
|
|
985
|
+
expect(handleConfirmationCalls[0].decision).toBe("deny");
|
|
995
986
|
});
|
|
996
987
|
|
|
997
988
|
test("auto-allows confirmation requests for guardian voice turns", async () => {
|
|
@@ -1065,6 +1056,147 @@ describe("voice-session-bridge", () => {
|
|
|
1065
1056
|
expect(handleConfirmationCalls[0].decision).toBe("allow");
|
|
1066
1057
|
});
|
|
1067
1058
|
|
|
1059
|
+
// Wire-order invariant under test: the bridge must broadcast the
|
|
1060
|
+
// `confirmation_request` BEFORE resolving it — canonical rationale on the
|
|
1061
|
+
// broadcast in voice-session-bridge.ts's confirmation_request branch. The
|
|
1062
|
+
// fake's handleConfirmationResponse mirrors production's synchronous
|
|
1063
|
+
// `interaction_resolved` broadcast so the wire order is observable through
|
|
1064
|
+
// the event hub, which serializes publishes in call order.
|
|
1065
|
+
function makeConfirmationOrderingSession(
|
|
1066
|
+
conversationId: string,
|
|
1067
|
+
requestId: string,
|
|
1068
|
+
): Conversation {
|
|
1069
|
+
let clientHandler: (msg: ServerMessage) => void = () => {};
|
|
1070
|
+
return {
|
|
1071
|
+
isProcessing: () => false,
|
|
1072
|
+
persistUserMessage: async () => ({
|
|
1073
|
+
id: "test-msg-id",
|
|
1074
|
+
deduplicated: false,
|
|
1075
|
+
}),
|
|
1076
|
+
setChannelCapabilities: () => {},
|
|
1077
|
+
setAssistantId: () => {},
|
|
1078
|
+
setTrustContext: () => {},
|
|
1079
|
+
setCommandIntent: () => {},
|
|
1080
|
+
setTurnChannelContext: () => {},
|
|
1081
|
+
setTurnInterfaceContext: () => {},
|
|
1082
|
+
setVoiceCallControlPrompt: () => {},
|
|
1083
|
+
updateClient: (handler: (msg: ServerMessage) => void) => {
|
|
1084
|
+
clientHandler = handler;
|
|
1085
|
+
},
|
|
1086
|
+
ensureActorScopedHistory: async () => {},
|
|
1087
|
+
runAgentLoop: async () => {
|
|
1088
|
+
clientHandler({
|
|
1089
|
+
type: "confirmation_request",
|
|
1090
|
+
requestId,
|
|
1091
|
+
toolName: "host_bash",
|
|
1092
|
+
input: { command: "ls" },
|
|
1093
|
+
riskLevel: "low",
|
|
1094
|
+
allowlistOptions: [],
|
|
1095
|
+
scopeOptions: [],
|
|
1096
|
+
conversationId,
|
|
1097
|
+
} as ServerMessage);
|
|
1098
|
+
},
|
|
1099
|
+
handleConfirmationResponse: (resolvedRequestId: string) => {
|
|
1100
|
+
broadcastMessage({
|
|
1101
|
+
type: "interaction_resolved",
|
|
1102
|
+
requestId: resolvedRequestId,
|
|
1103
|
+
conversationId,
|
|
1104
|
+
kind: "confirmation",
|
|
1105
|
+
state: "approved",
|
|
1106
|
+
} as ServerMessage);
|
|
1107
|
+
},
|
|
1108
|
+
abort: () => {},
|
|
1109
|
+
} as unknown as Conversation;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
async function collectConfirmationWireOrder(
|
|
1113
|
+
conversationId: string,
|
|
1114
|
+
turn: () => Promise<unknown>,
|
|
1115
|
+
): Promise<{ requestIndex: number; resolvedIndex: number }> {
|
|
1116
|
+
const published: ServerMessage[] = [];
|
|
1117
|
+
const subscription = assistantEventHub.subscribe({
|
|
1118
|
+
type: "process",
|
|
1119
|
+
filter: { conversationId },
|
|
1120
|
+
callback: (event) => {
|
|
1121
|
+
published.push(event.message);
|
|
1122
|
+
},
|
|
1123
|
+
});
|
|
1124
|
+
try {
|
|
1125
|
+
await turn();
|
|
1126
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1127
|
+
} finally {
|
|
1128
|
+
subscription.dispose();
|
|
1129
|
+
}
|
|
1130
|
+
return {
|
|
1131
|
+
requestIndex: published.findIndex(
|
|
1132
|
+
(m) => m.type === "confirmation_request",
|
|
1133
|
+
),
|
|
1134
|
+
resolvedIndex: published.findIndex(
|
|
1135
|
+
(m) => m.type === "interaction_resolved",
|
|
1136
|
+
),
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
test("broadcasts the confirmation_request before auto-allowing it (guardian)", async () => {
|
|
1141
|
+
const conversation = createConversation(
|
|
1142
|
+
"voice bridge confirmation order allow test",
|
|
1143
|
+
);
|
|
1144
|
+
injectDeps(() =>
|
|
1145
|
+
makeConfirmationOrderingSession(conversation.id, "req-order-allow"),
|
|
1146
|
+
);
|
|
1147
|
+
|
|
1148
|
+
const { requestIndex, resolvedIndex } = await collectConfirmationWireOrder(
|
|
1149
|
+
conversation.id,
|
|
1150
|
+
() =>
|
|
1151
|
+
startVoiceTurn({
|
|
1152
|
+
conversationId: conversation.id,
|
|
1153
|
+
content: "List files",
|
|
1154
|
+
isInbound: true,
|
|
1155
|
+
trustContext: {
|
|
1156
|
+
sourceChannel: "phone",
|
|
1157
|
+
trustClass: "guardian",
|
|
1158
|
+
guardianExternalUserId: "+15555550100",
|
|
1159
|
+
guardianChatId: "+15555550100",
|
|
1160
|
+
},
|
|
1161
|
+
onTextDelta: () => {},
|
|
1162
|
+
onComplete: () => {},
|
|
1163
|
+
onError: () => {},
|
|
1164
|
+
}),
|
|
1165
|
+
);
|
|
1166
|
+
|
|
1167
|
+
expect(requestIndex).toBeGreaterThanOrEqual(0);
|
|
1168
|
+
expect(resolvedIndex).toBeGreaterThan(requestIndex);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
test("broadcasts the confirmation_request before auto-denying it (non-guardian)", async () => {
|
|
1172
|
+
const conversation = createConversation(
|
|
1173
|
+
"voice bridge confirmation order deny test",
|
|
1174
|
+
);
|
|
1175
|
+
injectDeps(() =>
|
|
1176
|
+
makeConfirmationOrderingSession(conversation.id, "req-order-deny"),
|
|
1177
|
+
);
|
|
1178
|
+
|
|
1179
|
+
const { requestIndex, resolvedIndex } = await collectConfirmationWireOrder(
|
|
1180
|
+
conversation.id,
|
|
1181
|
+
() =>
|
|
1182
|
+
startVoiceTurn({
|
|
1183
|
+
conversationId: conversation.id,
|
|
1184
|
+
content: "List files",
|
|
1185
|
+
isInbound: true,
|
|
1186
|
+
trustContext: {
|
|
1187
|
+
sourceChannel: "phone",
|
|
1188
|
+
trustClass: "trusted_contact",
|
|
1189
|
+
},
|
|
1190
|
+
onTextDelta: () => {},
|
|
1191
|
+
onComplete: () => {},
|
|
1192
|
+
onError: () => {},
|
|
1193
|
+
}),
|
|
1194
|
+
);
|
|
1195
|
+
|
|
1196
|
+
expect(requestIndex).toBeGreaterThanOrEqual(0);
|
|
1197
|
+
expect(resolvedIndex).toBeGreaterThan(requestIndex);
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1068
1200
|
test("auto-resolves secret requests for voice turns (no secret-entry UI)", async () => {
|
|
1069
1201
|
const conversation = createConversation(
|
|
1070
1202
|
"voice bridge secret auto-resolve test",
|