@vellumai/assistant 0.10.11-dev.202607222029.495c516 → 0.10.11-dev.202607222129.31c06e5

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/approval-source-link.test.ts +208 -0
  3. package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -1
  4. package/src/__tests__/slack-notification-approval-card.test.ts +103 -20
  5. package/src/__tests__/tool-approval-seed-content-blocks.test.ts +179 -96
  6. package/src/api/events/memory-recalled.ts +59 -0
  7. package/src/api/events/memory-status.ts +29 -0
  8. package/src/api/index.ts +16 -0
  9. package/src/calls/__tests__/voice-triage-escalate.test.ts +58 -3
  10. package/src/calls/voice-session-bridge.ts +6 -2
  11. package/src/calls/voice-triage-escalate.ts +30 -1
  12. package/src/config/feature-flag-registry.json +9 -0
  13. package/src/daemon/conversation-tool-setup.ts +7 -3
  14. package/src/daemon/message-types/memory.ts +8 -46
  15. package/src/daemon/trust-context-types.ts +8 -0
  16. package/src/messaging/providers/slack/approval-source.ts +87 -0
  17. package/src/notifications/AGENTS.md +2 -0
  18. package/src/notifications/adapters/slack.ts +67 -13
  19. package/src/notifications/approval-card-data.ts +58 -16
  20. package/src/notifications/broadcaster.ts +41 -19
  21. package/src/notifications/guardian-question-mode.ts +81 -0
  22. package/src/notifications/types.ts +5 -0
  23. package/src/persistence/delivery-crud.ts +48 -1
  24. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +2 -2
  25. package/src/plugins/mtime-cache.ts +21 -10
  26. package/src/runtime/approval-source-link.ts +107 -0
  27. package/src/runtime/confirmation-request-guardian-bridge.ts +9 -0
  28. package/src/runtime/routes/inbound-message-handler.ts +4 -0
  29. package/src/runtime/tool-grant-request-helper.ts +14 -0
  30. package/src/tools/registry.ts +26 -17
  31. package/src/tools/tool-approval-handler.ts +2 -0
  32. package/src/tools/types.ts +8 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.11-dev.202607222029.495c516",
