pi-web-ui 0.111.0 → 0.112.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 +55 -2
- package/bin/frp-manager.mjs +9 -2
- package/dist/server/agent-service.js +1325 -488
- package/dist/server/approval-audit.js +119 -0
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/approval-rules.js +42 -17
- package/dist/server/attachment-store.js +8 -8
- package/dist/server/canvas/canvas-agent-tool.js +6 -0
- package/dist/server/canvas/canvas-orchestrator.js +88 -21
- package/dist/server/client-state.js +28 -0
- package/dist/server/delegate-mode.js +6 -3
- package/dist/server/delegate-task.js +18 -3
- package/dist/server/dispatch-domain-handlers.js +3 -0
- package/dist/server/dsh/dsh-agent-service.js +242 -11
- package/dist/server/dsh/dsh-serialize.js +1 -1
- package/dist/server/durable/durable-driver.js +75 -9
- package/dist/server/durable/durable-loader.js +1 -14
- package/dist/server/durable/durable-models.js +107 -0
- package/dist/server/durable/index.js +0 -4
- package/dist/server/engine-probe.js +76 -37
- package/dist/server/eval-tool.js +28 -3
- package/dist/server/goal-service.js +7 -0
- package/dist/server/index.js +344 -56
- package/dist/server/json-utils.js +57 -0
- package/dist/server/marker-service.js +8 -0
- package/dist/server/message-window.js +43 -10
- package/dist/server/model-admin.js +68 -106
- package/dist/server/model-resolver.js +66 -44
- package/dist/server/plan-manager.js +3 -6
- package/dist/server/plugin-api-catalog.js +1 -0
- package/dist/server/plugin-assets.js +238 -0
- package/dist/server/plugin-facilities.js +22 -0
- package/dist/server/plugin-ui-slots.js +1 -0
- package/dist/server/plugins.js +199 -5
- package/dist/server/preset-fields.js +25 -1
- package/dist/server/preset-share.js +5 -2
- package/dist/server/prompt-assembler.js +2 -1
- package/dist/server/prompt-composer.js +18 -8
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-utils.js +156 -0
- package/dist/server/sdk-builtin-extensions.js +85 -0
- package/dist/server/server-config.js +66 -0
- package/dist/server/session-parser.js +49 -13
- package/dist/server/session-search.js +4 -3
- package/dist/server/settings-service.js +38 -5
- package/dist/server/soft-cap.js +8 -6
- package/dist/server/subagent-helpers.js +22 -1
- package/dist/server/subagent-notify.js +93 -0
- package/dist/server/subagent-security-gate.js +282 -0
- package/dist/server/subagent-templates.js +8 -0
- package/dist/server/subagents.js +144 -17
- package/dist/server/terminals.js +196 -8
- package/dist/server/text-quote.js +61 -0
- package/dist/server/tool-approval.js +63 -4
- package/dist/server/tool-guards.js +208 -0
- package/dist/server/tool-host-factories.js +46 -10
- package/dist/server/tool-overrides.js +21 -11
- package/dist/server/universal/driver-base.js +8 -0
- package/dist/server/universal/drivers/claude-code.js +20 -3
- package/dist/server/universal/drivers/dsh-driver.js +3 -0
- package/dist/server/universal/index.js +0 -1
- package/dist/server/universal/universal-session.js +87 -10
- package/dist/server/worktree-service.js +189 -1
- package/docs/dsh-engine.md +1 -5
- package/package.json +1 -1
- package/plugin-sdk/client-utils.mjs +192 -5
- package/plugin-sdk/index.d.ts +63 -1
- package/plugin-sdk/index.mjs +94 -0
- package/plugin-sdk/package.json +5 -1
- package/plugins/catalog.json +11 -0
- package/web/dist/assets/{TerminalPanel-BiUNySMA.js → TerminalPanel-Dqr1dK28.js} +1 -1
- package/web/dist/assets/index-Dh8BX-lP.js +720 -0
- package/web/dist/assets/index-DqrC1I_a.css +1 -0
- package/web/dist/index.html +11 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-B0ajS__T.js +0 -697
- package/web/dist/assets/index-BHik5WGG.css +0 -1
|
@@ -12,7 +12,7 @@ export const DEFAULT_HISTORY_PAGE = 30;
|
|
|
12
12
|
/** 单次翻页上限,防止一条消息把几千条历史一次拉下来。 */
|
|
13
13
|
const MAX_PAGE = 2000;
|
|
14
14
|
/** 最多为几个对话保留全量缓存(LRU)—— 引用的是引擎已序列化好的对象,只有指针开销。 */
|
|
15
|
-
const MAX_CACHED_CONVERSATIONS =
|
|
15
|
+
const MAX_CACHED_CONVERSATIONS = 64;
|
|
16
16
|
const OFF_CONFIG = { windowSize: 0, charBudget: 0, pageSize: DEFAULT_HISTORY_PAGE };
|
|
17
17
|
const DEFAULT_CONFIG = {
|
|
18
18
|
windowSize: DEFAULT_HISTORY_WINDOW,
|
|
@@ -150,19 +150,51 @@ export class MessageWindowTap {
|
|
|
150
150
|
}
|
|
151
151
|
this.send(msg);
|
|
152
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* 按需回水:从运行时或存储中恢复某个会话的全量消息基线,
|
|
155
|
+
* 供 LRU 逐出、冷启动或跨连接无快照状态下立即恢复翻页服务能力。
|
|
156
|
+
*/
|
|
157
|
+
rehydrate(convId, full, start) {
|
|
158
|
+
const entry = this.entry(convId);
|
|
159
|
+
entry.full = full;
|
|
160
|
+
if (start !== undefined && Number.isFinite(start) && start >= 0) {
|
|
161
|
+
entry.start = Math.min(full.length, start);
|
|
162
|
+
}
|
|
163
|
+
else if (entry.start < 0) {
|
|
164
|
+
entry.start = pickWindowStart(full, this.cfg);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
153
167
|
/** 客户端往上翻页:把窗口起点往前扩 `count` 条(`all` = 一路拉到最早)。
|
|
154
|
-
* `conversationId
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
* - `conversationId`: 会话 ID(缺省回退最近一次快照会话);
|
|
169
|
+
* - `beforeId`: 客户端首条消息的 ID(优先使用该不可变锚点,不受压缩/重试导致的下标漂移影响);
|
|
170
|
+
* - `before`: 客户端当前窗口起点下标(自描述游标,entry 丢失或失忆时作为截断右边界);
|
|
171
|
+
* 返回 boolean: true = 已命中并下发 earlier_messages; false = entry 未命中(调用方可尝试回水)。 */
|
|
172
|
+
loadEarlier(countOrOpts, all, conversationId, beforeId, before) {
|
|
173
|
+
const opts = typeof countOrOpts === "object" && countOrOpts !== null
|
|
174
|
+
? countOrOpts
|
|
175
|
+
: { count: countOrOpts, all, conversationId, beforeId, before };
|
|
176
|
+
const convId = opts.conversationId || this.lastConversationId;
|
|
159
177
|
const entry = convId ? this.convs.get(convId) : undefined;
|
|
160
178
|
if (!entry || !convId)
|
|
161
|
-
return;
|
|
179
|
+
return false;
|
|
162
180
|
const total = entry.full.length;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
181
|
+
// 确定翻页右边界(end):
|
|
182
|
+
// 1. 优先使用不可变消息 ID beforeId 定位(防数组位移);
|
|
183
|
+
// 2. 其次使用客户端自描述下标 before(自描述游标);
|
|
184
|
+
// 3. 最后回退服务端自身记录的 entry.start(若小于 0 则说明未初始化,回退 total)。
|
|
185
|
+
let end = entry.start >= 0 ? entry.start : total;
|
|
186
|
+
if (opts.beforeId) {
|
|
187
|
+
const idx = entry.full.findIndex((m) => m.id === opts.beforeId);
|
|
188
|
+
if (idx >= 0) {
|
|
189
|
+
end = idx;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (typeof opts.before === "number" && Number.isFinite(opts.before) && opts.before >= 0) {
|
|
193
|
+
end = Math.min(total, opts.before);
|
|
194
|
+
}
|
|
195
|
+
const page = opts.all ? end : Math.min(MAX_PAGE, Math.max(1, Math.floor(opts.count ?? this.cfg.pageSize) || 1));
|
|
196
|
+
const start = opts.all ? 0 : Math.max(0, end - page);
|
|
197
|
+
const messages = start < end ? entry.full.slice(start, end) : [];
|
|
166
198
|
entry.start = start;
|
|
167
199
|
this.send({
|
|
168
200
|
type: "earlier_messages",
|
|
@@ -171,6 +203,7 @@ export class MessageWindowTap {
|
|
|
171
203
|
historyStart: start,
|
|
172
204
|
historyTotal: total,
|
|
173
205
|
});
|
|
206
|
+
return true;
|
|
174
207
|
}
|
|
175
208
|
/** 取(或建)对话窗口;LRU 超限时淘汰最久未用的那个。 */
|
|
176
209
|
entry(convId) {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
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
|
+
import { stripJsonComments } from "./json-utils.js";
|
|
17
18
|
import { enrichBatch } from "./model-enrich.js";
|
|
18
19
|
import { pick } from "./i18n.js";
|
|
19
20
|
import { ProviderOAuthFlowManager } from "./provider-oauth-flow.js";
|
|
@@ -77,49 +78,6 @@ function atomicWriteCredentialJson(path, data) {
|
|
|
77
78
|
/* best-effort (win) */
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
/** Strip // and /* *\/ comments without touching string literals (URLs contain //). */
|
|
81
|
-
function stripJsonComments(src) {
|
|
82
|
-
let out = "";
|
|
83
|
-
let inString = false;
|
|
84
|
-
let i = 0;
|
|
85
|
-
while (i < src.length) {
|
|
86
|
-
const c = src[i];
|
|
87
|
-
const next = src[i + 1];
|
|
88
|
-
if (inString) {
|
|
89
|
-
out += c;
|
|
90
|
-
if (c === "\\") {
|
|
91
|
-
out += next ?? "";
|
|
92
|
-
i += 2;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (c === '"')
|
|
96
|
-
inString = false;
|
|
97
|
-
i++;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (c === '"') {
|
|
101
|
-
inString = true;
|
|
102
|
-
out += c;
|
|
103
|
-
i++;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (c === "/" && next === "/") {
|
|
107
|
-
while (i < src.length && src[i] !== "\n")
|
|
108
|
-
i++;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (c === "/" && next === "*") {
|
|
112
|
-
i += 2;
|
|
113
|
-
while (i < src.length && !(src[i] === "*" && src[i + 1] === "/"))
|
|
114
|
-
i++;
|
|
115
|
-
i += 2;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
out += c;
|
|
119
|
-
i++;
|
|
120
|
-
}
|
|
121
|
-
return out;
|
|
122
|
-
}
|
|
123
81
|
/** Merge a UI-submitted provider config into the existing models.json entry.
|
|
124
82
|
*
|
|
125
83
|
* 表单(`UiProviderConfig`)只承载 UI 认识的字段:provider 级 name/api/baseUrl/
|
|
@@ -203,6 +161,38 @@ function boolMeta(v) {
|
|
|
203
161
|
function strArrMeta(v) {
|
|
204
162
|
return Array.isArray(v) ? v.filter((x) => typeof x === "string") : undefined;
|
|
205
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* 体系化启发式推断模型是否具备推理/深度思考能力:
|
|
166
|
+
* 1. 显式端点元数据优先(reasoning / supports_reasoning / modalities 包含 reasoning);
|
|
167
|
+
* 2. 业界主流推理模型命名特征正则库:
|
|
168
|
+
* - thinking / reasoner / reasoning 显式词
|
|
169
|
+
* - OpenAI o1 / o3 / o4 系列(如 o1, o1-mini, o1-preview, o3-mini, o3-high, o4 等)
|
|
170
|
+
* - DeepSeek R1 / Reasoner 系列(如 deepseek-r1, r1-distill 等)
|
|
171
|
+
* - 阿里千问 QwQ 系列(如 qwq-32b, qwq-32b-preview)
|
|
172
|
+
* - 智谱 GLM-Zero 系列(如 glm-4-zero, glm-zero)
|
|
173
|
+
* - CoT (Chain of Thought) 显式标记
|
|
174
|
+
*/
|
|
175
|
+
export function detectReasoningCapability(id, rawMeta) {
|
|
176
|
+
if (!id)
|
|
177
|
+
return false;
|
|
178
|
+
const r = rawMeta ?? {};
|
|
179
|
+
const modalities = strArrMeta(r.modalities) ?? strArrMeta(r.input_modalities);
|
|
180
|
+
if (boolMeta(r.reasoning) === true ||
|
|
181
|
+
boolMeta(r.supports_reasoning) === true ||
|
|
182
|
+
modalities?.includes("reasoning") === true) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
const lower = id.toLowerCase();
|
|
186
|
+
const REASONING_PATTERNS = [
|
|
187
|
+
/thinking|reasoner|reasoning/i,
|
|
188
|
+
/(?:^|[-_/])o[134](?:[-_](?:mini|preview|high|low|medium|max))?(?:[-_/]|$)/i,
|
|
189
|
+
/(?:^|[-_/])(?:deepseek[-_])?r1(?:[-_/]|$)/i,
|
|
190
|
+
/(?:^|[-_/])qwq(?:[-_]\d+b)?(?:[-_/]|$)/i,
|
|
191
|
+
/(?:^|[-_/])(?:glm[-_]4[-_]?zero|glm[-_]?zero)(?:[-_/]|$)/i,
|
|
192
|
+
/(?:^|[-_/])cot(?:[-_/]|$)/i,
|
|
193
|
+
];
|
|
194
|
+
return REASONING_PATTERNS.some((pattern) => pattern.test(lower));
|
|
195
|
+
}
|
|
206
196
|
/** Best-effort extraction of model metadata from an OpenAI-compatible
|
|
207
197
|
* /models `data[]` item. Most endpoints only return `{ id }` — the extra
|
|
208
198
|
* fields (context_window / max_model_len / modalities / supports_vision /
|
|
@@ -218,13 +208,9 @@ function parseOpenAiModel(m) {
|
|
|
218
208
|
boolMeta(r.supports_vision) === true ||
|
|
219
209
|
boolMeta(r.vision) === true ||
|
|
220
210
|
strArrMeta(r.input)?.includes("image") === true;
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
const reasoning = boolMeta(r.reasoning) === true ||
|
|
225
|
-
boolMeta(r.supports_reasoning) === true ||
|
|
226
|
-
modalities?.includes("reasoning") === true ||
|
|
227
|
-
id.toLowerCase().includes("thinking");
|
|
211
|
+
// 名字与元数据兜底:端点未提供 reasoning 时通过通用推理模型特征推断。
|
|
212
|
+
// 只增不减:取消勾选靠手填(编辑页/刷新合并都只补缺)。
|
|
213
|
+
const reasoning = detectReasoningCapability(id, r);
|
|
228
214
|
const contextWindow = numMeta(r.context_window) ?? numMeta(r.context_length) ?? numMeta(r.max_model_len) ?? numMeta(r.max_context_length);
|
|
229
215
|
const maxTokens = numMeta(r.max_tokens) ?? numMeta(r.max_output_tokens) ?? numMeta(r.max_completion_tokens);
|
|
230
216
|
return {
|
|
@@ -244,8 +230,8 @@ function parseGoogleModel(m) {
|
|
|
244
230
|
const rawName = typeof r.name === "string" ? r.name : "";
|
|
245
231
|
const id = rawName.replace(/^models\//, "");
|
|
246
232
|
const displayName = typeof r.displayName === "string" ? r.displayName : undefined;
|
|
247
|
-
// 与 OpenAI
|
|
248
|
-
const reasoning = id
|
|
233
|
+
// 与 OpenAI 形状同口径的推断兜底(见 detectReasoningCapability)。
|
|
234
|
+
const reasoning = detectReasoningCapability(id, r);
|
|
249
235
|
return {
|
|
250
236
|
id,
|
|
251
237
|
...(displayName && displayName !== id ? { name: displayName } : {}),
|
|
@@ -532,7 +518,17 @@ export class ModelAdminService {
|
|
|
532
518
|
catch {
|
|
533
519
|
// runtime not ready
|
|
534
520
|
}
|
|
535
|
-
for (const id of [
|
|
521
|
+
for (const id of [
|
|
522
|
+
"anthropic",
|
|
523
|
+
"openai",
|
|
524
|
+
"google",
|
|
525
|
+
"deepseek",
|
|
526
|
+
"groq",
|
|
527
|
+
"mistral",
|
|
528
|
+
"openrouter",
|
|
529
|
+
"ollama",
|
|
530
|
+
"llama.cpp",
|
|
531
|
+
]) {
|
|
536
532
|
ids.add(id);
|
|
537
533
|
}
|
|
538
534
|
return [...ids];
|
|
@@ -547,7 +543,18 @@ export class ModelAdminService {
|
|
|
547
543
|
catch {
|
|
548
544
|
// no file yet / unparsable — start fresh
|
|
549
545
|
}
|
|
550
|
-
|
|
546
|
+
if (pid === "llama.cpp") {
|
|
547
|
+
const prevLlama = (data[pid] ?? {});
|
|
548
|
+
const baseUrl = prevLlama.env?.LLAMA_BASE_URL || process.env.LLAMA_BASE_URL || "http://127.0.0.1:8080";
|
|
549
|
+
data[pid] = {
|
|
550
|
+
type: "api_key",
|
|
551
|
+
key: apiKey || "local",
|
|
552
|
+
env: { LLAMA_BASE_URL: baseUrl },
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
data[pid] = { type: "api_key", key: apiKey };
|
|
557
|
+
}
|
|
551
558
|
atomicWriteCredentialJson(authPath, data);
|
|
552
559
|
try {
|
|
553
560
|
chmodSync(this.providerKeysPath(), CREDENTIAL_FILE_MODE);
|
|
@@ -1183,6 +1190,7 @@ export class ModelAdminService {
|
|
|
1183
1190
|
{ id: "groq", name: "Groq" },
|
|
1184
1191
|
{ id: "mistral", name: "Mistral" },
|
|
1185
1192
|
{ id: "ollama", name: "Ollama" },
|
|
1193
|
+
{ id: "llama.cpp", name: "llama.cpp" },
|
|
1186
1194
|
];
|
|
1187
1195
|
const allIds = new Set();
|
|
1188
1196
|
providers = [];
|
|
@@ -1193,7 +1201,8 @@ export class ModelAdminService {
|
|
|
1193
1201
|
(b.id === "deepseek" && process.env.DEEPSEEK_API_KEY) ||
|
|
1194
1202
|
(b.id === "openai" && process.env.OPENAI_API_KEY) ||
|
|
1195
1203
|
(b.id === "openrouter" && process.env.OPENROUTER_API_KEY) ||
|
|
1196
|
-
(b.id === "google" && (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY))
|
|
1204
|
+
(b.id === "google" && (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY)) ||
|
|
1205
|
+
(b.id === "llama.cpp" && process.env.LLAMA_BASE_URL));
|
|
1197
1206
|
providers.push({
|
|
1198
1207
|
id: b.id,
|
|
1199
1208
|
name: b.name,
|
|
@@ -1237,49 +1246,6 @@ export class ModelAdminService {
|
|
|
1237
1246
|
modelsConfigPath() {
|
|
1238
1247
|
return join(this.host.agentDir, "models.json");
|
|
1239
1248
|
}
|
|
1240
|
-
/** Strip // and /* *\/ comments without touching string literals (URLs contain //). */
|
|
1241
|
-
static stripJsonComments(src) {
|
|
1242
|
-
let out = "";
|
|
1243
|
-
let inString = false;
|
|
1244
|
-
let i = 0;
|
|
1245
|
-
while (i < src.length) {
|
|
1246
|
-
const c = src[i];
|
|
1247
|
-
const next = src[i + 1];
|
|
1248
|
-
if (inString) {
|
|
1249
|
-
out += c;
|
|
1250
|
-
if (c === "\\") {
|
|
1251
|
-
out += next ?? "";
|
|
1252
|
-
i += 2;
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
if (c === '"')
|
|
1256
|
-
inString = false;
|
|
1257
|
-
i++;
|
|
1258
|
-
continue;
|
|
1259
|
-
}
|
|
1260
|
-
if (c === '"') {
|
|
1261
|
-
inString = true;
|
|
1262
|
-
out += c;
|
|
1263
|
-
i++;
|
|
1264
|
-
continue;
|
|
1265
|
-
}
|
|
1266
|
-
if (c === "/" && next === "/") {
|
|
1267
|
-
while (i < src.length && src[i] !== "\n")
|
|
1268
|
-
i++;
|
|
1269
|
-
continue;
|
|
1270
|
-
}
|
|
1271
|
-
if (c === "/" && next === "*") {
|
|
1272
|
-
i += 2;
|
|
1273
|
-
while (i < src.length && !(src[i] === "*" && src[i + 1] === "/"))
|
|
1274
|
-
i++;
|
|
1275
|
-
i += 2;
|
|
1276
|
-
continue;
|
|
1277
|
-
}
|
|
1278
|
-
out += c;
|
|
1279
|
-
i++;
|
|
1280
|
-
}
|
|
1281
|
-
return out;
|
|
1282
|
-
}
|
|
1283
1249
|
/** Read + parse models.json (tolerating // and /* *\/ comments like the SDK). */
|
|
1284
1250
|
readModelsConfig() {
|
|
1285
1251
|
const path = this.modelsConfigPath();
|
|
@@ -1371,12 +1337,8 @@ export class ModelAdminService {
|
|
|
1371
1337
|
boolMeta(r.supports_vision) === true ||
|
|
1372
1338
|
boolMeta(r.vision) === true ||
|
|
1373
1339
|
strArrMeta(r.input)?.includes("image") === true;
|
|
1374
|
-
//
|
|
1375
|
-
|
|
1376
|
-
const reasoning = boolMeta(r.reasoning) === true ||
|
|
1377
|
-
boolMeta(r.supports_reasoning) === true ||
|
|
1378
|
-
modalities?.includes("reasoning") === true ||
|
|
1379
|
-
id.toLowerCase().includes("thinking");
|
|
1340
|
+
// 名字与元数据兜底:端点未提供 reasoning 时通过通用推理模型特征推断。
|
|
1341
|
+
const reasoning = detectReasoningCapability(id, r);
|
|
1380
1342
|
const contextWindow = numMeta(r.context_window) ??
|
|
1381
1343
|
numMeta(r.context_length) ??
|
|
1382
1344
|
numMeta(r.max_model_len) ??
|
|
@@ -1399,8 +1361,8 @@ export class ModelAdminService {
|
|
|
1399
1361
|
const rawName = typeof r.name === "string" ? r.name : "";
|
|
1400
1362
|
const id = rawName.replace(/^models\//, "");
|
|
1401
1363
|
const displayName = typeof r.displayName === "string" ? r.displayName : undefined;
|
|
1402
|
-
// 与 OpenAI
|
|
1403
|
-
const reasoning = id
|
|
1364
|
+
// 与 OpenAI 形状同口径的推断兜底(见 detectReasoningCapability)。
|
|
1365
|
+
const reasoning = detectReasoningCapability(id, r);
|
|
1404
1366
|
return {
|
|
1405
1367
|
id,
|
|
1406
1368
|
...(displayName && displayName !== id ? { name: displayName } : {}),
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* 供 Claude Code CLI 驱动、DSH 引擎与 Pi 引擎统一调用,消除各引擎间的配置孤岛。
|
|
12
12
|
*/
|
|
13
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
function defaultAgentDir(agentDir) {
|
|
@@ -18,49 +18,8 @@ function defaultAgentDir(agentDir) {
|
|
|
18
18
|
? agentDir.trim()
|
|
19
19
|
: (process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent"));
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
let out = "";
|
|
24
|
-
let inString = false;
|
|
25
|
-
let i = 0;
|
|
26
|
-
while (i < src.length) {
|
|
27
|
-
const c = src[i];
|
|
28
|
-
const next = src[i + 1];
|
|
29
|
-
if (inString) {
|
|
30
|
-
out += c;
|
|
31
|
-
if (c === "\\") {
|
|
32
|
-
out += next ?? "";
|
|
33
|
-
i += 2;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (c === '"')
|
|
37
|
-
inString = false;
|
|
38
|
-
i++;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (c === '"') {
|
|
42
|
-
inString = true;
|
|
43
|
-
out += c;
|
|
44
|
-
i++;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (c === "/" && next === "/") {
|
|
48
|
-
while (i < src.length && src[i] !== "\n")
|
|
49
|
-
i++;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (c === "/" && next === "*") {
|
|
53
|
-
i += 2;
|
|
54
|
-
while (i < src.length && !(src[i] === "*" && src[i + 1] === "/"))
|
|
55
|
-
i++;
|
|
56
|
-
i += 2;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
out += c;
|
|
60
|
-
i++;
|
|
61
|
-
}
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
21
|
+
import { stripJsonComments, parseJsonWithComments } from "./json-utils.js";
|
|
22
|
+
export { stripJsonComments, parseJsonWithComments };
|
|
64
23
|
/** 读取并解析 models.json(容忍注释) */
|
|
65
24
|
export function readModelsJson(agentDir) {
|
|
66
25
|
const dir = defaultAgentDir(agentDir);
|
|
@@ -301,6 +260,69 @@ export function isProtocolSupportedByEngine(engine, api, providerId, modelId) {
|
|
|
301
260
|
}
|
|
302
261
|
return true;
|
|
303
262
|
}
|
|
263
|
+
/** 读取全局 settings.json */
|
|
264
|
+
export function readGlobalSettings(agentDir) {
|
|
265
|
+
const dir = defaultAgentDir(agentDir);
|
|
266
|
+
const filePath = join(dir, "settings.json");
|
|
267
|
+
if (!existsSync(filePath))
|
|
268
|
+
return {};
|
|
269
|
+
try {
|
|
270
|
+
const raw = readFileSync(filePath, "utf8");
|
|
271
|
+
return JSON.parse(stripJsonComments(raw));
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/** 获取特定模型在 settings.json 中的思考强度记忆或全局默认思考强度 */
|
|
278
|
+
export function getModelThinkingLevelFromSettings(modelId, agentDir) {
|
|
279
|
+
if (!modelId)
|
|
280
|
+
return undefined;
|
|
281
|
+
const settings = readGlobalSettings(agentDir);
|
|
282
|
+
const levels = settings.modelThinkingLevels;
|
|
283
|
+
if (levels && typeof levels === "object") {
|
|
284
|
+
// 1. 尝试全量匹配 "provider/model"
|
|
285
|
+
if (levels[modelId])
|
|
286
|
+
return levels[modelId];
|
|
287
|
+
// 2. 尝试裸 modelId 匹配
|
|
288
|
+
const slashIdx = modelId.indexOf("/");
|
|
289
|
+
const bareId = slashIdx >= 0 ? modelId.slice(slashIdx + 1) : modelId;
|
|
290
|
+
for (const [k, v] of Object.entries(levels)) {
|
|
291
|
+
if (k === bareId || k.endsWith(`/${bareId}`)) {
|
|
292
|
+
return v;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return settings.defaultThinkingLevel;
|
|
297
|
+
}
|
|
298
|
+
/** 保存特定模型的思考强度到 settings.json */
|
|
299
|
+
export function saveModelThinkingLevelToSettings(modelId, level, agentDir) {
|
|
300
|
+
if (!modelId || !level)
|
|
301
|
+
return;
|
|
302
|
+
const dir = defaultAgentDir(agentDir);
|
|
303
|
+
const filePath = join(dir, "settings.json");
|
|
304
|
+
try {
|
|
305
|
+
let current = {};
|
|
306
|
+
if (existsSync(filePath)) {
|
|
307
|
+
try {
|
|
308
|
+
current = JSON.parse(stripJsonComments(readFileSync(filePath, "utf8")));
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
/* start fresh */
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const existingLevels = (current.modelThinkingLevels && typeof current.modelThinkingLevels === "object"
|
|
315
|
+
? { ...current.modelThinkingLevels }
|
|
316
|
+
: {});
|
|
317
|
+
existingLevels[modelId] = level;
|
|
318
|
+
current.modelThinkingLevels = existingLevels;
|
|
319
|
+
const formatted = JSON.stringify(current, null, 2);
|
|
320
|
+
writeFileSync(filePath, formatted, "utf8");
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
/* best effort */
|
|
324
|
+
}
|
|
325
|
+
}
|
|
304
326
|
/**
|
|
305
327
|
* 结构化入参的协议校验重载包装(兼容既有调用点)。
|
|
306
328
|
*/
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* - 运行时缓存(plansByConv):以会话槽位 conversationId 为主键,仅存活于进程内存,绝不落盘。
|
|
18
18
|
* - 历史文件清洗:严格过滤形如 /^c\d+$/ 的易变短 ID,防止服务重启后新会话被上一个会话的任务附体。
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { writeJsonAtomicSync } from "./atomic-file.js";
|
|
22
22
|
const VALID_STATUSES = new Set(["pending", "in_progress", "done", "failed"]);
|
|
23
23
|
/** 判断是否为易变的临时 conversationId(如 c1, c2, c99 等)。此类短 ID 绝不入持久化文件。 */
|
|
24
24
|
function isEphemeralConvId(id) {
|
|
@@ -61,7 +61,6 @@ export class PlanManager {
|
|
|
61
61
|
if (!this.filePath)
|
|
62
62
|
return;
|
|
63
63
|
try {
|
|
64
|
-
mkdirSync(dirname(this.filePath), { recursive: true });
|
|
65
64
|
const obj = {};
|
|
66
65
|
for (const [k, v] of this.plansBySession.entries()) {
|
|
67
66
|
// 双重防护:临时 conversationId 绝不落盘
|
|
@@ -69,9 +68,7 @@ export class PlanManager {
|
|
|
69
68
|
continue;
|
|
70
69
|
obj[k] = v;
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
writeFileSync(tmp, JSON.stringify(obj, null, 2), "utf8");
|
|
74
|
-
renameSync(tmp, this.filePath);
|
|
71
|
+
writeJsonAtomicSync(this.filePath, obj);
|
|
75
72
|
}
|
|
76
73
|
catch {
|
|
77
74
|
// 持久化失败绝不阻断主流程
|
|
@@ -14,6 +14,7 @@ export const SLOT_EXAMPLES = {
|
|
|
14
14
|
"contextmenu.project": `{ "ui": { "contextmenu.project": [{ "id": "m", "label": "项目菜单", "kind": "action", "action": "my:m" }] } }`,
|
|
15
15
|
"contextmenu.file": `{ "contextmenu.file": [{ "id": "mail", "label": "发到邮箱", "kind": "action", "action": "my:send" }] }`,
|
|
16
16
|
"contextmenu.toolcall": `{ "ui": { "contextmenu.toolcall": [{ "id": "m", "label": "工具菜单", "kind": "action", "action": "my:m" }] } }`,
|
|
17
|
+
"tool.card.footer": `{ "ui": { "tool.card.footer": [{ "id": "m", "label": "工具卡底部", "kind": "action", "action": "my:m" }] } }`,
|
|
17
18
|
"settings.pages": `{ "settings": [{ "id": "conf", "label": "邮箱设置", "kind": "page" }] }`,
|
|
18
19
|
"tasks.panel": `{ "ui": { "tasks.panel": [{ "id": "pm2", "label": "pm2 托管的应用", "kind": "view" }] } }`,
|
|
19
20
|
"leftpanel.projects.actions": `{ "ui": { "leftpanel.projects.actions": [{ "id": "m", "label": "项目标题按钮", "kind": "action", "action": "my:m" }] } }`,
|