thatgfsj-code 3.0.17 → 3.0.19
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.md +6 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +45 -4
- package/dist/config/index.js.map +1 -1
- package/dist/config/providers.d.ts.map +1 -1
- package/dist/config/providers.js +1 -0
- package/dist/config/providers.js.map +1 -1
- package/dist/llm/anthropic.d.ts +28 -2
- package/dist/llm/anthropic.d.ts.map +1 -1
- package/dist/llm/anthropic.js +77 -38
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/gemini.d.ts +16 -2
- package/dist/llm/gemini.d.ts.map +1 -1
- package/dist/llm/gemini.js +51 -12
- package/dist/llm/gemini.js.map +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +11 -5
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai.d.ts +7 -0
- package/dist/llm/openai.d.ts.map +1 -1
- package/dist/llm/openai.js +16 -18
- package/dist/llm/openai.js.map +1 -1
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +5 -0
- package/dist/mcp/client.js.map +1 -1
- package/dist/session/index.d.ts +3 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +53 -22
- package/dist/session/index.js.map +1 -1
- package/dist/setup/browser-setup.d.ts.map +1 -1
- package/dist/setup/browser-setup.js +6 -2
- package/dist/setup/browser-setup.js.map +1 -1
- package/dist/tools/browser.d.ts +13 -1
- package/dist/tools/browser.d.ts.map +1 -1
- package/dist/tools/browser.js +69 -4
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/shell.d.ts +10 -1
- package/dist/tools/shell.d.ts.map +1 -1
- package/dist/tools/shell.js +12 -2
- package/dist/tools/shell.js.map +1 -1
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/app.js +25 -18
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/components/ChatMessage.d.ts +7 -0
- package/dist/tui/components/ChatMessage.d.ts.map +1 -1
- package/dist/tui/components/ChatMessage.js +4 -0
- package/dist/tui/components/ChatMessage.js.map +1 -1
- package/dist/tui/hooks/useChat.d.ts +6 -9
- package/dist/tui/hooks/useChat.d.ts.map +1 -1
- package/dist/tui/hooks/useChat.js +110 -174
- package/dist/tui/hooks/useChat.js.map +1 -1
- package/dist/utils/net.d.ts +73 -0
- package/dist/utils/net.d.ts.map +1 -0
- package/dist/utils/net.js +230 -0
- package/dist/utils/net.js.map +1 -0
- package/package.json +3 -2
|
@@ -1,85 +1,34 @@
|
|
|
1
1
|
import { useState, useCallback, useRef } from 'react';
|
|
2
|
-
import { useStdout } from 'ink';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
2
|
import { formatToolLabel, formatToolResultLine } from '../components/ToolCall.js';
|
|
5
3
|
import { compressThinking } from '../../utils/thinking.js';
|
|
6
4
|
import { formatTokens } from '../../utils/tokens.js';
|
|
7
|
-
import {
|
|
5
|
+
import { getVersion } from '../../version.js';
|
|
8
6
|
/**
|
|
9
7
|
* Hook for managing chat state and the streaming response lifecycle.
|
|
10
8
|
*
|
|
11
|
-
* v3.0.
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
9
|
+
* v3.0.18 (final scroll fix — "everything is Static"): the previous
|
|
10
|
+
* attempt (3.0.15/16) wrote streamed text to stdout BESIDE the live Ink
|
|
11
|
+
* frame. Manual writes move the cursor without telling Ink, so Ink's next
|
|
12
|
+
* frame redraw of the (constant-height) input box stomped old frame
|
|
13
|
+
* copies into the middle of the streamed text — the `┏━━┓` stamping the
|
|
14
|
+
* user reported. The robust design, per the Claude Code architecture
|
|
15
|
+
* study, is simpler:
|
|
16
16
|
*
|
|
17
|
-
* -
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* so the terminal never auto-scrolls and the wheel stays usable.
|
|
17
|
+
* - streamed text is buffered and committed as NEW <Static> items every
|
|
18
|
+
* ~200ms (Static renders each item once, then never re-renders it —
|
|
19
|
+
* Ink manages all cursor movement itself);
|
|
20
|
+
* - tool pending/result lines, the token chip, and the per-round stats
|
|
21
|
+
* line are Static items too;
|
|
22
|
+
* - the live frame is ONLY the constant-height region (thinking spinner
|
|
23
|
+
* + input box + queue notice).
|
|
25
24
|
*
|
|
26
25
|
* Persisted message order still matches the source chunks exactly:
|
|
27
26
|
* - text chunks → accumulated into fullContent (compressed via
|
|
28
27
|
* compressThinking before persistence)
|
|
29
28
|
* - tool_calls chunks → session/agent-loop behavior unchanged
|
|
30
|
-
* - usage chunks →
|
|
29
|
+
* - usage chunks → lastUsage state + auto-compact check
|
|
31
30
|
*/
|
|
32
|
-
|
|
33
|
-
class StreamWriter {
|
|
34
|
-
emit;
|
|
35
|
-
label;
|
|
36
|
-
throttleMs;
|
|
37
|
-
buffer = '';
|
|
38
|
-
timer = null;
|
|
39
|
-
/** 3.0.9 assistant label, printed once before the first streamed char. */
|
|
40
|
-
labelWritten = false;
|
|
41
|
-
constructor(emit, label, throttleMs = 33) {
|
|
42
|
-
this.emit = emit;
|
|
43
|
-
this.label = label;
|
|
44
|
-
this.throttleMs = throttleMs;
|
|
45
|
-
}
|
|
46
|
-
/** Queue a raw chunk of assistant text (label auto-prefixed once). */
|
|
47
|
-
text(s) {
|
|
48
|
-
if (!s)
|
|
49
|
-
return;
|
|
50
|
-
if (!this.labelWritten) {
|
|
51
|
-
this.labelWritten = true;
|
|
52
|
-
this.buffer += '\n' + chalk.hex(theme.textFaint)(this.label) + '\n';
|
|
53
|
-
}
|
|
54
|
-
this.buffer += s;
|
|
55
|
-
this.schedule();
|
|
56
|
-
}
|
|
57
|
-
/** Write immediately (tool lines / notices), flushing queued text first. */
|
|
58
|
-
now(data) {
|
|
59
|
-
this.flush();
|
|
60
|
-
this.emit(data);
|
|
61
|
-
}
|
|
62
|
-
schedule() {
|
|
63
|
-
if (this.timer)
|
|
64
|
-
return;
|
|
65
|
-
this.timer = setTimeout(() => {
|
|
66
|
-
this.timer = null;
|
|
67
|
-
this.flush();
|
|
68
|
-
}, this.throttleMs);
|
|
69
|
-
this.timer.unref?.();
|
|
70
|
-
}
|
|
71
|
-
flush() {
|
|
72
|
-
if (this.timer) {
|
|
73
|
-
clearTimeout(this.timer);
|
|
74
|
-
this.timer = null;
|
|
75
|
-
}
|
|
76
|
-
if (!this.buffer)
|
|
77
|
-
return;
|
|
78
|
-
const data = this.buffer;
|
|
79
|
-
this.buffer = '';
|
|
80
|
-
this.emit(data);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
31
|
+
const FLUSH_MS = 200;
|
|
83
32
|
export function useChat(app) {
|
|
84
33
|
const [state, setState] = useState({
|
|
85
34
|
messages: [],
|
|
@@ -87,90 +36,116 @@ export function useChat(app) {
|
|
|
87
36
|
queuedMessage: null,
|
|
88
37
|
lastUsage: null,
|
|
89
38
|
});
|
|
90
|
-
// Ink's managed write: erase frame → write data permanently → redraw the
|
|
91
|
-
// (constant-height) frame below it. Falls back to raw stdout outside Ink.
|
|
92
|
-
const { write: inkWrite } = useStdout();
|
|
93
39
|
const processingRef = useRef(false);
|
|
94
|
-
|
|
40
|
+
/** v3.0.18 fix: FIFO queue — an array, so a second queued input can no
|
|
41
|
+
* longer overwrite (and silently drop) the first one. */
|
|
42
|
+
const queuedRef = useRef([]);
|
|
95
43
|
const abortRef = useRef(false);
|
|
96
|
-
// v3.0.5: real AbortController — cancel
|
|
97
|
-
// instead of only stopping the render loop while tokens keep generating.
|
|
44
|
+
// v3.0.5: real AbortController — cancel aborts the provider fetch.
|
|
98
45
|
const abortCtrlRef = useRef(null);
|
|
46
|
+
/** Brand header is committed once per process. */
|
|
47
|
+
const headerCommittedRef = useRef(false);
|
|
48
|
+
/** Append an immutable item to the Static list. */
|
|
49
|
+
const commit = useCallback((item) => {
|
|
50
|
+
setState(prev => ({
|
|
51
|
+
...prev,
|
|
52
|
+
messages: [...prev.messages, { role: 'assistant', ...item }],
|
|
53
|
+
}));
|
|
54
|
+
}, []);
|
|
99
55
|
const processStream = async (input) => {
|
|
100
56
|
abortRef.current = false;
|
|
101
57
|
const ctrl = new AbortController();
|
|
102
58
|
abortCtrlRef.current = ctrl;
|
|
59
|
+
commit({ role: 'user', content: input });
|
|
60
|
+
// Show whatever is still waiting behind this message (empty → clear).
|
|
103
61
|
setState(prev => ({
|
|
104
62
|
...prev,
|
|
105
|
-
messages: [...prev.messages, { role: 'user', content: input }],
|
|
106
63
|
isThinking: true,
|
|
107
|
-
queuedMessage: null,
|
|
64
|
+
queuedMessage: queuedRef.current.length > 0 ? queuedRef.current.join(' │ ') : null,
|
|
108
65
|
}));
|
|
109
66
|
app.session.addMessage('user', input);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
67
|
+
// ── streamed-text batching ──
|
|
68
|
+
let pendingText = '';
|
|
69
|
+
let flushTimer = null;
|
|
70
|
+
const flushText = () => {
|
|
71
|
+
if (flushTimer) {
|
|
72
|
+
clearTimeout(flushTimer);
|
|
73
|
+
flushTimer = null;
|
|
74
|
+
}
|
|
75
|
+
if (!pendingText)
|
|
76
|
+
return;
|
|
77
|
+
const chunk = pendingText;
|
|
78
|
+
pendingText = '';
|
|
79
|
+
commit({ content: chunk, plain: true });
|
|
115
80
|
};
|
|
81
|
+
const scheduleFlush = () => {
|
|
82
|
+
if (flushTimer)
|
|
83
|
+
return;
|
|
84
|
+
flushTimer = setTimeout(() => { flushTimer = null; flushText(); }, FLUSH_MS);
|
|
85
|
+
flushTimer.unref?.();
|
|
86
|
+
};
|
|
87
|
+
const writeText = (s) => { pendingText += s; scheduleFlush(); };
|
|
116
88
|
const cfgModel = app.config.get().model || '';
|
|
117
|
-
|
|
118
|
-
|
|
89
|
+
/** Dim plain line (tool calls, chips, stats). */
|
|
90
|
+
const commitDim = (line) => { flushText(); commit({ content: line, plain: true, dim: true }); };
|
|
91
|
+
// First turn in this session: brand header as Static items.
|
|
92
|
+
if (!headerCommittedRef.current) {
|
|
93
|
+
headerCommittedRef.current = true;
|
|
94
|
+
const cols = process.stdout.columns || 80;
|
|
95
|
+
commit({ content: `◆ THATGFSJ v${getVersion()}`, plain: true, dim: true });
|
|
96
|
+
commit({ content: '─'.repeat(Math.max(20, cols - 2)), plain: true, dim: true });
|
|
97
|
+
}
|
|
98
|
+
// Assistant label line (once per turn, before the first streamed char).
|
|
99
|
+
let labelWritten = false;
|
|
100
|
+
const writeLabelOnce = () => {
|
|
101
|
+
if (labelWritten)
|
|
102
|
+
return;
|
|
103
|
+
labelWritten = true;
|
|
104
|
+
commitDim(`▪ Build${cfgModel ? ` · ${cfgModel}` : ''}`);
|
|
105
|
+
};
|
|
106
|
+
/** Pending `⎿ name(args) ⟳` line. */
|
|
119
107
|
const writePendingLine = (tc) => {
|
|
120
108
|
const { title, detail } = formatToolLabel(tc.function.name, tc.function.arguments);
|
|
121
|
-
|
|
122
|
-
chalk.hex(theme.toolMark)('⎿ ') +
|
|
123
|
-
chalk.hex(theme.accentDim)(title) +
|
|
124
|
-
(detail ? ' ' + chalk.hex(theme.textDim)(detail) : '') +
|
|
125
|
-
chalk.hex(theme.textFaint)(' ⟳') +
|
|
126
|
-
'\n');
|
|
109
|
+
commitDim(` ⎿ ${title}${detail ? ' ' + detail : ''} ⟳`);
|
|
127
110
|
};
|
|
128
|
-
/** Result summary line, same shape
|
|
111
|
+
/** Result summary line, same shape as <ToolCall/>. */
|
|
129
112
|
const writeResultLine = (r) => {
|
|
130
113
|
const line = formatToolResultLine(r.output, !r.ok);
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
writer.now(' ' + chalk.hex(line.color)(line.text) + '\n');
|
|
114
|
+
if (line)
|
|
115
|
+
commitDim(` ${line.text}`);
|
|
134
116
|
};
|
|
135
117
|
const stream = app.streamResponse(undefined, { signal: ctrl.signal });
|
|
136
118
|
let fullContent = '';
|
|
137
|
-
// Any tool call seen this turn (keeps persistence gating identical).
|
|
138
119
|
let sawToolCalls = false;
|
|
139
|
-
// Latest usage from this round; surfaced via state.lastUsage.
|
|
140
120
|
let lastUsage = null;
|
|
141
|
-
// v3.0.13: completion tokens summed across all rounds of this turn
|
|
142
|
-
// appended as a faint `· Nt` chip when the turn completes.
|
|
121
|
+
// v3.0.13: completion tokens summed across all rounds of this turn.
|
|
143
122
|
let turnCompletionTokens = 0;
|
|
144
|
-
// Spinner turns off at the first visible output (text or tool line).
|
|
145
123
|
let sawOutput = false;
|
|
146
124
|
try {
|
|
147
125
|
for await (const chunk of stream) {
|
|
148
|
-
|
|
149
|
-
if (abortRef.current) {
|
|
126
|
+
if (abortRef.current)
|
|
150
127
|
break;
|
|
151
|
-
}
|
|
152
128
|
switch (chunk.type) {
|
|
153
129
|
case 'text':
|
|
154
130
|
if (chunk.content) {
|
|
155
131
|
fullContent += chunk.content;
|
|
156
132
|
if (!sawOutput) {
|
|
157
133
|
sawOutput = true;
|
|
134
|
+
writeLabelOnce();
|
|
158
135
|
setState(prev => ({ ...prev, isThinking: false }));
|
|
159
136
|
}
|
|
160
|
-
|
|
137
|
+
writeText(chunk.content);
|
|
161
138
|
}
|
|
162
139
|
break;
|
|
163
140
|
case 'thinking':
|
|
164
|
-
// Reasoning text
|
|
165
|
-
// stripped from persistence in compressThinking), but when
|
|
166
|
-
// showThinking is on it streams straight to the scrollback too.
|
|
141
|
+
// Reasoning text: not part of fullContent unless showThinking.
|
|
167
142
|
if (app.showThinking && chunk.content) {
|
|
168
|
-
fullContent += chunk.content;
|
|
169
143
|
if (!sawOutput) {
|
|
170
144
|
sawOutput = true;
|
|
145
|
+
writeLabelOnce();
|
|
171
146
|
setState(prev => ({ ...prev, isThinking: false }));
|
|
172
147
|
}
|
|
173
|
-
|
|
148
|
+
writeText(chunk.content);
|
|
174
149
|
}
|
|
175
150
|
break;
|
|
176
151
|
case 'tool_calls':
|
|
@@ -181,58 +156,37 @@ export function useChat(app) {
|
|
|
181
156
|
setState(prev => ({ ...prev, isThinking: false }));
|
|
182
157
|
}
|
|
183
158
|
if (chunk.pending) {
|
|
184
|
-
// v3.0.16: pre-execution announcement → one ⟳ line per call.
|
|
185
159
|
for (const tc of chunk.toolCalls)
|
|
186
160
|
writePendingLine(tc);
|
|
187
161
|
}
|
|
188
162
|
else {
|
|
189
|
-
|
|
190
|
-
const results = chunk.results || [];
|
|
191
|
-
for (const r of results)
|
|
163
|
+
for (const r of chunk.results || [])
|
|
192
164
|
writeResultLine(r);
|
|
193
165
|
}
|
|
194
166
|
}
|
|
195
167
|
break;
|
|
196
168
|
case 'usage':
|
|
197
169
|
lastUsage = chunk.usage;
|
|
198
|
-
// v3.0.13: sum completion tokens across agent-loop rounds.
|
|
199
170
|
turnCompletionTokens += chunk.usage.completion_tokens || 0;
|
|
200
171
|
setState(prev => ({ ...prev, lastUsage: chunk.usage }));
|
|
201
172
|
break;
|
|
202
173
|
}
|
|
203
174
|
}
|
|
204
|
-
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
// hallucination loop where the next turn's LLM echoed the
|
|
208
|
-
// marker back. The fix is two-pronged:
|
|
209
|
-
// 1. Never persist when the stream was aborted (here).
|
|
210
|
-
// 2. SessionManager.addMessageSafe drops messages that match
|
|
211
|
-
// the pollution filter as a belt-and-suspenders check
|
|
212
|
-
// for cases where we somehow persist a polluted message.
|
|
175
|
+
flushText();
|
|
176
|
+
// v2.2.4: never persist aborted/truncated assistant messages (the
|
|
177
|
+
// [已中断] hallucination loop — see SessionManager.addMessageSafe).
|
|
213
178
|
const wasAborted = abortRef.current;
|
|
214
|
-
const shouldPersist = !wasAborted &&
|
|
215
|
-
(fullContent.trim() || sawToolCalls);
|
|
179
|
+
const shouldPersist = !wasAborted && (fullContent.trim() || sawToolCalls);
|
|
216
180
|
if (shouldPersist) {
|
|
217
|
-
// v2.2.5: strip blocks from the persisted message
|
|
218
|
-
// when compression is enabled. Same rationale as in
|
|
219
|
-
// cmd/index.tsx — keeps history compact, avoids re-feeding
|
|
220
|
-
// reasoning into the next turn's context window.
|
|
221
181
|
const toPersist = compressThinking(fullContent, app.showThinking);
|
|
222
182
|
app.session.addMessageSafe('assistant', toPersist);
|
|
223
183
|
}
|
|
224
|
-
// Commit whatever is still queued, then the turn's token chip.
|
|
225
|
-
// v2.2.6 note: the old belt-and-suspenders "[tool: name → result]"
|
|
226
|
-
// summary was display-only; result lines are now painted under each
|
|
227
|
-
// ⎿ call line the moment the results chunk arrives, so no suffix.
|
|
228
|
-
writer.flush();
|
|
229
184
|
if (shouldPersist && turnCompletionTokens > 0) {
|
|
230
|
-
|
|
185
|
+
commitDim(` · ${formatTokens(turnCompletionTokens)}t`);
|
|
231
186
|
}
|
|
232
|
-
// v3.0.16: per-round session stats line (
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
// Defensive: missing app facilities degrade to zeros, never throw.
|
|
187
|
+
// v3.0.16: per-round session stats line (chat mode's replacement for
|
|
188
|
+
// the StatusBar — a live StatusBar re-stamps via frame redraws; a
|
|
189
|
+
// Static line is permanent). Defensive against stub apps in tests.
|
|
236
190
|
let stats = { promptTokens: 0, completionTokens: 0 };
|
|
237
191
|
let win = 128000;
|
|
238
192
|
let snap = { totalInputTokens: 0, estimatedSavingsCNY: 0 };
|
|
@@ -246,38 +200,22 @@ export function useChat(app) {
|
|
|
246
200
|
const pct = stats.promptTokens > 0 && win > 0
|
|
247
201
|
? Math.min(999, Math.round((stats.promptTokens / win) * 100))
|
|
248
202
|
: 0;
|
|
249
|
-
|
|
203
|
+
commitDim(` ctx ${formatTokens(stats.promptTokens)}/${formatTokens(win)} (${pct}%)` +
|
|
250
204
|
` · ↑${formatTokens(snap.totalInputTokens ?? 0)} ↓${formatTokens(stats.completionTokens ?? 0)}` +
|
|
251
|
-
` · 节省 ¥${Number(snap.estimatedSavingsCNY ?? 0).toFixed(2)}
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
// here. Only notices/errors land in the React display list.
|
|
255
|
-
setState(prev => ({
|
|
256
|
-
...prev,
|
|
257
|
-
messages: [...prev.messages],
|
|
258
|
-
isThinking: false,
|
|
259
|
-
lastUsage,
|
|
260
|
-
}));
|
|
261
|
-
// v3.0.13: token-aware auto-compact — when this round's prompt tokens
|
|
262
|
-
// reached 85% of the model's context window, compact now and surface
|
|
263
|
-
// the notice in the chat.
|
|
205
|
+
` · 节省 ¥${Number(snap.estimatedSavingsCNY ?? 0).toFixed(2)}`);
|
|
206
|
+
setState(prev => ({ ...prev, isThinking: false, lastUsage }));
|
|
207
|
+
// v3.0.13: auto-compact at 85% of the model's context window.
|
|
264
208
|
const compactNotice = app.maybeAutoCompact(lastUsage ?? undefined);
|
|
265
209
|
if (compactNotice) {
|
|
266
|
-
|
|
267
|
-
...prev,
|
|
268
|
-
messages: [...prev.messages, { role: 'assistant', content: compactNotice }],
|
|
269
|
-
}));
|
|
210
|
+
commit({ content: compactNotice });
|
|
270
211
|
}
|
|
271
212
|
app.session.persist();
|
|
272
213
|
}
|
|
273
214
|
catch (error) {
|
|
274
|
-
|
|
215
|
+
flushText();
|
|
275
216
|
if (abortRef.current) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
messages: [...prev.messages, { role: 'assistant', content: '[已中断]' }],
|
|
279
|
-
isThinking: false,
|
|
280
|
-
}));
|
|
217
|
+
commit({ content: '[已中断]', plain: true });
|
|
218
|
+
setState(prev => ({ ...prev, isThinking: false }));
|
|
281
219
|
}
|
|
282
220
|
else {
|
|
283
221
|
const msg = error.message || String(error);
|
|
@@ -294,27 +232,25 @@ export function useChat(app) {
|
|
|
294
232
|
else if (msg.includes('abort') || msg.includes('AbortError')) {
|
|
295
233
|
errorMsg = `[已中断]`;
|
|
296
234
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
messages: [...prev.messages, { role: 'assistant', content: errorMsg }],
|
|
300
|
-
isThinking: false,
|
|
301
|
-
}));
|
|
235
|
+
commit({ content: errorMsg });
|
|
236
|
+
setState(prev => ({ ...prev, isThinking: false }));
|
|
302
237
|
}
|
|
303
238
|
}
|
|
304
|
-
// Process queued
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
queuedRef.current
|
|
239
|
+
// Process queued messages: consume EVERYTHING that piled up during the
|
|
240
|
+
// turn, in order (previously only the last input survived an overwrite).
|
|
241
|
+
if (!abortRef.current && queuedRef.current.length > 0) {
|
|
242
|
+
const next = queuedRef.current.shift();
|
|
308
243
|
await processStream(next);
|
|
309
244
|
}
|
|
310
245
|
else {
|
|
246
|
+
queuedRef.current = [];
|
|
311
247
|
processingRef.current = false;
|
|
312
248
|
}
|
|
313
249
|
};
|
|
314
250
|
const sendMessage = useCallback((input) => {
|
|
315
251
|
if (processingRef.current) {
|
|
316
|
-
queuedRef.current
|
|
317
|
-
setState(prev => ({ ...prev, queuedMessage:
|
|
252
|
+
queuedRef.current.push(input);
|
|
253
|
+
setState(prev => ({ ...prev, queuedMessage: queuedRef.current.join(' │ ') }));
|
|
318
254
|
return;
|
|
319
255
|
}
|
|
320
256
|
processingRef.current = true;
|
|
@@ -324,7 +260,7 @@ export function useChat(app) {
|
|
|
324
260
|
abortRef.current = true;
|
|
325
261
|
// v3.0.5: abort the actual HTTP request, not just the render loop.
|
|
326
262
|
abortCtrlRef.current?.abort();
|
|
327
|
-
queuedRef.current =
|
|
263
|
+
queuedRef.current = [];
|
|
328
264
|
setState(prev => ({ ...prev, queuedMessage: null, isThinking: false }));
|
|
329
265
|
}, []);
|
|
330
266
|
/**
|
|
@@ -334,7 +270,7 @@ export function useChat(app) {
|
|
|
334
270
|
const hydrateMessages = useCallback((msgs) => {
|
|
335
271
|
setState(prev => ({ ...prev, messages: msgs }));
|
|
336
272
|
}, []);
|
|
337
|
-
/** v3.0.16: /new
|
|
273
|
+
/** v3.0.16: /new clears the display list (session.reset keeps prompt). */
|
|
338
274
|
const clearMessages = useCallback(() => {
|
|
339
275
|
setState(prev => ({ ...prev, messages: [] }));
|
|
340
276
|
}, []);
|
|
@@ -1 +1 @@
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E,CAAC,CAAC;IAEP,0EAA0E;IAC1E,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network utilities shared by LLM providers.
|
|
3
|
+
*
|
|
4
|
+
* v3.0.19 hardening after live reports of bare "Error: fetch failed" on
|
|
5
|
+
* SiliconFlow (intermittent resets of the local Clash/mihomo TUN tunnel —
|
|
6
|
+
* DNS hands out fake-IP 198.18.0.0/15 addresses, so when the tunnel core
|
|
7
|
+
* hiccups Node's fetch dies with an opaque TypeError whose real reason
|
|
8
|
+
* hides in `e.cause`):
|
|
9
|
+
*
|
|
10
|
+
* 1. Cause transparency — the wrapped TypeError("fetch failed") is re-thrown
|
|
11
|
+
* as `fetch failed (ECONNRESET)` etc. so users finally see WHY.
|
|
12
|
+
* 2. Automatic retry — network-layer failures only (see isRetryableError),
|
|
13
|
+
* exponential backoff 500ms / 1500ms. HTTP 4xx/5xx are NOT retried; they
|
|
14
|
+
* resolve normally and the caller decides what to do with them.
|
|
15
|
+
* 3. Proxy support — Node's global fetch ignores the system proxy. When
|
|
16
|
+
* HTTPS_PROXY / https_proxy / HTTP_PROXY / http_proxy is set we route
|
|
17
|
+
* requests through undici's EnvHttpProxyAgent (honors NO_PROXY as well;
|
|
18
|
+
* falls back to ProxyAgent on undici builds without it). Set
|
|
19
|
+
* THATGFSJ_NO_PROXY=1 to force direct connections even when proxy env
|
|
20
|
+
* vars are present.
|
|
21
|
+
*/
|
|
22
|
+
export interface FetchWithRetryOptions {
|
|
23
|
+
/** Extra attempts after the first one fails with a network error. Default 2. */
|
|
24
|
+
retries?: number;
|
|
25
|
+
/** Per-attempt timeout in ms (AbortController based). Undefined = no timeout. */
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
/** External signal (user cancel / stream watchdog). Aborting never retries. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decide whether an error thrown by fetch is a transient network-layer
|
|
32
|
+
* failure worth retrying. HTTP 4xx/5xx never reach this function (fetch
|
|
33
|
+
* resolves those), so "API error 401" style Errors from callers are
|
|
34
|
+
* naturally not retryable.
|
|
35
|
+
*
|
|
36
|
+
* Note: AbortError is treated as retryable here (it usually means our own
|
|
37
|
+
* per-attempt timeout fired); genuine external cancellation is filtered out
|
|
38
|
+
* by fetchWithRetry BEFORE this check runs.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isRetryableError(err: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Human-readable reason for a failed fetch, taken from the underlying cause
|
|
43
|
+
* (Node puts the real error there — ECONNRESET, ETIMEDOUT, certificate
|
|
44
|
+
* failures, ...). Returns '' when nothing useful is attached.
|
|
45
|
+
*/
|
|
46
|
+
export declare function describeFetchCause(err: unknown): string;
|
|
47
|
+
/**
|
|
48
|
+
* Wrap the infamous TypeError("fetch failed") into an Error that surfaces
|
|
49
|
+
* the underlying cause, e.g. `fetch failed (ECONNRESET) after 3 attempts`.
|
|
50
|
+
* The original error is preserved on `.cause`. Any other error is returned
|
|
51
|
+
* untouched.
|
|
52
|
+
*/
|
|
53
|
+
export declare function enrichFetchError(err: unknown, attempts?: number): Error;
|
|
54
|
+
/** Drop the cached dispatcher so the next request re-reads proxy env vars. Exported for tests. */
|
|
55
|
+
export declare function resetProxyDispatcherCache(): void;
|
|
56
|
+
/**
|
|
57
|
+
* fetch() with automatic retry for network-layer failures and proxy support.
|
|
58
|
+
*
|
|
59
|
+
* - Retries: TypeError("fetch failed") / AbortError from our own timeout /
|
|
60
|
+
* undici UND_ERR_* / transient socket codes. Exponential backoff 500ms,
|
|
61
|
+
* 1500ms. HTTP 4xx/5xx resolve normally and are NEVER retried here.
|
|
62
|
+
* - External signal: passed through untouched; aborting it cancels the
|
|
63
|
+
* in-flight attempt and any pending backoff without retrying.
|
|
64
|
+
* - Timeout: per-attempt (each try gets a fresh timeoutMs window).
|
|
65
|
+
* - init.body must be a string/Buffer/URLSearchParams (reusable across
|
|
66
|
+
* attempts) — required for the POST JSON bodies LLM providers send.
|
|
67
|
+
*
|
|
68
|
+
* On final failure a TypeError("fetch failed") is re-thrown via
|
|
69
|
+
* enrichFetchError so the user sees `fetch failed (ECONNRESET)` instead of
|
|
70
|
+
* a bare "fetch failed".
|
|
71
|
+
*/
|
|
72
|
+
export declare function fetchWithRetry(url: string, init?: RequestInit, options?: FetchWithRetryOptions): Promise<Response>;
|
|
73
|
+
//# sourceMappingURL=net.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../src/utils/net.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAsBtD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAMvD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,SAAI,GAAG,KAAK,CASlE;AAiCD,kGAAkG;AAClG,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAwCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,QAAQ,CAAC,CA8CnB"}
|