@vellumai/assistant 0.10.11-dev.202607221933.baa2119 → 0.10.11-dev.202607222129.31c06e5
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__/binding-strength-contract.test.ts +122 -0
- package/node_modules/@vellumai/gateway-client/src/binding-strength-contract.ts +155 -0
- package/node_modules/@vellumai/gateway-client/src/index.ts +14 -0
- package/package.json +1 -1
- package/src/__tests__/approval-source-link.test.ts +208 -0
- package/src/__tests__/btw-routes.test.ts +13 -2
- package/src/__tests__/conversation-store-ephemeral.test.ts +182 -0
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -1
- package/src/__tests__/slack-notification-approval-card.test.ts +103 -20
- package/src/__tests__/tool-approval-seed-content-blocks.test.ts +179 -96
- package/src/__tests__/ui-choice-copy-surfaces.test.ts +144 -3
- package/src/api/events/memory-recalled.ts +59 -0
- package/src/api/events/memory-status.ts +29 -0
- package/src/api/events/service-group-update-complete.ts +29 -0
- package/src/api/events/service-group-update-progress.ts +23 -0
- package/src/api/events/service-group-update-starting.ts +26 -0
- package/src/api/index.ts +36 -1
- package/src/api/surfaces.ts +77 -21
- package/src/calls/__tests__/voice-triage-escalate.test.ts +58 -3
- package/src/calls/voice-session-bridge.ts +6 -2
- package/src/calls/voice-triage-escalate.ts +30 -1
- package/src/config/feature-flag-registry.json +9 -0
- package/src/daemon/conversation-store.ts +14 -2
- package/src/daemon/conversation-surfaces.ts +78 -168
- package/src/daemon/conversation-tool-setup.ts +7 -3
- package/src/daemon/handlers/shared.ts +11 -1
- package/src/daemon/message-types/memory.ts +8 -46
- package/src/daemon/message-types/surfaces.ts +1 -1
- package/src/daemon/message-types/upgrades.ts +11 -28
- package/src/daemon/trust-context-types.ts +8 -0
- package/src/messaging/channel-binding-schema.ts +6 -2
- package/src/messaging/providers/slack/approval-source.ts +87 -0
- package/src/messaging/providers/slack/deep-link.ts +45 -8
- package/src/messaging/providers/slack/message-metadata.ts +16 -0
- package/src/notifications/AGENTS.md +2 -0
- package/src/notifications/access-request-copy.ts +10 -21
- package/src/notifications/adapters/slack.ts +67 -13
- package/src/notifications/approval-card-data.ts +58 -16
- package/src/notifications/broadcaster.ts +41 -19
- package/src/notifications/guardian-question-mode.ts +81 -0
- package/src/notifications/types.ts +5 -0
- package/src/persistence/delivery-crud.ts +48 -1
- package/src/persistence/migrations/347-delete-stray-greeting-conversation.ts +46 -0
- package/src/persistence/migrations/__tests__/347-delete-stray-greeting-conversation.test.ts +100 -0
- package/src/persistence/steps.ts +2 -0
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +2 -2
- package/src/plugins/mtime-cache.ts +21 -10
- package/src/runtime/approval-source-link.ts +107 -0
- package/src/runtime/confirmation-request-guardian-bridge.ts +9 -0
- package/src/runtime/introduction-policy.ts +23 -54
- package/src/runtime/routes/btw-routes.ts +9 -2
- package/src/runtime/routes/inbound-message-handler.ts +5 -13
- package/src/runtime/routes/upgrade-broadcast-routes.ts +6 -8
- package/src/runtime/tool-grant-request-helper.ts +14 -0
- package/src/tools/registry.ts +26 -17
- package/src/tools/tool-approval-handler.ts +2 -0
- package/src/tools/types.ts +8 -0
- package/src/tools/ui-surface/definitions.ts +20 -16
- package/src/tools/ui-surface/surface-shape-docs.ts +21 -6
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
ApprovalCardBlock,
|
|
5
|
+
ApprovalCardFallbackBlock,
|
|
6
|
+
ApprovalCardSurfaceBlock,
|
|
7
|
+
} from "../notifications/approval-card-builder.js";
|
|
3
8
|
import { buildToolApprovalSeedContentBlocks } from "../notifications/approval-card-data.js";
|
|
4
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Narrow the `[ui_surface, text]` pair through the discriminated union so
|
|
12
|
+
* assertions read typed fields — a shape change in the block contract fails
|
|
13
|
+
* compilation here instead of silently passing through a cast.
|
|
14
|
+
*/
|
|
15
|
+
function surfaceBlock(blocks: ApprovalCardBlock[]): ApprovalCardSurfaceBlock {
|
|
16
|
+
const block = blocks[0];
|
|
17
|
+
if (block?.type !== "ui_surface") {
|
|
18
|
+
throw new Error("expected a ui_surface block first");
|
|
19
|
+
}
|
|
20
|
+
return block;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fallbackBlock(blocks: ApprovalCardBlock[]): ApprovalCardFallbackBlock {
|
|
24
|
+
const block = blocks[1];
|
|
25
|
+
if (block?.type !== "text") {
|
|
26
|
+
throw new Error("expected a text fallback block second");
|
|
27
|
+
}
|
|
28
|
+
return block;
|
|
29
|
+
}
|
|
30
|
+
|
|
5
31
|
describe("buildToolApprovalSeedContentBlocks", () => {
|
|
6
32
|
const toolApprovalPayload: Record<string, unknown> = {
|
|
7
33
|
requestId: "req-tool-456",
|
|
@@ -50,15 +76,18 @@ describe("buildToolApprovalSeedContentBlocks", () => {
|
|
|
50
76
|
voiceToolApprovalPayload,
|
|
51
77
|
)!;
|
|
52
78
|
expect(blocks).toHaveLength(2);
|
|
53
|
-
|
|
54
|
-
const surface = blocks[0] as Record<string, unknown>;
|
|
79
|
+
const surface = surfaceBlock(blocks);
|
|
55
80
|
expect(surface.surfaceType).toBe("card");
|
|
56
81
|
expect(surface.surfaceId).toBe("tool-approval-req-voice-101");
|
|
57
|
-
|
|
58
|
-
expect(data.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
expect(surface.data.subtitle).toBe("Requires your approval to run");
|
|
83
|
+
expect(surface.data.metadata).toContainEqual({
|
|
84
|
+
label: "Requested by",
|
|
85
|
+
value: "Bob",
|
|
86
|
+
});
|
|
87
|
+
expect(surface.data.metadata).toContainEqual({
|
|
88
|
+
label: "Source",
|
|
89
|
+
value: "phone",
|
|
90
|
+
});
|
|
62
91
|
});
|
|
63
92
|
|
|
64
93
|
test("returns null for pending_question without toolName", () => {
|
|
@@ -69,134 +98,187 @@ describe("buildToolApprovalSeedContentBlocks", () => {
|
|
|
69
98
|
test("produces a ui_surface block and a text fallback block for tool_approval", () => {
|
|
70
99
|
const blocks = buildToolApprovalSeedContentBlocks(toolApprovalPayload)!;
|
|
71
100
|
expect(blocks).toHaveLength(2);
|
|
72
|
-
|
|
73
|
-
expect((blocks[1] as Record<string, unknown>).type).toBe("text");
|
|
101
|
+
surfaceBlock(blocks);
|
|
74
102
|
// The fallback block is flagged so surface-capable clients skip it.
|
|
75
|
-
expect((blocks
|
|
103
|
+
expect(fallbackBlock(blocks)._surfaceFallback).toBe(true);
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
test("produces a ui_surface block and a text fallback block for tool_grant_request", () => {
|
|
79
107
|
const blocks = buildToolApprovalSeedContentBlocks(toolGrantPayload)!;
|
|
80
108
|
expect(blocks).toHaveLength(2);
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
// The narrowing helpers throw unless the pair is [ui_surface, text].
|
|
110
|
+
surfaceBlock(blocks);
|
|
111
|
+
fallbackBlock(blocks);
|
|
83
112
|
});
|
|
84
113
|
|
|
85
114
|
test("card surface has correct surfaceType and surfaceId for tool_approval", () => {
|
|
86
|
-
const
|
|
87
|
-
|
|
115
|
+
const surface = surfaceBlock(
|
|
116
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
117
|
+
);
|
|
88
118
|
expect(surface.surfaceType).toBe("card");
|
|
89
119
|
expect(surface.surfaceId).toBe("tool-approval-req-tool-456");
|
|
90
120
|
expect(surface.title).toBe("Tool Approval");
|
|
91
121
|
});
|
|
92
122
|
|
|
93
123
|
test("card surface has correct title for tool_grant_request", () => {
|
|
94
|
-
const
|
|
95
|
-
|
|
124
|
+
const surface = surfaceBlock(
|
|
125
|
+
buildToolApprovalSeedContentBlocks(toolGrantPayload)!,
|
|
126
|
+
);
|
|
96
127
|
expect(surface.title).toBe("Tool Grant Request");
|
|
97
128
|
});
|
|
98
129
|
|
|
99
130
|
test("card data uses the tool name as title — the decision is about the tool", () => {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
>;
|
|
105
|
-
expect(data.title).toBe("bash");
|
|
131
|
+
const surface = surfaceBlock(
|
|
132
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
133
|
+
);
|
|
134
|
+
expect(surface.data.title).toBe("bash");
|
|
106
135
|
});
|
|
107
136
|
|
|
108
137
|
test("requester appears only as metadata context, not as the card title", () => {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
138
|
+
const surface = surfaceBlock(
|
|
139
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
140
|
+
);
|
|
141
|
+
expect(surface.data.title).not.toBe("Bob");
|
|
142
|
+
expect(surface.data.metadata).toContainEqual({
|
|
143
|
+
label: "Requested by",
|
|
144
|
+
value: "Bob",
|
|
145
|
+
});
|
|
117
146
|
});
|
|
118
147
|
|
|
119
148
|
test("shows Requested by: Unknown when no requesterIdentifier", () => {
|
|
120
149
|
const payload = { ...toolApprovalPayload, requesterIdentifier: undefined };
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
unknown
|
|
125
|
-
>;
|
|
126
|
-
expect(data.title).toBe("bash");
|
|
127
|
-
const metadata = data.metadata as Array<{ label: string; value: string }>;
|
|
128
|
-
expect(metadata).toContainEqual({
|
|
150
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
151
|
+
expect(surface.data.title).toBe("bash");
|
|
152
|
+
expect(surface.data.metadata).toContainEqual({
|
|
129
153
|
label: "Requested by",
|
|
130
154
|
value: "Unknown",
|
|
131
155
|
});
|
|
132
156
|
|
|
133
157
|
// The plain-text fallback carries the same placeholder.
|
|
134
158
|
const noQuestion = { ...payload, questionText: undefined };
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
159
|
+
const fallback = fallbackBlock(
|
|
160
|
+
buildToolApprovalSeedContentBlocks(noQuestion)!,
|
|
161
|
+
);
|
|
162
|
+
expect(fallback.text).toContain(
|
|
138
163
|
"Approve tool: bash (requested by Unknown)",
|
|
139
164
|
);
|
|
140
165
|
});
|
|
141
166
|
|
|
142
167
|
test("card subtitle is tool-framed for both tool_approval and tool_grant_request", () => {
|
|
143
|
-
const
|
|
144
|
-
buildToolApprovalSeedContentBlocks(toolApprovalPayload)
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
expect(
|
|
151
|
-
expect(grantData.subtitle).toBe("Requires your approval to run");
|
|
168
|
+
const approvalSurface = surfaceBlock(
|
|
169
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
170
|
+
);
|
|
171
|
+
const grantSurface = surfaceBlock(
|
|
172
|
+
buildToolApprovalSeedContentBlocks(toolGrantPayload)!,
|
|
173
|
+
);
|
|
174
|
+
expect(approvalSurface.data.subtitle).toBe("Requires your approval to run");
|
|
175
|
+
expect(grantSurface.data.subtitle).toBe("Requires your approval to run");
|
|
152
176
|
});
|
|
153
177
|
|
|
154
178
|
test("includes requester and source channel in metadata", () => {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
expect(metadata).toContainEqual({
|
|
179
|
+
const surface = surfaceBlock(
|
|
180
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
181
|
+
);
|
|
182
|
+
expect(surface.data.metadata).toContainEqual({
|
|
183
|
+
label: "Requested by",
|
|
184
|
+
value: "Bob",
|
|
185
|
+
});
|
|
186
|
+
expect(surface.data.metadata).toContainEqual({
|
|
187
|
+
label: "Source",
|
|
188
|
+
value: "slack",
|
|
189
|
+
});
|
|
163
190
|
});
|
|
164
191
|
|
|
165
192
|
test("body includes questionText as blockquote", () => {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
193
|
+
const surface = surfaceBlock(
|
|
194
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
195
|
+
);
|
|
196
|
+
expect(surface.data.body).toContain("Approve tool: bash");
|
|
197
|
+
expect(surface.data.body).toContain("requested by Bob");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("Slack DM source reference renders a permalink and rich source row", () => {
|
|
201
|
+
const payload = {
|
|
202
|
+
...toolApprovalPayload,
|
|
203
|
+
sourceChatId: "D01XYZ",
|
|
204
|
+
sourceLink: {
|
|
205
|
+
webUrl: "https://slack.com/archives/D01XYZ/p1700000000000100",
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
209
|
+
expect(surface.data.body).toContain(
|
|
210
|
+
"[View message](https://slack.com/archives/D01XYZ/p1700000000000100)",
|
|
211
|
+
);
|
|
212
|
+
expect(surface.data.metadata).toContainEqual({
|
|
213
|
+
label: "Source",
|
|
214
|
+
value: "Slack — Direct message",
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("Slack channel source renders a #channel source row", () => {
|
|
219
|
+
const payload = {
|
|
220
|
+
...toolApprovalPayload,
|
|
221
|
+
sourceChatId: "C01ABC",
|
|
222
|
+
sourceLink: {
|
|
223
|
+
webUrl: "https://slack.com/archives/C01ABC/p1700000001000200",
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
227
|
+
expect(surface.data.body).toContain(
|
|
228
|
+
"[View message](https://slack.com/archives/C01ABC/p1700000001000200)",
|
|
229
|
+
);
|
|
230
|
+
expect(surface.data.metadata).toContainEqual({
|
|
231
|
+
label: "Source",
|
|
232
|
+
value: "Slack — #C01ABC",
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("Slack source falls back to requesterChatId and omits the link without one", () => {
|
|
237
|
+
const payload = {
|
|
238
|
+
...toolApprovalPayload,
|
|
239
|
+
requesterChatId: "D0OTHER",
|
|
240
|
+
};
|
|
241
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
242
|
+
expect(surface.data.body).not.toContain("[View message]");
|
|
243
|
+
expect(surface.data.metadata).toContainEqual({
|
|
244
|
+
label: "Source",
|
|
245
|
+
value: "Slack — Direct message",
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("non-Slack sources keep the plain channel row but still render a resolved link", () => {
|
|
250
|
+
const payload = {
|
|
251
|
+
...toolGrantPayload,
|
|
252
|
+
sourceChatId: "chat-123",
|
|
253
|
+
sourceLink: { webUrl: "https://example.com/messages/42" },
|
|
254
|
+
};
|
|
255
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
256
|
+
expect(surface.data.metadata).toContainEqual({
|
|
257
|
+
label: "Source",
|
|
258
|
+
value: "telegram",
|
|
259
|
+
});
|
|
260
|
+
expect(surface.data.body).toContain(
|
|
261
|
+
"[View message](https://example.com/messages/42)",
|
|
262
|
+
);
|
|
173
263
|
});
|
|
174
264
|
|
|
175
265
|
test("body shows fallback when no questionText", () => {
|
|
176
266
|
const payload = { ...toolApprovalPayload, questionText: undefined };
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
string,
|
|
180
|
-
unknown
|
|
181
|
-
>;
|
|
182
|
-
expect(data.body).toBe("No additional context available.");
|
|
267
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
268
|
+
expect(surface.data.body).toBe("No additional context available.");
|
|
183
269
|
});
|
|
184
270
|
|
|
185
271
|
test("surface block includes approve/reject actions when requestId present", () => {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
style: string;
|
|
192
|
-
}>;
|
|
193
|
-
expect(actions).toHaveLength(2);
|
|
194
|
-
expect(actions[0]).toEqual({
|
|
272
|
+
const surface = surfaceBlock(
|
|
273
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
274
|
+
);
|
|
275
|
+
expect(surface.actions).toHaveLength(2);
|
|
276
|
+
expect(surface.actions?.[0]).toEqual({
|
|
195
277
|
id: "apr:req-tool-456:approve_once",
|
|
196
278
|
label: "Approve",
|
|
197
279
|
style: "primary",
|
|
198
280
|
});
|
|
199
|
-
expect(actions[1]).toEqual({
|
|
281
|
+
expect(surface.actions?.[1]).toEqual({
|
|
200
282
|
id: "apr:req-tool-456:reject",
|
|
201
283
|
label: "Reject",
|
|
202
284
|
style: "destructive",
|
|
@@ -205,32 +287,33 @@ describe("buildToolApprovalSeedContentBlocks", () => {
|
|
|
205
287
|
|
|
206
288
|
test("surface block omits actions when requestId is missing", () => {
|
|
207
289
|
const payload = { ...toolApprovalPayload, requestId: undefined };
|
|
208
|
-
const
|
|
209
|
-
const surface = blocks[0] as Record<string, unknown>;
|
|
290
|
+
const surface = surfaceBlock(buildToolApprovalSeedContentBlocks(payload)!);
|
|
210
291
|
expect(surface.actions).toBeUndefined();
|
|
211
292
|
});
|
|
212
293
|
|
|
213
294
|
test("text fallback block contains questionText and request-code instruction", () => {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
expect(
|
|
218
|
-
expect(
|
|
219
|
-
expect(
|
|
295
|
+
const fallback = fallbackBlock(
|
|
296
|
+
buildToolApprovalSeedContentBlocks(toolApprovalPayload)!,
|
|
297
|
+
);
|
|
298
|
+
expect(fallback.text).toContain("Approve tool: bash");
|
|
299
|
+
expect(fallback.text).toContain("XYZ789");
|
|
300
|
+
expect(fallback.text).toContain("approve");
|
|
220
301
|
});
|
|
221
302
|
|
|
222
303
|
test("text fallback block omits request-code instruction when no requestCode", () => {
|
|
223
304
|
const payload = { ...toolApprovalPayload, requestCode: undefined };
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
expect(
|
|
305
|
+
const fallback = fallbackBlock(
|
|
306
|
+
buildToolApprovalSeedContentBlocks(payload)!,
|
|
307
|
+
);
|
|
308
|
+
expect(fallback.text).toContain("Approve tool: bash");
|
|
309
|
+
expect(fallback.text).not.toContain("XYZ789");
|
|
228
310
|
});
|
|
229
311
|
|
|
230
312
|
test("text fallback block uses tool-framed generic text when no questionText", () => {
|
|
231
313
|
const payload = { ...toolApprovalPayload, questionText: undefined };
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
314
|
+
const fallback = fallbackBlock(
|
|
315
|
+
buildToolApprovalSeedContentBlocks(payload)!,
|
|
316
|
+
);
|
|
317
|
+
expect(fallback.text).toContain("Approve tool: bash (requested by Bob)");
|
|
235
318
|
});
|
|
236
319
|
});
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
} from "../daemon/message-protocol.js";
|
|
18
18
|
import { INTERACTIVE_SURFACE_TYPES } from "../daemon/message-protocol.js";
|
|
19
19
|
import { uiShowTool } from "../tools/ui-surface/definitions.js";
|
|
20
|
+
import { uiShowTeachingError } from "../tools/ui-surface/surface-shape-docs.js";
|
|
20
21
|
|
|
21
22
|
function makeContext(sent: ServerMessage[] = []): SurfaceConversationContext {
|
|
22
23
|
return {
|
|
@@ -109,7 +110,9 @@ describe("choice and copy_block surface proxying", () => {
|
|
|
109
110
|
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
110
111
|
);
|
|
111
112
|
expect(showMessage).toBeDefined();
|
|
112
|
-
if (!showMessage || showMessage.surfaceType !== "choice")
|
|
113
|
+
if (!showMessage || showMessage.surfaceType !== "choice") {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
113
116
|
|
|
114
117
|
const data = showMessage.data as ChoiceSurfaceData;
|
|
115
118
|
expect(data.options.map((option) => option.id)).toEqual([
|
|
@@ -172,7 +175,9 @@ describe("choice and copy_block surface proxying", () => {
|
|
|
172
175
|
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
173
176
|
);
|
|
174
177
|
expect(showMessage).toBeDefined();
|
|
175
|
-
if (!showMessage || showMessage.surfaceType !== "copy_block")
|
|
178
|
+
if (!showMessage || showMessage.surfaceType !== "copy_block") {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
176
181
|
|
|
177
182
|
expect(showMessage.data as CopyBlockSurfaceData).toEqual({
|
|
178
183
|
text: "Paste this prompt into another assistant.",
|
|
@@ -205,7 +210,9 @@ describe("choice and copy_block surface proxying", () => {
|
|
|
205
210
|
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
206
211
|
);
|
|
207
212
|
expect(showMessage).toBeDefined();
|
|
208
|
-
if (!showMessage || showMessage.surfaceType !== "oauth_connect")
|
|
213
|
+
if (!showMessage || showMessage.surfaceType !== "oauth_connect") {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
209
216
|
|
|
210
217
|
expect(showMessage.data as OAuthConnectSurfaceData).toEqual({
|
|
211
218
|
providerKey: "google",
|
|
@@ -231,6 +238,140 @@ describe("choice and copy_block surface proxying", () => {
|
|
|
231
238
|
expect(sent).toHaveLength(0);
|
|
232
239
|
});
|
|
233
240
|
|
|
241
|
+
test("ui_show recovers copy_block data sent as a JSON-encoded string", async () => {
|
|
242
|
+
const sent: ServerMessage[] = [];
|
|
243
|
+
const ctx = makeContext(sent);
|
|
244
|
+
|
|
245
|
+
const result = await surfaceProxyResolver(ctx, "ui_show", {
|
|
246
|
+
surface_type: "copy_block",
|
|
247
|
+
data: JSON.stringify({ text: "bunx vellum doctor", label: "Command" }),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
expect(result.isError).toBe(false);
|
|
251
|
+
|
|
252
|
+
const showMessage = sent.find(
|
|
253
|
+
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
254
|
+
);
|
|
255
|
+
expect(showMessage).toBeDefined();
|
|
256
|
+
if (!showMessage || showMessage.surfaceType !== "copy_block") {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
expect(showMessage.data).toEqual({
|
|
260
|
+
text: "bunx vellum doctor",
|
|
261
|
+
label: "Command",
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("ui_show recovers copy_block fields placed at the top level of the input", async () => {
|
|
266
|
+
const sent: ServerMessage[] = [];
|
|
267
|
+
const ctx = makeContext(sent);
|
|
268
|
+
|
|
269
|
+
const result = await surfaceProxyResolver(ctx, "ui_show", {
|
|
270
|
+
surface_type: "copy_block",
|
|
271
|
+
text: "ssh user@example.com",
|
|
272
|
+
label: "SSH",
|
|
273
|
+
data: {},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
expect(result.isError).toBe(false);
|
|
277
|
+
|
|
278
|
+
const showMessage = sent.find(
|
|
279
|
+
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
280
|
+
);
|
|
281
|
+
expect(showMessage).toBeDefined();
|
|
282
|
+
if (!showMessage || showMessage.surfaceType !== "copy_block") {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
expect(showMessage.data).toEqual({
|
|
286
|
+
text: "ssh user@example.com",
|
|
287
|
+
label: "SSH",
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("ui_show rejects an unknown surface_type with the valid values", async () => {
|
|
292
|
+
const sent: ServerMessage[] = [];
|
|
293
|
+
const ctx = makeContext(sent);
|
|
294
|
+
|
|
295
|
+
const result = await surfaceProxyResolver(ctx, "ui_show", {
|
|
296
|
+
surface_type: "copyblock",
|
|
297
|
+
data: { text: "hello" },
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect(result.isError).toBe(true);
|
|
301
|
+
expect(result.content).toContain('"copyblock" is not a valid surface_type');
|
|
302
|
+
expect(result.content).toContain("copy_block");
|
|
303
|
+
expect(sent).toHaveLength(0);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("ui_show teaching guard accepts copy_block text at the top level of the input", () => {
|
|
307
|
+
const teachingError = uiShowTeachingError({
|
|
308
|
+
surface_type: "copy_block",
|
|
309
|
+
text: "bunx vellum doctor",
|
|
310
|
+
data: {},
|
|
311
|
+
});
|
|
312
|
+
expect(teachingError).toBeNull();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("uiShowTool.execute renders a copy_block whose text is at the top level", async () => {
|
|
316
|
+
const sent: ServerMessage[] = [];
|
|
317
|
+
const ctx = makeContext(sent);
|
|
318
|
+
const result = await uiShowTool.execute(
|
|
319
|
+
{ surface_type: "copy_block", text: "bunx vellum doctor", data: {} },
|
|
320
|
+
{
|
|
321
|
+
proxyToolResolver: (toolName: string, input: Record<string, unknown>) =>
|
|
322
|
+
surfaceProxyResolver(ctx, toolName, input),
|
|
323
|
+
} as unknown as Parameters<typeof uiShowTool.execute>[1],
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
expect(result.isError).toBe(false);
|
|
327
|
+
const showMessage = sent.find(
|
|
328
|
+
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
329
|
+
);
|
|
330
|
+
expect(showMessage).toBeDefined();
|
|
331
|
+
if (!showMessage || showMessage.surfaceType !== "copy_block") {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
expect(showMessage.data).toEqual({ text: "bunx vellum doctor" });
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("uiShowTool.execute renders a dynamic_page whose html is at the top level", async () => {
|
|
338
|
+
const sent: ServerMessage[] = [];
|
|
339
|
+
const ctx = makeContext(sent);
|
|
340
|
+
const result = await uiShowTool.execute(
|
|
341
|
+
{ surface_type: "dynamic_page", html: "<p>hello</p>", data: {} },
|
|
342
|
+
{
|
|
343
|
+
proxyToolResolver: (toolName: string, input: Record<string, unknown>) =>
|
|
344
|
+
surfaceProxyResolver(ctx, toolName, input),
|
|
345
|
+
} as unknown as Parameters<typeof uiShowTool.execute>[1],
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
expect(result.isError).toBe(false);
|
|
349
|
+
const showMessage = sent.find(
|
|
350
|
+
(msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
|
|
351
|
+
);
|
|
352
|
+
expect(showMessage).toBeDefined();
|
|
353
|
+
if (!showMessage || showMessage.surfaceType !== "dynamic_page") {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
expect(showMessage.data.html).toBe("<p>hello</p>");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("ui_show teaching guard accepts JSON-string copy_block data with text", () => {
|
|
360
|
+
const teachingError = uiShowTeachingError({
|
|
361
|
+
surface_type: "copy_block",
|
|
362
|
+
data: JSON.stringify({ text: "populated" }),
|
|
363
|
+
});
|
|
364
|
+
expect(teachingError).toBeNull();
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("ui_show teaching guard still flags copy_block without text", () => {
|
|
368
|
+
const teachingError = uiShowTeachingError({
|
|
369
|
+
surface_type: "copy_block",
|
|
370
|
+
data: { label: "Command" },
|
|
371
|
+
});
|
|
372
|
+
expect(teachingError).toContain("`data.text` must be a non-empty string");
|
|
373
|
+
});
|
|
374
|
+
|
|
234
375
|
test("choice completion summary names multi-select choices", () => {
|
|
235
376
|
expect(
|
|
236
377
|
buildCompletionSummary("choice", "submit", {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `memory_recalled` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server → client debug/telemetry gauge emitted once per turn after the
|
|
5
|
+
* memory subsystem recalls context. Carries the recall provider/model,
|
|
6
|
+
* per-tier hit counts, hybrid-search timing, and the token budget
|
|
7
|
+
* injected into the prompt, plus a `topCandidates` breakdown for
|
|
8
|
+
* debugging ranking. A side gauge, not part of the ordered timeline.
|
|
9
|
+
*
|
|
10
|
+
* Canonical wire-contract source. Daemon code imports the type
|
|
11
|
+
* directly from this file; external consumers import via
|
|
12
|
+
* `@vellumai/assistant-api`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
/** Why semantic recall fell back to a degraded path, if it did. */
|
|
18
|
+
export const MemoryRecalledDegradationSchema = z.object({
|
|
19
|
+
semanticUnavailable: z.boolean(),
|
|
20
|
+
reason: z.string(),
|
|
21
|
+
fallbackSources: z.array(z.string()),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type MemoryRecalledDegradation = z.infer<
|
|
25
|
+
typeof MemoryRecalledDegradationSchema
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
/** Per-candidate scoring breakdown surfaced for recall debugging. */
|
|
29
|
+
export const MemoryRecalledCandidateDebugSchema = z.object({
|
|
30
|
+
key: z.string(),
|
|
31
|
+
type: z.string(),
|
|
32
|
+
kind: z.string(),
|
|
33
|
+
finalScore: z.number(),
|
|
34
|
+
semantic: z.number(),
|
|
35
|
+
recency: z.number(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type MemoryRecalledCandidateDebug = z.infer<
|
|
39
|
+
typeof MemoryRecalledCandidateDebugSchema
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
export const MemoryRecalledEventSchema = z.object({
|
|
43
|
+
type: z.literal("memory_recalled"),
|
|
44
|
+
provider: z.string(),
|
|
45
|
+
model: z.string(),
|
|
46
|
+
degradation: MemoryRecalledDegradationSchema.optional(),
|
|
47
|
+
semanticHits: z.number(),
|
|
48
|
+
tier1Count: z.number(),
|
|
49
|
+
tier2Count: z.number(),
|
|
50
|
+
hybridSearchLatencyMs: z.number(),
|
|
51
|
+
sparseVectorUsed: z.boolean(),
|
|
52
|
+
mergedCount: z.number(),
|
|
53
|
+
selectedCount: z.number(),
|
|
54
|
+
injectedTokens: z.number(),
|
|
55
|
+
latencyMs: z.number(),
|
|
56
|
+
topCandidates: z.array(MemoryRecalledCandidateDebugSchema),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type MemoryRecalledEvent = z.infer<typeof MemoryRecalledEventSchema>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `memory_status` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server → client gauge reporting whether the memory subsystem is
|
|
5
|
+
* enabled and healthy for the current turn. When `degraded` is true,
|
|
6
|
+
* `degradation` / `reason` explain why semantic recall is unavailable
|
|
7
|
+
* so clients can surface a subtle notice. Shares the degradation shape
|
|
8
|
+
* with `memory_recalled`.
|
|
9
|
+
*
|
|
10
|
+
* Canonical wire-contract source. Daemon code imports the type
|
|
11
|
+
* directly from this file; external consumers import via
|
|
12
|
+
* `@vellumai/assistant-api`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
import { MemoryRecalledDegradationSchema } from "./memory-recalled.js";
|
|
18
|
+
|
|
19
|
+
export const MemoryStatusEventSchema = z.object({
|
|
20
|
+
type: z.literal("memory_status"),
|
|
21
|
+
enabled: z.boolean(),
|
|
22
|
+
degraded: z.boolean(),
|
|
23
|
+
degradation: MemoryRecalledDegradationSchema.optional(),
|
|
24
|
+
reason: z.string().optional(),
|
|
25
|
+
provider: z.string().optional(),
|
|
26
|
+
model: z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type MemoryStatusEvent = z.infer<typeof MemoryStatusEventSchema>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `service_group_update_complete` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server → client broadcast that a service-group update has finished.
|
|
5
|
+
* `installedVersion` is the version now running (may differ from the
|
|
6
|
+
* originally targeted version if the update rolled back), `success`
|
|
7
|
+
* flags whether the update applied or reverted, and
|
|
8
|
+
* `rolledBackToVersion` names the reverted-to version when it did.
|
|
9
|
+
*
|
|
10
|
+
* Canonical wire-contract source. Daemon code imports the type
|
|
11
|
+
* directly from this file; external consumers import via
|
|
12
|
+
* `@vellumai/assistant-api`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
export const ServiceGroupUpdateCompleteEventSchema = z.object({
|
|
18
|
+
type: z.literal("service_group_update_complete"),
|
|
19
|
+
/** The version that was installed (may differ from target if rolled back). */
|
|
20
|
+
installedVersion: z.string(),
|
|
21
|
+
/** Whether the update succeeded or rolled back. */
|
|
22
|
+
success: z.boolean(),
|
|
23
|
+
/** If rolled back, the version reverted to. */
|
|
24
|
+
rolledBackToVersion: z.string().optional(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type ServiceGroupUpdateCompleteEvent = z.infer<
|
|
28
|
+
typeof ServiceGroupUpdateCompleteEventSchema
|
|
29
|
+
>;
|