@vellumai/assistant 0.11.5-dev.202608251857.ea09afb → 0.11.5-dev.202608252008.65007aa

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 (24) hide show
  1. package/node_modules/@vellumai/gateway-client/src/__tests__/contact-read-contracts.test.ts +32 -0
  2. package/node_modules/@vellumai/gateway-client/src/__tests__/trust-verdict-contract.test.ts +18 -0
  3. package/node_modules/@vellumai/gateway-client/src/admission-policy-contract.ts +0 -5
  4. package/node_modules/@vellumai/gateway-client/src/channel-permission-contract.ts +3 -1
  5. package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +7 -0
  6. package/node_modules/@vellumai/gateway-client/src/trust-verdict-contract.ts +11 -0
  7. package/openapi.yaml +54 -0
  8. package/package.json +1 -1
  9. package/src/cli/commands/memory/memory-retrospective.ts +1 -0
  10. package/src/live-voice/__tests__/live-voice-session-manager.test.ts +73 -11
  11. package/src/live-voice/live-voice-session-manager.ts +39 -2
  12. package/src/live-voice/protocol.ts +27 -0
  13. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +125 -33
  14. package/src/plugins/defaults/memory/__tests__/memory-retrospective-prompt.test.ts +21 -31
  15. package/src/plugins/defaults/memory/__tests__/memory-retrospective-provider-path.test.ts +13 -9
  16. package/src/plugins/defaults/memory/__tests__/memory-retrospective-wake-chain.test.ts +31 -4
  17. package/src/plugins/defaults/memory/memory-retrospective-constants.ts +0 -11
  18. package/src/plugins/defaults/memory/memory-retrospective-job.ts +140 -107
  19. package/src/plugins/defaults/memory/memory-retrospective-prompt.ts +13 -13
  20. package/src/runtime/__tests__/agent-wake.test.ts +12 -2
  21. package/src/runtime/agent-wake.ts +29 -3
  22. package/src/runtime/routes/__tests__/contact-routes.test.ts +7 -0
  23. package/src/runtime/routes/contact-routes.ts +20 -15
  24. package/src/runtime/routes/wake-conversation-routes.ts +8 -1
