thatgfsj-code 0.9.3 → 0.9.5
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/cmd/index.js +1 -1
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/app.js +49 -20
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/components/Header.js +1 -1
- package/dist/tui/components/ModelSelector.d.ts +2 -2
- package/dist/tui/components/ModelSelector.d.ts.map +1 -1
- package/dist/tui/components/ModelSelector.js +53 -25
- package/dist/tui/components/ModelSelector.js.map +1 -1
- package/dist/tui/components/StatusBar.js +1 -1
- package/dist/tui/components/StatusBar.js.map +1 -1
- package/dist/tui/components/UserInput.d.ts.map +1 -1
- package/dist/tui/components/UserInput.js +28 -2
- package/dist/tui/components/UserInput.js.map +1 -1
- package/dist/tui/hooks/useChat.d.ts +1 -0
- package/dist/tui/hooks/useChat.d.ts.map +1 -1
- package/dist/tui/hooks/useChat.js +109 -96
- package/dist/tui/hooks/useChat.js.map +1 -1
- package/dist/tui/hooks/useCommands.d.ts +4 -0
- package/dist/tui/hooks/useCommands.d.ts.map +1 -1
- package/dist/tui/hooks/useCommands.js +58 -30
- package/dist/tui/hooks/useCommands.js.map +1 -1
- package/package.json +1 -1
- package/src/cmd/index.tsx +1 -1
- package/src/tui/app.tsx +57 -21
- package/src/tui/components/Header.tsx +1 -1
- package/src/tui/components/ModelSelector.tsx +65 -39
- package/src/tui/components/StatusBar.tsx +2 -2
- package/src/tui/components/UserInput.tsx +53 -6
- package/src/tui/hooks/useChat.ts +109 -95
- package/src/tui/hooks/useCommands.ts +61 -30
|
@@ -5,128 +5,141 @@ export function useChat(app) {
|
|
|
5
5
|
isThinking: false,
|
|
6
6
|
streaming: '',
|
|
7
7
|
streamingToolCalls: [],
|
|
8
|
+
queuedMessage: null,
|
|
8
9
|
});
|
|
9
10
|
const processingRef = useRef(false);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return;
|
|
13
|
-
processingRef.current = true;
|
|
11
|
+
const queuedRef = useRef(null);
|
|
12
|
+
const processStream = async (input) => {
|
|
14
13
|
setState(prev => ({
|
|
15
14
|
...prev,
|
|
16
15
|
messages: [...prev.messages, { role: 'user', content: input }],
|
|
17
16
|
isThinking: true,
|
|
18
17
|
streaming: '',
|
|
19
18
|
streamingToolCalls: [],
|
|
19
|
+
queuedMessage: null,
|
|
20
20
|
}));
|
|
21
21
|
app.session.addMessage('user', input);
|
|
22
22
|
const stream = app.streamResponse();
|
|
23
23
|
let fullContent = '';
|
|
24
24
|
let currentToolCalls = [];
|
|
25
25
|
let lastUpdateTime = 0;
|
|
26
|
-
const THROTTLE_MS = 50;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
else if (data.action === 'result') {
|
|
45
|
-
const lastIdx = currentToolCalls.length - 1;
|
|
46
|
-
if (lastIdx >= 0) {
|
|
47
|
-
currentToolCalls[lastIdx] = {
|
|
48
|
-
...currentToolCalls[lastIdx],
|
|
49
|
-
result: data.output || data.error || '',
|
|
50
|
-
isError: !!data.error,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
setState(prev => ({
|
|
54
|
-
...prev,
|
|
55
|
-
streamingToolCalls: [...currentToolCalls],
|
|
56
|
-
isThinking: true,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
26
|
+
const THROTTLE_MS = 50;
|
|
27
|
+
try {
|
|
28
|
+
for await (const chunk of stream) {
|
|
29
|
+
if (chunk.includes('@@TOOL@@')) {
|
|
30
|
+
const parts = chunk.split('\n');
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
if (part.startsWith('@@TOOL@@')) {
|
|
33
|
+
try {
|
|
34
|
+
const data = JSON.parse(part.slice(8));
|
|
35
|
+
if (data.action === 'call') {
|
|
36
|
+
currentToolCalls.push({ name: data.name, args: data.args || '' });
|
|
37
|
+
setState(prev => ({
|
|
38
|
+
...prev,
|
|
39
|
+
isThinking: false,
|
|
40
|
+
streamingToolCalls: [...currentToolCalls],
|
|
41
|
+
}));
|
|
59
42
|
}
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
else if (data.action === 'result') {
|
|
44
|
+
const lastIdx = currentToolCalls.length - 1;
|
|
45
|
+
if (lastIdx >= 0) {
|
|
46
|
+
currentToolCalls[lastIdx] = {
|
|
47
|
+
...currentToolCalls[lastIdx],
|
|
48
|
+
result: data.output || data.error || '',
|
|
49
|
+
isError: !!data.error,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
setState(prev => ({
|
|
53
|
+
...prev,
|
|
54
|
+
streamingToolCalls: [...currentToolCalls],
|
|
55
|
+
isThinking: true,
|
|
56
|
+
}));
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
|
-
|
|
59
|
+
catch {
|
|
65
60
|
fullContent += part;
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
// Throttle UI updates
|
|
73
|
-
const now = Date.now();
|
|
74
|
-
if (now - lastUpdateTime >= THROTTLE_MS) {
|
|
75
|
-
lastUpdateTime = now;
|
|
76
|
-
setState(prev => ({ ...prev, isThinking: false, streaming: fullContent }));
|
|
63
|
+
else if (part) {
|
|
64
|
+
fullContent += part;
|
|
65
|
+
}
|
|
77
66
|
}
|
|
78
67
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
app.session.addMessage('assistant', fullContent);
|
|
68
|
+
else {
|
|
69
|
+
fullContent += chunk;
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
...(fullContent.trim() || currentToolCalls.length > 0
|
|
88
|
-
? [{
|
|
89
|
-
role: 'assistant',
|
|
90
|
-
content: fullContent,
|
|
91
|
-
toolCalls: currentToolCalls.length > 0 ? currentToolCalls : undefined,
|
|
92
|
-
}]
|
|
93
|
-
: []),
|
|
94
|
-
],
|
|
95
|
-
streaming: '',
|
|
96
|
-
streamingToolCalls: [],
|
|
97
|
-
isThinking: false,
|
|
98
|
-
}));
|
|
99
|
-
app.session.truncate();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
const msg = error.message || String(error);
|
|
103
|
-
let errorMsg = `Error: ${msg}`;
|
|
104
|
-
if (msg.includes('401') || msg.includes('403') || msg.includes('Unauthorized')) {
|
|
105
|
-
errorMsg = `❌ API key invalid. Run \`gfcode init\` to reconfigure.`;
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
if (now - lastUpdateTime >= THROTTLE_MS) {
|
|
73
|
+
lastUpdateTime = now;
|
|
74
|
+
setState(prev => ({ ...prev, isThinking: false, streaming: fullContent }));
|
|
106
75
|
}
|
|
107
|
-
else if (msg.includes('429') || msg.includes('rate limit') || msg.includes('quota')) {
|
|
108
|
-
errorMsg = `❌ Rate limit exceeded. Wait or run \`gfcode init\` to switch provider.`;
|
|
109
|
-
}
|
|
110
|
-
else if (msg.includes('ECONNREFUSED') || msg.includes('ENOTFOUND')) {
|
|
111
|
-
errorMsg = `❌ Cannot connect. Check network or run \`gfcode init\`.`;
|
|
112
|
-
}
|
|
113
|
-
setState(prev => ({
|
|
114
|
-
...prev,
|
|
115
|
-
messages: [
|
|
116
|
-
...prev.messages,
|
|
117
|
-
...(fullContent.trim()
|
|
118
|
-
? [{ role: 'assistant', content: fullContent }]
|
|
119
|
-
: []),
|
|
120
|
-
{ role: 'assistant', content: errorMsg },
|
|
121
|
-
],
|
|
122
|
-
streaming: '',
|
|
123
|
-
streamingToolCalls: [],
|
|
124
|
-
isThinking: false,
|
|
125
|
-
}));
|
|
126
76
|
}
|
|
77
|
+
if (fullContent.trim() || currentToolCalls.length > 0) {
|
|
78
|
+
app.session.addMessage('assistant', fullContent);
|
|
79
|
+
}
|
|
80
|
+
setState(prev => ({
|
|
81
|
+
...prev,
|
|
82
|
+
messages: [
|
|
83
|
+
...prev.messages,
|
|
84
|
+
...(fullContent.trim() || currentToolCalls.length > 0
|
|
85
|
+
? [{
|
|
86
|
+
role: 'assistant',
|
|
87
|
+
content: fullContent,
|
|
88
|
+
toolCalls: currentToolCalls.length > 0 ? currentToolCalls : undefined,
|
|
89
|
+
}]
|
|
90
|
+
: []),
|
|
91
|
+
],
|
|
92
|
+
streaming: '',
|
|
93
|
+
streamingToolCalls: [],
|
|
94
|
+
isThinking: false,
|
|
95
|
+
}));
|
|
96
|
+
app.session.truncate();
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const msg = error.message || String(error);
|
|
100
|
+
let errorMsg = `Error: ${msg}`;
|
|
101
|
+
if (msg.includes('401') || msg.includes('403') || msg.includes('Unauthorized')) {
|
|
102
|
+
errorMsg = `❌ API key invalid. Run \`gfcode init\` to reconfigure.`;
|
|
103
|
+
}
|
|
104
|
+
else if (msg.includes('429') || msg.includes('rate limit') || msg.includes('quota')) {
|
|
105
|
+
errorMsg = `❌ Rate limit exceeded. Wait or run \`gfcode init\` to switch provider.`;
|
|
106
|
+
}
|
|
107
|
+
else if (msg.includes('ECONNREFUSED') || msg.includes('ENOTFOUND')) {
|
|
108
|
+
errorMsg = `❌ Cannot connect. Check network or run \`gfcode init\`.`;
|
|
109
|
+
}
|
|
110
|
+
setState(prev => ({
|
|
111
|
+
...prev,
|
|
112
|
+
messages: [
|
|
113
|
+
...prev.messages,
|
|
114
|
+
...(fullContent.trim()
|
|
115
|
+
? [{ role: 'assistant', content: fullContent }]
|
|
116
|
+
: []),
|
|
117
|
+
{ role: 'assistant', content: errorMsg },
|
|
118
|
+
],
|
|
119
|
+
streaming: '',
|
|
120
|
+
streamingToolCalls: [],
|
|
121
|
+
isThinking: false,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
// Check if there's a queued message
|
|
125
|
+
if (queuedRef.current) {
|
|
126
|
+
const next = queuedRef.current;
|
|
127
|
+
queuedRef.current = null;
|
|
128
|
+
await processStream(next);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
127
131
|
processingRef.current = false;
|
|
128
|
-
}
|
|
129
|
-
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const sendMessage = useCallback((input) => {
|
|
135
|
+
// If currently processing, queue the message
|
|
136
|
+
if (processingRef.current) {
|
|
137
|
+
queuedRef.current = input;
|
|
138
|
+
setState(prev => ({ ...prev, queuedMessage: input }));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
processingRef.current = true;
|
|
142
|
+
processStream(input);
|
|
130
143
|
}, [app]);
|
|
131
144
|
return { ...state, sendMessage };
|
|
132
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../../src/tui/hooks/useChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../../src/tui/hooks/useChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAatD,MAAM,UAAU,OAAO,CAAC,GAAQ;IAC9B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAY;QAC5C,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,EAAE;QACb,kBAAkB,EAAE,EAAE;QACtB,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAE9C,MAAM,aAAa,GAAG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AAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACtD,OAAO;QACT,CAAC;QAED,aAAa,CAAC,OAAO,GAAG,IAAI,CAAC;QAC7B,aAAa,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -4,6 +4,10 @@ interface CommandResult {
|
|
|
4
4
|
output?: string;
|
|
5
5
|
action?: 'clear' | 'reinit';
|
|
6
6
|
}
|
|
7
|
+
export declare const COMMAND_LIST: {
|
|
8
|
+
name: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
}[];
|
|
7
11
|
export declare function useCommands(app: App): {
|
|
8
12
|
handleCommand: (input: string) => CommandResult;
|
|
9
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommands.d.ts","sourceRoot":"","sources":["../../../src/tui/hooks/useCommands.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B;
|
|
1
|
+
{"version":3,"file":"useCommands.d.ts","sourceRoot":"","sources":["../../../src/tui/hooks/useCommands.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE9C,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B;AAeD,eAAO,MAAM,YAAY;;;GAQxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG;2BAEQ,MAAM,KAAG,aAAa;EAuHjE"}
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
+
// 中文命令别名映射
|
|
3
|
+
const CMD_ALIASES = {
|
|
4
|
+
'/模型': '/model',
|
|
5
|
+
'/新建': '/new',
|
|
6
|
+
'/清空': '/new',
|
|
7
|
+
'/压缩': '/compact',
|
|
8
|
+
'/技能': '/skills',
|
|
9
|
+
'/技能管理': '/skills',
|
|
10
|
+
'/mcp': '/mcp',
|
|
11
|
+
'/帮助': '/help',
|
|
12
|
+
'/服务商': '/provider',
|
|
13
|
+
};
|
|
14
|
+
export const COMMAND_LIST = [
|
|
15
|
+
{ name: '/模型', desc: '切换模型' },
|
|
16
|
+
{ name: '/服务商', desc: '更换服务商' },
|
|
17
|
+
{ name: '/新建', desc: '新建会话' },
|
|
18
|
+
{ name: '/压缩', desc: '压缩上下文' },
|
|
19
|
+
{ name: '/技能', desc: '管理技能' },
|
|
20
|
+
{ name: '/mcp', desc: 'MCP 设置' },
|
|
21
|
+
{ name: '/帮助', desc: '查看帮助' },
|
|
22
|
+
];
|
|
2
23
|
export function useCommands(app) {
|
|
3
24
|
const handleCommand = useCallback((input) => {
|
|
4
25
|
const cmd = input.trim();
|
|
5
26
|
const parts = cmd.split(/\s+/);
|
|
6
|
-
|
|
27
|
+
let name = parts[0].toLowerCase();
|
|
7
28
|
const arg = parts.slice(1).join(' ');
|
|
29
|
+
// 中文别名映射
|
|
30
|
+
if (CMD_ALIASES[name]) {
|
|
31
|
+
name = CMD_ALIASES[name];
|
|
32
|
+
}
|
|
8
33
|
// ── /model [name] ───────────────────────────────────
|
|
9
34
|
if (name === '/model') {
|
|
10
35
|
if (!arg) {
|
|
@@ -12,59 +37,57 @@ export function useCommands(app) {
|
|
|
12
37
|
return {
|
|
13
38
|
handled: true,
|
|
14
39
|
output: [
|
|
15
|
-
|
|
40
|
+
`当前: ${c.provider} / ${c.model}`,
|
|
16
41
|
'',
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
' /model qwen3-235b-a22b',
|
|
42
|
+
'用法: /模型 <名称>',
|
|
43
|
+
' /模型 deepseek-chat',
|
|
44
|
+
' /模型 gpt-4o',
|
|
45
|
+
' /模型 claude-sonnet-4-20250514',
|
|
22
46
|
'',
|
|
23
|
-
'
|
|
47
|
+
'或: /服务商 更换服务商',
|
|
24
48
|
].join('\n'),
|
|
25
49
|
};
|
|
26
50
|
}
|
|
27
51
|
app.config.save({ model: arg });
|
|
28
|
-
return { handled: true, output:
|
|
52
|
+
return { handled: true, output: `模型 → ${arg}` };
|
|
29
53
|
}
|
|
30
54
|
// ── /provider ───────────────────────────────────────
|
|
31
55
|
if (name === '/provider') {
|
|
32
56
|
return { handled: true, action: 'reinit' };
|
|
33
57
|
}
|
|
34
58
|
// ── /new, /clear ────────────────────────────────────
|
|
35
|
-
if (name === '/new'
|
|
59
|
+
if (name === '/new') {
|
|
36
60
|
app.session.clear();
|
|
37
|
-
return { handled: true, output: '
|
|
61
|
+
return { handled: true, output: '新会话已创建。', action: 'clear' };
|
|
38
62
|
}
|
|
39
63
|
// ── /compact ────────────────────────────────────────
|
|
40
64
|
if (name === '/compact') {
|
|
41
65
|
const before = app.session.getMessageCount();
|
|
42
66
|
app.session.truncate();
|
|
43
67
|
const after = app.session.getMessageCount();
|
|
44
|
-
return { handled: true, output:
|
|
68
|
+
return { handled: true, output: `上下文已压缩: ${before} → ${after} 条消息` };
|
|
45
69
|
}
|
|
46
70
|
// ── /skills [id] ────────────────────────────────────
|
|
47
71
|
if (name === '/skills') {
|
|
48
72
|
if (arg) {
|
|
49
|
-
// Toggle specific skill
|
|
50
73
|
if (app.skills.isActive(arg)) {
|
|
51
74
|
app.skills.deactivate(arg);
|
|
52
|
-
return { handled: true, output: `✗ ${arg}` };
|
|
75
|
+
return { handled: true, output: `✗ 已关闭: ${arg}` };
|
|
53
76
|
}
|
|
54
77
|
else if (app.skills.activate(arg)) {
|
|
55
|
-
return { handled: true, output: `✓ ${arg}` };
|
|
78
|
+
return { handled: true, output: `✓ 已开启: ${arg}` };
|
|
56
79
|
}
|
|
57
|
-
return { handled: true, output:
|
|
80
|
+
return { handled: true, output: `未知技能: ${arg}` };
|
|
58
81
|
}
|
|
59
82
|
const all = app.skills.list();
|
|
60
83
|
const lines = [
|
|
61
|
-
'
|
|
84
|
+
'技能列表:',
|
|
62
85
|
...all.map(s => {
|
|
63
86
|
const mark = app.skills.isActive(s.id) ? '✓' : '·';
|
|
64
|
-
return ` ${mark} ${s.id}`;
|
|
87
|
+
return ` ${mark} ${s.id} ${s.description}`;
|
|
65
88
|
}),
|
|
66
89
|
'',
|
|
67
|
-
'
|
|
90
|
+
'用法: /技能 <id> 切换',
|
|
68
91
|
];
|
|
69
92
|
return { handled: true, output: lines.join('\n') };
|
|
70
93
|
}
|
|
@@ -73,29 +96,34 @@ export function useCommands(app) {
|
|
|
73
96
|
return {
|
|
74
97
|
handled: true,
|
|
75
98
|
output: [
|
|
76
|
-
'MCP
|
|
99
|
+
'MCP 配置: ~/.thatgfsj/mcp.json',
|
|
77
100
|
'',
|
|
78
101
|
' {',
|
|
79
102
|
' "servers": {',
|
|
80
|
-
' "
|
|
103
|
+
' "名称": { "command": "npx", "args": ["-y", "server"] }',
|
|
81
104
|
' }',
|
|
82
105
|
' }',
|
|
83
106
|
].join('\n'),
|
|
84
107
|
};
|
|
85
108
|
}
|
|
86
109
|
// ── /help ───────────────────────────────────────────
|
|
87
|
-
if (name === '/help'
|
|
110
|
+
if (name === '/help') {
|
|
88
111
|
return {
|
|
89
112
|
handled: true,
|
|
90
113
|
output: [
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
'/
|
|
98
|
-
'
|
|
114
|
+
'命令列表:',
|
|
115
|
+
' /模型 <名称> 切换模型',
|
|
116
|
+
' /服务商 更换服务商',
|
|
117
|
+
' /新建 新建会话',
|
|
118
|
+
' /压缩 压缩上下文',
|
|
119
|
+
' /技能 [id] 管理技能',
|
|
120
|
+
' /mcp MCP 设置',
|
|
121
|
+
' /帮助 查看帮助',
|
|
122
|
+
' exit 退出',
|
|
123
|
+
'',
|
|
124
|
+
'快捷键:',
|
|
125
|
+
' ↑/↓ 历史记录',
|
|
126
|
+
' Ctrl+C 退出',
|
|
99
127
|
].join('\n'),
|
|
100
128
|
};
|
|
101
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommands.js","sourceRoot":"","sources":["../../../src/tui/hooks/useCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AASpC,MAAM,UAAU,WAAW,CAAC,GAAQ;IAElC,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,KAAa,EAAiB,EAAE;QACjE,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,
|
|
1
|
+
{"version":3,"file":"useCommands.js","sourceRoot":"","sources":["../../../src/tui/hooks/useCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AASpC,WAAW;AACX,MAAM,WAAW,GAA2B;IAC1C,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,UAAU;IACjB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE;IAC7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IAAI;gBACb,MAAM,EAAE;oBACN,OAAO;oBACP,oBAAoB;oBACpB,uBAAuB;oBACvB,uBAAuB;oBACvB,wBAAwB;oBACxB,uBAAuB;oBACvB,2BAA2B;oBAC3B,uBAAuB;oBACvB,uBAAuB;oBACvB,EAAE;oBACF,MAAM;oBACN,yBAAyB;oBACzB,uBAAuB;iBACxB,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
package/src/cmd/index.tsx
CHANGED
|
@@ -28,7 +28,7 @@ process.on('unhandledRejection', (reason) => {
|
|
|
28
28
|
program
|
|
29
29
|
.name('gfcode')
|
|
30
30
|
.description('Thatgfsj Code - AI Coding Assistant')
|
|
31
|
-
.version('0.9.
|
|
31
|
+
.version('0.9.5')
|
|
32
32
|
.argument('[prompt]', 'Task to execute (omit to start interactive mode)')
|
|
33
33
|
.option('-m, --model <model>', 'Specify model')
|
|
34
34
|
.option('-i, --interactive', 'Force interactive mode')
|
package/src/tui/app.tsx
CHANGED
|
@@ -8,39 +8,63 @@ import { UserInput } from './components/UserInput.js';
|
|
|
8
8
|
import { StatusBar } from './components/StatusBar.js';
|
|
9
9
|
import { ModelSelector } from './components/ModelSelector.js';
|
|
10
10
|
import { useChat } from './hooks/useChat.js';
|
|
11
|
-
import { useCommands } from './hooks/useCommands.js';
|
|
11
|
+
import { useCommands, COMMAND_LIST } from './hooks/useCommands.js';
|
|
12
12
|
import type { App } from '../app/index.js';
|
|
13
13
|
import type { MessageData } from './components/ChatMessage.js';
|
|
14
|
+
import { writeFileSync, readFileSync, existsSync, mkdirSync } from 'fs';
|
|
15
|
+
import { join } from 'path';
|
|
16
|
+
import { homedir } from 'os';
|
|
14
17
|
|
|
15
18
|
interface Props {
|
|
16
19
|
app: App;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
function saveModelToHistory(model: string) {
|
|
23
|
+
const dir = join(homedir(), '.thatgfsj');
|
|
24
|
+
const path = join(dir, 'models.json');
|
|
25
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
26
|
+
|
|
27
|
+
let history: string[] = [];
|
|
28
|
+
if (existsSync(path)) {
|
|
29
|
+
try { history = JSON.parse(readFileSync(path, 'utf-8')); } catch {}
|
|
30
|
+
}
|
|
31
|
+
if (!history.includes(model)) {
|
|
32
|
+
history.push(model);
|
|
33
|
+
writeFileSync(path, JSON.stringify(history, null, 2));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
19
37
|
export function TuiApp({ app }: Props) {
|
|
20
|
-
const { messages, isThinking, streaming, streamingToolCalls, sendMessage } = useChat(app);
|
|
38
|
+
const { messages, isThinking, streaming, streamingToolCalls, queuedMessage, sendMessage } = useChat(app);
|
|
21
39
|
const { handleCommand } = useCommands(app);
|
|
22
40
|
const [systemMessages, setSystemMessages] = useState<MessageData[]>([]);
|
|
23
41
|
const [showModelSelector, setShowModelSelector] = useState(false);
|
|
42
|
+
const [addModelMode, setAddModelMode] = useState(false);
|
|
24
43
|
const { stdout } = useStdout();
|
|
25
44
|
const terminalWidth = stdout?.columns || 80;
|
|
26
45
|
|
|
27
46
|
const onSubmit = useCallback(async (input: string) => {
|
|
28
|
-
//
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
// 添加新模型模式
|
|
48
|
+
if (addModelMode) {
|
|
49
|
+
const model = input.trim();
|
|
50
|
+
if (model) {
|
|
51
|
+
app.config.save({ model });
|
|
52
|
+
saveModelToHistory(model);
|
|
53
|
+
setSystemMessages(prev => [
|
|
54
|
+
...prev,
|
|
55
|
+
{ role: 'assistant', content: `模型已切换: ${model}` },
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
setAddModelMode(false);
|
|
36
59
|
return;
|
|
37
60
|
}
|
|
38
61
|
|
|
62
|
+
if (showModelSelector) return;
|
|
63
|
+
|
|
39
64
|
const result = handleCommand(input);
|
|
40
65
|
|
|
41
66
|
if (result.handled) {
|
|
42
|
-
|
|
43
|
-
if (input.trim().toLowerCase() === '/model') {
|
|
67
|
+
if (input.trim().toLowerCase() === '/model' || input.trim() === '/模型') {
|
|
44
68
|
setShowModelSelector(true);
|
|
45
69
|
return;
|
|
46
70
|
}
|
|
@@ -53,9 +77,7 @@ export function TuiApp({ app }: Props) {
|
|
|
53
77
|
]);
|
|
54
78
|
}
|
|
55
79
|
|
|
56
|
-
if (result.action === 'clear')
|
|
57
|
-
setSystemMessages([]);
|
|
58
|
-
}
|
|
80
|
+
if (result.action === 'clear') setSystemMessages([]);
|
|
59
81
|
|
|
60
82
|
if (result.action === 'reinit') {
|
|
61
83
|
const { WelcomeScreen } = await import('./welcome.js');
|
|
@@ -65,15 +87,15 @@ export function TuiApp({ app }: Props) {
|
|
|
65
87
|
Object.assign(app, newApp);
|
|
66
88
|
setSystemMessages(prev => [
|
|
67
89
|
...prev,
|
|
68
|
-
{ role: 'assistant', content: '
|
|
90
|
+
{ role: 'assistant', content: '配置已更新,模型: ' + app.config.get().model },
|
|
69
91
|
]);
|
|
70
92
|
}
|
|
71
93
|
|
|
72
94
|
return;
|
|
73
95
|
}
|
|
74
96
|
|
|
75
|
-
|
|
76
|
-
}, [handleCommand, sendMessage, app, showModelSelector]);
|
|
97
|
+
sendMessage(input);
|
|
98
|
+
}, [handleCommand, sendMessage, app, showModelSelector, addModelMode]);
|
|
77
99
|
|
|
78
100
|
const allMessages = [...systemMessages, ...messages];
|
|
79
101
|
const activeSkills = app.skills.listActive().map(s => s.id);
|
|
@@ -88,21 +110,35 @@ export function TuiApp({ app }: Props) {
|
|
|
88
110
|
width={terminalWidth - 4}
|
|
89
111
|
/>
|
|
90
112
|
<Thinking active={isThinking} />
|
|
113
|
+
{queuedMessage && (
|
|
114
|
+
<Box paddingLeft={1}>
|
|
115
|
+
<Text color="#F59E0B">📎 已排队: </Text>
|
|
116
|
+
<Text color="#94A3B8">{queuedMessage}</Text>
|
|
117
|
+
</Box>
|
|
118
|
+
)}
|
|
91
119
|
{showModelSelector ? (
|
|
92
120
|
<ModelSelector
|
|
93
121
|
currentModel={app.config.get().model}
|
|
94
122
|
onSelect={(model) => {
|
|
95
123
|
app.config.save({ model });
|
|
124
|
+
saveModelToHistory(model);
|
|
96
125
|
setShowModelSelector(false);
|
|
97
126
|
setSystemMessages(prev => [
|
|
98
127
|
...prev,
|
|
99
|
-
{ role: 'assistant', content:
|
|
128
|
+
{ role: 'assistant', content: `模型已切换: ${model}` },
|
|
100
129
|
]);
|
|
101
130
|
}}
|
|
102
|
-
|
|
131
|
+
onAddNew={() => {
|
|
132
|
+
setShowModelSelector(false);
|
|
133
|
+
setAddModelMode(true);
|
|
134
|
+
}}
|
|
103
135
|
/>
|
|
136
|
+
) : addModelMode ? (
|
|
137
|
+
<Box paddingLeft={1}>
|
|
138
|
+
<Text color="#06B6D4" bold>输入新模型名称: </Text>
|
|
139
|
+
</Box>
|
|
104
140
|
) : (
|
|
105
|
-
<UserInput onSubmit={onSubmit} disabled={
|
|
141
|
+
<UserInput onSubmit={onSubmit} disabled={false} />
|
|
106
142
|
)}
|
|
107
143
|
<StatusBar messageCount={allMessages.length} skills={activeSkills} />
|
|
108
144
|
</Box>
|
|
@@ -14,7 +14,7 @@ export const Header = React.memo(function Header({ provider, model }: Props) {
|
|
|
14
14
|
<Box>
|
|
15
15
|
<Text color="#06B6D4" bold> ⚡ </Text>
|
|
16
16
|
<Text color="#22D3EE" bold>THATGFSJ CODE</Text>
|
|
17
|
-
<Text dimColor> v0.9.
|
|
17
|
+
<Text dimColor> v0.9.5</Text>
|
|
18
18
|
</Box>
|
|
19
19
|
<Box>
|
|
20
20
|
<Text color="#06B6D4" bold> {provider} </Text>
|