@seavideo/cli 0.0.0-stage → 0.3.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/LICENSE +12 -0
- package/README.md +528 -2
- package/dist/bin/seavideo.js +11 -0
- package/dist/src/atomic-write.js +14 -0
- package/dist/src/canvas/api.js +172 -0
- package/dist/src/canvas/browser.js +40 -0
- package/dist/src/canvas/chrome-binary.js +109 -0
- package/dist/src/canvas/daemon.js +264 -0
- package/dist/src/canvas/engine-install.js +46 -0
- package/dist/src/canvas/engine-log.js +9 -0
- package/dist/src/canvas/engine.js +99 -0
- package/dist/src/canvas/entry.js +16 -0
- package/dist/src/canvas/env-lock.js +164 -0
- package/dist/src/canvas/launch.js +97 -0
- package/dist/src/canvas/lifecycle.js +65 -0
- package/dist/src/canvas/names.js +61 -0
- package/dist/src/canvas/params.js +38 -0
- package/dist/src/canvas/puppeteer.js +153 -0
- package/dist/src/canvas/screenshot.js +23 -0
- package/dist/src/canvas/session-record.js +77 -0
- package/dist/src/canvas/team.js +97 -0
- package/dist/src/canvas/tool-args.js +47 -0
- package/dist/src/canvas/tool-session.js +165 -0
- package/dist/src/canvas/tool-specs.js +54 -0
- package/dist/src/canvas/url.js +38 -0
- package/dist/src/cli/args.js +16 -0
- package/dist/src/cli/commands/auth.js +51 -0
- package/dist/src/cli/commands/canvas/common.js +31 -0
- package/dist/src/cli/commands/canvas/engine-choice.js +41 -0
- package/dist/src/cli/commands/canvas/index.js +5 -0
- package/dist/src/cli/commands/canvas/item.js +233 -0
- package/dist/src/cli/commands/canvas/list.js +168 -0
- package/dist/src/cli/commands/canvas/register.js +106 -0
- package/dist/src/cli/commands/canvas/render.js +229 -0
- package/dist/src/cli/commands/canvas/screenshot.js +52 -0
- package/dist/src/cli/commands/canvas/session.js +249 -0
- package/dist/src/cli/commands/canvas/teams.js +142 -0
- package/dist/src/cli/commands/config.js +74 -0
- package/dist/src/cli/commands/doctor.js +261 -0
- package/dist/src/cli/commands/engine.js +96 -0
- package/dist/src/cli/commands/env/create.js +160 -0
- package/dist/src/cli/commands/env/fields.js +26 -0
- package/dist/src/cli/commands/env/index.js +4 -0
- package/dist/src/cli/commands/env/list.js +44 -0
- package/dist/src/cli/commands/env/mutate.js +118 -0
- package/dist/src/cli/commands/login/flow-token.js +41 -0
- package/dist/src/cli/commands/login/index.js +12 -0
- package/dist/src/cli/commands/login/oauth.js +69 -0
- package/dist/src/cli/commands/login/save.js +26 -0
- package/dist/src/cli/commands/logout.js +92 -0
- package/dist/src/cli/commands/skill.js +185 -0
- package/dist/src/cli/commands/tool.js +279 -0
- package/dist/src/cli/commands/update.js +117 -0
- package/dist/src/cli/commands/wallet.js +69 -0
- package/dist/src/cli/commands/whoami.js +147 -0
- package/dist/src/cli/context.js +41 -0
- package/dist/src/cli/credential.js +93 -0
- package/dist/src/cli/elapsed.js +25 -0
- package/dist/src/cli/failure-screenshot.js +24 -0
- package/dist/src/cli/flags.js +1 -0
- package/dist/src/cli/hints.js +7 -0
- package/dist/src/cli/main.js +44 -0
- package/dist/src/cli/output-error.js +23 -0
- package/dist/src/cli/output.js +47 -0
- package/dist/src/cli/program.js +261 -0
- package/dist/src/cli/run.js +11 -0
- package/dist/src/cli/session.js +63 -0
- package/dist/src/config/base-url.js +26 -0
- package/dist/src/config/credential-vault.js +115 -0
- package/dist/src/config/dotenv.js +59 -0
- package/dist/src/config/envname.js +41 -0
- package/dist/src/config/paths.js +22 -0
- package/dist/src/config/preset-schema.js +67 -0
- package/dist/src/config/presets.js +132 -0
- package/dist/src/config/resolve.js +41 -0
- package/dist/src/config/secret-key.js +63 -0
- package/dist/src/config/store-schema.js +143 -0
- package/dist/src/config/store.js +273 -0
- package/dist/src/config/vault-crypto.js +44 -0
- package/dist/src/deps.js +191 -0
- package/dist/src/deps.types.js +1 -0
- package/dist/src/errors.js +24 -0
- package/dist/src/fs-retry.js +34 -0
- package/dist/src/i18n.js +1214 -0
- package/dist/src/loopback.js +134 -0
- package/dist/src/sdk/auth.js +20 -0
- package/dist/src/sdk/credential-expiry.js +67 -0
- package/dist/src/sdk/discovery.js +90 -0
- package/dist/src/sdk/http.js +98 -0
- package/dist/src/sdk/identity.js +17 -0
- package/dist/src/sdk/jwks.js +119 -0
- package/dist/src/sdk/oauth-protocol.js +226 -0
- package/dist/src/sdk/oauth.js +179 -0
- package/dist/src/sdk/provider/cn.js +34 -0
- package/dist/src/sdk/provider/index.js +16 -0
- package/dist/src/sdk/provider/oversea.js +41 -0
- package/dist/src/sdk/provider/types.js +1 -0
- package/dist/src/sdk/refresh.js +66 -0
- package/dist/src/semver.js +89 -0
- package/dist/src/skill/api.js +176 -0
- package/dist/src/text.js +3 -0
- package/dist/src/types.js +1 -0
- package/dist/src/update/check-cache.js +56 -0
- package/dist/src/update/install-layout.js +79 -0
- package/dist/src/update/notify.js +15 -0
- package/dist/src/update/npm-install.js +64 -0
- package/dist/src/update/passive.js +53 -0
- package/dist/src/update/registry.js +59 -0
- package/dist/src/wallet/api.js +107 -0
- package/package.json +67 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CliError, errorMessage } from "../errors.js";
|
|
2
|
+
import { t } from "../i18n.js";
|
|
3
|
+
import { credentialExpiry } from "../sdk/credential-expiry.js";
|
|
4
|
+
import { refreshAccessToken } from "../sdk/refresh.js";
|
|
5
|
+
import { closeCanvasSession } from "../canvas/lifecycle.js";
|
|
6
|
+
import { isCanvasLockBusy } from "../canvas/env-lock.js";
|
|
7
|
+
import { fetchDiscovery } from "../sdk/discovery.js";
|
|
8
|
+
export const RENEW_MARGIN_MS = 90_000;
|
|
9
|
+
export async function resolveFlowCredential(ctx, config) {
|
|
10
|
+
const { deps } = ctx;
|
|
11
|
+
const credential = config.flowCredential;
|
|
12
|
+
if (credential === null) {
|
|
13
|
+
throw new CliError('config', t('credential.flowMissing', { env: config.env }, deps.env), {
|
|
14
|
+
detail: t('credential.flowMissingDetail', {}, deps.env),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const expiry = credentialExpiry(credential.value, deps.clock().getTime(), RENEW_MARGIN_MS);
|
|
18
|
+
let result;
|
|
19
|
+
if (expiry === null || !expiry.expired) {
|
|
20
|
+
result = { token: credential.value, config, renewed: false };
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
result = await renew(ctx, config, credential, expiry);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
async function renew(ctx, config, credential, expiry) {
|
|
28
|
+
const { deps } = ctx;
|
|
29
|
+
const refreshToken = credential.refreshToken ?? null;
|
|
30
|
+
if (refreshToken === null) {
|
|
31
|
+
throw expiredError(deps.env, expiry.expiredAt, null);
|
|
32
|
+
}
|
|
33
|
+
let next;
|
|
34
|
+
try {
|
|
35
|
+
next = await doRefresh(ctx, config, refreshToken);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw expiredError(deps.env, expiry.expiredAt, errorMessage(err));
|
|
39
|
+
}
|
|
40
|
+
await closeOldSession(ctx, config.env);
|
|
41
|
+
return {
|
|
42
|
+
token: next.token,
|
|
43
|
+
config: {
|
|
44
|
+
...config,
|
|
45
|
+
flowCredential: { value: next.token, source: 'config', refreshToken: next.refreshToken },
|
|
46
|
+
},
|
|
47
|
+
renewed: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function closeOldSession(ctx, env) {
|
|
51
|
+
try {
|
|
52
|
+
await closeCanvasSession(ctx, env);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (!isCanvasLockBusy(err))
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function doRefresh(ctx, config, refreshToken) {
|
|
60
|
+
const { deps } = ctx;
|
|
61
|
+
const { issuer, clientId } = requireAuthConfig(config, deps.env);
|
|
62
|
+
const discovery = await fetchDiscovery({ fetch: deps.fetch, env: deps.env }, issuer);
|
|
63
|
+
const result = await refreshAccessToken({ fetch: deps.fetch, env: deps.env }, { tokenEndpoint: discovery.tokenEndpoint, clientId, refreshToken });
|
|
64
|
+
const rotated = result.refreshToken ?? refreshToken;
|
|
65
|
+
await ctx.store.writeFlowCredential(config.env, {
|
|
66
|
+
value: result.accessToken,
|
|
67
|
+
source: 'config',
|
|
68
|
+
refreshToken: rotated,
|
|
69
|
+
});
|
|
70
|
+
deps.stderr(`${t('credential.renewed', {}, deps.env)}\n`);
|
|
71
|
+
return { token: result.accessToken, refreshToken: rotated };
|
|
72
|
+
}
|
|
73
|
+
function expiredError(envMap, expiredAt, reason) {
|
|
74
|
+
const at = formatExpiry(expiredAt);
|
|
75
|
+
const detail = reason === null
|
|
76
|
+
? t('credential.expiredDetail', { at }, envMap)
|
|
77
|
+
: t('credential.renewFailedDetail', { at, reason }, envMap);
|
|
78
|
+
return new CliError('auth', t('credential.expired', {}, envMap), { detail });
|
|
79
|
+
}
|
|
80
|
+
function formatExpiry(at) {
|
|
81
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
82
|
+
return `${at.getFullYear()}-${p(at.getMonth() + 1)}-${p(at.getDate())} ${p(at.getHours())}:${p(at.getMinutes())}`;
|
|
83
|
+
}
|
|
84
|
+
function requireAuthConfig(config, envMap) {
|
|
85
|
+
const issuer = config.authIssuer;
|
|
86
|
+
const clientId = config.authClientId;
|
|
87
|
+
if (issuer === null || clientId === null) {
|
|
88
|
+
throw new CliError('config', t('oauth.notConfigured', {}, envMap), {
|
|
89
|
+
detail: t('oauth.notConfiguredDetail', {}, envMap),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { issuer, clientId };
|
|
93
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const MINUTE = 60_000;
|
|
2
|
+
const HOUR = 60 * MINUTE;
|
|
3
|
+
const DAY = 24 * HOUR;
|
|
4
|
+
export function elapsedSince(at, now) {
|
|
5
|
+
const diff = now.getTime() - Date.parse(at);
|
|
6
|
+
let result;
|
|
7
|
+
if (diff < MINUTE) {
|
|
8
|
+
result = { value: 0, unit: 'minute' };
|
|
9
|
+
}
|
|
10
|
+
else if (diff < HOUR) {
|
|
11
|
+
result = { value: Math.floor(diff / MINUTE), unit: 'minute' };
|
|
12
|
+
}
|
|
13
|
+
else if (diff < DAY) {
|
|
14
|
+
result = { value: Math.floor(diff / HOUR), unit: 'hour' };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
result = { value: Math.floor(diff / DAY), unit: 'day' };
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
export function formatTimestamp(at) {
|
|
22
|
+
const d = new Date(at);
|
|
23
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
24
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { saveScreenshot } from "../canvas/screenshot.js";
|
|
2
|
+
import { CliError } from "../errors.js";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
4
|
+
import { style } from "./output.js";
|
|
5
|
+
export async function withScreenshot(ctx, shot, err) {
|
|
6
|
+
const { deps } = ctx;
|
|
7
|
+
const png = await shot.browser.screenshot().catch(() => null);
|
|
8
|
+
const saved = png === null
|
|
9
|
+
? null
|
|
10
|
+
: await saveScreenshot({ fs: deps.fs, clock: deps.clock, dir: ctx.paths.screenshotsDir(shot.env) }, { canvasId: shot.canvasId, reason: shot.reason, png });
|
|
11
|
+
let result = err;
|
|
12
|
+
if (saved === null) {
|
|
13
|
+
}
|
|
14
|
+
else if (err instanceof CliError) {
|
|
15
|
+
const note = t('canvas.screenshotSaved', { path: saved }, deps.env);
|
|
16
|
+
const detail = err.detail === undefined ? note : `${err.detail}\n${note}`;
|
|
17
|
+
result = new CliError(err.kind, err.message, { detail });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const note = t('canvas.screenshotSaved', { path: saved }, deps.env);
|
|
21
|
+
deps.stderr(`${style.dim(` ${note}`)}\n`);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
2
|
+
export function cmdPrefix(ctx) {
|
|
3
|
+
return ctx.envFlag === undefined ? `${ctx.entry} ` : `${ctx.entry} --env ${ctx.envFlag} `;
|
|
4
|
+
}
|
|
5
|
+
export function hint(ctx, key, command) {
|
|
6
|
+
return `${t(key, {}, ctx.deps.env)}: ${cmdPrefix(ctx)}${command}`;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createPaths } from "../config/paths.js";
|
|
2
|
+
import { createConfigStore } from "../config/store.js";
|
|
3
|
+
import { applyDotEnv } from "../config/dotenv.js";
|
|
4
|
+
import { buildProgram, presetNamesFor } from "./program.js";
|
|
5
|
+
import { checkVersionBeforeCommand, refreshVersionAfterCommand } from "../update/passive.js";
|
|
6
|
+
export { buildProgram, VERSION } from "./program.js";
|
|
7
|
+
export { handleError } from "./output-error.js";
|
|
8
|
+
export function createContextFactory(deps, entry = 'seavideo') {
|
|
9
|
+
return () => {
|
|
10
|
+
const paths = createPaths(deps);
|
|
11
|
+
return {
|
|
12
|
+
deps,
|
|
13
|
+
paths,
|
|
14
|
+
store: createConfigStore(deps, paths),
|
|
15
|
+
envFlag: undefined,
|
|
16
|
+
entry,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function main(argv, deps, entry = 'seavideo') {
|
|
21
|
+
let ctxEnvFlag;
|
|
22
|
+
const merged = { ...deps, env: await applyDotEnv(deps) };
|
|
23
|
+
const ctxFactory = () => {
|
|
24
|
+
const paths = createPaths(merged);
|
|
25
|
+
return {
|
|
26
|
+
deps: merged,
|
|
27
|
+
paths,
|
|
28
|
+
store: createConfigStore(merged, paths),
|
|
29
|
+
envFlag: ctxEnvFlag,
|
|
30
|
+
entry,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const paths = createPaths(merged);
|
|
34
|
+
const presetNames = await presetNamesFor(merged, paths);
|
|
35
|
+
const program = buildProgram(merged, ctxFactory, entry, presetNames);
|
|
36
|
+
program.hook('preAction', (thisCommand, actionCommand) => {
|
|
37
|
+
const globalOpts = thisCommand.opts();
|
|
38
|
+
ctxEnvFlag = actionCommand.opts().env ?? globalOpts.env;
|
|
39
|
+
});
|
|
40
|
+
await checkVersionBeforeCommand(merged, paths);
|
|
41
|
+
await program.parseAsync(['node', entry, ...argv]);
|
|
42
|
+
await refreshVersionAfterCommand(merged, paths);
|
|
43
|
+
return process.exitCode;
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CliError, errorMessage } from "../errors.js";
|
|
2
|
+
import { style } from "./output.js";
|
|
3
|
+
export function handleError(err, write) {
|
|
4
|
+
let result;
|
|
5
|
+
if (err instanceof CliError) {
|
|
6
|
+
write(`${style.fail('✗')} ${err.message}\n`);
|
|
7
|
+
if (err.detail !== undefined) {
|
|
8
|
+
const indented = err.detail
|
|
9
|
+
.split('\n')
|
|
10
|
+
.map((line) => ` ${line}`)
|
|
11
|
+
.join('\n');
|
|
12
|
+
write(`${style.dim(indented)}\n`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
}
|
|
16
|
+
result = err.exitCode;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
write(`${style.fail('✗')} ${errorMessage(err)}\n`);
|
|
20
|
+
result = 1;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
2
|
+
const ESC = '\u001b[';
|
|
3
|
+
const enabled = process.env['NO_COLOR'] === undefined;
|
|
4
|
+
function wrap(code, text) {
|
|
5
|
+
return enabled ? `${ESC}${code}m${text}${ESC}0m` : text;
|
|
6
|
+
}
|
|
7
|
+
export const style = {
|
|
8
|
+
ok: (t) => wrap('32', t),
|
|
9
|
+
fail: (t) => wrap('31', t),
|
|
10
|
+
warn: (t) => wrap('33', t),
|
|
11
|
+
dim: (t) => wrap('2', t),
|
|
12
|
+
bold: (t) => wrap('1', t),
|
|
13
|
+
};
|
|
14
|
+
export function renderTable(rows) {
|
|
15
|
+
const count = rows.reduce((max, row) => Math.max(max, row.length), 0);
|
|
16
|
+
const widths = Array.from({ length: count }, (_, i) => rows.reduce((max, row) => Math.max(max, displayWidth(row[i] ?? '')), 0));
|
|
17
|
+
return rows
|
|
18
|
+
.map((row) => widths
|
|
19
|
+
.map((width, i) => i === count - 1 ? (row[i] ?? '') : style.dim(padEnd(row[i] ?? '', width)))
|
|
20
|
+
.join(' '))
|
|
21
|
+
.join('\n');
|
|
22
|
+
}
|
|
23
|
+
export function displayWidth(text) {
|
|
24
|
+
let width = 0;
|
|
25
|
+
for (const ch of stripAnsi(text)) {
|
|
26
|
+
width += /[一-鿿-]/.test(ch) ? 2 : 1;
|
|
27
|
+
}
|
|
28
|
+
return width;
|
|
29
|
+
}
|
|
30
|
+
const ANSI = /\u001b\[[0-9;]*m/g;
|
|
31
|
+
function stripAnsi(text) {
|
|
32
|
+
return text.replace(ANSI, '');
|
|
33
|
+
}
|
|
34
|
+
function padEnd(text, width) {
|
|
35
|
+
const pad = width - displayWidth(text);
|
|
36
|
+
return pad > 0 ? text + ' '.repeat(pad) : text;
|
|
37
|
+
}
|
|
38
|
+
export function maskSecret(value) {
|
|
39
|
+
let result;
|
|
40
|
+
if (value.length <= 4) {
|
|
41
|
+
result = '*'.repeat(value.length);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result = `${value.slice(0, 4)}${'*'.repeat(8)} ${t('config.lengthSuffix', { n: value.length })}`;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { t } from "../i18n.js";
|
|
3
|
+
import { loadPresetRegistry } from "../config/presets.js";
|
|
4
|
+
import { loginCommand } from "./commands/login/index.js";
|
|
5
|
+
import { whoamiCommand } from "./commands/whoami.js";
|
|
6
|
+
import { logoutCommand } from "./commands/logout.js";
|
|
7
|
+
import { envAddCommand, envCurrentCommand, envDeleteCommand, envEnsureCommand, envListCommand, envSetCommand, envUseCommand, } from "./commands/env/index.js";
|
|
8
|
+
import { configGetCommand, configPathCommand } from "./commands/config.js";
|
|
9
|
+
import { registerCanvas } from "./commands/canvas/register.js";
|
|
10
|
+
import { runCommand } from "./run.js";
|
|
11
|
+
import { toolCallCommand, toolListCommand, toolSpecCommand } from "./commands/tool.js";
|
|
12
|
+
import { doctorCommand } from "./commands/doctor.js";
|
|
13
|
+
import { authStatusCommand } from "./commands/auth.js";
|
|
14
|
+
import { engineInstallCommand, engineUninstallCommand } from "./commands/engine.js";
|
|
15
|
+
import { updateCommand } from "./commands/update.js";
|
|
16
|
+
import { walletCommand } from "./commands/wallet.js";
|
|
17
|
+
import { skillListCommand, skillReadCommand } from "./commands/skill.js";
|
|
18
|
+
export const VERSION = '0.3.0';
|
|
19
|
+
export function buildProgram(deps, ctx, entry = 'seavideo', presetNames = []) {
|
|
20
|
+
const program = new Command();
|
|
21
|
+
program
|
|
22
|
+
.name(entry)
|
|
23
|
+
.description(t(`program.description.${entry}`))
|
|
24
|
+
.version(VERSION)
|
|
25
|
+
.option('--env <name>', t('program.envOption'));
|
|
26
|
+
registerIdentity(program, deps, ctx);
|
|
27
|
+
registerEnv(program, deps, ctx, presetNames);
|
|
28
|
+
registerConfig(program, deps, ctx);
|
|
29
|
+
registerCanvas(program, deps, ctx);
|
|
30
|
+
registerTool(program, deps, ctx);
|
|
31
|
+
registerSkill(program, deps, ctx);
|
|
32
|
+
program
|
|
33
|
+
.command('doctor')
|
|
34
|
+
.description(t('cmd.doctor'))
|
|
35
|
+
.action(async () => {
|
|
36
|
+
process.exitCode = await runCommand(() => doctorCommand(ctx()), deps);
|
|
37
|
+
});
|
|
38
|
+
const engine = program.command('engine').description(t('cmd.engine'));
|
|
39
|
+
engine
|
|
40
|
+
.command('install')
|
|
41
|
+
.description(t('cmd.engine.install'))
|
|
42
|
+
.option('--force', t('opt.engineForce'))
|
|
43
|
+
.action(async (options) => {
|
|
44
|
+
process.exitCode = await runCommand(() => engineInstallCommand(ctx(), options), deps);
|
|
45
|
+
});
|
|
46
|
+
engine
|
|
47
|
+
.command('uninstall')
|
|
48
|
+
.description(t('cmd.engine.uninstall'))
|
|
49
|
+
.action(async () => {
|
|
50
|
+
process.exitCode = await runCommand(() => engineUninstallCommand(ctx()), deps);
|
|
51
|
+
});
|
|
52
|
+
program
|
|
53
|
+
.command('wallet')
|
|
54
|
+
.description(t('cmd.wallet'))
|
|
55
|
+
.option('--json', t('opt.walletJson'))
|
|
56
|
+
.action(async (options) => {
|
|
57
|
+
process.exitCode = await runCommand(() => walletCommand(ctx(), options), deps);
|
|
58
|
+
});
|
|
59
|
+
program
|
|
60
|
+
.command('update')
|
|
61
|
+
.description(t('cmd.update'))
|
|
62
|
+
.option('--channel <name>', t('opt.updateChannel'))
|
|
63
|
+
.option('--to <target>', t('opt.updateVersion'))
|
|
64
|
+
.option('--registry <url>', t('opt.updateRegistry'))
|
|
65
|
+
.option('--dry-run', t('opt.updateDryRun'))
|
|
66
|
+
.option('--json', t('opt.json'))
|
|
67
|
+
.action(async (options) => {
|
|
68
|
+
process.exitCode = await runCommand(() => updateCommand(ctx(), options), deps);
|
|
69
|
+
});
|
|
70
|
+
return program;
|
|
71
|
+
}
|
|
72
|
+
function registerIdentity(program, deps, ctx) {
|
|
73
|
+
program
|
|
74
|
+
.command('login')
|
|
75
|
+
.description(t('cmd.login'))
|
|
76
|
+
.option('--flow-token <value>', t('opt.flowToken'))
|
|
77
|
+
.option('--oauth', t('opt.oauth'))
|
|
78
|
+
.action(async (options) => {
|
|
79
|
+
process.exitCode = await runCommand(() => loginCommand(ctx(), options), deps);
|
|
80
|
+
});
|
|
81
|
+
program
|
|
82
|
+
.command('whoami')
|
|
83
|
+
.description(t('cmd.whoami'))
|
|
84
|
+
.option('--json', t('opt.json'))
|
|
85
|
+
.action(async (options) => {
|
|
86
|
+
process.exitCode = await runCommand(() => whoamiCommand(ctx(), options), deps);
|
|
87
|
+
});
|
|
88
|
+
program
|
|
89
|
+
.command('logout')
|
|
90
|
+
.description(t('cmd.logout'))
|
|
91
|
+
.option('--all', t('opt.all'))
|
|
92
|
+
.option('--flow', t('opt.logoutFlow'))
|
|
93
|
+
.action(async (options) => {
|
|
94
|
+
process.exitCode = await runCommand(() => logoutCommand(ctx(), options), deps);
|
|
95
|
+
});
|
|
96
|
+
const auth = program.command('auth').description(t('cmd.auth'));
|
|
97
|
+
auth
|
|
98
|
+
.command('status')
|
|
99
|
+
.description(t('cmd.auth.status'))
|
|
100
|
+
.option('--json', t('opt.json'))
|
|
101
|
+
.action(async (options) => {
|
|
102
|
+
process.exitCode = await runCommand(() => authStatusCommand(ctx(), options), deps);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function presetHelp(names, env) {
|
|
106
|
+
let result;
|
|
107
|
+
if (names.length === 0) {
|
|
108
|
+
result = t('opt.presetGeneric', {}, env);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result = t('opt.presetAvailable', { names: names.join(' | ') }, env);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
export async function presetNamesFor(deps, paths) {
|
|
116
|
+
let names;
|
|
117
|
+
try {
|
|
118
|
+
const registry = await loadPresetRegistry(deps, paths);
|
|
119
|
+
names = Object.keys(registry.presets).sort();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
names = [];
|
|
123
|
+
}
|
|
124
|
+
return names;
|
|
125
|
+
}
|
|
126
|
+
function registerEnv(program, deps, ctx, presetNames) {
|
|
127
|
+
const env = program.command('env').description(t('cmd.env'));
|
|
128
|
+
addEnvInspect(env, deps, ctx);
|
|
129
|
+
addEnvCreate(env, deps, ctx, presetNames);
|
|
130
|
+
addEnvMutate(env, deps, ctx);
|
|
131
|
+
}
|
|
132
|
+
function addEnvInspect(env, deps, ctx) {
|
|
133
|
+
env
|
|
134
|
+
.command('list')
|
|
135
|
+
.description(t('cmd.env.list'))
|
|
136
|
+
.action(async () => {
|
|
137
|
+
process.exitCode = await runCommand(() => envListCommand(ctx()), deps);
|
|
138
|
+
});
|
|
139
|
+
env
|
|
140
|
+
.command('current')
|
|
141
|
+
.description(t('cmd.env.current'))
|
|
142
|
+
.action(async () => {
|
|
143
|
+
process.exitCode = await runCommand(() => envCurrentCommand(ctx()), deps);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function addEnvCreate(env, deps, ctx, presetNames) {
|
|
147
|
+
env
|
|
148
|
+
.command('add [name]')
|
|
149
|
+
.description(t('cmd.env.add'))
|
|
150
|
+
.option('--preset <name>', presetHelp(presetNames, deps.env))
|
|
151
|
+
.option('--platform <name>', t('opt.platform'))
|
|
152
|
+
.option('--seavideo-base-url <url>', t('opt.seavideoBaseUrl'))
|
|
153
|
+
.option('--flow-web-base-url <url>', t('opt.flowWebBaseUrl'))
|
|
154
|
+
.option('--flow-api-base-url <url>', t('opt.flowApiBaseUrl'))
|
|
155
|
+
.option('--ai-video-api-base-url <url>', t('opt.aiVideoApiBaseUrl'))
|
|
156
|
+
.option('--auth-issuer <url>', t('opt.authIssuer'))
|
|
157
|
+
.option('--auth-client-id <id>', t('opt.authClientId'))
|
|
158
|
+
.option('--use', t('opt.use'))
|
|
159
|
+
.action(async (name, options) => {
|
|
160
|
+
process.exitCode = await runCommand(() => envAddCommand(ctx(), name, options), deps);
|
|
161
|
+
});
|
|
162
|
+
env
|
|
163
|
+
.command('ensure [name]')
|
|
164
|
+
.description(t('cmd.env.ensure'))
|
|
165
|
+
.option('--preset <name>', presetHelp(presetNames, deps.env))
|
|
166
|
+
.option('--use', t('opt.use'))
|
|
167
|
+
.action(async (name, options) => {
|
|
168
|
+
process.exitCode = await runCommand(() => envEnsureCommand(ctx(), options, name), deps);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function addEnvMutate(env, deps, ctx) {
|
|
172
|
+
env
|
|
173
|
+
.command('set <name>')
|
|
174
|
+
.description(t('cmd.env.set'))
|
|
175
|
+
.option('--seavideo-base-url <url>', t('opt.seavideoBaseUrl'))
|
|
176
|
+
.option('--flow-web-base-url <url>', t('opt.flowWebBaseUrl'))
|
|
177
|
+
.option('--flow-api-base-url <url>', t('opt.flowApiBaseUrl'))
|
|
178
|
+
.option('--ai-video-api-base-url <url>', t('opt.aiVideoApiBaseUrl'))
|
|
179
|
+
.option('--auth-issuer <url>', t('opt.authIssuer'))
|
|
180
|
+
.option('--auth-client-id <id>', t('opt.authClientId'))
|
|
181
|
+
.action(async (name, options) => {
|
|
182
|
+
process.exitCode = await runCommand(() => envSetCommand(ctx(), name, options), deps);
|
|
183
|
+
});
|
|
184
|
+
env
|
|
185
|
+
.command('use <name>')
|
|
186
|
+
.description(t('cmd.env.use'))
|
|
187
|
+
.action(async (name) => {
|
|
188
|
+
process.exitCode = await runCommand(() => envUseCommand(ctx(), name), deps);
|
|
189
|
+
});
|
|
190
|
+
env
|
|
191
|
+
.command('delete <name>')
|
|
192
|
+
.description(t('cmd.env.delete'))
|
|
193
|
+
.action(async (name) => {
|
|
194
|
+
process.exitCode = await runCommand(() => envDeleteCommand(ctx(), name), deps);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function registerConfig(program, deps, ctx) {
|
|
198
|
+
const config = program.command('config').description(t('cmd.config'));
|
|
199
|
+
config
|
|
200
|
+
.command('path')
|
|
201
|
+
.description(t('cmd.config.path'))
|
|
202
|
+
.action(async () => {
|
|
203
|
+
process.exitCode = await runCommand(() => configPathCommand(ctx()), deps);
|
|
204
|
+
});
|
|
205
|
+
config
|
|
206
|
+
.command('get')
|
|
207
|
+
.description(t('cmd.config.get'))
|
|
208
|
+
.option('--json', t('opt.json'))
|
|
209
|
+
.action(async (options) => {
|
|
210
|
+
process.exitCode = await runCommand(() => configGetCommand(ctx(), options), deps);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function registerTool(program, deps, ctx) {
|
|
214
|
+
const tool = program.command('tool').description(t('cmd.tool'));
|
|
215
|
+
tool
|
|
216
|
+
.command('list')
|
|
217
|
+
.description(t('cmd.tool.list'))
|
|
218
|
+
.option('--json', t('opt.json'))
|
|
219
|
+
.action(async (options) => {
|
|
220
|
+
process.exitCode = await runCommand(() => toolListCommand(ctx(), options), deps);
|
|
221
|
+
});
|
|
222
|
+
tool
|
|
223
|
+
.command('spec [names...]')
|
|
224
|
+
.description(t('cmd.tool.spec'))
|
|
225
|
+
.option('--json', t('opt.json'))
|
|
226
|
+
.action(async (names, options) => {
|
|
227
|
+
process.exitCode = await runCommand(() => toolSpecCommand(ctx(), names, options), deps);
|
|
228
|
+
});
|
|
229
|
+
tool
|
|
230
|
+
.command('call <name>')
|
|
231
|
+
.description(t('cmd.tool.call'))
|
|
232
|
+
.option('--args <json>', t('opt.toolArgs'))
|
|
233
|
+
.option('--args-file <path>', t('opt.toolArgsFile'))
|
|
234
|
+
.option('--timeout <seconds>', t('opt.toolTimeout'))
|
|
235
|
+
.option('--json', t('opt.json'))
|
|
236
|
+
.action(async (name, options) => {
|
|
237
|
+
process.exitCode = await runCommand(() => toolCallCommand(ctx(), name, options), deps);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function registerSkill(program, deps, ctx) {
|
|
241
|
+
const skill = program.command('skill').description(t('cmd.skill'));
|
|
242
|
+
skill
|
|
243
|
+
.command('list')
|
|
244
|
+
.description(t('cmd.skill.list'))
|
|
245
|
+
.option('--keyword <text...>', t('opt.keyword'))
|
|
246
|
+
.option('--page <n>', t('opt.page'))
|
|
247
|
+
.option('--page-size <n>', t('opt.pageSize'))
|
|
248
|
+
.option('--json', t('opt.json'))
|
|
249
|
+
.action(async (options) => {
|
|
250
|
+
process.exitCode = await runCommand(() => skillListCommand(ctx(), options), deps);
|
|
251
|
+
});
|
|
252
|
+
skill
|
|
253
|
+
.command('read <ids...>')
|
|
254
|
+
.description(t('cmd.skill.read'))
|
|
255
|
+
.option('--by <type>', t('opt.skillBy'))
|
|
256
|
+
.option('--file <path...>', t('opt.skillFile'))
|
|
257
|
+
.option('--json', t('opt.json'))
|
|
258
|
+
.action(async (ids, options) => {
|
|
259
|
+
process.exitCode = await runCommand(() => skillReadCommand(ctx(), ids, options), deps);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CliError } from "../errors.js";
|
|
2
|
+
import { resolveEnvName } from "../config/resolve.js";
|
|
3
|
+
import { connectPuppeteerBrowser, puppeteerConnect } from "../canvas/puppeteer.js";
|
|
4
|
+
import { readSessionRecord, sessionFingerprint, touchSessionRecord, } from "../canvas/session-record.js";
|
|
5
|
+
import { sessionAlive } from "../canvas/daemon.js";
|
|
6
|
+
import { resolveFlowCredential } from "./credential.js";
|
|
7
|
+
import { daemonDepsOf } from "../canvas/lifecycle.js";
|
|
8
|
+
import { style } from "./output.js";
|
|
9
|
+
import { t } from "../i18n.js";
|
|
10
|
+
export async function connectSession(ctx) {
|
|
11
|
+
const { deps } = ctx;
|
|
12
|
+
const env = await resolveEnvName(ctx.envFlag, deps, ctx.paths);
|
|
13
|
+
const sessionFile = ctx.paths.canvasSessionFile(env);
|
|
14
|
+
const record = await readSessionRecord(sessionFile, deps);
|
|
15
|
+
if (record === null) {
|
|
16
|
+
throw new CliError('config', t('tool.noSession', {}, deps.env), {
|
|
17
|
+
detail: t('tool.noSessionDetail', {}, deps.env),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const loaded = await ctx.store.read(env);
|
|
21
|
+
let config = loaded;
|
|
22
|
+
if (loaded.flowCredential !== null) {
|
|
23
|
+
const resolved = await resolveFlowCredential(ctx, loaded);
|
|
24
|
+
if (resolved.renewed) {
|
|
25
|
+
throw new CliError('config', t('tool.renewed', {}, deps.env), {
|
|
26
|
+
detail: t('tool.renewedDetail', { id: record.id }, deps.env),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
config = resolved.config;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
}
|
|
33
|
+
const expected = sessionFingerprint({
|
|
34
|
+
env,
|
|
35
|
+
id: record.id,
|
|
36
|
+
flowWebBaseUrl: config.flowWebBaseUrl,
|
|
37
|
+
flowCredential: config.flowCredential?.value ?? '',
|
|
38
|
+
});
|
|
39
|
+
if (expected !== record.fingerprint) {
|
|
40
|
+
throw new CliError('config', t('tool.stale', { id: record.id }, deps.env), {
|
|
41
|
+
detail: t('tool.staleDetail', {}, deps.env),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!(await sessionAlive(record, daemonDepsOf(ctx)))) {
|
|
45
|
+
throw new CliError('config', t('tool.sessionDead', { id: record.id }, deps.env), {
|
|
46
|
+
detail: t('tool.sessionDeadDetail', {}, deps.env),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const browser = connectPuppeteerBrowser({
|
|
50
|
+
connect: puppeteerConnect,
|
|
51
|
+
port: record.port,
|
|
52
|
+
envMap: deps.env,
|
|
53
|
+
});
|
|
54
|
+
return { browser, id: record.id, sessionFile };
|
|
55
|
+
}
|
|
56
|
+
export async function touchSession(ctx, opened) {
|
|
57
|
+
try {
|
|
58
|
+
await touchSessionRecord(opened.sessionFile, ctx.deps.clock().toISOString(), ctx.deps);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
ctx.deps.stderr(`${style.warn('!')} ${t('tool.touchFailed', {}, ctx.deps.env)}\n`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function normalizeBaseUrl(value) {
|
|
2
|
+
let parsed;
|
|
3
|
+
try {
|
|
4
|
+
parsed = new URL(value);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
parsed = null;
|
|
8
|
+
}
|
|
9
|
+
let result;
|
|
10
|
+
if (parsed === null) {
|
|
11
|
+
result = { ok: false, problem: 'invalid' };
|
|
12
|
+
}
|
|
13
|
+
else if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
14
|
+
result = { ok: false, problem: 'protocol' };
|
|
15
|
+
}
|
|
16
|
+
else if (parsed.username !== '' || parsed.password !== '') {
|
|
17
|
+
result = { ok: false, problem: 'credentials' };
|
|
18
|
+
}
|
|
19
|
+
else if (/[?#]/.test(value)) {
|
|
20
|
+
result = { ok: false, problem: 'query' };
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
result = { ok: true, url: parsed.href.replace(/\/+$/, '') };
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|