@5y/cli 0.1.2 → 0.1.4

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
@@ -36,20 +36,32 @@ npm i -g @5y/cli # 或者直接 npx @5y/cli ...
36
36
  5y models --type video # 看可用模型(含默认标记)
37
37
  ```
38
38
 
39
- ## 生成
39
+ ## 典型用法(复制就能用)
40
40
 
41
41
  ```bash
42
- # 文生图(不传 --model 用服务端默认,输出会回显实际模型与费用)
43
- 5y image --prompt "一只橘猫,电影感" --out ./out
42
+ # ① 文生图
43
+ 5y image --prompt "一只在雪地里的橘猫,电影感,黄昏光" --out ./out
44
44
 
45
- # 视频编辑:把视频里的人脸换成参考图
46
- 5y upload ./face.png # → asset_id
45
+ # ② 图生图(改图 / 换背景)—— 先上传参考图拿 asset_id
46
+ 5y upload ./cat.png
47
+ 5y image --prompt "把背景换成海边黄昏" --asset image=<asset_id> --out ./out
48
+
49
+ # ③ 文生视频
50
+ 5y video --prompt "海边日落,镜头缓慢推进,电影感" --param duration=5 --param ratio=16:9 --out ./out
51
+
52
+ # ④ 图生视频(用一张首帧图动起来)
53
+ 5y upload ./frame.png
54
+ 5y video --prompt "画面缓慢推进,光影流动" --asset image=<asset_id> --param mode=i2v_first --out ./out
55
+
56
+ # ⑤ 视频编辑(换脸 / 替换):输入 4–30 秒,比例必须 adaptive、时长必须 -1
57
+ 5y upload ./clip.mp4 && 5y upload ./face.png
47
58
  5y video --prompt "把视频里的脸换成参考图的脸" \
48
- --asset source_video=<视频 asset_id> --asset image=<图 asset_id> \
49
- --param mode=video_edit --param ratio=adaptive --param duration=-1 \
50
- --out ./out
59
+ --asset source_video=<clip id> --asset image=<face id> \
60
+ --param mode=video_edit --param ratio=adaptive --param duration=-1 --out ./out
51
61
  ```
52
62
 
63
+ 不传 `--model` 时服务端会用默认模型,并在结果里回显实际模型与费用(`5y models` 里标 `default: true` 的那个)。
64
+
53
65
  ## 等待方式
54
66
 
55
67
  - 默认 `--wait`:等到出片再返回,产物落到 `--out`(默认 `./5y-output`)
@@ -64,4 +76,15 @@ npm i -g @5y/cli # 或者直接 npx @5y/cli ...
64
76
 
65
77
  ## 配置
66
78
 
67
- `~/.config/5y/config.toml`(600)。也可用环境变量 `5Y_API_KEY`、`5Y_BASE_URL` 覆盖(CI 场景)。
79
+ `~/.config/5y/config.toml`(600)。
80
+
81
+ CI / 环境变量覆盖用 **`FIVEY_API_KEY`**、**`FIVEY_BASE_URL`**:
82
+
83
+ ```bash
84
+ FIVEY_API_KEY=5y_xxx FIVEY_BASE_URL=https://5y.com.cn/api 5y models
85
+ ```
86
+
87
+ > ⚠️ 旧写法 `5Y_API_KEY` 以数字开头,**POSIX shell 无法 `export`**;它只适用于
88
+ > `env 5Y_API_KEY=... 5y ...` 这种注入方式。
89
+ > ⚠️ 本机 `config.toml` 里的 `base_url` 会**覆盖**默认生产地址;若出现 401,
90
+ > 报错里会带上实际使用的 `base_url`,先看它是不是指向了本地/测试环境。
package/lib/commands.mjs CHANGED
@@ -37,21 +37,28 @@ QUICK START (in order):
37
37
  3. 5y models --type image|video # see model ids + supported params
38
38
  4. 5y image --prompt "a cat" --out ./out
39
39
 
40
- EXAMPLES:
41
- # text-to-image (model optional; server picks a default and echoes it)
42
- 5y image --prompt "一只橘猫,电影感" --param resolution=2K --out ./out
40
+ 典型的四类任务(复制就能用):
41
+ # ① 文生图
42
+ 5y image --prompt "一只在雪地里的橘猫,电影感,黄昏光" --out ./out
43
43
 
44
- # video edit: swap a face using a reference image (needs a 4-30s input video)
45
- 5y upload ./face.png # -> asset_id
46
- 5y upload ./clip.mp4 # -> asset_id
47
- 5y video --prompt "把视频里的脸换成参考图的脸" --asset source_video=<clip id> --asset image=<face id> --param mode=video_edit --param ratio=adaptive --param duration=-1 --out ./out
44
+ # ② 图生图(改图 / 换背景)—— 先上传参考图拿到 asset_id
45
+ 5y upload ./cat.png
46
+ 5y image --prompt "把背景换成海边黄昏" --asset image=<asset_id> --out ./out
47
+
48
+ # ③ 文生视频
49
+ 5y video --prompt "海边日落,镜头缓慢推进,电影感" --param duration=5 --param ratio=16:9 --out ./out
48
50
 
49
- # fire and forget, then poll
50
- 5y video --prompt "..." --no-wait
51
- 5y job get <job_id>
51
+ # ④ 图生视频(用一张首帧图动起来)
52
+ 5y upload ./frame.png
53
+ 5y video --prompt "画面缓慢推进,光影流动" --asset image=<asset_id> --param mode=i2v_first --out ./out
54
+
55
+ # ⑤ 视频编辑(换脸 / 替换):输入视频 4-30 秒,比例必须 adaptive、时长必须 -1
56
+ 5y upload ./clip.mp4 && 5y upload ./face.png
57
+ 5y video --prompt "把视频里的脸换成参考图的脸" --asset source_video=<clip id> --asset image=<face id> --param mode=video_edit --param ratio=adaptive --param duration=-1 --out ./out
52
58
 
53
- # notify a local service when done (5y never calls your machine)
54
- 5y image --prompt "..." --callback http://127.0.0.1:8787/hook
59
+ # 其他常用
60
+ 5y image --prompt "..." --no-wait # 立即返回 job_id,之后 5y job get <job_id>
61
+ 5y image --prompt "..." --callback http://127.0.0.1:8787/hook # 完成后由本机 CLI 通知
55
62
 
56
63
  COMMANDS:
57
64
  login --key <API_KEY> [--base-url URL]
@@ -249,9 +256,18 @@ function chooseFilename(jobId, url, contentType) {
249
256
  base = '';
250
257
  }
251
258
  base = base.replace(/[\\/\0]/g, '').replace(/^\.+/, '');
252
- if (base && base !== '.' && path.extname(base)) return base;
259
+ // 上游返回的 URL 扩展名可能和真实编码不一致(实测:`.png` 的链接内容是 JPEG)
260
+ // ⇒ **有 Content-Type 就以它为准**,否则才沿用 URL 扩展名。
261
+ const ctExt = extensionForContentType(contentType);
262
+ if (base && base !== '.' && path.extname(base)) {
263
+ const urlExt = path.extname(base).toLowerCase().replace('.', '');
264
+ if (ctExt && urlExt !== ctExt) {
265
+ return `${base.slice(0, -path.extname(base).length)}.${ctExt}`;
266
+ }
267
+ return base;
268
+ }
253
269
 
254
- const ext = extensionForContentType(contentType) || 'bin';
270
+ const ext = ctExt || 'bin';
255
271
  return `${jobId}.${ext}`;
256
272
  }
257
273
 
@@ -516,7 +532,9 @@ Save an API key locally (~/.config/5y/config.toml, mode 600).
516
532
  --key required; obtain it from https://5y.com.cn/settings/api-keys (a human must create it)
517
533
  --base-url override API base (default https://5y.com.cn/api; useful for self-hosted/dev)
518
534
 
519
- Env override: 5Y_API_KEY / 5Y_BASE_URL (handy in CI; they take precedence over the config file).
535
+ Env override: FIVEY_API_KEY / FIVEY_BASE_URL (shell-friendly; CI only).
536
+ NOTE: 5Y_API_KEY starts with a digit and CANNOT be exported by POSIX shells.
537
+ Use FIVEY_* in shell/CI, or: env 5Y_API_KEY=... 5y ...
520
538
  Verify with: 5y whoami`,
