pi-web-ui 0.106.0 → 0.107.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 +41 -1
- package/README.zh-TW.md +2 -2
- package/dist/server/agent-service.js +32 -16
- package/dist/server/client-state.js +2 -2
- package/dist/server/dsh/dsh-agent-service.js +15 -10
- package/dist/server/durable/durable-agent-service.js +153 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/durable/durable-driver.js +481 -0
- package/dist/server/durable/durable-loader.js +38 -0
- package/dist/server/durable/durable-models.js +283 -0
- package/dist/server/durable/durable-storage.js +42 -0
- package/dist/server/durable/durable-tools.js +45 -0
- package/dist/server/durable/index.js +8 -0
- package/dist/server/engine-capabilities.js +20 -1
- package/dist/server/engine-probe.js +156 -8
- package/dist/server/global-loader.js +335 -0
- package/dist/server/index.js +127 -17
- package/dist/server/managed.js +2 -0
- package/dist/server/marker-service.js +5 -19
- package/dist/server/markers/index.js +1 -3
- package/dist/server/model-resolver.js +91 -3
- package/dist/server/plugins.js +18 -1
- package/dist/server/sdk-origin.js +2 -2
- package/dist/server/serialize.js +1 -1
- package/dist/server/tool-manager.js +3 -19
- package/dist/server/universal/driver-base.js +4 -0
- package/dist/server/universal/drivers/claude-code.js +3 -2
- package/dist/server/universal/universal-service.js +19 -2
- package/dist/server/universal/universal-session.js +61 -7
- package/dist/server/update-check.js +20 -8
- package/package.json +1 -1
- package/plugins/catalog.json +13 -2
- package/themes/dark-teal.css +0 -1
- package/themes/flow-light.css +1085 -0
- package/themes/flow.css +1094 -0
- package/themes/wallpaper-flow.css +1158 -0
- package/themes/wallpaper-obsidian.css +50 -0
- package/themes/zhujian-dark.css +0 -7
- package/themes/zhujian.css +0 -7
- package/themes/zhupi-dark.css +0 -7
- package/themes/zhupi.css +0 -7
- package/web/dist/assets/{TerminalPanel-CfxKLDW9.js → TerminalPanel-BnViyTlx.js} +2 -2
- package/web/dist/assets/index-cCRCYMwT.css +1 -0
- package/web/dist/assets/index-fH5vhkAE.js +690 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BtcP6BDk.css +0 -1
- package/web/dist/assets/index-XVtCzcHR.js +0 -690
|
@@ -192,9 +192,6 @@ export function listCustomModelsFromConfig(agentDir, filter) {
|
|
|
192
192
|
const api = typeof p.api === "string" ? p.api.trim() : undefined;
|
|
193
193
|
const baseUrl = typeof p.baseUrl === "string" ? p.baseUrl.trim() : undefined;
|
|
194
194
|
const providerName = typeof p.name === "string" ? p.name.trim() : undefined;
|
|
195
|
-
if (filter && !filter({ providerId, api, baseUrl })) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
195
|
if (Array.isArray(p.models)) {
|
|
199
196
|
for (const m of p.models) {
|
|
200
197
|
if (!m || typeof m !== "object")
|
|
@@ -203,6 +200,9 @@ export function listCustomModelsFromConfig(agentDir, filter) {
|
|
|
203
200
|
const modelId = typeof row.id === "string" ? row.id.trim() : "";
|
|
204
201
|
if (!modelId)
|
|
205
202
|
continue;
|
|
203
|
+
if (filter && !filter({ providerId, api, baseUrl, modelId })) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
206
|
const name = typeof row.name === "string" && row.name.trim() ? row.name.trim() : modelId;
|
|
207
207
|
results.push({
|
|
208
208
|
providerId,
|
|
@@ -219,3 +219,91 @@ export function listCustomModelsFromConfig(agentDir, filter) {
|
|
|
219
219
|
}
|
|
220
220
|
return results;
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* 依据实际指定的 api 字段(或官方内置 Provider/模型特征)解析真实通信协议类型。
|
|
224
|
+
* 核心原则:优先遵循显式指定的 api 协议;未显式指定时,根据 providerId 与 modelId 特征合理推导默认协议。
|
|
225
|
+
*/
|
|
226
|
+
export function resolveModelProtocol(api, providerId, modelId) {
|
|
227
|
+
const rawApi = (api ?? "").trim().toLowerCase();
|
|
228
|
+
if (rawApi) {
|
|
229
|
+
if (rawApi === "anthropic-messages" || rawApi === "anthropic")
|
|
230
|
+
return "anthropic-messages";
|
|
231
|
+
if (rawApi === "openai-completions" || rawApi === "openai")
|
|
232
|
+
return "openai-completions";
|
|
233
|
+
if (rawApi === "openai-responses")
|
|
234
|
+
return "openai-responses";
|
|
235
|
+
if (rawApi === "google-generative-ai" || rawApi === "gemini" || rawApi === "google") {
|
|
236
|
+
return "google-generative-ai";
|
|
237
|
+
}
|
|
238
|
+
return rawApi;
|
|
239
|
+
}
|
|
240
|
+
const pid = (providerId ?? "").trim().toLowerCase();
|
|
241
|
+
const mid = (modelId ?? "").trim().toLowerCase();
|
|
242
|
+
// 若未显式配置 api,优先根据 providerId 的命名特征识别协议:
|
|
243
|
+
if (pid.includes("openai") ||
|
|
244
|
+
pid.includes("deepseek") ||
|
|
245
|
+
pid.includes("groq") ||
|
|
246
|
+
pid.includes("mistral") ||
|
|
247
|
+
pid.includes("openrouter")) {
|
|
248
|
+
return "openai-completions";
|
|
249
|
+
}
|
|
250
|
+
if (pid === "anthropic" || pid.includes("claude") || pid.includes("anthropic")) {
|
|
251
|
+
return "anthropic-messages";
|
|
252
|
+
}
|
|
253
|
+
if (pid === "google" || pid === "gemini") {
|
|
254
|
+
return "google-generative-ai";
|
|
255
|
+
}
|
|
256
|
+
if (pid === "ollama")
|
|
257
|
+
return "ollama";
|
|
258
|
+
if (pid === "bedrock")
|
|
259
|
+
return "bedrock";
|
|
260
|
+
// 再次依据 modelId 的前缀特征辅助推导默认协议:
|
|
261
|
+
if (mid.startsWith("claude")) {
|
|
262
|
+
return "anthropic-messages";
|
|
263
|
+
}
|
|
264
|
+
if (mid.startsWith("gemini")) {
|
|
265
|
+
return "google-generative-ai";
|
|
266
|
+
}
|
|
267
|
+
// 其余绝大多数官方及自定义 Provider 均遵循 OpenAI 协议规范
|
|
268
|
+
return "openai-completions";
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 严格按照实际的通信协议类型(Protocol Type)判断目标引擎是否支持。
|
|
272
|
+
* 核心原则:按协议本身做过滤,严禁无依据随意过滤。
|
|
273
|
+
*
|
|
274
|
+
* 1. Pi 原生引擎:支持全部协议全集;
|
|
275
|
+
* 2. DSH 引擎:仅支持 OpenAI 兼容协议(openai-completions / openai-responses),严格拒绝 Anthropic Messages 协议等;
|
|
276
|
+
* 3. Claude Code 引擎:仅支持 Anthropic Messages 协议(无论模型名称叫什么,只要走 Anthropic 协议即可);
|
|
277
|
+
* 4. Durable 引擎:由 @earendil-works/pi-ai 驱动,支持主流开放标准协议(OpenAI, Anthropic, Google 等)。
|
|
278
|
+
*/
|
|
279
|
+
export function isProtocolSupportedByEngine(engine, api, providerId, modelId) {
|
|
280
|
+
const normEngine = engine.toLowerCase().trim();
|
|
281
|
+
const protocol = resolveModelProtocol(api, providerId, modelId);
|
|
282
|
+
// 1. Pi 原生引擎支持全协议全集
|
|
283
|
+
if (normEngine === "pi") {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
// 2. DSH 引擎:仅支持 OpenAI 兼容协议(openai-completions / openai-responses)
|
|
287
|
+
// 严格不支持 Anthropic Messages 协议、Google Generative AI 协议等!
|
|
288
|
+
if (normEngine === "dsh") {
|
|
289
|
+
return protocol === "openai-completions" || protocol === "openai-responses";
|
|
290
|
+
}
|
|
291
|
+
// 3. Claude Code 引擎:仅支持 Anthropic Messages 协议
|
|
292
|
+
if (normEngine === "claude") {
|
|
293
|
+
return protocol === "anthropic-messages";
|
|
294
|
+
}
|
|
295
|
+
// 4. Durable 引擎:基于 @earendil-works/pi-ai,支持主流标准协议
|
|
296
|
+
if (normEngine === "durable") {
|
|
297
|
+
return (protocol === "openai-completions" ||
|
|
298
|
+
protocol === "openai-responses" ||
|
|
299
|
+
protocol === "anthropic-messages" ||
|
|
300
|
+
protocol === "google-generative-ai");
|
|
301
|
+
}
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 结构化入参的协议校验重载包装(兼容既有调用点)。
|
|
306
|
+
*/
|
|
307
|
+
export function isModelProtocolSupportedByEngine(engine, meta) {
|
|
308
|
+
return isProtocolSupportedByEngine(engine, meta.api, meta.providerId, meta.modelId);
|
|
309
|
+
}
|
package/dist/server/plugins.js
CHANGED
|
@@ -1312,12 +1312,29 @@ export class PluginManager {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
const table = this.loaded.get(pluginId)?.httpRoutes;
|
|
1314
1314
|
const path = "/" + pathIn.replace(/^\/+/, "");
|
|
1315
|
-
|
|
1315
|
+
let handler = table?.get(`${method.toUpperCase()} ${path}`);
|
|
1316
|
+
if (!handler && table) {
|
|
1317
|
+
const m = method.toUpperCase();
|
|
1318
|
+
// 通配符路由支持(例如 host.route("GET", "/api/web/*", ...) 或以 "/*" 结尾的前缀)
|
|
1319
|
+
for (const [key, fn] of table.entries()) {
|
|
1320
|
+
if (!key.startsWith(`${m} `))
|
|
1321
|
+
continue;
|
|
1322
|
+
const routePath = key.slice(m.length + 1);
|
|
1323
|
+
if (routePath.endsWith("/*")) {
|
|
1324
|
+
const prefix = routePath.slice(0, -2);
|
|
1325
|
+
if (path === prefix || path.startsWith(prefix + "/")) {
|
|
1326
|
+
handler = fn;
|
|
1327
|
+
break;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1316
1332
|
if (!handler) {
|
|
1317
1333
|
res.status(404).end("not found");
|
|
1318
1334
|
return;
|
|
1319
1335
|
}
|
|
1320
1336
|
try {
|
|
1337
|
+
req.pluginPath = path;
|
|
1321
1338
|
// 异步 handler(`async (req, res) => …`)的 rejection 不会被这里的 try 接住,
|
|
1322
1339
|
// 会变成 unhandledRejection 直接杀掉整个服务(插件读文件失败、host.fs 越界
|
|
1323
1340
|
// 拒绝、上游超时…都会走到这条路上)——用 Promise.resolve().catch 兜住,
|
|
@@ -87,8 +87,8 @@ function scanPathForPi(out, env = process.env) {
|
|
|
87
87
|
/** 探测 npm / pnpm 全局 prefix 目录(issue #559)。 */
|
|
88
88
|
function scanGlobalPrefixes(out, env = process.env) {
|
|
89
89
|
const home = env.HOME || env.USERPROFILE || "";
|
|
90
|
-
// 1. npm_config_prefix / PREFIX
|
|
91
|
-
const prefix = env.npm_config_prefix || env.PREFIX;
|
|
90
|
+
// 1. NPM_CONFIG_PREFIX / npm_config_prefix / PREFIX
|
|
91
|
+
const prefix = env.NPM_CONFIG_PREFIX || env.npm_config_prefix || env.PREFIX;
|
|
92
92
|
if (prefix) {
|
|
93
93
|
addCopy(join(prefix, "lib", "node_modules", PKG, "package.json"), out);
|
|
94
94
|
addCopy(join(prefix, "node_modules", PKG, "package.json"), out);
|
package/dist/server/serialize.js
CHANGED
|
@@ -363,7 +363,7 @@ export function serializeMessage(m, seq) {
|
|
|
363
363
|
};
|
|
364
364
|
// 结构化元数据(tool result details)也要下发:present_files 的预览卡片
|
|
365
365
|
// 就靠它拿 kind/size/excerpt(前端不能靠再打一次 HTTP 才知类型),
|
|
366
|
-
// ask_user_question
|
|
366
|
+
// ask_user_question 同理。体积封顶,超限整丢(见 TOOL_DETAILS_CAP)。
|
|
367
367
|
if (m.details !== undefined) {
|
|
368
368
|
try {
|
|
369
369
|
const json = JSON.stringify(m.details);
|
|
@@ -45,9 +45,6 @@ export const EDIT_SOFT_TOOL_NAME = "edit_soft";
|
|
|
45
45
|
export const DELEGATE_TASK_TOOL_NAME = "delegate_task";
|
|
46
46
|
/** 问卷提问工具(定义见 agent-service.ts makeAskUserQuestionTool)。 */
|
|
47
47
|
export const ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
48
|
-
/** 任务列表只读查询工具(定义见 agent-service.ts makeMarkersListTool;只服务 todo)。
|
|
49
|
-
* 曾用名 markers_list(名过其实,已迁移,见 normalizeDisabledAgentTools)。 */
|
|
50
|
-
export const MARKERS_LIST_TOOL_NAME = "todo_list";
|
|
51
48
|
/** 浏览器页面操作工具(定义见 agent-service.ts makeBrowserPageTool):模型经
|
|
52
49
|
* page-picker 浏览器扩展读/操作用户已授权的页面。 */
|
|
53
50
|
export const BROWSER_PAGE_TOOL_NAME = "browser_page";
|
|
@@ -96,9 +93,7 @@ export const TOOL_SEARCH_TOOL_NAME = "tool_search";
|
|
|
96
93
|
export const LOAD_TOOLS_TOOL_NAME = "load_tools";
|
|
97
94
|
/** 延迟加载模式下**永远活跃**的核心工具(其余全部先当未加载)。 */
|
|
98
95
|
export const LAZY_CORE_TOOL_NAMES = ["bash", "read", "edit", "write"];
|
|
99
|
-
/**
|
|
100
|
-
export const LEGACY_MARKERS_LIST_TOOL_NAME = "markers_list";
|
|
101
|
-
/** 可开关的 Agent 工具总目录(共 25 个)。核心内置工具 bash/read/edit/write 不进
|
|
96
|
+
/** 可开关的 Agent 工具总目录(共 24 个)。核心内置工具 bash/read/edit/write 不进
|
|
102
97
|
* 目录——目录条目 = OTHER_AGENT_TOOLS 自动渲染的设置行,而这四个在设置页
|
|
103
98
|
* 「核心工具」区单独开关(见 SettingsModal 的 CORE_BUILTIN_TOOL_NAMES 区块),
|
|
104
99
|
* 禁用名单同样接受它们(normalizeDisabledAgentTools)。 */
|
|
@@ -290,16 +285,6 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
290
285
|
descKey: "toolsWorktreeDesc",
|
|
291
286
|
offHintKey: "toolsWorktreeOffHint",
|
|
292
287
|
},
|
|
293
|
-
// todo_list 唯一例外:行不在「其他」组,固定在上面的 markers 分区(设置页循环
|
|
294
|
-
// 跳过它,见 OTHER_AGENT_TOOLS;文案 key 照给,万一哪天搬家不用补)。
|
|
295
|
-
{
|
|
296
|
-
name: MARKERS_LIST_TOOL_NAME,
|
|
297
|
-
group: "other",
|
|
298
|
-
defaultOn: true,
|
|
299
|
-
dshVisible: true,
|
|
300
|
-
descKey: "todoListEnabledDesc",
|
|
301
|
-
offHintKey: "todoListOffHint",
|
|
302
|
-
},
|
|
303
288
|
];
|
|
304
289
|
/** SDK 核心内置工具名(可被门控显式禁用或被预设白名单过滤)。 */
|
|
305
290
|
export const CORE_BUILTIN_TOOL_NAMES = ["bash", "read", "edit", "write", "powershell", "ls", "grep", "find"];
|
|
@@ -307,7 +292,7 @@ export function isCoreBuiltinTool(name) {
|
|
|
307
292
|
return CORE_BUILTIN_TOOL_NAMES.includes(name);
|
|
308
293
|
}
|
|
309
294
|
const KNOWN_NAMES = new Set(AGENT_TOOL_CATALOG.map((t) => t.name));
|
|
310
|
-
/** 全部已知可开关工具与核心内置工具全集(共
|
|
295
|
+
/** 全部已知可开关工具与核心内置工具全集(共 30 个)。用于白名单收敛与默认关闭推导。 */
|
|
311
296
|
export const ALL_KNOWN_AGENT_TOOL_NAMES = [
|
|
312
297
|
...AGENT_TOOL_CATALOG.map((t) => t.name),
|
|
313
298
|
...CORE_BUILTIN_TOOL_NAMES,
|
|
@@ -340,8 +325,7 @@ export function normalizeDisabledAgentTools(v) {
|
|
|
340
325
|
return defaultDisabledAgentTools();
|
|
341
326
|
const out = [];
|
|
342
327
|
for (const x of v) {
|
|
343
|
-
|
|
344
|
-
let name = x === LEGACY_MARKERS_LIST_TOOL_NAME ? MARKERS_LIST_TOOL_NAME : x;
|
|
328
|
+
let name = x;
|
|
345
329
|
// 旧版子代理工具迁移:任意旧 subagent_* 关闭均迁移为关闭 subagent 工具。
|
|
346
330
|
if (typeof name === "string" && LEGACY_SUBAGENT_TOOL_NAMES.includes(name)) {
|
|
347
331
|
name = SUBAGENT_TOOL_NAME;
|
|
@@ -17,7 +17,7 @@ import { createInterface } from "node:readline";
|
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
import { BaseAgentDriver } from "../driver-base.js";
|
|
20
|
-
import { resolveProviderCredential, listCustomModelsFromConfig } from "../../model-resolver.js";
|
|
20
|
+
import { resolveProviderCredential, listCustomModelsFromConfig, isModelProtocolSupportedByEngine, } from "../../model-resolver.js";
|
|
21
21
|
import { discoverDiskSkills } from "../../skill-discovery.js";
|
|
22
22
|
/**
|
|
23
23
|
* 快速异步探测系统中是否安装了可用的 Claude Code CLI。
|
|
@@ -358,7 +358,8 @@ export class ClaudeCodeDriver extends BaseAgentDriver {
|
|
|
358
358
|
];
|
|
359
359
|
if (!this.agentDir)
|
|
360
360
|
return official;
|
|
361
|
-
|
|
361
|
+
// 仅继承 Claude / Anthropic 兼容协议的模型,过滤纯 OpenAI / Google 协议
|
|
362
|
+
const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("claude", entry));
|
|
362
363
|
const customRows = custom.map((c) => ({
|
|
363
364
|
id: `${c.providerId}/${c.modelId}`,
|
|
364
365
|
name: c.name,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 2. 管理各浏览器客户端(clientId)的 UniversalSession 实例;
|
|
7
7
|
* 3. 负责安静停机(quiesce)、状态汇总(serviceStatus)与生命周期销毁。
|
|
8
8
|
*/
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
9
10
|
import { UniversalSessionStore } from "./session-store.js";
|
|
10
11
|
import { UniversalSession } from "./universal-session.js";
|
|
11
12
|
import { MockAgentDriver } from "./drivers/mock-driver.js";
|
|
@@ -38,10 +39,25 @@ export class UniversalAgentService {
|
|
|
38
39
|
async attach(clientId, send) {
|
|
39
40
|
let session = this.sessions.get(clientId);
|
|
40
41
|
if (!session) {
|
|
41
|
-
|
|
42
|
+
let effectiveCwd = this.cwd;
|
|
43
|
+
const saved = this.stateStore?.get(clientId);
|
|
44
|
+
if (saved?.lastCwd && saved.lastCwd !== this.cwd) {
|
|
45
|
+
try {
|
|
46
|
+
if (existsSync(saved.lastCwd)) {
|
|
47
|
+
effectiveCwd = saved.lastCwd;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
/* fallback */
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (typeof this.stateStore?.remember === "function") {
|
|
55
|
+
this.stateStore.remember(clientId, effectiveCwd);
|
|
56
|
+
}
|
|
57
|
+
const driver = this.driverFactory(effectiveCwd);
|
|
42
58
|
session = new UniversalSession({
|
|
43
59
|
clientId,
|
|
44
|
-
cwd:
|
|
60
|
+
cwd: effectiveCwd,
|
|
45
61
|
dataDir: this.dataDir,
|
|
46
62
|
agentDir: this.agentDir,
|
|
47
63
|
send,
|
|
@@ -54,6 +70,7 @@ export class UniversalAgentService {
|
|
|
54
70
|
onQuit: () => this.onQuit?.() ?? false,
|
|
55
71
|
});
|
|
56
72
|
this.sessions.set(clientId, session);
|
|
73
|
+
session.attachSink(send);
|
|
57
74
|
}
|
|
58
75
|
else {
|
|
59
76
|
session.attachSink(send);
|
|
@@ -274,6 +274,10 @@ export class UniversalSession {
|
|
|
274
274
|
this.conversations.set(initialConv.id, initialConv);
|
|
275
275
|
this.store.saveConversation(this.cwd, initialConv);
|
|
276
276
|
}
|
|
277
|
+
// 记录当前客户端访问的工作区
|
|
278
|
+
if (typeof this.stateStore?.remember === "function" && this.cwd) {
|
|
279
|
+
this.stateStore.remember(this.clientId, this.cwd);
|
|
280
|
+
}
|
|
277
281
|
// 若驱动为 Claude Code,异步探测环境并下发安装指引
|
|
278
282
|
if (this.driver instanceof ClaudeCodeDriver) {
|
|
279
283
|
void probeClaudeCode().then((probe) => {
|
|
@@ -392,6 +396,8 @@ export class UniversalSession {
|
|
|
392
396
|
}
|
|
393
397
|
this.bg.push();
|
|
394
398
|
void this.refreshSessions();
|
|
399
|
+
void this.pushProjects();
|
|
400
|
+
this.flushSnapshot(true);
|
|
395
401
|
}
|
|
396
402
|
detachSink(send) {
|
|
397
403
|
this.sinks.delete(send);
|
|
@@ -823,11 +829,16 @@ export class UniversalSession {
|
|
|
823
829
|
}
|
|
824
830
|
if (conv) {
|
|
825
831
|
this.activeConvId = conv.id;
|
|
832
|
+
// 同步底层驱动会话上下文(若存在)
|
|
833
|
+
if (conv.driverSessionId) {
|
|
834
|
+
await this.driver.resumeSession(conv.driverSessionId).catch(() => { });
|
|
835
|
+
}
|
|
826
836
|
}
|
|
827
837
|
else {
|
|
828
838
|
this.emitNotice("warning", "未能找到目标会话,已保持在当前对话", "Target conversation not found, staying on current conversation");
|
|
829
839
|
}
|
|
830
840
|
this.flushSnapshot(true);
|
|
841
|
+
void this.refreshSessions();
|
|
831
842
|
}
|
|
832
843
|
async switchSession(path, sessionId) {
|
|
833
844
|
const targetId = sessionId || path;
|
|
@@ -882,7 +893,17 @@ export class UniversalSession {
|
|
|
882
893
|
}
|
|
883
894
|
}
|
|
884
895
|
async deleteSession(path) {
|
|
885
|
-
|
|
896
|
+
const targetId = path.trim() || this.activeConvId;
|
|
897
|
+
// 1. 从磁盘删除持久化会话记录
|
|
898
|
+
this.store.deleteConversation(this.cwd, targetId);
|
|
899
|
+
// 2. 若内存中存在该会话,将其从内存中移除
|
|
900
|
+
if (this.conversations.has(targetId)) {
|
|
901
|
+
await this.dismissConversation(targetId, true, true);
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
void this.refreshSessions();
|
|
905
|
+
this.flushSnapshot();
|
|
906
|
+
}
|
|
886
907
|
}
|
|
887
908
|
async dismissConversation(id, withFinishedSubagents = false, force = false) {
|
|
888
909
|
const conv = this.conversations.get(id);
|
|
@@ -899,9 +920,7 @@ export class UniversalSession {
|
|
|
899
920
|
if (conv.isSubagent && conv.subagentStreaming) {
|
|
900
921
|
await this.stopSubagent(id);
|
|
901
922
|
}
|
|
902
|
-
|
|
903
|
-
this.store.deleteConversation(this.cwd, id);
|
|
904
|
-
}
|
|
923
|
+
// 仅从运行中会话映射与草稿中移除,保留磁盘持久化记录(供历史面板随时回溯打开)
|
|
905
924
|
this.conversations.delete(id);
|
|
906
925
|
this.sessionDrafts.delete(id);
|
|
907
926
|
if (this.activeConvId === id) {
|
|
@@ -1015,6 +1034,18 @@ export class UniversalSession {
|
|
|
1015
1034
|
if (forkedMessages.length > 0) {
|
|
1016
1035
|
forkedConv.updatedAt = Date.now();
|
|
1017
1036
|
}
|
|
1037
|
+
// 若底层驱动支持原生会话分叉(如 Durable 引擎的原生 CoW 分叉),保持事务级上下文关联
|
|
1038
|
+
if (targetConv.driverSessionId && typeof this.driver.forkSession === "function") {
|
|
1039
|
+
try {
|
|
1040
|
+
const forkedSid = await this.driver.forkSession(targetConv.driverSessionId);
|
|
1041
|
+
if (forkedSid) {
|
|
1042
|
+
forkedConv.driverSessionId = forkedSid;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
catch {
|
|
1046
|
+
/* fallback */
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1018
1049
|
this.conversations.set(forkedConv.id, forkedConv);
|
|
1019
1050
|
if (!forkedConv.isEphemeral) {
|
|
1020
1051
|
this.store.saveConversation(this.cwd, forkedConv);
|
|
@@ -1050,6 +1081,18 @@ export class UniversalSession {
|
|
|
1050
1081
|
if (headMessages.length > 0) {
|
|
1051
1082
|
forkedConv.updatedAt = Date.now();
|
|
1052
1083
|
}
|
|
1084
|
+
// 若底层驱动支持原生会话分叉(如 Durable 引擎),继承前序不可变记录
|
|
1085
|
+
if (conv.driverSessionId && typeof this.driver.forkSession === "function") {
|
|
1086
|
+
try {
|
|
1087
|
+
const forkedSid = await this.driver.forkSession(conv.driverSessionId);
|
|
1088
|
+
if (forkedSid) {
|
|
1089
|
+
forkedConv.driverSessionId = forkedSid;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
catch {
|
|
1093
|
+
/* fallback */
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1053
1096
|
this.conversations.set(forkedConv.id, forkedConv);
|
|
1054
1097
|
if (!forkedConv.isEphemeral) {
|
|
1055
1098
|
this.store.saveConversation(this.cwd, forkedConv);
|
|
@@ -1133,10 +1176,16 @@ export class UniversalSession {
|
|
|
1133
1176
|
return conv.title || (this.lang === "zh" ? "新对话" : "New chat");
|
|
1134
1177
|
}
|
|
1135
1178
|
async pushProjects() {
|
|
1136
|
-
|
|
1179
|
+
if (typeof this.stateStore?.getRecentProjects !== "function")
|
|
1180
|
+
return;
|
|
1181
|
+
const projects = await this.stateStore.getRecentProjects(this.clientId);
|
|
1182
|
+
this.send({ type: "projects", projects });
|
|
1137
1183
|
}
|
|
1138
|
-
async removeProject() {
|
|
1139
|
-
|
|
1184
|
+
async removeProject(path) {
|
|
1185
|
+
if (typeof this.stateStore?.removeProject !== "function")
|
|
1186
|
+
return;
|
|
1187
|
+
this.stateStore.removeProject(this.clientId, path);
|
|
1188
|
+
await this.pushProjects();
|
|
1140
1189
|
}
|
|
1141
1190
|
async searchSessions(query, reqId) {
|
|
1142
1191
|
const q = query.trim().toLowerCase();
|
|
@@ -1184,6 +1233,7 @@ export class UniversalSession {
|
|
|
1184
1233
|
path: conv.id,
|
|
1185
1234
|
sessionId: conv.id,
|
|
1186
1235
|
name: conv.title,
|
|
1236
|
+
displayName: this.resolveSessionDisplayName(conv, firstMsg),
|
|
1187
1237
|
firstMessage: firstMsg,
|
|
1188
1238
|
messageCount: conv.messages.length,
|
|
1189
1239
|
modified: conv.updatedAt,
|
|
@@ -1366,6 +1416,10 @@ export class UniversalSession {
|
|
|
1366
1416
|
}
|
|
1367
1417
|
await this.refreshSessions();
|
|
1368
1418
|
await this.refreshWorktreeInfo();
|
|
1419
|
+
if (typeof this.stateStore?.remember === "function") {
|
|
1420
|
+
this.stateStore.remember(this.clientId, path);
|
|
1421
|
+
}
|
|
1422
|
+
void this.pushProjects();
|
|
1369
1423
|
// 切换目录后恢复该目录按引擎隔离的项目记忆模型
|
|
1370
1424
|
const savedModel = this.stateStore?.getProjectModel(this.clientId, path, this.engine) ??
|
|
1371
1425
|
this.stateStore?.getDefaultModel(this.engine);
|
|
@@ -450,11 +450,19 @@ function versionFromCandidate(bin) {
|
|
|
450
450
|
return null;
|
|
451
451
|
}
|
|
452
452
|
/**
|
|
453
|
-
* Read the pi core version from disk: resolve the `pi` bin on PATH
|
|
454
|
-
*
|
|
455
|
-
*
|
|
453
|
+
* Read the pi core version from disk: resolve the `pi` bin on PATH and check standard
|
|
454
|
+
* global prefix directories, selecting the highest valid version found to avoid
|
|
455
|
+
* local/ancestor node_modules shadowing an updated global installation.
|
|
456
456
|
*/
|
|
457
457
|
export function readPiCoreVersionFromDisk(env = process.env) {
|
|
458
|
+
let bestVersion = null;
|
|
459
|
+
const updateBest = (v) => {
|
|
460
|
+
if (!v)
|
|
461
|
+
return;
|
|
462
|
+
if (!bestVersion || compareVersions(v, bestVersion) > 0) {
|
|
463
|
+
bestVersion = v;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
458
466
|
const rawPath = env.PATH ?? "";
|
|
459
467
|
const dirs = rawPath.split(delimiter).filter(Boolean);
|
|
460
468
|
const isWin = process.platform === "win32";
|
|
@@ -465,10 +473,14 @@ export function readPiCoreVersionFromDisk(env = process.env) {
|
|
|
465
473
|
if (!existsSync(candidate))
|
|
466
474
|
continue;
|
|
467
475
|
const version = versionFromCandidate(candidate);
|
|
468
|
-
if (version)
|
|
469
|
-
|
|
476
|
+
if (version) {
|
|
477
|
+
updateBest(version);
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
470
480
|
}
|
|
471
481
|
}
|
|
482
|
+
if (bestVersion)
|
|
483
|
+
return bestVersion;
|
|
472
484
|
// Fallback to global prefix directories (npm global prefix, pnpm, etc.)
|
|
473
485
|
const home = env.HOME || env.USERPROFILE || "";
|
|
474
486
|
const prefix = env.npm_config_prefix || env.PREFIX;
|
|
@@ -486,12 +498,12 @@ export function readPiCoreVersionFromDisk(env = process.env) {
|
|
|
486
498
|
for (const p of prefixDirs) {
|
|
487
499
|
const v1 = readPiCoreVersionAt(join(p, "node_modules", ...PI_CORE_PACKAGE.split("/"), "package.json"));
|
|
488
500
|
if (v1)
|
|
489
|
-
|
|
501
|
+
updateBest(v1);
|
|
490
502
|
const v2 = readPiCoreVersionAt(join(p, "lib", "node_modules", ...PI_CORE_PACKAGE.split("/"), "package.json"));
|
|
491
503
|
if (v2)
|
|
492
|
-
|
|
504
|
+
updateBest(v2);
|
|
493
505
|
}
|
|
494
|
-
return
|
|
506
|
+
return bestVersion;
|
|
495
507
|
}
|
|
496
508
|
/**
|
|
497
509
|
* Default pi core probe: run the globally installed `pi --version`, memoized
|
package/package.json
CHANGED
package/plugins/catalog.json
CHANGED
|
@@ -217,8 +217,8 @@
|
|
|
217
217
|
"nameEn": "Image Studio & Toolkit",
|
|
218
218
|
"icon": "🎨",
|
|
219
219
|
"iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 3l1.9 4.6L18.5 9.5l-4.6 1.9L12 16l-1.9-4.6L5.5 9.5l4.6-1.9z\"/><path d=\"M18 15l.9 2.1L21 18l-2.1.9L18 21l-.9-2.1L15 18l2.1-.9z\"/><path d=\"M4.5 19.5l2.5-2.5\"/></svg>",
|
|
220
|
-
"description": "一体化 AI 生图与图像处理工作台:一套配置同时接入通义万相、FLUX、OpenAI、Google Imagen/Gemini、智谱 CogView、火山豆包、Stability 与 ComfyUI 等主流生图服务;集成压缩(目标体积二分逼近)、裁剪、缩放、格式转换、水印、滤镜调色与 EXIF 分析;生图与处理在同一工作台内无缝流转。提供
|
|
221
|
-
"descriptionEn": "All-in-one AI image generation & processing studio: configure DashScope (Wanx), FLUX, OpenAI, Google Imagen/Gemini, Zhipu CogView, Volcengine Seedream, Stability & ComfyUI side by side; compress (with binary search target size), crop, resize, format conversion, watermark, filters & EXIF analysis. Seamlessly flow between generation and editing in one unified workbench. Ships
|
|
220
|
+
"description": "一体化 AI 生图与图像处理工作台:一套配置同时接入通义万相、FLUX、OpenAI、Google Imagen/Gemini、智谱 CogView、火山豆包、Stability 与 ComfyUI 等主流生图服务;集成压缩(目标体积二分逼近)、裁剪、缩放、格式转换、水印、滤镜调色与 EXIF 分析;生图与处理在同一工作台内无缝流转。提供 8 个 AI 工具,让 agent 自己生图、配置供应商、分析并加工工作区图片与精准像素取色(附带位置截图)。",
|
|
221
|
+
"descriptionEn": "All-in-one AI image generation & processing studio: configure DashScope (Wanx), FLUX, OpenAI, Google Imagen/Gemini, Zhipu CogView, Volcengine Seedream, Stability & ComfyUI side by side; compress (with binary search target size), crop, resize, format conversion, watermark, filters & EXIF analysis. Seamlessly flow between generation and editing in one unified workbench. Ships 8 AI tools for generation, provider configuration, analysis, processing, and exact pixel color picking with context screenshot crops.",
|
|
222
222
|
"source": "xing-shuyin/pi-web-ui/plugins/image-toolkit",
|
|
223
223
|
"homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/image-toolkit"
|
|
224
224
|
},
|
|
@@ -360,5 +360,16 @@
|
|
|
360
360
|
"descriptionEn": "Persistent Chrome automation: launches or attaches to a persistent Chrome instance, supports tab management, human-visible element snapshots, smart clicks and inputs, and anti-bot resilience across tasks.",
|
|
361
361
|
"source": "xing-shuyin/pi-web-ui/plugins/browser-use",
|
|
362
362
|
"homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/browser-use"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"id": "tts",
|
|
366
|
+
"name": "语音合成 (TTS)",
|
|
367
|
+
"nameEn": "TTS Voice Engine",
|
|
368
|
+
"icon": "🔊",
|
|
369
|
+
"iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><polygon points=\"11 5 6 9 2 9 2 15 6 15 11 19 11 5\"/><path d=\"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07\"/></svg>",
|
|
370
|
+
"description": "多源通用语音合成插件,聚合豆包大模型语音与 DeepSeek 官方音色,支持浏览器扩展一键同步登录凭据并支持消息朗读与实时边打字边流式发声。",
|
|
371
|
+
"descriptionEn": "Multi-engine TTS plugin aggregating Doubao and DeepSeek official voices, supporting one-click browser credential sync, message narration, and real-time streaming speech playback.",
|
|
372
|
+
"source": "xing-shuyin/pi-web-ui/plugins/tts",
|
|
373
|
+
"homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/tts"
|
|
363
374
|
}
|
|
364
375
|
]
|