@vatio-ai/cli 0.62.1 → 0.64.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 +3 -0
- package/lib/api-client.mjs +19 -0
- package/lib/commands/propose.mjs +51 -0
- package/lib/commands/webhooks.mjs +64 -8
- package/lib/help.mjs +11 -0
- package/lib/telemetry.mjs +1 -1
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { business } from "../lib/commands/business.mjs";
|
|
|
21
21
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
22
22
|
import { docs, feedback } from "../lib/commands/support-commands.mjs";
|
|
23
23
|
import { evalCommand, flags } from "../lib/commands/improve.mjs";
|
|
24
|
+
import { propose } from "../lib/commands/propose.mjs";
|
|
24
25
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
25
26
|
import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/telemetry.mjs";
|
|
26
27
|
|
|
@@ -108,6 +109,8 @@ async function run(command, args) {
|
|
|
108
109
|
return await flags(config, args);
|
|
109
110
|
case "eval":
|
|
110
111
|
return await evalCommand(config, args);
|
|
112
|
+
case "propose":
|
|
113
|
+
return await propose(config, args);
|
|
111
114
|
case "docs":
|
|
112
115
|
return await docs(config, args);
|
|
113
116
|
case "feedback":
|
package/lib/api-client.mjs
CHANGED
|
@@ -65,6 +65,19 @@ export class ApiClient extends HttpClient {
|
|
|
65
65
|
return this.delete(`/env/${encode(name)}`);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// --- proposals ------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
proposals() {
|
|
71
|
+
return this.get("/proposals");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
propose({ environment, title, summary }) {
|
|
75
|
+
const body = { environment };
|
|
76
|
+
if (title) body.title = title;
|
|
77
|
+
if (summary != null) body.summary = summary;
|
|
78
|
+
return this.post("/proposals", body);
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
// The project "Connect Supabase" picked in the console, if any.
|
|
69
82
|
supabase() {
|
|
70
83
|
return this.get("/supabase");
|
|
@@ -198,6 +211,12 @@ export class ApiClient extends HttpClient {
|
|
|
198
211
|
return this.get("/templates", { environment });
|
|
199
212
|
}
|
|
200
213
|
|
|
214
|
+
createTemplate({ name, language, category, body, examples = [], footer = null }) {
|
|
215
|
+
const payload = { name, language, category, body, examples };
|
|
216
|
+
if (String(footer ?? "").trim() !== "") payload.footer = String(footer).trim();
|
|
217
|
+
return this.post("/templates", payload);
|
|
218
|
+
}
|
|
219
|
+
|
|
201
220
|
listWebhookEndpoints() {
|
|
202
221
|
return this.get("/webhook_endpoints");
|
|
203
222
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { deployClient } from "./deploy.mjs";
|
|
3
|
+
import { fail, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
4
|
+
|
|
5
|
+
// `vatio propose`: put a branch's environment in front of the workspace's
|
|
6
|
+
// owner as a change to accept from the inbox, for a workspace with no
|
|
7
|
+
// repository connected -- there, the pull request is the proposal. Vatio
|
|
8
|
+
// replays every eval case on it and mails the owner once they finish; the
|
|
9
|
+
// owner accepts (which publishes it) or discards it. Proposing the same
|
|
10
|
+
// environment again, after another push, updates it and replays the evals.
|
|
11
|
+
export async function propose(config, args) {
|
|
12
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
13
|
+
const client = deployClient(config, workspace);
|
|
14
|
+
if (takeFlag(args, "--list")) return await list(client, workspace);
|
|
15
|
+
|
|
16
|
+
const title = takeValue(args, "--title");
|
|
17
|
+
const summaryFile = takeValue(args, "--summary-file");
|
|
18
|
+
let summary = takeValue(args, "--summary");
|
|
19
|
+
if (summaryFile) {
|
|
20
|
+
try {
|
|
21
|
+
summary = readFileSync(summaryFile, "utf8");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
fail(`Could not read ${summaryFile}: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const environment = takeEnv(args, { fallback: null, cwd: config.workspaceRoot });
|
|
27
|
+
if (!environment) {
|
|
28
|
+
fail('usage: vatio propose --env NAME --title "What it fixes" [--summary TEXT | --summary-file PATH]');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const payload = await client.propose({ environment, title, summary });
|
|
32
|
+
console.log(`${payload.created ? "Proposed" : "Updated"} ${payload.environment} as ${payload.id}: ${payload.title}`);
|
|
33
|
+
const runs = Array.isArray(payload.runs) ? payload.runs : [];
|
|
34
|
+
const cases = runs.reduce((sum, run) => sum + (run.cases ?? 0), 0);
|
|
35
|
+
if (cases > 0) {
|
|
36
|
+
console.log(`Replaying ${cases} eval case${cases === 1 ? "" : "s"} there; the owner gets a mail when they finish.`);
|
|
37
|
+
} else {
|
|
38
|
+
console.log("No eval cases to replay: the owner decides on the change alone.");
|
|
39
|
+
}
|
|
40
|
+
console.log(`Accept or discard it in the inbox: ${payload.url}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function list(client, workspace) {
|
|
44
|
+
const payload = await client.proposals();
|
|
45
|
+
const rows = Array.isArray(payload.data) ? payload.data : [];
|
|
46
|
+
console.log(`Proposals on workspace ${workspace} (${rows.length}):`);
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
console.log(` ${row.id} ${row.status.padEnd(9)} ${row.environment} ${row.title}`);
|
|
49
|
+
console.log(` ${row.url}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// `vatio templates` / `vatio webhooks` — what a developer sets up so their
|
|
2
2
|
// backend can send WhatsApp messages through the server API: the templates
|
|
3
|
-
// the number can send
|
|
4
|
-
// is the backend's job, with a server
|
|
3
|
+
// the number can send and new ones for Meta to approve, and where Vatio
|
|
4
|
+
// reports what happened. Sending itself is the backend's job, with a server
|
|
5
|
+
// key, not the CLI's.
|
|
5
6
|
|
|
6
7
|
import { deployClient } from "./deploy.mjs";
|
|
7
8
|
import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
@@ -15,13 +16,21 @@ function takeAll(args, name) {
|
|
|
15
16
|
return values;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
const LIST_USAGE = "vatio templates list [--env live] [--json]";
|
|
20
|
+
const CREATE_USAGE = "vatio templates create NAME --language CODE --body TEXT [--example VALUE]... " +
|
|
21
|
+
"[--category utility|marketing] [--footer TEXT] [--json]";
|
|
22
|
+
|
|
18
23
|
export async function templates(config, args) {
|
|
19
|
-
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
20
24
|
const json = takeFlag(args, "--json");
|
|
25
|
+
if (args[0] === "create") {
|
|
26
|
+
args.shift();
|
|
27
|
+
return createTemplate(config, args, json);
|
|
28
|
+
}
|
|
29
|
+
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
21
30
|
const workspace = config.resolveWorkspaceRequired();
|
|
22
31
|
const client = deployClient(config, workspace);
|
|
23
32
|
const sub = args.shift() ?? "list";
|
|
24
|
-
if (sub !== "list") fail(
|
|
33
|
+
if (sub !== "list") fail(`Usage: ${LIST_USAGE}\n ${CREATE_USAGE}`);
|
|
25
34
|
|
|
26
35
|
const payload = await client.listTemplates({ environment });
|
|
27
36
|
const list = Array.isArray(payload.templates) ? payload.templates : [];
|
|
@@ -29,22 +38,69 @@ export async function templates(config, args) {
|
|
|
29
38
|
console.log(JSON.stringify(list, null, 2));
|
|
30
39
|
return;
|
|
31
40
|
}
|
|
41
|
+
const live = environment === "live";
|
|
32
42
|
if (list.length === 0) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
if (live && payload.whatsapp_connected === false) {
|
|
44
|
+
console.log("This workspace has no WhatsApp number of its own yet. The templates you create stay on Vatio's " +
|
|
45
|
+
"test number until you connect one, and then Vatio moves them to it: vatio templates list --env preview");
|
|
46
|
+
} else if (!live && payload.whatsapp_connected === true) {
|
|
47
|
+
console.log("This workspace has its own WhatsApp number, so its templates are there: vatio templates list");
|
|
48
|
+
} else {
|
|
49
|
+
console.log(`No templates on ${live ? "this workspace's WhatsApp number" : "Vatio's test number for this workspace"} yet. Create one:`);
|
|
50
|
+
console.log(' vatio templates create order_shipped --language es --body "Hi {{1}}, order {{2}} is on its way." ' +
|
|
51
|
+
'--example Ana --example "#1042"');
|
|
52
|
+
}
|
|
36
53
|
return;
|
|
37
54
|
}
|
|
38
|
-
console.log(`Templates on the workspace's number (${list.length}):`);
|
|
55
|
+
console.log(`Templates on ${live ? "the workspace's number" : "Vatio's test number"} (${list.length}):`);
|
|
39
56
|
for (const template of list) {
|
|
40
57
|
const status = template.status === "APPROVED" ? paint("green", template.status) : paint("cyan", template.status);
|
|
41
58
|
const count = template.parameter_count ?? "?";
|
|
42
59
|
console.log(` ${template.name} (${template.language}) ${template.category} ${status} ${count} param${count === 1 ? "" : "s"}`);
|
|
43
60
|
if (template.body) console.log(` ${template.body.replace(/\n/g, "\n ")}`);
|
|
61
|
+
if (template.status === "REJECTED" && template.rejected_reason) console.log(` ${paint("red", "rejected:")} ${template.rejected_reason}`);
|
|
44
62
|
if (template.status === "APPROVED") console.log(` "template": ${JSON.stringify(template.example)}`);
|
|
45
63
|
}
|
|
46
64
|
}
|
|
47
65
|
|
|
66
|
+
// On the workspace's own number once it has one, and before that on Vatio's
|
|
67
|
+
// test number, where a preview key sends it to the workspace's test phones
|
|
68
|
+
// until Vatio moves it to the number the workspace connects. The backend
|
|
69
|
+
// decides where, so there is no environment to choose.
|
|
70
|
+
async function createTemplate(config, args, json) {
|
|
71
|
+
takeValue(args, "--env");
|
|
72
|
+
const language = takeValue(args, "--language");
|
|
73
|
+
const body = takeValue(args, "--body");
|
|
74
|
+
const category = takeValue(args, "--category") ?? "utility";
|
|
75
|
+
const footer = takeValue(args, "--footer");
|
|
76
|
+
const examples = takeAll(args, "--example");
|
|
77
|
+
const name = args.shift();
|
|
78
|
+
if (!name || !language || !body || args.length > 0) fail(`Usage: ${CREATE_USAGE}`);
|
|
79
|
+
|
|
80
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
81
|
+
const client = deployClient(config, workspace);
|
|
82
|
+
const template = await client.createTemplate({ name, language, category, body, examples, footer });
|
|
83
|
+
if (json) {
|
|
84
|
+
console.log(JSON.stringify(template, null, 2));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const own = template.whatsapp_connected === true;
|
|
88
|
+
const count = template.parameter_count ?? examples.length;
|
|
89
|
+
console.log(`Submitted ${template.name} (${template.language}) for Meta's review on ` +
|
|
90
|
+
`${own ? "your own number" : "Vatio's test number"}: ${template.category}, ` +
|
|
91
|
+
`${count} param${count === 1 ? "" : "s"}, ${paint("cyan", template.status)}.`);
|
|
92
|
+
console.log("Meta usually decides within minutes, at most 24 hours. Check with: vatio templates list" +
|
|
93
|
+
(own ? "" : " --env preview"));
|
|
94
|
+
console.log(own
|
|
95
|
+
? "Once APPROVED, your backend sends it with a live key outside the 24-hour window with:"
|
|
96
|
+
: "Once APPROVED, a preview key sends it to your test phones outside the 24-hour window with:");
|
|
97
|
+
console.log(` "template": ${JSON.stringify(template.example)}`);
|
|
98
|
+
if (!own) {
|
|
99
|
+
console.log("When you connect your own number, Vatio moves your templates to it, and from then on your backend " +
|
|
100
|
+
"sends from it with a live key: `vatio whatsapp` prints where.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
48
104
|
export async function webhooks(config, args) {
|
|
49
105
|
const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
|
|
50
106
|
const label = takeValue(args, "--label");
|
package/lib/help.mjs
CHANGED
|
@@ -60,6 +60,12 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
60
60
|
judge it; exits 1 if one fails. Default: the
|
|
61
61
|
branch's environment, else preview
|
|
62
62
|
eval --show RUN_ID One run's report
|
|
63
|
+
propose [--env NAME] --title TEXT [--summary TEXT|--summary-file PATH]
|
|
64
|
+
Without a GitHub repo: put the branch's
|
|
65
|
+
environment in front of the owner, who accepts
|
|
66
|
+
(publishes) or discards it in the inbox. Replays
|
|
67
|
+
every eval case there first
|
|
68
|
+
propose --list Every proposal and where it stands
|
|
63
69
|
|
|
64
70
|
Knowledge:
|
|
65
71
|
kb [list] Bases, and whether a deployed agent reads each
|
|
@@ -103,6 +109,11 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
103
109
|
templates list [--env live] [--json]
|
|
104
110
|
The number's templates, parameter counts, and the
|
|
105
111
|
"template" object to send
|
|
112
|
+
templates create NAME --language CODE --body TEXT [--example VALUE]...
|
|
113
|
+
[--category utility|marketing] [--footer TEXT] [--json]
|
|
114
|
+
Submit a template for Meta's review: on your number,
|
|
115
|
+
or on Vatio's test number until you connect one;
|
|
116
|
+
one --example per {{n}} in the body
|
|
106
117
|
webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID
|
|
107
118
|
Where Vatio tells your backend what happened
|
|
108
119
|
|
package/lib/telemetry.mjs
CHANGED
|
@@ -32,7 +32,7 @@ const SUBCOMMANDS = {
|
|
|
32
32
|
secrets: ["list", "set", "rm"],
|
|
33
33
|
tokens: ["list", "create", "revoke", "origins"],
|
|
34
34
|
keys: ["list", "create", "revoke"],
|
|
35
|
-
templates: ["list"],
|
|
35
|
+
templates: ["list", "create"],
|
|
36
36
|
webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
|
|
37
37
|
config: ["show", "get", "set", "unset"]
|
|
38
38
|
};
|