@vatio-ai/cli 0.132.0 → 0.134.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 +28 -3
- package/lib/api-client.mjs +31 -6
- package/lib/bundle.mjs +1 -1
- package/lib/commands/auth.mjs +1 -1
- package/lib/commands/channels.mjs +14 -3
- package/lib/commands/chat.mjs +55 -53
- package/lib/commands/deploy.mjs +1 -1
- package/lib/commands/improve.mjs +22 -35
- package/lib/commands/messages.mjs +3 -3
- package/lib/commands/owner.mjs +159 -0
- package/lib/commands/reach.mjs +104 -0
- package/lib/commands/support-commands.mjs +1 -1
- package/lib/commands/team.mjs +43 -6
- package/lib/commands/webhooks.mjs +13 -13
- package/lib/commands/workspace-admin.mjs +11 -9
- package/lib/config.mjs +1 -1
- package/lib/device-auth.mjs +3 -3
- package/lib/help.mjs +50 -11
- package/lib/http.mjs +12 -3
- package/lib/suggest.mjs +10 -1
- package/lib/support.mjs +9 -0
- package/lib/telemetry.mjs +10 -3
- package/lib/workspace.mjs +1 -1
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -26,6 +26,8 @@ import { team } from "../lib/commands/team.mjs";
|
|
|
26
26
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
27
27
|
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
28
28
|
import { test, tools } from "../lib/commands/improve.mjs";
|
|
29
|
+
import { activity, plan, security, supportAccess, transfer, workspace } from "../lib/commands/owner.mjs";
|
|
30
|
+
import { analytics, testers, widget } from "../lib/commands/reach.mjs";
|
|
29
31
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
30
32
|
import { runLatest } from "../lib/run-latest.mjs";
|
|
31
33
|
import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/telemetry.mjs";
|
|
@@ -35,8 +37,6 @@ import { beginRun, isCodingAgent, reportRun, telemetryEnabled } from "../lib/tel
|
|
|
35
37
|
const RETIRED = {
|
|
36
38
|
issue: "was removed: report a problem on the public repository it belongs to --\n" +
|
|
37
39
|
"https://github.com/vatio-ai/cli/issues (or sdk, ios, ruby under github.com/vatio-ai).",
|
|
38
|
-
widget: "was removed: `vatio env` prints the snippet and its token, and the look is edited in\n" +
|
|
39
|
-
"the inbox, under Channels → Widget.",
|
|
40
40
|
mcp: "was removed: the Vatio MCP is https://vatio.ai/mcp, and `npx @vatio-ai/skills` adds it to a project.",
|
|
41
41
|
update: "is npm's job: `npx @vatio-ai/cli@latest` always runs the current release, and\n" +
|
|
42
42
|
"`npm install -g @vatio-ai/cli@latest` updates a global install.\n" +
|
|
@@ -133,6 +133,24 @@ async function run(command, args) {
|
|
|
133
133
|
return await test(config, args);
|
|
134
134
|
case "tools":
|
|
135
135
|
return await tools(config, args);
|
|
136
|
+
case "widget":
|
|
137
|
+
return await widget(config, args);
|
|
138
|
+
case "analytics":
|
|
139
|
+
return await analytics(config, args);
|
|
140
|
+
case "testers":
|
|
141
|
+
return await testers(config, args);
|
|
142
|
+
case "security":
|
|
143
|
+
return await security(config, args);
|
|
144
|
+
case "activity":
|
|
145
|
+
return await activity(config, args);
|
|
146
|
+
case "support-access":
|
|
147
|
+
return await supportAccess(config, args);
|
|
148
|
+
case "transfer":
|
|
149
|
+
return await transfer(config, args);
|
|
150
|
+
case "workspace":
|
|
151
|
+
return await workspace(config, args);
|
|
152
|
+
case "plan":
|
|
153
|
+
return await plan(config, args);
|
|
136
154
|
case "changelog":
|
|
137
155
|
return await changelog(config, args);
|
|
138
156
|
case "docs":
|
|
@@ -174,8 +192,15 @@ function printError(error) {
|
|
|
174
192
|
console.error("Authentication failed (401). Run `vatio login`.");
|
|
175
193
|
return printTrailer(error);
|
|
176
194
|
}
|
|
195
|
+
// The platform says why, in the same words the MCP and the inbox get; the
|
|
196
|
+
// generic lines below are for an answer that does not.
|
|
197
|
+
const said = error?.body?.error_description;
|
|
177
198
|
if (error instanceof ForbiddenError) {
|
|
178
|
-
console.error("Access denied (403). Your token cannot access this workspace.");
|
|
199
|
+
console.error(said ? `Access denied (403): ${said}` : "Access denied (403). Your token cannot access this workspace.");
|
|
200
|
+
return printTrailer(error);
|
|
201
|
+
}
|
|
202
|
+
if (error instanceof NotFoundError && said && error.body.error !== "workspace_not_found") {
|
|
203
|
+
console.error(`Not found (404): ${said}`);
|
|
179
204
|
return printTrailer(error);
|
|
180
205
|
}
|
|
181
206
|
if (error instanceof NotFoundError) {
|
package/lib/api-client.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// Everything the CLI can ask of one workspace: /api/
|
|
1
|
+
// Everything the CLI can ask of one workspace: /api/v1/:slug/*, the API the MCP
|
|
2
|
+
// and the inbox call too (Api::V1::BaseController on the platform).
|
|
2
3
|
//
|
|
3
4
|
// One class rather than a client per surface. They share a host, a token and an
|
|
4
5
|
// error contract, and splitting them only ever meant passing the same three
|
|
@@ -251,6 +252,18 @@ export class ApiClient extends HttpClient {
|
|
|
251
252
|
return this.post("/members", body);
|
|
252
253
|
}
|
|
253
254
|
|
|
255
|
+
updateMember(id, body) {
|
|
256
|
+
return this.patch(`/members/${encode(id)}`, body);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
removeMember(id) {
|
|
260
|
+
return this.delete(`/members/${encode(id)}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
resendMember(id) {
|
|
264
|
+
return this.post(`/members/${encode(id)}/resend`, {});
|
|
265
|
+
}
|
|
266
|
+
|
|
254
267
|
// --- quiet hours ----------------------------------------------------
|
|
255
268
|
|
|
256
269
|
// The weekly schedule in which the agent does not answer, or null.
|
|
@@ -357,15 +370,27 @@ export class ApiClient extends HttpClient {
|
|
|
357
370
|
|
|
358
371
|
// `files` are `{ name, bytes }`, sent as the public API takes a visitor's
|
|
359
372
|
// (multipart `files[]`), so the agent reads them as it would on the web.
|
|
360
|
-
|
|
361
|
-
|
|
373
|
+
// `wait`: answer once the turn is over (or the wait runs out, at most 20
|
|
374
|
+
// seconds), with what it said (Vatio::Preview::Turn on the platform).
|
|
375
|
+
sendChatMessage({ chatId, content, files = [], wait = null }) {
|
|
376
|
+
if (files.length === 0) {
|
|
377
|
+
const body = { content };
|
|
378
|
+
if (wait) body.wait = wait;
|
|
379
|
+
return this.post(`/chats/${encode(chatId)}/messages`, body);
|
|
380
|
+
}
|
|
362
381
|
|
|
363
382
|
const form = new FormData();
|
|
364
383
|
if (content) form.set("content", content);
|
|
384
|
+
if (wait) form.set("wait", String(wait));
|
|
365
385
|
for (const file of files) form.append("files[]", new Blob([file.bytes]), file.name);
|
|
366
386
|
return this.post(`/chats/${encode(chatId)}/messages`, form);
|
|
367
387
|
}
|
|
368
388
|
|
|
389
|
+
// The turn that answers message `after`, waiting up to `wait` seconds more.
|
|
390
|
+
chatTurn({ chatId, after, wait }) {
|
|
391
|
+
return this.get(`/chats/${encode(chatId)}/turn`, { after, wait });
|
|
392
|
+
}
|
|
393
|
+
|
|
369
394
|
exportChats({ from, to = null, environment = null, channel = null, after = null }) {
|
|
370
395
|
const params = { from };
|
|
371
396
|
if (to) params.to = to;
|
|
@@ -377,17 +402,17 @@ export class ApiClient extends HttpClient {
|
|
|
377
402
|
|
|
378
403
|
}
|
|
379
404
|
|
|
380
|
-
// /api/
|
|
405
|
+
// /api/v1/workspaces -- not workspace-scoped, so it takes the bare host.
|
|
381
406
|
export class CliClient extends HttpClient {
|
|
382
407
|
listWorkspaces() {
|
|
383
|
-
return this.get("/api/
|
|
408
|
+
return this.get("/api/v1/workspaces");
|
|
384
409
|
}
|
|
385
410
|
|
|
386
411
|
createWorkspace({ slug, name = null, organization = null }) {
|
|
387
412
|
const body = { slug };
|
|
388
413
|
if (String(name ?? "").trim() !== "") body.name = String(name).trim();
|
|
389
414
|
if (String(organization ?? "").trim() !== "") body.organization = String(organization).trim().toLowerCase();
|
|
390
|
-
return this.post("/api/
|
|
415
|
+
return this.post("/api/v1/workspaces", body);
|
|
391
416
|
}
|
|
392
417
|
|
|
393
418
|
async workspaceExists(slug) {
|
package/lib/bundle.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The workspace directory as the bytes that go on the wire, for
|
|
2
|
-
// POST /api/
|
|
2
|
+
// POST /api/v1/:slug/check. The port of cli/lib/workspace_bundle.rb.
|
|
3
3
|
//
|
|
4
4
|
// There is deliberately no list here of "the files a manifest reads". That list
|
|
5
5
|
// *is* the contract -- `widget.logo` and `identity.public_key` name files from
|
package/lib/commands/auth.mjs
CHANGED
|
@@ -98,7 +98,7 @@ export async function logout(config) {
|
|
|
98
98
|
let revoked = false;
|
|
99
99
|
if (token) {
|
|
100
100
|
try {
|
|
101
|
-
const response = await fetch(`${config.resolveBaseUrl()}/api/
|
|
101
|
+
const response = await fetch(`${config.resolveBaseUrl()}/api/v1/session`, {
|
|
102
102
|
method: "DELETE",
|
|
103
103
|
headers: { ...clientHeaders(), Accept: "application/json", Authorization: `Bearer ${token}` },
|
|
104
104
|
signal: AbortSignal.timeout(LOGOUT_TIMEOUT_MS)
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { deployClient, whatsappIssueLines } from "./deploy.mjs";
|
|
9
9
|
import { messages } from "./messages.mjs";
|
|
10
10
|
import { withSecondFactor } from "./team.mjs";
|
|
11
|
+
import { errorCode } from "../http.mjs";
|
|
11
12
|
import { templates } from "./webhooks.mjs";
|
|
12
13
|
import { ask, fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
13
14
|
|
|
@@ -112,12 +113,22 @@ async function inInbox(config, channel) {
|
|
|
112
113
|
console.log(` ${published ? url : (status.try_url ?? url)}`);
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
// What `vatio whatsapp --json` has always printed: the number, not everything
|
|
117
|
+
// the inbox's WhatsApp page draws from the same answer.
|
|
118
|
+
const NUMBER_KEYS = ["connect_url", "connected", "number", "live", "state", "issue", "last_health_error",
|
|
119
|
+
"last_health_check_at", "failed_deliveries", "wa_me_url"];
|
|
120
|
+
|
|
121
|
+
function numberOnly(answer) {
|
|
122
|
+
return Object.fromEntries(NUMBER_KEYS.filter((key) => key in answer).map((key) => [key, answer[key]]));
|
|
123
|
+
}
|
|
124
|
+
|
|
115
125
|
async function status(config, client, { json }) {
|
|
116
126
|
let number = null;
|
|
117
127
|
try {
|
|
118
|
-
|
|
128
|
+
const answer = await client.getWhatsapp();
|
|
129
|
+
if (answer.connected !== false) number = numberOnly(answer);
|
|
119
130
|
} catch (error) {
|
|
120
|
-
if (error
|
|
131
|
+
if (errorCode(error) !== "whatsapp_not_connected") throw error;
|
|
121
132
|
}
|
|
122
133
|
if (json) return console.log(JSON.stringify(number ?? { connected: false }, null, 2));
|
|
123
134
|
// A number Meta refuses every send from comes before anything else.
|
|
@@ -169,7 +180,7 @@ function printTeam({ members = [] }, { json }) {
|
|
|
169
180
|
}
|
|
170
181
|
|
|
171
182
|
function printNumber(number, { json = false, checked = false } = {}) {
|
|
172
|
-
if (json) return console.log(JSON.stringify(number, null, 2));
|
|
183
|
+
if (json) return console.log(JSON.stringify(numberOnly(number), null, 2));
|
|
173
184
|
const name = number.number ?? "Your number";
|
|
174
185
|
if (number.issue) {
|
|
175
186
|
console.log("");
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
// does the widget's and WhatsApp's, so this gives you nothing you did not
|
|
14
14
|
// already hold (lib/visitor-identity.mjs, Vatio::Preview::Tester).
|
|
15
15
|
|
|
16
|
+
import { conversation } from "./reach.mjs";
|
|
16
17
|
import { randomBytes } from "node:crypto";
|
|
17
18
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
18
19
|
import { basename, dirname, join } from "node:path";
|
|
19
20
|
|
|
20
21
|
import { ApiClient } from "../api-client.mjs";
|
|
21
22
|
import { configHome } from "../config.mjs";
|
|
22
|
-
import { fail,
|
|
23
|
+
import { fail, takeAll, takeEnv, takeFlag, takeSide, takeValue } from "../support.mjs";
|
|
23
24
|
import { IDENTITY_FLAGS_USAGE, takeIdentity, tokenFor } from "../visitor-identity.mjs";
|
|
24
25
|
|
|
25
26
|
export const STATE_FILE = ".vatio-chat.json";
|
|
@@ -46,6 +47,7 @@ export async function chat(config, args) {
|
|
|
46
47
|
// Not a conversation of your own, so none of what follows applies to it,
|
|
47
48
|
// and its --from and --channel mean dates and a channel to read.
|
|
48
49
|
if (args[0] === "export") return await exportChats(config, args.slice(1));
|
|
50
|
+
if (args[0] === "reply" || args[0] === "release") return await conversation(config, args[0], args.slice(1));
|
|
49
51
|
|
|
50
52
|
for (const arg of args) {
|
|
51
53
|
if (REMOVED_FLAGS.some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
@@ -53,7 +55,7 @@ export async function chat(config, args) {
|
|
|
53
55
|
`\`${arg}\` was removed. A CLI chat is you, the developer holding the token, unless you say who: ` +
|
|
54
56
|
"--as-phone speaks as your verified WhatsApp (me) or a customer phone, --as-subject ID signs a visitor in " +
|
|
55
57
|
"with your identity key, and --visitor-token brings a token you have; " +
|
|
56
|
-
"to
|
|
58
|
+
"it talks to the newest version, the one your team has."
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -114,7 +116,7 @@ export function chatHelp() {
|
|
|
114
116
|
return `Usage:
|
|
115
117
|
vatio chat "message" [--file PATH]... [--new] [--timeout N] [--as-phone me|PHONE] ${IDENTITY_FLAGS_USAGE}
|
|
116
118
|
vatio chat --chat CHAT_ID "message" [--file PATH]...
|
|
117
|
-
vatio chat show [CHAT_ID] [--
|
|
119
|
+
vatio chat show [CHAT_ID] [--last N] [--json]
|
|
118
120
|
${EXPORT_USAGE}
|
|
119
121
|
|
|
120
122
|
It talks to the newest version, the one your team has: a change you just
|
|
@@ -161,7 +163,7 @@ workspace's customer phones (added in the inbox, under Conversations → Try the
|
|
|
161
163
|
agent → WhatsApp) is a customer. It stays a CLI chat: nothing goes to WhatsApp.
|
|
162
164
|
|
|
163
165
|
\`export\` prints what people said and what they were answered between two
|
|
164
|
-
dates (
|
|
166
|
+
dates (your customers', or your team's own with --team), one conversation per line as JSON,
|
|
165
167
|
for reading them in bulk -- with a coding agent, say. Vatio redacts it before
|
|
166
168
|
it leaves: names, emails, phone numbers and RUTs it knows are [FILTERED], and
|
|
167
169
|
\`person\` stands for whoever it was without naming them. Anyone on the
|
|
@@ -169,12 +171,12 @@ workspace's team can run it, a viewer too, and every call is in the
|
|
|
169
171
|
workspace's activity. Dates are whole days; --to defaults to now.`;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
const EXPORT_USAGE = "vatio chat export --from DATE [--to DATE] [--
|
|
174
|
+
const EXPORT_USAGE = "vatio chat export --from DATE [--to DATE] [--team] [--channel NAME] [--out FILE]";
|
|
173
175
|
|
|
174
176
|
// One page at a time, written as it arrives: a month of a busy WhatsApp number
|
|
175
177
|
// does not have to fit in memory to be read.
|
|
176
178
|
async function exportChats(config, args) {
|
|
177
|
-
const environment =
|
|
179
|
+
const environment = takeSide(args, "--team");
|
|
178
180
|
const from = takeValue(args, "--from");
|
|
179
181
|
const to = takeValue(args, "--to");
|
|
180
182
|
const channel = takeValue(args, "--channel");
|
|
@@ -372,14 +374,53 @@ function speaker(payload) {
|
|
|
372
374
|
async function converse(config, options, message, opened = null) {
|
|
373
375
|
const api = client(config, options);
|
|
374
376
|
const chatId = opened ?? (await chatToContinue(config, options));
|
|
375
|
-
const
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
377
|
+
const turn = await sendAndWait(api, { chatId, content: message, files: options.files ?? [], timeout: options.timeout });
|
|
378
|
+
if (options.files?.length > 0) for (const attachment of turn.sent_attachments ?? []) console.log(attachmentLine(attachment));
|
|
379
|
+
console.log(turnLines(turn, chatId).join("\n"));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// The longest one request waits on the platform; past it, the turn is read
|
|
383
|
+
// again until `timeout`.
|
|
384
|
+
const TURN_WAIT = 20;
|
|
385
|
+
|
|
386
|
+
// Sends the message and waits for the whole turn that answers it, as the
|
|
387
|
+
// MCP's chat_with_agent does (Vatio::Preview::Turn): not the first draft, which
|
|
388
|
+
// a safeguard may throw away, but what the visitor got.
|
|
389
|
+
async function sendAndWait(api, { chatId, content, files, timeout }) {
|
|
390
|
+
const deadline = Date.now() + timeout * 1000;
|
|
391
|
+
let turn = await api.sendChatMessage({ chatId, content, files, wait: Math.min(TURN_WAIT, timeout) });
|
|
392
|
+
while (turn.turn === "answering") {
|
|
393
|
+
const left = Math.ceil((deadline - Date.now()) / 1000);
|
|
394
|
+
if (left <= 0) fail(`Timed out waiting for the agent's reply after ${timeout}s: \`vatio chat show ${chatId}\` reads it later.`);
|
|
395
|
+
turn = await api.chatTurn({ chatId, after: turn.user_message_id, wait: Math.min(TURN_WAIT, left) });
|
|
396
|
+
}
|
|
397
|
+
return turn;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// What the turn said: every reply the visitor got, in order (a paced agent
|
|
401
|
+
// sends several), what a safeguard changed, and why there is none when there
|
|
402
|
+
// is none.
|
|
403
|
+
function turnLines(turn, chatId) {
|
|
404
|
+
if (turn.turn === "taken_over") {
|
|
405
|
+
return ["Someone on the team took this conversation over in the inbox, so the agent does not answer it " +
|
|
406
|
+
`until they hand it back (vatio chat release ${chatId}).`];
|
|
407
|
+
}
|
|
408
|
+
const entries = turn.entries ?? [];
|
|
409
|
+
const replies = entries.filter((entry) => entry.role === "assistant" && visitorVisible(entry));
|
|
410
|
+
const notes = entries.flatMap((entry) => (safeguardNote(entry.safeguard) ? [safeguardNote(entry.safeguard)] : []));
|
|
411
|
+
if (replies.length === 0) {
|
|
412
|
+
const why = turn.quiet_hours
|
|
413
|
+
? "Quiet hours are on, so the agent did not answer; the message waits in the inbox."
|
|
414
|
+
: "The turn ended without a reply.";
|
|
415
|
+
return [why, ...notes, `vatio chat show ${chatId} shows the whole turn.`];
|
|
416
|
+
}
|
|
417
|
+
return [...replies.map((reply) => formatVisitor(reply)), ...notes];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function safeguardNote(safeguard) {
|
|
421
|
+
if (!safeguard || !safeguard.policy) return null;
|
|
422
|
+
const done = safeguard.action === "discarded" ? "discarded a draft and asked the model again" : "rewrote the reply before it went out";
|
|
423
|
+
return `(the ${safeguard.policy} safeguard ${done})`;
|
|
383
424
|
}
|
|
384
425
|
|
|
385
426
|
function readFiles(paths) {
|
|
@@ -399,14 +440,6 @@ function readFiles(paths) {
|
|
|
399
440
|
});
|
|
400
441
|
}
|
|
401
442
|
|
|
402
|
-
// The message as stored, by the id the send returned: what was read of each
|
|
403
|
-
// file by the time the agent answered.
|
|
404
|
-
async function printSentFiles(api, chatId, messageId) {
|
|
405
|
-
const payload = await api.chatMessages({ chatId, after: messageId - 1 });
|
|
406
|
-
const stored = (Array.isArray(payload.data) ? payload.data : []).find((entry) => entry.id === messageId);
|
|
407
|
-
for (const attachment of stored?.attachments ?? []) console.log(attachmentLine(attachment));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
443
|
// One file a message carried, and what the agent was given of it: a PDF's
|
|
411
444
|
// reading (Vatio::Runtime::MediaPolicy.document_reading), or a video's
|
|
412
445
|
// description.
|
|
@@ -444,21 +477,6 @@ const visitorVisible = (entry) =>
|
|
|
444
477
|
["user", "assistant"].includes(entry.role) &&
|
|
445
478
|
String(entry.content ?? "").trim() !== "";
|
|
446
479
|
|
|
447
|
-
// Conversations are asynchronous: post a message, then poll for the reply.
|
|
448
|
-
async function waitForAssistant(api, { chatId, after, timeout, interval = 2 }) {
|
|
449
|
-
const deadline = Date.now() + timeout * 1000;
|
|
450
|
-
for (;;) {
|
|
451
|
-
const payload = await api.chatMessages({ chatId, after });
|
|
452
|
-
const messages = Array.isArray(payload.data) ? payload.data : [];
|
|
453
|
-
const assistant = [...messages]
|
|
454
|
-
.reverse()
|
|
455
|
-
.find((entry) => entry.role === "assistant" && visitorVisible(entry));
|
|
456
|
-
if (assistant) return assistant;
|
|
457
|
-
if (Date.now() >= deadline) fail(`Timed out waiting for assistant reply after ${timeout}s`);
|
|
458
|
-
await sleep(interval * 1000);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
480
|
// Every message, not the first page: a chat worth reading by id is usually one
|
|
463
481
|
// that went wrong somewhere in the middle.
|
|
464
482
|
async function allMessages(api, chatId) {
|
|
@@ -598,22 +616,6 @@ function truncate(text, max) {
|
|
|
598
616
|
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
599
617
|
}
|
|
600
618
|
|
|
601
|
-
// One question in a new chat, for `vatio test add "QUESTION" "WHAT IT SHOULD
|
|
602
|
-
// DO"`: the chat becomes the one `vatio chat` continues, and the reply is the
|
|
603
|
-
// one the test is made on.
|
|
604
|
-
export async function askInNewChat(config, { environment, asPhone = null, identity = null, timeout = 120 }, question) {
|
|
605
|
-
const options = { environment, asPhone, identity, timeout, apiUrl: null, token: null };
|
|
606
|
-
const apiUrl = config.resolveApiUrl({ explicit: null });
|
|
607
|
-
const payload = await openChat(config, options, { apiUrl, chatId: chatsFor(config, apiUrl)[environment] ?? null });
|
|
608
|
-
const chatId = Number(payload.chat_id);
|
|
609
|
-
const api = client(config, options);
|
|
610
|
-
const sent = await api.sendChatMessage({ chatId, content: question });
|
|
611
|
-
const reply = await waitForAssistant(api, { chatId, after: sent.user_message_id, timeout });
|
|
612
|
-
console.log(`[you] ${question}`);
|
|
613
|
-
console.log(formatVisitor(reply));
|
|
614
|
-
return reply;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
619
|
async function startOver(config, options) {
|
|
618
620
|
const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
|
|
619
621
|
const payload = await openChat(config, options, {
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export function deployClient(config, workspace) {
|
|
|
49
49
|
const token = config.resolveToken();
|
|
50
50
|
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
|
|
51
51
|
|
|
52
|
-
return new ApiClient({ baseUrl: `${base}/api/
|
|
52
|
+
return new ApiClient({ baseUrl: `${base}/api/v1/${workspace}`, token });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export function workspacesClient(config) {
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
|
|
|
11
11
|
import { dirname, resolve } from "node:path";
|
|
12
12
|
|
|
13
13
|
import { HttpClient, NotFoundError, throwIfOutdated } from "../http.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { rememberedChatId } from "./chat.mjs";
|
|
15
15
|
import { clientHeaders } from "../telemetry.mjs";
|
|
16
16
|
import { fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
17
17
|
import { printSkillsHint } from "../skills-hint.mjs";
|
|
@@ -27,7 +27,7 @@ function workspaceBase(config) {
|
|
|
27
27
|
const base = config.resolveBaseUrl();
|
|
28
28
|
const token = config.resolveToken();
|
|
29
29
|
if (!token) fail(`Run \`vatio login\` first (no token in ${config.configPath})`);
|
|
30
|
-
return { url: `${base}/api/
|
|
30
|
+
return { url: `${base}/api/v1/${config.resolveWorkspaceRequired()}`, token };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async function fetchMarkdown(config, path, what) {
|
|
@@ -69,7 +69,7 @@ export async function tools(config, args) {
|
|
|
69
69
|
const environment = takeEnv(args, { fallback: "live" });
|
|
70
70
|
const period = takeValue(args, "--period");
|
|
71
71
|
const json = takeFlag(args, "--json");
|
|
72
|
-
if (args.length > 0) fail("Usage: vatio tools [--
|
|
72
|
+
if (args.length > 0) fail("Usage: vatio tools [--period 1h|1d|7d|30d] [--json]");
|
|
73
73
|
|
|
74
74
|
if (json) {
|
|
75
75
|
const { url, token } = workspaceBase(config);
|
|
@@ -94,15 +94,16 @@ export async function test(config, args) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const TEST_ADD_USAGE =
|
|
97
|
-
'vatio test add "QUESTION" "WHAT IT SHOULD DO" [--as-phone me|PHONE] [--as-subject ID]
|
|
98
|
-
' vatio test add "WHAT IT SHOULD DO" [--chat ID | --message ID]
|
|
97
|
+
'vatio test add "QUESTION" "WHAT IT SHOULD DO" [--as-phone me|PHONE] [--as-subject ID]\n' +
|
|
98
|
+
' vatio test add "WHAT IT SHOULD DO" [--chat ID | --message ID]';
|
|
99
99
|
|
|
100
100
|
// What the agent should do when asked something, checked on every version.
|
|
101
101
|
// With a question, Vatio asks it in a new chat and the test is made on that
|
|
102
102
|
// turn; with only what it should do, on the agent's last reply in the chat
|
|
103
103
|
// `vatio chat` is in, or --chat's, or --message's (a reply a visitor got, or a
|
|
104
|
-
// report's, whose note it rewrites).
|
|
105
|
-
//
|
|
104
|
+
// report's, whose note it rewrites). The platform saves and judges it in the
|
|
105
|
+
// background, the way the MCP's add_test does; this waits for the verdict, so
|
|
106
|
+
// you know whether the test is a guard or work still to do.
|
|
106
107
|
async function addTest(config, args) {
|
|
107
108
|
const environment = takeEnv(args, { fallback: "preview" });
|
|
108
109
|
const chatId = takeValue(args, "--chat");
|
|
@@ -117,46 +118,32 @@ async function addTest(config, args) {
|
|
|
117
118
|
const [first, second] = args.map((arg) => arg.trim());
|
|
118
119
|
if (!first || (args.length === 2 && !second)) fail(`Usage: ${TEST_ADD_USAGE}`);
|
|
119
120
|
|
|
120
|
-
let
|
|
121
|
-
let note;
|
|
121
|
+
let body;
|
|
122
122
|
if (args.length === 2) {
|
|
123
123
|
if (chatId || messageId) fail("A question opens its own chat: drop --chat and --message, or the question.");
|
|
124
|
-
|
|
125
|
-
target = { message_id: reply.id };
|
|
126
|
-
note = second;
|
|
124
|
+
body = { question: first, should: second, environment, as_phone: asPhone, visitor_token: identity ? tokenFor(identity) : null };
|
|
127
125
|
} else {
|
|
128
126
|
if (asPhone || identity) fail("--as-phone and --as-subject go with a question: `vatio test add \"QUESTION\" \"WHAT IT SHOULD DO\"`.");
|
|
129
127
|
if (chatId && messageId) fail(`--chat or --message, not both. Usage: ${TEST_ADD_USAGE}`);
|
|
130
|
-
target = messageId ? { message_id: messageId } : { chat_id: chatId ?? rememberedChatId(config, environment) };
|
|
128
|
+
const target = messageId ? { message_id: messageId } : { chat_id: chatId ?? rememberedChatId(config, environment) };
|
|
131
129
|
if (!target.message_id && !target.chat_id) {
|
|
132
130
|
fail(`No ${environment} chat yet: \`vatio test add "QUESTION" "WHAT IT SHOULD DO"\` asks it, or pass --chat ID or --message ID.`);
|
|
133
131
|
}
|
|
134
|
-
|
|
132
|
+
body = { ...target, should: first };
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
const { url, token } = workspaceBase(config);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log(`${added.rewritten ? "Rewrote" : "Added"} ${what} (agent \`${added.agent}\`, chat ${added.chat_id}):`);
|
|
148
|
-
console.log(` Visitor: ${String(added.asked ?? "").trim().replace(/\s+/g, " ").slice(0, 200)}`);
|
|
149
|
-
console.log(` Should: ${added.note}`);
|
|
150
|
-
const judged = added.judged ?? {};
|
|
151
|
-
if (judged.verdict === "pass") {
|
|
152
|
-
console.log(` Passes now: ${judged.reason}`);
|
|
153
|
-
console.log("`vatio test` replays it on every version; once everyone's version passes it, a change that fails it does not reach them.");
|
|
154
|
-
} else if (judged.verdict === "fail") {
|
|
155
|
-
console.log(` Fails now: ${judged.reason}`);
|
|
156
|
-
console.log("Fix the agent, `vatio push`, then `vatio test`: `vatio test list` shows it with its replay once it has run.");
|
|
157
|
-
} else {
|
|
158
|
-
console.log(` Not judged now${judged.error ? `: ${judged.error}` : ""}. \`vatio test\` judges it with the rest.`);
|
|
136
|
+
const api = new HttpClient({ baseUrl: url, token });
|
|
137
|
+
const deadline = Date.now() + timeout * 1000;
|
|
138
|
+
let answer = await api.post("/evals/cases", Object.fromEntries(Object.entries(body).filter(([, value]) => value)));
|
|
139
|
+
while (!answer.text) {
|
|
140
|
+
if (Date.now() >= deadline) {
|
|
141
|
+
fail(`Still ${answer.status} after ${timeout}s: \`vatio test list\` shows the test once it is saved.`);
|
|
142
|
+
}
|
|
143
|
+
await sleep(Math.max(1, Math.min(answer.check_in_seconds ?? 5, (deadline - Date.now()) / 1000)) * 1000);
|
|
144
|
+
answer = await api.get("/evals/cases/lookup", { chat_id: answer.chat_id });
|
|
159
145
|
}
|
|
146
|
+
console.log(answer.text);
|
|
160
147
|
}
|
|
161
148
|
|
|
162
149
|
// What there is to fix, then the whole suite: the reports still open, each
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Review terminal failures after Vatio has finished its automatic attempts.
|
|
2
2
|
|
|
3
3
|
import { deployClient } from "./deploy.mjs";
|
|
4
|
-
import { fail,
|
|
4
|
+
import { fail, takeFlag, takeSide, takeValue } from "../support.mjs";
|
|
5
5
|
|
|
6
|
-
const USAGE = "vatio whatsapp failed [--since DATE] [--until DATE] [--error-code CODE] " +
|
|
6
|
+
const USAGE = "vatio whatsapp failed [--test] [--since DATE] [--until DATE] [--error-code CODE] " +
|
|
7
7
|
"[--error-contains TEXT] [--before ID] [--json]";
|
|
8
8
|
|
|
9
9
|
export async function messages(config, args) {
|
|
10
|
-
const environment =
|
|
10
|
+
const environment = takeSide(args, "--test");
|
|
11
11
|
const json = takeFlag(args, "--json");
|
|
12
12
|
const since = takeValue(args, "--since");
|
|
13
13
|
const until = takeValue(args, "--until");
|