@vatio-ai/cli 0.92.1 → 0.94.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 +14 -2
- package/lib/commands/business.mjs +23 -15
- package/lib/commands/deploy.mjs +2 -2
- package/lib/commands/improve.mjs +18 -7
- package/lib/commands/messages.mjs +91 -0
- package/lib/commands/misc.mjs +2 -2
- package/lib/help.mjs +26 -9
- package/lib/telemetry.mjs +1 -0
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { kb } from "../lib/commands/knowledge.mjs";
|
|
|
21
21
|
import { business } from "../lib/commands/business.mjs";
|
|
22
22
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
23
23
|
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
24
|
+
import { messages } from "../lib/commands/messages.mjs";
|
|
24
25
|
import { evalCommand, flags, test, tools } from "../lib/commands/improve.mjs";
|
|
25
26
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
26
27
|
import { runLatest } from "../lib/run-latest.mjs";
|
|
@@ -104,6 +105,8 @@ async function run(command, args) {
|
|
|
104
105
|
return await auth(config, args);
|
|
105
106
|
case "chat":
|
|
106
107
|
return await chat(config, args);
|
|
108
|
+
case "messages":
|
|
109
|
+
return await messages(config, args);
|
|
107
110
|
case "kb":
|
|
108
111
|
return await kb(config, args);
|
|
109
112
|
case "business":
|
package/lib/api-client.mjs
CHANGED
|
@@ -9,6 +9,18 @@ import { HttpClient } from "./http.mjs";
|
|
|
9
9
|
const encode = (value) => encodeURIComponent(String(value));
|
|
10
10
|
|
|
11
11
|
export class ApiClient extends HttpClient {
|
|
12
|
+
// --- outbound WhatsApp messages ------------------------------------
|
|
13
|
+
|
|
14
|
+
failedMessages({ environment = "live", since = null, until = null, errorCode = null, errorContains = null, before = null } = {}) {
|
|
15
|
+
return this.get("/messages", {
|
|
16
|
+
environment, since, until, error_code: errorCode, error_contains: errorContains, before
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
resendMessage(id, { environment = "live" } = {}) {
|
|
21
|
+
return this.post(`/messages/${encode(id)}/resend`, { environment });
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
// --- deploy ---------------------------------------------------------
|
|
13
25
|
|
|
14
26
|
deployStatus() {
|
|
@@ -189,8 +201,8 @@ export class ApiClient extends HttpClient {
|
|
|
189
201
|
|
|
190
202
|
// --- business -------------------------------------------------------
|
|
191
203
|
|
|
192
|
-
// Name
|
|
193
|
-
//
|
|
204
|
+
// Name and brand: one row for every environment, the same one the inbox
|
|
205
|
+
// edits under Channels → Web widget.
|
|
194
206
|
business() {
|
|
195
207
|
return this.get("/business");
|
|
196
208
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// business — the business the agent works for: name
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// business — the business the agent works for: its name and brand (logo,
|
|
2
|
+
// color, about), the same row the inbox edits under Channels → Web widget.
|
|
3
|
+
// Not part of vatio.yml: one value for every environment, live on save.
|
|
4
|
+
//
|
|
5
|
+
// It also held a description of the business, which moved into the agent's
|
|
6
|
+
// instructions: one written before is shown here, and --clear-description
|
|
7
|
+
// removes it once the instructions say it.
|
|
6
8
|
|
|
7
9
|
import { readFileSync, statSync } from "node:fs";
|
|
8
10
|
import { basename, extname } from "node:path";
|
|
@@ -16,9 +18,12 @@ const LOGO_MAX_BYTES = 2 * 1024 * 1024;
|
|
|
16
18
|
|
|
17
19
|
const USAGE =
|
|
18
20
|
"Usage: vatio business [show]\n" +
|
|
19
|
-
" vatio business set [--name NAME] [--
|
|
20
|
-
" [--
|
|
21
|
-
|
|
21
|
+
" vatio business set [--name NAME] [--about TEXT] [--color #RRGGBB | --color default]\n" +
|
|
22
|
+
" [--logo FILE | --remove-logo] [--clear-description]";
|
|
23
|
+
|
|
24
|
+
const DESCRIPTION_MOVED =
|
|
25
|
+
"The business description moved into the agent's instructions: write what the business does in " +
|
|
26
|
+
"`agent.instructions` in vatio.yml, where it is tested and published like the rest.";
|
|
22
27
|
|
|
23
28
|
export async function business(config, args) {
|
|
24
29
|
const workspace = config.resolveWorkspaceRequired();
|
|
@@ -31,13 +36,10 @@ export async function business(config, args) {
|
|
|
31
36
|
}
|
|
32
37
|
if (sub === "set") {
|
|
33
38
|
const fields = {};
|
|
39
|
+
if (args.includes("--description") || args.includes("--description-file")) fail(DESCRIPTION_MOVED);
|
|
34
40
|
const name = takeValue(args, "--name");
|
|
35
|
-
const description = takeValue(args, "--description");
|
|
36
|
-
const file = takeValue(args, "--description-file");
|
|
37
|
-
if (description !== null && file !== null) fail("Give --description or --description-file, not both");
|
|
38
41
|
if (name !== null) fields.name = name;
|
|
39
|
-
if (description
|
|
40
|
-
if (file !== null) fields.summary = readFileSync(file === "-" ? 0 : file, "utf8");
|
|
42
|
+
if (takeFlag(args, "--clear-description")) fields.summary = "";
|
|
41
43
|
|
|
42
44
|
const about = takeValue(args, "--about");
|
|
43
45
|
if (about !== null) fields.about = about;
|
|
@@ -90,8 +92,14 @@ function rejectLeftovers(args) {
|
|
|
90
92
|
function print(payload, workspace) {
|
|
91
93
|
console.log(`${payload.name} (workspace ${workspace})`);
|
|
92
94
|
console.log("");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
if (payload.summary) {
|
|
96
|
+
console.log("Business description (Vatio still adds it to every prompt):");
|
|
97
|
+
console.log(indent(payload.summary));
|
|
98
|
+
console.log(
|
|
99
|
+
` ${DESCRIPTION_MOVED} Once live runs that version, \`vatio business set --clear-description\` removes this one.`
|
|
100
|
+
);
|
|
101
|
+
console.log("");
|
|
102
|
+
}
|
|
95
103
|
|
|
96
104
|
console.log("Brand:");
|
|
97
105
|
console.log(` logo ${payload.logo_url ?? "none (vatio business set --logo FILE)"}`);
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -108,8 +108,8 @@ export async function push(config, args) {
|
|
|
108
108
|
|
|
109
109
|
// The remote has to exist before the workspace can be checked: the slug is in
|
|
110
110
|
// the URL of the call that checks it. It is created unnamed; the display name
|
|
111
|
-
// is the business name (`vatio business set --name`, or the inbox's
|
|
112
|
-
//
|
|
111
|
+
// is the business name (`vatio business set --name`, or the inbox's Channels
|
|
112
|
+
// → Web widget), not part of a push.
|
|
113
113
|
const clients = workspacesClient(config);
|
|
114
114
|
const created = !(await clients.workspaceExists(workspace));
|
|
115
115
|
if (created) {
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -93,8 +93,10 @@ function replyTarget(config, args, usage) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// What the inbox's Reportar does, from the terminal: a reply that was wrong,
|
|
96
|
-
// and what it should have done.
|
|
97
|
-
//
|
|
96
|
+
// and what it should have done. On live the note makes it a report and a
|
|
97
|
+
// test case; on preview it is a note for the coding agent, closed by the
|
|
98
|
+
// next push. A reply that is already right is not a flag: `vatio test add`
|
|
99
|
+
// keeps it.
|
|
98
100
|
async function addFlag(config, args) {
|
|
99
101
|
if (args.includes("--passes")) {
|
|
100
102
|
fail('A reply that is already right is a test, not a report: `vatio test add "WHAT IT SHOULD DO"` keeps it.');
|
|
@@ -112,9 +114,17 @@ async function addFlag(config, args) {
|
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
const reply = String(flag.reply ?? "").trim().replace(/\s+/g, " ");
|
|
115
|
-
|
|
117
|
+
const note = flag.environment === "preview";
|
|
118
|
+
console.log(
|
|
119
|
+
`${flag.rewritten ? "Rewrote" : note ? "Noted" : "Reported"} ${flag.public_id}, chat ${flag.chat_id} on ${flag.environment}:`
|
|
120
|
+
);
|
|
116
121
|
console.log(` [agent #${flag.message_id}] ${reply.length > 200 ? `${reply.slice(0, 200)}…` : reply}`);
|
|
117
|
-
if (
|
|
122
|
+
if (note) {
|
|
123
|
+
console.log(
|
|
124
|
+
"A note on preview, not a test case: `vatio flags` lists it for your coding agent until your next `vatio push` closes it. " +
|
|
125
|
+
'Once the agent gets it right, `vatio test add "WHAT IT SHOULD DO"` keeps that reply as a test.'
|
|
126
|
+
);
|
|
127
|
+
} else if (flag.test_case) {
|
|
118
128
|
console.log("It is a test case now: `vatio test` replays it, `vatio flags` lists it, `vatio flags rm` removes it.");
|
|
119
129
|
} else {
|
|
120
130
|
console.log("No visitor message comes before that reply, so there is nothing to replay: it is not a test case.");
|
|
@@ -175,9 +185,10 @@ export async function test(config, args) {
|
|
|
175
185
|
|
|
176
186
|
const TEST_ADD_USAGE = 'vatio test add "WHAT IT SHOULD DO" [--chat ID | --message ID] [--env NAME]';
|
|
177
187
|
|
|
178
|
-
// A reply
|
|
179
|
-
// turn, like a report's case, with no report for Vatio to
|
|
180
|
-
// set of `vatio chat --new` + `vatio test add` is a test
|
|
188
|
+
// A reply kept as a test of what it should do, right already or not yet: a
|
|
189
|
+
// photo of its turn, like a report's case, with no report for Vatio to
|
|
190
|
+
// triage or fix. A set of `vatio chat --new` + `vatio test add` is a test
|
|
191
|
+
// suite, and on preview the only way to make one: a flag there is a note.
|
|
181
192
|
async function addTest(config, args) {
|
|
182
193
|
const body = replyTarget(config, args, TEST_ADD_USAGE);
|
|
183
194
|
const { url, token } = workspaceBase(config);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Review and deliberately resend failed outbound WhatsApp messages. The
|
|
2
|
+
// platform owns the retry relationship and idempotency key; the CLI only
|
|
3
|
+
// selects attempts and makes the operator see them before sending.
|
|
4
|
+
|
|
5
|
+
import { deployClient } from "./deploy.mjs";
|
|
6
|
+
import { ask, fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
7
|
+
|
|
8
|
+
const MAX_BATCH = 200;
|
|
9
|
+
const USAGE = "vatio messages failed [--since DATE] [--until DATE] [--error-code CODE] [--error-contains TEXT] [--before ID] [--json]\n" +
|
|
10
|
+
" vatio messages resend ID [--env live]\n" +
|
|
11
|
+
" vatio messages resend --since DATE (--error-code CODE|--error-contains TEXT) [--until DATE] [--before ID] [--yes]";
|
|
12
|
+
|
|
13
|
+
export async function messages(config, args) {
|
|
14
|
+
const environment = takeEnv(args, { fallback: "live" });
|
|
15
|
+
const json = takeFlag(args, "--json");
|
|
16
|
+
const yes = takeFlag(args, "--yes") || takeFlag(args, "-y");
|
|
17
|
+
const since = takeValue(args, "--since");
|
|
18
|
+
const until = takeValue(args, "--until");
|
|
19
|
+
const errorCode = takeValue(args, "--error-code");
|
|
20
|
+
const errorContains = takeValue(args, "--error-contains");
|
|
21
|
+
const before = takeValue(args, "--before");
|
|
22
|
+
const status = takeValue(args, "--status");
|
|
23
|
+
const sub = args.shift() ?? "failed";
|
|
24
|
+
if (status !== null && status !== "failed") fail("Only --status failed is supported");
|
|
25
|
+
if (!(["failed", "resend"].includes(sub)) || (sub === "resend" && json)) fail(`Usage: ${USAGE}`);
|
|
26
|
+
if (args.length > 1 || (sub === "failed" && args.length > 0)) fail(`Usage: ${USAGE}`);
|
|
27
|
+
if (before !== null && !/^[1-9]\d*$/.test(before)) fail("--before needs a positive message ID");
|
|
28
|
+
|
|
29
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
30
|
+
const client = deployClient(config, workspace);
|
|
31
|
+
|
|
32
|
+
if (sub === "resend" && args.length === 1) {
|
|
33
|
+
if (!/^\d+$/.test(args[0]) || since || until || errorCode || errorContains || before) fail(`Usage: ${USAGE}`);
|
|
34
|
+
const { message, replayed } = await client.resendMessage(args[0], { environment });
|
|
35
|
+
console.log(`Message #${args[0]} → retry #${message.id} (${message.status})${replayed ? " — already created" : ""}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (sub === "resend" && (!since || (!errorCode && !errorContains))) {
|
|
40
|
+
fail("A batch resend needs --since and --error-code or --error-contains, so it cannot catch unrelated failures.\n" + USAGE);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const selection = { environment, since, until, errorCode, errorContains, before };
|
|
44
|
+
const { list, nextBefore } = await collect(client, selection);
|
|
45
|
+
if (sub === "failed" && json) return console.log(JSON.stringify({ messages: list, next_before: nextBefore }, null, 2));
|
|
46
|
+
|
|
47
|
+
console.log(`${list.length} failed message${list.length === 1 ? "" : "s"} on ${workspace} (${environment}):`);
|
|
48
|
+
for (const row of list) {
|
|
49
|
+
console.log(` #${row.id} ${row.created_at} ${row.mode} ${row.error_code || "?"} ${row.error_message || ""}`);
|
|
50
|
+
}
|
|
51
|
+
if (nextBefore) console.log(`More may match. Continue with --before ${nextBefore} after this batch.`);
|
|
52
|
+
if (sub === "failed" || list.length === 0) return;
|
|
53
|
+
|
|
54
|
+
if (!yes) {
|
|
55
|
+
if (!process.stdin.isTTY) fail("Nothing resent. Review the selection above, then pass --yes.");
|
|
56
|
+
const answer = (await ask(`Resend these ${list.length} messages? [y/N] `)).trim().toLowerCase();
|
|
57
|
+
if (!["y", "yes", "s", "si", "sí"].includes(answer)) return console.log("Nothing resent.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let resent = 0;
|
|
61
|
+
let replayed = 0;
|
|
62
|
+
let failed = 0;
|
|
63
|
+
for (const [index, row] of list.entries()) {
|
|
64
|
+
try {
|
|
65
|
+
const result = await client.resendMessage(row.id, { environment });
|
|
66
|
+
console.log(` #${row.id} → #${result.message.id} (${result.message.status})${result.replayed ? " — already created" : ""}`);
|
|
67
|
+
if (result.replayed) replayed += 1;
|
|
68
|
+
else resent += 1;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(` #${row.id} → could not resend: ${error.message}`);
|
|
71
|
+
failed += 1;
|
|
72
|
+
if ([401, 403, 429].includes(error.status)) break;
|
|
73
|
+
}
|
|
74
|
+
if (index < list.length - 1) await sleep(1_100);
|
|
75
|
+
}
|
|
76
|
+
const skipped = list.length - resent - replayed - failed;
|
|
77
|
+
console.log(`Queued ${resent} new retry attempt${resent === 1 ? "" : "s"}; ${replayed} already existed; ${failed} refused; ${skipped} not attempted.`);
|
|
78
|
+
if (failed > 0 || skipped > 0) process.exitCode = 1;
|
|
79
|
+
console.log("Follow their status in the inbox or server API.");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function collect(client, selection) {
|
|
83
|
+
const list = [];
|
|
84
|
+
let before = selection.before;
|
|
85
|
+
do {
|
|
86
|
+
const page = await client.failedMessages({ ...selection, before });
|
|
87
|
+
list.push(...(page.messages ?? []));
|
|
88
|
+
before = page.next_before ?? null;
|
|
89
|
+
} while (before !== null && list.length < MAX_BATCH);
|
|
90
|
+
return { list, nextBefore: before };
|
|
91
|
+
}
|
package/lib/commands/misc.mjs
CHANGED
|
@@ -153,7 +153,7 @@ export async function init(config, args) {
|
|
|
153
153
|
if (agentsNote) console.log(agentsNote);
|
|
154
154
|
if (!authorized) console.log(`Local only for now — \`vatio push\` is what creates ${slug} on the platform.`);
|
|
155
155
|
if (!authorized && String(name ?? "").trim() !== "") {
|
|
156
|
-
console.log("Set the display name once it exists: `vatio business set --name NAME`, or the inbox
|
|
156
|
+
console.log("Set the display name once it exists: `vatio business set --name NAME`, or in the inbox under Channels → Web widget.");
|
|
157
157
|
}
|
|
158
158
|
console.log("");
|
|
159
159
|
console.log("Next:");
|
|
@@ -200,7 +200,7 @@ function writeAgentsNote(target) {
|
|
|
200
200
|
// The smallest file that deploys: which workspace, and what the agent does.
|
|
201
201
|
// The slug is already validated as a slug, so it needs no quoting. The display
|
|
202
202
|
// name is not here: it is the business name, set with `vatio business set --name`
|
|
203
|
-
// or
|
|
203
|
+
// or in the inbox under Channels → Web widget.
|
|
204
204
|
function starterManifest(slug) {
|
|
205
205
|
const lines = ["# Which Vatio workspace this directory deploys to.", `workspace: ${slug}`, ""];
|
|
206
206
|
lines.push("agent:");
|
package/lib/help.mjs
CHANGED
|
@@ -79,9 +79,11 @@ Commands default as listed.
|
|
|
79
79
|
Every open report: the conversation, what each tool
|
|
80
80
|
answered, and what should have happened
|
|
81
81
|
flags add "NOTE" [--chat ID|--message ID] [--env NAME]
|
|
82
|
-
|
|
82
|
+
Flag a reply and what should have happened:
|
|
83
83
|
the agent's last one in the chat \`vatio chat\`
|
|
84
|
-
is in (default: preview).
|
|
84
|
+
is in (default: preview). On live it is a report
|
|
85
|
+
and a test case; on preview, a note for your
|
|
86
|
+
coding agent that the next push closes
|
|
85
87
|
flags rm ID [ID...] Remove a report and its test case, open or
|
|
86
88
|
resolved, as the inbox's Remove does
|
|
87
89
|
tools [--env NAME] [--period 1h|1d|7d|30d] [--json]
|
|
@@ -98,8 +100,8 @@ Commands default as listed.
|
|
|
98
100
|
test --show RUN_ID One run's report so far, with the replay chat of
|
|
99
101
|
each case that did not pass (vatio chat show ID)
|
|
100
102
|
test add "NOTE" [--chat ID|--message ID] [--env NAME]
|
|
101
|
-
Keep a reply
|
|
102
|
-
last one in the chat \`vatio chat\` is in
|
|
103
|
+
Keep a reply as a test of what it should do: the
|
|
104
|
+
agent's last one in the chat \`vatio chat\` is in
|
|
103
105
|
test list [--json] | test rm ID [ID...]
|
|
104
106
|
The tests \`test add\` made; reports are \`flags\`
|
|
105
107
|
eval Deprecated: \`vatio test --wait\` under its old name
|
|
@@ -118,11 +120,13 @@ Commands default as listed.
|
|
|
118
120
|
kb history BASE What reached live, newest first
|
|
119
121
|
(entry commands take --env; --env live writes live)
|
|
120
122
|
|
|
121
|
-
Business (one value for every environment, live on save; also
|
|
122
|
-
|
|
123
|
-
business [show] Name, description
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
Business (one value for every environment, live on save; also in the inbox,
|
|
124
|
+
under Channels → Web widget):
|
|
125
|
+
business [show] Name and brand, and the old business description
|
|
126
|
+
if there is one
|
|
127
|
+
business set [--name NAME] [--about TEXT] [--color #RRGGBB|default]
|
|
128
|
+
[--logo FILE | --remove-logo] [--clear-description]
|
|
129
|
+
What the business does goes in agent.instructions
|
|
126
130
|
|
|
127
131
|
Credentials:
|
|
128
132
|
secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]
|
|
@@ -140,6 +144,19 @@ Commands default as listed.
|
|
|
140
144
|
Your users sign in with Supabase: verify their
|
|
141
145
|
session, no keys or signing code
|
|
142
146
|
|
|
147
|
+
Recover outbound WhatsApp messages (with your developer login):
|
|
148
|
+
Live templates rejected for payment eligibility retry automatically;
|
|
149
|
+
these commands inspect progress and recover other confirmed failures.
|
|
150
|
+
messages failed [--since DATE] [--until DATE] [--error-code CODE]
|
|
151
|
+
[--error-contains TEXT] [--before ID] [--json]
|
|
152
|
+
List failed outgoing messages, including Meta's
|
|
153
|
+
delivery failures (default: live)
|
|
154
|
+
messages resend ID Retry one confirmed failure once
|
|
155
|
+
messages resend --since DATE (--error-code CODE|--error-contains TEXT) [--before ID] [--yes]
|
|
156
|
+
Preview a matching batch, then retry it. --yes
|
|
157
|
+
is required without a terminal. At most 200
|
|
158
|
+
messages per batch; use --before to continue
|
|
159
|
+
|
|
143
160
|
Sending from your backend (WhatsApp, with a server key):
|
|
144
161
|
templates list [--env live] [--json]
|
|
145
162
|
The number's templates, parameter counts, and the
|
package/lib/telemetry.mjs
CHANGED
|
@@ -26,6 +26,7 @@ const MAX_MESSAGE = 2_000;
|
|
|
26
26
|
// there is a value (`vatio chat "hola"`), and values are not sent.
|
|
27
27
|
const SUBCOMMANDS = {
|
|
28
28
|
chat: ["show"],
|
|
29
|
+
messages: ["failed", "resend"],
|
|
29
30
|
env: ["list", "rm"],
|
|
30
31
|
kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
|
|
31
32
|
business: ["show", "set"],
|