@solti/cli 0.1.2 → 0.2.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 +18 -1
- package/dist/api/client.js +18 -1
- package/dist/auth/oauth.js +60 -36
- package/dist/commands/cronjob.js +24 -0
- package/dist/commands/job.js +5 -1
- package/dist/commands/workflow.js +76 -0
- package/dist/index.js +70 -3
- package/dist/lib/parse.js +37 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Command-line interface for the [Solti Platform](https://solti.run) — schedule and run asynchronous workloads without managing infrastructure.
|
|
4
4
|
|
|
5
|
+
**Packages:** `@solti/cli` (npm) · `solti-cli` (PyPI) · **License:** MIT
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -15,6 +17,13 @@ npm install -g @solti/cli
|
|
|
15
17
|
# or: pnpm add -g @solti/cli
|
|
16
18
|
```
|
|
17
19
|
|
|
20
|
+
Or via pip / uv (requires Node.js >= 20 on your PATH):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install solti-cli
|
|
24
|
+
# or: uv add solti-cli
|
|
25
|
+
```
|
|
26
|
+
|
|
18
27
|
## Quickstart
|
|
19
28
|
|
|
20
29
|
```bash
|
|
@@ -55,4 +64,12 @@ pnpm build
|
|
|
55
64
|
node dist/index.js --help
|
|
56
65
|
```
|
|
57
66
|
|
|
58
|
-
|
|
67
|
+
### PyPI packaging (Change 069)
|
|
68
|
+
|
|
69
|
+
The `solti-cli` Python package vendors a self-contained Node bundle. To
|
|
70
|
+
rebuild it after a code change:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pnpm build && pnpm bundle:python
|
|
74
|
+
uv build
|
|
75
|
+
```
|
package/dist/api/client.js
CHANGED
|
@@ -69,6 +69,23 @@ export function projectBaseUrl(credentials, apiUrlOverride) {
|
|
|
69
69
|
return GLOBAL_API_URL;
|
|
70
70
|
}
|
|
71
71
|
/** Returns the active profile's `api_url` override, if set. */
|
|
72
|
+
/** Returns the api-url override for the current invocation.
|
|
73
|
+
*
|
|
74
|
+
* Headless env auth (SOLTI_API_KEY set without an explicit SOLTI_PROFILE)
|
|
75
|
+
* bypasses local profile config entirely: otherwise the active profile's
|
|
76
|
+
* `api_url` silently hijacks SOLTI_API_URL and headless requests are routed
|
|
77
|
+
* to the wrong host (observed 2026-10-24 — headless preview requests were
|
|
78
|
+
* served by the live API because the active syslive profile pointed there).
|
|
79
|
+
* With SOLTI_PROFILE set explicitly, that profile's `api_url` wins over the
|
|
80
|
+
* env var (documented precedence); without a profile override, the env var
|
|
81
|
+
* applies. */
|
|
82
|
+
export async function resolveApiUrlOverride() {
|
|
83
|
+
if (process.env.SOLTI_API_KEY && !process.env.SOLTI_PROFILE) {
|
|
84
|
+
return process.env.SOLTI_API_URL ?? null;
|
|
85
|
+
}
|
|
86
|
+
const profileOverride = await profileApiUrlOverride();
|
|
87
|
+
return profileOverride ?? process.env.SOLTI_API_URL ?? null;
|
|
88
|
+
}
|
|
72
89
|
async function profileApiUrlOverride() {
|
|
73
90
|
const account = await getActiveAccount();
|
|
74
91
|
if (account === null)
|
|
@@ -115,7 +132,7 @@ export async function request(path, options = {}) {
|
|
|
115
132
|
}
|
|
116
133
|
}
|
|
117
134
|
else {
|
|
118
|
-
const override = await
|
|
135
|
+
const override = await resolveApiUrlOverride();
|
|
119
136
|
const url = projectBaseUrl(credentials, override);
|
|
120
137
|
if (url === null) {
|
|
121
138
|
throw new Error("No active project. Run `solti profile set <name> --project-id <id>` / `solti project use <id>`, or set SOLTI_PROJECT_ID.");
|
package/dist/auth/oauth.js
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Solti ID (Authorizer) OAuth 2.0 Authorization Code + PKCE flow for the
|
|
3
|
+
* Solti CLI (Change 057f — direct loopback PKCE, no relay, no solti-api
|
|
4
|
+
* token endpoints).
|
|
3
5
|
*
|
|
4
|
-
* Registered clients (Change
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Registered reserved interactive clients (Change 057b spike; public clients,
|
|
7
|
+
* no secret — authorization_code+PKCE token exchanges need client_id alone,
|
|
8
|
+
* refresh/revoke need client_id + token):
|
|
9
|
+
* - live Authorizer (https://id.solti.run): `113215f1a2a2beeed9f5c6279e3537a2`
|
|
10
|
+
* - dev Authorizer (https://id.dev.solti.run): `b7435147811323ceb1055d8bec85b315`
|
|
11
|
+
* - Redirect URIs http://localhost:4242..4245/callback (exact-match, also
|
|
12
|
+
* registered as allowed origins); scopes `openid offline_access email
|
|
13
|
+
* profile`. No OAuth `resource` param: access tokens are Authorizer JWTs
|
|
14
|
+
* with aud=client_id and solti-api now validates aud=client_id (057e).
|
|
10
15
|
*
|
|
11
16
|
* The DEFAULT issuer is the live one: the CLI's default API host is the live
|
|
12
17
|
* `https://api.solti.run/1`, and the live API rejects dev-issued tokens
|
|
13
|
-
* ("Missing user context for project scope" / "User is not authenticated")
|
|
14
18
|
* — the previous dev default made plain `solti account login` unusable
|
|
15
19
|
* against the default API (Change 048). Dev-issuer sign-in remains available
|
|
16
|
-
* via
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* via SOLTI_AUTHORIZER_ISSUER / SOLTI_AUTHORIZER_CLIENT_ID (the pre-migration
|
|
21
|
+
* SOLTI_LOGTO_ISSUER / SOLTI_LOGTO_CLIENT_ID names are still honored as
|
|
22
|
+
* deprecated fallbacks so existing env profiles survive the migration).
|
|
23
|
+
* Whichever environment a login used is persisted per account
|
|
24
|
+
* (AuthStore.issuer/client_id) so token refresh and logout hit the same
|
|
25
|
+
* Authorizer instance.
|
|
19
26
|
*/
|
|
20
27
|
import crypto from "node:crypto";
|
|
21
28
|
import http from "node:http";
|
|
22
29
|
import { deleteAuth, getActiveAccount, listAccounts, readActive, readAuth, writeActive, writeAuth, } from "../config/store.js";
|
|
23
|
-
export const CLIENT_ID = process.env.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export const
|
|
30
|
+
export const CLIENT_ID = process.env.SOLTI_AUTHORIZER_CLIENT_ID ??
|
|
31
|
+
process.env.SOLTI_LOGTO_CLIENT_ID ??
|
|
32
|
+
"113215f1a2a2beeed9f5c6279e3537a2";
|
|
33
|
+
export const ISSUER = process.env.SOLTI_AUTHORIZER_ISSUER ??
|
|
34
|
+
process.env.SOLTI_LOGTO_ISSUER ??
|
|
35
|
+
"https://id.solti.run";
|
|
36
|
+
export const SCOPES = "openid offline_access email profile";
|
|
37
|
+
/** Manual endpoint fallback for issuers whose OIDC discovery is unavailable
|
|
38
|
+
* (Change 057b evidence: Authorizer serves the standard paths). */
|
|
39
|
+
function fallbackEndpoints(issuer) {
|
|
40
|
+
return {
|
|
41
|
+
authorization_endpoint: `${issuer}/authorize`,
|
|
42
|
+
token_endpoint: `${issuer}/oauth/token`,
|
|
43
|
+
userinfo_endpoint: `${issuer}/userinfo`,
|
|
44
|
+
revocation_endpoint: `${issuer}/oauth/revoke`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
27
47
|
/** Decodes JWT payload claims (no signature check — best-effort hints only). */
|
|
28
48
|
function decodeJwtClaims(token) {
|
|
29
49
|
if (token === undefined)
|
|
@@ -49,7 +69,10 @@ export function resolveOidc(auth) {
|
|
|
49
69
|
CLIENT_ID;
|
|
50
70
|
return { issuer, clientId };
|
|
51
71
|
}
|
|
52
|
-
/** Fixed registered loopback port range (spec §1.1 / logto-changes.md §5.1).
|
|
72
|
+
/** Fixed registered loopback port range (spec §1.1 / logto-changes.md §5.1).
|
|
73
|
+
* The listener binds dual-stack (no explicit host) so browsers resolving
|
|
74
|
+
* `localhost` to ::1 still reach the callback server (observed in the 057f
|
|
75
|
+
* e2e: Chromium connected to ::1 only). */
|
|
53
76
|
const CALLBACK_PORTS = [4242, 4243, 4244, 4245];
|
|
54
77
|
const CALLBACK_PATH = "/callback";
|
|
55
78
|
const discoveryCache = new Map();
|
|
@@ -57,13 +80,21 @@ export async function discover(issuer = ISSUER) {
|
|
|
57
80
|
const cached = discoveryCache.get(issuer);
|
|
58
81
|
if (cached !== undefined)
|
|
59
82
|
return cached;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetch(`${issuer}/.well-known/openid-configuration`);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new Error(`HTTP ${response.status}`);
|
|
87
|
+
}
|
|
88
|
+
const discovery = (await response.json());
|
|
89
|
+
discoveryCache.set(issuer, discovery);
|
|
90
|
+
return discovery;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Discovery unavailable — fall back to the standard Authorizer paths.
|
|
94
|
+
const discovery = fallbackEndpoints(issuer);
|
|
95
|
+
discoveryCache.set(issuer, discovery);
|
|
96
|
+
return discovery;
|
|
63
97
|
}
|
|
64
|
-
const discovery = (await response.json());
|
|
65
|
-
discoveryCache.set(issuer, discovery);
|
|
66
|
-
return discovery;
|
|
67
98
|
}
|
|
68
99
|
function base64url(buffer) {
|
|
69
100
|
return buffer.toString("base64url");
|
|
@@ -97,13 +128,9 @@ export async function login(options) {
|
|
|
97
128
|
authorizationUrl.searchParams.set("client_id", CLIENT_ID);
|
|
98
129
|
authorizationUrl.searchParams.set("redirect_uri", redirectUri);
|
|
99
130
|
authorizationUrl.searchParams.set("scope", SCOPES);
|
|
100
|
-
authorizationUrl.searchParams.set("resource", RESOURCE);
|
|
101
131
|
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
102
132
|
authorizationUrl.searchParams.set("code_challenge_method", "S256");
|
|
103
133
|
authorizationUrl.searchParams.set("state", state);
|
|
104
|
-
// LogTo only issues a refresh token when `prompt=consent` is requested
|
|
105
|
-
// (first-party apps skip the visible consent screen).
|
|
106
|
-
authorizationUrl.searchParams.set("prompt", "consent");
|
|
107
134
|
if (launchBrowser) {
|
|
108
135
|
console.log(`Opening browser for sign-in:\n ${authorizationUrl.toString()}\n`);
|
|
109
136
|
openBrowser(authorizationUrl.toString());
|
|
@@ -114,7 +141,7 @@ export async function login(options) {
|
|
|
114
141
|
const code = await waitForCallback(server, state);
|
|
115
142
|
server.close();
|
|
116
143
|
const tokens = (await exchangeCode(oidc, code, redirectUri, codeVerifier));
|
|
117
|
-
// Diagnostics: help identify what
|
|
144
|
+
// Diagnostics: help identify what the issuer actually granted.
|
|
118
145
|
if (tokens.access_token.split(".").length !== 3) {
|
|
119
146
|
console.error("(warning: access token is opaque, not a JWT — the API resource was not bound to the grant)");
|
|
120
147
|
}
|
|
@@ -132,7 +159,7 @@ export async function login(options) {
|
|
|
132
159
|
token_type: tokens.token_type ?? "Bearer",
|
|
133
160
|
email,
|
|
134
161
|
// Persist the environment this login used so refresh/logout stay on the
|
|
135
|
-
// same
|
|
162
|
+
// same Authorizer instance (Change 048, retargeted by 057f).
|
|
136
163
|
issuer: ISSUER,
|
|
137
164
|
client_id: CLIENT_ID,
|
|
138
165
|
};
|
|
@@ -162,7 +189,7 @@ function bindCallbackServer() {
|
|
|
162
189
|
reject(error);
|
|
163
190
|
}
|
|
164
191
|
});
|
|
165
|
-
server.listen(port,
|
|
192
|
+
server.listen(port, () => {
|
|
166
193
|
resolve(server);
|
|
167
194
|
});
|
|
168
195
|
};
|
|
@@ -213,7 +240,6 @@ async function exchangeCode(oidc, code, redirectUri, codeVerifier) {
|
|
|
213
240
|
redirect_uri: redirectUri,
|
|
214
241
|
client_id: CLIENT_ID,
|
|
215
242
|
code_verifier: codeVerifier,
|
|
216
|
-
resource: RESOURCE,
|
|
217
243
|
}),
|
|
218
244
|
});
|
|
219
245
|
if (!response.ok) {
|
|
@@ -262,7 +288,7 @@ export async function ensureFreshAccessToken(email) {
|
|
|
262
288
|
}
|
|
263
289
|
const expiresAt = Date.parse(auth.expires_at);
|
|
264
290
|
const refreshThreshold = Date.now() + 5 * 60 * 1000;
|
|
265
|
-
// An opaque access token is useless against
|
|
291
|
+
// An opaque (non-JWT) access token is useless against JWT-verifying APIs —
|
|
266
292
|
// treat it as stale and refresh into a JWT.
|
|
267
293
|
const isJwt = auth.access_token.split(".").length === 3;
|
|
268
294
|
if (Number.isFinite(expiresAt) && expiresAt > refreshThreshold && isJwt) {
|
|
@@ -280,19 +306,17 @@ export async function ensureFreshAccessToken(email) {
|
|
|
280
306
|
grant_type: "refresh_token",
|
|
281
307
|
refresh_token: auth.refresh_token,
|
|
282
308
|
client_id: clientId,
|
|
283
|
-
// LogTo does not auto-reuse the grant's resource (useGrantedResource=false)
|
|
284
|
-
// — the refreshed access token must explicitly request it to stay a JWT.
|
|
285
|
-
resource: RESOURCE,
|
|
286
309
|
}),
|
|
287
310
|
});
|
|
288
311
|
if (!response.ok) {
|
|
289
|
-
throw new Error(`Token refresh failed for ${email} (HTTP ${response.status})
|
|
312
|
+
throw new Error(`Token refresh failed for ${email} (HTTP ${response.status}): ` +
|
|
313
|
+
`session expired — run \`solti account login\` again.`);
|
|
290
314
|
}
|
|
291
315
|
const tokens = (await response.json());
|
|
292
316
|
const updated = {
|
|
293
317
|
...auth,
|
|
294
318
|
access_token: tokens.access_token,
|
|
295
|
-
//
|
|
319
|
+
// Authorizer rotates refresh tokens on use — persist the new one.
|
|
296
320
|
refresh_token: tokens.refresh_token ?? auth.refresh_token,
|
|
297
321
|
expires_at: new Date(Date.now() + tokens.expires_in * 1000).toISOString(),
|
|
298
322
|
// Stamp the resolved environment so legacy auth.json entries are upgraded.
|
package/dist/commands/cronjob.js
CHANGED
|
@@ -21,6 +21,30 @@ export async function cronjobShow(idOrName) {
|
|
|
21
21
|
console.log(`Image: ${c.job_definition?.image ?? "—"}`);
|
|
22
22
|
console.log(`Last run: ${c.last_triggered_at ?? "Never"}`);
|
|
23
23
|
}
|
|
24
|
+
export async function cronjobWorkflows(idOrName, options = {}) {
|
|
25
|
+
// GET /1/cronjobs/{id_or_name}/workflows (change 092; OpenAPI 0.3.2): the
|
|
26
|
+
// cronjob's workflow-run history — same list envelope as GET /1/workflows
|
|
27
|
+
// (ListWorkflowsResponse). Query params forwarded verbatim; the API
|
|
28
|
+
// validates (status enum 422, limit ≤ 200). No trailing slash: this is a
|
|
29
|
+
// sub-resource route like GET /1/workflows/{id}.
|
|
30
|
+
const query = new URLSearchParams();
|
|
31
|
+
if (options.status !== undefined)
|
|
32
|
+
query.set("status", options.status);
|
|
33
|
+
if (options.limit !== undefined)
|
|
34
|
+
query.set("limit", options.limit);
|
|
35
|
+
if (options.offset !== undefined)
|
|
36
|
+
query.set("offset", options.offset);
|
|
37
|
+
const qs = query.toString();
|
|
38
|
+
const data = (await request(`cronjobs/${idOrName}/workflows${qs ? `?${qs}` : ""}`));
|
|
39
|
+
if (data.workflows.length === 0) {
|
|
40
|
+
console.log(`No workflow runs for ${idOrName} yet.`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.log("NAME | STATUS | CREATED | ENDED");
|
|
44
|
+
for (const workflow of data.workflows) {
|
|
45
|
+
console.log(`${workflow.name} | ${workflow.status} | ${workflow.created_at ?? "—"} | ${workflow.ended_at ?? "—"}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
24
48
|
export async function cronjobCreate(options) {
|
|
25
49
|
// Two forms per tools/cli.md: inline (--image [+ --command/--args]) or a
|
|
26
50
|
// workload YAML/JSON file reused as the job_definition template (--file).
|
package/dist/commands/job.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { request } from "../api/client.js";
|
|
3
|
-
import { parseEnvFile, parseResources, parseStringList, parseVolumeShorthand } from "../lib/parse.js";
|
|
3
|
+
import { parseEnvFile, parseResources, parseRunAfter, parseStringList, parseVolumeShorthand } from "../lib/parse.js";
|
|
4
4
|
export async function jobList(options = {}) {
|
|
5
5
|
// API filters (jobs/dtos.py ListJobsRequest): repeatable `tag=` and
|
|
6
6
|
// `label=` query params; labels are "key:value" ("key=value" accepted).
|
|
@@ -97,6 +97,10 @@ export async function jobRun(options) {
|
|
|
97
97
|
name: options.name,
|
|
98
98
|
namePrefix: options.namePrefix,
|
|
99
99
|
maxRetries: options.maxRetries !== undefined ? Number(options.maxRetries) : undefined,
|
|
100
|
+
// Change 090: validated timezone-aware datetime — the job stays queued
|
|
101
|
+
// (no VM, zero cost) until the instant passes. Sent verbatim; the API
|
|
102
|
+
// normalizes aware values to UTC.
|
|
103
|
+
runAfter: options.runAfter !== undefined ? parseRunAfter(options.runAfter) : undefined,
|
|
100
104
|
env: {
|
|
101
105
|
// --env-from-file provides the base set; explicit --env flags win.
|
|
102
106
|
...(options.envFromFile !== undefined ? parseEnvFile(readEnvFile(options.envFromFile)) : {}),
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { request } from "../api/client.js";
|
|
3
|
+
export async function workflowSubmit(file, options = {}) {
|
|
4
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
5
|
+
// Same JSON-then-YAML loading as `solti job run -f` (jobRun).
|
|
6
|
+
let parsed;
|
|
7
|
+
try {
|
|
8
|
+
parsed = JSON.parse(raw);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
const { parse } = await import("yaml");
|
|
12
|
+
parsed = parse(raw);
|
|
13
|
+
}
|
|
14
|
+
const templates = parsed.templates;
|
|
15
|
+
if (!Array.isArray(templates) || templates.length === 0) {
|
|
16
|
+
throw new Error(`Invalid workflow file '${file}' — expected an object with a non-empty \`templates\` list (WorkflowCreateRequest)`);
|
|
17
|
+
}
|
|
18
|
+
// Explicit flags win over name/namePrefix carried in the file (091 D-3).
|
|
19
|
+
const payload = {
|
|
20
|
+
name: options.name ?? parsed.name,
|
|
21
|
+
namePrefix: options.namePrefix ?? parsed.namePrefix,
|
|
22
|
+
templates,
|
|
23
|
+
};
|
|
24
|
+
// Trailing slash: collection routes live at /1/workflows/ (see jobList —
|
|
25
|
+
// a bare /1/workflows 307-redirects behind the TLS-terminating LB).
|
|
26
|
+
const workflow = (await request("workflows/", { method: "POST", body: payload }));
|
|
27
|
+
console.log(`Workflow submitted: ${workflow.name} (${workflow.workflow_id ?? workflow.id}) — ${workflow.status}`);
|
|
28
|
+
}
|
|
29
|
+
export async function workflowGet(idOrName) {
|
|
30
|
+
const workflow = (await request(`workflows/${idOrName}`));
|
|
31
|
+
console.log(`Name: ${workflow.name}`);
|
|
32
|
+
console.log(`ID: ${workflow.id}`);
|
|
33
|
+
console.log(`Status: ${workflow.status}`);
|
|
34
|
+
if (workflow.error_message)
|
|
35
|
+
console.log(`Error: ${workflow.error_message}`);
|
|
36
|
+
console.log(`Nodes: ${workflow.node_count ?? workflow.nodes?.length ?? "—"}`);
|
|
37
|
+
console.log(`Cost (EST): ${workflow.estimated_cost ?? "—"}`);
|
|
38
|
+
console.log(`Cost (ACT): ${workflow.actual_cost ?? "—"}`);
|
|
39
|
+
console.log("\nNODE | STATUS | VM STATUS | JOB ID | COST (EST/ACT) | ERROR");
|
|
40
|
+
for (const node of workflow.nodes ?? []) {
|
|
41
|
+
console.log(`${node.name} | ${node.status} | ${node.vm_status ?? "—"} | ${node.job_id} | ${node.estimated_cost ?? "—"}/${node.actual_cost ?? "—"} | ${node.error_message ?? "—"}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function workflowList(options = {}) {
|
|
45
|
+
// GET /1/workflows query params: status (running|succeeded|failed|cancelled),
|
|
46
|
+
// limit (default 50/max 200), offset. Forwarded verbatim; the API validates.
|
|
47
|
+
const query = new URLSearchParams();
|
|
48
|
+
if (options.status !== undefined)
|
|
49
|
+
query.set("status", options.status);
|
|
50
|
+
if (options.limit !== undefined)
|
|
51
|
+
query.set("limit", options.limit);
|
|
52
|
+
if (options.offset !== undefined)
|
|
53
|
+
query.set("offset", options.offset);
|
|
54
|
+
const qs = query.toString();
|
|
55
|
+
const data = (await request(`workflows/${qs ? `?${qs}` : ""}`));
|
|
56
|
+
if (data.workflows.length === 0) {
|
|
57
|
+
console.log("No workflows. Submit one with `solti workflow submit <file.yaml>`.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log("NAME | STATUS | NODES");
|
|
61
|
+
for (const workflow of data.workflows) {
|
|
62
|
+
console.log(`${workflow.name} | ${workflow.status} | ${workflow.node_count ?? "—"}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function workflowCancel(idOrName, options = {}) {
|
|
66
|
+
// Confirmation pattern mirrors projectDelete/organizationDelete: no
|
|
67
|
+
// interactive prompt — refuse until --yes.
|
|
68
|
+
if (!options.yes) {
|
|
69
|
+
console.error("This cancels every non-terminal node job of the workflow. Re-run with --yes to confirm.");
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Only valid while the workflow is running (the API 409s otherwise).
|
|
74
|
+
await request(`workflows/${idOrName}/cancel`, { method: "POST" });
|
|
75
|
+
console.log(`Cancellation requested for ${idOrName}.`);
|
|
76
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,36 @@ import * as organization from "./commands/organization.js";
|
|
|
9
9
|
import * as profile from "./commands/profile.js";
|
|
10
10
|
import * as project from "./commands/project.js";
|
|
11
11
|
import * as resource from "./commands/resource.js";
|
|
12
|
+
import * as workflow from "./commands/workflow.js";
|
|
12
13
|
const program = new Command();
|
|
13
14
|
program
|
|
14
15
|
.name("solti")
|
|
15
16
|
.description("Solti Platform CLI — schedule and run asynchronous workloads without managing infrastructure.")
|
|
16
|
-
.version("0.1.
|
|
17
|
+
.version("0.1.5")
|
|
17
18
|
.option("--profile <name>", "override the active profile (or set SOLTI_PROFILE)")
|
|
18
|
-
.option("--api-key <key>", "override the API key (or set SOLTI_API_KEY)")
|
|
19
|
+
.option("--api-key <key>", "override the API key (or set SOLTI_API_KEY)")
|
|
20
|
+
// Positional options: the root only consumes its options BEFORE the
|
|
21
|
+
// subcommand. Without this, commander's root-level parse swallows an
|
|
22
|
+
// occurrence of --api-key after the subcommand too, so `profile set` (which
|
|
23
|
+
// declares its own --api-key) never sees the value and silently persists
|
|
24
|
+
// null (change 073 follow-up, item 20).
|
|
25
|
+
.enablePositionalOptions();
|
|
26
|
+
// Global override flags must take effect before any command resolves its
|
|
27
|
+
// credentials: every resolution path reads SOLTI_PROFILE / SOLTI_API_KEY from
|
|
28
|
+
// the environment (resolveCredentials, profile stores), so map the explicit
|
|
29
|
+
// flags onto the env vars here. Explicit flags win over a pre-set env var —
|
|
30
|
+
// they are the more specific user intent.
|
|
31
|
+
// Read the ROOT options, not thisCommand's: with enablePositionalOptions a
|
|
32
|
+
// subcommand-local --api-key (`profile set`) never lands here (it must not
|
|
33
|
+
// leak into the global override), and flags placed before the subcommand are
|
|
34
|
+
// stored at the root.
|
|
35
|
+
program.hook("preAction", () => {
|
|
36
|
+
const globalOptions = program.opts();
|
|
37
|
+
if (globalOptions.profile)
|
|
38
|
+
process.env.SOLTI_PROFILE = globalOptions.profile;
|
|
39
|
+
if (globalOptions.apiKey)
|
|
40
|
+
process.env.SOLTI_API_KEY = globalOptions.apiKey;
|
|
41
|
+
});
|
|
19
42
|
function fail(error) {
|
|
20
43
|
console.error(`error: ${error.message}`);
|
|
21
44
|
process.exit(1);
|
|
@@ -30,7 +53,7 @@ function collectValues(value, previous) {
|
|
|
30
53
|
const accountCommand = program.command("account").description("Manage logged-in accounts");
|
|
31
54
|
accountCommand
|
|
32
55
|
.command("login")
|
|
33
|
-
.description("Log in via your browser (
|
|
56
|
+
.description("Log in via your browser (Solti ID)")
|
|
34
57
|
.option("--no-launch-browser", "print the sign-in URL instead of opening a browser")
|
|
35
58
|
.action(async (_args, command) => {
|
|
36
59
|
const { launchBrowser } = command.opts();
|
|
@@ -186,6 +209,7 @@ jobCommand
|
|
|
186
209
|
.option("--name <name>", "explicit job name")
|
|
187
210
|
.option("--name-prefix <prefix>", "prefix for auto-generated names")
|
|
188
211
|
.option("--max-retries <n>", "maximum container retries")
|
|
212
|
+
.option("--run-after <datetime>", "start the job only after this RFC 3339 datetime (timezone required, e.g. 2026-11-25T02:00:00Z) — it stays queued with no VM until the instant passes")
|
|
189
213
|
.option("--env <key=value>", "environment variable (repeatable)")
|
|
190
214
|
.option("--env-from-file <path>", "load KEY=VALUE lines from a .env file (explicit --env flags win)")
|
|
191
215
|
.option("--volume <spec>", "storage volume mount: <bucket>[/<prefix>]:<mountPath> or bucket=<b>,mountPath=<p>[,connection=...][,prefix=...] (repeatable)")
|
|
@@ -222,6 +246,40 @@ jobCommand
|
|
|
222
246
|
.action(async (jobIdOrName) => {
|
|
223
247
|
await job.jobCancel(jobIdOrName).catch(fail);
|
|
224
248
|
});
|
|
249
|
+
// --- workflow ---------------------------------------------------------------
|
|
250
|
+
const workflowCommand = program
|
|
251
|
+
.command("workflow")
|
|
252
|
+
.description("Manage DAG workflows (templates of standard jobs)");
|
|
253
|
+
workflowCommand
|
|
254
|
+
.command("submit <file>")
|
|
255
|
+
.description("Submit a workflow from a YAML/JSON file (Argo-ish templates payload)")
|
|
256
|
+
.option("--name <name>", "explicit workflow name (overrides the file)")
|
|
257
|
+
.option("--name-prefix <prefix>", "prefix for auto-generated names (overrides the file)")
|
|
258
|
+
.action(async (file, options) => {
|
|
259
|
+
await workflow.workflowSubmit(file, options).catch(fail);
|
|
260
|
+
});
|
|
261
|
+
workflowCommand
|
|
262
|
+
.command("get <id_or_name>")
|
|
263
|
+
.description("Show workflow status and its node jobs")
|
|
264
|
+
.action(async (idOrName) => {
|
|
265
|
+
await workflow.workflowGet(idOrName).catch(fail);
|
|
266
|
+
});
|
|
267
|
+
workflowCommand
|
|
268
|
+
.command("list")
|
|
269
|
+
.description("List recent workflows")
|
|
270
|
+
.option("--status <status>", "filter by status (running | succeeded | failed | cancelled)")
|
|
271
|
+
.option("--limit <n>", "maximum number of workflows to return")
|
|
272
|
+
.option("--offset <n>", "number of workflows to skip")
|
|
273
|
+
.action(async (options) => {
|
|
274
|
+
await workflow.workflowList(options).catch(fail);
|
|
275
|
+
});
|
|
276
|
+
workflowCommand
|
|
277
|
+
.command("cancel <id_or_name>")
|
|
278
|
+
.description("Cancel a workflow (cancels all non-terminal node jobs)")
|
|
279
|
+
.option("--yes", "skip the confirmation prompt")
|
|
280
|
+
.action(async (idOrName, options) => {
|
|
281
|
+
await workflow.workflowCancel(idOrName, options).catch(fail);
|
|
282
|
+
});
|
|
225
283
|
// --- cronjob ----------------------------------------------------------------
|
|
226
284
|
const cronjobCommand = program
|
|
227
285
|
.command("cronjob")
|
|
@@ -238,6 +296,15 @@ cronjobCommand
|
|
|
238
296
|
.action(async (idOrName) => {
|
|
239
297
|
await cronjob.cronjobShow(idOrName).catch(fail);
|
|
240
298
|
});
|
|
299
|
+
cronjobCommand
|
|
300
|
+
.command("workflows <id_or_name>")
|
|
301
|
+
.description("List the workflow runs spawned by a cronjob")
|
|
302
|
+
.option("--status <status>", "filter by status (running | succeeded | failed | cancelled)")
|
|
303
|
+
.option("--limit <n>", "maximum number of workflows to return")
|
|
304
|
+
.option("--offset <n>", "number of workflows to skip")
|
|
305
|
+
.action(async (idOrName, options) => {
|
|
306
|
+
await cronjob.cronjobWorkflows(idOrName, options).catch(fail);
|
|
307
|
+
});
|
|
241
308
|
cronjobCommand
|
|
242
309
|
.command("create")
|
|
243
310
|
.description("Create a cronjob (--image form, or --file with a workload YAML/JSON template)")
|
package/dist/lib/parse.js
CHANGED
|
@@ -38,6 +38,43 @@ export function parseEnvFile(text) {
|
|
|
38
38
|
return env;
|
|
39
39
|
}
|
|
40
40
|
const VRAM_RE = /^\d+(\.\d+)?(Gi|Mi)?$/;
|
|
41
|
+
/** Matches an RFC 3339 / ISO 8601 datetime that carries an explicit UTC
|
|
42
|
+
* offset: `Z`/`z`, `±HH:MM`, `±HHMM`, or `±HH`; `T`/`t`/space separator;
|
|
43
|
+
* optional fractional seconds. Naive datetimes (no offset) never match —
|
|
44
|
+
* the API rejects them with 422 (Change 090), so the CLI must too. */
|
|
45
|
+
const RUN_AFTER_RE = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.\d+)?(?:[Zz]|([+-])(\d{2}):?(\d{2})?)$/;
|
|
46
|
+
const NAIVE_RUN_AFTER_RE = /^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(\.\d+)?$/;
|
|
47
|
+
/** Validates a `--run-after` value (Change 090): a parseable, timezone-aware
|
|
48
|
+
* RFC 3339 / ISO 8601 datetime. Garbage and naive datetimes (no offset) throw
|
|
49
|
+
* with a clear message — no server-local-time guessing. Past instants are
|
|
50
|
+
* allowed (the API treats them as "start now"). Returns the trimmed value for
|
|
51
|
+
* the `runAfter` payload field verbatim; the API normalizes it to UTC. */
|
|
52
|
+
export function parseRunAfter(value) {
|
|
53
|
+
const datetime = value.trim();
|
|
54
|
+
if (NAIVE_RUN_AFTER_RE.test(datetime)) {
|
|
55
|
+
throw new Error(`Invalid --run-after '${value}' — naive datetime without a timezone; append an offset (Z or ±HH:MM), e.g. 2026-11-25T02:00:00Z`);
|
|
56
|
+
}
|
|
57
|
+
const match = RUN_AFTER_RE.exec(datetime);
|
|
58
|
+
if (!match) {
|
|
59
|
+
throw new Error(`Invalid --run-after '${value}' — expected an RFC 3339 / ISO 8601 datetime with timezone, e.g. 2026-11-25T02:00:00Z or 2026-11-25T11:00:00+09:00`);
|
|
60
|
+
}
|
|
61
|
+
// Round-trip the calendar components through Date.UTC: impossible dates
|
|
62
|
+
// (2026-02-30) or out-of-range times (25:00) silently roll over in JS, so
|
|
63
|
+
// a mismatch means the value is not a real datetime. Date.UTC ignores the
|
|
64
|
+
// offset entirely, so the offset groups are range-checked separately.
|
|
65
|
+
const [, year, month, day, hour, minute, second, , offsetSign, offsetHours, offsetMinutes] = match;
|
|
66
|
+
const parsed = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second)));
|
|
67
|
+
if (parsed.getUTCFullYear() !== Number(year) ||
|
|
68
|
+
parsed.getUTCMonth() !== Number(month) - 1 ||
|
|
69
|
+
parsed.getUTCDate() !== Number(day) ||
|
|
70
|
+
parsed.getUTCHours() !== Number(hour) ||
|
|
71
|
+
parsed.getUTCMinutes() !== Number(minute) ||
|
|
72
|
+
parsed.getUTCSeconds() !== Number(second) ||
|
|
73
|
+
(offsetSign !== undefined && (Number(offsetHours) > 23 || Number(offsetMinutes ?? "0") > 59))) {
|
|
74
|
+
throw new Error(`Invalid --run-after '${value}' — not a real calendar datetime`);
|
|
75
|
+
}
|
|
76
|
+
return datetime;
|
|
77
|
+
}
|
|
41
78
|
/** Parses a `--resources` spec, e.g. `cpu=4,memory=16Gi,gpu=24Gi` or
|
|
42
79
|
* `cpu=4,memory=16Gi,gpu.model=A100,gpu.count=2`. Unknown keys, duplicates
|
|
43
80
|
* of the same key, non-numeric cpu/count values, and `gpu.count` without
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solti/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Solti Platform CLI
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Solti Platform CLI — schedule and run asynchronous workloads without managing infrastructure.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"dev": "tsc --watch",
|
|
21
|
-
"test": "bun test"
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"bundle:python": "esbuild dist/index.js --bundle --platform=node --format=cjs --target=node20 --outfile=solti_cli/vendor/cli.cjs"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"commander": "^14.0.2",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^24.10.1",
|
|
30
|
+
"esbuild": "^0.28.2",
|
|
29
31
|
"typescript": "^5.9.3"
|
|
30
32
|
}
|
|
31
33
|
}
|