@vatio-ai/cli 0.54.1 → 0.56.0
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/README.md +10 -18
- package/bin/vatio.mjs +20 -23
- package/lib/api-client.mjs +17 -172
- package/lib/bundle.mjs +1 -1
- package/lib/commands/channels.mjs +10 -335
- package/lib/commands/chat.mjs +31 -84
- package/lib/commands/deploy.mjs +2 -17
- package/lib/commands/improve.mjs +112 -0
- package/lib/commands/knowledge.mjs +13 -70
- package/lib/commands/misc.mjs +36 -1
- package/lib/commands/support-commands.mjs +2 -167
- package/lib/commands/workspace-admin.mjs +3 -18
- package/lib/config.mjs +1 -1
- package/lib/device-auth.mjs +3 -3
- package/lib/help.mjs +21 -22
- package/lib/update-notice.mjs +2 -3
- package/lib/workspace.mjs +1 -5
- package/package.json +1 -1
- package/lib/commands/mcp.mjs +0 -333
|
@@ -1,341 +1,16 @@
|
|
|
1
|
-
// whatsapp / instagram
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// account, which serves live, and a shared preview you can use immediately with
|
|
5
|
-
// no Meta account of your own. `numbers` and `accounts` are the preview halves,
|
|
6
|
-
// and they hang off the channel they belong to because "accounts" on its own
|
|
7
|
-
// would say nothing about which one.
|
|
1
|
+
// whatsapp / instagram -- both are set up in the console now: connecting your
|
|
2
|
+
// own number or account needs Meta's consent screen, and test phones and
|
|
3
|
+
// accounts are a form with a code. The CLI only says where.
|
|
8
4
|
|
|
9
5
|
import { deployClient } from "./deploy.mjs";
|
|
10
|
-
import { fail, openBrowser, takeEnv } from "../support.mjs";
|
|
11
6
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
const client = deployClient(config, workspace);
|
|
15
|
-
const sub = args.shift() ?? "status";
|
|
7
|
+
export const whatsapp = (config) => inConsole(config, "WhatsApp");
|
|
8
|
+
export const instagram = (config) => inConsole(config, "Instagram");
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
await client.activateWhatsappAccount();
|
|
23
|
-
console.log(`Activated WhatsApp on workspace ${workspace} — it answers customers now.`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
case "deactivate": {
|
|
27
|
-
await client.deactivateWhatsappAccount();
|
|
28
|
-
console.log(`Paused WhatsApp on workspace ${workspace}. The credentials are kept.`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
case "disconnect": case "remove": case "rm": {
|
|
32
|
-
await client.disconnectWhatsappAccount();
|
|
33
|
-
console.log(`Disconnected WhatsApp from workspace ${workspace}. Vatio stops receiving its messages.`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
case "numbers": return await numbers(client, workspace, args, config.workspaceRoot);
|
|
37
|
-
default: fail(whatsappUsage());
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function whatsappUsage() {
|
|
42
|
-
return `Usage: vatio whatsapp status|connect|check|activate|deactivate|disconnect
|
|
43
|
-
vatio whatsapp numbers list|add PHONE|point PHONE|verify PHONE CODE|resend PHONE|remove PHONE [--env NAME]
|
|
44
|
-
|
|
45
|
-
The bare commands drive your own WhatsApp number, which serves live.
|
|
46
|
-
\`numbers\` registers test phones on the shared WhatsApp preview. Each reaches
|
|
47
|
-
the environment it points at: preview, or a branch's (\`add\` and \`point\`
|
|
48
|
-
take --env, and default to the branch you are on) — the counterpart of
|
|
49
|
-
\`vatio instagram accounts\`.
|
|
50
|
-
|
|
51
|
-
connect
|
|
52
|
-
Prints a link to finish in a browser. Connecting a number is Meta's
|
|
53
|
-
Embedded Signup, a consent screen a person has to read, so there is
|
|
54
|
-
nothing for a command to do but hand the link over.`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function printWhatsapp(account, workspace) {
|
|
58
|
-
if (!account.connected) {
|
|
59
|
-
console.log(`No WhatsApp number connected to workspace ${workspace}.`);
|
|
60
|
-
console.log(" Connect yours: vatio whatsapp connect");
|
|
61
|
-
console.log(" Or test on the shared preview number with no Meta account: vatio whatsapp numbers add +56912345678");
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const label = account.phone_number ?? "your WhatsApp number";
|
|
66
|
-
console.log(`${label} on workspace ${workspace}:`);
|
|
67
|
-
console.log(` status: ${account.status}`);
|
|
68
|
-
console.log(` receiving: ${account.receiving_messages ? "yes" : "no"}`);
|
|
69
|
-
console.log(` active: ${account.active ? "yes" : "no (paused)"}`);
|
|
70
|
-
if (account.last_health_error) console.log(` error: ${account.last_health_error}`);
|
|
71
|
-
console.log("");
|
|
72
|
-
|
|
73
|
-
// Three things that fail separately, so the advice names which one did.
|
|
74
|
-
if (account.live_ready) {
|
|
75
|
-
console.log(`Messages to ${label} reach your live deployment.`);
|
|
76
|
-
console.log("Change what it answers with: vatio push && vatio publish");
|
|
77
|
-
} else if (!account.receiving_messages) {
|
|
78
|
-
console.log("Meta is not delivering this number's messages to Vatio, so the agent");
|
|
79
|
-
console.log("never sees them. Repair the subscription: vatio whatsapp check");
|
|
80
|
-
} else if (!account.active) {
|
|
81
|
-
console.log("Connected and receiving, but paused — nobody gets an answer yet.");
|
|
82
|
-
console.log("Start answering: vatio whatsapp activate");
|
|
83
|
-
} else {
|
|
84
|
-
console.log("Not ready to answer yet. Re-check with: vatio whatsapp check");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Prints the link and stops. Meta's Embedded Signup needs a logged-in browser
|
|
89
|
-
// and a person reading a consent screen; there is no headless form of it, and
|
|
90
|
-
// the ids a credentials flag would take do not exist until it has run. Keeping
|
|
91
|
-
// a number in the WhatsApp Business phone app is only possible through it too.
|
|
92
|
-
async function connectWhatsapp(client, workspace) {
|
|
93
|
-
const payload = await client.whatsappConnectLink();
|
|
94
|
-
const url = payload.connect_url;
|
|
95
|
-
if (!url) fail("The platform did not return a connect URL");
|
|
96
|
-
|
|
97
|
-
if (payload.connected_number) {
|
|
98
|
-
console.log(`Workspace ${workspace} is already connected to ${payload.connected_number}.`);
|
|
99
|
-
console.log("Connecting the same number again renews its access token. To connect a");
|
|
100
|
-
console.log("different one, run `vatio whatsapp disconnect` first.");
|
|
101
|
-
console.log("");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.log("Open this to connect your WhatsApp number:");
|
|
105
|
-
console.log("");
|
|
106
|
-
console.log(` ${url}`);
|
|
107
|
-
console.log("");
|
|
108
|
-
console.log("Choose your number in Meta's popup. A number already in the WhatsApp");
|
|
109
|
-
console.log("Business app on your phone stays there — you keep answering from the");
|
|
110
|
-
console.log("phone and the agent answers on the same number.");
|
|
111
|
-
console.log("");
|
|
112
|
-
console.log("Then run `vatio whatsapp`.");
|
|
113
|
-
// The link is printed first and stays printed: openBrowser is a convenience
|
|
114
|
-
// that silently does nothing over SSH, in a container, or wherever there is
|
|
115
|
-
// no browser to open, and the developer still has the URL to paste.
|
|
116
|
-
openBrowser(url);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function numbers(client, workspace, args, cwd) {
|
|
120
|
-
const sub = args.shift() ?? "list";
|
|
121
|
-
const usage = "Usage: vatio whatsapp numbers list|add PHONE|point PHONE|verify PHONE CODE|resend PHONE|remove PHONE [--env NAME]";
|
|
122
|
-
const environment = ["add", "point"].includes(sub) ? takeEnv(args, { fallback: null, cwd }) : null;
|
|
123
|
-
|
|
124
|
-
if (sub === "list") {
|
|
125
|
-
const list = asArray((await client.listTestPhoneNumbers()).test_phone_numbers);
|
|
126
|
-
if (list.length === 0) {
|
|
127
|
-
console.log(`No test phone numbers on workspace ${workspace}`);
|
|
128
|
-
console.log(" Register one: vatio whatsapp numbers add +56912345678");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
console.log(`Test phone numbers on workspace ${workspace} (${list.length}):`);
|
|
132
|
-
for (const number of list) {
|
|
133
|
-
const suffix = number.status === "verified" ? `verified ${number.verified_at}` : "pending verification";
|
|
134
|
-
console.log(` ${number.phone_number} → ${number.environment} ${suffix}`);
|
|
135
|
-
}
|
|
136
|
-
console.log("");
|
|
137
|
-
console.log("Each reaches its environment on the shared WhatsApp preview number, never live.");
|
|
138
|
-
console.log("Point one elsewhere: vatio whatsapp numbers point PHONE --env NAME");
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (sub === "point") {
|
|
142
|
-
const phoneNumber = requireArg(args, "vatio whatsapp numbers point +56912345678 [--env NAME]");
|
|
143
|
-
const number = await client.pointTestPhoneNumber({ phoneNumber, environment: environment ?? "preview" });
|
|
144
|
-
console.log(`${number.phone_number} now reaches ${number.environment} on workspace ${workspace}.`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (sub === "add") {
|
|
148
|
-
const phoneNumber = requireArg(args, "vatio whatsapp numbers add +56912345678");
|
|
149
|
-
const number = await client.addTestPhoneNumber({ phoneNumber, environment });
|
|
150
|
-
if (number.already_verified) {
|
|
151
|
-
console.log(`${number.phone_number} is already verified on workspace ${workspace} — nothing to do.`);
|
|
152
|
-
} else if (number.moved_from) {
|
|
153
|
-
console.log(`Moved ${number.phone_number} from workspace ${number.moved_from} to ${workspace}.`);
|
|
154
|
-
console.log("It was already verified, so no new code was sent.");
|
|
155
|
-
} else {
|
|
156
|
-
console.log(`Sent a 6-digit code over WhatsApp to ${number.phone_number}.`);
|
|
157
|
-
console.log("It is valid for 10 minutes. When it arrives:");
|
|
158
|
-
console.log("");
|
|
159
|
-
console.log(` vatio whatsapp numbers verify ${number.phone_number} 123456`);
|
|
160
|
-
}
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (sub === "verify") {
|
|
164
|
-
const phoneNumber = requireArg(args, "vatio whatsapp numbers verify +56912345678 123456");
|
|
165
|
-
const code = requireArg(args, "vatio whatsapp numbers verify +56912345678 123456");
|
|
166
|
-
const number = await client.verifyTestPhoneNumber({ phoneNumber, code });
|
|
167
|
-
console.log(
|
|
168
|
-
number.already_verified
|
|
169
|
-
? `${number.phone_number} was already verified on workspace ${workspace}.`
|
|
170
|
-
: `Verified ${number.phone_number} on workspace ${workspace}.`
|
|
171
|
-
);
|
|
172
|
-
console.log(`Anything you send from that phone now reaches ${number.environment}.`);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (sub === "resend") {
|
|
176
|
-
const phoneNumber = requireArg(args, "vatio whatsapp numbers resend +56912345678");
|
|
177
|
-
const number = await client.resendTestPhoneNumberCode({ phoneNumber });
|
|
178
|
-
console.log(
|
|
179
|
-
number.already_verified
|
|
180
|
-
? `${number.phone_number} is already verified on workspace ${workspace} — no code needed.`
|
|
181
|
-
: `Sent a new 6-digit code to ${number.phone_number}.`
|
|
182
|
-
);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (sub === "remove" || sub === "delete" || sub === "rm") {
|
|
186
|
-
const phoneNumber = requireArg(args, "vatio whatsapp numbers remove +56912345678");
|
|
187
|
-
await client.removeTestPhoneNumber({ phoneNumber });
|
|
188
|
-
console.log(`Removed ${phoneNumber} from workspace ${workspace}.`);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
fail(usage);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export async function instagram(config, args) {
|
|
196
|
-
const workspace = config.resolveWorkspaceRequired();
|
|
197
|
-
const client = deployClient(config, workspace);
|
|
198
|
-
const sub = args.shift() ?? "status";
|
|
199
|
-
|
|
200
|
-
switch (sub) {
|
|
201
|
-
case "status": return printInstagram(await client.instagramAccount(), workspace);
|
|
202
|
-
case "connect": return await connectInstagram(client);
|
|
203
|
-
case "check": return printInstagram(await client.checkInstagramAccount(), workspace);
|
|
204
|
-
case "disconnect": case "remove": case "rm": {
|
|
205
|
-
await client.disconnectInstagramAccount();
|
|
206
|
-
console.log(`Disconnected Instagram from workspace ${workspace}. Vatio stops receiving its DMs.`);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
case "accounts": return await instagramAccounts(client, workspace, args, config.workspaceRoot);
|
|
210
|
-
default: fail(instagramUsage());
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function instagramUsage() {
|
|
215
|
-
return `Usage: vatio instagram status|connect|check|disconnect
|
|
216
|
-
vatio instagram accounts list|add @HANDLE|point ID|verify CODE|resend ID|remove ID [--env NAME]
|
|
217
|
-
|
|
218
|
-
The bare commands drive your own Instagram account, which serves live.
|
|
219
|
-
\`accounts\` registers test accounts on the shared Instagram preview. Each
|
|
220
|
-
reaches the environment it points at: preview, or a branch's (\`add\` and
|
|
221
|
-
\`point\` take --env, and default to the branch you are on) — the counterpart
|
|
222
|
-
of \`vatio whatsapp numbers\`.`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function printInstagram(account, workspace) {
|
|
226
|
-
if (!account.connected) {
|
|
227
|
-
console.log(`No Instagram account connected to workspace ${workspace}.`);
|
|
228
|
-
console.log(" Connect yours: vatio instagram connect");
|
|
229
|
-
console.log(" Or test on the shared preview account: vatio instagram accounts add @yourhandle");
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const handle = account.username ? `@${account.username}` : "your Instagram account";
|
|
234
|
-
console.log(`${handle} on workspace ${workspace}:`);
|
|
235
|
-
console.log(` status: ${account.status}`);
|
|
236
|
-
console.log(` receiving: ${account.receiving_messages ? "yes" : "no"}`);
|
|
237
|
-
if (account.last_health_error) console.log(` error: ${account.last_health_error}`);
|
|
238
|
-
console.log("");
|
|
239
|
-
|
|
240
|
-
if (account.live_ready) {
|
|
241
|
-
console.log(`DMs to ${handle} reach your live deployment.`);
|
|
242
|
-
console.log("Change what it answers with: vatio push && vatio publish");
|
|
243
|
-
} else if (account.token_expired) {
|
|
244
|
-
console.log("The access token expired. Re-grant it: vatio instagram connect");
|
|
245
|
-
} else if (!account.receiving_messages) {
|
|
246
|
-
console.log("Instagram is not delivering this account's messages to Vatio, so the");
|
|
247
|
-
console.log("agent never sees them. Repair the subscription: vatio instagram check");
|
|
248
|
-
} else {
|
|
249
|
-
console.log("Not ready to answer DMs yet. Re-check with: vatio instagram check");
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Connecting mints a URL for Meta's consent screen rather than taking
|
|
254
|
-
// credentials: granting an app access to an Instagram account is a decision
|
|
255
|
-
// Meta insists a human makes in a browser.
|
|
256
|
-
async function connectInstagram(client) {
|
|
257
|
-
const payload = await client.instagramConnectLink();
|
|
258
|
-
const url = payload.url ?? payload.consent_url;
|
|
259
|
-
if (!url) fail("The platform did not return a consent URL");
|
|
260
|
-
|
|
261
|
-
console.log("Open this to grant Vatio access to an Instagram professional account:");
|
|
262
|
-
console.log("");
|
|
10
|
+
async function inConsole(config, channel) {
|
|
11
|
+
const status = await deployClient(config, config.resolveWorkspaceRequired()).deployStatus();
|
|
12
|
+
const url = status.integrations_url ?? `${config.resolveBaseUrl()}/workspaces`;
|
|
13
|
+
console.log(`${channel} is set up in the console: your own account, and the test phones and`);
|
|
14
|
+
console.log("accounts that reach a preview or a branch.");
|
|
263
15
|
console.log(` ${url}`);
|
|
264
|
-
console.log("");
|
|
265
|
-
console.log("Then run `vatio instagram check`.");
|
|
266
|
-
openBrowser(url);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
async function instagramAccounts(client, workspace, args, cwd) {
|
|
270
|
-
const sub = args.shift() ?? "list";
|
|
271
|
-
const usage = "Usage: vatio instagram accounts list|add @HANDLE|point ID|verify CODE|resend ID|remove ID [--env NAME]";
|
|
272
|
-
const environment = ["add", "point"].includes(sub) ? takeEnv(args, { fallback: null, cwd }) : null;
|
|
273
|
-
|
|
274
|
-
if (sub === "list") {
|
|
275
|
-
const list = asArray((await client.listTestInstagramAccounts()).test_instagram_accounts);
|
|
276
|
-
if (list.length === 0) {
|
|
277
|
-
console.log(`No test Instagram accounts on workspace ${workspace}`);
|
|
278
|
-
console.log(" Register one: vatio instagram accounts add @yourhandle");
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
console.log(`Test Instagram accounts on workspace ${workspace} (${list.length}):`);
|
|
282
|
-
for (const account of list) {
|
|
283
|
-
const suffix =
|
|
284
|
-
account.status === "verified" ? `verified ${account.verified_at}`
|
|
285
|
-
: account.status === "awaiting_code" ? "code sent — confirm it: vatio instagram accounts verify CODE"
|
|
286
|
-
: `declared — DM @${account.dm_to} from that account to get a code`;
|
|
287
|
-
console.log(` [${account.id}] @${account.username} → ${account.environment} ${suffix}`);
|
|
288
|
-
}
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
if (sub === "point") {
|
|
292
|
-
const id = requireArg(args, "vatio instagram accounts point ID [--env NAME]");
|
|
293
|
-
const account = await client.pointTestInstagramAccount({ id, environment: environment ?? "preview" });
|
|
294
|
-
console.log(`@${account.username} now reaches ${account.environment} on workspace ${workspace}.`);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (sub === "add") {
|
|
298
|
-
const username = requireArg(args, "vatio instagram accounts add @yourhandle").replace(/^@/, "");
|
|
299
|
-
const account = await client.addTestInstagramAccount({ username, environment });
|
|
300
|
-
console.log(`Declared @${account.username} on workspace ${workspace}.`);
|
|
301
|
-
console.log("");
|
|
302
|
-
// Meta will not let an app DM an account that has not written first, which
|
|
303
|
-
// is why the code travels in that direction and nothing happens until the
|
|
304
|
-
// developer sends that first message.
|
|
305
|
-
console.log(`Now DM @${account.dm_to} from that account. Vatio replies with a 6-digit code:`);
|
|
306
|
-
console.log("");
|
|
307
|
-
console.log(" vatio instagram accounts verify 123456");
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (sub === "verify") {
|
|
311
|
-
const code = requireArg(args, "vatio instagram accounts verify 123456");
|
|
312
|
-
const account = await client.verifyTestInstagramAccount({ code });
|
|
313
|
-
console.log(`Verified @${account.username} on workspace ${workspace}.`);
|
|
314
|
-
console.log(`DMs from that account now reach ${account.environment}.`);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (sub === "resend") {
|
|
318
|
-
const id = requireArg(args, "vatio instagram accounts resend ID");
|
|
319
|
-
const account = await client.resendTestInstagramAccountCode(id);
|
|
320
|
-
console.log(`Sent a new code to @${account.username}.`);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (sub === "remove" || sub === "delete" || sub === "rm") {
|
|
324
|
-
const id = requireArg(args, "vatio instagram accounts remove ID");
|
|
325
|
-
await client.removeTestInstagramAccount(id);
|
|
326
|
-
console.log(`Removed test Instagram account ${id} from workspace ${workspace}.`);
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
fail(usage);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function requireArg(args, usage) {
|
|
334
|
-
const value = String(args.shift() ?? "").trim();
|
|
335
|
-
if (value === "") fail(`Usage: ${usage}`);
|
|
336
|
-
return value;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function asArray(value) {
|
|
340
|
-
return Array.isArray(value) ? value : [];
|
|
341
16
|
}
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// accounts do that for real, and a simulated channel was only ever a second
|
|
7
7
|
// answer to keep in step with the true one.
|
|
8
8
|
|
|
9
|
-
import { existsSync, readFileSync,
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
|
|
12
12
|
import { ApiClient } from "../api-client.mjs";
|
|
@@ -14,7 +14,15 @@ import { fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
|
14
14
|
|
|
15
15
|
export const STATE_FILE = ".vatio-chat.json";
|
|
16
16
|
|
|
17
|
-
const SUBCOMMANDS = new Set(["show", "
|
|
17
|
+
const SUBCOMMANDS = new Set(["show", "help"]);
|
|
18
|
+
// Answered by name, so old muscle memory gets the new spelling.
|
|
19
|
+
const RETIRED = {
|
|
20
|
+
transcript: "`vatio chat transcript` is `vatio chat show` now.",
|
|
21
|
+
debug: "`vatio chat debug` is `vatio chat show` now (add --json for everything).",
|
|
22
|
+
reset: "`vatio chat reset` is `vatio chat --new \"message\"` now.",
|
|
23
|
+
destroy: "`vatio chat destroy` was removed.",
|
|
24
|
+
delete: "`vatio chat delete` was removed."
|
|
25
|
+
};
|
|
18
26
|
const REMOVED_FLAGS = ["--channel", "--from", "--as", "--sandbox-url"];
|
|
19
27
|
|
|
20
28
|
export async function chat(config, args) {
|
|
@@ -22,7 +30,7 @@ export async function chat(config, args) {
|
|
|
22
30
|
if (REMOVED_FLAGS.some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
23
31
|
fail(
|
|
24
32
|
`\`${arg}\` was removed. A CLI chat is you, the developer holding the token. ` +
|
|
25
|
-
"To test a real channel
|
|
33
|
+
"To test a real channel add a test phone or Instagram account in the console; " +
|
|
26
34
|
"to pick a deployment use --env."
|
|
27
35
|
);
|
|
28
36
|
}
|
|
@@ -33,44 +41,39 @@ export async function chat(config, args) {
|
|
|
33
41
|
const lastValue = takeValue(args, "--last");
|
|
34
42
|
const last = Number(lastValue ?? 10);
|
|
35
43
|
const json = takeFlag(args, "--json");
|
|
44
|
+
const fresh = takeFlag(args, "--new");
|
|
36
45
|
const apiUrl = takeValue(args, "--api-url");
|
|
37
46
|
const token = takeValue(args, "--token");
|
|
38
47
|
|
|
39
48
|
const options = { environment, timeout, last, lastGiven: lastValue != null, json, apiUrl, token };
|
|
49
|
+
if (args.length === 1 && RETIRED[args[0]]) fail(RETIRED[args[0]]);
|
|
40
50
|
const sub = SUBCOMMANDS.has(args[0]) ? args.shift() : null;
|
|
41
51
|
|
|
42
52
|
if (sub === "help") return console.log(chatHelp());
|
|
43
53
|
if (sub === "show") return await showChat(config, options, args);
|
|
44
|
-
if (sub === "transcript") return await transcript(config, options);
|
|
45
|
-
if (sub === "debug") return await debugChat(config, options);
|
|
46
|
-
if (sub === "reset") return await resetChat(config, options);
|
|
47
|
-
if (sub === "destroy" || sub === "delete") return await destroyChat(config, options, args);
|
|
48
54
|
|
|
55
|
+
if (fresh) await startOver(config, options);
|
|
49
56
|
const message = args.join(" ").trim();
|
|
50
|
-
if (message === "") return console.log(chatHelp());
|
|
57
|
+
if (message === "") return fresh ? undefined : console.log(chatHelp());
|
|
51
58
|
|
|
52
59
|
return await converse(config, options, message);
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
function chatHelp() {
|
|
56
63
|
return `Usage:
|
|
57
|
-
vatio chat "message" [--env NAME] [--timeout N]
|
|
58
|
-
vatio chat
|
|
59
|
-
vatio chat debug [--last N]
|
|
60
|
-
vatio chat show CHAT_ID [--last N] [--json]
|
|
61
|
-
vatio chat reset
|
|
62
|
-
vatio chat destroy CHAT_ID
|
|
64
|
+
vatio chat "message" [--env NAME] [--new] [--timeout N]
|
|
65
|
+
vatio chat show [CHAT_ID] [--env NAME] [--last N] [--json]
|
|
63
66
|
|
|
64
67
|
--env picks the deployment that answers: preview (default), live, or a preview
|
|
65
68
|
name like pr-42. A chat against live is a real conversation and shows up in
|
|
66
69
|
your inbox.
|
|
67
70
|
|
|
68
|
-
\`show\`
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
\`show\` prints the chat you are in, with every tool call the agent made. Give
|
|
72
|
+
it an id to read any chat in the workspace -- one a visitor had on the web,
|
|
73
|
+
WhatsApp or Instagram -- with the environment and deployment that answered it.
|
|
71
74
|
|
|
72
75
|
The open chat per deployment is remembered in ${STATE_FILE}, so a second
|
|
73
|
-
\`vatio chat\` continues the first. \`
|
|
76
|
+
\`vatio chat\` continues the first. \`--new\` starts over as a visitor the
|
|
74
77
|
workspace has never met.`;
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -181,33 +184,6 @@ async function waitForAssistant(api, { chatId, after, timeout, interval = 2 }) {
|
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
async function transcript(config, options) {
|
|
185
|
-
const api = client(config, options);
|
|
186
|
-
const chatId = await ensureChat(config, options);
|
|
187
|
-
const payload = await api.chatMessages({
|
|
188
|
-
chatId,
|
|
189
|
-
limit: Math.min(options.last * 6, 200)
|
|
190
|
-
});
|
|
191
|
-
const messages = (Array.isArray(payload.data) ? payload.data : [])
|
|
192
|
-
.filter(visitorVisible)
|
|
193
|
-
.slice(-options.last);
|
|
194
|
-
for (const message of messages) console.log(formatVisitor(message));
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function debugChat(config, options) {
|
|
198
|
-
const api = client(config, options);
|
|
199
|
-
const chatId = await ensureChat(config, options);
|
|
200
|
-
|
|
201
|
-
console.log("## Chat status (developer)");
|
|
202
|
-
console.log(JSON.stringify(await api.showChat({ chatId }), null, 2));
|
|
203
|
-
console.log("");
|
|
204
|
-
console.log(`## Transcript (developer/debug, last ${options.last})`);
|
|
205
|
-
const payload = await api.chatMessages({ chatId, limit: options.last });
|
|
206
|
-
for (const message of Array.isArray(payload.data) ? payload.data : []) {
|
|
207
|
-
console.log(`[${message.role}] ${String(message.content ?? "").trim()}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
187
|
// Every message, not the first page: a chat worth reading by id is usually one
|
|
212
188
|
// that went wrong somewhere in the middle.
|
|
213
189
|
async function allMessages(api, chatId) {
|
|
@@ -223,8 +199,14 @@ async function allMessages(api, chatId) {
|
|
|
223
199
|
}
|
|
224
200
|
|
|
225
201
|
async function showChat(config, options, args) {
|
|
226
|
-
|
|
227
|
-
if (
|
|
202
|
+
let chatId = args.shift();
|
|
203
|
+
if (chatId !== undefined && !/^\d+$/.test(chatId)) fail("Usage: vatio chat show [CHAT_ID] [--last N] [--json]");
|
|
204
|
+
if (chatId === undefined) {
|
|
205
|
+
const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
|
|
206
|
+
chatId = chatsFor(config, apiUrl)[options.environment];
|
|
207
|
+
if (!chatId) fail(`No ${options.environment} chat yet: run \`vatio chat "hello"\` first, or pass a CHAT_ID.`);
|
|
208
|
+
chatId = String(chatId);
|
|
209
|
+
}
|
|
228
210
|
|
|
229
211
|
const api = client(config, options);
|
|
230
212
|
const chat = await api.showChat({ chatId });
|
|
@@ -268,40 +250,13 @@ function truncate(text, max) {
|
|
|
268
250
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
269
251
|
}
|
|
270
252
|
|
|
271
|
-
async function
|
|
253
|
+
async function startOver(config, options) {
|
|
272
254
|
const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
|
|
273
255
|
const payload = await openChat(config, options, {
|
|
274
256
|
apiUrl,
|
|
275
257
|
chatId: chatsFor(config, apiUrl)[options.environment] ?? null
|
|
276
258
|
});
|
|
277
|
-
console.log(`
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Destroying a chat on the platform must not leave the local state pointing at
|
|
281
|
-
// it: the next `vatio chat` would send a message to an id that is gone. Only
|
|
282
|
-
// that deployment's entry is dropped -- destroying the live chat should not
|
|
283
|
-
// close the preview one.
|
|
284
|
-
async function destroyChat(config, options, args) {
|
|
285
|
-
const chatId = args.shift();
|
|
286
|
-
if (!chatId) fail("Usage: vatio chat destroy CHAT_ID");
|
|
287
|
-
|
|
288
|
-
const workspace = config.resolveWorkspaceRequired();
|
|
289
|
-
await client(config, options).destroyChat({ chatId });
|
|
290
|
-
|
|
291
|
-
const state = loadState(config);
|
|
292
|
-
if (state.chats && typeof state.chats === "object") {
|
|
293
|
-
const kept = Object.fromEntries(
|
|
294
|
-
Object.entries(state.chats).filter(([, id]) => Number(id) !== Number(chatId))
|
|
295
|
-
);
|
|
296
|
-
const path = statePath(config);
|
|
297
|
-
if (Object.keys(kept).length === 0 && Object.keys(state.chats).length > 0) {
|
|
298
|
-
writeFileSync(path, `${JSON.stringify({ ...state, chats: {} }, null, 2)}\n`);
|
|
299
|
-
} else if (existsSync(path)) {
|
|
300
|
-
writeFileSync(path, `${JSON.stringify({ ...state, chats: kept }, null, 2)}\n`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
console.log(`Destroyed chat ${chatId} in ${workspace}`);
|
|
259
|
+
console.log(`New ${options.environment} chat ${payload.chat_id}`);
|
|
305
260
|
}
|
|
306
261
|
|
|
307
262
|
function formatVisitor(message) {
|
|
@@ -309,11 +264,3 @@ function formatVisitor(message) {
|
|
|
309
264
|
const role = message.role === "assistant" ? "agent" : "you";
|
|
310
265
|
return `[${role}] ${String(message.content ?? "").trim()}`;
|
|
311
266
|
}
|
|
312
|
-
|
|
313
|
-
export function removeLegacyChatState(root) {
|
|
314
|
-
// `.vatio-sandbox.json` held a chat id *and* the simulated identity it was
|
|
315
|
-
// opened with. The identity half no longer means anything, so it is removed
|
|
316
|
-
// rather than migrated.
|
|
317
|
-
const legacy = join(root, ".vatio-sandbox.json");
|
|
318
|
-
if (existsSync(legacy)) rmSync(legacy);
|
|
319
|
-
}
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// push / publish / rollback / status / diff
|
|
1
|
+
// push / publish / rollback / status / diff.
|
|
2
2
|
//
|
|
3
3
|
// Every one of them is HTTP. The workspace is parsed by the platform
|
|
4
4
|
// (POST /deploy/check), so what is left here is: read the directory, send it,
|
|
@@ -38,7 +38,7 @@ export function deployClient(config, workspace) {
|
|
|
38
38
|
const token = config.resolveToken();
|
|
39
39
|
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
|
|
40
40
|
|
|
41
|
-
return new ApiClient({ baseUrl: `${base}/api/v1/${workspace}`, token });
|
|
41
|
+
return new ApiClient({ baseUrl: `${base}/api/developer/v1/${workspace}`, token });
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function workspacesClient(config) {
|
|
@@ -82,21 +82,6 @@ function diagnosticLine(row) {
|
|
|
82
82
|
return `${path}: ${message}`;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export async function toolsCheck(config, args) {
|
|
86
|
-
if (args[0] === "invoke") {
|
|
87
|
-
fail("`vatio tools invoke` was removed. Test tools inside `vatio chat` so access/auth run in the agent loop.");
|
|
88
|
-
}
|
|
89
|
-
if (args.length > 0 && args[0] !== "check") fail("Usage: vatio tools check");
|
|
90
|
-
|
|
91
|
-
const workspace = config.resolveWorkspaceRequired();
|
|
92
|
-
const payload = await checkWorkspace(config, workspace);
|
|
93
|
-
printDiagnostics(payload);
|
|
94
|
-
if (!payload.ok) fail(`tools check failed (${asArray(payload.errors).length} error(s))`);
|
|
95
|
-
|
|
96
|
-
const tools = asArray(payload.manifest?.tools);
|
|
97
|
-
console.log(`tools check ok (${tools.length} tool(s))`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
85
|
export async function push(config, args) {
|
|
101
86
|
// Null, not "preview": the platform owns that default, and sending it
|
|
102
87
|
// explicitly would make a bare `vatio push` and `vatio push --env preview`
|