3
+ "version": "0.10.11-dev.202607222129.31c06e5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,208 @@
1
+ import { beforeEach, describe, expect, test } from "bun:test";
2
+
3
+ import { getDb } from "../persistence/db-connection.js";
4
+ import { initializeDb } from "../persistence/db-init.js";
5
+ import { recordInbound } from "../persistence/delivery-crud.js";
6
+ import { upsertBinding } from "../persistence/external-conversation-store.js";
7
+ import { resolveApprovalSourceReference } from "../runtime/approval-source-link.js";
8
+
9
+ await initializeDb();
10
+
11
+ function resetTables() {
12
+ const db = getDb();
13
+ db.run("DELETE FROM channel_inbound_events");
14
+ db.run("DELETE FROM conversation_keys");
15
+ db.run("DELETE FROM external_conversation_bindings");
16
+ db.run("DELETE FROM conversations");
17
+ }
18
+
19
+ describe("resolveApprovalSourceReference", () => {
20
+ beforeEach(resetTables);
21
+
22
+ test("returns null for channels without a registered resolver", () => {
23
+ const result = recordInbound("telegram", "12345", "evt-1", {
24
+ sourceMessageId: "678",
25
+ });
26
+ expect(
27
+ resolveApprovalSourceReference("telegram", result.conversationId),
28
+ ).toBeNull();
29
+ });
30
+
31
+ test("returns null for a conversation with no Slack provenance", () => {
32
+ expect(resolveApprovalSourceReference("slack", "conv-none")).toBeNull();
33
+ });
34
+
35
+ test("resolves chat id and message permalink from the latest inbound event (DM)", () => {
36
+ const result = recordInbound("slack", "D01XYZ", "evt-1", {
37
+ sourceMessageId: "1700000000.000100",
38
+ });
39
+
40
+ expect(
41
+ resolveApprovalSourceReference("slack", result.conversationId),
42
+ ).toEqual({
43
+ sourceChatId: "D01XYZ",
44
+ sourceLink: {
45
+ webUrl: "https://slack.com/archives/D01XYZ/p1700000000000100",
46
+ },
47
+ });
48
+ });
49
+
50
+ test("uses the most recent inbound event when several exist", () => {
51
+ const first = recordInbound("slack", "D01XYZ", "evt-1", {
52
+ sourceMessageId: "1699999900.000001",
53
+ });
54
+ recordInbound("slack", "D01XYZ", "evt-2", {
55
+ sourceMessageId: "1700000000.000100",
56
+ });
57
+
58
+ expect(
59
+ resolveApprovalSourceReference("slack", first.conversationId),
60
+ ).toEqual({
61
+ sourceChatId: "D01XYZ",
62
+ sourceLink: {
63
+ webUrl: "https://slack.com/archives/D01XYZ/p1700000000000100",
64
+ },
65
+ });
66
+ });
67
+
68
+ test("threaded conversations link the message inside its thread", () => {
69
+ const result = recordInbound("slack", "C01ABC", "evt-1", {
70
+ sourceMessageId: "1700000001.000200",
71
+ sourceThreadId: "1700000000.000100",
72
+ });
73
+ upsertBinding({
74
+ conversationId: result.conversationId,
75
+ sourceChannel: "slack",
76
+ externalChatId: "C01ABC",
77
+ externalThreadId: "1700000000.000100",
78
+ });
79
+
80
+ expect(
81
+ resolveApprovalSourceReference("slack", result.conversationId),
82
+ ).toEqual({
83
+ sourceChatId: "C01ABC",
84
+ sourceLink: {
85
+ webUrl:
86
+ "https://slack.com/archives/C01ABC/p1700000001000200?thread_ts=1700000000.000100&cid=C01ABC",
87
+ },
88
+ });
89
+ });
90
+
91
+ test("a thread-root message carries no thread params", () => {
92
+ const result = recordInbound("slack", "C01ABC", "evt-1", {
93
+ sourceMessageId: "1700000000.000100",
94
+ sourceThreadId: "1700000000.000100",
95
+ });
96
+ upsertBinding({
97
+ conversationId: result.conversationId,
98
+ sourceChannel: "slack",
99
+ externalChatId: "C01ABC",
100
+ externalThreadId: "1700000000.000100",
101
+ });
102
+
103
+ expect(
104
+ resolveApprovalSourceReference("slack", result.conversationId),
105
+ ).toEqual({
106
+ sourceChatId: "C01ABC",
107
+ sourceLink: {
108
+ webUrl: "https://slack.com/archives/C01ABC/p1700000000000100",
109
+ },
110
+ });
111
+ });
112
+
113
+ test("falls back to a ts-shaped externalMessageId when sourceMessageId is absent", () => {
114
+ const result = recordInbound("slack", "D01XYZ", "1700000000.000100");
115
+
116
+ expect(
117
+ resolveApprovalSourceReference("slack", result.conversationId),
118
+ ).toEqual({
119
+ sourceChatId: "D01XYZ",
120
+ sourceLink: {
121
+ webUrl: "https://slack.com/archives/D01XYZ/p1700000000000100",
122
+ },
123
+ });
124
+ });
125
+
126
+ test("omits the link when no id is ts-shaped", () => {
127
+ const result = recordInbound("slack", "D01XYZ", "evt-opaque");
128
+
129
+ expect(
130
+ resolveApprovalSourceReference("slack", result.conversationId),
131
+ ).toEqual({
132
+ sourceChatId: "D01XYZ",
133
+ });
134
+ });
135
+
136
+ test("an ingress-stamped hint identifies the exact message, immune to later inbound rows", () => {
137
+ // A second message lands while the first message's turn is still
138
+ // escalating — the hint pins the card to the actual triggering message.
139
+ const result = recordInbound("slack", "D01XYZ", "evt-1", {
140
+ sourceMessageId: "1699999900.000001",
141
+ });
142
+ recordInbound("slack", "D01XYZ", "evt-2", {
143
+ sourceMessageId: "1700000000.000100",
144
+ });
145
+
146
+ expect(
147
+ resolveApprovalSourceReference("slack", result.conversationId, {
148
+ requesterChatId: "D01XYZ",
149
+ sourceMessageId: "1699999900.000001",
150
+ }),
151
+ ).toEqual({
152
+ sourceChatId: "D01XYZ",
153
+ sourceLink: {
154
+ webUrl: "https://slack.com/archives/D01XYZ/p1699999900000001",
155
+ },
156
+ });
157
+ });
158
+
159
+ test("a threaded hint links the message inside its thread without a DB row", () => {
160
+ expect(
161
+ resolveApprovalSourceReference("slack", "conv-unpersisted", {
162
+ requesterChatId: "C01ABC",
163
+ sourceMessageId: "1700000001.000200",
164
+ sourceThreadId: "1700000000.000100",
165
+ }),
166
+ ).toEqual({
167
+ sourceChatId: "C01ABC",
168
+ sourceLink: {
169
+ webUrl:
170
+ "https://slack.com/archives/C01ABC/p1700000001000200?thread_ts=1700000000.000100&cid=C01ABC",
171
+ },
172
+ });
173
+ });
174
+
175
+ test("a hint without a ts-shaped message id falls back to persisted reconstruction", () => {
176
+ const result = recordInbound("slack", "D01XYZ", "evt-1", {
177
+ sourceMessageId: "1700000000.000100",
178
+ });
179
+
180
+ expect(
181
+ resolveApprovalSourceReference("slack", result.conversationId, {
182
+ requesterChatId: "D01XYZ",
183
+ sourceMessageId: "not-a-ts",
184
+ }),
185
+ ).toEqual({
186
+ sourceChatId: "D01XYZ",
187
+ sourceLink: {
188
+ webUrl: "https://slack.com/archives/D01XYZ/p1700000000000100",
189
+ },
190
+ });
191
+ });
192
+
193
+ test("ignores bindings from other channels", () => {
194
+ const result = recordInbound("slack", "D01XYZ", "evt-opaque");
195
+ upsertBinding({
196
+ conversationId: result.conversationId,
197
+ sourceChannel: "telegram",
198
+ externalChatId: "12345",
199
+ externalThreadId: "1700000000.000100",
200
+ });
201
+
202
+ expect(
203
+ resolveApprovalSourceReference("slack", result.conversationId),
204
+ ).toEqual({
205
+ sourceChatId: "D01XYZ",
206
+ });
207
+ });
208
+ });
@@ -102,6 +102,7 @@ const BASELINE: Record<string, readonly string[]> = {
102
102
  "../../../../../runtime/background-job-runner.js",
103
103
  "../../../../../security/untrusted-content.js",
104
104
  "../../../../agent/image-optimize.js",
105
+ "../../../../api/events/memory-recalled.js",
105
106
  "../../../../api/responses/memory-v3-selection-log.js",
106
107
  "../../../../config/assistant-feature-flags.js",
107
108
  "../../../../config/default-profile-catalog.js",
@@ -117,7 +118,6 @@ const BASELINE: Record<string, readonly string[]> = {
117
118
  "../../../../daemon/conversation-registry.js",
118
119
  "../../../../daemon/conversation-runtime-assembly.js",
119
120
  "../../../../daemon/message-protocol.js",
120
- "../../../../daemon/message-types/memory.js",
121
121
  "../../../../daemon/trust-context.js",
122
122
  "../../../../daemon/turn-latency-sub-spans.js",
123
123
  "../../../../persistence/checkpoints.js",
@@ -1,5 +1,14 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
 
3
+ import type {
4
+ CardBlock,
5
+ ContextBlock,
6
+ KnownBlock,
7
+ MrkdwnElement,
8
+ PlainTextElement,
9
+ SectionBlock,
10
+ } from "@slack/types";
11
+
3
12
  import { parseAccessRequestPayload } from "../notifications/access-request-copy.js";
4
13
  import { buildApprovalNotificationBlocks } from "../notifications/adapters/slack.js";
5
14
  import type { ChannelDeliveryPayload } from "../notifications/types.js";
@@ -35,27 +44,28 @@ function buildPayload(
35
44
  };
36
45
  }
37
46
 
38
- type Block = Record<string, unknown>;
39
-
40
- function card(blocks: unknown[]): Block {
41
- const c = (blocks as Block[]).find((b) => b.type === "card");
47
+ // Narrowing helpers over the `@slack/types` block union so assertions read
48
+ // typed fields — a block-contract change fails compilation here instead of
49
+ // slipping through a cast.
50
+ function card(blocks: KnownBlock[]): CardBlock {
51
+ const c = blocks.find((b): b is CardBlock => b.type === "card");
42
52
  if (!c) {
43
53
  throw new Error("no card block");
44
54
  }
45
55
  return c;
46
56
  }
47
57
 
48
- function contextTexts(blocks: unknown[]): string[] {
49
- return (blocks as Block[])
50
- .filter((b) => b.type === "context")
51
- .map((b) => {
52
- const elements = b.elements as Array<{ text: string }>;
53
- return elements.map((e) => e.text).join("");
54
- });
58
+ function contextTexts(blocks: KnownBlock[]): string[] {
59
+ return blocks
60
+ .filter((b): b is ContextBlock => b.type === "context")
61
+ .map((b) => b.elements.map((e) => ("text" in e ? e.text : "")).join(""));
55
62
  }
56
63
 
57
- function text(node: unknown): string {
58
- return (node as { text: string }).text;
64
+ function text(node: MrkdwnElement | PlainTextElement | undefined): string {
65
+ if (!node) {
66
+ throw new Error("expected a text element");
67
+ }
68
+ return node.text;
59
69
  }
60
70
 
61
71
  const BASE: Record<string, unknown> = {
@@ -81,7 +91,7 @@ describe("Slack access-request card blocks", () => {
81
91
 
82
92
  test("card actions encode the apr:<requestId>:<action> callback ids", () => {
83
93
  const c = card(buildApprovalNotificationBlocks(buildPayload(BASE), "msg"));
84
- const actions = c.actions as Array<Record<string, unknown>>;
94
+ const actions = c.actions ?? [];
85
95
  expect(actions).toHaveLength(2);
86
96
  expect(actions[0].action_id).toBe("apr:req-123:approve_once");
87
97
  expect(actions[0].style).toBe("primary");
@@ -136,7 +146,7 @@ describe("Slack access-request card blocks", () => {
136
146
  );
137
147
  // `subtext` is not a Slack card field; warnings must live in a real block
138
148
  // or Slack drops them and the guardian never sees them.
139
- expect(card(blocks).subtext).toBeUndefined();
149
+ expect("subtext" in card(blocks)).toBe(false);
140
150
  const warning = contextTexts(blocks).find((t) => t.includes(":warning:"));
141
151
  expect(warning).toBeDefined();
142
152
  expect(warning).toContain(":warning: This user was previously revoked.");
@@ -148,7 +158,7 @@ describe("Slack access-request card blocks", () => {
148
158
 
149
159
  test("no warning context block when there are no warnings", () => {
150
160
  const blocks = buildApprovalNotificationBlocks(buildPayload(BASE), "msg");
151
- expect(card(blocks).subtext).toBeUndefined();
161
+ expect("subtext" in card(blocks)).toBe(false);
152
162
  expect(contextTexts(blocks).some((t) => t.includes(":warning:"))).toBe(
153
163
  false,
154
164
  );
@@ -192,18 +202,21 @@ const TOOL_APPROVAL: ApprovalUIMetadata = {
192
202
  },
193
203
  };
194
204
 
195
- function buildToolApprovalPayload(): ChannelDeliveryPayload {
205
+ function buildToolApprovalPayload(
206
+ toolApprovalSource?: ChannelDeliveryPayload["toolApprovalSource"],
207
+ ): ChannelDeliveryPayload {
196
208
  return {
197
209
  sourceEventName: "guardian.question",
198
210
  copy: { title: "Guardian Question", body: "Approve tool: bash" },
199
211
  urgency: "high",
200
212
  approvalContext: TOOL_APPROVAL,
213
+ toolApprovalSource,
201
214
  };
202
215
  }
203
216
 
204
- function sectionTexts(blocks: unknown[]): string[] {
205
- return (blocks as Block[])
206
- .filter((b) => b.type === "section")
217
+ function sectionTexts(blocks: KnownBlock[]): string[] {
218
+ return blocks
219
+ .filter((b): b is SectionBlock => b.type === "section")
207
220
  .map((b) => text(b.text));
208
221
  }
209
222
 
@@ -260,4 +273,74 @@ describe("Slack tool-approval card blocks", () => {
260
273
  expect(text(card(blocks).body)).toBe(`${"a".repeat(190)} ↓`);
261
274
  expect(sectionTexts(blocks)[0]).toBe(`… ${"b".repeat(60)}`);
262
275
  });
276
+
277
+ test("Slack DM source reference renders a source context block with permalink", () => {
278
+ const blocks = buildApprovalNotificationBlocks(
279
+ buildToolApprovalPayload({
280
+ channel: "slack",
281
+ chatId: "D01XYZ",
282
+ isSlackDm: true,
283
+ permalink: "https://slack.com/archives/D01XYZ/p1700000000000100",
284
+ }),
285
+ "msg",
286
+ );
287
+ expect(contextTexts(blocks)).toContain(
288
+ "Source: Slack — Direct message · <https://slack.com/archives/D01XYZ/p1700000000000100|View message>",
289
+ );
290
+ });
291
+
292
+ test("Slack channel source renders a channel mention with permalink", () => {
293
+ const blocks = buildApprovalNotificationBlocks(
294
+ buildToolApprovalPayload({
295
+ channel: "slack",
296
+ chatId: "C01ABC",
297
+ isSlackDm: false,
298
+ permalink:
299
+ "https://slack.com/archives/C01ABC/p1700000001000200?thread_ts=1700000000.000100&cid=C01ABC",
300
+ }),
301
+ "msg",
302
+ );
303
+ expect(contextTexts(blocks)).toContain(
304
+ "Source: Slack — <#C01ABC> · <https://slack.com/archives/C01ABC/p1700000001000200?thread_ts=1700000000.000100&cid=C01ABC|View message>",
305
+ );
306
+ });
307
+
308
+ test("a non-Slack source with a link renders a generic source line", () => {
309
+ const blocks = buildApprovalNotificationBlocks(
310
+ buildToolApprovalPayload({
311
+ channel: "discord",
312
+ chatId: "chat-123",
313
+ isSlackDm: false,
314
+ permalink: "https://example.com/messages/42",
315
+ }),
316
+ "msg",
317
+ );
318
+ expect(contextTexts(blocks)).toContain(
319
+ "Source: discord · <https://example.com/messages/42|View message>",
320
+ );
321
+ });
322
+
323
+ test("no source context block without a source reference", () => {
324
+ const blocks = buildApprovalNotificationBlocks(
325
+ buildToolApprovalPayload(),
326
+ "msg",
327
+ );
328
+ expect(contextTexts(blocks).some((t) => t.startsWith("Source:"))).toBe(
329
+ false,
330
+ );
331
+ });
332
+
333
+ test("no source context block for a non-Slack source without a link", () => {
334
+ const blocks = buildApprovalNotificationBlocks(
335
+ buildToolApprovalPayload({
336
+ channel: "telegram",
337
+ chatId: "12345",
338
+ isSlackDm: false,
339
+ }),
340
+ "msg",
341
+ );
342
+ expect(contextTexts(blocks).some((t) => t.startsWith("Source:"))).toBe(
343
+ false,
344
+ );
345
+ });
263
346
  });