@vellumai/assistant 0.11.6-dev.202608262202.d09b5d7 → 0.11.6-dev.202608270011.0dcdb01
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/package.json +1 -1
- package/src/__tests__/channel-policy.test.ts +1 -3
- package/src/__tests__/guardian-card-withdrawal.test.ts +30 -0
- package/src/__tests__/notification-discord-adapter.test.ts +162 -0
- package/src/approvals/guardian-card-withdrawal.ts +22 -0
- package/src/channels/config.ts +23 -12
- package/src/config/bundled-skills/computer-use/TOOLS.json +2 -2
- package/src/config/feature-flag-registry.json +8 -0
- package/src/messaging/providers/discord/withdraw.ts +62 -0
- package/src/notifications/__tests__/connected-channels.test.ts +12 -0
- package/src/notifications/__tests__/destination-resolver.test.ts +38 -0
- package/src/notifications/adapters/discord.ts +132 -0
- package/src/notifications/adapters/shared.ts +16 -0
- package/src/notifications/adapters/telegram.ts +5 -8
- package/src/notifications/destination-resolver.ts +45 -5
- package/src/notifications/emit-signal.ts +19 -5
- package/src/notifications/types.ts +2 -8
- package/src/tools/computer-use/definitions.ts +2 -2
package/package.json
CHANGED
|
@@ -38,9 +38,7 @@ describe("channel policy registry", () => {
|
|
|
38
38
|
|
|
39
39
|
test("getDeliverableChannels returns exactly the channels with deliveryEnabled: true", () => {
|
|
40
40
|
const deliverable = getDeliverableChannels();
|
|
41
|
-
const expected = CHANNEL_IDS.filter(
|
|
42
|
-
(id) => getChannelPolicy(id).notification.deliveryEnabled,
|
|
43
|
-
);
|
|
41
|
+
const expected = CHANNEL_IDS.filter(isNotificationDeliverable);
|
|
44
42
|
|
|
45
43
|
expect(deliverable).toHaveLength(expected.length);
|
|
46
44
|
for (const id of expected) {
|
|
@@ -14,6 +14,11 @@ mock.module("../messaging/providers/slack/withdraw.js", () => ({
|
|
|
14
14
|
withdrawSlackApprovalCard,
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
const withdrawDiscordApprovalCard = mock(async (_params: unknown) => undefined);
|
|
18
|
+
mock.module("../messaging/providers/discord/withdraw.js", () => ({
|
|
19
|
+
withdrawDiscordApprovalCard,
|
|
20
|
+
}));
|
|
21
|
+
|
|
17
22
|
const withdrawTelegramApprovalCard = mock(
|
|
18
23
|
async (_params: Record<string, unknown>) => {},
|
|
19
24
|
);
|
|
@@ -68,6 +73,7 @@ describe("withdrawGuardianRequestCards", () => {
|
|
|
68
73
|
markSurfaceCompleted.mockClear();
|
|
69
74
|
withdrawSlackApprovalCard.mockClear();
|
|
70
75
|
withdrawTelegramApprovalCard.mockClear();
|
|
76
|
+
withdrawDiscordApprovalCard.mockClear();
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
test("withdraws + broadcasts the in-app card when the decision came from another surface", async () => {
|
|
@@ -232,6 +238,30 @@ describe("withdrawGuardianRequestCards", () => {
|
|
|
232
238
|
});
|
|
233
239
|
});
|
|
234
240
|
|
|
241
|
+
test("withdraws the Discord card by rewriting it to the outcome", async () => {
|
|
242
|
+
const req = makeRequest({ sourceChannel: "discord" });
|
|
243
|
+
bridgeState.seedDelivery({
|
|
244
|
+
requestId: req.id,
|
|
245
|
+
destinationChannel: "discord",
|
|
246
|
+
destinationChatId: "111222333444555666",
|
|
247
|
+
destinationMessageId: "2001",
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await withdrawGuardianRequestCards({
|
|
251
|
+
request: req,
|
|
252
|
+
status: "approved",
|
|
253
|
+
originChannel: "vellum",
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
expect(withdrawTelegramApprovalCard).not.toHaveBeenCalled();
|
|
257
|
+
expect(withdrawDiscordApprovalCard).toHaveBeenCalledTimes(1);
|
|
258
|
+
expect(withdrawDiscordApprovalCard).toHaveBeenCalledWith({
|
|
259
|
+
guardianUserId: "111222333444555666",
|
|
260
|
+
messageId: "2001",
|
|
261
|
+
status: "approved",
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
235
265
|
test("suppresses the Telegram status reply only when the origin flow replies to the guardian", async () => {
|
|
236
266
|
const req = makeRequest({ sourceChannel: "telegram" });
|
|
237
267
|
bridgeState.seedDelivery({
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DiscordAdapter delivery behavior.
|
|
3
|
+
*
|
|
4
|
+
* The invariant under test: the adapter addresses the *person*. Every send
|
|
5
|
+
* and update resolves the DM channel from the guardian's user snowflake at
|
|
6
|
+
* call time, so a room id stored anywhere can never become a delivery
|
|
7
|
+
* target, and approval notifications carry the typed-command instructions
|
|
8
|
+
* because nothing ingests component presses yet.
|
|
9
|
+
*/
|
|
10
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
11
|
+
|
|
12
|
+
const dmOpens: string[] = [];
|
|
13
|
+
const sendCalls: Array<{ channelId: string; text: string }> = [];
|
|
14
|
+
const editCalls: Array<{ channelId: string; messageId: string; text: string }> =
|
|
15
|
+
[];
|
|
16
|
+
|
|
17
|
+
mock.module("../messaging/providers/discord/api.js", () => ({
|
|
18
|
+
openDiscordDmChannel: async (userId: string) => {
|
|
19
|
+
dmOpens.push(userId);
|
|
20
|
+
return `dm-for-${userId}`;
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
mock.module("../messaging/providers/discord/send.js", () => ({
|
|
25
|
+
sendDiscordReply: async (target: { channelId: string }, text: string) => {
|
|
26
|
+
sendCalls.push({ channelId: target.channelId, text });
|
|
27
|
+
return { lastMessageId: String(2000 + sendCalls.length) };
|
|
28
|
+
},
|
|
29
|
+
editDiscordMessage: async (
|
|
30
|
+
target: { channelId: string },
|
|
31
|
+
messageId: string,
|
|
32
|
+
text: string,
|
|
33
|
+
) => {
|
|
34
|
+
editCalls.push({ channelId: target.channelId, messageId, text });
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
import type {
|
|
39
|
+
ChannelDeliveryPayload,
|
|
40
|
+
ChannelDestination,
|
|
41
|
+
} from "../notifications/types.js";
|
|
42
|
+
|
|
43
|
+
const { DiscordAdapter } = await import("../notifications/adapters/discord.js");
|
|
44
|
+
|
|
45
|
+
const GUARDIAN_USER_ID = "111222333444555666";
|
|
46
|
+
|
|
47
|
+
function makePayload(
|
|
48
|
+
overrides?: Partial<ChannelDeliveryPayload>,
|
|
49
|
+
): ChannelDeliveryPayload {
|
|
50
|
+
return {
|
|
51
|
+
sourceEventName: "schedule.notify",
|
|
52
|
+
copy: {
|
|
53
|
+
title: "Heads up",
|
|
54
|
+
body: "Your task finished.",
|
|
55
|
+
},
|
|
56
|
+
urgency: "medium",
|
|
57
|
+
...overrides,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function makeDestination(
|
|
62
|
+
overrides?: Partial<ChannelDestination>,
|
|
63
|
+
): ChannelDestination {
|
|
64
|
+
return {
|
|
65
|
+
channel: "discord",
|
|
66
|
+
endpoint: GUARDIAN_USER_ID,
|
|
67
|
+
...overrides,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
dmOpens.length = 0;
|
|
73
|
+
sendCalls.length = 0;
|
|
74
|
+
editCalls.length = 0;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("DiscordAdapter.send", () => {
|
|
78
|
+
test("resolves the DM channel from the guardian's user snowflake", async () => {
|
|
79
|
+
const adapter = new DiscordAdapter();
|
|
80
|
+
const result = await adapter.send(makePayload(), makeDestination());
|
|
81
|
+
|
|
82
|
+
expect(result.success).toBe(true);
|
|
83
|
+
expect(result.messageId).toBe("2001");
|
|
84
|
+
expect(dmOpens).toEqual([GUARDIAN_USER_ID]);
|
|
85
|
+
expect(sendCalls).toHaveLength(1);
|
|
86
|
+
expect(sendCalls[0].channelId).toBe(`dm-for-${GUARDIAN_USER_ID}`);
|
|
87
|
+
expect(sendCalls[0].text).toContain("Your task finished.");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("approval notifications carry the typed-command instructions", async () => {
|
|
91
|
+
const adapter = new DiscordAdapter();
|
|
92
|
+
const result = await adapter.send(
|
|
93
|
+
makePayload({
|
|
94
|
+
approvalContext: {
|
|
95
|
+
requestId: "req-1",
|
|
96
|
+
actions: [{ id: "approve_once", label: "Approve once" }],
|
|
97
|
+
plainTextFallback: 'Reply "approve" or "reject" to decide.',
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
makeDestination(),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(result.success).toBe(true);
|
|
104
|
+
expect(sendCalls).toHaveLength(1);
|
|
105
|
+
expect(sendCalls[0].text).toContain(
|
|
106
|
+
'Reply "approve" or "reject" to decide.',
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a destination without a guardian user id fails without calling the API", async () => {
|
|
111
|
+
const adapter = new DiscordAdapter();
|
|
112
|
+
const result = await adapter.send(
|
|
113
|
+
makePayload(),
|
|
114
|
+
makeDestination({ endpoint: undefined }),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(result.success).toBe(false);
|
|
118
|
+
expect(dmOpens).toHaveLength(0);
|
|
119
|
+
expect(sendCalls).toHaveLength(0);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("DiscordAdapter.update", () => {
|
|
124
|
+
test("edits the card through the same person-resolved DM channel", async () => {
|
|
125
|
+
const adapter = new DiscordAdapter();
|
|
126
|
+
const result = await adapter.update(
|
|
127
|
+
{
|
|
128
|
+
deliveryId: "delivery-1",
|
|
129
|
+
destination: GUARDIAN_USER_ID,
|
|
130
|
+
messageId: "2001",
|
|
131
|
+
},
|
|
132
|
+
{ body: "This approval request has been resolved." },
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(result.success).toBe(true);
|
|
136
|
+
expect(result.messageId).toBe("2001");
|
|
137
|
+
expect(dmOpens).toEqual([GUARDIAN_USER_ID]);
|
|
138
|
+
expect(editCalls).toEqual([
|
|
139
|
+
{
|
|
140
|
+
channelId: `dm-for-${GUARDIAN_USER_ID}`,
|
|
141
|
+
messageId: "2001",
|
|
142
|
+
text: "This approval request has been resolved.",
|
|
143
|
+
},
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("a delivery row without a captured message id cannot be updated", async () => {
|
|
148
|
+
const adapter = new DiscordAdapter();
|
|
149
|
+
const result = await adapter.update(
|
|
150
|
+
{
|
|
151
|
+
deliveryId: "delivery-2",
|
|
152
|
+
destination: GUARDIAN_USER_ID,
|
|
153
|
+
messageId: null,
|
|
154
|
+
},
|
|
155
|
+
{ body: "resolved" },
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(result.success).toBe(false);
|
|
159
|
+
expect(result.error).toContain("missing_message_id");
|
|
160
|
+
expect(editCalls).toHaveLength(0);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
completeSurfaceAndNotify,
|
|
32
32
|
markSurfaceCompleted,
|
|
33
33
|
} from "../daemon/conversation-surfaces.js";
|
|
34
|
+
import { withdrawDiscordApprovalCard } from "../messaging/providers/discord/withdraw.js";
|
|
34
35
|
import { withdrawSlackApprovalCard } from "../messaging/providers/slack/withdraw.js";
|
|
35
36
|
import { withdrawTelegramApprovalCard } from "../messaging/providers/telegram-bot/withdraw.js";
|
|
36
37
|
import { approvalCardSurfaceId } from "../notifications/approval-card-data.js";
|
|
@@ -131,6 +132,8 @@ export async function withdrawGuardianRequestCards(
|
|
|
131
132
|
decidedAction,
|
|
132
133
|
hasOriginGuardianReply ?? false,
|
|
133
134
|
);
|
|
135
|
+
} else if (delivery.destinationChannel === "discord") {
|
|
136
|
+
await withdrawDiscordCard(delivery, status, decidedAction);
|
|
134
137
|
}
|
|
135
138
|
// WhatsApp direct delivery can't edit a message in place (it would
|
|
136
139
|
// post a new one), so its stale clicks are left to the existing
|
|
@@ -231,6 +234,25 @@ async function withdrawSlackCard(
|
|
|
231
234
|
* outcome. No-ops when the channel-native message id was not captured at
|
|
232
235
|
* delivery time.
|
|
233
236
|
*/
|
|
237
|
+
async function withdrawDiscordCard(
|
|
238
|
+
delivery: GuardianRequestDeliveryWire,
|
|
239
|
+
status: GuardianRequestStatus,
|
|
240
|
+
decidedAction: ApprovalAction | undefined,
|
|
241
|
+
): Promise<void> {
|
|
242
|
+
if (!delivery.destinationChatId || !delivery.destinationMessageId) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// The Discord edit rewrites the card's actionable tail to the outcome, so
|
|
246
|
+
// it serves both halves of withdrawal in one call and needs no separate
|
|
247
|
+
// status reply regardless of where the decision originated.
|
|
248
|
+
await withdrawDiscordApprovalCard({
|
|
249
|
+
guardianUserId: delivery.destinationChatId,
|
|
250
|
+
messageId: delivery.destinationMessageId,
|
|
251
|
+
status,
|
|
252
|
+
...(decidedAction ? { decidedAction } : {}),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
234
256
|
async function withdrawTelegramCard(
|
|
235
257
|
delivery: GuardianRequestDeliveryWire,
|
|
236
258
|
status: GuardianRequestStatus,
|
package/src/channels/config.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* to compile until a policy is added below.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type
|
|
9
|
+
import { CHANNEL_IDS, type ChannelId } from "./types.js";
|
|
10
10
|
|
|
11
11
|
export type ConversationStrategy =
|
|
12
12
|
| "start_new_conversation"
|
|
@@ -77,12 +77,12 @@ const CHANNEL_POLICIES = {
|
|
|
77
77
|
notification: {
|
|
78
78
|
// Replies to an inbound Discord message do not read this flag: they
|
|
79
79
|
// route by `replyCallbackUrl` through the channel transport. This gates
|
|
80
|
-
// proactive notification
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
deliveryEnabled:
|
|
80
|
+
// proactive notification, which addresses the verified guardian
|
|
81
|
+
// directly: the adapter resolves a DM channel from the guardian
|
|
82
|
+
// binding's user snowflake, so a notification can never land in a
|
|
83
|
+
// guild room whose id merely looks like a DM's (both are bare
|
|
84
|
+
// snowflakes).
|
|
85
|
+
deliveryEnabled: true,
|
|
86
86
|
conversationStrategy: "continue_existing_conversation",
|
|
87
87
|
},
|
|
88
88
|
},
|
|
@@ -110,20 +110,31 @@ export function getChannelPolicy(
|
|
|
110
110
|
return CHANNEL_POLICIES[channelId];
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* The channels whose policy enables proactive delivery, derived from the
|
|
115
|
+
* registry's literal flags: flipping a channel's deliveryEnabled changes
|
|
116
|
+
* this union, and every exhaustive switch over it, at compile time.
|
|
117
|
+
*/
|
|
118
|
+
export type DeliverableChannelId = {
|
|
119
|
+
[K in keyof ChannelPolicies]: ChannelPolicies[K]["notification"]["deliveryEnabled"] extends true
|
|
120
|
+
? K
|
|
121
|
+
: never;
|
|
122
|
+
}[keyof ChannelPolicies];
|
|
123
|
+
|
|
113
124
|
/**
|
|
114
125
|
* Returns the list of channels where notification delivery is enabled.
|
|
115
126
|
*
|
|
116
127
|
* The return type is derived from the registry so downstream consumers
|
|
117
128
|
* get a narrow union rather than the full ChannelId set.
|
|
118
129
|
*/
|
|
119
|
-
export function getDeliverableChannels():
|
|
120
|
-
return
|
|
121
|
-
(id) => CHANNEL_POLICIES[id].notification.deliveryEnabled,
|
|
122
|
-
);
|
|
130
|
+
export function getDeliverableChannels(): DeliverableChannelId[] {
|
|
131
|
+
return CHANNEL_IDS.filter(isNotificationDeliverable);
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
/** Whether notification delivery is enabled for the given channel. */
|
|
126
|
-
export function isNotificationDeliverable(
|
|
135
|
+
export function isNotificationDeliverable(
|
|
136
|
+
channelId: ChannelId,
|
|
137
|
+
): channelId is DeliverableChannelId {
|
|
127
138
|
return CHANNEL_POLICIES[channelId].notification.deliveryEnabled;
|
|
128
139
|
}
|
|
129
140
|
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
},
|
|
199
199
|
"executor": "tools/computer-use-drag.ts",
|
|
200
200
|
"execution_target": "host",
|
|
201
|
-
"supported_client_os": ["macos"]
|
|
201
|
+
"supported_client_os": ["macos", "windows"]
|
|
202
202
|
},
|
|
203
203
|
{
|
|
204
204
|
"name": "computer_use_wait",
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
},
|
|
252
252
|
"executor": "tools/computer-use-open-app.ts",
|
|
253
253
|
"execution_target": "host",
|
|
254
|
-
"supported_client_os": ["macos"]
|
|
254
|
+
"supported_client_os": ["macos", "windows"]
|
|
255
255
|
},
|
|
256
256
|
{
|
|
257
257
|
"name": "computer_use_run_applescript",
|
|
@@ -396,6 +396,14 @@
|
|
|
396
396
|
"label": "iOS Avatar App Icon",
|
|
397
397
|
"description": "Shows the App icon picker in Settings -> General, where any user chooses an eyes-on-color home screen icon for iOS, seeds the picker from their assistant's character avatar, or resets to the default. Every change is a press, and iOS confirms each one with an alert of its own. Off hides the picker and leaves the default icon in place.",
|
|
398
398
|
"defaultEnabled": false
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
"id": "channel-conversation-sidecar",
|
|
402
|
+
"scope": "client",
|
|
403
|
+
"key": "channel-conversation-sidecar",
|
|
404
|
+
"label": "Channel Conversation Sidecar",
|
|
405
|
+
"description": "Renders a conversation bound to an external channel (Slack, Telegram, Discord, phone, email, and any other channel adapter) as two lanes in web chat: Vellum stays the primary full-width lane, and the canonical external-channel transcript moves into the existing read-only right drawer, opened from a channel-thread control in the chat header. Rows the client can attribute to the external channel are drawn once, in the drawer, instead of being blended into the Vellum lane. The drawer offers an Open in <channel> secondary action and a per-message Reference in Vellum action that stages one quoted reference above the Vellum composer. The Vellum composer stays the only input; nothing about delivery, routing, or permissions changes. Off leaves the header deep-link pill and the blended transcript unchanged.",
|
|
406
|
+
"defaultEnabled": false
|
|
399
407
|
}
|
|
400
408
|
]
|
|
401
409
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdraw a Discord approval card when its underlying guardian request
|
|
3
|
+
* resolves.
|
|
4
|
+
*
|
|
5
|
+
* A Discord card is plain text whose actionable tail (the typed-command
|
|
6
|
+
* instructions) rides the last chunk, and that chunk's id is what the
|
|
7
|
+
* delivery row captured. Rewriting it to the terminal outcome removes every
|
|
8
|
+
* live affordance and shows the decision in one edit, so no separate status
|
|
9
|
+
* reply is needed. The delivery row's chat id is the guardian's *user*
|
|
10
|
+
* snowflake, never a room: the DM channel is resolved from the person at
|
|
11
|
+
* withdrawal time, the same way the adapter resolved it to deliver.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
isParkAction,
|
|
16
|
+
resolveDecisionStatusWord,
|
|
17
|
+
} from "../../../runtime/channel-approval-types.js";
|
|
18
|
+
import { getLogger } from "../../../util/logger.js";
|
|
19
|
+
import { openDiscordDmChannel } from "./api.js";
|
|
20
|
+
import { editDiscordMessage } from "./send.js";
|
|
21
|
+
|
|
22
|
+
const log = getLogger("discord-withdraw");
|
|
23
|
+
|
|
24
|
+
const STATUS_GLYPH: Record<string, string> = {
|
|
25
|
+
approved: "✅",
|
|
26
|
+
denied: "❌",
|
|
27
|
+
expired: "⌛",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const PARK_STATUS_GLYPH = "⏸️";
|
|
31
|
+
|
|
32
|
+
function buildStatusText(status: string, decidedAction?: string): string {
|
|
33
|
+
const park = status === "denied" && isParkAction(decidedAction);
|
|
34
|
+
const glyph = park ? PARK_STATUS_GLYPH : (STATUS_GLYPH[status] ?? "");
|
|
35
|
+
const word = resolveDecisionStatusWord(status, decidedAction);
|
|
36
|
+
return glyph ? `${glyph} ${word}` : word;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WithdrawDiscordApprovalCardParams {
|
|
40
|
+
/** The guardian's user snowflake from the delivery row. */
|
|
41
|
+
guardianUserId: string;
|
|
42
|
+
/** The card's last-chunk message id from the delivery row. */
|
|
43
|
+
messageId: string;
|
|
44
|
+
status: string;
|
|
45
|
+
decidedAction?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function withdrawDiscordApprovalCard(
|
|
49
|
+
params: WithdrawDiscordApprovalCardParams,
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
const channelId = await openDiscordDmChannel(params.guardianUserId);
|
|
52
|
+
await editDiscordMessage(
|
|
53
|
+
{ channelId },
|
|
54
|
+
params.messageId,
|
|
55
|
+
buildStatusText(params.status, params.decidedAction),
|
|
56
|
+
{ emphasis: "muted" },
|
|
57
|
+
);
|
|
58
|
+
log.info(
|
|
59
|
+
{ guardianUserId: params.guardianUserId, messageId: params.messageId },
|
|
60
|
+
"Discord approval card withdrawn",
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -78,6 +78,18 @@ describe("getConnectedChannels gateway connectivity", () => {
|
|
|
78
78
|
expect(await getConnectedChannels()).toContain("slack");
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
test("marks discord connected from a verified guardian binding", async () => {
|
|
82
|
+
deliverableChannels = ["discord"];
|
|
83
|
+
gatewayGuardians = [gatewayBinding("discord", "999888777666555444")];
|
|
84
|
+
expect(await getConnectedChannels()).toContain("discord");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("marks discord disconnected when the gateway has no binding", async () => {
|
|
88
|
+
deliverableChannels = ["discord"];
|
|
89
|
+
gatewayGuardians = [];
|
|
90
|
+
expect(await getConnectedChannels()).not.toContain("discord");
|
|
91
|
+
});
|
|
92
|
+
|
|
81
93
|
test("always reports vellum and platform connected", async () => {
|
|
82
94
|
deliverableChannels = ["vellum", "platform"];
|
|
83
95
|
gatewayGuardians = null;
|
|
@@ -79,6 +79,44 @@ describe("resolveDestinations — gateway guardian list", () => {
|
|
|
79
79
|
expect(result.has("telegram")).toBe(false);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
+
test("discord addresses the guardian's user snowflake, never a room id", () => {
|
|
83
|
+
const list = [
|
|
84
|
+
guardian({
|
|
85
|
+
channelType: "discord",
|
|
86
|
+
address: "111222333444555666",
|
|
87
|
+
externalChatId: "999888777666555444",
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
const result = resolveDestinations(["discord"], list);
|
|
91
|
+
expect(result.get("discord")).toEqual({
|
|
92
|
+
channel: "discord",
|
|
93
|
+
endpoint: "111222333444555666",
|
|
94
|
+
metadata: { externalUserId: "111222333444555666" },
|
|
95
|
+
bindingContext: {
|
|
96
|
+
sourceChannel: "discord",
|
|
97
|
+
externalChatId: "999888777666555444",
|
|
98
|
+
externalUserId: "111222333444555666",
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("discord without a binding conversation still resolves the person", () => {
|
|
104
|
+
const list = [
|
|
105
|
+
guardian({ channelType: "discord", address: "111222333444555666" }),
|
|
106
|
+
];
|
|
107
|
+
const result = resolveDestinations(["discord"], list);
|
|
108
|
+
expect(result.get("discord")).toEqual({
|
|
109
|
+
channel: "discord",
|
|
110
|
+
endpoint: "111222333444555666",
|
|
111
|
+
metadata: { externalUserId: "111222333444555666" },
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("discord with no guardian binding is omitted", () => {
|
|
116
|
+
const result = resolveDestinations(["discord"], []);
|
|
117
|
+
expect(result.has("discord")).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
82
120
|
test("slack resolves DM endpoint and binding context", () => {
|
|
83
121
|
const list = [
|
|
84
122
|
guardian({
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord channel adapter: delivers notifications to the guardian's DM by
|
|
3
|
+
* calling the Discord REST API directly.
|
|
4
|
+
*
|
|
5
|
+
* The destination endpoint is the guardian's *user* snowflake, never a stored
|
|
6
|
+
* channel id: user and channel snowflakes are indistinguishable bare numbers,
|
|
7
|
+
* so the adapter resolves the DM channel from the person at send time
|
|
8
|
+
* (cached per user) and a room id on the binding can never become a delivery
|
|
9
|
+
* target. That is Slack's D-prefix DM gate, achieved by construction.
|
|
10
|
+
*
|
|
11
|
+
* Approval notifications carry the typed-command instructions instead of
|
|
12
|
+
* component buttons: nothing ingests INTERACTION_CREATE yet, and a button
|
|
13
|
+
* whose press goes nowhere is a dead control. When interaction ingest lands,
|
|
14
|
+
* buttons arrive here as a rendering upgrade, not a new decision path.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { openDiscordDmChannel } from "../../messaging/providers/discord/api.js";
|
|
18
|
+
import {
|
|
19
|
+
editDiscordMessage,
|
|
20
|
+
sendDiscordReply,
|
|
21
|
+
} from "../../messaging/providers/discord/send.js";
|
|
22
|
+
import { ConfigError } from "../../util/errors.js";
|
|
23
|
+
import { getLogger } from "../../util/logger.js";
|
|
24
|
+
import type {
|
|
25
|
+
ChannelAdapter,
|
|
26
|
+
ChannelDeliveryPayload,
|
|
27
|
+
ChannelDestination,
|
|
28
|
+
ChannelUpdateContext,
|
|
29
|
+
ChannelUpdatePayload,
|
|
30
|
+
DeliveryResult,
|
|
31
|
+
NotificationChannel,
|
|
32
|
+
} from "../types.js";
|
|
33
|
+
import { appendPlainTextFallback, resolveMessageText } from "./shared.js";
|
|
34
|
+
|
|
35
|
+
const log = getLogger("notif-adapter-discord");
|
|
36
|
+
|
|
37
|
+
export class DiscordAdapter implements ChannelAdapter {
|
|
38
|
+
readonly channel: NotificationChannel = "discord";
|
|
39
|
+
|
|
40
|
+
async send(
|
|
41
|
+
payload: ChannelDeliveryPayload,
|
|
42
|
+
destination: ChannelDestination,
|
|
43
|
+
): Promise<DeliveryResult> {
|
|
44
|
+
const guardianUserId = destination.endpoint;
|
|
45
|
+
if (!guardianUserId) {
|
|
46
|
+
log.warn(
|
|
47
|
+
{ sourceEventName: payload.sourceEventName },
|
|
48
|
+
"Discord destination has no guardian user id; skipping",
|
|
49
|
+
);
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: "No guardian user id configured for Discord destination",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const text = appendPlainTextFallback(
|
|
57
|
+
resolveMessageText(payload),
|
|
58
|
+
payload.approvalContext,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const channelId = await openDiscordDmChannel(guardianUserId);
|
|
63
|
+
const sent = await sendDiscordReply({ channelId }, text);
|
|
64
|
+
|
|
65
|
+
log.info(
|
|
66
|
+
{ sourceEventName: payload.sourceEventName, guardianUserId },
|
|
67
|
+
"Discord notification delivered",
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// The message id lets the delivery row address the card later
|
|
71
|
+
// (in-place withdrawal when the request resolves elsewhere).
|
|
72
|
+
return { success: true, messageId: sent.lastMessageId };
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
75
|
+
// A missing bot token means the operator simply hasn't configured
|
|
76
|
+
// Discord; it is not a code fault, so log it at warn to keep it out
|
|
77
|
+
// of Sentry. Genuine and transient failures stay at error so they
|
|
78
|
+
// remain visible.
|
|
79
|
+
const logFn = err instanceof ConfigError ? log.warn : log.error;
|
|
80
|
+
logFn(
|
|
81
|
+
{ err, sourceEventName: payload.sourceEventName, guardianUserId },
|
|
82
|
+
"Failed to deliver Discord notification",
|
|
83
|
+
);
|
|
84
|
+
return { success: false, error: message };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Replace a delivered notification in place, so a card that has been
|
|
90
|
+
* answered or withdrawn stops reading as still waiting.
|
|
91
|
+
*/
|
|
92
|
+
async update(
|
|
93
|
+
delivery: ChannelUpdateContext,
|
|
94
|
+
patch: ChannelUpdatePayload,
|
|
95
|
+
): Promise<DeliveryResult> {
|
|
96
|
+
if (!delivery.messageId) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
error:
|
|
100
|
+
"missing_message_id: this delivery has no captured Discord message id",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const text = patch.body?.trim() || patch.title?.trim();
|
|
104
|
+
if (!text) {
|
|
105
|
+
return { success: false, error: "no body or title supplied for update" };
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
// The delivery row's destination is the guardian's user snowflake, so
|
|
109
|
+
// the edit resolves the same cached DM channel the send used.
|
|
110
|
+
const channelId = await openDiscordDmChannel(delivery.destination);
|
|
111
|
+
await editDiscordMessage({ channelId }, delivery.messageId, text);
|
|
112
|
+
log.info(
|
|
113
|
+
{ guardianUserId: delivery.destination, messageId: delivery.messageId },
|
|
114
|
+
"Discord notification updated",
|
|
115
|
+
);
|
|
116
|
+
// An edit keeps the message it addressed, so the delivery row's id
|
|
117
|
+
// still identifies the card.
|
|
118
|
+
return { success: true, messageId: delivery.messageId };
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
121
|
+
log.error(
|
|
122
|
+
{
|
|
123
|
+
err,
|
|
124
|
+
guardianUserId: delivery.destination,
|
|
125
|
+
messageId: delivery.messageId,
|
|
126
|
+
},
|
|
127
|
+
"Failed to update Discord notification",
|
|
128
|
+
);
|
|
129
|
+
return { success: false, error: message };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -33,3 +33,19 @@ export function resolveMessageText(payload: ChannelDeliveryPayload): string {
|
|
|
33
33
|
|
|
34
34
|
return payload.sourceEventName.replace(/[._]/g, " ");
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Append an approval's typed-command instructions to the message text, when
|
|
39
|
+
* the copy does not already carry them. Used by adapters delivering an
|
|
40
|
+
* approval without live buttons (Discord always; Telegram when its rich
|
|
41
|
+
* delivery fails), so the guardian still knows how to decide.
|
|
42
|
+
*/
|
|
43
|
+
export function appendPlainTextFallback(
|
|
44
|
+
text: string,
|
|
45
|
+
approval: ChannelDeliveryPayload["approvalContext"],
|
|
46
|
+
): string {
|
|
47
|
+
return approval?.plainTextFallback &&
|
|
48
|
+
!text.includes(approval.plainTextFallback)
|
|
49
|
+
? `${text}\n\n${approval.plainTextFallback}`
|
|
50
|
+
: text;
|
|
51
|
+
}
|
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
DeliveryResult,
|
|
24
24
|
NotificationChannel,
|
|
25
25
|
} from "../types.js";
|
|
26
|
-
import { resolveMessageText } from "./shared.js";
|
|
26
|
+
import { appendPlainTextFallback, resolveMessageText } from "./shared.js";
|
|
27
27
|
|
|
28
28
|
const log = getLogger("notif-adapter-telegram");
|
|
29
29
|
|
|
@@ -74,13 +74,10 @@ export class TelegramAdapter implements ChannelAdapter {
|
|
|
74
74
|
|
|
75
75
|
// When falling back from rich delivery, append the plain-text
|
|
76
76
|
// instructions so the guardian still knows how to approve/reject.
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: messageText;
|
|
82
|
-
|
|
83
|
-
const sent = await sendTelegramReply(chatId, fallbackText);
|
|
77
|
+
const sent = await sendTelegramReply(
|
|
78
|
+
chatId,
|
|
79
|
+
appendPlainTextFallback(messageText, approval),
|
|
80
|
+
);
|
|
84
81
|
|
|
85
82
|
log.info(
|
|
86
83
|
{ sourceEventName: payload.sourceEventName, chatId },
|
|
@@ -66,10 +66,9 @@ export function resolveDestinations(
|
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
switch (channel as NotificationChannel) {
|
|
69
|
+
// `isNotificationDeliverable` is a type predicate, so past this point
|
|
70
|
+
// `channel` is a NotificationChannel and the switch below is exhaustive.
|
|
71
|
+
switch (channel) {
|
|
73
72
|
case "vellum": {
|
|
74
73
|
// Vellum delivery is local — no external endpoint required.
|
|
75
74
|
// Include the guardianPrincipalId so the adapter can annotate
|
|
@@ -155,6 +154,44 @@ export function resolveDestinations(
|
|
|
155
154
|
);
|
|
156
155
|
break;
|
|
157
156
|
}
|
|
157
|
+
case "discord": {
|
|
158
|
+
const guardian = resolveGuardian(guardians, "discord");
|
|
159
|
+
// The endpoint is the guardian's user snowflake: the person, never a
|
|
160
|
+
// stored room id. User and channel snowflakes are indistinguishable
|
|
161
|
+
// bare numbers, so the adapter resolves the DM channel from the
|
|
162
|
+
// person at send time and a guild room can never become a delivery
|
|
163
|
+
// target. The binding context reuses the conversation the guardian
|
|
164
|
+
// verified in, which the verification intercept scopes to the DM
|
|
165
|
+
// lane; delivery stays DM-safe regardless, since it never reads
|
|
166
|
+
// this id.
|
|
167
|
+
if (guardian?.address) {
|
|
168
|
+
result.set("discord", {
|
|
169
|
+
channel: "discord",
|
|
170
|
+
endpoint: guardian.address,
|
|
171
|
+
metadata: {
|
|
172
|
+
externalUserId: guardian.address,
|
|
173
|
+
},
|
|
174
|
+
...(guardian.externalChatId
|
|
175
|
+
? {
|
|
176
|
+
bindingContext: {
|
|
177
|
+
sourceChannel: "discord" as const,
|
|
178
|
+
externalChatId: guardian.externalChatId,
|
|
179
|
+
externalUserId: guardian.address,
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
log.debug(
|
|
186
|
+
{
|
|
187
|
+
channel: "discord",
|
|
188
|
+
source: "guardian-delivery",
|
|
189
|
+
hasEndpoint: !!guardian?.address,
|
|
190
|
+
},
|
|
191
|
+
"destination resolved",
|
|
192
|
+
);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
158
195
|
case "platform": {
|
|
159
196
|
// Platform delivery goes through the daemon's VellumPlatformClient —
|
|
160
197
|
// no external binding needed. Include guardianPrincipalId so the
|
|
@@ -180,7 +217,10 @@ export function resolveDestinations(
|
|
|
180
217
|
break;
|
|
181
218
|
}
|
|
182
219
|
default: {
|
|
183
|
-
//
|
|
220
|
+
// Exhaustive over NotificationChannel: a channel whose policy turns
|
|
221
|
+
// deliveryEnabled on must answer addressing here at compile time,
|
|
222
|
+
// because a silent skip is how a half-wired channel disappears.
|
|
223
|
+
channel satisfies never;
|
|
184
224
|
break;
|
|
185
225
|
}
|
|
186
226
|
}
|
|
@@ -22,6 +22,7 @@ import { isPlatformClientConfigured } from "../platform/client.js";
|
|
|
22
22
|
import { broadcastMessage } from "../runtime/assistant-event-hub.js";
|
|
23
23
|
import { getLogger } from "../util/logger.js";
|
|
24
24
|
import { withSqliteRetry } from "../util/sqlite-retry.js";
|
|
25
|
+
import { DiscordAdapter } from "./adapters/discord.js";
|
|
25
26
|
import { VellumAdapter } from "./adapters/macos.js";
|
|
26
27
|
import { PlatformPushAdapter } from "./adapters/platform.js";
|
|
27
28
|
import { SlackAdapter } from "./adapters/slack.js";
|
|
@@ -64,6 +65,7 @@ export function getBroadcaster(): NotificationBroadcaster {
|
|
|
64
65
|
new VellumAdapter(broadcastMessage),
|
|
65
66
|
new TelegramAdapter(),
|
|
66
67
|
new SlackAdapter(),
|
|
68
|
+
new DiscordAdapter(),
|
|
67
69
|
new PlatformPushAdapter(),
|
|
68
70
|
]);
|
|
69
71
|
|
|
@@ -117,9 +119,6 @@ export async function getConnectedChannels(): Promise<NotificationChannel[]> {
|
|
|
117
119
|
// unreachable, so binding-based connectivity falls back to the local read.
|
|
118
120
|
const guardians = await getGuardianDelivery();
|
|
119
121
|
|
|
120
|
-
// getDeliverableChannels() returns ChannelId[] but every returned channel
|
|
121
|
-
// has deliveryEnabled: true, making it a valid NotificationChannel at
|
|
122
|
-
// runtime. We iterate over the broad type and narrow via the switch.
|
|
123
122
|
for (const channel of getDeliverableChannels()) {
|
|
124
123
|
switch (channel) {
|
|
125
124
|
case "vellum":
|
|
@@ -153,9 +152,24 @@ export async function getConnectedChannels(): Promise<NotificationChannel[]> {
|
|
|
153
152
|
}
|
|
154
153
|
break;
|
|
155
154
|
}
|
|
155
|
+
case "discord": {
|
|
156
|
+
// Connected when a verified guardian binding names a user to DM,
|
|
157
|
+
// mirroring destination-resolver: the person is the endpoint, and
|
|
158
|
+
// the adapter resolves the DM channel from them at send time.
|
|
159
|
+
const guardian = guardians
|
|
160
|
+
? guardianForChannel(guardians, channel)
|
|
161
|
+
: undefined;
|
|
162
|
+
if (guardian?.address) {
|
|
163
|
+
channels.push(channel);
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
156
167
|
default:
|
|
157
|
-
//
|
|
158
|
-
//
|
|
168
|
+
// Exhaustive over NotificationChannel: a channel whose policy turns
|
|
169
|
+
// deliveryEnabled on must answer connectivity here at compile time.
|
|
170
|
+
// A silent skip is how a half-wired channel disappears without a
|
|
171
|
+
// trace, so the compiler holds the door instead.
|
|
172
|
+
channel satisfies never;
|
|
159
173
|
break;
|
|
160
174
|
}
|
|
161
175
|
}
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
import { ApprovalUIMetadataSchema } from "@vellumai/gateway-client";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
import type { ChannelId } from "../channels/types.js";
|
|
13
|
+
import type { DeliverableChannelId } from "../channels/config.js";
|
|
15
14
|
import { AccessRequestPayloadSchema } from "./access-request-copy.js";
|
|
16
15
|
import { ToolApprovalSourceViewSchema } from "./guardian-question-mode.js";
|
|
17
16
|
import { UrgencySchema } from "./urgency.js";
|
|
@@ -20,12 +19,7 @@ import { UrgencySchema } from "./urgency.js";
|
|
|
20
19
|
* Derived from the channel policy registry: only channels whose
|
|
21
20
|
* deliveryEnabled flag is true are valid notification channels.
|
|
22
21
|
*/
|
|
23
|
-
export type NotificationChannel =
|
|
24
|
-
[K in keyof ChannelPolicies]: ChannelPolicies[K]["notification"]["deliveryEnabled"] extends true
|
|
25
|
-
? K
|
|
26
|
-
: never;
|
|
27
|
-
}[keyof ChannelPolicies] &
|
|
28
|
-
ChannelId;
|
|
22
|
+
export type NotificationChannel = DeliverableChannelId;
|
|
29
23
|
|
|
30
24
|
export const NotificationDeliveryStatusSchema = z.enum([
|
|
31
25
|
"pending",
|
|
@@ -224,7 +224,7 @@ export const computerUseDragTool = {
|
|
|
224
224
|
category: "computer-use",
|
|
225
225
|
defaultRiskLevel: RiskLevel.Low,
|
|
226
226
|
executionTarget: "host",
|
|
227
|
-
supportedClientOs: ["macos"],
|
|
227
|
+
supportedClientOs: ["macos", "windows"],
|
|
228
228
|
|
|
229
229
|
input_schema: {
|
|
230
230
|
type: "object",
|
|
@@ -317,7 +317,7 @@ export const computerUseOpenAppTool = {
|
|
|
317
317
|
category: "computer-use",
|
|
318
318
|
defaultRiskLevel: RiskLevel.Low,
|
|
319
319
|
executionTarget: "host",
|
|
320
|
-
supportedClientOs: ["macos"],
|
|
320
|
+
supportedClientOs: ["macos", "windows"],
|
|
321
321
|
|
|
322
322
|
input_schema: {
|
|
323
323
|
type: "object",
|