@playcraft/cli 0.0.21 → 0.0.23

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.
@@ -1,4 +1,4 @@
1
- import { writeFileSync, mkdirSync } from 'fs';
1
+ import { writeFileSync, mkdirSync, readFileSync } from 'fs';
2
2
  import { dirname, join } from 'path';
3
3
  import { tmpdir } from 'os';
4
4
  import { AgentApiClient } from '../utils/agent-api-client.js';
@@ -23,24 +23,36 @@ function handleError(err) {
23
23
  export function registerToolsCommands(program) {
24
24
  const tools = program
25
25
  .command('tools')
26
- .description('调用后端 /api/agent/tools:素材 AI(generate-*)与平台能力(Git/沙箱构建/发布/查询/Prefab 等)');
26
+ .description('后端 /api/agent/tools;需 PLAYCRAFT_API_URL + PLAYCRAFT_SANDBOX_TOKEN 或 .playcraft.json');
27
27
  // ─── Generation ─────────────────────────────────────────────
28
28
  tools.command('generate-image')
29
- .description('AI 生成图片')
29
+ .description('AI 生成图片(支持参考图图生图)')
30
30
  .requiredOption('--prompt <text>', '图片描述')
31
31
  .option('--aspect-ratio <ratio>', '宽高比 (1:1|16:9|9:16|3:4|4:3)', '1:1')
32
32
  .requiredOption('--output <path>', '保存路径')
33
33
  .option('--image-size <size>', '图片尺寸 (1K|2K|4K)')
34
+ .option('--reference-image <path>', '参考图路径(图生图),支持 PNG/JPG/WEBP')
34
35
  .action(async (opts) => {
35
36
  try {
37
+ let referenceImageBase64;
38
+ let referenceImageMimeType;
39
+ if (opts.referenceImage) {
40
+ const imgBuf = readFileSync(opts.referenceImage);
41
+ referenceImageBase64 = imgBuf.toString('base64');
42
+ const ext = opts.referenceImage.split('.').pop()?.toLowerCase();
43
+ referenceImageMimeType =
44
+ ext === 'png' ? 'image/png' : ext === 'webp' ? 'image/webp' : 'image/jpeg';
45
+ }
36
46
  const client = new AgentApiClient();
37
47
  const result = await client.post('/generate-image', {
38
48
  prompt: opts.prompt,
39
49
  aspectRatio: opts.aspectRatio,
40
50
  imageSize: opts.imageSize,
51
+ referenceImageBase64,
52
+ referenceImageMimeType,
41
53
  });
42
54
  mkdirSync(dirname(opts.output), { recursive: true });
43
- const buf = Buffer.from(result.base64, 'base64');
55
+ const buf = Buffer.from(result.imageBase64, 'base64');
44
56
  writeFileSync(opts.output, buf);
45
57
  const sizeKB = Math.round(buf.length / 1024);
46
58
  console.log(`Image saved to ${opts.output} (${sizeKB}KB, ${result.mimeType})`);
@@ -200,8 +212,13 @@ export function registerToolsCommands(program) {
200
212
  .action(async (opts) => {
201
213
  try {
202
214
  const client = new AgentApiClient();
215
+ const projectId = Number(opts.projectId);
216
+ if (!Number.isInteger(projectId) || projectId <= 0) {
217
+ console.error(`Error: --project-id must be a positive integer, got: ${opts.projectId}`);
218
+ process.exit(1);
219
+ }
203
220
  const result = await client.post('/create-remix', {
204
- projectId: opts.projectId,
221
+ projectId,
205
222
  sourceBranch: opts.sourceBranch,
206
223
  name: opts.name,
207
224
  description: opts.description,
@@ -435,13 +452,4 @@ export function registerToolsCommands(program) {
435
452
  handleError(e);
436
453
  }
437
454
  });
438
- tools.addHelpText('before', () => [
439
- '子命令分区(均需 PLAYCRAFT_API_URL + PLAYCRAFT_SANDBOX_TOKEN 或 .playcraft.json):',
440
- '',
441
- ' 素材 AI generate-image, generate-sfx, generate-bgm',
442
- ' 流水线 save-to-git, build-project, publish, create-remix',
443
- ' 查询 list-templates, list-assets, list-remixes, list-builds, get-build, get-build-download',
444
- ' 资产库 publish-prefab',
445
- '',
446
- ].join('\n'));
447
455
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/cli",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,8 +22,8 @@
22
22
  "release": "node scripts/release.js"
23
23
  },
24
24
  "dependencies": {
25
- "@playcraft/build": "^0.0.19",
26
- "@playcraft/common": "^0.0.10",
25
+ "@playcraft/build": "^0.0.23",
26
+ "@playcraft/common": "^0.0.12",
27
27
  "chokidar": "^4.0.3",
28
28
  "commander": "^13.1.0",
29
29
  "cors": "^2.8.6",