dgxay-code-cli 1.0.0 → 1.1.0
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-zh.md +50 -8
- package/README.md +50 -9
- package/package.json +1 -1
- package/src/cli/ansi.js +38 -8
- package/src/cli/approval.js +11 -11
- package/src/cli/editor.js +456 -202
- package/src/cli/i18n.js +276 -0
- package/src/cli/index.js +34 -34
- package/src/cli/print.js +5 -5
- package/src/cli/render.js +147 -76
- package/src/cli/repl.js +205 -141
- package/src/cli/slash.js +29 -28
- package/src/cli/ui.js +8 -8
- package/src/commands/chat.js +45 -45
- package/src/commands/config.js +81 -81
- package/src/commands/context.js +5 -5
- package/src/commands/doctor.js +34 -34
- package/src/commands/export.js +13 -13
- package/src/commands/mcp.js +51 -51
- package/src/commands/model.js +38 -38
- package/src/commands/oauth.js +61 -61
- package/src/commands/permission.js +19 -19
- package/src/commands/provider.js +70 -70
- package/src/commands/run.js +20 -20
- package/src/commands/skill.js +15 -15
- package/src/commands/workspace.js +18 -18
- package/src/core/agent.js +19 -18
- package/src/core/llm.js +10 -10
- package/src/core/mcp.js +5 -5
- package/src/core/oauth.js +36 -36
- package/src/core/prompt.js +46 -46
- package/src/core/sessions.js +7 -7
- package/src/core/tools.js +24 -24
- package/src/services/input.js +1 -1
- package/src/services/settings.js +28 -28
- package/src/services/skills.js +1 -1
- package/src/services/terminal.js +3 -3
package/src/commands/export.js
CHANGED
|
@@ -16,20 +16,20 @@ const { actionFirst } = require('../cli/args');
|
|
|
16
16
|
const sessions = require('../core/sessions');
|
|
17
17
|
|
|
18
18
|
const options = [
|
|
19
|
-
{ name: 'format', type: 'string', valueName: 'md|json', desc: '
|
|
20
|
-
{ name: 'output', alias: 'o', type: 'string', valueName: 'file', desc: '
|
|
19
|
+
{ name: 'format', type: 'string', valueName: 'md|json', desc: 'Output format: markdown (default) / json' },
|
|
20
|
+
{ name: 'output', alias: 'o', type: 'string', valueName: 'file', desc: 'Write to a file instead of printing' }
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
function toMarkdown(chat) {
|
|
24
24
|
const lines = [];
|
|
25
25
|
const date = new Date(chat.createdAt || Date.now());
|
|
26
|
-
lines.push(`# ${chat.title || '
|
|
26
|
+
lines.push(`# ${chat.title || 'New conversation'}`);
|
|
27
27
|
lines.push('');
|
|
28
|
-
lines.push(`> ${date.toLocaleString()} · ${chat.mode === 'work' ? '
|
|
28
|
+
lines.push(`> ${date.toLocaleString()} · ${chat.mode === 'work' ? 'Work mode' : 'Chat mode'}${chat.skill ? ` · Skill ${chat.skill}` : ''}`);
|
|
29
29
|
lines.push('');
|
|
30
30
|
for (const message of chat.messages) {
|
|
31
31
|
if (message.role === 'user') {
|
|
32
|
-
lines.push('##
|
|
32
|
+
lines.push('## User');
|
|
33
33
|
lines.push('');
|
|
34
34
|
lines.push(message.content || '');
|
|
35
35
|
lines.push('');
|
|
@@ -39,17 +39,17 @@ function toMarkdown(chat) {
|
|
|
39
39
|
lines.push(message.content || '');
|
|
40
40
|
lines.push('');
|
|
41
41
|
if (message.toolLog?.length) {
|
|
42
|
-
lines.push('<details><summary
|
|
42
|
+
lines.push('<details><summary>Tool calls</summary>');
|
|
43
43
|
lines.push('');
|
|
44
44
|
for (const tool of message.toolLog) {
|
|
45
|
-
lines.push(`- \`${tool.name}\` ${tool.ok ? '
|
|
45
|
+
lines.push(`- \`${tool.name}\` ${tool.ok ? 'ok' : 'failed'}${tool.review?.reason ? ` · ${tool.review.reason}` : ''}`);
|
|
46
46
|
}
|
|
47
47
|
lines.push('');
|
|
48
48
|
lines.push('</details>');
|
|
49
49
|
lines.push('');
|
|
50
50
|
}
|
|
51
51
|
} else if (message.role === 'terminal') {
|
|
52
|
-
lines.push('##
|
|
52
|
+
lines.push('## Terminal');
|
|
53
53
|
lines.push('');
|
|
54
54
|
lines.push('```');
|
|
55
55
|
lines.push(`$ ${message.command}`);
|
|
@@ -66,12 +66,12 @@ async function run({ argv }) {
|
|
|
66
66
|
const ref = action || rest[0] || '';
|
|
67
67
|
const chats = sessions.listChats();
|
|
68
68
|
if (!chats.length) {
|
|
69
|
-
print.warn('
|
|
69
|
+
print.warn('No conversation to export yet');
|
|
70
70
|
return 1;
|
|
71
71
|
}
|
|
72
72
|
const chat = ref ? sessions.resolveChat(ref, chats) : chats[0];
|
|
73
73
|
if (!chat) {
|
|
74
|
-
print.fail(
|
|
74
|
+
print.fail(`Conversation not found: ${ref}`);
|
|
75
75
|
return 1;
|
|
76
76
|
}
|
|
77
77
|
const format = String(opts.format || 'md').toLowerCase();
|
|
@@ -84,7 +84,7 @@ async function run({ argv }) {
|
|
|
84
84
|
const target = path.resolve(opts.output);
|
|
85
85
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
86
86
|
fs.writeFileSync(target, content, 'utf8');
|
|
87
|
-
print.ok(
|
|
87
|
+
print.ok(`Exported "${chat.title}" to ${target}`);
|
|
88
88
|
return 0;
|
|
89
89
|
}
|
|
90
90
|
process.stdout.write(content.endsWith('\n') ? content : `${content}\n`);
|
|
@@ -94,8 +94,8 @@ async function run({ argv }) {
|
|
|
94
94
|
module.exports = {
|
|
95
95
|
name: 'export',
|
|
96
96
|
aliases: ['dump'],
|
|
97
|
-
summary: '
|
|
98
|
-
usage: 'dgxay export [
|
|
97
|
+
summary: 'Export a conversation as Markdown / JSON',
|
|
98
|
+
usage: 'dgxay export [n|id] [--format md|json] [-o file]',
|
|
99
99
|
options,
|
|
100
100
|
examples: ['dgxay export', 'dgxay export 2 -o chat.md', 'dgxay export -o chats.json --format json'],
|
|
101
101
|
run
|
package/src/commands/mcp.js
CHANGED
|
@@ -22,32 +22,32 @@ const cfg = require('../services/config');
|
|
|
22
22
|
const { ask } = require('../services/input');
|
|
23
23
|
|
|
24
24
|
const options = [
|
|
25
|
-
{ name: 'name', type: 'string', valueName: 'text', desc: '
|
|
26
|
-
{ name: 'command', type: 'string', valueName: 'cmd', desc: '
|
|
27
|
-
{ name: 'args', type: 'string', valueName: 'text', desc: '
|
|
28
|
-
{ name: 'env', type: 'list', valueName: 'K=V', desc: '
|
|
29
|
-
{ name: 'cwd', type: 'string', valueName: 'dir', desc: '
|
|
30
|
-
{ name: 'follow', alias: 'f', type: 'boolean', desc: 'logs
|
|
31
|
-
{ name: 'yes', alias: 'y', type: 'boolean', desc: '
|
|
25
|
+
{ name: 'name', type: 'string', valueName: 'text', desc: 'Display name' },
|
|
26
|
+
{ name: 'command', type: 'string', valueName: 'cmd', desc: 'Start command (e.g. npx / uvx)' },
|
|
27
|
+
{ name: 'args', type: 'string', valueName: 'text', desc: 'Command arguments' },
|
|
28
|
+
{ name: 'env', type: 'list', valueName: 'K=V', desc: 'Environment variables, repeatable' },
|
|
29
|
+
{ name: 'cwd', type: 'string', valueName: 'dir', desc: 'Working directory' },
|
|
30
|
+
{ name: 'follow', alias: 'f', type: 'boolean', desc: 'logs: keep streaming output' },
|
|
31
|
+
{ name: 'yes', alias: 'y', type: 'boolean', desc: 'Skip confirmation' }
|
|
32
32
|
];
|
|
33
33
|
|
|
34
34
|
function statusText(status) {
|
|
35
|
-
if (status === 'running') return COLORS.green('
|
|
36
|
-
if (status === 'error') return COLORS.red('
|
|
37
|
-
if (status === 'stopping') return COLORS.yellow('
|
|
38
|
-
return COLORS.faint('
|
|
35
|
+
if (status === 'running') return COLORS.green('running');
|
|
36
|
+
if (status === 'error') return COLORS.red('error');
|
|
37
|
+
if (status === 'stopping') return COLORS.yellow('stopping');
|
|
38
|
+
return COLORS.faint('stopped');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function list() {
|
|
42
42
|
const servers = mcp.listServers();
|
|
43
43
|
print.blank();
|
|
44
44
|
if (!servers.length) {
|
|
45
|
-
print.hint(
|
|
46
|
-
print.hint('
|
|
45
|
+
print.hint(`No MCP servers yet (config is stored in ${cfg.MCP_PATH})`);
|
|
46
|
+
print.hint('Add: dgxay mcp add --name filesystem --command npx --args "-y @modelcontextprotocol/server-filesystem ."');
|
|
47
47
|
print.blank();
|
|
48
48
|
return 0;
|
|
49
49
|
}
|
|
50
|
-
print.heading(`MCP
|
|
50
|
+
print.heading(`MCP servers (${servers.length})`);
|
|
51
51
|
const rows = servers.map((server, index) => [
|
|
52
52
|
String(index + 1),
|
|
53
53
|
server.name,
|
|
@@ -59,17 +59,17 @@ function list() {
|
|
|
59
59
|
print.table(
|
|
60
60
|
[
|
|
61
61
|
{ title: '#', max: 3 },
|
|
62
|
-
{ title: '
|
|
63
|
-
{ title: '
|
|
62
|
+
{ title: 'Name', max: 20 },
|
|
63
|
+
{ title: 'Status', max: 8 },
|
|
64
64
|
{ title: 'PID', max: 7 },
|
|
65
|
-
{ title: '
|
|
66
|
-
{ title: '
|
|
65
|
+
{ title: 'Command', max: 50 },
|
|
66
|
+
{ title: 'Working dir', max: 30 }
|
|
67
67
|
],
|
|
68
68
|
rows
|
|
69
69
|
);
|
|
70
70
|
print.blank();
|
|
71
|
-
print.hint('MCP
|
|
72
|
-
print.hint('
|
|
71
|
+
print.hint('MCP servers do not start with the app; run start manually each time');
|
|
72
|
+
print.hint('This version only manages processes; MCP tools are not yet exposed to the model');
|
|
73
73
|
print.blank();
|
|
74
74
|
return 0;
|
|
75
75
|
}
|
|
@@ -77,7 +77,7 @@ function list() {
|
|
|
77
77
|
function resolve(ref) {
|
|
78
78
|
const server = mcp.findServer(ref);
|
|
79
79
|
if (!server) {
|
|
80
|
-
print.fail(
|
|
80
|
+
print.fail(`MCP not found: ${ref}`);
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
return server;
|
|
@@ -86,10 +86,10 @@ function resolve(ref) {
|
|
|
86
86
|
async function add(opts) {
|
|
87
87
|
let name = opts.name;
|
|
88
88
|
let command = opts.command;
|
|
89
|
-
if (!name && process.stdin.isTTY) name = String((await ask('
|
|
90
|
-
if (!command && process.stdin.isTTY) command = String((await ask('
|
|
89
|
+
if (!name && process.stdin.isTTY) name = String((await ask('Name: ')) || '').trim();
|
|
90
|
+
if (!command && process.stdin.isTTY) command = String((await ask('Start command (e.g. npx): ')) || '').trim();
|
|
91
91
|
if (!name || !command) {
|
|
92
|
-
throw Object.assign(new Error('
|
|
92
|
+
throw Object.assign(new Error('Usage: dgxay mcp add --name <name> --command <command> [--args "..."]'), {
|
|
93
93
|
userError: true
|
|
94
94
|
});
|
|
95
95
|
}
|
|
@@ -100,8 +100,8 @@ async function add(opts) {
|
|
|
100
100
|
env: (opts.env || []).join('\n'),
|
|
101
101
|
cwd: opts.cwd || ''
|
|
102
102
|
});
|
|
103
|
-
print.ok(
|
|
104
|
-
print.hint(
|
|
103
|
+
print.ok(`Saved MCP server "${server.name}" (${server.id})`);
|
|
104
|
+
print.hint(`Start: dgxay mcp start ${server.name}`);
|
|
105
105
|
return 0;
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -110,9 +110,9 @@ function start(ref) {
|
|
|
110
110
|
if (!server) return 1;
|
|
111
111
|
try {
|
|
112
112
|
const result = mcp.startServer(server.id);
|
|
113
|
-
if (result.status === 'running' && result.pid) print.ok(
|
|
114
|
-
else print.ok(`${server.name}
|
|
115
|
-
print.hint(
|
|
113
|
+
if (result.status === 'running' && result.pid) print.ok(`Started ${server.name} (pid ${result.pid})`);
|
|
114
|
+
else print.ok(`${server.name} is already running`);
|
|
115
|
+
print.hint(`View logs: dgxay mcp logs ${server.name}`);
|
|
116
116
|
return 0;
|
|
117
117
|
} catch (err) {
|
|
118
118
|
print.fail(err.message);
|
|
@@ -124,8 +124,8 @@ function stop(ref) {
|
|
|
124
124
|
const server = resolve(ref);
|
|
125
125
|
if (!server) return 1;
|
|
126
126
|
const ok = mcp.stopServer(server.id);
|
|
127
|
-
if (ok) print.ok(
|
|
128
|
-
else print.warn(`${server.name}
|
|
127
|
+
if (ok) print.ok(`Stopped ${server.name}`);
|
|
128
|
+
else print.warn(`${server.name} is not running`);
|
|
129
129
|
return 0;
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -144,10 +144,10 @@ async function logs(ref, opts) {
|
|
|
144
144
|
};
|
|
145
145
|
printLogs();
|
|
146
146
|
if (!opts.follow) {
|
|
147
|
-
if (!shown.size) print.hint('
|
|
147
|
+
if (!shown.size) print.hint('No logs yet');
|
|
148
148
|
return 0;
|
|
149
149
|
}
|
|
150
|
-
print.hint('
|
|
150
|
+
print.hint('Streaming; press Ctrl+C to exit');
|
|
151
151
|
mcp.setNotifier((event) => {
|
|
152
152
|
if (event.type === 'log' && event.id === server.id) {
|
|
153
153
|
print.write(event.stream === 'stderr' ? COLORS.red(event.text) : event.text);
|
|
@@ -163,14 +163,14 @@ async function remove(ref, opts) {
|
|
|
163
163
|
const server = resolve(ref);
|
|
164
164
|
if (!server) return 1;
|
|
165
165
|
if (!opts.yes && process.stdin.isTTY) {
|
|
166
|
-
const answer = await ask(
|
|
166
|
+
const answer = await ask(`Delete MCP server "${server.name}" and stop its process? [y/N] `);
|
|
167
167
|
if (!/^y/i.test(String(answer || '').trim())) {
|
|
168
|
-
print.hint('
|
|
168
|
+
print.hint('Cancelled');
|
|
169
169
|
return 1;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
mcp.removeServer(server.id);
|
|
173
|
-
print.ok(
|
|
173
|
+
print.ok(`Deleted ${server.name}`);
|
|
174
174
|
return 0;
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -189,8 +189,8 @@ function updateEnv(ref, opts) {
|
|
|
189
189
|
env,
|
|
190
190
|
cwd: server.cwd
|
|
191
191
|
});
|
|
192
|
-
print.ok(
|
|
193
|
-
print.warn('
|
|
192
|
+
print.ok(`Updated environment variables for ${server.name} (${Object.keys(env).length} entries)`);
|
|
193
|
+
print.warn('Takes effect after restart: dgxay mcp stop ' + server.name + ' && dgxay mcp start ' + server.name);
|
|
194
194
|
return 0;
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -212,22 +212,22 @@ async function run({ argv }) {
|
|
|
212
212
|
return add(opts);
|
|
213
213
|
case 'start':
|
|
214
214
|
case 'run':
|
|
215
|
-
if (!ref) throw Object.assign(new Error('
|
|
215
|
+
if (!ref) throw Object.assign(new Error('Usage: dgxay mcp start <name|id>'), { userError: true });
|
|
216
216
|
return start(ref);
|
|
217
217
|
case 'stop':
|
|
218
|
-
if (!ref) throw Object.assign(new Error('
|
|
218
|
+
if (!ref) throw Object.assign(new Error('Usage: dgxay mcp stop <name|id>'), { userError: true });
|
|
219
219
|
return stop(ref);
|
|
220
220
|
case 'logs':
|
|
221
221
|
case 'log':
|
|
222
|
-
if (!ref) throw Object.assign(new Error('
|
|
222
|
+
if (!ref) throw Object.assign(new Error('Usage: dgxay mcp logs <name|id> [-f]'), { userError: true });
|
|
223
223
|
return logs(ref, opts);
|
|
224
224
|
case 'rm':
|
|
225
225
|
case 'remove':
|
|
226
226
|
case 'delete':
|
|
227
|
-
if (!ref) throw Object.assign(new Error('
|
|
227
|
+
if (!ref) throw Object.assign(new Error('Usage: dgxay mcp rm <name|id>'), { userError: true });
|
|
228
228
|
return remove(ref, opts);
|
|
229
229
|
case 'env':
|
|
230
|
-
if (!ref) throw Object.assign(new Error('
|
|
230
|
+
if (!ref) throw Object.assign(new Error('Usage: dgxay mcp env <name|id> --env "KEY=value"'), { userError: true });
|
|
231
231
|
return updateEnv(ref, opts);
|
|
232
232
|
default:
|
|
233
233
|
return 1;
|
|
@@ -236,17 +236,17 @@ async function run({ argv }) {
|
|
|
236
236
|
|
|
237
237
|
module.exports = {
|
|
238
238
|
name: 'mcp',
|
|
239
|
-
summary: 'MCP
|
|
239
|
+
summary: 'Manage MCP servers',
|
|
240
240
|
usage: 'dgxay mcp <list|add|start|stop|logs|rm|env>',
|
|
241
241
|
options,
|
|
242
242
|
subcommands: [
|
|
243
|
-
['list', '
|
|
244
|
-
['add', '
|
|
245
|
-
['start
|
|
246
|
-
['stop
|
|
247
|
-
['logs
|
|
248
|
-
['rm
|
|
249
|
-
['env
|
|
243
|
+
['list', 'List MCP servers'],
|
|
244
|
+
['add', 'Add a server'],
|
|
245
|
+
['start <name>', 'Start the process'],
|
|
246
|
+
['stop <name>', 'Stop the process'],
|
|
247
|
+
['logs <name> [-f]', 'View logs'],
|
|
248
|
+
['rm <name>', 'Delete'],
|
|
249
|
+
['env <name> --env K=V', 'Update environment variables']
|
|
250
250
|
],
|
|
251
251
|
examples: [
|
|
252
252
|
'dgxay mcp add --name filesystem --command npx --args "-y @modelcontextprotocol/server-filesystem ."',
|
package/src/commands/model.js
CHANGED
|
@@ -18,26 +18,26 @@ const sessions = require('../core/sessions');
|
|
|
18
18
|
const { askSecret } = require('../services/input');
|
|
19
19
|
|
|
20
20
|
const options = [
|
|
21
|
-
{ name: 'provider', alias: 'p', type: 'string', valueName: 'name', desc: '
|
|
22
|
-
{ name: 'name', type: 'string', valueName: 'text', desc: '
|
|
23
|
-
{ name: 'context-window', type: 'number', valueName: 'n', desc: '
|
|
24
|
-
{ name: 'base-url', type: 'string', valueName: 'url', desc: '
|
|
25
|
-
{ name: 'api-key', type: 'string', valueName: 'key', desc: '
|
|
26
|
-
{ name: 'add', type: 'list', valueName: 'id', desc: '
|
|
21
|
+
{ name: 'provider', alias: 'p', type: 'string', valueName: 'name', desc: 'Target provider (default: active provider)' },
|
|
22
|
+
{ name: 'name', type: 'string', valueName: 'text', desc: 'Display name' },
|
|
23
|
+
{ name: 'context-window', type: 'number', valueName: 'n', desc: 'Context window' },
|
|
24
|
+
{ name: 'base-url', type: 'string', valueName: 'url', desc: 'Use this base URL when fetching the list' },
|
|
25
|
+
{ name: 'api-key', type: 'string', valueName: 'key', desc: 'Use this key when fetching the list' },
|
|
26
|
+
{ name: 'add', type: 'list', valueName: 'id', desc: 'Add the given models to the provider after fetching' }
|
|
27
27
|
];
|
|
28
28
|
|
|
29
29
|
function list(providerRef) {
|
|
30
30
|
const config = settings.readConfig();
|
|
31
31
|
const provider = providerRef ? settings.findProvider(providerRef) : settings.activeProvider(config);
|
|
32
32
|
if (!provider) {
|
|
33
|
-
print.warn('
|
|
33
|
+
print.warn('No providers yet, run dgxay config init');
|
|
34
34
|
return 1;
|
|
35
35
|
}
|
|
36
36
|
const models = provider.models || [];
|
|
37
37
|
print.blank();
|
|
38
|
-
print.heading(
|
|
38
|
+
print.heading(`Models for ${provider.name} (${models.length})`);
|
|
39
39
|
if (!models.length) {
|
|
40
|
-
print.hint('
|
|
40
|
+
print.hint(' No models yet, run dgxay model add <id>');
|
|
41
41
|
print.blank();
|
|
42
42
|
return 0;
|
|
43
43
|
}
|
|
@@ -47,16 +47,16 @@ function list(providerRef) {
|
|
|
47
47
|
model.id === active ? COLORS.accent('❯') : ' ',
|
|
48
48
|
model.name || model.id,
|
|
49
49
|
model.id,
|
|
50
|
-
model.contextWindow ? sessions.formatTokens(model.contextWindow) : COLORS.faint('
|
|
51
|
-
provider.reviewModelId === model.id ? '
|
|
50
|
+
model.contextWindow ? sessions.formatTokens(model.contextWindow) : COLORS.faint('protocol default'),
|
|
51
|
+
provider.reviewModelId === model.id ? 'review' : ''
|
|
52
52
|
]);
|
|
53
53
|
print.table(
|
|
54
54
|
[
|
|
55
55
|
{ title: '#', max: 3 },
|
|
56
56
|
{ title: '', max: 1 },
|
|
57
|
-
{ title: '
|
|
57
|
+
{ title: 'Name', max: 26 },
|
|
58
58
|
{ title: 'ID', max: 32 },
|
|
59
|
-
{ title: '
|
|
59
|
+
{ title: 'Context', max: 10 },
|
|
60
60
|
{ title: '', max: 4 }
|
|
61
61
|
],
|
|
62
62
|
rows
|
|
@@ -73,7 +73,7 @@ async function fetchList(opts) {
|
|
|
73
73
|
const secret = await askSecret('API Key: ');
|
|
74
74
|
apiKey = secret || '';
|
|
75
75
|
}
|
|
76
|
-
process.stdout.write(`${COLORS.faint('
|
|
76
|
+
process.stdout.write(`${COLORS.faint('Fetching model list...')}`);
|
|
77
77
|
try {
|
|
78
78
|
let models;
|
|
79
79
|
if (opts.baseUrl) {
|
|
@@ -83,22 +83,22 @@ async function fetchList(opts) {
|
|
|
83
83
|
protocol: opts.protocol || provider?.protocol || 'openai'
|
|
84
84
|
});
|
|
85
85
|
} else {
|
|
86
|
-
if (!provider) throw new Error('
|
|
86
|
+
if (!provider) throw new Error('No provider available');
|
|
87
87
|
models = await settings.fetchModels({ providerRef: provider.id, apiKey });
|
|
88
88
|
}
|
|
89
89
|
process.stdout.write('\r\x1b[2K');
|
|
90
|
-
print.ok(
|
|
90
|
+
print.ok(`Fetched ${models.length} model(s)`);
|
|
91
91
|
const existing = new Set((provider?.models || []).map((m) => m.id));
|
|
92
92
|
for (const id of models) {
|
|
93
93
|
print.write(` ${existing.has(id) ? COLORS.green('✓') : ' '} ${id}`);
|
|
94
94
|
}
|
|
95
95
|
print.blank();
|
|
96
|
-
print.hint('
|
|
96
|
+
print.hint('Use dgxay model add <id> to add to the provider; if fetching fails you can type the model ID manually');
|
|
97
97
|
return 0;
|
|
98
98
|
} catch (err) {
|
|
99
99
|
process.stdout.write('\r\x1b[2K');
|
|
100
|
-
print.fail(
|
|
101
|
-
print.hint('
|
|
100
|
+
print.fail(`Fetch failed: ${err.message}`);
|
|
101
|
+
print.hint('Some gateways do not support the /models endpoint; add models manually with dgxay model add <id>');
|
|
102
102
|
return 1;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -107,12 +107,12 @@ function addModel(id, opts) {
|
|
|
107
107
|
const config = settings.readConfig();
|
|
108
108
|
const provider = opts.provider ? settings.findProvider(opts.provider) : settings.activeProvider(config);
|
|
109
109
|
if (!provider) {
|
|
110
|
-
print.warn('
|
|
110
|
+
print.warn('No providers yet, run dgxay config init');
|
|
111
111
|
return 1;
|
|
112
112
|
}
|
|
113
113
|
const models = (provider.models || []).slice();
|
|
114
114
|
if (models.some((m) => m.id === id)) {
|
|
115
|
-
print.warn(
|
|
115
|
+
print.warn(`Model ${id} already exists`);
|
|
116
116
|
return 1;
|
|
117
117
|
}
|
|
118
118
|
models.push({
|
|
@@ -124,7 +124,7 @@ function addModel(id, opts) {
|
|
|
124
124
|
const patch = { providers: next };
|
|
125
125
|
if (provider.id === config.activeProviderId && !config.activeModelId) patch.activeModelId = id;
|
|
126
126
|
settings.saveConfig(patch);
|
|
127
|
-
print.ok(
|
|
127
|
+
print.ok(`Model added: ${id}`);
|
|
128
128
|
return 0;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -132,16 +132,16 @@ function removeModel(id, opts) {
|
|
|
132
132
|
const config = settings.readConfig();
|
|
133
133
|
const provider = opts.provider ? settings.findProvider(opts.provider) : settings.activeProvider(config);
|
|
134
134
|
if (!provider) {
|
|
135
|
-
print.warn('
|
|
135
|
+
print.warn('No providers yet');
|
|
136
136
|
return 1;
|
|
137
137
|
}
|
|
138
138
|
const models = (provider.models || []).filter((m) => m.id !== id);
|
|
139
139
|
if (models.length === (provider.models || []).length) {
|
|
140
|
-
print.fail(
|
|
140
|
+
print.fail(`Provider ${provider.name} has no model ${id}`);
|
|
141
141
|
return 1;
|
|
142
142
|
}
|
|
143
143
|
if (!models.length) {
|
|
144
|
-
print.fail('
|
|
144
|
+
print.fail('Cannot delete the last model; add another model first');
|
|
145
145
|
return 1;
|
|
146
146
|
}
|
|
147
147
|
const reviewModelId = models.some((m) => m.id === provider.reviewModelId)
|
|
@@ -153,7 +153,7 @@ function removeModel(id, opts) {
|
|
|
153
153
|
const patch = { providers: next };
|
|
154
154
|
if (config.activeModelId === id) patch.activeModelId = models[0].id;
|
|
155
155
|
settings.saveConfig(patch);
|
|
156
|
-
print.ok(
|
|
156
|
+
print.ok(`Model deleted: ${id}`);
|
|
157
157
|
return 0;
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -161,7 +161,7 @@ function useModel(ref, opts) {
|
|
|
161
161
|
const config = settings.readConfig();
|
|
162
162
|
const provider = opts.provider ? settings.findProvider(opts.provider) : settings.activeProvider(config);
|
|
163
163
|
if (!provider) {
|
|
164
|
-
print.warn('
|
|
164
|
+
print.warn('No providers yet');
|
|
165
165
|
return 1;
|
|
166
166
|
}
|
|
167
167
|
const models = provider.models || [];
|
|
@@ -171,11 +171,11 @@ function useModel(ref, opts) {
|
|
|
171
171
|
models.find((m) => m.id === ref) ||
|
|
172
172
|
models.find((m) => m.id.includes(ref));
|
|
173
173
|
if (!target) {
|
|
174
|
-
print.fail(
|
|
174
|
+
print.fail(`Model not found: ${ref}`);
|
|
175
175
|
return 1;
|
|
176
176
|
}
|
|
177
177
|
settings.setActiveModel(provider.id, target.id);
|
|
178
|
-
print.ok(
|
|
178
|
+
print.ok(`Active model: ${target.name || target.id} (${provider.name})`);
|
|
179
179
|
return 0;
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -185,17 +185,17 @@ async function run({ argv }) {
|
|
|
185
185
|
|
|
186
186
|
// model add deepseek-chat gpt-4o 支持多个
|
|
187
187
|
if (action === 'add') {
|
|
188
|
-
if (!rest.length) throw Object.assign(new Error('
|
|
188
|
+
if (!rest.length) throw Object.assign(new Error('Usage: dgxay model add <id> [<id>...]'), { userError: true });
|
|
189
189
|
let code = 0;
|
|
190
190
|
for (const id of rest) code = Math.max(code, addModel(id, opts));
|
|
191
191
|
return code;
|
|
192
192
|
}
|
|
193
193
|
if (action === 'rm' || action === 'remove' || action === 'delete') {
|
|
194
|
-
if (!rest[0]) throw Object.assign(new Error('
|
|
194
|
+
if (!rest[0]) throw Object.assign(new Error('Usage: dgxay model rm <id>'), { userError: true });
|
|
195
195
|
return removeModel(rest[0], opts);
|
|
196
196
|
}
|
|
197
197
|
if (action === 'use' || action === 'set') {
|
|
198
|
-
if (!rest[0]) throw Object.assign(new Error('
|
|
198
|
+
if (!rest[0]) throw Object.assign(new Error('Usage: dgxay model use <id|index>'), { userError: true });
|
|
199
199
|
return useModel(rest[0], opts);
|
|
200
200
|
}
|
|
201
201
|
if (action === 'fetch' || action === 'ls-remote') return fetchList(opts);
|
|
@@ -208,15 +208,15 @@ async function run({ argv }) {
|
|
|
208
208
|
module.exports = {
|
|
209
209
|
name: 'model',
|
|
210
210
|
aliases: ['models'],
|
|
211
|
-
summary: '
|
|
211
|
+
summary: 'Model management: list, switch, add/remove, fetch',
|
|
212
212
|
usage: 'dgxay model <list|use|add|rm|fetch>',
|
|
213
213
|
options,
|
|
214
214
|
subcommands: [
|
|
215
|
-
['list', '
|
|
216
|
-
['use <id
|
|
217
|
-
['add <id>', '
|
|
218
|
-
['rm <id>', '
|
|
219
|
-
['fetch', '
|
|
215
|
+
['list', 'List models'],
|
|
216
|
+
['use <id|index>', 'Switch the active model'],
|
|
217
|
+
['add <id>', 'Add a model'],
|
|
218
|
+
['rm <id>', 'Delete a model'],
|
|
219
|
+
['fetch', 'Fetch the model list from the provider API']
|
|
220
220
|
],
|
|
221
221
|
examples: ['dgxay model list', 'dgxay model use 2', 'dgxay model add gpt-4o --name GPT-4o', 'dgxay model fetch'],
|
|
222
222
|
run
|