521
539
 
522
540
  whoami: `5y whoami
@@ -569,10 +587,18 @@ Generate an image.
569
587
  --interval N poll interval seconds (default 5)
570
588
  --timeout N overall wait timeout seconds
571
589
 
572
- Examples:
573
- 5y image --prompt "一只橘猫,电影感" --param resolution=2K --out ./out
574
- 5y image --prompt "把背景换成海边" --asset image=<id> --param quality=high
575
- 5y image --prompt "..." --no-wait # then: 5y job get <job_id>`,
590
+ 典型用法:
591
+ # 文生图(最常用)
592
+ 5y image --prompt "一只在雪地里的橘猫,电影感,黄昏光" --out ./out
593
+
594
+ # 图生图 / 改图:先 5y upload ./x.png 拿到 asset_id
595
+ 5y image --prompt "把背景换成海边黄昏" --asset image=<asset_id> --out ./out
596
+
597
+ # 指定尺寸/清晰度(可选参数,见 5y models 的 param_schema)
598
+ 5y image --prompt "..." --param resolution=2K --param ratio=16:9
599
+
600
+ # 异步:先返回 job_id
601
+ 5y image --prompt "..." --no-wait && 5y job get <job_id>`,
576
602
 
577
603
  video: `5y video --prompt <text> [options]
578
604
 
@@ -591,9 +617,16 @@ Generate or edit a video (3-5 minutes per job).
591
617
  Editing rules (upstream enforced): mode=video_edit REQUIRES ratio=adaptive, duration=-1,
592
618
  and a 4-30s source_video.
593
619
 
594
- Examples:
595
- 5y video --prompt "海边日落,镜头缓慢推进" --param duration=5 --param ratio=16:9
596
- 5y video --prompt "把视频里的脸换成参考图的脸" --asset source_video=<clip id> --asset image=<face id> --param mode=video_edit --param ratio=adaptive --param duration=-1`,
620
+ 典型用法:
621
+ # 文生视频(最常用)
622
+ 5y video --prompt "海边日落,镜头缓慢推进,电影感" --param duration=5 --param ratio=16:9 --out ./out
623
+
624
+ # 图生视频:用一张首帧图动起来(先 5y upload ./frame.png)
625
+ 5y video --prompt "画面缓慢推进,光影流动" --asset image=<asset_id> --param mode=i2v_first --out ./out
626
+
627
+ # 视频编辑 / 换脸(输入 4-30 秒;比例 adaptive、时长 -1 是硬约束)
628
+ 5y upload ./clip.mp4 && 5y upload ./face.png
629
+ 5y video --prompt "把视频里的脸换成参考图的脸" --asset source_video=<clip id> --asset image=<face id> --param mode=video_edit --param ratio=adaptive --param duration=-1 --out ./out`,
597
630
 
598
631
  job: `5y job list [--limit N]
599
632
  5y job get <job_id>
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.2",
3
+ "version": "0.1.4",
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": {