@vellumai/assistant 0.10.4-dev.202607021934.1d42792 → 0.10.4-dev.202607022130.febf41d
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/node_modules/@vellumai/gateway-client/src/__tests__/contact-read-contracts.test.ts +36 -0
- package/node_modules/@vellumai/gateway-client/src/__tests__/trust-verdict-contract.test.ts +22 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +7 -2
- package/node_modules/@vellumai/gateway-client/src/trust-verdict-contract.ts +6 -0
- package/openapi.yaml +36 -10
- package/package.json +1 -1
- package/src/__tests__/actor-trust-resolver-address-fallback.test.ts +0 -5
- package/src/__tests__/channel-guardian.test.ts +4 -7
- package/src/__tests__/compactor-media-strip.test.ts +177 -0
- package/src/__tests__/contact-store-interaction-info.test.ts +27 -70
- package/src/__tests__/contacts-relay-reads.test.ts +188 -23
- package/src/__tests__/contacts-tools.test.ts +42 -1
- package/src/__tests__/contacts-write.test.ts +181 -0
- package/src/__tests__/conversation-history-web-search.test.ts +7 -0
- package/src/__tests__/conversation-runtime-assembly.test.ts +36 -16
- package/src/__tests__/pre-model-call-sanitize.test.ts +1 -1
- package/src/__tests__/stt-hints.test.ts +0 -2
- package/src/__tests__/voice-approval-resolver-relay.test.ts +150 -0
- package/src/agent/ax-tree-compaction.test.ts +4 -1
- package/src/agent/loop.ts +1 -176
- package/src/calls/__tests__/relay-setup-router.test.ts +0 -5
- package/src/cli/commands/contacts.ts +2 -2
- package/src/config/bundled-skills/contacts/tools/contact-merge.ts +1 -1
- package/src/config/bundled-skills/contacts/tools/contact-search.ts +1 -1
- package/src/contacts/contact-store.ts +81 -30
- package/src/contacts/contacts-write.ts +50 -23
- package/src/contacts/member-write-relay.ts +0 -41
- package/src/contacts/types.ts +0 -7
- package/src/context/compactor.ts +29 -15
- package/src/context/outbound-sanitize.ts +202 -0
- package/src/daemon/conversation-runtime-assembly.ts +7 -4
- package/src/daemon/handlers/__tests__/config-channels.test.ts +0 -4
- package/src/daemon/handlers/config-a2a.ts +0 -4
- package/src/daemon/handlers/config-channels.ts +2 -10
- package/src/daemon/host-cu-proxy.ts +1 -1
- package/src/daemon/message-types/contacts.ts +2 -10
- package/src/daemon/trust-context.ts +7 -0
- package/src/ipc/__tests__/contacts-info-ipc.test.ts +285 -0
- package/src/ipc/assistant-server.ts +26 -5
- package/src/ipc/routes/__tests__/contacts-mirror-apply-atomicity.test.ts +62 -0
- package/src/ipc/routes/__tests__/contacts-mirror-apply.test.ts +272 -0
- package/src/ipc/routes/__tests__/contacts-mirror-ipc-routes.test.ts +322 -0
- package/src/ipc/routes/contacts-info-ipc-routes.ts +239 -0
- package/src/ipc/routes/contacts-mirror-ipc-routes.ts +202 -0
- package/src/ipc/routes/db-proxy.ts +5 -2
- package/src/persistence/migrations/318-drop-contact-channel-telemetry.ts +32 -0
- package/src/persistence/migrations/__tests__/318-drop-contact-channel-telemetry.test.ts +134 -0
- package/src/persistence/schema/contacts.ts +0 -3
- package/src/persistence/steps.ts +2 -0
- package/src/runtime/AGENTS.md +0 -2
- package/src/runtime/__tests__/trust-verdict-consumer.test.ts +37 -7
- package/src/runtime/channel-verification-service.ts +0 -8
- package/src/runtime/routes/__tests__/channel-verification-revoke.test.ts +6 -35
- package/src/runtime/routes/__tests__/contact-routes.test.ts +80 -14
- package/src/runtime/routes/__tests__/global-search-routes.test.ts +0 -3
- package/src/runtime/routes/channel-verification-routes.ts +0 -3
- package/src/runtime/routes/contact-routes.ts +143 -26
- package/src/runtime/trust-verdict-consumer.ts +7 -5
- package/src/contacts/__tests__/contacts-write-revoke-relay.test.ts +0 -128
|
@@ -48,6 +48,42 @@ describe("contact read contracts", () => {
|
|
|
48
48
|
expect(parsed.updatedAt).toBe(1700000000);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
test("ContactReadSchema accepts null interactionCount (daemon-native gateway-telemetry outage fail-soft)", () => {
|
|
52
|
+
const contact = {
|
|
53
|
+
id: "c1",
|
|
54
|
+
displayName: "Example User",
|
|
55
|
+
role: "contact",
|
|
56
|
+
contactType: "human",
|
|
57
|
+
lastInteraction: null,
|
|
58
|
+
interactionCount: null,
|
|
59
|
+
createdAt: 1699000000,
|
|
60
|
+
updatedAt: 1700000000,
|
|
61
|
+
channels: [
|
|
62
|
+
{
|
|
63
|
+
id: "ch1",
|
|
64
|
+
contactId: "c1",
|
|
65
|
+
type: "imessage",
|
|
66
|
+
address: "+15555550100",
|
|
67
|
+
isPrimary: true,
|
|
68
|
+
externalUserId: null,
|
|
69
|
+
status: "active",
|
|
70
|
+
policy: "allow",
|
|
71
|
+
verifiedAt: null,
|
|
72
|
+
verifiedVia: null,
|
|
73
|
+
lastSeenAt: null,
|
|
74
|
+
interactionCount: null,
|
|
75
|
+
lastInteraction: null,
|
|
76
|
+
revokedReason: null,
|
|
77
|
+
blockedReason: null,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const parsed = ContactReadSchema.parse(contact);
|
|
83
|
+
expect(parsed.interactionCount).toBeNull();
|
|
84
|
+
expect(parsed.channels[0].interactionCount).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
51
87
|
test("ContactReadSchema requires createdAt/updatedAt", () => {
|
|
52
88
|
const withoutTimestamps = {
|
|
53
89
|
id: "c1",
|
|
@@ -29,6 +29,8 @@ const fullVerdict: TrustVerdict = {
|
|
|
29
29
|
policy: "allow",
|
|
30
30
|
verifiedAt: 1699999999,
|
|
31
31
|
verifiedVia: "voice",
|
|
32
|
+
interactionCount: 12,
|
|
33
|
+
lastInteraction: 1699999998,
|
|
32
34
|
memberDisplayName: "Member Name",
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -92,6 +94,26 @@ describe("TrustVerdictSchema", () => {
|
|
|
92
94
|
});
|
|
93
95
|
});
|
|
94
96
|
|
|
97
|
+
test("carries interaction telemetry and tolerates a null lastInteraction", () => {
|
|
98
|
+
const parsed = TrustVerdictSchema.parse({
|
|
99
|
+
trustClass: "trusted_contact",
|
|
100
|
+
canonicalSenderId: "+15555550100",
|
|
101
|
+
interactionCount: 0,
|
|
102
|
+
lastInteraction: null,
|
|
103
|
+
});
|
|
104
|
+
expect(parsed.interactionCount).toBe(0);
|
|
105
|
+
expect(parsed.lastInteraction).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("leaves interaction telemetry undefined when absent", () => {
|
|
109
|
+
const parsed = TrustVerdictSchema.parse({
|
|
110
|
+
trustClass: "unknown",
|
|
111
|
+
canonicalSenderId: null,
|
|
112
|
+
});
|
|
113
|
+
expect(parsed.interactionCount).toBeUndefined();
|
|
114
|
+
expect(parsed.lastInteraction).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
95
117
|
test("rejects an invalid trustClass", () => {
|
|
96
118
|
expect(() =>
|
|
97
119
|
TrustVerdictSchema.parse({
|
|
@@ -233,7 +233,7 @@ export const ContactReadChannelSchema = z.object({
|
|
|
233
233
|
verifiedAt: z.number().nullable(),
|
|
234
234
|
verifiedVia: z.string().nullable(),
|
|
235
235
|
lastSeenAt: z.number().nullable(),
|
|
236
|
-
interactionCount: z.number(),
|
|
236
|
+
interactionCount: z.number().nullable(),
|
|
237
237
|
lastInteraction: z.number().nullable(),
|
|
238
238
|
revokedReason: z.string().nullable(),
|
|
239
239
|
blockedReason: z.string().nullable(),
|
|
@@ -248,7 +248,7 @@ export const ContactReadSchema = z.object({
|
|
|
248
248
|
notes: z.string().nullable().optional(),
|
|
249
249
|
contactType: z.string().nullable().optional(),
|
|
250
250
|
lastInteraction: z.number().nullable().optional(),
|
|
251
|
-
interactionCount: z.number(),
|
|
251
|
+
interactionCount: z.number().nullable(),
|
|
252
252
|
createdAt: z.number(),
|
|
253
253
|
updatedAt: z.number(),
|
|
254
254
|
channels: z.array(ContactReadChannelSchema),
|
|
@@ -270,6 +270,11 @@ export const ListContactsIpcParamsSchema = z
|
|
|
270
270
|
.object({
|
|
271
271
|
limit: z.number().optional(),
|
|
272
272
|
role: z.string().optional(),
|
|
273
|
+
// Restrict the read to these contact ids (any order). Used by the daemon to
|
|
274
|
+
// batch-hydrate gateway-owned telemetry onto daemon-native filtered/search
|
|
275
|
+
// results without re-implementing search in the gateway. When present,
|
|
276
|
+
// `role`/`limit` filtering is bypassed — the id set is the filter.
|
|
277
|
+
ids: z.array(z.string()).optional(),
|
|
273
278
|
})
|
|
274
279
|
.strict()
|
|
275
280
|
.default({});
|
|
@@ -77,6 +77,12 @@ export const TrustVerdictSchema = z.object({
|
|
|
77
77
|
verifiedAt: z.number().nullable().optional(),
|
|
78
78
|
verifiedVia: z.string().nullable().optional(),
|
|
79
79
|
memberDisplayName: z.string().optional(),
|
|
80
|
+
|
|
81
|
+
// Gateway-owned interaction telemetry (a trust signal, not an info field per
|
|
82
|
+
// the 2×2) — carried straight off the member `contact_channels` row.
|
|
83
|
+
// Present only when a member channel resolves; absent for unknown senders.
|
|
84
|
+
interactionCount: z.number().optional(),
|
|
85
|
+
lastInteraction: z.number().nullable().optional(),
|
|
80
86
|
});
|
|
81
87
|
|
|
82
88
|
export type TrustVerdict = z.infer<typeof TrustVerdictSchema>;
|
package/openapi.yaml
CHANGED
|
@@ -4130,6 +4130,12 @@ paths:
|
|
|
4130
4130
|
- type: "null"
|
|
4131
4131
|
memberDisplayName:
|
|
4132
4132
|
type: string
|
|
4133
|
+
interactionCount:
|
|
4134
|
+
type: number
|
|
4135
|
+
lastInteraction:
|
|
4136
|
+
anyOf:
|
|
4137
|
+
- type: number
|
|
4138
|
+
- type: "null"
|
|
4133
4139
|
required:
|
|
4134
4140
|
- trustClass
|
|
4135
4141
|
- canonicalSenderId
|
|
@@ -5159,7 +5165,9 @@ paths:
|
|
|
5159
5165
|
- type: number
|
|
5160
5166
|
- type: "null"
|
|
5161
5167
|
interactionCount:
|
|
5162
|
-
|
|
5168
|
+
anyOf:
|
|
5169
|
+
- type: number
|
|
5170
|
+
- type: "null"
|
|
5163
5171
|
createdAt:
|
|
5164
5172
|
type: number
|
|
5165
5173
|
updatedAt:
|
|
@@ -5200,7 +5208,9 @@ paths:
|
|
|
5200
5208
|
- type: number
|
|
5201
5209
|
- type: "null"
|
|
5202
5210
|
interactionCount:
|
|
5203
|
-
|
|
5211
|
+
anyOf:
|
|
5212
|
+
- type: number
|
|
5213
|
+
- type: "null"
|
|
5204
5214
|
lastInteraction:
|
|
5205
5215
|
anyOf:
|
|
5206
5216
|
- type: number
|
|
@@ -5319,7 +5329,9 @@ paths:
|
|
|
5319
5329
|
- type: number
|
|
5320
5330
|
- type: "null"
|
|
5321
5331
|
interactionCount:
|
|
5322
|
-
|
|
5332
|
+
anyOf:
|
|
5333
|
+
- type: number
|
|
5334
|
+
- type: "null"
|
|
5323
5335
|
createdAt:
|
|
5324
5336
|
type: number
|
|
5325
5337
|
updatedAt:
|
|
@@ -5360,7 +5372,9 @@ paths:
|
|
|
5360
5372
|
- type: number
|
|
5361
5373
|
- type: "null"
|
|
5362
5374
|
interactionCount:
|
|
5363
|
-
|
|
5375
|
+
anyOf:
|
|
5376
|
+
- type: number
|
|
5377
|
+
- type: "null"
|
|
5364
5378
|
lastInteraction:
|
|
5365
5379
|
anyOf:
|
|
5366
5380
|
- type: number
|
|
@@ -5448,7 +5462,9 @@ paths:
|
|
|
5448
5462
|
- type: number
|
|
5449
5463
|
- type: "null"
|
|
5450
5464
|
interactionCount:
|
|
5451
|
-
|
|
5465
|
+
anyOf:
|
|
5466
|
+
- type: number
|
|
5467
|
+
- type: "null"
|
|
5452
5468
|
createdAt:
|
|
5453
5469
|
type: number
|
|
5454
5470
|
updatedAt:
|
|
@@ -5489,7 +5505,9 @@ paths:
|
|
|
5489
5505
|
- type: number
|
|
5490
5506
|
- type: "null"
|
|
5491
5507
|
interactionCount:
|
|
5492
|
-
|
|
5508
|
+
anyOf:
|
|
5509
|
+
- type: number
|
|
5510
|
+
- type: "null"
|
|
5493
5511
|
lastInteraction:
|
|
5494
5512
|
anyOf:
|
|
5495
5513
|
- type: number
|
|
@@ -5847,7 +5865,9 @@ paths:
|
|
|
5847
5865
|
- type: number
|
|
5848
5866
|
- type: "null"
|
|
5849
5867
|
interactionCount:
|
|
5850
|
-
|
|
5868
|
+
anyOf:
|
|
5869
|
+
- type: number
|
|
5870
|
+
- type: "null"
|
|
5851
5871
|
createdAt:
|
|
5852
5872
|
type: number
|
|
5853
5873
|
updatedAt:
|
|
@@ -5888,7 +5908,9 @@ paths:
|
|
|
5888
5908
|
- type: number
|
|
5889
5909
|
- type: "null"
|
|
5890
5910
|
interactionCount:
|
|
5891
|
-
|
|
5911
|
+
anyOf:
|
|
5912
|
+
- type: number
|
|
5913
|
+
- type: "null"
|
|
5892
5914
|
lastInteraction:
|
|
5893
5915
|
anyOf:
|
|
5894
5916
|
- type: number
|
|
@@ -6041,7 +6063,9 @@ paths:
|
|
|
6041
6063
|
- type: number
|
|
6042
6064
|
- type: "null"
|
|
6043
6065
|
interactionCount:
|
|
6044
|
-
|
|
6066
|
+
anyOf:
|
|
6067
|
+
- type: number
|
|
6068
|
+
- type: "null"
|
|
6045
6069
|
createdAt:
|
|
6046
6070
|
type: number
|
|
6047
6071
|
updatedAt:
|
|
@@ -6082,7 +6106,9 @@ paths:
|
|
|
6082
6106
|
- type: number
|
|
6083
6107
|
- type: "null"
|
|
6084
6108
|
interactionCount:
|
|
6085
|
-
|
|
6109
|
+
anyOf:
|
|
6110
|
+
- type: number
|
|
6111
|
+
- type: "null"
|
|
6086
6112
|
lastInteraction:
|
|
6087
6113
|
anyOf:
|
|
6088
6114
|
- type: number
|
package/package.json
CHANGED
|
@@ -85,8 +85,6 @@ function makeContact(
|
|
|
85
85
|
displayName: "Patrick Test",
|
|
86
86
|
notes: null,
|
|
87
87
|
role,
|
|
88
|
-
lastInteraction: null,
|
|
89
|
-
interactionCount: 0,
|
|
90
88
|
contactType: "human" as const,
|
|
91
89
|
userFile: null,
|
|
92
90
|
createdAt: 0,
|
|
@@ -99,9 +97,6 @@ function makeContact(
|
|
|
99
97
|
address: PHONE,
|
|
100
98
|
externalChatId: null,
|
|
101
99
|
isPrimary: true,
|
|
102
|
-
lastSeenAt: null,
|
|
103
|
-
interactionCount: 0,
|
|
104
|
-
lastInteraction: null,
|
|
105
100
|
createdAt: 0,
|
|
106
101
|
updatedAt: 0,
|
|
107
102
|
},
|
|
@@ -152,7 +152,6 @@ import {
|
|
|
152
152
|
getPendingSession,
|
|
153
153
|
isGuardian,
|
|
154
154
|
resolveBootstrapToken,
|
|
155
|
-
revokeBinding as serviceRevokeBinding,
|
|
156
155
|
updateSessionStatus as serviceUpdateSessionStatus,
|
|
157
156
|
validateAndConsumeVerification,
|
|
158
157
|
} from "../runtime/channel-verification-service.js";
|
|
@@ -607,9 +606,8 @@ describe("guardian identity check", () => {
|
|
|
607
606
|
guardianDeliveryChatId: "chat-42",
|
|
608
607
|
});
|
|
609
608
|
|
|
610
|
-
// The revoke is gateway-owned
|
|
611
|
-
//
|
|
612
|
-
serviceRevokeBinding("asst-1", "telegram");
|
|
609
|
+
// The revoke is gateway-owned. Stamp the local downgrade and assert the
|
|
610
|
+
// read reflects it.
|
|
613
611
|
revokeGuardianChannelLocally("telegram");
|
|
614
612
|
expect(await getGuardianBinding("asst-1", "telegram")).toBeNull();
|
|
615
613
|
});
|
|
@@ -1478,9 +1476,8 @@ describe("voice guardian identity and revocation", () => {
|
|
|
1478
1476
|
guardianDeliveryChatId: "voice-chat-1",
|
|
1479
1477
|
});
|
|
1480
1478
|
|
|
1481
|
-
// The revoke is gateway-owned
|
|
1482
|
-
//
|
|
1483
|
-
serviceRevokeBinding("asst-1", "phone");
|
|
1479
|
+
// The revoke is gateway-owned. Stamp the local downgrade and assert the
|
|
1480
|
+
// read reflects it.
|
|
1484
1481
|
revokeGuardianChannelLocally("phone");
|
|
1485
1482
|
expect(await getGuardianBinding("asst-1", "phone")).toBeNull();
|
|
1486
1483
|
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
function makeLoggerStub(): Record<string, unknown> {
|
|
4
|
+
const stub: Record<string, unknown> = {};
|
|
5
|
+
for (const m of [
|
|
6
|
+
"info",
|
|
7
|
+
"warn",
|
|
8
|
+
"error",
|
|
9
|
+
"debug",
|
|
10
|
+
"trace",
|
|
11
|
+
"fatal",
|
|
12
|
+
"silent",
|
|
13
|
+
"child",
|
|
14
|
+
]) {
|
|
15
|
+
stub[m] = m === "child" ? () => makeLoggerStub() : () => {};
|
|
16
|
+
}
|
|
17
|
+
return stub;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
mock.module("../util/logger.js", () => ({
|
|
21
|
+
getLogger: () => makeLoggerStub(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
mock.module("../persistence/conversation-crud.js", () => ({
|
|
25
|
+
setConversationProcessingStartedAt: () => {},
|
|
26
|
+
isConversationProcessing: () => false,
|
|
27
|
+
getMessages: () => [],
|
|
28
|
+
reserveMessage: mock(async () => ({ id: "msg-reserve" })),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
mock.module("../persistence/attachments-store.js", () => ({
|
|
32
|
+
getAttachmentMetadataForMessage: () => [],
|
|
33
|
+
getAttachmentContent: () => null,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
import { runAssistantDrivenCompaction } from "../context/compactor.js";
|
|
37
|
+
import type { Message, Provider } from "../providers/types.js";
|
|
38
|
+
|
|
39
|
+
const TAIL_TIMESTAMP =
|
|
40
|
+
"2026-05-21 (Thursday) 10:00:00 -05:00 (America/Chicago)";
|
|
41
|
+
|
|
42
|
+
const compactionResponse = `
|
|
43
|
+
<compaction_result>
|
|
44
|
+
<summary>
|
|
45
|
+
Earlier turns summarized here.
|
|
46
|
+
</summary>
|
|
47
|
+
|
|
48
|
+
<key_state>
|
|
49
|
+
- Nothing critical pending.
|
|
50
|
+
</key_state>
|
|
51
|
+
|
|
52
|
+
<tail_start timestamp="${TAIL_TIMESTAMP}" preview="tail anchor message" />
|
|
53
|
+
</compaction_result>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
const OLD_SCREENSHOT_DATA = "b64-old-screenshot-bytes";
|
|
57
|
+
const LATEST_SCREENSHOT_DATA = "b64-latest-screenshot-bytes";
|
|
58
|
+
const USER_ATTACHED_IMAGE_DATA = "b64-user-attached-bytes";
|
|
59
|
+
|
|
60
|
+
const userTextWithTurnContext = (text: string, timestamp: string): Message => ({
|
|
61
|
+
role: "user",
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: `<turn_context>\ncurrent_time: ${timestamp}\n</turn_context>\n${text}`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const assistantToolUse = (id: string): Message => ({
|
|
71
|
+
role: "assistant",
|
|
72
|
+
content: [{ type: "tool_use", id, name: "screenshot", input: {} }],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const toolResultWithImage = (id: string, data: string): Message => ({
|
|
76
|
+
role: "user",
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: "tool_result",
|
|
80
|
+
tool_use_id: id,
|
|
81
|
+
content: "captured",
|
|
82
|
+
contentBlocks: [
|
|
83
|
+
{
|
|
84
|
+
type: "image",
|
|
85
|
+
source: { type: "base64", media_type: "image/png", data },
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const userWithAttachedImage = (): Message => ({
|
|
93
|
+
role: "user",
|
|
94
|
+
content: [
|
|
95
|
+
{ type: "text", text: "here is a mockup" },
|
|
96
|
+
{
|
|
97
|
+
type: "image",
|
|
98
|
+
source: {
|
|
99
|
+
type: "base64",
|
|
100
|
+
media_type: "image/png",
|
|
101
|
+
data: USER_ATTACHED_IMAGE_DATA,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function serializeBlocks(messages: Message[]): string {
|
|
108
|
+
return JSON.stringify(messages);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Records the exact message list the provider is asked to summarize.
|
|
112
|
+
function recordingProvider(sink: { sent: Message[] }): Provider {
|
|
113
|
+
return {
|
|
114
|
+
name: "mock-provider",
|
|
115
|
+
sendMessage: async (msgs: Message[]) => {
|
|
116
|
+
sink.sent = msgs;
|
|
117
|
+
return {
|
|
118
|
+
content: [{ type: "text", text: compactionResponse }],
|
|
119
|
+
model: "mock-model",
|
|
120
|
+
usage: { inputTokens: 100, outputTokens: 50 },
|
|
121
|
+
stopReason: "end_turn",
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// The summary request must carry the same media-stripped projection the agent
|
|
128
|
+
// loop sends on its own model calls. An unsanitized history resends every
|
|
129
|
+
// screenshot in the conversation; enough of them cross Anthropic's many-image
|
|
130
|
+
// threshold, where a stricter per-image dimension cap rejects the whole
|
|
131
|
+
// summary call (and trips the compaction circuit breaker).
|
|
132
|
+
describe("compaction summary calls — old tool-result media stripping", () => {
|
|
133
|
+
test("runAssistantDrivenCompaction strips images from older tool results, keeps the latest turn's image and user-attached images, and leaves durable history untouched", async () => {
|
|
134
|
+
// GIVEN a screenshot-heavy history: older tool results with images, a
|
|
135
|
+
// user-attached image, and a most-recent tool result with an image
|
|
136
|
+
const messages: Message[] = [
|
|
137
|
+
userWithAttachedImage(),
|
|
138
|
+
assistantToolUse("tu_old_1"),
|
|
139
|
+
toolResultWithImage("tu_old_1", OLD_SCREENSHOT_DATA),
|
|
140
|
+
userTextWithTurnContext("tail anchor message", TAIL_TIMESTAMP),
|
|
141
|
+
assistantToolUse("tu_latest"),
|
|
142
|
+
toolResultWithImage("tu_latest", LATEST_SCREENSHOT_DATA),
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
// AND a snapshot of the caller's array so we can assert it is not mutated
|
|
146
|
+
const inputSnapshot = serializeBlocks(messages);
|
|
147
|
+
const sink = { sent: [] as Message[] };
|
|
148
|
+
|
|
149
|
+
// WHEN compaction runs over that history
|
|
150
|
+
const result = await runAssistantDrivenCompaction({
|
|
151
|
+
conversationId: "conv-media-strip",
|
|
152
|
+
messages,
|
|
153
|
+
provider: recordingProvider(sink),
|
|
154
|
+
systemPrompt: "system",
|
|
155
|
+
compaction: { enabled: true, autoThreshold: 0.7 },
|
|
156
|
+
// Large budget so the request is not front-truncated — this test
|
|
157
|
+
// exercises the media-strip sanitizer, not the truncation fallback.
|
|
158
|
+
maxInputTokens: 100000,
|
|
159
|
+
previousEstimatedInputTokens: 90000,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// THEN older tool-result screenshots are replaced with a text marker
|
|
163
|
+
const sentSerialized = serializeBlocks(sink.sent);
|
|
164
|
+
expect(sentSerialized).not.toContain(OLD_SCREENSHOT_DATA);
|
|
165
|
+
expect(sentSerialized).toContain("binary data removed to save context");
|
|
166
|
+
|
|
167
|
+
// AND the most recent tool-result turn keeps its image (the model may
|
|
168
|
+
// still need it), as do images the user attached directly
|
|
169
|
+
expect(sentSerialized).toContain(LATEST_SCREENSHOT_DATA);
|
|
170
|
+
expect(sentSerialized).toContain(USER_ATTACHED_IMAGE_DATA);
|
|
171
|
+
|
|
172
|
+
// AND the caller's durable history array is left byte-for-byte untouched,
|
|
173
|
+
// so persisted messages keep the original rich blocks
|
|
174
|
+
expect(serializeBlocks(messages)).toBe(inputSnapshot);
|
|
175
|
+
expect(result.compacted).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* read paths (getContact / searchContacts
|
|
2
|
+
* Interaction telemetry (interactionCount/lastInteraction/lastSeenAt) is
|
|
3
|
+
* gateway-owned: reads source it from the stamped trust verdict and the gateway
|
|
4
|
+
* rich-read relay, and the assistant DB no longer carries the columns. These
|
|
5
|
+
* tests assert the daemon-native read paths (getContact / searchContacts /
|
|
6
|
+
* findContactInfoById) surface no telemetry.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
@@ -43,114 +44,70 @@ function insertChannel(params: {
|
|
|
43
44
|
contactId: string;
|
|
44
45
|
type: string;
|
|
45
46
|
address: string;
|
|
46
|
-
interactionCount: number;
|
|
47
|
-
lastInteraction: number | null;
|
|
48
|
-
lastSeenAt?: number | null;
|
|
49
47
|
}): void {
|
|
50
48
|
const now = Date.now();
|
|
51
49
|
getSqlite().run(
|
|
52
|
-
"INSERT INTO contact_channels (id, contact_id, type, address, is_primary,
|
|
53
|
-
[
|
|
54
|
-
params.id,
|
|
55
|
-
params.contactId,
|
|
56
|
-
params.type,
|
|
57
|
-
params.address,
|
|
58
|
-
params.interactionCount,
|
|
59
|
-
params.lastInteraction,
|
|
60
|
-
params.lastSeenAt ?? null,
|
|
61
|
-
now,
|
|
62
|
-
now,
|
|
63
|
-
],
|
|
50
|
+
"INSERT INTO contact_channels (id, contact_id, type, address, is_primary, created_at, updated_at) VALUES (?, ?, ?, ?, 0, ?, ?)",
|
|
51
|
+
[params.id, params.contactId, params.type, params.address, now, now],
|
|
64
52
|
);
|
|
65
53
|
}
|
|
66
54
|
|
|
67
|
-
|
|
55
|
+
const TELEMETRY_KEYS = ["interactionCount", "lastInteraction", "lastSeenAt"];
|
|
56
|
+
|
|
57
|
+
describe("contact-store surfaces no interaction telemetry", () => {
|
|
68
58
|
beforeEach(() => {
|
|
69
59
|
resetContactTables();
|
|
70
60
|
});
|
|
71
61
|
|
|
72
|
-
test("getContact
|
|
62
|
+
test("getContact returns no telemetry fields on the contact or its channels", () => {
|
|
73
63
|
insertContact("ct_1", "Alice");
|
|
74
64
|
insertChannel({
|
|
75
65
|
id: "ch_a",
|
|
76
66
|
contactId: "ct_1",
|
|
77
67
|
type: "phone",
|
|
78
68
|
address: "+15550100",
|
|
79
|
-
interactionCount: 3,
|
|
80
|
-
lastInteraction: 1900,
|
|
81
|
-
lastSeenAt: 1850,
|
|
82
|
-
});
|
|
83
|
-
insertChannel({
|
|
84
|
-
id: "ch_b",
|
|
85
|
-
contactId: "ct_1",
|
|
86
|
-
type: "email",
|
|
87
|
-
address: "alice@example.com",
|
|
88
|
-
interactionCount: 4,
|
|
89
|
-
lastInteraction: 2100,
|
|
90
|
-
lastSeenAt: 2050,
|
|
91
69
|
});
|
|
92
70
|
|
|
93
71
|
const contact = getContact("ct_1");
|
|
94
72
|
expect(contact).not.toBeNull();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
expect(phone?.lastSeenAt).toBe(1850);
|
|
73
|
+
for (const key of TELEMETRY_KEYS) {
|
|
74
|
+
expect(key in contact!).toBe(false);
|
|
75
|
+
}
|
|
76
|
+
const phone = contact!.channels.find((c) => c.type === "phone")!;
|
|
77
|
+
for (const key of TELEMETRY_KEYS) {
|
|
78
|
+
expect(key in phone).toBe(false);
|
|
79
|
+
}
|
|
103
80
|
});
|
|
104
81
|
|
|
105
|
-
test("findContactInfoById
|
|
82
|
+
test("findContactInfoById returns the notes-only INFO shape (telemetry is gateway-owned)", () => {
|
|
106
83
|
insertContact("ct_2", "Bob");
|
|
107
84
|
insertChannel({
|
|
108
85
|
id: "ch_c",
|
|
109
86
|
contactId: "ct_2",
|
|
110
87
|
type: "phone",
|
|
111
88
|
address: "+15550200",
|
|
112
|
-
interactionCount: 5,
|
|
113
|
-
lastInteraction: 1000,
|
|
114
89
|
});
|
|
115
90
|
|
|
116
91
|
const info = findContactInfoById("ct_2");
|
|
117
|
-
expect(info
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
test("lastInteraction is null when no channel has interacted", () => {
|
|
121
|
-
insertContact("ct_3", "Carol");
|
|
122
|
-
insertChannel({
|
|
123
|
-
id: "ch_d",
|
|
124
|
-
contactId: "ct_3",
|
|
125
|
-
type: "phone",
|
|
126
|
-
address: "+15550300",
|
|
127
|
-
interactionCount: 0,
|
|
128
|
-
lastInteraction: null,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const contact = getContact("ct_3");
|
|
132
|
-
expect(contact!.interactionCount).toBe(0);
|
|
133
|
-
expect(contact!.lastInteraction).toBeNull();
|
|
92
|
+
expect(info).not.toBeNull();
|
|
93
|
+
expect(Object.keys(info!)).toEqual(["notes"]);
|
|
94
|
+
expect(info!.notes).toBeNull();
|
|
134
95
|
});
|
|
135
96
|
|
|
136
|
-
test("filtered searchContacts carries
|
|
97
|
+
test("filtered searchContacts carries no telemetry fields", () => {
|
|
137
98
|
insertContact("ct_4", "Dana");
|
|
138
99
|
insertChannel({
|
|
139
100
|
id: "ch_e",
|
|
140
101
|
contactId: "ct_4",
|
|
141
102
|
type: "phone",
|
|
142
103
|
address: "+15550400",
|
|
143
|
-
interactionCount: 9,
|
|
144
|
-
lastInteraction: 3000,
|
|
145
|
-
lastSeenAt: 2900,
|
|
146
104
|
});
|
|
147
105
|
|
|
148
106
|
const results = searchContacts({ query: "Dana", limit: 10 });
|
|
149
107
|
expect(results).toHaveLength(1);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
expect(ch.lastSeenAt).toBe(2900);
|
|
108
|
+
for (const key of TELEMETRY_KEYS) {
|
|
109
|
+
expect(key in results[0]).toBe(false);
|
|
110
|
+
expect(key in results[0].channels[0]).toBe(false);
|
|
111
|
+
}
|
|
155
112
|
});
|
|
156
113
|
});
|