@vellumai/assistant 0.11.1-dev.202608032034.aebd2da → 0.11.1-dev.202608032226.351a4e2

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.
Files changed (47) hide show
  1. package/openapi.yaml +1 -0
  2. package/package.json +1 -1
  3. package/src/__tests__/agent-loop-resume-interrupted.test.ts +223 -0
  4. package/src/__tests__/conversation-agent-loop.test.ts +16 -7
  5. package/src/__tests__/conversation-error.test.ts +106 -0
  6. package/src/__tests__/llm-resolver.test.ts +16 -0
  7. package/src/__tests__/provider-send-message-override-profile.test.ts +95 -0
  8. package/src/__tests__/workspace-migration-137-repair-retired-fireworks-minimax-model-id.test.ts +6 -6
  9. package/src/__tests__/workspace-migration-138-backfill-home-feed-titles.test.ts +373 -0
  10. package/src/agent/loop.ts +36 -7
  11. package/src/cli/commands/notifications.help.ts +3 -2
  12. package/src/config/llm-resolver.ts +19 -3
  13. package/src/daemon/conversation-agent-loop-handlers.ts +15 -6
  14. package/src/daemon/conversation-agent-loop.ts +31 -18
  15. package/src/daemon/conversation-error.ts +40 -24
  16. package/src/home/__tests__/feed-types.test.ts +43 -8
  17. package/src/home/__tests__/feed-writer.test.ts +59 -0
  18. package/src/home/feed-types.ts +34 -7
  19. package/src/home/feed-writer.ts +15 -6
  20. package/src/live-voice/__tests__/activity-label.test.ts +68 -0
  21. package/src/live-voice/__tests__/live-activity-reporter.test.ts +86 -5
  22. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +14 -5
  23. package/src/live-voice/activity-label.ts +106 -0
  24. package/src/live-voice/live-activity-reporter.ts +35 -6
  25. package/src/live-voice/live-voice-session.ts +58 -0
  26. package/src/live-voice/protocol.ts +23 -0
  27. package/src/notifications/__tests__/copy-composer.test.ts +53 -3
  28. package/src/notifications/__tests__/decision-engine.test.ts +150 -20
  29. package/src/notifications/__tests__/edit-notification.test.ts +330 -0
  30. package/src/notifications/__tests__/home-feed-side-effect.test.ts +170 -12
  31. package/src/notifications/copy-composer.ts +23 -3
  32. package/src/notifications/decision-engine.ts +29 -7
  33. package/src/notifications/edit-notification.ts +8 -4
  34. package/src/notifications/home-feed-side-effect.ts +43 -6
  35. package/src/notifications/notification-utils.ts +8 -2
  36. package/src/persistence/conversation-title-service.ts +5 -170
  37. package/src/providers/__tests__/dispatch-connection-routing.test.ts +43 -2
  38. package/src/providers/__tests__/vellum-mismatch-routing.test.ts +8 -0
  39. package/src/providers/call-site-routing.ts +77 -14
  40. package/src/providers/connection-resolution.ts +42 -2
  41. package/src/providers/types.ts +7 -1
  42. package/src/runtime/routes/notification-routes.ts +4 -1
  43. package/src/util/__tests__/short-title.test.ts +229 -0
  44. package/src/util/errors.ts +15 -0
  45. package/src/util/short-title.ts +189 -0
  46. package/src/workspace/migrations/138-backfill-home-feed-titles.ts +179 -0
  47. package/src/workspace/migrations/registry.ts +2 -0
