@5y/cli 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -64,4 +64,15 @@ npm i -g @5y/cli # 或者直接 npx @5y/cli ...
64
64
 
65
65
  ## 配置
66
66
 
67
- `~/.config/5y/config.toml`(600)。也可用环境变量 `5Y_API_KEY`、`5Y_BASE_URL` 覆盖(CI 场景)。
67
+ `~/.config/5y/config.toml`(600)。
68
+
69
+ CI / 环境变量覆盖用 **`FIVEY_API_KEY`**、**`FIVEY_BASE_URL`**:
70
+
71
+ ```bash
72
+ FIVEY_API_KEY=5y_xxx FIVEY_BASE_URL=https://5y.com.cn/api 5y models
73
+ ```
74
+
75
+ > ⚠️ 旧写法 `5Y_API_KEY` 以数字开头,**POSIX shell 无法 `export`**;它只适用于
76
+ > `env 5Y_API_KEY=... 5y ...` 这种注入方式。
77
+ > ⚠️ 本机 `config.toml` 里的 `base_url` 会**覆盖**默认生产地址;若出现 401,
78
+ > 报错里会带上实际使用的 `base_url`,先看它是不是指向了本地/测试环境。
package/lib/commands.mjs CHANGED
@@ -249,9 +249,18 @@ function chooseFilename(jobId, url, contentType) {
249
249
  base = '';
250
250
  }
251
251
  base = base.replace(/[\\/\0]/g, '').replace(/^\.+/, '');
252
- if (base && base !== '.' && path.extname(base)) return base;
252
+ // 上游返回的 URL 扩展名可能和真实编码不一致(实测:`.png` 的链接内容是 JPEG)
253
+ // ⇒ **有 Content-Type 就以它为准**,否则才沿用 URL 扩展名。
254
+ const ctExt = extensionForContentType(contentType);
255
+ if (base && base !== '.' && path.extname(base)) {
256
+ const urlExt = path.extname(base).toLowerCase().replace('.', '');
257
+ if (ctExt && urlExt !== ctExt) {
258
+ return `${base.slice(0, -path.extname(base).length)}.${ctExt}`;
259
+ }
260
+ return base;
261
+ }
253
262
 
254
- const ext = extensionForContentType(contentType) || 'bin';
263
+ const ext = ctExt || 'bin';
255
264
  return `${jobId}.${ext}`;
256
265
  }
257
266
 
@@ -508,7 +517,119 @@ async function runGeneration(cfg, flags, parsed, type) {
508
517
  return failure.exitCode;
509
518
  }
510
519
 
