@vatio-ai/cli 0.99.1 → 0.100.1

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 CHANGED
@@ -22,6 +22,7 @@ import { chat, chatHelp } from "../lib/commands/chat.mjs";
22
22
  import { kb } from "../lib/commands/knowledge.mjs";
23
23
  import { business } from "../lib/commands/business.mjs";
24
24
  import { quietHours } from "../lib/commands/quiet-hours.mjs";
25
+ import { team } from "../lib/commands/team.mjs";
25
26
  import { instagram, whatsapp } from "../lib/commands/channels.mjs";
26
27
  import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
27
28
  import { messages } from "../lib/commands/messages.mjs";
@@ -117,6 +118,8 @@ async function run(command, args) {
117
118
  return await business(config, args);
118
119
  case "quiet-hours":
119
120
  return await quietHours(config, args);
121
+ case "team":
122
+ return await team(config, args);
120
123
  case "secrets":
121
124
  return await secrets(config, args);
122
125
  case "whatsapp":
@@ -29,6 +29,11 @@ export class ApiClient extends HttpClient {
29
29
  return this.get("/whatsapp");
30
30
  }
31
31
 
32
+ // The phones verified on the Test page.
33
+ testPhones() {
34
+ return this.get("/test_phones");
35
+ }
36
+
32
37
  updateWhatsapp(body) {
33
38
  return this.patch("/whatsapp", body);
34
39
  }
@@ -208,6 +213,16 @@ export class ApiClient extends HttpClient {
208
213
  return this.patch("/business", fields);
209
214
  }
210
215
 
216
+ // --- team -----------------------------------------------------------
217
+
218
+ members() {
219
+ return this.get("/members");
220
+ }
221
+
222
+ inviteMember(body) {
223
+ return this.post("/members", body);
224
+ }
225
+
211
226
  // --- quiet hours ----------------------------------------------------
212
227
 
213
228
  // The weekly schedule in which the agent does not answer, or null.
@@ -11,16 +11,25 @@
11
11
  // still reach the inbox.
12
12
 
13
13
  import { deployClient } from "./deploy.mjs";
14
- import { fail, paint } from "../support.mjs";
14
+ import { fail, paint, takeFlag } from "../support.mjs";
15
15
 
16
- const WHATSAPP_USAGE = "Usage: vatio whatsapp [only NUMBER [NUMBER]... | everyone]";
16
+ const WHATSAPP_USAGE = "Usage: vatio whatsapp [test-phones [--json] | only NUMBER [NUMBER]... | everyone]";
17
17
 
18
18
  export async function whatsapp(config, args = []) {
19
19
  const sub = args.shift();
20
20
  if (sub === undefined) {
21
21
  await inInbox(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
22
+ // A server that predates the route answers 404; the link above is enough.
23
+ await printTestPhones(config).catch((error) => {
24
+ if (error?.status !== 404 && error?.body?.error?.code !== "not_found") throw error;
25
+ });
22
26
  return printAgentNumbers(config);
23
27
  }
28
+ if (sub === "test-phones") {
29
+ const json = takeFlag(args, "--json");
30
+ if (args.length > 0) fail(WHATSAPP_USAGE);
31
+ return printTestPhones(config, { json });
32
+ }
24
33
  if (sub === "only") {
25
34
  if (args.length === 0) fail(WHATSAPP_USAGE);
26
35
  return setAgentNumbers(config, args.splice(0));
@@ -49,6 +58,19 @@ async function inInbox(config, channel) {
49
58
  console.log(` ${url}`);
50
59
  }
51
60
 
61
+ // The phones that joined by sending the Test page's code: the ones a preview
62
+ // message can go to. Adding one is only in the inbox.
63
+ async function printTestPhones(config, { json = false } = {}) {
64
+ const { data = [], max } = await deployClient(config, config.resolveWorkspaceRequired()).testPhones();
65
+ if (json) return console.log(JSON.stringify({ data, max }, null, 2));
66
+ if (data.length === 0) {
67
+ console.log("\nNo test phones yet. Add yours on the inbox's Test page: send it the code it shows.");
68
+ return;
69
+ }
70
+ console.log(`\nTest phones (${data.length} of ${max}), verified on the Test page:`);
71
+ for (const phone of data) console.log(` ${phone.phone_number}`);
72
+ }
73
+
52
74
  async function setAgentNumbers(config, numbers) {
53
75
  const client = deployClient(config, config.resolveWorkspaceRequired());
54
76
  printAnswers(await client.updateWhatsapp({ agent_numbers: numbers }));
@@ -291,6 +291,17 @@ function findSession(id) {
291
291
  const current = currentSession();
292
292
  if (current) return current;
293
293
 
294
+ // Inside a coding agent whose session file is not where we read: the newest
295
+ // one for this directory would be another conversation, sent as this one.
296
+ const running = Object.values(AGENTS).find(({ currentId }) => currentId());
297
+ if (running) {
298
+ fail(
299
+ `This runs inside ${running.label} session ${short(running.currentId())}, but its file is not on this machine ` +
300
+ "where share-session looks,\nso nothing was sent rather than another session. " +
301
+ "`vatio share-session --list` shows the sessions it found; send one with --id ID."
302
+ );
303
+ }
304
+
294
305
  const session = sessionsHere().find((candidate) => candidate.messages > 0);
295
306
  if (session) return session;
296
307
  fail(
@@ -0,0 +1,78 @@
1
+ // team — who is in the workspace, and inviting someone: what the inbox's Team
2
+ // page does, for a coding agent that is asked to "add Ana as a supervisor". The
3
+ // owner's alone, like the page. Removing a member and changing a role stay in
4
+ // the inbox, where the owner confirms it is them.
5
+
6
+ import { deployClient } from "./deploy.mjs";
7
+ import { askSecret, fail, paint, takeFlag, takeValue } from "../support.mjs";
8
+
9
+ // The answers that say something the generic 401 and 403 lines would hide.
10
+ const SAYS_WHY = new Set(["owner_only", "reauthentication_required", "invalid_confirmation"]);
11
+
12
+ function explain(error) {
13
+ const code = error?.body?.error?.code;
14
+ if (SAYS_WHY.has(code)) fail(error.message);
15
+ throw error;
16
+ }
17
+
18
+ const ROLES = ["viewer", "supervisor", "developer"];
19
+ const USAGE = `Usage: vatio team [list] [--json]\n` +
20
+ ` vatio team invite EMAIL --role ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
21
+ " With a second factor on your account, --code is the 6-digit code from your authenticator app.";
22
+
23
+ export async function team(config, args) {
24
+ const json = takeFlag(args, "--json");
25
+ const workspace = config.resolveWorkspaceRequired();
26
+ const client = deployClient(config, workspace);
27
+ const sub = args.shift() ?? "list";
28
+
29
+ if (sub === "list") {
30
+ if (args.length > 0) fail(USAGE);
31
+ return print(await client.members().catch(explain), workspace, json);
32
+ }
33
+
34
+ if (sub === "invite") {
35
+ const role = takeValue(args, "--role");
36
+ const code = takeValue(args, "--code");
37
+ const recoveryCode = takeValue(args, "--recovery-code");
38
+ const email = args.shift();
39
+ if (!email || args.length > 0) fail(USAGE);
40
+ // The platform would make an unknown role a supervisor; here it is asked for.
41
+ if (!ROLES.includes(role)) fail(`--role is required: ${ROLES.join(", ")}\n\n${USAGE}`);
42
+ const answer = await invite(client, { email, role, code, recovery_code: recoveryCode }).catch(explain);
43
+ if (!json) {
44
+ console.log(`${paint("green", "✓")} Invited ${email.trim().toLowerCase()} as ${role}. They get an email, and sign in with that address.`);
45
+ console.log("");
46
+ }
47
+ return print(answer, workspace, json);
48
+ }
49
+
50
+ fail(USAGE);
51
+ }
52
+
53
+ function print(answer, workspace, json) {
54
+ if (json) return console.log(JSON.stringify(answer, null, 2));
55
+ const members = answer.data ?? [];
56
+ console.log(`Team on workspace ${workspace}:`);
57
+ if (answer.owner) console.log(` owner ${answer.owner.email}`);
58
+ for (const member of members) {
59
+ console.log(` ${member.role.padEnd(11)} ${member.email}${member.pending ? " (has not signed in yet)" : ""}`);
60
+ }
61
+ if (members.length === 0) console.log(" No one else. Invite someone: vatio team invite EMAIL --role supervisor");
62
+ }
63
+
64
+ // An owner with a second factor confirms it is them, as the inbox asks. From a
65
+ // terminal the code is asked for; a coding agent has none, so it fails with what
66
+ // to ask the person for.
67
+ async function invite(client, body) {
68
+ const confirmed = Object.fromEntries(Object.entries(body).filter(([, value]) => value));
69
+ try {
70
+ return await client.inviteMember(confirmed);
71
+ } catch (error) {
72
+ const needsCode = error?.status === 403 && error?.body?.error?.code === "reauthentication_required";
73
+ if (!needsCode || confirmed.code || confirmed.recovery_code) throw error;
74
+ if (!process.stdin.isTTY || !/--code/.test(error.message)) throw error;
75
+ const code = await askSecret(`${paint("green", "?")} Code from your authenticator app: `);
76
+ return await client.inviteMember({ ...confirmed, code });
77
+ }
78
+ }
package/lib/help.mjs CHANGED
@@ -145,6 +145,13 @@ the two you are in. Commands default as listed.
145
145
  A range may cross midnight: "fri 22:00-08:00"
146
146
  quiet-hours off Answer around the clock
147
147
 
148
+ Team (the owner's; the same roles as the inbox's Team page):
149
+ team [list] [--json] The owner and everyone invited, and who has not signed in yet
150
+ team invite EMAIL --role viewer|supervisor|developer [--code CODE]
151
+ Invite them and email them. With a second factor on your
152
+ account, --code is your authenticator app's code. Removing
153
+ someone or changing a role stays in the inbox
154
+
148
155
  Credentials:
149
156
  secrets list|set KEY [VALUE] [--from-env [NAME]]|rm KEY [--env NAME | --tests]
150
157
  Without VALUE, set asks for it with the input hidden.
@@ -192,6 +199,9 @@ the two you are in. Commands default as listed.
192
199
  Channels:
193
200
  whatsapp Set up in the inbox; prints the link (Test page
194
201
  until you publish, then Channels)
202
+ whatsapp test-phones [--json]
203
+ The phones verified on the Test page, to send a
204
+ preview message to
195
205
  whatsapp only NUMBER...|everyone
196
206
  Who the agent answers on your own number; the
197
207
  rest still reach the inbox
package/lib/suggest.mjs CHANGED
@@ -53,6 +53,7 @@ export const COMMANDS = [
53
53
  "secrets",
54
54
  "share-session",
55
55
  "status",
56
+ "team",
56
57
  "templates",
57
58
  "test",
58
59
  "tokens",
@@ -82,7 +83,8 @@ const SUBCOMMAND_OF = {
82
83
  follow: ["kb"],
83
84
  get: ["config"],
84
85
  history: ["kb"],
85
- list: ["env", "kb", "secrets", "tokens", "keys", "templates", "webhooks", "routines", "test"],
86
+ invite: ["team"],
87
+ list: ["env", "kb", "secrets", "tokens", "keys", "team", "templates", "webhooks", "routines", "test"],
86
88
  off: ["quiet-hours"],
87
89
  origins: ["tokens"],
88
90
  refresh: ["kb"],
@@ -93,6 +95,7 @@ const SUBCOMMAND_OF = {
93
95
  runs: ["routines"],
94
96
  set: ["business", "quiet-hours", "secrets", "config"],
95
97
  show: ["chat", "kb", "business", "quiet-hours", "config"],
98
+ "test-phones": ["whatsapp"],
96
99
  unfollow: ["kb"],
97
100
  unset: ["config"],
98
101
  update: ["routines"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.99.1",
3
+ "version": "0.100.1",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",