@vatio-ai/cli 0.56.0 → 0.58.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 +13 -0
- package/lib/commands/business.mjs +170 -0
- package/lib/help.mjs +9 -0
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { secrets, tokens } from "../lib/commands/workspace-admin.mjs";
|
|
|
16
16
|
import { auth } from "../lib/commands/identity-key.mjs";
|
|
17
17
|
import { chat } from "../lib/commands/chat.mjs";
|
|
18
18
|
import { kb } from "../lib/commands/knowledge.mjs";
|
|
19
|
+
import { business } from "../lib/commands/business.mjs";
|
|
19
20
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
20
21
|
import { docs } from "../lib/commands/support-commands.mjs";
|
|
21
22
|
import { evalCommand, flags } from "../lib/commands/improve.mjs";
|
|
@@ -84,6 +85,8 @@ async function run(command, args) {
|
|
|
84
85
|
return await chat(config, args);
|
|
85
86
|
case "kb":
|
|
86
87
|
return await kb(config, args);
|
|
88
|
+
case "business":
|
|
89
|
+
return await business(config, args);
|
|
87
90
|
case "secrets":
|
|
88
91
|
return await secrets(config, args);
|
|
89
92
|
case "whatsapp":
|
package/lib/api-client.mjs
CHANGED
|
@@ -158,6 +158,19 @@ export class ApiClient extends HttpClient {
|
|
|
158
158
|
return this.delete(`/publishable_tokens/${encode(prefix)}`);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
// --- business -------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
// Name, description and opening hours: one row for every environment,
|
|
164
|
+
// the same one the inbox's Business page edits.
|
|
165
|
+
business() {
|
|
166
|
+
return this.get("/business");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Only the keys given change. `hours: null` clears the schedule.
|
|
170
|
+
updateBusiness(fields) {
|
|
171
|
+
return this.patch("/business", fields);
|
|
172
|
+
}
|
|
173
|
+
|
|
161
174
|
// --- chats ----------------------------------------------------------
|
|
162
175
|
|
|
163
176
|
createChat({ environment }) {
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// business — the business the agent works for: name, description, opening
|
|
2
|
+
// hours and brand (logo, color, about). Not part of vatio.yml: it belongs to
|
|
3
|
+
// whoever runs the business and is usually edited on the inbox's Business
|
|
4
|
+
// page. This is the same row, for a developer setting a workspace up from a
|
|
5
|
+
// terminal. One value for every environment, live on save.
|
|
6
|
+
|
|
7
|
+
import { readFileSync, statSync } from "node:fs";
|
|
8
|
+
import { basename, extname } from "node:path";
|
|
9
|
+
import { deployClient } from "./deploy.mjs";
|
|
10
|
+
import { fail, paint, takeFlag, takeValue } from "../support.mjs";
|
|
11
|
+
|
|
12
|
+
const DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
13
|
+
const DAY_LABELS = { mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", fri: "Fri", sat: "Sat", sun: "Sun" };
|
|
14
|
+
const RANGE = /^\d{2}:\d{2}-\d{2}:\d{2}$/;
|
|
15
|
+
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
16
|
+
// The platform checks the type and the size again; these only fail early.
|
|
17
|
+
const LOGO_TYPES = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif" };
|
|
18
|
+
const LOGO_MAX_BYTES = 2 * 1024 * 1024;
|
|
19
|
+
|
|
20
|
+
const USAGE =
|
|
21
|
+
"Usage: vatio business [show]\n" +
|
|
22
|
+
" vatio business set [--name NAME] [--description TEXT | --description-file FILE]\n" +
|
|
23
|
+
" [--about TEXT] [--color #RRGGBB | --color default]\n" +
|
|
24
|
+
" [--logo FILE | --remove-logo]\n" +
|
|
25
|
+
" vatio business hours [--timezone ZONE] [--mon 09:00-18:00] [--tue 09:00-13:00,14:00-18:00] ...\n" +
|
|
26
|
+
" vatio business hours --clear";
|
|
27
|
+
|
|
28
|
+
export async function business(config, args) {
|
|
29
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
30
|
+
const client = deployClient(config, workspace);
|
|
31
|
+
const sub = args.shift() ?? "show";
|
|
32
|
+
|
|
33
|
+
if (sub === "show") {
|
|
34
|
+
print(await client.business(), workspace);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (sub === "set") {
|
|
38
|
+
const fields = {};
|
|
39
|
+
const name = takeValue(args, "--name");
|
|
40
|
+
const description = takeValue(args, "--description");
|
|
41
|
+
const file = takeValue(args, "--description-file");
|
|
42
|
+
if (description !== null && file !== null) fail("Give --description or --description-file, not both");
|
|
43
|
+
if (name !== null) fields.name = name;
|
|
44
|
+
if (description !== null) fields.summary = description;
|
|
45
|
+
if (file !== null) fields.summary = readFileSync(file === "-" ? 0 : file, "utf8");
|
|
46
|
+
|
|
47
|
+
const about = takeValue(args, "--about");
|
|
48
|
+
if (about !== null) fields.about = about;
|
|
49
|
+
|
|
50
|
+
const color = takeValue(args, "--color");
|
|
51
|
+
if (color !== null) {
|
|
52
|
+
if (color !== "default" && !HEX.test(color)) fail(`--color: "${color}" is not #RRGGBB (or "default")`);
|
|
53
|
+
fields.accent_color = color === "default" ? null : color.toUpperCase();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const logo = takeValue(args, "--logo");
|
|
57
|
+
const removeLogo = takeFlag(args, "--remove-logo");
|
|
58
|
+
if (logo !== null && removeLogo) fail("Give --logo or --remove-logo, not both");
|
|
59
|
+
if (logo !== null) fields.logo = readLogo(logo);
|
|
60
|
+
if (removeLogo) fields.logo = null;
|
|
61
|
+
rejectLeftovers(args);
|
|
62
|
+
if (Object.keys(fields).length === 0) fail(USAGE);
|
|
63
|
+
|
|
64
|
+
print(await client.updateBusiness(fields), workspace);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (sub === "hours") {
|
|
68
|
+
if (takeFlag(args, "--clear")) {
|
|
69
|
+
rejectLeftovers(args);
|
|
70
|
+
print(await client.updateBusiness({ hours: null }), workspace);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const timezone = takeValue(args, "--timezone") ?? takeValue(args, "--tz");
|
|
75
|
+
const days = {};
|
|
76
|
+
for (const day of DAYS) {
|
|
77
|
+
const value = takeValue(args, `--${day}`);
|
|
78
|
+
if (value === null) continue;
|
|
79
|
+
const ranges = value.split(",").map((range) => range.trim()).filter(Boolean);
|
|
80
|
+
const bad = ranges.find((range) => !RANGE.test(range));
|
|
81
|
+
if (bad) fail(`--${day}: "${bad}" is not a range like 09:00-18:00`);
|
|
82
|
+
if (ranges.length > 0) days[day] = ranges;
|
|
83
|
+
}
|
|
84
|
+
rejectLeftovers(args);
|
|
85
|
+
|
|
86
|
+
// Nothing to change: show them.
|
|
87
|
+
if (timezone === null && Object.keys(days).length === 0) {
|
|
88
|
+
print(await client.business(), workspace);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (Object.keys(days).length === 0) {
|
|
92
|
+
fail("Give at least one day (--mon 09:00-18:00 ...), or --clear for someone always available");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// The week is replaced as a whole -- a day not given is a day nobody is
|
|
96
|
+
// on -- so the timezone is the only thing worth keeping from before.
|
|
97
|
+
const zone = timezone ?? (await client.business()).hours?.timezone ?? localTimezone();
|
|
98
|
+
print(await client.updateBusiness({ hours: { timezone: zone, days } }), workspace);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fail(USAGE);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Sent inside the JSON body, base64, the same way the inbox sends it.
|
|
106
|
+
function readLogo(path) {
|
|
107
|
+
const contentType = LOGO_TYPES[extname(path).toLowerCase()];
|
|
108
|
+
if (!contentType) fail(`--logo: ${path} must be a PNG, JPG, WebP or GIF`);
|
|
109
|
+
let size;
|
|
110
|
+
try {
|
|
111
|
+
size = statSync(path).size;
|
|
112
|
+
} catch {
|
|
113
|
+
fail(`--logo: cannot read ${path}`);
|
|
114
|
+
}
|
|
115
|
+
if (size > LOGO_MAX_BYTES) fail(`--logo: ${path} is ${(size / 1024 / 1024).toFixed(1)} MB; the limit is 2 MB`);
|
|
116
|
+
return { data: readFileSync(path).toString("base64"), content_type: contentType, filename: basename(path) };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function rejectLeftovers(args) {
|
|
120
|
+
if (args.length > 0) fail(`Unexpected: ${args.join(" ")}\n\n${USAGE}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function localTimezone() {
|
|
124
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
125
|
+
if (zone && zone.includes("/")) return zone;
|
|
126
|
+
fail("Give --timezone, like --timezone America/Santiago");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function print(payload, workspace) {
|
|
130
|
+
console.log(`${payload.name} (workspace ${workspace})`);
|
|
131
|
+
console.log("");
|
|
132
|
+
console.log(payload.summary ? indent(payload.summary) : " No description yet. Set one: vatio business set --description \"…\"");
|
|
133
|
+
console.log("");
|
|
134
|
+
|
|
135
|
+
console.log("Brand:");
|
|
136
|
+
console.log(` logo ${payload.logo_url ?? "none (vatio business set --logo FILE)"}`);
|
|
137
|
+
console.log(` color ${payload.accent_color ?? `${payload.default_accent_color} (Vatio's default)`}`);
|
|
138
|
+
console.log(` about ${payload.about ? payload.about.replace(/\s*\n\s*/g, " ") : "none"}`);
|
|
139
|
+
console.log("");
|
|
140
|
+
|
|
141
|
+
if (!payload.hours) {
|
|
142
|
+
console.log("Hours: none set — someone is always available");
|
|
143
|
+
} else {
|
|
144
|
+
const state = payload.open_now ? paint("green", "open now") : "closed now";
|
|
145
|
+
console.log(`Hours (${payload.hours.timezone}) — ${state}`);
|
|
146
|
+
for (const day of DAYS) {
|
|
147
|
+
const ranges = payload.hours.days?.[day] ?? [];
|
|
148
|
+
console.log(` ${DAY_LABELS[day]} ${ranges.length > 0 ? ranges.join(", ") : "closed"}`);
|
|
149
|
+
}
|
|
150
|
+
if (payload.next_opening) console.log(` Opens next ${payload.next_opening}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log("");
|
|
154
|
+
if (!payload.handoff) {
|
|
155
|
+
console.log("Handoff: not declared in vatio.yml — the agent never hands a conversation over");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
console.log("Hands over to a person when (from vatio.yml):");
|
|
159
|
+
const rules = [...(payload.handoff.when ?? [])];
|
|
160
|
+
if (payload.handoff.after_turns != null) rules.push(`always after ${payload.handoff.after_turns} visitor messages`);
|
|
161
|
+
if (rules.length === 0) rules.push("the agent judges it");
|
|
162
|
+
for (const rule of rules) console.log(` - ${rule}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function indent(text) {
|
|
166
|
+
return String(text)
|
|
167
|
+
.split("\n")
|
|
168
|
+
.map((line) => ` ${line}`)
|
|
169
|
+
.join("\n");
|
|
170
|
+
}
|
package/lib/help.mjs
CHANGED
|
@@ -72,6 +72,15 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
|
|
|
72
72
|
kb history BASE What reached live, newest first
|
|
73
73
|
(entry commands take --env; --env live writes live)
|
|
74
74
|
|
|
75
|
+
Business (one value for every environment, live on save; also on the inbox's
|
|
76
|
+
Business page):
|
|
77
|
+
business [show] Name, description, brand, opening hours, handoff rules
|
|
78
|
+
business set [--name NAME] [--description TEXT | --description-file FILE]
|
|
79
|
+
[--about TEXT] [--color #RRGGBB|default] [--logo FILE | --remove-logo]
|
|
80
|
+
business hours --timezone ZONE --mon 09:00-18:00 --tue 09:00-13:00,14:00-18:00 ...
|
|
81
|
+
Replaces the week: a day not given is closed
|
|
82
|
+
business hours --clear No hours: someone is always available
|
|
83
|
+
|
|
75
84
|
Credentials:
|
|
76
85
|
secrets list|set KEY [VALUE]|rm KEY [--env NAME]
|
|
77
86
|
Without VALUE, set asks for it with the input hidden.
|