511
- function handleHelp() {
520
+ const HELP_TOPICS = {
521
+ login: `5y login --key <API_KEY> [--base-url URL]
522
+
523
+ Save an API key locally (~/.config/5y/config.toml, mode 600).
524
+
525
+ --key required; obtain it from https://5y.com.cn/settings/api-keys (a human must create it)
526
+ --base-url override API base (default https://5y.com.cn/api; useful for self-hosted/dev)
527
+
528
+ Env override: FIVEY_API_KEY / FIVEY_BASE_URL (shell-friendly; CI only).
529
+ NOTE: 5Y_API_KEY starts with a digit and CANNOT be exported by POSIX shells.
530
+ Use FIVEY_* in shell/CI, or: env 5Y_API_KEY=... 5y ...
531
+ Verify with: 5y whoami`,
532
+
533
+ whoami: `5y whoami
534
+
535
+ Show the current identity as the server sees it: user, key prefix, bound workspace project,
536
+ rate limits. Falls back to local config with "offline": true when the API is unreachable.`,
537
+
538
+ models: `5y models [--type image|video]
539
+
540
+ List models available to this key (visibility + key allowlist already applied).
541
+ Each entry carries capabilities and a param_schema — use it to build --param values.
542
+
543
+ Fields: id, type, label, default (true = used when --model is omitted),
544
+ capabilities{modes,resolutions,durations,param_schema}, pricing_hint{credits}.
545
+
546
+ Example: 5y models --type video`,
547
+
548
+ upload: `5y upload <file> [--name <name>]
549
+
550
+ Upload a local image/video/audio and get an asset_id (reusable as generation input).
551
+ Limits: 50MB per file; accepted types are the same as the web canvas.
552
+
553
+ Output: {"ok":true,"asset_id":"...","url":"...","type":"image|video|audio",...}
554
+ Use the asset_id with: --asset source_video=<id> / --asset image=<id> / --asset video=<id>
555
+
556
+ Example: 5y upload ./face.png`,
557
+
558
+ assets: `5y assets list [--type image|video|audio] [--limit N]
559
+ 5y assets get <asset_id>
560
+ 5y assets delete <asset_id>
561
+
562
+ Assets live in the workspace project bound to this key.
563
+ Deleting an asset that an in-flight job references returns 409 ASSET_IN_USE.
564
+
565
+ Examples:
566
+ 5y assets list --type video --limit 20
567
+ 5y assets delete 8f3c...`,
568
+
569
+ image: `5y image --prompt <text> [options]
570
+
571
+ Generate an image.
572
+
573
+ --prompt required
574
+ --model optional; omit to use the server default (echoed in the result + "notice")
575
+ --param k=v model params (see 5y models → param_schema), repeatable
576
+ --asset image=<asset_id> reference image (upload it first)
577
+ --out <dir> download the result here (default ./5y-output)
578
+ --wait | --no-wait | --callback URL
579
+ --idempotency-key K same key + same body within 10 min returns the same job
580
+ --interval N poll interval seconds (default 5)
581
+ --timeout N overall wait timeout seconds
582
+
583
+ Examples:
584
+ 5y image --prompt "一只橘猫,电影感" --param resolution=2K --out ./out
585
+ 5y image --prompt "把背景换成海边" --asset image=<id> --param quality=high
586
+ 5y image --prompt "..." --no-wait # then: 5y job get <job_id>`,
587
+
588
+ video: `5y video --prompt <text> [options]
589
+
590
+ Generate or edit a video (3-5 minutes per job).
591
+
592
+ --prompt required
593
+ --model optional; omit for the server default
594
+ --param k=v model params, repeatable. Common ones:
595
+ mode=t2v | i2v_reference | i2v_first | i2v_first_last | video_edit | video_extend
596
+ ratio=16:9|9:16|1:1|adaptive duration=<seconds> | -1
597
+ resolution=480P|720P|1080P generate_audio=true|false
598
+ --asset source_video=<asset_id> the video to edit/extend (4-30s input)
599
+ --asset image=<asset_id> reference image(s); repeatable
600
+ --out / --wait / --no-wait / --callback / --idempotency-key / --interval / --timeout
601
+
602
+ Editing rules (upstream enforced): mode=video_edit REQUIRES ratio=adaptive, duration=-1,
603
+ and a 4-30s source_video.
604
+
605
+ Examples:
606
+ 5y video --prompt "海边日落,镜头缓慢推进" --param duration=5 --param ratio=16:9
607
+ 5y video --prompt "把视频里的脸换成参考图的脸" --asset source_video=<clip id> --asset image=<face id> --param mode=video_edit --param ratio=adaptive --param duration=-1`,
608
+
609
+ job: `5y job list [--limit N]
610
+ 5y job get <job_id>
611
+ 5y job wait <job_id> [--interval N] [--timeout N]
612
+ 5y job cancel <job_id>
613
+ 5y job replay <job_id> --callback URL
614
+
615
+ Statuses: queued | running | succeeded | failed | cancelled.
616
+ job get returns cost{estimated,charged,refunded} and error{code,message,retryable,request_id}.
617
+ Replay re-delivers a finished job to a local callback (for when delivery failed).`,
618
+
619
+ download: `5y download <job_id> [--out <dir>]
620
+
621
+ Download the produced file of a finished job to a local directory (default ./5y-output).
622
+ Relative result URLs (/api/static/...) are resolved against the configured base URL.`,
623
+ };
624
+
625
+ function handleHelp(topic) {
626
+ const key = String(topic || '').toLowerCase();
627
+ const text = HELP_TOPICS[key];
628
+ if (text) {
629
+ process.stderr.write(`${text}\n\nRun "5y" for the command list.\n`);
630
+ emitSuccess({ help: key, usage: text });
631
+ return EXIT.OK;
632
+ }
512
633
  process.stderr.write(`${USAGE}\n`);
513
634
  emitSuccess({ usage: USAGE });
514
635
  return EXIT.OK;
@@ -556,7 +677,8 @@ export async function run(argv) {
556
677
  return EXIT.OK;
557
678
  }
558
679
  if (flags.help || positionals.length === 0 || positionals[0] === 'help') {
559
- return handleHelp();
680
+ const topic = positionals[0] === 'help' ? positionals[1] : positionals[0];
681
+ return handleHelp(topic);
560
682
  }
561
683
 
562
684
  const cfg = loadRuntimeConfig(flags);
@@ -912,4 +1034,4 @@ export async function run(argv) {
912
1034
  }
913
1035
  }
914
1036
 
915
- export { USAGE };
1037
+ export { USAGE, HELP_TOPICS };
package/lib/config.mjs CHANGED
@@ -120,9 +120,14 @@ export function loadRuntimeConfig(flags = {}) {
120
120
  const file = configFilePath();
121
121
  const stored = readConfigFile(file);
122
122
 
123
- const apiKey = String(process.env['5Y_API_KEY'] || stored.api_key || '').trim();
123
+ // ⚠️ `5Y_API_KEY` 以数字开头,POSIX shell **无法 export**(不是合法标识符)。
124
+ // 所以正式名用 `FIVEY_API_KEY`;`5Y_API_KEY` 仍保留给 `env 5Y_API_KEY=... cmd` 这类注入。
125
+ const apiKey = String(
126
+ process.env['FIVEY_API_KEY'] || process.env['5Y_API_KEY'] || stored.api_key || ''
127
+ ).trim();
124
128
  const baseUrl = normalizeBaseUrl(
125
- flags['base-url'] || process.env['5Y_BASE_URL'] || stored.base_url || DEFAULT_BASE_URL,
129
+ flags['base-url'] || process.env['FIVEY_BASE_URL'] || process.env['5Y_BASE_URL']
130
+ || stored.base_url || DEFAULT_BASE_URL,
126
131
  );
127
132
 
128
133
  return {
package/lib/http.mjs CHANGED
@@ -353,7 +353,15 @@ export async function openApi(cfg, options = {}) {
353
353
  label: label || `${method} ${apiPath}`,
354
354
  });
355
355
 
356
- if (res.status < 200 || res.status >= 300) throw errorFromResponse(res);
356
+ if (res.status < 200 || res.status >= 300) {
357
+ const err = errorFromResponse(res);
358
+ // 🔴 配置里的 base_url 会被本地 config 覆盖(实测:残留的 localhost 导致
359
+ // 「Key 无效或已吊销」,排查绕了一大圈)。把实际地址带回错误里。
360
+ if (err instanceof CliError && (res.status === 401 || res.status === 403)) {
361
+ err.message = `${err.message} (base_url: ${cfg.baseUrl})`;
362
+ }
363
+ throw err;
364
+ }
357
365
 
358
366
  return {
359
367
  data: parseBody(res),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5y/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "5y open API CLI — generate images/videos and manage assets from Codex / Claude Code / WorkBuddy",
5
5
  "type": "module",
6
6
  "bin": {