@vatio-ai/cli 0.75.0 → 0.76.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":
@@ -231,6 +231,32 @@ export class ApiClient extends HttpClient {
231
231
  return this.get(`/webhook_endpoints/${encode(id)}/deliveries`);
232
232
  }
233
233
 
234
+ // --- routines -------------------------------------------------------
235
+
236
+ listRoutines() {
237
+ return this.get("/routines");
238
+ }
239
+
240
+ createRoutine(body) {
241
+ return this.post("/routines", body);
242
+ }
243
+
244
+ updateRoutine({ id, ...attrs }) {
245
+ return this.patch(`/routines/${encode(id)}`, attrs);
246
+ }
247
+
248
+ deleteRoutine({ id }) {
249
+ return this.delete(`/routines/${encode(id)}`);
250
+ }
251
+
252
+ testRoutine({ id }) {
253
+ return this.post(`/routines/${encode(id)}/test`);
254
+ }
255
+
256
+ listRoutineRuns({ id }) {
257
+ return this.get(`/routines/${encode(id)}/runs`);
258
+ }
259
+
234
260
  // --- chats ----------------------------------------------------------
235
261
 
236
262
  createChat({ environment }) {
@@ -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,6 +127,11 @@ 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)
package/lib/telemetry.mjs CHANGED
@@ -34,6 +34,7 @@ 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"],
37
38
  config: ["show", "get", "set", "unset"],
38
39
  "share-session": ["--should-ask", "--never"]
39
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",