@vellumai/assistant 0.12.2-dev.202609182015.188de8a → 0.12.2-dev.202609182114.335fa56
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/package.json +1 -1
- 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 +83 -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/cli/commands/roadmap.help.ts +2 -3
- 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/persistence/conversation-crud.ts +8 -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/assistant-event-hub.ts +16 -86
- 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/http-types.ts +6 -0
- package/src/runtime/routes/events-routes.ts +2 -2
- package/src/runtime/routes/inbound-message-handler.ts +35 -38
- package/src/runtime/routes/inbound-stages/backfill-sender-provenance.test.ts +165 -0
- package/src/runtime/routes/inbound-stages/backfill-sender-provenance.ts +92 -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/util/canonicalize-identity.test.ts +21 -0
- package/src/util/canonicalize-identity.ts +16 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provenance for backfilled Slack rows, resolved per sender.
|
|
3
|
+
*
|
|
4
|
+
* A backfilled row was written by someone other than the live inbound actor,
|
|
5
|
+
* so the live turn's trust context says nothing about it. Each sender is
|
|
6
|
+
* classified by the same gateway verdict live ingress uses
|
|
7
|
+
* (`resolve_inbound_trust`), so a backfilled row and a live row from the same
|
|
8
|
+
* person carry the same trust class and contact id. The verdict answers for
|
|
9
|
+
* the contact list at import time, which is when the row is written.
|
|
10
|
+
*
|
|
11
|
+
* When the verdict is unreadable or unusable, the row falls back to the
|
|
12
|
+
* guardian-address comparison and carries no contact id.
|
|
13
|
+
*
|
|
14
|
+
* A read goes through `readInboundTrust`, so it also refreshes the
|
|
15
|
+
* member-verdict cache for that sender, as a live inbound read does.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readInboundTrust } from "../../../calls/inbound-trust-reader.js";
|
|
19
|
+
import type { ActorAuthorProvenance } from "../../../daemon/message-provenance.js";
|
|
20
|
+
import type { Message as ProviderMessage } from "../../../messaging/provider-types.js";
|
|
21
|
+
import { inboundIdentitiesMatch } from "../../../util/canonicalize-identity.js";
|
|
22
|
+
import type { TrustClass } from "../../trust-class.js";
|
|
23
|
+
import {
|
|
24
|
+
verdictMemberFromVerdict,
|
|
25
|
+
verdictUsability,
|
|
26
|
+
} from "../../trust-verdict-consumer.js";
|
|
27
|
+
|
|
28
|
+
export interface BackfilledSenderProvenance extends ActorAuthorProvenance {
|
|
29
|
+
provenanceTrustClass: TrustClass;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Resolves a backfilled message's sender provenance. One resolver serves one
|
|
34
|
+
* backfill pass and reads the gateway at most once per distinct sender.
|
|
35
|
+
*/
|
|
36
|
+
export type BackfilledSenderProvenanceResolver = (
|
|
37
|
+
senderId: string | undefined,
|
|
38
|
+
) => Promise<BackfilledSenderProvenance>;
|
|
39
|
+
|
|
40
|
+
export function createBackfilledSenderProvenanceResolver(
|
|
41
|
+
guardianExternalUserId: string | undefined,
|
|
42
|
+
messages: readonly ProviderMessage[],
|
|
43
|
+
): BackfilledSenderProvenanceResolver {
|
|
44
|
+
const bySender = new Map<string, Promise<BackfilledSenderProvenance>>();
|
|
45
|
+
const resolve: BackfilledSenderProvenanceResolver = (senderId) => {
|
|
46
|
+
const trimmed = senderId?.trim();
|
|
47
|
+
if (!trimmed) {
|
|
48
|
+
return Promise.resolve({ provenanceTrustClass: "unknown" });
|
|
49
|
+
}
|
|
50
|
+
let pending = bySender.get(trimmed);
|
|
51
|
+
if (!pending) {
|
|
52
|
+
pending = resolveSenderProvenance(trimmed, guardianExternalUserId);
|
|
53
|
+
bySender.set(trimmed, pending);
|
|
54
|
+
}
|
|
55
|
+
return pending;
|
|
56
|
+
};
|
|
57
|
+
// Every sender's read starts now, so the pass waits on the slowest read
|
|
58
|
+
// rather than their sum. Bots included: a third-party bot's post is a user
|
|
59
|
+
// row, and singling out this assistant's own posts needs an async lookup.
|
|
60
|
+
// A read reports failure as a result, never a rejection.
|
|
61
|
+
for (const message of messages) {
|
|
62
|
+
void resolve(message.sender?.id);
|
|
63
|
+
}
|
|
64
|
+
return resolve;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function resolveSenderProvenance(
|
|
68
|
+
senderId: string,
|
|
69
|
+
guardianExternalUserId: string | undefined,
|
|
70
|
+
): Promise<BackfilledSenderProvenance> {
|
|
71
|
+
const read = await readInboundTrust({
|
|
72
|
+
channelType: "slack",
|
|
73
|
+
actorExternalId: senderId,
|
|
74
|
+
});
|
|
75
|
+
if (read.ok) {
|
|
76
|
+
const usability = verdictUsability(read.verdict);
|
|
77
|
+
if (usability.usable) {
|
|
78
|
+
const member = verdictMemberFromVerdict(usability.verdict);
|
|
79
|
+
return {
|
|
80
|
+
provenanceTrustClass: usability.verdict.trustClass,
|
|
81
|
+
...(member ? { provenanceContactId: member.contactId } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
provenanceTrustClass:
|
|
87
|
+
guardianExternalUserId !== undefined &&
|
|
88
|
+
inboundIdentitiesMatch("slack", senderId, guardianExternalUserId)
|
|
89
|
+
? "guardian"
|
|
90
|
+
: "unknown",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -260,6 +260,35 @@ describe("processChannelMessageInBackground — reply delivery", () => {
|
|
|
260
260
|
const flush = (): Promise<void> =>
|
|
261
261
|
new Promise((resolve) => setTimeout(resolve, 10));
|
|
262
262
|
|
|
263
|
+
test("names the inbound sender as the persisted message's author", async () => {
|
|
264
|
+
let capturedAuthor: TrustContext | undefined;
|
|
265
|
+
const processMessage: MessageProcessor = async (
|
|
266
|
+
_conversationId,
|
|
267
|
+
_content,
|
|
268
|
+
options,
|
|
269
|
+
) => {
|
|
270
|
+
capturedAuthor = options?.author;
|
|
271
|
+
return { messageId: "user-msg-author" };
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
processChannelMessageInBackground({
|
|
275
|
+
processMessage,
|
|
276
|
+
conversationId: "conv-author",
|
|
277
|
+
eventId: "evt-author",
|
|
278
|
+
content: "the export endpoint needs a scoped token",
|
|
279
|
+
sourceChannel: "slack",
|
|
280
|
+
sourceInterface: "slack",
|
|
281
|
+
externalChatId: "C-AUTHOR",
|
|
282
|
+
trustCtx,
|
|
283
|
+
metadataHints: [],
|
|
284
|
+
replyCallbackUrl: "https://example.test/deliver/slack?channel=C-AUTHOR",
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
await flush();
|
|
288
|
+
|
|
289
|
+
expect(capturedAuthor).toBe(trustCtx);
|
|
290
|
+
});
|
|
291
|
+
|
|
263
292
|
test("records callback delivery failures without failing processing", async () => {
|
|
264
293
|
const conversationId = "conv-delivery-failure";
|
|
265
294
|
const channelId = "C-DELIVERY-FAILURE";
|
|
@@ -286,6 +286,7 @@ export function processChannelMessageInBackground(
|
|
|
286
286
|
},
|
|
287
287
|
assistantId,
|
|
288
288
|
trustContext: trustCtx,
|
|
289
|
+
author: trustCtx,
|
|
289
290
|
isInteractive: resolveRoutingState(trustCtx).promptWaitingAllowed,
|
|
290
291
|
...(displayContent !== undefined ? { displayContent } : {}),
|
|
291
292
|
...(cmdIntent ? { commandIntent: cmdIntent } : {}),
|
|
@@ -35,6 +35,7 @@ import { createApprovalCopyGenerator } from "../../../daemon/approval-generators
|
|
|
35
35
|
import { findConversation } from "../../../daemon/conversation-registry.js";
|
|
36
36
|
import { getDiskPressureStatus } from "../../../daemon/disk-pressure-guard.js";
|
|
37
37
|
import { classifyDiskPressureTurnPolicy } from "../../../daemon/disk-pressure-policy.js";
|
|
38
|
+
import { actorAuthorProvenance } from "../../../daemon/message-provenance.js";
|
|
38
39
|
import { processMessage } from "../../../daemon/process-message.js";
|
|
39
40
|
import { renderReactionHistoryText } from "../../../daemon/reaction-history-render.js";
|
|
40
41
|
import type { TrustContext } from "../../../daemon/trust-context-types.js";
|
|
@@ -544,6 +545,7 @@ async function persistReactionAsMessage(params: {
|
|
|
544
545
|
{
|
|
545
546
|
metadata: {
|
|
546
547
|
...provenanceFromTrustContext(params.trustCtx),
|
|
548
|
+
...actorAuthorProvenance(params.trustCtx),
|
|
547
549
|
...buildReactionRowEnvelope(facts),
|
|
548
550
|
},
|
|
549
551
|
skipIndexing: true,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { inboundIdentitiesMatch } from "./canonicalize-identity.js";
|
|
4
|
+
|
|
5
|
+
describe("inboundIdentitiesMatch", () => {
|
|
6
|
+
test("matches ids that canonicalize to the same sender", () => {
|
|
7
|
+
expect(inboundIdentitiesMatch("slack", " U123 ", "U123")).toBe(true);
|
|
8
|
+
expect(
|
|
9
|
+
inboundIdentitiesMatch("email", "USER@example.com", "user@example.com"),
|
|
10
|
+
).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("distinct senders do not match", () => {
|
|
14
|
+
expect(inboundIdentitiesMatch("slack", "U123", "U456")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("an empty identifier matches nothing, not even another empty one", () => {
|
|
18
|
+
expect(inboundIdentitiesMatch("slack", "", "")).toBe(false);
|
|
19
|
+
expect(inboundIdentitiesMatch("slack", " ", "U123")).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -55,3 +55,19 @@ export function canonicalizeInboundIdentity(
|
|
|
55
55
|
|
|
56
56
|
return trimmed;
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether two raw identifiers name the same sender on `channel`. An empty
|
|
61
|
+
* identifier matches nothing.
|
|
62
|
+
*/
|
|
63
|
+
export function inboundIdentitiesMatch(
|
|
64
|
+
channel: ChannelId,
|
|
65
|
+
left: string,
|
|
66
|
+
right: string,
|
|
67
|
+
): boolean {
|
|
68
|
+
const canonicalLeft = canonicalizeInboundIdentity(channel, left);
|
|
69
|
+
return (
|
|
70
|
+
canonicalLeft !== null &&
|
|
71
|
+
canonicalLeft === canonicalizeInboundIdentity(channel, right)
|
|
72
|
+
);
|
|
73
|
+
}
|