pi-web-ui 0.100.0 → 0.102.0
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 +53 -1
- package/README.md +46 -44
- package/README.zh-CN.md +41 -39
- package/bin/pi-web-ui.mjs +17 -19
- package/dist/server/agent-formatters.js +191 -0
- package/dist/server/agent-service-daemon.js +1266 -0
- package/dist/server/agent-service.js +9884 -12815
- package/dist/server/approval-default-rules.js +158 -0
- package/dist/server/approval-rules.js +41 -167
- package/dist/server/ask-user-question-tool.js +104 -0
- package/dist/server/attachment-store.js +38 -1
- package/dist/server/bash-tool.js +83 -0
- package/dist/server/browser-page-tool.js +207 -0
- package/dist/server/client-id-utils.js +51 -0
- package/dist/server/client-state.js +38 -2
- package/dist/server/compaction-markers.js +34 -1
- package/dist/server/context-budget-runner.js +43 -0
- package/dist/server/dangling-tools.js +18 -5
- package/dist/server/delegate-mode.js +1 -0
- package/dist/server/dispatch-domain-handlers.js +631 -0
- package/dist/server/dispatch-plugin-handlers.js +300 -0
- package/dist/server/dsh/dsh-agent-service.js +30 -5
- package/dist/server/dsh/runtime/goal-rpc.mjs +5 -1
- package/dist/server/goal-evidence.js +9 -2
- package/dist/server/goal-service.js +1 -1
- package/dist/server/hashline-engine.js +1 -1
- package/dist/server/index.js +191 -969
- package/dist/server/left-panel-running.js +115 -0
- package/dist/server/lsp-tool.js +40 -12
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/market-service.js +277 -0
- package/dist/server/mcp-bridge.js +137 -30
- package/dist/server/mcp-hot-reload.js +84 -27
- package/dist/server/mcp-manager.js +215 -0
- package/dist/server/message-entry-resolver.js +32 -0
- package/dist/server/orphan-manager.js +44 -0
- package/dist/server/persona-chain.js +63 -0
- package/dist/server/plan-mode.js +2 -0
- package/dist/server/plan-update-tool.js +96 -0
- package/dist/server/plugin-api-catalog.js +20 -0
- package/dist/server/plugin-facilities.js +13 -3
- package/dist/server/plugin-installer.js +6 -1
- package/dist/server/plugin-ui-slots.js +39 -0
- package/dist/server/plugins.js +72 -38
- package/dist/server/preset-fields.js +35 -0
- package/dist/server/preset-share.js +9 -0
- package/dist/server/process-utils.js +30 -0
- package/dist/server/prompt-assembler.js +80 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/scm-commitmsg.js +74 -0
- package/dist/server/serialize.js +97 -7
- package/dist/server/session-branch.js +367 -0
- package/dist/server/session-parser.js +235 -0
- package/dist/server/session-search.js +158 -0
- package/dist/server/settings-service.js +28 -1
- package/dist/server/skill-content-filler.js +33 -0
- package/dist/server/subagent-handoff.js +18 -0
- package/dist/server/subagent-helpers.js +88 -0
- package/dist/server/terminals.js +155 -58
- package/dist/server/tool-guards.js +527 -0
- package/dist/server/tool-host-factories.js +217 -0
- package/dist/server/tool-manager.js +30 -5
- package/dist/server/wait-subscription-scan.js +46 -1
- package/dist/server/workspace-snapshot.js +18 -0
- package/extensions/webui.ts +90 -24
- package/package.json +1 -1
- package/plugin-sdk/README.md +17 -0
- package/plugin-sdk/index.d.ts +17 -0
- package/plugin-sdk/index.mjs +5 -0
- package/plugins/catalog.json +20 -0
- package/themes/aetheris.css +3 -1
- package/themes/translucent.css +8 -1
- package/themes/transparent.css +9 -1
- package/themes/zhupi-dark.css +3 -14
- package/themes/zhupi.css +2 -16
- package/web/dist/assets/{TerminalPanel-C3I1Mc-C.js → TerminalPanel-CYGOzbPT.js} +1 -1
- package/web/dist/assets/index-CP71PHb6.js +680 -0
- package/web/dist/assets/index-ytRwL6j0.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-B-E2EM_0.css +0 -1
- package/web/dist/assets/index-BYumAaGi.js +0 -379
package/dist/server/index.js
CHANGED
|
@@ -33,7 +33,7 @@ import { WebSocket, WebSocketServer } from "ws";
|
|
|
33
33
|
import { VERSION, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
34
34
|
import { sdkCopies, sdkOriginNote } from "./sdk-origin.js";
|
|
35
35
|
import { PROTOCOL_VERSION } from "./protocol-version.js";
|
|
36
|
-
import { AgentService, workspacePath, QuiesceRejectedError } from "./agent-service.js";
|
|
36
|
+
import { AgentService, workspacePath, QuiesceRejectedError, ClientSession } from "./agent-service.js";
|
|
37
37
|
import { WS_MAX_PAYLOAD_BYTES, isAbsoluteWirePath, wireToAbs } from "./files-service.js";
|
|
38
38
|
import { httpHostAllowed } from "./host-guard.js";
|
|
39
39
|
import { registerFileTransferRoutes } from "./file-transfer-routes.js";
|
|
@@ -60,6 +60,8 @@ import { SchedulerStore, SchedulerValidationError } from "./scheduler-tasks.js";
|
|
|
60
60
|
import { initHttpProxy } from "./http-proxy.js";
|
|
61
61
|
import { globalLspPool } from "./lsp-tool.js";
|
|
62
62
|
import { buildPiWebTokenCookie, decodeCookieToken, isTlsRequest } from "./auth-cookie.js";
|
|
63
|
+
import { handleFileMessage, handleScmMessage, handleBgServerMessage, handlePresetAndDshMessage, handleModelAndProviderMessage, handleTerminalMessage, handleSessionLifecycleMessage, handlePlanAndGoalMessage, handleScheduleMessage, handleSettingsMessage, handleInteractiveResponseMessage, } from "./dispatch-domain-handlers.js";
|
|
64
|
+
import { handlePluginMessage } from "./dispatch-plugin-handlers.js";
|
|
63
65
|
/** Strip npm-injected env (`npm start` exports `npm_config_*` / `npm_package_*` /
|
|
64
66
|
* `npm_lifecycle_*` into every child). Anything this server spawns — shells,
|
|
65
67
|
* `pi update` — would otherwise inherit `npm_config_allow_scripts`, which npm
|
|
@@ -1343,13 +1345,19 @@ function pushNoticeToAll(level, text, textEn) {
|
|
|
1343
1345
|
}
|
|
1344
1346
|
}
|
|
1345
1347
|
}
|
|
1346
|
-
// MCP
|
|
1348
|
+
// MCP 工具桥:读取配置启动外部 MCP 服务器(stdio),把它们的
|
|
1347
1349
|
// 工具并入与插件工具相同的 customTools 管线;单服务器失败不炸进程。
|
|
1348
|
-
const mcpBridge = new McpBridge(DATA_DIR, (...a) => console.log("[mcp]", ...a)
|
|
1350
|
+
const mcpBridge = new McpBridge(DATA_DIR, (...a) => console.log("[mcp]", ...a), {
|
|
1351
|
+
agentDir: getAgentDir(),
|
|
1352
|
+
cwd: CWD,
|
|
1353
|
+
});
|
|
1354
|
+
ClientSession.mcpBridge = mcpBridge;
|
|
1349
1355
|
// mcp.json 热加载:保存文件即生效,改完不必再重启服务。两半都在这里收口 —— reload 换入
|
|
1350
1356
|
// 新的服务器集合(只重启规格真变了的),applyPluginAgentTools 把新工具推给已有会话。
|
|
1351
1357
|
const mcpHotReload = createMcpHotReload({
|
|
1352
1358
|
dataDir: DATA_DIR,
|
|
1359
|
+
agentDir: getAgentDir(),
|
|
1360
|
+
cwd: CWD,
|
|
1353
1361
|
reload: () => mcpBridge.reload(),
|
|
1354
1362
|
onToolsChanged: () => service.applyPluginAgentTools(),
|
|
1355
1363
|
onNotice: (level, text, textEn) => pushNoticeToAll(level, text, textEn),
|
|
@@ -1691,835 +1699,125 @@ wss.on("connection", (ws) => {
|
|
|
1691
1699
|
send({ type: "notice", level: "error", text: refusal });
|
|
1692
1700
|
return;
|
|
1693
1701
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1702
|
+
try {
|
|
1703
|
+
if (handleFileMessage(msg, cs))
|
|
1704
|
+
return;
|
|
1705
|
+
if (handleScmMessage(msg, cs, send))
|
|
1706
|
+
return;
|
|
1707
|
+
if (handleBgServerMessage(msg, cs))
|
|
1708
|
+
return;
|
|
1709
|
+
if (handlePresetAndDshMessage(msg, cs))
|
|
1710
|
+
return;
|
|
1711
|
+
if (handleModelAndProviderMessage(msg, cs))
|
|
1712
|
+
return;
|
|
1713
|
+
if (handleTerminalMessage(msg, cs))
|
|
1714
|
+
return;
|
|
1715
|
+
if (handleSessionLifecycleMessage(msg, cs))
|
|
1716
|
+
return;
|
|
1717
|
+
if (handlePlanAndGoalMessage(msg, cs))
|
|
1718
|
+
return;
|
|
1719
|
+
if (handleScheduleMessage(msg, scheduler, send))
|
|
1720
|
+
return;
|
|
1721
|
+
if (handleSettingsMessage(msg, cs))
|
|
1722
|
+
return;
|
|
1723
|
+
if (handleInteractiveResponseMessage(msg, cs, service, clientId, send))
|
|
1724
|
+
return;
|
|
1725
|
+
if (handlePluginMessage(msg, {
|
|
1726
|
+
pluginMgr,
|
|
1727
|
+
pluginInstaller,
|
|
1728
|
+
cs,
|
|
1729
|
+
clientId,
|
|
1730
|
+
send,
|
|
1731
|
+
dataDir: DATA_DIR,
|
|
1732
|
+
cwd: CWD,
|
|
1733
|
+
clients: wss.clients,
|
|
1734
|
+
pendingPathRequests,
|
|
1735
|
+
pendingPermissionRequests,
|
|
1736
|
+
pendingDomConsents,
|
|
1737
|
+
findDomConsentById,
|
|
1738
|
+
applyDomConsent,
|
|
1739
|
+
pushPluginGrants,
|
|
1740
|
+
pushPluginPermissions,
|
|
1741
|
+
reloadPluginsAndPush,
|
|
1742
|
+
confirmPluginInstallHelper,
|
|
1743
|
+
}))
|
|
1744
|
+
return;
|
|
1745
|
+
switch (msg.type) {
|
|
1746
|
+
case "prompt": {
|
|
1747
|
+
const hasAttach = Boolean(msg.attachments && msg.attachments.length > 0);
|
|
1748
|
+
if (!msg.text?.trim() && !hasAttach) {
|
|
1749
|
+
send({
|
|
1750
|
+
type: "notice",
|
|
1751
|
+
level: "warning",
|
|
1752
|
+
text: "发送已忽略:提示词为空且未附带文件或上下文引用。",
|
|
1753
|
+
textEn: "Prompt ignored: text is empty and no attachments were provided.",
|
|
1754
|
+
});
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
void cs.prompt(msg.text, msg.attachments, msg.queue);
|
|
1704
1758
|
break;
|
|
1705
1759
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
// #491:removeQueued 是 async——dispatch 是 fire-and-forget,缺 void 时
|
|
1711
|
-
// 内部抛错即 unhandledRejection,而全仓没有兜底 handler,Node ≥15 直接崩进程。
|
|
1712
|
-
void cs.removeQueued(msg.kind, msg.text, msg.index);
|
|
1713
|
-
break;
|
|
1714
|
-
case "draft_update":
|
|
1715
|
-
cs.saveDraft?.(msg.sessionId, msg.text, msg.ts);
|
|
1716
|
-
break;
|
|
1717
|
-
case "abort":
|
|
1718
|
-
void cs.abort();
|
|
1719
|
-
break;
|
|
1720
|
-
case "abort_bash":
|
|
1721
|
-
void cs.abortBash();
|
|
1722
|
-
break;
|
|
1723
|
-
case "retry_last":
|
|
1724
|
-
void cs.retryLast();
|
|
1725
|
-
break;
|
|
1726
|
-
case "kill_background_server":
|
|
1727
|
-
void cs.killBackgroundServer(msg.port, msg.taskId);
|
|
1728
|
-
break;
|
|
1729
|
-
case "kill_background_servers":
|
|
1730
|
-
void cs.killAllBackgroundServers();
|
|
1731
|
-
break;
|
|
1732
|
-
case "list_bg_servers":
|
|
1733
|
-
void cs.listBgServers();
|
|
1734
|
-
break;
|
|
1735
|
-
case "set_bg_keep":
|
|
1736
|
-
cs.setBackgroundKeep(msg.port, msg.keep);
|
|
1737
|
-
break;
|
|
1738
|
-
case "clean_bg_leftovers":
|
|
1739
|
-
void cs.cleanBackgroundLeftovers(msg.minutes);
|
|
1740
|
-
break;
|
|
1741
|
-
case "new_chat":
|
|
1742
|
-
void cs.newChat(msg.preset, msg.ephemeral);
|
|
1743
|
-
break;
|
|
1744
|
-
case "edit_message":
|
|
1745
|
-
void cs.editMessage(msg.messageId, msg.text, msg.attachments);
|
|
1746
|
-
break;
|
|
1747
|
-
case "fork_session":
|
|
1748
|
-
void cs.forkSession?.(msg.messageId, msg.position, msg.conversationId);
|
|
1749
|
-
break;
|
|
1750
|
-
case "rollback_session":
|
|
1751
|
-
void cs.rollbackSession?.(msg.messageId, msg.conversationId, msg.restoreWorkspace);
|
|
1752
|
-
break;
|
|
1753
|
-
case "get_state":
|
|
1754
|
-
// Always a FULL snapshot: the client is (re)connecting or detected
|
|
1755
|
-
// a rev/seq gap — it needs an authoritative state to rebuild from.
|
|
1756
|
-
cs.flushSnapshot(true);
|
|
1757
|
-
break;
|
|
1758
|
-
case "get_commands":
|
|
1759
|
-
void cs.pushSlashCommands();
|
|
1760
|
-
break;
|
|
1761
|
-
case "get_tool_info":
|
|
1762
|
-
// 工具卡右键菜单的「显示工具详细信息」:按需取一次工具定义(不进快照)。
|
|
1763
|
-
// 引擎没实现(或旧版服务端)时回一条 unsupported,前端据此显示「不支持」
|
|
1764
|
-
// 而不是永远转圈。
|
|
1765
|
-
if (typeof cs.getToolInfo === "function") {
|
|
1766
|
-
void cs.getToolInfo(msg.name);
|
|
1767
|
-
}
|
|
1768
|
-
else {
|
|
1769
|
-
send({ type: "tool_info", name: msg.name, found: false, unsupported: true });
|
|
1770
|
-
}
|
|
1771
|
-
break;
|
|
1772
|
-
case "get_tool_prompt":
|
|
1773
|
-
// 设置页逐工具文案编辑器:取「出厂默认 + 当前覆盖」。
|
|
1774
|
-
if (typeof cs.getToolPrompt === "function") {
|
|
1775
|
-
void cs.getToolPrompt(msg.name);
|
|
1776
|
-
}
|
|
1777
|
-
else {
|
|
1778
|
-
send({ type: "tool_prompt", name: msg.name, found: false, unsupported: true });
|
|
1779
|
-
}
|
|
1780
|
-
break;
|
|
1781
|
-
case "get_compacted_messages":
|
|
1782
|
-
void cs.getCompactedMessages?.(msg.compactionMessageId, msg.conversationId);
|
|
1783
|
-
break;
|
|
1784
|
-
case "list_sessions":
|
|
1785
|
-
void cs.refreshSessions();
|
|
1786
|
-
break;
|
|
1787
|
-
case "list_projects":
|
|
1788
|
-
void cs.pushProjects();
|
|
1789
|
-
break;
|
|
1790
|
-
case "remove_project":
|
|
1791
|
-
void cs.removeProject(msg.path);
|
|
1792
|
-
break;
|
|
1793
|
-
case "delete_session":
|
|
1794
|
-
void cs.deleteSession(msg.path);
|
|
1795
|
-
break;
|
|
1796
|
-
case "rename_session":
|
|
1797
|
-
void cs.renameSession(msg.path, msg.name);
|
|
1798
|
-
break;
|
|
1799
|
-
case "rename_conversation":
|
|
1800
|
-
void cs.renameConversation(msg.id, msg.name);
|
|
1801
|
-
break;
|
|
1802
|
-
case "dismiss_conversation":
|
|
1803
|
-
void cs.dismissConversation(msg.id, msg.withFinishedSubagents, msg.force);
|
|
1804
|
-
break;
|
|
1805
|
-
case "persist_conversation":
|
|
1806
|
-
if (typeof cs.persistConversation === "function") {
|
|
1807
|
-
void cs.persistConversation(msg.id);
|
|
1808
|
-
}
|
|
1809
|
-
break;
|
|
1810
|
-
case "pin_conversation":
|
|
1811
|
-
if (typeof cs.setConversationPinned === "function") {
|
|
1812
|
-
void cs.setConversationPinned(msg.id, msg.pinned);
|
|
1813
|
-
}
|
|
1814
|
-
break;
|
|
1815
|
-
case "pin_session":
|
|
1816
|
-
if (typeof cs.pinSession === "function") {
|
|
1817
|
-
void cs.pinSession(msg.path, msg.pinned);
|
|
1818
|
-
}
|
|
1819
|
-
break;
|
|
1820
|
-
case "dismiss_finished_subagents":
|
|
1821
|
-
void cs.dismissFinishedSubagents(msg.parentId);
|
|
1822
|
-
break;
|
|
1823
|
-
case "switch_session":
|
|
1824
|
-
void cs.switchSession(msg.path);
|
|
1825
|
-
break;
|
|
1826
|
-
case "switch_conversation":
|
|
1827
|
-
void cs.switchConversation(msg.id);
|
|
1828
|
-
break;
|
|
1829
|
-
case "take_over_conversation":
|
|
1830
|
-
if (typeof service.takeOverConversation === "function") {
|
|
1831
|
-
void service.takeOverConversation(clientId, msg.owner, msg.id);
|
|
1832
|
-
}
|
|
1833
|
-
else {
|
|
1834
|
-
send({
|
|
1835
|
-
type: "notice",
|
|
1836
|
-
level: "error",
|
|
1837
|
-
text: "当前引擎不支持过户(take over),请用 pi 引擎",
|
|
1838
|
-
textEn: "Takeover is not supported by the current engine; use the pi engine.",
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
break;
|
|
1842
|
-
case "peek_elsewhere_question":
|
|
1843
|
-
if (typeof service.peekElsewhereQuestion === "function") {
|
|
1844
|
-
void service.peekElsewhereQuestion(clientId, msg.owner, msg.id);
|
|
1845
|
-
}
|
|
1846
|
-
else {
|
|
1847
|
-
send({
|
|
1848
|
-
type: "notice",
|
|
1849
|
-
level: "error",
|
|
1850
|
-
text: "当前引擎不支持跨页作答,请用 pi 引擎",
|
|
1851
|
-
textEn: "Cross-page answering is not supported by the current engine; use the pi engine.",
|
|
1852
|
-
});
|
|
1853
|
-
}
|
|
1854
|
-
break;
|
|
1855
|
-
case "list_files":
|
|
1856
|
-
void cs.listFiles(msg.path);
|
|
1857
|
-
break;
|
|
1858
|
-
case "search_files":
|
|
1859
|
-
void cs.searchFiles(msg.query, msg.reqId);
|
|
1860
|
-
break;
|
|
1861
|
-
case "search_sessions":
|
|
1862
|
-
void cs.searchSessions(msg.query, msg.reqId);
|
|
1863
|
-
break;
|
|
1864
|
-
case "scm_status":
|
|
1865
|
-
void cs.scmQuery("status", msg.reqId);
|
|
1866
|
-
break;
|
|
1867
|
-
case "scm_history":
|
|
1868
|
-
void cs.scmQuery("history", msg.reqId);
|
|
1869
|
-
break;
|
|
1870
|
-
case "scm_filediff":
|
|
1871
|
-
void cs.scmQuery("filediff", msg.reqId, { path: msg.path });
|
|
1872
|
-
break;
|
|
1873
|
-
case "scm_commit":
|
|
1874
|
-
void cs.scmQuery("commit", msg.reqId, { hash: msg.hash });
|
|
1875
|
-
break;
|
|
1876
|
-
case "scm_commitmsg":
|
|
1877
|
-
if (typeof cs.scmGenCommitMessage === "function") {
|
|
1878
|
-
void cs.scmGenCommitMessage(msg.reqId);
|
|
1879
|
-
}
|
|
1880
|
-
else {
|
|
1881
|
-
// DSH 等引擎没有 pi 的 ModelRuntime——照样应答一次(ok:false),
|
|
1882
|
-
// 前端按钮不能因引擎差异卡在转圈。
|
|
1883
|
-
send({
|
|
1884
|
-
type: "scm_data",
|
|
1885
|
-
reqId: msg.reqId,
|
|
1886
|
-
kind: "commitmsg",
|
|
1887
|
-
ok: false,
|
|
1888
|
-
error: "当前引擎不支持 AI 生成提交信息(请用 pi 引擎)/ AI commit messages need the pi engine",
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
break;
|
|
1892
|
-
case "read_file":
|
|
1893
|
-
void cs.readFile(msg.path);
|
|
1894
|
-
break;
|
|
1895
|
-
case "write_file":
|
|
1896
|
-
void cs.writeFile(msg.path, msg.text);
|
|
1897
|
-
break;
|
|
1898
|
-
case "upload_file":
|
|
1899
|
-
void cs.uploadFile(msg.dirPath, msg.name, msg.data);
|
|
1900
|
-
break;
|
|
1901
|
-
case "file_create":
|
|
1902
|
-
void cs.createEntry(msg.dir, msg.name, msg.kind);
|
|
1903
|
-
break;
|
|
1904
|
-
case "file_rename":
|
|
1905
|
-
void cs.renameEntry(msg.path, msg.newName);
|
|
1906
|
-
break;
|
|
1907
|
-
case "file_delete":
|
|
1908
|
-
void cs.deleteEntry(msg.path);
|
|
1909
|
-
break;
|
|
1910
|
-
case "file_copy":
|
|
1911
|
-
void cs.copyEntry(msg.src, msg.destDir, msg.move);
|
|
1912
|
-
break;
|
|
1913
|
-
case "file_reveal":
|
|
1914
|
-
void cs.revealEntry(msg.path);
|
|
1915
|
-
break;
|
|
1916
|
-
case "file_open_default":
|
|
1917
|
-
void cs.openDefaultEntry(msg.path);
|
|
1918
|
-
break;
|
|
1919
|
-
case "list_models":
|
|
1920
|
-
void cs.listModels();
|
|
1921
|
-
break;
|
|
1922
|
-
case "set_model":
|
|
1923
|
-
void cs.setModel(msg.modelId);
|
|
1924
|
-
break;
|
|
1925
|
-
case "set_default_model":
|
|
1926
|
-
void cs.setDefaultModel?.(msg.modelId);
|
|
1927
|
-
break;
|
|
1928
|
-
case "clear_default_model":
|
|
1929
|
-
cs.clearDefaultModel?.();
|
|
1930
|
-
break;
|
|
1931
|
-
case "set_thinking":
|
|
1932
|
-
cs.setThinking(msg.level);
|
|
1933
|
-
break;
|
|
1934
|
-
case "set_cwd":
|
|
1935
|
-
void cs.setCwd(msg.path);
|
|
1936
|
-
break;
|
|
1937
|
-
case "set_workspace_roots":
|
|
1938
|
-
// 宿主侧多根(issue #146):只改「哪些路径算工作区内」与右栏文件树的根,
|
|
1939
|
-
// 不动 cwd(AI 仍只在主 cwd 里干活)。
|
|
1940
|
-
void cs.setWorkspaceRoots(msg.roots);
|
|
1941
|
-
break;
|
|
1942
|
-
case "set_locale":
|
|
1943
|
-
// UI language report — per-client persist + lang-aware prompt
|
|
1944
|
-
// refresh (streaming-safe). Engine-agnostic via DispatchSession.
|
|
1945
|
-
void service.setLocale(clientId, msg.locale);
|
|
1946
|
-
break;
|
|
1947
|
-
case "complete_path":
|
|
1948
|
-
void cs.completePath(msg.path);
|
|
1949
|
-
break;
|
|
1950
|
-
case "make_dir":
|
|
1951
|
-
void cs.makeDir(msg.path, msg.setAsCwd === true);
|
|
1952
|
-
break;
|
|
1953
|
-
case "check_update":
|
|
1954
|
-
void cs.checkUpdate();
|
|
1955
|
-
break;
|
|
1956
|
-
case "check_updates_all":
|
|
1957
|
-
void cs.checkUpdatesAll(msg.force === true);
|
|
1958
|
-
break;
|
|
1959
|
-
case "check_plugin_updates":
|
|
1960
|
-
if (typeof cs.checkPluginUpdates === "function") {
|
|
1961
|
-
void cs.checkPluginUpdates(true);
|
|
1962
|
-
}
|
|
1963
|
-
break;
|
|
1964
|
-
case "restart_service": {
|
|
1965
|
-
// Same effect as `pi-web-ui server restart`: this process exits and its
|
|
1966
|
-
// supervisor brings it back (launchd/systemd immediately, the Windows
|
|
1967
|
-
// watchdog within ~10s). Refused without a supervisor — exiting there
|
|
1968
|
-
// would just stop the server the user is looking at.
|
|
1969
|
-
if (!ORIGIN.supervisor) {
|
|
1970
|
-
send({
|
|
1971
|
-
type: "notice",
|
|
1972
|
-
level: "error",
|
|
1973
|
-
text: "当前实例不是由 pi-web-ui 服务启动的(前台运行),无法自动重启;请在终端里重启,或先用 pi-web-ui server install 安装服务。",
|
|
1974
|
-
textEn: "This instance runs in the foreground, not as a pi-web-ui service — nothing would bring it back. Restart it in its terminal, or install the service with `pi-web-ui server install`.",
|
|
1975
|
-
});
|
|
1760
|
+
case "queue_remove":
|
|
1761
|
+
// #491:removeQueued 是 async——dispatch 是 fire-and-forget,缺 void 时
|
|
1762
|
+
// 内部抛错即 unhandledRejection,而全仓没有兜底 handler,Node ≥15 直接崩进程。
|
|
1763
|
+
void cs.removeQueued(msg.kind, msg.text, msg.index);
|
|
1976
1764
|
break;
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
type: "notice",
|
|
1980
|
-
level: "info",
|
|
1981
|
-
text: "正在重启服务…页面会在服务恢复后自动重连,进行中的对话会自动恢复并继续。",
|
|
1982
|
-
textEn: "Restarting the service… this page reconnects once it is back; running conversations resume automatically.",
|
|
1983
|
-
});
|
|
1984
|
-
// Record streaming runs BEFORE exiting: under systemd this path
|
|
1985
|
-
// exits via process.exit without shutdown(), so without this the
|
|
1986
|
-
// post-restart resume would find nothing to continue.
|
|
1987
|
-
try {
|
|
1988
|
-
service.recordInterruptedRuns();
|
|
1989
|
-
}
|
|
1990
|
-
catch {
|
|
1991
|
-
/* best effort — never block the restart on bookkeeping */
|
|
1992
|
-
}
|
|
1993
|
-
// Let the notice (and this socket's backlog) flush before we go down.
|
|
1994
|
-
setTimeout(() => void scheduleQuit(), 400);
|
|
1995
|
-
break;
|
|
1996
|
-
}
|
|
1997
|
-
case "dialog_response":
|
|
1998
|
-
cs.resolveDialog(msg.id, msg.value);
|
|
1999
|
-
break;
|
|
2000
|
-
case "install_pi_agent":
|
|
2001
|
-
void cs.installPiAgent();
|
|
2002
|
-
break;
|
|
2003
|
-
case "set_provider_api_key":
|
|
2004
|
-
void cs.setProviderApiKey(msg.provider, msg.apiKey);
|
|
2005
|
-
break;
|
|
2006
|
-
case "clear_provider_api_key":
|
|
2007
|
-
void cs.clearProviderApiKey(msg.provider);
|
|
2008
|
-
break;
|
|
2009
|
-
case "provider_oauth_start":
|
|
2010
|
-
cs.startProviderOAuth(msg.provider);
|
|
2011
|
-
break;
|
|
2012
|
-
case "provider_oauth_reply":
|
|
2013
|
-
cs.replyProviderOAuth(msg.flowId, msg.promptId, msg.value);
|
|
2014
|
-
break;
|
|
2015
|
-
case "provider_oauth_cancel":
|
|
2016
|
-
cs.cancelProviderOAuth(msg.flowId);
|
|
2017
|
-
break;
|
|
2018
|
-
case "list_provider_oauth_flows":
|
|
2019
|
-
cs.listProviderOAuthFlows();
|
|
2020
|
-
break;
|
|
2021
|
-
case "provider_oauth_logout":
|
|
2022
|
-
void cs.logoutProviderOAuth(msg.provider);
|
|
2023
|
-
break;
|
|
2024
|
-
case "list_models_config":
|
|
2025
|
-
void cs.listModelsConfig();
|
|
2026
|
-
break;
|
|
2027
|
-
case "reload_models_config":
|
|
2028
|
-
void cs.reloadModelsConfig();
|
|
2029
|
-
break;
|
|
2030
|
-
case "save_model_config":
|
|
2031
|
-
void cs.saveModelConfig(msg.providerId, msg.config);
|
|
2032
|
-
break;
|
|
2033
|
-
case "delete_model_config":
|
|
2034
|
-
void cs.deleteModelConfig(msg.providerId);
|
|
2035
|
-
break;
|
|
2036
|
-
case "list_providers":
|
|
2037
|
-
void cs.listProviders();
|
|
2038
|
-
break;
|
|
2039
|
-
case "fetch_models":
|
|
2040
|
-
void cs.fetchModelsList(msg.reqId, msg.baseUrl, msg.apiKey, msg.authHeader, msg.api, msg.providerId);
|
|
2041
|
-
break;
|
|
2042
|
-
case "test_model_connection":
|
|
2043
|
-
void cs.testModelConnection?.(msg.reqId, msg.baseUrl, msg.apiKey, msg.authHeader, msg.api, msg.providerId);
|
|
2044
|
-
break;
|
|
2045
|
-
case "refresh_provider_models":
|
|
2046
|
-
void cs.refreshProviderModels(msg.providerId, msg.reqId);
|
|
2047
|
-
break;
|
|
2048
|
-
case "refresh_builtin_models":
|
|
2049
|
-
void cs.refreshBuiltinModels(msg.reqId);
|
|
2050
|
-
break;
|
|
2051
|
-
case "append_builtin_model":
|
|
2052
|
-
void cs.appendBuiltinModel(msg.providerId, msg.model, msg.reqId);
|
|
2053
|
-
break;
|
|
2054
|
-
case "clone_provider":
|
|
2055
|
-
void cs.cloneProvider(msg.provider, msg.reqId);
|
|
2056
|
-
break;
|
|
2057
|
-
case "enrich_models":
|
|
2058
|
-
void cs.enrichModels(msg.reqId, msg.ids, msg.hints);
|
|
2059
|
-
break;
|
|
2060
|
-
case "abort_enrich_models":
|
|
2061
|
-
cs.abortEnrichModels(msg.reqId);
|
|
2062
|
-
break;
|
|
2063
|
-
case "list_provider_keys":
|
|
2064
|
-
cs.listProviderKeys();
|
|
2065
|
-
break;
|
|
2066
|
-
case "add_provider_key":
|
|
2067
|
-
void cs.addProviderKey(msg.provider, msg.apiKey, msg.name);
|
|
2068
|
-
break;
|
|
2069
|
-
case "activate_provider_key":
|
|
2070
|
-
void cs.activateProviderKey(msg.provider, msg.keyName);
|
|
2071
|
-
break;
|
|
2072
|
-
case "remove_provider_key":
|
|
2073
|
-
void cs.removeProviderKey(msg.provider, msg.keyName);
|
|
2074
|
-
break;
|
|
2075
|
-
case "terminal_create": {
|
|
2076
|
-
const tm = cs.getTerminalManager(msg.conversationId);
|
|
2077
|
-
if (tm) {
|
|
2078
|
-
// agentBash 透传:前端重建已退出的 AI 终端时保留其身份(issue #147);
|
|
2079
|
-
// 字段缺省(旧前端)时 create() 再从 history 继承。
|
|
2080
|
-
const createOpts = msg.locale !== undefined || msg.agentBash !== undefined
|
|
2081
|
-
? { locale: msg.locale, agentBash: msg.agentBash }
|
|
2082
|
-
: undefined;
|
|
2083
|
-
tm.create(msg.terminalId, msg.cwd, msg.cols, msg.rows, cs.getTerminalCwd(msg.conversationId), msg.title, createOpts);
|
|
2084
|
-
}
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
case "terminal_input":
|
|
2088
|
-
cs.getTerminalManager(msg.conversationId)?.input(msg.terminalId, msg.data);
|
|
2089
|
-
break;
|
|
2090
|
-
case "terminal_resize":
|
|
2091
|
-
cs.getTerminalManager(msg.conversationId)?.resize(msg.terminalId, msg.cols, msg.rows);
|
|
2092
|
-
break;
|
|
2093
|
-
case "terminal_kill":
|
|
2094
|
-
cs.getTerminalManager(msg.conversationId)?.kill(msg.terminalId);
|
|
2095
|
-
break;
|
|
2096
|
-
case "rename_terminal":
|
|
2097
|
-
cs.getTerminalManager(msg.conversationId)?.rename(msg.terminalId, msg.title);
|
|
2098
|
-
break;
|
|
2099
|
-
case "run_command":
|
|
2100
|
-
cs.getTerminalManager(msg.conversationId)?.runCommand(msg.terminalId, msg.command, msg.cols, msg.rows, cs.getTerminalCwd(msg.conversationId));
|
|
2101
|
-
break;
|
|
2102
|
-
case "list_commands":
|
|
2103
|
-
void cs.listCommands();
|
|
2104
|
-
break;
|
|
2105
|
-
case "save_commands":
|
|
2106
|
-
void cs.saveCommands(msg.commands);
|
|
2107
|
-
break;
|
|
2108
|
-
case "set_goal":
|
|
2109
|
-
void cs.setGoal(msg.goal, {
|
|
2110
|
-
reviewModel: msg.reviewModel,
|
|
2111
|
-
maxRounds: msg.maxRounds,
|
|
2112
|
-
locked: msg.locked,
|
|
2113
|
-
execModel: msg.execModel,
|
|
2114
|
-
});
|
|
2115
|
-
break;
|
|
2116
|
-
case "clear_goal":
|
|
2117
|
-
void cs.clearGoal();
|
|
2118
|
-
break;
|
|
2119
|
-
case "start_goal_wizard":
|
|
2120
|
-
void cs.startGoalWizard(msg.text, {
|
|
2121
|
-
wizardModel: msg.wizardModel,
|
|
2122
|
-
maxRounds: msg.maxRounds,
|
|
2123
|
-
locked: msg.locked,
|
|
2124
|
-
});
|
|
2125
|
-
break;
|
|
2126
|
-
case "set_goal_prefs":
|
|
2127
|
-
void cs.setGoalPrefs({
|
|
2128
|
-
reviewModel: msg.reviewModel,
|
|
2129
|
-
maxRounds: msg.maxRounds,
|
|
2130
|
-
locked: msg.locked,
|
|
2131
|
-
execModel: msg.execModel,
|
|
2132
|
-
});
|
|
2133
|
-
break;
|
|
2134
|
-
case "get_settings":
|
|
2135
|
-
cs.pushSettings();
|
|
2136
|
-
break;
|
|
2137
|
-
case "set_settings":
|
|
2138
|
-
// SAFETY: Both dispatch engines validate the explicitly enumerated settings fields below.
|
|
2139
|
-
void cs.setSettings({
|
|
2140
|
-
promptMode: msg.promptMode,
|
|
2141
|
-
customSystemPrompt: msg.customSystemPrompt,
|
|
2142
|
-
promptTemplate: msg.promptTemplate,
|
|
2143
|
-
promptOverrides: msg.promptOverrides,
|
|
2144
|
-
toolPromptOverrides: msg.toolPromptOverrides,
|
|
2145
|
-
disabledSkills: msg.disabledSkills,
|
|
2146
|
-
disabledExtensions: msg.disabledExtensions,
|
|
2147
|
-
disabledAgentTools: msg.disabledAgentTools,
|
|
2148
|
-
disabledPluginTools: msg.disabledPluginTools,
|
|
2149
|
-
disabledPlugins: msg.disabledPlugins,
|
|
2150
|
-
terminalToolsEnabled: msg.terminalToolsEnabled,
|
|
2151
|
-
terminalBash: msg.terminalBash,
|
|
2152
|
-
terminalBashIdleMs: msg.terminalBashIdleMs,
|
|
2153
|
-
terminalBashMaxForegroundMs: msg.terminalBashMaxForegroundMs,
|
|
2154
|
-
toolWatchdogTimeoutMs: msg.toolWatchdogTimeoutMs,
|
|
2155
|
-
readDirEnabled: msg.readDirEnabled,
|
|
2156
|
-
bgAutoCleanupMin: msg.bgAutoCleanupMin,
|
|
2157
|
-
toolLazyLoading: msg.toolLazyLoading,
|
|
2158
|
-
toolApprovalEnabled: msg.toolApprovalEnabled,
|
|
2159
|
-
editSoftEnabled: msg.editSoftEnabled,
|
|
2160
|
-
questionnaireEnabled: msg.questionnaireEnabled,
|
|
2161
|
-
parallelReminderEnabled: msg.parallelReminderEnabled,
|
|
2162
|
-
goalModeEnabled: msg.goalModeEnabled,
|
|
2163
|
-
thinkingWrap: msg.thinkingWrap,
|
|
2164
|
-
toolsWrap: msg.toolsWrap,
|
|
2165
|
-
toolImagesEnabled: msg.toolImagesEnabled,
|
|
2166
|
-
devNoCache: msg.devNoCache,
|
|
2167
|
-
autoReload: msg.autoReload,
|
|
2168
|
-
skillsFullText: msg.skillsFullText,
|
|
2169
|
-
visionBridgeEnabled: msg.visionBridgeEnabled,
|
|
2170
|
-
visionBridgeModel: msg.visionBridgeModel,
|
|
2171
|
-
visionBridgePromptMode: msg.visionBridgePromptMode,
|
|
2172
|
-
visionBridgePrompt: msg.visionBridgePrompt,
|
|
2173
|
-
subagentDefaultModel: msg.subagentDefaultModel,
|
|
2174
|
-
retryMaxAttempts: msg.retryMaxAttempts,
|
|
2175
|
-
softCapTokens: msg.softCapTokens,
|
|
2176
|
-
softCapByModel: msg.softCapByModel,
|
|
2177
|
-
reviewPrompt: msg.reviewPrompt,
|
|
2178
|
-
reviewDisabledSkills: msg.reviewDisabledSkills,
|
|
2179
|
-
markersEnabled: msg.markersEnabled,
|
|
2180
|
-
disabledMarkers: msg.disabledMarkers,
|
|
2181
|
-
quickPhrases: msg.quickPhrases,
|
|
2182
|
-
quickPhrasesEnabled: msg.quickPhrasesEnabled,
|
|
2183
|
-
quickPhrasesSeeded: msg.quickPhrasesSeeded,
|
|
2184
|
-
uiLayout: msg.uiLayout,
|
|
2185
|
-
});
|
|
2186
|
-
break;
|
|
2187
|
-
case "extensions_reload":
|
|
2188
|
-
void cs.reloadExtensions();
|
|
2189
|
-
break;
|
|
2190
|
-
case "plugin_message":
|
|
2191
|
-
pluginMgr.handleMessage(msg.pluginId, msg.payload, clientId ?? undefined);
|
|
2192
|
-
break;
|
|
2193
|
-
case "plugin_settings": {
|
|
2194
|
-
const r = pluginMgr.savePluginSettings(msg.pluginId, msg.values ?? {}, () => cs?.getLang() ?? "en");
|
|
2195
|
-
if (r.error) {
|
|
2196
|
-
cs?.emitNotice("error", `插件设置保存失败:${r.error}`, `Failed to save plugin settings: ${r.error}`);
|
|
2197
|
-
}
|
|
2198
|
-
else {
|
|
2199
|
-
cs?.emitNotice("info", "插件设置已保存", "Plugin settings saved");
|
|
2200
|
-
}
|
|
2201
|
-
break;
|
|
2202
|
-
}
|
|
2203
|
-
case "plugins_reload":
|
|
2204
|
-
void pluginMgr.reload(() => cs?.getLang() ?? "en").then(() => pluginMgr.pushToAll());
|
|
2205
|
-
break;
|
|
2206
|
-
case "plugin_catalog_add": {
|
|
2207
|
-
const r = pluginMgr.addCatalogEntry(msg.entry ?? {}, () => cs?.getLang() ?? "en");
|
|
2208
|
-
if (r.error) {
|
|
2209
|
-
cs?.emitNotice("error", `添加到插件列表失败:${r.error}`, `Failed to add to plugin list: ${r.error}`);
|
|
2210
|
-
}
|
|
2211
|
-
else {
|
|
2212
|
-
cs?.emitNotice("info", "已添加到插件列表", "Added to the plugin list");
|
|
2213
|
-
}
|
|
2214
|
-
break;
|
|
2215
|
-
}
|
|
2216
|
-
case "plugin_catalog_remove": {
|
|
2217
|
-
const r = pluginMgr.removeCatalogEntry(msg.id, () => cs?.getLang() ?? "en");
|
|
2218
|
-
if (r.error) {
|
|
2219
|
-
cs?.emitNotice("error", `从插件列表移除失败:${r.error}`, `Failed to remove from plugin list: ${r.error}`);
|
|
2220
|
-
}
|
|
2221
|
-
else {
|
|
2222
|
-
cs?.emitNotice("info", "已从插件列表移除", "Removed from the plugin list");
|
|
2223
|
-
}
|
|
2224
|
-
break;
|
|
2225
|
-
}
|
|
2226
|
-
// -- 插件后台作业(安装/更新/卸载,issue #152)----------------------------
|
|
2227
|
-
// 不再是「开一个可见终端 tab 并关掉设置面板」:作业在服务端后台跑,输出按行
|
|
2228
|
-
// 回给发起者,设置面板原就位显示。真正的执行者是 CLI(单一实现)。
|
|
2229
|
-
case "plugin_job": {
|
|
2230
|
-
const jobLang = () => cs?.getLang() ?? "en";
|
|
2231
|
-
const jobId = String(msg.jobId ?? "");
|
|
2232
|
-
const pluginId = String(msg.id ?? "");
|
|
2233
|
-
// function 声明会提升、TS 对 msg 判别联合的收窄进不了闭包 —— 先拍平成常量。
|
|
2234
|
-
const jobAction = msg.action;
|
|
2235
|
-
const jobSpec = {
|
|
2236
|
-
jobId,
|
|
2237
|
-
action: jobAction,
|
|
2238
|
-
id: pluginId,
|
|
2239
|
-
source: msg.source,
|
|
2240
|
-
build: msg.build === true,
|
|
2241
|
-
noBuild: msg.noBuild === true,
|
|
2242
|
-
};
|
|
2243
|
-
const jobDone = (ok, error) => {
|
|
2244
|
-
send({
|
|
2245
|
-
type: "plugin_job",
|
|
2246
|
-
jobId,
|
|
2247
|
-
action: jobAction,
|
|
2248
|
-
pluginId,
|
|
2249
|
-
phase: "done",
|
|
2250
|
-
ok,
|
|
2251
|
-
...(error ? { error } : {}),
|
|
2252
|
-
output: "",
|
|
2253
|
-
});
|
|
2254
|
-
};
|
|
2255
|
-
// 参数静态校验:参数非法直接拒绝,避免向客户端发起无意义/恶意的确认弹窗。
|
|
2256
|
-
const argCheck = buildPluginJobArgs(jobSpec, DATA_DIR, jobLang);
|
|
2257
|
-
if ("error" in argCheck) {
|
|
2258
|
-
jobDone(false, argCheck.error);
|
|
1765
|
+
case "draft_update":
|
|
1766
|
+
cs.saveDraft?.(msg.sessionId, msg.text, msg.ts);
|
|
2259
1767
|
break;
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
1768
|
+
case "abort":
|
|
1769
|
+
void cs.abort();
|
|
1770
|
+
break;
|
|
1771
|
+
case "abort_bash":
|
|
1772
|
+
void cs.abortBash();
|
|
1773
|
+
break;
|
|
1774
|
+
case "retry_last":
|
|
1775
|
+
void cs.retryLast();
|
|
1776
|
+
break;
|
|
1777
|
+
case "get_state":
|
|
1778
|
+
// Always a FULL snapshot: the client is (re)connecting or detected
|
|
1779
|
+
// a rev/seq gap — it needs an authoritative state to rebuild from.
|
|
1780
|
+
cs.flushSnapshot(true);
|
|
1781
|
+
break;
|
|
1782
|
+
case "get_commands":
|
|
1783
|
+
void cs.pushSlashCommands();
|
|
1784
|
+
break;
|
|
1785
|
+
case "get_tool_info":
|
|
1786
|
+
// 工具卡右键菜单的「显示工具详细信息」:按需取一次工具定义(不进快照)。
|
|
1787
|
+
// 引擎没实现(或旧版服务端)时回一条 unsupported,前端据此显示「不支持」
|
|
1788
|
+
// 而不是永远转圈。
|
|
1789
|
+
if (typeof cs.getToolInfo === "function") {
|
|
1790
|
+
void cs.getToolInfo(msg.name);
|
|
1791
|
+
}
|
|
1792
|
+
else {
|
|
1793
|
+
send({ type: "tool_info", name: msg.name, found: false, unsupported: true });
|
|
2282
1794
|
}
|
|
2283
|
-
void confirmPluginInstallHelper([{ id: pluginId, source: String(msg.source ?? "") }])
|
|
2284
|
-
.then((confirmed) => {
|
|
2285
|
-
if (!confirmed) {
|
|
2286
|
-
jobDone(false, jobLang() === "zh"
|
|
2287
|
-
? "用户未确认安装(拒绝或 120 秒超时)"
|
|
2288
|
-
: "Installation not confirmed (rejected or timed out after 120s)");
|
|
2289
|
-
return;
|
|
2290
|
-
}
|
|
2291
|
-
startPluginJob();
|
|
2292
|
-
})
|
|
2293
|
-
.catch(() => jobDone(false, jobLang() === "zh" ? "安装确认流程异常" : "Installation confirmation error"));
|
|
2294
1795
|
break;
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
function startPluginJob() {
|
|
2300
|
-
const started = pluginInstaller.start(jobSpec, {
|
|
2301
|
-
lang: jobLang,
|
|
2302
|
-
emit: (m) => send(m),
|
|
2303
|
-
done: async (ok, info) => {
|
|
2304
|
-
if (ok) {
|
|
2305
|
-
await reloadPluginsAndPush(jobLang);
|
|
2306
|
-
if (typeof cs?.checkPluginUpdates === "function") {
|
|
2307
|
-
void cs.checkPluginUpdates(false);
|
|
2308
|
-
}
|
|
2309
|
-
const isZh = jobLang() === "zh";
|
|
2310
|
-
const actionLabel = jobAction === "uninstall"
|
|
2311
|
-
? isZh
|
|
2312
|
-
? "卸载"
|
|
2313
|
-
: "uninstalled"
|
|
2314
|
-
: jobAction === "update"
|
|
2315
|
-
? isZh
|
|
2316
|
-
? "更新"
|
|
2317
|
-
: "updated"
|
|
2318
|
-
: isZh
|
|
2319
|
-
? "安装"
|
|
2320
|
-
: "installed";
|
|
2321
|
-
cs?.emitNotice("info", `插件「${pluginId}」${actionLabel}完成`, `Plugin "${pluginId}" ${actionLabel} successfully`);
|
|
2322
|
-
}
|
|
2323
|
-
else if (info.error) {
|
|
2324
|
-
cs?.emitNotice("error", `插件操作失败:${info.error}`, `Plugin operation failed: ${info.error}`);
|
|
2325
|
-
}
|
|
2326
|
-
},
|
|
2327
|
-
});
|
|
2328
|
-
if (!started.ok)
|
|
2329
|
-
jobDone(false, started.error);
|
|
2330
|
-
}
|
|
2331
|
-
break;
|
|
2332
|
-
}
|
|
2333
|
-
case "plugin_job_cancel":
|
|
2334
|
-
pluginInstaller.cancel(String(msg.jobId ?? ""));
|
|
2335
|
-
break;
|
|
2336
|
-
// 注册面目录(DSH P2-7):只读装配(slot/工具/宿主方法表+当前占用者),按需拉取。
|
|
2337
|
-
case "plugin_api_catalog": {
|
|
2338
|
-
const requestId = String(msg.requestId ?? "");
|
|
2339
|
-
send({ type: "plugin_api_catalog_result", requestId, catalog: pluginMgr.getApiCatalog() });
|
|
2340
|
-
break;
|
|
2341
|
-
}
|
|
2342
|
-
// 安装前先读 spec(DSH P0-3):不联网也能查(形状/已装),GitHub 源再探一次
|
|
2343
|
-
// raw manifest。结果只作引导(UI 把 problem 渲染成输入框下的一句话),不阻塞安装。
|
|
2344
|
-
case "plugin_install_inspect": {
|
|
2345
|
-
const requestId = String(msg.requestId ?? "");
|
|
2346
|
-
const source = String(msg.source ?? "");
|
|
2347
|
-
void inspectInstallSpec(source, {
|
|
2348
|
-
pluginsDir: pluginMgr.pluginsDir,
|
|
2349
|
-
...(typeof msg.explicitId === "string" && msg.explicitId.trim() ? { explicitId: msg.explicitId.trim() } : {}),
|
|
2350
|
-
force: msg.force === true,
|
|
2351
|
-
}).then((r) => {
|
|
2352
|
-
send({
|
|
2353
|
-
type: "plugin_install_inspect_result",
|
|
2354
|
-
requestId,
|
|
2355
|
-
source,
|
|
2356
|
-
kind: r.spec.kind,
|
|
2357
|
-
suggestedId: r.suggestedId,
|
|
2358
|
-
installed: r.installed,
|
|
2359
|
-
...(r.problem ? { problem: r.problem } : {}),
|
|
2360
|
-
...(r.detail ? { detail: r.detail } : {}),
|
|
2361
|
-
...(r.manifest ? { manifest: r.manifest } : {}),
|
|
2362
|
-
});
|
|
2363
|
-
});
|
|
2364
|
-
break;
|
|
2365
|
-
}
|
|
2366
|
-
// -- 插件目录授权(issue #146)------------------------------------------
|
|
2367
|
-
case "plugin_path_response": {
|
|
2368
|
-
const id = String(msg.id ?? "");
|
|
2369
|
-
const pending = pendingPathRequests.get(id);
|
|
2370
|
-
// 来源绑定:应答必须来自弹窗广播时在线的 clientId——广播后才连上的
|
|
2371
|
-
// 端没见过弹窗,忽略其代答(pending 保留,真正的弹窗端仍可答复)。
|
|
2372
|
-
if (pending && clientId && pending.recipients.has(clientId)) {
|
|
2373
|
-
clearTimeout(pending.timer);
|
|
2374
|
-
pendingPathRequests.delete(id);
|
|
2375
|
-
pending.resolve(msg.ok === true);
|
|
2376
|
-
}
|
|
2377
|
-
break;
|
|
2378
|
-
}
|
|
2379
|
-
// -- 插件能力授权(host.requestPermission)-------------------------------
|
|
2380
|
-
case "plugin_permission_response": {
|
|
2381
|
-
const id = String(msg.id ?? "");
|
|
2382
|
-
const pending = pendingPermissionRequests.get(id);
|
|
2383
|
-
// 来源绑定:同 plugin_path_response——只有收到弹窗广播的端可代答。
|
|
2384
|
-
if (pending && clientId && pending.recipients.has(clientId)) {
|
|
2385
|
-
clearTimeout(pending.timer);
|
|
2386
|
-
pendingPermissionRequests.delete(id);
|
|
2387
|
-
// 先答复者胜:通知其它在线端收起同一条请求(与目录授权不同,这里要显式 resolved)。
|
|
2388
|
-
const resolved = JSON.stringify({ type: "plugin_permission_resolved", id });
|
|
2389
|
-
for (const client of wss.clients) {
|
|
2390
|
-
if (client.readyState === WebSocket.OPEN) {
|
|
2391
|
-
try {
|
|
2392
|
-
client.send(resolved);
|
|
2393
|
-
}
|
|
2394
|
-
catch {
|
|
2395
|
-
/* 死连接 */
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
1796
|
+
case "get_tool_prompt":
|
|
1797
|
+
// 设置页逐工具文案编辑器:取「出厂默认 + 当前覆盖」。
|
|
1798
|
+
if (typeof cs.getToolPrompt === "function") {
|
|
1799
|
+
void cs.getToolPrompt(msg.name);
|
|
2398
1800
|
}
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
break;
|
|
2402
|
-
}
|
|
2403
|
-
case "plugin_dom_consent": {
|
|
2404
|
-
// grant 是提权方向:走两步握手——只生成在途 consent 请求并广播,不在此
|
|
2405
|
-
// 处落盘;收到绑定来源的 plugin_dom_consent_response 后才 setDomConsent。
|
|
2406
|
-
// 同 pluginId 已有在途请求时忽略(首个优先,120s 超时自动失效)。
|
|
2407
|
-
if (msg.granted === true) {
|
|
2408
|
-
const pid = typeof msg.pluginId === "string" ? msg.pluginId.trim() : "";
|
|
2409
|
-
if (!pid || !pluginMgr.isDomPlugin(pid) || pendingDomConsents.has(pid))
|
|
2410
|
-
break;
|
|
2411
|
-
const id = randomUUID();
|
|
2412
|
-
const timer = setTimeout(() => {
|
|
2413
|
-
pendingDomConsents.delete(pid);
|
|
2414
|
-
}, 120_000);
|
|
2415
|
-
pendingDomConsents.set(pid, { id, pluginId: pid, recipients: new Set(pluginMgr.onlineClientIds()), timer });
|
|
2416
|
-
// from = 发起端 clientId:前端只自动应答自己发起的授权(设置面板点击)。
|
|
2417
|
-
const payload = JSON.stringify({ type: "plugin_dom_consent_request", id, pluginId: pid, from: clientId });
|
|
2418
|
-
for (const client of wss.clients) {
|
|
2419
|
-
if (client.readyState === WebSocket.OPEN) {
|
|
2420
|
-
try {
|
|
2421
|
-
client.send(payload);
|
|
2422
|
-
}
|
|
2423
|
-
catch {
|
|
2424
|
-
/* 死连接 */
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
1801
|
+
else {
|
|
1802
|
+
send({ type: "tool_prompt", name: msg.name, found: false, unsupported: true });
|
|
2427
1803
|
}
|
|
2428
1804
|
break;
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
break;
|
|
2433
|
-
}
|
|
2434
|
-
// -- DOM 授权两步握手的应答:按 id 回查在途请求,且应答连接必须在弹窗
|
|
2435
|
-
// 广播时的在线端集合里,才允许把 grant 持久写盘。
|
|
2436
|
-
case "plugin_dom_consent_response": {
|
|
2437
|
-
const id = typeof msg.id === "string" ? msg.id : "";
|
|
2438
|
-
const pendingConsent = findDomConsentById(id);
|
|
2439
|
-
if (pendingConsent && clientId && pendingConsent.recipients.has(clientId)) {
|
|
2440
|
-
clearTimeout(pendingConsent.timer);
|
|
2441
|
-
pendingDomConsents.delete(pendingConsent.pluginId);
|
|
2442
|
-
// ok=false = 显式拒绝:只清在途请求不落盘(当前前端自动应答只发
|
|
2443
|
-
// true,这里守住协议语义,将来接拒绝按钮不用动服务端)。
|
|
2444
|
-
if (msg.ok === true)
|
|
2445
|
-
applyDomConsent(pendingConsent.pluginId, true);
|
|
2446
|
-
}
|
|
2447
|
-
break;
|
|
2448
|
-
}
|
|
2449
|
-
case "plugin_path_revoke": {
|
|
2450
|
-
const removed = pluginMgr.grants.revoke(typeof msg.pluginId === "string" ? msg.pluginId : undefined, typeof msg.path === "string" ? msg.path : undefined);
|
|
2451
|
-
cs?.emitNotice("info", `已撤销 ${removed} 条插件目录授权`, `Revoked ${removed} plugin path grant(s)`);
|
|
2452
|
-
pushPluginGrants();
|
|
2453
|
-
break;
|
|
2454
|
-
}
|
|
2455
|
-
case "plugin_permission_revoke": {
|
|
2456
|
-
const family = msg.family === "net" || msg.family === "llm" ? msg.family : undefined;
|
|
2457
|
-
const removed = pluginMgr.permGrants.revoke(typeof msg.pluginId === "string" ? msg.pluginId : undefined, family, typeof msg.host === "string" || typeof msg.model === "string"
|
|
2458
|
-
? {
|
|
2459
|
-
...(typeof msg.host === "string" ? { host: msg.host } : {}),
|
|
2460
|
-
...(typeof msg.model === "string" ? { model: msg.model } : {}),
|
|
1805
|
+
case "take_over_conversation":
|
|
1806
|
+
if (typeof service.takeOverConversation === "function") {
|
|
1807
|
+
void service.takeOverConversation(clientId, msg.owner, msg.id);
|
|
2461
1808
|
}
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
const syncLang = () => cs?.getLang() ?? "en";
|
|
2470
|
-
const requestId = String(msg.requestId ?? "");
|
|
2471
|
-
void syncPluginCatalog(String(msg.source ?? ""), { install: msg.install === true, replace: msg.replace === true }, {
|
|
2472
|
-
customCatalogPath: pluginMgr.customCatalogPath,
|
|
2473
|
-
pluginsDir: join(DATA_DIR, "plugins"),
|
|
2474
|
-
installer: pluginInstaller,
|
|
2475
|
-
// 只更新市场列表时无需重启已激活插件,避免重复广播工作目录。
|
|
2476
|
-
afterWrite: () => (msg.install === true ? reloadPluginsAndPush(syncLang) : pluginMgr.pushCatalog()),
|
|
2477
|
-
lang: syncLang,
|
|
2478
|
-
// 本地文件来源只允许工作区内(防任意路径文件探测 oracle)。
|
|
2479
|
-
workspaceRoot: cs?.cwd ?? CWD,
|
|
2480
|
-
// 安装确认门(P0):拒绝/超时只写目录不安装。
|
|
2481
|
-
confirmInstall: (items) => confirmPluginInstallHelper(items),
|
|
2482
|
-
}).then((r) => {
|
|
2483
|
-
if (r.installRefused) {
|
|
2484
|
-
cs?.emitNotice("warning", "目录已同步,但安装未获用户确认(拒绝或超时),未安装任何插件", "Catalog synced, but installation was not confirmed (denied or timed out) — nothing was installed");
|
|
1809
|
+
else {
|
|
1810
|
+
send({
|
|
1811
|
+
type: "notice",
|
|
1812
|
+
level: "error",
|
|
1813
|
+
text: "当前引擎不支持过户(take over),请用 pi 引擎",
|
|
1814
|
+
textEn: "Takeover is not supported by the current engine; use the pi engine.",
|
|
1815
|
+
});
|
|
2485
1816
|
}
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
...(r.error ? { error: r.error } : {}),
|
|
2491
|
-
entries: pluginMgr.catalog(),
|
|
2492
|
-
...(r.installed ? { installed: r.installed } : {}),
|
|
2493
|
-
});
|
|
2494
|
-
});
|
|
2495
|
-
break;
|
|
2496
|
-
}
|
|
2497
|
-
case "dsh_patches_list":
|
|
2498
|
-
void cs.listDshPatches?.();
|
|
2499
|
-
break;
|
|
2500
|
-
case "dsh_preset_list":
|
|
2501
|
-
void cs.refreshAgentPresets?.();
|
|
2502
|
-
break;
|
|
2503
|
-
case "dsh_preset_select":
|
|
2504
|
-
void cs.selectAgentPreset?.(msg.preset);
|
|
2505
|
-
break;
|
|
2506
|
-
case "dsh_preset_default":
|
|
2507
|
-
void cs.setDefaultAgentPreset?.(msg.preset);
|
|
2508
|
-
break;
|
|
2509
|
-
case "dsh_permission_set":
|
|
2510
|
-
void cs.setPermissionPreset?.(msg.preset);
|
|
2511
|
-
break;
|
|
2512
|
-
case "dsh_permission_default":
|
|
2513
|
-
void cs.setDefaultPermissionPreset?.(msg.preset);
|
|
2514
|
-
break;
|
|
2515
|
-
case "dsh_patches_rescan":
|
|
2516
|
-
void cs.rescanDshPatches?.();
|
|
2517
|
-
break;
|
|
2518
|
-
case "question_answer":
|
|
2519
|
-
if (msg.owner) {
|
|
2520
|
-
// 跨页作答:答案转交持有方会话(本页不持有该问卷)。
|
|
2521
|
-
if (typeof service.answerElsewhereQuestion === "function") {
|
|
2522
|
-
void service.answerElsewhereQuestion(clientId, msg.owner, msg.id, msg.answers, msg.cancelled);
|
|
1817
|
+
break;
|
|
1818
|
+
case "peek_elsewhere_question":
|
|
1819
|
+
if (typeof service.peekElsewhereQuestion === "function") {
|
|
1820
|
+
void service.peekElsewhereQuestion(clientId, msg.owner, msg.id);
|
|
2523
1821
|
}
|
|
2524
1822
|
else {
|
|
2525
1823
|
send({
|
|
@@ -2529,161 +1827,77 @@ wss.on("connection", (ws) => {
|
|
|
2529
1827
|
textEn: "Cross-page answering is not supported by the current engine; use the pi engine.",
|
|
2530
1828
|
});
|
|
2531
1829
|
}
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
break;
|
|
2556
|
-
case "plan_step_add":
|
|
2557
|
-
cs.addPlanStep?.(msg.step, msg.afterStepId, msg.conversationId);
|
|
2558
|
-
break;
|
|
2559
|
-
case "plan_clean_handoff":
|
|
2560
|
-
void cs.planCleanHandoff?.(msg.steps, msg.prompt);
|
|
2561
|
-
break;
|
|
2562
|
-
case "set_plan_mode":
|
|
2563
|
-
// 计划模式(只规划不实施):会话级开关,热生效(提示词重建 + 工具硬闸门)。
|
|
2564
|
-
void cs.setPlanMode?.(msg.enabled, msg.conversationId);
|
|
2565
|
-
break;
|
|
2566
|
-
case "set_delegate_mode":
|
|
2567
|
-
// 审查者模式(自动委派):会话级开关,默认关。开启后本对话只审阅,
|
|
2568
|
-
// 用户 prompt 由服务端转给常驻落盘执行对话。DSH 引擎的实现在
|
|
2569
|
-
// setDelegateMode 里直接拒(无 customTools 注册面 → 闸门无处可挂)。
|
|
2570
|
-
void cs.setDelegateMode?.(msg.enabled, msg.conversationId);
|
|
2571
|
-
break;
|
|
2572
|
-
case "page_response":
|
|
2573
|
-
// 浏览器(page-picker 扩展经前端)对 browser_page 的回包:恢复挂起的
|
|
2574
|
-
// pageCall;id 不匹配(超时后迟到/页面刷新)由 resolvePageCall 静默忽略。
|
|
2575
|
-
cs.resolvePageCall?.(msg.id, msg.ok, msg.result, msg.error);
|
|
2576
|
-
break;
|
|
2577
|
-
case "save_preset":
|
|
2578
|
-
void cs.savePreset(msg.name);
|
|
2579
|
-
break;
|
|
2580
|
-
// -- 预设分享(server/preset-share.ts,docs/preset-sharing.md)------
|
|
2581
|
-
case "preset_export":
|
|
2582
|
-
void cs.exportPreset(msg);
|
|
2583
|
-
break;
|
|
2584
|
-
case "preset_import":
|
|
2585
|
-
void cs.importPreset(msg);
|
|
2586
|
-
break;
|
|
2587
|
-
case "preset_import_url":
|
|
2588
|
-
void cs.importPresetFromUrl(msg);
|
|
2589
|
-
break;
|
|
2590
|
-
case "preset_catalog":
|
|
2591
|
-
void cs.pushPresetCatalog(msg);
|
|
2592
|
-
break;
|
|
2593
|
-
case "preset_share":
|
|
2594
|
-
void cs.sharePreset(msg);
|
|
2595
|
-
break;
|
|
2596
|
-
case "save_subagent_template":
|
|
2597
|
-
void cs.saveSubagentTemplate(msg.template);
|
|
2598
|
-
break;
|
|
2599
|
-
case "delete_subagent_template":
|
|
2600
|
-
void cs.deleteSubagentTemplate(msg.name);
|
|
2601
|
-
break;
|
|
2602
|
-
case "save_approval_rule":
|
|
2603
|
-
void cs.saveApprovalRule?.(msg.rule);
|
|
2604
|
-
break;
|
|
2605
|
-
case "save_approval_rules":
|
|
2606
|
-
void cs.saveApprovalRules?.(msg.rules);
|
|
2607
|
-
break;
|
|
2608
|
-
case "delete_approval_rule":
|
|
2609
|
-
void cs.deleteApprovalRule?.(msg.id);
|
|
2610
|
-
break;
|
|
2611
|
-
case "reset_builtin_approval_rule":
|
|
2612
|
-
void cs.resetBuiltinApprovalRule?.(msg.id);
|
|
2613
|
-
break;
|
|
2614
|
-
case "apply_preset":
|
|
2615
|
-
void cs.applyPreset(msg.name);
|
|
2616
|
-
break;
|
|
2617
|
-
case "delete_preset":
|
|
2618
|
-
void cs.deletePreset(msg.name);
|
|
2619
|
-
break;
|
|
2620
|
-
case "schedule_list":
|
|
2621
|
-
try {
|
|
2622
|
-
send({ type: "scheduler_tasks", tasks: scheduler.list() });
|
|
2623
|
-
}
|
|
2624
|
-
catch (err) {
|
|
2625
|
-
send({
|
|
2626
|
-
type: "notice",
|
|
2627
|
-
level: "error",
|
|
2628
|
-
text: `读取定时任务失败:${err.message}`,
|
|
2629
|
-
textEn: `Failed to list scheduled tasks: ${err.message}`,
|
|
2630
|
-
});
|
|
2631
|
-
}
|
|
2632
|
-
break;
|
|
2633
|
-
case "schedule_save":
|
|
2634
|
-
try {
|
|
2635
|
-
scheduler.upsert(msg.task);
|
|
2636
|
-
}
|
|
2637
|
-
catch (err) {
|
|
2638
|
-
const isVal = err instanceof SchedulerValidationError;
|
|
2639
|
-
send({
|
|
2640
|
-
type: "notice",
|
|
2641
|
-
level: "error",
|
|
2642
|
-
text: `保存定时任务失败:${isVal ? err.messageZh : err.message}`,
|
|
2643
|
-
textEn: `Failed to save scheduled task: ${isVal ? err.messageEn : err.message}`,
|
|
2644
|
-
});
|
|
2645
|
-
}
|
|
2646
|
-
break;
|
|
2647
|
-
case "schedule_delete":
|
|
2648
|
-
if (!scheduler.remove(msg.id)) {
|
|
2649
|
-
send({
|
|
2650
|
-
type: "notice",
|
|
2651
|
-
level: "warning",
|
|
2652
|
-
text: `定时任务不存在:${msg.id}`,
|
|
2653
|
-
textEn: `No such scheduled task: ${msg.id}`,
|
|
2654
|
-
});
|
|
2655
|
-
}
|
|
2656
|
-
break;
|
|
2657
|
-
case "schedule_run":
|
|
2658
|
-
void scheduler.runNow(msg.id).then((r) => {
|
|
2659
|
-
if (!r.ok)
|
|
1830
|
+
break;
|
|
1831
|
+
case "set_locale":
|
|
1832
|
+
// UI language report — per-client persist + lang-aware prompt
|
|
1833
|
+
// refresh (streaming-safe). Engine-agnostic via DispatchSession.
|
|
1834
|
+
void service.setLocale(clientId, msg.locale);
|
|
1835
|
+
break;
|
|
1836
|
+
case "check_update":
|
|
1837
|
+
void cs.checkUpdate();
|
|
1838
|
+
break;
|
|
1839
|
+
case "check_updates_all":
|
|
1840
|
+
void cs.checkUpdatesAll(msg.force === true);
|
|
1841
|
+
break;
|
|
1842
|
+
case "check_plugin_updates":
|
|
1843
|
+
if (typeof cs.checkPluginUpdates === "function") {
|
|
1844
|
+
void cs.checkPluginUpdates(true);
|
|
1845
|
+
}
|
|
1846
|
+
break;
|
|
1847
|
+
case "restart_service": {
|
|
1848
|
+
// Same effect as `pi-web-ui server restart`: this process exits and its
|
|
1849
|
+
// supervisor brings it back (launchd/systemd immediately, the Windows
|
|
1850
|
+
// watchdog within ~10s). Refused without a supervisor — exiting there
|
|
1851
|
+
// would just stop the server the user is looking at.
|
|
1852
|
+
if (!ORIGIN.supervisor) {
|
|
2660
1853
|
send({
|
|
2661
1854
|
type: "notice",
|
|
2662
|
-
level: "
|
|
2663
|
-
text:
|
|
2664
|
-
textEn:
|
|
1855
|
+
level: "error",
|
|
1856
|
+
text: "当前实例不是由 pi-web-ui 服务启动的(前台运行),无法自动重启;请在终端里重启,或先用 pi-web-ui server install 安装服务。",
|
|
1857
|
+
textEn: "This instance runs in the foreground, not as a pi-web-ui service — nothing would bring it back. Restart it in its terminal, or install the service with `pi-web-ui server install`.",
|
|
2665
1858
|
});
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
case "schedule_toggle":
|
|
2669
|
-
if (!scheduler.setEnabled(msg.id, msg.enabled === true)) {
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
2670
1861
|
send({
|
|
2671
1862
|
type: "notice",
|
|
2672
|
-
level: "
|
|
2673
|
-
text:
|
|
2674
|
-
textEn:
|
|
1863
|
+
level: "info",
|
|
1864
|
+
text: "正在重启服务…页面会在服务恢复后自动重连,进行中的对话会自动恢复并继续。",
|
|
1865
|
+
textEn: "Restarting the service… this page reconnects once it is back; running conversations resume automatically.",
|
|
2675
1866
|
});
|
|
1867
|
+
// Record streaming runs BEFORE exiting: under systemd this path
|
|
1868
|
+
// exits via process.exit without shutdown(), so without this the
|
|
1869
|
+
// post-restart resume would find nothing to continue.
|
|
1870
|
+
try {
|
|
1871
|
+
service.recordInterruptedRuns();
|
|
1872
|
+
}
|
|
1873
|
+
catch {
|
|
1874
|
+
/* best effort — never block the restart on bookkeeping */
|
|
1875
|
+
}
|
|
1876
|
+
// Let the notice (and this socket's backlog) flush before we go down.
|
|
1877
|
+
setTimeout(() => void scheduleQuit(), 400);
|
|
1878
|
+
break;
|
|
2676
1879
|
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
1880
|
+
default: {
|
|
1881
|
+
// 未知 type 只计数 + 节流 warn,不改变已知类型行为。
|
|
1882
|
+
// default 分支里 msg 已收窄成 never,type 需从宽化后取。
|
|
1883
|
+
const raw = msg.type;
|
|
1884
|
+
const name = typeof raw === "string" ? raw : String(raw);
|
|
1885
|
+
const r = recordUnknownWsType(name);
|
|
1886
|
+
if (r.warn)
|
|
1887
|
+
console.warn(`[ws] unknown message type "${name}" (x${r.count})`);
|
|
1888
|
+
break;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
catch (err) {
|
|
1893
|
+
console.error(`[dispatch error on "${msg.type}"]:`, err);
|
|
1894
|
+
if (!closed) {
|
|
1895
|
+
send({
|
|
1896
|
+
type: "notice",
|
|
1897
|
+
level: "error",
|
|
1898
|
+
text: `操作「${msg.type}」执行出错:${err instanceof Error ? err.message : String(err)}`,
|
|
1899
|
+
textEn: `Error executing "${msg.type}": ${err instanceof Error ? err.message : String(err)}`,
|
|
1900
|
+
});
|
|
2687
1901
|
}
|
|
2688
1902
|
}
|
|
2689
1903
|
};
|
|
@@ -2770,6 +1984,8 @@ wss.on("connection", (ws) => {
|
|
|
2770
1984
|
// 让各插件向新接入的客户端推送自身初始状态(onAttach 钩子)——
|
|
2771
1985
|
// 插件不要依赖客户端挂载后自己拉(见 plugins.ts onAttach 注释)。
|
|
2772
1986
|
pluginMgr.notifyAttach(cid);
|
|
1987
|
+
// P3:左栏插件运行条目全量补发(之后的变更经 plugin_panel_items 广播)。
|
|
1988
|
+
send({ type: "plugin_panel_items", groups: pluginMgr.panelGroups() });
|
|
2773
1989
|
// 插件目录授权表(设置面板展示 + 可撤销)
|
|
2774
1990
|
send({ type: "plugin_grants", grants: pluginMgr.grants.list() });
|
|
2775
1991
|
// 插件能力授权表(设置面板展示 + 可撤销;session 授权带标记)
|
|
@@ -3063,3 +2279,9 @@ async function shutdown(signal = "SIGINT") {
|
|
|
3063
2279
|
}
|
|
3064
2280
|
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
3065
2281
|
process.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
2282
|
+
process.on("unhandledRejection", (reason) => {
|
|
2283
|
+
console.error("[pi-web-ui] Unhandled Promise Rejection:", reason);
|
|
2284
|
+
});
|
|
2285
|
+
process.on("uncaughtException", (err) => {
|
|
2286
|
+
console.error("[pi-web-ui] Uncaught Exception:", err);
|
|
2287
|
+
});
|