@vellumai/assistant 0.10.10-staging.1 → 0.10.10-staging.2

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.
@@ -31,6 +31,7 @@ import type { TtsProvider, TtsProviderId } from "../tts/types.js";
31
31
  import { getLogger } from "../util/logger.js";
32
32
  import type { CallAudioFormat } from "./audio-store.js";
33
33
  import {
34
+ getEndCallDrainMaxWaitMs,
34
35
  getEndCallListenWindowMs,
35
36
  getMaxCallDurationMs,
36
37
  getSilenceTimeoutMs,
@@ -105,6 +106,12 @@ interface PendingGuardianInput {
105
106
  timer: ReturnType<typeof setTimeout>;
106
107
  }
107
108
 
109
+ interface PendingEndCall {
110
+ cancelled: boolean;
111
+ /** Settles the teardown's current in-flight wait (drain cap or listen window). */
112
+ wake: (() => void) | null;
113
+ }
114
+
108
115
  export class CallController {
109
116
  private callSessionId: string;
110
117
  private transport: CallTransport;
@@ -114,7 +121,12 @@ export class CallController {
114
121
  private currentTurnPromise: Promise<void> | null = null;
115
122
  private destroyed = false;
116
123
  private silenceTimer: ReturnType<typeof setTimeout> | null = null;
117
- private endCallListenTimer: ReturnType<typeof setTimeout> | null = null;
124
+ /**
125
+ * Cancellation token for the in-flight end-call teardown (drain → listen).
126
+ * `wake` settles the teardown's current wait; all wait state lives on the
127
+ * token so a superseding teardown never clobbers a prior one's timers.
128
+ */
129
+ private pendingEndCall: PendingEndCall | null = null;
118
130
  /**
119
131
  * How many times the caller has re-engaged (spoken) after an END_CALL
120
132
  * marker was emitted but before the listen window fired. Each caller
@@ -281,11 +293,15 @@ export class CallController {
281
293
  transcript: string,
282
294
  speaker?: PromptSpeakerContext,
283
295
  ): Promise<void> {
284
- // If the caller speaks while an END_CALL listen window is pending,
285
- // this is a deferral — the caller is re-engaging after we tried to
286
- // hang up. Track it so we can cap repeat deferrals.
287
- if (this.endCallListenTimer) {
296
+ // If the caller speaks while an END_CALL teardown is pending (during the
297
+ // drain wait or the listen window), this is a deferral — the caller is
298
+ // re-engaging after we tried to hang up. Track it so we can cap repeats.
299
+ if (this.pendingEndCall) {
288
300
  this.endCallDeferralCount++;
301
+ // The goodbye's speech was queued while state was idle, so the
302
+ // media-stream barge-in ignored it. Cancel it here so it can't play
303
+ // over the caller's follow-up or the next turn.
304
+ this.transport.cancelPendingSpeech?.();
289
305
  }
290
306
  this.cancelPendingEndCall();
291
307
 
@@ -458,7 +474,7 @@ export class CallController {
458
474
  destroy(): void {
459
475
  this.destroyed = true;
460
476
  if (this.silenceTimer) clearTimeout(this.silenceTimer);
461
- if (this.endCallListenTimer) clearTimeout(this.endCallListenTimer);
477
+ this.cancelPendingEndCall();
462
478
  if (this.durationTimer) clearTimeout(this.durationTimer);
463
479
  if (this.durationWarningTimer) clearTimeout(this.durationWarningTimer);
464
480
  if (this.pendingGuardianInput) {
@@ -470,7 +486,6 @@ export class CallController {
470
486
  this.durationEndTimer = null;
471
487
  }
472
488
  this.pendingInstructions = [];
473
- this.endCallListenTimer = null;
474
489
  this.llmRunVersion++;
475
490
  this.abortCurrentTurn();
476
491
  this.abortActiveSynthesis();
@@ -1339,46 +1354,96 @@ export class CallController {
1339
1354
  this.state = "idle";
1340
1355
  this.currentTurnHandle = null;
1341
1356
 
1342
- if (this.endCallListenTimer) {
1343
- clearTimeout(this.endCallListenTimer);
1344
- this.endCallListenTimer = null;
1345
- }
1357
+ // Cancel any teardown still in flight from a prior END_CALL so it can't
1358
+ // fire or cancel a later run.
1359
+ this.cancelPendingEndCall();
1346
1360
 
1347
- const listenWindowMs = getEndCallListenWindowMs();
1348
- // After the caller has re-engaged once post-END_CALL, complete
1349
- // immediately on the next END_CALL. The first deferral gets a
1350
- // listen window (caller might say "wait, one more thing"); a
1351
- // second END_CALL means the assistant wants out and the caller
1352
- // already had their chance to re-engage.
1353
- const effectiveListenWindowMs =
1354
- this.endCallDeferralCount > 0 ? 0 : listenWindowMs;
1355
- const callContinues =
1356
- this.pendingInstructions.length > 0 || effectiveListenWindowMs > 0;
1357
- if (clearedPendingGuardianInput && callContinues) {
1361
+ // The call always continues past END_CALL — either flushing queued
1362
+ // instructions or waiting for playback drain — so restore in_progress if
1363
+ // we just cleared a pending guardian consultation for the end.
1364
+ if (clearedPendingGuardianInput) {
1358
1365
  updateCallSession(this.callSessionId, { status: "in_progress" });
1359
1366
  }
1360
1367
 
1368
+ // Queued instructions mean the call is continuing — flush and skip teardown.
1361
1369
  if (this.pendingInstructions.length > 0) {
1362
1370
  this.flushPendingInstructions();
1363
1371
  return;
1364
1372
  }
1365
1373
 
1366
- if (effectiveListenWindowMs <= 0) {
1367
- this.completeCallFromEndMarker();
1374
+ const pending: PendingEndCall = { cancelled: false, wake: null };
1375
+ this.pendingEndCall = pending;
1376
+ void this.runEndCallTeardown(pending);
1377
+ }
1378
+
1379
+ /**
1380
+ * End-of-call teardown: wait for goodbye audio to drain (capped), then run
1381
+ * the re-engagement listen window, then end the session. Cancellable at
1382
+ * every step via the `pending` token (caller re-engagement, destroy).
1383
+ */
1384
+ private async runEndCallTeardown(pending: PendingEndCall): Promise<void> {
1385
+ if (this.transport.awaitPlaybackDrained) {
1386
+ await this.awaitCancellable(pending, (resolve) => {
1387
+ const cap = setTimeout(resolve, getEndCallDrainMaxWaitMs());
1388
+ void this.transport.awaitPlaybackDrained!().then(resolve, resolve);
1389
+ return () => clearTimeout(cap);
1390
+ });
1391
+ }
1392
+ if (pending.cancelled || this.destroyed) {
1368
1393
  return;
1369
1394
  }
1370
1395
 
1371
- this.resetSilenceTimer();
1372
- this.endCallListenTimer = setTimeout(() => {
1373
- this.endCallListenTimer = null;
1374
- this.completeCallFromEndMarker();
1375
- }, effectiveListenWindowMs);
1396
+ // After one deferral, subsequent END_CALL markers skip the listen window
1397
+ // (the caller already had their grace re-engagement).
1398
+ const listenWindowMs =
1399
+ this.endCallDeferralCount > 0 ? 0 : getEndCallListenWindowMs();
1400
+ if (listenWindowMs > 0) {
1401
+ this.resetSilenceTimer();
1402
+ await this.awaitCancellable(pending, (resolve) => {
1403
+ const timer = setTimeout(resolve, listenWindowMs);
1404
+ return () => clearTimeout(timer);
1405
+ });
1406
+ }
1407
+ if (pending.cancelled || this.destroyed) {
1408
+ return;
1409
+ }
1410
+
1411
+ this.completeCallFromEndMarker();
1412
+ }
1413
+
1414
+ /**
1415
+ * Await a wait that {@link cancelPendingEndCall} can settle early. `arm`
1416
+ * starts the wait and returns a cleanup for its timers. The resolver lives
1417
+ * on the `pending` token (not shared instance state) so a superseding
1418
+ * teardown's wait is never clobbered by a prior teardown's continuation.
1419
+ */
1420
+ private awaitCancellable(
1421
+ pending: PendingEndCall,
1422
+ arm: (resolve: () => void) => () => void,
1423
+ ): Promise<void> {
1424
+ return new Promise<void>((resolve) => {
1425
+ let cleanup: (() => void) | null = null;
1426
+ const done = (): void => {
1427
+ if (pending.wake === done) {
1428
+ pending.wake = null;
1429
+ }
1430
+ cleanup?.();
1431
+ resolve();
1432
+ };
1433
+ pending.wake = done;
1434
+ cleanup = arm(done);
1435
+ });
1376
1436
  }
1377
1437
 
1378
1438
  private cancelPendingEndCall(): void {
1379
- if (!this.endCallListenTimer) return;
1380
- clearTimeout(this.endCallListenTimer);
1381
- this.endCallListenTimer = null;
1439
+ const pending = this.pendingEndCall;
1440
+ this.pendingEndCall = null;
1441
+ if (pending) {
1442
+ pending.cancelled = true;
1443
+ // Settle its in-flight wait so runEndCallTeardown unblocks and returns
1444
+ // instead of leaking a pending promise.
1445
+ pending.wake?.();
1446
+ }
1382
1447
  }
1383
1448
 
1384
1449
  private clearPendingGuardianInputForCallEnd(): boolean {
@@ -1408,6 +1473,9 @@ export class CallController {
1408
1473
  }
1409
1474
 
1410
1475
  private completeCallFromEndMarker(): void {
1476
+ // The teardown has run to completion; drop the token so a later utterance
1477
+ // can't read it as a still-pending end-call.
1478
+ this.pendingEndCall = null;
1411
1479
  if (this.destroyed) return;
1412
1480
 
1413
1481
  const currentSession = getCallSession(this.callSessionId);
@@ -72,4 +72,13 @@ export interface CallTransport {
72
72
  * this.
73
73
  */
74
74
  cancelPendingSpeech?(): void;
75
+
76
+ /**
77
+ * Resolve once all queued speech has played out to the caller (the most
78
+ * recent end-of-turn boundary has been echoed back by the downstream
79
+ * transport). Used to gate end-of-call teardown so a goodbye is never cut
80
+ * off mid-sentence. Transports that play speech synchronously may omit
81
+ * this — the controller then treats playback as already drained.
82
+ */
83
+ awaitPlaybackDrained?(): Promise<void>;
75
84
  }
@@ -57,6 +57,9 @@ import { resolveCallTtsProvider } from "./resolve-call-tts-provider.js";
57
57
 
58
58
  const log = getLogger("media-stream-output");
59
59
 
60
+ /** Prefix for the sequenced end-of-turn playback marks Twilio echoes back. */
61
+ const END_OF_TURN_MARK_PREFIX = "end-of-turn";
62
+
60
63
  /** Twilio media streams consume 8 kHz mono mu-law. */
61
64
  const TELEPHONY_SAMPLE_RATE_HZ = 8000;
62
65
 
@@ -335,6 +338,18 @@ export class MediaStreamOutput implements CallTransport {
335
338
  */
336
339
  private audioStartCallback: (() => void) | null = null;
337
340
 
341
+ /** Incremented per end-of-turn mark enqueued. */
342
+ private enqueuedEndOfTurnSeq = 0;
343
+
344
+ /** Highest end-of-turn seq actually sent to Twilio (buffered downstream). */
345
+ private sentEndOfTurnSeq = 0;
346
+
347
+ /** Highest end-of-turn seq echoed back by Twilio. */
348
+ private echoedEndOfTurnSeq = 0;
349
+
350
+ /** Pending {@link awaitPlaybackDrained} waiters, each with its target seq. */
351
+ private drainWaiters: Array<{ targetSeq: number; resolve: () => void }> = [];
352
+
338
353
  /**
339
354
  * The media-stream transport requires raw PCM audio because its
340
355
  * mu-law transcoder cannot decode compressed formats (mp3, opus).
@@ -378,9 +393,13 @@ export class MediaStreamOutput implements CallTransport {
378
393
  }
379
394
 
380
395
  if (last) {
381
- // Always send an end-of-turn mark so the media-stream server
382
- // can detect turn boundaries.
383
- this.enqueuePlayback({ type: "mark", name: "end-of-turn" });
396
+ // Always send a sequenced end-of-turn mark so the media-stream server
397
+ // can detect turn boundaries and drain waiters can track playback.
398
+ const seq = ++this.enqueuedEndOfTurnSeq;
399
+ this.enqueuePlayback({
400
+ type: "mark",
401
+ name: `${END_OF_TURN_MARK_PREFIX}:${seq}`,
402
+ });
384
403
  this.turnSegmentEnqueued = false;
385
404
  }
386
405
  }
@@ -439,7 +458,7 @@ export class MediaStreamOutput implements CallTransport {
439
458
  }
440
459
  this.state = "closed";
441
460
 
442
- // Cancel any in-flight playback
461
+ // Cancel any in-flight playback (also releases drain waiters).
443
462
  this.flushPlaybackQueue();
444
463
 
445
464
  log.info(
@@ -502,6 +521,10 @@ export class MediaStreamOutput implements CallTransport {
502
521
 
503
522
  try {
504
523
  this.ws.send(JSON.stringify(command));
524
+ const seq = this.parseEndOfTurnSeq(name);
525
+ if (seq !== null && seq > this.sentEndOfTurnSeq) {
526
+ this.sentEndOfTurnSeq = seq;
527
+ }
505
528
  } catch (err) {
506
529
  log.error(
507
530
  { err, streamSid: this.streamSid },
@@ -510,6 +533,53 @@ export class MediaStreamOutput implements CallTransport {
510
533
  }
511
534
  }
512
535
 
536
+ /**
537
+ * Record a mark echoed back by Twilio. When it is an end-of-turn mark,
538
+ * advance the echoed sequence and resolve any drain waiters whose target
539
+ * has now been reached (played out to the caller).
540
+ */
541
+ notePlaybackMarkEcho(name: string): void {
542
+ const seq = this.parseEndOfTurnSeq(name);
543
+ if (seq === null) {
544
+ return;
545
+ }
546
+ // Ignore echoes for marks we never enqueued (stale/forged/out-of-range).
547
+ // Accepting a future seq would advance the high-water mark and make later
548
+ // real turns' awaitPlaybackDrained() resolve before their audio played.
549
+ if (seq > this.enqueuedEndOfTurnSeq) {
550
+ return;
551
+ }
552
+ if (seq > this.echoedEndOfTurnSeq) {
553
+ this.echoedEndOfTurnSeq = seq;
554
+ }
555
+ this.resolveDrainWaiters();
556
+ }
557
+
558
+ /** Parse the sequence from an `end-of-turn:<n>` mark name, else null. */
559
+ private parseEndOfTurnSeq(name: string): number | null {
560
+ if (!name.startsWith(`${END_OF_TURN_MARK_PREFIX}:`)) {
561
+ return null;
562
+ }
563
+ const seq = Number(name.slice(END_OF_TURN_MARK_PREFIX.length + 1));
564
+ return Number.isFinite(seq) ? seq : null;
565
+ }
566
+
567
+ /**
568
+ * Resolve once the most-recently-enqueued end-of-turn mark has been
569
+ * echoed by Twilio (all queued speech has played out to the caller).
570
+ * Resolves immediately if nothing is outstanding or the output is closed.
571
+ * Also resolves if the playback queue is later flushed (barge-in / teardown)
572
+ * so callers never hang.
573
+ */
574
+ awaitPlaybackDrained(): Promise<void> {
575
+ if (this.state === "closed") return Promise.resolve();
576
+ const targetSeq = this.enqueuedEndOfTurnSeq;
577
+ if (this.echoedEndOfTurnSeq >= targetSeq) return Promise.resolve();
578
+ return new Promise<void>((resolve) => {
579
+ this.drainWaiters.push({ targetSeq, resolve });
580
+ });
581
+ }
582
+
513
583
  /**
514
584
  * Clear any queued outbound audio. Used for barge-in scenarios where
515
585
  * the caller interrupts the assistant.
@@ -552,6 +622,14 @@ export class MediaStreamOutput implements CallTransport {
552
622
  return;
553
623
  }
554
624
  this.sendClearCommand();
625
+ // Twilio drops its buffered audio (and the marks within it) on `clear`, so
626
+ // any end-of-turn mark already sent will never echo. Treat those as drained
627
+ // so a pending end-call drain wait resolves instead of stalling on the cap.
628
+ // Marks still queued locally are preserved and will echo when they play.
629
+ if (this.sentEndOfTurnSeq > this.echoedEndOfTurnSeq) {
630
+ this.echoedEndOfTurnSeq = this.sentEndOfTurnSeq;
631
+ this.resolveDrainWaiters();
632
+ }
555
633
  }
556
634
 
557
635
  private sendClearCommand(): void {
@@ -610,6 +688,24 @@ export class MediaStreamOutput implements CallTransport {
610
688
  return this.state === "closed";
611
689
  }
612
690
 
691
+ // ── Private: playback drain waiters ─────────────────────────────────
692
+
693
+ private resolveDrainWaiters(): void {
694
+ if (this.drainWaiters.length === 0) return;
695
+ const remaining: typeof this.drainWaiters = [];
696
+ for (const w of this.drainWaiters) {
697
+ if (this.echoedEndOfTurnSeq >= w.targetSeq) w.resolve();
698
+ else remaining.push(w);
699
+ }
700
+ this.drainWaiters = remaining;
701
+ }
702
+
703
+ private releaseAllDrainWaiters(): void {
704
+ const waiters = this.drainWaiters;
705
+ this.drainWaiters = [];
706
+ for (const w of waiters) w.resolve();
707
+ }
708
+
613
709
  // ── Private: playback queue management ──────────────────────────────
614
710
 
615
711
  private enqueuePlayback(item: PlaybackItem): void {
@@ -636,6 +732,13 @@ export class MediaStreamOutput implements CallTransport {
636
732
  this.activePlaybackAbort.abort();
637
733
  this.activePlaybackAbort = null;
638
734
  }
735
+ // A flushed queue will never (genuinely) echo its pending end-of-turn
736
+ // marks — Twilio drops the buffered audio on `clear`. Treat every
737
+ // outstanding mark as drained so existing waiters resolve now and any
738
+ // *future* awaitPlaybackDrained() targeting a flushed seq doesn't hang.
739
+ // It also makes a late cleared-mark echo a no-op (seq <= echoed).
740
+ this.echoedEndOfTurnSeq = this.enqueuedEndOfTurnSeq;
741
+ this.releaseAllDrainWaiters();
639
742
  }
640
743
 
641
744
  /**
@@ -208,6 +208,7 @@ export class MediaStreamCallSession {
208
208
  onTranscriptFinal: (text, durationMs) =>
209
209
  this.handleTranscriptFinal(text, durationMs),
210
210
  onDtmf: (digit) => this.handleDtmf(digit),
211
+ onMark: (name) => this.handleMarkEcho(name),
211
212
  onStop: () => this.handleStreamStop(),
212
213
  onError: (category, message) => this.handleSttError(category, message),
213
214
  };
@@ -254,7 +255,9 @@ export class MediaStreamCallSession {
254
255
  * audio processing.
255
256
  */
256
257
  handleMessage(raw: string): void {
257
- if (this.disposed) {return;}
258
+ if (this.disposed) {
259
+ return;
260
+ }
258
261
 
259
262
  // Intercept `start` to bootstrap the session before forwarding.
260
263
  const parseResult = parseMediaStreamFrame(raw);
@@ -277,7 +280,9 @@ export class MediaStreamCallSession {
277
280
  * in a terminal state.
278
281
  */
279
282
  handleTransportClosed(code?: number, reason?: string): void {
280
- if (this.disposed) {return;}
283
+ if (this.disposed) {
284
+ return;
285
+ }
281
286
 
282
287
  // Tear down an in-flight setup flow first: clears its timers and emits
283
288
  // the guardian-wait callback handoff when the caller opted in.
@@ -286,7 +291,9 @@ export class MediaStreamCallSession {
286
291
  setupFlow?.dispose("transport_closed");
287
292
 
288
293
  const session = getCallSession(this.callSessionId);
289
- if (!session) {return;}
294
+ if (!session) {
295
+ return;
296
+ }
290
297
  if (isTerminalState(session.status)) {
291
298
  // A hangup during a flow-terminal goodbye: dispose above swallowed the
292
299
  // flow's pending complete(), so finalize + revoke grants here. Normal
@@ -373,7 +380,9 @@ export class MediaStreamCallSession {
373
380
  * Dispose of the session, cleaning up all resources.
374
381
  */
375
382
  destroy(): void {
376
- if (this.disposed) {return;}
383
+ if (this.disposed) {
384
+ return;
385
+ }
377
386
  this.disposed = true;
378
387
 
379
388
  this.sttSession.dispose();
@@ -427,7 +436,9 @@ export class MediaStreamCallSession {
427
436
  session.status !== "waiting_on_user"
428
437
  ) {
429
438
  updates.status = "in_progress";
430
- if (!session.startedAt) {updates.startedAt = Date.now();}
439
+ if (!session.startedAt) {
440
+ updates.startedAt = Date.now();
441
+ }
431
442
  }
432
443
  updateCallSession(this.callSessionId, updates);
433
444
  }
@@ -750,9 +761,7 @@ export class MediaStreamCallSession {
750
761
  // end-of-turn mark it enqueues survives the queue flush.
751
762
  if (this.output && this.controller) {
752
763
  const output = this.output;
753
- const accepted = this.controller.handleBargeIn(() =>
754
- output.clearAudio(),
755
- );
764
+ const accepted = this.controller.handleBargeIn(() => output.clearAudio());
756
765
  if (accepted) {
757
766
  this.bargeInAccepted++;
758
767
  log.info(
@@ -775,7 +784,9 @@ export class MediaStreamCallSession {
775
784
  }
776
785
 
777
786
  private handleTranscriptFinal(text: string, _durationMs: number): void {
778
- if (!text.trim()) {return;}
787
+ if (!text.trim()) {
788
+ return;
789
+ }
779
790
 
780
791
  // Drop transcripts arriving while setup routing is still pending so a
781
792
  // not-yet-authorized / floor-denied caller's speech is never persisted
@@ -865,6 +876,15 @@ export class MediaStreamCallSession {
865
876
  this.setupFlow?.pushDtmfDigit(digit);
866
877
  }
867
878
 
879
+ private handleMarkEcho(name: string): void {
880
+ if (this.disposed) {
881
+ return;
882
+ }
883
+ // Twilio echoes each queued mark once its preceding audio has played
884
+ // out; forward to the output so drain waiters resolve on real playback.
885
+ this.output.notePlaybackMarkEcho(name);
886
+ }
887
+
868
888
  private handleStreamStop(): void {
869
889
  log.info(
870
890
  { callSessionId: this.callSessionId },
@@ -136,6 +136,12 @@ export interface MediaStreamSttSessionCallbacks {
136
136
  */
137
137
  onDtmf?: (digit: string) => void;
138
138
 
139
+ /**
140
+ * Called when Twilio echoes an outbound mark back — i.e. the caller's
141
+ * playback has reached that mark. Used to detect real playback drain.
142
+ */
143
+ onMark?: (name: string) => void;
144
+
139
145
  /**
140
146
  * Called when the media stream stops.
141
147
  */
@@ -264,7 +270,7 @@ export class MediaStreamSttSession {
264
270
  this.callbacks.onDtmf?.(event.dtmf.digit);
265
271
  break;
266
272
  case "mark":
267
- // Marks are informational — no action needed in the STT session.
273
+ this.callbacks.onMark?.(event.mark.name);
268
274
  break;
269
275
  case "stop":
270
276
  this.handleStop();
@@ -29,9 +29,15 @@ let ipcResponse: {
29
29
  };
30
30
 
31
31
  const exitCodeFromIpcResult = (r: { statusCode?: number }): number => {
32
- if (r.statusCode === undefined) return 10;
33
- if (r.statusCode >= 500) return 3;
34
- if (r.statusCode >= 400) return 2;
32
+ if (r.statusCode === undefined) {
33
+ return 10;
34
+ }
35
+ if (r.statusCode >= 500) {
36
+ return 3;
37
+ }
38
+ if (r.statusCode >= 400) {
39
+ return 2;
40
+ }
35
41
  return 1;
36
42
  };
37
43
 
@@ -518,6 +524,21 @@ describe("notifications list", () => {
518
524
  expect(ipcCalls[0].method).toBe("list_home_feed");
519
525
  });
520
526
 
527
+ test("list help disambiguates Vellum notifications from email inboxes", async () => {
528
+ const { stdout, exitCode } = await runRawCommand([
529
+ "notifications",
530
+ "list",
531
+ "--help",
532
+ ]);
533
+
534
+ expect(exitCode).toBe(0);
535
+ const normalizedHelp = stdout.replace(/\s+/g, " ");
536
+ expect(normalizedHelp).toContain("Vellum Home feed");
537
+ expect(normalizedHelp).toContain("does not read email inboxes");
538
+ expect(normalizedHelp).toContain("Gmail");
539
+ expect(normalizedHelp).toContain("Outlook");
540
+ });
541
+
521
542
  test("list returns items from IPC", async () => {
522
543
  ipcResponse = {
523
544
  ok: true,
@@ -48,9 +48,9 @@ source channel, event name, and attention hints. The decision engine evaluates
48
48
  whether and where to deliver the notification based on connected channels,
49
49
  urgency, and user preferences.
50
50
 
51
- Minimal usage: only --message is required. Add --urgent for a push + visual
52
- flag in the inbox. Source channel/event name fall back to assistant_tool /
53
- assistant.share when omitted.
51
+ Minimal usage: only --message is required. Add --urgent for a push +
52
+ visual flag in the Vellum Home feed. Source channel/event name fall back
53
+ to assistant_tool / assistant.share when omitted.
54
54
 
55
55
  Examples:
56
56
  $ assistant notifications send --message "Build finished"
@@ -71,7 +71,7 @@ Examples:
71
71
  {
72
72
  flags: "--urgent",
73
73
  description:
74
- "Mark this notification as urgent (fires push + visual flag in inbox)",
74
+ "Mark this notification as urgent (fires push + visual flag in Vellum Home)",
75
75
  defaultValue: false,
76
76
  },
77
77
  {
@@ -176,7 +176,7 @@ Examples:
176
176
  {
177
177
  name: "list",
178
178
  description:
179
- "List notifications surfaced to the user via the home feed. Excludes dismissed items by default.",
179
+ "List Vellum Home feed notifications surfaced by the assistant. Excludes dismissed items by default.",
180
180
  options: [
181
181
  {
182
182
  flags: "--all",
@@ -231,11 +231,11 @@ Examples:
231
231
  },
232
232
  ],
233
233
  helpText: `
234
- Reads the home feed at $VELLUM_WORKSPACE_DIR/data/home-feed.json — the
235
- user's notification inbox. Items are ordered by priority then recency,
236
- matching what the user sees in the macOS Home page. The home feed covers
237
- background/async notifications mirrored from the unified pipeline;
238
- real-time chat pushes that did not mirror to the feed will not appear.
234
+ Reads Vellum's Home feed at $VELLUM_WORKSPACE_DIR/data/home-feed.json.
235
+ Items are ordered by priority then recency, matching what the user sees
236
+ in the macOS Home page. This is only the assistant's Vellum notification
237
+ feed; it does not read email inboxes, Gmail, Outlook, or other external
238
+ message providers. Use OAuth/provider-specific commands for external mail.
239
239
 
240
240
  Examples:
241
241
  $ assistant notifications list
@@ -0,0 +1,40 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ buildOAuthConnectSurfaceRedirect,
5
+ isModelSpawnedConversationShell,
6
+ oauthConnectSurfaceHint,
7
+ } from "./connect-surface-guidance.js";
8
+
9
+ describe("OAuth connect surface guidance", () => {
10
+ test("builds the oauth_connect next action payload", () => {
11
+ expect(buildOAuthConnectSurfaceRedirect("google")).toEqual({
12
+ ok: false,
13
+ code: "use_oauth_connect_surface",
14
+ provider: "google",
15
+ hint: oauthConnectSurfaceHint("google"),
16
+ nextAction: {
17
+ type: "ui_show",
18
+ surfaceType: "oauth_connect",
19
+ data: { providerKey: "google" },
20
+ },
21
+ });
22
+ });
23
+
24
+ test("detects model-spawned conversation shells", () => {
25
+ expect(
26
+ isModelSpawnedConversationShell({ __CONVERSATION_ID: "conv-123" }),
27
+ ).toBe(true);
28
+ expect(isModelSpawnedConversationShell({ __CONVERSATION_ID: " " })).toBe(
29
+ false,
30
+ );
31
+ expect(isModelSpawnedConversationShell({})).toBe(false);
32
+ });
33
+
34
+ test("hint tells the model not to paste OAuth URLs", () => {
35
+ const hint = oauthConnectSurfaceHint("google");
36
+ expect(hint).toContain('surface_type "oauth_connect"');
37
+ expect(hint).toContain('data.providerKey "google"');
38
+ expect(hint).toContain("paste an OAuth URL");
39
+ });
40
+ });