@vatio-ai/cli 0.133.0 → 0.135.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/bin/vatio.mjs +28 -3
- package/lib/api-client.mjs +31 -6
- package/lib/bundle.mjs +1 -1
- package/lib/commands/auth.mjs +1 -1
- package/lib/commands/channels.mjs +14 -3
- package/lib/commands/chat.mjs +50 -48
- package/lib/commands/deploy.mjs +1 -1
- package/lib/commands/improve.mjs +19 -32
- package/lib/commands/owner.mjs +159 -0
- package/lib/commands/reach.mjs +104 -0
- package/lib/commands/support-commands.mjs +1 -1
- package/lib/commands/team.mjs +43 -6
- package/lib/commands/webhooks.mjs +1 -1
- package/lib/commands/workspace-admin.mjs +4 -2
- package/lib/config.mjs +1 -1
- package/lib/device-auth.mjs +3 -3
- package/lib/help.mjs +36 -4
- package/lib/http.mjs +12 -3
- package/lib/suggest.mjs +10 -1
- package/lib/telemetry.mjs +10 -3
- package/lib/workspace.mjs +1 -1
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -26,6 +26,8 @@ import { team } from "../lib/commands/team.mjs";
|
|
|
26
26
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
27
27
|
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
28
28
|
import { test, tools } from "../lib/commands/improve.mjs";
|
|
29
|
+
import { activity, plan, security, supportAccess, transfer, workspace } from "../lib/commands/owner.mjs";
|
|
30
|
+
import { analytics, testers, widget } from "../lib/commands/reach.mjs";
|
|
29
31
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
30
32
|
import { runLatest } from "../lib/run-latest.mjs";
|
|
31
33
|
import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/telemetry.mjs";
|
|
@@ -35,8 +37,6 @@ import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/tel
|
|
|
35
37
|
const RETIRED = {
|
|
36
38
|
issue: "was removed: report a problem on the public repository it belongs to --\n" +
|
|
37
39
|
"https://github.com/vatio-ai/cli/issues (or sdk, ios, ruby under github.com/vatio-ai).",
|
|
38
|
-
widget: "was removed: `vatio env` prints the snippet and its token, and the look is edited in\n" +
|
|
39
|
-
"the inbox, under Channels → Widget.",
|
|
40
40
|
mcp: "was removed: the Vatio MCP is https://vatio.ai/mcp, and `npx @vatio-ai/skills` adds it to a project.",
|
|
41
41
|
update: "is npm's job: `npx @vatio-ai/cli@latest` always runs the current release, and\n" +
|
|
42
42
|
"`npm install -g @vatio-ai/cli@latest` updates a global install.\n" +
|
|
@@ -133,6 +133,24 @@ async function run(command, args) {
|
|
|
133
133
|
return await test(config, args);
|
|
134
134
|
case "tools":
|
|
135
135
|
return await tools(config, args);
|
|
136
|
+
case "widget":
|
|
137
|
+
return await widget(config, args);
|
|
138
|
+
case "analytics":
|
|
139
|
+
return await analytics(config, args);
|
|
140
|
+
case "testers":
|
|
141
|
+
return await testers(config, args);
|
|
142
|
+
case "security":
|
|
143
|
+
return await security(config, args);
|
|
144
|
+
case "activity":
|
|
145
|
+
return await activity(config, args);
|
|
146
|
+
case "support-access":
|
|
147
|
+
return await supportAccess(config, args);
|
|
148
|
+
case "transfer":
|
|
149
|
+
return await transfer(config, args);
|
|
150
|
+
case "workspace":
|
|
151
|
+
return await workspace(config, args);
|
|
152
|
+
case "plan":
|
|
153
|
+
return await plan(config, args);
|
|
136
154
|
case "changelog":
|
|
137
155
|
return await changelog(config, args);
|
|
138
156
|
case "docs":
|
|
@@ -174,8 +192,15 @@ function printError(error) {
|
|
|
174
192
|
console.error("Authentication failed (401). Run `vatio login`.");
|
|
175
193
|
return printTrailer(error);
|
|
176
194
|
}
|
|
195
|
+
// The platform says why, in the same words the MCP and the inbox get; the
|
|
196
|
+
// generic lines below are for an answer that does not.
|
|
197
|
+
const said = error?.body?.error_description;
|
|
177
198
|
if (error instanceof ForbiddenError) {
|
|
178
|
-
console.error("Access denied (403). Your token cannot access this workspace.");
|
|
199
|
+
console.error(said ? `Access denied (403): ${said}` : "Access denied (403). Your token cannot access this workspace.");
|
|
200
|
+
return printTrailer(error);
|
|
201
|
+
}
|
|
202
|
+
if (error instanceof NotFoundError && said && error.body.error !== "workspace_not_found") {
|
|
203
|
+
console.error(`Not found (404): ${said}`);
|
|
179
204
|
return printTrailer(error);
|
|
180
205
|
}
|
|
181
206
|
if (error instanceof NotFoundError) {
|
package/lib/api-client.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// Everything the CLI can ask of one workspace: /api/
|
|
1
|
+
// Everything the CLI can ask of one workspace: /api/v1/:slug/*, the API the MCP
|
|
2
|
+
// and the inbox call too (Api::V1::BaseController on the platform).
|
|
2
3
|
//
|
|
3
4
|
// One class rather than a client per surface. They share a host, a token and an
|
|
4
5
|
// error contract, and splitting them only ever meant passing the same three
|
|
@@ -251,6 +252,18 @@ export class ApiClient extends HttpClient {
|
|
|
251
252
|
return this.post("/members", body);
|
|
252
253
|
}
|
|
253
254
|
|
|
255
|
+
updateMember(id, body) {
|
|
256
|
+
return this.patch(`/members/${encode(id)}`, body);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
removeMember(id) {
|
|
260
|
+
return this.delete(`/members/${encode(id)}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
resendMember(id) {
|
|
264
|
+
return this.post(`/members/${encode(id)}/resend`, {});
|
|
265
|
+
}
|
|
266
|
+
|
|
254
267
|
// --- quiet hours ----------------------------------------------------
|
|
255
268
|
|
|
256
269
|
// The weekly schedule in which the agent does not answer, or null.
|
|
@@ -357,15 +370,27 @@ export class ApiClient extends HttpClient {
|
|
|
357
370
|
|
|
358
371
|
// `files` are `{ name, bytes }`, sent as the public API takes a visitor's
|
|
359
372
|
// (multipart `files[]`), so the agent reads them as it would on the web.
|
|
360
|
-
|
|
361
|
-
|
|
373
|
+
// `wait`: answer once the turn is over (or the wait runs out, at most 20
|
|
374
|
+
// seconds), with what it said (Vatio::Preview::Turn on the platform).
|
|
375
|
+
sendChatMessage({ chatId, content, files = [], wait = null }) {
|
|
376
|
+
if (files.length === 0) {
|
|
377
|
+
const body = { content };
|
|
378
|
+
if (wait) body.wait = wait;
|
|
379
|
+
return this.post(`/chats/${encode(chatId)}/messages`, body);
|
|
380
|
+
}
|
|
362
381
|
|
|
363
382
|
const form = new FormData();
|
|
364
383
|
if (content) form.set("content", content);
|
|
384
|
+
if (wait) form.set("wait", String(wait));
|
|
365
385
|
for (const file of files) form.append("files[]", new Blob([file.bytes]), file.name);
|
|
366
386
|
return this.post(`/chats/${encode(chatId)}/messages`, form);
|
|
367
387
|
}
|
|
368
388
|
|
|
389
|
+
// The turn that answers message `after`, waiting up to `wait` seconds more.
|
|
390
|
+
chatTurn({ chatId, after, wait }) {
|
|
391
|
+
return this.get(`/chats/${encode(chatId)}/turn`, { after, wait });
|
|
392
|
+
}
|
|
393
|
+
|
|
369
394
|
exportChats({ from, to = null, environment = null, channel = null, after = null }) {
|
|
370
395
|
const params = { from };
|
|
371
396
|
if (to) params.to = to;
|
|
@@ -377,17 +402,17 @@ export class ApiClient extends HttpClient {
|
|
|
377
402
|
|
|
378
403
|
}
|
|
379
404
|
|
|
380
|
-
// /api/
|
|
405
|
+
// /api/v1/workspaces -- not workspace-scoped, so it takes the bare host.
|
|
381
406
|
export class CliClient extends HttpClient {
|
|
382
407
|
listWorkspaces() {
|
|
383
|
-
return this.get("/api/
|
|
408
|
+
return this.get("/api/v1/workspaces");
|
|
384
409
|
}
|
|
385
410
|
|
|
386
411
|
createWorkspace({ slug, name = null, organization = null }) {
|
|
387
412
|
const body = { slug };
|
|
388
413
|
if (String(name ?? "").trim() !== "") body.name = String(name).trim();
|
|
389
414
|
if (String(organization ?? "").trim() !== "") body.organization = String(organization).trim().toLowerCase();
|
|
390
|
-
return this.post("/api/
|
|
415
|
+
return this.post("/api/v1/workspaces", body);
|
|
391
416
|
}
|
|
392
417
|
|
|
393
418
|
async workspaceExists(slug) {
|
package/lib/bundle.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The workspace directory as the bytes that go on the wire, for
|
|
2
|
-
// POST /api/
|
|
2
|
+
// POST /api/v1/:slug/check. The port of cli/lib/workspace_bundle.rb.
|
|
3
3
|
//
|
|
4
4
|
// There is deliberately no list here of "the files a manifest reads". That list
|
|
5
5
|
// *is* the contract -- `widget.logo` and `identity.public_key` name files from
|
package/lib/commands/auth.mjs
CHANGED
|
@@ -98,7 +98,7 @@ export async function logout(config) {
|
|
|
98
98
|
let revoked = false;
|
|
99
99
|
if (token) {
|
|
100
100
|
try {
|
|
101
|
-
const response = await fetch(`${config.resolveBaseUrl()}/api/
|
|
101
|
+
const response = await fetch(`${config.resolveBaseUrl()}/api/v1/session`, {
|
|
102
102
|
method: "DELETE",
|
|
103
103
|
headers: { ...clientHeaders(), Accept: "application/json", Authorization: `Bearer ${token}` },
|
|
104
104
|
signal: AbortSignal.timeout(LOGOUT_TIMEOUT_MS)
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { deployClient, whatsappIssueLines } from "./deploy.mjs";
|
|
9
9
|
import { messages } from "./messages.mjs";
|
|
10
10
|
import { withSecondFactor } from "./team.mjs";
|
|
11
|
+
import { errorCode } from "../http.mjs";
|
|
11
12
|
import { templates } from "./webhooks.mjs";
|
|
12
13
|
import { ask, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
13
14
|
|
|
@@ -112,12 +113,22 @@ async function inInbox(config, channel) {
|
|
|
112
113
|
console.log(` ${published ? url : (status.try_url ?? url)}`);
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
// What `vatio whatsapp --json` has always printed: the number, not everything
|
|
117
|
+
// the inbox's WhatsApp page draws from the same answer.
|
|
118
|
+
const NUMBER_KEYS = ["connect_url", "connected", "number", "live", "state", "issue", "last_health_error",
|
|
119
|
+
"last_health_check_at", "failed_deliveries", "wa_me_url"];
|
|
120
|
+
|
|
121
|
+
function numberOnly(answer) {
|
|
122
|
+
return Object.fromEntries(NUMBER_KEYS.filter((key) => key in answer).map((key) => [key, answer[key]]));
|
|
123
|
+
}
|
|
124
|
+
|
|
115
125
|
async function status(config, client, { json }) {
|
|
116
126
|
let number = null;
|
|
117
127
|
try {
|
|
118
|
-
|
|
128
|
+
const answer = await client.getWhatsapp();
|
|
129
|
+
if (answer.connected !== false) number = numberOnly(answer);
|
|
119
130
|
} catch (error) {
|
|
120
|
-
if (error
|
|
131
|
+
if (errorCode(error) !== "whatsapp_not_connected") throw error;
|
|
121
132
|
}
|
|
122
133
|
if (json) return console.log(JSON.stringify(number ?? { connected: false }, null, 2));
|
|
123
134
|
// A number Meta refuses every send from comes before anything else.
|
|
@@ -169,7 +180,7 @@ function printTeam({ members = [] }, { json }) {
|
|
|
169
180
|
}
|
|
170
181
|
|
|
171
182
|
function printNumber(number, { json = false, checked = false } = {}) {
|
|
172
|
-
if (json) return console.log(JSON.stringify(number, null, 2));
|
|
183
|
+
if (json) return console.log(JSON.stringify(numberOnly(number), null, 2));
|
|
173
184
|
const name = number.number ?? "Your number";
|
|
174
185
|
if (number.issue) {
|
|
175
186
|
console.log("");
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
// does the widget's and WhatsApp's, so this gives you nothing you did not
|
|
14
14
|
// already hold (lib/visitor-identity.mjs, Vatio::Preview::Tester).
|
|
15
15
|
|
|
16
|
+
import { conversation } from "./reach.mjs";
|
|
16
17
|
import { randomBytes } from "node:crypto";
|
|
17
18
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
18
19
|
import { basename, dirname, join } from "node:path";
|
|
19
20
|
|
|
20
21
|
import { ApiClient } from "../api-client.mjs";
|
|
21
22
|
import { configHome } from "../config.mjs";
|
|
22
|
-
import { fail,
|
|
23
|
+
import { fail, takeAll, takeEnv, takeFlag, takeSide, takeValue } from "../support.mjs";
|
|
23
24
|
import { IDENTITY_FLAGS_USAGE, takeIdentity, tokenFor } from "../visitor-identity.mjs";
|
|
24
25
|
|
|
25
26
|
export const STATE_FILE = ".vatio-chat.json";
|
|
@@ -46,6 +47,7 @@ export async function chat(config, args) {
|
|
|
46
47
|
// Not a conversation of your own, so none of what follows applies to it,
|
|
47
48
|
// and its --from and --channel mean dates and a channel to read.
|
|
48
49
|
if (args[0] === "export") return await exportChats(config, args.slice(1));
|
|
50
|
+
if (args[0] === "reply" || args[0] === "release") return await conversation(config, args[0], args.slice(1));
|
|
49
51
|
|
|
50
52
|
for (const arg of args) {
|
|
51
53
|
if (REMOVED_FLAGS.some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
@@ -372,14 +374,53 @@ function speaker(payload) {
|
|
|
372
374
|
async function converse(config, options, message, opened = null) {
|
|
373
375
|
const api = client(config, options);
|
|
374
376
|
const chatId = opened ?? (await chatToContinue(config, options));
|
|
375
|
-
const
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
377
|
+
const turn = await sendAndWait(api, { chatId, content: message, files: options.files ?? [], timeout: options.timeout });
|
|
378
|
+
if (options.files?.length > 0) for (const attachment of turn.sent_attachments ?? []) console.log(attachmentLine(attachment));
|
|
379
|
+
console.log(turnLines(turn, chatId).join("\n"));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// The longest one request waits on the platform; past it, the turn is read
|
|
383
|
+
// again until `timeout`.
|
|
384
|
+
const TURN_WAIT = 20;
|
|
385
|
+
|
|
386
|
+
// Sends the message and waits for the whole turn that answers it, as the
|
|
387
|
+
// MCP's chat_with_agent does (Vatio::Preview::Turn): not the first draft, which
|
|
388
|
+
// a safeguard may throw away, but what the visitor got.
|
|
389
|
+
async function sendAndWait(api, { chatId, content, files, timeout }) {
|
|
390
|
+
const deadline = Date.now() + timeout * 1000;
|
|
391
|
+
let turn = await api.sendChatMessage({ chatId, content, files, wait: Math.min(TURN_WAIT, timeout) });
|
|
392
|
+
while (turn.turn === "answering") {
|
|
393
|
+
const left = Math.ceil((deadline - Date.now()) / 1000);
|
|
394
|
+
if (left <= 0) fail(`Timed out waiting for the agent's reply after ${timeout}s: \`vatio chat show ${chatId}\` reads it later.`);
|
|
395
|
+
turn = await api.chatTurn({ chatId, after: turn.user_message_id, wait: Math.min(TURN_WAIT, left) });
|
|
396
|
+
}
|
|
397
|
+
return turn;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// What the turn said: every reply the visitor got, in order (a paced agent
|
|
401
|
+
// sends several), what a safeguard changed, and why there is none when there
|
|
402
|
+
// is none.
|
|
403
|
+
function turnLines(turn, chatId) {
|
|
404
|
+
if (turn.turn === "taken_over") {
|
|
405
|
+
return ["Someone on the team took this conversation over in the inbox, so the agent does not answer it " +
|
|
406
|
+
`until they hand it back (vatio chat release ${chatId}).`];
|
|
407
|
+
}
|
|
408
|
+
const entries = turn.entries ?? [];
|
|
409
|
+
const replies = entries.filter((entry) => entry.role === "assistant" && visitorVisible(entry));
|
|
410
|
+
const notes = entries.flatMap((entry) => (safeguardNote(entry.safeguard) ? [safeguardNote(entry.safeguard)] : []));
|
|
411
|
+
if (replies.length === 0) {
|
|
412
|
+
const why = turn.quiet_hours
|
|
413
|
+
? "Quiet hours are on, so the agent did not answer; the message waits in the inbox."
|
|
414
|
+
: "The turn ended without a reply.";
|
|
415
|
+
return [why, ...notes, `vatio chat show ${chatId} shows the whole turn.`];
|
|
416
|
+
}
|
|
417
|
+
return [...replies.map((reply) => formatVisitor(reply)), ...notes];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function safeguardNote(safeguard) {
|
|
421
|
+
if (!safeguard || !safeguard.policy) return null;
|
|
422
|
+
const done = safeguard.action === "discarded" ? "discarded a draft and asked the model again" : "rewrote the reply before it went out";
|
|
423
|
+
return `(the ${safeguard.policy} safeguard ${done})`;
|
|
383
424
|
}
|
|
384
425
|
|
|
385
426
|
function readFiles(paths) {
|
|
@@ -399,14 +440,6 @@ function readFiles(paths) {
|
|
|
399
440
|
});
|
|
400
441
|
}
|
|
401
442
|
|
|
402
|
-
// The message as stored, by the id the send returned: what was read of each
|
|
403
|
-
// file by the time the agent answered.
|
|
404
|
-
async function printSentFiles(api, chatId, messageId) {
|
|
405
|
-
const payload = await api.chatMessages({ chatId, after: messageId - 1 });
|
|
406
|
-
const stored = (Array.isArray(payload.data) ? payload.data : []).find((entry) => entry.id === messageId);
|
|
407
|
-
for (const attachment of stored?.attachments ?? []) console.log(attachmentLine(attachment));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
443
|
// One file a message carried, and what the agent was given of it: a PDF's
|
|
411
444
|
// reading (Vatio::Runtime::MediaPolicy.document_reading), or a video's
|
|
412
445
|
// description.
|
|
@@ -444,21 +477,6 @@ const visitorVisible = (entry) =>
|
|
|
444
477
|
["user", "assistant"].includes(entry.role) &&
|
|
445
478
|
String(entry.content ?? "").trim() !== "";
|
|
446
479
|
|
|
447
|
-
// Conversations are asynchronous: post a message, then poll for the reply.
|
|
448
|
-
async function waitForAssistant(api, { chatId, after, timeout, interval = 2 }) {
|
|
449
|
-
const deadline = Date.now() + timeout * 1000;
|
|
450
|
-
for (;;) {
|
|
451
|
-
const payload = await api.chatMessages({ chatId, after });
|
|
452
|
-
const messages = Array.isArray(payload.data) ? payload.data : [];
|
|
453
|
-
const assistant = [...messages]
|
|
454
|
-
.reverse()
|
|
455
|
-
.find((entry) => entry.role === "assistant" && visitorVisible(entry));
|
|
456
|
-
if (assistant) return assistant;
|
|
457
|
-
if (Date.now() >= deadline) fail(`Timed out waiting for assistant reply after ${timeout}s`);
|
|
458
|
-
await sleep(interval * 1000);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
480
|
// Every message, not the first page: a chat worth reading by id is usually one
|
|
463
481
|
// that went wrong somewhere in the middle.
|
|
464
482
|
async function allMessages(api, chatId) {
|
|
@@ -598,22 +616,6 @@ function truncate(text, max) {
|
|
|
598
616
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
599
617
|
}
|
|
600
618
|
|
|
601
|
-
// One question in a new chat, for `vatio test add "QUESTION" "WHAT IT SHOULD
|
|
602
|
-
// DO"`: the chat becomes the one `vatio chat` continues, and the reply is the
|
|
603
|
-
// one the test is made on.
|
|
604
|
-
export async function askInNewChat(config, { environment, asPhone = null, identity = null, timeout = 120 }, question) {
|
|
605
|
-
const options = { environment, asPhone, identity, timeout, apiUrl: null, token: null };
|
|
606
|
-
const apiUrl = config.resolveApiUrl({ explicit: null });
|
|
607
|
-
const payload = await openChat(config, options, { apiUrl, chatId: chatsFor(config, apiUrl)[environment] ?? null });
|
|
608
|
-
const chatId = Number(payload.chat_id);
|
|
609
|
-
const api = client(config, options);
|
|
610
|
-
const sent = await api.sendChatMessage({ chatId, content: question });
|
|
611
|
-
const reply = await waitForAssistant(api, { chatId, after: sent.user_message_id, timeout });
|
|
612
|
-
console.log(`[you] ${question}`);
|
|
613
|
-
console.log(formatVisitor(reply));
|
|
614
|
-
return reply;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
619
|
async function startOver(config, options) {
|
|
618
620
|
const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
|
|
619
621
|
const payload = await openChat(config, options, {
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export function deployClient(config, workspace) {
|
|
|
49
49
|
const token = config.resolveToken();
|
|
50
50
|
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
|
|
51
51
|
|
|
52
|
-
return new ApiClient({ baseUrl: `${base}/api/
|
|
52
|
+
return new ApiClient({ baseUrl: `${base}/api/v1/${workspace}`, token });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export function workspacesClient(config) {
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
|
|
|
11
11
|
import { dirname, resolve } from "node:path";
|
|
12
12
|
|
|
13
13
|
import { HttpClient, NotFoundError, throwIfOutdated } from "../http.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { rememberedChatId } from "./chat.mjs";
|
|
15
15
|
import { clientHeaders } from "../telemetry.mjs";
|
|
16
16
|
import { fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
17
17
|
import { printSkillsHint } from "../skills-hint.mjs";
|
|
@@ -27,7 +27,7 @@ function workspaceBase(config) {
|
|
|
27
27
|
const base = config.resolveBaseUrl();
|
|
28
28
|
const token = config.resolveToken();
|
|
29
29
|
if (!token) fail(`Run \`vatio login\` first (no token in ${config.configPath})`);
|
|
30
|
-
return { url: `${base}/api/
|
|
30
|
+
return { url: `${base}/api/v1/${config.resolveWorkspaceRequired()}`, token };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async function fetchMarkdown(config, path, what) {
|
|
@@ -101,8 +101,9 @@ const TEST_ADD_USAGE =
|
|
|
101
101
|
// With a question, Vatio asks it in a new chat and the test is made on that
|
|
102
102
|
// turn; with only what it should do, on the agent's last reply in the chat
|
|
103
103
|
// `vatio chat` is in, or --chat's, or --message's (a reply a visitor got, or a
|
|
104
|
-
// report's, whose note it rewrites).
|
|
105
|
-
//
|
|
104
|
+
// report's, whose note it rewrites). The platform saves and judges it in the
|
|
105
|
+
// background, the way the MCP's add_test does; this waits for the verdict, so
|
|
106
|
+
// you know whether the test is a guard or work still to do.
|
|
106
107
|
async function addTest(config, args) {
|
|
107
108
|
const environment = takeEnv(args, { fallback: "preview" });
|
|
108
109
|
const chatId = takeValue(args, "--chat");
|
|
@@ -117,46 +118,32 @@ async function addTest(config, args) {
|
|
|
117
118
|
const [first, second] = args.map((arg) => arg.trim());
|
|
118
119
|
if (!first || (args.length === 2 && !second)) fail(`Usage: ${TEST_ADD_USAGE}`);
|
|
119
120
|
|
|
120
|
-
let
|
|
121
|
-
let note;
|
|
121
|
+
let body;
|
|
122
122
|
if (args.length === 2) {
|
|
123
123
|
if (chatId || messageId) fail("A question opens its own chat: drop --chat and --message, or the question.");
|
|
124
|
-
|
|
125
|
-
target = { message_id: reply.id };
|
|
126
|
-
note = second;
|
|
124
|
+
body = { question: first, should: second, environment, as_phone: asPhone, visitor_token: identity ? tokenFor(identity) : null };
|
|
127
125
|
} else {
|
|
128
126
|
if (asPhone || identity) fail("--as-phone and --as-subject go with a question: `vatio test add \"QUESTION\" \"WHAT IT SHOULD DO\"`.");
|
|
129
127
|
if (chatId && messageId) fail(`--chat or --message, not both. Usage: ${TEST_ADD_USAGE}`);
|
|
130
|
-
target = messageId ? { message_id: messageId } : { chat_id: chatId ?? rememberedChatId(config, environment) };
|
|
128
|
+
const target = messageId ? { message_id: messageId } : { chat_id: chatId ?? rememberedChatId(config, environment) };
|
|
131
129
|
if (!target.message_id && !target.chat_id) {
|
|
132
130
|
fail(`No ${environment} chat yet: \`vatio test add "QUESTION" "WHAT IT SHOULD DO"\` asks it, or pass --chat ID or --message ID.`);
|
|
133
131
|
}
|
|
134
|
-
|
|
132
|
+
body = { ...target, should: first };
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
const { url, token } = workspaceBase(config);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log(`${added.rewritten ? "Rewrote" : "Added"} ${what} (agent \`${added.agent}\`, chat ${added.chat_id}):`);
|
|
148
|
-
console.log(` Visitor: ${String(added.asked ?? "").trim().replace(/\s+/g, " ").slice(0, 200)}`);
|
|
149
|
-
console.log(` Should: ${added.note}`);
|
|
150
|
-
const judged = added.judged ?? {};
|
|
151
|
-
if (judged.verdict === "pass") {
|
|
152
|
-
console.log(` Passes now: ${judged.reason}`);
|
|
153
|
-
console.log("`vatio test` replays it on every version; once everyone's version passes it, a change that fails it does not reach them.");
|
|
154
|
-
} else if (judged.verdict === "fail") {
|
|
155
|
-
console.log(` Fails now: ${judged.reason}`);
|
|
156
|
-
console.log("Fix the agent, `vatio push`, then `vatio test`: `vatio test list` shows it with its replay once it has run.");
|
|
157
|
-
} else {
|
|
158
|
-
console.log(` Not judged now${judged.error ? `: ${judged.error}` : ""}. \`vatio test\` judges it with the rest.`);
|
|
136
|
+
const api = new HttpClient({ baseUrl: url, token });
|
|
137
|
+
const deadline = Date.now() + timeout * 1000;
|
|
138
|
+
let answer = await api.post("/evals/cases", Object.fromEntries(Object.entries(body).filter(([, value]) => value)));
|
|
139
|
+
while (!answer.text) {
|
|
140
|
+
if (Date.now() >= deadline) {
|
|
141
|
+
fail(`Still ${answer.status} after ${timeout}s: \`vatio test list\` shows the test once it is saved.`);
|
|
142
|
+
}
|
|
143
|
+
await sleep(Math.max(1, Math.min(answer.check_in_seconds ?? 5, (deadline - Date.now()) / 1000)) * 1000);
|
|
144
|
+
answer = await api.get("/evals/cases/lookup", { chat_id: answer.chat_id });
|
|
159
145
|
}
|
|
146
|
+
console.log(answer.text);
|
|
160
147
|
}
|
|
161
148
|
|
|
162
149
|
// What there is to fix, then the whole suite: the reports still open, each
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// The owner's side of the workspace, as the inbox's Security, Activity and
|
|
2
|
+
// Plan pages have it: how it is protected, what happened in it, letting Vatio
|
|
3
|
+
// in, handing it over, deleting it, and its plan. The same API the MCP's
|
|
4
|
+
// workspace tools call. What outlives a support grant needs a fresh code from
|
|
5
|
+
// the owner's second factor (--code), as `vatio team invite` does.
|
|
6
|
+
|
|
7
|
+
import { deployClient, workspacesClient } from "./deploy.mjs";
|
|
8
|
+
import { withSecondFactor } from "./team.mjs";
|
|
9
|
+
import { ask, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
10
|
+
|
|
11
|
+
const print = (answer) => console.log(JSON.stringify(answer, null, 2));
|
|
12
|
+
|
|
13
|
+
const SECURITY_USAGE = "Usage: vatio security [show] [--json]\n" +
|
|
14
|
+
" vatio security set [--require-2fa on|off] [--retention-days N]";
|
|
15
|
+
|
|
16
|
+
export async function security(config, args) {
|
|
17
|
+
const json = takeFlag(args, "--json");
|
|
18
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
19
|
+
const sub = args.shift() ?? "show";
|
|
20
|
+
if (sub === "show") {
|
|
21
|
+
if (args.length) fail(SECURITY_USAGE);
|
|
22
|
+
return showSecurity(await client.get("/security"), json);
|
|
23
|
+
}
|
|
24
|
+
if (sub === "set") {
|
|
25
|
+
const require2fa = takeValue(args, "--require-2fa");
|
|
26
|
+
const retention = takeValue(args, "--retention-days");
|
|
27
|
+
if (args.length || (require2fa === null && retention === null)) fail(SECURITY_USAGE);
|
|
28
|
+
if (require2fa !== null && !["on", "off"].includes(require2fa)) fail(SECURITY_USAGE);
|
|
29
|
+
const body = {};
|
|
30
|
+
if (require2fa !== null) body.require_two_factor = require2fa === "on";
|
|
31
|
+
if (retention !== null) body.retention_days = Number(retention);
|
|
32
|
+
return showSecurity(await client.patch("/security", body), json);
|
|
33
|
+
}
|
|
34
|
+
fail(SECURITY_USAGE);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function showSecurity(answer, json) {
|
|
38
|
+
if (json) return print(answer);
|
|
39
|
+
console.log(`Two-step verification for everyone: ${answer.require_two_factor ? "required" : "not required"}`);
|
|
40
|
+
console.log(`Conversations kept: ${answer.retention_days ? `${answer.retention_days} days` : "until deleted"}`);
|
|
41
|
+
if (answer.members_without_two_factor) {
|
|
42
|
+
console.log(`${answer.members_without_two_factor} on the team have no second factor yet.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ACTIVITY_USAGE = "Usage: vatio activity [--category NAME] [--page N] [--json]";
|
|
47
|
+
|
|
48
|
+
export async function activity(config, args) {
|
|
49
|
+
const json = takeFlag(args, "--json");
|
|
50
|
+
const category = takeValue(args, "--category");
|
|
51
|
+
const page = takeValue(args, "--page");
|
|
52
|
+
if (args.length) fail(ACTIVITY_USAGE);
|
|
53
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
54
|
+
const answer = await client.get("/activity", { category, page });
|
|
55
|
+
if (json) return print(answer);
|
|
56
|
+
for (const event of answer.data ?? []) {
|
|
57
|
+
console.log(`${String(event.at ?? event.created_at ?? "").slice(0, 16).replace("T", " ")} ${event.who ?? event.who_label ?? "Vatio"} ${event.label ?? event.action}`);
|
|
58
|
+
}
|
|
59
|
+
if ((answer.data ?? []).length === 0) console.log("Nothing yet.");
|
|
60
|
+
if (answer.meta?.next_page) console.log(`More: vatio activity --page ${answer.meta.next_page}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const SUPPORT_USAGE = "Usage: vatio support-access [show] [--json]\n" +
|
|
64
|
+
" vatio support-access open 24h|72h|7d\n" +
|
|
65
|
+
" vatio support-access close";
|
|
66
|
+
|
|
67
|
+
export async function supportAccess(config, args) {
|
|
68
|
+
const json = takeFlag(args, "--json");
|
|
69
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
70
|
+
const sub = args.shift() ?? "show";
|
|
71
|
+
let answer;
|
|
72
|
+
if (sub === "show") answer = await client.get("/support_access");
|
|
73
|
+
else if (sub === "open") {
|
|
74
|
+
const duration = args.shift();
|
|
75
|
+
if (!duration || args.length) fail(SUPPORT_USAGE);
|
|
76
|
+
answer = await client.post("/support_access", { duration });
|
|
77
|
+
} else if (sub === "close") answer = await client.delete("/support_access");
|
|
78
|
+
else fail(SUPPORT_USAGE);
|
|
79
|
+
if (json) return print(answer);
|
|
80
|
+
const active = answer.active ?? [];
|
|
81
|
+
if (active.length === 0) return console.log("Vatio staff cannot open this workspace.");
|
|
82
|
+
for (const grant of active) console.log(`Open until ${grant.expires_at} (${grant.kind ?? "granted"})`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const TRANSFER_USAGE = "Usage: vatio transfer [show] [--json]\n" +
|
|
86
|
+
" vatio transfer offer EMAIL [--code CODE | --recovery-code CODE]\n" +
|
|
87
|
+
" vatio transfer cancel\n" +
|
|
88
|
+
" vatio transfer accept SLUG [--code CODE | --recovery-code CODE]\n" +
|
|
89
|
+
" vatio transfer decline SLUG";
|
|
90
|
+
|
|
91
|
+
export async function transfer(config, args) {
|
|
92
|
+
const json = takeFlag(args, "--json");
|
|
93
|
+
const code = takeValue(args, "--code");
|
|
94
|
+
const recoveryCode = takeValue(args, "--recovery-code");
|
|
95
|
+
const sub = args.shift() ?? "show";
|
|
96
|
+
if (sub === "accept" || sub === "decline") {
|
|
97
|
+
const slug = args.shift();
|
|
98
|
+
if (!slug || args.length) fail(TRANSFER_USAGE);
|
|
99
|
+
const account = workspacesClient(config);
|
|
100
|
+
if (sub === "decline") {
|
|
101
|
+
await account.post(`/api/v1/transfers/${encodeURIComponent(slug)}/decline`, {});
|
|
102
|
+
return console.log(`Declined ${slug}: it stays with its owner.`);
|
|
103
|
+
}
|
|
104
|
+
await withSecondFactor((body) => account.post(`/api/v1/transfers/${encodeURIComponent(slug)}/accept`, body),
|
|
105
|
+
{ code, recovery_code: recoveryCode });
|
|
106
|
+
return console.log(`${paint("green", "✓")} ${slug} is yours now.`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
110
|
+
let answer;
|
|
111
|
+
if (sub === "show") answer = await client.get("/transfer");
|
|
112
|
+
else if (sub === "offer") {
|
|
113
|
+
const email = args.shift();
|
|
114
|
+
if (!email || args.length) fail(TRANSFER_USAGE);
|
|
115
|
+
answer = await withSecondFactor((body) => client.post("/transfer", body), { email, code, recovery_code: recoveryCode });
|
|
116
|
+
} else if (sub === "cancel") answer = await client.delete("/transfer");
|
|
117
|
+
else fail(TRANSFER_USAGE);
|
|
118
|
+
if (json) return print(answer);
|
|
119
|
+
if (answer?.pending) return console.log(`Offered to ${answer.pending.email ?? answer.pending.to ?? "someone"} until ${answer.pending.expires_at}.`);
|
|
120
|
+
console.log(answer?.transferable === false ? "This workspace cannot be transferred." : "No offer open.");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const WORKSPACE_USAGE = "Usage: vatio workspace delete SLUG [--yes] [--code CODE | --recovery-code CODE]";
|
|
124
|
+
|
|
125
|
+
export async function workspace(config, args) {
|
|
126
|
+
const yes = takeFlag(args, "--yes");
|
|
127
|
+
const code = takeValue(args, "--code");
|
|
128
|
+
const recoveryCode = takeValue(args, "--recovery-code");
|
|
129
|
+
const sub = args.shift();
|
|
130
|
+
const slug = args.shift();
|
|
131
|
+
if (sub !== "delete" || !slug || args.length) fail(WORKSPACE_USAGE);
|
|
132
|
+
if (slug !== config.resolveWorkspaceRequired()) {
|
|
133
|
+
fail(`${slug} is not the workspace this command is on (${config.resolveWorkspaceRequired()}): name the same one.`);
|
|
134
|
+
}
|
|
135
|
+
if (!yes) {
|
|
136
|
+
if (!process.stdin.isTTY) fail("Deleting a workspace cannot be undone, so without a terminal it needs --yes.");
|
|
137
|
+
const answer = await ask(`${paint("green", "?")} Delete ${slug} for everyone? Type its slug: `);
|
|
138
|
+
if (answer.trim() !== slug) fail("Nothing changed.");
|
|
139
|
+
}
|
|
140
|
+
const client = deployClient(config, slug);
|
|
141
|
+
await withSecondFactor((query) => client.delete(`/workspace${toQuery(query)}`), { code, recovery_code: recoveryCode });
|
|
142
|
+
console.log(`Deleted ${slug}.`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function toQuery(values) {
|
|
146
|
+
const search = new URLSearchParams(Object.entries(values).filter(([, value]) => value));
|
|
147
|
+
const text = search.toString();
|
|
148
|
+
return text ? `?${text}` : "";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function plan(config, args) {
|
|
152
|
+
const json = takeFlag(args, "--json");
|
|
153
|
+
if (args.length) fail("Usage: vatio plan [--json]");
|
|
154
|
+
const answer = await deployClient(config, config.resolveWorkspaceRequired()).get("/plan");
|
|
155
|
+
if (json) return print(answer);
|
|
156
|
+
console.log(`Plan: ${answer.plan}`);
|
|
157
|
+
console.log(`Conversations this period: ${answer.conversations} of ${answer.included}${answer.over ? " (over)" : ""}`);
|
|
158
|
+
if (answer.period) console.log(`Period: ${answer.period.from} → ${answer.period.to}`);
|
|
159
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// What the inbox shows about how the agent reaches people and how it is
|
|
2
|
+
// doing: the web widget's look, the Analytics page, the testers on Vatio's
|
|
3
|
+
// shared number and account, and a person stepping into a conversation. The
|
|
4
|
+
// same API the MCP's tools for them call.
|
|
5
|
+
|
|
6
|
+
import { deployClient } from "./deploy.mjs";
|
|
7
|
+
import { fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
8
|
+
|
|
9
|
+
const print = (answer) => console.log(JSON.stringify(answer, null, 2));
|
|
10
|
+
|
|
11
|
+
const WIDGET_USAGE = "Usage: vatio widget [show] [--json]\n" +
|
|
12
|
+
" vatio widget set [--title T] [--greeting G] [--suggestion S]... [--position left|right]\n" +
|
|
13
|
+
" [--scheme auto|light|dark] [--reply-style stream|paced] [--locale en|es|pt]\n" +
|
|
14
|
+
" A field given replaces that one; the rest stays. Name, about, color and logo are `vatio business set`.";
|
|
15
|
+
|
|
16
|
+
const WIDGET_FLAGS = { "--title": "title", "--greeting": "greeting", "--position": "position", "--scheme": "scheme",
|
|
17
|
+
"--reply-style": "reply_style" };
|
|
18
|
+
|
|
19
|
+
export async function widget(config, args) {
|
|
20
|
+
const json = takeFlag(args, "--json");
|
|
21
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
22
|
+
const sub = args.shift() ?? "show";
|
|
23
|
+
if (sub === "show") {
|
|
24
|
+
if (args.length) fail(WIDGET_USAGE);
|
|
25
|
+
return showWidget(await client.get("/widget"), json);
|
|
26
|
+
}
|
|
27
|
+
if (sub !== "set") fail(WIDGET_USAGE);
|
|
28
|
+
|
|
29
|
+
const current = await client.get("/widget");
|
|
30
|
+
const settings = { ...(current.settings && !Array.isArray(current.settings) ? current.settings : {}) };
|
|
31
|
+
for (const [flag, key] of Object.entries(WIDGET_FLAGS)) {
|
|
32
|
+
const value = takeValue(args, flag);
|
|
33
|
+
if (value !== null) settings[key] = value;
|
|
34
|
+
}
|
|
35
|
+
const suggestions = [];
|
|
36
|
+
for (let value = takeValue(args, "--suggestion"); value !== null; value = takeValue(args, "--suggestion")) suggestions.push(value);
|
|
37
|
+
if (suggestions.length) settings.suggestions = suggestions;
|
|
38
|
+
const locale = takeValue(args, "--locale");
|
|
39
|
+
if (args.length) fail(WIDGET_USAGE);
|
|
40
|
+
showWidget(await client.patch("/widget", { settings, locale: locale ?? current.locale }), json);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function showWidget(answer, json) {
|
|
44
|
+
if (json) return print(answer);
|
|
45
|
+
const settings = answer.settings && !Array.isArray(answer.settings) ? answer.settings : {};
|
|
46
|
+
const keys = Object.keys(settings);
|
|
47
|
+
console.log(keys.length ? keys.map((key) => `${key.padEnd(12)} ${JSON.stringify(settings[key])}`).join("\n") : "Vatio's defaults.");
|
|
48
|
+
if (answer.locale) console.log(`${"locale".padEnd(12)} ${answer.locale}`);
|
|
49
|
+
console.log("");
|
|
50
|
+
console.log(answer.snippet);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function analytics(config, args) {
|
|
54
|
+
const json = takeFlag(args, "--json");
|
|
55
|
+
const days = takeValue(args, "--days");
|
|
56
|
+
if (args.length) fail("Usage: vatio analytics [--days N] [--json]");
|
|
57
|
+
const answer = await deployClient(config, config.resolveWorkspaceRequired()).get("/analytics", { days });
|
|
58
|
+
if (json) return print(answer);
|
|
59
|
+
const change = (block) => (block?.previous_total ? ` (${block.previous_total} the ${answer.days} days before)` : "");
|
|
60
|
+
console.log(`Last ${answer.days} days, your customers:`);
|
|
61
|
+
console.log(` conversations ${answer.conversations?.total ?? 0}${change(answer.conversations)}`);
|
|
62
|
+
console.log(` messages ${answer.messages?.total ?? 0}${change(answer.messages)}`);
|
|
63
|
+
if (answer.saved_replies) console.log(` replies Vatio saved ${answer.saved_replies.total ?? 0}`);
|
|
64
|
+
if (answer.after_hours) console.log(` conversations after hours ${answer.after_hours.after_hours ?? 0}`);
|
|
65
|
+
if (answer.asked_team) console.log(` questions to the team ${answer.asked_team.questions ?? 0} (${answer.asked_team.answered ?? 0} answered)`);
|
|
66
|
+
if (answer.flags) console.log(` reports ${answer.flags.opened ?? 0} opened, ${answer.flags.resolved ?? 0} resolved`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const TESTERS_USAGE = "Usage: vatio testers [web|whatsapp|instagram] [--json]\n" +
|
|
70
|
+
" vatio testers rm whatsapp|instagram ID";
|
|
71
|
+
|
|
72
|
+
export async function testers(config, args) {
|
|
73
|
+
const json = takeFlag(args, "--json");
|
|
74
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
75
|
+
const sub = args.shift() ?? "whatsapp";
|
|
76
|
+
if (sub === "rm" || sub === "remove") {
|
|
77
|
+
const channel = args.shift();
|
|
78
|
+
const id = args.shift();
|
|
79
|
+
if (!["whatsapp", "instagram"].includes(channel) || !id || args.length) fail(TESTERS_USAGE);
|
|
80
|
+
await client.delete(`/test/${channel === "instagram" ? "instagram_accounts" : "whatsapp_numbers"}/${encodeURIComponent(id)}`);
|
|
81
|
+
return console.log(`${paint("green", "✓")} Removed ${channel} tester ${id}.`);
|
|
82
|
+
}
|
|
83
|
+
if (!["web", "whatsapp", "instagram"].includes(sub) || args.length) fail(TESTERS_USAGE);
|
|
84
|
+
print(await client.get("/test", { channel: sub }));
|
|
85
|
+
if (!json) console.log("\nThe inbox's Try the agent shows the same, with the code that adds a tester.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// `vatio chat reply ID "text"` and `vatio chat release ID`: a person on the
|
|
89
|
+
// team stepping into a customer's conversation, and handing it back.
|
|
90
|
+
export async function conversation(config, sub, args) {
|
|
91
|
+
const json = takeFlag(args, "--json");
|
|
92
|
+
const id = args.shift();
|
|
93
|
+
if (!id) fail(`Usage: vatio chat ${sub} CHAT_ID${sub === "reply" ? ' "TEXT"' : ""}`);
|
|
94
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
95
|
+
if (sub === "release") {
|
|
96
|
+
const answer = await client.post(`/conversations/${encodeURIComponent(id)}/release`, {});
|
|
97
|
+
return json ? print(answer) : console.log(`${paint("green", "✓")} The agent answers conversation ${id} again.`);
|
|
98
|
+
}
|
|
99
|
+
const content = args.join(" ").trim();
|
|
100
|
+
if (!content) fail('Usage: vatio chat reply CHAT_ID "TEXT"');
|
|
101
|
+
const answer = await client.post(`/conversations/${encodeURIComponent(id)}/messages`, { content });
|
|
102
|
+
if (json) return print(answer);
|
|
103
|
+
console.log(`${paint("green", "✓")} Sent in conversation ${id}. The agent stays out of it until \`vatio chat release ${id}\`.`);
|
|
104
|
+
}
|
|
@@ -309,7 +309,7 @@ export async function shareSession(config, args) {
|
|
|
309
309
|
|
|
310
310
|
let response;
|
|
311
311
|
try {
|
|
312
|
-
response = await fetch(`${config.resolveBaseUrl()}/api/
|
|
312
|
+
response = await fetch(`${config.resolveBaseUrl()}/api/v1/cli/transcripts`, {
|
|
313
313
|
method: "POST",
|
|
314
314
|
headers: { ...chosenHeaders(), Authorization: `Bearer ${config.resolveToken()}`, Accept: "application/json" },
|
|
315
315
|
body: form,
|
package/lib/commands/team.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
// team — who is in the workspace, and
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// team — who is in the workspace, and as what: what the inbox's Team page does,
|
|
2
|
+
// for a coding agent that is asked to "add Ana as a supervisor". The owner's
|
|
3
|
+
// alone, like the page. A person is named by their email; the platform keys
|
|
4
|
+
// them by membership, which the list gives.
|
|
5
5
|
|
|
6
6
|
import { deployClient } from "./deploy.mjs";
|
|
7
|
+
import { errorCode } from "../http.mjs";
|
|
7
8
|
import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
8
9
|
|
|
9
10
|
// The answers that say something the generic 401 and 403 lines would hide.
|
|
10
11
|
const SAYS_WHY = new Set(["owner_only", "reauthentication_required", "invalid_confirmation"]);
|
|
11
12
|
|
|
12
13
|
function explain(error) {
|
|
13
|
-
const code = error
|
|
14
|
+
const code = errorCode(error);
|
|
14
15
|
if (SAYS_WHY.has(code)) fail(error.message);
|
|
15
16
|
throw error;
|
|
16
17
|
}
|
|
@@ -18,6 +19,9 @@ function explain(error) {
|
|
|
18
19
|
const ROLES = ["viewer", "supervisor", "developer"];
|
|
19
20
|
const USAGE = `Usage: vatio team [list] [--json]\n` +
|
|
20
21
|
` vatio team invite EMAIL --role ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
|
|
22
|
+
` vatio team role EMAIL ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
|
|
23
|
+
" vatio team rm EMAIL [--json]\n" +
|
|
24
|
+
" vatio team resend EMAIL [--json]\n" +
|
|
21
25
|
" With a second factor on your account, --code is the 6-digit code from your authenticator app.\n" +
|
|
22
26
|
" vatio team questions [--to EMAIL...|--none] [--template NAME [--language CODE]|--no-template] [--json]";
|
|
23
27
|
|
|
@@ -50,9 +54,42 @@ export async function team(config, args) {
|
|
|
50
54
|
return print(answer, workspace, json);
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
if (sub === "role" || sub === "rm" || sub === "remove" || sub === "resend") {
|
|
58
|
+
const code = takeValue(args, "--code");
|
|
59
|
+
const recoveryCode = takeValue(args, "--recovery-code");
|
|
60
|
+
const email = args.shift();
|
|
61
|
+
const role = sub === "role" ? args.shift() : null;
|
|
62
|
+
if (!email || args.length > 0 || (sub === "role" && !ROLES.includes(role))) fail(USAGE);
|
|
63
|
+
const member = await memberByEmail(client, email);
|
|
64
|
+
let answer;
|
|
65
|
+
if (sub === "role") {
|
|
66
|
+
answer = await withSecondFactor((confirmed) => client.updateMember(member.id, confirmed),
|
|
67
|
+
{ role, code, recovery_code: recoveryCode }).catch(explain);
|
|
68
|
+
} else if (sub === "resend") {
|
|
69
|
+
answer = await client.resendMember(member.id).catch(explain);
|
|
70
|
+
} else {
|
|
71
|
+
answer = await client.removeMember(member.id).catch(explain);
|
|
72
|
+
}
|
|
73
|
+
if (!json) {
|
|
74
|
+
const done = { role: `${member.email} is now ${role}`, resend: `Sent ${member.email} the invitation again`,
|
|
75
|
+
rm: `Removed ${member.email}: they no longer reach this workspace`, remove: `Removed ${member.email}` }[sub];
|
|
76
|
+
console.log(`${paint("green", "✓")} ${done}.`);
|
|
77
|
+
console.log("");
|
|
78
|
+
}
|
|
79
|
+
return print(answer, workspace, json);
|
|
80
|
+
}
|
|
81
|
+
|
|
53
82
|
fail(USAGE);
|
|
54
83
|
}
|
|
55
84
|
|
|
85
|
+
async function memberByEmail(client, email) {
|
|
86
|
+
const wanted = email.trim().toLowerCase();
|
|
87
|
+
const list = await client.members().catch(explain);
|
|
88
|
+
const member = (list.data ?? []).find((row) => String(row.email).toLowerCase() === wanted);
|
|
89
|
+
if (!member) fail(`${wanted} is not on this workspace's team (vatio team list).`);
|
|
90
|
+
return member;
|
|
91
|
+
}
|
|
92
|
+
|
|
56
93
|
function print(answer, workspace, json) {
|
|
57
94
|
if (json) return console.log(JSON.stringify(answer, null, 2));
|
|
58
95
|
const members = answer.data ?? [];
|
|
@@ -75,7 +112,7 @@ export async function withSecondFactor(send, body) {
|
|
|
75
112
|
try {
|
|
76
113
|
return await send(confirmed);
|
|
77
114
|
} catch (error) {
|
|
78
|
-
const needsCode = error?.status === 403 && error
|
|
115
|
+
const needsCode = error?.status === 403 && errorCode(error) === "reauthentication_required";
|
|
79
116
|
if (!needsCode || confirmed.code || confirmed.recovery_code) throw error;
|
|
80
117
|
if (!process.stdin.isTTY || !/--code/.test(error.message)) throw error;
|
|
81
118
|
const code = await askSecret(`${paint("green", "?")} Code from your authenticator app: `);
|
|
@@ -210,7 +210,7 @@ export async function webhooks(config, args) {
|
|
|
210
210
|
|
|
211
211
|
if (sub === "list") {
|
|
212
212
|
const payload = await client.listWebhookEndpoints();
|
|
213
|
-
const list = Array.isArray(payload.
|
|
213
|
+
const list = Array.isArray(payload.webhooks) ? payload.webhooks : [];
|
|
214
214
|
if (list.length === 0) {
|
|
215
215
|
console.log(`No webhook endpoints on workspace ${workspace}`);
|
|
216
216
|
console.log(" Add one: vatio webhooks create https://your-app.com/vatio/webhooks");
|
|
@@ -6,6 +6,7 @@ import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
|
|
8
8
|
import { deployClient } from "./deploy.mjs";
|
|
9
|
+
import { errorCode } from "../http.mjs";
|
|
9
10
|
import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
10
11
|
|
|
11
12
|
// The platform says which names exist (preview and live); this only keeps
|
|
@@ -113,7 +114,7 @@ function takeRepeated(args, flag) {
|
|
|
113
114
|
const KINDS = ["publishable", "secret"];
|
|
114
115
|
// What a secret key may call on the server API. The platform validates them;
|
|
115
116
|
// this list is only for the help text. `team` is never given by default.
|
|
116
|
-
const SCOPES = ["messages", "instagram", "chats", "team"];
|
|
117
|
+
const SCOPES = ["messages", "instagram", "chats", "status", "team"];
|
|
117
118
|
const KEYS_USAGE =
|
|
118
119
|
"Usage: vatio keys list [--json]|create publishable|secret [--test] [--label NAME] " +
|
|
119
120
|
"[--scope NAME]... [--code CODE | --recovery-code CODE] [--json]|revoke PREFIX";
|
|
@@ -214,6 +215,7 @@ export async function keys(config, args) {
|
|
|
214
215
|
const granted = asArray(payload.api_key?.scopes);
|
|
215
216
|
const [what, path] = granted.includes("messages")
|
|
216
217
|
? ["lists the templates your number can send", "templates"]
|
|
218
|
+
: granted.includes("status") ? ["reads where the WhatsApp number stands", "whatsapp"]
|
|
217
219
|
: granted.includes("team") ? ["lists the workspace's team", "team_members"] : [null, null];
|
|
218
220
|
if (path) {
|
|
219
221
|
console.log(`Try it (${what}):`);
|
|
@@ -244,7 +246,7 @@ async function createKey(client, { code, recoveryCode, ...fields }) {
|
|
|
244
246
|
try {
|
|
245
247
|
return await client.createApiKey({ ...fields, confirmation }).catch(explainKeyError);
|
|
246
248
|
} catch (error) {
|
|
247
|
-
const needsCode = error?.status === 403 && error
|
|
249
|
+
const needsCode = error?.status === 403 && errorCode(error) === "reauthentication_required";
|
|
248
250
|
// explainKeyError let it through only when the terminal can answer it.
|
|
249
251
|
if (!needsCode || code || recoveryCode) throw error;
|
|
250
252
|
const typed = await askSecret(`${paint("green", "?")} Code from your authenticator app: `);
|
package/lib/config.mjs
CHANGED
|
@@ -290,7 +290,7 @@ export class Config {
|
|
|
290
290
|
const base = this.resolveBaseUrl();
|
|
291
291
|
const workspace = this.resolveWorkspace();
|
|
292
292
|
if (!base || !workspace) return null;
|
|
293
|
-
return `${base}/api/
|
|
293
|
+
return `${base}/api/v1/${workspace}`;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
writeAuth({ baseUrl, token }) {
|
package/lib/device-auth.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Device-code auth (/api/
|
|
1
|
+
// Device-code auth (/api/v1/device_authorizations): the CLI asks for a code, the
|
|
2
2
|
// developer approves it in a browser, the CLI polls until a token comes back.
|
|
3
3
|
// The port of cli/lib/device_auth_client.rb.
|
|
4
4
|
//
|
|
@@ -23,11 +23,11 @@ export class DeviceAuthClient {
|
|
|
23
23
|
start({ workspace } = {}) {
|
|
24
24
|
const body = {};
|
|
25
25
|
if (workspace) body.workspace = workspace;
|
|
26
|
-
return this.#post("/api/
|
|
26
|
+
return this.#post("/api/v1/device_authorizations", body);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
poll({ deviceCode }) {
|
|
30
|
-
return this.#post("/api/
|
|
30
|
+
return this.#post("/api/v1/device_authorizations/token", { device_code: deviceCode });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async #post(path, body) {
|
package/lib/help.mjs
CHANGED
|
@@ -97,6 +97,14 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
97
97
|
line as JSON: your customers', or your team's own
|
|
98
98
|
with --team. Any team member,
|
|
99
99
|
viewers included; every call is in the activity
|
|
100
|
+
chat reply CHAT_ID "TEXT" Write in a customer's conversation as a person on the
|
|
101
|
+
team: the agent stays out of it until
|
|
102
|
+
chat release CHAT_ID hands it back to the agent
|
|
103
|
+
analytics [--days N] The inbox's Analytics: conversations, messages, replies
|
|
104
|
+
Vatio saved, after hours, questions to the team
|
|
105
|
+
testers [web|whatsapp|instagram] | rm whatsapp|instagram ID
|
|
106
|
+
Who reaches your team's version on Vatio's shared
|
|
107
|
+
number and account
|
|
100
108
|
|
|
101
109
|
Test and improve it: what it should do, what supervisors reported, and how
|
|
102
110
|
its tools answered (test add, test list, fix, push, test):
|
|
@@ -156,13 +164,37 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
156
164
|
Replace the schedule. DAYS: mon, mon-fri, sat,sun, all
|
|
157
165
|
A range may cross midnight: "fri 22:00-08:00"
|
|
158
166
|
quiet-hours off Answer around the clock
|
|
167
|
+
widget [show] The web widget's look and greeting, and its snippet
|
|
168
|
+
widget set [--title T] [--greeting G] [--suggestion S]... [--position left|right]
|
|
169
|
+
[--scheme auto|light|dark] [--reply-style stream|paced] [--locale en|es|pt]
|
|
159
170
|
|
|
160
171
|
Team (the owner's; the same roles as the inbox's Team page):
|
|
161
172
|
team [list] [--json] The owner and everyone invited, and who has not signed in yet
|
|
162
173
|
team invite EMAIL --role viewer|supervisor|developer [--code CODE]
|
|
163
174
|
Invite them and email them. Needs a second factor on your
|
|
164
|
-
account: --code is your authenticator app's code
|
|
165
|
-
|
|
175
|
+
account: --code is your authenticator app's code
|
|
176
|
+
team role EMAIL viewer|supervisor|developer [--code CODE]
|
|
177
|
+
Change what they reach; the same second factor
|
|
178
|
+
team rm EMAIL Take their access away
|
|
179
|
+
team resend EMAIL Email the invitation again
|
|
180
|
+
team questions [--to EMAIL...|--none] [--template NAME [--language CODE]|--no-template]
|
|
181
|
+
Who the agent asks when it cannot answer a customer
|
|
182
|
+
|
|
183
|
+
The workspace (the owner's, as the inbox's Security, Activity and Plan pages):
|
|
184
|
+
security [show] Whether everyone needs two-step verification, and how long
|
|
185
|
+
conversations are kept
|
|
186
|
+
security set [--require-2fa on|off] [--retention-days N]
|
|
187
|
+
activity [--category NAME] [--page N]
|
|
188
|
+
Who did what in the workspace, newest first
|
|
189
|
+
support-access [show] Whether Vatio staff can open the workspace now
|
|
190
|
+
support-access open 24h|72h|7d | close
|
|
191
|
+
transfer [show] Handing the workspace to someone else
|
|
192
|
+
transfer offer EMAIL [--code CODE] | cancel
|
|
193
|
+
transfer accept SLUG [--code CODE] | decline SLUG
|
|
194
|
+
A workspace someone offered to you
|
|
195
|
+
workspace delete SLUG [--yes] [--code CODE]
|
|
196
|
+
Delete it for everyone; it cannot be undone
|
|
197
|
+
plan The plan and this period's conversations against it
|
|
166
198
|
|
|
167
199
|
Credentials:
|
|
168
200
|
secrets list|set KEY [VALUE] [--from-env [NAME]]|rm KEY [--tests]
|
|
@@ -183,8 +215,8 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
183
215
|
number: for your backend's development and staging
|
|
184
216
|
keys create secret --scope NAME... [--code CODE | --recovery-code CODE]
|
|
185
217
|
What the secret key may call: messages, instagram,
|
|
186
|
-
chats, team (repeatable). Without --scope,
|
|
187
|
-
team. team (add people to the team) is the owner's,
|
|
218
|
+
chats, status, team (repeatable). Without --scope,
|
|
219
|
+
all but team. team (add people to the team) is the owner's,
|
|
188
220
|
with a code from their authenticator app
|
|
189
221
|
keys revoke PREFIX
|
|
190
222
|
auth --new-key Keypair that signs the JWT saying who a visitor is
|
package/lib/http.mjs
CHANGED
|
@@ -71,10 +71,11 @@ function unprocessableMessage(body) {
|
|
|
71
71
|
.map((entry) => (typeof entry === "object" ? String(entry.message ?? "") : String(entry)));
|
|
72
72
|
if (errors.length > 0) return errors.join("; ");
|
|
73
73
|
|
|
74
|
-
// `{ error
|
|
75
|
-
//
|
|
74
|
+
// `{ error, error_description }` is how the API the MCP and the inbox share
|
|
75
|
+
// says it; `{ error: { code, message } }` how the knowledge and token
|
|
76
|
+
// endpoints do.
|
|
76
77
|
const error = body.error && typeof body.error === "object" && !Array.isArray(body.error) ? body.error.message : body.error;
|
|
77
|
-
const message = body.error_message ?? error;
|
|
78
|
+
const message = body.error_description ?? body.error_message ?? error;
|
|
78
79
|
if (message != null) return Array.isArray(message) ? message.join("; ") : String(message);
|
|
79
80
|
|
|
80
81
|
return "Unprocessable";
|
|
@@ -192,3 +193,11 @@ function responseMessage(body, raw, response) {
|
|
|
192
193
|
if (text === "" || text.startsWith("<")) return response.statusText || `HTTP ${response.status}`;
|
|
193
194
|
return text.slice(0, 200);
|
|
194
195
|
}
|
|
196
|
+
|
|
197
|
+
// The code a refusal carries, whichever way the platform wrote it: `error`
|
|
198
|
+
// as a string (the API the MCP and the inbox share), `error: { code }` or
|
|
199
|
+
// `error_key`.
|
|
200
|
+
export function errorCode(error) {
|
|
201
|
+
const body = error?.body ?? {};
|
|
202
|
+
return body.error_key ?? (typeof body.error === "string" ? body.error : body.error?.code) ?? null;
|
|
203
|
+
}
|
package/lib/suggest.mjs
CHANGED
|
@@ -56,7 +56,16 @@ export const COMMANDS = [
|
|
|
56
56
|
"version",
|
|
57
57
|
"webhooks",
|
|
58
58
|
"whatsapp",
|
|
59
|
-
"whoami"
|
|
59
|
+
"whoami",
|
|
60
|
+
"activity",
|
|
61
|
+
"analytics",
|
|
62
|
+
"plan",
|
|
63
|
+
"security",
|
|
64
|
+
"support-access",
|
|
65
|
+
"testers",
|
|
66
|
+
"transfer",
|
|
67
|
+
"widget",
|
|
68
|
+
"workspace"
|
|
60
69
|
];
|
|
61
70
|
|
|
62
71
|
// Words that only mean something after a command. A token that is one of
|
package/lib/telemetry.mjs
CHANGED
|
@@ -29,7 +29,7 @@ const MAX_MESSAGE = 2_000;
|
|
|
29
29
|
// Only words a command takes as its first argument are kept: anything else
|
|
30
30
|
// there is a value (`vatio chat "hola"`), and values are not sent.
|
|
31
31
|
const SUBCOMMANDS = {
|
|
32
|
-
chat: ["show"],
|
|
32
|
+
chat: ["show", "export", "reply", "release"],
|
|
33
33
|
env: ["list", "rm"],
|
|
34
34
|
kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
|
|
35
35
|
business: ["show", "set"],
|
|
@@ -41,7 +41,14 @@ const SUBCOMMANDS = {
|
|
|
41
41
|
whatsapp: ["status", "connect", "live", "check", "disconnect", "invite", "team", "templates", "failed"],
|
|
42
42
|
config: ["show", "get", "set", "unset"],
|
|
43
43
|
"share-session": ["--should-ask", "--never"],
|
|
44
|
-
test: ["add", "list", "rm"]
|
|
44
|
+
test: ["add", "list", "rm"],
|
|
45
|
+
team: ["list", "invite", "role", "rm", "resend", "questions"],
|
|
46
|
+
widget: ["show", "set"],
|
|
47
|
+
security: ["show", "set"],
|
|
48
|
+
"support-access": ["show", "open", "close"],
|
|
49
|
+
transfer: ["show", "offer", "cancel", "accept", "decline"],
|
|
50
|
+
workspace: ["delete"],
|
|
51
|
+
testers: ["web", "whatsapp", "instagram", "rm"]
|
|
45
52
|
};
|
|
46
53
|
|
|
47
54
|
export const USER_AGENT = `vatio-cli/${VERSION} (node ${process.version}; ${platform()} ${arch()})`;
|
|
@@ -201,7 +208,7 @@ async function post(config, body, { strict = false } = {}) {
|
|
|
201
208
|
const headers = { ...(strict ? chosenHeaders() : clientHeaders()), "Content-Type": "application/json", Accept: "application/json" };
|
|
202
209
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
203
210
|
|
|
204
|
-
const response = await fetch(`${config.resolveBaseUrl()}/api/
|
|
211
|
+
const response = await fetch(`${config.resolveBaseUrl()}/api/v1/cli/events`, {
|
|
205
212
|
method: "POST",
|
|
206
213
|
headers,
|
|
207
214
|
body: JSON.stringify({
|
package/lib/workspace.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// small.
|
|
4
4
|
//
|
|
5
5
|
// What a `tools/*.yml` declares, which blocks `vatio.yml` accepts and whether
|
|
6
|
-
// any of it is valid are answered by POST /api/
|
|
6
|
+
// any of it is valid are answered by POST /api/v1/:slug/check. The one
|
|
7
7
|
// thing a client cannot ask the platform for is the address of that call: the
|
|
8
8
|
// slug is in its URL. So this reads `workspace:` and stops.
|
|
9
9
|
|