@vatio-ai/cli 0.60.0 → 0.61.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
@@ -12,7 +12,8 @@ import { login, logout } from "../lib/commands/auth.mjs";
12
12
  import { configCommand, doctor, init, version } from "../lib/commands/misc.mjs";
13
13
  import { diff, publish, push, rollback, status } from "../lib/commands/deploy.mjs";
14
14
  import { env } from "../lib/commands/env.mjs";
15
- import { secrets, tokens } from "../lib/commands/workspace-admin.mjs";
15
+ import { keys, secrets, tokens } from "../lib/commands/workspace-admin.mjs";
16
+ import { templates, webhooks } from "../lib/commands/webhooks.mjs";
16
17
  import { auth } from "../lib/commands/identity-key.mjs";
17
18
  import { chat } from "../lib/commands/chat.mjs";
18
19
  import { kb } from "../lib/commands/knowledge.mjs";
@@ -83,6 +84,12 @@ async function run(command, args) {
83
84
  return await diff(config, args);
84
85
  case "tokens":
85
86
  return await tokens(config, args);
87
+ case "keys":
88
+ return await keys(config, args);
89
+ case "templates":
90
+ return await templates(config, args);
91
+ case "webhooks":
92
+ return await webhooks(config, args);
86
93
  case "auth":
87
94
  return await auth(config, args);
88
95
  case "chat":
@@ -171,6 +171,54 @@ export class ApiClient extends HttpClient {
171
171
  return this.patch("/business", fields);
172
172
  }
173
173
 
174
+ // --- server keys ----------------------------------------------------
175
+
176
+ listServerKeys() {
177
+ return this.get("/server_keys");
178
+ }
179
+
180
+ createServerKey({ environment, label = null }) {
181
+ const body = { environment };
182
+ if (String(label ?? "").trim() !== "") body.label = String(label).trim();
183
+ return this.post("/server_keys", body);
184
+ }
185
+
186
+ revokeServerKey({ prefix }) {
187
+ return this.delete(`/server_keys/${encode(prefix)}`);
188
+ }
189
+
190
+ // --- templates, webhooks ---------------------------------------------
191
+
192
+ listTemplates({ environment }) {
193
+ return this.get("/templates", { environment });
194
+ }
195
+
196
+ listWebhookEndpoints() {
197
+ return this.get("/webhook_endpoints");
198
+ }
199
+
200
+ createWebhookEndpoint({ environment, url, events = [], label = null }) {
201
+ const body = { environment, url, events };
202
+ if (String(label ?? "").trim() !== "") body.label = String(label).trim();
203
+ return this.post("/webhook_endpoints", body);
204
+ }
205
+
206
+ updateWebhookEndpoint({ id, ...attrs }) {
207
+ return this.patch(`/webhook_endpoints/${encode(id)}`, attrs);
208
+ }
209
+
210
+ deleteWebhookEndpoint({ id }) {
211
+ return this.delete(`/webhook_endpoints/${encode(id)}`);
212
+ }
213
+
214
+ testWebhookEndpoint({ id }) {
215
+ return this.post(`/webhook_endpoints/${encode(id)}/test`);
216
+ }
217
+
218
+ listWebhookDeliveries({ id }) {
219
+ return this.get(`/webhook_endpoints/${encode(id)}/deliveries`);
220
+ }
221
+
174
222
  // --- chats ----------------------------------------------------------
175
223
 
176
224
  createChat({ environment }) {
@@ -0,0 +1,142 @@
1
+ // `vatio templates` / `vatio webhooks` — what a developer sets up so their
2
+ // backend can send WhatsApp messages through the server API: the templates
3
+ // the number can send, and where Vatio reports what happened. Sending itself
4
+ // is the backend's job, with a server key, not the CLI's.
5
+
6
+ import { deployClient } from "./deploy.mjs";
7
+ import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
8
+
9
+ const WAIT_INTERVAL_MS = 2_000;
10
+
11
+ // Repeatable: `--event message.sent --event message.replied`.
12
+ function takeAll(args, name) {
13
+ const values = [];
14
+ for (let value = takeValue(args, name); value !== null; value = takeValue(args, name)) values.push(value);
15
+ return values;
16
+ }
17
+
18
+ export async function templates(config, args) {
19
+ const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
20
+ const json = takeFlag(args, "--json");
21
+ const workspace = config.resolveWorkspaceRequired();
22
+ const client = deployClient(config, workspace);
23
+ const sub = args.shift() ?? "list";
24
+ if (sub !== "list") fail("Usage: vatio templates list [--env live] [--json]");
25
+
26
+ const payload = await client.listTemplates({ environment });
27
+ const list = Array.isArray(payload.templates) ? payload.templates : [];
28
+ if (json) {
29
+ console.log(JSON.stringify(list, null, 2));
30
+ return;
31
+ }
32
+ if (list.length === 0) {
33
+ console.log(environment === "live"
34
+ ? "No templates on this workspace's WhatsApp number. Create them on the console's Channels → WhatsApp page."
35
+ : "Templates belong to the workspace's own number; the preview number has none of yours. Use --env live.");
36
+ return;
37
+ }
38
+ console.log(`Templates on the workspace's number (${list.length}):`);
39
+ for (const template of list) {
40
+ const status = template.status === "APPROVED" ? paint("green", template.status) : paint("cyan", template.status);
41
+ const count = template.parameter_count ?? "?";
42
+ console.log(` ${template.name} (${template.language}) ${template.category} ${status} ${count} param${count === 1 ? "" : "s"}`);
43
+ if (template.body) console.log(` ${template.body.replace(/\n/g, "\n ")}`);
44
+ if (template.status === "APPROVED") console.log(` "template": ${JSON.stringify(template.example)}`);
45
+ }
46
+ }
47
+
48
+ export async function webhooks(config, args) {
49
+ const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
50
+ const label = takeValue(args, "--label");
51
+ const events = takeAll(args, "--event");
52
+ const workspace = config.resolveWorkspaceRequired();
53
+ const client = deployClient(config, workspace);
54
+ const sub = args.shift() ?? "list";
55
+
56
+ if (sub === "list") {
57
+ const payload = await client.listWebhookEndpoints();
58
+ const list = Array.isArray(payload.webhook_endpoints) ? payload.webhook_endpoints : [];
59
+ if (list.length === 0) {
60
+ console.log(`No webhook endpoints on workspace ${workspace}`);
61
+ console.log(" Add one: vatio webhooks create https://your-app.com/vatio/webhooks --env live");
62
+ return;
63
+ }
64
+ console.log(`Webhook endpoints on workspace ${workspace} (${list.length}):`);
65
+ for (const endpoint of list) {
66
+ const state = endpoint.enabled ? paint("green", "enabled") : paint("red", "disabled");
67
+ console.log(` #${endpoint.id} ${endpoint.environment} ${endpoint.url} ${state}`);
68
+ console.log(` events: ${endpoint.events.length > 0 ? endpoint.events.join(", ") : "all"}` +
69
+ (endpoint.consecutive_failures > 0 ? ` failing: ${endpoint.consecutive_failures} in a row` : ""));
70
+ }
71
+ return;
72
+ }
73
+ if (sub === "create") {
74
+ const url = args.shift();
75
+ if (!url) fail("Usage: vatio webhooks create URL [--event NAME]... [--label NAME] [--env NAME]");
76
+ const payload = await client.createWebhookEndpoint({ environment, url, events, label });
77
+ console.log(`Created webhook endpoint #${payload.id} for ${environment}: ${payload.url}`);
78
+ console.log(` events: ${payload.events.length > 0 ? payload.events.join(", ") : "all"}`);
79
+ console.log("");
80
+ // Vatio signs every delivery with it; it is not shown again.
81
+ console.log(` ${payload.secret}`);
82
+ console.log("");
83
+ console.log("Copy the signing secret now — it is not shown again. Check it with: vatio webhooks test " + payload.id);
84
+ return;
85
+ }
86
+ if (sub === "test") {
87
+ const id = args.shift();
88
+ if (!id) fail("Usage: vatio webhooks test ID");
89
+ const delivery = await client.testWebhookEndpoint({ id });
90
+ console.log(`Sent a ping (${delivery.id}). Waiting for your endpoint…`);
91
+ const deadline = Date.now() + 30_000;
92
+ for (;;) {
93
+ await sleep(WAIT_INTERVAL_MS);
94
+ const { deliveries = [] } = await client.listWebhookDeliveries({ id });
95
+ const current = deliveries.find((entry) => entry.id === delivery.id);
96
+ if (current && (current.status === "delivered" || current.attempts > 0)) {
97
+ printDelivery(current);
98
+ return;
99
+ }
100
+ if (Date.now() > deadline) {
101
+ console.log("No answer yet. Check later with: vatio webhooks deliveries " + id);
102
+ return;
103
+ }
104
+ }
105
+ }
106
+ if (sub === "deliveries") {
107
+ const id = args.shift();
108
+ if (!id) fail("Usage: vatio webhooks deliveries ID");
109
+ const { deliveries = [] } = await client.listWebhookDeliveries({ id });
110
+ if (deliveries.length === 0) {
111
+ console.log("No deliveries yet.");
112
+ return;
113
+ }
114
+ for (const delivery of deliveries) printDelivery(delivery);
115
+ return;
116
+ }
117
+ if (sub === "enable") {
118
+ const id = args.shift();
119
+ if (!id) fail("Usage: vatio webhooks enable ID");
120
+ await client.updateWebhookEndpoint({ id, enabled: true });
121
+ console.log(`Enabled webhook endpoint #${id}`);
122
+ return;
123
+ }
124
+ if (sub === "rm" || sub === "remove" || sub === "delete") {
125
+ const id = args.shift();
126
+ if (!id) fail("Usage: vatio webhooks rm ID");
127
+ await client.deleteWebhookEndpoint({ id });
128
+ console.log(`Removed webhook endpoint #${id}`);
129
+ return;
130
+ }
131
+
132
+ fail("Usage: vatio webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID [--env NAME]");
133
+ }
134
+
135
+ function printDelivery(delivery) {
136
+ const status = delivery.status === "delivered"
137
+ ? paint("green", "delivered")
138
+ : delivery.status === "failed" ? paint("red", "failed") : paint("cyan", "retrying");
139
+ const http = delivery.response_status ? ` HTTP ${delivery.response_status}` : "";
140
+ const error = delivery.last_error ? ` — ${delivery.last_error}` : "";
141
+ console.log(` ${delivery.id} ${delivery.event} ${status}${http} attempts ${delivery.attempts} ${delivery.created_at}${error}`);
142
+ }
@@ -1,6 +1,7 @@
1
- // secrets / tokens — the two things a workspace has that its manifest
2
- // deliberately does not carry. A secret is a credential, and so is a
3
- // publishable token (with the origins it accepts); neither is in vatio.yml.
1
+ // secrets / tokens / keys — the things a workspace has that its manifest
2
+ // deliberately does not carry. A secret is a credential, and so are a
3
+ // publishable token (with the origins it accepts) and a server key; none of
4
+ // them is in vatio.yml.
4
5
 
5
6
  import { deployClient } from "./deploy.mjs";
6
7
  import { askSecret, branchDefault, fail, paint, takeValue } from "../support.mjs";
@@ -137,6 +138,62 @@ export async function tokens(config, args) {
137
138
  );
138
139
  }
139
140
 
141
+ // Server keys: what the developer's own backend calls the server API with --
142
+ // today, to have the agent write to a contact first. Unlike a publishable
143
+ // token it is a secret, and unlike the CLI's own token it belongs to the
144
+ // workspace, so it outlives whoever created it.
145
+ export async function keys(config, args) {
146
+ const environment = environmentOption(args, "live", config.workspaceRoot);
147
+ const label = takeValue(args, "--label") ?? takeValue(args, "-l");
148
+ const workspace = config.resolveWorkspaceRequired();
149
+ const client = deployClient(config, workspace);
150
+ const sub = args.shift() ?? "list";
151
+
152
+ if (sub === "list") {
153
+ const payload = await client.listServerKeys();
154
+ const list = asArray(payload.server_keys);
155
+ if (list.length === 0) {
156
+ console.log(`No server keys on workspace ${workspace}`);
157
+ console.log(" Create one: vatio keys create --env live --label backend");
158
+ return;
159
+ }
160
+ console.log(`Server keys on workspace ${workspace} (${list.length}):`);
161
+ for (const key of list) {
162
+ const parts = [key.prefix, key.environment];
163
+ if (key.label) parts.push(key.label);
164
+ parts.push(key.last_used_at ? `last used ${key.last_used_at}` : "never used");
165
+ console.log(` ${parts.join(" ")}`);
166
+ }
167
+ return;
168
+ }
169
+ if (sub === "create") {
170
+ const payload = await client.createServerKey({ environment, label });
171
+ console.log(`Created a server key for ${environment} on workspace ${workspace}`);
172
+ console.log("");
173
+ // The platform keeps only a digest: this is the one time the key exists
174
+ // anywhere it can be copied from.
175
+ console.log(` ${payload.key}`);
176
+ console.log("");
177
+ console.log("Copy it now — it is not shown again. Keep it on your server, never in a page or an app:");
178
+ console.log("");
179
+ console.log(` VATIO_SERVER_KEY=${payload.key}`);
180
+ console.log("");
181
+ console.log("Try it (lists the templates your number can send):");
182
+ console.log(` curl ${config.resolveBaseUrl()}/api/server/v1/${workspace}/templates \\`);
183
+ console.log(' -H "Authorization: Bearer $VATIO_SERVER_KEY"');
184
+ return;
185
+ }
186
+ if (sub === "revoke") {
187
+ const prefix = args.shift();
188
+ if (!prefix) fail("Usage: vatio keys revoke PREFIX");
189
+ await client.revokeServerKey({ prefix });
190
+ console.log(`Revoked ${prefix} on workspace ${workspace}`);
191
+ return;
192
+ }
193
+
194
+ fail("Usage: vatio keys list|create [--env live|preview|NAME] [--label NAME]|revoke PREFIX");
195
+ }
196
+
140
197
  // An empty list is not "anywhere": only Vatio's own pages can use the token.
141
198
  function originsLine(origins) {
142
199
  const list = asArray(origins);
package/lib/help.mjs CHANGED
@@ -92,8 +92,17 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
92
92
  tokens list|create [--env NAME] [--label NAME] [--origin URL]...|revoke PREFIX
93
93
  tokens origins PREFIX URL...
94
94
  The origins a token is accepted from (replaces the list)
95
+ keys list|create [--env NAME] [--label NAME]|revoke PREFIX
96
+ Server keys, for your backend to call the server API
95
97
  auth --new-key Keypair that signs the JWT saying who a visitor is
96
98
 
99
+ Sending from your backend (WhatsApp, with a server key):
100
+ templates list [--env live] [--json]
101
+ The number's templates, parameter counts, and the
102
+ "template" object to send
103
+ webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID
104
+ Where Vatio tells your backend what happened
105
+
97
106
  Channels:
98
107
  whatsapp Set up in the console; prints the link
99
108
  instagram Set up in the console; prints the link
package/lib/telemetry.mjs CHANGED
@@ -31,6 +31,9 @@ const SUBCOMMANDS = {
31
31
  business: ["show", "set", "hours"],
32
32
  secrets: ["list", "set", "rm"],
33
33
  tokens: ["list", "create", "revoke", "origins"],
34
+ keys: ["list", "create", "revoke"],
35
+ templates: ["list"],
36
+ webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
34
37
  config: ["show", "get", "set", "unset"]
35
38
  };
36
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.60.0",
3
+ "version": "0.61.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",