@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.
Files changed (110) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +528 -2
  3. package/dist/bin/seavideo.js +11 -0
  4. package/dist/src/atomic-write.js +14 -0
  5. package/dist/src/canvas/api.js +172 -0
  6. package/dist/src/canvas/browser.js +40 -0
  7. package/dist/src/canvas/chrome-binary.js +109 -0
  8. package/dist/src/canvas/daemon.js +264 -0
  9. package/dist/src/canvas/engine-install.js +46 -0
  10. package/dist/src/canvas/engine-log.js +9 -0
  11. package/dist/src/canvas/engine.js +99 -0
  12. package/dist/src/canvas/entry.js +16 -0
  13. package/dist/src/canvas/env-lock.js +164 -0
  14. package/dist/src/canvas/launch.js +97 -0
  15. package/dist/src/canvas/lifecycle.js +65 -0
  16. package/dist/src/canvas/names.js +61 -0
  17. package/dist/src/canvas/params.js +38 -0
  18. package/dist/src/canvas/puppeteer.js +153 -0
  19. package/dist/src/canvas/screenshot.js +23 -0
  20. package/dist/src/canvas/session-record.js +77 -0
  21. package/dist/src/canvas/team.js +97 -0
  22. package/dist/src/canvas/tool-args.js +47 -0
  23. package/dist/src/canvas/tool-session.js +165 -0
  24. package/dist/src/canvas/tool-specs.js +54 -0
  25. package/dist/src/canvas/url.js +38 -0
  26. package/dist/src/cli/args.js +16 -0
  27. package/dist/src/cli/commands/auth.js +51 -0
  28. package/dist/src/cli/commands/canvas/common.js +31 -0
  29. package/dist/src/cli/commands/canvas/engine-choice.js +41 -0
  30. package/dist/src/cli/commands/canvas/index.js +5 -0
  31. package/dist/src/cli/commands/canvas/item.js +233 -0
  32. package/dist/src/cli/commands/canvas/list.js +168 -0
  33. package/dist/src/cli/commands/canvas/register.js +106 -0
  34. package/dist/src/cli/commands/canvas/render.js +229 -0
  35. package/dist/src/cli/commands/canvas/screenshot.js +52 -0
  36. package/dist/src/cli/commands/canvas/session.js +249 -0
  37. package/dist/src/cli/commands/canvas/teams.js +142 -0
  38. package/dist/src/cli/commands/config.js +74 -0
  39. package/dist/src/cli/commands/doctor.js +261 -0
  40. package/dist/src/cli/commands/engine.js +96 -0
  41. package/dist/src/cli/commands/env/create.js +160 -0
  42. package/dist/src/cli/commands/env/fields.js +26 -0
  43. package/dist/src/cli/commands/env/index.js +4 -0
  44. package/dist/src/cli/commands/env/list.js +44 -0
  45. package/dist/src/cli/commands/env/mutate.js +118 -0
  46. package/dist/src/cli/commands/login/flow-token.js +41 -0
  47. package/dist/src/cli/commands/login/index.js +12 -0
  48. package/dist/src/cli/commands/login/oauth.js +69 -0
  49. package/dist/src/cli/commands/login/save.js +26 -0
  50. package/dist/src/cli/commands/logout.js +92 -0
  51. package/dist/src/cli/commands/skill.js +185 -0
  52. package/dist/src/cli/commands/tool.js +279 -0
  53. package/dist/src/cli/commands/update.js +117 -0
  54. package/dist/src/cli/commands/wallet.js +69 -0
  55. package/dist/src/cli/commands/whoami.js +147 -0
  56. package/dist/src/cli/context.js +41 -0
  57. package/dist/src/cli/credential.js +93 -0
  58. package/dist/src/cli/elapsed.js +25 -0
  59. package/dist/src/cli/failure-screenshot.js +24 -0
  60. package/dist/src/cli/flags.js +1 -0
  61. package/dist/src/cli/hints.js +7 -0
  62. package/dist/src/cli/main.js +44 -0
  63. package/dist/src/cli/output-error.js +23 -0
  64. package/dist/src/cli/output.js +47 -0
  65. package/dist/src/cli/program.js +261 -0
  66. package/dist/src/cli/run.js +11 -0
  67. package/dist/src/cli/session.js +63 -0
  68. package/dist/src/config/base-url.js +26 -0
  69. package/dist/src/config/credential-vault.js +115 -0
  70. package/dist/src/config/dotenv.js +59 -0
  71. package/dist/src/config/envname.js +41 -0
  72. package/dist/src/config/paths.js +22 -0
  73. package/dist/src/config/preset-schema.js +67 -0
  74. package/dist/src/config/presets.js +132 -0
  75. package/dist/src/config/resolve.js +41 -0
  76. package/dist/src/config/secret-key.js +63 -0
  77. package/dist/src/config/store-schema.js +143 -0
  78. package/dist/src/config/store.js +273 -0
  79. package/dist/src/config/vault-crypto.js +44 -0
  80. package/dist/src/deps.js +191 -0
  81. package/dist/src/deps.types.js +1 -0
  82. package/dist/src/errors.js +24 -0
  83. package/dist/src/fs-retry.js +34 -0
  84. package/dist/src/i18n.js +1214 -0
  85. package/dist/src/loopback.js +134 -0
  86. package/dist/src/sdk/auth.js +20 -0
  87. package/dist/src/sdk/credential-expiry.js +67 -0
  88. package/dist/src/sdk/discovery.js +90 -0
  89. package/dist/src/sdk/http.js +98 -0
  90. package/dist/src/sdk/identity.js +17 -0
  91. package/dist/src/sdk/jwks.js +119 -0
  92. package/dist/src/sdk/oauth-protocol.js +226 -0
  93. package/dist/src/sdk/oauth.js +179 -0
  94. package/dist/src/sdk/provider/cn.js +34 -0
  95. package/dist/src/sdk/provider/index.js +16 -0
  96. package/dist/src/sdk/provider/oversea.js +41 -0
  97. package/dist/src/sdk/provider/types.js +1 -0
  98. package/dist/src/sdk/refresh.js +66 -0
  99. package/dist/src/semver.js +89 -0
  100. package/dist/src/skill/api.js +176 -0
  101. package/dist/src/text.js +3 -0
  102. package/dist/src/types.js +1 -0
  103. package/dist/src/update/check-cache.js +56 -0
  104. package/dist/src/update/install-layout.js +79 -0
  105. package/dist/src/update/notify.js +15 -0
  106. package/dist/src/update/npm-install.js +64 -0
  107. package/dist/src/update/passive.js +53 -0
  108. package/dist/src/update/registry.js +59 -0
  109. package/dist/src/wallet/api.js +107 -0
  110. package/package.json +67 -4
