@vellumai/assistant 0.12.2-dev.202609182015.188de8a → 0.12.2-dev.202609182214.bd8f92f
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/ARCHITECTURE.md +8 -6
- package/docs/architecture/turn-actor.md +2 -0
- package/openapi.yaml +108 -9
- package/package.json +1 -1
- package/src/__tests__/approval-message-composer.test.ts +1 -118
- package/src/__tests__/assistant-event-hub-connection-history.test.ts +111 -0
- package/src/__tests__/assistant-event-targeting.test.ts +186 -0
- package/src/__tests__/assistant-stream-state.test.ts +7 -9
- package/src/__tests__/channel-retry-sweep.test.ts +9 -0
- package/src/__tests__/dm-backfill.test.ts +91 -1
- package/src/__tests__/emit-signal-routing-intent.test.ts +141 -1
- package/src/__tests__/helpers/verification-sessions-ipc-sim.ts +5 -0
- package/src/__tests__/message-provenance-contact-id.test.ts +69 -0
- package/src/__tests__/process-message-display-content.test.ts +56 -0
- package/src/__tests__/reaction-persistence.test.ts +5 -0
- package/src/__tests__/runtime-events-sse-reconnect.test.ts +1 -1
- package/src/__tests__/scripted-turn-metadata-persistence.test.ts +73 -0
- package/src/__tests__/thread-backfill.test.ts +53 -0
- package/src/approvals/AGENTS.md +1 -1
- package/src/calls/__tests__/voice-escalation-judge.test.ts +3 -3
- package/src/calls/guardian-action-sweep.ts +2 -3
- package/src/calls/typesafe-noul.ts +156 -0
- package/src/calls/voice-escalation-judge.ts +30 -139
- package/src/cli/__tests__/roadmap-cli.test.ts +4 -41
- package/src/cli/commands/__tests__/notifications.test.ts +25 -0
- package/src/cli/commands/clients.help.ts +46 -0
- package/src/cli/commands/clients.ts +116 -0
- package/src/cli/commands/notifications.help.ts +16 -2
- package/src/cli/commands/notifications.ts +30 -8
- package/src/cli/commands/roadmap.help.ts +18 -21
- package/src/cli/commands/roadmap.ts +4 -21
- package/src/config/call-site-defaults.ts +4 -0
- package/src/config/schemas/call-site-catalog.ts +7 -0
- package/src/config/schemas/llm.ts +1 -0
- package/src/daemon/conversation-messaging.ts +19 -1
- package/src/daemon/message-provenance.ts +23 -0
- package/src/daemon/process-message.ts +13 -4
- package/src/live-voice/__tests__/continuation-judge.test.ts +151 -0
- package/src/live-voice/__tests__/live-voice-vad.test.ts +215 -0
- package/src/live-voice/continuation-judge.ts +123 -0
- package/src/live-voice/live-voice-session.ts +193 -0
- package/src/notifications/README.md +2 -0
- package/src/notifications/__tests__/channel-allowlist.test.ts +39 -0
- package/src/notifications/__tests__/decision-engine.test.ts +75 -0
- package/src/notifications/__tests__/home-feed-side-effect.test.ts +87 -0
- package/src/notifications/__tests__/notification-utils.test.ts +18 -0
- package/src/notifications/channel-allowlist.ts +44 -0
- package/src/notifications/decision-engine.ts +24 -14
- package/src/notifications/emit-signal.ts +101 -22
- package/src/notifications/home-feed-side-effect.ts +5 -1
- package/src/notifications/notification-utils.ts +19 -0
- package/src/notifications/types.ts +15 -0
- package/src/persistence/__tests__/client-connection-events-store.test.ts +322 -0
- package/src/persistence/client-connection-events-store.ts +377 -0
- package/src/persistence/conversation-crud.ts +16 -0
- package/src/persistence/migrations/382-create-client-connection-events.ts +40 -0
- package/src/persistence/migrations/__tests__/382-create-client-connection-events.test.ts +56 -0
- package/src/persistence/schema/infrastructure.ts +29 -0
- package/src/persistence/steps.ts +2 -0
- package/src/plugins/defaults/memory/__tests__/archive-removal-framing.test.ts +64 -0
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +2 -2
- package/src/plugins/defaults/memory/tools.test.ts +24 -1
- package/src/plugins/defaults/memory/tools.ts +12 -1
- package/src/runtime/approval-message-composer.ts +3 -69
- package/src/runtime/assistant-event-hub.ts +63 -89
- package/src/runtime/assistant-event-targeting.ts +79 -0
- package/src/runtime/assistant-stream-state.ts +13 -112
- package/src/runtime/channel-retry-sweep.ts +1 -0
- package/src/runtime/guardian-action-message-composer.ts +8 -161
- package/src/runtime/http-types.ts +6 -0
- package/src/runtime/message-composer-types.ts +3 -61
- package/src/runtime/routes/__tests__/client-history-routes.test.ts +104 -0
- package/src/runtime/routes/__tests__/roadmap-routes.test.ts +29 -6
- package/src/runtime/routes/client-routes.ts +108 -0
- package/src/runtime/routes/events-routes.ts +18 -9
- package/src/runtime/routes/inbound-message-handler.ts +35 -38
- package/src/runtime/routes/inbound-stages/backfill-sender-provenance.test.ts +168 -0
- package/src/runtime/routes/inbound-stages/backfill-sender-provenance.ts +96 -0
- package/src/runtime/routes/inbound-stages/background-dispatch.test.ts +29 -0
- package/src/runtime/routes/inbound-stages/background-dispatch.ts +1 -0
- package/src/runtime/routes/inbound-stages/reaction-intercept.ts +2 -0
- package/src/runtime/routes/notification-routes.ts +10 -0
- package/src/runtime/routes/roadmap-routes.ts +47 -8
- package/src/util/canonicalize-identity.test.ts +21 -0
- package/src/util/canonicalize-identity.ts +16 -0
|
@@ -9,10 +9,8 @@ import { dirname, join } from "node:path";
|
|
|
9
9
|
import { beforeEach, describe, expect, test } from "bun:test";
|
|
10
10
|
|
|
11
11
|
import type { AssistantEventEnvelope } from "../api/index.js";
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
ReplaySubscriber,
|
|
15
|
-
} from "../runtime/assistant-stream-state.js";
|
|
12
|
+
import type { AssistantEventPublishOptions } from "../runtime/assistant-event-publish-options.js";
|
|
13
|
+
import type { SubscriberIdentity } from "../runtime/assistant-event-targeting.js";
|
|
16
14
|
import {
|
|
17
15
|
_peekStreamForTesting,
|
|
18
16
|
_resetStreamStateForTesting,
|
|
@@ -103,7 +101,7 @@ describe("assistant-stream-state", () => {
|
|
|
103
101
|
/** Targeted events stay in the ring so replay can filter them. */
|
|
104
102
|
|
|
105
103
|
// GIVEN a targeting modifier
|
|
106
|
-
const targeting:
|
|
104
|
+
const targeting: AssistantEventPublishOptions = {
|
|
107
105
|
targetCapability: "host_bash",
|
|
108
106
|
};
|
|
109
107
|
|
|
@@ -334,28 +332,28 @@ describe("assistant-stream-state", () => {
|
|
|
334
332
|
});
|
|
335
333
|
|
|
336
334
|
describe("getReplayWindow — targeting filter", () => {
|
|
337
|
-
const MACOS_CLIENT:
|
|
335
|
+
const MACOS_CLIENT: SubscriberIdentity = {
|
|
338
336
|
type: "client",
|
|
339
337
|
clientId: "mac-1",
|
|
340
338
|
interfaceId: "macos",
|
|
341
339
|
capabilities: ["host_bash", "host_file", "host_cu", "host_browser"],
|
|
342
340
|
};
|
|
343
341
|
|
|
344
|
-
const WEB_CLIENT:
|
|
342
|
+
const WEB_CLIENT: SubscriberIdentity = {
|
|
345
343
|
type: "client",
|
|
346
344
|
clientId: "web-1",
|
|
347
345
|
interfaceId: "web",
|
|
348
346
|
capabilities: [],
|
|
349
347
|
};
|
|
350
348
|
|
|
351
|
-
const CHROME_EXT_CLIENT:
|
|
349
|
+
const CHROME_EXT_CLIENT: SubscriberIdentity = {
|
|
352
350
|
type: "client",
|
|
353
351
|
clientId: "ext-1",
|
|
354
352
|
interfaceId: "chrome-extension",
|
|
355
353
|
capabilities: ["host_browser"],
|
|
356
354
|
};
|
|
357
355
|
|
|
358
|
-
const PROCESS_SUB:
|
|
356
|
+
const PROCESS_SUB: SubscriberIdentity = { type: "process" };
|
|
359
357
|
|
|
360
358
|
test("untargeted events are replayed to all subscriber types", () => {
|
|
361
359
|
/** Events without targeting metadata go to everyone. */
|
|
@@ -98,6 +98,7 @@ import {
|
|
|
98
98
|
clearConversations,
|
|
99
99
|
setConversation,
|
|
100
100
|
} from "../daemon/conversation-registry.js";
|
|
101
|
+
import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
101
102
|
import { getDb } from "../persistence/db-connection.js";
|
|
102
103
|
import { initializeDb } from "../persistence/db-init.js";
|
|
103
104
|
import * as deliveryCrud from "../persistence/delivery-crud.js";
|
|
@@ -318,7 +319,11 @@ describe("channel-retry-sweep", () => {
|
|
|
318
319
|
}
|
|
319
320
|
| undefined;
|
|
320
321
|
|
|
322
|
+
let capturedAuthor: TrustContext | undefined;
|
|
323
|
+
let capturedTrust: TrustContext | undefined;
|
|
321
324
|
await sweepFailedEvents(async (conversationId, _content, options) => {
|
|
325
|
+
capturedAuthor = options?.author;
|
|
326
|
+
capturedTrust = options?.trustContext;
|
|
322
327
|
capturedOptions = options as {
|
|
323
328
|
trustContext?: {
|
|
324
329
|
trustClass?: string;
|
|
@@ -345,6 +350,10 @@ describe("channel-retry-sweep", () => {
|
|
|
345
350
|
"principal-1",
|
|
346
351
|
);
|
|
347
352
|
expect(capturedOptions?.isInteractive).toBe(c.expectedInteractive);
|
|
353
|
+
// The replay persists the sender's own message, so it names them as
|
|
354
|
+
// the row's author, exactly as live ingress does.
|
|
355
|
+
expect(capturedAuthor?.trustClass).toBe(c.trustClass);
|
|
356
|
+
expect(capturedAuthor).toEqual(capturedTrust);
|
|
348
357
|
|
|
349
358
|
const db = getDb();
|
|
350
359
|
const row = db
|
|
@@ -11,7 +11,15 @@
|
|
|
11
11
|
* - When `backfillDm` throws, the turn proceeds without a crash and
|
|
12
12
|
* nothing extra is persisted.
|
|
13
13
|
*/
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
afterAll,
|
|
16
|
+
beforeEach,
|
|
17
|
+
describe,
|
|
18
|
+
expect,
|
|
19
|
+
mock,
|
|
20
|
+
spyOn,
|
|
21
|
+
test,
|
|
22
|
+
} from "bun:test";
|
|
15
23
|
|
|
16
24
|
// ---------------------------------------------------------------------------
|
|
17
25
|
// Mocks (must precede module imports under test)
|
|
@@ -68,6 +76,7 @@ mock.module("../messaging/providers/slack/backfill.js", () => ({
|
|
|
68
76
|
backfillThread: () => backfillThreadMock(),
|
|
69
77
|
}));
|
|
70
78
|
|
|
79
|
+
import * as inboundTrustReader from "../calls/inbound-trust-reader.js";
|
|
71
80
|
import {
|
|
72
81
|
loadRawConfig,
|
|
73
82
|
saveRawConfig,
|
|
@@ -87,6 +96,15 @@ import {
|
|
|
87
96
|
|
|
88
97
|
await initializeDb();
|
|
89
98
|
|
|
99
|
+
// Backfilled senders are classified by the gateway verdict; with no gateway
|
|
100
|
+
// in the test process the read reports unreachable unless a test says so.
|
|
101
|
+
// A spy rather than mock.module, so the stub does not leak into other files.
|
|
102
|
+
const readInboundTrustMock = spyOn(inboundTrustReader, "readInboundTrust");
|
|
103
|
+
|
|
104
|
+
afterAll(() => {
|
|
105
|
+
readInboundTrustMock.mockRestore();
|
|
106
|
+
});
|
|
107
|
+
|
|
90
108
|
// ---------------------------------------------------------------------------
|
|
91
109
|
// Helpers
|
|
92
110
|
// ---------------------------------------------------------------------------
|
|
@@ -180,6 +198,8 @@ function readPersistedSlackRows(): Array<{
|
|
|
180
198
|
provenanceSourceChannel: string | undefined;
|
|
181
199
|
provenanceGuardianExternalUserId: string | undefined;
|
|
182
200
|
provenanceRequesterIdentifier: string | undefined;
|
|
201
|
+
provenanceContactId: string | undefined;
|
|
202
|
+
provenanceLookupFailed: boolean | undefined;
|
|
183
203
|
sentAt: number | undefined;
|
|
184
204
|
createdAt: number;
|
|
185
205
|
}> {
|
|
@@ -234,6 +254,14 @@ function readPersistedSlackRows(): Array<{
|
|
|
234
254
|
typeof envelope.provenanceRequesterIdentifier === "string"
|
|
235
255
|
? envelope.provenanceRequesterIdentifier
|
|
236
256
|
: undefined,
|
|
257
|
+
provenanceContactId:
|
|
258
|
+
typeof envelope.provenanceContactId === "string"
|
|
259
|
+
? envelope.provenanceContactId
|
|
260
|
+
: undefined,
|
|
261
|
+
provenanceLookupFailed:
|
|
262
|
+
typeof envelope.provenanceLookupFailed === "boolean"
|
|
263
|
+
? envelope.provenanceLookupFailed
|
|
264
|
+
: undefined,
|
|
237
265
|
sentAt:
|
|
238
266
|
typeof envelope.sentAt === "number" ? envelope.sentAt : undefined,
|
|
239
267
|
createdAt: row.createdAt,
|
|
@@ -279,6 +307,8 @@ describe("PR 23 — Slack DM cold-start backfill", () => {
|
|
|
279
307
|
backfillDmMock.mockReset();
|
|
280
308
|
backfillDmMock.mockImplementation(async () => []);
|
|
281
309
|
backfillThreadMock.mockReset();
|
|
310
|
+
readInboundTrustMock.mockReset();
|
|
311
|
+
readInboundTrustMock.mockImplementation(async () => ({ ok: false }));
|
|
282
312
|
});
|
|
283
313
|
|
|
284
314
|
test("first DM in cold conversation triggers backfill exactly once and persists history", async () => {
|
|
@@ -335,6 +365,8 @@ describe("PR 23 — Slack DM cold-start backfill", () => {
|
|
|
335
365
|
expect(meta!.channelId).toBe(SLACK_DM_CHANNEL_ID);
|
|
336
366
|
expect(meta!.actorExternalUserId).toBe(SLACK_DM_USER_ID);
|
|
337
367
|
expect(r.provenanceTrustClass).toBe("unknown");
|
|
368
|
+
// No gateway in the test process: the lookup failed, and the row says so.
|
|
369
|
+
expect(r.provenanceLookupFailed).toBe(true);
|
|
338
370
|
expect(r.provenanceSourceChannel).toBe("slack");
|
|
339
371
|
expect(r.provenanceRequesterIdentifier).toBe(SLACK_DM_USER_ID);
|
|
340
372
|
return meta!.channelTs;
|
|
@@ -523,6 +555,64 @@ describe("PR 23 — Slack DM cold-start backfill", () => {
|
|
|
523
555
|
expect(botRow?.provenanceRequesterIdentifier).toBe("B_BOT");
|
|
524
556
|
});
|
|
525
557
|
|
|
558
|
+
test("backfilled rows record the sender's gateway trust class and contact id", async () => {
|
|
559
|
+
readInboundTrustMock.mockImplementation(async (input) =>
|
|
560
|
+
input.actorExternalId === SLACK_DM_USER_ID
|
|
561
|
+
? {
|
|
562
|
+
ok: true,
|
|
563
|
+
verdict: {
|
|
564
|
+
trustClass: "trusted_contact",
|
|
565
|
+
canonicalSenderId: SLACK_DM_USER_ID,
|
|
566
|
+
contactId: "contact-dm-user",
|
|
567
|
+
channelId: "channel-dm-user",
|
|
568
|
+
status: "active",
|
|
569
|
+
policy: "allow",
|
|
570
|
+
},
|
|
571
|
+
admissionPolicy: null,
|
|
572
|
+
}
|
|
573
|
+
: { ok: false },
|
|
574
|
+
);
|
|
575
|
+
backfillDmMock.mockImplementation(async () => [
|
|
576
|
+
makeBackfilledMessage({
|
|
577
|
+
id: "1700000000.000001",
|
|
578
|
+
text: "first from member",
|
|
579
|
+
}),
|
|
580
|
+
makeBackfilledMessage({
|
|
581
|
+
id: "1700000000.000002",
|
|
582
|
+
text: "assistant's own post",
|
|
583
|
+
sender: { id: "U_BOT", name: "assistant-bot" },
|
|
584
|
+
metadata: { isBot: true },
|
|
585
|
+
}),
|
|
586
|
+
makeBackfilledMessage({
|
|
587
|
+
id: "1700000000.000003",
|
|
588
|
+
text: "second from member",
|
|
589
|
+
}),
|
|
590
|
+
]);
|
|
591
|
+
|
|
592
|
+
await handleChannelInbound(
|
|
593
|
+
buildDmRequest("live new DM"),
|
|
594
|
+
noopProcessMessage,
|
|
595
|
+
TEST_BEARER_TOKEN,
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const rows = readPersistedSlackRows();
|
|
599
|
+
const memberRows = rows.filter((r) => r.role === "user");
|
|
600
|
+
expect(memberRows.map((r) => r.content).sort()).toEqual([
|
|
601
|
+
"first from member",
|
|
602
|
+
"second from member",
|
|
603
|
+
]);
|
|
604
|
+
for (const row of memberRows) {
|
|
605
|
+
expect(row.provenanceTrustClass).toBe("trusted_contact");
|
|
606
|
+
expect(row.provenanceContactId).toBe("contact-dm-user");
|
|
607
|
+
expect(row.provenanceLookupFailed).toBeUndefined();
|
|
608
|
+
}
|
|
609
|
+
const ownPost = rows.find((r) => r.role === "assistant");
|
|
610
|
+
expect(ownPost?.provenanceTrustClass).toBe("unknown");
|
|
611
|
+
expect(ownPost?.provenanceContactId).toBeUndefined();
|
|
612
|
+
// One read per distinct sender, the member's rows sharing theirs.
|
|
613
|
+
expect(readInboundTrustMock).toHaveBeenCalledTimes(2);
|
|
614
|
+
});
|
|
615
|
+
|
|
526
616
|
test("skips Slack assistant new-thread placeholder during DM backfill", async () => {
|
|
527
617
|
backfillDmMock.mockImplementation(async () => [
|
|
528
618
|
makeBackfilledMessage({
|
|
@@ -95,7 +95,10 @@ mock.module("../platform/client.js", () => ({
|
|
|
95
95
|
isPlatformClientConfigured: () => isPlatformClientConfiguredMock(),
|
|
96
96
|
}));
|
|
97
97
|
|
|
98
|
-
import {
|
|
98
|
+
import {
|
|
99
|
+
classifyNotificationReceipt,
|
|
100
|
+
emitNotificationSignal,
|
|
101
|
+
} from "../notifications/emit-signal.js";
|
|
99
102
|
|
|
100
103
|
beforeEach(() => {
|
|
101
104
|
evaluateSignalMock.mockReset();
|
|
@@ -707,3 +710,140 @@ describe("high/critical urgency channel force", () => {
|
|
|
707
710
|
});
|
|
708
711
|
});
|
|
709
712
|
});
|
|
713
|
+
|
|
714
|
+
describe("exclusive channelAllowlist policy", () => {
|
|
715
|
+
function makeDecision(overrides: Record<string, unknown>) {
|
|
716
|
+
return {
|
|
717
|
+
shouldNotify: true,
|
|
718
|
+
selectedChannels: ["telegram"],
|
|
719
|
+
reasoningSummary: "LLM selected telegram only",
|
|
720
|
+
renderedCopy: {},
|
|
721
|
+
dedupeKey: "dedupe-allow-1",
|
|
722
|
+
confidence: 0.9,
|
|
723
|
+
fallbackUsed: false,
|
|
724
|
+
persistedDecisionId: "dec-allow-1",
|
|
725
|
+
...overrides,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
test("skips urgent vellum and platform force", async () => {
|
|
730
|
+
evaluateSignalMock.mockResolvedValue(
|
|
731
|
+
makeDecision({ selectedChannels: ["vellum"] }),
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
const result = await emitNotificationSignal({
|
|
735
|
+
sourceEventName: "user.send_notification",
|
|
736
|
+
sourceChannel: "assistant_tool",
|
|
737
|
+
sourceContextId: "cli-allowlist-1",
|
|
738
|
+
attentionHints: {
|
|
739
|
+
requiresAction: true,
|
|
740
|
+
urgency: "critical",
|
|
741
|
+
isAsyncBackground: false,
|
|
742
|
+
visibleInSourceNow: false,
|
|
743
|
+
},
|
|
744
|
+
contextPayload: {
|
|
745
|
+
requestedMessage: "telegram only",
|
|
746
|
+
channelAllowlist: ["vellum"],
|
|
747
|
+
},
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
expect(enforceRoutingIntentMock).not.toHaveBeenCalled();
|
|
751
|
+
const dispatched = dispatchDecisionMock.mock.calls[0][1] as {
|
|
752
|
+
selectedChannels: string[];
|
|
753
|
+
reasoningSummary: string;
|
|
754
|
+
};
|
|
755
|
+
expect(dispatched.selectedChannels).toEqual(["vellum"]);
|
|
756
|
+
expect(dispatched.reasoningSummary).not.toContain("forced");
|
|
757
|
+
expect(result.selectedChannels).toEqual(["vellum"]);
|
|
758
|
+
expect(result.receiptClass).toBe("unknown");
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
test("replaces an LLM selection with the connected allowlist", async () => {
|
|
762
|
+
evaluateSignalMock.mockResolvedValue(
|
|
763
|
+
makeDecision({ selectedChannels: ["vellum", "telegram", "platform"] }),
|
|
764
|
+
);
|
|
765
|
+
|
|
766
|
+
await emitNotificationSignal({
|
|
767
|
+
sourceEventName: "user.send_notification",
|
|
768
|
+
sourceChannel: "assistant_tool",
|
|
769
|
+
sourceContextId: "cli-allowlist-2",
|
|
770
|
+
attentionHints: {
|
|
771
|
+
requiresAction: true,
|
|
772
|
+
urgency: "high",
|
|
773
|
+
isAsyncBackground: false,
|
|
774
|
+
visibleInSourceNow: false,
|
|
775
|
+
},
|
|
776
|
+
contextPayload: { channelAllowlist: ["vellum"] },
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
const dispatched = dispatchDecisionMock.mock.calls[0][1] as {
|
|
780
|
+
selectedChannels: string[];
|
|
781
|
+
shouldNotify: boolean;
|
|
782
|
+
reasoningSummary: string;
|
|
783
|
+
};
|
|
784
|
+
expect(dispatched.selectedChannels).toEqual(["vellum"]);
|
|
785
|
+
expect(dispatched.shouldNotify).toBe(true);
|
|
786
|
+
expect(dispatched.reasoningSummary).toContain("channelAllowlist: vellum");
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
test("access-request floor still adds vellum when the allowlist omitted it", async () => {
|
|
790
|
+
evaluateSignalMock.mockResolvedValue(
|
|
791
|
+
makeDecision({ shouldNotify: false, selectedChannels: [] }),
|
|
792
|
+
);
|
|
793
|
+
|
|
794
|
+
await emitNotificationSignal<string>({
|
|
795
|
+
sourceEventName: "ingress.access_request",
|
|
796
|
+
sourceChannel: "telegram",
|
|
797
|
+
sourceContextId: "access-req-allowlist-1",
|
|
798
|
+
requiresConversation: true,
|
|
799
|
+
attentionHints: {
|
|
800
|
+
requiresAction: true,
|
|
801
|
+
urgency: "high",
|
|
802
|
+
isAsyncBackground: false,
|
|
803
|
+
visibleInSourceNow: false,
|
|
804
|
+
},
|
|
805
|
+
contextPayload: {
|
|
806
|
+
requestId: "req-allowlist-1",
|
|
807
|
+
channelAllowlist: ["telegram"],
|
|
808
|
+
},
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
const dispatched = dispatchDecisionMock.mock.calls[0][1] as {
|
|
812
|
+
shouldNotify: boolean;
|
|
813
|
+
selectedChannels: string[];
|
|
814
|
+
reasoningSummary: string;
|
|
815
|
+
};
|
|
816
|
+
expect(dispatched.shouldNotify).toBe(true);
|
|
817
|
+
expect(dispatched.selectedChannels).toContain("vellum");
|
|
818
|
+
expect(dispatched.reasoningSummary).toContain(
|
|
819
|
+
"vellum forced: decisionable access request",
|
|
820
|
+
);
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
describe("classifyNotificationReceipt", () => {
|
|
825
|
+
test("reports provider_accepted when an external channel is sent", () => {
|
|
826
|
+
expect(
|
|
827
|
+
classifyNotificationReceipt([
|
|
828
|
+
{ channel: "telegram", destination: "chat-1", status: "sent" },
|
|
829
|
+
{ channel: "vellum", destination: "vellum", status: "sent" },
|
|
830
|
+
]),
|
|
831
|
+
).toBe("provider_accepted");
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
test("reports gateway_accepted when only platform is accepted", () => {
|
|
835
|
+
expect(
|
|
836
|
+
classifyNotificationReceipt([
|
|
837
|
+
{ channel: "platform", destination: "push", status: "pending" },
|
|
838
|
+
]),
|
|
839
|
+
).toBe("gateway_accepted");
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test("does not claim client_os_posted from a vellum sent row", () => {
|
|
843
|
+
expect(
|
|
844
|
+
classifyNotificationReceipt([
|
|
845
|
+
{ channel: "vellum", destination: "vellum", status: "sent" },
|
|
846
|
+
]),
|
|
847
|
+
).toBe("unknown");
|
|
848
|
+
});
|
|
849
|
+
});
|
|
@@ -276,6 +276,11 @@ export function createOutboundSessionGuarded(
|
|
|
276
276
|
}
|
|
277
277
|
source.status = "revoked";
|
|
278
278
|
source.updatedAt = Date.now();
|
|
279
|
+
// Like the gateway, the replacement keeps the claimed session's purpose.
|
|
280
|
+
return createOutboundSession({
|
|
281
|
+
...createParams,
|
|
282
|
+
verificationPurpose: source.verificationPurpose,
|
|
283
|
+
});
|
|
279
284
|
}
|
|
280
285
|
|
|
281
286
|
return createOutboundSession(createParams);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { actorAuthorProvenance } from "../daemon/message-provenance.js";
|
|
4
|
+
import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
5
|
+
import {
|
|
6
|
+
addMessage,
|
|
7
|
+
createConversation,
|
|
8
|
+
getMessageById,
|
|
9
|
+
parseMessageMetadata,
|
|
10
|
+
provenanceFromTrustContext,
|
|
11
|
+
} from "../persistence/conversation-crud.js";
|
|
12
|
+
import { getDb } from "../persistence/db-connection.js";
|
|
13
|
+
import { initializeDb } from "../persistence/db-init.js";
|
|
14
|
+
|
|
15
|
+
await initializeDb();
|
|
16
|
+
|
|
17
|
+
const ALICE: TrustContext = {
|
|
18
|
+
sourceChannel: "slack",
|
|
19
|
+
trustClass: "trusted_contact",
|
|
20
|
+
requesterIdentifier: "@alice",
|
|
21
|
+
requesterContactId: "contact-alice",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function persistWith(
|
|
25
|
+
role: "user" | "assistant",
|
|
26
|
+
metadata: Record<string, unknown>,
|
|
27
|
+
): Promise<ReturnType<typeof parseMessageMetadata>> {
|
|
28
|
+
const conversation = createConversation("provenance-contact-id");
|
|
29
|
+
const row = await addMessage(conversation.id, role, "hello", { metadata });
|
|
30
|
+
const stored = getMessageById(row.id, conversation.id);
|
|
31
|
+
return parseMessageMetadata(stored?.metadata ?? null);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("message provenance contact id", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
const db = getDb();
|
|
37
|
+
db.run(`DELETE FROM messages`);
|
|
38
|
+
db.run(`DELETE FROM conversations`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("a person's own row names them as its author", async () => {
|
|
42
|
+
const metadata = await persistWith("user", {
|
|
43
|
+
...provenanceFromTrustContext(ALICE),
|
|
44
|
+
...actorAuthorProvenance(ALICE),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(metadata?.provenanceTrustClass).toBe("trusted_contact");
|
|
48
|
+
expect(metadata?.provenanceContactId).toBe("contact-alice");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a row written during their turn carries the turn's trust but no author", async () => {
|
|
52
|
+
// The assistant's replies, tool results, and notices are stamped with the
|
|
53
|
+
// turn's provenance alone.
|
|
54
|
+
const metadata = await persistWith(
|
|
55
|
+
"assistant",
|
|
56
|
+
provenanceFromTrustContext(ALICE),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(metadata?.provenanceTrustClass).toBe("trusted_contact");
|
|
60
|
+
expect(metadata?.provenanceContactId).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("an actor with no resolved contact names no author", () => {
|
|
64
|
+
expect(
|
|
65
|
+
actorAuthorProvenance({ sourceChannel: "slack", trustClass: "unknown" }),
|
|
66
|
+
).toEqual({});
|
|
67
|
+
expect(actorAuthorProvenance(undefined)).toEqual({});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -148,6 +148,7 @@ import { persistQueuedMessageBody } from "../daemon/conversation-messaging.js";
|
|
|
148
148
|
import type { MessageQueue } from "../daemon/conversation-queue-manager.js";
|
|
149
149
|
import type { UserMessageAttachment } from "../daemon/message-protocol.js";
|
|
150
150
|
import { processMessage } from "../daemon/process-message.js";
|
|
151
|
+
import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
151
152
|
import type { Message } from "../providers/types.js";
|
|
152
153
|
|
|
153
154
|
function makeTestConversation() {
|
|
@@ -554,3 +555,58 @@ describe("processMessage skipUserMessageIndexing", () => {
|
|
|
554
555
|
expect(addMessageCalls[0]!.skipIndexing).toBeUndefined();
|
|
555
556
|
});
|
|
556
557
|
});
|
|
558
|
+
|
|
559
|
+
describe("processMessage author", () => {
|
|
560
|
+
const author: TrustContext = {
|
|
561
|
+
sourceChannel: "slack",
|
|
562
|
+
trustClass: "trusted_contact",
|
|
563
|
+
requesterContactId: "contact-alice",
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
beforeEach(() => {
|
|
567
|
+
addMessageCalls.length = 0;
|
|
568
|
+
activeConversation = undefined;
|
|
569
|
+
resolveSlashForTest = (content) => ({ kind: "passthrough", content });
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test("a relayed message names its author on the user row", async () => {
|
|
573
|
+
activeConversation = makeTestConversation();
|
|
574
|
+
|
|
575
|
+
await processMessage("conv-display-content", "the export needs a token", {
|
|
576
|
+
author,
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
expect(addMessageCalls[0]!.role).toBe("user");
|
|
580
|
+
expect(addMessageCalls[0]!.metadata?.provenanceContactId).toBe(
|
|
581
|
+
"contact-alice",
|
|
582
|
+
);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
test("a message nobody relayed names no author", async () => {
|
|
586
|
+
activeConversation = makeTestConversation();
|
|
587
|
+
|
|
588
|
+
await processMessage("conv-display-content", "kickoff prompt body", {});
|
|
589
|
+
|
|
590
|
+
expect(addMessageCalls[0]!.metadata?.provenanceContactId).toBeUndefined();
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test("a relayed slash command names its author on the user row, not the reply", async () => {
|
|
594
|
+
resolveSlashForTest = () => ({
|
|
595
|
+
kind: "unknown",
|
|
596
|
+
message: "Unknown slash command.",
|
|
597
|
+
});
|
|
598
|
+
activeConversation = makeTestConversation();
|
|
599
|
+
|
|
600
|
+
await processMessage("conv-display-content", "/missing-command", {
|
|
601
|
+
author,
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
expect(addMessageCalls).toHaveLength(2);
|
|
605
|
+
expect(addMessageCalls[0]!.role).toBe("user");
|
|
606
|
+
expect(addMessageCalls[0]!.metadata?.provenanceContactId).toBe(
|
|
607
|
+
"contact-alice",
|
|
608
|
+
);
|
|
609
|
+
expect(addMessageCalls[1]!.role).toBe("assistant");
|
|
610
|
+
expect(addMessageCalls[1]!.metadata?.provenanceContactId).toBeUndefined();
|
|
611
|
+
});
|
|
612
|
+
});
|
|
@@ -116,9 +116,12 @@ function resetState(): void {
|
|
|
116
116
|
_conversationMocks.clear();
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
const REACTOR_CONTACT_ID = "contact-reactor";
|
|
120
|
+
|
|
119
121
|
function seedActiveMember(): void {
|
|
120
122
|
seedContactChannel({
|
|
121
123
|
sourceChannel: "slack",
|
|
124
|
+
contactId: REACTOR_CONTACT_ID,
|
|
122
125
|
externalUserId: SLACK_USER_ID,
|
|
123
126
|
externalChatId: SLACK_CHANNEL_ID,
|
|
124
127
|
status: "active",
|
|
@@ -276,6 +279,8 @@ describe("Slack reaction event persistence", () => {
|
|
|
276
279
|
// filterMessagesForUntrustedActor drops rows with no trust class.
|
|
277
280
|
expect(envelope.provenanceTrustClass).toBe("trusted_contact");
|
|
278
281
|
expect(envelope.provenanceSourceChannel).toBe("slack");
|
|
282
|
+
// The reactor wrote this row, so it names them as its author.
|
|
283
|
+
expect(envelope.provenanceContactId).toBe(REACTOR_CONTACT_ID);
|
|
279
284
|
const slackMetaRaw = envelope.slackMeta;
|
|
280
285
|
expect(typeof slackMetaRaw).toBe("string");
|
|
281
286
|
|
|
@@ -270,7 +270,7 @@ describe("SSE reconnect replay (B7.2)", () => {
|
|
|
270
270
|
test("replay excludes events the subscriber is not targeted to receive", async () => {
|
|
271
271
|
// Stamp three events: two untargeted (seq 1, 3) + one with a
|
|
272
272
|
// capability target (seq 2, host_bash). A process subscriber
|
|
273
|
-
// does NOT match capability targeting (
|
|
273
|
+
// does NOT match capability targeting (matchesTargeting requires
|
|
274
274
|
// type=client + matching capability), so the replay filters out
|
|
275
275
|
// seq 2. The subscriber receives seq 1 and 3.
|
|
276
276
|
const { conversationId } = getOrCreateConversation("replay-targeting");
|
|
@@ -73,6 +73,7 @@ import type {
|
|
|
73
73
|
import type { MessagingConversationContext } from "../daemon/conversation-messaging.js";
|
|
74
74
|
import { persistQueuedMessageBody } from "../daemon/conversation-messaging.js";
|
|
75
75
|
import type { MessageQueue } from "../daemon/conversation-queue-manager.js";
|
|
76
|
+
import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
76
77
|
|
|
77
78
|
function createContext(): MessagingConversationContext {
|
|
78
79
|
const channel: TurnChannelContext = {
|
|
@@ -223,3 +224,75 @@ describe("scripted-turn metadata persistence", () => {
|
|
|
223
224
|
expect(lastUserMetadata().scripted).toBe(false);
|
|
224
225
|
});
|
|
225
226
|
});
|
|
227
|
+
|
|
228
|
+
describe("author contact id on a persisted user message", () => {
|
|
229
|
+
const sender: TrustContext = {
|
|
230
|
+
sourceChannel: "slack",
|
|
231
|
+
trustClass: "trusted_contact",
|
|
232
|
+
requesterContactId: "contact-alice",
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
beforeEach(() => {
|
|
236
|
+
addMessageCalls.length = 0;
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("a message relayed from the sender names them as its author", async () => {
|
|
240
|
+
await persistQueuedMessageBody(createContext(), {
|
|
241
|
+
content: "the export endpoint needs a scoped token",
|
|
242
|
+
requestId: "req-author-typed",
|
|
243
|
+
trustContext: sender,
|
|
244
|
+
author: sender,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(lastUserMetadata().provenanceContactId).toBe("contact-alice");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("a row persisted under the sender's trust but not relayed from them names no author", async () => {
|
|
251
|
+
// Machine-authored rows (ACP and subagent notifications, pointer turns)
|
|
252
|
+
// share this writer and the conversation's trust; only an explicit
|
|
253
|
+
// author names one.
|
|
254
|
+
await persistQueuedMessageBody(createContext(), {
|
|
255
|
+
content: "the delegated task finished",
|
|
256
|
+
requestId: "req-author-machine",
|
|
257
|
+
trustContext: sender,
|
|
258
|
+
metadata: { acpNotification: { acpSessionId: "acp-session-1" } },
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(lastUserMetadata().provenanceContactId).toBeUndefined();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test.each([
|
|
265
|
+
["scripted", { scripted: true }],
|
|
266
|
+
["automated", { metadata: { automated: true } }],
|
|
267
|
+
["hidden", { metadata: { hidden: true } }],
|
|
268
|
+
[
|
|
269
|
+
"ACP notification",
|
|
270
|
+
{ metadata: { acpNotification: { acpSessionId: "acp-session-1" } } },
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
"subagent notification",
|
|
274
|
+
{
|
|
275
|
+
metadata: {
|
|
276
|
+
subagentNotification: {
|
|
277
|
+
subagentId: "subagent-1",
|
|
278
|
+
label: "Research",
|
|
279
|
+
status: "completed",
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
] as const)(
|
|
285
|
+
"a %s row speaks in their voice without naming them",
|
|
286
|
+
async (kind, extra) => {
|
|
287
|
+
await persistQueuedMessageBody(createContext(), {
|
|
288
|
+
content: "sent on the sender's behalf",
|
|
289
|
+
requestId: `req-author-${kind}`,
|
|
290
|
+
trustContext: sender,
|
|
291
|
+
author: sender,
|
|
292
|
+
...extra,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(lastUserMetadata().provenanceContactId).toBeUndefined();
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
});
|