@vatio-ai/cli 0.75.0 → 0.77.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 CHANGED
@@ -14,6 +14,7 @@ import { diff, publish, push, rollback, status } from "../lib/commands/deploy.mj
14
14
  import { env } from "../lib/commands/env.mjs";
15
15
  import { keys, secrets, tokens } from "../lib/commands/workspace-admin.mjs";
16
16
  import { templates, webhooks } from "../lib/commands/webhooks.mjs";
17
+ import { routines } from "../lib/commands/routines.mjs";
17
18
  import { auth } from "../lib/commands/identity-key.mjs";
18
19
  import { chat } from "../lib/commands/chat.mjs";
19
20
  import { kb } from "../lib/commands/knowledge.mjs";
@@ -89,6 +90,8 @@ async function run(command, args) {
89
90
  return await templates(config, args);
90
91
  case "webhooks":
91
92
  return await webhooks(config, args);
93
+ case "routines":
94
+ return await routines(config, args);
92
95
  case "auth":
93
96
  return await auth(config, args);
94
97
  case "chat":
@@ -15,6 +15,16 @@ export class ApiClient extends HttpClient {
15
15
  return this.get("/status");
16
16
  }
17
17
 
18
+ // --- whatsapp -------------------------------------------------------
19
+
20
+ getWhatsapp() {
21
+ return this.get("/whatsapp");
22
+ }
23
+
24
+ updateWhatsapp(body) {
25
+ return this.patch("/whatsapp", body);
26
+ }
27
+
18
28
  deployedManifest({ environment = "live" } = {}) {
19
29
  return this.get("/manifest", { environment });
20
30
  }
@@ -231,6 +241,32 @@ export class ApiClient extends HttpClient {
231
241
  return this.get(`/webhook_endpoints/${encode(id)}/deliveries`);
232
242
  }
233
243
 
244
+ // --- routines -------------------------------------------------------
245
+
246
+ listRoutines() {
247
+ return this.get("/routines");
248
+ }
249
+
250
+ createRoutine(body) {
251
+ return this.post("/routines", body);
252
+ }
253
+
254
+ updateRoutine({ id, ...attrs }) {
255
+ return this.patch(`/routines/${encode(id)}`, attrs);
256
+ }
257
+
258
+ deleteRoutine({ id }) {
259
+ return this.delete(`/routines/${encode(id)}`);
260
+ }
261
+
262
+ testRoutine({ id }) {
263
+ return this.post(`/routines/${encode(id)}/test`);
264
+ }
265
+
266
+ listRoutineRuns({ id }) {
267
+ return this.get(`/routines/${encode(id)}/runs`);
268
+ }
269
+
234
270
  // --- chats ----------------------------------------------------------
235
271
 
236
272
  createChat({ environment }) {
@@ -3,11 +3,33 @@
3
3
  // accounts are a form with a code. The CLI only says where, and that depends
4
4
  // on whether the workspace has published: before, only the Test page is in the
5
5
  // console's sidebar; after, the channel's own page under Integrations.
6
+ //
7
+ // One thing about your own WhatsApp number is set here too: who the agent
8
+ // answers on it (`vatio whatsapp only` / `everyone`). Everyone else's messages
9
+ // still reach the inbox.
6
10
 
7
11
  import { deployClient } from "./deploy.mjs";
12
+ import { fail, paint } from "../support.mjs";
13
+
14
+ const WHATSAPP_USAGE = "Usage: vatio whatsapp [only NUMBER [NUMBER]... | everyone]";
15
+
16
+ export async function whatsapp(config, args = []) {
17
+ const sub = args.shift();
18
+ if (sub === undefined) {
19
+ await inConsole(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
20
+ return printAgentNumbers(config);
21
+ }
22
+ if (sub === "only") {
23
+ if (args.length === 0) fail(WHATSAPP_USAGE);
24
+ return setAgentNumbers(config, args.splice(0));
25
+ }
26
+ if (sub === "everyone") {
27
+ if (args.length > 0) fail(WHATSAPP_USAGE);
28
+ return setAgentNumbers(config, []);
29
+ }
30
+ fail(WHATSAPP_USAGE);
31
+ }
8
32
 
9
- export const whatsapp = (config) =>
10
- inConsole(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
11
33
  export const instagram = (config) =>
12
34
  inConsole(config, { name: "Instagram", key: "instagram", own: "account", test: "account" });
13
35
 
@@ -24,3 +46,33 @@ async function inConsole(config, channel) {
24
46
  }
25
47
  console.log(` ${url}`);
26
48
  }
49
+
50
+ async function setAgentNumbers(config, numbers) {
51
+ const client = deployClient(config, config.resolveWorkspaceRequired());
52
+ printAnswers(await client.updateWhatsapp({ agent_numbers: numbers }));
53
+ }
54
+
55
+ // After the console link: a workspace with no number of its own has nothing
56
+ // more to show, and the link already says what to do.
57
+ async function printAgentNumbers(config) {
58
+ const client = deployClient(config, config.resolveWorkspaceRequired());
59
+ try {
60
+ printAnswers(await client.getWhatsapp());
61
+ } catch (error) {
62
+ if (error?.body?.error?.code === "whatsapp_not_connected") return;
63
+ throw error;
64
+ }
65
+ }
66
+
67
+ function printAnswers(number) {
68
+ const list = Array.isArray(number.agent_numbers) ? number.agent_numbers : [];
69
+ const live = number.live ? paint("green", "live") : paint("cyan", "paused: Live is off in the console");
70
+ console.log(`\n${number.display_phone_number ?? "Your number"}: ${live}`);
71
+ if (list.length === 0) {
72
+ console.log(" The agent answers everyone. To answer only some numbers: vatio whatsapp only +56912345678");
73
+ return;
74
+ }
75
+ console.log(` The agent answers only: ${list.join(", ")}`);
76
+ console.log(" Everyone else's messages reach the inbox unanswered; your routines' numbers always count.");
77
+ console.log(" Back to everyone: vatio whatsapp everyone");
78
+ }
@@ -0,0 +1,176 @@
1
+ // `vatio routines` — Claude Code routines that a WhatsApp number starts. When
2
+ // one of a routine's numbers writes to the workspace, Vatio waits for them to
3
+ // finish and calls the routine's API trigger with where the conversation is;
4
+ // Claude reads it with a server key (GET /api/server/v1/:ws/chats/:id/messages).
5
+
6
+ import { deployClient } from "./deploy.mjs";
7
+ import { askSecret, fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
8
+
9
+ const WAIT_INTERVAL_MS = 2_000;
10
+
11
+ const CREATE_USAGE = "vatio routines create NAME --url URL --phone NUMBER [--phone NUMBER]... " +
12
+ "[--quiet SECONDS] [--env NAME]";
13
+ const UPDATE_USAGE = "vatio routines update ID [--name NAME] [--url URL] [--phone NUMBER]... [--new-token] " +
14
+ "[--quiet SECONDS]";
15
+ const USAGE = `Usage: vatio routines list|create NAME …|update ID …|test ID|runs ID|enable ID|rm ID\n` +
16
+ ` ${CREATE_USAGE}\n ${UPDATE_USAGE}`;
17
+
18
+ // Repeatable: `--phone +56911111111 --phone +56922222222`.
19
+ function takeAll(args, name) {
20
+ const values = [];
21
+ for (let value = takeValue(args, name); value !== null; value = takeValue(args, name)) values.push(value);
22
+ return values;
23
+ }
24
+
25
+ function takeQuiet(args) {
26
+ const raw = takeValue(args, "--quiet");
27
+ if (raw === null) return null;
28
+ const seconds = Number(raw);
29
+ if (!Number.isInteger(seconds)) fail("--quiet is a whole number of seconds, between 5 and 600");
30
+ return seconds;
31
+ }
32
+
33
+ export async function routines(config, args) {
34
+ const json = takeFlag(args, "--json");
35
+ const workspace = config.resolveWorkspaceRequired();
36
+ const client = deployClient(config, workspace);
37
+ const sub = args.shift() ?? "list";
38
+
39
+ if (sub === "list") {
40
+ const { routines: list = [] } = await client.listRoutines();
41
+ if (json) return console.log(JSON.stringify(list, null, 2));
42
+ if (list.length === 0) {
43
+ console.log(`No routines on workspace ${workspace}`);
44
+ console.log(" Add one: vatio routines create encargos --url https://api.anthropic.com/v1/claude_code/routines/trig_…/fire " +
45
+ "--phone +56912345678");
46
+ return;
47
+ }
48
+ console.log(`Routines on workspace ${workspace} (${list.length}):`);
49
+ for (const routine of list) printRoutine(routine);
50
+ return;
51
+ }
52
+
53
+ if (sub === "create") {
54
+ const environment = takeEnv(args, { fallback: "live" });
55
+ const url = takeValue(args, "--url");
56
+ const phoneNumbers = takeAll(args, "--phone");
57
+ const quiet = takeQuiet(args);
58
+ const name = args.shift();
59
+ if (!name || !url || phoneNumbers.length === 0 || args.length > 0) fail(`Usage: ${CREATE_USAGE}`);
60
+
61
+ // Asked for rather than typed on the command line, where it would stay in
62
+ // shell history; piped in works too: `op read … | vatio routines create …`.
63
+ const token = await askSecret(`${paint("green", "?")} Paste the routine's API token (sk-ant-oat01-…): `);
64
+ if (token === "") fail("No token given. claude.ai shows it once, when you generate it on the routine's API trigger.");
65
+
66
+ const body = { environment, name, url, token, phone_numbers: phoneNumbers };
67
+ if (quiet !== null) body.quiet_seconds = quiet;
68
+ const routine = await client.createRoutine(body);
69
+ if (json) return console.log(JSON.stringify(routine, null, 2));
70
+ console.log(`${paint("green", "✓")} Created routine #${routine.id} (${routine.name}) on ${routine.environment}`);
71
+ printRoutine(routine);
72
+ console.log("");
73
+ console.log("Give the routine a server key so it can read the conversation: vatio keys create --env " +
74
+ `${routine.environment} --label ${routine.name}`);
75
+ console.log(`Then check it starts: vatio routines test ${routine.id}`);
76
+ return;
77
+ }
78
+
79
+ if (sub === "update") {
80
+ const name = takeValue(args, "--name");
81
+ const url = takeValue(args, "--url");
82
+ const phoneNumbers = takeAll(args, "--phone");
83
+ const newToken = takeFlag(args, "--new-token");
84
+ const quiet = takeQuiet(args);
85
+ const id = args.shift();
86
+ if (!id || args.length > 0) fail(`Usage: ${UPDATE_USAGE}`);
87
+
88
+ const body = {};
89
+ if (name !== null) body.name = name;
90
+ if (url !== null) body.url = url;
91
+ if (phoneNumbers.length > 0) body.phone_numbers = phoneNumbers;
92
+ if (quiet !== null) body.quiet_seconds = quiet;
93
+ if (newToken) {
94
+ body.token = await askSecret(`${paint("green", "?")} Paste the new API token: `);
95
+ if (body.token === "") fail("No token given");
96
+ }
97
+ if (Object.keys(body).length === 0) fail(`Nothing to change. ${UPDATE_USAGE}`);
98
+
99
+ const routine = await client.updateRoutine({ id, ...body });
100
+ if (json) return console.log(JSON.stringify(routine, null, 2));
101
+ console.log(`${paint("green", "✓")} Updated routine #${routine.id}`);
102
+ printRoutine(routine);
103
+ return;
104
+ }
105
+
106
+ if (sub === "test") {
107
+ const id = args.shift();
108
+ if (!id) fail("Usage: vatio routines test ID");
109
+ const run = await client.testRoutine({ id });
110
+ console.log(`Fired a ping (run #${run.id}). It starts a real Claude session; the routine's prompt decides what a ping does.`);
111
+ const deadline = Date.now() + 30_000;
112
+ for (;;) {
113
+ await sleep(WAIT_INTERVAL_MS);
114
+ const { runs: list = [] } = await client.listRoutineRuns({ id });
115
+ const current = list.find((entry) => entry.id === run.id);
116
+ if (current && current.status !== "pending") {
117
+ printRun(current);
118
+ return;
119
+ }
120
+ if (Date.now() > deadline) {
121
+ console.log(`No answer yet. Check later with: vatio routines runs ${id}`);
122
+ return;
123
+ }
124
+ }
125
+ }
126
+
127
+ if (sub === "runs") {
128
+ const id = args.shift();
129
+ if (!id) fail("Usage: vatio routines runs ID");
130
+ const { runs: list = [] } = await client.listRoutineRuns({ id });
131
+ if (json) return console.log(JSON.stringify(list, null, 2));
132
+ if (list.length === 0) {
133
+ console.log("No runs yet.");
134
+ return;
135
+ }
136
+ for (const run of list) printRun(run);
137
+ return;
138
+ }
139
+
140
+ if (sub === "enable") {
141
+ const id = args.shift();
142
+ if (!id) fail("Usage: vatio routines enable ID");
143
+ await client.updateRoutine({ id, enabled: true });
144
+ console.log(`Enabled routine #${id}`);
145
+ return;
146
+ }
147
+
148
+ if (sub === "rm" || sub === "remove" || sub === "delete") {
149
+ const id = args.shift();
150
+ if (!id) fail("Usage: vatio routines rm ID");
151
+ await client.deleteRoutine({ id });
152
+ console.log(`Removed routine #${id}`);
153
+ return;
154
+ }
155
+
156
+ fail(USAGE);
157
+ }
158
+
159
+ function printRoutine(routine) {
160
+ const state = routine.enabled ? paint("green", "enabled") : paint("red", "disabled");
161
+ console.log(` #${routine.id} ${routine.name} ${routine.environment} ${state}`);
162
+ console.log(` numbers: ${routine.phone_numbers.join(", ")}`);
163
+ console.log(` waits ${routine.quiet_seconds}s after the last message, then fires and the agent answers` +
164
+ (routine.consecutive_failures > 0 ? ` failing: ${routine.consecutive_failures} in a row` : ""));
165
+ }
166
+
167
+ function printRun(run) {
168
+ const status = run.status === "fired"
169
+ ? paint("green", "fired")
170
+ : run.status === "failed" ? paint("red", "failed") : paint("cyan", "pending");
171
+ const http = run.response_status ? ` HTTP ${run.response_status}` : "";
172
+ const chat = run.chat_id ? ` chat ${run.chat_id}` : "";
173
+ console.log(` #${run.id} ${run.event} ${status}${http}${chat} attempts ${run.attempts} ${run.created_at}`);
174
+ if (run.session_url) console.log(` ${run.session_url}`);
175
+ if (run.last_error) console.log(` ${paint("red", run.last_error)}`);
176
+ }
package/lib/help.mjs CHANGED
@@ -127,9 +127,17 @@ Commands default as listed.
127
127
  webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID
128
128
  Where Vatio tells your backend what happened
129
129
 
130
+ Claude Code routines (WhatsApp):
131
+ routines list|create NAME --url URL --phone NUMBER...|update ID|test ID|runs ID|enable ID|rm ID
132
+ A routine on claude.ai that a message from these
133
+ numbers starts; it reads the chat with a server key
134
+
130
135
  Channels:
131
136
  whatsapp Set up in the console; prints the link (Test page
132
137
  until you publish, then Integrations)
138
+ whatsapp only NUMBER...|everyone
139
+ Who the agent answers on your own number; the
140
+ rest still reach the inbox
133
141
  instagram The same, for Instagram
134
142
 
135
143
  Everything else:
package/lib/telemetry.mjs CHANGED
@@ -34,6 +34,8 @@ const SUBCOMMANDS = {
34
34
  keys: ["list", "create", "revoke"],
35
35
  templates: ["list", "create"],
36
36
  webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
37
+ routines: ["list", "create", "update", "test", "runs", "enable", "rm"],
38
+ whatsapp: ["only", "everyone"],
37
39
  config: ["show", "get", "set", "unset"],
38
40
  "share-session": ["--should-ask", "--never"]
39
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.75.0",
3
+ "version": "0.77.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",