@vellumai/assistant 0.11.7-dev.202608310724.dde6a86 → 0.11.7-dev.202608311516.e0ee55e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +1 -1
- package/docs/architecture/security.md +1 -1
- package/node_modules/@vellumai/credential-storage/src/static-credentials.ts +43 -12
- package/openapi.yaml +155 -3
- package/package.json +1 -1
- package/src/__tests__/credential-record-retire.test.ts +256 -0
- package/src/__tests__/credential-record-write-through.test.ts +7 -0
- package/src/api/events/contact-form-closed.ts +32 -0
- package/src/api/events/contact-record-request.ts +63 -0
- package/src/api/events/contact-request.ts +10 -3
- package/src/api/index.ts +12 -0
- package/src/cli/__tests__/contacts-record-prompt-cli.test.ts +329 -0
- package/src/cli/commands/contacts.help.ts +173 -11
- package/src/cli/commands/contacts.ts +343 -4
- package/src/config/bundled-skills/contacts/SKILL.md +60 -17
- package/src/runtime/migrations/vbundle-metadata-merge.ts +4 -7
- package/src/runtime/routes/__tests__/contact-record-prompt-route.test.ts +303 -0
- package/src/runtime/routes/contact-prompt-routes.ts +346 -31
- package/src/tools/credentials/metadata-store.ts +109 -10
- package/src/util/contact-form-timeouts.ts +48 -0
package/ARCHITECTURE.md
CHANGED
|
@@ -2066,7 +2066,7 @@ Connected channels are resolved at signal emission time: vellum is always includ
|
|
|
2066
2066
|
| ---------------------------------------- | ------------------------------------------------------ | ----------------------------------- | ---------------------------------- | ------------------------------------------------------- |
|
|
2067
2067
|
| API key | CES / encrypted file store | Encrypted binary | CES API / `secure-keys.ts` | Permanent |
|
|
2068
2068
|
| Credential secrets | CES / encrypted file store | Encrypted binary | `secure-keys.ts` wrapper | Permanent (until deleted via tool) |
|
|
2069
|
-
| Credential
|
|
2069
|
+
| Credential records | CES `<cesDataRoot>/metadata.json` | JSON | CES RPC/HTTP + atomic file write | Permanent (until deleted via tool) |
|
|
2070
2070
|
| Integration OAuth tokens | CES / encrypted file store (via `secure-keys.ts`) | Encrypted binary | `TokenManager` auto-refresh | Until disconnected or revoked |
|
|
2071
2071
|
| User preferences | UserDefaults | plist | Foundation | Permanent |
|
|
2072
2072
|
| Session logs | `~/Library/.../logs/session-*.json` | JSON per session | Swift Codable | Unbounded |
|
|
@@ -229,7 +229,7 @@ User messages are scanned at ingress (`secret-ingress.ts`) against known credent
|
|
|
229
229
|
| Component | Location | What it stores |
|
|
230
230
|
| ------------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
231
231
|
| Secret values | CES credential store or encrypted file store | Encrypted credential values keyed as `credential/{service}/{field}`. Stored via CES RPC (primary), CES HTTP (containerized), or encrypted file store (fallback). |
|
|
232
|
-
| Credential
|
|
232
|
+
| Credential records | CES `<cesDataRoot>/metadata.json` | Service, field, alias, policy (`allowedTools`, `allowedDomains`, `injectionTemplates`), timestamps. Served over CES RPC/HTTP. |
|
|
233
233
|
| Config | `$VELLUM_WORKSPACE_DIR/config.*` | `secretDetection` settings: enabled, blockIngress, allowOneTimeSend, blockTokenShapedMessages (default `true` — whole-message token-shape heuristic) |
|
|
234
234
|
|
|
235
235
|
### Key Files
|
|
@@ -216,6 +216,8 @@ export interface StaticCredentialPolicyInput {
|
|
|
216
216
|
*/
|
|
217
217
|
export class StaticCredentialMetadataStore {
|
|
218
218
|
private metadataPath: string;
|
|
219
|
+
/** When set, reads and writes stay in process and do not touch the file. */
|
|
220
|
+
private memory: MetadataFile | null = null;
|
|
219
221
|
|
|
220
222
|
constructor(metadataPath: string) {
|
|
221
223
|
this.metadataPath = metadataPath;
|
|
@@ -224,6 +226,17 @@ export class StaticCredentialMetadataStore {
|
|
|
224
226
|
/** Update the metadata file path (primarily for testing). */
|
|
225
227
|
setPath(path: string): void {
|
|
226
228
|
this.metadataPath = path;
|
|
229
|
+
this.memory = null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Switch to an in-memory backing filled with `records`.
|
|
234
|
+
*/
|
|
235
|
+
useMemory(records: StaticCredentialRecord[] = []): void {
|
|
236
|
+
this.memory = {
|
|
237
|
+
version: CURRENT_VERSION,
|
|
238
|
+
credentials: records.map((record) => ({ ...record })),
|
|
239
|
+
};
|
|
227
240
|
}
|
|
228
241
|
|
|
229
242
|
/** Get the current metadata file path. */
|
|
@@ -231,13 +244,28 @@ export class StaticCredentialMetadataStore {
|
|
|
231
244
|
return this.metadataPath;
|
|
232
245
|
}
|
|
233
246
|
|
|
247
|
+
private load(): LoadResult {
|
|
248
|
+
if (this.memory) {
|
|
249
|
+
return this.memory;
|
|
250
|
+
}
|
|
251
|
+
return loadFile(this.metadataPath, saveFile);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private persist(data: MetadataFile): void {
|
|
255
|
+
if (this.memory) {
|
|
256
|
+
this.memory = data;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
saveFile(data, this.metadataPath);
|
|
260
|
+
}
|
|
261
|
+
|
|
234
262
|
/**
|
|
235
263
|
* Throws if the metadata file has an unrecognized version.
|
|
236
264
|
* Call this before performing irreversible credential store operations
|
|
237
265
|
* so the operation fails cleanly before any side effects.
|
|
238
266
|
*/
|
|
239
267
|
assertWritable(): void {
|
|
240
|
-
const result =
|
|
268
|
+
const result = this.load();
|
|
241
269
|
if (isUnknownVersion(result)) {
|
|
242
270
|
throw new Error(
|
|
243
271
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -254,7 +282,7 @@ export class StaticCredentialMetadataStore {
|
|
|
254
282
|
field: string,
|
|
255
283
|
policy?: StaticCredentialPolicyInput
|
|
256
284
|
): StaticCredentialRecord {
|
|
257
|
-
const result =
|
|
285
|
+
const result = this.load();
|
|
258
286
|
if (isUnknownVersion(result)) {
|
|
259
287
|
throw new Error(
|
|
260
288
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -268,12 +296,15 @@ export class StaticCredentialMetadataStore {
|
|
|
268
296
|
);
|
|
269
297
|
|
|
270
298
|
if (existing) {
|
|
271
|
-
if (policy?.allowedTools !== undefined)
|
|
299
|
+
if (policy?.allowedTools !== undefined) {
|
|
272
300
|
existing.allowedTools = policy.allowedTools;
|
|
273
|
-
|
|
301
|
+
}
|
|
302
|
+
if (policy?.allowedDomains !== undefined) {
|
|
274
303
|
existing.allowedDomains = policy.allowedDomains;
|
|
275
|
-
|
|
304
|
+
}
|
|
305
|
+
if (policy?.usageDescription !== undefined) {
|
|
276
306
|
existing.usageDescription = policy.usageDescription;
|
|
307
|
+
}
|
|
277
308
|
if (policy?.alias !== undefined) {
|
|
278
309
|
if (policy.alias == null) {
|
|
279
310
|
delete existing.alias;
|
|
@@ -289,7 +320,7 @@ export class StaticCredentialMetadataStore {
|
|
|
289
320
|
}
|
|
290
321
|
}
|
|
291
322
|
existing.updatedAt = now;
|
|
292
|
-
|
|
323
|
+
this.persist(data);
|
|
293
324
|
return existing;
|
|
294
325
|
}
|
|
295
326
|
|
|
@@ -307,7 +338,7 @@ export class StaticCredentialMetadataStore {
|
|
|
307
338
|
};
|
|
308
339
|
|
|
309
340
|
data.credentials.push(record);
|
|
310
|
-
|
|
341
|
+
this.persist(data);
|
|
311
342
|
return record;
|
|
312
343
|
}
|
|
313
344
|
|
|
@@ -318,7 +349,7 @@ export class StaticCredentialMetadataStore {
|
|
|
318
349
|
service: string,
|
|
319
350
|
field: string
|
|
320
351
|
): StaticCredentialRecord | undefined {
|
|
321
|
-
const result =
|
|
352
|
+
const result = this.load();
|
|
322
353
|
if (isUnknownVersion(result)) return undefined;
|
|
323
354
|
return result.credentials.find(
|
|
324
355
|
(c) => c.service === service && c.field === field
|
|
@@ -329,7 +360,7 @@ export class StaticCredentialMetadataStore {
|
|
|
329
360
|
* Get metadata for a credential by its opaque ID.
|
|
330
361
|
*/
|
|
331
362
|
getById(credentialId: string): StaticCredentialRecord | undefined {
|
|
332
|
-
const result =
|
|
363
|
+
const result = this.load();
|
|
333
364
|
if (isUnknownVersion(result)) return undefined;
|
|
334
365
|
return result.credentials.find((c) => c.credentialId === credentialId);
|
|
335
366
|
}
|
|
@@ -338,7 +369,7 @@ export class StaticCredentialMetadataStore {
|
|
|
338
369
|
* List all credential metadata records.
|
|
339
370
|
*/
|
|
340
371
|
list(): StaticCredentialRecord[] {
|
|
341
|
-
const result =
|
|
372
|
+
const result = this.load();
|
|
342
373
|
if (isUnknownVersion(result)) return [];
|
|
343
374
|
return result.credentials;
|
|
344
375
|
}
|
|
@@ -347,7 +378,7 @@ export class StaticCredentialMetadataStore {
|
|
|
347
378
|
* Delete metadata for a credential.
|
|
348
379
|
*/
|
|
349
380
|
delete(service: string, field: string): boolean {
|
|
350
|
-
const result =
|
|
381
|
+
const result = this.load();
|
|
351
382
|
if (isUnknownVersion(result)) {
|
|
352
383
|
throw new Error(
|
|
353
384
|
"Credential metadata file has an unrecognized version; refusing to mutate to avoid data loss"
|
|
@@ -359,7 +390,7 @@ export class StaticCredentialMetadataStore {
|
|
|
359
390
|
);
|
|
360
391
|
if (idx === -1) return false;
|
|
361
392
|
data.credentials.splice(idx, 1);
|
|
362
|
-
|
|
393
|
+
this.persist(data);
|
|
363
394
|
return true;
|
|
364
395
|
}
|
|
365
396
|
}
|
package/openapi.yaml
CHANGED
|
@@ -5559,6 +5559,49 @@ paths:
|
|
|
5559
5559
|
- runs
|
|
5560
5560
|
- nextCursor
|
|
5561
5561
|
additionalProperties: false
|
|
5562
|
+
/v1/contact_prompt_claim:
|
|
5563
|
+
post:
|
|
5564
|
+
operationId: contact_prompt_claim_post
|
|
5565
|
+
summary: Claim a pending contact form for one submission
|
|
5566
|
+
description:
|
|
5567
|
+
Marks a pending form as answered so a second client submitting the same form writes nothing. Returns
|
|
5568
|
+
claimed=false with reason 'already_claimed' when somebody got there first, or 'unknown' when no such form is
|
|
5569
|
+
pending. A granted claim carries the window its write has to report back in.
|
|
5570
|
+
tags:
|
|
5571
|
+
- contacts
|
|
5572
|
+
requestBody:
|
|
5573
|
+
required: true
|
|
5574
|
+
content:
|
|
5575
|
+
application/json:
|
|
5576
|
+
schema:
|
|
5577
|
+
type: object
|
|
5578
|
+
properties:
|
|
5579
|
+
requestId:
|
|
5580
|
+
type: string
|
|
5581
|
+
description: The pending contact_request id.
|
|
5582
|
+
required:
|
|
5583
|
+
- requestId
|
|
5584
|
+
responses:
|
|
5585
|
+
"200":
|
|
5586
|
+
description: Successful response
|
|
5587
|
+
content:
|
|
5588
|
+
application/json:
|
|
5589
|
+
schema:
|
|
5590
|
+
type: object
|
|
5591
|
+
properties:
|
|
5592
|
+
claimed:
|
|
5593
|
+
type: boolean
|
|
5594
|
+
reason:
|
|
5595
|
+
type: string
|
|
5596
|
+
enum:
|
|
5597
|
+
- already_claimed
|
|
5598
|
+
- unknown
|
|
5599
|
+
settleMs:
|
|
5600
|
+
description: How long a granted claim has to report its write back before the waiting call gives up.
|
|
5601
|
+
type: number
|
|
5602
|
+
required:
|
|
5603
|
+
- claimed
|
|
5604
|
+
additionalProperties: false
|
|
5562
5605
|
/v1/contact_prompt_flags:
|
|
5563
5606
|
post:
|
|
5564
5607
|
operationId: contact_prompt_flags_post
|
|
@@ -6482,7 +6525,7 @@ paths:
|
|
|
6482
6525
|
summary: Prompt user to register a contact channel
|
|
6483
6526
|
description:
|
|
6484
6527
|
Broadcasts a contact_request to connected clients, waits for the user to submit an address via the gateway.
|
|
6485
|
-
The gateway owns the contact write and
|
|
6528
|
+
The gateway owns the contact write and reports it back via resolve_contact_prompt.
|
|
6486
6529
|
tags:
|
|
6487
6530
|
- contacts
|
|
6488
6531
|
requestBody:
|
|
@@ -6516,8 +6559,17 @@ paths:
|
|
|
6516
6559
|
- trusted-contact
|
|
6517
6560
|
- unknown
|
|
6518
6561
|
verify:
|
|
6519
|
-
description:
|
|
6562
|
+
description:
|
|
6563
|
+
Pre-check the form's 'mark verified' box. The guardian's answer on submit decides the attest, so an
|
|
6564
|
+
unchecked box leaves the channel unverified.
|
|
6520
6565
|
type: boolean
|
|
6566
|
+
timeoutMs:
|
|
6567
|
+
description:
|
|
6568
|
+
How long to hold the form open (ms). The caller waits slightly longer than this, so the form closing is
|
|
6569
|
+
what ends the wait. Defaults to 300000.
|
|
6570
|
+
type: integer
|
|
6571
|
+
exclusiveMinimum: 0
|
|
6572
|
+
maximum: 3600000
|
|
6521
6573
|
responses:
|
|
6522
6574
|
"200":
|
|
6523
6575
|
description: Successful response
|
|
@@ -6538,6 +6590,106 @@ paths:
|
|
|
6538
6590
|
type: string
|
|
6539
6591
|
address:
|
|
6540
6592
|
type: string
|
|
6593
|
+
verified:
|
|
6594
|
+
type: boolean
|
|
6595
|
+
required:
|
|
6596
|
+
- ok
|
|
6597
|
+
additionalProperties: false
|
|
6598
|
+
/v1/contacts/record-prompt:
|
|
6599
|
+
post:
|
|
6600
|
+
operationId: contacts_recordprompt_post
|
|
6601
|
+
summary: Ask the guardian to confirm a contact record write
|
|
6602
|
+
description:
|
|
6603
|
+
Broadcasts a contact_record_request to connected clients and waits for the guardian to submit the form. The
|
|
6604
|
+
gateway owns the write and reports it back via resolve_contact_prompt. Nothing is written if nobody answers.
|
|
6605
|
+
tags:
|
|
6606
|
+
- contacts
|
|
6607
|
+
requestBody:
|
|
6608
|
+
required: true
|
|
6609
|
+
content:
|
|
6610
|
+
application/json:
|
|
6611
|
+
schema:
|
|
6612
|
+
type: object
|
|
6613
|
+
properties:
|
|
6614
|
+
operation:
|
|
6615
|
+
type: string
|
|
6616
|
+
enum:
|
|
6617
|
+
- create
|
|
6618
|
+
- update
|
|
6619
|
+
- delete
|
|
6620
|
+
description: Which record write the guardian is being asked to confirm.
|
|
6621
|
+
contactId:
|
|
6622
|
+
description: Target contact. Required for update and delete.
|
|
6623
|
+
type: string
|
|
6624
|
+
currentDisplayName:
|
|
6625
|
+
description:
|
|
6626
|
+
The target's current name, resolved by the caller, so the form can show what is changing. Gateway-owned
|
|
6627
|
+
facts are not read here.
|
|
6628
|
+
type: string
|
|
6629
|
+
currentNotes:
|
|
6630
|
+
description:
|
|
6631
|
+
The target's current notes, resolved by the caller. The form submits a field only when it differs from what
|
|
6632
|
+
is stored.
|
|
6633
|
+
type: string
|
|
6634
|
+
channels:
|
|
6635
|
+
description:
|
|
6636
|
+
The target's channels, resolved by the caller, so a delete confirmation can identify the contact and show
|
|
6637
|
+
what access is about to be lost.
|
|
6638
|
+
type: array
|
|
6639
|
+
items:
|
|
6640
|
+
type: object
|
|
6641
|
+
properties:
|
|
6642
|
+
type:
|
|
6643
|
+
type: string
|
|
6644
|
+
address:
|
|
6645
|
+
type: string
|
|
6646
|
+
required:
|
|
6647
|
+
- type
|
|
6648
|
+
- address
|
|
6649
|
+
displayName:
|
|
6650
|
+
description: Proposed name, prefilled into the form. The guardian can edit it.
|
|
6651
|
+
type: string
|
|
6652
|
+
notes:
|
|
6653
|
+
description: Proposed notes, prefilled into the form. The guardian can edit them.
|
|
6654
|
+
type: string
|
|
6655
|
+
notesProposed:
|
|
6656
|
+
description:
|
|
6657
|
+
Whether the caller asked for these notes explicitly, so the form submits them even when they match what is
|
|
6658
|
+
stored.
|
|
6659
|
+
type: boolean
|
|
6660
|
+
label:
|
|
6661
|
+
description: Display label shown in the form.
|
|
6662
|
+
type: string
|
|
6663
|
+
description:
|
|
6664
|
+
description: Longer description shown in the form.
|
|
6665
|
+
type: string
|
|
6666
|
+
timeoutMs:
|
|
6667
|
+
description:
|
|
6668
|
+
How long to hold the form open (ms). The caller waits slightly longer than this, so the form closing is
|
|
6669
|
+
what ends the wait. Defaults to 300000.
|
|
6670
|
+
type: integer
|
|
6671
|
+
exclusiveMinimum: 0
|
|
6672
|
+
maximum: 3600000
|
|
6673
|
+
required:
|
|
6674
|
+
- operation
|
|
6675
|
+
responses:
|
|
6676
|
+
"200":
|
|
6677
|
+
description: Successful response
|
|
6678
|
+
content:
|
|
6679
|
+
application/json:
|
|
6680
|
+
schema:
|
|
6681
|
+
type: object
|
|
6682
|
+
properties:
|
|
6683
|
+
ok:
|
|
6684
|
+
type: boolean
|
|
6685
|
+
error:
|
|
6686
|
+
type: string
|
|
6687
|
+
contactId:
|
|
6688
|
+
type: string
|
|
6689
|
+
notesSaved:
|
|
6690
|
+
type: boolean
|
|
6691
|
+
nothingWritten:
|
|
6692
|
+
type: boolean
|
|
6541
6693
|
required:
|
|
6542
6694
|
- ok
|
|
6543
6695
|
additionalProperties: false
|
|
@@ -26026,7 +26178,7 @@ paths:
|
|
|
26026
26178
|
post:
|
|
26027
26179
|
operationId: resolve_contact_prompt_post
|
|
26028
26180
|
summary: "Gateway callback: resolve a pending contact prompt"
|
|
26029
|
-
description: Called by the gateway after it writes the contact and channel. Unblocks the waiting contacts/prompt
|
|
26181
|
+
description: Called by the gateway after it writes the contact and channel. Unblocks the waiting contacts/prompt call.
|
|
26030
26182
|
tags:
|
|
26031
26183
|
- contacts
|
|
26032
26184
|
responses:
|
package/package.json
CHANGED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { credentialKey } from "@vellumai/credential-storage";
|
|
6
|
+
import type { CredentialRecord } from "@vellumai/service-contracts/credential-rpc";
|
|
7
|
+
|
|
8
|
+
import type { CredentialRecordBackend } from "../security/ces-rpc-record-backend.js";
|
|
9
|
+
import {
|
|
10
|
+
_ensureCesRecordsLoaded,
|
|
11
|
+
_setMetadataPath,
|
|
12
|
+
getCredentialMetadata,
|
|
13
|
+
setCredentialRecordBackend,
|
|
14
|
+
upsertCredentialMetadata,
|
|
15
|
+
} from "../tools/credentials/metadata-store.js";
|
|
16
|
+
import { getDataDir } from "../util/platform.js";
|
|
17
|
+
|
|
18
|
+
function leftoverPath(): string {
|
|
19
|
+
return join(getDataDir(), "credentials", "metadata.json");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function writeLeftover(record: CredentialRecord): void {
|
|
23
|
+
const path = leftoverPath();
|
|
24
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
25
|
+
writeFileSync(
|
|
26
|
+
path,
|
|
27
|
+
JSON.stringify({
|
|
28
|
+
version: 5,
|
|
29
|
+
credentials: [record],
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function leftoverContents(): string {
|
|
35
|
+
return readFileSync(leftoverPath(), "utf-8");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function makeBackend(): CredentialRecordBackend & {
|
|
39
|
+
store: Map<string, CredentialRecord>;
|
|
40
|
+
bulkSetCalls: number;
|
|
41
|
+
listCalls: number;
|
|
42
|
+
} {
|
|
43
|
+
const store = new Map<string, CredentialRecord>();
|
|
44
|
+
const backend: CredentialRecordBackend & {
|
|
45
|
+
store: Map<string, CredentialRecord>;
|
|
46
|
+
bulkSetCalls: number;
|
|
47
|
+
listCalls: number;
|
|
48
|
+
} = {
|
|
49
|
+
store,
|
|
50
|
+
bulkSetCalls: 0,
|
|
51
|
+
listCalls: 0,
|
|
52
|
+
isAvailable: () => true,
|
|
53
|
+
get: async (account) => store.get(account),
|
|
54
|
+
set: async (account, record) => {
|
|
55
|
+
store.set(account, record);
|
|
56
|
+
return true;
|
|
57
|
+
},
|
|
58
|
+
delete: async (account) => {
|
|
59
|
+
if (!store.has(account)) {
|
|
60
|
+
return "not-found";
|
|
61
|
+
}
|
|
62
|
+
store.delete(account);
|
|
63
|
+
return "deleted";
|
|
64
|
+
},
|
|
65
|
+
list: async () => {
|
|
66
|
+
backend.listCalls += 1;
|
|
67
|
+
return [...store.entries()].map(([account, record]) => ({
|
|
68
|
+
account,
|
|
69
|
+
record,
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
bulkSet: async (records) => {
|
|
73
|
+
backend.bulkSetCalls += 1;
|
|
74
|
+
for (const { account, record } of records) {
|
|
75
|
+
store.set(account, record);
|
|
76
|
+
}
|
|
77
|
+
return records.map((entry) => ({ account: entry.account, ok: true }));
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return backend;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe("CES credential record cache", () => {
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
setCredentialRecordBackend(undefined);
|
|
86
|
+
_setMetadataPath(null);
|
|
87
|
+
const leftover = leftoverPath();
|
|
88
|
+
if (existsSync(leftover)) {
|
|
89
|
+
rmSync(leftover, { force: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
afterEach(() => {
|
|
94
|
+
setCredentialRecordBackend(undefined);
|
|
95
|
+
_setMetadataPath(null);
|
|
96
|
+
const leftover = leftoverPath();
|
|
97
|
+
if (existsSync(leftover)) {
|
|
98
|
+
rmSync(leftover, { force: true });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("first catalog read lazy-loads CES records into the in-process cache", async () => {
|
|
103
|
+
const backend = makeBackend();
|
|
104
|
+
const record: CredentialRecord = {
|
|
105
|
+
credentialId: "cred-1",
|
|
106
|
+
service: "github",
|
|
107
|
+
field: "token",
|
|
108
|
+
allowedTools: ["bash"],
|
|
109
|
+
allowedDomains: [],
|
|
110
|
+
createdAt: 1,
|
|
111
|
+
updatedAt: 2,
|
|
112
|
+
};
|
|
113
|
+
backend.store.set(credentialKey("github", "token"), record);
|
|
114
|
+
setCredentialRecordBackend(backend);
|
|
115
|
+
expect(backend.listCalls).toBe(0);
|
|
116
|
+
|
|
117
|
+
getCredentialMetadata("github", "token");
|
|
118
|
+
await _ensureCesRecordsLoaded();
|
|
119
|
+
expect(backend.listCalls).toBe(1);
|
|
120
|
+
|
|
121
|
+
expect(getCredentialMetadata("github", "token")?.credentialId).toBe(
|
|
122
|
+
"cred-1",
|
|
123
|
+
);
|
|
124
|
+
expect(getCredentialMetadata("github", "token")?.allowedTools).toEqual([
|
|
125
|
+
"bash",
|
|
126
|
+
]);
|
|
127
|
+
getCredentialMetadata("github", "token");
|
|
128
|
+
await _ensureCesRecordsLoaded();
|
|
129
|
+
expect(backend.listCalls).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("lazy load leaves leftover metadata.json in place and ignores it", async () => {
|
|
133
|
+
const leftoverRecord: CredentialRecord = {
|
|
134
|
+
credentialId: "cred-leftover",
|
|
135
|
+
service: "github",
|
|
136
|
+
field: "token",
|
|
137
|
+
allowedTools: ["bash"],
|
|
138
|
+
allowedDomains: ["github.com"],
|
|
139
|
+
createdAt: 1,
|
|
140
|
+
updatedAt: 2,
|
|
141
|
+
};
|
|
142
|
+
writeLeftover(leftoverRecord);
|
|
143
|
+
const before = leftoverContents();
|
|
144
|
+
|
|
145
|
+
const backend = makeBackend();
|
|
146
|
+
backend.store.set(credentialKey("github", "token"), leftoverRecord);
|
|
147
|
+
setCredentialRecordBackend(backend);
|
|
148
|
+
|
|
149
|
+
getCredentialMetadata("github", "token");
|
|
150
|
+
await _ensureCesRecordsLoaded();
|
|
151
|
+
|
|
152
|
+
expect(existsSync(leftoverPath())).toBe(true);
|
|
153
|
+
expect(leftoverContents()).toBe(before);
|
|
154
|
+
expect(backend.bulkSetCalls).toBe(0);
|
|
155
|
+
expect(getCredentialMetadata("github", "token")?.allowedTools).toEqual([
|
|
156
|
+
"bash",
|
|
157
|
+
]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("lazy load ignores leftover metadata.json when CES list fails", async () => {
|
|
161
|
+
const leftoverRecord: CredentialRecord = {
|
|
162
|
+
credentialId: "cred-keep",
|
|
163
|
+
service: "slack_channel",
|
|
164
|
+
field: "bot_token",
|
|
165
|
+
allowedTools: ["bash"],
|
|
166
|
+
allowedDomains: [],
|
|
167
|
+
createdAt: 1,
|
|
168
|
+
updatedAt: 2,
|
|
169
|
+
};
|
|
170
|
+
writeLeftover(leftoverRecord);
|
|
171
|
+
|
|
172
|
+
const backend = makeBackend();
|
|
173
|
+
backend.list = async () => null;
|
|
174
|
+
setCredentialRecordBackend(backend);
|
|
175
|
+
|
|
176
|
+
getCredentialMetadata("slack_channel", "bot_token");
|
|
177
|
+
await _ensureCesRecordsLoaded();
|
|
178
|
+
|
|
179
|
+
expect(existsSync(leftoverPath())).toBe(true);
|
|
180
|
+
expect(backend.bulkSetCalls).toBe(0);
|
|
181
|
+
expect(
|
|
182
|
+
getCredentialMetadata("slack_channel", "bot_token"),
|
|
183
|
+
).toBeUndefined();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("lazy load ignores leftover metadata.json when CES has no leftover accounts", async () => {
|
|
187
|
+
const leftoverRecord: CredentialRecord = {
|
|
188
|
+
credentialId: "cred-missing",
|
|
189
|
+
service: "github",
|
|
190
|
+
field: "token",
|
|
191
|
+
allowedTools: ["bash"],
|
|
192
|
+
allowedDomains: [],
|
|
193
|
+
createdAt: 1,
|
|
194
|
+
updatedAt: 2,
|
|
195
|
+
};
|
|
196
|
+
writeLeftover(leftoverRecord);
|
|
197
|
+
|
|
198
|
+
const backend = makeBackend();
|
|
199
|
+
setCredentialRecordBackend(backend);
|
|
200
|
+
|
|
201
|
+
getCredentialMetadata("github", "token");
|
|
202
|
+
await _ensureCesRecordsLoaded();
|
|
203
|
+
|
|
204
|
+
expect(existsSync(leftoverPath())).toBe(true);
|
|
205
|
+
expect(backend.store.size).toBe(0);
|
|
206
|
+
expect(backend.bulkSetCalls).toBe(0);
|
|
207
|
+
expect(getCredentialMetadata("github", "token")).toBeUndefined();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("lazy load does not throw when CES isAvailable throws", async () => {
|
|
211
|
+
const backend = makeBackend();
|
|
212
|
+
backend.isAvailable = () => {
|
|
213
|
+
throw new Error("CES boom");
|
|
214
|
+
};
|
|
215
|
+
setCredentialRecordBackend(backend);
|
|
216
|
+
|
|
217
|
+
getCredentialMetadata("github", "token");
|
|
218
|
+
await _ensureCesRecordsLoaded();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("upsert write-throughs to CES without updating leftover metadata.json", async () => {
|
|
222
|
+
const leftoverRecord: CredentialRecord = {
|
|
223
|
+
credentialId: "cred-leftover",
|
|
224
|
+
service: "github",
|
|
225
|
+
field: "token",
|
|
226
|
+
allowedTools: ["bash"],
|
|
227
|
+
allowedDomains: [],
|
|
228
|
+
createdAt: 1,
|
|
229
|
+
updatedAt: 2,
|
|
230
|
+
};
|
|
231
|
+
writeLeftover(leftoverRecord);
|
|
232
|
+
const leftoverBefore = leftoverContents();
|
|
233
|
+
|
|
234
|
+
const backend = makeBackend();
|
|
235
|
+
backend.store.set(credentialKey("github", "token"), leftoverRecord);
|
|
236
|
+
setCredentialRecordBackend(backend);
|
|
237
|
+
getCredentialMetadata("github", "token");
|
|
238
|
+
await _ensureCesRecordsLoaded();
|
|
239
|
+
expect(existsSync(leftoverPath())).toBe(true);
|
|
240
|
+
|
|
241
|
+
const created = upsertCredentialMetadata("slack_channel", "bot_token", {
|
|
242
|
+
allowedTools: ["bash"],
|
|
243
|
+
});
|
|
244
|
+
await Promise.resolve();
|
|
245
|
+
|
|
246
|
+
expect(existsSync(leftoverPath())).toBe(true);
|
|
247
|
+
expect(leftoverContents()).toBe(leftoverBefore);
|
|
248
|
+
expect(
|
|
249
|
+
backend.store.get(credentialKey("slack_channel", "bot_token"))
|
|
250
|
+
?.credentialId,
|
|
251
|
+
).toBe(created.credentialId);
|
|
252
|
+
expect(getCredentialMetadata("slack_channel", "bot_token")?.allowedTools).toEqual(
|
|
253
|
+
["bash"],
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, rmSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
1
3
|
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
4
|
|
|
3
5
|
import { credentialKey } from "@vellumai/credential-storage";
|
|
@@ -9,6 +11,7 @@ import {
|
|
|
9
11
|
setCredentialRecordBackend,
|
|
10
12
|
upsertCredentialMetadata,
|
|
11
13
|
} from "../tools/credentials/metadata-store.js";
|
|
14
|
+
import { getDataDir } from "../util/platform.js";
|
|
12
15
|
|
|
13
16
|
function makeBackend(): CredentialRecordBackend & {
|
|
14
17
|
store: Map<string, CredentialRecord>;
|
|
@@ -44,6 +47,10 @@ describe("CES credential record write-through", () => {
|
|
|
44
47
|
afterEach(() => {
|
|
45
48
|
setCredentialRecordBackend(undefined);
|
|
46
49
|
_setMetadataPath(null);
|
|
50
|
+
const leftover = join(getDataDir(), "credentials", "metadata.json");
|
|
51
|
+
if (existsSync(leftover)) {
|
|
52
|
+
rmSync(leftover, { force: true });
|
|
53
|
+
}
|
|
47
54
|
});
|
|
48
55
|
|
|
49
56
|
test("upsert write-through updates the CES backend", async () => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contact_form_closed` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Tells every connected client that a contact form is over, so the card comes
|
|
5
|
+
* down instead of sitting there offering to submit an answer the gateway will
|
|
6
|
+
* now refuse.
|
|
7
|
+
*
|
|
8
|
+
* Both contact forms are workspace-global, broadcast without a conversation,
|
|
9
|
+
* which is why this is its own event rather than `interaction_resolved`: that
|
|
10
|
+
* one is conversation-scoped on the wire and is deliberately not broadcast for
|
|
11
|
+
* a conversation-less interaction.
|
|
12
|
+
*
|
|
13
|
+
* Canonical wire-contract source. Daemon code imports the type directly from
|
|
14
|
+
* this file; external consumers import via `@vellumai/assistant-api`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
export const ContactFormClosedEventSchema = z.object({
|
|
20
|
+
type: z.literal("contact_form_closed"),
|
|
21
|
+
requestId: z.string(),
|
|
22
|
+
/**
|
|
23
|
+
* Why it closed. Every client saw the form, so every client needs to know:
|
|
24
|
+
* "answered" and "cancelled" retire the card on the clients that did not
|
|
25
|
+
* answer it, and "timed_out" retires it on all of them.
|
|
26
|
+
*/
|
|
27
|
+
reason: z.enum(["answered", "cancelled", "timed_out"]),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type ContactFormClosedEvent = z.infer<
|
|
31
|
+
typeof ContactFormClosedEventSchema
|
|
32
|
+
>;
|