@vatio-ai/cli 0.96.0 → 0.97.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 CHANGED
@@ -19,6 +19,7 @@ import { auth } from "../lib/commands/identity-key.mjs";
19
19
  import { chat, chatHelp } from "../lib/commands/chat.mjs";
20
20
  import { kb } from "../lib/commands/knowledge.mjs";
21
21
  import { business } from "../lib/commands/business.mjs";
22
+ import { quietHours } from "../lib/commands/quiet-hours.mjs";
22
23
  import { instagram, whatsapp } from "../lib/commands/channels.mjs";
23
24
  import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
24
25
  import { messages } from "../lib/commands/messages.mjs";
@@ -111,6 +112,8 @@ async function run(command, args) {
111
112
  return await kb(config, args);
112
113
  case "business":
113
114
  return await business(config, args);
115
+ case "quiet-hours":
116
+ return await quietHours(config, args);
114
117
  case "secrets":
115
118
  return await secrets(config, args);
116
119
  case "whatsapp":
@@ -208,6 +208,17 @@ export class ApiClient extends HttpClient {
208
208
  return this.patch("/business", fields);
209
209
  }
210
210
 
211
+ // --- quiet hours ----------------------------------------------------
212
+
213
+ // The weekly schedule in which the agent does not answer, or null.
214
+ quietHours() {
215
+ return this.get("/quiet_hours");
216
+ }
217
+
218
+ setQuietHours(quietHours) {
219
+ return this.patch("/quiet_hours", { quiet_hours: quietHours });
220
+ }
221
+
211
222
  // --- server keys ----------------------------------------------------
212
223
 
213
224
  listServerKeys() {
@@ -0,0 +1,131 @@
1
+ // quiet-hours — the weekly schedule in which the agent does not answer, the
2
+ // same one the inbox edits under Channels. Not part of vatio.yml: one value
3
+ // for every environment, live on save. A message that arrives inside it is
4
+ // not answered afterwards; it waits for the team in the inbox.
5
+
6
+ import { deployClient } from "./deploy.mjs";
7
+ import { fail, takeFlag, takeValue } from "../support.mjs";
8
+
9
+ const USAGE =
10
+ "Usage: vatio quiet-hours [show]\n" +
11
+ ' vatio quiet-hours set --timezone ZONE --range "DAYS HH:MM-HH:MM" [--range ...]\n' +
12
+ " vatio quiet-hours off\n" +
13
+ ' DAYS is mon, mon-fri, sat,sun or all. A range may cross midnight ("fri 22:00-08:00").';
14
+
15
+ // Weekday keys are the platform's: 0 is Sunday.
16
+ const DAY_KEYS = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
17
+ const WEEK = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
18
+ const TIME = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
19
+
20
+ export async function quietHours(config, args) {
21
+ const workspace = config.resolveWorkspaceRequired();
22
+ const client = deployClient(config, workspace);
23
+ const sub = args.shift() ?? "show";
24
+
25
+ if (sub === "show") {
26
+ rejectLeftovers(args);
27
+ print(await client.quietHours(), workspace);
28
+ return;
29
+ }
30
+ if (sub === "off") {
31
+ rejectLeftovers(args);
32
+ print(await client.setQuietHours(null), workspace);
33
+ return;
34
+ }
35
+ if (sub === "set") {
36
+ const timezone = takeValue(args, "--timezone");
37
+ if (!timezone) fail(`--timezone is required (for example America/Santiago)\n\n${USAGE}`);
38
+ const ranges = [];
39
+ for (let value = takeValue(args, "--range"); value !== null; value = takeValue(args, "--range")) ranges.push(value);
40
+ if (takeFlag(args, "--off")) fail(USAGE);
41
+ rejectLeftovers(args);
42
+ if (ranges.length === 0) fail(`Give at least one --range, or use \`vatio quiet-hours off\`\n\n${USAGE}`);
43
+
44
+ print(await client.setQuietHours({ timezone, days: buildDays(ranges) }), workspace);
45
+ return;
46
+ }
47
+
48
+ fail(USAGE);
49
+ }
50
+
51
+ // "mon-fri 00:00-08:00" -> ranges on each of those days. One that crosses
52
+ // midnight ("fri 22:00-08:00") becomes the evening of that day and the
53
+ // morning of the next, which is how the platform keeps them.
54
+ export function buildDays(ranges) {
55
+ const days = {};
56
+ const add = (day, from, to) => {
57
+ (days[day] ??= []).push({ from, to });
58
+ };
59
+
60
+ for (const spec of ranges) {
61
+ const match = /^\s*(\S+)\s+(\d{2}:\d{2})-(\d{2}:\d{2})\s*$/.exec(spec);
62
+ if (!match) fail(`--range "${spec}": expected "DAYS HH:MM-HH:MM", for example "mon-fri 22:00-08:00"`);
63
+ const [, dayList, from, to] = match;
64
+ if (!TIME.test(from) || !(TIME.test(to) || to === "24:00")) fail(`--range "${spec}": times are HH:MM, 00:00 to 24:00`);
65
+ if (from === to) fail(`--range "${spec}": it starts and ends at the same time`);
66
+
67
+ for (const day of parseDays(dayList, spec)) {
68
+ if (from < to) {
69
+ add(day, from, to);
70
+ } else {
71
+ add(day, from, "24:00");
72
+ add((day + 1) % 7, "00:00", to);
73
+ }
74
+ }
75
+ }
76
+ return Object.fromEntries(Object.entries(days).map(([day, list]) => [day, mergeRanges(list)]));
77
+ }
78
+
79
+ function parseDays(list, spec) {
80
+ const days = new Set();
81
+ for (const part of list.toLowerCase().split(",")) {
82
+ if (part === "all") {
83
+ WEEK.forEach((name) => days.add(DAY_KEYS[name]));
84
+ continue;
85
+ }
86
+ const [first, last = first] = part.split("-");
87
+ const start = WEEK.indexOf(first);
88
+ const end = WEEK.indexOf(last);
89
+ if (start === -1 || end === -1) fail(`--range "${spec}": "${part}" is not a day (mon, tue, wed, thu, fri, sat, sun, all)`);
90
+ // Monday-first, wrapping: sat-mon is sat, sun, mon.
91
+ for (let i = start; ; i = (i + 1) % 7) {
92
+ days.add(DAY_KEYS[WEEK[i]]);
93
+ if (i === end) break;
94
+ }
95
+ }
96
+ return [...days];
97
+ }
98
+
99
+ // Touching or overlapping ranges on one day become one, so "all 00:00-08:00"
100
+ // and "fri 22:00-08:00" do not trip the platform's overlap check.
101
+ function mergeRanges(list) {
102
+ const sorted = [...list].sort((a, b) => a.from.localeCompare(b.from));
103
+ const merged = [];
104
+ for (const range of sorted) {
105
+ const last = merged[merged.length - 1];
106
+ if (last && range.from <= last.to) last.to = range.to > last.to ? range.to : last.to;
107
+ else merged.push({ ...range });
108
+ }
109
+ return merged;
110
+ }
111
+
112
+ function rejectLeftovers(args) {
113
+ if (args.length > 0) fail(`Unexpected: ${args.join(" ")}\n\n${USAGE}`);
114
+ }
115
+
116
+ function print(payload, workspace) {
117
+ const schedule = payload.quiet_hours;
118
+ console.log(`Quiet hours (workspace ${workspace})`);
119
+ console.log("");
120
+ if (!schedule) {
121
+ console.log(" Off: the agent answers around the clock. Set one with `vatio quiet-hours set`.");
122
+ return;
123
+ }
124
+ console.log(` time zone ${schedule.timezone}`);
125
+ for (const name of WEEK) {
126
+ const ranges = schedule.days[DAY_KEYS[name]] ?? [];
127
+ const text = ranges.length ? ranges.map((range) => `${range.from}-${range.to}`).join(", ") : "answers all day";
128
+ console.log(` ${name} ${text}`);
129
+ }
130
+ if (payload.active_now) console.log("\n Silent right now.");
131
+ }
package/lib/help.mjs CHANGED
@@ -128,6 +128,14 @@ Commands default as listed.
128
128
  [--logo FILE | --remove-logo] [--clear-description]
129
129
  What the business does goes in agent.instructions
130
130
 
131
+ Quiet hours (when the agent does not answer; one schedule for every environment,
132
+ live on save; also in the inbox, under Channels):
133
+ quiet-hours [show] The weekly schedule, and whether it is silent now
134
+ quiet-hours set --timezone ZONE --range "DAYS HH:MM-HH:MM" [--range ...]
135
+ Replace the schedule. DAYS: mon, mon-fri, sat,sun, all
136
+ A range may cross midnight: "fri 22:00-08:00"
137
+ quiet-hours off Answer around the clock
138
+
131
139
  Credentials:
132
140
  secrets list|set KEY [VALUE]|rm KEY [--env NAME | --tests]
133
141
  Without VALUE, set asks for it with the input hidden.
package/lib/telemetry.mjs CHANGED
@@ -30,6 +30,7 @@ const SUBCOMMANDS = {
30
30
  env: ["list", "rm"],
31
31
  kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
32
32
  business: ["show", "set"],
33
+ "quiet-hours": ["show", "set", "off"],
33
34
  secrets: ["list", "set", "rm"],
34
35
  tokens: ["list", "create", "revoke", "origins"],
35
36
  keys: ["list", "create", "revoke"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.96.0",
3
+ "version": "0.97.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",