@@ -20,6 +20,7 @@ describe("contact read contracts", () => {
20
20
  contactType: "human",
21
21
  lastInteraction: 1700000000,
22
22
  interactionCount: 12,
23
+ autoApproveThreshold: "medium",
23
24
  createdAt: 1699000000,
24
25
  updatedAt: 1700000000,
25
26
  channels: [
@@ -46,6 +47,7 @@ describe("contact read contracts", () => {
46
47
  const parsed = ContactReadSchema.parse(contact);
47
48
  expect(parsed.createdAt).toBe(1699000000);
48
49
  expect(parsed.updatedAt).toBe(1700000000);
50
+ expect(parsed.autoApproveThreshold).toBe("medium");
49
51
  });
50
52
 
51
53
  test("ContactReadSchema accepts null interactionCount (daemon-native gateway-telemetry outage fail-soft)", () => {
@@ -82,6 +84,36 @@ describe("contact read contracts", () => {
82
84
  const parsed = ContactReadSchema.parse(contact);
83
85
  expect(parsed.interactionCount).toBeNull();
84
86
  expect(parsed.channels[0].interactionCount).toBeNull();
87
+ expect(parsed.autoApproveThreshold).toBeUndefined();
88
+ });
89
+
90
+ test("ContactReadSchema accepts a null auto-approve threshold", () => {
91
+ const contact = {
92
+ id: "c1",
93
+ displayName: "Example User",
94
+ role: "contact",
95
+ interactionCount: 0,
96
+ autoApproveThreshold: null,
97
+ createdAt: 1699000000,
98
+ updatedAt: 1700000000,
99
+ channels: [],
100
+ };
101
+ expect(ContactReadSchema.parse(contact).autoApproveThreshold).toBeNull();
102
+ });
103
+
104
+ test("ContactReadSchema rejects an unknown auto-approve threshold", () => {
105
+ expect(() =>
106
+ ContactReadSchema.parse({
107
+ id: "c1",
108
+ displayName: "Example User",
109
+ role: "contact",
110
+ interactionCount: 0,
111
+ autoApproveThreshold: "full",
112
+ createdAt: 1699000000,
113
+ updatedAt: 1700000000,
114
+ channels: [],
115
+ }),
116
+ ).toThrow();
85
117
  });
86
118
 
87
119
  test("ContactReadSchema requires createdAt/updatedAt", () => {
@@ -31,6 +31,7 @@ const fullVerdict: TrustVerdict = {
31
31
  verifiedAt: 1699999999,
32
32
  interactionCount: 12,
33
33
  memberDisplayName: "Member Name",
34
+ autoApproveThreshold: "high",
34
35
  };
35
36
 
36
37
  describe("TrustVerdictSchema", () => {
@@ -38,6 +39,23 @@ describe("TrustVerdictSchema", () => {
38
39
  expect(TrustVerdictSchema.parse(fullVerdict)).toEqual(fullVerdict);
39
40
  });
40
41
 
42
+ test("parses a verdict with a null contact auto-approve threshold", () => {
43
+ const verdict = {
44
+ ...fullVerdict,
45
+ autoApproveThreshold: null,
46
+ } satisfies TrustVerdict;
47
+ expect(TrustVerdictSchema.parse(verdict)).toEqual(verdict);
48
+ });
49
+
50
+ test("rejects an unknown contact auto-approve threshold", () => {
51
+ expect(() =>
52
+ TrustVerdictSchema.parse({
53
+ ...fullVerdict,
54
+ autoApproveThreshold: "full",
55
+ }),
56
+ ).toThrow();
57
+ });
58
+
41
59
  test("parses a minimal verdict", () => {
42
60
  const minimal = {
43
61
  trustClass: "unknown",
@@ -82,15 +82,10 @@ export function isAdmissionPolicyExemptChannel(channelType: string): boolean {
82
82
  * `vellum` is the local desktop/web client surface; the guardian is always
83
83
  * max-rank there, so the seed default admits them regardless of the floor.
84
84
  *
85
- * `discord` has no ingress implementation, so there is nothing for a floor to
86
- * gate and nothing for the user to configure. Hiding keeps it pinned at the
87
- * seed default rather than offering a Channel Trust Floors row for a channel
88
- * that receives nothing.
89
85
  */
90
86
  export const ADMISSION_POLICY_HIDDEN_CHANNELS: ReadonlySet<string> = new Set([
91
87
  "vellum",
92
88
  "whatsapp",
93
- "discord",
94
89
  ]);
95
90
 
96
91
  export function isAdmissionPolicyHiddenChannel(channelType: string): boolean {
@@ -10,7 +10,9 @@
10
10
  *
11
11
  * Storage lives in the gateway DB (`channel_permission_overrides`) so the
12
12
  * assistant cannot tamper with it, matching `channel_admission_policy` and
13
- * `auto_approve_thresholds`.
13
+ * `auto_approve_thresholds`. A contact-level ceiling can live on
14
+ * `contacts.auto_approve_threshold` and is stamped on the trust verdict;
15
+ * that override is not a matrix cell.
14
16
  */
15
17
 
16
18
  import { z } from "zod";
@@ -5,6 +5,8 @@
5
5
  import { CHANNEL_IDS } from "@vellumai/service-contracts/channels";
6
6
  import { z } from "zod";
7
7
 
8
+ import { RiskThresholdSchema } from "./channel-permission-contract.js";
9
+
8
10
  export const GATEWAY_LOG_LEVEL_NAMES = [
9
11
  "trace",
10
12
  "debug",
@@ -275,6 +277,11 @@ export const ContactReadSchema = z.object({
275
277
  contactType: z.string().nullable().optional(),
276
278
  lastInteraction: z.number().nullable().optional(),
277
279
  interactionCount: z.number().nullable(),
280
+ /**
281
+ * Per-contact auto-approve ceiling. Null when unset (inherit cascade).
282
+ * Optional on the wire for version skew; gateway reads always emit it.
283
+ */
284
+ autoApproveThreshold: RiskThresholdSchema.nullable().optional(),
278
285
  createdAt: z.number(),
279
286
  updatedAt: z.number(),
280
287
  channels: z.array(ContactReadChannelSchema),
@@ -78,6 +78,17 @@ export const TrustVerdictSchema = z.object({
78
78
  policy: z.string().optional(),
79
79
  verifiedAt: z.number().nullable().optional(),
80
80
  memberDisplayName: z.string().optional(),
81
+ /**
82
+ * Contact-level auto-approve ceiling from the gateway `contacts` row.
83
+ * Present when a member channel resolves. Null means the contact has no
84
+ * explicit override (inherit the room / trust-class cascade).
85
+ * Same vocabulary as `RiskThreshold` (`none` | `low` | `medium` | `high`).
86
+ * Inlined here so this leaf contract does not import the permission matrix.
87
+ */
88
+ autoApproveThreshold: z
89
+ .enum(["none", "low", "medium", "high"])
90
+ .nullable()
91
+ .optional(),
81
92
 
82
93
  // Gateway-owned interaction telemetry (a trust signal, not an info field per
83
94
  // the 2×2) — carried straight off the member `contact_channels` row.
package/openapi.yaml CHANGED
@@ -4342,6 +4342,15 @@ paths:
4342
4342
  - type: "null"
4343
4343
  memberDisplayName:
4344
4344
  type: string
4345
+ autoApproveThreshold:
4346
+ anyOf:
4347
+ - type: string
4348
+ enum:
4349
+ - none
4350
+ - low
4351
+ - medium
4352
+ - high
4353
+ - type: "null"
4345
4354
  interactionCount:
4346
4355
  type: number
4347
4356
  hasInterceptableVerificationSession:
@@ -5597,6 +5606,15 @@ paths:
5597
5606
  anyOf:
5598
5607
  - type: number
5599
5608
  - type: "null"
5609
+ autoApproveThreshold:
5610
+ anyOf:
5611
+ - type: string
5612
+ enum:
5613
+ - none
5614
+ - low
5615
+ - medium
5616
+ - high
5617
+ - type: "null"
5600
5618
  createdAt:
5601
5619
  type: number
5602
5620
  updatedAt:
@@ -5761,6 +5779,15 @@ paths:
5761
5779
  anyOf:
5762
5780
  - type: number
5763
5781
  - type: "null"
5782
+ autoApproveThreshold:
5783
+ anyOf:
5784
+ - type: string
5785
+ enum:
5786
+ - none
5787
+ - low
5788
+ - medium
5789
+ - high
5790
+ - type: "null"
5764
5791
  createdAt:
5765
5792
  type: number
5766
5793
  updatedAt:
@@ -5894,6 +5921,15 @@ paths:
5894
5921
  anyOf:
5895
5922
  - type: number
5896
5923
  - type: "null"
5924
+ autoApproveThreshold:
5925
+ anyOf:
5926
+ - type: string
5927
+ enum:
5928
+ - none
5929
+ - low
5930
+ - medium
5931
+ - high
5932
+ - type: "null"
5897
5933
  createdAt:
5898
5934
  type: number
5899
5935
  updatedAt:
@@ -6298,6 +6334,15 @@ paths:
6298
6334
  anyOf:
6299
6335
  - type: number
6300
6336
  - type: "null"
6337
+ autoApproveThreshold:
6338
+ anyOf:
6339
+ - type: string
6340
+ enum:
6341
+ - none
6342
+ - low
6343
+ - medium
6344
+ - high
6345
+ - type: "null"
6301
6346
  createdAt:
6302
6347
  type: number
6303
6348
  updatedAt:
@@ -6497,6 +6542,15 @@ paths:
6497
6542
  anyOf:
6498
6543
  - type: number
6499
6544
  - type: "null"
6545
+ autoApproveThreshold:
6546
+ anyOf:
6547
+ - type: string
6548
+ enum:
6549
+ - none
6550
+ - low
6551
+ - medium
6552
+ - high
6553
+ - type: "null"
6500
6554
  createdAt:
6501
6555
  type: number
6502
6556
  updatedAt:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.5-dev.202608251857.ea09afb",
3
+ "version": "0.11.5-dev.202608252008.65007aa",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -169,6 +169,7 @@ function renderOutcome(outcome: MemoryRetrospectiveOutcome): void {
169
169
  case "invoked":
170
170
  log.info(
171
171
  `Retrospective invoked.\n` +
172
+ ` outcome: ${outcome.noFindings ? "reviewed, nothing new to save" : "saved to memory"}\n` +
172
173
  ` fork conversation: ${outcome.backgroundConversationId}\n` +
173
174
  ` cutoff message: ${outcome.cutoffMessageId}\n` +
174
175
  ` new messages: ${outcome.newMessageCount}` +
@@ -122,24 +122,86 @@ describe("LiveVoiceSessionManager", () => {
122
122
  const rejected = await manager.startSession(START_FRAME, second.sink);
123
123
 
124
124
  expect(accepted).toEqual({ status: "accepted", sessionId: "session-1" });
125
+ const busyFrame = {
126
+ type: "busy",
127
+ seq: 1,
128
+ activeSessionId: "session-1",
129
+ // Names where the blocking session is, so the refused client has
130
+ // somewhere to point the user.
131
+ holder: { conversationId: "conversation-123" },
132
+ } as const satisfies LiveVoiceServerFrame;
125
133
  expect(rejected).toEqual({
126
134
  status: "busy",
127
135
  activeSessionId: "session-1",
136
+ frame: busyFrame,
137
+ });
138
+ expect(second.frames).toEqual([busyFrame]);
139
+ expect(sessions).toHaveLength(1);
140
+ expect(sessions[0]?.start).toHaveBeenCalledTimes(1);
141
+ });
142
+
143
+ test("names the holder's device and the conversation it landed in", async () => {
144
+ const sessions: TestSession[] = [];
145
+ const manager = new LiveVoiceSessionManager({
146
+ createSessionId: mock(() => `session-${sessions.length + 1}`),
147
+ createSession: (context) => {
148
+ const session = createTestSession({
149
+ start: mock(async () => {
150
+ await context.sendFrame({
151
+ type: "ready",
152
+ sessionId: context.sessionId,
153
+ // The session minted its own conversation, so the start frame's
154
+ // is not the one to send anybody to.
155
+ conversationId: "conversation-minted",
156
+ });
157
+ }),
158
+ });
159
+ sessions.push(session);
160
+ return session;
161
+ },
162
+ });
163
+ const second = createSink();
164
+
165
+ await manager.startSession(
166
+ { ...START_FRAME, client: "ios" },
167
+ createSink().sink,
168
+ );
169
+ const rejected = await manager.startSession(START_FRAME, second.sink);
170
+
171
+ expect(rejected).toMatchObject({
172
+ status: "busy",
128
173
  frame: {
129
- type: "busy",
130
- seq: 1,
131
- activeSessionId: "session-1",
174
+ holder: { client: "ios", conversationId: "conversation-minted" },
132
175
  },
133
176
  });
134
- expect(second.frames).toEqual([
135
- {
136
- type: "busy",
137
- seq: 1,
138
- activeSessionId: "session-1",
177
+ });
178
+
179
+ test("says nothing about a holder that revealed nothing", async () => {
180
+ const sessions: TestSession[] = [];
181
+ const manager = new LiveVoiceSessionManager({
182
+ createSessionId: mock(() => `session-${sessions.length + 1}`),
183
+ createSession: () => {
184
+ const session = createTestSession();
185
+ sessions.push(session);
186
+ return session;
139
187
  },
140
- ]);
141
- expect(sessions).toHaveLength(1);
142
- expect(sessions[0]?.start).toHaveBeenCalledTimes(1);
188
+ });
189
+ const anonymous = {
190
+ type: "start",
191
+ audio: START_FRAME.audio,
192
+ } as const satisfies LiveVoiceClientStartFrame;
193
+ const second = createSink();
194
+
195
+ await manager.startSession(anonymous, createSink().sink);
196
+ const rejected = await manager.startSession(anonymous, second.sink);
197
+
198
+ // An empty holder would read as "we know where it is" while naming
199
+ // nothing, so the field is dropped and the client uses its vaguer copy.
200
+ expect(rejected).toEqual({
201
+ status: "busy",
202
+ activeSessionId: "session-1",
203
+ frame: { type: "busy", seq: 1, activeSessionId: "session-1" },
204
+ });
143
205
  });
144
206
 
145
207
  test("releases the active session once for repeated close events", async () => {
@@ -6,6 +6,7 @@ import {
6
6
  type LiveVoiceClientStartFrame,
7
7
  type LiveVoiceServerFrame,
8
8
  type LiveVoiceServerFramePayload,
9
+ type LiveVoiceSessionHolder,
9
10
  } from "./protocol.js";
10
11
 
11
12
  type MaybePromise<T> = T | Promise<T>;
@@ -157,6 +158,23 @@ function waitForSlotRelease(
157
158
  });
158
159
  }
159
160
 
161
+ /** {@link LiveVoiceSessionHolder}, as the manager keeps it while filling it in. */
162
+ interface MutableLiveVoiceSessionHolder {
163
+ client?: LiveVoiceSessionHolder["client"];
164
+ conversationId?: string;
165
+ }
166
+
167
+ /** Drop an all-empty holder, so `busy` carries a field or says nothing. */
168
+ function describeHolder(
169
+ holder: MutableLiveVoiceSessionHolder,
170
+ ): LiveVoiceSessionHolder | null {
171
+ const described: MutableLiveVoiceSessionHolder = {
172
+ ...(holder.client ? { client: holder.client } : {}),
173
+ ...(holder.conversationId ? { conversationId: holder.conversationId } : {}),
174
+ };
175
+ return Object.keys(described).length > 0 ? described : null;
176
+ }
177
+
160
178
  export class LiveVoiceSessionStartupError extends Error {
161
179
  constructor(message: string) {
162
180
  super(message);
@@ -208,6 +226,8 @@ interface ActiveLiveVoiceSession {
208
226
  sessionId: string;
209
227
  session: LiveVoiceSession;
210
228
  sink: LiveVoiceServerFrameSink;
229
+ /** What a refused client is told about who holds the slot. */
230
+ holder: MutableLiveVoiceSessionHolder;
211
231
  closing: boolean;
212
232
  silenceTimer: ReturnType<typeof setTimeout> | null;
213
233
  /** Resolves once this session has let go of the slot, however it went. */
@@ -272,12 +292,15 @@ export class LiveVoiceSessionManager {
272
292
  }
273
293
  }
274
294
 
275
- const existingSessionId = this.activeSessionId;
276
- if (existingSessionId !== null) {
295
+ const existing = this.activeSession;
296
+ const existingSessionId = existing?.sessionId ?? null;
297
+ if (existing !== null && existingSessionId !== null) {
277
298
  const busySequencer = createLiveVoiceServerFrameSequencer();
299
+ const holder = describeHolder(existing.holder);
278
300
  const frame = busySequencer.next({
279
301
  type: "busy",
280
302
  activeSessionId: existingSessionId,
303
+ ...(holder ? { holder } : {}),
281
304
  });
282
305
  await sink.sendFrame(frame);
283
306
  return {
@@ -289,10 +312,23 @@ export class LiveVoiceSessionManager {
289
312
 
290
313
  const sessionId = this.createSessionId();
291
314
  const sequencer = createLiveVoiceServerFrameSequencer();
315
+ const holder: MutableLiveVoiceSessionHolder = {
316
+ ...(startFrame.client ? { client: startFrame.client } : {}),
317
+ ...(startFrame.conversationId
318
+ ? { conversationId: startFrame.conversationId }
319
+ : {}),
320
+ };
292
321
  const context: LiveVoiceSessionFactoryContext = {
293
322
  sessionId,
294
323
  startFrame,
295
324
  sendFrame: async (payload) => {
325
+ // `ready` carries the conversation the session actually landed in,
326
+ // which is the only source for one it minted itself. Read in passing
327
+ // rather than through a new session method: every frame already goes
328
+ // through here.
329
+ if (payload.type === "ready") {
330
+ holder.conversationId = payload.conversationId;
331
+ }
296
332
  const frame = sequencer.next(payload);
297
333
  await sink.sendFrame(frame);
298
334
  return frame;
@@ -310,6 +346,7 @@ export class LiveVoiceSessionManager {
310
346
  sessionId,
311
347
  session,
312
348
  sink,
349
+ holder,
313
350
  closing: false,
314
351
  silenceTimer: null,
315
352
  released,
@@ -280,9 +280,36 @@ export interface LiveVoiceReadyServerFrame extends LiveVoiceServerFrameBase {
280
280
  readonly audioInput?: boolean;
281
281
  }
282
282
 
283
+ /**
284
+ * Where the session holding the daemon's single live-voice slot is running,
285
+ * as much of it as the daemon knows.
286
+ *
287
+ * Display only: it is what lets a client refused a session say where the one
288
+ * that blocked it is. Nothing routes, authorizes, or decides capability on
289
+ * it, and every field is optional, so a holder that names neither its surface
290
+ * nor a conversation is simply less specific.
291
+ */
292
+ export interface LiveVoiceSessionHolder {
293
+ /**
294
+ * The OS surface the holder is running on, from its `start` frame. A
295
+ * {@link ClientOs} carries no transport meaning by contract (see
296
+ * `channels/types.ts`), which is exactly right for a label: it says which
297
+ * device the user should go looking on, and answers nothing else.
298
+ */
299
+ readonly client?: ClientOs;
300
+ /** The conversation the holder is talking in, once it has one. */
301
+ readonly conversationId?: string;
302
+ }
303
+
283
304
  export interface LiveVoiceBusyServerFrame extends LiveVoiceServerFrameBase {
284
305
  readonly type: "busy";
285
306
  readonly activeSessionId: string;
307
+ /**
308
+ * Absent from daemons that predate it, and from a holder that revealed
309
+ * neither field, so a client must degrade to the unspecific copy rather
310
+ * than assume.
311
+ */
312
+ readonly holder?: LiveVoiceSessionHolder;
286
313
  }
287
314
 
288
315
  /**