@vatio-ai/cli 0.86.1 → 0.88.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
@@ -27,9 +27,7 @@ npx @vatio-ai/cli init my-agent
27
27
  npx @vatio-ai/cli push
28
28
  ```
29
29
 
30
- No runtime to install first: if you have Node 20 or newer, you have this. No
31
- account either: with none on the machine, `push` deploys a 7-day trial and
32
- prints a link to try it and one to keep it, which is where you sign in.
30
+ No runtime to install first: if you have Node 20 or newer, you have this.
33
31
 
34
32
  The package is `@vatio-ai/cli`; the command it installs is `vatio`. So
35
33
  `npm install -g @vatio-ai/cli` gives you `vatio push`, and `npx @vatio-ai/cli push`
package/bin/vatio.mjs CHANGED
@@ -5,16 +5,7 @@
5
5
  // terminal; the credential lives in ~/.vatio/config.json.
6
6
 
7
7
  import { Config, ConfigError } from "../lib/config.mjs";
8
- import {
9
- CliOutdatedError,
10
- HttpError,
11
- UnauthorizedError,
12
- ForbiddenError,
13
- NotFoundError,
14
- TrialClaimedError,
15
- TrialGoneError
16
- } from "../lib/http.mjs";
17
- import { keepClaimedTrial } from "../lib/trial.mjs";
8
+ import { CliOutdatedError, HttpError, UnauthorizedError, ForbiddenError, NotFoundError } from "../lib/http.mjs";
18
9
  import { UserError, fail } from "../lib/support.mjs";
19
10
  import { helpText } from "../lib/help.mjs";
20
11
  import { login, logout } from "../lib/commands/auth.mjs";
@@ -58,25 +49,11 @@ async function main(argv) {
58
49
  const command = args.shift();
59
50
  beginRun(command, args);
60
51
  const updateCheck = startUpdateCheck(command);
61
- await runKeepingTrial(command, args);
52
+ await run(command, args);
62
53
  await reportRun(config, { exitCode: process.exitCode ?? 0 });
63
54
  await printUpdateNotice(updateCheck);
64
55
  }
65
56
 
66
- // The trial this directory pushed to was kept in the browser since the last
67
- // command (lib/trial.mjs): the refused call did nothing, so this terminal signs
68
- // in to the account that kept it and the command runs again, as that account.
69
- async function runKeepingTrial(command, args) {
70
- const again = [...args];
71
- try {
72
- await run(command, args);
73
- } catch (error) {
74
- if (!(error instanceof TrialClaimedError) || !error.workspace) throw error;
75
- await keepClaimedTrial(config, error);
76
- await run(command, again);
77
- }
78
- }
79
-
80
57
  async function run(command, args) {
81
58
  // `--help` after a command asks about it. Left to the command, it reads as a
82
59
  // message to send, an argument, or nothing at all: `vatio chat --help` said
@@ -180,23 +157,10 @@ function printError(error) {
180
157
  console.error(error.message);
181
158
  return suggestFeedback();
182
159
  }
183
- if (error instanceof TrialGoneError) {
184
- config.clearTrial();
185
- // The platform's hint says what to run next.
186
- console.error("This trial no longer exists: nobody kept it in time, so it was deleted.");
187
- return printTrailer(error);
188
- }
189
160
  if (error instanceof UnauthorizedError) {
190
161
  console.error("Authentication failed (401). Run `vatio login`.");
191
162
  return printTrailer(error);
192
163
  }
193
- if (error instanceof ForbiddenError && errorCode(error) === "trial_unclaimed") {
194
- // The platform says what needs an account; the link to keep it is only here.
195
- const trial = config.trial();
196
- const link = trial?.claim_url ?? 'the link `vatio push` printed after "Keep it"';
197
- console.error(`${error.message} Keep it first: ${link}, then run vatio ${process.argv[2]} again (it signs this terminal in).`);
198
- return printTrailer(error, { hint: false });
199
- }
200
164
  if (error instanceof ForbiddenError) {
201
165
  console.error("Access denied (403). Your token cannot access this workspace.");
202
166
  return printTrailer(error);
@@ -219,20 +183,16 @@ function printError(error) {
219
183
 
220
184
  // What the platform said to do next, and the ids that find this request in
221
185
  // its logs.
222
- function printTrailer(error, { hint: withHint = true } = {}) {
186
+ function printTrailer(error) {
223
187
  const hint = error.body?.hint;
224
- if (withHint && hint && !(error instanceof UnauthorizedError)) console.error(`Next: ${hint}`);
188
+ if (hint && !(error instanceof UnauthorizedError)) console.error(`Next: ${hint}`);
225
189
 
226
- const code = errorCode(error);
190
+ const code = error.body?.error_key ?? (typeof error.body?.error === "string" ? error.body.error : error.body?.error?.code);
227
191
  const ids = [code && `error=${code}`, error.requestId && `request_id=${error.requestId}`].filter(Boolean);
228
192
  if (ids.length > 0) console.error(ids.join(" "));
229
193
  suggestFeedback();
230
194
  }
231
195
 
232
- function errorCode(error) {
233
- return error.body?.error_key ?? (typeof error.body?.error === "string" ? error.body.error : error.body?.error?.code);
234
- }
235
-
236
196
  // Said to coding agents only: a person at a terminal has better ways to
237
197
  // complain, and does not need the line on every typo.
238
198
  function suggestFeedback() {
@@ -138,24 +138,18 @@ async function exportChats(config, args) {
138
138
  }
139
139
  }
140
140
 
141
- // With no account on this machine, the trial this directory pushed to, with
142
- // its key (lib/trial.mjs): a chat there is the trial's developer, like any.
143
141
  function client(config, options) {
144
- const apiUrl = apiUrlFor(config, options);
145
- const token = options.token ?? config.resolveToken() ?? config.activeTrial()?.key;
142
+ const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
143
+ const token = options.token ?? config.resolveToken();
146
144
  if (!apiUrl) {
147
145
  // Says which: no vatio.yml here (and where one is), or one without `workspace:`.
148
146
  config.resolveWorkspaceRequired();
149
147
  fail("A workspace API url is required (--api-url, or base_url + a vatio.yml with `workspace:`)");
150
148
  }
151
- if (!token) fail("VATIO_TOKEN is required (env or `vatio login`). `vatio push` deploys a trial with no account.");
149
+ if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
152
150
  return new ApiClient({ baseUrl: apiUrl, token });
153
151
  }
154
152
 
155
- function apiUrlFor(config, options) {
156
- return config.resolveApiUrl({ explicit: options.apiUrl, token: options.token });
157
- }
158
-
159
153
  function statePath(config) {
160
154
  return join(config.workspaceRootRequired(), STATE_FILE);
161
155
  }
@@ -187,7 +181,7 @@ function rememberChat(config, { apiUrl, environment, chatId }) {
187
181
  }
188
182
 
189
183
  async function ensureChat(config, options) {
190
- const apiUrl = apiUrlFor(config, options);
184
+ const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
191
185
  const existing = chatsFor(config, apiUrl)[options.environment];
192
186
  if (existing) return Number(existing);
193
187
 
@@ -273,7 +267,7 @@ async function showChat(config, options, args) {
273
267
  let chatId = args.shift();
274
268
  if (chatId !== undefined && !/^\d+$/.test(chatId)) fail("Usage: vatio chat show [CHAT_ID] [--last N] [--json]");
275
269
  if (chatId === undefined) {
276
- const apiUrl = apiUrlFor(config, options);
270
+ const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
277
271
  chatId = chatsFor(config, apiUrl)[options.environment];
278
272
  if (!chatId) fail(`No ${options.environment} chat yet: run \`vatio chat "hello"\` first, or pass a CHAT_ID.`);
