@vatio-ai/cli 0.55.0 → 0.57.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/README.md CHANGED
@@ -19,13 +19,11 @@ is the same thing without installing anything.
19
19
  ## If you are a coding agent
20
20
 
21
21
  ```bash
22
- vatio mcp # MCP over stdio
23
- vatio docs # the whole developer contract as markdown, live from Vatio
22
+ vatio docs --save # the whole developer contract as markdown, live from Vatio
24
23
  ```
25
24
 
26
- `vatio mcp` is the short path: it hands you the contract and the deploy commands
27
- over MCP, with no browser step. Failing that, `vatio docs` prints the same
28
- contract that [docs.vatio.ai/docs.md](https://docs.vatio.ai/docs.md) serves, and
25
+ `vatio docs` prints the same contract that
26
+ [docs.vatio.ai/docs.md](https://docs.vatio.ai/docs.md) serves, and
29
27
  `vatio docs --save` writes it next to the workspace.
30
28
 
31
29
  Don't guess `vatio.yml` keys. Unknown root keys fail validation, and the rules
@@ -60,27 +58,22 @@ publish [--env NAME] Promote the latest push to live, or the named previe
60
58
  diff [--env NAME] What this directory would change
61
59
  status Preview and live deployment state
62
60
  rollback Restore the previous live deployment
63
- tools check Validate the workspace against Vatio's contracts
64
61
 
65
- chat "message" [--env NAME] Talk to your own agent; the token is the identity
66
- chat transcript|debug|reset|destroy
67
- chat show CHAT_ID [--json] Any chat in the workspace, with its deployment and tool calls
62
+ chat "message" [--env NAME] [--new]
63
+ Talk to your own agent; the token is the identity
64
+ chat show [CHAT_ID] [--json]
65
+ The chat you are in, or any chat in the workspace, with its tool calls
68
66
 
69
67
  kb list|show|create|rm Knowledge bases
70
68
  kb write|cat|rm-entry Entries, from a file or stdin
71
- kb follow|unfollow|refresh Read a site into a base, nightly
72
69
 
73
70
  secrets list|set|rm Credentials your tools read
74
71
  tokens list|create|origins|revoke Publishable tokens and the origins each accepts
75
- widget [--env NAME] What the platform enforces, and the tokens there are
76
72
  auth --new-key Keypair that signs the visitor's JWT
77
73
 
78
- whatsapp ... Shared preview number, or your own business number
79
- instagram ... Shared sandbox, or your own account
74
+ whatsapp | instagram Set up in the console; prints the link
80
75
 
81
76
  docs [--save [PATH]] The whole developer contract
82
- mcp Speak MCP over stdio, for a coding agent
83
- issue "what should change" Send a change request, workspace attached
84
77
  config show|set|unset base_url and token, per developer
85
78
  ```
86
79
 
@@ -99,14 +92,13 @@ command, which is what CI should use.
99
92
  ## Where the rules live
100
93
 
101
94
  Whether a workspace is valid is answered by Vatio, not by this package: `push`
102
- and `tools check` send the directory and read the result back. So the rules that
95
+ and `diff` send the directory and read the result back. So the rules that
103
96
  judge your workspace are always the deployed ones, and this CLI never has to be
104
97
  upgraded to understand a new one.
105
98
 
106
99
  ## Issues
107
100
 
108
- Bugs and questions go to [issues](https://github.com/vatio-ai/cli/issues), or
109
- `vatio issue` from inside a workspace. This repository is a read-only mirror of
101
+ Bugs and questions go to [issues](https://github.com/vatio-ai/cli/issues). This repository is a read-only mirror of
110
102
  the CLI as it ships inside Vatio, so a pull request cannot be merged here: open
111
103
  an issue describing the change instead. Release notes live in the
112
104
  [changelog](https://docs.vatio.ai/changelog).
package/bin/vatio.mjs CHANGED
@@ -1,14 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  // The Vatio CLI, as an npm package: `npx @vatio-ai/cli push`.
3
3
  //
4
- // Same platform, same API, same ~/.vatio/config.json as the Ruby CLI that
5
- // `curl … /install.sh | bash` puts on a machine. Either can drive a workspace,
6
- // and a developer who logged in with one is logged in for the other -- the
7
- // credential belongs to their home directory, not to a client.
8
- //
9
- // This exists because Node is the runtime this audience already has and Ruby
10
- // is the one some of them do not. Nothing about the contract moved: the
11
- // workspace is parsed by the platform, so a client is HTTP and a terminal.
4
+ // The workspace is parsed by the platform, so a client is HTTP and a
5
+ // terminal; the credential lives in ~/.vatio/config.json.
12
6
 
13
7
  import { Config, ConfigError } from "../lib/config.mjs";
14
8
  import { HttpError, UnauthorizedError, ForbiddenError, NotFoundError } from "../lib/http.mjs";
@@ -16,24 +10,31 @@ import { UserError, fail } from "../lib/support.mjs";
16
10
  import { helpText } from "../lib/help.mjs";
17
11
  import { login, logout } from "../lib/commands/auth.mjs";
18
12
  import { configCommand, doctor, init, version } from "../lib/commands/misc.mjs";
19
- import { diff, publish, push, rollback, status, toolsCheck } from "../lib/commands/deploy.mjs";
13
+ import { diff, publish, push, rollback, status } from "../lib/commands/deploy.mjs";
20
14
  import { env } from "../lib/commands/env.mjs";
21
- import { secrets, tokens, widget } from "../lib/commands/workspace-admin.mjs";
15
+ import { secrets, tokens } from "../lib/commands/workspace-admin.mjs";
22
16
  import { auth } from "../lib/commands/identity-key.mjs";
23
17
  import { chat } from "../lib/commands/chat.mjs";
24
18
  import { kb } from "../lib/commands/knowledge.mjs";
19
+ import { business } from "../lib/commands/business.mjs";
25
20
  import { instagram, whatsapp } from "../lib/commands/channels.mjs";
26
- import { docs, issue } from "../lib/commands/support-commands.mjs";
21
+ import { docs } from "../lib/commands/support-commands.mjs";
27
22
  import { evalCommand, flags } from "../lib/commands/improve.mjs";
28
- import { mcp } from "../lib/commands/mcp.mjs";
29
23
  import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
30
24
 
31
- // Two commands that existed and are gone, answered by name rather than as
32
- // unknown: one was removed from the product, the other is what npm does.
25
+ // Commands that existed and are gone, answered by name rather than as
26
+ // unknown: removed from the product, or what npm does now.
33
27
  const RETIRED = {
34
28
  pull: "was removed: a deployed manifest only ever comes from a push, so it could never\n" +
35
29
  "hand back anything your repository did not already have. Use `vatio diff --env live`,\n" +
36
- "or read the manifest at GET /api/v1/:slug/deploy/manifest.",
30
+ "or read the manifest at GET /api/developer/v1/:slug/manifest.",
31
+ issue: "was removed: report a problem on the public repository it belongs to --\n" +
32
+ "https://github.com/vatio-ai/cli/issues (or sdk, ios, ruby under github.com/vatio-ai).",
33
+ tools: "was removed: `vatio push` validates before it deploys, and `vatio diff` validates\n" +
34
+ "without deploying.",
35
+ widget: "was removed: `vatio env` prints the snippet and its token, and the look is edited on\n" +
36
+ "the console's Widget page.",
37
+ mcp: "was removed. Point your coding agent at `vatio docs --save` and let it run the CLI.",
37
38
  update: "is npm's job now: `npx @vatio-ai/cli@latest` always runs the current release, and\n" +
38
39
  "`npm install -g @vatio-ai/cli@latest` updates a global install."
39
40
  };
@@ -76,18 +77,16 @@ async function run(command, args) {
76
77
  return await env(config, args);
77
78
  case "diff":
78
79
  return await diff(config, args);
79
- case "tools":
80
- return await toolsCheck(config, args);
81
80
  case "tokens":
82
81
  return await tokens(config, args);
83
- case "widget":
84
- return await widget(config, args);
85
82
  case "auth":
86
83
  return await auth(config, args);
87
84
  case "chat":
88
85
  return await chat(config, args);
89
86
  case "kb":
90
87
  return await kb(config, args);
88
+ case "business":
89
+ return await business(config, args);
91
90
  case "secrets":
92
91
  return await secrets(config, args);
93
92
  case "whatsapp":
@@ -100,10 +99,6 @@ async function run(command, args) {
100
99
  return await evalCommand(config, args);
101
100
  case "docs":
102
101
  return await docs(config, args);
103
- case "issue":
104
- return await issue(config, args);
105
- case "mcp":
106
- return await mcp(config);
107
102
  case "help":
108
103
  case "-h":
109
104
  case "--help":
@@ -1,4 +1,4 @@
1
- // Everything the CLI can ask of one workspace: /api/v1/:slug/*.
1
+ // Everything the CLI can ask of one workspace: /api/developer/v1/:slug/*.
2
2
  //
3
3
  // One class rather than a client per surface. They share a host, a token and an
4
4
  // error contract, and splitting them only ever meant passing the same three
@@ -12,11 +12,11 @@ export class ApiClient extends HttpClient {
12
12
  // --- deploy ---------------------------------------------------------
13
13
 
14
14
  deployStatus() {
15
- return this.get("/deploy/status");
15
+ return this.get("/status");
16
16
  }
17
17
 
18
18
  deployedManifest({ environment = "live" } = {}) {
19
- return this.get("/deploy/manifest", { environment });
19
+ return this.get("/manifest", { environment });
20
20
  }
21
21
 
22
22
  // Validation without deploying: send the directory, get back the manifest it
@@ -26,7 +26,7 @@ export class ApiClient extends HttpClient {
26
26
  check({ files, environment = null }) {
27
27
  const body = { files };
28
28
  if (environment) body.environment = environment;
29
- return this.post("/deploy/check", body);
29
+ return this.post("/check", body);
30
30
  }
31
31
 
32
32
  pushPreview({ manifest, gitSha = null, gitBranch = null, createdBy = null, environment = null }) {
@@ -35,42 +35,34 @@ export class ApiClient extends HttpClient {
35
35
  if (gitBranch) body.git_branch = gitBranch;
36
36
  if (createdBy) body.created_by = createdBy;
37
37
  if (environment) body.environment = environment;
38
- return this.put("/deploy/preview", body);
38
+ return this.put("/push", body);
39
39
  }
40
40
 
41
41
  publish({ createdBy = null, environment = null } = {}) {
42
42
  const body = {};
43
43
  if (createdBy) body.created_by = createdBy;
44
44
  if (environment) body.environment = environment;
45
- return this.post("/deploy/publish", body);
45
+ return this.post("/publish", body);
46
46
  }
47
47
 
48
48
  rollback({ createdBy = null } = {}) {
49
49
  const body = {};
50
50
  if (createdBy) body.created_by = createdBy;
51
- return this.post("/deploy/rollback", body);
52
- }
53
-
54
- revisions() {
55
- return this.get("/deploy/revisions");
56
- }
57
-
58
- revision(id) {
59
- return this.get(`/deploy/revisions/${encode(id)}`);
51
+ return this.post("/rollback", body);
60
52
  }
61
53
 
62
54
  // --- environments ---------------------------------------------------
63
55
 
64
56
  environments() {
65
- return this.get("/deploy/environments");
57
+ return this.get("/env");
66
58
  }
67
59
 
68
60
  environment(name) {
69
- return this.get(`/deploy/environments/${encode(name)}`);
61
+ return this.get(`/env/${encode(name)}`);
70
62
  }
71
63
 
72
64
  deleteEnvironment(name) {
73
- return this.delete(`/deploy/environments/${encode(name)}`);
65
+ return this.delete(`/env/${encode(name)}`);
74
66
  }
75
67
 
76
68
  // --- secrets --------------------------------------------------------
@@ -78,24 +70,21 @@ export class ApiClient extends HttpClient {
78
70
  // Without an environment, the value everywhere; with one, the value only
79
71
  // that environment uses instead.
80
72
  listSecrets({ environment = null } = {}) {
81
- return this.get("/deploy/secrets", { environment });
73
+ return this.get("/secrets", { environment });
82
74
  }
83
75
 
84
76
  upsertSecret({ key, value, environment = null }) {
85
77
  const body = { value };
86
78
  if (environment) body.environment = environment;
87
- return this.put(`/deploy/secrets/${encode(key)}`, body);
79
+ return this.put(`/secrets/${encode(key)}`, body);
88
80
  }
89
81
 
90
82
  deleteSecret({ key, environment = null }) {
91
- return this.delete(`/deploy/secrets/${encode(key)}${query({ environment })}`);
83
+ return this.delete(`/secrets/${encode(key)}${query({ environment })}`);
92
84
  }
93
85
 
94
86
  // --- knowledge bases ------------------------------------------------
95
87
  //
96
- // A base holds entries (markdown) and reads sites (a URL or a pattern). Two
97
- // nouns, and every call below is one of them.
98
-
99
88
  // Every read and write below is as one environment sees the base: a
100
89
  // branch's, which keeps its changes on top of live, or `live` itself.
101
90
  // Without one the platform means `preview`.
@@ -116,10 +105,6 @@ export class ApiClient extends HttpClient {
116
105
  return this.delete(`/knowledge_bases/${encode(name)}`);
117
106
  }
118
107
 
119
- refreshKnowledgeBase(name) {
120
- return this.post(`/knowledge_bases/${encode(name)}/refresh`, {});
121
- }
122
-
123
108
  knowledgeEntry({ base, name, environment = null, version = null }) {
124
109
  return this.get(`/knowledge_bases/${encode(base)}/entries/${encode(name)}`, { environment, version });
125
110
  }
@@ -137,21 +122,6 @@ export class ApiClient extends HttpClient {
137
122
  return this.delete(`/knowledge_bases/${encode(base)}/entries/${encode(name)}${query({ environment })}`);
138
123
  }
139
124
 
140
- followKnowledgeSite({ base, url }) {
141
- return this.post(`/knowledge_bases/${encode(base)}/sites`, { url });
142
- }
143
-
144
- // Addressed by the URL you typed rather than by an id you would have to look
145
- // up first. It travels as a query parameter because a URL does not survive
146
- // being a path segment.
147
- unfollowKnowledgeSite({ base, url }) {
148
- return this.delete(`/knowledge_bases/${encode(base)}/sites?url=${encode(url)}`);
149
- }
150
-
151
- refreshKnowledgeSite({ base, url }) {
152
- return this.post(`/knowledge_bases/${encode(base)}/sites/refresh`, { url });
153
- }
154
-
155
125
  // What the environment changed that live does not have yet.
156
126
  knowledgeChanges(base, { environment = null } = {}) {
157
127
  return this.get(`/knowledge_bases/${encode(base)}/changes`, { environment });
@@ -167,7 +137,7 @@ export class ApiClient extends HttpClient {
167
137
  return this.get(`/knowledge_bases/${encode(base)}/history`);
168
138
  }
169
139
 
170
- // --- publishable tokens and the widget ------------------------------
140
+ // --- publishable tokens ------------------------------------------
171
141
 
172
142
  listPublishableTokens() {
173
143
  return this.get("/publishable_tokens");
@@ -188,119 +158,17 @@ export class ApiClient extends HttpClient {
188
158
  return this.delete(`/publishable_tokens/${encode(prefix)}`);
189
159
  }
190
160
 
191
- widget() {
192
- return this.get("/widget");
193
- }
194
-
195
- // --- the shared WhatsApp preview ------------------------------------
196
-
197
- listTestPhoneNumbers() {
198
- return this.get("/test_phone_numbers");
199
- }
200
-
201
- addTestPhoneNumber({ phoneNumber, environment = null }) {
202
- const body = { phone_number: phoneNumber };
203
- if (environment) body.environment = environment;
204
- return this.post("/test_phone_numbers", body);
205
- }
206
-
207
- // Which environment the phone reaches on the shared number.
208
- pointTestPhoneNumber({ phoneNumber, environment }) {
209
- return this.patch(`/test_phone_numbers/${waId(phoneNumber)}`, { environment });
210
- }
211
-
212
- verifyTestPhoneNumber({ phoneNumber, code }) {
213
- return this.post(`/test_phone_numbers/${waId(phoneNumber)}/verify`, { code });
214
- }
215
-
216
- resendTestPhoneNumberCode({ phoneNumber }) {
217
- return this.post(`/test_phone_numbers/${waId(phoneNumber)}/resend`, {});
218
- }
219
-
220
- removeTestPhoneNumber({ phoneNumber }) {
221
- return this.delete(`/test_phone_numbers/${waId(phoneNumber)}`);
222
- }
223
-
224
- // --- the workspace's own WhatsApp number ----------------------------
225
-
226
- whatsappAccount() {
227
- return this.get("/whatsapp_account");
228
- }
229
-
230
- // Mints the URL for Meta's Embedded Signup and returns it; it connects
231
- // nothing on its own. Same shape as instagramConnectLink.
232
- whatsappConnectLink() {
233
- return this.post("/whatsapp_account", {});
234
- }
235
-
236
- checkWhatsappAccount() {
237
- return this.post("/whatsapp_account/check", {});
238
- }
239
-
240
- activateWhatsappAccount() {
241
- return this.post("/whatsapp_account/activate", {});
242
- }
243
-
244
- deactivateWhatsappAccount() {
245
- return this.post("/whatsapp_account/deactivate", {});
246
- }
247
-
248
- disconnectWhatsappAccount() {
249
- return this.delete("/whatsapp_account");
250
- }
251
-
252
- // --- Instagram ------------------------------------------------------
253
-
254
- instagramAccount() {
255
- return this.get("/instagram_account");
256
- }
257
-
258
- instagramConnectLink() {
259
- return this.post("/instagram_account", {});
260
- }
261
-
262
- checkInstagramAccount() {
263
- return this.post("/instagram_account/check", {});
264
- }
161
+ // --- business -------------------------------------------------------
265
162
 
266
- disconnectInstagramAccount() {
267
- return this.delete("/instagram_account");
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");
268
167
  }
269
168
 
270
- listTestInstagramAccounts() {
271
- return this.get("/test_instagram_accounts");
272
- }
273
-
274
- // Declares which Instagram account you mean. The code comes later, by DM,
275
- // once that account writes to the shared preview -- Instagram will not let
276
- // Vatio message an account that has not messaged it first.
277
- addTestInstagramAccount({ username, environment = null }) {
278
- const body = { username };
279
- if (environment) body.environment = environment;
280
- return this.post("/test_instagram_accounts", body);
281
- }
282
-
283
- // Which environment the account reaches on the shared one.
284
- pointTestInstagramAccount({ id, environment }) {
285
- return this.patch(`/test_instagram_accounts/${encode(id)}`, { environment });
286
- }
287
-
288
- // Addressed by the code alone: the workspace is already in the path and the
289
- // code is the only value the developer has in hand.
290
- verifyTestInstagramAccount({ code }) {
291
- return this.post("/test_instagram_accounts/verify", { code });
292
- }
293
-
294
- showTestInstagramAccount(id) {
295
- return this.get(`/test_instagram_accounts/${encode(id)}`);
296
- }
297
-
298
- resendTestInstagramAccountCode(id) {
299
- return this.post(`/test_instagram_accounts/${encode(id)}/resend_otp`, {});
300
- }
301
-
302
- removeTestInstagramAccount(id) {
303
- return this.delete(`/test_instagram_accounts/${encode(id)}`);
169
+ // Only the keys given change. `hours: null` clears the schedule.
170
+ updateBusiness(fields) {
171
+ return this.patch("/business", fields);
304
172
  }
305
173
 
306
174
  // --- chats ----------------------------------------------------------
@@ -315,7 +183,6 @@ export class ApiClient extends HttpClient {
315
183
 
316
184
  // No `view` parameter: the developer token is the developer view, so the
317
185
  // API returns one shape and the caller decides how much of it to print.
318
- // `transcript` prints the visitor's half of it; `debug` prints all of it.
319
186
  showChat({ chatId }) {
320
187
  return this.get(`/chats/${encode(chatId)}`);
321
188
  }
@@ -331,21 +198,18 @@ export class ApiClient extends HttpClient {
331
198
  return this.post(`/chats/${encode(chatId)}/messages`, { content });
332
199
  }
333
200
 
334
- destroyChat({ chatId }) {
335
- return this.delete(`/chats/${encode(chatId)}`);
336
- }
337
201
  }
338
202
 
339
- // /cli/* -- not workspace-scoped, so it takes the bare host.
203
+ // /api/developer/v1/workspaces -- not workspace-scoped, so it takes the bare host.
340
204
  export class CliClient extends HttpClient {
341
205
  listWorkspaces() {
342
- return this.get("/cli/workspaces");
206
+ return this.get("/api/developer/v1/workspaces");
343
207
  }
344
208
 
345
209
  createWorkspace({ slug, name = null }) {
346
210
  const body = { slug };
347
211
  if (String(name ?? "").trim() !== "") body.name = String(name).trim();
348
- return this.post("/cli/workspaces", body);
212
+ return this.post("/api/developer/v1/workspaces", body);
349
213
  }
350
214
 
351
215
  async workspaceExists(slug) {
@@ -364,9 +228,3 @@ function query(params) {
364
228
  const text = search.toString();
365
229
  return text ? `?${text}` : "";
366
230
  }
367
-
368
- // The path carries the digits: "+" and spaces do not survive a URL, and the
369
- // digits are what the API stores as `wa_id`.
370
- function waId(phoneNumber) {
371
- return String(phoneNumber ?? "").replace(/\D/g, "");
372
- }
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/v1/:slug/deploy/check. The port of cli/lib/workspace_bundle.rb.
2
+ // POST /api/developer/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
@@ -0,0 +1,128 @@
1
+ // business — the business the agent works for: name, description and opening
2
+ // hours. Not part of vatio.yml: it belongs to whoever runs the business and is
3
+ // usually edited on the inbox's Business page. This is the same row, for a
4
+ // developer setting a workspace up from a terminal. One value for every
5
+ // environment, live on save.
6
+
7
+ import { readFileSync } from "node:fs";
8
+ import { deployClient } from "./deploy.mjs";
9
+ import { fail, paint, takeFlag, takeValue } from "../support.mjs";
10
+
11
+ const DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
12
+ const DAY_LABELS = { mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", fri: "Fri", sat: "Sat", sun: "Sun" };
13
+ const RANGE = /^\d{2}:\d{2}-\d{2}:\d{2}$/;
14
+
15
+ const USAGE =
16
+ "Usage: vatio business [show]\n" +
17
+ " vatio business set [--name NAME] [--description TEXT | --description-file FILE]\n" +
18
+ " vatio business hours [--timezone ZONE] [--mon 09:00-18:00] [--tue 09:00-13:00,14:00-18:00] ...\n" +
19
+ " vatio business hours --clear";
20
+
21
+ export async function business(config, args) {
22
+ const workspace = config.resolveWorkspaceRequired();
23
+ const client = deployClient(config, workspace);
24
+ const sub = args.shift() ?? "show";
25
+
26
+ if (sub === "show") {
27
+ print(await client.business(), workspace);
28
+ return;
29
+ }
30
+ if (sub === "set") {
31
+ const fields = {};
32
+ const name = takeValue(args, "--name");
33
+ const description = takeValue(args, "--description");
34
+ const file = takeValue(args, "--description-file");
35
+ if (description !== null && file !== null) fail("Give --description or --description-file, not both");
36
+ if (name !== null) fields.name = name;
37
+ if (description !== null) fields.summary = description;
38
+ if (file !== null) fields.summary = readFileSync(file === "-" ? 0 : file, "utf8");
39
+ rejectLeftovers(args);
40
+ if (Object.keys(fields).length === 0) fail(USAGE);
41
+
42
+ print(await client.updateBusiness(fields), workspace);
43
+ return;
44
+ }
45
+ if (sub === "hours") {
46
+ if (takeFlag(args, "--clear")) {
47
+ rejectLeftovers(args);
48
+ print(await client.updateBusiness({ hours: null }), workspace);
49
+ return;
50
+ }
51
+
52
+ const timezone = takeValue(args, "--timezone") ?? takeValue(args, "--tz");
53
+ const days = {};
54
+ for (const day of DAYS) {
55
+ const value = takeValue(args, `--${day}`);
56
+ if (value === null) continue;
57
+ const ranges = value.split(",").map((range) => range.trim()).filter(Boolean);
58
+ const bad = ranges.find((range) => !RANGE.test(range));
59
+ if (bad) fail(`--${day}: "${bad}" is not a range like 09:00-18:00`);
60
+ if (ranges.length > 0) days[day] = ranges;
61
+ }
62
+ rejectLeftovers(args);
63
+
64
+ // Nothing to change: show them.
65
+ if (timezone === null && Object.keys(days).length === 0) {
66
+ print(await client.business(), workspace);
67
+ return;
68
+ }
69
+ if (Object.keys(days).length === 0) {
70
+ fail("Give at least one day (--mon 09:00-18:00 ...), or --clear for someone always available");
71
+ }
72
+
73
+ // The week is replaced as a whole -- a day not given is a day nobody is
74
+ // on -- so the timezone is the only thing worth keeping from before.
75
+ const zone = timezone ?? (await client.business()).hours?.timezone ?? localTimezone();
76
+ print(await client.updateBusiness({ hours: { timezone: zone, days } }), workspace);
77
+ return;
78
+ }
79
+
80
+ fail(USAGE);
81
+ }
82
+
83
+ function rejectLeftovers(args) {
84
+ if (args.length > 0) fail(`Unexpected: ${args.join(" ")}\n\n${USAGE}`);
85
+ }
86
+
87
+ function localTimezone() {
88
+ const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
89
+ if (zone && zone.includes("/")) return zone;
90
+ fail("Give --timezone, like --timezone America/Santiago");
91
+ }
92
+
93
+ function print(payload, workspace) {
94
+ console.log(`${payload.name} (workspace ${workspace})`);
95
+ console.log("");
96
+ console.log(payload.summary ? indent(payload.summary) : " No description yet. Set one: vatio business set --description \"…\"");
97
+ console.log("");
98
+
99
+ if (!payload.hours) {
100
+ console.log("Hours: none set — someone is always available");
101
+ } else {
102
+ const state = payload.open_now ? paint("green", "open now") : "closed now";
103
+ console.log(`Hours (${payload.hours.timezone}) — ${state}`);
104
+ for (const day of DAYS) {
105
+ const ranges = payload.hours.days?.[day] ?? [];
106
+ console.log(` ${DAY_LABELS[day]} ${ranges.length > 0 ? ranges.join(", ") : "closed"}`);
107
+ }
108
+ if (payload.next_opening) console.log(` Opens next ${payload.next_opening}`);
109
+ }
110
+
111
+ console.log("");
112
+ if (!payload.handoff) {
113
+ console.log("Handoff: not declared in vatio.yml — the agent never hands a conversation over");
114
+ return;
115
+ }
116
+ console.log("Hands over to a person when (from vatio.yml):");
117
+ const rules = [...(payload.handoff.when ?? [])];
118
+ if (payload.handoff.after_turns != null) rules.push(`always after ${payload.handoff.after_turns} visitor messages`);
119
+ if (rules.length === 0) rules.push("the agent judges it");
120
+ for (const rule of rules) console.log(` - ${rule}`);
121
+ }
122
+
123
+ function indent(text) {
124
+ return String(text)
125
+ .split("\n")
126
+ .map((line) => ` ${line}`)
127
+ .join("\n");
128
+ }