@vellumai/assistant 0.11.7-dev.202608311418.27c51fa → 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/openapi.yaml +155 -3
- package/package.json +1 -1
- 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/routes/__tests__/contact-record-prompt-route.test.ts +303 -0
- package/src/runtime/routes/contact-prompt-routes.ts +346 -31
- package/src/util/contact-form-timeouts.ts +48 -0
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,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
|
+
>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contact_record_request` SSE event.
|
|
3
|
+
*
|
|
4
|
+
* Server to client form asking the guardian to confirm a contact record write
|
|
5
|
+
* the assistant proposed: a create, an update, or a delete. Emitted by the
|
|
6
|
+
* `contacts/record-prompt` IPC route while a `pendingContactPrompts` entry
|
|
7
|
+
* awaits a reply.
|
|
8
|
+
*
|
|
9
|
+
* The proposed values are a starting point, not a decision. The guardian may
|
|
10
|
+
* edit the name and notes before submitting, and the client posts the result
|
|
11
|
+
* straight to the gateway, which owns the write.
|
|
12
|
+
*
|
|
13
|
+
* The form closes when the guardian answers it, or with a
|
|
14
|
+
* `contact_form_closed` event if it times out first. `interaction_resolved`
|
|
15
|
+
* does not cover it: that event is conversation-scoped on the wire and is
|
|
16
|
+
* deliberately not broadcast for a conversation-less interaction like this
|
|
17
|
+
* one.
|
|
18
|
+
*
|
|
19
|
+
* Canonical wire-contract source. Daemon code imports the type directly from
|
|
20
|
+
* this file; external consumers import via `@vellumai/assistant-api`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { z } from "zod";
|
|
24
|
+
|
|
25
|
+
export const ContactRecordRequestEventSchema = z.object({
|
|
26
|
+
type: z.literal("contact_record_request"),
|
|
27
|
+
requestId: z.string(),
|
|
28
|
+
operation: z.enum(["create", "update", "delete"]),
|
|
29
|
+
/** Target of an update or delete. Absent on create. */
|
|
30
|
+
contactId: z.string().optional(),
|
|
31
|
+
/** Current name of the target, so the form can show what is changing. */
|
|
32
|
+
currentDisplayName: z.string().optional(),
|
|
33
|
+
/**
|
|
34
|
+
* The target's current notes. The form submits a field only when it differs
|
|
35
|
+
* from what is stored, so it needs what is stored to compare against.
|
|
36
|
+
*/
|
|
37
|
+
currentNotes: z.string().optional(),
|
|
38
|
+
/**
|
|
39
|
+
* The target's channels, so a delete confirmation can say which of two
|
|
40
|
+
* same-named contacts it is about, and what access is about to be lost.
|
|
41
|
+
*/
|
|
42
|
+
channels: z
|
|
43
|
+
.array(z.object({ type: z.string(), address: z.string() }))
|
|
44
|
+
.optional(),
|
|
45
|
+
|
|
46
|
+
/** Proposed name, prefilled into the form. */
|
|
47
|
+
displayName: z.string().optional(),
|
|
48
|
+
/** Proposed notes, prefilled into the form. */
|
|
49
|
+
notes: z.string().optional(),
|
|
50
|
+
/**
|
|
51
|
+
* Whether the caller asked for these notes explicitly. A proposal that
|
|
52
|
+
* happens to match what is stored is still a change the guardian confirmed,
|
|
53
|
+
* and an unreadable mirror reports stored notes as empty, so the form cannot
|
|
54
|
+
* tell "clear them" from "nothing to do" by comparison alone.
|
|
55
|
+
*/
|
|
56
|
+
notesProposed: z.boolean().optional(),
|
|
57
|
+
label: z.string().optional(),
|
|
58
|
+
description: z.string().optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export type ContactRecordRequestEvent = z.infer<
|
|
62
|
+
typeof ContactRecordRequestEventSchema
|
|
63
|
+
>;
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* address (phone, email, etc.). Emitted by the `contacts/prompt` IPC
|
|
6
6
|
* route while a `pendingContactPrompts` entry awaits a reply.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* The form closes when the user answers it, or with a
|
|
9
|
+
* `contact_form_closed` event if it times out first. `interaction_resolved`
|
|
10
|
+
* does not cover it: that event is conversation-scoped on the wire and is
|
|
11
|
+
* deliberately not broadcast for a conversation-less interaction like this
|
|
12
|
+
* one.
|
|
11
13
|
*
|
|
12
14
|
* `channel` and `role` are advisory hints, not enforced enums — the
|
|
13
15
|
* client may render any input it likes and post back a structured
|
|
@@ -29,6 +31,11 @@ export const ContactRequestEventSchema = z.object({
|
|
|
29
31
|
label: z.string().optional(),
|
|
30
32
|
description: z.string().optional(),
|
|
31
33
|
role: z.string().optional(),
|
|
34
|
+
/**
|
|
35
|
+
* Initial state of the form's "mark verified" checkbox, from the CLI's
|
|
36
|
+
* `--verify`. What the guardian submits is what gets attested.
|
|
37
|
+
*/
|
|
38
|
+
verify: z.boolean().optional(),
|
|
32
39
|
});
|
|
33
40
|
|
|
34
41
|
export type ContactRequestEvent = z.infer<typeof ContactRequestEventSchema>;
|
package/src/api/index.ts
CHANGED
|
@@ -23,6 +23,8 @@ import { CompactionCircuitOpenEventSchema } from "./events/compaction-circuit-op
|
|
|
23
23
|
import { ConfigChangedEventSchema } from "./events/config-changed.js";
|
|
24
24
|
import { ConfirmationRequestEventSchema } from "./events/confirmation-request.js";
|
|
25
25
|
import { ConfirmationStateChangedEventSchema } from "./events/confirmation-state-changed.js";
|
|
26
|
+
import { ContactFormClosedEventSchema } from "./events/contact-form-closed.js";
|
|
27
|
+
import { ContactRecordRequestEventSchema } from "./events/contact-record-request.js";
|
|
26
28
|
import { ContactRequestEventSchema } from "./events/contact-request.js";
|
|
27
29
|
import { ContactsChangedEventSchema } from "./events/contacts-changed.js";
|
|
28
30
|
import { ContextCompactedEventSchema } from "./events/context-compacted.js";
|
|
@@ -285,6 +287,14 @@ export {
|
|
|
285
287
|
type ConfirmationStateChangedEvent,
|
|
286
288
|
ConfirmationStateChangedEventSchema,
|
|
287
289
|
} from "./events/confirmation-state-changed.js";
|
|
290
|
+
export {
|
|
291
|
+
type ContactFormClosedEvent,
|
|
292
|
+
ContactFormClosedEventSchema,
|
|
293
|
+
} from "./events/contact-form-closed.js";
|
|
294
|
+
export {
|
|
295
|
+
type ContactRecordRequestEvent,
|
|
296
|
+
ContactRecordRequestEventSchema,
|
|
297
|
+
} from "./events/contact-record-request.js";
|
|
288
298
|
export {
|
|
289
299
|
type ContactRequestEvent,
|
|
290
300
|
ContactRequestEventSchema,
|
|
@@ -952,6 +962,8 @@ export const AssistantEventSchema = z.discriminatedUnion("type", [
|
|
|
952
962
|
ConfigChangedEventSchema,
|
|
953
963
|
ConfirmationRequestEventSchema,
|
|
954
964
|
ConfirmationStateChangedEventSchema,
|
|
965
|
+
ContactFormClosedEventSchema,
|
|
966
|
+
ContactRecordRequestEventSchema,
|
|
955
967
|
ContactRequestEventSchema,
|
|
956
968
|
ContactsChangedEventSchema,
|
|
957
969
|
ContextCompactedEventSchema,
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for what `contacts create` / `update` / `delete` put in front of the
|
|
3
|
+
* guardian.
|
|
4
|
+
*
|
|
5
|
+
* The form is seeded from these bodies and the guardian submits what it shows,
|
|
6
|
+
* so a field the CLI leaves empty is a field the guardian unknowingly writes
|
|
7
|
+
* over. That makes the request body, not just the eventual write, the thing
|
|
8
|
+
* worth pinning.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
12
|
+
|
|
13
|
+
import { CONTACT_FORM_SETTLE_MS } from "../../util/contact-form-timeouts.js";
|
|
14
|
+
|
|
15
|
+
interface IpcCall {
|
|
16
|
+
operationId: string;
|
|
17
|
+
options?: Record<string, unknown>;
|
|
18
|
+
/** Transport options, where the socket deadline lives. */
|
|
19
|
+
callOptions?: { timeoutMs?: number };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let calls: IpcCall[] = [];
|
|
23
|
+
|
|
24
|
+
const contact = {
|
|
25
|
+
id: "ct_1",
|
|
26
|
+
displayName: "Alice",
|
|
27
|
+
notes: "Dentist, referred by Bob",
|
|
28
|
+
contactType: "human",
|
|
29
|
+
createdAt: 0,
|
|
30
|
+
updatedAt: 0,
|
|
31
|
+
interactionCount: 0,
|
|
32
|
+
channels: [
|
|
33
|
+
{
|
|
34
|
+
id: "ch_1",
|
|
35
|
+
contactId: "ct_1",
|
|
36
|
+
type: "email",
|
|
37
|
+
address: "alice@example.com",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** What a contact with no notes actually looks like on the wire. */
|
|
43
|
+
const contactWithoutNotes = { ...contact, notes: null };
|
|
44
|
+
|
|
45
|
+
let contactForRead: Record<string, unknown> = contact;
|
|
46
|
+
/** Make the display readback fail, as a transient IPC hiccup would. */
|
|
47
|
+
let readFails = false;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The ordinary answers. Held as a named function so `beforeEach` can put it
|
|
51
|
+
* back: a test that installs its own implementation would otherwise leave it
|
|
52
|
+
* in place for everything after it, since clearing a mock keeps the last
|
|
53
|
+
* implementation.
|
|
54
|
+
*/
|
|
55
|
+
/** Whether the daemon reports the submitted notes as having reached storage. */
|
|
56
|
+
let notesSaved: boolean | undefined;
|
|
57
|
+
/** Whether the daemon reports that nothing the guardian submitted landed. */
|
|
58
|
+
let nothingWritten: boolean | undefined;
|
|
59
|
+
|
|
60
|
+
const baseIpcImplementation = async (
|
|
61
|
+
operationId: string,
|
|
62
|
+
options?: Record<string, unknown>,
|
|
63
|
+
callOptions?: { timeoutMs?: number },
|
|
64
|
+
) => {
|
|
65
|
+
calls.push({ operationId, options, callOptions });
|
|
66
|
+
if (operationId === "getContact") {
|
|
67
|
+
if (readFails) {
|
|
68
|
+
// 404-shaped, as a gateway-backed read reports a contact it cannot see.
|
|
69
|
+
return { ok: false, error: "Contact not found", statusCode: 404 };
|
|
70
|
+
}
|
|
71
|
+
return { ok: true, result: { ok: true, contact: contactForRead } };
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
ok: true,
|
|
75
|
+
result: { ok: true, contactId: contact.id, notesSaved, nothingWritten },
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const cliIpcCallMock = mock(baseIpcImplementation);
|
|
80
|
+
|
|
81
|
+
const actualCliClient = await import("../../ipc/cli-client.js");
|
|
82
|
+
mock.module("../../ipc/cli-client.js", () => ({
|
|
83
|
+
...actualCliClient,
|
|
84
|
+
cliIpcCall: cliIpcCallMock,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
const { runAssistantCommand } = await import("./run-assistant-command.js");
|
|
88
|
+
|
|
89
|
+
function recordPromptBody(): Record<string, unknown> {
|
|
90
|
+
const call = calls.find((c) => c.operationId === "contacts_record_prompt");
|
|
91
|
+
expect(call).toBeDefined();
|
|
92
|
+
return (call!.options as { body: Record<string, unknown> }).body;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe("contacts record prompts", () => {
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
calls = [];
|
|
98
|
+
contactForRead = contact;
|
|
99
|
+
readFails = false;
|
|
100
|
+
notesSaved = undefined;
|
|
101
|
+
nothingWritten = undefined;
|
|
102
|
+
// Global and sticky: the failure-path cases below set it, and a later test
|
|
103
|
+
// asserting success would otherwise read their exit code as its own.
|
|
104
|
+
// Cleared to 0 rather than undefined, which does not reset it.
|
|
105
|
+
process.exitCode = 0;
|
|
106
|
+
cliIpcCallMock.mockClear();
|
|
107
|
+
cliIpcCallMock.mockImplementation(baseIpcImplementation);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a name-only update carries the notes the contact already has", async () => {
|
|
111
|
+
await runAssistantCommand(
|
|
112
|
+
"contacts",
|
|
113
|
+
"update",
|
|
114
|
+
"ct_1",
|
|
115
|
+
"--name",
|
|
116
|
+
"Alice Chen",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const body = recordPromptBody();
|
|
120
|
+
expect(body.operation).toBe("update");
|
|
121
|
+
expect(body.displayName).toBe("Alice Chen");
|
|
122
|
+
// The form compares against what is stored, so it has to be told.
|
|
123
|
+
expect(body.currentNotes).toBe("Dentist, referred by Bob");
|
|
124
|
+
// Without this the form shows an empty notes box and the guardian submits
|
|
125
|
+
// it, erasing the notes as a side effect of a rename.
|
|
126
|
+
expect(body.notes).toBe("Dentist, referred by Bob");
|
|
127
|
+
expect(body.currentDisplayName).toBe("Alice");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("an explicit empty --notes stays empty, so clearing still works", async () => {
|
|
131
|
+
await runAssistantCommand("contacts", "update", "ct_1", "--notes", "");
|
|
132
|
+
|
|
133
|
+
expect(recordPromptBody().notes).toBe("");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("--notes overrides the existing value", async () => {
|
|
137
|
+
await runAssistantCommand(
|
|
138
|
+
"contacts",
|
|
139
|
+
"update",
|
|
140
|
+
"ct_1",
|
|
141
|
+
"--notes",
|
|
142
|
+
"Moved to Berlin",
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(recordPromptBody().notes).toBe("Moved to Berlin");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a contact with no notes still opens the form", async () => {
|
|
149
|
+
// `notes` is nullable on the wire, and the daemon's schema takes a string
|
|
150
|
+
// or nothing. Passing the null through would reject the request and the
|
|
151
|
+
// guardian would never see a form.
|
|
152
|
+
contactForRead = contactWithoutNotes;
|
|
153
|
+
|
|
154
|
+
await runAssistantCommand(
|
|
155
|
+
"contacts",
|
|
156
|
+
"update",
|
|
157
|
+
"ct_1",
|
|
158
|
+
"--name",
|
|
159
|
+
"Alice Chen",
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const body = recordPromptBody();
|
|
163
|
+
expect(body.notes).toBeUndefined();
|
|
164
|
+
expect("notes" in body ? body.notes : undefined).not.toBeNull();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("the requested timeout bounds the form, not just the socket", async () => {
|
|
168
|
+
// A CLI that gave up first would report failure while the form stayed
|
|
169
|
+
// open, and a later answer would write something the caller was told had
|
|
170
|
+
// not happened.
|
|
171
|
+
await runAssistantCommand(
|
|
172
|
+
"contacts",
|
|
173
|
+
"create",
|
|
174
|
+
"--name",
|
|
175
|
+
"Alice",
|
|
176
|
+
"--timeout",
|
|
177
|
+
"1000",
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const call = calls.find((c) => c.operationId === "contacts_record_prompt");
|
|
181
|
+
const body = (call!.options as { body: Record<string, unknown> }).body;
|
|
182
|
+
expect(body.timeoutMs).toBe(1000);
|
|
183
|
+
// The socket has to outlast an answer arriving at the deadline, which
|
|
184
|
+
// starts the settle window from there. Giving up sooner would report a
|
|
185
|
+
// failure while the write went on to commit.
|
|
186
|
+
expect(call!.callOptions?.timeoutMs).toBeGreaterThan(
|
|
187
|
+
1000 + CONTACT_FORM_SETTLE_MS,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test.each(["1e3", "100.5", "300000ms", "abc", "-5"])(
|
|
192
|
+
"a timeout of %p is refused rather than partly parsed",
|
|
193
|
+
async (raw) => {
|
|
194
|
+
// parseInt takes a valid prefix, so "1e3" would otherwise become a 1ms
|
|
195
|
+
// form: open and shut before anyone could answer it.
|
|
196
|
+
await runAssistantCommand(
|
|
197
|
+
"contacts",
|
|
198
|
+
"create",
|
|
199
|
+
"--name",
|
|
200
|
+
"Alice",
|
|
201
|
+
"--timeout",
|
|
202
|
+
raw,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
expect(
|
|
206
|
+
calls.some((c) => c.operationId === "contacts_record_prompt"),
|
|
207
|
+
).toBe(false);
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
test("a timeout past the ceiling is refused before the guardian is bothered", async () => {
|
|
212
|
+
await runAssistantCommand(
|
|
213
|
+
"contacts",
|
|
214
|
+
"create",
|
|
215
|
+
"--name",
|
|
216
|
+
"Alice",
|
|
217
|
+
"--timeout",
|
|
218
|
+
"99999999",
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(calls.some((c) => c.operationId === "contacts_record_prompt")).toBe(
|
|
222
|
+
false,
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("a write still reports success when only the display readback fails", async () => {
|
|
227
|
+
// The guardian has answered and the write is done. Exiting non-zero here
|
|
228
|
+
// says otherwise, and a retried create makes a second contact.
|
|
229
|
+
readFails = true;
|
|
230
|
+
|
|
231
|
+
await runAssistantCommand("contacts", "create", "--name", "Alice");
|
|
232
|
+
|
|
233
|
+
expect(calls.some((c) => c.operationId === "contacts_record_prompt")).toBe(
|
|
234
|
+
true,
|
|
235
|
+
);
|
|
236
|
+
expect(process.exitCode).toBeFalsy();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("an update that wrote nothing exits nonzero", async () => {
|
|
240
|
+
// The guardian submits only what they changed, so a proposed name they
|
|
241
|
+
// left at its stored value never reaches the write. Whether anything
|
|
242
|
+
// landed is the gateway's to report, not this command's to infer.
|
|
243
|
+
notesSaved = false;
|
|
244
|
+
nothingWritten = true;
|
|
245
|
+
|
|
246
|
+
await runAssistantCommand(
|
|
247
|
+
"contacts",
|
|
248
|
+
"update",
|
|
249
|
+
"ct_1",
|
|
250
|
+
"--name",
|
|
251
|
+
"Alice",
|
|
252
|
+
"--notes",
|
|
253
|
+
"Moved",
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
expect(process.exitCode).toBe(1);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("a rename that loses its notes still succeeds, since the rename landed", async () => {
|
|
260
|
+
notesSaved = false;
|
|
261
|
+
nothingWritten = false;
|
|
262
|
+
|
|
263
|
+
await runAssistantCommand(
|
|
264
|
+
"contacts",
|
|
265
|
+
"update",
|
|
266
|
+
"ct_1",
|
|
267
|
+
"--name",
|
|
268
|
+
"Alice Chen",
|
|
269
|
+
"--notes",
|
|
270
|
+
"Moved",
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(process.exitCode).toBeFalsy();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("create proposes only what was asked for", async () => {
|
|
277
|
+
await runAssistantCommand("contacts", "create", "--name", "Alice");
|
|
278
|
+
|
|
279
|
+
const body = recordPromptBody();
|
|
280
|
+
expect(body.operation).toBe("create");
|
|
281
|
+
expect(body.displayName).toBe("Alice");
|
|
282
|
+
expect(body.contactId).toBeUndefined();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("delete reads the contact first, so a bad id fails before the guardian sees a form", async () => {
|
|
286
|
+
await runAssistantCommand("contacts", "delete", "ct_1");
|
|
287
|
+
|
|
288
|
+
const body = recordPromptBody();
|
|
289
|
+
expect(body.operation).toBe("delete");
|
|
290
|
+
expect(body.contactId).toBe("ct_1");
|
|
291
|
+
expect(body.currentDisplayName).toBe("Alice");
|
|
292
|
+
// Two contacts can share a name, so the confirmation carries the channels
|
|
293
|
+
// that identify this one and that the delete will take with it.
|
|
294
|
+
expect(body.channels).toEqual([
|
|
295
|
+
{ type: "email", address: "alice@example.com" },
|
|
296
|
+
]);
|
|
297
|
+
// The read comes first: the form names the contact it is about.
|
|
298
|
+
expect(calls[0]!.operationId).toBe("getContact");
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("delete reaches the confirmation for a contact the read cannot see", async () => {
|
|
302
|
+
// A dual-write gap leaves contacts in the assistant mirror that this
|
|
303
|
+
// gateway-backed read misses. `contacts list --query` surfaces them and
|
|
304
|
+
// the delete supports removing them, so refusing here would strand an id
|
|
305
|
+
// the guardian can see.
|
|
306
|
+
readFails = true;
|
|
307
|
+
|
|
308
|
+
await runAssistantCommand("contacts", "delete", "ct_orphan");
|
|
309
|
+
|
|
310
|
+
const body = recordPromptBody();
|
|
311
|
+
expect(body.operation).toBe("delete");
|
|
312
|
+
expect(body.contactId).toBe("ct_orphan");
|
|
313
|
+
// Nothing to show but the id, and no channels to compare against.
|
|
314
|
+
expect(body.channels).toEqual([]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// The refusing side of that branch (an update against a contact the read
|
|
318
|
+
// cannot see, or a delete for an id nothing knows about) has no test: it
|
|
319
|
+
// ends in `exitFromIpcResult`, which calls `process.exit` and takes the test
|
|
320
|
+
// runner with it.
|
|
321
|
+
|
|
322
|
+
test("update refuses when neither --name nor --notes is given", async () => {
|
|
323
|
+
await runAssistantCommand("contacts", "update", "ct_1");
|
|
324
|
+
|
|
325
|
+
expect(calls.some((c) => c.operationId === "contacts_record_prompt")).toBe(
|
|
326
|
+
false,
|
|
327
|
+
);
|
|
328
|
+
});
|
|
329
|
+
});
|