@vellumai/assistant 0.11.7-dev.202608312016.603ba19 → 0.11.7-dev.202608312114.5fab2e2
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/docs/guardian-request-flow.md +35 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +46 -0
- package/node_modules/@vellumai/gateway-client/src/guardian-request-contract.ts +17 -0
- package/node_modules/@vellumai/gateway-client/src/index.ts +2 -0
- package/openapi.yaml +213 -0
- package/package.json +1 -1
- package/src/__tests__/contacts-write.test.ts +33 -3
- package/src/__tests__/conversation-load-history-repair.test.ts +59 -0
- package/src/__tests__/conversation-retry-route.test.ts +5 -0
- package/src/__tests__/conversation-summarize-route.test.ts +5 -0
- package/src/__tests__/guardian-gateway-sim.ts +15 -0
- package/src/__tests__/guardian-reply-router-answer-mode.test.ts +6 -0
- package/src/__tests__/guardian-wait-controller.test.ts +6 -0
- package/src/__tests__/list-messages-system-card.test.ts +40 -0
- package/src/__tests__/media-stream-server-integration.test.ts +6 -0
- package/src/api/index.ts +8 -0
- package/src/api/responses/conversation-message.ts +14 -0
- package/src/api/responses/home.ts +101 -0
- package/src/approvals/guardian-card-withdrawal.ts +22 -2
- package/src/approvals/guardian-request-status-sync.ts +9 -0
- package/src/channels/gateway-guardian-requests.ts +19 -1
- package/src/config/feature-flag-registry.json +8 -0
- package/src/contacts/__tests__/mirror-reconciler.test.ts +352 -0
- package/src/contacts/contact-store.ts +21 -0
- package/src/contacts/mirror-reconciler.ts +210 -0
- package/src/contacts/mirror-tombstones.ts +42 -0
- package/src/contacts/notify-contacts-changed.ts +11 -2
- package/src/daemon/conversation-agent-loop.ts +53 -0
- package/src/daemon/conversation.ts +17 -2
- package/src/daemon/handlers/conversations.ts +2 -0
- package/src/daemon/reaction-history-render.test.ts +33 -0
- package/src/daemon/reaction-history-render.ts +36 -5
- package/src/daemon/reaction-record.test.ts +162 -0
- package/src/daemon/reaction-record.ts +83 -0
- package/src/home/feed-types.ts +4 -0
- package/src/home/feed-writer.ts +25 -0
- package/src/messaging/reaction-envelopes.ts +79 -0
- package/src/notifications/__tests__/guardian-feed-projection.test.ts +360 -0
- package/src/notifications/__tests__/home-feed-side-effect.test.ts +8 -0
- package/src/notifications/conversation-pairing.ts +23 -0
- package/src/notifications/emit-signal.ts +8 -5
- package/src/notifications/guardian-feed-projection.ts +492 -0
- package/src/notifications/home-feed-side-effect.ts +59 -11
- package/src/permissions/question-guardian-request.test.ts +6 -0
- package/src/persistence/conversation-crud.ts +4 -1
- package/src/persistence/conversation-types.ts +18 -0
- package/src/runtime/routes/conversation-routes.ts +22 -0
- package/src/runtime/routes/guardian-expiry-sweep.ts +9 -0
- package/src/runtime/routes/inbound-message-handler.ts +17 -0
- package/src/runtime/routes/inbound-stages/guardian-reply-intercept.test.ts +6 -0
- package/src/runtime/routes/inbound-stages/reaction-intercept.ts +19 -53
- package/src/tools/channel/react-to-message.test.ts +71 -0
- package/src/tools/channel/react-to-message.ts +32 -0
|
@@ -54,6 +54,41 @@ anti-pattern was retired in #35642 and again in the ask_question redesign).
|
|
|
54
54
|
| Kind-specific follow-through | resolver registry (`kind` → resolver) | switch statements in the router |
|
|
55
55
|
| Reply understanding | guardian reply router (codes, buttons, reactions, modes) | per-feature inbound intercepts |
|
|
56
56
|
|
|
57
|
+
## The canonical home-feed projection
|
|
58
|
+
|
|
59
|
+
Every pending request is also exactly one home-feed item, the bell's
|
|
60
|
+
"Needs attention" row. `notifications/guardian-feed-projection.ts` owns
|
|
61
|
+
it end to end:
|
|
62
|
+
|
|
63
|
+
- The pipeline's feed side effect writes it keyed
|
|
64
|
+
`guardian:<requestId>`, so the feed's replace-in-place merge keeps one
|
|
65
|
+
item per request. Its typed `guardianRequest` field
|
|
66
|
+
(`FeedItemGuardianRequestSchema` in `api/responses/home.ts`) is a read
|
|
67
|
+
projection of the gateway row: intent, status, requester, tool, source
|
|
68
|
+
reference, and the Slack-DM card deep links. It is never a delivery
|
|
69
|
+
row of its own; clients derive every affordance from `status`.
|
|
70
|
+
- `withdrawGuardianRequestCards` rewrites it into a terminal receipt as
|
|
71
|
+
one of the surfaces it settles, and its failure gates `complete` the
|
|
72
|
+
same way a failed card edit does. The write-vs-resolve race converges
|
|
73
|
+
from the other side too: the feed writer re-checks canonical status
|
|
74
|
+
after its append.
|
|
75
|
+
- The feed writer's bulk-dismiss pass skips pending guardian items
|
|
76
|
+
(`isPendingGuardianFeedItem`), so "Clear all" can never retire an
|
|
77
|
+
unresolved request; only its receipt is clearable.
|
|
78
|
+
- The guardian expiry sweep runs `reconcileGuardianFeedProjections()`
|
|
79
|
+
each round: pending requests missing an item are backfilled from the
|
|
80
|
+
request row (no conversation is generated), and an item still
|
|
81
|
+
actionable for a terminal request is receipted with a loud log line.
|
|
82
|
+
|
|
83
|
+
Routing policy for the Slack guardian DM: the card message there is a
|
|
84
|
+
delivery projection, not conversation content. Its delivery is not
|
|
85
|
+
paired with any conversation (`conversation-pairing.ts` skips
|
|
86
|
+
guardian.question Slack deliveries), and the Slack DM cold backfill
|
|
87
|
+
skips messages whose ts matches a recorded guardian delivery for the
|
|
88
|
+
chat (`guardian_requests_list_deliveries_by_chat`), so the card never
|
|
89
|
+
enters a Vellum transcript. The in-app homes of a request are the feed
|
|
90
|
+
item and the source conversation's pinned vellum card.
|
|
91
|
+
|
|
57
92
|
## Cards are not conversation history
|
|
58
93
|
|
|
59
94
|
`pairDeliveryWithConversation` persists one message row per delivery so the
|
|
@@ -355,6 +355,52 @@ export type GetGuardianContactIpcResponse = z.infer<
|
|
|
355
355
|
typeof GetGuardianContactIpcResponseSchema
|
|
356
356
|
>;
|
|
357
357
|
|
|
358
|
+
// ── contacts_identity_snapshot ───────────────────────────────────────────────
|
|
359
|
+
// Lean identity projection of every gateway contact + channel, for the
|
|
360
|
+
// daemon's mirror reconciler: enough to converge the assistant identity
|
|
361
|
+
// mirror onto gateway truth (ids, ownership, addresses), nothing more. No
|
|
362
|
+
// ACL columns (the mirror never carries them) and no assistant-info join
|
|
363
|
+
// (the daemon IS the assistant), so the read is uncapped and cheap.
|
|
364
|
+
|
|
365
|
+
export const ContactsIdentitySnapshotIpcParamsSchema = z
|
|
366
|
+
.object({})
|
|
367
|
+
.strict()
|
|
368
|
+
.default({});
|
|
369
|
+
|
|
370
|
+
export type ContactsIdentitySnapshotIpcParams = z.infer<
|
|
371
|
+
typeof ContactsIdentitySnapshotIpcParamsSchema
|
|
372
|
+
>;
|
|
373
|
+
|
|
374
|
+
export const ContactIdentityChannelSchema = z.object({
|
|
375
|
+
id: z.string(),
|
|
376
|
+
contactId: z.string(),
|
|
377
|
+
type: z.string(),
|
|
378
|
+
address: z.string(),
|
|
379
|
+
externalChatId: z.string().nullable(),
|
|
380
|
+
isPrimary: z.boolean(),
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
export type ContactIdentityChannel = z.infer<
|
|
384
|
+
typeof ContactIdentityChannelSchema
|
|
385
|
+
>;
|
|
386
|
+
|
|
387
|
+
export const ContactIdentitySchema = z.object({
|
|
388
|
+
id: z.string(),
|
|
389
|
+
displayName: z.string(),
|
|
390
|
+
channels: z.array(ContactIdentityChannelSchema),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
export type ContactIdentity = z.infer<typeof ContactIdentitySchema>;
|
|
394
|
+
|
|
395
|
+
export const ContactsIdentitySnapshotIpcResponseSchema = z.object({
|
|
396
|
+
ok: z.boolean(),
|
|
397
|
+
contacts: z.array(ContactIdentitySchema),
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
export type ContactsIdentitySnapshotIpcResponse = z.infer<
|
|
401
|
+
typeof ContactsIdentitySnapshotIpcResponseSchema
|
|
402
|
+
>;
|
|
403
|
+
|
|
358
404
|
// ── classify_risk ────────────────────────────────────────────────────────────
|
|
359
405
|
// Risk classification is gateway-owned; the assistant sends one request per
|
|
360
406
|
// tool invocation and reads the whole answer back. The gateway validates the
|
|
@@ -193,6 +193,7 @@ export const GUARDIAN_REQUESTS_IPC_METHODS = {
|
|
|
193
193
|
createDelivery: "guardian_requests_create_delivery",
|
|
194
194
|
updateDelivery: "guardian_requests_update_delivery",
|
|
195
195
|
listDeliveries: "guardian_requests_list_deliveries",
|
|
196
|
+
listDeliveriesByChat: "guardian_requests_list_deliveries_by_chat",
|
|
196
197
|
getByDestinationMessage: "guardian_requests_get_by_destination_message",
|
|
197
198
|
listPendingByDestination: "guardian_requests_list_pending_by_destination",
|
|
198
199
|
listPendingByScope: "guardian_requests_list_pending_by_scope",
|
|
@@ -597,6 +598,22 @@ export type ListGuardianRequestDeliveriesIpcParams = z.infer<
|
|
|
597
598
|
typeof ListGuardianRequestDeliveriesIpcParamsSchema
|
|
598
599
|
>;
|
|
599
600
|
|
|
601
|
+
/**
|
|
602
|
+
* Request for `guardian_requests_list_deliveries_by_chat`: every
|
|
603
|
+
* delivery row addressed to one channel-native chat, whatever request it
|
|
604
|
+
* belongs to. Lets transcript importers recognize guardian card
|
|
605
|
+
* messages (by their recorded message id) as delivery projections
|
|
606
|
+
* rather than conversation content.
|
|
607
|
+
*/
|
|
608
|
+
export const ListGuardianRequestDeliveriesByChatIpcParamsSchema = z.object({
|
|
609
|
+
channel: z.string().min(1),
|
|
610
|
+
chatId: z.string().min(1),
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
export type ListGuardianRequestDeliveriesByChatIpcParams = z.infer<
|
|
614
|
+
typeof ListGuardianRequestDeliveriesByChatIpcParamsSchema
|
|
615
|
+
>;
|
|
616
|
+
|
|
600
617
|
/** Response for `guardian_requests_list_deliveries`. */
|
|
601
618
|
export const GuardianRequestDeliveryListIpcResponseSchema = z.array(
|
|
602
619
|
GuardianRequestDeliverySchema,
|
|
@@ -264,6 +264,7 @@ export {
|
|
|
264
264
|
GuardianRequestSourceTypeSchema,
|
|
265
265
|
GuardianRequestStatusSchema,
|
|
266
266
|
isGuardianRequestExpired,
|
|
267
|
+
ListGuardianRequestDeliveriesByChatIpcParamsSchema,
|
|
267
268
|
ListGuardianRequestDeliveriesIpcParamsSchema,
|
|
268
269
|
ListGuardianRequestsIpcParamsSchema,
|
|
269
270
|
ListPendingGuardianRequestsByDestinationIpcParamsSchema,
|
|
@@ -303,6 +304,7 @@ export type {
|
|
|
303
304
|
GuardianRequestSourceType,
|
|
304
305
|
GuardianRequestStatus,
|
|
305
306
|
GuardianRequestWire,
|
|
307
|
+
ListGuardianRequestDeliveriesByChatIpcParams,
|
|
306
308
|
ListGuardianRequestDeliveriesIpcParams,
|
|
307
309
|
ListGuardianRequestsIpcParams,
|
|
308
310
|
ListPendingGuardianRequestsByDestinationIpcParams,
|
package/openapi.yaml
CHANGED
|
@@ -13762,6 +13762,54 @@ paths:
|
|
|
13762
13762
|
required:
|
|
13763
13763
|
- kind
|
|
13764
13764
|
additionalProperties: false
|
|
13765
|
+
guardianRequest:
|
|
13766
|
+
type: object
|
|
13767
|
+
properties:
|
|
13768
|
+
requestId:
|
|
13769
|
+
type: string
|
|
13770
|
+
kind:
|
|
13771
|
+
type: string
|
|
13772
|
+
intent:
|
|
13773
|
+
type: string
|
|
13774
|
+
enum:
|
|
13775
|
+
- approval
|
|
13776
|
+
- question
|
|
13777
|
+
status:
|
|
13778
|
+
type: string
|
|
13779
|
+
enum:
|
|
13780
|
+
- pending
|
|
13781
|
+
- approved
|
|
13782
|
+
- denied
|
|
13783
|
+
- expired
|
|
13784
|
+
- cancelled
|
|
13785
|
+
requesterLabel:
|
|
13786
|
+
type: string
|
|
13787
|
+
toolName:
|
|
13788
|
+
type: string
|
|
13789
|
+
sourceChannel:
|
|
13790
|
+
type: string
|
|
13791
|
+
sourceContextLabel:
|
|
13792
|
+
type: string
|
|
13793
|
+
sourceUrl:
|
|
13794
|
+
type: string
|
|
13795
|
+
slackCardUrl:
|
|
13796
|
+
type: string
|
|
13797
|
+
slackCardAppUrl:
|
|
13798
|
+
type: string
|
|
13799
|
+
decidedAction:
|
|
13800
|
+
type: string
|
|
13801
|
+
decidedByLabel:
|
|
13802
|
+
type: string
|
|
13803
|
+
decidedAt:
|
|
13804
|
+
type: string
|
|
13805
|
+
terminalReason:
|
|
13806
|
+
type: string
|
|
13807
|
+
required:
|
|
13808
|
+
- requestId
|
|
13809
|
+
- kind
|
|
13810
|
+
- intent
|
|
13811
|
+
- status
|
|
13812
|
+
additionalProperties: false
|
|
13765
13813
|
category:
|
|
13766
13814
|
type: string
|
|
13767
13815
|
enum:
|
|
@@ -13955,6 +14003,54 @@ paths:
|
|
|
13955
14003
|
required:
|
|
13956
14004
|
- kind
|
|
13957
14005
|
additionalProperties: false
|
|
14006
|
+
guardianRequest:
|
|
14007
|
+
type: object
|
|
14008
|
+
properties:
|
|
14009
|
+
requestId:
|
|
14010
|
+
type: string
|
|
14011
|
+
kind:
|
|
14012
|
+
type: string
|
|
14013
|
+
intent:
|
|
14014
|
+
type: string
|
|
14015
|
+
enum:
|
|
14016
|
+
- approval
|
|
14017
|
+
- question
|
|
14018
|
+
status:
|
|
14019
|
+
type: string
|
|
14020
|
+
enum:
|
|
14021
|
+
- pending
|
|
14022
|
+
- approved
|
|
14023
|
+
- denied
|
|
14024
|
+
- expired
|
|
14025
|
+
- cancelled
|
|
14026
|
+
requesterLabel:
|
|
14027
|
+
type: string
|
|
14028
|
+
toolName:
|
|
14029
|
+
type: string
|
|
14030
|
+
sourceChannel:
|
|
14031
|
+
type: string
|
|
14032
|
+
sourceContextLabel:
|
|
14033
|
+
type: string
|
|
14034
|
+
sourceUrl:
|
|
14035
|
+
type: string
|
|
14036
|
+
slackCardUrl:
|
|
14037
|
+
type: string
|
|
14038
|
+
slackCardAppUrl:
|
|
14039
|
+
type: string
|
|
14040
|
+
decidedAction:
|
|
14041
|
+
type: string
|
|
14042
|
+
decidedByLabel:
|
|
14043
|
+
type: string
|
|
14044
|
+
decidedAt:
|
|
14045
|
+
type: string
|
|
14046
|
+
terminalReason:
|
|
14047
|
+
type: string
|
|
14048
|
+
required:
|
|
14049
|
+
- requestId
|
|
14050
|
+
- kind
|
|
14051
|
+
- intent
|
|
14052
|
+
- status
|
|
14053
|
+
additionalProperties: false
|
|
13958
14054
|
category:
|
|
13959
14055
|
type: string
|
|
13960
14056
|
enum:
|
|
@@ -14242,6 +14338,54 @@ paths:
|
|
|
14242
14338
|
required:
|
|
14243
14339
|
- kind
|
|
14244
14340
|
additionalProperties: false
|
|
14341
|
+
guardianRequest:
|
|
14342
|
+
type: object
|
|
14343
|
+
properties:
|
|
14344
|
+
requestId:
|
|
14345
|
+
type: string
|
|
14346
|
+
kind:
|
|
14347
|
+
type: string
|
|
14348
|
+
intent:
|
|
14349
|
+
type: string
|
|
14350
|
+
enum:
|
|
14351
|
+
- approval
|
|
14352
|
+
- question
|
|
14353
|
+
status:
|
|
14354
|
+
type: string
|
|
14355
|
+
enum:
|
|
14356
|
+
- pending
|
|
14357
|
+
- approved
|
|
14358
|
+
- denied
|
|
14359
|
+
- expired
|
|
14360
|
+
- cancelled
|
|
14361
|
+
requesterLabel:
|
|
14362
|
+
type: string
|
|
14363
|
+
toolName:
|
|
14364
|
+
type: string
|
|
14365
|
+
sourceChannel:
|
|
14366
|
+
type: string
|
|
14367
|
+
sourceContextLabel:
|
|
14368
|
+
type: string
|
|
14369
|
+
sourceUrl:
|
|
14370
|
+
type: string
|
|
14371
|
+
slackCardUrl:
|
|
14372
|
+
type: string
|
|
14373
|
+
slackCardAppUrl:
|
|
14374
|
+
type: string
|
|
14375
|
+
decidedAction:
|
|
14376
|
+
type: string
|
|
14377
|
+
decidedByLabel:
|
|
14378
|
+
type: string
|
|
14379
|
+
decidedAt:
|
|
14380
|
+
type: string
|
|
14381
|
+
terminalReason:
|
|
14382
|
+
type: string
|
|
14383
|
+
required:
|
|
14384
|
+
- requestId
|
|
14385
|
+
- kind
|
|
14386
|
+
- intent
|
|
14387
|
+
- status
|
|
14388
|
+
additionalProperties: false
|
|
14245
14389
|
category:
|
|
14246
14390
|
type: string
|
|
14247
14391
|
enum:
|
|
@@ -20832,6 +20976,27 @@ paths:
|
|
|
20832
20976
|
type: boolean
|
|
20833
20977
|
noResponse:
|
|
20834
20978
|
type: boolean
|
|
20979
|
+
reaction:
|
|
20980
|
+
type: object
|
|
20981
|
+
properties:
|
|
20982
|
+
emoji:
|
|
20983
|
+
type: string
|
|
20984
|
+
op:
|
|
20985
|
+
type: string
|
|
20986
|
+
enum:
|
|
20987
|
+
- added
|
|
20988
|
+
- removed
|
|
20989
|
+
targetMessageId:
|
|
20990
|
+
type: string
|
|
20991
|
+
actorDisplayName:
|
|
20992
|
+
type: string
|
|
20993
|
+
selfAuthored:
|
|
20994
|
+
type: boolean
|
|
20995
|
+
required:
|
|
20996
|
+
- emoji
|
|
20997
|
+
- op
|
|
20998
|
+
- targetMessageId
|
|
20999
|
+
additionalProperties: false
|
|
20835
21000
|
providerError:
|
|
20836
21001
|
type: object
|
|
20837
21002
|
properties:
|
|
@@ -22810,6 +22975,54 @@ paths:
|
|
|
22810
22975
|
required:
|
|
22811
22976
|
- kind
|
|
22812
22977
|
additionalProperties: false
|
|
22978
|
+
guardianRequest:
|
|
22979
|
+
type: object
|
|
22980
|
+
properties:
|
|
22981
|
+
requestId:
|
|
22982
|
+
type: string
|
|
22983
|
+
kind:
|
|
22984
|
+
type: string
|
|
22985
|
+
intent:
|
|
22986
|
+
type: string
|
|
22987
|
+
enum:
|
|
22988
|
+
- approval
|
|
22989
|
+
- question
|
|
22990
|
+
status:
|
|
22991
|
+
type: string
|
|
22992
|
+
enum:
|
|
22993
|
+
- pending
|
|
22994
|
+
- approved
|
|
22995
|
+
- denied
|
|
22996
|
+
- expired
|
|
22997
|
+
- cancelled
|
|
22998
|
+
requesterLabel:
|
|
22999
|
+
type: string
|
|
23000
|
+
toolName:
|
|
23001
|
+
type: string
|
|
23002
|
+
sourceChannel:
|
|
23003
|
+
type: string
|
|
23004
|
+
sourceContextLabel:
|
|
23005
|
+
type: string
|
|
23006
|
+
sourceUrl:
|
|
23007
|
+
type: string
|
|
23008
|
+
slackCardUrl:
|
|
23009
|
+
type: string
|
|
23010
|
+
slackCardAppUrl:
|
|
23011
|
+
type: string
|
|
23012
|
+
decidedAction:
|
|
23013
|
+
type: string
|
|
23014
|
+
decidedByLabel:
|
|
23015
|
+
type: string
|
|
23016
|
+
decidedAt:
|
|
23017
|
+
type: string
|
|
23018
|
+
terminalReason:
|
|
23019
|
+
type: string
|
|
23020
|
+
required:
|
|
23021
|
+
- requestId
|
|
23022
|
+
- kind
|
|
23023
|
+
- intent
|
|
23024
|
+
- status
|
|
23025
|
+
additionalProperties: false
|
|
22813
23026
|
category:
|
|
22814
23027
|
type: string
|
|
22815
23028
|
enum:
|
package/package.json
CHANGED
|
@@ -130,6 +130,34 @@ describe("identity-mirror faithful-replica semantics", () => {
|
|
|
130
130
|
expect(result?.contact.userFile).toBeNull();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
test("an op carrying the gateway channel id adopts it onto a divergent legacy row", () => {
|
|
134
|
+
upsertContactChannel({
|
|
135
|
+
sourceChannel: "slack",
|
|
136
|
+
externalUserId: "UADOPTID",
|
|
137
|
+
displayName: "Alice",
|
|
138
|
+
contactId: "co-adopt-id",
|
|
139
|
+
channelId: "legacy-ch",
|
|
140
|
+
refreshDisplayName: true,
|
|
141
|
+
userFileOnCreate: null,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// The gateway's row for the same identity lives under a different UUID;
|
|
145
|
+
// the mirror adopts it so both stores key the channel identically.
|
|
146
|
+
upsertContactChannel({
|
|
147
|
+
sourceChannel: "slack",
|
|
148
|
+
externalUserId: "UADOPTID",
|
|
149
|
+
displayName: "Alice",
|
|
150
|
+
contactId: "co-adopt-id",
|
|
151
|
+
channelId: "gw-ch-aligned",
|
|
152
|
+
refreshDisplayName: true,
|
|
153
|
+
userFileOnCreate: null,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(channelOwnerById("gw-ch-aligned")).toBe("co-adopt-id");
|
|
157
|
+
expect(channelOwnerById("legacy-ch")).toBeUndefined();
|
|
158
|
+
expect(channelCount("slack", "UADOPTID")).toBe(1);
|
|
159
|
+
});
|
|
160
|
+
|
|
133
161
|
test("Finding B: an explicit (gateway-minted) channel id is reused verbatim", () => {
|
|
134
162
|
const result = upsertContactChannel({
|
|
135
163
|
sourceChannel: "slack",
|
|
@@ -233,9 +261,11 @@ describe("mirror channel-reparenting race semantics", () => {
|
|
|
233
261
|
reassignConflictingChannels: false,
|
|
234
262
|
});
|
|
235
263
|
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
264
|
+
// Ownership never moves without reassign and no duplicate channel is
|
|
265
|
+
// created; the row's id follows the latest gateway-sourced op (id
|
|
266
|
+
// adoption), which is what keeps the two stores' keys aligned.
|
|
267
|
+
expect(channelOwnerById("gw-ch-race-2")).toBe("co-race-1");
|
|
268
|
+
expect(channelOwnerById("gw-ch-race-1")).toBeUndefined();
|
|
239
269
|
expect(channelCount("slack", "URACE")).toBe(1);
|
|
240
270
|
// The losing seed adopts contact #1 rather than minting a channel-less
|
|
241
271
|
// contact under its own id.
|
|
@@ -645,6 +645,65 @@ describe("loadFromDb history repair", () => {
|
|
|
645
645
|
expect(allText).not.toContain("secret text");
|
|
646
646
|
});
|
|
647
647
|
|
|
648
|
+
test("the assistant's own reaction row renders second-person", async () => {
|
|
649
|
+
mockConversation = {
|
|
650
|
+
id: "conv-1",
|
|
651
|
+
contextSummary: null,
|
|
652
|
+
contextCompactedMessageCount: 0,
|
|
653
|
+
totalInputTokens: 0,
|
|
654
|
+
totalOutputTokens: 0,
|
|
655
|
+
totalEstimatedCost: 0,
|
|
656
|
+
};
|
|
657
|
+
mockDbMessages = [
|
|
658
|
+
{
|
|
659
|
+
id: "m1",
|
|
660
|
+
role: "user",
|
|
661
|
+
content: [{ type: "text", text: "great work" }],
|
|
662
|
+
metadata: JSON.stringify({
|
|
663
|
+
providerMeta: JSON.stringify({
|
|
664
|
+
source: "discord",
|
|
665
|
+
conversationExternalId: "chan-1",
|
|
666
|
+
messageId: "555.9",
|
|
667
|
+
eventKind: "message",
|
|
668
|
+
}),
|
|
669
|
+
}),
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
id: "m2",
|
|
673
|
+
role: "assistant",
|
|
674
|
+
content: [{ type: "text", text: "[reaction]" }],
|
|
675
|
+
metadata: JSON.stringify({
|
|
676
|
+
messageKind: "reaction",
|
|
677
|
+
providerMeta: JSON.stringify({
|
|
678
|
+
source: "discord",
|
|
679
|
+
conversationExternalId: "chan-1",
|
|
680
|
+
eventKind: "reaction",
|
|
681
|
+
reaction: {
|
|
682
|
+
targetMessageId: "555.9",
|
|
683
|
+
emoji: "🎉",
|
|
684
|
+
op: "added",
|
|
685
|
+
},
|
|
686
|
+
}),
|
|
687
|
+
}),
|
|
688
|
+
},
|
|
689
|
+
];
|
|
690
|
+
|
|
691
|
+
const conversation = makeConversation();
|
|
692
|
+
await conversation.loadFromDb();
|
|
693
|
+
const allText = conversation
|
|
694
|
+
.getMessages()
|
|
695
|
+
.flatMap((m) => m.content)
|
|
696
|
+
.filter((b) => b.type === "text")
|
|
697
|
+
.map((b) => (b.type === "text" ? b.text : ""))
|
|
698
|
+
.join("\n");
|
|
699
|
+
expect(allText).not.toContain("[reaction]");
|
|
700
|
+
expect(allText).toContain("You reacted with 🎉 to this message:");
|
|
701
|
+
// The quoted target is sender text and stays fenced even in the
|
|
702
|
+
// assistant's own row.
|
|
703
|
+
expect(allText).toContain("great work");
|
|
704
|
+
expect(allText).toContain("<external_content");
|
|
705
|
+
});
|
|
706
|
+
|
|
648
707
|
test("a reaction row does not count as a turn on rehydration", async () => {
|
|
649
708
|
mockConversation = {
|
|
650
709
|
id: "conv-1",
|
|
@@ -115,7 +115,12 @@ mock.module("../schedule/schedule-store.js", () => ({
|
|
|
115
115
|
deleteSchedule: async () => {},
|
|
116
116
|
}));
|
|
117
117
|
|
|
118
|
+
// Spread the actual module so transitive importers of names this
|
|
119
|
+
// factory does not stub keep resolving (a partial factory breaks at
|
|
120
|
+
// import time when the graph gains a new named import).
|
|
121
|
+
const actualFeedWriter = await import("../home/feed-writer.js");
|
|
118
122
|
mock.module("../home/feed-writer.js", () => ({
|
|
123
|
+
...actualFeedWriter,
|
|
119
124
|
stripConversationIds: async () => {},
|
|
120
125
|
}));
|
|
121
126
|
|
|
@@ -98,7 +98,12 @@ mock.module("../schedule/schedule-store.js", () => ({
|
|
|
98
98
|
deleteSchedule: async () => {},
|
|
99
99
|
}));
|
|
100
100
|
|
|
101
|
+
// Spread the actual module so transitive importers of names this
|
|
102
|
+
// factory does not stub keep resolving (a partial factory breaks at
|
|
103
|
+
// import time when the graph gains a new named import).
|
|
104
|
+
const actualFeedWriter = await import("../home/feed-writer.js");
|
|
101
105
|
mock.module("../home/feed-writer.js", () => ({
|
|
106
|
+
...actualFeedWriter,
|
|
102
107
|
stripConversationIds: async () => {},
|
|
103
108
|
}));
|
|
104
109
|
|
|
@@ -441,6 +441,19 @@ export function createGuardianGatewaySim() {
|
|
|
441
441
|
.map((d) => ({ ...d }));
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
+
async function listGuardianRequestDeliveriesByChat(
|
|
445
|
+
channel: string,
|
|
446
|
+
chatId: string,
|
|
447
|
+
): Promise<SimGuardianDelivery[]> {
|
|
448
|
+
throwIfReadError();
|
|
449
|
+
return deliveries
|
|
450
|
+
.filter(
|
|
451
|
+
(d) =>
|
|
452
|
+
d.destinationChannel === channel && d.destinationChatId === chatId,
|
|
453
|
+
)
|
|
454
|
+
.map((d) => ({ ...d }));
|
|
455
|
+
}
|
|
456
|
+
|
|
444
457
|
async function getPendingRequestByDestinationMessage(
|
|
445
458
|
channel: string,
|
|
446
459
|
chatId: string,
|
|
@@ -596,6 +609,7 @@ export function createGuardianGatewaySim() {
|
|
|
596
609
|
getGuardianRequest,
|
|
597
610
|
getGuardianRequestOrNull: degrade(getGuardianRequest, null),
|
|
598
611
|
getGuardianRequestByCodeOrNull: degrade(getGuardianRequestByCode, null),
|
|
612
|
+
listGuardianRequests,
|
|
599
613
|
listGuardianRequestsOrEmpty: degrade(listGuardianRequests, []),
|
|
600
614
|
updateGuardianRequest,
|
|
601
615
|
decideGuardianRequest,
|
|
@@ -605,6 +619,7 @@ export function createGuardianGatewaySim() {
|
|
|
605
619
|
createGuardianRequestDelivery,
|
|
606
620
|
updateGuardianRequestDelivery,
|
|
607
621
|
listGuardianRequestDeliveries,
|
|
622
|
+
listGuardianRequestDeliveriesByChat,
|
|
608
623
|
listGuardianRequestDeliveriesOrEmpty: degrade(
|
|
609
624
|
listGuardianRequestDeliveries,
|
|
610
625
|
[],
|
|
@@ -34,7 +34,13 @@ mock.module("../approvals/guardian-decision-primitive.js", () => ({
|
|
|
34
34
|
applyGuardianDecisionMock(params),
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
|
+
// Spread the actual module so transitive importers of names this
|
|
38
|
+
// factory does not stub keep resolving (a partial factory breaks at
|
|
39
|
+
// import time when the graph gains a new named import).
|
|
40
|
+
const actualGatewayGuardianRequests =
|
|
41
|
+
await import("../channels/gateway-guardian-requests.js");
|
|
37
42
|
mock.module("../channels/gateway-guardian-requests.js", () => ({
|
|
43
|
+
...actualGatewayGuardianRequests,
|
|
38
44
|
getGuardianRequestOrNull: (id: string) =>
|
|
39
45
|
Promise.resolve(requestsById.get(id) ?? null),
|
|
40
46
|
getGuardianRequestByCodeOrNull: () => Promise.resolve(null),
|
|
@@ -37,7 +37,13 @@ mock.module("../util/logger.js", () => ({
|
|
|
37
37
|
|
|
38
38
|
// Gateway guardian-request client — in-memory map driven by tests.
|
|
39
39
|
const guardianRequests = new Map<string, GuardianRequestWire>();
|
|
40
|
+
// Spread the actual module so transitive importers of names this
|
|
41
|
+
// factory does not stub keep resolving (a partial factory breaks at
|
|
42
|
+
// import time when the graph gains a new named import).
|
|
43
|
+
const actualGatewayGuardianRequests =
|
|
44
|
+
await import("../channels/gateway-guardian-requests.js");
|
|
40
45
|
mock.module("../channels/gateway-guardian-requests.js", () => ({
|
|
46
|
+
...actualGatewayGuardianRequests,
|
|
41
47
|
getGuardianRequestOrNull: async (id: string) =>
|
|
42
48
|
guardianRequests.get(id) ?? null,
|
|
43
49
|
}));
|
|
@@ -104,6 +104,46 @@ describe("handleListMessages system-card projection", () => {
|
|
|
104
104
|
expect(silentRow?.noResponse).toBe(true);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
test("projects the reaction fact from a reaction row's envelope", async () => {
|
|
108
|
+
const conv = createConversation();
|
|
109
|
+
const row = await addMessage(
|
|
110
|
+
conv.id,
|
|
111
|
+
"assistant",
|
|
112
|
+
JSON.stringify([{ type: "text", text: "[reaction]" }]),
|
|
113
|
+
{
|
|
114
|
+
metadata: {
|
|
115
|
+
messageKind: "reaction",
|
|
116
|
+
providerMeta: JSON.stringify({
|
|
117
|
+
source: "discord",
|
|
118
|
+
conversationExternalId: "chan-1",
|
|
119
|
+
eventKind: "reaction",
|
|
120
|
+
reaction: {
|
|
121
|
+
targetMessageId: "555.1",
|
|
122
|
+
emoji: "🎉",
|
|
123
|
+
op: "added",
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const response = (await handleListMessages({
|
|
131
|
+
queryParams: { conversationId: conv.id },
|
|
132
|
+
})) as {
|
|
133
|
+
messages: Array<
|
|
134
|
+
ProjectedMessage & {
|
|
135
|
+
reaction?: { emoji: string; selfAuthored?: boolean };
|
|
136
|
+
}
|
|
137
|
+
>;
|
|
138
|
+
};
|
|
139
|
+
for (const message of response.messages) {
|
|
140
|
+
expect(() => ConversationMessageSchema.parse(message)).not.toThrow();
|
|
141
|
+
}
|
|
142
|
+
const projected = response.messages.find((m) => m.id === row.id);
|
|
143
|
+
expect(projected?.reaction?.emoji).toBe("🎉");
|
|
144
|
+
expect(projected?.reaction?.selfAuthored).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
107
147
|
test("omits systemCard on ordinary user and assistant rows", async () => {
|
|
108
148
|
const conv = createConversation();
|
|
109
149
|
await addMessage(
|
|
@@ -385,7 +385,13 @@ mock.module("../runtime/access-request-helper.js", () => ({
|
|
|
385
385
|
// Gateway guardian-request client polled by the guardian wait controller.
|
|
386
386
|
let mockGuardianRequest: { status: string } | null = null;
|
|
387
387
|
const mockGetGuardianRequest = jest.fn(async () => mockGuardianRequest);
|
|
388
|
+
// Spread the actual module so transitive importers of names this
|
|
389
|
+
// factory does not stub keep resolving (a partial factory breaks at
|
|
390
|
+
// import time when the graph gains a new named import).
|
|
391
|
+
const actualGatewayGuardianRequests =
|
|
392
|
+
await import("../channels/gateway-guardian-requests.js");
|
|
388
393
|
mock.module("../channels/gateway-guardian-requests.js", () => ({
|
|
394
|
+
...actualGatewayGuardianRequests,
|
|
389
395
|
getGuardianRequestOrNull: mockGetGuardianRequest,
|
|
390
396
|
}));
|
|
391
397
|
|