pi-web-ui 0.90.0 → 0.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +7 -4
- package/README.zh-CN.md +6 -3
- package/bin/pi-web-ui.mjs +37 -10
- package/deploy/pi-web-ui.service +36 -31
- package/dist/server/agent-service.js +546 -90
- package/dist/server/index.js +61 -14
- package/dist/server/terminals.js +50 -20
- package/package.json +32 -32
- package/web/dist/assets/TerminalPanel-CkxM4Byl.js +3 -0
- package/web/dist/assets/index-DJIV4A-t.js +355 -0
- package/web/dist/assets/index-DLdcRBs_.css +1 -0
- package/web/dist/assets/markdown-CCeVCbci.css +1 -0
- package/web/dist/assets/markdown-eUQn_o9D.js +296 -0
- package/web/dist/assets/react-CR5VJ85Q.js +9 -0
- package/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
- package/web/dist/assets/xterm-B1njb2Cr.css +1 -0
- package/web/dist/assets/xterm-Cf5xxe4g.js +16 -0
- package/web/dist/index.html +6 -4
- package/web/dist/assets/TerminalPanel-BDbdLhpT.js +0 -6
- package/web/dist/assets/TerminalPanel-DOrYoP_4.css +0 -32
- package/web/dist/assets/index-1f_DP8S3.js +0 -380
- package/web/dist/assets/index-DeUwDA-C.css +0 -10
- package/web/dist/assets/markdown-D3PKeHAZ.js +0 -311
- package/web/dist/assets/react-w24rH0km.js +0 -24
- package/web/dist/assets/xterm-B96xOxS9.js +0 -38
package/dist/server/index.js
CHANGED
|
@@ -358,10 +358,10 @@ app.get("/api/file", async (req, res) => {
|
|
|
358
358
|
* get a sandboxed CSP (?allowJs=1 relaxes scripts only — never same-origin),
|
|
359
359
|
* everything else streams with its real content type.
|
|
360
360
|
*/
|
|
361
|
-
app.get("/api/preview/*", async (req, res) => {
|
|
361
|
+
app.get("/api/preview/*splat", async (req, res) => {
|
|
362
362
|
try {
|
|
363
|
-
// SAFETY: Express
|
|
364
|
-
const captured = String(req.params
|
|
363
|
+
// SAFETY: Express 5 命名通配 *splat 落在 req.params.splat(Express 4 是 params[0])。
|
|
364
|
+
const captured = String(req.params.splat ?? "");
|
|
365
365
|
const ABS_MARKER = "__abs__/";
|
|
366
366
|
const cid = typeof req.query.clientId === "string" ? req.query.clientId : "";
|
|
367
367
|
const cs = cid ? service.get(cid) : undefined;
|
|
@@ -509,9 +509,9 @@ const PLUGINS_DIR = join(DATA_DIR, "plugins");
|
|
|
509
509
|
// 插件 HTTP 路由挂载点:host.route("GET", "/inbox") 实际暴露为
|
|
510
510
|
// /plugins-api/<id>/inbox。PI_WEB_TOKEN 鉴权(上方 app.use)自动覆盖;
|
|
511
511
|
// 响应已在前面过了 express.json。注意不要在此 catch-all 里消费 body。
|
|
512
|
-
app.all(["/plugins-api/:id/*", "/plugins-api/:id"], (req, res) => {
|
|
513
|
-
// SAFETY: Express
|
|
514
|
-
const rest = String(req.params
|
|
512
|
+
app.all(["/plugins-api/:id/*splat", "/plugins-api/:id"], (req, res) => {
|
|
513
|
+
// SAFETY: Express 5 命名通配 *splat 落在 req.params.splat(Express 4 是 params[0])。
|
|
514
|
+
const rest = String(req.params.splat ?? "");
|
|
515
515
|
pluginMgr.handleHttp(String(req.params.id ?? ""), req.method, rest, req, res);
|
|
516
516
|
});
|
|
517
517
|
function proxyForwardPath(hit, url) {
|
|
@@ -583,9 +583,9 @@ app.use((req, res, next) => {
|
|
|
583
583
|
}
|
|
584
584
|
proxyHttp(hit, req, res);
|
|
585
585
|
});
|
|
586
|
-
app.get("/plugins/:id/client/*", (req, res) => {
|
|
587
|
-
// SAFETY:
|
|
588
|
-
const rest = String(req.params
|
|
586
|
+
app.get("/plugins/:id/client/*splat", (req, res) => {
|
|
587
|
+
// SAFETY: Express 5 命名通配 *splat 落在 req.params.splat(Express 4 是 params[0])。
|
|
588
|
+
const rest = String(req.params.splat ?? "");
|
|
589
589
|
// 特权 DOM 门禁:声明了 dom 能力的插件,其 bundle 需用户逐个授权后才下发
|
|
590
590
|
// (同源 bundle 技术上拦不住 DOM 访问,门只能放在这里;见 server/plugin-dom.ts)。
|
|
591
591
|
if (pluginMgr.isDomBundleBlocked(String(req.params.id ?? ""))) {
|
|
@@ -1442,6 +1442,32 @@ wss.on("connection", (ws) => {
|
|
|
1442
1442
|
case "switch_conversation":
|
|
1443
1443
|
void cs.switchConversation(msg.id);
|
|
1444
1444
|
break;
|
|
1445
|
+
case "take_over_conversation":
|
|
1446
|
+
if (typeof service.takeOverConversation === "function") {
|
|
1447
|
+
void service.takeOverConversation(clientId, msg.owner, msg.id);
|
|
1448
|
+
}
|
|
1449
|
+
else {
|
|
1450
|
+
send({
|
|
1451
|
+
type: "notice",
|
|
1452
|
+
level: "error",
|
|
1453
|
+
text: "当前引擎不支持过户(take over),请用 pi 引擎",
|
|
1454
|
+
textEn: "Takeover is not supported by the current engine; use the pi engine.",
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
break;
|
|
1458
|
+
case "peek_elsewhere_question":
|
|
1459
|
+
if (typeof service.peekElsewhereQuestion === "function") {
|
|
1460
|
+
void service.peekElsewhereQuestion(clientId, msg.owner, msg.id);
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
send({
|
|
1464
|
+
type: "notice",
|
|
1465
|
+
level: "error",
|
|
1466
|
+
text: "当前引擎不支持跨页作答,请用 pi 引擎",
|
|
1467
|
+
textEn: "Cross-page answering is not supported by the current engine; use the pi engine.",
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
break;
|
|
1445
1471
|
case "list_files":
|
|
1446
1472
|
void cs.listFiles(msg.path);
|
|
1447
1473
|
break;
|
|
@@ -1919,7 +1945,23 @@ wss.on("connection", (ws) => {
|
|
|
1919
1945
|
void cs.rescanDshPatches?.();
|
|
1920
1946
|
break;
|
|
1921
1947
|
case "question_answer":
|
|
1922
|
-
|
|
1948
|
+
if (msg.owner) {
|
|
1949
|
+
// 跨页作答:答案转交持有方会话(本页不持有该问卷)。
|
|
1950
|
+
if (typeof service.answerElsewhereQuestion === "function") {
|
|
1951
|
+
void service.answerElsewhereQuestion(clientId, msg.owner, msg.id, msg.answers, msg.cancelled);
|
|
1952
|
+
}
|
|
1953
|
+
else {
|
|
1954
|
+
send({
|
|
1955
|
+
type: "notice",
|
|
1956
|
+
level: "error",
|
|
1957
|
+
text: "当前引擎不支持跨页作答,请用 pi 引擎",
|
|
1958
|
+
textEn: "Cross-page answering is not supported by the current engine; use the pi engine.",
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
else {
|
|
1963
|
+
void cs.answerQuestion?.(msg.id, msg.answers, msg.cancelled);
|
|
1964
|
+
}
|
|
1923
1965
|
break;
|
|
1924
1966
|
case "page_response":
|
|
1925
1967
|
// 浏览器(page-picker 扩展经前端)对 browser_page 的回包:恢复挂起的
|
|
@@ -2212,10 +2254,15 @@ async function shutdown(signal = "SIGINT") {
|
|
|
2212
2254
|
}
|
|
2213
2255
|
shuttingDown = true;
|
|
2214
2256
|
console.log("\nshutting down…");
|
|
2215
|
-
// Windows ConPTY 兜底看门狗(
|
|
2216
|
-
// ClosePseudoConsole
|
|
2257
|
+
// Windows ConPTY 兜底看门狗(issue #215):主线程若死锁在 native
|
|
2258
|
+
// ClosePseudoConsole 里,事件循环冻结,进程内的 forceExitTimer 永远触发不了 ——
|
|
2217
2259
|
// 只能靠外部进程收尾。超时取 forceExit + 余量(只在进程内兜底失效时才开火);
|
|
2218
2260
|
// 正常退出在 finally 里取消,避免误杀 + PID 复用竞态。
|
|
2261
|
+
// taskkill 必须带 /T(树杀):只杀单个 node.exe 会留下 node-pty 派生的
|
|
2262
|
+
// conhost --headless / bash,控制台永远不回提示符;/T 连它们一起收走。
|
|
2263
|
+
// 不用 detached:Windows 会给 detached 子进程分配可见控制台窗口(黑框一闪),
|
|
2264
|
+
// 而看门狗根本不需要脱离——父进程死锁时它照样能跑,父进程正常退出时 finally
|
|
2265
|
+
// 里会取消它;父进程崩掉时看门狗也没了,但那时本来就不需要收尾。
|
|
2219
2266
|
// cmd.exe 是无 GUI 的控制台宿主,windowsHide 藏的是它一闪而过的黑窗口。
|
|
2220
2267
|
let disarmKiller = null;
|
|
2221
2268
|
if (process.platform === "win32") {
|
|
@@ -2223,8 +2270,8 @@ async function shutdown(signal = "SIGINT") {
|
|
|
2223
2270
|
const { spawn } = await import("node:child_process");
|
|
2224
2271
|
const killer = spawn("cmd.exe", [
|
|
2225
2272
|
"/c",
|
|
2226
|
-
`timeout /t ${Math.ceil((SHUTDOWN_FORCE_EXIT_MS + 5000) / 1000)} /nobreak >nul && taskkill /F /PID ${process.pid}`,
|
|
2227
|
-
], {
|
|
2273
|
+
`timeout /t ${Math.ceil((SHUTDOWN_FORCE_EXIT_MS + 5000) / 1000)} /nobreak >nul && taskkill /F /T /PID ${process.pid}`,
|
|
2274
|
+
], { stdio: "ignore", windowsHide: true });
|
|
2228
2275
|
killer.unref();
|
|
2229
2276
|
disarmKiller = () => {
|
|
2230
2277
|
try {
|
package/dist/server/terminals.js
CHANGED
|
@@ -660,6 +660,11 @@ export class TerminalManager {
|
|
|
660
660
|
this.workspaceRoot = workspaceRoot;
|
|
661
661
|
this.lang = lang;
|
|
662
662
|
}
|
|
663
|
+
/** 过户:对话整体搬到另一个 ClientSession 时,把输出/退出事件改发给新宿主。
|
|
664
|
+
* PTY 本体不动(进程不重启,输出缓冲保留),只换投递地址. */
|
|
665
|
+
rebindEmit(emit) {
|
|
666
|
+
this.emit = emit;
|
|
667
|
+
}
|
|
663
668
|
/** Start a plain interactive shell in the given directory. */
|
|
664
669
|
create(id, cwd, cols, rows, fallbackCwd, title, opts) {
|
|
665
670
|
const valid = this.validateId(id);
|
|
@@ -735,12 +740,7 @@ export class TerminalManager {
|
|
|
735
740
|
if (!existing.exited) {
|
|
736
741
|
this.flushPending(existing);
|
|
737
742
|
existing.exited = true;
|
|
738
|
-
|
|
739
|
-
existing.pty.kill();
|
|
740
|
-
}
|
|
741
|
-
catch {
|
|
742
|
-
// already dead
|
|
743
|
-
}
|
|
743
|
+
this.killNative(existing);
|
|
744
744
|
}
|
|
745
745
|
cols = existing.cols || cols;
|
|
746
746
|
rows = existing.rows || rows;
|
|
@@ -1333,12 +1333,7 @@ export class TerminalManager {
|
|
|
1333
1333
|
w.cb(null);
|
|
1334
1334
|
this.flushPending(entry);
|
|
1335
1335
|
entry.exited = true;
|
|
1336
|
-
|
|
1337
|
-
entry.pty.kill();
|
|
1338
|
-
}
|
|
1339
|
-
catch {
|
|
1340
|
-
// already dead
|
|
1341
|
-
}
|
|
1336
|
+
this.killNative(entry);
|
|
1342
1337
|
this.terms.delete(id);
|
|
1343
1338
|
this.emit({ type: "terminal_exit", terminalId: id, exitCode: null });
|
|
1344
1339
|
this.emitList();
|
|
@@ -1358,19 +1353,54 @@ export class TerminalManager {
|
|
|
1358
1353
|
entry.title = trimmed;
|
|
1359
1354
|
this.emitList();
|
|
1360
1355
|
}
|
|
1361
|
-
/**
|
|
1362
|
-
|
|
1356
|
+
/**
|
|
1357
|
+
* Kill the native PTY (issue #215:Windows ConPTY 关机死锁)。
|
|
1358
|
+
*
|
|
1359
|
+
* Windows 下 `pty.kill()` 底层走 `ClosePseudoConsole`,管道有未排空数据时会
|
|
1360
|
+
* 内核级同步死锁,直接冻住单线程事件循环(进程内 setTimeout 看门狗与二次
|
|
1361
|
+
* Ctrl+C 全灭)。所以 Windows 先走 Node 原生的 `process.kill(pid)`
|
|
1362
|
+
*(TerminateProcess,从不阻塞)把 shell 干掉:
|
|
1363
|
+
* - 关机(shutdown=true):到此为止,不再调 `pty.kill()`。进程马上就
|
|
1364
|
+
* `process.exit`,HPC 句柄由 OS 回收;再调只会自找死锁。
|
|
1365
|
+
* - 日常(tab 关闭/移出对话):子进程已死、管道见 EOF 后再调 `pty.kill()`
|
|
1366
|
+
* 释放 HPC 句柄,此时不再阻塞(长驻服务必须释放句柄,不能像关机那样一走了之)。
|
|
1367
|
+
* 非 Windows 原样直调 `pty.kill()`。
|
|
1368
|
+
*/
|
|
1369
|
+
killNative(entry, shutdown = false) {
|
|
1370
|
+
if (process.platform === "win32") {
|
|
1371
|
+
const pid = entry.pty.pid;
|
|
1372
|
+
if (typeof pid === "number") {
|
|
1373
|
+
try {
|
|
1374
|
+
process.kill(pid);
|
|
1375
|
+
}
|
|
1376
|
+
catch {
|
|
1377
|
+
// already dead
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
if (shutdown)
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
try {
|
|
1384
|
+
entry.pty.kill();
|
|
1385
|
+
}
|
|
1386
|
+
catch {
|
|
1387
|
+
// already dead
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Kill every terminal owned by this conversation.
|
|
1392
|
+
* @param opts.shutdown=true = 进程关机路径(disposeAll):Windows 下跳过
|
|
1393
|
+
* `pty.kill()`(见 killNative),只做 TerminateProcess + 状态清理,50ms 内退出。
|
|
1394
|
+
* 日常移出对话走默认 false,必须释放 HPC 句柄。
|
|
1395
|
+
*/
|
|
1396
|
+
killAll(opts) {
|
|
1397
|
+
const shutdown = opts?.shutdown === true;
|
|
1363
1398
|
for (const entry of this.terms.values()) {
|
|
1364
1399
|
this.disarmIdleWatch(entry);
|
|
1365
1400
|
if (entry.exited)
|
|
1366
1401
|
continue;
|
|
1367
1402
|
entry.exited = true;
|
|
1368
|
-
|
|
1369
|
-
entry.pty.kill();
|
|
1370
|
-
}
|
|
1371
|
-
catch {
|
|
1372
|
-
// already dead
|
|
1373
|
-
}
|
|
1403
|
+
this.killNative(entry, shutdown);
|
|
1374
1404
|
}
|
|
1375
1405
|
for (const entry of this.terms.values()) {
|
|
1376
1406
|
for (const wake of entry.waiters)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-web-ui",
|
|
3
|
-
"version": "0.90.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.90.1",
|
|
4
|
+
"description": "Just open your browser to get all your work done — browser cockpit for AI coding agents (chat, code, files, terminal, Git in one tab)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "xingshuyin",
|
|
@@ -87,51 +87,51 @@
|
|
|
87
87
|
"@earendil-works/pi-coding-agent": "^0.85.1",
|
|
88
88
|
"@xterm/addon-fit": "^0.11.0",
|
|
89
89
|
"@xterm/xterm": "^6.0.0",
|
|
90
|
-
"compression": "^1.8.
|
|
90
|
+
"compression": "^1.8.2",
|
|
91
91
|
"electron-updater": "^6.8.9",
|
|
92
|
-
"express": "^
|
|
93
|
-
"highlight.js": "^11.
|
|
94
|
-
"katex": "^0.
|
|
92
|
+
"express": "^5.2.1",
|
|
93
|
+
"highlight.js": "^11.12.0",
|
|
94
|
+
"katex": "^0.18.7",
|
|
95
95
|
"node-pty": "^1.1.0",
|
|
96
|
-
"react": "^
|
|
97
|
-
"react-dom": "^
|
|
96
|
+
"react": "^19.3.0",
|
|
97
|
+
"react-dom": "^19.3.0",
|
|
98
98
|
"react-icons": "^5.7.0",
|
|
99
|
-
"react-markdown": "^
|
|
100
|
-
"rehype-highlight": "^7.0.
|
|
99
|
+
"react-markdown": "^10.1.0",
|
|
100
|
+
"rehype-highlight": "^7.0.2",
|
|
101
101
|
"rehype-katex": "^7.0.1",
|
|
102
102
|
"rehype-raw": "^7.0.0",
|
|
103
103
|
"remark-breaks": "^4.0.0",
|
|
104
|
-
"remark-gfm": "^4.0.
|
|
104
|
+
"remark-gfm": "^4.0.1",
|
|
105
105
|
"remark-math": "^6.0.0",
|
|
106
106
|
"tar": "^7.5.22",
|
|
107
|
-
"typebox": "^1.3.
|
|
108
|
-
"ws": "^8.
|
|
107
|
+
"typebox": "^1.3.34",
|
|
108
|
+
"ws": "^8.21.3",
|
|
109
109
|
"yauzl": "^3.4.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/compression": "^1.8.1",
|
|
113
|
-
"@types/express": "^
|
|
114
|
-
"@types/node": "^
|
|
115
|
-
"@types/react": "^
|
|
116
|
-
"@types/react-dom": "^
|
|
117
|
-
"@types/ws": "^8.
|
|
113
|
+
"@types/express": "^5.0.6",
|
|
114
|
+
"@types/node": "^26.6.1",
|
|
115
|
+
"@types/react": "^19.3.0",
|
|
116
|
+
"@types/react-dom": "^19.3.0",
|
|
117
|
+
"@types/ws": "^8.18.1",
|
|
118
118
|
"@types/yauzl": "^3.4.0",
|
|
119
|
-
"@vitejs/plugin-react": "^
|
|
120
|
-
"concurrently": "^
|
|
119
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
120
|
+
"concurrently": "^10.0.5",
|
|
121
121
|
"cross-env": "^10.1.0",
|
|
122
|
-
"electron": "^44.
|
|
123
|
-
"electron-builder": "^26.
|
|
124
|
-
"esbuild": "^0.
|
|
125
|
-
"jsdom": "^
|
|
126
|
-
"mermaid": "^
|
|
127
|
-
"oxlint": "^1.
|
|
128
|
-
"playwright-core": "^1.
|
|
129
|
-
"prettier": "^3.9.
|
|
130
|
-
"tsx": "^4.
|
|
131
|
-
"typescript": "^
|
|
122
|
+
"electron": "^44.4.2",
|
|
123
|
+
"electron-builder": "^26.15.3",
|
|
124
|
+
"esbuild": "^0.28.2",
|
|
125
|
+
"jsdom": "^30.1.0",
|
|
126
|
+
"mermaid": "^12.0.0",
|
|
127
|
+
"oxlint": "^1.83.0",
|
|
128
|
+
"playwright-core": "^1.63.0",
|
|
129
|
+
"prettier": "^3.9.8",
|
|
130
|
+
"tsx": "^4.23.13",
|
|
131
|
+
"typescript": "^7.0.2",
|
|
132
132
|
"vis-timeline": "^8.5.4",
|
|
133
|
-
"vite": "^
|
|
134
|
-
"vitest": "^
|
|
133
|
+
"vite": "^8.3.0",
|
|
134
|
+
"vitest": "^5.0.1"
|
|
135
135
|
},
|
|
136
136
|
"allowScripts": {
|
|
137
137
|
"node-pty@1.1.0": true
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-CR5VJ85Q.js";import{a as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,o as f,p,r as m,s as h,t as g,u as _}from"./index-DJIV4A-t.js";import{n as v,t as y}from"./xterm-Cf5xxe4g.js";var b=e(t(),1);function x(e,t){return Math.abs(t)>10&&Math.abs(t)>Math.abs(e)*1.2}function S(e,t){return e-t}var C=n();function w(e){let t=null;return{clean:e.replace(/\r?\n?\[pi-term-exit:(-?\d+)\]\r?\n?/g,(e,n)=>(t=Number(n),`\r
|
|
2
|
+
`)).replace(/\r?\n?\x1b\[90m\[(?:进程已退出,退出码 |Process exited with code )-?\d+\]\x1b\[0m\r?\n?/g,`\r
|
|
3
|
+
`),exitCode:t}}function T({conversationId:e,terminalId:t,command:n,cwd:i,title:a,agentBash:o,active:s,running:c,exitCode:u,register:d}){let p=(0,b.useRef)(null),h=(0,b.useRef)(null),{locale:g}=f(),_=(0,b.useRef)(g);_.current=g;let T=n?JSON.stringify(n):``,E=(0,b.useRef)(c===!1);(0,b.useEffect)(()=>{let c=p.current;if(!c)return;let u=new v({theme:l(),fontFamily:`"SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace`,fontSize:13,cursorBlink:!0,scrollback:8e3}),f=new y;u.loadAddon(f),u.open(c),h.current={term:u,fit:f},s&&u.focus();let g=()=>{u.options.theme=l()};window.addEventListener(m,g),u.attachCustomKeyEventHandler(e=>{if(e.type!==`keydown`)return!0;let t=e.key?.toLowerCase();if((e.ctrlKey||e.metaKey)&&t===`v`)return!1;if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&t===`c`&&u.hasSelection()){let e=u.textarea;return e&&(e.value=u.getSelection(),e.select()),!1}return!0});let b=d(e,t,{write:e=>u.write(w(e).clean),dispose:()=>u.dispose()}),C=()=>{try{f.fit(),r({type:`terminal_resize`,terminalId:t,conversationId:e,cols:u.cols,rows:u.rows})}catch{}},T=requestAnimationFrame(()=>{try{f.fit()}catch{}E.current||r(n?{type:`run_command`,terminalId:t,conversationId:e,command:n,cols:u.cols,rows:u.rows}:{type:`terminal_create`,terminalId:t,title:a,locale:_.current,agentBash:o,conversationId:e,cwd:i,cols:u.cols,rows:u.rows})}),D=u.onData(n=>{r({type:`terminal_input`,terminalId:t,conversationId:e,data:n})}),O=u.element,k=null,A=0,j=0,M=0,N=!1,P=e=>{if(e.touches.length!==1){k=null,N=!1;return}let t=e.touches[0];k=t.identifier,A=t.clientX,j=t.clientY,M=t.clientY,N=!1},F=e=>{if(k===null||e.touches.length!==1)return;let t=e.touches[0];if(t.identifier!==k)return;if(!N){if(!x(t.clientX-A,t.clientY-j))return;N=!0}e.preventDefault();let n=S(M,t.clientY);M=t.clientY,n!==0&&typeof WheelEvent<`u`&&(c.querySelector(`.xterm-viewport`)??O)?.dispatchEvent(new WheelEvent(`wheel`,{bubbles:!0,cancelable:!0,deltaY:n,deltaMode:0,clientX:t.clientX,clientY:t.clientY}))},I=e=>{if(k!==null){if(e.touches.length>0){k=null,N=!1;return}k=null,N=!1}};O?.addEventListener(`touchstart`,P,{passive:!0}),O?.addEventListener(`touchmove`,F,{passive:!1}),O?.addEventListener(`touchend`,I),O?.addEventListener(`touchcancel`,I);let L=null;return typeof ResizeObserver<`u`&&(L=new ResizeObserver(()=>{c.offsetWidth>0&&c.offsetHeight>0&&C()}),L.observe(c)),()=>{cancelAnimationFrame(T),D.dispose(),O?.removeEventListener(`touchstart`,P),O?.removeEventListener(`touchmove`,F),O?.removeEventListener(`touchend`,I),O?.removeEventListener(`touchcancel`,I),window.removeEventListener(m,g),L?.disconnect(),b(),u.dispose(),h.current=null}},[e,t,T,d]),(0,b.useEffect)(()=>{if(!s)return;let n=requestAnimationFrame(()=>{let n=h.current;if(n){try{n.fit.fit(),r({type:`terminal_resize`,terminalId:t,conversationId:e,cols:n.term.cols,rows:n.term.rows})}catch{}n.term.focus()}});return()=>cancelAnimationFrame(n)},[s]);let{t:D}=f(),O=(0,b.useRef)(void 0);return(0,b.useEffect)(()=>{if(c===O.current||(O.current=c,c!==!1))return;let e=h.current;e&&e.term.write(`\r\n\x1b[90m${D(`exitBanner`,{code:u??``})}\x1b[0m\r\n`)},[c,t,u]),(0,C.jsx)(`div`,{ref:p,className:`term-xterm ${s?``:`hidden`}`})}var E={name:``,command:``,cwd:"${pwd}"};function D({chat:e,terminal:t,uiTerminalToolbar:n,onUiAction:l}){let f=h(),[m,v]=(0,b.useState)(null),[y,x]=(0,b.useState)(!1),[S,w]=(0,b.useState)(!1),[D,O]=(0,b.useState)(null),[k,A]=(0,b.useState)(E),[j,M]=(0,b.useState)(null),N=(0,b.useRef)(null),[P,F]=(0,b.useState)(!0),[I,L]=(0,b.useState)(null),[R,z]=(0,b.useState)(``);(0,b.useEffect)(()=>{e.terminals.length===0?v(null):e.terminals.some(e=>e.id===m)||v(e.terminals[e.terminals.length-1].id)},[e.terminals,m]),(0,b.useEffect)(()=>{e.terminalActiveId&&(v(e.terminalActiveId),x(!1))},[e.terminalActiveId]),(0,b.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]);let B=e.terminals.filter(e=>!e.agentBash),V=e.terminals.filter(e=>e.agentBash),H=n=>{if(!e.ready)return;let r=i(),a=e.activeConversationId||e.state?.conversationId||``;t.create({...n,id:r,conversationId:a,cols:n.cols??80,rows:n.rows??24,running:!0,exitCode:null}),v(r),x(!1)},U=()=>H({title:f(`terminalTitle`,{n:B.length+1}),cwd:e.state?.cwd??``}),W=n=>{let i=n.name||n.command,a=e.terminals.find(e=>e.title===i);if(a){t.restart(a.id),v(a.id),r({type:`run_command`,terminalId:a.id,conversationId:a.conversationId,command:n,cols:80,rows:24});return}H({title:i,cwd:e.state?.cwd??``,command:n})},G=n=>{let i=e.terminals.find(e=>e.id===n);if(i&&r({type:`terminal_kill`,terminalId:n,conversationId:i.conversationId}),t.close(n),m===n){let t=e.terminals.filter(e=>e.id!==n);v(t.length>0?t[t.length-1].id:null)}},K=e=>(0,C.jsxs)(`div`,{className:`term-tab ${e.id===m?`active`:``}`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`term-tab-main`,title:`${e.cwd}${e.command?`\n> ${e.command.command}`:``}`,onClick:()=>{I||(v(e.id),x(!1))},children:[(0,C.jsx)(`span`,{className:`term-tab-dot ${e.running?`run`:`exit`}`}),(0,C.jsxs)(`span`,{className:`term-tab-title`,children:[I===e.id?(0,C.jsx)(`input`,{autoFocus:!0,className:`term-tab-rename-input`,value:R,placeholder:e.title,onClick:e=>e.stopPropagation(),onChange:e=>z(e.target.value),onKeyDown:t=>{if(t.stopPropagation(),t.key===`Enter`&&!t.nativeEvent.isComposing){let t=R.trim();t&&r({type:`rename_terminal`,terminalId:e.id,conversationId:e.conversationId,title:t}),L(null)}else t.key===`Escape`&&L(null)},onBlur:()=>L(null)}):e.title,!e.running&&(0,C.jsx)(`span`,{className:`term-tab-exit`,children:f(`exited`,{code:e.exitCode===null?``:` ${e.exitCode}`})})]})]}),(0,C.jsx)(`button`,{type:`button`,className:`term-tab-close term-tab-rename`,title:f(`renameTerminal`),onClick:t=>{t.stopPropagation(),z(e.title),L(e.id)},children:(0,C.jsx)(u,{})}),(0,C.jsx)(`button`,{type:`button`,className:`term-tab-close`,title:f(`closeTerminal`),onClick:()=>G(e.id),children:(0,C.jsx)(s,{})})]},e.id),q=()=>{w(!0),O(null),A(E)},J=t=>{let n=e.commands[t];n&&(w(!1),O(t),A({name:n.name,command:n.command,cwd:n.cwd??``}))},Y=()=>{w(!1),O(null)},X=()=>{let t=k.name.trim(),n=k.command.trim();if(!t||!n)return;let i={name:t,command:n,cwd:k.cwd.trim()||void 0},a=S?[...e.commands,i]:D===null?e.commands:e.commands.map((e,t)=>t===D?i:e);r({type:`save_commands`,commands:a}),Y()},Z=t=>{if(j===t){let n=e.commands.filter((e,n)=>n!==t);r({type:`save_commands`,commands:n}),M(null),N.current&&clearTimeout(N.current)}else M(t),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>M(null),2500)},ee=S||D!==null,te=n===void 0?[`host:term-cmd-refresh`,`host:term-cmd-new`,`host:term-tab-new`].map(e=>({id:e,source:`host`})):n.filter(e=>!e.hidden),Q=(e,t)=>{let n=new Set(e);return te.filter(e=>n.has(e.id)||t&&e.source!==`host`)},$={"host:term-cmd-refresh":(0,C.jsx)(`button`,{type:`button`,className:`panel-refresh`,title:f(`rerun`),onClick:()=>r({type:`list_commands`}),children:(0,C.jsx)(p,{})}),"host:term-cmd-new":(0,C.jsx)(`button`,{type:`button`,className:`panel-new`,title:f(`newCommand`),onClick:q,children:(0,C.jsx)(o,{})}),"host:term-tab-new":(0,C.jsx)(`button`,{type:`button`,className:`panel-new`,title:f(`newTerminal`),onClick:U,children:(0,C.jsx)(o,{})})};return(0,C.jsxs)(`div`,{className:`terminal-view`,children:[(0,C.jsxs)(`aside`,{className:`term-side term-commands ${y?`open`:``}`,children:[(0,C.jsxs)(`div`,{className:`panel-header`,children:[(0,C.jsx)(`span`,{className:`panel-title`,children:f(`commands`)}),(0,C.jsx)(`div`,{className:`panel-header-actions`,children:g(Q([`host:term-cmd-refresh`,`host:term-cmd-new`],!1),$,l)})]}),(0,C.jsx)(`div`,{className:`panel-body`,children:ee?(0,C.jsxs)(`div`,{className:`cmd-form`,children:[(0,C.jsx)(`label`,{htmlFor:`cmd-name`,children:f(`name`)}),(0,C.jsx)(`input`,{id:`cmd-name`,className:`cmd-input`,value:k.name,placeholder:f(`exampleName`),autoFocus:!0,onChange:e=>A({...k,name:e.target.value})}),(0,C.jsx)(`label`,{htmlFor:`cmd-command`,children:f(`command`)}),(0,C.jsx)(`input`,{id:`cmd-command`,className:`cmd-input`,value:k.command,placeholder:f(`exampleCommand`),onChange:e=>A({...k,command:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&X()}}),(0,C.jsxs)(`label`,{htmlFor:`cmd-cwd`,children:[f(`directory`),` `,(0,C.jsx)(`span`,{className:`cmd-hint`,children:f(`cwdHint`)})]}),(0,C.jsx)(`input`,{id:`cmd-cwd`,className:`cmd-input`,value:k.cwd,placeholder:"${pwd}",onChange:e=>A({...k,cwd:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&X()}}),(0,C.jsxs)(`div`,{className:`cmd-form-actions`,children:[(0,C.jsx)(`button`,{type:`button`,className:`btn`,onClick:Y,children:f(`cancel`)}),(0,C.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:!k.name.trim()||!k.command.trim(),onClick:X,children:f(`save`)})]})]}):(0,C.jsxs)(C.Fragment,{children:[e.commands.length===0&&(0,C.jsx)(`div`,{className:`panel-empty`,children:f(`noCommands`)}),e.commands.map((e,t)=>(0,C.jsxs)(`div`,{className:`cmd-item`,children:[(0,C.jsx)(`button`,{type:`button`,className:`cmd-run`,title:f(`clickToRun`),onClick:()=>W(e),children:(0,C.jsx)(a,{})}),(0,C.jsxs)(`button`,{type:`button`,className:`cmd-main`,title:f(`clickToRun`),onClick:()=>W(e),children:[(0,C.jsx)(`span`,{className:`cmd-name`,children:e.name}),(0,C.jsx)(`span`,{className:`cmd-command`,children:e.command}),e.cwd&&(0,C.jsx)(`span`,{className:`cmd-cwd`,children:e.cwd})]}),(0,C.jsx)(`button`,{type:`button`,className:`cmd-act`,title:f(`edit`),onClick:()=>J(t),children:(0,C.jsx)(u,{})}),(0,C.jsx)(`button`,{type:`button`,className:`cmd-act del ${j===t?`confirm`:``}`,title:f(`delete`),onClick:()=>Z(t),children:j===t?f(`confirmQ`):(0,C.jsx)(c,{})})]},t))]})}),(0,C.jsxs)(`div`,{className:`term-tabs-block`,children:[(0,C.jsxs)(`div`,{className:`panel-header`,children:[(0,C.jsx)(`span`,{className:`panel-title`,children:f(`terminal`)}),g(Q([`host:term-tab-new`],!0),$,l)]}),(0,C.jsxs)(`div`,{className:`panel-body`,children:[e.terminals.length===0&&(0,C.jsx)(`div`,{className:`panel-empty`,children:f(`noTerminal`)}),B.map(K),V.length>0&&(0,C.jsxs)(`div`,{className:`term-folder`,children:[(0,C.jsxs)(`button`,{type:`button`,className:`term-folder-header ${P?`open`:``}`,title:f(`aiBashGroup`),onClick:()=>F(e=>!e),children:[(0,C.jsx)(`span`,{className:`term-folder-caret`,children:P?`▾`:`▸`}),(0,C.jsx)(`span`,{className:`term-folder-title`,children:f(`aiBashGroup`)}),(0,C.jsx)(`span`,{className:`term-folder-count`,children:V.length})]}),P&&(0,C.jsx)(`div`,{className:`term-folder-body`,children:V.map(K)})]})]})]})]}),(0,C.jsxs)(`div`,{className:`term-main`,children:[y&&(0,C.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>x(!1)}),(0,C.jsx)(`button`,{type:`button`,className:`term-side-toggle`,title:f(`commands`),onClick:()=>x(e=>!e),children:(0,C.jsx)(_,{})}),e.terminals.length===0?(0,C.jsxs)(`div`,{className:`term-empty`,children:[(0,C.jsx)(d,{className:`term-empty-icon`}),(0,C.jsx)(`div`,{className:`term-empty-title`,children:f(`builtinTerminal`)}),(0,C.jsx)(`div`,{className:`term-empty-sub`,children:f(`termEmptySub`)})]}):e.terminals.map(e=>(0,C.jsx)(T,{conversationId:e.conversationId,terminalId:e.id,command:e.command,cwd:e.cwd,title:e.title,agentBash:e.agentBash,active:e.id===m,running:e.running,exitCode:e.exitCode,register:t.register},`${e.conversationId}:${e.id}`))]})]})}export{D as TerminalPanel};
|