pi-web-ui 0.89.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 +65 -1
- 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 +651 -112
- package/dist/server/auth-cookie.js +23 -0
- package/dist/server/client-state.js +13 -0
- package/dist/server/composer-drafts.js +20 -2
- package/dist/server/dsh/dsh-agent-service.js +14 -8
- package/dist/server/file-archives.js +258 -0
- package/dist/server/file-transfer-routes.js +113 -0
- package/dist/server/files-service.js +22 -3
- package/dist/server/index.js +169 -31
- package/dist/server/marker-service.js +3 -1
- package/dist/server/plugins.js +12 -4
- package/dist/server/queue-utils.js +16 -0
- package/dist/server/schedule-agent-tool.js +240 -0
- package/dist/server/scheduler-tasks.js +9 -0
- package/dist/server/settings-service.js +68 -1
- package/dist/server/terminals.js +50 -20
- package/dist/server/tool-manager.js +11 -1
- package/dist/server/update-check.js +10 -6
- package/dist/server/webui-context.js +4 -0
- package/dist/server/ws-unknown-types.js +44 -0
- package/package.json +35 -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-BOUmN3uu.js +0 -6
- package/web/dist/assets/TerminalPanel-DOrYoP_4.css +0 -32
- package/web/dist/assets/index-3XU67qMh.js +0 -376
- package/web/dist/assets/index-B-gdvWtW.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
|
@@ -30,7 +30,8 @@ import { WebSocket, WebSocketServer } from "ws";
|
|
|
30
30
|
import { VERSION, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
31
31
|
import { PROTOCOL_VERSION } from "./protocol-version.js";
|
|
32
32
|
import { AgentService, workspacePath, QuiesceRejectedError } from "./agent-service.js";
|
|
33
|
-
import { isAbsoluteWirePath, wireToAbs } from "./files-service.js";
|
|
33
|
+
import { WS_MAX_PAYLOAD_BYTES, isAbsoluteWirePath, wireToAbs } from "./files-service.js";
|
|
34
|
+
import { registerFileTransferRoutes } from "./file-transfer-routes.js";
|
|
34
35
|
import { previewKind } from "./text-sniff.js";
|
|
35
36
|
import { startControlServer } from "./control-socket.js";
|
|
36
37
|
import { scheduleUploadCleanup } from "./uploads.js";
|
|
@@ -39,6 +40,7 @@ import { listThemes, resolveThemeFile } from "./themes.js";
|
|
|
39
40
|
import { isManaged, managedRefusal } from "./managed.js";
|
|
40
41
|
import { launchOrigin, toServiceInfo } from "./launch-origin.js";
|
|
41
42
|
import { parseTabs, tabsRefusal } from "./tabs.js";
|
|
43
|
+
import { recordUnknownWsType } from "./ws-unknown-types.js";
|
|
42
44
|
import { installPack, isKnownPack, listPacks, loadServerStrings, readPackFile, removePack, unloadServerStrings, } from "./locales.js";
|
|
43
45
|
import { PluginManager, resolvePluginClientFile, } from "./plugins.js";
|
|
44
46
|
import { PluginInstaller } from "./plugin-installer.js";
|
|
@@ -47,6 +49,7 @@ import { McpBridge } from "./mcp-bridge.js";
|
|
|
47
49
|
import { createMcpHotReload } from "./mcp-hot-reload.js";
|
|
48
50
|
import { createHostMetricsSampler } from "./host-metrics.js";
|
|
49
51
|
import { SchedulerStore } from "./scheduler-tasks.js";
|
|
52
|
+
import { buildPiWebTokenCookie, isTlsRequest } from "./auth-cookie.js";
|
|
50
53
|
/** Strip npm-injected env (`npm start` exports `npm_config_*` / `npm_package_*` /
|
|
51
54
|
* `npm_lifecycle_*` into every child). Anything this server spawns — shells,
|
|
52
55
|
* `pi update` — would otherwise inherit `npm_config_allow_scripts`, which npm
|
|
@@ -219,15 +222,19 @@ if (AUTH_TOKEN) {
|
|
|
219
222
|
// 重要:只要请求携带着有效 token(query/header/cookie 任一匹配)就把 cookie 刷新为
|
|
220
223
|
// 当前 AUTH_TOKEN——服务端重启改了 PI_WEB_TOKEN 后,旧 cookie 经一次正确的
|
|
221
224
|
// ?token= 进入即被重新同步,无需用户清缓存(issue #71)。
|
|
225
|
+
// Secure 只在 TLS 连接上加:常加会让明文 HTTP(默认 loopback)收不到 cookie。
|
|
226
|
+
const secure = isTlsRequest(req);
|
|
222
227
|
if (ok) {
|
|
223
228
|
if (cookie !== encodeURIComponent(AUTH_TOKEN)) {
|
|
224
|
-
res.setHeader("Set-Cookie",
|
|
229
|
+
res.setHeader("Set-Cookie", buildPiWebTokenCookie(encodeURIComponent(AUTH_TOKEN), 31536000, secure));
|
|
225
230
|
}
|
|
226
231
|
}
|
|
227
232
|
else if (cookie) {
|
|
228
233
|
// 请求带的 cookie 已是失效旧值(服务端口令已更换)——立即让其过期,
|
|
229
234
|
// 避免浏览器被残留 cookie 卡死一年(本来也不该再信任它鉴权)。
|
|
230
|
-
|
|
235
|
+
// Secure 与非 Secure 在浏览器里是两个独立 cookie:只清一种会因种植时的
|
|
236
|
+
// 协议不同而残留,所以两种属性组合各发一遍(HTTP 下 Secure 那条被忽略,无害)。
|
|
237
|
+
res.setHeader("Set-Cookie", [buildPiWebTokenCookie("", 0, false), buildPiWebTokenCookie("", 0, true)]);
|
|
231
238
|
}
|
|
232
239
|
if (req.path === "/api/health" || ok) {
|
|
233
240
|
next();
|
|
@@ -253,6 +260,7 @@ const ORIGIN = launchOrigin();
|
|
|
253
260
|
const SERVICE_INFO = toServiceInfo(ORIGIN);
|
|
254
261
|
/** PI_WEB_TABS: the tabs this instance offers. null = all of them, as before. */
|
|
255
262
|
const TABS = parseTabs();
|
|
263
|
+
registerFileTransferRoutes(app, (clientId) => service.get(clientId)?.cwd);
|
|
256
264
|
app.get("/api/health", (_req, res) => {
|
|
257
265
|
res.json({ ok: true, piVersion: VERSION, cwd: CWD, pid: process.pid, engine: ENGINE });
|
|
258
266
|
});
|
|
@@ -350,9 +358,10 @@ app.get("/api/file", async (req, res) => {
|
|
|
350
358
|
* get a sandboxed CSP (?allowJs=1 relaxes scripts only — never same-origin),
|
|
351
359
|
* everything else streams with its real content type.
|
|
352
360
|
*/
|
|
353
|
-
app.get("/api/preview/*", async (req, res) => {
|
|
361
|
+
app.get("/api/preview/*splat", async (req, res) => {
|
|
354
362
|
try {
|
|
355
|
-
|
|
363
|
+
// SAFETY: Express 5 命名通配 *splat 落在 req.params.splat(Express 4 是 params[0])。
|
|
364
|
+
const captured = String(req.params.splat ?? "");
|
|
356
365
|
const ABS_MARKER = "__abs__/";
|
|
357
366
|
const cid = typeof req.query.clientId === "string" ? req.query.clientId : "";
|
|
358
367
|
const cs = cid ? service.get(cid) : undefined;
|
|
@@ -500,8 +509,9 @@ const PLUGINS_DIR = join(DATA_DIR, "plugins");
|
|
|
500
509
|
// 插件 HTTP 路由挂载点:host.route("GET", "/inbox") 实际暴露为
|
|
501
510
|
// /plugins-api/<id>/inbox。PI_WEB_TOKEN 鉴权(上方 app.use)自动覆盖;
|
|
502
511
|
// 响应已在前面过了 express.json。注意不要在此 catch-all 里消费 body。
|
|
503
|
-
app.all(["/plugins-api/:id/*", "/plugins-api/:id"], (req, res) => {
|
|
504
|
-
|
|
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 ?? "");
|
|
505
515
|
pluginMgr.handleHttp(String(req.params.id ?? ""), req.method, rest, req, res);
|
|
506
516
|
});
|
|
507
517
|
function proxyForwardPath(hit, url) {
|
|
@@ -573,9 +583,9 @@ app.use((req, res, next) => {
|
|
|
573
583
|
}
|
|
574
584
|
proxyHttp(hit, req, res);
|
|
575
585
|
});
|
|
576
|
-
app.get("/plugins/:id/client/*", (req, res) => {
|
|
577
|
-
//
|
|
578
|
-
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 ?? "");
|
|
579
589
|
// 特权 DOM 门禁:声明了 dom 能力的插件,其 bundle 需用户逐个授权后才下发
|
|
580
590
|
// (同源 bundle 技术上拦不住 DOM 访问,门只能放在这里;见 server/plugin-dom.ts)。
|
|
581
591
|
if (pluginMgr.isDomBundleBlocked(String(req.params.id ?? ""))) {
|
|
@@ -667,9 +677,10 @@ else if (process.env[RESTART_CHILD_ENV]) {
|
|
|
667
677
|
const httpServer = createServer(app);
|
|
668
678
|
const wss = new WebSocketServer({
|
|
669
679
|
noServer: true,
|
|
670
|
-
//
|
|
671
|
-
//
|
|
672
|
-
|
|
680
|
+
// 右键上传走单帧 base64(100MB 文件 → ~133MB 文本):上限与
|
|
681
|
+
// files-service 的上传 cap 对齐(base64 上限 + 1MB 包络余量),
|
|
682
|
+
// 超限帧由 ws 层直接拒收,不进 handler 再分配 Buffer。
|
|
683
|
+
maxPayload: WS_MAX_PAYLOAD_BYTES,
|
|
673
684
|
// Per-message deflate: big-session snapshots serialize to multi-MB JSON
|
|
674
685
|
// strings; wire-level compression cuts that several-fold. threshold keeps
|
|
675
686
|
// tiny messages (notices/heartbeats) uncompressed to save CPU.
|
|
@@ -832,6 +843,8 @@ const heartbeatTimer = setInterval(() => {
|
|
|
832
843
|
}
|
|
833
844
|
}
|
|
834
845
|
}, HEARTBEAT_INTERVAL_MS);
|
|
846
|
+
// Unref'd so it never blocks exit: heartbeat alone must not hold the event loop open.
|
|
847
|
+
heartbeatTimer.unref?.();
|
|
835
848
|
// 引擎分发:PI_WEB_ENGINE=dsh 时使用 DeepSeek Harness 引擎(server/dsh/),
|
|
836
849
|
// 默认 pi 引擎。同一 wire 协议,前端无感知(ready/health 携带 engine 字段)。
|
|
837
850
|
import { DshAgentService } from "./dsh/dsh-agent-service.js";
|
|
@@ -953,25 +966,60 @@ pluginMgr.permissionRequester = (pluginId, req) => new Promise((resolve) => {
|
|
|
953
966
|
});
|
|
954
967
|
pluginMgr.onPermGrantsChanged = () => pushPluginPermissions();
|
|
955
968
|
// 内置定时任务(issue #184):全局 <dataDir>/scheduler-tasks.json,TTL 与
|
|
956
|
-
// client-state
|
|
957
|
-
//
|
|
969
|
+
// client-state 同级;Agent 工具建的任务优先唤醒发起对话(issue #193:
|
|
970
|
+
// wakeConversation steer 投递,不切用户当前对话),对话不在了再回落无头伪
|
|
971
|
+
// 客户端(chatFromScheduler);单次任务触发后自动删除。DSH 引擎无这俩方法时
|
|
972
|
+
// executor 回 not-supported(历史里记失败,不炸进程)。
|
|
958
973
|
const scheduler = new SchedulerStore(DATA_DIR, {
|
|
959
974
|
executor: async (task) => {
|
|
975
|
+
let result;
|
|
960
976
|
try {
|
|
961
977
|
const svc = service;
|
|
962
|
-
if (typeof svc.chatFromScheduler !== "function")
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
978
|
+
if (typeof svc.chatFromScheduler !== "function" && typeof svc.wakeConversation !== "function") {
|
|
979
|
+
result = { ok: false, error: "当前引擎不支持定时任务(仅标准 pi 引擎)" };
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
// 发起对话还在 → steer 唤醒它(报告直接落原对话);不在了 → 无头执行。
|
|
983
|
+
const target = String(task.conversationId ?? "").trim();
|
|
984
|
+
if (target && typeof svc.wakeConversation === "function") {
|
|
985
|
+
const w = await svc.wakeConversation(target, `[定时任务 ${task.name}] ${task.prompt}`);
|
|
986
|
+
if (w.ok) {
|
|
987
|
+
result = { ok: true, conversationId: w.conversationId };
|
|
988
|
+
}
|
|
989
|
+
else {
|
|
990
|
+
result = await svc.chatFromScheduler({
|
|
991
|
+
id: task.id,
|
|
992
|
+
cwd: task.cwd,
|
|
993
|
+
prompt: task.prompt,
|
|
994
|
+
model: task.model,
|
|
995
|
+
thinkingLevel: task.thinkingLevel,
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
result = await svc.chatFromScheduler({
|
|
1001
|
+
id: task.id,
|
|
1002
|
+
cwd: task.cwd,
|
|
1003
|
+
prompt: task.prompt,
|
|
1004
|
+
model: task.model,
|
|
1005
|
+
thinkingLevel: task.thinkingLevel,
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
971
1009
|
}
|
|
972
1010
|
catch (err) {
|
|
973
|
-
|
|
1011
|
+
result = { ok: false, error: err.message };
|
|
1012
|
+
}
|
|
1013
|
+
// 单次任务:触发一次后自动删除(历史随任务一起走,成败已由上面的 notify 播报)。
|
|
1014
|
+
if (task.oneShot) {
|
|
1015
|
+
try {
|
|
1016
|
+
scheduler.remove(task.id);
|
|
1017
|
+
}
|
|
1018
|
+
catch {
|
|
1019
|
+
// 删除失败不影响已记录的执行结果
|
|
1020
|
+
}
|
|
974
1021
|
}
|
|
1022
|
+
return result;
|
|
975
1023
|
},
|
|
976
1024
|
onChange: () => pushSchedulerTasks(),
|
|
977
1025
|
notify: (level, text, textEn) => pushNoticeToAll(level, text, textEn ?? text),
|
|
@@ -1052,6 +1100,11 @@ service.pluginCommandsProvider = () => pluginMgr.listCommands();
|
|
|
1052
1100
|
pluginMgr.onBgTasksChanged = () => service.refreshBackgroundServers();
|
|
1053
1101
|
service.pluginBgTasksProvider = () => pluginMgr.bgTasks();
|
|
1054
1102
|
service.pluginStopBgTask = (taskId) => pluginMgr.stopPluginBgTask(taskId);
|
|
1103
|
+
// 定时任务 Agent 工具的数据源(schedule_task/list/cancel):标准 pi 引擎的
|
|
1104
|
+
// AgentService 才有 schedulerStore 字段,DSH service 没有 —— 有才设。
|
|
1105
|
+
if ("schedulerStore" in service) {
|
|
1106
|
+
service.schedulerStore = scheduler;
|
|
1107
|
+
}
|
|
1055
1108
|
// ---------------------------------------------------------------------------
|
|
1056
1109
|
// 插件扩展点 v2(并行任务在 server/plugins.ts 加 host.conversations/prompt/
|
|
1057
1110
|
// steer/abortRun/chatWait/fs.watch/scm/bash/schedule/models/onStats/onStreaming/
|
|
@@ -1065,12 +1118,12 @@ service.pluginStopBgTask = (taskId) => pluginMgr.stopPluginBgTask(taskId);
|
|
|
1065
1118
|
// {ok:false},绝不抛错炸进程。
|
|
1066
1119
|
// ---------------------------------------------------------------------------
|
|
1067
1120
|
{
|
|
1121
|
+
// SAFETY: This compatibility bridge only assigns optional plugin hooks; consumers test their presence.
|
|
1068
1122
|
const pm = pluginMgr;
|
|
1069
1123
|
/** 挑一个客户端会话:标准 pi 引擎走 service.pluginClient(),DSH/未知引擎无此方法即 undefined。 */
|
|
1070
1124
|
const pickClient = () => {
|
|
1071
1125
|
try {
|
|
1072
|
-
|
|
1073
|
-
return typeof svc.pluginClient === "function" ? svc.pluginClient() : undefined;
|
|
1126
|
+
return service instanceof AgentService ? service.pluginClient() : undefined;
|
|
1074
1127
|
}
|
|
1075
1128
|
catch {
|
|
1076
1129
|
return undefined;
|
|
@@ -1156,6 +1209,7 @@ service.pluginStopBgTask = (taskId) => pluginMgr.stopPluginBgTask(taskId);
|
|
|
1156
1209
|
// 标准 pi 引擎走 service.completeForPlugins;DSH/未知引擎回 {ok:false},绝不抛错。
|
|
1157
1210
|
pm.llmProvider = async (pluginId, req) => {
|
|
1158
1211
|
try {
|
|
1212
|
+
// SAFETY: Only invoked after the optional method is checked; request fields are narrowed below.
|
|
1159
1213
|
const svc = service;
|
|
1160
1214
|
if (typeof svc.completeForPlugins !== "function")
|
|
1161
1215
|
return { ok: false, error: "当前引擎不支持 LLM 直调(仅标准 pi 引擎)" };
|
|
@@ -1315,7 +1369,7 @@ wss.on("connection", (ws) => {
|
|
|
1315
1369
|
void cs.prompt(msg.text, msg.attachments, msg.queue);
|
|
1316
1370
|
break;
|
|
1317
1371
|
case "queue_remove":
|
|
1318
|
-
cs.removeQueued(msg.kind, msg.text);
|
|
1372
|
+
cs.removeQueued(msg.kind, msg.text, msg.index);
|
|
1319
1373
|
break;
|
|
1320
1374
|
case "draft_update":
|
|
1321
1375
|
cs.saveDraft?.(msg.sessionId, msg.text, msg.ts);
|
|
@@ -1388,6 +1442,32 @@ wss.on("connection", (ws) => {
|
|
|
1388
1442
|
case "switch_conversation":
|
|
1389
1443
|
void cs.switchConversation(msg.id);
|
|
1390
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;
|
|
1391
1471
|
case "list_files":
|
|
1392
1472
|
void cs.listFiles(msg.path);
|
|
1393
1473
|
break;
|
|
@@ -1462,7 +1542,7 @@ wss.on("connection", (ws) => {
|
|
|
1462
1542
|
void cs.completePath(msg.path);
|
|
1463
1543
|
break;
|
|
1464
1544
|
case "make_dir":
|
|
1465
|
-
void cs.makeDir(msg.path);
|
|
1545
|
+
void cs.makeDir(msg.path, msg.setAsCwd === true);
|
|
1466
1546
|
break;
|
|
1467
1547
|
case "check_update":
|
|
1468
1548
|
void cs.checkUpdate();
|
|
@@ -1633,6 +1713,7 @@ wss.on("connection", (ws) => {
|
|
|
1633
1713
|
cs.pushSettings();
|
|
1634
1714
|
break;
|
|
1635
1715
|
case "set_settings":
|
|
1716
|
+
// SAFETY: Both dispatch engines validate the explicitly enumerated settings fields below.
|
|
1636
1717
|
void cs.setSettings({
|
|
1637
1718
|
promptMode: msg.promptMode,
|
|
1638
1719
|
customSystemPrompt: msg.customSystemPrompt,
|
|
@@ -1864,7 +1945,23 @@ wss.on("connection", (ws) => {
|
|
|
1864
1945
|
void cs.rescanDshPatches?.();
|
|
1865
1946
|
break;
|
|
1866
1947
|
case "question_answer":
|
|
1867
|
-
|
|
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
|
+
}
|
|
1868
1965
|
break;
|
|
1869
1966
|
case "page_response":
|
|
1870
1967
|
// 浏览器(page-picker 扩展经前端)对 browser_page 的回包:恢复挂起的
|
|
@@ -1943,8 +2040,16 @@ wss.on("connection", (ws) => {
|
|
|
1943
2040
|
});
|
|
1944
2041
|
}
|
|
1945
2042
|
break;
|
|
1946
|
-
default:
|
|
2043
|
+
default: {
|
|
2044
|
+
// 未知 type 只计数 + 节流 warn,不改变已知类型行为。
|
|
2045
|
+
// default 分支里 msg 已收窄成 never,type 需从宽化后取。
|
|
2046
|
+
const raw = msg.type;
|
|
2047
|
+
const name = typeof raw === "string" ? raw : String(raw);
|
|
2048
|
+
const r = recordUnknownWsType(name);
|
|
2049
|
+
if (r.warn)
|
|
2050
|
+
console.warn(`[ws] unknown message type "${name}" (x${r.count})`);
|
|
1947
2051
|
break;
|
|
2052
|
+
}
|
|
1948
2053
|
}
|
|
1949
2054
|
};
|
|
1950
2055
|
ws.on("message", (data) => {
|
|
@@ -2149,6 +2254,38 @@ async function shutdown(signal = "SIGINT") {
|
|
|
2149
2254
|
}
|
|
2150
2255
|
shuttingDown = true;
|
|
2151
2256
|
console.log("\nshutting down…");
|
|
2257
|
+
// Windows ConPTY 兜底看门狗(issue #215):主线程若死锁在 native
|
|
2258
|
+
// ClosePseudoConsole 里,事件循环冻结,进程内的 forceExitTimer 永远触发不了 ——
|
|
2259
|
+
// 只能靠外部进程收尾。超时取 forceExit + 余量(只在进程内兜底失效时才开火);
|
|
2260
|
+
// 正常退出在 finally 里取消,避免误杀 + PID 复用竞态。
|
|
2261
|
+
// taskkill 必须带 /T(树杀):只杀单个 node.exe 会留下 node-pty 派生的
|
|
2262
|
+
// conhost --headless / bash,控制台永远不回提示符;/T 连它们一起收走。
|
|
2263
|
+
// 不用 detached:Windows 会给 detached 子进程分配可见控制台窗口(黑框一闪),
|
|
2264
|
+
// 而看门狗根本不需要脱离——父进程死锁时它照样能跑,父进程正常退出时 finally
|
|
2265
|
+
// 里会取消它;父进程崩掉时看门狗也没了,但那时本来就不需要收尾。
|
|
2266
|
+
// cmd.exe 是无 GUI 的控制台宿主,windowsHide 藏的是它一闪而过的黑窗口。
|
|
2267
|
+
let disarmKiller = null;
|
|
2268
|
+
if (process.platform === "win32") {
|
|
2269
|
+
try {
|
|
2270
|
+
const { spawn } = await import("node:child_process");
|
|
2271
|
+
const killer = spawn("cmd.exe", [
|
|
2272
|
+
"/c",
|
|
2273
|
+
`timeout /t ${Math.ceil((SHUTDOWN_FORCE_EXIT_MS + 5000) / 1000)} /nobreak >nul && taskkill /F /T /PID ${process.pid}`,
|
|
2274
|
+
], { stdio: "ignore", windowsHide: true });
|
|
2275
|
+
killer.unref();
|
|
2276
|
+
disarmKiller = () => {
|
|
2277
|
+
try {
|
|
2278
|
+
killer.kill();
|
|
2279
|
+
}
|
|
2280
|
+
catch {
|
|
2281
|
+
// 已退出/杀不掉:看门狗使命本来就是收尾,无需上报
|
|
2282
|
+
}
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
catch {
|
|
2286
|
+
// 看门狗起不来:回落进程内 forceExitTimer,不阻断关机
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2152
2289
|
const forceExitTimer = setTimeout(() => {
|
|
2153
2290
|
console.error("shutdown 超时仍未完成,强制退出…");
|
|
2154
2291
|
process.exit(1);
|
|
@@ -2186,6 +2323,7 @@ async function shutdown(signal = "SIGINT") {
|
|
|
2186
2323
|
}
|
|
2187
2324
|
finally {
|
|
2188
2325
|
clearTimeout(forceExitTimer);
|
|
2326
|
+
disarmKiller?.();
|
|
2189
2327
|
process.exit(code);
|
|
2190
2328
|
}
|
|
2191
2329
|
}
|
package/dist/server/plugins.js
CHANGED
|
@@ -872,7 +872,9 @@ export class PluginManager {
|
|
|
872
872
|
try {
|
|
873
873
|
this.onBgTasksChanged?.();
|
|
874
874
|
}
|
|
875
|
-
catch {
|
|
875
|
+
catch {
|
|
876
|
+
// best-effort:可选 UI 刷新,失败忽略。
|
|
877
|
+
}
|
|
876
878
|
return true;
|
|
877
879
|
}
|
|
878
880
|
return false;
|
|
@@ -1686,7 +1688,9 @@ export class PluginManager {
|
|
|
1686
1688
|
try {
|
|
1687
1689
|
t.stop?.();
|
|
1688
1690
|
}
|
|
1689
|
-
catch {
|
|
1691
|
+
catch {
|
|
1692
|
+
// best-effort:反激活清理,单个任务失败不阻断。
|
|
1693
|
+
}
|
|
1690
1694
|
}
|
|
1691
1695
|
}
|
|
1692
1696
|
this.pluginBgTasks.clear();
|
|
@@ -1875,7 +1879,9 @@ export class PluginManager {
|
|
|
1875
1879
|
try {
|
|
1876
1880
|
apiVersion = Number(JSON.parse(readFileSync(join(dir, "manifest.json"), "utf8")).apiVersion ?? 1) || 1;
|
|
1877
1881
|
}
|
|
1878
|
-
catch {
|
|
1882
|
+
catch {
|
|
1883
|
+
// best-effort:无 manifest/JSON 坏 → 按 apiVersion 1 处理。
|
|
1884
|
+
}
|
|
1879
1885
|
if (apiVersion > PLUGIN_API_VERSION) {
|
|
1880
1886
|
const msg = pick(l, `插件要求宿主 API v${apiVersion},当前宿主 v${PLUGIN_API_VERSION} —— 请升级 pi-web-ui`, `Plugin requires host API v${apiVersion} but the host is v${PLUGIN_API_VERSION} — please upgrade pi-web-ui`, "plugins.host.api.mismatch", { apiVersion, PLUGIN_API_VERSION });
|
|
1881
1887
|
console.error(`[plugin:${info.id}] ${msg}`);
|
|
@@ -2464,7 +2470,9 @@ export class PluginManager {
|
|
|
2464
2470
|
try {
|
|
2465
2471
|
this.onBgTasksChanged?.();
|
|
2466
2472
|
}
|
|
2467
|
-
catch {
|
|
2473
|
+
catch {
|
|
2474
|
+
// best-effort:可选 UI 刷新,失败忽略。
|
|
2475
|
+
}
|
|
2468
2476
|
};
|
|
2469
2477
|
fire();
|
|
2470
2478
|
return {
|
|
@@ -16,3 +16,19 @@ export function removeFirstOccurrence(list, text) {
|
|
|
16
16
|
return [...list];
|
|
17
17
|
return [...list.slice(0, index), ...list.slice(index + 1)];
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* 按气泡下标移除一条排队消息(✕ 对应的是「第几个气泡」,不是「哪段文本」)。
|
|
21
|
+
* `index` 越界、非整数、或该位置文本与 `text` 对不上(点击与执行之间队列
|
|
22
|
+
* 已变化——有条消息刚送达或新入队)时,回落到 `removeFirstOccurrence` 的文本匹配,
|
|
23
|
+
* 保持旧客户端(只发 text)行为不变。不修改入参。
|
|
24
|
+
*/
|
|
25
|
+
export function removeQueuedByIndexOrText(list, text, index) {
|
|
26
|
+
if (typeof index === "number" &&
|
|
27
|
+
Number.isInteger(index) &&
|
|
28
|
+
index >= 0 &&
|
|
29
|
+
index < list.length &&
|
|
30
|
+
list[index] === text) {
|
|
31
|
+
return [...list.slice(0, index), ...list.slice(index + 1)];
|
|
32
|
+
}
|
|
33
|
+
return removeFirstOccurrence(list, text);
|
|
34
|
+
}
|