@vellumai/assistant 0.12.1-dev.202609151913.a151da3 → 0.12.1-dev.202609152015.82616de
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/openapi.yaml +0 -10
- package/package.json +1 -1
- package/src/__tests__/always-loaded-tools-guard.test.ts +5 -5
- package/src/__tests__/conversation-runtime-assembly.test.ts +28 -0
- package/src/__tests__/oauth-commands-routes.test.ts +28 -0
- package/src/__tests__/subagent-tool-gate-mode.test.ts +51 -0
- package/src/__tests__/ui-channel-variants.test.ts +1 -56
- package/src/calls/__tests__/voice-control-protocol.test.ts +62 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +19 -0
- package/src/calls/voice-control-protocol.ts +102 -0
- package/src/calls/voice-session-bridge.ts +33 -26
- package/src/calls/voice-triage-escalate.ts +3 -3
- package/src/cli/commands/oauth/status.ts +5 -0
- package/src/cli/lib/bundled-marketplace.json +13 -0
- package/src/config/feature-flag-registry.json +8 -0
- package/src/config/loader.ts +1 -0
- package/src/config/schemas/services.ts +10 -0
- package/src/daemon/conversation-runtime-assembly.ts +18 -6
- package/src/daemon/conversation-surfaces.ts +5 -0
- package/src/daemon/conversation-tool-setup.ts +8 -16
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +121 -0
- package/src/live-voice/__tests__/live-voice-events.test.ts +8 -7
- package/src/live-voice/__tests__/live-voice-progress.test.ts +79 -0
- package/src/live-voice/__tests__/protocol.test.ts +39 -0
- package/src/live-voice/__tests__/session-controls.test.ts +79 -0
- package/src/live-voice/live-voice-session.ts +84 -6
- package/src/live-voice/protocol.ts +60 -0
- package/src/live-voice/session-controls.ts +111 -0
- package/src/oauth/__tests__/seed-providers-managed.test.ts +75 -0
- package/src/oauth/connection-resolver.test.ts +27 -0
- package/src/oauth/connection-resolver.ts +25 -1
- package/src/oauth/seed-providers.ts +87 -0
- package/src/onboarding/checkin-event.ts +2 -1
- package/src/providers/inference/__tests__/adapter-factory-opencode.test.ts +3 -89
- package/src/providers/inference/__tests__/endpoint-probe.test.ts +33 -43
- package/src/providers/inference/adapter-factory.ts +4 -15
- package/src/providers/inference/auth.ts +0 -28
- package/src/providers/inference/endpoint-probe.ts +25 -46
- package/src/providers/openai/chat-completions-provider.ts +0 -10
- package/src/providers/opencode/client.test.ts +30 -41
- package/src/providers/opencode/client.ts +22 -56
- package/src/providers/openrouter/client.ts +9 -0
- package/src/providers/vercel-ai-gateway/client.ts +9 -0
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +0 -36
- package/src/runtime/routes/inference-provider-connection-routes.ts +0 -11
- package/src/runtime/routes/oauth-commands-routes.ts +5 -0
- package/src/tools/ui-surface/channel-variants.ts +10 -59
- package/src/watch/watch-retro.ts +6 -8
package/openapi.yaml
CHANGED
|
@@ -38303,11 +38303,6 @@ components:
|
|
|
38303
38303
|
displayName:
|
|
38304
38304
|
type: string
|
|
38305
38305
|
minLength: 1
|
|
38306
|
-
transport:
|
|
38307
|
-
type: string
|
|
38308
|
-
enum:
|
|
38309
|
-
- chat_completions
|
|
38310
|
-
- responses
|
|
38311
38306
|
required:
|
|
38312
38307
|
- id
|
|
38313
38308
|
TelemetryJsonValue:
|
|
@@ -39439,11 +39434,6 @@ components:
|
|
|
39439
39434
|
displayName:
|
|
39440
39435
|
type: string
|
|
39441
39436
|
minLength: 1
|
|
39442
|
-
transport:
|
|
39443
|
-
type: string
|
|
39444
|
-
enum:
|
|
39445
|
-
- chat_completions
|
|
39446
|
-
- responses
|
|
39447
39437
|
required:
|
|
39448
39438
|
- id
|
|
39449
39439
|
additionalProperties: false
|
package/package.json
CHANGED
|
@@ -44,11 +44,11 @@ describe("always-loaded tool count", () => {
|
|
|
44
44
|
);
|
|
45
45
|
const activeNames = activeTools.map((t) => t.name).sort();
|
|
46
46
|
|
|
47
|
-
// `watch_retro_report` survives this baseline
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
47
|
+
// `watch_retro_report` survives this baseline because a watch
|
|
48
|
+
// retrospective runs clientless and can only report through a tool that
|
|
49
|
+
// stays on this baseline. The ui_* tools stay here because background
|
|
50
|
+
// surfaces persist and return instead of awaiting action, so a connected
|
|
51
|
+
// client is not required for the definitions to be present.
|
|
52
52
|
// Host tool definitions stay on the wire for background turns: schemas
|
|
53
53
|
// are cache-stable, and the shared execution gate rejects host tools on
|
|
54
54
|
// explicitly non-interactive turns before any proxy dispatch.
|
|
@@ -119,6 +119,7 @@ import {
|
|
|
119
119
|
applyRuntimeInjections,
|
|
120
120
|
assembleSlackActiveThreadFocusBlock,
|
|
121
121
|
assembleSlackChronologicalMessages,
|
|
122
|
+
buildChannelCapabilityBlock,
|
|
122
123
|
buildSubagentStatusBlock,
|
|
123
124
|
getSlackCompactionWatermarkForPrefix,
|
|
124
125
|
getSlackWatermarkAdvanceForRowPrefix,
|
|
@@ -586,6 +587,33 @@ describe("injectChannelCapabilityContext", () => {
|
|
|
586
587
|
expect(text).not.toContain("Do NOT use ui_show, ui_update, or app_create");
|
|
587
588
|
});
|
|
588
589
|
|
|
590
|
+
test("guides non-interactive turns to persist UI for a later capable client", () => {
|
|
591
|
+
const slack: ChannelCapabilities = {
|
|
592
|
+
channel: "slack",
|
|
593
|
+
dashboardCapable: false,
|
|
594
|
+
supportsDynamicUi: false,
|
|
595
|
+
supportsVoiceInput: false,
|
|
596
|
+
};
|
|
597
|
+
const phone: ChannelCapabilities = {
|
|
598
|
+
channel: "phone",
|
|
599
|
+
dashboardCapable: false,
|
|
600
|
+
supportsDynamicUi: false,
|
|
601
|
+
supportsVoiceInput: false,
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
for (const caps of [slack, phone]) {
|
|
605
|
+
const text = buildChannelCapabilityBlock(caps, undefined, true)!;
|
|
606
|
+
expect(text).toContain(
|
|
607
|
+
"ui_show, ui_update, and ui_dismiss persist conversation content",
|
|
608
|
+
);
|
|
609
|
+
expect(text).not.toContain("Only use ui_show/ui_update");
|
|
610
|
+
expect(text).not.toContain("Do NOT use ui_show, ui_update, or app_create");
|
|
611
|
+
expect(text).not.toContain(
|
|
612
|
+
"Present information as well-formatted text instead of dynamic UI.",
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
|
|
589
617
|
test("keeps blanket ui_show/ui_update prohibition for other non-dynamic channels", () => {
|
|
590
618
|
const caps: ChannelCapabilities = {
|
|
591
619
|
channel: "phone",
|
|
@@ -1255,6 +1255,7 @@ describe("GET oauth/managed-connect/poll", () => {
|
|
|
1255
1255
|
id: string;
|
|
1256
1256
|
account_label: string | null;
|
|
1257
1257
|
scopes_granted: string[];
|
|
1258
|
+
provider_params: Record<string, string>;
|
|
1258
1259
|
}>;
|
|
1259
1260
|
};
|
|
1260
1261
|
expect(result.ok).toBe(true);
|
|
@@ -1263,6 +1264,7 @@ describe("GET oauth/managed-connect/poll", () => {
|
|
|
1263
1264
|
id: "conn-1",
|
|
1264
1265
|
account_label: "alice@example.com",
|
|
1265
1266
|
scopes_granted: ["email"],
|
|
1267
|
+
provider_params: {},
|
|
1266
1268
|
},
|
|
1267
1269
|
]);
|
|
1268
1270
|
});
|
|
@@ -1275,4 +1277,30 @@ describe("GET oauth/managed-connect/poll", () => {
|
|
|
1275
1277
|
),
|
|
1276
1278
|
).rejects.toBeInstanceOf(BadRequestError);
|
|
1277
1279
|
});
|
|
1280
|
+
|
|
1281
|
+
test("passes through the provider params a connection is scoped by", async () => {
|
|
1282
|
+
// QuickBooks pins the company (realm) the user picked to the connection;
|
|
1283
|
+
// a caller addressing /companyinfo/<realmId> needs it back.
|
|
1284
|
+
mockFetchImpl = async () => ({
|
|
1285
|
+
ok: true,
|
|
1286
|
+
status: 200,
|
|
1287
|
+
json: async () => [
|
|
1288
|
+
{
|
|
1289
|
+
id: "conn-qb",
|
|
1290
|
+
account_label: "Acme Widgets",
|
|
1291
|
+
scopes_granted: ["com.intuit.quickbooks.accounting"],
|
|
1292
|
+
provider_params: { realm_id: "9130357849012345" },
|
|
1293
|
+
},
|
|
1294
|
+
],
|
|
1295
|
+
text: async () => "",
|
|
1296
|
+
});
|
|
1297
|
+
const result = (await getRoute("GET", "oauth/managed-connect/poll").handler(
|
|
1298
|
+
makeArgs({ queryParams: { provider: "quickbooks" } }),
|
|
1299
|
+
)) as {
|
|
1300
|
+
connections: Array<{ provider_params: Record<string, string> }>;
|
|
1301
|
+
};
|
|
1302
|
+
expect(result.connections[0]?.provider_params).toEqual({
|
|
1303
|
+
realm_id: "9130357849012345",
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1278
1306
|
});
|
|
@@ -88,6 +88,7 @@ import {
|
|
|
88
88
|
} from "../tools/registry.js";
|
|
89
89
|
import { RiskLevel } from "../tools/tool-types.js";
|
|
90
90
|
import type { Tool } from "../tools/types.js";
|
|
91
|
+
import { uiShowTool } from "../tools/ui-surface/definitions.js";
|
|
91
92
|
import { asConversation } from "./helpers/mock-conversation.js";
|
|
92
93
|
|
|
93
94
|
// ---------------------------------------------------------------------------
|
|
@@ -249,6 +250,56 @@ describe("createResolveToolsCallback — toolContextPin", () => {
|
|
|
249
250
|
});
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
test("Slack and desktop turns keep the same full ui_show schema while surfaces persist", () => {
|
|
254
|
+
projectedSkillToolNames = [];
|
|
255
|
+
const slackCaps = {
|
|
256
|
+
channel: "slack" as const,
|
|
257
|
+
dashboardCapable: false,
|
|
258
|
+
supportsDynamicUi: false,
|
|
259
|
+
supportsVoiceInput: false,
|
|
260
|
+
};
|
|
261
|
+
const desktopCaps = {
|
|
262
|
+
channel: "macos" as const,
|
|
263
|
+
dashboardCapable: true,
|
|
264
|
+
supportsDynamicUi: true,
|
|
265
|
+
supportsVoiceInput: true,
|
|
266
|
+
};
|
|
267
|
+
const liveSlackResolve = createResolveToolsCallback(
|
|
268
|
+
[uiShowTool],
|
|
269
|
+
makeProjectionCtx({
|
|
270
|
+
hasNoClient: false,
|
|
271
|
+
channelCapabilities: slackCaps,
|
|
272
|
+
}),
|
|
273
|
+
)!;
|
|
274
|
+
const clientlessSlackResolve = createResolveToolsCallback(
|
|
275
|
+
[uiShowTool],
|
|
276
|
+
clientlessExecutionCtx({
|
|
277
|
+
channelCapabilities: slackCaps,
|
|
278
|
+
}),
|
|
279
|
+
)!;
|
|
280
|
+
const liveDesktopResolve = createResolveToolsCallback(
|
|
281
|
+
[uiShowTool],
|
|
282
|
+
makeProjectionCtx({
|
|
283
|
+
hasNoClient: false,
|
|
284
|
+
channelCapabilities: desktopCaps,
|
|
285
|
+
}),
|
|
286
|
+
)!;
|
|
287
|
+
|
|
288
|
+
const [liveSlackUiShow] = liveSlackResolve(EMPTY_HISTORY);
|
|
289
|
+
const [clientlessSlackUiShow] = clientlessSlackResolve(EMPTY_HISTORY);
|
|
290
|
+
const [liveDesktopUiShow] = liveDesktopResolve(EMPTY_HISTORY);
|
|
291
|
+
expect(liveSlackUiShow).toEqual(clientlessSlackUiShow);
|
|
292
|
+
expect(liveSlackUiShow).toEqual(liveDesktopUiShow);
|
|
293
|
+
expect(
|
|
294
|
+
(
|
|
295
|
+
liveSlackUiShow.input_schema as {
|
|
296
|
+
properties: { surface_type: { enum: string[] } };
|
|
297
|
+
}
|
|
298
|
+
).properties.surface_type.enum,
|
|
299
|
+
).toContain("choice");
|
|
300
|
+
expect(liveSlackUiShow.description).toContain("dynamic_page");
|
|
301
|
+
});
|
|
302
|
+
|
|
252
303
|
test("control: without a pin, a clientless fork drops client-gated tools but keeps host and UI tools", () => {
|
|
253
304
|
projectedSkillToolNames = [];
|
|
254
305
|
const resolve = createResolveToolsCallback(
|
|
@@ -2,10 +2,7 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import type { ToolDefinition } from "../providers/types.js";
|
|
4
4
|
import { ACTIVATION_MOMENT_PARAMS } from "../telemetry/activation-funnel.js";
|
|
5
|
-
import {
|
|
6
|
-
injectActivationMomentParam,
|
|
7
|
-
projectUiToolsForChannel,
|
|
8
|
-
} from "../tools/ui-surface/channel-variants.js";
|
|
5
|
+
import { injectActivationMomentParam } from "../tools/ui-surface/channel-variants.js";
|
|
9
6
|
import {
|
|
10
7
|
uiDismissTool,
|
|
11
8
|
uiShowTool,
|
|
@@ -23,58 +20,6 @@ const defs: ToolDefinition[] = [
|
|
|
23
20
|
},
|
|
24
21
|
];
|
|
25
22
|
|
|
26
|
-
function surfaceTypeEnum(def: ToolDefinition): string[] {
|
|
27
|
-
return (
|
|
28
|
-
def.input_schema as { properties: { surface_type: { enum: string[] } } }
|
|
29
|
-
).properties.surface_type.enum;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe("projectUiToolsForChannel", () => {
|
|
33
|
-
test("returns the same array for channels without a variant", () => {
|
|
34
|
-
for (const channel of [undefined, "macos", "telegram", "phone"]) {
|
|
35
|
-
expect(projectUiToolsForChannel(defs, channel)).toBe(defs);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("slack gets a task_progress-only ui_show", () => {
|
|
40
|
-
const projected = projectUiToolsForChannel(defs, "slack");
|
|
41
|
-
const uiShow = projected.find((d) => d.name === "ui_show")!;
|
|
42
|
-
|
|
43
|
-
expect(surfaceTypeEnum(uiShow)).toEqual(["card"]);
|
|
44
|
-
expect(uiShow.description).toContain("task_progress");
|
|
45
|
-
expect(uiShow.description).toContain(
|
|
46
|
-
"the only surface this channel renders",
|
|
47
|
-
);
|
|
48
|
-
expect(uiShow.description).not.toContain("oauth_connect");
|
|
49
|
-
expect(uiShow.description).not.toContain("dynamic_page");
|
|
50
|
-
expect(uiShow.description!.length).toBeLessThan(
|
|
51
|
-
uiShowTool.description.length / 2,
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("slack projection keeps execute and leaves other tools untouched", () => {
|
|
56
|
-
const projected = projectUiToolsForChannel(defs, "slack");
|
|
57
|
-
const uiShow = projected.find((d) => d.name === "ui_show") as {
|
|
58
|
-
execute?: unknown;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
expect(uiShow.execute).toBe(uiShowTool.execute);
|
|
62
|
-
expect(projected.find((d) => d.name === "ui_update")).toBe(uiUpdateTool);
|
|
63
|
-
expect(projected.find((d) => d.name === "ui_dismiss")).toBe(uiDismissTool);
|
|
64
|
-
expect(projected.find((d) => d.name === "bash")).toBe(defs[3]);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("projection never mutates the shared definitions", () => {
|
|
68
|
-
const descriptionBefore = uiShowTool.description;
|
|
69
|
-
const schemaBefore = JSON.stringify(uiShowTool.input_schema);
|
|
70
|
-
|
|
71
|
-
projectUiToolsForChannel(defs, "slack");
|
|
72
|
-
|
|
73
|
-
expect(uiShowTool.description).toBe(descriptionBefore);
|
|
74
|
-
expect(JSON.stringify(uiShowTool.input_schema)).toBe(schemaBefore);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
23
|
describe("injectActivationMomentParam", () => {
|
|
79
24
|
function properties(def: ToolDefinition): Record<string, unknown> {
|
|
80
25
|
return (def.input_schema as { properties: Record<string, unknown> })
|
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
HOLD_VERDICT_TOKEN,
|
|
7
7
|
isIncompleteControlMarkerTail,
|
|
8
8
|
MINIMIZE_ROOM_MARKER,
|
|
9
|
+
parseTerminalSessionControl,
|
|
10
|
+
type SessionControlRequest,
|
|
9
11
|
stripInternalSpeechMarkers,
|
|
12
|
+
terminalControlMarkerLength,
|
|
10
13
|
} from "../voice-control-protocol.js";
|
|
11
14
|
|
|
12
15
|
describe("front-door verdict tokens", () => {
|
|
@@ -136,3 +139,62 @@ describe("createControlMarkerHoldback", () => {
|
|
|
136
139
|
expect(chunks).toEqual([]);
|
|
137
140
|
});
|
|
138
141
|
});
|
|
142
|
+
|
|
143
|
+
describe("session control markers", () => {
|
|
144
|
+
test("strips untimed and timed mute markers", () => {
|
|
145
|
+
expect(stripInternalSpeechMarkers("Muted. [MUTE]").trim()).toBe("Muted.");
|
|
146
|
+
expect(stripInternalSpeechMarkers("Muted. [MUTE:30]").trim()).toBe(
|
|
147
|
+
"Muted.",
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("holds a streaming timed mute until its bracket arrives", () => {
|
|
152
|
+
expect(isIncompleteControlMarkerTail("[MU")).toBe(true);
|
|
153
|
+
expect(isIncompleteControlMarkerTail("[MUTE:3")).toBe(true);
|
|
154
|
+
expect(isIncompleteControlMarkerTail("[MUTE:30]")).toBe(false);
|
|
155
|
+
expect(isIncompleteControlMarkerTail("[UPDATES:FEW")).toBe(true);
|
|
156
|
+
expect(isIncompleteControlMarkerTail("[UPDATES:FEWER]")).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test.each([
|
|
160
|
+
["Okay, talk soon. [END_CALL]", { action: "end" }],
|
|
161
|
+
["Muted. [MUTE]", { action: "mute" }],
|
|
162
|
+
[
|
|
163
|
+
"I'll check in less. [UPDATES:FEWER]",
|
|
164
|
+
{ action: "updates", cadence: "fewer" },
|
|
165
|
+
],
|
|
166
|
+
[
|
|
167
|
+
"Updates are back on. [UPDATES:NORMAL]",
|
|
168
|
+
{ action: "updates", cadence: "normal" },
|
|
169
|
+
],
|
|
170
|
+
[
|
|
171
|
+
"Muting for half a minute. [MUTE:30] ",
|
|
172
|
+
{ action: "mute", durationMs: 30_000 },
|
|
173
|
+
],
|
|
174
|
+
["Muted. [MUTE: 1.5]", { action: "mute", durationMs: 1_500 }],
|
|
175
|
+
// A garbled or oversized duration still mutes, just until unmuted.
|
|
176
|
+
["Muted. [MUTE:soon]", { action: "mute" }],
|
|
177
|
+
["Muted. [MUTE:0]", { action: "mute" }],
|
|
178
|
+
["Muted. [MUTE:99999]", { action: "mute" }],
|
|
179
|
+
] as Array<[string, SessionControlRequest]>)(
|
|
180
|
+
"parses the terminal control in %j",
|
|
181
|
+
(text, expected) => {
|
|
182
|
+
expect(parseTerminalSessionControl(text)).toEqual(expected);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
test("a marker anywhere but the end controls nothing", () => {
|
|
187
|
+
expect(
|
|
188
|
+
parseTerminalSessionControl("Say [END_CALL] and I would hang up."),
|
|
189
|
+
).toBeNull();
|
|
190
|
+
expect(parseTerminalSessionControl("No markers here.")).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("measures the terminal marker the transcript pass strips", () => {
|
|
194
|
+
expect(terminalControlMarkerLength("Done [-1]")).toBe(4);
|
|
195
|
+
expect(terminalControlMarkerLength("Bye [END_CALL] ")).toBe(10);
|
|
196
|
+
expect(terminalControlMarkerLength("Muted [MUTE:30]")).toBe(9);
|
|
197
|
+
expect(terminalControlMarkerLength("Okay [UPDATES:FEWER]")).toBe(15);
|
|
198
|
+
expect(terminalControlMarkerLength("The array [-1] sorts")).toBe(0);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -2513,6 +2513,25 @@ describe("transcript hygiene (teardown pass)", () => {
|
|
|
2513
2513
|
expect(events).toContain("loadFromDb");
|
|
2514
2514
|
});
|
|
2515
2515
|
|
|
2516
|
+
test("a row ending with a session control marker persists with it stripped", async () => {
|
|
2517
|
+
const { events } = makeReservedRowConversation();
|
|
2518
|
+
getMessageByIdImpl = () =>
|
|
2519
|
+
makeRow("Muting you for thirty seconds. [MUTE:30]");
|
|
2520
|
+
|
|
2521
|
+
await startVoiceTurn({ ...makeTurnOptions(), routingLeg: "front-door" });
|
|
2522
|
+
await flushMicrotasks();
|
|
2523
|
+
|
|
2524
|
+
expect(crudLog.updates).toEqual([
|
|
2525
|
+
{
|
|
2526
|
+
messageId: "assistant-row-1",
|
|
2527
|
+
content: JSON.stringify([
|
|
2528
|
+
{ type: "text", text: "Muting you for thirty seconds." },
|
|
2529
|
+
]),
|
|
2530
|
+
},
|
|
2531
|
+
]);
|
|
2532
|
+
expect(events).toContain("loadFromDb");
|
|
2533
|
+
});
|
|
2534
|
+
|
|
2516
2535
|
test("a mid-text [-1] (content, not command) leaves the row untouched", async () => {
|
|
2517
2536
|
const { events } = makeReservedRowConversation();
|
|
2518
2537
|
getMessageByIdImpl = () =>
|
|
@@ -37,6 +37,29 @@ export const ESCALATE_VERDICT_TOKEN = "[1]";
|
|
|
37
37
|
*/
|
|
38
38
|
export const MINIMIZE_ROOM_MARKER = "[-1]";
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Mic-mute session control for live voice: `[MUTE]` mutes until the user
|
|
42
|
+
* unmutes, `[MUTE:<seconds>]` mutes for that long. Like {@link END_CALL_MARKER}
|
|
43
|
+
* on a live-voice session, it is acted on only at the very end of a reply
|
|
44
|
+
* (see {@link parseTerminalSessionControl}), after the acknowledgement that
|
|
45
|
+
* precedes it has been spoken.
|
|
46
|
+
*/
|
|
47
|
+
export const MUTE_MARKER = "[MUTE]";
|
|
48
|
+
const MUTE_MARKER_PREFIX = "[MUTE:";
|
|
49
|
+
|
|
50
|
+
/** Longest timed mute a marker can ask for; longer asks mute until unmuted. */
|
|
51
|
+
export const MAX_TIMED_MUTE_SECONDS = 3600;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Progress-update cadence for the rest of a live-voice session:
|
|
55
|
+
* {@link FEWER_UPDATES_MARKER} after "don't give me updates so often",
|
|
56
|
+
* {@link NORMAL_UPDATES_MARKER} to go back. Terminal like the other session
|
|
57
|
+
* controls, but carried out by the session itself: narration is the daemon's.
|
|
58
|
+
*/
|
|
59
|
+
export const FEWER_UPDATES_MARKER = "[UPDATES:FEWER]";
|
|
60
|
+
export const NORMAL_UPDATES_MARKER = "[UPDATES:NORMAL]";
|
|
61
|
+
const UPDATES_MARKER_PREFIX = "[UPDATES:";
|
|
62
|
+
|
|
40
63
|
// ---------------------------------------------------------------------------
|
|
41
64
|
// Regexes
|
|
42
65
|
// ---------------------------------------------------------------------------
|
|
@@ -57,6 +80,8 @@ const END_CALL_MARKER_REGEX = /\[END_CALL\]/g;
|
|
|
57
80
|
const HOLD_VERDICT_TOKEN_REGEX = /\[0\]/g;
|
|
58
81
|
const ESCALATE_VERDICT_TOKEN_REGEX = /\[1\]/g;
|
|
59
82
|
const MINIMIZE_ROOM_MARKER_REGEX = /\[-1\]/g;
|
|
83
|
+
const MUTE_MARKER_REGEX = /\[MUTE(?::\s*[^\]]*)?\]/g;
|
|
84
|
+
const UPDATES_MARKER_REGEX = /\[UPDATES:\s*[^\]]*\]/g;
|
|
60
85
|
const GUARDIAN_TIMEOUT_MARKER_REGEX = /\[GUARDIAN_TIMEOUT\]/g;
|
|
61
86
|
const GUARDIAN_UNAVAILABLE_MARKER_REGEX = /\[GUARDIAN_UNAVAILABLE\]/g;
|
|
62
87
|
|
|
@@ -182,6 +207,8 @@ export function stripInternalSpeechMarkers(text: string): string {
|
|
|
182
207
|
.replace(HOLD_VERDICT_TOKEN_REGEX, "")
|
|
183
208
|
.replace(ESCALATE_VERDICT_TOKEN_REGEX, "")
|
|
184
209
|
.replace(MINIMIZE_ROOM_MARKER_REGEX, "")
|
|
210
|
+
.replace(MUTE_MARKER_REGEX, "")
|
|
211
|
+
.replace(UPDATES_MARKER_REGEX, "")
|
|
185
212
|
.replace(GUARDIAN_TIMEOUT_MARKER_REGEX, "")
|
|
186
213
|
.replace(GUARDIAN_UNAVAILABLE_MARKER_REGEX, "");
|
|
187
214
|
return result;
|
|
@@ -207,6 +234,9 @@ const CONTROL_MARKER_STRINGS = [
|
|
|
207
234
|
"[0]",
|
|
208
235
|
"[1]",
|
|
209
236
|
"[-1]",
|
|
237
|
+
MUTE_MARKER,
|
|
238
|
+
MUTE_MARKER_PREFIX,
|
|
239
|
+
UPDATES_MARKER_PREFIX,
|
|
210
240
|
"[GUARDIAN_TIMEOUT]",
|
|
211
241
|
"[GUARDIAN_UNAVAILABLE]",
|
|
212
242
|
];
|
|
@@ -220,6 +250,8 @@ const FIRST_BRACKET_TERMINATED_PREFIXES = [
|
|
|
220
250
|
"[ASK_GUARDIAN:",
|
|
221
251
|
"[USER_ANSWERED:",
|
|
222
252
|
"[USER_INSTRUCTION:",
|
|
253
|
+
MUTE_MARKER_PREFIX,
|
|
254
|
+
UPDATES_MARKER_PREFIX,
|
|
223
255
|
];
|
|
224
256
|
|
|
225
257
|
const GUARDIAN_APPROVAL_PREFIX = "[ASK_GUARDIAN_APPROVAL:";
|
|
@@ -299,3 +331,73 @@ export function createControlMarkerHoldback(
|
|
|
299
331
|
}
|
|
300
332
|
};
|
|
301
333
|
}
|
|
334
|
+
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
// Live-voice session controls
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A session control a live-voice reply asked for with a terminal marker:
|
|
341
|
+
* `end` from {@link END_CALL_MARKER}, `mute` from {@link MUTE_MARKER} or its
|
|
342
|
+
* timed form, `updates` from the progress-cadence markers.
|
|
343
|
+
*/
|
|
344
|
+
export type SessionControlRequest =
|
|
345
|
+
| { readonly action: "end" }
|
|
346
|
+
| { readonly action: "mute"; readonly durationMs?: number }
|
|
347
|
+
| { readonly action: "updates"; readonly cadence: "fewer" | "normal" };
|
|
348
|
+
|
|
349
|
+
const TERMINAL_SESSION_CONTROL_REGEX =
|
|
350
|
+
/(\[END_CALL\]|\[UPDATES:(FEWER|NORMAL)\]|\[MUTE\]|\[MUTE:\s*([^\]]*)\])\s*$/;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The session control a reply ends with, or null.
|
|
354
|
+
*
|
|
355
|
+
* **Terminal position only.** The marker follows the spoken acknowledgement
|
|
356
|
+
* ("Okay, talk soon."), so a reply that merely mentions a marker mid-text, or
|
|
357
|
+
* parrots one from history before carrying on, controls nothing. This is the
|
|
358
|
+
* same rule the minimize marker's transcript hygiene applies.
|
|
359
|
+
*
|
|
360
|
+
* A timed mute whose body is not a positive number of seconds degrades to an
|
|
361
|
+
* untimed mute rather than to nothing: the user asked to be muted, and muting
|
|
362
|
+
* until they unmute is the conservative reading of a garbled duration. Asks
|
|
363
|
+
* past {@link MAX_TIMED_MUTE_SECONDS} degrade the same way.
|
|
364
|
+
*/
|
|
365
|
+
export function parseTerminalSessionControl(
|
|
366
|
+
text: string,
|
|
367
|
+
): SessionControlRequest | null {
|
|
368
|
+
const match = TERMINAL_SESSION_CONTROL_REGEX.exec(text);
|
|
369
|
+
if (!match) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
if (match[1] === END_CALL_MARKER) {
|
|
373
|
+
return { action: "end" };
|
|
374
|
+
}
|
|
375
|
+
if (match[2] !== undefined) {
|
|
376
|
+
return {
|
|
377
|
+
action: "updates",
|
|
378
|
+
cadence: match[2] === "FEWER" ? "fewer" : "normal",
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const seconds = match[3] === undefined ? NaN : Number(match[3].trim());
|
|
382
|
+
if (
|
|
383
|
+
Number.isFinite(seconds) &&
|
|
384
|
+
seconds > 0 &&
|
|
385
|
+
seconds <= MAX_TIMED_MUTE_SECONDS
|
|
386
|
+
) {
|
|
387
|
+
return { action: "mute", durationMs: Math.round(seconds * 1000) };
|
|
388
|
+
}
|
|
389
|
+
return { action: "mute" };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Length of the marker a row's text ends with, ignoring trailing whitespace,
|
|
394
|
+
* when it is one the transcript hygiene pass strips from the persisted row
|
|
395
|
+
* (the minimize marker or a session control); 0 otherwise.
|
|
396
|
+
*/
|
|
397
|
+
export function terminalControlMarkerLength(text: string): number {
|
|
398
|
+
const trimmed = text.trimEnd();
|
|
399
|
+
if (trimmed.endsWith(MINIMIZE_ROOM_MARKER)) {
|
|
400
|
+
return MINIMIZE_ROOM_MARKER.length;
|
|
401
|
+
}
|
|
402
|
+
return TERMINAL_SESSION_CONTROL_REGEX.exec(trimmed)?.[1]?.length ?? 0;
|
|
403
|
+
}
|
|
@@ -70,8 +70,8 @@ import {
|
|
|
70
70
|
CALL_VERIFICATION_COMPLETE_MARKER,
|
|
71
71
|
ESCALATE_VERDICT_TOKEN,
|
|
72
72
|
HOLD_VERDICT_TOKEN,
|
|
73
|
-
MINIMIZE_ROOM_MARKER,
|
|
74
73
|
stripInternalSpeechMarkers,
|
|
74
|
+
terminalControlMarkerLength,
|
|
75
75
|
} from "./voice-control-protocol.js";
|
|
76
76
|
import {
|
|
77
77
|
createFrontDoorStreamGate,
|
|
@@ -767,17 +767,22 @@ function stripMarkersFromBlocks(blocks: ContentBlock[]): ContentBlock[] {
|
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
/**
|
|
770
|
-
* Remove
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
770
|
+
* Remove a terminal control marker (the minimize marker or a session control,
|
|
771
|
+
* `markerLength` characters long) from the end of a row's text, walking text
|
|
772
|
+
* blocks from the last one backward so a marker split across block boundaries
|
|
773
|
+
* (e.g. `"Done [-"` + `"1]"`) is removed whole — the per-block strip in
|
|
774
|
+
* {@link stripMarkersFromBlocks} only sees fragments and would leave both
|
|
775
|
+
* halves in place. Callers must have established, with
|
|
776
|
+
* {@link terminalControlMarkerLength}, that the row's joined text ends with
|
|
777
|
+
* the marker after trimming trailing whitespace.
|
|
776
778
|
*/
|
|
777
|
-
function
|
|
779
|
+
function stripTerminalControlMarker(
|
|
780
|
+
blocks: ContentBlock[],
|
|
781
|
+
markerLength: number,
|
|
782
|
+
): ContentBlock[] {
|
|
778
783
|
const result = blocks.map((block) => ({ ...block }));
|
|
779
784
|
const joined = joinedTextOfBlocks(result);
|
|
780
|
-
const cutAt = joined.trimEnd().length -
|
|
785
|
+
const cutAt = joined.trimEnd().length - markerLength;
|
|
781
786
|
let blockEnd = joined.length;
|
|
782
787
|
for (let i = result.length - 1; i >= 0 && blockEnd > cutAt; i--) {
|
|
783
788
|
const block = result[i]!;
|
|
@@ -1810,14 +1815,14 @@ export async function startVoiceTurn(
|
|
|
1810
1815
|
* never the verdict token or the text streamed past the cap (issue
|
|
1811
1816
|
* #37850). A row with no spoken bridge (canned-fallback case — that
|
|
1812
1817
|
* bridge is audio-only) is deleted.
|
|
1813
|
-
* - Any leg whose row ENDS with the `[-1]` minimize marker
|
|
1814
|
-
*
|
|
1818
|
+
* - Any leg whose row ENDS with the `[-1]` minimize marker or a session
|
|
1819
|
+
* control marker (`[END_CALL]`, `[MUTE]`, `[MUTE:<seconds>]`), all
|
|
1820
|
+
* swallowed before TTS, has its text blocks rewritten through
|
|
1815
1821
|
* `stripInternalSpeechMarkers` so the marker never renders in the chat
|
|
1816
|
-
* transcript. This covers front-door answers too:
|
|
1817
|
-
*
|
|
1818
|
-
* history
|
|
1819
|
-
*
|
|
1820
|
-
* persist byte-identical.
|
|
1822
|
+
* transcript. This covers front-door answers too: a front-door answer
|
|
1823
|
+
* may end with a session control, and it can parrot `[-1]` from visible
|
|
1824
|
+
* conversation history. Deliberately scoped to terminal markers: rows
|
|
1825
|
+
* without one persist byte-identical.
|
|
1821
1826
|
*
|
|
1822
1827
|
* After a rewrite, in-memory history is reloaded from the clean DB before
|
|
1823
1828
|
* the escalated leg — blocked on this turn's teardown — snapshots it, so
|
|
@@ -1851,6 +1856,9 @@ export async function startVoiceTurn(
|
|
|
1851
1856
|
action = "delete_discarded";
|
|
1852
1857
|
} else {
|
|
1853
1858
|
const row = getMessageById(reservedAssistantRowId, opts.conversationId);
|
|
1859
|
+
const terminalMarkerLength = row
|
|
1860
|
+
? terminalControlMarkerLength(joinedTextOfBlocks(row.content))
|
|
1861
|
+
: 0;
|
|
1854
1862
|
const cut =
|
|
1855
1863
|
row && opts.routingLeg === "front-door"
|
|
1856
1864
|
? cutFrontDoorContentAtVerdict(row.content)
|
|
@@ -1869,19 +1877,18 @@ export async function startVoiceTurn(
|
|
|
1869
1877
|
action = "delete_empty";
|
|
1870
1878
|
}
|
|
1871
1879
|
} else if (
|
|
1872
|
-
// Terminal position only — mirrors
|
|
1873
|
-
//
|
|
1874
|
-
//
|
|
1875
|
-
//
|
|
1876
|
-
|
|
1877
|
-
joinedTextOfBlocks(row.content)
|
|
1878
|
-
.trimEnd()
|
|
1879
|
-
.endsWith(MINIMIZE_ROOM_MARKER)
|
|
1880
|
+
// Terminal position only — mirrors parseTerminalSessionControl: a
|
|
1881
|
+
// reply whose CONTENT contains a marker mid-text never acted on it,
|
|
1882
|
+
// so its transcript keeps that content untouched too. Front-door
|
|
1883
|
+
// answer rows (no verdict token to cut) take this branch as well.
|
|
1884
|
+
terminalMarkerLength > 0
|
|
1880
1885
|
) {
|
|
1881
1886
|
// Terminal marker first (boundary-aware — it may span text blocks),
|
|
1882
1887
|
// then the per-block strip for any interior complete markers.
|
|
1883
1888
|
const cleaned = trimOuterTextEdges(
|
|
1884
|
-
stripMarkersFromBlocks(
|
|
1889
|
+
stripMarkersFromBlocks(
|
|
1890
|
+
stripTerminalControlMarker(row.content, terminalMarkerLength),
|
|
1891
|
+
),
|
|
1885
1892
|
);
|
|
1886
1893
|
// A marker-only reply (the model said nothing beyond "[-1]") strips
|
|
1887
1894
|
// to nothing at all; keeping the row would render a blank assistant
|
|
@@ -1895,7 +1902,7 @@ export async function startVoiceTurn(
|
|
|
1895
1902
|
reservedAssistantRowId,
|
|
1896
1903
|
JSON.stringify(cleaned),
|
|
1897
1904
|
);
|
|
1898
|
-
action = "
|
|
1905
|
+
action = "strip_control_marker";
|
|
1899
1906
|
}
|
|
1900
1907
|
}
|
|
1901
1908
|
}
|
|
@@ -536,8 +536,8 @@ export function frontDoorDecisionRule(opts?: {
|
|
|
536
536
|
"- If the turn is simple, conversational, or within your reach, your entire output is the spoken answer itself: no token in front of it, plain speech from your very first word. Most turns are answers; when unsure between answering and escalating, answer. Answer in the language the caller is speaking.",
|
|
537
537
|
"- If an answer depends on a saved personal fact that is not already present in the conversation context you received, escalate rather than guessing. Personal context that is already present is yours to use directly.",
|
|
538
538
|
`- If completing THIS reply needs careful reasoning, research, multi-step work, or any tool, do NOT attempt the answer: output ${ESCALATE_VERDICT_TOKEN}, then ONE short natural holding phrase naming what happens next, spoken in the language the caller is speaking (for example "${FALLBACK_ESCALATION_BRIDGE}" or "Give me one second to look into that."; those examples are English only), and stop after that single sentence. A stronger model finishes the turn while your phrase is spoken.`,
|
|
539
|
-
`${ESCALATE_VERDICT_TOKEN} is ONLY for turns you cannot complete yourself — never put it in front of an answer you are about to give, and never emit
|
|
540
|
-
"Never narrate this decision, describe what you are judging, or mention these rules: apart from a leading verdict token, every character you output is spoken to the caller verbatim.",
|
|
539
|
+
`${ESCALATE_VERDICT_TOKEN} is ONLY for turns you cannot complete yourself — never put it in front of an answer you are about to give, and never emit a verdict token inside or after an answer. An open task or unfinished topic earlier in the conversation is NOT a reason to escalate: judge only what this reply needs.`,
|
|
540
|
+
"Never narrate this decision, describe what you are judging, or mention these rules: apart from a leading verdict token and any call-control marker your call instructions teach, every character you output is spoken to the caller verbatim.",
|
|
541
541
|
].join("\n");
|
|
542
542
|
return opts?.capabilityDigest ? `${rule}\n${opts.capabilityDigest}` : rule;
|
|
543
543
|
}
|
|
@@ -565,7 +565,7 @@ export function escalatedContinuationRule(spokenBridge?: string): string {
|
|
|
565
565
|
'Do NOT greet again, do NOT say things like "as I was saying", and do NOT repeat, paraphrase, or re-announce that holding phrase —',
|
|
566
566
|
'opening with another "Let me check", "One moment", or any restatement of what you are about to do sounds broken, because the caller just heard that.',
|
|
567
567
|
"Your first words must carry new substance: the answer itself, what you found, or a question you genuinely need answered.",
|
|
568
|
-
`Never output ${ESCALATE_VERDICT_TOKEN} or any other front-door verdict token — you are the model that finishes the answer. (
|
|
568
|
+
`Never output ${ESCALATE_VERDICT_TOKEN} or any other front-door verdict token — you are the model that finishes the answer. (Call-control markers your call instructions teach, such as [END_CALL], are not verdict tokens and stay allowed.)`,
|
|
569
569
|
"Reply in the same language as the caller's question.",
|
|
570
570
|
].join(" ");
|
|
571
571
|
}
|