pi-web-ui 0.106.0 → 0.108.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 +77 -11
- package/README.zh-TW.md +2 -2
- package/dist/server/agent-formatters.js +19 -4
- package/dist/server/agent-service.js +33 -16
- package/dist/server/bg-servers.js +205 -53
- package/dist/server/client-state.js +6 -2
- package/dist/server/dispatch-domain-handlers.js +2 -0
- package/dist/server/dsh/dsh-agent-service.js +24 -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/files-service.js +15 -1
- 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-admin.js +61 -10
- package/dist/server/model-resolver.js +91 -3
- package/dist/server/plugins.js +18 -1
- package/dist/server/preset-fields.js +14 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/process-utils.js +114 -12
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/sdk-origin.js +2 -2
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +4 -0
- package/dist/server/text-sniff.js +2 -0
- 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 +63 -7
- package/dist/server/update-check.js +20 -8
- package/package.json +2 -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-CslRhcS7.js} +2 -2
- package/web/dist/assets/index-C_2Fl6f6.js +690 -0
- package/web/dist/assets/index-D0BtO5dn.css +1 -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
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 经 ModelAdminHost 与 ClientSession 解耦(同 settings/goal/slash 服务模式)。
|
|
12
12
|
* UI 文案直接中文(服务端 notice 约定)。apiKey/headers 绝不下发浏览器。
|
|
13
13
|
*/
|
|
14
|
-
import { existsSync, mkdirSync, readFileSync, renameSync } from "node:fs";
|
|
14
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
15
15
|
import { dirname, join } from "node:path";
|
|
16
16
|
import { writeJsonAtomicSync } from "./atomic-file.js";
|
|
17
17
|
import { enrichBatch } from "./model-enrich.js";
|
|
@@ -70,6 +70,17 @@ export function graduateOverlayModels(providers, official) {
|
|
|
70
70
|
function atomicWriteJson(path, data) {
|
|
71
71
|
writeJsonAtomicSync(path, data);
|
|
72
72
|
}
|
|
73
|
+
/** 原子写凭据 JSON 并修权限 0600(port from fork 50e723f,保留上游原子写语义)。
|
|
74
|
+
* chmod 覆盖已存在文件(mode 选项只对新建有效)。Windows 下尽力而为。 */
|
|
75
|
+
function atomicWriteCredentialJson(path, data) {
|
|
76
|
+
writeJsonAtomicSync(path, data);
|
|
77
|
+
try {
|
|
78
|
+
chmodSync(path, CREDENTIAL_FILE_MODE);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
/* best-effort (win) */
|
|
82
|
+
}
|
|
83
|
+
}
|
|
73
84
|
/** Strip // and /* *\/ comments without touching string literals (URLs contain //). */
|
|
74
85
|
function stripJsonComments(src) {
|
|
75
86
|
let out = "";
|
|
@@ -247,12 +258,40 @@ function parseGoogleModel(m) {
|
|
|
247
258
|
...(numMeta(r.outputTokenLimit) ? { maxTokens: numMeta(r.outputTokenLimit) } : {}),
|
|
248
259
|
};
|
|
249
260
|
}
|
|
261
|
+
/** Credential files hold raw provider API keys — always mode 0600.
|
|
262
|
+
* models.json can hold per-provider apiKey/headers, so it gets the same treatment. */
|
|
263
|
+
export const CREDENTIAL_FILE_MODE = 0o600;
|
|
264
|
+
/** Write a credential file (provider-keys.json / auth.json / models.json) with mode 0600.
|
|
265
|
+
* The `mode` option covers creation; the chmod covers pre-existing files
|
|
266
|
+
* (mode is ignored when the file already exists). Best-effort on Windows. */
|
|
267
|
+
export function writeCredentialFile(path, data) {
|
|
268
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
269
|
+
writeFileSync(path, data, { mode: CREDENTIAL_FILE_MODE });
|
|
270
|
+
try {
|
|
271
|
+
chmodSync(path, CREDENTIAL_FILE_MODE);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
/* best-effort (win) */
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** Startup repair: chmod existing credential files to 0600 (best-effort). */
|
|
278
|
+
export function ensureCredentialFilePermissions(agentDir) {
|
|
279
|
+
for (const name of ["provider-keys.json", "auth.json", "models.json"]) {
|
|
280
|
+
try {
|
|
281
|
+
chmodSync(join(agentDir, name), CREDENTIAL_FILE_MODE);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
/* missing / win — ignore */
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
250
288
|
export class ModelAdminService {
|
|
251
289
|
host;
|
|
252
290
|
oauthFlows;
|
|
253
291
|
activeEnrichAbort = new Map();
|
|
254
292
|
constructor(host) {
|
|
255
293
|
this.host = host;
|
|
294
|
+
ensureCredentialFilePermissions(host.agentDir);
|
|
256
295
|
this.oauthFlows = new ProviderOAuthFlowManager({
|
|
257
296
|
modelRuntime: host.modelRuntime ??
|
|
258
297
|
(() => {
|
|
@@ -379,8 +418,15 @@ export class ModelAdminService {
|
|
|
379
418
|
return out;
|
|
380
419
|
}
|
|
381
420
|
writeProviderKeys(data) {
|
|
382
|
-
|
|
383
|
-
|
|
421
|
+
atomicWriteCredentialJson(this.providerKeysPath(), data);
|
|
422
|
+
// Keep the sibling credential file at 0600 too (e.g. adding an
|
|
423
|
+
// inactive key rewrites provider-keys.json but not auth.json).
|
|
424
|
+
try {
|
|
425
|
+
chmodSync(join(this.host.agentDir, "auth.json"), CREDENTIAL_FILE_MODE);
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
/* missing / win — ignore */
|
|
429
|
+
}
|
|
384
430
|
}
|
|
385
431
|
/** 解析失败的配置文件改名留存为 <name>.corrupt-<timestamp>。改名失败(占用/
|
|
386
432
|
* 跨盘等)也不抛——留存是尽力而为,绝不能阻塞主流程。 */
|
|
@@ -498,7 +544,6 @@ export class ModelAdminService {
|
|
|
498
544
|
/** Persist the ACTIVE key's apiKey into auth.json + runtime override + refresh. */
|
|
499
545
|
async applyActiveKey(pid, apiKey) {
|
|
500
546
|
const authPath = join(this.host.agentDir, "auth.json");
|
|
501
|
-
mkdirSync(this.host.agentDir, { recursive: true });
|
|
502
547
|
let data = {};
|
|
503
548
|
try {
|
|
504
549
|
data = JSON.parse(readFileSync(authPath, "utf8"));
|
|
@@ -507,7 +552,13 @@ export class ModelAdminService {
|
|
|
507
552
|
// no file yet / unparsable — start fresh
|
|
508
553
|
}
|
|
509
554
|
data[pid] = { type: "api_key", key: apiKey };
|
|
510
|
-
|
|
555
|
+
atomicWriteCredentialJson(authPath, data);
|
|
556
|
+
try {
|
|
557
|
+
chmodSync(this.providerKeysPath(), CREDENTIAL_FILE_MODE);
|
|
558
|
+
}
|
|
559
|
+
catch {
|
|
560
|
+
/* missing / win — ignore */
|
|
561
|
+
}
|
|
511
562
|
const mr = this.host.modelRuntime?.();
|
|
512
563
|
if (mr) {
|
|
513
564
|
await mr.setRuntimeApiKey(pid, apiKey);
|
|
@@ -740,7 +791,7 @@ export class ModelAdminService {
|
|
|
740
791
|
// no file yet — nothing to clean
|
|
741
792
|
}
|
|
742
793
|
delete auth[pid];
|
|
743
|
-
|
|
794
|
+
atomicWriteCredentialJson(authPath, auth);
|
|
744
795
|
const mr = this.host.modelRuntime?.();
|
|
745
796
|
if (mr) {
|
|
746
797
|
await mr.removeRuntimeApiKey(pid);
|
|
@@ -833,7 +884,7 @@ export class ModelAdminService {
|
|
|
833
884
|
return;
|
|
834
885
|
}
|
|
835
886
|
delete data[pid];
|
|
836
|
-
|
|
887
|
+
atomicWriteCredentialJson(authPath, data);
|
|
837
888
|
// Clear every stored key so the provider returns to unconfigured.
|
|
838
889
|
delete keyData[pid];
|
|
839
890
|
this.writeProviderKeys(keyData);
|
|
@@ -1704,7 +1755,7 @@ export class ModelAdminService {
|
|
|
1704
1755
|
if (graduated.length === 0)
|
|
1705
1756
|
return graduated;
|
|
1706
1757
|
try {
|
|
1707
|
-
|
|
1758
|
+
atomicWriteCredentialJson(this.modelsConfigPath(), { providers });
|
|
1708
1759
|
}
|
|
1709
1760
|
catch {
|
|
1710
1761
|
return [];
|
|
@@ -1741,7 +1792,7 @@ export class ModelAdminService {
|
|
|
1741
1792
|
* config list + the picker. Callers emit their own notice. */
|
|
1742
1793
|
async writeModelsConfigAndReload(providers, pid) {
|
|
1743
1794
|
mkdirSync(this.host.agentDir, { recursive: true });
|
|
1744
|
-
|
|
1795
|
+
atomicWriteCredentialJson(this.modelsConfigPath(), { providers });
|
|
1745
1796
|
// Allow a models.json entry to reuse the provider credential already
|
|
1746
1797
|
// stored in auth.json. Seed the shared runtime too, because older pi-ai
|
|
1747
1798
|
// versions did not always fall back to stored credentials for a
|
|
@@ -1898,7 +1949,7 @@ export class ModelAdminService {
|
|
|
1898
1949
|
return;
|
|
1899
1950
|
}
|
|
1900
1951
|
delete providers[providerId];
|
|
1901
|
-
|
|
1952
|
+
atomicWriteCredentialJson(this.modelsConfigPath(), { providers });
|
|
1902
1953
|
await this.host.modelRuntime?.()?.refresh();
|
|
1903
1954
|
this.host.invalidatePiConfig?.();
|
|
1904
1955
|
await this.listModelsConfig();
|
|
@@ -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 兜住,
|
|
@@ -77,6 +77,7 @@ export const PRESET_FIELD_GROUPS = {
|
|
|
77
77
|
"toolsWrap",
|
|
78
78
|
"toolImagesEnabled",
|
|
79
79
|
"keepRecentMessages",
|
|
80
|
+
"reversePagination",
|
|
80
81
|
"showForkedParentSessions",
|
|
81
82
|
"retainFinishedConversations",
|
|
82
83
|
"openRecentSessionOnProjectSwitch",
|
|
@@ -84,6 +85,7 @@ export const PRESET_FIELD_GROUPS = {
|
|
|
84
85
|
"quickPhrases",
|
|
85
86
|
"quickPhrasesEnabled",
|
|
86
87
|
"minimalNewChat",
|
|
88
|
+
"preserveDraftAcrossConversations",
|
|
87
89
|
"devNoCache",
|
|
88
90
|
"autoReload",
|
|
89
91
|
],
|
|
@@ -403,6 +405,12 @@ export const PRESET_FIELD_META = {
|
|
|
403
405
|
hintZh: "消息列表尾部保持完整渲染的消息条数;更早的折叠为摘要行",
|
|
404
406
|
hintEn: "Recent messages rendered in full; older ones collapse to summary rows",
|
|
405
407
|
},
|
|
408
|
+
reversePagination: {
|
|
409
|
+
labelZh: "向上分页加载",
|
|
410
|
+
labelEn: "Load Earlier Messages",
|
|
411
|
+
hintZh: "默认仅挂载最近消息,向上滚动或点击加载更早历史,完全跳过视口占位符获得原生流畅度",
|
|
412
|
+
hintEn: "Only mount recent messages; scroll up or click to load earlier history with zero placeholders",
|
|
413
|
+
},
|
|
406
414
|
showForkedParentSessions: {
|
|
407
415
|
labelZh: "显示已分支的父会话",
|
|
408
416
|
labelEn: "Show Forked Parent Sessions",
|
|
@@ -439,6 +447,12 @@ export const PRESET_FIELD_META = {
|
|
|
439
447
|
hintZh: "新对话隐藏提示词模板并隐藏快捷短语,呈现现代极简风格",
|
|
440
448
|
hintEn: "Hide prompt templates and quick phrases on new chat for a clean modern look",
|
|
441
449
|
},
|
|
450
|
+
preserveDraftAcrossConversations: {
|
|
451
|
+
labelZh: "输入框文字跨对话保留",
|
|
452
|
+
labelEn: "Preserve Composer Text Across Conversations",
|
|
453
|
+
hintZh: "开启:输入文字切换别的会话不清空;关闭:仅保留当前会话文字,切换其他会话时清空或显示该会话已保留文字,切回时恢复当前会话文字",
|
|
454
|
+
hintEn: "Enabled: keep composer text when switching conversations. Disabled: retain text only for the current conversation",
|
|
455
|
+
},
|
|
442
456
|
devNoCache: {
|
|
443
457
|
labelZh: "开发者免缓存模式",
|
|
444
458
|
labelEn: "Developer No-Cache Mode",
|
|
@@ -273,12 +273,14 @@ const PRESET_FIELD_KINDS = {
|
|
|
273
273
|
toolsWrap: "bool",
|
|
274
274
|
toolImagesEnabled: "bool",
|
|
275
275
|
keepRecentMessages: "number",
|
|
276
|
+
reversePagination: "bool",
|
|
276
277
|
showForkedParentSessions: "bool",
|
|
277
278
|
retainFinishedConversations: "bool",
|
|
278
279
|
openRecentSessionOnProjectSwitch: "bool",
|
|
279
280
|
quickPhrases: "list",
|
|
280
281
|
quickPhrasesEnabled: "bool",
|
|
281
282
|
minimalNewChat: "bool",
|
|
283
|
+
preserveDraftAcrossConversations: "bool",
|
|
282
284
|
devNoCache: "bool",
|
|
283
285
|
autoReload: "bool",
|
|
284
286
|
// -- engine ----------------------------------------------------------
|
|
@@ -47,12 +47,11 @@ export async function snapshotListeningPorts() {
|
|
|
47
47
|
return m;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Snapshot every process's parent pid → Map<pid,
|
|
51
|
-
* PowerShell CIM pass
|
|
52
|
-
*
|
|
53
|
-
* fails — callers should treat that as "cannot verify, stay conservative".
|
|
50
|
+
* Snapshot every process's parent pid & name → Map<pid, ProcessTreeNode>.
|
|
51
|
+
* Windows: one PowerShell CIM pass; POSIX: one `ps -Ao pid=,ppid=,comm=` pass.
|
|
52
|
+
* Returns undefined when query fails — callers should treat as unverified.
|
|
54
53
|
*/
|
|
55
|
-
export async function
|
|
54
|
+
export async function snapshotProcessTree() {
|
|
56
55
|
try {
|
|
57
56
|
const { execFile } = await import("node:child_process");
|
|
58
57
|
const m = new Map();
|
|
@@ -61,23 +60,35 @@ export async function snapshotProcessParents() {
|
|
|
61
60
|
"-NoProfile",
|
|
62
61
|
"-NonInteractive",
|
|
63
62
|
"-Command",
|
|
64
|
-
'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId):$($_.ParentProcessId)" }',
|
|
63
|
+
'Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId):$($_.ParentProcessId):$($_.Name)" }',
|
|
65
64
|
], { windowsHide: true, timeout: 10000 }, (err, stdout) => (err ? reject(err) : resolve(stdout))));
|
|
66
65
|
for (const line of out.split(/\r?\n/)) {
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
|
|
66
|
+
const trimmed = line.trim();
|
|
67
|
+
if (!trimmed)
|
|
68
|
+
continue;
|
|
69
|
+
const firstColon = trimmed.indexOf(":");
|
|
70
|
+
const secondColon = trimmed.indexOf(":", firstColon + 1);
|
|
71
|
+
if (firstColon === -1)
|
|
72
|
+
continue;
|
|
73
|
+
const pid = Number(trimmed.slice(0, firstColon));
|
|
74
|
+
const ppid = Number(secondColon === -1 ? trimmed.slice(firstColon + 1) : trimmed.slice(firstColon + 1, secondColon));
|
|
75
|
+
const name = secondColon === -1 ? undefined : trimmed.slice(secondColon + 1).trim() || undefined;
|
|
76
|
+
if (Number.isFinite(pid) && Number.isFinite(ppid)) {
|
|
77
|
+
m.set(pid, { ppid, ...(name ? { name } : {}) });
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
else {
|
|
73
|
-
const out = await new Promise((resolve, reject) => execFile("ps", ["-Ao", "pid=,ppid="], { timeout: 5000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
82
|
+
const out = await new Promise((resolve, reject) => execFile("ps", ["-Ao", "pid=,ppid=,comm="], { timeout: 5000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
74
83
|
for (const line of out.split(/\r?\n/)) {
|
|
75
84
|
const p = line.trim().split(/\s+/);
|
|
76
85
|
if (p.length >= 2) {
|
|
77
86
|
const pid = Number(p[0]);
|
|
78
87
|
const ppid = Number(p[1]);
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
const name = p.slice(2).join(" ").trim() || undefined;
|
|
89
|
+
if (Number.isFinite(pid) && Number.isFinite(ppid)) {
|
|
90
|
+
m.set(pid, { ppid, ...(name ? { name } : {}) });
|
|
91
|
+
}
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
}
|
|
@@ -87,6 +98,97 @@ export async function snapshotProcessParents() {
|
|
|
87
98
|
return undefined;
|
|
88
99
|
}
|
|
89
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Snapshot every process's parent pid → Map<pid, ppid>.
|
|
103
|
+
* Retained for backward compatibility; powered by snapshotProcessTree.
|
|
104
|
+
*/
|
|
105
|
+
export async function snapshotProcessParents() {
|
|
106
|
+
const tree = await snapshotProcessTree();
|
|
107
|
+
if (!tree)
|
|
108
|
+
return undefined;
|
|
109
|
+
const m = new Map();
|
|
110
|
+
for (const [pid, node] of tree) {
|
|
111
|
+
m.set(pid, node.ppid);
|
|
112
|
+
}
|
|
113
|
+
return m;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Batch lookup detailed process info (pid, ppid, name, commandLine, createdMs).
|
|
117
|
+
* Windows: single PowerShell CIM pass with filter; POSIX: `ps -o pid=,ppid=,etimes=,comm=,command=`.
|
|
118
|
+
*/
|
|
119
|
+
export async function lookupProcessDetailsBatch(pids) {
|
|
120
|
+
const out = new Map();
|
|
121
|
+
const validPids = [...new Set(pids.filter((p) => Number.isInteger(p) && p > 0))];
|
|
122
|
+
if (validPids.length === 0)
|
|
123
|
+
return out;
|
|
124
|
+
try {
|
|
125
|
+
const { execFile } = await import("node:child_process");
|
|
126
|
+
if (process.platform === "win32") {
|
|
127
|
+
const filter = validPids.map((p) => `ProcessId=${p}`).join(" or ");
|
|
128
|
+
const command = [
|
|
129
|
+
`$filter = '${filter}';`,
|
|
130
|
+
`Get-CimInstance Win32_Process -Filter $filter | ForEach-Object {`,
|
|
131
|
+
` $ts = if ($_.CreationDate) { [DateTimeOffset]::new($_.CreationDate).ToUnixTimeMilliseconds() } else { 0 };`,
|
|
132
|
+
` $cmd = if ($_.CommandLine) { $_.CommandLine -replace "\\r?\\n", " " } else { "" };`,
|
|
133
|
+
` "$($_.ProcessId)\`t$($_.ParentProcessId)\`t$($_.Name)\`t$ts\`t$cmd"`,
|
|
134
|
+
`}`,
|
|
135
|
+
].join(" ");
|
|
136
|
+
const stdout = await new Promise((resolve, reject) => execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], { windowsHide: true, timeout: 8000 }, (err, res) => (err ? reject(err) : resolve(res))));
|
|
137
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
138
|
+
const trimmed = line.trim();
|
|
139
|
+
if (!trimmed)
|
|
140
|
+
continue;
|
|
141
|
+
const parts = trimmed.split("\t");
|
|
142
|
+
if (parts.length >= 3) {
|
|
143
|
+
const pid = Number(parts[0]);
|
|
144
|
+
const ppid = Number(parts[1]);
|
|
145
|
+
const name = parts[2] || undefined;
|
|
146
|
+
const ts = Number(parts[3]);
|
|
147
|
+
const cmd = parts.slice(4).join("\t").trim();
|
|
148
|
+
if (Number.isFinite(pid)) {
|
|
149
|
+
out.set(pid, {
|
|
150
|
+
pid,
|
|
151
|
+
...(Number.isFinite(ppid) ? { ppid } : {}),
|
|
152
|
+
...(name ? { name } : {}),
|
|
153
|
+
...(Number.isFinite(ts) && ts > 0 ? { createdMs: ts } : {}),
|
|
154
|
+
...(cmd ? { commandLine: cmd } : {}),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
// POSIX (Linux / macOS)
|
|
162
|
+
const stdout = await new Promise((resolve, reject) => execFile("ps", ["-o", "pid=,ppid=,etimes=,comm=,command=", "-p", validPids.join(",")], { timeout: 5000 }, (err, res) => (err ? reject(err) : resolve(res))));
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
165
|
+
const trimmed = line.trim();
|
|
166
|
+
if (!trimmed)
|
|
167
|
+
continue;
|
|
168
|
+
// 格式: pid ppid etimes comm command...
|
|
169
|
+
const match = trimmed.match(/^(\d+)\s+(\d+)\s+(\d+)\s+(\S+)(?:\s+(.*))?$/);
|
|
170
|
+
if (match) {
|
|
171
|
+
const pid = Number(match[1]);
|
|
172
|
+
const ppid = Number(match[2]);
|
|
173
|
+
const etimes = Number(match[3]);
|
|
174
|
+
const name = match[4];
|
|
175
|
+
const commandLine = match[5]?.trim();
|
|
176
|
+
const createdMs = Number.isFinite(etimes) ? now - etimes * 1000 : undefined;
|
|
177
|
+
out.set(pid, {
|
|
178
|
+
pid,
|
|
179
|
+
ppid,
|
|
180
|
+
name,
|
|
181
|
+
...(commandLine ? { commandLine } : {}),
|
|
182
|
+
...(createdMs !== undefined ? { createdMs } : {}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// best effort — lookup failure just returns empty map
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
90
192
|
/** Kill a pid and its whole process tree (cross-platform).
|
|
91
193
|
*
|
|
92
194
|
* The returned promise is only meaningful on Windows, where taskkill is itself
|
|
@@ -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);
|
|
@@ -372,6 +372,7 @@ export class SettingsService {
|
|
|
372
372
|
quickPhrases: [...this.settings.quickPhrases],
|
|
373
373
|
quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
|
|
374
374
|
minimalNewChat: this.settings.minimalNewChat,
|
|
375
|
+
preserveDraftAcrossConversations: this.settings.preserveDraftAcrossConversations ?? false,
|
|
375
376
|
quickPhrasesSeeded: this.host.stateStore.getQuickPhrasesSeeded(),
|
|
376
377
|
mcpServers: mcp.servers,
|
|
377
378
|
mcpGlobalConfigPath: mcp.globalPath,
|
|
@@ -662,6 +663,9 @@ export class SettingsService {
|
|
|
662
663
|
if (partial.minimalNewChat !== undefined) {
|
|
663
664
|
this.settings.minimalNewChat = partial.minimalNewChat;
|
|
664
665
|
}
|
|
666
|
+
if (partial.preserveDraftAcrossConversations !== undefined) {
|
|
667
|
+
this.settings.preserveDraftAcrossConversations = Boolean(partial.preserveDraftAcrossConversations);
|
|
668
|
+
}
|
|
665
669
|
// 统一工具开关 live 生效(ActiveSet 加减;失败静默,下次创建/reload 重放)。
|
|
666
670
|
// 必须在 this.push() 前生效,保证 promptSnapshot 收集到的是最新的活跃工具集与完整提示词!
|
|
667
671
|
if (toolGatingChanged)
|
|
@@ -151,6 +151,8 @@ export function previewKind(name) {
|
|
|
151
151
|
return "image";
|
|
152
152
|
if (PREVIEW_VIDEO_EXTS.has(ext))
|
|
153
153
|
return "video";
|
|
154
|
+
if (PREVIEW_AUDIO_EXTS.has(ext))
|
|
155
|
+
return "audio";
|
|
154
156
|
if (ext === "" || PREVIEW_TEXT_EXTS.has(ext))
|
|
155
157
|
return "text";
|
|
156
158
|
return "none";
|
|
@@ -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,
|