@optima-chat/comfy-cli 0.3.3 → 0.4.1
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/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +129 -28
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/download.d.ts.map +1 -1
- package/dist/commands/download.js +119 -33
- package/dist/commands/download.js.map +1 -1
- package/dist/commands/edit.d.ts.map +1 -1
- package/dist/commands/edit.js +73 -23
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +67 -15
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/interrupt.d.ts.map +1 -1
- package/dist/commands/interrupt.js +42 -7
- package/dist/commands/interrupt.js.map +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +49 -11
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/node.d.ts.map +1 -1
- package/dist/commands/node.js +96 -18
- package/dist/commands/node.js.map +1 -1
- package/dist/commands/queue.d.ts.map +1 -1
- package/dist/commands/queue.js +127 -25
- package/dist/commands/queue.js.map +1 -1
- package/dist/commands/system.d.ts.map +1 -1
- package/dist/commands/system.js +48 -10
- package/dist/commands/system.js.map +1 -1
- package/dist/commands/video.d.ts.map +1 -1
- package/dist/commands/video.js +86 -25
- package/dist/commands/video.js.map +1 -1
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +141 -34
- package/dist/commands/workflow.js.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/helpText.d.ts +15 -0
- package/dist/utils/helpText.d.ts.map +1 -0
- package/dist/utils/helpText.js +37 -0
- package/dist/utils/helpText.js.map +1 -0
- package/dist/utils/output.d.ts +54 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +76 -0
- package/dist/utils/output.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QAqMrD"}
|
package/dist/commands/config.js
CHANGED
|
@@ -1,55 +1,91 @@
|
|
|
1
1
|
import { config, getConfig, setConfig, resetConfig } from '../services/config.js';
|
|
2
|
-
import { success,
|
|
2
|
+
import { success, info } from '../utils/logger.js';
|
|
3
|
+
import { outputSuccess, outputError, isPrettyMode } from '../utils/output.js';
|
|
4
|
+
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
3
5
|
import Table from 'cli-table3';
|
|
4
6
|
export function registerConfigCommand(program) {
|
|
5
7
|
const configCmd = program
|
|
6
8
|
.command('config')
|
|
7
9
|
.description('配置管理');
|
|
8
10
|
// comfy config set
|
|
9
|
-
configCmd
|
|
11
|
+
const setCmd = configCmd
|
|
10
12
|
.command('set')
|
|
11
|
-
.description('设置配置项')
|
|
13
|
+
.description('设置配置项 - 配置 ComfyUI 服务器地址和其他选项')
|
|
12
14
|
.argument('<key>', '配置键 (server, timeout, autoConnect, outputDir)')
|
|
13
15
|
.argument('<value>', '配置值')
|
|
14
|
-
.action((key, value) => {
|
|
16
|
+
.action((key, value, options) => {
|
|
17
|
+
const pretty = isPrettyMode(options);
|
|
15
18
|
try {
|
|
16
19
|
if (!['server', 'timeout', 'autoConnect', 'outputDir'].includes(key)) {
|
|
17
|
-
|
|
18
|
-
info('可用配置: server, timeout, autoConnect, outputDir');
|
|
19
|
-
process.exit(1);
|
|
20
|
+
outputError('INVALID_CONFIG_KEY', `无效的配置键: ${key}`, options);
|
|
20
21
|
}
|
|
21
22
|
let parsedValue = value;
|
|
22
23
|
// 类型转换
|
|
23
24
|
if (key === 'timeout') {
|
|
24
25
|
parsedValue = parseInt(value);
|
|
25
26
|
if (isNaN(parsedValue)) {
|
|
26
|
-
|
|
27
|
-
process.exit(1);
|
|
27
|
+
outputError('INVALID_VALUE', 'timeout 必须是数字', options);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
else if (key === 'autoConnect') {
|
|
31
31
|
parsedValue = value === 'true';
|
|
32
32
|
}
|
|
33
33
|
setConfig(key, parsedValue);
|
|
34
|
-
|
|
34
|
+
if (pretty) {
|
|
35
|
+
success(`已设置 ${key} = ${parsedValue}`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
outputSuccess({
|
|
39
|
+
message: '配置已更新',
|
|
40
|
+
key,
|
|
41
|
+
value: parsedValue,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
45
|
catch (err) {
|
|
37
|
-
|
|
38
|
-
process.exit(1);
|
|
46
|
+
outputError('CONFIG_SET_FAILED', `设置失败: ${err}`, options);
|
|
39
47
|
}
|
|
40
48
|
});
|
|
49
|
+
// Add enhanced help for set command
|
|
50
|
+
addEnhancedHelp(setCmd, {
|
|
51
|
+
examples: [
|
|
52
|
+
'# 设置 ComfyUI 服务器地址(首次必需)',
|
|
53
|
+
'$ comfy config set server http://localhost:8188',
|
|
54
|
+
'',
|
|
55
|
+
'# 设置请求超时时间(毫秒)',
|
|
56
|
+
'$ comfy config set timeout 30000',
|
|
57
|
+
'',
|
|
58
|
+
'# 设置输出目录',
|
|
59
|
+
'$ comfy config set outputDir ./my-outputs',
|
|
60
|
+
],
|
|
61
|
+
outputJson: `{
|
|
62
|
+
"success": true,
|
|
63
|
+
"data": {
|
|
64
|
+
"message": "配置已更新",
|
|
65
|
+
"key": "server",
|
|
66
|
+
"value": "http://localhost:8188"
|
|
67
|
+
}
|
|
68
|
+
}`,
|
|
69
|
+
relatedCommands: [
|
|
70
|
+
{ command: 'config list', description: '查看当前配置' },
|
|
71
|
+
{ command: 'config reset --confirm', description: '重置为默认配置' },
|
|
72
|
+
],
|
|
73
|
+
notes: [
|
|
74
|
+
'可用配置键: server, timeout, autoConnect, outputDir',
|
|
75
|
+
'server: ComfyUI 服务器地址(必需)',
|
|
76
|
+
'timeout: 请求超时时间(毫秒,默认 30000)',
|
|
77
|
+
'outputDir: 下载输出文件的目录(默认 ./output)',
|
|
78
|
+
],
|
|
79
|
+
});
|
|
41
80
|
// comfy config list
|
|
42
|
-
configCmd
|
|
81
|
+
const listCmd = configCmd
|
|
43
82
|
.command('list')
|
|
44
|
-
.description('查看当前配置')
|
|
45
|
-
.option('--json', '输出 JSON 格式')
|
|
83
|
+
.description('查看当前配置 - 显示所有配置项和配置文件路径')
|
|
46
84
|
.action((options) => {
|
|
85
|
+
const pretty = isPrettyMode(options);
|
|
47
86
|
try {
|
|
48
87
|
const cfg = getConfig();
|
|
49
|
-
if (
|
|
50
|
-
console.log(JSON.stringify(cfg, null, 2));
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
88
|
+
if (pretty) {
|
|
53
89
|
const table = new Table({
|
|
54
90
|
head: ['配置项', '值'],
|
|
55
91
|
colWidths: [20, 60],
|
|
@@ -58,30 +94,95 @@ export function registerConfigCommand(program) {
|
|
|
58
94
|
console.log(table.toString());
|
|
59
95
|
info(`配置文件位置: ${config.path}`);
|
|
60
96
|
}
|
|
97
|
+
else {
|
|
98
|
+
outputSuccess({
|
|
99
|
+
config: cfg,
|
|
100
|
+
config_path: config.path,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
61
103
|
}
|
|
62
104
|
catch (err) {
|
|
63
|
-
|
|
64
|
-
process.exit(1);
|
|
105
|
+
outputError('CONFIG_LIST_FAILED', `获取配置失败: ${err}`, options);
|
|
65
106
|
}
|
|
66
107
|
});
|
|
108
|
+
// Add enhanced help for list command
|
|
109
|
+
addEnhancedHelp(listCmd, {
|
|
110
|
+
examples: [
|
|
111
|
+
'# 查看当前配置',
|
|
112
|
+
'$ comfy config list',
|
|
113
|
+
'',
|
|
114
|
+
'# Pretty 模式',
|
|
115
|
+
'$ comfy config list --pretty',
|
|
116
|
+
],
|
|
117
|
+
outputJson: `{
|
|
118
|
+
"success": true,
|
|
119
|
+
"data": {
|
|
120
|
+
"config": {
|
|
121
|
+
"server": "http://localhost:8188",
|
|
122
|
+
"timeout": 30000,
|
|
123
|
+
"autoConnect": true,
|
|
124
|
+
"outputDir": "./output"
|
|
125
|
+
},
|
|
126
|
+
"config_path": "/Users/username/.comfy-cli/config.json"
|
|
127
|
+
}
|
|
128
|
+
}`,
|
|
129
|
+
relatedCommands: [
|
|
130
|
+
{ command: 'config set <key> <value>', description: '设置配置项' },
|
|
131
|
+
{ command: 'config reset --confirm', description: '重置配置' },
|
|
132
|
+
],
|
|
133
|
+
notes: [
|
|
134
|
+
'显示所有配置项的当前值',
|
|
135
|
+
'包含配置文件的完整路径',
|
|
136
|
+
'配置文件存储在用户主目录的 .comfy-cli 文件夹中',
|
|
137
|
+
],
|
|
138
|
+
});
|
|
67
139
|
// comfy config reset
|
|
68
|
-
configCmd
|
|
140
|
+
const resetCmd = configCmd
|
|
69
141
|
.command('reset')
|
|
70
|
-
.description('重置为默认配置')
|
|
142
|
+
.description('重置为默认配置 - 将所有配置恢复为默认值(需要确认)')
|
|
71
143
|
.option('--confirm', '确认重置')
|
|
72
144
|
.action((options) => {
|
|
145
|
+
const pretty = isPrettyMode(options);
|
|
73
146
|
try {
|
|
74
147
|
if (!options.confirm) {
|
|
75
|
-
|
|
76
|
-
process.exit(1);
|
|
148
|
+
outputError('CONFIRM_REQUIRED', '请使用 --confirm 确认重置操作', options);
|
|
77
149
|
}
|
|
78
150
|
resetConfig();
|
|
79
|
-
|
|
151
|
+
if (pretty) {
|
|
152
|
+
success('配置已重置为默认值');
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
outputSuccess({
|
|
156
|
+
message: '配置已重置为默认值',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
80
159
|
}
|
|
81
160
|
catch (err) {
|
|
82
|
-
|
|
83
|
-
process.exit(1);
|
|
161
|
+
outputError('CONFIG_RESET_FAILED', `重置失败: ${err}`, options);
|
|
84
162
|
}
|
|
85
163
|
});
|
|
164
|
+
// Add enhanced help for reset command
|
|
165
|
+
addEnhancedHelp(resetCmd, {
|
|
166
|
+
examples: [
|
|
167
|
+
'# 重置配置为默认值(需要 --confirm)',
|
|
168
|
+
'$ comfy config reset --confirm',
|
|
169
|
+
],
|
|
170
|
+
outputJson: `{
|
|
171
|
+
"success": true,
|
|
172
|
+
"data": {
|
|
173
|
+
"message": "配置已重置为默认值"
|
|
174
|
+
}
|
|
175
|
+
}`,
|
|
176
|
+
relatedCommands: [
|
|
177
|
+
{ command: 'config list', description: '查看当前配置' },
|
|
178
|
+
{ command: 'config set <key> <value>', description: '设置配置项' },
|
|
179
|
+
],
|
|
180
|
+
notes: [
|
|
181
|
+
'必须使用 --confirm 选项才能执行',
|
|
182
|
+
'会清除所有自定义配置',
|
|
183
|
+
'默认值: server=http://localhost:8188, timeout=30000',
|
|
184
|
+
'此操作不可撤销',
|
|
185
|
+
],
|
|
186
|
+
});
|
|
86
187
|
}
|
|
87
188
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,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C;SAChB,WAAW,CAAC,6BAA6B,CAAC;SAC1C,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC;SAC3B,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAErC,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACrB,WAAW,CAAC,kBAAkB,EAAE,sBAAsB,EAAE,OAAO,CAAC,CAAC;YACnE,CAAC;YAED,WAAW,EAAE,CAAC;YAEd,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,WAAW,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,aAAa,CAAC;oBACZ,OAAO,EAAE,WAAW;iBACrB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,qBAAqB,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,sCAAsC;IACtC,eAAe,CAAC,QAAQ,EAAE;QACxB,QAAQ,EAAE;YACR,0BAA0B;YAC1B,gCAAgC;SACjC;QACD,UAAU,EAAE;;;;;EAKd;QACE,eAAe,EAAE;YACf,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE;YACjD,EAAE,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,OAAO,EAAE;SAC9D;QACD,KAAK,EAAE;YACL,uBAAuB;YACvB,YAAY;YACZ,kDAAkD;YAClD,SAAS;SACV;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/commands/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/commands/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAyKvD"}
|
|
@@ -3,46 +3,93 @@ import * as fs from 'fs';
|
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import { ComfyAPIClient } from '../services/api.js';
|
|
5
5
|
import { success, error } from '../utils/logger.js';
|
|
6
|
+
import { outputSuccess, outputError, isPrettyMode } from '../utils/output.js';
|
|
7
|
+
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
6
8
|
export function registerDownloadCommand(program) {
|
|
7
|
-
program
|
|
9
|
+
const cmd = program
|
|
8
10
|
.command('download')
|
|
9
|
-
.description('下载生成的图像或视频')
|
|
10
|
-
.argument('<prompt_id>', 'Prompt ID')
|
|
11
|
-
.option('-o, --output <path>', '
|
|
12
|
-
.option('--json', '输出 JSON 格式的文件信息')
|
|
11
|
+
.description('下载生成的图像或视频 - 根据 Prompt ID 下载 ComfyUI 生成的文件')
|
|
12
|
+
.argument('<prompt_id>', 'Prompt ID(从 generate/edit/video 命令获取)')
|
|
13
|
+
.option('-o, --output <path>', '输出文件路径或目录')
|
|
13
14
|
.action(async (promptId, options) => {
|
|
15
|
+
const pretty = isPrettyMode(options);
|
|
14
16
|
try {
|
|
15
17
|
const client = new ComfyAPIClient();
|
|
16
18
|
// 获取输出文件列表
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let files;
|
|
20
|
+
if (pretty) {
|
|
21
|
+
const spinner = ora('正在获取输出文件...').start();
|
|
22
|
+
files = await client.getOutputFiles(promptId);
|
|
23
|
+
if (files.length === 0) {
|
|
24
|
+
spinner.fail('未找到输出文件');
|
|
25
|
+
outputError('NO_OUTPUT_FILES', `Prompt ID: ${promptId} 没有生成任何文件`, options);
|
|
26
|
+
}
|
|
27
|
+
spinner.succeed(`找到 ${files.length} 个文件`);
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
else {
|
|
30
|
+
files = await client.getOutputFiles(promptId);
|
|
31
|
+
if (files.length === 0) {
|
|
32
|
+
outputError('NO_OUTPUT_FILES', `Prompt ID: ${promptId} 没有生成任何文件`, options);
|
|
33
|
+
}
|
|
28
34
|
}
|
|
35
|
+
const downloadedFiles = [];
|
|
29
36
|
// 下载所有文件
|
|
30
37
|
for (let i = 0; i < files.length; i++) {
|
|
31
38
|
const file = files[i];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
if (pretty) {
|
|
40
|
+
const downloadSpinner = ora(`正在下载 (${i + 1}/${files.length}): ${file.filename}`).start();
|
|
41
|
+
try {
|
|
42
|
+
// 下载文件
|
|
43
|
+
const buffer = await client.downloadImage(file.filename, file.subfolder, file.type);
|
|
44
|
+
// 确定输出路径
|
|
45
|
+
let outputPath;
|
|
46
|
+
if (options.output) {
|
|
47
|
+
// 如果指定了输出路径
|
|
48
|
+
if (files.length === 1) {
|
|
49
|
+
// 只有一个文件,直接使用指定路径
|
|
50
|
+
outputPath = options.output;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// 多个文件,将指定路径作为目录
|
|
54
|
+
const dir = options.output;
|
|
55
|
+
if (!fs.existsSync(dir)) {
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
outputPath = path.join(dir, file.filename);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// 默认保存到 ./output 目录
|
|
63
|
+
const outputDir = './output';
|
|
64
|
+
if (!fs.existsSync(outputDir)) {
|
|
65
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
outputPath = path.join(outputDir, file.filename);
|
|
68
|
+
}
|
|
69
|
+
// 确保输出目录存在
|
|
70
|
+
const outputDir = path.dirname(outputPath);
|
|
71
|
+
if (!fs.existsSync(outputDir)) {
|
|
72
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
// 保存文件
|
|
75
|
+
fs.writeFileSync(outputPath, buffer);
|
|
76
|
+
downloadSpinner.succeed(`已下载: ${outputPath}`);
|
|
77
|
+
downloadedFiles.push(outputPath);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
downloadSpinner.fail(`下载失败: ${file.filename}`);
|
|
81
|
+
error(`错误: ${err}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// JSON 模式:直接下载,不显示进度
|
|
35
86
|
const buffer = await client.downloadImage(file.filename, file.subfolder, file.type);
|
|
36
|
-
// 确定输出路径
|
|
37
87
|
let outputPath;
|
|
38
88
|
if (options.output) {
|
|
39
|
-
// 如果指定了输出路径
|
|
40
89
|
if (files.length === 1) {
|
|
41
|
-
// 只有一个文件,直接使用指定路径
|
|
42
90
|
outputPath = options.output;
|
|
43
91
|
}
|
|
44
92
|
else {
|
|
45
|
-
// 多个文件,将指定路径作为目录
|
|
46
93
|
const dir = options.output;
|
|
47
94
|
if (!fs.existsSync(dir)) {
|
|
48
95
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -51,33 +98,72 @@ export function registerDownloadCommand(program) {
|
|
|
51
98
|
}
|
|
52
99
|
}
|
|
53
100
|
else {
|
|
54
|
-
// 默认保存到 ./output 目录
|
|
55
101
|
const outputDir = './output';
|
|
56
102
|
if (!fs.existsSync(outputDir)) {
|
|
57
103
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
58
104
|
}
|
|
59
105
|
outputPath = path.join(outputDir, file.filename);
|
|
60
106
|
}
|
|
61
|
-
// 确保输出目录存在
|
|
62
107
|
const outputDir = path.dirname(outputPath);
|
|
63
108
|
if (!fs.existsSync(outputDir)) {
|
|
64
109
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
65
110
|
}
|
|
66
|
-
// 保存文件
|
|
67
111
|
fs.writeFileSync(outputPath, buffer);
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
downloadSpinner.fail(`下载失败: ${file.filename}`);
|
|
72
|
-
error(`错误: ${err}`);
|
|
112
|
+
downloadedFiles.push(outputPath);
|
|
73
113
|
}
|
|
74
114
|
}
|
|
75
|
-
|
|
115
|
+
if (pretty) {
|
|
116
|
+
success(`完成!共下载 ${files.length} 个文件`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
outputSuccess({
|
|
120
|
+
prompt_id: promptId,
|
|
121
|
+
files: downloadedFiles,
|
|
122
|
+
total: downloadedFiles.length,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
76
125
|
}
|
|
77
126
|
catch (err) {
|
|
78
|
-
|
|
79
|
-
process.exit(1);
|
|
127
|
+
outputError('DOWNLOAD_FAILED', `下载失败: ${err}`, options);
|
|
80
128
|
}
|
|
81
129
|
});
|
|
130
|
+
// Add enhanced help text
|
|
131
|
+
addEnhancedHelp(cmd, {
|
|
132
|
+
examples: [
|
|
133
|
+
'# 下载生成的图像(默认 JSON 输出)',
|
|
134
|
+
'$ comfy download abc-123-def',
|
|
135
|
+
'',
|
|
136
|
+
'# 指定输出路径',
|
|
137
|
+
'$ comfy download abc-123-def -o my-image.png',
|
|
138
|
+
'',
|
|
139
|
+
'# 指定输出目录(多文件时)',
|
|
140
|
+
'$ comfy download abc-123-def -o ./images/',
|
|
141
|
+
'',
|
|
142
|
+
'# Pretty 模式(显示下载进度)',
|
|
143
|
+
'$ comfy download abc-123-def --pretty',
|
|
144
|
+
],
|
|
145
|
+
outputJson: `{
|
|
146
|
+
"success": true,
|
|
147
|
+
"data": {
|
|
148
|
+
"prompt_id": "abc-123-def",
|
|
149
|
+
"files": [
|
|
150
|
+
"output/comfy-cli_00001_.png"
|
|
151
|
+
],
|
|
152
|
+
"total": 1
|
|
153
|
+
}
|
|
154
|
+
}`,
|
|
155
|
+
relatedCommands: [
|
|
156
|
+
{ command: 'generate <prompt>', description: '生成图像获取 prompt_id' },
|
|
157
|
+
{ command: 'workflow list', description: '查看历史 prompt_id' },
|
|
158
|
+
{ command: 'workflow get <id>', description: '查看工作流详情' },
|
|
159
|
+
],
|
|
160
|
+
notes: [
|
|
161
|
+
'Prompt ID 从 generate/edit/video 命令的输出中获取',
|
|
162
|
+
'默认保存到 ./output 目录',
|
|
163
|
+
'单文件时 -o 指定文件路径,多文件时 -o 指定目录',
|
|
164
|
+
'文件名保持 ComfyUI 原始命名',
|
|
165
|
+
'如果找不到文件,可能任务还在执行中',
|
|
166
|
+
],
|
|
167
|
+
});
|
|
82
168
|
}
|
|
83
169
|
//# sourceMappingURL=download.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/commands/download.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAQ,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/commands/download.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAQ,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,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EAAE,OAAO,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,yBAAyB;IACzB,eAAe,CAAC,GAAG,EAAE;QACnB,QAAQ,EAAE;YACR,uBAAuB;YACvB,8BAA8B;YAC9B,EAAE;YACF,UAAU;YACV,8CAA8C;YAC9C,EAAE;YACF,gBAAgB;YAChB,2CAA2C;YAC3C,EAAE;YACF,qBAAqB;YACrB,uCAAuC;SACxC;QACD,UAAU,EAAE;;;;;;;;;EASd;QACE,eAAe,EAAE;YACf,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,kBAAkB,EAAE;YACjE,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE;YAC3D,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,SAAS,EAAE;SACzD;QACD,KAAK,EAAE;YACL,0CAA0C;YAC1C,mBAAmB;YACnB,6BAA6B;YAC7B,oBAAoB;YACpB,mBAAmB;SACpB;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/commands/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/commands/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QAyJnD"}
|
package/dist/commands/edit.js
CHANGED
|
@@ -3,39 +3,48 @@ import * as fs from 'fs';
|
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import { ComfyAPIClient } from '../services/api.js';
|
|
5
5
|
import { loadWorkflow, getBuiltinWorkflowPath, replaceVariables } from '../utils/workflow.js';
|
|
6
|
-
import { success,
|
|
6
|
+
import { success, info } from '../utils/logger.js';
|
|
7
|
+
import { outputSuccess, outputError, isPrettyMode } from '../utils/output.js';
|
|
8
|
+
import { addEnhancedHelp } from '../utils/helpText.js';
|
|
7
9
|
import { monitorProgress } from '../services/websocket.js';
|
|
8
10
|
export function registerEditCommand(program) {
|
|
9
|
-
program
|
|
11
|
+
const cmd = program
|
|
10
12
|
.command('edit')
|
|
11
|
-
.description('
|
|
13
|
+
.description('编辑图像(图生图)- 使用 FLUX 模型对现有图像进行编辑和修改')
|
|
12
14
|
.argument('<image>', '输入图像路径')
|
|
13
15
|
.argument('<prompt>', '编辑描述提示词')
|
|
14
|
-
.option('-o, --output <dir>', '输出目录', './output')
|
|
15
|
-
.option('--no-wait', '
|
|
16
|
-
.option('--json', '输出 JSON 格式')
|
|
16
|
+
.option('-o, --output <dir>', '输出目录 (默认: ./output)', './output')
|
|
17
|
+
.option('--no-wait', '提交任务后立即返回,不等待编辑完成')
|
|
17
18
|
.action(async (image, prompt, options) => {
|
|
19
|
+
const pretty = isPrettyMode(options);
|
|
18
20
|
try {
|
|
19
21
|
// 检查图像文件是否存在
|
|
20
22
|
const imagePath = path.resolve(image);
|
|
21
23
|
if (!fs.existsSync(imagePath)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
outputError('IMAGE_NOT_FOUND', `图像文件不存在: ${imagePath}`, options);
|
|
25
|
+
}
|
|
26
|
+
if (pretty) {
|
|
27
|
+
info(`正在编辑图像: "${path.basename(image)}"`);
|
|
28
|
+
info(`提示词: "${prompt}"`);
|
|
24
29
|
}
|
|
25
|
-
info(`正在编辑图像: "${path.basename(image)}"`);
|
|
26
|
-
info(`提示词: "${prompt}"`);
|
|
27
30
|
// 先上传图像
|
|
28
|
-
const uploadSpinner = ora('正在上传图像...').start();
|
|
29
31
|
const client = new ComfyAPIClient();
|
|
30
32
|
let uploadResult;
|
|
31
|
-
|
|
33
|
+
if (pretty) {
|
|
34
|
+
const uploadSpinner = ora('正在上传图像...').start();
|
|
35
|
+
try {
|
|
36
|
+
const imageBuffer = fs.readFileSync(imagePath);
|
|
37
|
+
uploadResult = await client.uploadImage(imageBuffer, path.basename(imagePath));
|
|
38
|
+
uploadSpinner.succeed('图像上传完成');
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
uploadSpinner.fail('图像上传失败');
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
32
46
|
const imageBuffer = fs.readFileSync(imagePath);
|
|
33
47
|
uploadResult = await client.uploadImage(imageBuffer, path.basename(imagePath));
|
|
34
|
-
uploadSpinner.succeed('图像上传完成');
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
uploadSpinner.fail('图像上传失败');
|
|
38
|
-
throw err;
|
|
39
48
|
}
|
|
40
49
|
// 加载内置 workflow
|
|
41
50
|
const workflowPath = getBuiltinWorkflowPath('flux_image_to_image.json');
|
|
@@ -61,10 +70,7 @@ export function registerEditCommand(program) {
|
|
|
61
70
|
const processedWorkflow = replaceVariables(workflow, params);
|
|
62
71
|
// 提交到 ComfyUI
|
|
63
72
|
const result = await client.submitWorkflow(processedWorkflow);
|
|
64
|
-
if (
|
|
65
|
-
console.log(JSON.stringify(result, null, 2));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
73
|
+
if (pretty) {
|
|
68
74
|
success(`图像编辑任务已提交`);
|
|
69
75
|
info(`Prompt ID: ${result.prompt_id}`);
|
|
70
76
|
// 默认等待完成,除非指定了 --no-wait
|
|
@@ -95,11 +101,55 @@ export function registerEditCommand(program) {
|
|
|
95
101
|
info(`使用 'comfy download ${result.prompt_id}' 下载结果`);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
104
|
+
else {
|
|
105
|
+
outputSuccess({
|
|
106
|
+
prompt_id: result.prompt_id,
|
|
107
|
+
image: path.basename(image),
|
|
108
|
+
prompt,
|
|
109
|
+
status: options.wait !== false ? 'submitted_waiting' : 'submitted',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
98
112
|
}
|
|
99
113
|
catch (err) {
|
|
100
|
-
|
|
101
|
-
process.exit(1);
|
|
114
|
+
outputError('EDIT_FAILED', `编辑失败: ${err}`, options);
|
|
102
115
|
}
|
|
103
116
|
});
|
|
117
|
+
// Add enhanced help text
|
|
118
|
+
addEnhancedHelp(cmd, {
|
|
119
|
+
examples: [
|
|
120
|
+
'# 基础用法:编辑图像',
|
|
121
|
+
'$ comfy edit input.png "make it more colorful"',
|
|
122
|
+
'',
|
|
123
|
+
'# 添加元素到图像',
|
|
124
|
+
'$ comfy edit photo.jpg "add a rainbow in the sky"',
|
|
125
|
+
'',
|
|
126
|
+
'# 不等待完成(立即返回)',
|
|
127
|
+
'$ comfy edit image.png "remove background" --no-wait',
|
|
128
|
+
'',
|
|
129
|
+
'# Pretty 模式',
|
|
130
|
+
'$ comfy edit cat.png "add a hat" --pretty',
|
|
131
|
+
],
|
|
132
|
+
outputJson: `{
|
|
133
|
+
"success": true,
|
|
134
|
+
"data": {
|
|
135
|
+
"prompt_id": "abc-123-def",
|
|
136
|
+
"image": "input.png",
|
|
137
|
+
"prompt": "make it more colorful",
|
|
138
|
+
"status": "submitted_waiting"
|
|
139
|
+
}
|
|
140
|
+
}`,
|
|
141
|
+
relatedCommands: [
|
|
142
|
+
{ command: 'download <prompt_id>', description: '下载编辑后的图像' },
|
|
143
|
+
{ command: 'generate <prompt>', description: '从文本生成新图像' },
|
|
144
|
+
{ command: 'video <image>', description: '将图像转换为视频' },
|
|
145
|
+
],
|
|
146
|
+
notes: [
|
|
147
|
+
'图像会先上传到 ComfyUI 服务器',
|
|
148
|
+
'默认使用 FLUX 图生图模型',
|
|
149
|
+
'支持常见图像格式:PNG, JPG, JPEG',
|
|
150
|
+
'编辑完成后使用 "comfy download <prompt_id>" 下载结果',
|
|
151
|
+
'默认输出 JSON 格式,使用 --pretty 可显示上传和生成进度',
|
|
152
|
+
],
|
|
153
|
+
});
|
|
104
154
|
}
|
|
105
155
|
//# sourceMappingURL=edit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/commands/edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/commands/edit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO;SAChB,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mCAAmC,CAAC;SAChD,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC;SAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;SAC/B,MAAM,CAAC,oBAAoB,EAAE,qBAAqB,EAAE,UAAU,CAAC;SAC/D,MAAM,CA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ACnE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,aAAa,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,yBAAyB;IACzB,eAAe,CAAC,GAAG,EAAE;QACnB,QAAQ,EAAE;YACR,aAAa;YACb,gDAAgD;YAChD,EAAE;YACF,WAAW;YACX,mDAAmD;YACnD,EAAE;YACF,eAAe;YACf,sDAAsD;YACtD,EAAE;YACF,aAAa;YACb,2CAA2C;SAC5C;QACD,UAAU,EAAE;;;;;;;;EAQd;QACE,eAAe,EAAE;YACf,EAAE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,UAAU,EAAE;YAC5D,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,UAAU,EAAE;YACzD,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE;SACtD;QACD,KAAK,EAAE;YACL,qBAAqB;YACrB,iBAAiB;YACjB,yBAAyB;YACzB,2CAA2C;YAC3C,qCAAqC;SACtC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QAsIvD"}
|