@@ -0,0 +1,74 @@
1
+ import { resolveEnvName } from "../../config/resolve.js";
2
+ import { maskSecret, renderTable, style } from "../output.js";
3
+ import { loadEnv } from "../context.js";
4
+ import { t } from "../../i18n.js";
5
+ export async function configPathCommand(ctx) {
6
+ const env = await resolveEnvName(ctx.envFlag, ctx.deps, ctx.paths);
7
+ ctx.deps.stdout(`${ctx.paths.root}\n`);
8
+ ctx.deps.stdout(`${ctx.paths.currentFile}\n`);
9
+ ctx.deps.stdout(`${ctx.paths.configFile(env)}\n`);
10
+ ctx.deps.stdout(`${ctx.paths.userFile(env)}\n`);
11
+ return 0;
12
+ }
13
+ export async function configGetCommand(ctx, options) {
14
+ const config = await loadEnv(ctx);
15
+ const credential = config.credential;
16
+ const flowCredential = config.flowCredential;
17
+ if (options.json === true) {
18
+ ctx.deps.stdout(`${JSON.stringify({
19
+ env: config.env,
20
+ platform: config.platform,
21
+ seavideoBaseUrl: config.seavideoBaseUrl,
22
+ flowWebBaseUrl: config.flowWebBaseUrl,
23
+ flowApiBaseUrl: config.flowApiBaseUrl,
24
+ aiVideoApiBaseUrl: config.aiVideoApiBaseUrl,
25
+ authIssuer: config.authIssuer,
26
+ authClientId: config.authClientId,
27
+ credential: credential === null
28
+ ? null
29
+ : { masked: maskSecret(credential.value), source: credential.source },
30
+ flowCredential: flowCredential === null
31
+ ? null
32
+ : { masked: maskSecret(flowCredential.value), source: flowCredential.source },
33
+ }, null, 2)}\n`);
34
+ }
35
+ else {
36
+ ctx.deps.stdout(`${renderTable([
37
+ [t('config.label.env', {}, ctx.deps.env), config.env],
38
+ [t('config.label.platform', {}, ctx.deps.env), config.platform],
39
+ [t('config.label.server', {}, ctx.deps.env), config.seavideoBaseUrl],
40
+ [t('config.label.flowWebBaseUrl', {}, ctx.deps.env), config.flowWebBaseUrl],
41
+ [t('config.label.flowApiBaseUrl', {}, ctx.deps.env), config.flowApiBaseUrl],
42
+ [
43
+ t('config.label.credential', {}, ctx.deps.env),
44
+ credential === null
45
+ ? style.dim(t('config.notConfigured', {}, ctx.deps.env))
46
+ : maskSecret(credential.value),
47
+ ],
48
+ [
49
+ t('config.label.flowCredential', {}, ctx.deps.env),
50
+ flowCredential === null
51
+ ? style.dim(t('config.notConfigured', {}, ctx.deps.env))
52
+ : maskSecret(flowCredential.value),
53
+ ],
54
+ [
55
+ t('config.label.authIssuer', {}, ctx.deps.env),
56
+ config.authIssuer === null
57
+ ? style.dim(t('config.notConfigured', {}, ctx.deps.env))
58
+ : config.authIssuer,
59
+ ],
60
+ [
61
+ t('config.label.authClientId', {}, ctx.deps.env),
62
+ config.authClientId === null
63
+ ? style.dim(t('config.notConfigured', {}, ctx.deps.env))
64
+ : config.authClientId,
65
+ ],
66
+ [
67
+ t('config.label.source', {}, ctx.deps.env),
68
+ credential === null ? style.dim('-') : credential.source,
69
+ ],
70
+ [t('config.label.file', {}, ctx.deps.env), ctx.paths.configFile(config.env)],
71
+ ])}\n`);
72
+ }
73
+ return 0;
74
+ }
@@ -0,0 +1,261 @@
1
+ import { resolveEnvName } from "../../config/resolve.js";
2
+ import { fetchProfile } from "../../sdk/auth.js";
3
+ import { fetchIdentity } from "../../sdk/identity.js";
4
+ import { getProvider } from "../../sdk/provider/index.js";
5
+ import { detectCanvasEngine } from "../../canvas/engine.js";
6
+ import { checkDisabled, readCheckCache } from "../../update/check-cache.js";
7
+ import { DEFAULT_CHANNEL, PACKAGE_NAME, fetchVersionInfo } from "../../update/registry.js";
8
+ import { compareVersions } from "../../semver.js";
9
+ import { VERSION } from "../program.js";
10
+ import { CliError } from "../../errors.js";
11
+ import { sanitizeText } from "../../text.js";
12
+ import { style } from "../output.js";
13
+ import {} from "../context.js";
14
+ import { t } from "../../i18n.js";
15
+ export function detailOf(err) {
16
+ let result;
17
+ if (!(err instanceof CliError)) {
18
+ result = String(err);
19
+ }
20
+ else {
21
+ result = err.detail === undefined ? err.message : `${err.message} · ${err.detail}`;
22
+ }
23
+ return result;
24
+ }
25
+ export async function doctorCommand(ctx) {
26
+ const { deps } = ctx;
27
+ const checks = [];
28
+ const env = await resolveEnvCheck(ctx, checks);
29
+ const versionCheck = await cliVersionCheck(ctx);
30
+ checks.push(versionCheck);
31
+ let result;
32
+ if (env === null) {
33
+ result = report(ctx, checks);
34
+ }
35
+ else {
36
+ const config = await readConfigCheck(ctx, checks, env);
37
+ if (config === null) {
38
+ result = report(ctx, checks);
39
+ }
40
+ else {
41
+ await userSnapshotCheck(ctx, checks, env);
42
+ const flowCredential = config.flowCredential;
43
+ if (flowCredential !== null) {
44
+ result = await reportCanvasCredential(ctx, config, flowCredential, checks);
45
+ }
46
+ else {
47
+ const credential = config.credential;
48
+ if (credential === null) {
49
+ checks.push({
50
+ name: t('doctor.credential', {}, deps.env),
51
+ ok: false,
52
+ detail: t('doctor.credentialMissing', {}, deps.env),
53
+ });
54
+ result = report(ctx, checks);
55
+ }
56
+ else {
57
+ result = await reportAccountCredential(ctx, config, credential, checks);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return result;
63
+ }
64
+ async function resolveEnvCheck(ctx, checks) {
65
+ const { deps } = ctx;
66
+ let result;
67
+ try {
68
+ const env = await resolveEnvName(ctx.envFlag, deps, ctx.paths);
69
+ checks.push({ name: t('doctor.envResolve', {}, deps.env), ok: true, detail: env });
70
+ result = env;
71
+ }
72
+ catch (err) {
73
+ checks.push({
74
+ name: t('doctor.envResolve', {}, deps.env),
75
+ ok: false,
76
+ detail: detailOf(err),
77
+ });
78
+ result = null;
79
+ }
80
+ return result;
81
+ }
82
+ async function readConfigCheck(ctx, checks, env) {
83
+ const { deps } = ctx;
84
+ let result;
85
+ try {
86
+ const config = await ctx.store.read(env);
87
+ checks.push({
88
+ name: t('doctor.configRead', {}, deps.env),
89
+ ok: true,
90
+ detail: ctx.paths.configFile(env),
91
+ });
92
+ result = config;
93
+ }
94
+ catch (err) {
95
+ checks.push({
96
+ name: t('doctor.configRead', {}, deps.env),
97
+ ok: false,
98
+ detail: detailOf(err),
99
+ });
100
+ result = null;
101
+ }
102
+ return result;
103
+ }
104
+ async function userSnapshotCheck(ctx, checks, env) {
105
+ const { deps } = ctx;
106
+ try {
107
+ const cachedUser = await ctx.store.readUser(env);
108
+ checks.push({
109
+ name: t('doctor.userSnapshot', {}, deps.env),
110
+ ok: true,
111
+ detail: cachedUser === null
112
+ ? t('doctor.snapshotEmpty', {}, deps.env)
113
+ : t('doctor.snapshotCached', {}, deps.env),
114
+ });
115
+ }
116
+ catch (err) {
117
+ checks.push({ name: t('doctor.userSnapshot', {}, deps.env), ok: false, detail: detailOf(err) });
118
+ }
119
+ }
120
+ async function reportAccountCredential(ctx, config, credential, checks) {
121
+ const { deps } = ctx;
122
+ checks.push(credentialCheck(credential, deps.env));
123
+ const provider = getProvider(config.platform);
124
+ checks.push({
125
+ name: t('doctor.credentialShape', {}, deps.env),
126
+ ok: true,
127
+ detail: provider.looksLike(credential.value)
128
+ ? t('doctor.shapeMatch', { platform: config.platform }, deps.env)
129
+ : t('doctor.shapeMismatch', { platform: config.platform }, deps.env),
130
+ });
131
+ checks.push(await canvasEngineCheck(deps));
132
+ try {
133
+ const profile = await fetchProfile(provider, credential, {
134
+ fetch: deps.fetch,
135
+ env: deps.env,
136
+ baseUrl: config.seavideoBaseUrl,
137
+ });
138
+ checks.push({
139
+ name: t('doctor.serverConnectivity', {}, deps.env),
140
+ ok: true,
141
+ detail: `${config.seavideoBaseUrl}`,
142
+ });
143
+ checks.push({
144
+ name: t('doctor.credentialValidity', {}, deps.env),
145
+ ok: true,
146
+ detail: `${sanitizeText(profile.displayName)} (${sanitizeText(profile.id)})`,
147
+ });
148
+ }
149
+ catch (err) {
150
+ checks.push({
151
+ name: t('doctor.serverConnectivity', {}, deps.env),
152
+ ok: false,
153
+ detail: detailOf(err),
154
+ });
155
+ }
156
+ return report(ctx, checks);
157
+ }
158
+ async function reportCanvasCredential(ctx, config, credential, checks) {
159
+ const { deps } = ctx;
160
+ checks.push(credentialCheck(credential, deps.env));
161
+ checks.push({
162
+ name: t('doctor.credentialShape', {}, deps.env),
163
+ ok: true,
164
+ detail: t('doctor.flowShape', { segments: credential.value.split('.').length }, deps.env),
165
+ });
166
+ checks.push(await canvasEngineCheck(deps));
167
+ try {
168
+ const identity = await fetchIdentity({ fetch: deps.fetch, env: deps.env, baseUrl: config.flowApiBaseUrl }, credential.value);
169
+ checks.push({
170
+ name: t('doctor.serverConnectivity', {}, deps.env),
171
+ ok: true,
172
+ detail: config.flowApiBaseUrl,
173
+ });
174
+ checks.push({
175
+ name: t('doctor.credentialValidity', {}, deps.env),
176
+ ok: true,
177
+ detail: sanitizeText(identity.userId),
178
+ });
179
+ }
180
+ catch (err) {
181
+ checks.push({
182
+ name: t('doctor.serverConnectivity', {}, deps.env),
183
+ ok: false,
184
+ detail: detailOf(err),
185
+ });
186
+ }
187
+ return report(ctx, checks);
188
+ }
189
+ function credentialCheck(credential, envMap) {
190
+ return {
191
+ name: t('doctor.credential', {}, envMap),
192
+ ok: true,
193
+ detail: t('doctor.credentialDetail', { source: credential.source, length: credential.value.length }, envMap),
194
+ };
195
+ }
196
+ export async function cliVersionCheck(ctx) {
197
+ const { deps } = ctx;
198
+ const name = t('doctor.cliVersion', {}, deps.env);
199
+ let result;
200
+ if (checkDisabled(deps.env)) {
201
+ result = { name, ok: true, detail: t('doctor.versionCheckDisabled', {}, deps.env) };
202
+ }
203
+ else {
204
+ const cache = await readCheckCache(deps.fs, ctx.paths.versionCheckFile);
205
+ result = { name, ok: true, detail: await versionDetail(deps, cache) };
206
+ }
207
+ return result;
208
+ }
209
+ export async function versionDetail(deps, cache) {
210
+ let latest = null;
211
+ let stale = false;
212
+ try {
213
+ const info = await fetchVersionInfo({ fetch: deps.fetch, env: deps.env }, PACKAGE_NAME, VERSION, cache?.channel ?? DEFAULT_CHANNEL);
214
+ latest = info.latest;
215
+ }
216
+ catch {
217
+ latest = cache?.latest ?? null;
218
+ stale = true;
219
+ }
220
+ return describeVersion(latest, stale, deps.env);
221
+ }
222
+ export function describeVersion(latest, stale, envMap) {
223
+ let detail;
224
+ if (latest === null) {
225
+ detail = t('doctor.versionUnknown', { reason: t('doctor.versionNotChecked', {}, envMap) }, envMap);
226
+ }
227
+ else if (compareVersions(latest, VERSION) === 1) {
228
+ detail = t('doctor.versionOutdated', { current: VERSION, latest }, envMap);
229
+ }
230
+ else if (stale) {
231
+ detail = t('doctor.versionReadyStale', { version: VERSION, latest }, envMap);
232
+ }
233
+ else {
234
+ detail = t('doctor.versionReady', { version: VERSION }, envMap);
235
+ }
236
+ return detail;
237
+ }
238
+ async function canvasEngineCheck(deps) {
239
+ const engine = await detectCanvasEngine(deps);
240
+ return {
241
+ name: t('doctor.canvasEngine', {}, deps.env),
242
+ ok: engine.found,
243
+ detail: engine.found
244
+ ? engine.version === null
245
+ ? t('doctor.engineReadyNoVersion', {}, deps.env)
246
+ : t('doctor.engineReady', { version: engine.version }, deps.env)
247
+ : `${t('doctor.engineMissing', {}, deps.env)} · ${t('doctor.engineInstallHint', {}, deps.env)}`,
248
+ };
249
+ }
250
+ function report(ctx, checks) {
251
+ const { deps } = ctx;
252
+ const failed = checks.filter((c) => !c.ok).length;
253
+ for (const c of checks) {
254
+ const mark = c.ok ? style.ok('✓') : style.fail('✗');
255
+ ctx.deps.stdout(`${mark} ${c.name} ${style.dim(c.detail)}\n`);
256
+ }
257
+ ctx.deps.stdout(failed === 0
258
+ ? `\n${style.ok(t('doctor.allPassed', {}, deps.env))}\n`
259
+ : `\n${style.fail(t('doctor.someFailed', { count: failed }, deps.env))}\n`);
260
+ return failed === 0 ? 0 : 1;
261
+ }
@@ -0,0 +1,96 @@
1
+ import { CliError, errorMessage } from "../../errors.js";
2
+ import { detectCanvasEngine, ENGINE_PATH_ENV, engineInstallDir } from "../../canvas/engine.js";
3
+ import { downloadCanvasEngine } from "../../canvas/engine-install.js";
4
+ import { withRetry } from "../../fs-retry.js";
5
+ import { t } from "../../i18n.js";
6
+ import { style } from "../output.js";
7
+ export async function engineInstallCommand(ctx, options = {}) {
8
+ const { deps } = ctx;
9
+ const existing = await detectCanvasEngine(deps);
10
+ let code;
11
+ if (existing.found && options.force !== true) {
12
+ deps.stdout(`${style.ok(t('engine.alreadyInstalled', { version: existing.version ?? '-' }, deps.env))}\n`);
13
+ deps.stdout(`${style.dim(t('engine.location', { path: existing.path }, deps.env))}\n`);
14
+ code = 0;
15
+ }
16
+ else {
17
+ code = await installMissingEngine(ctx);
18
+ }
19
+ return code;
20
+ }
21
+ async function installMissingEngine(ctx) {
22
+ const { deps } = ctx;
23
+ const result = await downloadCanvasEngine({
24
+ homeDir: deps.homeDir,
25
+ platform: deps.platform,
26
+ arch: deps.arch,
27
+ env: deps.env,
28
+ stderr: deps.stderr,
29
+ download: deps.downloadEngine,
30
+ });
31
+ let code;
32
+ if (result.ok) {
33
+ deps.stdout(`${style.ok(t('engine.installed', { version: result.version }, deps.env))}\n`);
34
+ deps.stdout(`${style.dim(t('engine.location', { path: result.path }, deps.env))}\n`);
35
+ reportOverrideIfAny(ctx, result.path);
36
+ code = 0;
37
+ }
38
+ else {
39
+ deps.stderr(`${style.fail(t('engine.installFailed', { message: result.message }, deps.env))}\n`);
40
+ code = 1;
41
+ }
42
+ return code;
43
+ }
44
+ function reportOverrideIfAny(ctx, installedPath) {
45
+ const override = ctx.deps.env[ENGINE_PATH_ENV];
46
+ if (override === undefined || override === '' || override === installedPath)
47
+ return;
48
+ ctx.deps.stderr(`${style.dim(t('engine.overrideInEffect', { env: ENGINE_PATH_ENV }, ctx.deps.env))}\n`);
49
+ }
50
+ export async function engineUninstallCommand(ctx) {
51
+ const { deps } = ctx;
52
+ const override = deps.env[ENGINE_PATH_ENV];
53
+ if (override !== undefined && override !== '') {
54
+ throw new CliError('config', t('engine.overrideBlocksUninstall', {}, deps.env), {
55
+ detail: t('engine.overrideBlocksUninstallDetail', { env: ENGINE_PATH_ENV }, deps.env),
56
+ });
57
+ }
58
+ const existing = await detectCanvasEngine(deps);
59
+ let code;
60
+ if (!existing.found) {
61
+ deps.stdout(`${style.dim(t('engine.notInstalled', {}, deps.env))}\n`);
62
+ code = 0;
63
+ }
64
+ else {
65
+ const dir = engineInstallDir(existing.path);
66
+ const removed = await removeEngineDir(ctx, dir);
67
+ if (removed) {
68
+ const version = existing.version;
69
+ deps.stdout(`${style.ok(t('engine.removed', { version }, deps.env))}\n`);
70
+ deps.stdout(`${style.dim(t('engine.removedLocation', { path: dir }, deps.env))}\n`);
71
+ const remaining = await detectCanvasEngine(deps);
72
+ if (remaining.found) {
73
+ deps.stdout(`${style.dim(t('engine.otherVersionsKept', { version: remaining.version }, deps.env))}\n`);
74
+ }
75
+ else {
76
+ }
77
+ code = 0;
78
+ }
79
+ else {
80
+ code = 1;
81
+ }
82
+ }
83
+ return code;
84
+ }
85
+ async function removeEngineDir(ctx, dir) {
86
+ let ok;
87
+ try {
88
+ await withRetry(ctx.deps, () => ctx.deps.fs.rm(dir, { recursive: true, force: true }));
89
+ ok = true;
90
+ }
91
+ catch (err) {
92
+ ctx.deps.stderr(`${style.fail(t('engine.uninstallFailed', { message: errorMessage(err) }, ctx.deps.env))}\n`);
93
+ ok = false;
94
+ }
95
+ return ok;
96
+ }
@@ -0,0 +1,160 @@
1
+ import { CliError } from "../../../errors.js";
2
+ import { style } from "../../output.js";
3
+ import { parsePlatform, setCurrentEnv } from "../../context.js";
4
+ import { validateEnvName } from "../../../config/envname.js";
5
+ import { t } from "../../../i18n.js";
6
+ import { parseIssuer } from "../../../sdk/oauth.js";
7
+ import { loadPresetRegistry, lookupPreset, } from "../../../config/presets.js";
8
+ import { requireAuthClientId, resolveBaseUrl } from "./fields.js";
9
+ const SOURCE_LABEL = {
10
+ builtin: 'env.list.source.builtin',
11
+ 'user-file': 'env.list.source.user-file',
12
+ 'project-file': 'env.list.source.project-file',
13
+ 'env-vars': 'env.list.source.env-vars',
14
+ };
15
+ export function resolveEnvAdd(name, options, registry, env = process.env) {
16
+ let result;
17
+ if (options.preset !== undefined) {
18
+ if (options.platform !== undefined ||
19
+ options.seavideoBaseUrl !== undefined ||
20
+ options.flowWebBaseUrl !== undefined ||
21
+ options.flowApiBaseUrl !== undefined ||
22
+ options.aiVideoApiBaseUrl !== undefined ||
23
+ options.authIssuer !== undefined ||
24
+ options.authClientId !== undefined) {
25
+ throw new CliError('usage', t('env.add.presetConflict', {}, env), {
26
+ detail: t('env.add.presetConflictDetail', {}, env),
27
+ });
28
+ }
29
+ const { preset } = lookupPreset(registry, options.preset, env);
30
+ result = {
31
+ env: validateEnvName(name ?? options.preset, env),
32
+ platform: preset.platform,
33
+ seavideoBaseUrl: preset.seavideoBaseUrl,
34
+ flowWebBaseUrl: preset.flowWebBaseUrl,
35
+ flowApiBaseUrl: preset.flowApiBaseUrl,
36
+ aiVideoApiBaseUrl: preset.aiVideoApiBaseUrl,
37
+ authIssuer: preset.authIssuer,
38
+ authClientId: preset.authClientId,
39
+ };
40
+ }
41
+ else {
42
+ if (name === undefined) {
43
+ throw new CliError('usage', t('env.add.missingName', {}, env), {
44
+ detail: missingNameDetail(registry, env),
45
+ });
46
+ }
47
+ const envName = validateEnvName(name, env);
48
+ if (options.platform === undefined) {
49
+ throw new CliError('usage', t('env.add.missingPlatform', {}, env), {
50
+ detail: t('env.add.missingPlatformDetail', {}, env),
51
+ });
52
+ }
53
+ const seavideoBaseUrl = requireUrl(options.seavideoBaseUrl, 'seavideo-base-url', env);
54
+ const flowWebBaseUrl = requireUrl(options.flowWebBaseUrl, 'flow-web-base-url', env);
55
+ const flowApiBaseUrl = requireUrl(options.flowApiBaseUrl, 'flow-api-base-url', env);
56
+ const aiVideoApiBaseUrl = requireUrl(options.aiVideoApiBaseUrl, 'ai-video-api-base-url', env);
57
+ result = {
58
+ env: envName,
59
+ platform: parsePlatform(options.platform),
60
+ seavideoBaseUrl: resolveBaseUrl(seavideoBaseUrl, env),
61
+ flowWebBaseUrl: resolveBaseUrl(flowWebBaseUrl, env),
62
+ flowApiBaseUrl: resolveBaseUrl(flowApiBaseUrl, env),
63
+ aiVideoApiBaseUrl: resolveBaseUrl(aiVideoApiBaseUrl, env),
64
+ authIssuer: options.authIssuer === undefined ? null : parseIssuer(options.authIssuer, 'usage', env),
65
+ authClientId: options.authClientId === undefined ? null : requireAuthClientId(options.authClientId, env),
66
+ };
67
+ }
68
+ return result;
69
+ }
70
+ function missingNameDetail(registry, env) {
71
+ const names = Object.keys(registry.presets).sort();
72
+ const sample = names[0];
73
+ return [
74
+ t('env.add.missingNamePresets', { presets: names.join(' | ') }, env),
75
+ ` ${t('env.add.examplePreset', { name: sample }, env)}`,
76
+ ` ${t('env.add.examplePresetUse', { name: sample }, env)}`,
77
+ ].join('\n');
78
+ }
79
+ function requireUrl(value, field, env) {
80
+ if (value === undefined || value === '') {
81
+ throw new CliError('usage', t('env.add.missingUrl', { field }, env), {
82
+ detail: t('env.add.missingUrlDetail', {}, env),
83
+ });
84
+ }
85
+ return value;
86
+ }
87
+ export async function envAddCommand(ctx, name, options) {
88
+ const registry = await loadPresetRegistry(ctx.deps, ctx.paths);
89
+ const presetName = options.preset;
90
+ const resolved = resolveEnvAdd(name, options, registry, ctx.deps.env);
91
+ if (await ctx.store.exists(resolved.env)) {
92
+ throw new CliError('usage', t('env.add.exists', { env: resolved.env }, ctx.deps.env), {
93
+ detail: t('env.add.existsDetail', {}, ctx.deps.env),
94
+ });
95
+ }
96
+ if (resolved.seavideoBaseUrl.startsWith('http://')) {
97
+ ctx.deps.stderr(`${style.warn('!')} ${t('env.add.insecureWarning', {}, ctx.deps.env)}\n`);
98
+ }
99
+ else {
100
+ }
101
+ await ctx.store.write({
102
+ ...resolved,
103
+ credential: null,
104
+ flowCredential: null,
105
+ });
106
+ ctx.deps.stdout(`${style.ok('✓')} ${t('env.add.created', { env: resolved.env, platform: resolved.platform, seavideoBaseUrl: resolved.seavideoBaseUrl }, ctx.deps.env)}\n`);
107
+ ctx.deps.stdout(`${style.dim(` ${t('env.add.urls', {
108
+ flowWebBaseUrl: resolved.flowWebBaseUrl,
109
+ flowApiBaseUrl: resolved.flowApiBaseUrl,
110
+ aiVideoApiBaseUrl: resolved.aiVideoApiBaseUrl,
111
+ }, ctx.deps.env)}`)}\n`);
112
+ if (presetName === undefined) {
113
+ }
114
+ else {
115
+ const { source } = lookupPreset(registry, presetName, ctx.deps.env);
116
+ const label = t(SOURCE_LABEL[source], {}, ctx.deps.env);
117
+ ctx.deps.stderr(`${style.dim(` ${t('env.add.presetFrom', { source: label }, ctx.deps.env)}`)}\n`);
118
+ }
119
+ const canOAuth = resolved.authIssuer !== null && resolved.authClientId !== null;
120
+ if (options.use === true) {
121
+ await setCurrentEnv(ctx, resolved.env);
122
+ ctx.deps.stdout(`${style.ok('✓')} ${t('env.add.switched', { env: resolved.env }, ctx.deps.env)}\n`);
123
+ const hint = canOAuth ? 'env.add.nextLogin' : 'env.add.nextFlowTokenOnly';
124
+ ctx.deps.stdout(`${style.dim(` ${t(hint, {}, ctx.deps.env)}`)}\n`);
125
+ }
126
+ else {
127
+ const hint = canOAuth ? 'env.add.nextToken' : 'env.add.nextFlowTokenOnly';
128
+ ctx.deps.stdout(`${style.dim(` ${t(hint, {}, ctx.deps.env)}`)}\n`);
129
+ }
130
+ return 0;
131
+ }
132
+ export async function envEnsureCommand(ctx, options, name) {
133
+ const { deps } = ctx;
134
+ if (options.preset === undefined) {
135
+ throw new CliError('usage', t('env.ensure.missingPreset', {}, deps.env), {
136
+ detail: t('env.ensure.missingPresetDetail', {}, deps.env),
137
+ });
138
+ }
139
+ const registry = await loadPresetRegistry(deps, ctx.paths);
140
+ const resolved = resolveEnvAdd(name, { preset: options.preset }, registry, deps.env);
141
+ const existed = await ctx.store.exists(resolved.env);
142
+ if (!existed) {
143
+ await ctx.store.write({
144
+ ...resolved,
145
+ credential: null,
146
+ flowCredential: null,
147
+ });
148
+ deps.stdout(`${style.ok('✓')} ${t('env.ensure.created', { env: resolved.env, preset: options.preset }, deps.env)}\n`);
149
+ }
150
+ else {
151
+ deps.stdout(`${style.dim(t('env.ensure.exists', { env: resolved.env }, deps.env))}\n`);
152
+ }
153
+ if (options.use === true) {
154
+ await setCurrentEnv(ctx, resolved.env);
155
+ deps.stdout(`${style.ok('✓')} ${t('env.add.switched', { env: resolved.env }, deps.env)}\n`);
156
+ }
157
+ else {
158
+ }
159
+ return 0;
160
+ }
@@ -0,0 +1,26 @@
1
+ import { CliError } from "../../../errors.js";
2
+ import { t } from "../../../i18n.js";
3
+ import { normalizeBaseUrl } from "../../../config/base-url.js";
4
+ export function resolveBaseUrl(value, env) {
5
+ const normalized = normalizeBaseUrl(value);
6
+ if (!normalized.ok) {
7
+ throw presetUrlError(normalized.problem, value, env);
8
+ }
9
+ return normalized.url;
10
+ }
11
+ function presetUrlError(problem, value, env) {
12
+ const detail = PRESET_URL_PROBLEM_DETAIL[problem];
13
+ return new CliError('usage', t(detail.key, detail.params(value), env));
14
+ }
15
+ const PRESET_URL_PROBLEM_DETAIL = {
16
+ invalid: { key: 'env.add.invalidUrl', params: (value) => ({ value }) },
17
+ protocol: { key: 'env.add.badProtocol', params: (value) => ({ value }) },
18
+ credentials: { key: 'env.add.hasCredentials', params: () => ({}) },
19
+ query: { key: 'env.add.hasQuery', params: (value) => ({ value }) },
20
+ };
21
+ export function requireAuthClientId(value, env) {
22
+ if (value === '' || /\s/.test(value)) {
23
+ throw new CliError('usage', t('env.add.badAuthClientId', {}, env));
24
+ }
25
+ return value;
26
+ }
@@ -0,0 +1,4 @@
1
+ export { envCurrentCommand, envListCommand } from "./list.js";
2
+ export { envAddCommand, envEnsureCommand, resolveEnvAdd, } from "./create.js";
3
+ export { envDeleteCommand, envSetCommand, envUseCommand, } from "./mutate.js";
4
+ export { validateEnvName } from "../../../config/envname.js";
@@ -0,0 +1,44 @@
1
+ import { CliError } from "../../../errors.js";
2
+ import { renderTable, style } from "../../output.js";
3
+ import { resolveEnvName } from "../../../config/resolve.js";
4
+ import { t } from "../../../i18n.js";
5
+ export async function envListCommand(ctx) {
6
+ const envs = (await ctx.store.list()).sort();
7
+ if (envs.length === 0) {
8
+ ctx.deps.stdout(`${style.dim(t('env.add.empty', {}, ctx.deps.env))}\n`);
9
+ }
10
+ else {
11
+ let current = null;
12
+ try {
13
+ current = await resolveEnvName(ctx.envFlag, ctx.deps, ctx.paths);
14
+ }
15
+ catch {
16
+ current = null;
17
+ }
18
+ const rows = [];
19
+ for (const env of envs) {
20
+ const mark = env === current ? style.ok('*') : ' ';
21
+ try {
22
+ const config = await ctx.store.read(env);
23
+ rows.push([`${mark} ${env}`, config.platform, config.seavideoBaseUrl]);
24
+ }
25
+ catch (err) {
26
+ rows.push([`${mark} ${env}`, '-', style.fail(err.message)]);
27
+ }
28
+ }
29
+ ctx.deps.stdout(`${style.bold(t('env.list.header', {}, ctx.deps.env))}\n`);
30
+ ctx.deps.stdout(`${renderTable(rows)}\n`);
31
+ ctx.deps.stdout(`${style.dim(` ${t('env.list.currentMark', {}, ctx.deps.env)}`)}\n`);
32
+ }
33
+ return 0;
34
+ }
35
+ export async function envCurrentCommand(ctx) {
36
+ const env = await resolveEnvName(ctx.envFlag, ctx.deps, ctx.paths);
37
+ if (!(await ctx.store.exists(env))) {
38
+ throw new CliError('config', t('env.current.dangling', { env }, ctx.deps.env), {
39
+ detail: t('env.current.danglingDetail', {}, ctx.deps.env),
40
+ });
41
+ }
42
+ ctx.deps.stdout(`${env}\n`);
43
+ return 0;
44
+ }