@vatio-ai/cli 0.87.0 → 0.89.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 +2 -3
- package/bin/vatio.mjs +8 -49
- package/lib/api-client.mjs +14 -1
- package/lib/commands/chat.mjs +6 -12
- package/lib/commands/deploy.mjs +165 -80
- package/lib/commands/misc.mjs +1 -15
- package/lib/config.mjs +36 -42
- package/lib/help.mjs +9 -5
- package/lib/http.mjs +7 -10
- package/lib/pull.mjs +605 -0
- package/lib/support.mjs +17 -0
- package/lib/workspace.mjs +1 -17
- package/package.json +1 -1
- package/lib/trial.mjs +0 -135
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
|
|
144
|
-
|
|
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
|
|
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 ?? "")) ?? "";
|
|
@@ -216,6 +177,35 @@ export class Config {
|
|
|
216
177
|
return this.save(data);
|
|
217
178
|
}
|
|
218
179
|
|
|
180
|
+
// The deployment a workspace's files were last made to match, by a push or
|
|
181
|
+
// a pull, which the next push says it is built on: the platform refuses one
|
|
182
|
+
// that would overwrite edits made since outside the files. Per server and
|
|
183
|
+
// workspace, since a deployment id only means anything on the server that
|
|
184
|
+
// issued it; null when this machine never pushed or pulled it.
|
|
185
|
+
baseDeploymentFor({ baseUrl, workspace }) {
|
|
186
|
+
const all = this.load().base_deployments;
|
|
187
|
+
const id = plainObject(all) && plainObject(all[stripSlash(baseUrl)]) ? all[stripSlash(baseUrl)][workspace] : null;
|
|
188
|
+
return Number.isInteger(id) && id > 0 ? id : null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Quietly does nothing when the file cannot be written: the push or pull it
|
|
192
|
+
// follows already happened, and the cost of forgetting is one refused push
|
|
193
|
+
// that says to pull.
|
|
194
|
+
rememberBaseDeployment({ baseUrl, workspace, deploymentId }) {
|
|
195
|
+
const id = Number(deploymentId);
|
|
196
|
+
const server = stripSlash(baseUrl);
|
|
197
|
+
if (!Number.isInteger(id) || id <= 0 || !server || !workspace) return;
|
|
198
|
+
try {
|
|
199
|
+
const data = this.load();
|
|
200
|
+
const all = plainObject(data.base_deployments) ? data.base_deployments : {};
|
|
201
|
+
const forServer = plainObject(all[server]) ? all[server] : {};
|
|
202
|
+
data.base_deployments = { ...all, [server]: { ...forServer, [workspace]: id } };
|
|
203
|
+
this.save(data);
|
|
204
|
+
} catch {
|
|
205
|
+
// See above.
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
219
209
|
displayHash() {
|
|
220
210
|
const out = {};
|
|
221
211
|
const base = this.resolveBaseUrl();
|
|
@@ -277,6 +267,10 @@ function stripSlash(value) {
|
|
|
277
267
|
return value == null ? null : value.replace(/\/$/, "");
|
|
278
268
|
}
|
|
279
269
|
|
|
270
|
+
function plainObject(value) {
|
|
271
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
272
|
+
}
|
|
273
|
+
|
|
280
274
|
function maskSecret(value) {
|
|
281
275
|
if (!value) return null;
|
|
282
276
|
return value.length <= 8 ? value : `${value.slice(0, 4)}…${value.slice(-4)}`;
|
package/lib/help.mjs
CHANGED
|
@@ -37,11 +37,15 @@ Commands default as listed.
|
|
|
37
37
|
|
|
38
38
|
Deploy:
|
|
39
39
|
push [--force] Validate the workspace, then update preview; runs
|
|
40
|
-
no tests
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
--force replaces
|
|
44
|
-
|
|
40
|
+
no tests (the first push signs in like \`login\`).
|
|
41
|
+
Refused over edits made outside your files (pull
|
|
42
|
+
them first) and over an unpublished push from
|
|
43
|
+
another git branch; --force replaces either
|
|
44
|
+
pull [--env NAME] [--force]
|
|
45
|
+
Write the deployed agent into vatio.yml's agent:
|
|
46
|
+
block and tools/, edits from the Vatio MCP
|
|
47
|
+
included (default: preview). Wants vatio.yml and
|
|
48
|
+
tools/ committed to git; --force writes anyway
|
|
45
49
|
publish [--force] Take preview live, with its knowledge changes.
|
|
46
50
|
Once published, refused until \`vatio test\` has
|
|
47
51
|
tested preview's version, and while it fails a
|
package/lib/http.mjs
CHANGED
|
@@ -21,19 +21,17 @@ export class UnauthorizedError extends HttpError {}
|
|
|
21
21
|
export class ForbiddenError extends HttpError {}
|
|
22
22
|
export class NotFoundError extends HttpError {}
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
24
|
+
// 409: the call would overwrite something it has not seen -- a push over edits
|
|
25
|
+
// made outside the files (preview_edited_outside), or over another branch's
|
|
26
|
+
// unpublished push. `errorKey` says which, for the command that knows what to
|
|
27
|
+
// do next.
|
|
28
|
+
export class ConflictError extends HttpError {
|
|
28
29
|
constructor(message, options) {
|
|
29
30
|
super(message, options);
|
|
30
|
-
this.
|
|
31
|
+
this.errorKey = typeof options.body?.error_key === "string" ? options.body.error_key : null;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
// A trial's deploy key whose trial was deleted: nobody kept it in time.
|
|
35
|
-
export class TrialGoneError extends HttpError {}
|
|
36
|
-
|
|
37
35
|
// The platform takes calls only from the CLI's current release
|
|
38
36
|
// (RequiresLatestCli on the backend): `latest` is the version to run instead.
|
|
39
37
|
// The refused call did nothing, so bin/vatio.mjs runs the whole command again
|
|
@@ -160,11 +158,10 @@ export class HttpClient {
|
|
|
160
158
|
|
|
161
159
|
const options = { status, requestId, body: body ?? {} };
|
|
162
160
|
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
161
|
if (status === 401) throw new UnauthorizedError(message, options);
|
|
166
162
|
if (status === 403) throw new ForbiddenError(message, options);
|
|
167
163
|
if (status === 404) throw new NotFoundError(message, options);
|
|
164
|
+
if (status === 409) throw new ConflictError(message, options);
|
|
168
165
|
if (status === 422) throw new UnprocessableError(body);
|
|
169
166
|
throw new HttpError(`HTTP ${status}: ${message}`, options);
|
|
170
167
|
}
|