agens-studio 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/cli.js +27 -1
- package/config.js +3 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -11,11 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
import readline from 'node:readline';
|
|
13
13
|
import fs from 'node:fs/promises';
|
|
14
|
+
import fsSync from 'node:fs';
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
import { randomUUID } from 'node:crypto';
|
|
16
17
|
import { exec } from 'node:child_process';
|
|
17
18
|
import { fileURLToPath } from 'node:url';
|
|
18
19
|
import { config, USER_CONFIG_FILE, saveUserConfig, readUserConfig } from './config.js';
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = path.dirname(__filename);
|
|
23
|
+
const PKG_VERSION = JSON.parse(fsSync.readFileSync(path.join(__dirname, 'package.json'), 'utf8')).version;
|
|
19
24
|
import { generateImage, generateVideo, getTaskStatus } from './src/services/agensClient.js';
|
|
20
25
|
import { optimizePrompt, optimizeNegativePrompt, dimensionsToText } from './src/services/mimoClient.js';
|
|
21
26
|
import { describeImage, descriptionToText } from './src/services/mimoVision.js';
|
|
@@ -424,7 +429,7 @@ async function mainMenu() {
|
|
|
424
429
|
while (true) {
|
|
425
430
|
console.log('');
|
|
426
431
|
console.log(`${C.yellow}==================================================${C.reset}`);
|
|
427
|
-
console.log(`${C.yellow}${C.bold} Agens 创作工作台 CLI
|
|
432
|
+
console.log(`${C.yellow}${C.bold} Agens 创作工作台 CLI v${PKG_VERSION}${C.reset}`);
|
|
428
433
|
console.log(`${C.yellow} 图片 · 视频 · AI 提示词优化 · 素材库${C.reset}`);
|
|
429
434
|
console.log(`${C.yellow}==================================================${C.reset}`);
|
|
430
435
|
console.log(` API:${config.agens.image.apiKey ? C.green + '已配置' + C.reset : C.red + '未配置' + C.reset}`);
|
|
@@ -464,9 +469,25 @@ async function mainMenu() {
|
|
|
464
469
|
}
|
|
465
470
|
}
|
|
466
471
|
|
|
472
|
+
/**
|
|
473
|
+
* 检查 API 是否已配置,未配置时自动引导 setup wizard
|
|
474
|
+
* @returns {Promise<boolean>} true = 已配置可继续,false = 用户取消
|
|
475
|
+
*/
|
|
476
|
+
async function ensureApiConfigured() {
|
|
477
|
+
if (config.agens.image.apiKey) return true;
|
|
478
|
+
console.log(`\n${C.red}${C.bold} ⚠ API Key 未配置,无法生成${C.reset}`);
|
|
479
|
+
console.log(`${C.gray} 请先配置 Agnes API Key 后重试${C.reset}\n`);
|
|
480
|
+
const go = await confirm('是否现在配置 API Key');
|
|
481
|
+
if (go) {
|
|
482
|
+
await setupWizard(false);
|
|
483
|
+
}
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
|
|
467
487
|
// ═══════════════════ [1] 文生图 ═══════════════════
|
|
468
488
|
|
|
469
489
|
async function modeText2Image() {
|
|
490
|
+
if (!(await ensureApiConfigured())) return;
|
|
470
491
|
console.log(`\n${C.bold}─────── 文生图 ───────${C.reset}`);
|
|
471
492
|
|
|
472
493
|
const rawPrompt = await ask('描述你想生成的画面');
|
|
@@ -506,6 +527,7 @@ async function modeText2Image() {
|
|
|
506
527
|
// ═══════════════════ [2] 图生图 ═══════════════════
|
|
507
528
|
|
|
508
529
|
async function modeImage2Image() {
|
|
530
|
+
if (!(await ensureApiConfigured())) return;
|
|
509
531
|
console.log(`\n${C.bold}─────── 图生图 ───────${C.reset}`);
|
|
510
532
|
console.log(`${C.gray}输入参考图片的本地文件路径(支持拖拽文件到窗口)${C.reset}`);
|
|
511
533
|
|
|
@@ -593,6 +615,7 @@ async function callVisionDirect(dataUri) {
|
|
|
593
615
|
// ═══════════════════ [3] 文生视频 ═══════════════════
|
|
594
616
|
|
|
595
617
|
async function modeText2Video() {
|
|
618
|
+
if (!(await ensureApiConfigured())) return;
|
|
596
619
|
console.log(`\n${C.bold}─────── 文生视频 ───────${C.reset}`);
|
|
597
620
|
|
|
598
621
|
const rawPrompt = await ask('描述你想生成的视频场景');
|
|
@@ -639,6 +662,7 @@ async function modeText2Video() {
|
|
|
639
662
|
// ═══════════════════ [4] 图生视频 ═══════════════════
|
|
640
663
|
|
|
641
664
|
async function modeImage2Video() {
|
|
665
|
+
if (!(await ensureApiConfigured())) return;
|
|
642
666
|
console.log(`\n${C.bold}─────── 图生视频 ───────${C.reset}`);
|
|
643
667
|
console.log(`${C.gray}输入参考图片路径(支持拖拽)${C.reset}`);
|
|
644
668
|
|
|
@@ -691,6 +715,7 @@ async function modeImage2Video() {
|
|
|
691
715
|
// ═══════════════════ [5] 多图生视频 ═══════════════════
|
|
692
716
|
|
|
693
717
|
async function modeMulti2Video() {
|
|
718
|
+
if (!(await ensureApiConfigured())) return;
|
|
694
719
|
console.log(`\n${C.bold}─────── 多图生视频 ───────${C.reset}`);
|
|
695
720
|
console.log(`${C.gray}输入多张图片路径,生成过渡视频(2-5 张)${C.reset}`);
|
|
696
721
|
|
|
@@ -753,6 +778,7 @@ async function modeMulti2Video() {
|
|
|
753
778
|
// ═══════════════════ [6] 关键帧动画 ═══════════════════
|
|
754
779
|
|
|
755
780
|
async function modeKeyframe() {
|
|
781
|
+
if (!(await ensureApiConfigured())) return;
|
|
756
782
|
console.log(`\n${C.bold}─────── 关键帧动画 ───────${C.reset}`);
|
|
757
783
|
console.log(`${C.gray}至少输入首帧和尾帧图片(2-5 张关键帧)${C.reset}`);
|
|
758
784
|
|
package/config.js
CHANGED
|
@@ -132,7 +132,9 @@ export function saveUserConfig(cfg) {
|
|
|
132
132
|
*/
|
|
133
133
|
export function readUserConfig() {
|
|
134
134
|
try {
|
|
135
|
-
|
|
135
|
+
const data = JSON.parse(fs.readFileSync(USER_CONFIG_FILE, 'utf8'));
|
|
136
|
+
if (data && typeof data === 'object' && Object.keys(data).length > 0) return data;
|
|
137
|
+
return null;
|
|
136
138
|
} catch {
|
|
137
139
|
return null;
|
|
138
140
|
}
|