pi-web-ui 0.111.0 → 0.113.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 +92 -2
- package/bin/frp-manager.mjs +9 -2
- package/bin/pi-web-ui.mjs +325 -45
- package/dist/server/agent-service-daemon.js +29 -4
- package/dist/server/agent-service.js +1527 -510
- 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 +8 -0
- package/dist/server/canvas/canvas-orchestrator.js +128 -22
- package/dist/server/canvas/pstack-skills-data.js +498 -0
- 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 +39 -11
- package/dist/server/dsh/dsh-agent-service.js +294 -15
- package/dist/server/dsh/dsh-serialize.js +1 -1
- package/dist/server/durable/durable-driver.js +112 -107
- package/dist/server/durable/durable-event-projector.js +253 -0
- 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 +111 -48
- package/dist/server/eval-tool.js +28 -3
- package/dist/server/goal-service.js +7 -0
- package/dist/server/index.js +371 -57
- 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 +247 -163
- 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 +209 -11
- 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/remote-ssh-service.js +110 -12
- package/dist/server/sdk-builtin-extensions.js +85 -0
- package/dist/server/serialize.js +1 -1
- 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 +74 -53
- package/dist/server/setup-page.js +632 -0
- package/dist/server/skill-discovery.js +361 -59
- package/dist/server/skill-maintenance.js +231 -0
- package/dist/server/skill-tool.js +32 -3
- package/dist/server/soft-cap.js +30 -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 +390 -48
- 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 +48 -10
- package/dist/server/tool-manager.js +106 -28
- 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 +116 -7
- 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 +106 -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 +21 -0
- package/web/dist/assets/{TerminalPanel-BiUNySMA.js → TerminalPanel-3wojLfLk.js} +2 -2
- package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
- package/web/dist/assets/index-BwL7qBh6.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
|
@@ -93,7 +93,7 @@ const DSH_PRICE_INPUT = 0.14;
|
|
|
93
93
|
const DSH_PRICE_CACHE_READ = 0.0028;
|
|
94
94
|
const DSH_PRICE_OUTPUT = 0.28;
|
|
95
95
|
/** 会话 root:<dataDir>/dsh-sessions(与 pi 引擎的会话目录隔离)。 */
|
|
96
|
-
|
|
96
|
+
function dshSessionRoot(dataDir) {
|
|
97
97
|
return join(dataDir, "dsh-sessions");
|
|
98
98
|
}
|
|
99
99
|
function estimateCost(t) {
|
|
@@ -107,7 +107,7 @@ function estimateCost(t) {
|
|
|
107
107
|
/** 把插件工具 execute 的原始返回值归一化成模型可读文本。
|
|
108
108
|
* 兼容:`{content:[{type:"text",text}...],details}` → text 拼接;string → 原串;
|
|
109
109
|
* 其它对象 → JSON.stringify;null/undefined → 空串。 */
|
|
110
|
-
|
|
110
|
+
function normalizeToolResult(result) {
|
|
111
111
|
if (typeof result === "string")
|
|
112
112
|
return result;
|
|
113
113
|
if (result === null || result === undefined)
|
|
@@ -164,6 +164,7 @@ const DEFAULT_SETTINGS = {
|
|
|
164
164
|
preserveDraftAcrossConversations: false,
|
|
165
165
|
promptTemplate: "",
|
|
166
166
|
promptOverrides: {},
|
|
167
|
+
promptDisabled: [],
|
|
167
168
|
};
|
|
168
169
|
// ---------------------------------------------------------------------------
|
|
169
170
|
// DshClientSession — 一个浏览器客户端
|
|
@@ -179,6 +180,8 @@ export class DshClientSession {
|
|
|
179
180
|
dataDir;
|
|
180
181
|
/** pi 配置目录(auth.json 所在;尊重 PI_CODING_AGENT_DIR)。 */
|
|
181
182
|
agentDir;
|
|
183
|
+
/** 用户直接创建的交互式终端(按 CLIENT/工作区 存活,始终显示,不受单个对话切换、生命周期与过滤影响) */
|
|
184
|
+
userTerminals;
|
|
182
185
|
runtime;
|
|
183
186
|
convs = new Map();
|
|
184
187
|
activeId = "";
|
|
@@ -312,6 +315,13 @@ export class DshClientSession {
|
|
|
312
315
|
},
|
|
313
316
|
lang: () => this.getLang(),
|
|
314
317
|
});
|
|
318
|
+
this.userTerminals = new TerminalManager((msg) => {
|
|
319
|
+
if (msg.type === "terminal_list") {
|
|
320
|
+
this.pushTerminals();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
this.emit(msg);
|
|
324
|
+
}, this.cwd, () => this.getLang());
|
|
315
325
|
}
|
|
316
326
|
static create(clientId, cwd, stateStore, dataDir, agentDir) {
|
|
317
327
|
const cs = new DshClientSession(clientId, cwd, stateStore, dataDir, agentDir ?? join(homedir(), ".pi", "agent"));
|
|
@@ -365,6 +375,7 @@ export class DshClientSession {
|
|
|
365
375
|
preserveDraftAcrossConversations: savedSettings.preserveDraftAcrossConversations ?? false,
|
|
366
376
|
promptTemplate: savedSettings.promptTemplate ?? "",
|
|
367
377
|
promptOverrides: savedSettings.promptOverrides ?? {},
|
|
378
|
+
promptDisabled: savedSettings.promptDisabled ?? [],
|
|
368
379
|
defaultAgentPreset: savedSettings.defaultAgentPreset ?? PRESET_DEFAULT_ID,
|
|
369
380
|
defaultPermissionPreset: savedSettings.defaultPermissionPreset && PERMISSION_OFFERED.includes(savedSettings.defaultPermissionPreset)
|
|
370
381
|
? savedSettings.defaultPermissionPreset
|
|
@@ -554,17 +565,23 @@ export class DshClientSession {
|
|
|
554
565
|
const cutoff = Date.now() - DshClientSession.SESSION_RETENTION_MS;
|
|
555
566
|
try {
|
|
556
567
|
const { readdirSync, rmSync } = await import("node:fs");
|
|
557
|
-
const dirLastModified = (dir) => {
|
|
568
|
+
const dirLastModified = (dir, cutoffMs) => {
|
|
558
569
|
let max = 0;
|
|
559
570
|
try {
|
|
560
571
|
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
561
572
|
const p = join(dir, e.name);
|
|
562
573
|
try {
|
|
563
574
|
if (e.isDirectory()) {
|
|
564
|
-
|
|
575
|
+
const subMax = dirLastModified(p, cutoffMs);
|
|
576
|
+
if (subMax >= cutoffMs)
|
|
577
|
+
return subMax;
|
|
578
|
+
max = Math.max(max, subMax);
|
|
565
579
|
}
|
|
566
580
|
else {
|
|
567
|
-
|
|
581
|
+
const m = statSync(p).mtimeMs;
|
|
582
|
+
if (m >= cutoffMs)
|
|
583
|
+
return m;
|
|
584
|
+
max = Math.max(max, m);
|
|
568
585
|
}
|
|
569
586
|
}
|
|
570
587
|
catch {
|
|
@@ -590,9 +607,10 @@ export class DshClientSession {
|
|
|
590
607
|
const p = join(dir, e.name);
|
|
591
608
|
if (!e.isDirectory())
|
|
592
609
|
continue;
|
|
593
|
-
|
|
610
|
+
const lastMod = dirLastModified(p, cutoff);
|
|
611
|
+
if (lastMod === 0)
|
|
594
612
|
continue; // 空目录不删
|
|
595
|
-
if (
|
|
613
|
+
if (lastMod < cutoff) {
|
|
596
614
|
rmSync(p, { recursive: true, force: true });
|
|
597
615
|
removed++;
|
|
598
616
|
}
|
|
@@ -1490,12 +1508,50 @@ export class DshClientSession {
|
|
|
1490
1508
|
this.emit({ type: "notice", level, text, textEn });
|
|
1491
1509
|
}
|
|
1492
1510
|
pushTerminals() {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1511
|
+
const userList = this.userTerminals ? this.userTerminals.list() : [];
|
|
1512
|
+
const activeConv = this.convs.get(this.activeId) ?? this.conv;
|
|
1513
|
+
const convList = activeConv ? activeConv.terminals.list() : [];
|
|
1514
|
+
const allTerminals = [...userList, ...convList];
|
|
1515
|
+
this.emit({ type: "terminal_list", conversationId: activeConv?.id, terminals: allTerminals });
|
|
1516
|
+
if (this.userTerminals) {
|
|
1517
|
+
for (const output of this.userTerminals.replay()) {
|
|
1518
|
+
this.emit({
|
|
1519
|
+
type: "terminal_output",
|
|
1520
|
+
conversationId: activeConv?.id,
|
|
1521
|
+
terminalId: output.terminalId,
|
|
1522
|
+
data: output.data,
|
|
1523
|
+
});
|
|
1497
1524
|
}
|
|
1498
1525
|
}
|
|
1526
|
+
if (activeConv) {
|
|
1527
|
+
for (const output of activeConv.terminals.replay()) {
|
|
1528
|
+
this.emit({
|
|
1529
|
+
type: "terminal_output",
|
|
1530
|
+
conversationId: activeConv.id,
|
|
1531
|
+
terminalId: output.terminalId,
|
|
1532
|
+
data: output.data,
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
getUserTerminalManager() {
|
|
1538
|
+
return this.userTerminals;
|
|
1539
|
+
}
|
|
1540
|
+
findTerminalManager(terminalId, conversationId) {
|
|
1541
|
+
if (this.userTerminals?.has(terminalId))
|
|
1542
|
+
return this.userTerminals;
|
|
1543
|
+
if (conversationId) {
|
|
1544
|
+
const convTm = this.convs.get(conversationId)?.terminals;
|
|
1545
|
+
if (convTm?.has(terminalId))
|
|
1546
|
+
return convTm;
|
|
1547
|
+
}
|
|
1548
|
+
if (this.conv?.terminals.has(terminalId))
|
|
1549
|
+
return this.conv.terminals;
|
|
1550
|
+
for (const conv of this.convs.values()) {
|
|
1551
|
+
if (conv.terminals.has(terminalId))
|
|
1552
|
+
return conv.terminals;
|
|
1553
|
+
}
|
|
1554
|
+
return this.getTerminalManager(conversationId);
|
|
1499
1555
|
}
|
|
1500
1556
|
getTerminalManager(conversationId) {
|
|
1501
1557
|
return (conversationId ? this.convs.get(conversationId) : this.conv)?.terminals;
|
|
@@ -1579,6 +1635,7 @@ export class DshClientSession {
|
|
|
1579
1635
|
isStreaming: conv.isStreaming,
|
|
1580
1636
|
isSubagent: false,
|
|
1581
1637
|
pinned: isPinned,
|
|
1638
|
+
...(conv.terminals.countUserBlockingLive() > 0 ? { hasUserTerminals: true } : {}),
|
|
1582
1639
|
// DSH Agent 预设(左栏徽标/详情用;pi 引擎不填)。
|
|
1583
1640
|
agentPreset: conv.agentPreset,
|
|
1584
1641
|
presetLocked: conv.presetLocked,
|
|
@@ -1808,7 +1865,7 @@ export class DshClientSession {
|
|
|
1808
1865
|
* cancel). `index` is the clicked bubble's position (duplicate texts need
|
|
1809
1866
|
* it); mismatch or omission falls back to first-occurrence text match.
|
|
1810
1867
|
*/
|
|
1811
|
-
removeQueued(kind, text, index) {
|
|
1868
|
+
removeQueued(kind, text, index, _id) {
|
|
1812
1869
|
const conv = this.conv;
|
|
1813
1870
|
const arr = kind === "steer" ? conv.queue.steering : conv.queue.followUp;
|
|
1814
1871
|
const next = removeQueuedByIndexOrText(arr, text, index);
|
|
@@ -1863,6 +1920,8 @@ export class DshClientSession {
|
|
|
1863
1920
|
async promptConv(conv, text, attachments, _queue = false,
|
|
1864
1921
|
// issue #145 同项目并行提醒:只进运行时上下文,不进用户气泡。
|
|
1865
1922
|
sysPrefix = "") {
|
|
1923
|
+
let optimisticId;
|
|
1924
|
+
let followUpAdded = false;
|
|
1866
1925
|
try {
|
|
1867
1926
|
if (this.quiesceBlocked())
|
|
1868
1927
|
return;
|
|
@@ -1913,14 +1972,19 @@ export class DshClientSession {
|
|
|
1913
1972
|
.filter((q) => q !== null),
|
|
1914
1973
|
},
|
|
1915
1974
|
};
|
|
1975
|
+
optimisticId = optimistic.id;
|
|
1916
1976
|
this.appendMessage(conv, optimistic);
|
|
1917
1977
|
if (conv.isStreaming) {
|
|
1918
1978
|
// DSH 无 mid-run steering:isStreaming 时入队(followUp),
|
|
1919
1979
|
// 运行时 inbox 在 run 结束后消费。入队后立即 flushSnapshot 让排队气泡上屏。
|
|
1920
1980
|
conv.queue.followUp.push(text);
|
|
1981
|
+
followUpAdded = true;
|
|
1921
1982
|
this.flushSnapshot();
|
|
1922
1983
|
await this.runtime.prompt(conv.sessionId, blocks);
|
|
1923
|
-
|
|
1984
|
+
const qIdx = conv.queue.followUp.indexOf(text);
|
|
1985
|
+
if (qIdx !== -1)
|
|
1986
|
+
conv.queue.followUp.splice(qIdx, 1);
|
|
1987
|
+
followUpAdded = false;
|
|
1924
1988
|
}
|
|
1925
1989
|
else {
|
|
1926
1990
|
this.flushSnapshot();
|
|
@@ -1933,6 +1997,19 @@ export class DshClientSession {
|
|
|
1933
1997
|
}
|
|
1934
1998
|
}
|
|
1935
1999
|
catch (err) {
|
|
2000
|
+
// 发送失败事务补偿:回滚乐观用户消息与排队气泡
|
|
2001
|
+
if (optimisticId) {
|
|
2002
|
+
const optIdx = conv.messages.findIndex((m) => m.id === optimisticId);
|
|
2003
|
+
if (optIdx !== -1) {
|
|
2004
|
+
conv.messages.splice(optIdx, 1);
|
|
2005
|
+
conv.messageIds.delete(optimisticId);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
if (followUpAdded) {
|
|
2009
|
+
const qIdx = conv.queue.followUp.indexOf(text);
|
|
2010
|
+
if (qIdx !== -1)
|
|
2011
|
+
conv.queue.followUp.splice(qIdx, 1);
|
|
2012
|
+
}
|
|
1936
2013
|
this.emit({
|
|
1937
2014
|
type: "notice",
|
|
1938
2015
|
level: "error",
|
|
@@ -2509,8 +2586,8 @@ export class DshClientSession {
|
|
|
2509
2586
|
this.emit({
|
|
2510
2587
|
type: "notice",
|
|
2511
2588
|
level: "warning",
|
|
2512
|
-
text: `对话「${conv.title}
|
|
2513
|
-
textEn: `Conversation "${conv.title}" still has open terminals — close them
|
|
2589
|
+
text: `对话「${conv.title}」还有未关闭的终端,请先关闭终端或右键选择「强行关闭」后再移出`,
|
|
2590
|
+
textEn: `Conversation "${conv.title}" still has open terminals — close them or right-click to force-dismiss`,
|
|
2514
2591
|
});
|
|
2515
2592
|
return;
|
|
2516
2593
|
}
|
|
@@ -3659,6 +3736,7 @@ export class DshClientSession {
|
|
|
3659
3736
|
uiLayout: normalizeUiLayout(this.settings.uiLayout),
|
|
3660
3737
|
promptTemplate: this.settings.promptTemplate ?? "",
|
|
3661
3738
|
promptOverrides: this.settings.promptOverrides ?? {},
|
|
3739
|
+
promptDisabled: [...(this.settings.promptDisabled ?? [])],
|
|
3662
3740
|
// DSH 无 pi 工具注册表面,逐工具文案覆盖不适用;保协议完整。
|
|
3663
3741
|
toolPromptOverrides: {},
|
|
3664
3742
|
effectiveSystemPrompt,
|
|
@@ -3699,6 +3777,8 @@ export class DshClientSession {
|
|
|
3699
3777
|
this.settings.promptTemplate = partial.promptTemplate;
|
|
3700
3778
|
if (partial.promptOverrides !== undefined)
|
|
3701
3779
|
this.settings.promptOverrides = partial.promptOverrides;
|
|
3780
|
+
if (partial.promptDisabled !== undefined)
|
|
3781
|
+
this.settings.promptDisabled = [...partial.promptDisabled];
|
|
3702
3782
|
if (partial.disabledSkills !== undefined)
|
|
3703
3783
|
this.settings.disabledSkills = partial.disabledSkills;
|
|
3704
3784
|
if (partial.disabledExtensions !== undefined)
|
|
@@ -3801,6 +3881,7 @@ export class DshClientSession {
|
|
|
3801
3881
|
defaultAgentPreset: this.settings.defaultAgentPreset,
|
|
3802
3882
|
promptTemplate: this.settings.promptTemplate ?? "",
|
|
3803
3883
|
promptOverrides: this.settings.promptOverrides ?? {},
|
|
3884
|
+
promptDisabled: [...(this.settings.promptDisabled ?? [])],
|
|
3804
3885
|
});
|
|
3805
3886
|
// 仅系统提示词或内联标记指引变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
|
|
3806
3887
|
// 其他设置(开关/隐藏插件等)只存不回写运行时。
|
|
@@ -4154,6 +4235,7 @@ export class DshClientSession {
|
|
|
4154
4235
|
customSystemPrompt: this.settings.customSystemPrompt,
|
|
4155
4236
|
promptTemplate: "",
|
|
4156
4237
|
promptOverrides: {},
|
|
4238
|
+
promptDisabled: [],
|
|
4157
4239
|
disabledSkills: this.settings.disabledSkills,
|
|
4158
4240
|
disabledExtensions: this.settings.disabledExtensions,
|
|
4159
4241
|
// DSH engine: no unified tool gating (no subagent/edit_soft); empty keeps protocol complete.
|
|
@@ -4255,6 +4337,7 @@ export class DshClientSession {
|
|
|
4255
4337
|
customSystemPrompt: s.customSystemPrompt,
|
|
4256
4338
|
promptTemplate: "",
|
|
4257
4339
|
promptOverrides: {},
|
|
4340
|
+
promptDisabled: [],
|
|
4258
4341
|
disabledSkills: [...(s.disabledSkills ?? [])],
|
|
4259
4342
|
disabledExtensions: [...(s.disabledExtensions ?? [])],
|
|
4260
4343
|
disabledAgentTools: [],
|
|
@@ -5306,6 +5389,7 @@ export class DshClientSession {
|
|
|
5306
5389
|
this.modelAdmin.dispose();
|
|
5307
5390
|
for (const conv of this.convs.values())
|
|
5308
5391
|
conv.terminals.killAll();
|
|
5392
|
+
this.userTerminals?.killAll();
|
|
5309
5393
|
try {
|
|
5310
5394
|
await this.runtime.close();
|
|
5311
5395
|
}
|
|
@@ -5313,6 +5397,146 @@ export class DshClientSession {
|
|
|
5313
5397
|
/* ignore */
|
|
5314
5398
|
}
|
|
5315
5399
|
}
|
|
5400
|
+
// -----------------------------------------------------------------------
|
|
5401
|
+
// 插件扩展点(与 pi 引擎的 *ForPlugins 对齐)
|
|
5402
|
+
// -----------------------------------------------------------------------
|
|
5403
|
+
activeConversationId() {
|
|
5404
|
+
return this.activeId;
|
|
5405
|
+
}
|
|
5406
|
+
readConversationForPlugins(opts) {
|
|
5407
|
+
if (opts?.clientId && opts.clientId !== this.clientId)
|
|
5408
|
+
return null;
|
|
5409
|
+
const conv = this.convs.get(this.activeId) ?? [...this.convs.values()][0];
|
|
5410
|
+
if (!conv)
|
|
5411
|
+
return null;
|
|
5412
|
+
return {
|
|
5413
|
+
clientId: this.clientId,
|
|
5414
|
+
conversationId: conv.id,
|
|
5415
|
+
isSubagent: false,
|
|
5416
|
+
sessionId: conv.sessionId,
|
|
5417
|
+
sessionFile: conv.sessionFile,
|
|
5418
|
+
title: conv.title,
|
|
5419
|
+
model: `${this.modelProvider}/${this.model}`,
|
|
5420
|
+
at: conv.lastEventAt || conv.createdAt,
|
|
5421
|
+
isStreaming: conv.isStreaming,
|
|
5422
|
+
messages: conv.messages,
|
|
5423
|
+
streamingMessage: conv.isStreaming && conv.messages.length ? conv.messages[conv.messages.length - 1] : null,
|
|
5424
|
+
stats: {
|
|
5425
|
+
totalMessages: conv.messages.length,
|
|
5426
|
+
tokens: { input: 0, output: 0, total: 0 },
|
|
5427
|
+
cost: 0,
|
|
5428
|
+
},
|
|
5429
|
+
};
|
|
5430
|
+
}
|
|
5431
|
+
listRunningForPlugins() {
|
|
5432
|
+
const out = [];
|
|
5433
|
+
for (const conv of this.convs.values()) {
|
|
5434
|
+
out.push({ id: conv.id, title: conv.title, cwd: conv.cwd, kind: "running", isStreaming: conv.isStreaming });
|
|
5435
|
+
}
|
|
5436
|
+
return out;
|
|
5437
|
+
}
|
|
5438
|
+
async listHistoryForPlugins(limit = 50) {
|
|
5439
|
+
try {
|
|
5440
|
+
const files = findSessionFilesForCwd(this.sessionRoot, this.cwd);
|
|
5441
|
+
const out = [];
|
|
5442
|
+
for (const file of files.slice(0, Math.max(0, limit))) {
|
|
5443
|
+
try {
|
|
5444
|
+
const { events } = readSessionLog(file);
|
|
5445
|
+
const title = sessionLogTitle(events) || firstUserText(events, this.getLang()) || basename(dirname(file));
|
|
5446
|
+
out.push({
|
|
5447
|
+
id: file,
|
|
5448
|
+
title: title.slice(0, 60),
|
|
5449
|
+
cwd: this.cwd,
|
|
5450
|
+
kind: "history",
|
|
5451
|
+
isStreaming: false,
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5454
|
+
catch {
|
|
5455
|
+
// 忽略损坏的会话日志
|
|
5456
|
+
}
|
|
5457
|
+
}
|
|
5458
|
+
return out;
|
|
5459
|
+
}
|
|
5460
|
+
catch {
|
|
5461
|
+
return [];
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
5464
|
+
async searchForPlugins(query, limit = 20) {
|
|
5465
|
+
const q = query.trim().toLowerCase();
|
|
5466
|
+
if (!q)
|
|
5467
|
+
return [];
|
|
5468
|
+
const out = [];
|
|
5469
|
+
for (const conv of this.convs.values()) {
|
|
5470
|
+
if (conv.title.toLowerCase().includes(q))
|
|
5471
|
+
out.push({ id: conv.id, title: conv.title });
|
|
5472
|
+
if (out.length >= limit)
|
|
5473
|
+
return out;
|
|
5474
|
+
}
|
|
5475
|
+
try {
|
|
5476
|
+
const files = findSessionFilesForCwd(this.sessionRoot, this.cwd);
|
|
5477
|
+
for (const file of files) {
|
|
5478
|
+
try {
|
|
5479
|
+
const { events } = readSessionLog(file);
|
|
5480
|
+
const title = sessionLogTitle(events) || firstUserText(events, this.getLang()) || basename(dirname(file));
|
|
5481
|
+
if (title.toLowerCase().includes(q)) {
|
|
5482
|
+
out.push({ id: file, title: title.slice(0, 60) });
|
|
5483
|
+
if (out.length >= limit)
|
|
5484
|
+
break;
|
|
5485
|
+
}
|
|
5486
|
+
}
|
|
5487
|
+
catch { }
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
catch { }
|
|
5491
|
+
return out;
|
|
5492
|
+
}
|
|
5493
|
+
async writeForPlugins(id, text) {
|
|
5494
|
+
try {
|
|
5495
|
+
const conv = this.convs.get(id);
|
|
5496
|
+
if (!conv)
|
|
5497
|
+
return { ok: false, error: `未知对话:${id}` };
|
|
5498
|
+
if (!text.trim())
|
|
5499
|
+
return { ok: false, error: "投递文本为空" };
|
|
5500
|
+
if (id !== this.activeId)
|
|
5501
|
+
await this.switchConversation(id);
|
|
5502
|
+
await this.prompt(text);
|
|
5503
|
+
return { ok: true };
|
|
5504
|
+
}
|
|
5505
|
+
catch (err) {
|
|
5506
|
+
return { ok: false, error: err.message };
|
|
5507
|
+
}
|
|
5508
|
+
}
|
|
5509
|
+
async abortForPlugins(id) {
|
|
5510
|
+
try {
|
|
5511
|
+
const conv = this.convs.get(id);
|
|
5512
|
+
if (!conv)
|
|
5513
|
+
return { ok: false, error: `未知对话:${id}` };
|
|
5514
|
+
if (conv.isStreaming) {
|
|
5515
|
+
await this.abort();
|
|
5516
|
+
}
|
|
5517
|
+
return { ok: true };
|
|
5518
|
+
}
|
|
5519
|
+
catch (err) {
|
|
5520
|
+
return { ok: false, error: err.message };
|
|
5521
|
+
}
|
|
5522
|
+
}
|
|
5523
|
+
async steerForPlugins(conversationId, text) {
|
|
5524
|
+
try {
|
|
5525
|
+
if (!text.trim())
|
|
5526
|
+
return { ok: false, error: "空消息" };
|
|
5527
|
+
const conv = this.convs.get(conversationId);
|
|
5528
|
+
if (!conv)
|
|
5529
|
+
return { ok: false, error: `未知对话:${conversationId}` };
|
|
5530
|
+
conv.queue.followUp.push(text.trim());
|
|
5531
|
+
return { ok: true };
|
|
5532
|
+
}
|
|
5533
|
+
catch (err) {
|
|
5534
|
+
return { ok: false, error: err.message };
|
|
5535
|
+
}
|
|
5536
|
+
}
|
|
5537
|
+
async listModelsForPlugins() {
|
|
5538
|
+
return [{ id: `${this.modelProvider}/${this.model}`, provider: this.modelProvider, vision: this.modelVision }];
|
|
5539
|
+
}
|
|
5316
5540
|
}
|
|
5317
5541
|
// ---------------------------------------------------------------------------
|
|
5318
5542
|
// DshAgentService — 服务级:客户端会话管理与引擎分发入口
|
|
@@ -5547,4 +5771,59 @@ export class DshAgentService {
|
|
|
5547
5771
|
recordInterruptedRuns() {
|
|
5548
5772
|
/* no-op */
|
|
5549
5773
|
}
|
|
5774
|
+
// -----------------------------------------------------------------------
|
|
5775
|
+
// 插件扩展点适配层(AAL - Agent Adapter Layer)
|
|
5776
|
+
// -----------------------------------------------------------------------
|
|
5777
|
+
pluginClient() {
|
|
5778
|
+
let fallback;
|
|
5779
|
+
for (const cs of this.clients.values()) {
|
|
5780
|
+
if (!fallback)
|
|
5781
|
+
fallback = cs;
|
|
5782
|
+
try {
|
|
5783
|
+
if (cs.activeConversations() > 0)
|
|
5784
|
+
return cs;
|
|
5785
|
+
}
|
|
5786
|
+
catch { }
|
|
5787
|
+
}
|
|
5788
|
+
return fallback;
|
|
5789
|
+
}
|
|
5790
|
+
readConversationForPlugins(opts) {
|
|
5791
|
+
const targetId = opts?.clientId;
|
|
5792
|
+
if (targetId) {
|
|
5793
|
+
const cs = this.clients.get(targetId);
|
|
5794
|
+
return cs ? cs.readConversationForPlugins({ clientId: targetId }) : null;
|
|
5795
|
+
}
|
|
5796
|
+
for (const cs of this.clients.values()) {
|
|
5797
|
+
const s = cs.readConversationForPlugins();
|
|
5798
|
+
if (s)
|
|
5799
|
+
return s;
|
|
5800
|
+
}
|
|
5801
|
+
return null;
|
|
5802
|
+
}
|
|
5803
|
+
async chatFromPlugin(pluginId, req) {
|
|
5804
|
+
const cs = this.pluginClient();
|
|
5805
|
+
if (!cs)
|
|
5806
|
+
throw new Error("无可用客户端会话");
|
|
5807
|
+
const targetConvId = req.conversationId || cs.activeConversationId();
|
|
5808
|
+
await cs.prompt(req.text);
|
|
5809
|
+
return { conversationId: targetConvId, clientId: cs.clientId };
|
|
5810
|
+
}
|
|
5811
|
+
async completeForPlugins(pluginId, req) {
|
|
5812
|
+
try {
|
|
5813
|
+
if (this.quiesced)
|
|
5814
|
+
return { ok: false, error: "插件 LLM 调用被拒绝,请等服务器恢复后重试" };
|
|
5815
|
+
const cs = this.pluginClient();
|
|
5816
|
+
const agentDir = this.agentDir ?? process.env.PI_CODING_AGENT_DIR ?? "";
|
|
5817
|
+
const env = { cwd: cs?.cwd ?? this.cwd, agentDir };
|
|
5818
|
+
const mod = await import("../plugin-llm.js");
|
|
5819
|
+
const r = await mod.completeWithIsolatedSession(env, { ...req, prompt: String(req?.prompt ?? "") });
|
|
5820
|
+
if (!r.ok)
|
|
5821
|
+
return r;
|
|
5822
|
+
console.log(`[plugin:${pluginId}] dsh llm.complete ok(模型 ${r.model},输出 ${r.text.length} 字)`);
|
|
5823
|
+
return r;
|
|
5824
|
+
}
|
|
5825
|
+
catch (err) {
|
|
5826
|
+
return { ok: false, error: err.message };
|
|
5827
|
+
}
|
|
5828
|
+
}
|
|
5550
5829
|
}
|
|
@@ -27,7 +27,7 @@ import { parseTextQuote } from "../text-quote.js";
|
|
|
27
27
|
import { ARGS_CAP, TEXT_CAP, TOOL_OUTPUT_CAP, truncate } from "../serialize.js";
|
|
28
28
|
import { stripMarkers } from "../markers/index.js";
|
|
29
29
|
/** DSH user-role content blocks → UiContentBlock[]。 */
|
|
30
|
-
|
|
30
|
+
function serializeUserBlocks(blocks) {
|
|
31
31
|
if (!Array.isArray(blocks) || blocks.length === 0) {
|
|
32
32
|
return [{ type: "text", text: "" }];
|
|
33
33
|
}
|