cli-link 0.0.5 → 0.0.7
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/bin/agentpilot.js +1 -0
- package/dist/client/assets/History-D2xDopni.js +4 -0
- package/dist/client/assets/ImageViewer-DuegU_fC.js +1 -0
- package/dist/client/assets/MarkdownRenderer-CsyizEL3.js +1 -0
- package/dist/client/assets/{PageTopBar-C8j-5s_3.js → PageTopBar-CQwjO6Af.js} +1 -1
- package/dist/client/assets/Session-B0s5zBGg.js +7 -0
- package/dist/client/assets/Settings-CfHFmJdV.js +1 -0
- package/dist/client/assets/Workspace-Cfl0mbNE.js +4 -0
- package/dist/client/assets/WorkspaceLinkedText-DCVYd9x-.js +2 -0
- package/dist/client/assets/c-BIGW1oBm.js +1 -0
- package/dist/client/assets/cpp-DIPi6g--.js +1 -0
- package/dist/client/assets/csharp-DSvCPggb.js +1 -0
- package/dist/client/assets/dart-bE4Kk8sk.js +1 -0
- package/dist/client/assets/dotenv-Da5cRb03.js +1 -0
- package/dist/client/assets/go-C27-OAKa.js +1 -0
- package/dist/client/assets/graphql-pNE0_Gx8.js +1 -0
- package/dist/client/assets/groovy-gcz8RCvz.js +1 -0
- package/dist/client/assets/index-BCg3ymV3.css +1 -0
- package/dist/client/assets/index-CrJqHlc8.js +2 -0
- package/dist/client/assets/java-VnEXKtx_.js +148 -0
- package/dist/client/assets/jsx-g9-lgVsj.js +1 -0
- package/dist/client/assets/kotlin-BdnUsdx6.js +1 -0
- package/dist/client/assets/less-B1dDrJ26.js +1 -0
- package/dist/client/assets/lua-BaeVxFsk.js +1 -0
- package/dist/client/assets/makefile-CHLpvVh8.js +1 -0
- package/dist/client/assets/php-BcCyJq-p.js +1 -0
- package/dist/client/assets/properties-DTPjHERo.js +1 -0
- package/dist/client/assets/ruby-BwImf3Ka.js +1 -0
- package/dist/client/assets/rust-B1yitclQ.js +1 -0
- package/dist/client/assets/scss-lMagJa-5.js +1 -0
- package/dist/client/assets/sql-CRqJ_cUM.js +1 -0
- package/dist/client/assets/svelte-B4a9v_or.js +1 -0
- package/dist/client/assets/swift-D82vCrfD.js +1 -0
- package/dist/client/assets/toml-vGWfd6FD.js +1 -0
- package/dist/client/assets/{vendor-icons-CNN4EKVi.js → vendor-icons-CMXJHDEv.js} +125 -65
- package/dist/client/assets/vendor-markdown--d-T3AbU.js +37 -0
- package/dist/client/assets/{vendor-motion-n6Lx6G4a.js → vendor-motion-D0ZmPdi9.js} +1 -1
- package/dist/client/assets/{vendor-react-DSV5aFEg.js → vendor-react-CcDXZHn_.js} +1 -1
- package/dist/client/assets/{vendor-virtual-CcftJrIC.js → vendor-virtual-DJI7OicV.js} +1 -1
- package/dist/client/assets/vue-DBXACu8K.js +1 -0
- package/dist/client/assets/workspace-return-FrQUv7g3.js +1 -0
- package/dist/client/index.html +18 -4
- package/dist/server/cli-manager.js +151 -26
- package/dist/server/codex-history.js +119 -17
- package/dist/server/index.js +1051 -65
- package/dist/server/store.js +369 -27
- package/dist/server/terminal-qr.js +17 -314
- package/package.json +5 -3
- package/dist/client/assets/History-BxJVDFpN.js +0 -3
- package/dist/client/assets/MarkdownRenderer-BO-KS_L1.js +0 -1
- package/dist/client/assets/Session-CQFXA2Sr.js +0 -11
- package/dist/client/assets/Settings-DYmjRmoN.js +0 -1
- package/dist/client/assets/Workspace-D8kv9euM.js +0 -8
- package/dist/client/assets/WorkspaceLinkedText-DQyPLk-X.js +0 -2
- package/dist/client/assets/code-highlight-CEcsuMpw.js +0 -1
- package/dist/client/assets/index-BXT2BylN.css +0 -1
- package/dist/client/assets/index-DOgH1Kf3.js +0 -2
- package/dist/client/assets/vendor-markdown-BDwu-Ux6.js +0 -35
|
@@ -1,317 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
toBytes() {
|
|
21
|
-
const bytes = [];
|
|
22
|
-
for (let i = 0; i < this.bits.length; i += 8) {
|
|
23
|
-
let value = 0;
|
|
24
|
-
for (let j = 0; j < 8; j += 1) {
|
|
25
|
-
value = (value << 1) | (this.bits[i + j] || 0);
|
|
26
|
-
}
|
|
27
|
-
bytes.push(value);
|
|
28
|
-
}
|
|
29
|
-
return bytes;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function getQrDataCodewordCount(version) {
|
|
33
|
-
return QR_TOTAL_CODEWORDS[version] - QR_EC_CODEWORDS_PER_BLOCK_M[version] * QR_NUM_ERROR_CORRECTION_BLOCKS_M[version];
|
|
34
|
-
}
|
|
35
|
-
function selectQrVersion(data) {
|
|
36
|
-
for (let version = 1; version < QR_TOTAL_CODEWORDS.length; version += 1) {
|
|
37
|
-
const capacityBits = getQrDataCodewordCount(version) * 8;
|
|
38
|
-
if (4 + 8 + data.length * 8 <= capacityBits)
|
|
39
|
-
return version;
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
function qrMultiply(x, y) {
|
|
44
|
-
let z = 0;
|
|
45
|
-
for (let i = 7; i >= 0; i -= 1) {
|
|
46
|
-
z = (z << 1) ^ ((z >>> 7) * 0x11d);
|
|
47
|
-
z ^= ((y >>> i) & 1) * x;
|
|
48
|
-
}
|
|
49
|
-
return z;
|
|
50
|
-
}
|
|
51
|
-
function qrReedSolomonDivisor(degree) {
|
|
52
|
-
const result = Array(degree).fill(0);
|
|
53
|
-
result[degree - 1] = 1;
|
|
54
|
-
let root = 1;
|
|
55
|
-
for (let i = 0; i < degree; i += 1) {
|
|
56
|
-
for (let j = 0; j < result.length; j += 1) {
|
|
57
|
-
result[j] = qrMultiply(result[j], root);
|
|
58
|
-
if (j + 1 < result.length)
|
|
59
|
-
result[j] ^= result[j + 1];
|
|
60
|
-
}
|
|
61
|
-
root = qrMultiply(root, 0x02);
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
function qrReedSolomonRemainder(data, divisor) {
|
|
66
|
-
const result = Array(divisor.length).fill(0);
|
|
67
|
-
for (const byte of data) {
|
|
68
|
-
const factor = byte ^ (result.shift() || 0);
|
|
69
|
-
result.push(0);
|
|
70
|
-
for (let i = 0; i < divisor.length; i += 1) {
|
|
71
|
-
result[i] ^= qrMultiply(divisor[i], factor);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
function qrAddEccAndInterleave(dataCodewords, version) {
|
|
77
|
-
const numBlocks = QR_NUM_ERROR_CORRECTION_BLOCKS_M[version];
|
|
78
|
-
const blockEccLen = QR_EC_CODEWORDS_PER_BLOCK_M[version];
|
|
79
|
-
const rawCodewords = QR_TOTAL_CODEWORDS[version];
|
|
80
|
-
const numShortBlocks = numBlocks - (rawCodewords % numBlocks);
|
|
81
|
-
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
82
|
-
const divisor = qrReedSolomonDivisor(blockEccLen);
|
|
83
|
-
const blocks = [];
|
|
84
|
-
for (let i = 0, offset = 0; i < numBlocks; i += 1) {
|
|
85
|
-
const dataLen = shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1);
|
|
86
|
-
const data = dataCodewords.slice(offset, offset + dataLen);
|
|
87
|
-
offset += dataLen;
|
|
88
|
-
const ecc = qrReedSolomonRemainder(data, divisor);
|
|
89
|
-
if (i < numShortBlocks)
|
|
90
|
-
data.push(0);
|
|
91
|
-
blocks.push(data.concat(ecc));
|
|
92
|
-
}
|
|
93
|
-
const result = [];
|
|
94
|
-
for (let i = 0; i < blocks[0].length; i += 1) {
|
|
95
|
-
for (let j = 0; j < blocks.length; j += 1) {
|
|
96
|
-
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) {
|
|
97
|
-
result.push(blocks[j][i]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
function qrFormatBits(mask) {
|
|
104
|
-
const data = mask; // Error correction level M has format bits 00.
|
|
105
|
-
let rem = data;
|
|
106
|
-
for (let i = 0; i < 10; i += 1) {
|
|
107
|
-
rem = (rem << 1) ^ (((rem >>> 9) & 1) * 0x537);
|
|
108
|
-
}
|
|
109
|
-
return ((data << 10) | rem) ^ 0x5412;
|
|
110
|
-
}
|
|
111
|
-
function qrMask(mask, x, y) {
|
|
112
|
-
switch (mask) {
|
|
113
|
-
case 0: return (x + y) % 2 === 0;
|
|
114
|
-
case 1: return y % 2 === 0;
|
|
115
|
-
case 2: return x % 3 === 0;
|
|
116
|
-
case 3: return (x + y) % 3 === 0;
|
|
117
|
-
case 4: return (Math.floor(y / 2) + Math.floor(x / 3)) % 2 === 0;
|
|
118
|
-
case 5: return ((x * y) % 2) + ((x * y) % 3) === 0;
|
|
119
|
-
case 6: return (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
|
|
120
|
-
case 7: return (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
|
|
121
|
-
default: return false;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function createQrMatrix(text) {
|
|
125
|
-
const data = new TextEncoder().encode(text);
|
|
126
|
-
const version = selectQrVersion(data);
|
|
127
|
-
if (!version)
|
|
1
|
+
import QRCode from 'qrcode';
|
|
2
|
+
export async function renderTerminalQr(text, options = {}) {
|
|
3
|
+
try {
|
|
4
|
+
if (options.color === false) {
|
|
5
|
+
return await QRCode.toString(text, {
|
|
6
|
+
type: 'utf8',
|
|
7
|
+
errorCorrectionLevel: 'M',
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return await QRCode.toString(text, {
|
|
11
|
+
type: 'terminal',
|
|
12
|
+
small: options.mode !== 'large',
|
|
13
|
+
errorCorrectionLevel: 'M',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.warn(`[AgentPilot] Failed to render terminal QR code: ${err instanceof Error ? err.message : String(err)}`);
|
|
128
18
|
return null;
|
|
129
|
-
const dataCodewordCount = getQrDataCodewordCount(version);
|
|
130
|
-
const buffer = new BitBuffer();
|
|
131
|
-
buffer.append(0b0100, 4);
|
|
132
|
-
buffer.append(data.length, 8);
|
|
133
|
-
for (const byte of data)
|
|
134
|
-
buffer.append(byte, 8);
|
|
135
|
-
const capacityBits = dataCodewordCount * 8;
|
|
136
|
-
buffer.append(0, Math.min(4, capacityBits - buffer.bits.length));
|
|
137
|
-
while (buffer.bits.length % 8 !== 0)
|
|
138
|
-
buffer.append(0, 1);
|
|
139
|
-
const dataCodewords = buffer.toBytes();
|
|
140
|
-
for (let pad = 0xec; dataCodewords.length < dataCodewordCount; pad ^= 0xec ^ 0x11) {
|
|
141
|
-
dataCodewords.push(pad);
|
|
142
|
-
}
|
|
143
|
-
const codewords = qrAddEccAndInterleave(dataCodewords, version);
|
|
144
|
-
const size = version * 4 + 17;
|
|
145
|
-
const modules = Array.from({ length: size }, () => Array(size).fill(false));
|
|
146
|
-
const isFunction = Array.from({ length: size }, () => Array(size).fill(false));
|
|
147
|
-
const setFunction = (x, y, dark) => {
|
|
148
|
-
if (x < 0 || y < 0 || x >= size || y >= size)
|
|
149
|
-
return;
|
|
150
|
-
modules[y][x] = dark;
|
|
151
|
-
isFunction[y][x] = true;
|
|
152
|
-
};
|
|
153
|
-
const drawFinder = (cx, cy) => {
|
|
154
|
-
for (let dy = -4; dy <= 4; dy += 1) {
|
|
155
|
-
for (let dx = -4; dx <= 4; dx += 1) {
|
|
156
|
-
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
157
|
-
setFunction(cx + dx, cy + dy, dist !== 2 && dist !== 4);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const drawAlignment = (cx, cy) => {
|
|
162
|
-
for (let dy = -2; dy <= 2; dy += 1) {
|
|
163
|
-
for (let dx = -2; dx <= 2; dx += 1) {
|
|
164
|
-
setFunction(cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const drawFormat = (mask) => {
|
|
169
|
-
const bits = qrFormatBits(mask);
|
|
170
|
-
for (let i = 0; i <= 5; i += 1)
|
|
171
|
-
setFunction(8, i, ((bits >>> i) & 1) !== 0);
|
|
172
|
-
setFunction(8, 7, ((bits >>> 6) & 1) !== 0);
|
|
173
|
-
setFunction(8, 8, ((bits >>> 7) & 1) !== 0);
|
|
174
|
-
setFunction(7, 8, ((bits >>> 8) & 1) !== 0);
|
|
175
|
-
for (let i = 9; i < 15; i += 1)
|
|
176
|
-
setFunction(14 - i, 8, ((bits >>> i) & 1) !== 0);
|
|
177
|
-
for (let i = 0; i < 8; i += 1)
|
|
178
|
-
setFunction(size - 1 - i, 8, ((bits >>> i) & 1) !== 0);
|
|
179
|
-
for (let i = 8; i < 15; i += 1)
|
|
180
|
-
setFunction(8, size - 15 + i, ((bits >>> i) & 1) !== 0);
|
|
181
|
-
setFunction(8, size - 8, true);
|
|
182
|
-
};
|
|
183
|
-
drawFinder(3, 3);
|
|
184
|
-
drawFinder(size - 4, 3);
|
|
185
|
-
drawFinder(3, size - 4);
|
|
186
|
-
const alignment = QR_ALIGNMENT_POSITIONS[version];
|
|
187
|
-
for (const x of alignment) {
|
|
188
|
-
for (const y of alignment) {
|
|
189
|
-
if (isFunction[y]?.[x])
|
|
190
|
-
continue;
|
|
191
|
-
drawAlignment(x, y);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
for (let i = 8; i < size - 8; i += 1) {
|
|
195
|
-
setFunction(6, i, i % 2 === 0);
|
|
196
|
-
setFunction(i, 6, i % 2 === 0);
|
|
197
|
-
}
|
|
198
|
-
drawFormat(0);
|
|
199
|
-
let bitIndex = 0;
|
|
200
|
-
for (let right = size - 1; right >= 1; right -= 2) {
|
|
201
|
-
if (right === 6)
|
|
202
|
-
right -= 1;
|
|
203
|
-
for (let vert = 0; vert < size; vert += 1) {
|
|
204
|
-
const y = ((right + 1) & 2) === 0 ? size - 1 - vert : vert;
|
|
205
|
-
for (let j = 0; j < 2; j += 1) {
|
|
206
|
-
const x = right - j;
|
|
207
|
-
if (isFunction[y][x])
|
|
208
|
-
continue;
|
|
209
|
-
modules[y][x] = ((codewords[Math.floor(bitIndex / 8)] >>> (7 - (bitIndex % 8))) & 1) !== 0;
|
|
210
|
-
bitIndex += 1;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
let bestMask = 0;
|
|
215
|
-
let bestPenalty = Infinity;
|
|
216
|
-
for (let mask = 0; mask < 8; mask += 1) {
|
|
217
|
-
const penalty = scoreQrMask(modules, isFunction, mask);
|
|
218
|
-
if (penalty < bestPenalty) {
|
|
219
|
-
bestMask = mask;
|
|
220
|
-
bestPenalty = penalty;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
for (let y = 0; y < size; y += 1) {
|
|
224
|
-
for (let x = 0; x < size; x += 1) {
|
|
225
|
-
if (!isFunction[y][x] && qrMask(bestMask, x, y))
|
|
226
|
-
modules[y][x] = !modules[y][x];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
drawFormat(bestMask);
|
|
230
|
-
return modules;
|
|
231
|
-
}
|
|
232
|
-
function scoreQrMask(modules, isFunction, mask) {
|
|
233
|
-
const size = modules.length;
|
|
234
|
-
const get = (x, y) => modules[y][x] !== (!isFunction[y][x] && qrMask(mask, x, y));
|
|
235
|
-
let penalty = 0;
|
|
236
|
-
for (let y = 0; y < size; y += 1) {
|
|
237
|
-
let runColor = get(0, y);
|
|
238
|
-
let runLen = 1;
|
|
239
|
-
for (let x = 1; x < size; x += 1) {
|
|
240
|
-
const color = get(x, y);
|
|
241
|
-
if (color === runColor) {
|
|
242
|
-
runLen += 1;
|
|
243
|
-
if (runLen === 5)
|
|
244
|
-
penalty += 3;
|
|
245
|
-
else if (runLen > 5)
|
|
246
|
-
penalty += 1;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
runColor = color;
|
|
250
|
-
runLen = 1;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
for (let x = 0; x < size; x += 1) {
|
|
255
|
-
let runColor = get(x, 0);
|
|
256
|
-
let runLen = 1;
|
|
257
|
-
for (let y = 1; y < size; y += 1) {
|
|
258
|
-
const color = get(x, y);
|
|
259
|
-
if (color === runColor) {
|
|
260
|
-
runLen += 1;
|
|
261
|
-
if (runLen === 5)
|
|
262
|
-
penalty += 3;
|
|
263
|
-
else if (runLen > 5)
|
|
264
|
-
penalty += 1;
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
runColor = color;
|
|
268
|
-
runLen = 1;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
let dark = 0;
|
|
273
|
-
for (let y = 0; y < size; y += 1) {
|
|
274
|
-
for (let x = 0; x < size; x += 1) {
|
|
275
|
-
if (get(x, y))
|
|
276
|
-
dark += 1;
|
|
277
|
-
if (x + 1 < size && y + 1 < size) {
|
|
278
|
-
const color = get(x, y);
|
|
279
|
-
if (color === get(x + 1, y) && color === get(x, y + 1) && color === get(x + 1, y + 1)) {
|
|
280
|
-
penalty += 3;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const total = size * size;
|
|
286
|
-
penalty += Math.floor(Math.abs(dark * 20 - total * 10) / total) * 10;
|
|
287
|
-
return penalty;
|
|
288
|
-
}
|
|
289
|
-
export function renderTerminalQr(text, options = {}) {
|
|
290
|
-
const modules = createQrMatrix(text);
|
|
291
|
-
if (!modules)
|
|
292
|
-
return null;
|
|
293
|
-
const size = modules.length;
|
|
294
|
-
const quiet = 2;
|
|
295
|
-
const lines = [];
|
|
296
|
-
if (options.color === false) {
|
|
297
|
-
for (let y = -quiet; y < size + quiet; y += 1) {
|
|
298
|
-
let line = '';
|
|
299
|
-
for (let x = -quiet; x < size + quiet; x += 1) {
|
|
300
|
-
const dark = x >= 0 && x < size && y >= 0 && y < size && modules[y][x];
|
|
301
|
-
line += dark ? '██' : ' ';
|
|
302
|
-
}
|
|
303
|
-
lines.push(line);
|
|
304
|
-
}
|
|
305
|
-
return lines.join('\n');
|
|
306
|
-
}
|
|
307
|
-
for (let y = -quiet; y < size + quiet; y += 2) {
|
|
308
|
-
let line = '\x1b[30;47m';
|
|
309
|
-
for (let x = -quiet; x < size + quiet; x += 1) {
|
|
310
|
-
const top = x >= 0 && x < size && y >= 0 && y < size && modules[y][x];
|
|
311
|
-
const bottom = x >= 0 && x < size && y + 1 >= 0 && y + 1 < size && modules[y + 1][x];
|
|
312
|
-
line += top && bottom ? '█' : top ? '▀' : bottom ? '▄' : ' ';
|
|
313
|
-
}
|
|
314
|
-
lines.push(`${line}\x1b[0m`);
|
|
315
19
|
}
|
|
316
|
-
return lines.join('\n');
|
|
317
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-link",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"cli-link": "bin/agentpilot.js"
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"better-sqlite3": "^12.9.0",
|
|
35
|
+
"qrcode": "^1.5.4",
|
|
35
36
|
"ws": "^8.16.0"
|
|
36
37
|
},
|
|
37
38
|
"pnpm": {
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"@tanstack/react-virtual": "^3.13.23",
|
|
46
47
|
"@types/better-sqlite3": "^7.6.13",
|
|
47
48
|
"@types/node": "^25.6.0",
|
|
49
|
+
"@types/qrcode": "^1.5.6",
|
|
48
50
|
"@types/react": "^18.2.0",
|
|
49
51
|
"@types/react-dom": "^18.2.0",
|
|
50
52
|
"@types/ws": "^8.5.10",
|
|
@@ -60,10 +62,10 @@
|
|
|
60
62
|
"react-dom": "18.2.0",
|
|
61
63
|
"react-markdown": "^9.0.1",
|
|
62
64
|
"react-router-dom": "6.23.0",
|
|
63
|
-
"rehype-highlight": "^7.0.2",
|
|
64
65
|
"remark-gfm": "^4.0.0",
|
|
65
|
-
"
|
|
66
|
+
"shiki": "^4.2.0",
|
|
66
67
|
"tailwind-merge": "2.3.0",
|
|
68
|
+
"tailwindcss": "^3.4.3",
|
|
67
69
|
"tsx": "^4.7.0",
|
|
68
70
|
"typescript": "^5.4.0",
|
|
69
71
|
"vite": "^5.2.0"
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{u as oe,h as xe,r as m,j as e}from"./vendor-react-DSV5aFEg.js";import{u as ce,s as N,g as me,c as g}from"./index-DOgH1Kf3.js";import{g as ue,M as C,W as ge}from"./WorkspaceLinkedText-DQyPLk-X.js";import{P as pe}from"./PageTopBar-C8j-5s_3.js";import{C as ye,X as K,L as O,j as he,g as L,q as H,r as R,s as fe,B as be,m as _,n as D,c as F,o as je,p as ke}from"./vendor-icons-CNN4EKVi.js";import{A as Ne,m as q}from"./vendor-motion-n6Lx6G4a.js";function G(r){if(/^```/.test(r.trim()))return r;try{const s=JSON.parse(r);return"```json\n"+JSON.stringify(s,null,2)+"\n```"}catch{}return r.split(`
|
|
2
|
-
`).map(s=>{const n=s.trim();if(!n)return s;try{const i=JSON.parse(n);return"```json\n"+JSON.stringify(i,null,2)+"\n```"}catch{return s}}).join(`
|
|
3
|
-
`)}function V(r){const l=Date.now()-r,s=Math.floor(l/6e4);if(s<1)return"刚刚";if(s<60)return`${s}分钟前`;const n=Math.floor(s/60);if(n<24)return`${n}小时前`;const i=Math.floor(n/24);return i===1?"昨天":i<7?`${i}天前`:new Date(r).toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}function we(r){return r.split(/[\\/]/).filter(Boolean).pop()||r}const ze=()=>{var A;const r=oe(),{cliConfig:t}=ce(),[l,s]=xe(),n=l.get("filter")||"all",i=l.get("detail"),[c,p]=m.useState([]),[d,u]=m.useState(!0),[b,h]=m.useState(""),[j,$]=m.useState(null),[I,k]=m.useState(""),[re,B]=m.useState(null),[P,w]=m.useState(""),v=m.useRef(null),T=m.useCallback(async()=>{try{const a=await N.fetchHistory();p(x=>a.map(y=>{const f=x.find(de=>de.id===y.id);return f!=null&&f.messagesLoaded?{...y,messagesLoaded:!0,messages:f.messages}:y}))}catch(a){console.error("[History] Failed to fetch:",a)}finally{u(!1)}},[]);m.useEffect(()=>{T()},[T]),m.useEffect(()=>{h(""),k(""),$(null),w(""),v.current=null},[i]),m.useEffect(()=>{const x=me().onMessage(y=>{y.type==="history_changed"&&T()});return()=>{x()}},[T]);const U=c.filter(a=>n==="all"?!0:n==="running"?a.status==="running"||a.status==="confirm":a.status===n),o=c.find(a=>a.id===i),W=o!=null&&o.messagesLoaded?ue(o.messages):[],M=(t==null?void 0:t.workDir)||((A=c.find(a=>a.workDir))==null?void 0:A.workDir)||"",te=M?we(M):"未选择工作目录";m.useEffect(()=>{if(!i||!o||o.messagesLoaded||v.current===i)return;let a=!1;return v.current=i,B(i),w(""),N.fetchHistoryTask(i).then(x=>{if(!a){if(!x){w("会话记录不存在或已被删除");return}p(y=>y.map(f=>f.id===x.id?x:f))}}).catch(x=>{a||(console.error("[History] Failed to fetch detail:",x),w(x instanceof Error?x.message:"加载会话记录失败"))}).finally(()=>{a||(B(null),v.current=null)}),()=>{a=!0}},[i,o==null?void 0:o.id,o==null?void 0:o.messagesLoaded]);const ae=a=>{s(x=>(x.set("filter",a),x.delete("detail"),x))},se=a=>{s(x=>(x.set("detail",a),x))},S=()=>{s(a=>(a.delete("detail"),a))},ne=async(a,x)=>{x.stopPropagation();try{await N.deleteHistoryTask(a),p(y=>y.filter(f=>f.id!==a)),i===a&&S()}catch(y){console.error("[History] Failed to delete:",y)}},le=async()=>{try{await N.clearHistory(),p([])}catch(a){console.error("[History] Failed to clear:",a)}},z=async()=>{if(!o||j)return;const a=b.trim();if(a){if(!o.canResume){k("该会话记录缺少可恢复的 CLI 会话 ID,无法继续追问");return}$(o.id),k("");try{await N.resumeHistoryTask(o.id,a),h(""),r("/session")}catch(x){k(x instanceof Error?x.message:"恢复会话记录失败")}finally{$(null)}}},ie=[{id:"all",label:"全部",count:c.length},{id:"running",label:"进行中",count:c.filter(a=>a.status==="running"||a.status==="confirm").length},{id:"completed",label:"已完成",count:c.filter(a=>a.status==="completed").length},{id:"failed",label:"失败",count:c.filter(a=>a.status==="failed").length}];return e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950 relative",children:[e.jsx(pe,{title:"会话记录",meta:e.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[120px] flex-shrink-0",title:M,children:te}),actions:c.length>0?e.jsx("button",{onClick:le,className:"text-xs text-gray-400 hover:text-red-500 transition-colors flex-shrink-0",children:"清空"}):void 0,bottom:e.jsx("div",{className:"flex px-2 overflow-x-auto hide-scrollbar",children:ie.map(a=>e.jsxs("button",{onClick:()=>ae(a.id),className:g("flex items-center gap-1.5 px-4 py-2.5 border-b-2 text-sm font-medium whitespace-nowrap transition-colors",n===a.id?"border-primary-600 text-primary-600 dark:text-primary-400":"border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:[a.label,e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full",n===a.id?"bg-primary-100 text-primary-700 dark:bg-primary-900 dark:text-primary-300":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:a.count})]},a.id))})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:U.length>0?U.map(a=>e.jsx(Re,{task:a,onClick:()=>se(a.id),onDelete:x=>ne(a.id,x)},a.id)):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-400 dark:text-gray-600 gap-3",children:[e.jsx(ye,{className:"w-12 h-12 opacity-20"}),e.jsx("p",{className:"text-sm",children:"暂无相关会话"})]})}),e.jsx(Ne,{children:i&&o&&e.jsxs(e.Fragment,{children:[e.jsx(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:S,className:"absolute inset-0 bg-black/40 z-40"}),e.jsxs(q.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",damping:25,stiffness:200},className:"absolute bottom-0 left-0 right-0 h-[85%] bg-white dark:bg-gray-900 rounded-t-2xl z-50 flex flex-col shadow-xl",children:[e.jsx("div",{className:"flex justify-center pt-3 pb-2 flex-shrink-0",onClick:S,children:e.jsx("div",{className:"w-12 h-1.5 bg-gray-300 dark:bg-gray-600 rounded-full"})}),e.jsxs("div",{className:"px-5 pb-4 border-b border-gray-100 dark:border-gray-800 flex-shrink-0",children:[e.jsxs("div",{className:"flex justify-between items-start gap-4 mb-3",children:[e.jsx("h2",{className:"text-base font-medium text-gray-900 dark:text-gray-100 leading-snug",children:o.title}),e.jsx("button",{onClick:S,className:"p-1 text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full flex-shrink-0",children:e.jsx(K,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx(ee,{status:o.status}),o.duration&&e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:["耗时 ",o.duration]}),e.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:V(o.startTime)})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 bg-gray-50 dark:bg-gray-950",children:[e.jsx("div",{className:"text-center text-xs text-gray-400 dark:text-gray-600 mb-4",children:"完整消息流"}),re===o.id?e.jsxs("div",{className:"flex flex-col items-center justify-center mt-10 gap-2 text-gray-400 dark:text-gray-600",children:[e.jsx(O,{className:"w-5 h-5 animate-spin"}),e.jsx("div",{className:"text-sm",children:"正在加载会话详情"})]}):P?e.jsx("div",{className:"text-center text-sm text-red-500 dark:text-red-400 mt-8",children:P}):W.length>0?e.jsx("div",{className:"space-y-4",children:W.map(a=>e.jsx(ve,{message:a},a.id))}):o.messagesLoaded?e.jsx("div",{className:"text-center text-sm text-gray-400 dark:text-gray-600 mt-8",children:"无消息记录"}):e.jsx("div",{className:"text-center text-sm text-gray-400 dark:text-gray-600 mt-8",children:"点击后加载消息记录"})]}),e.jsx("div",{className:"border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900 p-3 pb-safe flex-shrink-0",children:o.canResume?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("textarea",{value:b,onChange:a=>{h(a.target.value),k(""),a.currentTarget.style.height="auto",a.currentTarget.style.height=`${Math.min(a.currentTarget.scrollHeight,96)}px`},onKeyDown:a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&(a.preventDefault(),z())},placeholder:"基于这段会话继续追问…",rows:1,disabled:j===o.id,className:"flex-1 min-h-[42px] max-h-24 resize-none rounded-2xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 px-4 py-2.5 text-sm text-gray-800 dark:text-gray-200 placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none focus:border-primary-400 focus:bg-white dark:focus:bg-gray-800 focus:ring-[3px] focus:ring-primary-100 dark:focus:ring-primary-900 hide-scrollbar"}),e.jsx("button",{type:"button",onClick:z,disabled:!b.trim()||j===o.id,className:g("p-2.5 rounded-full flex-shrink-0 transition-all duration-200 shadow-sm active:scale-95",b.trim()&&j!==o.id?"bg-primary-600 text-white hover:bg-primary-700":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500 shadow-none"),title:"继续追问",children:j===o.id?e.jsx(O,{className:"w-4 h-4 animate-spin"}):e.jsx(he,{className:"w-4 h-4"})})]}),I&&e.jsx("div",{className:"mt-2 text-xs text-red-500 dark:text-red-400 px-1",children:I})]}):e.jsx("div",{className:"rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-950 px-3 py-2 text-xs text-gray-500 dark:text-gray-400",children:"该会话记录缺少底层 CLI 会话 ID,无法继续追问。"})})]})]})})]})},ve=({message:r})=>{switch(r.type){case"system_group":return e.jsx(Ee,{group:r});case"tool_group":return e.jsx(Me,{group:r});case"user":return e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"bg-primary-600 text-white rounded-2xl rounded-tr-sm px-4 py-2.5 max-w-[85%] shadow-sm",children:e.jsx("p",{className:"text-[15px] leading-relaxed whitespace-pre-wrap",children:e.jsx(ge,{linkClassName:"text-white decoration-white/70",children:r.content})})})});case"ai":return e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 text-gray-800 dark:text-gray-200 rounded-2xl rounded-tl-md px-3.5 py-3 max-w-[88%] shadow-sm markdown-body overflow-hidden min-w-0",children:e.jsx(C,{children:r.content})})});case"tool":return e.jsx($e,{message:r});case"confirm":return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:g("border rounded-xl px-4 py-2.5 max-w-[85%] shadow-sm",r.status==="approved"?"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800":"bg-red-50 dark:bg-red-950 border-red-200 dark:border-red-800"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.status==="approved"?e.jsx(R,{className:"w-3.5 h-3.5 text-green-600"}):e.jsx(H,{className:"w-3.5 h-3.5 text-red-600"}),e.jsx("span",{className:g("text-xs font-medium",r.status==="approved"?"text-green-700 dark:text-green-400":"text-red-700 dark:text-red-400"),children:r.status==="approved"?"已批准":"已拒绝"})]}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:r.content})]})});case"system":{const t=r.details;if(t&&Object.keys(t).length>0){const l=t.subtype==="result",s=[];if(t.model&&s.push({label:"模型",value:t.model}),t.costUsd!=null&&s.push({label:"费用",value:`$${Number(t.costUsd).toFixed(4)}`}),t.durationMs!=null){const n=Math.round(Number(t.durationMs)/1e3);s.push({label:"耗时",value:n>=60?`${Math.floor(n/60)}m${n%60}s`:`${n}s`})}return t.numTurns!=null&&s.push({label:"轮次",value:String(t.numTurns)}),e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:`px-3 py-2 rounded-xl border max-w-[85%] ${l?"bg-green-50/80 dark:bg-green-950/40 border-green-200/60 dark:border-green-800/40":"bg-gray-50 dark:bg-gray-800/80 border-gray-200 dark:border-gray-700"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx("span",{className:`text-xs font-medium ${l?"text-green-700 dark:text-green-300":"text-gray-500 dark:text-gray-400"}`,children:r.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:r.time})]}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((n,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300",children:[e.jsx("span",{className:"opacity-60",children:n.label}),e.jsx("span",{className:"font-semibold",children:n.value})]},i))})]})})}return e.jsx("div",{className:"flex justify-start",children:e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-600 bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded-full",children:r.content})})}case"thinking":return e.jsx(Le,{message:r});case"error":return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-800 text-red-800 dark:text-red-300 rounded-xl px-4 py-2.5 max-w-[85%] shadow-sm flex items-start gap-2",children:[e.jsx(H,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm leading-relaxed",children:r.content})]})});default:return null}};function Te(r){const t=(r.toolName||r.content||"").toLowerCase();return["readfile","writefile","read","write","edit","multiedit"].includes(t)}function E(r){return r.toolName&&r.toolName!=="result"?r.toolName:r.content||"tool"}function Se(r){return X(r).join("、")||"工具调用"}function X(r){return Array.from(new Set(r.map(E).filter(Boolean)))}function Ce(r){if(r.some(t=>t.status==="failed"))return"failed";if(r.some(t=>t.status==="running"))return"running";if(r.some(t=>t.status==="success"))return"success"}function He(r){const t=r.filter(i=>i.status==="running").length,l=r.filter(i=>i.status==="failed").length,s=r.filter(i=>i.status==="success").length,n=[`${r.length} 个`];return t&&n.push(`${t} 运行中`),l&&n.push(`${l} 失败`),s&&!t&&!l&&n.push("已完成"),n.join(" · ")}function Q(r,t="w-4 h-4 text-primary-600 dark:text-primary-400"){return Te(r)?e.jsx(je,{className:t}):e.jsx(F,{className:t})}function Y({status:r,className:t="w-3.5 h-3.5"}){return r==="running"?e.jsx(ke,{className:g(t,"text-primary-500 animate-pulse")}):r==="success"?e.jsx(R,{className:g(t,"text-green-600")}):r==="failed"?e.jsx(H,{className:g(t,"text-red-600")}):null}function De({status:r}){return e.jsx("span",{className:g("w-1.5 h-1.5 rounded-full flex-shrink-0",r==="running"?"bg-primary-500 animate-pulse":r==="failed"?"bg-red-500":r==="success"?"bg-green-500":"bg-gray-300 dark:bg-gray-600")})}const Z=({message:r,compact:t=!1})=>{const l="max-h-32";return e.jsxs(e.Fragment,{children:[r.toolDetails&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-0.5",children:"输入"}),e.jsx("div",{className:g("text-xs text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 p-2 rounded-lg border border-primary-50 dark:border-gray-700 overflow-y-auto",l),children:e.jsx(C,{children:G(r.toolDetails)})})]}),r.toolResult&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-0.5",children:"输出"}),e.jsx("div",{className:g("text-xs p-2 rounded-lg overflow-y-auto",l,r.status==="failed"?"text-red-700 dark:text-red-300 bg-red-50/50 dark:bg-red-950/50 border border-red-100 dark:border-red-900":"text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 border border-primary-50 dark:border-gray-700"),children:e.jsx(C,{children:G(r.toolResult)})})]})]})},$e=({message:r})=>e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-primary-50 dark:bg-primary-950 border border-primary-100 dark:border-primary-900 rounded-xl px-3 py-2 max-w-[85%] flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[Q(r),e.jsx("span",{className:"text-sm text-primary-800 dark:text-primary-300 break-words min-w-0",children:r.content}),e.jsx("span",{className:"ml-auto flex-shrink-0",children:e.jsx(Y,{status:r.status})})]}),e.jsx(Z,{message:r})]})}),Me=({group:r})=>{const[t,l]=m.useState(!1),[s,n]=m.useState({}),i=Ce(r.messages),c=Se(r.messages),p=m.useCallback(d=>{n(u=>({...u,[d]:!u[d]}))},[]);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[85%] rounded-xl border border-primary-100 dark:border-gray-700 bg-primary-50/90 dark:bg-gray-800 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>l(!t),className:"w-full px-3 py-2 flex items-center gap-2 text-left min-w-0 hover:bg-primary-100/60 dark:hover:bg-gray-700 transition-colors",children:[t?e.jsx(D,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}):e.jsx(L,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}),e.jsx(F,{className:"w-3.5 h-3.5 text-primary-600 dark:text-primary-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-primary-800 dark:text-primary-300 flex-shrink-0",children:"工具调用"}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",i==="failed"?"bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300":i==="running"?"bg-primary-100 text-primary-700 dark:bg-primary-950 dark:text-primary-300":"bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300"),children:He(r.messages)}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:r.time}),e.jsx("span",{className:"min-w-0 truncate text-xs text-gray-600 dark:text-gray-400",title:c,children:c})]}),!t&&e.jsx("div",{className:"px-3 pb-2 flex flex-wrap gap-1.5",children:X(r.messages).map(d=>{const u=r.messages.find(b=>E(b)===d);return e.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-600 dark:text-gray-300 border border-primary-100/60 dark:border-gray-700",title:d,children:[e.jsx(De,{status:u==null?void 0:u.status}),e.jsx("span",{className:"truncate text-left",children:d})]},d)})}),t&&e.jsx("div",{className:"border-t border-primary-100/80 dark:border-gray-700 divide-y divide-primary-100/70 dark:divide-gray-700",children:r.messages.map(d=>{const u=E(d),b=d.content&&d.content!==u,h=!!(d.toolDetails||d.toolResult),j=!!s[d.id];return e.jsxs("div",{className:"px-3 py-2 flex flex-col gap-1.5 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>h&&p(d.id),className:g("w-full flex flex-col gap-1 min-w-0 text-left",h&&"cursor-pointer hover:text-primary-900 dark:hover:text-primary-200"),children:[e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0",children:[Q(d,"w-3.5 h-3.5 text-primary-600 dark:text-primary-400 flex-shrink-0 mt-0.5"),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold text-primary-800 dark:text-primary-300",title:u,children:u}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:d.time}),h&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-500 dark:text-gray-400 border border-primary-100/60 dark:border-gray-700",children:d.toolDetails&&d.toolResult?"输入/输出":d.toolDetails?"输入":"输出"}),e.jsx(Y,{status:d.status,className:"w-3 h-3"}),h&&(j?e.jsx(_,{className:"w-3 h-3 text-primary-500"}):e.jsx(D,{className:"w-3 h-3 text-primary-500"}))]})]}),b&&e.jsx("span",{className:"w-full pl-5 pr-1 text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:d.content})]}),h&&j&&e.jsx(Z,{message:d,compact:!0})]},d.id)})})]})})};function J(r){const t=r.details;if(!t)return[];const l=[];if(t.model&&l.push({label:"模型",value:t.model}),t.costUsd!=null&&l.push({label:"费用",value:`$${Number(t.costUsd).toFixed(4)}`}),t.durationMs!=null){const s=Math.round(Number(t.durationMs)/1e3);l.push({label:"耗时",value:s>=60?`${Math.floor(s/60)}m${s%60}s`:`${s}s`})}if(t.numTurns!=null&&l.push({label:"轮次",value:String(t.numTurns)}),t.inputTokens!=null||t.outputTokens!=null){const s=t.inputTokens?Number(t.inputTokens).toLocaleString():"0",n=t.outputTokens?Number(t.outputTokens).toLocaleString():"0";l.push({label:"Token",value:`${s} → ${n}`})}return l}const Ee=({group:r})=>{const[t,l]=m.useState(!1),s=r.messages.length>1,n=r.messages[r.messages.length-1],i=J(n);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"max-w-[85%] rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50/90 dark:bg-gray-900/80 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>s&&l(!t),className:g("w-full px-3 py-2 flex items-center gap-2 text-left min-w-0",s&&"hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"),children:[s?t?e.jsx(D,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(L,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(F,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-gray-600 dark:text-gray-300 flex-shrink-0",children:"系统消息"}),s&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-gray-200/70 dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex-shrink-0",children:[r.messages.length," 条"]}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:r.time}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:r.content})]}),!t&&i.length>0&&e.jsx("div",{className:"px-3 pb-2 flex flex-wrap gap-1.5",children:i.map((c,p)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 max-w-full",children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:c.label}),e.jsx("span",{className:"font-semibold truncate",children:c.value})]},`${c.label}-${p}`))}),t&&s&&e.jsx("div",{className:"border-t border-gray-200/80 dark:border-gray-800 divide-y divide-gray-200/70 dark:divide-gray-800",children:r.messages.map(c=>{const p=J(c);return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate min-w-0",children:c.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:c.time})]}),p.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:p.map((d,u)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 max-w-full",children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:d.label}),e.jsx("span",{className:"font-semibold truncate",children:d.value})]},`${d.label}-${u}`))})]},c.id)})})]})})},Le=({message:r})=>{const[t,l]=m.useState(!1);return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-indigo-50/80 dark:bg-indigo-950/40 border border-indigo-200/60 dark:border-indigo-800/40 rounded-xl px-3 py-2 max-w-[85%] cursor-pointer hover:bg-indigo-100/60 dark:hover:bg-indigo-950/60 transition-colors",onClick:()=>l(!t),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(be,{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-indigo-600 dark:text-indigo-400",children:t?"思考过程":"思考中..."}),e.jsxs("span",{className:"text-[10px] text-indigo-400 dark:text-indigo-500",children:["(",r.content.length," 字)"]}),t?e.jsx(_,{className:"w-3 h-3 text-indigo-400"}):e.jsx(D,{className:"w-3 h-3 text-indigo-400"})]}),t&&e.jsx("div",{className:"mt-2 text-sm text-indigo-800/80 dark:text-indigo-200/80 markdown-body-sm prose-sm",children:e.jsx(C,{children:r.content})})]})})},Re=({task:r,onClick:t,onDelete:l})=>e.jsxs("div",{onClick:t,className:"bg-white dark:bg-gray-900 p-4 rounded-xl border border-gray-100 dark:border-gray-800 shadow-sm active:scale-[0.98] transition-transform cursor-pointer group",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsx(ee,{status:r.status}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:V(r.startTime)}),e.jsx("button",{onClick:l,className:"p-0.5 text-gray-300 dark:text-gray-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all",children:e.jsx(K,{className:"w-3.5 h-3.5"})})]})]}),e.jsx("p",{className:"text-sm text-gray-800 dark:text-gray-200 font-medium line-clamp-2 mb-3 leading-relaxed",children:r.title}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-500 dark:text-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:[r.confirmCount," 次确认"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[r.toolCount," 个工具调用"]}),r.duration&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:r.duration})]})]}),e.jsx(L,{className:"w-4 h-4 text-gray-300 dark:text-gray-600"})]})]}),ee=({status:r})=>{switch(r){case"running":return e.jsxs("div",{className:"flex items-center gap-1.5 text-primary-600 dark:text-primary-400",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary-600 dark:bg-primary-400 animate-pulse"}),e.jsx("span",{className:"text-xs font-medium",children:"进行中"})]});case"confirm":return e.jsxs("div",{className:"flex items-center gap-1.5 text-orange-600 dark:text-orange-400",children:[e.jsx(fe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"等待确认"})]});case"completed":return e.jsxs("div",{className:"flex items-center gap-1.5 text-green-600",children:[e.jsx(R,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"已完成"})]});case"failed":return e.jsxs("div",{className:"flex items-center gap-1.5 text-red-600",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"text-xs font-medium",children:"失败"})]})}};export{ze as History};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as x,r as f,j as m}from"./vendor-react-DSV5aFEg.js";import{u as k}from"./index-DOgH1Kf3.js";import{c as H}from"./code-highlight-CEcsuMpw.js";import{p as d,s as M}from"./WorkspaceLinkedText-DQyPLk-X.js";import{r as j,M as w,a as K}from"./vendor-markdown-BDwu-Ux6.js";import"./vendor-icons-CNN4EKVi.js";const P=[K];function R(t){return function(){return function(n){h(n,t)}}}function W(t){return(t==null?void 0:t.type)==="element"&&["a","code","pre"].includes(t.tagName)}function h(t,o){if(!(t!=null&&t.children)||W(t))return;const r=[];let n=!1;for(const e of t.children){if((e==null?void 0:e.type)==="text"&&typeof e.value=="string"){const c=M(e.value,o);if(c.length===1&&c[0].type==="text"){r.push(e);continue}n=!0;for(const i of c)i.type==="text"?r.push({type:"text",value:i.text}):r.push({type:"element",tagName:"a",properties:{href:i.target.href,title:`打开 ${i.target.path}:${i.target.line}`},children:[{type:"text",value:i.text}]});continue}h(e,o),r.push(e)}n&&(t.children=r)}function $(t){return t.startsWith("/workspace?")}function S({children:t,enableWorkspaceLinks:o=!0}){const r=x(),{cliConfig:n}=k(),e=n==null?void 0:n.workDir,c=f.useMemo(()=>{const s=[[j,H]];return o&&s.push(R(e)),s},[o,e]),i=f.useMemo(()=>({a({href:s,children:g,node:N,...l}){const a=typeof s=="string"?d(s,e):null,p=(a==null?void 0:a.href)||(typeof s=="string"&&$(s)?s:""),y=p||s;return m.jsx("a",{...l,href:y,title:a?`打开 ${a.path}:${a.line}`:l.title,onClick:u=>{!p||u.button!==0||u.metaKey||u.ctrlKey||u.shiftKey||u.altKey||(u.preventDefault(),r(p))},children:g})}}),[r,e]);return m.jsx(w,{remarkPlugins:P,rehypePlugins:c,components:i,children:t})}export{S as default};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{r as i,j as e,R as F}from"./vendor-react-DSV5aFEg.js";import{u as bt}from"./vendor-virtual-CcftJrIC.js";import{u as yt,a as Be,c as g}from"./index-DOgH1Kf3.js";import{g as kt,M as ne,i as He,W as jt}from"./WorkspaceLinkedText-DQyPLk-X.js";import{P as wt}from"./PageTopBar-C8j-5s_3.js";import{b as le,c as oe,d as Nt,T as Se,A as vt,H as Ct,e as Oe,f as St,F as Tt,g as Te,h as De,i as Dt,j as Et,X as ie,k as Ee,l as Re,m as de,n as V,B as Rt,P as Pt,o as Ft,p as Lt}from"./vendor-icons-CNN4EKVi.js";function Ve(r){if(/^```/.test(r.trim()))return r;try{const l=JSON.parse(r);return"```json\n"+JSON.stringify(l,null,2)+"\n```"}catch{}return r.split(`
|
|
2
|
-
`).map(l=>{const a=l.trim();if(!a)return l;try{const d=JSON.parse(a);return"```json\n"+JSON.stringify(d,null,2)+"\n```"}catch{return l}}).join(`
|
|
3
|
-
`)}function Mt(r){var a;const t=(r==null?void 0:r.cliCommand)||"",o=((a=t.split(/[\\/]/).pop())==null?void 0:a.toLowerCase())||t.toLowerCase();return((r==null?void 0:r.cliType)||(o.includes("codex")?"codex":"claude"))==="codex"?"Codex CLI":"Claude Code"}const sr=()=>{const{status:r,messages:t,connectionStatus:o,sendMessage:l,confirmResponse:a,questionResponse:d,interrupt:c,newSession:b,editUserMessage:j,cliConfig:m,tokenUsage:f,hasMoreMessagesBefore:x,isLoadingOlderMessages:w,loadOlderMessages:S}=yt(),h=Mt(m),[u,p]=i.useState(""),[N,v]=i.useState(!1),[C,k]=i.useState(!1),[_,R]=i.useState(""),[Je,ce]=i.useState([]),[M,Pe]=i.useState(!1),[Fe,xe]=i.useState(!1),[G,P]=i.useState(!1),[Le,qe]=i.useState(""),[Me,Xe]=i.useState([]),[Ie,Ye]=i.useState([]),[Ze,et]=i.useState(""),[tt,rt]=i.useState(!1),[X,$e]=i.useState(!1),[Y,I]=i.useState(""),[ue,W]=i.useState(!1),[L,Z]=i.useState(null),[K,Q]=i.useState(""),[me,ee]=i.useState(!1),[st,$]=i.useState(null),[ge,Ae]=i.useState({}),te=i.useRef(null),he=i.useRef(null),fe=i.useRef(null),pe=i.useRef(!0),J=i.useRef(),be=i.useRef(new Set),ye=i.useRef(!1),T=i.useMemo(()=>kt(t),[t]),A=bt({count:T.length,getScrollElement:()=>fe.current,estimateSize:s=>{const n=T[s];return n?n.type==="system_group"?ge[n.id]?48+n.messages.length*42:44:n.type==="tool_group"?ge[n.id]?72+n.messages.length*40:58:n.type==="system"&&!n.details&&n.content==="系统消息"?0:n.type==="system"&&!n.details?32:n.type==="thinking"?44:n.type==="tool"?56:n.type==="confirm"?80:n.type==="question"?100:n.type==="error"?60:80:80},overscan:5});i.useEffect(()=>{const s=fe.current;if(!s)return;const n=()=>{pe.current=s.scrollHeight-s.scrollTop-s.clientHeight<150,s.scrollTop<80&&x&&!w&&S()};return s.addEventListener("scroll",n,{passive:!0}),()=>s.removeEventListener("scroll",n)},[x,w,S]),i.useEffect(()=>{t.length===0&&(ye.current=!1,be.current.clear(),Ae({}))},[t.length]),i.useEffect(()=>{T.length>0&&!ye.current&&(ye.current=!0,requestAnimationFrame(()=>{A.scrollToIndex(T.length-1,{align:"end"}),pe.current=!0}))},[T.length,A]);const z=T.length>0?T[T.length-1]:null,at=(z==null?void 0:z.id)||"",nt=(z==null?void 0:z.content)||"";i.useEffect(()=>(T.length>0&&pe.current&&(J.current&&cancelAnimationFrame(J.current),J.current=requestAnimationFrame(()=>{A.scrollToIndex(T.length-1,{align:"end"})})),()=>{J.current&&cancelAnimationFrame(J.current)}),[T.length,at,nt,A]);const lt=i.useCallback(s=>{Ae(n=>({...n,[s]:!n[s]}))},[]),re=i.useCallback(()=>{const s=he.current,n=te.current;if(!s||!n)return;he.current=null;const y=Math.min(s.start,n.value.length),E=Math.min(s.end,n.value.length);n.focus(),n.setSelectionRange(y,E)},[]),D=i.useCallback((s,n=s.length)=>{he.current={start:n,end:n},p(s),requestAnimationFrame(re)},[re]);i.useLayoutEffect(()=>{re()},[u,re]);const Ue=i.useCallback(async()=>{if(!M){Pe(!0);try{const s=await Be.getSkills();ce(s.skills||[]),xe(!0)}catch{ce([]),xe(!0)}finally{Pe(!1)}}},[M]);i.useEffect(()=>{ce([]),xe(!1)},[m==null?void 0:m.workDir,m==null?void 0:m.cliCommand]),i.useEffect(()=>{C&&!Fe&&!M&&Ue()},[C,Fe,M,Ue]);const We=()=>{!u.trim()||r==="running"||(l(u),p(""),k(!1),R(""),W(!1),te.current&&(te.current.style.height="auto"))},it=s=>{const n=s.target.value;p(n);const y=s.target;if(y.style.height="auto",y.style.height=`${Math.min(y.scrollHeight,120)}px`,n.startsWith("/")){const E=n.slice(1).trimStart();R(E),C||k(!0),G&&(P(!1),I(""))}else if(n.startsWith("@")){const E=n.slice(1).trimStart();if(I(E),!G){P(!0);const H=(m==null?void 0:m.workDir)||"~";ae(H)}C&&(k(!1),R(""))}else C&&(k(!1),R("")),G&&(P(!1),I(""))},ot=s=>{a(s)},se=i.useCallback(s=>{if(s==="/"){k(!0),R(""),D("/",1);return}if(s==="@"){P(!0),I(""),D("@",1);const O=(m==null?void 0:m.workDir)||"~";ae(O);return}const n=u,y=n.trimStart(),E=s+" ",H=E.length;if(y===""){D(E,H);return}if(y.startsWith("/ ")||y.startsWith("! ")||y.startsWith("@ ")||y.startsWith("# ")){const O=y.slice(2);D(E+O,H);return}if(y.startsWith("/")||y.startsWith("!")||y.startsWith("@")||y.startsWith("#")){const O=y.indexOf(" "),pt=O>=0?y.slice(O+1):"";D(E+pt,H);return}D(E+n,H)},[m==null?void 0:m.workDir,u,D]),dt=i.useCallback(s=>{D(s+" ",s.length+1),k(!1),R("")},[D]),ae=i.useCallback(async s=>{$e(!0);try{const n=await Be.listFiles(s);qe(n.dir),Xe(n.dirs),Ye(n.files||[]),et(n.parent),rt(n.isRoot)}catch{}$e(!1)},[]),ct=i.useCallback(s=>{const n=Le.split("/").slice(0,3).join("/"),y=s.replace(n,"~");D("@"+y+" ",y.length+2),P(!1),I("")},[Le,D]),ze=i.useCallback(()=>t.filter(s=>s.type==="user"&&s.content.trim()).map(s=>s.content.trim()).filter((s,n,y)=>y.indexOf(s)===n).slice(-20),[t]),xt=i.useCallback(s=>{D(s),W(!1)},[D]),ut=i.useCallback(s=>{r!=="idle"||o!=="connected"||(Z(s.id),Q(s.content),$(null),k(!1),P(!1),W(!1))},[o,r]),mt=i.useCallback(()=>{Z(null),Q(""),ee(!1),$(null)},[]),gt=i.useCallback(async()=>{if(!L||me)return;const s=t.find(n=>n.id===L);if(!K.trim()){$("消息不能为空");return}if(s&&K.trim()===s.content.trim()){$("内容没有变化");return}ee(!0),$(null);try{await j(L,K),Z(null),Q("")}catch(n){$(n instanceof Error?n.message:"编辑消息失败")}finally{ee(!1)}},[j,L,me,K,t]);i.useEffect(()=>{L&&!t.some(s=>s.id===L)&&(Z(null),Q(""),$(null),ee(!1))},[L,t]);const U=o==="disconnected",B=o==="reconnecting",ht=r==="idle"&&o==="connected",ft=A.getVirtualItems(),ke=_.toLowerCase(),je=Je.filter(s=>!ke||s.command.toLowerCase().includes(ke)||s.description.toLowerCase().includes(ke));return e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950",children:[e.jsx(wt,{leading:e.jsx("div",{className:"relative flex items-center justify-center w-4 h-4 flex-shrink-0",children:U?e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500"}):o==="connecting"?e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-500 animate-pulse"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500 z-10"}),r==="running"&&e.jsx("div",{className:"absolute w-4 h-4 rounded-full bg-green-500 opacity-30 animate-ping"})]})}),title:h,meta:e.jsxs(e.Fragment,{children:[(m==null?void 0:m.workDir)&&e.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400 truncate max-w-[120px] flex-shrink-0",children:m.workDir.split("/").pop()}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full font-medium",U?"bg-red-50 dark:bg-red-950 text-red-600 dark:text-red-400":B||o==="connecting"?"bg-yellow-50 dark:bg-yellow-950 text-yellow-600 dark:text-yellow-400":r==="idle"?"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400":r==="running"?"bg-primary-50 dark:bg-primary-950 text-primary-600 dark:text-primary-400":r==="confirm"?"bg-orange-50 dark:bg-orange-950 text-orange-600 dark:text-orange-400":r==="question"?"bg-blue-50 dark:bg-blue-950 text-blue-600 dark:text-blue-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"),children:U?"已断开":B?"重连中...":o==="connecting"?"连接中...":r==="idle"?"空闲":r==="running"?"进行中":r==="confirm"?"等待确认":r==="question"?"等待回答":"空闲"})]}),actions:e.jsxs(e.Fragment,{children:[f.inputTokens>0&&e.jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 font-mono mr-1",title:`会话累计 Token
|
|
4
|
-
输入: ${f.inputTokens.toLocaleString()}
|
|
5
|
-
输出: ${f.outputTokens.toLocaleString()}${f.cacheReadTokens?`
|
|
6
|
-
缓存读: `+f.cacheReadTokens.toLocaleString():""}${f.cacheCreationTokens?`
|
|
7
|
-
缓存写: `+f.cacheCreationTokens.toLocaleString():""}${f.costUsd>0?`
|
|
8
|
-
费用: $`+f.costUsd.toFixed(4):""}`,children:[(f.inputTokens+f.outputTokens).toLocaleString()," tok"]}),e.jsx("button",{onClick:()=>{t.length>0?v(!0):b()},className:"p-2 text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:bg-primary-50 dark:hover:bg-primary-950 rounded-full transition-colors",title:"新开会话",children:e.jsx(le,{className:"w-5 h-5"})})]})}),e.jsx("div",{ref:fe,className:"flex-1 overflow-y-auto",children:T.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-400 dark:text-gray-600 gap-3",children:[e.jsx(oe,{className:"w-12 h-12 opacity-20"}),e.jsx("p",{className:"text-sm font-medium",children:"AgentPilot"}),e.jsx("p",{className:"text-xs text-gray-300 dark:text-gray-600",children:"AI Agent 遥控器,随时随地掌控"})]}):e.jsxs(e.Fragment,{children:[x&&e.jsx("div",{className:"px-4 pt-3 pb-1 flex justify-center",children:e.jsx("button",{type:"button",onClick:S,disabled:w,className:"text-xs px-3 py-1.5 rounded-full bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:border-primary-200 dark:hover:border-primary-800 disabled:opacity-60 transition-colors",children:w?"加载中...":"加载更早消息"})}),e.jsx("div",{style:{height:A.getTotalSize()+16,width:"100%",position:"relative"},children:ft.map(s=>{const n=T[s.index],y=!be.current.has(n.id);return be.current.add(n.id),e.jsx("div",{"data-index":s.index,ref:A.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${s.start}px)`},children:e.jsx("div",{className:g("px-4 py-2"),children:e.jsx($t,{message:n,isStreaming:r==="running"&&s.index===T.length-1&&n.type==="ai",animate:y,expanded:ge[n.id]??!1,onToggleExpand:lt,canEditUserMessage:ht,editingMessageId:L,editingValue:K,editingSubmitting:me,editError:st,onStartEdit:ut,onEditingValueChange:Q,onCancelEdit:mt,onSubmitEdit:gt})})},n.id)})})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-900 border-t border-gray-100 dark:border-gray-800 flex-shrink-0 relative shadow-[0_-1px_8px_rgba(0,0,0,0.04)] dark:shadow-[0_-1px_8px_rgba(0,0,0,0.2)]",children:r==="confirm"?e.jsx(Qt,{pendingMessage:t.filter(s=>s.type==="confirm"&&s.status==="pending").slice(-1)[0],onConfirm:ot}):r==="question"?e.jsx(qt,{pendingMessage:t.filter(s=>s.type==="question"&&s.status==="pending").slice(-1)[0],onAnswer:d}):e.jsxs("div",{children:[e.jsxs("div",{className:"px-3 pt-1 flex items-center gap-1 overflow-x-auto hide-scrollbar",children:[e.jsx(q,{prefix:"/",icon:e.jsx(Nt,{className:"w-3 h-3"}),label:"命令",color:"bg-blue-50/50 dark:bg-blue-950/50 text-blue-500/70 dark:text-blue-400/70 border-blue-200/40 dark:border-blue-800/40",onClick:()=>se("/")}),e.jsx(q,{prefix:"!",icon:e.jsx(Se,{className:"w-3 h-3"}),label:"Bash",color:"bg-amber-50/50 dark:bg-amber-950/50 text-amber-500/70 dark:text-amber-400/70 border-amber-200/40 dark:border-amber-800/40",onClick:()=>se("!")}),e.jsx(q,{prefix:"@",icon:e.jsx(vt,{className:"w-3 h-3"}),label:"文件",color:"bg-green-50/50 dark:bg-green-950/50 text-green-500/70 dark:text-green-400/70 border-green-200/40 dark:border-green-800/40",onClick:()=>se("@")}),e.jsx(q,{prefix:"#",icon:e.jsx(Ct,{className:"w-3 h-3"}),label:"记忆",color:"bg-purple-50/50 dark:bg-purple-950/50 text-purple-500/70 dark:text-purple-400/70 border-purple-200/40 dark:border-purple-800/40",onClick:()=>se("#")}),ze().length>0&&e.jsx(q,{prefix:"",icon:e.jsx(Oe,{className:"w-3 h-3"}),label:"历史",color:"bg-gray-50/50 dark:bg-gray-950/50 text-gray-500/70 dark:text-gray-400/70 border-gray-200/40 dark:border-gray-800/40",onClick:()=>{W(!ue),k(!1),P(!1)}})]}),C&&e.jsx("div",{className:"overflow-hidden border-t border-gray-100 dark:border-gray-800",onBlur:s=>{s.currentTarget.contains(s.relatedTarget)||(k(!1),R(""))},children:e.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain py-1",children:[(je.length>0||M)&&e.jsx("div",{className:"px-4 py-1 text-[10px] font-medium uppercase tracking-wider text-gray-400 dark:text-gray-500",children:"CLI Skills"}),je.map(s=>e.jsxs("button",{onClick:()=>dt(s.command),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-purple-50 dark:hover:bg-purple-950/50 active:bg-purple-100 dark:active:bg-purple-950 transition-colors text-left",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-purple-600 dark:text-purple-400 whitespace-nowrap",children:s.command}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 truncate flex-1",children:s.description}),e.jsx("span",{className:"text-[10px] text-gray-300 dark:text-gray-600 flex-shrink-0",children:s.source})]},`${s.source}:${s.name}`)),M&&e.jsx("div",{className:"px-4 py-3 text-xs text-gray-400 text-center",children:"正在加载 CLI Skills..."}),!M&&je.length===0&&e.jsx("div",{className:"px-4 py-3 text-xs text-gray-400 text-center",children:"命令会原样发送给 CLI"})]})}),G&&e.jsx("div",{className:"overflow-hidden border-t border-gray-100 dark:border-gray-800",onBlur:s=>{s.currentTarget.contains(s.relatedTarget)||(P(!1),I(""))},children:e.jsxs("div",{className:"max-h-52 overflow-y-auto overscroll-contain py-1",children:[!tt&&e.jsxs("button",{onClick:()=>ae(Ze),className:"w-full flex items-center gap-3 px-4 py-2 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors text-left",children:[e.jsx(St,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:"返回上级"})]}),X&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx("div",{className:"w-5 h-5 border-2 border-green-500 border-t-transparent rounded-full animate-spin"})}),!X&&Me.filter(s=>!Y||s.name.toLowerCase().includes(Y.toLowerCase())).map(s=>e.jsxs("button",{onClick:()=>ae(s.path),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-green-50 dark:hover:bg-green-950/50 active:bg-green-100 dark:active:bg-green-950 transition-colors text-left",children:[e.jsx(Tt,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:s.name}),e.jsx(Te,{className:"w-3.5 h-3.5 text-gray-300 dark:text-gray-600 ml-auto flex-shrink-0"})]},s.path)),!X&&Ie.filter(s=>!Y||s.name.toLowerCase().includes(Y.toLowerCase())).map(s=>e.jsxs("button",{onClick:()=>ct(s.path),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-green-50 dark:hover:bg-green-950/50 active:bg-green-100 dark:active:bg-green-950 transition-colors text-left",children:[e.jsx(De,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate flex-1",children:s.name}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:s.ext||"?"})]},s.path)),!X&&Me.length===0&&Ie.length===0&&e.jsx("div",{className:"px-4 py-3 text-xs text-gray-400 text-center",children:"空目录"})]})}),ue&&e.jsx("div",{className:"overflow-hidden border-t border-gray-100 dark:border-gray-800",onBlur:s=>{s.currentTarget.contains(s.relatedTarget)||W(!1)},children:e.jsx("div",{className:"max-h-48 overflow-y-auto overscroll-contain py-1",children:ze().slice().reverse().map((s,n)=>e.jsxs("button",{onClick:()=>xt(s),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-gray-50 dark:hover:bg-gray-800 active:bg-gray-100 dark:active:bg-gray-700 transition-colors text-left",children:[e.jsx(Oe,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 truncate",children:s})]},n))})}),e.jsxs("div",{className:"p-3 pb-safe flex items-center gap-2.5",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("textarea",{ref:te,value:u,onChange:it,placeholder:U||B?"连接已断开":"输入指令…",disabled:U||B,className:"w-full bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 focus:bg-white dark:focus:bg-gray-800 focus:border-primary-400 focus:ring-[3px] focus:ring-primary-100 dark:focus:ring-primary-900 rounded-2xl px-4 py-3 text-sm text-gray-800 dark:text-gray-200 placeholder:text-gray-400 dark:placeholder:text-gray-600 resize-none min-h-[44px] max-h-[120px] transition-all duration-200 outline-none hide-scrollbar",rows:1,onKeyDown:s=>{if(s.key==="Escape"){if(C){s.preventDefault(),k(!1),R("");return}if(G){s.preventDefault(),P(!1),I("");return}if(ue){s.preventDefault(),W(!1);return}}s.key==="Enter"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),We())}})}),r==="running"?e.jsx("button",{className:"p-2.5 bg-red-500 text-white rounded-full flex-shrink-0 hover:bg-red-600 active:scale-95 transition-all shadow-sm",onClick:c,children:e.jsx(Dt,{className:"w-4 h-4 fill-current"})},"interrupt"):e.jsx("button",{onClick:We,disabled:!u.trim()||U||B,className:g("p-2.5 rounded-full flex-shrink-0 transition-all duration-200 shadow-sm active:scale-95",u.trim()&&!U&&!B?"bg-primary-600 text-white hover:bg-primary-700 shadow-primary-200 dark:shadow-primary-900":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500 shadow-none"),children:e.jsx(Et,{className:"w-4 h-4"})},"send")]})]})}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>v(!1),className:"absolute inset-0 bg-black/40 z-40"}),e.jsxs("div",{className:"absolute inset-x-4 top-1/2 -translate-y-1/2 bg-white dark:bg-gray-900 rounded-2xl z-50 p-5 shadow-xl",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary-50 dark:bg-primary-950 flex items-center justify-center flex-shrink-0",children:e.jsx(le,{className:"w-5 h-5 text-primary-600 dark:text-primary-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"新开会话"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-0.5",children:"当前会话将保存到会话记录"})]})]}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 py-2.5 border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 rounded-xl font-medium hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors text-sm",children:"取消"}),e.jsx("button",{onClick:()=>{v(!1),b()},className:"flex-1 py-2.5 bg-primary-600 text-white rounded-xl font-medium hover:bg-primary-700 transition-colors text-sm shadow-sm",children:"确认"})]})]})]})]})},It=F.memo(function({message:t,animClass:o,canEdit:l,isEditing:a,editingValue:d,editingSubmitting:c,editError:b,onStartEdit:j,onEditingValueChange:m,onCancelEdit:f,onSubmitEdit:x}){const w=i.useRef(null),S=i.useCallback(h=>{h&&(h.style.height="auto",h.style.height=`${Math.min(h.scrollHeight,240)}px`)},[]);return i.useEffect(()=>{a&&requestAnimationFrame(()=>{const h=w.current;h&&(S(h),h.focus(),h.setSelectionRange(h.value.length,h.value.length))})},[a,S]),a?e.jsx("div",{className:g("flex justify-end",o),children:e.jsxs("div",{className:"w-[95%] max-w-2xl bg-primary-600 text-white rounded-2xl rounded-tr-sm px-3 py-3 shadow-sm",children:[e.jsx("textarea",{ref:w,value:d,disabled:c,onChange:h=>{m(h.target.value),S(h.currentTarget)},onKeyDown:h=>{h.key==="Escape"&&(h.preventDefault(),f()),h.key==="Enter"&&(h.metaKey||h.ctrlKey)&&(h.preventDefault(),x())},className:"w-full min-h-[88px] max-h-60 resize-none overflow-y-auto rounded-xl border border-white/25 bg-white/10 px-3 py-2 text-[15px] leading-relaxed text-white placeholder:text-primary-100 outline-none focus:border-white/60 focus:ring-2 focus:ring-white/20 disabled:opacity-70"}),b&&e.jsx("div",{className:"mt-2 text-xs text-red-100 bg-red-500/25 border border-red-200/30 rounded-lg px-2 py-1",children:b}),e.jsxs("div",{className:"mt-2 flex justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:f,disabled:c,className:"p-1.5 rounded-full text-primary-100 hover:text-white hover:bg-white/15 active:scale-95 transition-all disabled:opacity-50",title:"取消编辑",children:e.jsx(ie,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:x,disabled:c||!d.trim(),className:"p-1.5 rounded-full bg-white text-primary-700 hover:bg-primary-50 active:scale-95 transition-all disabled:opacity-50 disabled:cursor-not-allowed",title:"提交编辑",children:e.jsx(Re,{className:"w-4 h-4"})})]})]})}):e.jsx("div",{className:g("flex justify-end",o),children:e.jsxs("div",{className:"relative group max-w-[95%]",children:[l&&e.jsx("button",{type:"button",onClick:()=>j(t),className:"absolute -left-8 top-1/2 -translate-y-1/2 p-1.5 rounded-full bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 shadow-sm opacity-70 sm:opacity-0 sm:group-hover:opacity-100 focus:opacity-100 transition-all",title:"编辑消息",children:e.jsx(Pt,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"bg-primary-600 text-white rounded-2xl rounded-tr-sm px-4 py-2.5 shadow-sm relative overflow-hidden",children:[e.jsx("p",{className:"text-[15px] leading-relaxed whitespace-pre-wrap break-words",children:e.jsx(jt,{linkClassName:"text-white decoration-white/70",children:t.content})}),e.jsx("span",{className:"text-[10px] text-primary-200 absolute bottom-1 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:t.time})]})]})})}),$t=F.memo(function({message:t,isStreaming:o,animate:l,expanded:a,onToggleExpand:d,canEditUserMessage:c,editingMessageId:b,editingValue:j,editingSubmitting:m,editError:f,onStartEdit:x,onEditingValueChange:w,onCancelEdit:S,onSubmitEdit:h}){var p;const u=l?"message-animate-in":"";switch(t.type){case"system_group":return e.jsx(_t,{group:t,animate:l,expanded:a??!1,onToggleExpand:d});case"tool_group":return e.jsx(Ot,{group:t,animate:l,expanded:a??!1,onToggleExpand:d});case"user":return e.jsx(It,{message:t,animClass:u,canEdit:c,isEditing:b===t.id,editingValue:j,editingSubmitting:m,editError:f,onStartEdit:x,onEditingValueChange:w,onCancelEdit:S,onSubmitEdit:h});case"ai":return e.jsx("div",{className:g("flex justify-start",u),children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 text-gray-800 dark:text-gray-200 rounded-2xl rounded-tl-md px-3.5 py-3 max-w-[94%] shadow-sm relative group markdown-body overflow-hidden min-w-0",children:[e.jsx(ne,{children:t.content}),o&&e.jsx("span",{className:"inline-block w-1.5 h-4 bg-primary-500 animate-pulse ml-0.5 align-text-bottom rounded-sm"}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 absolute bottom-1 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:t.time})]})});case"tool":return e.jsx(Ht,{message:t,animate:l,expanded:a??!1,onToggleExpand:d});case"confirm":return e.jsx("div",{className:g("flex justify-start",u),children:e.jsxs("div",{className:g("border rounded-xl px-4 py-3 max-w-[95%] shadow-sm relative overflow-hidden",t.status==="pending"?"bg-orange-50 dark:bg-orange-950 border-orange-200 dark:border-orange-800":t.status==="approved"?"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800":"bg-red-50 dark:bg-red-950 border-red-200 dark:border-red-800"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.status==="pending"?e.jsx(Ee,{className:"w-4 h-4 text-orange-500"}):t.status==="approved"?e.jsx(Re,{className:"w-4 h-4 text-green-600"}):e.jsx(ie,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{className:g("text-sm font-semibold",t.status==="pending"?"text-orange-800 dark:text-orange-300":t.status==="approved"?"text-green-800 dark:text-green-300":"text-red-800 dark:text-red-300"),children:t.status==="pending"?"等待确认":t.status==="approved"?"已批准":"已拒绝"}),t.permission&&e.jsx(Qe,{permission:t.permission})]}),e.jsx("p",{className:g("text-sm",t.status==="pending"?"text-orange-900 dark:text-orange-200":t.status==="approved"?"text-green-900 dark:text-green-200":"text-red-900 dark:text-red-200"),children:t.content}),((p=t.permission)==null?void 0:p.filePath)&&e.jsx("div",{className:"mt-1.5 text-xs font-mono text-gray-500 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1 rounded break-all",children:t.permission.filePath})]})});case"system":return e.jsx(Gt,{message:t,animate:l});case"question":return e.jsx(Jt,{message:t,animate:l});case"thinking":return e.jsx(Kt,{message:t,animate:l,expanded:a??!1,onToggleExpand:d});case"error":return e.jsx("div",{className:g("flex justify-start",u),children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-950 border border-red-100 dark:border-red-800 text-red-800 dark:text-red-300 rounded-xl px-4 py-3 max-w-[95%] shadow-sm flex items-start gap-2 overflow-hidden",children:[e.jsx(ie,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm leading-relaxed break-words min-w-0",children:t.content})]})});default:return null}},(r,t)=>{const o=He(r.message),l=He(t.message);if(o||l){if(!o||!l||r.message.type!==t.message.type||r.message.id!==t.message.id||r.message.content!==t.message.content||r.message.time!==t.message.time||r.message.messages.length!==t.message.messages.length)return!1;for(let a=0;a<r.message.messages.length;a+=1){const d=r.message.messages[a],c=t.message.messages[a];if(d.id!==c.id||d.content!==c.content||d.status!==c.status||d.toolDetails!==c.toolDetails||d.toolResult!==c.toolResult||d.details!==c.details)return!1}return!(r.animate!==t.animate||r.expanded!==t.expanded)}return!(r.message.id!==t.message.id||r.message.content!==t.message.content||r.message.status!==t.message.status||r.isStreaming!==t.isStreaming||r.animate!==t.animate||r.expanded!==t.expanded||(r.message.type==="user"||t.message.type==="user")&&(r.canEditUserMessage!==t.canEditUserMessage||r.editingMessageId!==t.editingMessageId||(r.editingMessageId===r.message.id||t.editingMessageId===t.message.id)&&(r.editingValue!==t.editingValue||r.editingSubmitting!==t.editingSubmitting||r.editError!==t.editError))||r.message.toolDetails!==t.message.toolDetails||r.message.toolResult!==t.message.toolResult||r.message.permission!==t.message.permission||r.message.question!==t.message.question)});function At(r){const t=(r.toolName||r.content||"").toLowerCase();return["readfile","writefile","read","write","edit","multiedit"].includes(t)}function we(r){return r.toolName&&r.toolName!=="result"?r.toolName:r.content||"tool"}function Ut(r){return _e(r).join("、")||"工具调用"}function _e(r){return Array.from(new Set(r.map(we).filter(Boolean)))}function Wt(r){if(r.some(t=>t.status==="failed"))return"failed";if(r.some(t=>t.status==="running"))return"running";if(r.some(t=>t.status==="success"))return"success"}function zt(r){const t=r.filter(d=>d.status==="running").length,o=r.filter(d=>d.status==="failed").length,l=r.filter(d=>d.status==="success").length,a=[`${r.length} 个`];return t&&a.push(`${t} 运行中`),o&&a.push(`${o} 失败`),l&&!t&&!o&&a.push("已完成"),a.join(" · ")}function Ge(r,t="w-4 h-4"){return At(r)?e.jsx(Ft,{className:t}):e.jsx(oe,{className:t})}function Ne({status:r,className:t="w-3.5 h-3.5"}){return r==="running"?e.jsx(Lt,{className:g(t,"text-primary-500 animate-pulse")}):r==="success"?e.jsx(Re,{className:g(t,"text-green-600")}):r==="failed"?e.jsx(ie,{className:g(t,"text-red-600")}):null}function Bt({status:r}){return e.jsx("span",{className:g("w-1.5 h-1.5 rounded-full flex-shrink-0",r==="running"?"bg-primary-500 animate-pulse":r==="failed"?"bg-red-500":r==="success"?"bg-green-500":"bg-gray-300 dark:bg-gray-600")})}const Ke=F.memo(function({message:t,compact:o=!1}){const l=o?"max-h-40":"max-h-72";return e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",onClick:a=>a.stopPropagation(),children:[t.toolDetails&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-1",children:"输入"}),e.jsx("div",{className:g("text-xs text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 p-2.5 rounded-lg border border-primary-50 dark:border-gray-700 overflow-y-auto markdown-body-sm",l),children:e.jsx(ne,{children:Ve(t.toolDetails)})})]}),t.toolResult&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-medium text-primary-600 dark:text-primary-400 uppercase tracking-wider mb-1",children:"输出"}),e.jsx("div",{className:g("text-xs p-2.5 rounded-lg overflow-y-auto markdown-body-sm",l,t.status==="failed"?"text-red-700 dark:text-red-300 bg-red-50/50 dark:bg-red-950/50 border border-red-100 dark:border-red-900":"text-gray-600 dark:text-gray-400 bg-white/50 dark:bg-gray-900/50 border border-primary-50 dark:border-gray-700"),children:e.jsx(ne,{children:Ve(t.toolResult)})})]})]})}),Ht=F.memo(function({message:t,animate:o,expanded:l,onToggleExpand:a}){const d=o?"message-animate-in":"",c=!!(t.toolDetails||t.toolResult);return e.jsx("div",{className:g("flex justify-start",d),children:e.jsxs("div",{className:g("bg-primary-50 dark:bg-gray-800 border border-primary-100 dark:border-gray-700 rounded-xl px-3 py-2 max-w-[95%] flex flex-col gap-1.5 overflow-hidden",c&&"cursor-pointer hover:bg-primary-100/50 dark:hover:bg-gray-700 transition-colors"),onClick:()=>c&&a(t.id),children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-800 dark:text-primary-300 min-w-0",children:[Ge(t,"w-4 h-4 flex-shrink-0"),e.jsx("span",{className:"text-sm font-medium break-words min-w-0",children:t.content}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(Ne,{status:t.status}),c&&(l?e.jsx(de,{className:"w-3.5 h-3.5 text-primary-500"}):e.jsx(V,{className:"w-3.5 h-3.5 text-primary-500"}))]})]}),l&&c&&e.jsx(Ke,{message:t})]})})}),Ot=F.memo(function({group:t,animate:o,expanded:l,onToggleExpand:a}){const d=o?"message-animate-in":"",c=Wt(t.messages),b=Ut(t.messages),[j,m]=i.useState({}),f=i.useCallback(x=>{m(w=>({...w,[x]:!w[x]}))},[]);return e.jsx("div",{className:g("flex justify-start",d),children:e.jsxs("div",{className:"max-w-[95%] rounded-xl border border-primary-100 dark:border-gray-700 bg-primary-50/90 dark:bg-gray-800 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>a(t.id),className:"w-full px-3 py-2 flex items-center gap-2 text-left min-w-0 hover:bg-primary-100/60 dark:hover:bg-gray-700 transition-colors",children:[l?e.jsx(V,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}):e.jsx(Te,{className:"w-3.5 h-3.5 text-primary-500 flex-shrink-0"}),e.jsx(oe,{className:"w-3.5 h-3.5 text-primary-600 dark:text-primary-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-primary-800 dark:text-primary-300 flex-shrink-0",children:"工具调用"}),e.jsx("span",{className:g("text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0",c==="failed"?"bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300":c==="running"?"bg-primary-100 text-primary-700 dark:bg-primary-950 dark:text-primary-300":"bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300"),children:zt(t.messages)}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"min-w-0 truncate text-xs text-gray-600 dark:text-gray-400",title:b,children:b}),e.jsx("span",{className:"ml-auto flex-shrink-0",children:e.jsx(Ne,{status:c})})]}),!l&&e.jsx("div",{className:"px-3 pb-2 flex flex-wrap gap-1.5",children:_e(t.messages).map(x=>{const w=t.messages.find(S=>we(S)===x);return e.jsxs("span",{className:"inline-flex max-w-full min-w-0 items-center gap-1.5 text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-600 dark:text-gray-300 border border-primary-100/60 dark:border-gray-700",title:x,children:[e.jsx(Bt,{status:w==null?void 0:w.status}),e.jsx("span",{className:"truncate text-left",children:x})]},x)})}),l&&e.jsx("div",{className:"border-t border-primary-100/80 dark:border-gray-700 divide-y divide-primary-100/70 dark:divide-gray-700",children:t.messages.map(x=>{const w=we(x),S=x.content&&x.content!==w,h=!!(x.toolDetails||x.toolResult),u=!!j[x.id];return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>h&&f(x.id),className:g("w-full flex flex-col gap-1 text-primary-800 dark:text-primary-300 min-w-0 text-left",h&&"cursor-pointer hover:text-primary-900 dark:hover:text-primary-200"),children:[e.jsxs("div",{className:"w-full flex items-start gap-2 min-w-0",children:[Ge(x,"w-3.5 h-3.5 flex-shrink-0 mt-0.5"),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-semibold",title:w,children:w}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:x.time}),h&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-white/70 dark:bg-gray-900/50 text-gray-500 dark:text-gray-400 border border-primary-100/60 dark:border-gray-700",children:x.toolDetails&&x.toolResult?"输入/输出":x.toolDetails?"输入":"输出"}),e.jsx(Ne,{status:x.status,className:"w-3 h-3"}),h&&(u?e.jsx(de,{className:"w-3 h-3 text-primary-500"}):e.jsx(V,{className:"w-3 h-3 text-primary-500"}))]})]}),S&&e.jsx("span",{className:"w-full pl-5 pr-1 text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:x.content})]}),h&&u&&e.jsx(Ke,{message:x,compact:!0})]},x.id)})})]})})});function Vt(r){const t=Math.round(r/1e3);return t>=60?`${Math.floor(t/60)}m${t%60}s`:`${t}s`}function ve(r){if(!r)return[];const t=[];if(r.model&&t.push({label:"模型",value:r.model,color:"bg-purple-50 text-purple-700 dark:bg-purple-950 dark:text-purple-300"}),r.costUsd!=null&&t.push({label:"费用",value:`$${Number(r.costUsd).toFixed(4)}`,color:"bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300"}),r.durationMs!=null&&t.push({label:"耗时",value:Vt(Number(r.durationMs)),color:"bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300"}),r.numTurns!=null&&t.push({label:"轮次",value:String(r.numTurns),color:"bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-300"}),r.inputTokens!=null||r.outputTokens!=null){const o=r.inputTokens?Number(r.inputTokens).toLocaleString():"0",l=r.outputTokens?Number(r.outputTokens).toLocaleString():"0";let a=`${o} → ${l}`;if(r.cacheReadTokens||r.cacheCreationTokens){const d=[];r.cacheCreationTokens&&d.push(`缓存写 ${Number(r.cacheCreationTokens).toLocaleString()}`),r.cacheReadTokens&&d.push(`缓存读 ${Number(r.cacheReadTokens).toLocaleString()}`),a+=` (${d.join(", ")})`}t.push({label:"Token",value:a,color:"bg-cyan-50 text-cyan-700 dark:bg-cyan-950 dark:text-cyan-300"})}return r.toolsCount!=null&&t.push({label:"工具",value:String(r.toolsCount),color:"bg-indigo-50 text-indigo-700 dark:bg-indigo-950 dark:text-indigo-300"}),t}function Ce(r){return r.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map((t,o)=>e.jsxs("span",{className:g("inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium max-w-full",t.color),children:[e.jsx("span",{className:"opacity-60 flex-shrink-0",children:t.label}),e.jsx("span",{className:"font-semibold truncate",children:t.value})]},`${t.label}-${o}`))})}const _t=F.memo(function({group:t,animate:o,expanded:l,onToggleExpand:a}){const d=o?"message-animate-in":"",c=t.messages[t.messages.length-1],b=ve(c==null?void 0:c.details),j=t.messages.length>1,m=t.messages.filter(f=>{var x;return((x=f.details)==null?void 0:x.subtype)==="result"}).length;return e.jsx("div",{className:g("flex justify-start",d),children:e.jsxs("div",{className:"max-w-[95%] rounded-xl border border-gray-200 dark:border-gray-800 bg-gray-50/90 dark:bg-gray-900/80 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>j&&a(t.id),className:g("w-full px-3 py-2 flex items-center gap-2 text-left min-w-0",j&&"hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer"),children:[j?l?e.jsx(V,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(Te,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}):e.jsx(oe,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-gray-600 dark:text-gray-300 flex-shrink-0",children:"系统消息"}),j&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-gray-200/70 dark:bg-gray-800 text-gray-500 dark:text-gray-400 flex-shrink-0",children:[t.messages.length," 条",m>0?` · ${m} 次完成`:""]}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.time}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate min-w-0",children:t.content})]}),!l&&b.length>0&&e.jsx("div",{className:"px-3 pb-2",children:Ce(b)}),l&&j&&e.jsx("div",{className:"border-t border-gray-200/80 dark:border-gray-800 divide-y divide-gray-200/70 dark:divide-gray-800",children:t.messages.map(f=>{const x=ve(f.details);return e.jsxs("div",{className:"px-3 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate min-w-0",children:f.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0",children:f.time})]}),x.length>0&&e.jsx("div",{className:"mt-1.5",children:Ce(x)})]},f.id)})})]})})}),Gt=F.memo(function({message:t,animate:o}){const l=t.details,a=o?"message-animate-in":"",d=t.content==="系统消息";if((!l||Object.keys(l).length===0)&&d)return null;if(!l||Object.keys(l).length===0)return e.jsx("div",{className:g("flex justify-start",a),children:e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-800 px-3 py-1 rounded-full",children:t.content})});const c=l.subtype==="result",b=l.subtype==="init",j=ve(l);return e.jsx("div",{className:g("flex justify-start",a),children:e.jsxs("div",{className:g("px-3 py-2 rounded-xl border max-w-[95%]",c?"bg-green-50/80 dark:bg-green-950/40 border-green-200/60 dark:border-green-800/40":b?"bg-blue-50/80 dark:bg-blue-950/40 border-blue-200/60 dark:border-blue-800/40":"bg-gray-50 dark:bg-gray-800/80 border-gray-200 dark:border-gray-700"),children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx("span",{className:g("text-xs font-medium",c?"text-green-700 dark:text-green-300":b?"text-blue-700 dark:text-blue-300":"text-gray-500 dark:text-gray-400"),children:t.content}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:t.time})]}),Ce(j)]})})}),Kt=F.memo(function({message:t,animate:o,expanded:l,onToggleExpand:a}){const d=o?"message-animate-in":"";return e.jsx("div",{className:g("flex justify-start",d),children:e.jsxs("div",{className:"bg-indigo-50/80 dark:bg-indigo-950/40 border border-indigo-200/60 dark:border-indigo-800/40 rounded-xl px-3 py-2 max-w-[95%] cursor-pointer hover:bg-indigo-100/60 dark:hover:bg-indigo-950/60 transition-colors",onClick:()=>a(t.id),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Rt,{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-indigo-600 dark:text-indigo-400",children:l?"思考过程":"思考中..."}),e.jsxs("span",{className:"text-[10px] text-indigo-400 dark:text-indigo-500",children:["(",t.content.length," 字)"]}),l?e.jsx(de,{className:"w-3 h-3 text-indigo-400"}):e.jsx(V,{className:"w-3 h-3 text-indigo-400"})]}),l&&e.jsx("div",{className:"mt-2 text-sm text-indigo-800/80 dark:text-indigo-200/80 markdown-body-sm prose-sm",children:e.jsx(ne,{children:t.content})})]})})}),Qe=({permission:r})=>{const t={file:{icon:De,label:"文件操作",color:"bg-primary-100 text-primary-700 dark:bg-primary-900 dark:text-primary-300"},command:{icon:Se,label:"命令执行",color:"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300"},other:{icon:Ee,label:"权限请求",color:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"}}[r.category],o=t.icon;return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full font-medium ${t.color}`,children:[e.jsx(o,{className:"w-3 h-3"}),t.label]})},Qt=({pendingMessage:r,onConfirm:t})=>{const[o,l]=i.useState(!1),a=r==null?void 0:r.permission;return e.jsxs("div",{className:"p-4 pb-safe",children:[e.jsxs("div",{className:"flex items-center gap-2 text-orange-600 dark:text-orange-400 mb-3",children:[e.jsx(Ee,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:"需要确认"}),a&&e.jsx(Qe,{permission:a})]}),e.jsx("div",{className:"mb-3",children:e.jsx("p",{className:"text-sm text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-100 dark:border-gray-700",children:(r==null?void 0:r.content)||"CLI 请求确认"})}),(a==null?void 0:a.category)==="file"&&a.filePath&&e.jsxs("div",{className:"mb-3 bg-primary-50 dark:bg-primary-950 border border-primary-100 dark:border-primary-900 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary-800 dark:text-primary-300 mb-1",children:[e.jsx(De,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:a.toolName})]}),e.jsx("div",{className:"text-xs font-mono text-primary-600 dark:text-primary-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1 rounded",children:a.filePath})]}),(a==null?void 0:a.category)==="command"&&a.command&&e.jsxs("div",{className:"mb-3 bg-amber-50 dark:bg-amber-950 border border-amber-100 dark:border-amber-900 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-800 dark:text-amber-300 mb-1",children:[e.jsx(Se,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:"命令执行"})]}),e.jsx("div",{className:"text-xs font-mono text-amber-700 dark:text-amber-400 bg-white/50 dark:bg-gray-900/50 px-2 py-1.5 rounded whitespace-pre-wrap break-all",children:a.command})]}),(a==null?void 0:a.diffContent)&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 mb-1.5",children:[o?e.jsx(de,{className:"w-3.5 h-3.5"}):e.jsx(V,{className:"w-3.5 h-3.5"}),o?"收起内容":"查看变更内容"]}),o&&e.jsx("div",{className:"overflow-hidden",children:e.jsx("div",{className:"text-xs font-mono bg-slate-800 text-slate-200 p-3 rounded-lg max-h-48 overflow-y-auto whitespace-pre-wrap break-all",children:a.diffContent})})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>t(!1),className:"flex-1 py-2.5 border border-red-200 dark:border-red-800 text-red-600 dark:text-red-400 rounded-lg font-medium hover:bg-red-50 dark:hover:bg-red-950 transition-colors",children:"拒绝"}),e.jsx("button",{onClick:()=>t(!0),className:"flex-1 py-2.5 bg-primary-600 text-white rounded-lg font-medium hover:bg-primary-700 transition-colors shadow-sm",children:"批准"})]})]})},Jt=F.memo(function({message:t,animate:o}){var c;const l=o?"message-animate-in":"",a=t.question,d=t.status==="answered";return e.jsx("div",{className:g("flex justify-start",l),children:e.jsxs("div",{className:g("border rounded-xl px-4 py-3 max-w-[95%] shadow-sm relative overflow-hidden","bg-blue-50 dark:bg-blue-950 border-blue-200 dark:border-blue-800"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(le,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-semibold text-blue-800 dark:text-blue-300",children:d?"已回答":"Agent 提问"})]}),(c=a==null?void 0:a.questions)==null?void 0:c.map((b,j)=>e.jsxs("div",{className:"mb-2 last:mb-0",children:[b.header&&e.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400 uppercase tracking-wider",children:b.header}),e.jsx("p",{className:"text-sm text-blue-900 dark:text-blue-200",children:b.question}),b.options&&b.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:b.options.map((m,f)=>e.jsx("span",{className:"text-xs px-2 py-1 rounded-full bg-blue-100/60 dark:bg-blue-900/60 text-blue-700 dark:text-blue-300 border border-blue-200/50 dark:border-blue-800/50",children:m.label},f))})]},j))]})})}),qt=({pendingMessage:r,onAnswer:t})=>{const[o,l]=i.useState({}),[a,d]=i.useState({}),c=r==null?void 0:r.question,b=(c==null?void 0:c.questions)||[],j=b.length<=1;i.useEffect(()=>{l({}),d({})},[r==null?void 0:r.id]);const m=u=>{var N;const p=(N=o[u])==null?void 0:N.trim();return p||(a[u]||[]).join(", ")},f=(u,p)=>j?p||m(0):b.map((N,v)=>{const C=v===u&&p?p:m(v);return`${N.header?`[${N.header}] ${N.question}`:N.question}
|
|
9
|
-
回答:${C}`}).join(`
|
|
10
|
-
|
|
11
|
-
`),x=b.length>0&&b.every((u,p)=>!!m(p)),w=(u,p,N)=>{if(j&&!N){t(f(u,p),c==null?void 0:c.toolUseId);return}l(v=>({...v,[u]:""})),d(v=>{const C=v[u]||[],k=N?C.includes(p)?C.filter(_=>_!==p):[...C,p]:[p];return{...v,[u]:k}})},S=(u,p)=>{l(N=>({...N,[u]:p})),p.trim()&&d(N=>({...N,[u]:[]}))},h=()=>{x&&(t(f(),c==null?void 0:c.toolUseId),l({}),d({}))};return e.jsxs("div",{className:"p-4 pb-safe",children:[e.jsxs("div",{className:"flex items-center gap-2 text-blue-600 dark:text-blue-400 mb-3",children:[e.jsx(le,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:"Agent 提问"})]}),b.map((u,p)=>{var C;const N=a[p]||[],v=o[p]||"";return e.jsxs("div",{className:"mb-3",children:[u.header&&e.jsx("span",{className:"text-[10px] font-medium text-blue-600 dark:text-blue-400 uppercase tracking-wider",children:u.header}),e.jsx("p",{className:"text-sm text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-100 dark:border-gray-700",children:u.question}),u.options&&u.options.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:u.options.map((k,_)=>{const R=N.includes(k.label);return e.jsxs("button",{onClick:()=>w(p,k.label,u.multiSelect),className:g("w-full text-left px-4 py-3 border rounded-lg transition-colors",R?"bg-blue-100 dark:bg-blue-900 border-blue-400 dark:border-blue-600":"bg-blue-50 dark:bg-blue-950 border-blue-200 dark:border-blue-800 hover:bg-blue-100 dark:hover:bg-blue-900"),children:[e.jsx("span",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:k.label}),k.description&&e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400 mt-0.5",children:k.description})]},_)})}),e.jsx("input",{type:"text",value:v,onChange:k=>S(p,k.target.value),onKeyDown:k=>{k.key==="Enter"&&j&&v.trim()?(t(v.trim(),c==null?void 0:c.toolUseId),l({})):k.key==="Enter"&&x&&h()},placeholder:(C=u.options)!=null&&C.length?"或输入自定义回答...":"输入回答...",className:"mt-2 w-full bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 focus:border-blue-400 focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900 rounded-lg px-3 py-2 text-sm text-gray-800 dark:text-gray-200 placeholder:text-gray-400 dark:placeholder:text-gray-600 outline-none transition-all"})]},p)}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:h,disabled:!x,className:g("px-4 py-2 rounded-lg font-medium text-sm transition-colors",x?"bg-blue-600 text-white hover:bg-blue-700 shadow-sm":"bg-gray-200 dark:bg-gray-700 text-gray-400 dark:text-gray-500"),children:"发送"})})]})},q=({prefix:r,icon:t,label:o,color:l,onClick:a})=>e.jsxs("button",{onClick:a,className:g("inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded border text-[10px] font-normal whitespace-nowrap active:scale-95 transition-all flex-shrink-0 opacity-50 hover:opacity-100",l),children:[t,e.jsx("span",{children:o})]});export{sr as Session};
|