@tea-agent/loop-agent 0.53.0-next.3 → 0.53.0-next.4
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 +8 -2
- package/dist/build-stamp.json +3 -3
- package/dist/worker/console/chat/api-workbench-endpoint-detect.js +286 -0
- package/dist/worker/console/chat/api-workbench.js +69 -0
- package/dist/worker/console/chat/chat-event-store.js +32 -20
- package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +77 -1
- package/dist/worker/console/chat/routes.js +39 -6
- package/dist/worker/console/chat/subagents/session-store.js +23 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-9YdcTSkA.js → abnfDiagram-N423BO3Z-BQGQzeB4.js} +1 -1
- package/dist/worker/console/static/assets/{arc-5o9a24RM.js → arc-VohM6k-u.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-kk-Y4K8w.js → architectureDiagram-T3A2C74G-B4aiPVwO.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-BuMyp-i-.js → blockDiagram-VBNYF7ZC-BiOHLIjV.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BnAbUXQM.js → c4Diagram-5PPSVZJV-BeyEgSte.js} +1 -1
- package/dist/worker/console/static/assets/channel-vEMQugvb.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-sQ2VjuFx.js → chunk-2GRJ4B5K-BlHEbEDm.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-CbkqzTV8.js → chunk-2Q5K7J3B-ABS6wshI.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-CaP8JTC3.js → chunk-5RXB4S5H-CfxvbyTL.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-D7yUFtwu.js → chunk-5VM5RSS4-C5Le1PPI.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-zowLlgmO.js → chunk-6Q2QTUOP-DniQmSFb.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-KGzLFdSC.js → chunk-GF5L2VYU-BBXIq87q.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DuVIxg_I.js → chunk-JWPE2WC7-CuZFyj4e.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CXP8iZrQ.js → chunk-KBJHAD2P-BqltI7Xa.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-DASfOCYV.js → chunk-RYQCIY6F-LYNDI4V3.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DFwLDf-r.js → chunk-XXDRQBXY-ehKC3TY6.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-Dk4zlu_w.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-Dk4zlu_w.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-CIrJSuNM.js → cose-bilkent-JH36ORCC-BgLB7_Gs.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-BrI5M-XP.js → cynefinDiagram-MW4NZA55-9_ELNaGh.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BEJlUQi2.js → dagre-VZM6K2ZE-BQ2TK9_p.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-Buw7nAqS.js → diagram-7IWD3JNH-BkM26qk5.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-DHURLBbb.js → diagram-B4RE2ZJO-CrAzvppm.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-CEFuptxk.js → diagram-LBJQPF4R-DpGT-pk8.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-Cejgl71p.js → diagram-Q27KOJAE-Diukaccq.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-Bwxq3Xoa.js → diagram-UB23O5K3-C2B4xR64.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-i4NNenm0.js → ebnfDiagram-BXEA7PRR-ClHD75wJ.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-BaSp03BR.js → erDiagram-JOGREHBK-BjDCis5U.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-CQtgCCPg.js → flowDiagram-UKHOOZJN-D8htdME5.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DkS9Vbt8.js → ganttDiagram-PKOTCBZU-jnfyRfrb.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Dm64UQgY.js → gitGraphDiagram-DS77QQ5N-Bjbg88s7.js} +1 -1
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-BpcLrRRV.js → infoDiagram-6WML65LV-DOHcqlQa.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DFjxaE3Q.js → ishikawaDiagram-WSZJBQD7-BhFciWDX.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-G6kuLGYK.js → journeyDiagram-NVQOT4AX-hdKB39Nb.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-DistDdnp.js → kanban-definition-27J2QSJJ-BdQwpama.js} +1 -1
- package/dist/worker/console/static/assets/{linear-Cadcj4Jf.js → linear-Duip0xUK.js} +1 -1
- package/dist/worker/console/static/assets/main-B3dqMT9t.css +1 -0
- package/dist/worker/console/static/assets/{main-CKu0wCrM.js → main-BxLSZyxc.js} +145 -145
- package/dist/worker/console/static/assets/{mermaid.core-CVqQBsGx.js → mermaid.core-DRY-520_.js} +4 -4
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-oIAAXLn3.js → mindmap-definition-FAOFIHXS-CYtRHYwj.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-BgBPFLA0.js → pegDiagram-VL7TDLO6-CK_Sgiks.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-RTyZdL9S.js → pieDiagram-7S7Q4E2Y-BeOsa7QB.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BHEYQMZx.js → quadrantDiagram-CIZ2JOQS-D4D9CRa0.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-B2JIrks2.js → railroadDiagram-AXF67PYL-4GuuCKY5.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-TJ5_MWbY.js → requirementDiagram-LRYGKXZP-BkIuekzP.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BzjUsr0j.js → sankeyDiagram-W5VNT64P-uX7nPf0J.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-DrmrPPVE.js → sequenceDiagram-SI44F4Z6-CnP16DIz.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-DCQgjy0Q.js → sheet-workbook-BpM2xbR-.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BLp8F5fC.js → sizeCapture-X5ZJPWSS-Bjm5OhZY.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-5MNm447q.js → stateDiagram-OKZ733FA-DXZ2RYku.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BYPZczKU.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-Cs2RUkNq.js → swimlanes-SLNWSIFB-B2mW_ryg.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-_6bzI4ly.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-BoeTHoWc.js → timeline-definition-Z64GVDOM-eLhaZ_6G.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-DFWej-Mm.js → vennDiagram-T6HMQDX7-tJh-1pOO.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-BcD0_2m5.js → wardleyDiagram-T6FBY63Y-oQI6fAHm.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-y4PQYZiq.js → xychartDiagram-ELKLHX3M-Bpg-EQfm.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/package.json +3 -3
- package/dist/worker/console/static/assets/channel-DzpJs7JM.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-ClK7LSSv.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-ClK7LSSv.js +0 -1
- package/dist/worker/console/static/assets/main-DpBoCiky.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-gP-t-MQJ.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-D6MJJUTV.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- 设置里新增模型时,模型名称在左、模型 ID 在右,与已有模型列表的排列一致。
|
|
10
|
+
|
|
11
|
+
## [0.53.0-next.4] - 2026-10-29
|
|
8
12
|
|
|
9
13
|
本预发布快照记录构建时已整理的待发布变化,不表示相对上一构建全部新增。
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
### 修复
|
|
16
|
+
|
|
17
|
+
- 设置里新增模型时,模型名称在左、模型 ID 在右,与已有模型列表的排列一致。
|
|
12
18
|
|
|
13
19
|
## [0.52.0] - 2026-10-25
|
|
14
20
|
|
package/dist/build-stamp.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"version": "0.53.0-next.
|
|
4
|
-
"gitSha": "
|
|
5
|
-
"builtAt": "2026-10-
|
|
3
|
+
"version": "0.53.0-next.4",
|
|
4
|
+
"gitSha": "e4f7672608c6b55639152bfaa7e63d33e1e26fa0",
|
|
5
|
+
"builtAt": "2026-10-29T06:26:12.229Z"
|
|
6
6
|
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/** Spring's default when nothing is configured. */
|
|
4
|
+
const DEFAULT_PORT = 8080;
|
|
5
|
+
/** How long one candidate gets before it counts as down. */
|
|
6
|
+
const PROBE_TIMEOUT_MS = 3_000;
|
|
7
|
+
/** Config file names, in the order they override each other (later wins). */
|
|
8
|
+
const CONFIG_FILES = [
|
|
9
|
+
"application.properties",
|
|
10
|
+
"application.yml",
|
|
11
|
+
"application.yaml",
|
|
12
|
+
];
|
|
13
|
+
/** A YAML line `server.port: 8081`, tolerating nested form and inline values. */
|
|
14
|
+
function yamlConfigValue(text, key) {
|
|
15
|
+
const lines = text.split(/\r?\n/);
|
|
16
|
+
// The key may be written nested (`server:\n port: 8081`) or flattened
|
|
17
|
+
// (`server.port: 8081`); both appear in real projects.
|
|
18
|
+
const flat = new RegExp(`^\\s*${key.replace(/\./g, "\\.")}\\s*:\\s*(.+)$`);
|
|
19
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
20
|
+
const hit = flat.exec(lines[index] ?? "");
|
|
21
|
+
if (hit)
|
|
22
|
+
return { value: stripYamlScalar(hit[1] ?? ""), line: index + 1 };
|
|
23
|
+
}
|
|
24
|
+
/*
|
|
25
|
+
* Nested form: `server:` → `servlet:` → `context-path:`.
|
|
26
|
+
*
|
|
27
|
+
* The path can be several levels deep, so this walks the key segment by segment,
|
|
28
|
+
* tracking indentation at each level. A single-level parent lookup missed
|
|
29
|
+
* `server.servlet.context-path` entirely, which silently dropped the context path
|
|
30
|
+
* from the probed URL.
|
|
31
|
+
/*
|
|
32
|
+
* Nested form: `server:` → `servlet:` → `context-path:`.
|
|
33
|
+
*
|
|
34
|
+
* The path can be several levels deep. This walks the key segment by segment and
|
|
35
|
+
* tracks indentation: intermediate levels are headers with no value (`servlet:`)
|
|
36
|
+
* while the last one carries it (`context-path: /api`). A single-level parent
|
|
37
|
+
* lookup missed `server.servlet.context-path` entirely, which silently dropped the
|
|
38
|
+
* context path from the probed URL.
|
|
39
|
+
*/
|
|
40
|
+
const segments = key.split(".");
|
|
41
|
+
let scopeStart = 0;
|
|
42
|
+
let scopeIndent = -1;
|
|
43
|
+
for (let depth = 0; depth < segments.length; depth += 1) {
|
|
44
|
+
const segment = segments[depth];
|
|
45
|
+
const isLeaf = depth === segments.length - 1;
|
|
46
|
+
// A leaf may be written inline (`port: 8081`); a header has nothing after the colon.
|
|
47
|
+
const pattern = isLeaf
|
|
48
|
+
? new RegExp(`^(\\s*)${segment.replace(/\./g, "\\.")}\\s*:\\s*(.+)$`)
|
|
49
|
+
: new RegExp(`^(\\s*)${segment.replace(/\./g, "\\.")}\\s*:\\s*$`);
|
|
50
|
+
let found = -1;
|
|
51
|
+
let foundIndent = -1;
|
|
52
|
+
let foundValue = "";
|
|
53
|
+
for (let index = scopeStart; index < lines.length; index += 1) {
|
|
54
|
+
const line = lines[index] ?? "";
|
|
55
|
+
if (line.trim() === "" || line.trim().startsWith("#"))
|
|
56
|
+
continue;
|
|
57
|
+
const indent = /^\s*/.exec(line)?.[0].length ?? 0;
|
|
58
|
+
// Leaving the enclosing block means the key is not here.
|
|
59
|
+
if (scopeIndent >= 0 && indent <= scopeIndent)
|
|
60
|
+
break;
|
|
61
|
+
const hit = pattern.exec(line);
|
|
62
|
+
if (hit) {
|
|
63
|
+
found = index;
|
|
64
|
+
foundIndent = (hit[1] ?? "").length;
|
|
65
|
+
foundValue = hit[2] ?? "";
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (found < 0)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (isLeaf)
|
|
72
|
+
return { value: stripYamlScalar(foundValue), line: found + 1 };
|
|
73
|
+
scopeStart = found + 1;
|
|
74
|
+
scopeIndent = foundIndent;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
function stripYamlScalar(raw) {
|
|
79
|
+
return raw.trim().replace(/^["']/, "").replace(/["']$/, "").replace(/\s+#.*$/, "").trim();
|
|
80
|
+
}
|
|
81
|
+
/** A `.properties` line, ignoring comments. */
|
|
82
|
+
function propertiesConfigValue(text, key) {
|
|
83
|
+
const lines = text.split(/\r?\n/);
|
|
84
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
85
|
+
const line = lines[index] ?? "";
|
|
86
|
+
if (/^\s*[#!]/.test(line))
|
|
87
|
+
continue;
|
|
88
|
+
const hit = new RegExp(`^\\s*${key.replace(/\./g, "\\.")}\\s*[=:]\\s*(.*)$`).exec(line);
|
|
89
|
+
if (hit)
|
|
90
|
+
return { value: (hit[1] ?? "").trim(), line: index + 1 };
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
function readKey(file, text, key) {
|
|
95
|
+
return file.endsWith(".properties")
|
|
96
|
+
? propertiesConfigValue(text, key)
|
|
97
|
+
: yamlConfigValue(text, key);
|
|
98
|
+
}
|
|
99
|
+
/** Directories a Spring project keeps its configuration in. */
|
|
100
|
+
function configLocations(project) {
|
|
101
|
+
return [
|
|
102
|
+
path.join(project.absolute, "src", "main", "resources"),
|
|
103
|
+
path.join(project.absolute, "src", "test", "resources"),
|
|
104
|
+
project.absolute,
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
/** Treat `0.0.0.0` and a blank host as loopback for probing purposes. */
|
|
108
|
+
function asProbeHost(host) {
|
|
109
|
+
const trimmed = (host ?? "").trim();
|
|
110
|
+
if (trimmed === "" || trimmed === "0.0.0.0" || trimmed === "::")
|
|
111
|
+
return "127.0.0.1";
|
|
112
|
+
return trimmed;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Read a Spring project's configuration and derive the addresses it could serve on.
|
|
116
|
+
*
|
|
117
|
+
* Only local files are read. A project that keeps its port in Nacos or an environment
|
|
118
|
+
* variable yields the default 8080 plus a note, rather than pretending to know.
|
|
119
|
+
*
|
|
120
|
+
* @param project - the project root and its repository-relative directory.
|
|
121
|
+
* @returns candidates in priority order, plus what was inspected.
|
|
122
|
+
*/
|
|
123
|
+
export async function detectSpringEndpoints(project) {
|
|
124
|
+
const inspected = [];
|
|
125
|
+
const candidates = [];
|
|
126
|
+
let port;
|
|
127
|
+
let contextPath;
|
|
128
|
+
let address;
|
|
129
|
+
// Profile-specific files win over the base file, and `src/main` wins over `src/test`.
|
|
130
|
+
for (const dir of configLocations(project)) {
|
|
131
|
+
for (const name of CONFIG_FILES) {
|
|
132
|
+
const absolute = path.join(dir, name);
|
|
133
|
+
let text;
|
|
134
|
+
try {
|
|
135
|
+
text = await readFile(absolute, "utf8");
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const relative = path.relative(path.dirname(project.absolute), absolute).replace(/\\/g, "/");
|
|
141
|
+
const portHit = readKey(name, text, "server.port");
|
|
142
|
+
const contextHit = readKey(name, text, "server.servlet.context-path");
|
|
143
|
+
const addressHit = readKey(name, text, "server.address");
|
|
144
|
+
const summary = [
|
|
145
|
+
portHit ? `port=${portHit.value}` : null,
|
|
146
|
+
contextHit ? `context-path=${contextHit.value}` : null,
|
|
147
|
+
].filter(Boolean).join(", ");
|
|
148
|
+
inspected.push({ file: relative, found: summary === "" ? null : summary });
|
|
149
|
+
// Later files override earlier ones; a profile file therefore wins.
|
|
150
|
+
if (portHit)
|
|
151
|
+
port = { value: portHit.value, file: relative, line: portHit.line };
|
|
152
|
+
if (contextHit)
|
|
153
|
+
contextPath = { value: contextHit.value, file: relative, line: contextHit.line };
|
|
154
|
+
if (addressHit)
|
|
155
|
+
address = { value: addressHit.value, file: relative, line: addressHit.line };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Profile files are siblings named `application-<profile>.yml`; a project that
|
|
159
|
+
// activates one usually keeps the port there. Read them after the base files.
|
|
160
|
+
for (const dir of configLocations(project)) {
|
|
161
|
+
let names;
|
|
162
|
+
try {
|
|
163
|
+
names = await (await import("node:fs/promises")).readdir(dir);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
for (const name of names.sort()) {
|
|
169
|
+
if (!/^application-.+\.(yml|yaml|properties)$/.test(name))
|
|
170
|
+
continue;
|
|
171
|
+
const absolute = path.join(dir, name);
|
|
172
|
+
let text;
|
|
173
|
+
try {
|
|
174
|
+
text = await readFile(absolute, "utf8");
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const relative = path.relative(path.dirname(project.absolute), absolute).replace(/\\/g, "/");
|
|
180
|
+
const portHit = readKey(name, text, "server.port");
|
|
181
|
+
const contextHit = readKey(name, text, "server.servlet.context-path");
|
|
182
|
+
const summary = [
|
|
183
|
+
portHit ? `port=${portHit.value}` : null,
|
|
184
|
+
contextHit ? `context-path=${contextHit.value}` : null,
|
|
185
|
+
].filter(Boolean).join(", ");
|
|
186
|
+
inspected.push({ file: relative, found: summary === "" ? null : summary });
|
|
187
|
+
if (portHit)
|
|
188
|
+
port = { value: portHit.value, file: relative, line: portHit.line };
|
|
189
|
+
if (contextHit)
|
|
190
|
+
contextPath = { value: contextHit.value, file: relative, line: contextHit.line };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const fallback = port === undefined;
|
|
194
|
+
const resolvedPort = Number.parseInt(port?.value ?? "", 10);
|
|
195
|
+
const host = asProbeHost(address?.value);
|
|
196
|
+
const safePort = Number.isFinite(resolvedPort) && resolvedPort > 0 && resolvedPort < 65_536
|
|
197
|
+
? resolvedPort
|
|
198
|
+
: DEFAULT_PORT;
|
|
199
|
+
// A context path is usually written with a leading slash; normalise both ways.
|
|
200
|
+
const rawContext = (contextPath?.value ?? "").trim();
|
|
201
|
+
const normalisedContext = rawContext === "" || rawContext === "/"
|
|
202
|
+
? ""
|
|
203
|
+
: rawContext.startsWith("/") ? rawContext : `/${rawContext}`;
|
|
204
|
+
const baseUrl = `http://${host}:${safePort}${normalisedContext}`;
|
|
205
|
+
const sourceFile = port?.file ?? contextPath?.file;
|
|
206
|
+
candidates.push({
|
|
207
|
+
baseUrl: baseUrl.replace(/\/$/, ""),
|
|
208
|
+
source: sourceFile === undefined ? "默认值" : `${sourceFile}:${(port ?? contextPath).line}`,
|
|
209
|
+
detail: fallback
|
|
210
|
+
? `未找到 server.port,使用 Spring 默认端口 ${DEFAULT_PORT}`
|
|
211
|
+
: `port=${safePort}${normalisedContext === "" ? "" : `, context-path=${normalisedContext}`}`,
|
|
212
|
+
});
|
|
213
|
+
// A service bound to a specific interface still answers on loopback in practice.
|
|
214
|
+
if (host !== "127.0.0.1" && host !== "localhost") {
|
|
215
|
+
candidates.push({
|
|
216
|
+
baseUrl: `http://127.0.0.1:${safePort}${normalisedContext}`,
|
|
217
|
+
source: "回环地址",
|
|
218
|
+
detail: "server.address 指定了具体网卡,同时尝试本机回环",
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return { candidates, inspected, fallback };
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Ask each candidate for its OpenAPI document.
|
|
225
|
+
*
|
|
226
|
+
* A `HEAD`/JSON sniff would be cheaper, but Spring returns the document with a 200 and
|
|
227
|
+
* a JSON body, and a wrong-guess port answers nothing at all — so the request itself is
|
|
228
|
+
* the cheapest reliable probe.
|
|
229
|
+
*
|
|
230
|
+
* @param candidates - addresses to try, in priority order.
|
|
231
|
+
* @returns the first document found, or the reasons every candidate failed.
|
|
232
|
+
*/
|
|
233
|
+
export async function probeRunningServices(candidates, options = {}) {
|
|
234
|
+
const portFromLocalConfig = options.portFromLocalConfig ?? true;
|
|
235
|
+
const started = Date.now();
|
|
236
|
+
const tried = [];
|
|
237
|
+
for (const candidate of candidates) {
|
|
238
|
+
// `springdoc.api-docs.path` is configurable, but the default is by far the most
|
|
239
|
+
// common; a miss here still tells the operator the service is down.
|
|
240
|
+
const url = `${candidate.baseUrl}/v3/api-docs`;
|
|
241
|
+
const controller = new AbortController();
|
|
242
|
+
const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);
|
|
243
|
+
try {
|
|
244
|
+
const response = await fetch(url, { signal: controller.signal, redirect: "follow" });
|
|
245
|
+
if (!response.ok) {
|
|
246
|
+
tried.push({ baseUrl: candidate.baseUrl, reason: `HTTP ${response.status}` });
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const text = await response.text();
|
|
250
|
+
const parsed = JSON.parse(text);
|
|
251
|
+
if (!parsed || typeof parsed.paths !== "object") {
|
|
252
|
+
tried.push({ baseUrl: candidate.baseUrl, reason: "返回内容不是 OpenAPI 文档" });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
return { ok: true, baseUrl: candidate.baseUrl, document: text, elapsedMs: Date.now() - started };
|
|
256
|
+
}
|
|
257
|
+
catch (reason) {
|
|
258
|
+
const aborted = reason instanceof Error && reason.name === "AbortError";
|
|
259
|
+
tried.push({
|
|
260
|
+
baseUrl: candidate.baseUrl,
|
|
261
|
+
reason: aborted ? `${PROBE_TIMEOUT_MS / 1000} 秒内无响应` : "连接失败",
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
clearTimeout(timer);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/*
|
|
269
|
+
* The message has to distinguish "not running" from "guessed the wrong port".
|
|
270
|
+
*
|
|
271
|
+
* A project that keeps `server.port` in Nacos, a launch argument or an environment
|
|
272
|
+
* variable has no local value, so detection falls back to 8080 and the probe fails
|
|
273
|
+
* against an address that was never going to answer. Telling that operator "start
|
|
274
|
+
* your service" is wrong — their service is running, on a port we never saw. The
|
|
275
|
+
* caller passes whether the port was declared locally so this can say so.
|
|
276
|
+
*/
|
|
277
|
+
return {
|
|
278
|
+
ok: false,
|
|
279
|
+
tried,
|
|
280
|
+
message: candidates.length === 0
|
|
281
|
+
? "没有找到可用的服务地址。请在右侧环境里手动填写服务地址。"
|
|
282
|
+
: portFromLocalConfig
|
|
283
|
+
? "服务没有响应。请先启动项目,再点「获取接口文档」;如果地址不对,可在右侧环境里改成实际地址。"
|
|
284
|
+
: "没有在项目的配置文件里找到 server.port,下面试过的是猜测的地址。请在右侧环境里手动填写服务地址,再点「获取接口文档」。",
|
|
285
|
+
};
|
|
286
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { detectSpringEndpoints, probeRunningServices } from "./api-workbench-endpoint-detect.js";
|
|
3
4
|
import { findSpringProjects, generateSpringDocument, writeGeneratedSpec } from "./api-workbench-spring.js";
|
|
4
5
|
import { parseAssertions } from "./api-workbench-assertions.js";
|
|
5
6
|
import { sendJson } from "../routes.js";
|
|
@@ -342,6 +343,74 @@ export async function handleApiWorkbenchRequest(req, res, deps, pathname) {
|
|
|
342
343
|
* Generating runs the user's build and application, so it is a POST behind the
|
|
343
344
|
* mutation gate rather than something a GET does as a side effect.
|
|
344
345
|
*/
|
|
346
|
+
/*
|
|
347
|
+
* Obtain a document from a service that is already running.
|
|
348
|
+
*
|
|
349
|
+
* This is the cheap path and it is the default: read the project's own
|
|
350
|
+
* configuration for the port, then ask that address for `/v3/api-docs`. No
|
|
351
|
+
* build, no process, no side effects — and in the common case the developer
|
|
352
|
+
* already has the service up in their IDE.
|
|
353
|
+
*
|
|
354
|
+
* It is a POST because it is a deliberate action from the panel, and it is
|
|
355
|
+
* gated because it writes a document into the workspace's generated directory.
|
|
356
|
+
* It never starts anything: when nothing answers, the caller is told which
|
|
357
|
+
* addresses were tried so they can start the service themselves.
|
|
358
|
+
*/
|
|
359
|
+
if (route === "specs/obtain" && method === "POST") {
|
|
360
|
+
const gate = deps.gateMutation(req);
|
|
361
|
+
if (!gate.ok) {
|
|
362
|
+
sendApiError(res, gate.status, gate.code, gate.message);
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
const projects = await findSpringProjects(deps.repoRoot);
|
|
366
|
+
if (projects.length === 0) {
|
|
367
|
+
sendJson(res, 200, {
|
|
368
|
+
ok: false,
|
|
369
|
+
code: "NOT_SPRING",
|
|
370
|
+
message: "这个工作区里没有找到 Maven 或 Gradle 项目。",
|
|
371
|
+
candidates: [], inspected: [],
|
|
372
|
+
});
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
const detections = await Promise.all(projects.map(async (project) => ({
|
|
376
|
+
project,
|
|
377
|
+
detection: await detectSpringEndpoints(project),
|
|
378
|
+
})));
|
|
379
|
+
const candidates = detections.flatMap(({ project, detection }) => detection.candidates.map((candidate) => ({ ...candidate, project: project.dir })));
|
|
380
|
+
const inspected = detections.flatMap(({ detection }) => detection.inspected);
|
|
381
|
+
// If no project declared a port locally, the probe is aimed at a guess and a
|
|
382
|
+
// failure means "we do not know the address", not "the service is down".
|
|
383
|
+
const portFromLocalConfig = detections.some(({ detection }) => !detection.fallback);
|
|
384
|
+
const probe = await probeRunningServices(candidates, { portFromLocalConfig });
|
|
385
|
+
if (!probe.ok) {
|
|
386
|
+
sendJson(res, 200, {
|
|
387
|
+
ok: false,
|
|
388
|
+
code: "SERVICE_NOT_RUNNING",
|
|
389
|
+
message: probe.message,
|
|
390
|
+
candidates, inspected, tried: probe.tried,
|
|
391
|
+
});
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
const owner = candidates.find((candidate) => candidate.baseUrl === probe.baseUrl)?.project ?? ".";
|
|
395
|
+
await writeGeneratedSpec(deps.appData.root, path.basename(generatedDirFor(deps)), owner, probe.document);
|
|
396
|
+
let endpoints = 0;
|
|
397
|
+
try {
|
|
398
|
+
const parsed = JSON.parse(probe.document);
|
|
399
|
+
endpoints = parsed.paths === undefined ? 0 : Object.keys(parsed.paths).length;
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
// A document we just fetched failing to parse is reported as zero endpoints.
|
|
403
|
+
}
|
|
404
|
+
sendJson(res, 200, {
|
|
405
|
+
ok: true,
|
|
406
|
+
baseUrl: probe.baseUrl,
|
|
407
|
+
endpoints,
|
|
408
|
+
elapsedMs: probe.elapsedMs,
|
|
409
|
+
candidates, inspected,
|
|
410
|
+
message: `已从 ${probe.baseUrl} 获取 ${endpoints} 个接口。`,
|
|
411
|
+
});
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
345
414
|
if (route === "spring/generate" && method === "POST") {
|
|
346
415
|
await handleGenerateSpringSpec(req, res, deps);
|
|
347
416
|
return true;
|
|
@@ -29,6 +29,20 @@ import { isShellTool } from "./tool-preview.js";
|
|
|
29
29
|
import { projectPresentationArgs, projectFileResult, hashedPreview, boundedJson, safeText, textOfResult } from "./tool-presentation-projection.js";
|
|
30
30
|
/** Bounded preview stored on the event ring / SSE (not the live tool payload). */
|
|
31
31
|
export const OPERATION_PREVIEW_MAX_CHARS = 4000;
|
|
32
|
+
/**
|
|
33
|
+
* Skill guides get a larger ceiling than other tool previews.
|
|
34
|
+
*
|
|
35
|
+
* A skill's whole purpose is the instruction document it loads, and real ones
|
|
36
|
+
* run 4–22 KB (measured across `skills/*\/SKILL.md`). At the shared 4,000-char
|
|
37
|
+
* limit almost every skill preview was cut, so the card said 「指引已截断」 as a
|
|
38
|
+
* matter of course — which reads like the load failed. The model always
|
|
39
|
+
* received the full guide; only the stored preview was clipped.
|
|
40
|
+
*
|
|
41
|
+
* 24,000 covers the largest guide in the repo with headroom and stays a bounded
|
|
42
|
+
* event: previews are per-call records, and this is the one call whose payload
|
|
43
|
+
* IS the document being fetched.
|
|
44
|
+
*/
|
|
45
|
+
export const SKILL_PREVIEW_MAX_CHARS = 24_000;
|
|
32
46
|
const OPERATION_PREVIEW_TRUNCATION_SUFFIX = "…[truncated]";
|
|
33
47
|
function boundedRedactedText(value, maxChars = OPERATION_PREVIEW_MAX_CHARS) {
|
|
34
48
|
if (typeof value !== "string" || !value.trim())
|
|
@@ -318,13 +332,22 @@ export function projectCommandArgs(toolName, value) {
|
|
|
318
332
|
return { preview, previewHash: createHash("sha256").update(preview).digest("hex") };
|
|
319
333
|
}
|
|
320
334
|
/** Prefer readable Pi ToolResult text content; fall back to JSON shell. */
|
|
321
|
-
function projectToolResultPreview(value) {
|
|
322
|
-
|
|
323
|
-
|
|
335
|
+
function projectToolResultPreview(value, maxChars = OPERATION_PREVIEW_MAX_CHARS) {
|
|
336
|
+
/*
|
|
337
|
+
* `boundedRedactedText` clips but reports nothing, so the caller cannot tell a
|
|
338
|
+
* complete preview from a clipped one. The suffix is the only signal, and the
|
|
339
|
+
* skill card needs it: without the flag a 24k guide that got clipped looked
|
|
340
|
+
* complete, so the note explaining the omission never rendered.
|
|
341
|
+
*/
|
|
342
|
+
const build = (text) => {
|
|
343
|
+
const preview = boundedRedactedText(text, maxChars) ?? "";
|
|
324
344
|
return {
|
|
325
345
|
preview,
|
|
326
346
|
previewHash: createHash("sha256").update(preview).digest("hex"),
|
|
327
347
|
};
|
|
348
|
+
};
|
|
349
|
+
if (typeof value === "string") {
|
|
350
|
+
return build(value);
|
|
328
351
|
}
|
|
329
352
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
330
353
|
const record = value;
|
|
@@ -339,27 +362,14 @@ function projectToolResultPreview(value) {
|
|
|
339
362
|
texts.push(item.text);
|
|
340
363
|
}
|
|
341
364
|
if (texts.length > 0) {
|
|
342
|
-
|
|
343
|
-
const preview = boundedRedactedText(joined) ?? "";
|
|
344
|
-
return {
|
|
345
|
-
preview,
|
|
346
|
-
previewHash: createHash("sha256").update(preview).digest("hex"),
|
|
347
|
-
};
|
|
365
|
+
return build(texts.join("\n"));
|
|
348
366
|
}
|
|
349
367
|
}
|
|
350
368
|
if (typeof record.text === "string") {
|
|
351
|
-
|
|
352
|
-
return {
|
|
353
|
-
preview,
|
|
354
|
-
previewHash: createHash("sha256").update(preview).digest("hex"),
|
|
355
|
-
};
|
|
369
|
+
return build(record.text);
|
|
356
370
|
}
|
|
357
371
|
if (typeof record.output === "string") {
|
|
358
|
-
|
|
359
|
-
return {
|
|
360
|
-
preview,
|
|
361
|
-
previewHash: createHash("sha256").update(preview).digest("hex"),
|
|
362
|
-
};
|
|
372
|
+
return build(record.output);
|
|
363
373
|
}
|
|
364
374
|
}
|
|
365
375
|
return boundedRedactedJson(value);
|
|
@@ -438,7 +448,9 @@ export function projectChatToolEventPayload(input) {
|
|
|
438
448
|
const { preview, previewHash } = isShellTool(input.toolName) ? projectCommandResultPreview(input.value)
|
|
439
449
|
: input.kind === "tool_result" && input.toolName === "Agent"
|
|
440
450
|
? projectExploreResultPreview(input.value) ?? projectToolResultPreview(input.value)
|
|
441
|
-
: fileResult ? hashedPreview(fileResult)
|
|
451
|
+
: fileResult ? hashedPreview(fileResult)
|
|
452
|
+
: input.toolName === "skill" ? projectToolResultPreview(input.value, SKILL_PREVIEW_MAX_CHARS)
|
|
453
|
+
: projectToolResultPreview(input.value);
|
|
442
454
|
if (input.kind === "tool_update") {
|
|
443
455
|
return {
|
|
444
456
|
toolCallId: input.toolCallId,
|
|
@@ -17,10 +17,13 @@ import { parseAssertions } from "../../api-workbench-assertions.js";
|
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
18
|
import path from "node:path";
|
|
19
19
|
import { scanSpecsSnapshot, parseQueryParams, ApiWorkbenchCoreError, } from "../../api-workbench-core.js";
|
|
20
|
+
import { detectSpringEndpoints, probeRunningServices } from "../../api-workbench-endpoint-detect.js";
|
|
21
|
+
import { findSpringProjects } from "../../api-workbench-spring.js";
|
|
20
22
|
const APIWB_TOOLS_DESCRIPTION = "API workbench: list every endpoint (api_scan), look up ONE endpoint's parameters, request body and responses " +
|
|
21
23
|
"(api_endpoint), send one sandboxed HTTP request with environment {{key}} substitution (api_send), " +
|
|
22
24
|
"list/upsert environment prefixes + variables (api_environments), review send history (api_history), " +
|
|
23
|
-
"
|
|
25
|
+
"pull a one-shot debugging brief (api_debug), and explain why the interface panel is empty " +
|
|
26
|
+
"plus what to do next (api_spec_status). " +
|
|
24
27
|
"Prefer api_endpoint over api_scan once you know the path: a real service has hundreds of routes and only " +
|
|
25
28
|
"one of them matters at a time. Use either before guessing endpoints; environments carry non-secret " +
|
|
26
29
|
"key=value variables. Never submit credential values through tool arguments.";
|
|
@@ -213,6 +216,79 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
213
216
|
}, { signal }));
|
|
214
217
|
},
|
|
215
218
|
}),
|
|
219
|
+
defineTool({
|
|
220
|
+
name: "api_spec_status",
|
|
221
|
+
label: "API contract status",
|
|
222
|
+
/*
|
|
223
|
+
* Answers "why is my interface panel empty", which the panel itself cannot say.
|
|
224
|
+
*
|
|
225
|
+
* The workbench has three ways to learn a contract and they fail for different
|
|
226
|
+
* reasons — no Spring project, no springdoc dependency, service not running,
|
|
227
|
+
* no document in the repo. A model asked to help needs to know which of those
|
|
228
|
+
* it is before it can suggest a fix, and the operator needs an answer they can
|
|
229
|
+
* act on rather than a blank list.
|
|
230
|
+
*/
|
|
231
|
+
description: "Explain the API contract situation in this workspace and what to do next: whether Spring projects " +
|
|
232
|
+
"were found, whether they declare springdoc, where the service is expected to listen, and whether " +
|
|
233
|
+
"it answers right now. Use this when the operator asks why the interface panel is empty or how to " +
|
|
234
|
+
"get their endpoints into it.",
|
|
235
|
+
promptSnippet: "Explain why the API panel is empty and what to do next.",
|
|
236
|
+
parameters: Type.Object({}, { additionalProperties: false }),
|
|
237
|
+
async execute() {
|
|
238
|
+
return run("APIWB_SPEC_STATUS_FAILED", async () => {
|
|
239
|
+
const projects = await findSpringProjects(opts.repoRoot);
|
|
240
|
+
const withDocs = projects.filter((project) => project.hasOpenApiDependency);
|
|
241
|
+
const detections = await Promise.all(projects.map(async (project) => ({ project, detection: await detectSpringEndpoints(project) })));
|
|
242
|
+
const candidates = detections.flatMap(({ project, detection }) => detection.candidates.map((candidate) => ({ ...candidate, project: project.dir })));
|
|
243
|
+
// A port that no project declared locally was a guess, so a failed probe
|
|
244
|
+
// says nothing about whether the service is up.
|
|
245
|
+
const portFromLocalConfig = detections.some(({ detection }) => !detection.fallback);
|
|
246
|
+
const probe = candidates.length > 0
|
|
247
|
+
? await probeRunningServices(candidates, { portFromLocalConfig })
|
|
248
|
+
: null;
|
|
249
|
+
const snapshot = await scanWithGenerated();
|
|
250
|
+
const endpoints = snapshot.specs.reduce((total, spec) => total + (spec.endpoints?.length ?? 0), 0);
|
|
251
|
+
// A plain-language next step is the point of this tool; the model relays it.
|
|
252
|
+
const advice = [];
|
|
253
|
+
if (projects.length === 0) {
|
|
254
|
+
advice.push("这个工作区里没有 Maven 或 Gradle 项目,接口面板只能依赖仓库里的 OpenAPI 文件或代码扫描。");
|
|
255
|
+
}
|
|
256
|
+
else if (withDocs.length === 0) {
|
|
257
|
+
advice.push("找到了 Spring 项目,但 pom 里没有 springdoc 依赖。加上 springdoc-openapi-starter-webmvc-ui 后重启服务,就能获取完整接口文档。");
|
|
258
|
+
}
|
|
259
|
+
if (probe !== null && probe.ok) {
|
|
260
|
+
advice.push(`服务已在 ${probe.baseUrl} 运行,可以直接获取接口文档。`);
|
|
261
|
+
}
|
|
262
|
+
else if (candidates.length > 0) {
|
|
263
|
+
if (portFromLocalConfig) {
|
|
264
|
+
advice.push(`没有探测到运行中的服务。请先启动项目(预计端口 ${candidates[0].baseUrl}),然后在接口调试台点「获取接口文档」。`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// Never tell the operator to "start the service" here: the address
|
|
268
|
+
// was a guess, so their service may well be running on a port this
|
|
269
|
+
// workspace cannot see (Nacos, a launch argument, an env var).
|
|
270
|
+
advice.push("项目的配置文件里没有 server.port,端口可能来自 Nacos、启动参数或环境变量。" +
|
|
271
|
+
`试过 ${candidates[0].baseUrl} 但没有响应。` +
|
|
272
|
+
"请让用户确认服务的实际地址,在接口调试台右侧的环境里手动填写,再点「获取接口文档」。");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
ok: true,
|
|
277
|
+
projects: projects.map((project) => ({
|
|
278
|
+
dir: project.dir,
|
|
279
|
+
buildTool: project.buildTool,
|
|
280
|
+
hasOpenApiDependency: project.hasOpenApiDependency,
|
|
281
|
+
})),
|
|
282
|
+
candidates,
|
|
283
|
+
serviceRunning: probe?.ok === true,
|
|
284
|
+
runningAt: probe?.ok === true ? probe.baseUrl : null,
|
|
285
|
+
documentedEndpoints: endpoints,
|
|
286
|
+
specSources: snapshot.specs.map((spec) => ({ id: spec.id, endpoints: spec.endpoints?.length ?? 0 })),
|
|
287
|
+
advice,
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
}),
|
|
216
292
|
defineTool({
|
|
217
293
|
name: "api_debug",
|
|
218
294
|
label: "API debug brief",
|
|
@@ -2013,15 +2013,35 @@ export async function handleListChatSubagentTasks(_req, res, deps, workspaceScop
|
|
|
2013
2013
|
diagnostics: projection.diagnostics,
|
|
2014
2014
|
});
|
|
2015
2015
|
}
|
|
2016
|
-
async function subagentCatalogFor(deps, sessionId, storedMessages) {
|
|
2016
|
+
async function subagentCatalogFor(deps, sessionId, storedMessages, groupedChildren, options) {
|
|
2017
2017
|
const owner = deps.subagents ? await deps.subagents.get(sessionId).catch(() => undefined) : undefined;
|
|
2018
2018
|
const rootSessionId = owner?.rootSessionId ?? sessionId;
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2019
|
+
/*
|
|
2020
|
+
* Prefer the caller's single grouped scan. Falling back per session would
|
|
2021
|
+
* restore the `sessions × records` cost this exists to remove.
|
|
2022
|
+
*/
|
|
2023
|
+
const storedChildren = groupedChildren
|
|
2024
|
+
? (groupedChildren.get(rootSessionId) ?? [])
|
|
2025
|
+
: deps.subagents
|
|
2026
|
+
? await deps.subagents.listByRoot(rootSessionId)
|
|
2027
|
+
: [];
|
|
2028
|
+
/*
|
|
2029
|
+
* `events.snapshot()` materializes the whole event ring, loading it from disk
|
|
2030
|
+
* for any session that is not already hot. A list screen does that for every
|
|
2031
|
+
* row, which is what made opening a workspace with many conversations slow.
|
|
2032
|
+
*
|
|
2033
|
+
* `storedMessages` already carries the same `Agent` tool results, so a cold
|
|
2034
|
+
* row can be summarized without the ring. Only a session with a live turn can
|
|
2035
|
+
* have events the stored messages do not: its catalog stays exact, and it is
|
|
2036
|
+
* the one row the reader is watching.
|
|
2037
|
+
*/
|
|
2038
|
+
let events = [];
|
|
2039
|
+
if (!options?.skipEventRing) {
|
|
2040
|
+
events = deps.events?.snapshot(sessionId) ?? [];
|
|
2041
|
+
}
|
|
2022
2042
|
return projectSubagentCatalog({
|
|
2023
2043
|
sessionId: rootSessionId,
|
|
2024
|
-
events
|
|
2044
|
+
events,
|
|
2025
2045
|
live: typeof deps.runtime?.listExploreRunStates === "function"
|
|
2026
2046
|
? deps.runtime.listExploreRunStates(sessionId)
|
|
2027
2047
|
: [],
|
|
@@ -2354,12 +2374,25 @@ export async function handlePromptChatSubagent(req, res, deps, parentSessionId,
|
|
|
2354
2374
|
*/
|
|
2355
2375
|
export async function listChatSessionSummaries(deps, ownerWorkspaceId) {
|
|
2356
2376
|
const sessions = await deps.store.list({ includeArchived: true });
|
|
2377
|
+
/*
|
|
2378
|
+
* One directory scan for every row's children.
|
|
2379
|
+
*
|
|
2380
|
+
* `subagentCatalogFor` calls `listByRoot`, which re-reads and re-parses every
|
|
2381
|
+
* stored child record. Calling it per session made the list cost
|
|
2382
|
+
* `sessions × childRecords` — the thing that made a workspace with many
|
|
2383
|
+
* conversations slow to open. The grouped map is built once and reused.
|
|
2384
|
+
*/
|
|
2385
|
+
const groupedChildren = deps.subagents
|
|
2386
|
+
? await deps.subagents.listGroupedByRoot().catch(() => undefined)
|
|
2387
|
+
: undefined;
|
|
2357
2388
|
return Promise.all(sessions.map(async (session) => {
|
|
2358
2389
|
const active = deps.events?.getActiveTurn(session.sessionId);
|
|
2359
2390
|
const workspaceId = ownerWorkspaceId ?? session.workspaceId;
|
|
2360
2391
|
let subagentSummary;
|
|
2361
2392
|
if (deps.events || deps.runtime || deps.subagents) {
|
|
2362
|
-
const catalog = await subagentCatalogFor(deps, session.sessionId, session.messages
|
|
2393
|
+
const catalog = await subagentCatalogFor(deps, session.sessionId, session.messages, groupedChildren,
|
|
2394
|
+
// Only a live turn can hold events the stored messages lack.
|
|
2395
|
+
{ skipEventRing: active === undefined });
|
|
2363
2396
|
const activeRuns = catalog.items.filter((item) => item.status === "starting" || item.status === "working").length;
|
|
2364
2397
|
const failed = catalog.items.filter((item) => item.status === "failed").length;
|
|
2365
2398
|
subagentSummary = { total: catalog.items.length, active: activeRuns, failed };
|