279
273
  chatId = String(chatId);
@@ -388,7 +382,7 @@ function truncate(text, max) {
388
382
  }
389
383
 
390
384
  async function startOver(config, options) {
391
- const apiUrl = apiUrlFor(config, options);
385
+ const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
392
386
  const payload = await openChat(config, options, {
393
387
  apiUrl,
394
388
  chatId: chatsFor(config, apiUrl)[options.environment] ?? null
@@ -16,14 +16,13 @@ import { stringify as stringifyYaml } from "yaml";
16
16
 
17
17
  import { buildBundle, BundleError } from "../bundle.mjs";
18
18
  import { ApiClient, CliClient } from "../api-client.mjs";
19
- import { NotFoundError, TrialGoneError, UnprocessableError } from "../http.mjs";
20
- import { printTrialPush, startTrial } from "../trial.mjs";
19
+ import { NotFoundError, UnprocessableError } from "../http.mjs";
21
20
  import { deviceLogin } from "./auth.mjs";
22
21
  import { detectGitBranch, detectGitSha, fail, paint, takeEnv, takeFlag, takeValue } from "../support.mjs";
23
22
 
24
- // For a command that needs to know whose it is. `push` does not: with no
25
- // account it deploys a trial, and the account comes when someone keeps it.
26
- export async function ensureAuthorized(config, { workspace = null, message = "Before I can do this, I need to know who you are." } = {}) {
23
+ // The first command that makes something exist on a server, so the first one
24
+ // that needs to know whose it is.
25
+ export async function ensureAuthorized(config, { workspace = null, message = "Before I can push this, I need to know whose it is." } = {}) {
27
26
  if (config.resolveToken()) return;
28
27
 
29
28
  const auth = await deviceLogin({ config, workspace, message });
@@ -33,18 +32,13 @@ export async function ensureAuthorized(config, { workspace = null, message = "Be
33
32
  console.log("");
34
33
  }
35
34
 
36
- // With no account on this machine, the trial `vatio push` made from this
37
- // directory (lib/trial.mjs), on its own slug and key: the platform answers
38
- // what a trial may do and refuses the rest with `trial_unclaimed`.
39
35
  export function deployClient(config, workspace) {
40
36
  const base = config.resolveBaseUrl();
41
37
  if (!base) fail("VATIO_BASE_URL is required (env or `vatio config set base_url …`)");
42
38
  const token = config.resolveToken();
43
- if (token) return new ApiClient({ baseUrl: `${base}/api/developer/v1/${workspace}`, token });
39
+ if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
44
40
 
45
- const trial = config.trial();
46
- if (trial) return new ApiClient({ baseUrl: `${base}/api/developer/v1/${trial.workspace}`, token: trial.key });
47
- fail("VATIO_TOKEN is required (env or `vatio login`). `vatio push` deploys a trial with no account.");
41
+ return new ApiClient({ baseUrl: `${base}/api/developer/v1/${workspace}`, token });
48
42
  }
49
43
 
50
44
  export function workspacesClient(config) {
@@ -98,9 +92,7 @@ export async function push(config, args) {
98
92
  const force = takeFlag(args, "--force");
99
93
  const workspace = config.resolveWorkspaceRequired();
100
94
 
101
- // No account here: a trial, which asks for one only when someone keeps it.
102
- if (!config.resolveToken()) return await pushTrial(config, { workspace, environment, force });
103
- noticeLeftoverTrial(config);
95
+ await ensureAuthorized(config, { workspace });
104
96
 
105
97
  // The remote has to exist before the workspace can be checked: the slug is in
106
98
  // the URL of the call that checks it. It is created unnamed; the display name
@@ -113,7 +105,19 @@ export async function push(config, args) {
113
105
  console.log(`Created remote workspace ${workspace}`);
114
106
  }
115
107
 
116
- const payload = await checkAndPush(config, workspace, { environment, force });
108
+ const check = await checkWorkspace(config, workspace, { environment });
109
+ printDiagnostics(check);
110
+ if (!check.ok) fail(`push aborted: check failed (${asArray(check.errors).length} error(s))`);
111
+
112
+ const client = deployClient(config, workspace);
113
+ const payload = await client.pushPreview({
114
+ manifest: check.manifest,
115
+ gitSha: detectGitSha(config.workspaceRootRequired()),
116
+ gitBranch: detectGitBranch(config.workspaceRootRequired()),
117
+ createdBy: process.env.USER ?? null,
118
+ environment,
119
+ force
120
+ });
117
121
 
118
122
  const landedOn = payload.environment ?? "preview";
119
123
  console.log(`Pushed deployment #${payload.deployment_id} to ${landedOn} (git_sha=${JSON.stringify(payload.git_sha ?? null)})`);
@@ -131,66 +135,6 @@ export async function push(config, args) {
131
135
  printNotices(payload);
132
136
  }
133
137
 
134
- async function checkAndPush(config, workspace, { environment, force }) {
135
- const check = await checkWorkspace(config, workspace, { environment });
136
- printDiagnostics(check);
137
- if (!check.ok) fail(`push aborted: check failed (${asArray(check.errors).length} error(s))`);
138
-
139
- return await deployClient(config, workspace).pushPreview({
140
- manifest: check.manifest,
141
- gitSha: detectGitSha(config.workspaceRootRequired()),
142
- gitBranch: detectGitBranch(config.workspaceRootRequired()),
143
- createdBy: process.env.USER ?? null,
144
- environment,
145
- force
146
- });
147
- }
148
-
149
- // The first push makes the trial; the next ones reuse it, each one moving its
150
- // deletion a week on. One deleted meanwhile is replaced by a new one, once.
151
- async function pushTrial(config, { workspace, environment, force }) {
152
- let trial = config.trial();
153
- let started = false;
154
- if (!trial) {
155
- trial = await startTrial(config, workspace);
156
- started = true;
157
- }
158
-
159
- let payload;
160
- try {
161
- payload = await checkAndPush(config, workspace, { environment, force });
162
- } catch (error) {
163
- if (!(error instanceof TrialGoneError) || started) throw error;
164
- config.clearTrial();
165
- console.log(`The trial this directory had (${trial.workspace}) is gone: nobody kept it in time. Starting a new one.`);
166
- trial = await startTrial(config, workspace);
167
- started = true;
168
- payload = await checkAndPush(config, workspace, { environment, force });
169
- }
170
-
171
- config.writeTrial({
172
- ...trial,
173
- try_url: payload.trial?.try_url ?? payload.share_url ?? trial.try_url ?? null,
174
- expires_at: payload.trial?.expires_at ?? trial.expires_at
175
- });
176
- printTrialPush(config.trial(), payload, { started });
177
- }
178
-
179
- // Signed in, in a directory that pushed to a trial before: the push goes to
180
- // the account as usual, and the trial stays as it is until it is kept or
181
- // deleted. Said on every push until it is due to be deleted.
182
- function noticeLeftoverTrial(config) {
183
- const trial = config.trial();
184
- if (!trial) return;
185
- if (Date.parse(trial.expires_at) < Date.now()) {
186
- config.clearTrial();
187
- return;
188
- }
189
- process.stderr.write(
190
- `${paint("yellow", `This directory had a trial (${trial.workspace}): keep it with ${trial.claim_url} or this push goes to your account`)}\n\n`
191
- );
192
- }
193
-
194
138
  // Something the platform wants the developer to know about the command they
195
139
  // just ran -- a deprecation, usually. On stderr so scripts reading stdout keep
196
140
  // working.
@@ -7,7 +7,6 @@ import { KEYS, SLUG_FORMAT } from "../config.mjs";
7
7
  import { MANIFEST_FILE, manifestPath } from "../workspace.mjs";
8
8
  import { VERSION } from "../version.mjs";
9
9
  import { fail, takeValue } from "../support.mjs";
10
- import { formatUtc } from "../trial.mjs";
11
10
  import { workspacesClient } from "./deploy.mjs";
12
11
 
13
12
  export const DOCS_URL = "https://vatio.ai/docs";
@@ -40,14 +39,6 @@ export async function doctor(config) {
40
39
  const token = config.resolveToken();
41
40
  console.log(`Token: ${token ? "configured" : "missing — run `vatio login`"}`);
42
41
  if (token) console.log(`Account: ${await accountLine(config)}`);
43
- // Where this directory pushes with no account. The link to keep it is not
44
- // printed: whoever holds it can take the trial, and this output is the one
45
- // that gets pasted into issues.
46
- const trial = config.trial();
47
- if (trial) {
48
- const used = token ? " (not used: this machine has an account)" : "";
49
- console.log(`Trial: ${trial.workspace}${used}, deleted ${formatUtc(trial.expires_at)} unless kept`);
50
- }
51
42
  console.log(`Docs: ${DOCS_URL}`);
52
43
  }
53
44
 
@@ -160,12 +151,7 @@ export async function init(config, args) {
160
151
  console.log(`Wrote ${manifest}`);
161
152
  const agentsNote = writeAgentsNote(target);
162
153
  if (agentsNote) console.log(agentsNote);
163
- if (!authorized) {
164
- console.log(
165
- "Local only for now — `vatio push` deploys it with no account, as a trial, and prints a link to try it " +
166
- `and one to keep it as ${slug}.`
167
- );
168
- }
154
+ if (!authorized) console.log(`Local only for now — \`vatio push\` is what creates ${slug} on the platform.`);
169
155
  if (!authorized && String(name ?? "").trim() !== "") {
170
156
  console.log("Set the display name once it exists: `vatio business set --name NAME`, or the inbox's Business page.");
171
157
  }
package/lib/config.mjs CHANGED
@@ -10,11 +10,6 @@
10
10
  // identity is per directory and lives in that workspace's own vatio.yml. There
11
11
  // is no --workspace flag, because the slug is a property of the directory, and
12
12
  // reading it anywhere else is how a push lands in the wrong workspace.
13
- //
14
- // The one thing kept here per directory is a trial (lib/trial.mjs): what
15
- // `vatio push` made with no account on this machine, under `trials`, keyed by
16
- // the workspace's absolute path. Its deploy key is a credential, so it lives
17
- // in this 0600 file and never in the directory, where it could be committed.
18
13
 
19
14
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
20
15
  import { homedir } from "node:os";
@@ -140,51 +135,17 @@ export class Config {
140
135
  return this.workspaceRoot ? manifestPath(this.workspaceRoot) : null;
141
136
  }
142
137
 
143
- // The workspace's slice of the API, which is what chat talks to: the trial
144
- // this directory pushed to while this machine has no account, unless a
145
- // token was given for the call itself.
146
- resolveApiUrl({ explicit = null, token = null } = {}) {
138
+ // The workspace's slice of the API, which is what chat talks to.
139
+ resolveApiUrl({ explicit = null } = {}) {
147
140
  const url = presence(explicit);
148
141
  if (url) return stripSlash(url);
149
142
 
150
143
  const base = this.resolveBaseUrl();
151
- const trial = presence(token) ? null : this.activeTrial();
152
- const workspace = trial?.workspace ?? this.resolveWorkspace();
144
+ const workspace = this.resolveWorkspace();
153
145
  if (!base || !workspace) return null;
154
146
  return `${base}/api/developer/v1/${workspace}`;
155
147
  }
156
148
 
157
- // The trial `vatio push` made from this directory against this base URL:
158
- // { base_url, workspace, requested, key, claim_url, try_url, expires_at }.
159
- trial() {
160
- if (!this.workspaceRoot) return null;
161
- const trials = this.load().trials;
162
- const entry = trials && typeof trials === "object" ? trials[this.workspaceRoot] : null;
163
- if (!entry || typeof entry !== "object" || !presence(entry.key) || !presence(entry.workspace)) return null;
164
- return stripSlash(presence(entry.base_url)) === this.resolveBaseUrl() ? entry : null;
165
- }
166
-
167
- // The trial commands go to: only while this machine has no account.
168
- activeTrial() {
169
- return this.resolveToken() ? null : this.trial();
170
- }
171
-
172
- writeTrial(entry) {
173
- const root = this.workspaceRootRequired();
174
- const data = this.load();
175
- const trials = data.trials && typeof data.trials === "object" ? data.trials : {};
176
- data.trials = { ...trials, [root]: { ...entry, base_url: this.resolveBaseUrl() } };
177
- return this.save(data);
178
- }
179
-
180
- clearTrial() {
181
- const data = this.load();
182
- if (!this.workspaceRoot || !data.trials?.[this.workspaceRoot]) return data;
183
- delete data.trials[this.workspaceRoot];
184
- if (Object.keys(data.trials).length === 0) delete data.trials;
185
- return this.save(data);
186
- }
187
-
188
149
  writeAuth({ baseUrl, token }) {
189
150
  const data = this.load();
190
151
  data.base_url = stripSlash(String(baseUrl ?? "")) ?? "";
package/lib/help.mjs CHANGED
@@ -37,9 +37,7 @@ Commands default as listed.
37
37
 
38
38
  Deploy:
39
39
  push [--force] Validate the workspace, then update preview; runs
40
- no tests. With no account on this machine it
41
- deploys a 7-day trial and prints a link to try
42
- it and one to keep it (keeping it signs in).
40
+ no tests (the first push signs in like \`login\`).
43
41
  --force replaces an unpublished push from
44
42
  another git branch
45
43
  publish [--force] Take preview live, with its knowledge changes.
package/lib/http.mjs CHANGED
@@ -21,19 +21,6 @@ export class UnauthorizedError extends HttpError {}
21
21
  export class ForbiddenError extends HttpError {}
22
22
  export class NotFoundError extends HttpError {}
23
23
 
24
- // A trial's deploy key (lib/trial.mjs) after someone kept the trial: the call
25
- // did nothing, and `workspace` is the workspace it became. bin/vatio.mjs signs
26
- // this terminal in and runs the command again.
27
- export class TrialClaimedError extends HttpError {
28
- constructor(message, options) {
29
- super(message, options);
30
- this.workspace = typeof options.body?.workspace === "string" ? options.body.workspace : null;
31
- }
32
- }
33
-
34
- // A trial's deploy key whose trial was deleted: nobody kept it in time.
35
- export class TrialGoneError extends HttpError {}
36
-
37
24
  // The platform takes calls only from the CLI's current release
38
25
  // (RequiresLatestCli on the backend): `latest` is the version to run instead.
39
26
  // The refused call did nothing, so bin/vatio.mjs runs the whole command again
@@ -160,8 +147,6 @@ export class HttpClient {
160
147
 
161
148
  const options = { status, requestId, body: body ?? {} };
162
149
  if (status === 426 && body?.error_key === "cli_outdated") throw new CliOutdatedError(message, options);
163
- if (status === 409 && body?.error === "trial_claimed") throw new TrialClaimedError(message, options);
164
- if (status === 401 && body?.error === "trial_not_found") throw new TrialGoneError(message, options);
165
150
  if (status === 401) throw new UnauthorizedError(message, options);
166
151
  if (status === 403) throw new ForbiddenError(message, options);
167
152
  if (status === 404) throw new NotFoundError(message, options);
package/lib/workspace.mjs CHANGED
@@ -7,7 +7,7 @@
7
7
  // thing a client cannot ask the platform for is the address of that call: the
8
8
  // slug is in its URL. So this reads `workspace:` and stops.
9
9
 
10
- import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
10
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
11
11
  import { dirname, join, parse as parsePath, relative, resolve } from "node:path";
12
12
  import { parse as parseYaml } from "yaml";
13
13
 
@@ -90,22 +90,6 @@ export function workspaceSlug(dir) {
90
90
  return slug;
91
91
  }
92
92
 
93
- // Points the directory at another workspace: the one a trial became when it
94
- // was kept under a slug other than the one vatio.yml asked for. Only the
95
- // top-level `workspace:` line changes, comment and all kept, so the rest of
96
- // the file is exactly what the developer wrote. False when there is no such
97
- // line to change.
98
- export function rewriteWorkspaceSlug(dir, slug) {
99
- const file = manifestPath(dir);
100
- if (!file || !SLUG_FORMAT.test(slug)) return false;
101
-
102
- const text = readFileSync(file, "utf8");
103
- const line = /^workspace:[ \t]*(["']?)[a-z0-9-]*\1([ \t]*#.*)?$/m;
104
- if (!line.test(text)) return false;
105
- writeFileSync(file, text.replace(line, (_match, _quote, comment = "") => `workspace: ${slug}${comment}`));
106
- return true;
107
- }
108
-
109
93
  function readManifest(file) {
110
94
  if (!existsSync(file)) return null;
111
95
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.86.1",
3
+ "version": "0.88.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",
package/lib/trial.mjs DELETED
@@ -1,135 +0,0 @@
1
- // `vatio push` on a machine with no account: a trial workspace.
2
- //
3
- // The platform makes one (POST /api/developer/v1/trials) and answers with two
4
- // secrets. The deploy key (`vtk_`) stays on this machine, in the config file,
5
- // next to this directory's path: it pushes, checks, chats and writes knowledge
6
- // on the trial's preview, and nothing else. The link to keep it (`claim_url`)
7
- // is for the person: opened signed in, it makes the trial theirs.
8
- //
9
- // Keeping it hands this machine nothing. The key answers `409 trial_claimed`
10
- // from then on, naming the workspace the trial became, and the next command
11
- // signs this terminal in with a device code like `vatio login` does
12
- // (keepClaimedTrial). A link that sent a token back here would send one to
13
- // whoever made the trial and got someone else to open its link.
14
-
15
- import { MANIFEST_FILE, rewriteWorkspaceSlug, workspaceSlug } from "./workspace.mjs";
16
- import { HttpError, throwIfOutdated } from "./http.mjs";
17
- import { clientHeaders } from "./telemetry.mjs";
18
- import { deviceLogin } from "./commands/auth.mjs";
19
-
20
- // Asks for a trial, and remembers it for this directory. `requested` is the
21
- // slug vatio.yml names, which the trial takes when it is kept if it is free.
22
- export async function startTrial(config, requested) {
23
- const baseUrl = config.resolveBaseUrl();
24
- const url = `${baseUrl}/api/developer/v1/trials`;
25
- let response;
26
- try {
27
- response = await fetch(url, {
28
- method: "POST",
29
- headers: { ...clientHeaders(), "Content-Type": "application/json", Accept: "application/json" },
30
- body: JSON.stringify({ workspace: requested }),
31
- signal: AbortSignal.timeout(30_000)
32
- });
33
- } catch (error) {
34
- const reason = error?.cause?.code ?? error?.name ?? "request failed";
35
- throw new HttpError(`${reason}: ${url}`);
36
- }
37
- await throwIfOutdated(response);
38
-
39
- const raw = await response.text();
40
- let body;
41
- try {
42
- body = JSON.parse(raw);
43
- } catch {
44
- body = {};
45
- }
46
- if (response.status !== 201 || !body.trial_key || !body.workspace) {
47
- const message = body.error_description ?? body.error ?? (raw.trim().slice(0, 200) || `HTTP ${response.status}`);
48
- throw new HttpError(`Could not start a trial: ${message}`, {
49
- status: response.status,
50
- requestId: body.request_id ?? null,
51
- body
52
- });
53
- }
54
-
55
- console.log(
56
- "No Vatio account on this machine, so this goes to a trial workspace. Nothing to sign up for until you keep it."
57
- );
58
- const trial = {
59
- workspace: body.workspace,
60
- requested,
61
- key: body.trial_key,
62
- claim_url: body.claim_url,
63
- expires_at: body.expires_at
64
- };
65
- config.writeTrial(trial);
66
- return config.trial();
67
- }
68
-
69
- // What a push to a trial prints: the two links, what a trial cannot do, and
70
- // how long it lasts.
71
- export function printTrialPush(trial, payload, { started }) {
72
- const where = started ? "preview" : `preview of trial ${trial.workspace}`;
73
- console.log(`Pushed deployment #${payload.deployment_id} to ${where} (git_sha=${JSON.stringify(payload.git_sha ?? null)})`);
74
- for (const warning of Array.isArray(payload.warnings) ? payload.warnings : []) console.log(` warning: ${warning}`);
75
- console.log("");
76
- printTrialLinks(trial);
77
- console.log("");
78
- console.log(
79
- `Deleted ${formatUtc(trial.expires_at)} unless you keep it. Until then: preview only, tools make no writes, no secrets.`
80
- );
81
- console.log('Talk to it: vatio chat "hello" Already have an account? vatio login, then vatio push.');
82
- console.log("(A coding agent running this: give the person you work for both links.)");
83
- }
84
-
85
- export function printTrialLinks(trial) {
86
- if (trial.try_url) {
87
- console.log("Try it (anyone with this link can chat with it):");
88
- console.log(` ${trial.try_url}`);
89
- }
90
- console.log("Keep it (sign in or create an account; this link makes it yours, so don't share it):");
91
- console.log(` ${trial.claim_url}`);
92
- }
93
-
94
- // Someone opened the link and kept the trial since the last command: the key
95
- // stopped working, and this terminal signs in to the account that kept it --
96
- // with a device code its owner approves in the browser, never with anything
97
- // the platform sent here. vatio.yml then names the workspace the trial became,
98
- // if that is not the slug it asked for.
99
- export async function keepClaimedTrial(config, error) {
100
- const trial = config.trial();
101
- const workspace = error.workspace;
102
- const auth = await deviceLogin({
103
- config,
104
- baseUrl: config.resolveBaseUrl(),
105
- workspace,
106
- message: `You kept this agent: it is workspace ${workspace} now. Sign this terminal in to keep working on it.`
107
- });
108
- config.writeAuth({ baseUrl: auth.baseUrl, token: auth.token });
109
- if (auth.email) console.log(`Signed in as ${auth.email}`);
110
- console.log(`Token saved to ${config.configPath}`);
111
-
112
- const root = config.workspaceRoot;
113
- let current = null;
114
- try {
115
- current = root ? workspaceSlug(root) : null;
116
- } catch {
117
- current = null;
118
- }
119
- if (root && workspace && current !== workspace && rewriteWorkspaceSlug(root, workspace)) {
120
- const why = current && current === trial?.requested ? `${current} was taken` : "the workspace you kept";
121
- console.log(`${MANIFEST_FILE}: workspace ${current ?? "(none)"} → ${workspace} (${why})`);
122
- }
123
- config.clearTrial();
124
- console.log("");
125
- }
126
-
127
- // "Fri Oct 16 03:40 UTC": when, to the minute, in the zone every terminal shows
128
- // the same.
129
- export function formatUtc(iso) {
130
- const date = new Date(iso);
131
- if (Number.isNaN(date.getTime())) return "soon";
132
- const day = date.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric", timeZone: "UTC" });
133
- const time = date.toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
134
- return `${day.replace(",", "")} ${time} UTC`;
135
- }