@@ -63,6 +63,8 @@ export interface ClassifiedConversationError {
63
63
  export interface ConversationErrorAttribution {
64
64
  connectionName?: string;
65
65
  profileName?: string;
66
+ /** Whether the resolved turn route uses Vellum-managed inference. */
67
+ isManagedRoute?: boolean;
66
68
  }
67
69
 
68
70
  // Network-level error patterns (connection refused, timeout, DNS, reset)
@@ -181,6 +183,11 @@ export interface ErrorContext {
181
183
  * underlying connection name is generic.
182
184
  */
183
185
  profileName?: string;
186
+ /**
187
+ * Whether the resolved turn route uses Vellum-managed inference. Turn routing
188
+ * takes precedence over the provider registry's boot-time default.
189
+ */
190
+ isManagedRoute?: boolean;
184
191
  }
185
192
 
186
193
  /**
@@ -253,9 +260,19 @@ export function classifyConversationError(
253
260
  // credential-related classifications can name the exact slot to fix.
254
261
  // A `ProviderNotConfiguredError` instance carries its own attribution
255
262
  // (from the throw site) which takes priority over context when present.
263
+ // The failed call's own route wins field by field — it is resolved at
264
+ // dispatch, while context describes the turn and can be stale for this
265
+ // call. Per-field, so a route carrying only some fields doesn't blank the
266
+ // rest.
267
+ const providerRoute =
268
+ error instanceof ProviderError ? error.routeAttribution : undefined;
269
+ const connectionName = providerRoute?.connectionName ?? ctx.connectionName;
270
+ const profileName = providerRoute?.profileName ?? ctx.profileName;
271
+ const isManagedRoute = providerRoute?.isManagedRoute ?? ctx.isManagedRoute;
256
272
  const attribution: ConversationErrorAttribution = {
257
- ...(ctx.connectionName ? { connectionName: ctx.connectionName } : {}),
258
- ...(ctx.profileName ? { profileName: ctx.profileName } : {}),
273
+ ...(connectionName ? { connectionName } : {}),
274
+ ...(profileName ? { profileName } : {}),
275
+ ...(isManagedRoute !== undefined ? { isManagedRoute } : {}),
259
276
  };
260
277
 
261
278
  // Dedicated classification for missing provider API key
@@ -354,13 +371,18 @@ function classifyCore(
354
371
  message: string,
355
372
  attribution: ConversationErrorAttribution = {},
356
373
  ): Omit<ClassifiedConversationError, "debugDetails"> {
374
+ const isManagedRoute =
375
+ error instanceof ProviderError &&
376
+ (attribution.isManagedRoute ??
377
+ getProviderRoutingSource(error.provider) === "managed-proxy");
378
+
357
379
  // Prefer the semantic reason stamped by the provider layer, regardless of
358
380
  // HTTP status — statusless errors (e.g. SDK streaming failures) still carry a
359
381
  // reason. Reasons that map cleanly win here; `bad_request`/`unknown` (and a
360
382
  // reason-less error) fall through to the status switch + regex battery below.
361
383
  if (error instanceof ProviderError && error.reason) {
362
384
  const c = reasonToClassification(error.reason, {
363
- routingSource: getProviderRoutingSource(error.provider),
385
+ isManagedRoute,
364
386
  attribution,
365
387
  message,
366
388
  });
@@ -382,20 +404,19 @@ function classifyCore(
382
404
  // Everything else is a user-set credential that the upstream provider
383
405
  // rejected, so emit `PROVIDER_INVALID_KEY` and let the chat banner point
384
406
  // at Settings.
385
- const providerName = error.provider;
386
- if (getProviderRoutingSource(providerName) === "managed-proxy") {
407
+ if (isManagedRoute) {
387
408
  return managedKeyInvalidClassification();
388
409
  }
389
410
  return invalidApiKeyClassification(attribution);
390
411
  }
391
412
  if (error.statusCode === 402) {
392
- if (isManagedBalanceError(error)) {
413
+ if (isManagedRoute) {
393
414
  return managedBalanceClassification();
394
415
  }
395
416
  return providerBillingClassification();
396
417
  }
397
418
  if (error.statusCode === 429) {
398
- if (isManagedUsageLimitError(error, message)) {
419
+ if (isManagedUsageLimitError(message, isManagedRoute)) {
399
420
  return managedUsageLimitClassification();
400
421
  }
401
422
  return rateLimitClassification();
@@ -508,7 +529,7 @@ function classifyCore(
508
529
  }
509
530
 
510
531
  // Regex fallback for non-ProviderError or ProviderError without statusCode
511
- return classifyByMessage(error, message);
532
+ return classifyByMessage(message, isManagedRoute);
512
533
  }
513
534
 
514
535
  /**
@@ -540,12 +561,12 @@ function extractProviderDetail(message: string): string | undefined {
540
561
  function reasonToClassification(
541
562
  reason: ProviderErrorReason,
542
563
  args: {
543
- routingSource?: string;
564
+ isManagedRoute: boolean;
544
565
  attribution?: ConversationErrorAttribution;
545
566
  message: string;
546
567
  },
547
568
  ): Omit<ClassifiedConversationError, "debugDetails"> | null {
548
- const managed = args.routingSource === "managed-proxy";
569
+ const managed = args.isManagedRoute;
549
570
  switch (reason) {
550
571
  case "invalid_credentials":
551
572
  return managed
@@ -670,18 +691,13 @@ function isStreamingError(message: string): boolean {
670
691
  return STREAMING_ERROR_PATTERNS.some((p) => p.test(message));
671
692
  }
672
693
 
673
- function isManagedUsageLimitError(error: unknown, message: string): boolean {
674
- if (
675
- error instanceof ProviderError &&
676
- getProviderRoutingSource(error.provider) === "managed-proxy"
677
- ) {
678
- return true;
679
- }
680
- return MANAGED_USAGE_LIMIT_PATTERNS.some((p) => p.test(message));
681
- }
682
-
683
- function isManagedBalanceError(error: ProviderError): boolean {
684
- return getProviderRoutingSource(error.provider) === "managed-proxy";
694
+ function isManagedUsageLimitError(
695
+ message: string,
696
+ isManagedRoute: boolean,
697
+ ): boolean {
698
+ return (
699
+ isManagedRoute || MANAGED_USAGE_LIMIT_PATTERNS.some((p) => p.test(message))
700
+ );
685
701
  }
686
702
 
687
703
  function isProviderBillingError(message: string): boolean {
@@ -912,8 +928,8 @@ function providerNotConfiguredClassification(
912
928
  * short-circuit and the status switch both decline to classify.
913
929
  */
914
930
  function classifyByMessage(
915
- error: unknown,
916
931
  message: string,
932
+ isManagedRoute: boolean,
917
933
  ): Omit<ClassifiedConversationError, "debugDetails"> {
918
934
  // Empty-request-messages is always an internal construction failure — check
919
935
  // it before the provider/network patterns so a ProviderError that carries the
@@ -930,7 +946,7 @@ function classifyByMessage(
930
946
  // Check rate limit first (before network, since 429 could match both)
931
947
  for (const pattern of RATE_LIMIT_PATTERNS) {
932
948
  if (pattern.test(message)) {
933
- if (isManagedUsageLimitError(error, message)) {
949
+ if (isManagedUsageLimitError(message, isManagedRoute)) {
934
950
  return managedUsageLimitClassification();
935
951
  }
936
952
  return rateLimitClassification();
@@ -257,14 +257,49 @@ describe("parseFeedFile", () => {
257
257
  ).toThrow();
258
258
  });
259
259
 
260
- test("throws when an item in the file is invalid", () => {
261
- expect(() =>
262
- parseFeedFile({
263
- version: 2,
264
- items: [{ ...minimalNotification(), priority: 999 }],
265
- updatedAt: NOW_ISO,
266
- }),
267
- ).toThrow();
260
+ test("throws when `items` is missing entirely", () => {
261
+ expect(() => parseFeedFile({ version: 2, updatedAt: NOW_ISO })).toThrow();
262
+ });
263
+
264
+ test("throws when `updatedAt` is missing", () => {
265
+ expect(() => parseFeedFile({ version: 2, items: [] })).toThrow();
266
+ });
267
+
268
+ test("drops an invalid item but keeps the valid ones", () => {
269
+ const parsed = parseFeedFile({
270
+ version: 2,
271
+ items: [
272
+ minimalNotification(),
273
+ { ...minimalNotification(), id: "notif-bad", priority: 999 },
274
+ ],
275
+ updatedAt: NOW_ISO,
276
+ });
277
+ expect(parsed.items).toHaveLength(1);
278
+ expect(parsed.items[0]?.id).toBe("notif-1");
279
+ expect(parsed.droppedCount).toBe(1);
280
+ expect(parsed.updatedAt).toBe(NOW_ISO);
281
+ });
282
+
283
+ test("reports droppedCount 0 for a fully valid file", () => {
284
+ const parsed = parseFeedFile({
285
+ version: 2,
286
+ items: [minimalNotification(), notificationWithActions()],
287
+ updatedAt: NOW_ISO,
288
+ });
289
+ expect(parsed.items).toHaveLength(2);
290
+ expect(parsed.droppedCount).toBe(0);
291
+ });
292
+
293
+ test("returns an empty item list when every item is invalid", () => {
294
+ const parsed = parseFeedFile({
295
+ version: 2,
296
+ items: [{ ...minimalNotification(), type: "banner" }, null, "nope"],
297
+ updatedAt: NOW_ISO,
298
+ });
299
+ expect(parsed.items).toEqual([]);
300
+ expect(parsed.droppedCount).toBe(3);
301
+ expect(parsed.version).toBe(2);
302
+ expect(parsed.updatedAt).toBe(NOW_ISO);
268
303
  });
269
304
 
270
305
  test("accepts a file with a noteworthy item", () => {
@@ -50,6 +50,7 @@ const {
50
50
  bulkSetFeedItemStatus,
51
51
  clearAllConversationIds,
52
52
  getHomeFeedPath,
53
+ patchFeedItemContent,
53
54
  patchFeedItemStatus,
54
55
  readHomeFeed,
55
56
  stripConversationIds,
@@ -199,6 +200,23 @@ describe("feed-writer", () => {
199
200
  const feed = readHomeFeed();
200
201
  expect(feed.items).toEqual([]);
201
202
  });
203
+
204
+ test("keeps the valid items when a single row is malformed", () => {
205
+ mkdirSync(join(workspaceDir, "data"), { recursive: true });
206
+ const file = {
207
+ version: 2,
208
+ updatedAt: "2026-04-14T12:00:00.000Z",
209
+ items: [
210
+ makeItem({ id: "good" }),
211
+ { ...makeItem({ id: "bad" }), priority: 999 },
212
+ ],
213
+ };
214
+ writeFileSync(getHomeFeedPath(), JSON.stringify(file, null, 2), "utf-8");
215
+
216
+ const feed = readHomeFeed();
217
+ expect(feed.items).toHaveLength(1);
218
+ expect(feed.items[0]!.id).toBe("good");
219
+ });
202
220
  });
203
221
 
204
222
  describe("appendFeedItem", () => {
@@ -406,6 +424,47 @@ describe("feed-writer", () => {
406
424
  });
407
425
  });
408
426
 
427
+ describe("patchFeedItemContent", () => {
428
+ test("trims and applies a non-empty title", async () => {
429
+ await appendFeedItem(makeItem({ id: "item-1", title: "Original" }));
430
+
431
+ const result = await patchFeedItemContent("item-1", {
432
+ title: " Renamed ",
433
+ });
434
+
435
+ expect(result!.title).toBe("Renamed");
436
+ expect(readFileJson().items[0]!.title).toBe("Renamed");
437
+ });
438
+
439
+ test("ignores an empty or whitespace-only title instead of clearing it", async () => {
440
+ await appendFeedItem(makeItem({ id: "item-1", title: "Original" }));
441
+
442
+ const empty = await patchFeedItemContent("item-1", { title: "" });
443
+ expect(empty!.title).toBe("Original");
444
+
445
+ const blank = await patchFeedItemContent("item-1", { title: " \t" });
446
+ expect(blank!.title).toBe("Original");
447
+
448
+ expect(readFileJson().items[0]!.title).toBe("Original");
449
+ });
450
+
451
+ test("a summary-only patch leaves the title untouched", async () => {
452
+ await appendFeedItem(makeItem({ id: "item-1", title: "Original" }));
453
+
454
+ const result = await patchFeedItemContent("item-1", {
455
+ summary: "Fresh summary",
456
+ });
457
+
458
+ expect(result!.title).toBe("Original");
459
+ expect(result!.summary).toBe("Fresh summary");
460
+ });
461
+
462
+ test("returns null for an unknown id", async () => {
463
+ await appendFeedItem(makeItem({ id: "known" }));
464
+ expect(await patchFeedItemContent("unknown", { title: "x" })).toBeNull();
465
+ });
466
+ });
467
+
409
468
  describe("concurrency", () => {
410
469
  test("10 concurrent appends with distinct ids all land", async () => {
411
470
  const items = Array.from({ length: 10 }, (_, i) =>
@@ -55,10 +55,13 @@ export interface HomeFeedFile {
55
55
  updatedAt: string;
56
56
  }
57
57
 
58
- /** Schema for the on-disk `home-feed.json` file. */
59
- const homeFeedFileSchema = z.object({
58
+ /**
59
+ * Envelope schema for the on-disk `home-feed.json` file. Items stay
60
+ * unvalidated here so `parseFeedFile` can validate them one at a time.
61
+ */
62
+ const homeFeedEnvelopeSchema = z.object({
60
63
  version: z.literal(2),
61
- items: z.array(FeedItemSchema),
64
+ items: z.array(z.unknown()),
62
65
  updatedAt: z.string(),
63
66
  });
64
67
 
@@ -66,9 +69,33 @@ const homeFeedFileSchema = z.object({
66
69
  * Parse and validate a raw value read from `home-feed.json`.
67
70
  *
68
71
  * Used by the writer on read-back and by the HTTP route when serving the
69
- * feed. Throws a `ZodError` on any validation failure — callers are
70
- * expected to log + recover (e.g. treat the file as empty).
72
+ * feed. Throws a `ZodError` when the envelope itself is invalid (wrong
73
+ * `version`, non-object input, missing `updatedAt`). Callers are
74
+ * expected to log + recover (e.g. treat the file as empty). Individual
75
+ * items that fail validation are dropped and counted in `droppedCount`,
76
+ * an in-memory-only field on the return value that is never persisted,
77
+ * so one malformed row cannot erase the rest of the feed.
71
78
  */
72
- export function parseFeedFile(raw: unknown): HomeFeedFile {
73
- return homeFeedFileSchema.parse(raw) as HomeFeedFile;
79
+ export function parseFeedFile(
80
+ raw: unknown,
81
+ ): HomeFeedFile & { droppedCount: number } {
82
+ const envelope = homeFeedEnvelopeSchema.parse(raw);
83
+
84
+ const items: z.infer<typeof FeedItemSchema>[] = [];
85
+ let droppedCount = 0;
86
+ for (const rawItem of envelope.items) {
87
+ const result = FeedItemSchema.safeParse(rawItem);
88
+ if (result.success) {
89
+ items.push(result.data);
90
+ } else {
91
+ droppedCount++;
92
+ }
93
+ }
94
+
95
+ return {
96
+ version: envelope.version,
97
+ items,
98
+ updatedAt: envelope.updatedAt,
99
+ droppedCount,
100
+ };
74
101
  }
@@ -68,7 +68,9 @@ export function getHomeFeedPath(): string {
68
68
  * Read the on-disk feed file, applying the stateless TTL filter.
69
69
  *
70
70
  * Returns an empty `HomeFeedFile` when the file is missing, unreadable,
71
- * or fails Zod validation — callers never see a throw from this path.
71
+ * or has an invalid envelope. Callers never see a throw from this path.
72
+ * Individual items that fail validation are dropped and warn-logged
73
+ * while the rest of the feed survives.
72
74
  * Items whose `expiresAt` is in the past are dropped from the returned
73
75
  * `items` array but are NOT rewritten to disk; the next append cycle
74
76
  * will persist the post-filter view naturally.
@@ -93,7 +95,7 @@ export function readHomeFeed(): HomeFeedFile {
93
95
  return empty;
94
96
  }
95
97
 
96
- let parsed: HomeFeedFile;
98
+ let parsed: ReturnType<typeof parseFeedFile>;
97
99
  try {
98
100
  parsed = parseFeedFile(raw);
99
101
  } catch (err) {
@@ -104,6 +106,13 @@ export function readHomeFeed(): HomeFeedFile {
104
106
  return empty;
105
107
  }
106
108
 
109
+ if (parsed.droppedCount > 0) {
110
+ log.warn(
111
+ { path, droppedCount: parsed.droppedCount },
112
+ "Dropped invalid items from home-feed.json",
113
+ );
114
+ }
115
+
107
116
  const now = Date.now();
108
117
  const items = parsed.items.filter((item) => !isExpired(item, now));
109
118
  return {
@@ -165,7 +174,8 @@ export async function patchFeedItemStatus(
165
174
  *
166
175
  * Only fields explicitly present on `patch` are touched. Pass an empty
167
176
  * object and the call is a no-op that returns the existing item (or
168
- * `null` if the id isn't on disk).
177
+ * `null` if the id isn't on disk). A `title` that trims to empty is
178
+ * ignored, so no edit path can strip a title off an existing item.
169
179
  */
170
180
  export interface FeedItemContentPatch {
171
181
  title?: string;
@@ -363,9 +373,8 @@ async function runWrite(): Promise<void> {
363
373
  const updated: FeedItem = { ...existing };
364
374
  if (patch.title !== undefined) {
365
375
  const trimmed = patch.title.trim();
366
- if (trimmed.length === 0) {
367
- delete updated.title;
368
- } else {
376
+ // Blank titles are ignored: an item keeps its title once it has one.
377
+ if (trimmed.length > 0) {
369
378
  updated.title = trimmed;
370
379
  }
371
380
  }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Tests for the voice activity line.
3
+ *
4
+ * The invariant worth guarding is totality: the tool vocabulary is open
5
+ * (plugins, MCP servers, and skills all contribute names this module has never
6
+ * seen), and the surface this feeds is a Lock Screen the user cannot correct.
7
+ * A label that came back empty would blank the island exactly when the
8
+ * assistant is busiest.
9
+ */
10
+
11
+ import { describe, expect, test } from "bun:test";
12
+
13
+ import {
14
+ activityLabelForTool,
15
+ GENERIC_ACTIVITY_LABEL,
16
+ } from "../activity-label.js";
17
+
18
+ describe("activityLabelForTool", () => {
19
+ test("names what the user would say is happening, not the tool", () => {
20
+ expect(activityLabelForTool("bash")).toBe("Running a command");
21
+ expect(activityLabelForTool("web_search")).toBe("Searching the web");
22
+ expect(activityLabelForTool("file_read")).toBe("Reading a file");
23
+ });
24
+
25
+ // Where a tool runs is not a distinction anyone glancing at a Lock Screen is
26
+ // making.
27
+ test("host and sandbox variants read the same", () => {
28
+ expect(activityLabelForTool("host_bash")).toBe(
29
+ activityLabelForTool("bash"),
30
+ );
31
+ expect(activityLabelForTool("host_file_read")).toBe(
32
+ activityLabelForTool("file_read"),
33
+ );
34
+ });
35
+
36
+ test("falls back by prefix for structured tool families", () => {
37
+ expect(activityLabelForTool("browser_click")).toBe("Using the browser");
38
+ expect(activityLabelForTool("mcp_notion_search")).toBe(
39
+ "Using a connected app",
40
+ );
41
+ });
42
+
43
+ test("every tool gets a label, including ones this module has never seen", () => {
44
+ for (const name of [
45
+ "slack_conversations_history",
46
+ "",
47
+ "a",
48
+ "some_vendor::weird.tool/name",
49
+ ]) {
50
+ expect(activityLabelForTool(name)).toBe(GENERIC_ACTIVITY_LABEL);
51
+ }
52
+ });
53
+
54
+ test("labels stay short enough for the slot they land in", () => {
55
+ for (const name of [
56
+ "bash",
57
+ "web_search",
58
+ "host_file_transfer",
59
+ "computer_use",
60
+ "ui_show",
61
+ "unknown_tool",
62
+ ]) {
63
+ const label = activityLabelForTool(name);
64
+ expect(label.length).toBeLessThanOrEqual(32);
65
+ expect(label).not.toMatch(/[.!?]$/);
66
+ }
67
+ });
68
+ });
@@ -34,16 +34,26 @@ function sttFinal(text: string): LiveVoiceServerFramePayload {
34
34
 
35
35
  /** A reporter whose dispatches are captured instead of sent. */
36
36
  class RecordingReporter extends LiveActivityReporter {
37
- readonly dispatched: Array<{ phase: string; event: string }> = [];
37
+ readonly dispatched: Array<{ phase: string; event: string; detail: string }> =
38
+ [];
38
39
 
39
40
  protected override async dispatch(
40
41
  phase: string,
41
42
  event: "update" | "end",
43
+ detail: string,
42
44
  ): Promise<void> {
43
- this.dispatched.push({ phase, event });
45
+ this.dispatched.push({ phase, event, detail });
44
46
  }
45
47
  }
46
48
 
49
+ function activity(label: string): LiveVoiceServerFramePayload {
50
+ return {
51
+ type: "activity",
52
+ turnId: "t1",
53
+ label,
54
+ } as LiveVoiceServerFramePayload;
55
+ }
56
+
47
57
  describe("phaseForFrame", () => {
48
58
  test("maps the frames the client derives phases from", () => {
49
59
  expect(phaseForFrame(frame("utterance_end"), "listening")).toBe(
@@ -92,7 +102,7 @@ describe("LiveActivityReporter", () => {
92
102
  reporter.report(frame("thinking"));
93
103
 
94
104
  expect(reporter.dispatched).toEqual([
95
- { phase: "thinking", event: "update" },
105
+ { phase: "thinking", event: "update", detail: "" },
96
106
  ]);
97
107
  });
98
108
 
@@ -105,7 +115,7 @@ describe("LiveActivityReporter", () => {
105
115
  reporter.report(frame("tts_audio"));
106
116
 
107
117
  expect(reporter.dispatched).toEqual([
108
- { phase: "speaking", event: "update" },
118
+ { phase: "speaking", event: "update", detail: "" },
109
119
  ]);
110
120
  });
111
121
 
@@ -144,6 +154,7 @@ describe("LiveActivityReporter", () => {
144
154
  expect(reporter.dispatched.at(-1)).toEqual({
145
155
  phase: "ending",
146
156
  event: "end",
157
+ detail: "",
147
158
  });
148
159
  });
149
160
 
@@ -165,7 +176,77 @@ describe("LiveActivityReporter", () => {
165
176
  reporter.end();
166
177
  reporter.report(frame("tts_audio"));
167
178
 
168
- expect(reporter.dispatched).toEqual([{ phase: "ending", event: "end" }]);
179
+ expect(reporter.dispatched).toEqual([
180
+ { phase: "ending", event: "end", detail: "" },
181
+ ]);
182
+ });
183
+ });
184
+
185
+ describe("LiveActivityReporter activity line", () => {
186
+ test("carries the activity label alongside the phase it holds", () => {
187
+ const reporter = new RecordingReporter("conv-1");
188
+
189
+ reporter.report(frame("utterance_end"));
190
+ reporter.report(frame("thinking"));
191
+ reporter.report(activity("Running a command"));
192
+
193
+ expect(reporter.dispatched.at(-1)).toEqual({
194
+ phase: "thinking",
195
+ event: "update",
196
+ detail: "Running a command",
197
+ });
198
+ });
199
+
200
+ // A push replaces the whole content state, so the label has to ride along on
201
+ // phase changes too, or the next phase would blank it.
202
+ test("keeps the label through a later phase change", () => {
203
+ const reporter = new RecordingReporter("conv-1");
204
+
205
+ reporter.report(frame("thinking"));
206
+ reporter.report(activity("Reading a file"));
207
+ reporter.report(frame("tts_audio"));
208
+
209
+ expect(reporter.dispatched.at(-1)).toEqual({
210
+ phase: "speaking",
211
+ event: "update",
212
+ detail: "Reading a file",
213
+ });
214
+ });
215
+
216
+ test("an empty label clears the line", () => {
217
+ const reporter = new RecordingReporter("conv-1");
218
+
219
+ reporter.report(frame("thinking"));
220
+ reporter.report(activity("Reading a file"));
221
+ reporter.report(activity(""));
222
+
223
+ expect(reporter.dispatched.at(-1)?.detail).toBe("");
224
+ });
225
+
226
+ test("does not dispatch a label it already sent", () => {
227
+ const reporter = new RecordingReporter("conv-1");
228
+
229
+ reporter.report(frame("thinking"));
230
+ reporter.report(activity("Reading a file"));
231
+ const before = reporter.dispatched.length;
232
+ reporter.report(activity("Reading a file"));
233
+
234
+ expect(reporter.dispatched.length).toBe(before);
235
+ });
236
+
237
+ // A tool can start before any phase-bearing frame lands. There is no content
238
+ // state to attach a label to yet, and the phase that follows carries it.
239
+ test("holds a label that arrives before any phase", () => {
240
+ const reporter = new RecordingReporter("conv-1");
241
+
242
+ reporter.report(activity("Searching the web"));
243
+ expect(reporter.dispatched).toEqual([]);
244
+
245
+ reporter.report(frame("thinking"));
246
+
247
+ expect(reporter.dispatched).toEqual([
248
+ { phase: "thinking", event: "update", detail: "Searching the web" },
249
+ ]);
169
250
  });
170
251
  });
171
252
 
@@ -442,7 +442,7 @@ describe("LiveVoiceSession assistant turn", () => {
442
442
  });
443
443
  });
444
444
 
445
- test("records tool_use_start on the active turn without emitting frames", async () => {
445
+ test("records tool_use_start on the active turn and publishes what it is doing", async () => {
446
446
  let callbacks: VoiceTurnCallbacks | undefined;
447
447
  const startVoiceTurn = mock(async (options: VoiceTurnOptions) => {
448
448
  callbacks = options.callbacks;
@@ -459,9 +459,8 @@ describe("LiveVoiceSession assistant turn", () => {
459
459
  "thinking",
460
460
  ]);
461
461
 
462
- const frameCountBefore = frames.length;
463
462
  callbacks?.tool_use_start?.("some_tool");
464
- await flushAsyncCallbacks();
463
+ await waitForFrameCount(frames, 4);
465
464
 
466
465
  const activeTurn = (
467
466
  session as unknown as {
@@ -469,20 +468,30 @@ describe("LiveVoiceSession assistant turn", () => {
469
468
  }
470
469
  ).activeAssistantTurn;
471
470
  expect(activeTurn?.toolUseStarted).toBe(true);
472
- expect(frames).toHaveLength(frameCountBefore);
471
+ // One activity frame, so a silent stretch of tool work is visible on the
472
+ // surfaces that show the session. An unrecognized tool still gets a line.
473
+ expect(frames.at(-1)).toMatchObject({
474
+ type: "activity",
475
+ label: "Working on it",
476
+ });
473
477
 
474
478
  callbacks?.message_complete?.({
475
479
  type: "message_complete",
476
480
  conversationId: "conversation-123",
477
481
  messageId: "assistant-message-123",
478
482
  });
479
- await waitForFrameCount(frames, 4);
483
+ await waitForFrameCount(frames, 6);
480
484
  expect(frames.map((frame) => frame.type)).toEqual([
481
485
  "ready",
482
486
  "stt_final",
483
487
  "thinking",
488
+ "activity",
484
489
  "tts_done",
490
+ // The turn is over, so the line clears: no surface should keep showing
491
+ // the last tool it touched through the silence that follows.
492
+ "activity",
485
493
  ]);
494
+ expect(frames.at(-1)).toMatchObject({ type: "activity", label: "" });
486
495
  });
487
496
 
488
497
  test("interrupt aborts the in-flight turn and ignores late bridge events", async () => {