cladogram 0.6.0-beta.6 → 0.6.0-beta.8
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/README.md +2 -2
- package/docs/agent-context.md +1 -1
- package/docs/agent-reference.md +1 -1
- package/docs/release.md +21 -4
- package/package.json +1 -1
- package/plugins/agent/index.js +1291 -107
- package/plugins/agent/style.css +50 -0
- package/skills/clado/SKILL.md +1 -1
- package/src/agent/automations.js +2 -22
- package/src/agent/clado-tools.js +2 -2
- package/src/agent/pi-bridge.js +621 -58
- package/src/agent/pi-config.js +137 -11
- package/src/server/agent.js +96 -20
- package/src/server/assets/library.js +9 -1
- package/src/server/plugin-registry.js +664 -2
- package/src/server/workspace.js +120 -3
package/src/agent/pi-config.js
CHANGED
|
@@ -234,6 +234,9 @@ export function resolvePiAgentDir() {
|
|
|
234
234
|
const dir = process.env.CLADO_PI_AGENT_DIR
|
|
235
235
|
? resolve(process.env.CLADO_PI_AGENT_DIR)
|
|
236
236
|
: getAgentDir();
|
|
237
|
+
if (process.env.CLADO_PI_AGENT_DIR && process.env.PI_CODING_AGENT_DIR !== dir) {
|
|
238
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
239
|
+
}
|
|
237
240
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
238
241
|
return dir;
|
|
239
242
|
}
|
|
@@ -687,6 +690,8 @@ export function deleteRole(roleId, agentDir = resolvePiAgentDir()) {
|
|
|
687
690
|
// 3. Pi Native MCP (mcp.json), Skills, Prompt Templates (/Commands), Packages
|
|
688
691
|
// ============================================================================
|
|
689
692
|
|
|
693
|
+
const MCP_EXPOSURES = ['direct', 'codemode', 'deferred', 'hidden'];
|
|
694
|
+
|
|
690
695
|
function readMcpFile(filePath, scope) {
|
|
691
696
|
const raw = readJsonSafe(filePath, null);
|
|
692
697
|
const servers = raw?.mcpServers && typeof raw.mcpServers === 'object' ? raw.mcpServers : {};
|
|
@@ -696,10 +701,14 @@ function readMcpFile(filePath, scope) {
|
|
|
696
701
|
type: cfg?.url ? 'http' : 'stdio',
|
|
697
702
|
command: cfg?.command || '',
|
|
698
703
|
args: Array.isArray(cfg?.args) ? cfg.args : [],
|
|
704
|
+
cwd: cfg?.cwd || '',
|
|
699
705
|
url: cfg?.url || '',
|
|
700
|
-
env: cfg?.env
|
|
701
|
-
headers: cfg?.headers
|
|
702
|
-
|
|
706
|
+
env: cfg?.env && typeof cfg.env === 'object' ? cfg.env : {},
|
|
707
|
+
headers: cfg?.headers && typeof cfg.headers === 'object' ? cfg.headers : {},
|
|
708
|
+
timeout: typeof cfg?.timeout === 'number' ? cfg.timeout : undefined,
|
|
709
|
+
exposure: MCP_EXPOSURES.includes(cfg?.exposure) ? cfg.exposure : 'codemode',
|
|
710
|
+
description: typeof cfg?.description === 'string' ? cfg.description : '',
|
|
711
|
+
enabled: cfg?.enabled !== false && cfg?.disabled !== true,
|
|
703
712
|
}));
|
|
704
713
|
}
|
|
705
714
|
|
|
@@ -712,6 +721,35 @@ export function listPiMcpServers(workspace = process.cwd(), agentDir = resolvePi
|
|
|
712
721
|
return [...byName.values()];
|
|
713
722
|
}
|
|
714
723
|
|
|
724
|
+
export function readPiMcpRawJson(workspace = process.cwd(), agentDir = resolvePiAgentDir()) {
|
|
725
|
+
const userPath = join(agentDir, 'mcp.json');
|
|
726
|
+
const projectPath = join(workspace, '.pi', 'mcp.json');
|
|
727
|
+
const readRaw = p => {
|
|
728
|
+
if (!existsSync(p)) return JSON.stringify({ mcpServers: {} }, null, 2) + '\n';
|
|
729
|
+
try { return readFileSync(p, 'utf8'); } catch { return JSON.stringify({ mcpServers: {} }, null, 2) + '\n'; }
|
|
730
|
+
};
|
|
731
|
+
return {
|
|
732
|
+
userPath,
|
|
733
|
+
projectPath,
|
|
734
|
+
user: readRaw(userPath),
|
|
735
|
+
project: readRaw(projectPath),
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
export function savePiMcpRawJson(scope = 'user', jsonText = '', workspace = process.cwd(), agentDir = resolvePiAgentDir()) {
|
|
740
|
+
const parsed = typeof jsonText === 'string' ? JSON.parse(jsonText || '{"mcpServers":{}}') : jsonText;
|
|
741
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
742
|
+
throw new Error('mcp.json 顶层必须是 JSON 对象。');
|
|
743
|
+
}
|
|
744
|
+
const normalized = parsed.mcpServers && typeof parsed.mcpServers === 'object'
|
|
745
|
+
? parsed
|
|
746
|
+
: { mcpServers: parsed };
|
|
747
|
+
const targetScope = scope === 'project' ? 'project' : 'user';
|
|
748
|
+
const filePath = targetScope === 'project' ? join(workspace, '.pi', 'mcp.json') : join(agentDir, 'mcp.json');
|
|
749
|
+
writeJsonSafe(filePath, normalized);
|
|
750
|
+
return { ok: true, scope: targetScope, path: filePath, count: Object.keys(normalized.mcpServers || {}).length };
|
|
751
|
+
}
|
|
752
|
+
|
|
715
753
|
export function savePiMcpServer(input, workspace = process.cwd(), agentDir = resolvePiAgentDir()) {
|
|
716
754
|
const name = String(input?.name || '').trim().replace(/[^a-zA-Z0-9._-]/g, '-');
|
|
717
755
|
if (!name) throw new Error('MCP 服务器名称不能为空。');
|
|
@@ -719,33 +757,51 @@ export function savePiMcpServer(input, workspace = process.cwd(), agentDir = res
|
|
|
719
757
|
const filePath = scope === 'project' ? join(workspace, '.pi', 'mcp.json') : join(agentDir, 'mcp.json');
|
|
720
758
|
const doc = readJsonSafe(filePath, { mcpServers: {} });
|
|
721
759
|
if (!doc.mcpServers || typeof doc.mcpServers !== 'object') doc.mcpServers = {};
|
|
760
|
+
const prevName = String(input?.originalName || '').trim();
|
|
761
|
+
if (prevName && prevName !== name && prevName in doc.mcpServers) {
|
|
762
|
+
delete doc.mcpServers[prevName];
|
|
763
|
+
}
|
|
722
764
|
const entry = {};
|
|
723
|
-
if (input?.url && String(input.url).trim()) {
|
|
724
|
-
|
|
725
|
-
if (
|
|
765
|
+
if (input?.type === 'http' || (input?.url && String(input.url).trim() && input?.type !== 'stdio')) {
|
|
766
|
+
const urlStr = String(input?.url || '').trim();
|
|
767
|
+
if (!urlStr) throw new Error('请填写远程 MCP 端点 URL。');
|
|
768
|
+
entry.url = urlStr;
|
|
769
|
+
if (input.headers && typeof input.headers === 'object' && Object.keys(input.headers).length) {
|
|
770
|
+
entry.headers = input.headers;
|
|
771
|
+
}
|
|
726
772
|
} else {
|
|
727
773
|
const cmd = String(input?.command || '').trim();
|
|
728
774
|
if (!cmd) throw new Error('请填写 MCP 启动命令(command)或远程 URL。');
|
|
729
775
|
entry.command = cmd;
|
|
730
776
|
entry.args = Array.isArray(input?.args)
|
|
731
|
-
? input.args.map(String)
|
|
777
|
+
? input.args.map(String).filter(Boolean)
|
|
732
778
|
: typeof input?.args === 'string' && input.args.trim()
|
|
733
779
|
? input.args.trim().split(/\s+/)
|
|
734
780
|
: [];
|
|
781
|
+
if (input?.cwd && String(input.cwd).trim()) entry.cwd = String(input.cwd).trim();
|
|
735
782
|
if (input.env && typeof input.env === 'object' && Object.keys(input.env).length) entry.env = input.env;
|
|
736
783
|
}
|
|
737
|
-
if (input?.
|
|
784
|
+
if (typeof input?.timeout === 'number' && Number.isFinite(input.timeout) && input.timeout > 0) {
|
|
785
|
+
entry.timeout = Math.round(input.timeout);
|
|
786
|
+
}
|
|
787
|
+
if (input?.description && String(input.description).trim()) {
|
|
788
|
+
entry.description = String(input.description).trim().slice(0, 250);
|
|
789
|
+
}
|
|
790
|
+
const exposure = MCP_EXPOSURES.includes(input?.exposure) ? input.exposure : 'direct';
|
|
791
|
+
entry.exposure = exposure;
|
|
792
|
+
if (input?.enabled === false) entry.enabled = false;
|
|
738
793
|
doc.mcpServers[name] = entry;
|
|
739
794
|
writeJsonSafe(filePath, doc);
|
|
740
|
-
return { ok: true, name, scope };
|
|
795
|
+
return { ok: true, name, scope, exposure };
|
|
741
796
|
}
|
|
742
797
|
|
|
743
798
|
export function togglePiMcpServer(name, enabled, workspace = process.cwd(), agentDir = resolvePiAgentDir()) {
|
|
744
799
|
for (const filePath of [join(workspace, '.pi', 'mcp.json'), join(agentDir, 'mcp.json')]) {
|
|
745
800
|
const doc = readJsonSafe(filePath, null);
|
|
746
801
|
if (doc?.mcpServers && name in doc.mcpServers) {
|
|
747
|
-
|
|
748
|
-
|
|
802
|
+
delete doc.mcpServers[name].disabled;
|
|
803
|
+
if (enabled) delete doc.mcpServers[name].enabled;
|
|
804
|
+
else doc.mcpServers[name].enabled = false;
|
|
749
805
|
writeJsonSafe(filePath, doc);
|
|
750
806
|
return { ok: true, name, enabled: Boolean(enabled) };
|
|
751
807
|
}
|
|
@@ -783,6 +839,76 @@ export function importPiMcpJson(jsonText, scope = 'user', workspace = process.cw
|
|
|
783
839
|
return { ok: true, count };
|
|
784
840
|
}
|
|
785
841
|
|
|
842
|
+
// ============================================================================
|
|
843
|
+
// 3.5 Plugin / Extension Injected Parameters (.clado/plugin-params.json + user)
|
|
844
|
+
// ============================================================================
|
|
845
|
+
|
|
846
|
+
export function readPluginParams(workspace = process.cwd(), stateDir = '', agentDir = resolvePiAgentDir()) {
|
|
847
|
+
const userPath = join(agentDir, 'clado-plugin-params.json');
|
|
848
|
+
const wsPath = stateDir ? join(stateDir, 'plugin-params.json') : join(workspace, '.clado', 'plugin-params.json');
|
|
849
|
+
const userRaw = readJsonSafe(userPath, {});
|
|
850
|
+
const wsRaw = readJsonSafe(wsPath, {});
|
|
851
|
+
const merged = {};
|
|
852
|
+
for (const [id, val] of Object.entries(userRaw && typeof userRaw === 'object' ? userRaw : {})) {
|
|
853
|
+
if (val && typeof val === 'object') merged[id] = { scope: 'user', env: val.env || {}, params: val.params || {} };
|
|
854
|
+
}
|
|
855
|
+
for (const [id, val] of Object.entries(wsRaw && typeof wsRaw === 'object' ? wsRaw : {})) {
|
|
856
|
+
if (val && typeof val === 'object') {
|
|
857
|
+
const prev = merged[id] || { env: {}, params: {} };
|
|
858
|
+
merged[id] = {
|
|
859
|
+
scope: 'project',
|
|
860
|
+
env: { ...(prev.env || {}), ...(val.env || {}) },
|
|
861
|
+
params: { ...(prev.params || {}), ...(val.params || {}) },
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return { userPath, projectPath: wsPath, items: merged };
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export function savePluginParams({ pluginId, scope = 'project', env = {}, params = {} } = {}, workspace = process.cwd(), stateDir = '', agentDir = resolvePiAgentDir()) {
|
|
869
|
+
const id = String(pluginId || '').trim();
|
|
870
|
+
if (!id) throw new Error('插件或扩展标识不能为空。');
|
|
871
|
+
const targetScope = scope === 'user' ? 'user' : 'project';
|
|
872
|
+
const filePath = targetScope === 'user'
|
|
873
|
+
? join(agentDir, 'clado-plugin-params.json')
|
|
874
|
+
: (stateDir ? join(stateDir, 'plugin-params.json') : join(workspace, '.clado', 'plugin-params.json'));
|
|
875
|
+
const doc = readJsonSafe(filePath, {});
|
|
876
|
+
const cleanEnv = {};
|
|
877
|
+
if (env && typeof env === 'object' && !Array.isArray(env)) {
|
|
878
|
+
for (const [k, v] of Object.entries(env)) {
|
|
879
|
+
const ck = String(k || '').trim();
|
|
880
|
+
if (ck) cleanEnv[ck] = String(v ?? '');
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const cleanParams = (params && typeof params === 'object' && !Array.isArray(params)) ? params : {};
|
|
884
|
+
doc[id] = { env: cleanEnv, params: cleanParams, updatedAt: new Date().toISOString() };
|
|
885
|
+
writeJsonSafe(filePath, doc);
|
|
886
|
+
return { ok: true, pluginId: id, scope: targetScope, path: filePath };
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
export function deletePluginParams(pluginId, scope = 'all', workspace = process.cwd(), stateDir = '', agentDir = resolvePiAgentDir()) {
|
|
890
|
+
const id = String(pluginId || '').trim();
|
|
891
|
+
if (!id) return { ok: false };
|
|
892
|
+
const paths = scope === 'user'
|
|
893
|
+
? [join(agentDir, 'clado-plugin-params.json')]
|
|
894
|
+
: scope === 'project'
|
|
895
|
+
? [stateDir ? join(stateDir, 'plugin-params.json') : join(workspace, '.clado', 'plugin-params.json')]
|
|
896
|
+
: [
|
|
897
|
+
join(agentDir, 'clado-plugin-params.json'),
|
|
898
|
+
stateDir ? join(stateDir, 'plugin-params.json') : join(workspace, '.clado', 'plugin-params.json'),
|
|
899
|
+
];
|
|
900
|
+
let removed = false;
|
|
901
|
+
for (const p of paths) {
|
|
902
|
+
const doc = readJsonSafe(p, null);
|
|
903
|
+
if (doc && typeof doc === 'object' && id in doc) {
|
|
904
|
+
delete doc[id];
|
|
905
|
+
writeJsonSafe(p, doc);
|
|
906
|
+
removed = true;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return { ok: removed, pluginId: id };
|
|
910
|
+
}
|
|
911
|
+
|
|
786
912
|
export function savePiSkill({ name, description, content, scope = 'user' }, workspace = process.cwd(), agentDir = resolvePiAgentDir()) {
|
|
787
913
|
const slug = String(name || '').trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
788
914
|
if (!slug) throw new Error('Skill 名称不能为空。');
|
package/src/server/agent.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
deletePiMcpServer,
|
|
16
16
|
deletePiPrompt,
|
|
17
17
|
deletePiSkill,
|
|
18
|
+
deletePluginParams,
|
|
18
19
|
deleteProviderConfig,
|
|
19
20
|
deleteRole,
|
|
20
21
|
ensureCladoPlatformDocs,
|
|
@@ -25,6 +26,8 @@ import {
|
|
|
25
26
|
listRoles,
|
|
26
27
|
readAgentsMemory,
|
|
27
28
|
readCanvasComponentsConfig,
|
|
29
|
+
readPiMcpRawJson,
|
|
30
|
+
readPluginParams,
|
|
28
31
|
readRuntimeSettings,
|
|
29
32
|
removePiPackage,
|
|
30
33
|
resetCladoPlatformDocs,
|
|
@@ -32,9 +35,11 @@ import {
|
|
|
32
35
|
resolveRole,
|
|
33
36
|
saveAgentsMemory,
|
|
34
37
|
saveCladoPlatformContext,
|
|
38
|
+
savePiMcpRawJson,
|
|
35
39
|
savePiMcpServer,
|
|
36
40
|
savePiPrompt,
|
|
37
41
|
savePiSkill,
|
|
42
|
+
savePluginParams,
|
|
38
43
|
saveProviderConfig,
|
|
39
44
|
saveRole,
|
|
40
45
|
saveRuntimeSettings,
|
|
@@ -42,6 +47,7 @@ import {
|
|
|
42
47
|
toggleCanvasComponent,
|
|
43
48
|
togglePiMcpServer,
|
|
44
49
|
} from '../agent/pi-config.js';
|
|
50
|
+
import { listInstalledWorkspacePlugins } from './plugin-registry.js';
|
|
45
51
|
import {
|
|
46
52
|
archiveSession,
|
|
47
53
|
createPiBridge,
|
|
@@ -57,7 +63,6 @@ import {
|
|
|
57
63
|
import {
|
|
58
64
|
createAutomationEngine,
|
|
59
65
|
deleteAutomationRule,
|
|
60
|
-
MEMORY_SCRIBE_PRESET,
|
|
61
66
|
readAutomationsState,
|
|
62
67
|
saveAutomationRule,
|
|
63
68
|
setAutomationsPaused,
|
|
@@ -206,10 +211,10 @@ export function createAgentHandler({
|
|
|
206
211
|
automationEngine.registerWorkspace(rt.workspace);
|
|
207
212
|
const act = String(params.action || 'list').trim();
|
|
208
213
|
if (act === 'events_catalog') {
|
|
209
|
-
return { ok: true, catalog: SYSTEM_EVENT_CATALOG
|
|
214
|
+
return { ok: true, catalog: SYSTEM_EVENT_CATALOG };
|
|
210
215
|
}
|
|
211
216
|
if (act === 'list') {
|
|
212
|
-
return { ok: true, ...readAutomationsState(rt.stateDir)
|
|
217
|
+
return { ok: true, ...readAutomationsState(rt.stateDir) };
|
|
213
218
|
}
|
|
214
219
|
if (act === 'save') {
|
|
215
220
|
const saved = saveAutomationRule(rt.stateDir, params.rule || params);
|
|
@@ -254,8 +259,23 @@ export function createAgentHandler({
|
|
|
254
259
|
const memory = readAgentsMemory(rt.workspace);
|
|
255
260
|
const platformDocs = ensureCladoPlatformDocs(agentDir);
|
|
256
261
|
const canvasComponents = readCanvasComponentsConfig(agentDir);
|
|
257
|
-
const
|
|
262
|
+
const rawSessions = listSessions(rt.stateDir, { includeArchived: true, messageLimit: 30, agentDir });
|
|
263
|
+
const sessions = bridge.overlayLiveSessions(rt.workspace, rawSessions);
|
|
258
264
|
const automations = readAutomationsState(rt.stateDir);
|
|
265
|
+
const mcpRawJson = readPiMcpRawJson(rt.workspace, agentDir);
|
|
266
|
+
const pluginParams = readPluginParams(rt.workspace, rt.stateDir, agentDir);
|
|
267
|
+
const installedWsPlugins = listInstalledWorkspacePlugins(rt.stateDir);
|
|
268
|
+
const descriptorById = new Map((rt.pluginDescriptors || []).map(p => [p.id, p]));
|
|
269
|
+
const workspacePluginsMap = new Map();
|
|
270
|
+
for (const p of rt.pluginDescriptors || []) workspacePluginsMap.set(p.id, { ...p });
|
|
271
|
+
for (const inst of installedWsPlugins) {
|
|
272
|
+
const prev = workspacePluginsMap.get(inst.id) || {};
|
|
273
|
+
workspacePluginsMap.set(inst.id, {
|
|
274
|
+
...prev,
|
|
275
|
+
...inst,
|
|
276
|
+
active: descriptorById.has(inst.id),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
259
279
|
|
|
260
280
|
return {
|
|
261
281
|
engine: 'pi',
|
|
@@ -273,20 +293,26 @@ export function createAgentHandler({
|
|
|
273
293
|
configuredModels: modelsInfo.configuredModels,
|
|
274
294
|
roles,
|
|
275
295
|
ecosystem,
|
|
296
|
+
mcpRawJson,
|
|
297
|
+
pluginParams,
|
|
276
298
|
canvasComponents,
|
|
277
|
-
workspacePlugins:
|
|
299
|
+
workspacePlugins: [...workspacePluginsMap.values()],
|
|
278
300
|
memory,
|
|
279
301
|
platformDocs,
|
|
280
302
|
automations,
|
|
281
303
|
eventCatalog: SYSTEM_EVENT_CATALOG,
|
|
282
|
-
memoryScribePreset: MEMORY_SCRIBE_PRESET,
|
|
283
304
|
activeRuns: bridge.listActiveRuns(rt.workspace),
|
|
305
|
+
liveRuntime: bridge.inspectRuntime(rt.workspace),
|
|
284
306
|
sessions,
|
|
285
307
|
};
|
|
286
308
|
}
|
|
287
309
|
|
|
288
310
|
return {
|
|
289
311
|
automationEngine,
|
|
312
|
+
async reloadWorkspace(targetWorkspace) {
|
|
313
|
+
const rt = getRuntime(targetWorkspace);
|
|
314
|
+
return await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
315
|
+
},
|
|
290
316
|
notifySystemEvent(targetWorkspace, eventType, payload = {}) {
|
|
291
317
|
const rt = getRuntime(targetWorkspace);
|
|
292
318
|
automationEngine.notifyEvent(rt.workspace, eventType, payload);
|
|
@@ -359,7 +385,6 @@ export function createAgentHandler({
|
|
|
359
385
|
ok: true,
|
|
360
386
|
...state,
|
|
361
387
|
eventCatalog: SYSTEM_EVENT_CATALOG,
|
|
362
|
-
preset: MEMORY_SCRIBE_PRESET,
|
|
363
388
|
});
|
|
364
389
|
return;
|
|
365
390
|
}
|
|
@@ -391,18 +416,22 @@ export function createAgentHandler({
|
|
|
391
416
|
limit,
|
|
392
417
|
before: beforeParam !== null ? Number(beforeParam) : null,
|
|
393
418
|
});
|
|
419
|
+
const merged = beforeParam !== null
|
|
420
|
+
? { ...item, messages: page.messages, totalMessages: page.totalMessages, oldestIndex: page.oldestIndex, hasMoreBefore: page.hasMoreBefore }
|
|
421
|
+
: bridge.overlayLiveSession(rt.workspace, { ...item, messages: page.messages, totalMessages: page.totalMessages, oldestIndex: page.oldestIndex, hasMoreBefore: page.hasMoreBefore });
|
|
394
422
|
sendJson(res, 200, {
|
|
395
|
-
session:
|
|
423
|
+
session: merged,
|
|
396
424
|
...page,
|
|
397
425
|
});
|
|
398
426
|
return;
|
|
399
427
|
}
|
|
400
|
-
sendJson(res, 200, { session: item });
|
|
428
|
+
sendJson(res, 200, { session: bridge.overlayLiveSession(rt.workspace, item) });
|
|
401
429
|
return;
|
|
402
430
|
}
|
|
403
431
|
const includeArchived = url.searchParams.get('archived') === '1';
|
|
404
432
|
const sinceMinutes = Number(url.searchParams.get('sinceMinutes') || 0);
|
|
405
|
-
|
|
433
|
+
const list = listSessions(rt.stateDir, { includeArchived, sinceMinutes, messageLimit: 30, agentDir });
|
|
434
|
+
sendJson(res, 200, { sessions: bridge.overlayLiveSessions(rt.workspace, list) });
|
|
406
435
|
return;
|
|
407
436
|
}
|
|
408
437
|
|
|
@@ -436,6 +465,15 @@ export function createAgentHandler({
|
|
|
436
465
|
sendJson(res, 200, result);
|
|
437
466
|
return;
|
|
438
467
|
}
|
|
468
|
+
if (body?.action === 'reload') {
|
|
469
|
+
const result = await bridge.reloadSession({
|
|
470
|
+
workspace: rt.workspace,
|
|
471
|
+
stateDir: rt.stateDir,
|
|
472
|
+
sessionId: body.id || '',
|
|
473
|
+
});
|
|
474
|
+
sendJson(res, 200, result);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
439
477
|
if (body?.action === 'abort_all') {
|
|
440
478
|
const stoppedCount = await bridge.abortAllRuns(rt.workspace);
|
|
441
479
|
sendJson(res, 200, { ok: true, stoppedCount });
|
|
@@ -473,6 +511,7 @@ export function createAgentHandler({
|
|
|
473
511
|
const id = url.searchParams.get('id');
|
|
474
512
|
if (!id) throw new DocumentError('缺少会话 ID。', 400);
|
|
475
513
|
await bridge.cancel(rt.workspace, id);
|
|
514
|
+
await bridge.disposeWarmSession(rt.workspace, id);
|
|
476
515
|
sendJson(res, 200, deleteSession(rt.stateDir, id, agentDir));
|
|
477
516
|
return;
|
|
478
517
|
}
|
|
@@ -527,54 +566,91 @@ export function createAgentHandler({
|
|
|
527
566
|
sendJson(res, 200, { ...result, meta: await buildFullMeta(targetWorkspace) });
|
|
528
567
|
return;
|
|
529
568
|
}
|
|
569
|
+
if (action === 'reload_pi') {
|
|
570
|
+
const result = await bridge.reloadSession({
|
|
571
|
+
workspace: rt.workspace,
|
|
572
|
+
stateDir: rt.stateDir,
|
|
573
|
+
sessionId: body.sessionId || '',
|
|
574
|
+
});
|
|
575
|
+
sendJson(res, 200, { ...result, meta: await buildFullMeta(targetWorkspace) });
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
530
578
|
if (action === 'save_mcp') {
|
|
531
579
|
const result = savePiMcpServer(body, rt.workspace, agentDir);
|
|
532
|
-
|
|
580
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
581
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
533
582
|
return;
|
|
534
583
|
}
|
|
535
584
|
if (action === 'toggle_mcp') {
|
|
536
585
|
const result = togglePiMcpServer(body.name, body.enabled, rt.workspace, agentDir);
|
|
537
|
-
|
|
586
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
587
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
538
588
|
return;
|
|
539
589
|
}
|
|
540
590
|
if (action === 'delete_mcp') {
|
|
541
591
|
const result = deletePiMcpServer(body.name, rt.workspace, agentDir);
|
|
542
|
-
|
|
592
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
593
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
543
594
|
return;
|
|
544
595
|
}
|
|
545
596
|
if (action === 'import_mcp_json') {
|
|
546
597
|
const result = importPiMcpJson(body.json, body.scope || 'user', rt.workspace, agentDir);
|
|
547
|
-
|
|
598
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
599
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (action === 'save_mcp_raw') {
|
|
603
|
+
const result = savePiMcpRawJson(body.scope || 'user', body.json, rt.workspace, agentDir);
|
|
604
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
605
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
if (action === 'save_plugin_params') {
|
|
609
|
+
const result = savePluginParams(body, rt.workspace, rt.stateDir, agentDir);
|
|
610
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
611
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (action === 'delete_plugin_params') {
|
|
615
|
+
const result = deletePluginParams(body.pluginId || body.id, body.scope || 'all', rt.workspace, rt.stateDir, agentDir);
|
|
616
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
617
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
548
618
|
return;
|
|
549
619
|
}
|
|
550
620
|
if (action === 'save_skill') {
|
|
551
621
|
const result = savePiSkill(body, rt.workspace, agentDir);
|
|
552
|
-
|
|
622
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
623
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
553
624
|
return;
|
|
554
625
|
}
|
|
555
626
|
if (action === 'delete_skill') {
|
|
556
627
|
const result = deletePiSkill(body.name, rt.workspace, agentDir);
|
|
557
|
-
|
|
628
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
629
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
558
630
|
return;
|
|
559
631
|
}
|
|
560
632
|
if (action === 'save_command') {
|
|
561
633
|
const result = savePiPrompt(body, rt.workspace, agentDir);
|
|
562
|
-
|
|
634
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
635
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
563
636
|
return;
|
|
564
637
|
}
|
|
565
638
|
if (action === 'delete_command') {
|
|
566
639
|
const result = deletePiPrompt(body.name, rt.workspace, agentDir);
|
|
567
|
-
|
|
640
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
641
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
568
642
|
return;
|
|
569
643
|
}
|
|
570
644
|
if (action === 'install_pi_package') {
|
|
571
645
|
const result = await installPiPackage(body.source, { local: Boolean(body.local) }, rt.workspace, agentDir);
|
|
572
|
-
|
|
646
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
647
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
573
648
|
return;
|
|
574
649
|
}
|
|
575
650
|
if (action === 'remove_pi_package') {
|
|
576
651
|
const result = await removePiPackage(body.source, { local: Boolean(body.local) }, rt.workspace, agentDir);
|
|
577
|
-
|
|
652
|
+
const reload = await bridge.reloadWorkspaceSessions(rt.workspace);
|
|
653
|
+
sendJson(res, 200, { ...result, reload, meta: await buildFullMeta(targetWorkspace) });
|
|
578
654
|
return;
|
|
579
655
|
}
|
|
580
656
|
if (action === 'save_memory') {
|
|
@@ -2224,8 +2224,16 @@
|
|
|
2224
2224
|
}
|
|
2225
2225
|
} catch {}
|
|
2226
2226
|
});
|
|
2227
|
+
es.addEventListener('agent.stream', event => {
|
|
2228
|
+
try {
|
|
2229
|
+
const payload = JSON.parse(event.data || '{}');
|
|
2230
|
+
if (typeof CustomEvent === 'function') {
|
|
2231
|
+
dispatchEvent(new CustomEvent('clado:agent-stream', { detail: payload }));
|
|
2232
|
+
}
|
|
2233
|
+
} catch {}
|
|
2234
|
+
});
|
|
2227
2235
|
es.onerror = () => { sseReady = false; pushDebugLog('sse', 'SSE 连接中断,正在重试'); };
|
|
2228
|
-
for (const evtName of ['ready', 'doc.updated', 'agent.activity', 'agent.presence', 'agent.stage', 'canvas.draft', 'code.activity', 'code.diff']) {
|
|
2236
|
+
for (const evtName of ['ready', 'doc.updated', 'agent.activity', 'agent.presence', 'agent.stage', 'agent.sessions', 'canvas.draft', 'code.activity', 'code.diff']) {
|
|
2229
2237
|
es.addEventListener(evtName, ev => pushDebugLog('sse', evtName + (ev.data ? ' ' + String(ev.data).slice(0, 140) : '')));
|
|
2230
2238
|
}
|
|
2231
2239
|
addEventListener('pagehide', () => es.close());
|