@tea-agent/loop-agent 0.53.0-next.1 → 0.53.0-next.3
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 +18 -52
- package/dist/build-stamp.json +3 -3
- package/dist/shared/pi-context-pressure/compaction-policy.js +22 -34
- package/dist/shared/pi-context-pressure/index.js +1 -1
- package/dist/worker/console/automation-actions.js +62 -7
- package/dist/worker/console/chat/api-workbench-core.js +131 -4
- package/dist/worker/console/chat/api-workbench-schema.js +278 -0
- package/dist/worker/console/chat/api-workbench-spring.js +333 -0
- package/dist/worker/console/chat/api-workbench.js +88 -2
- package/dist/worker/console/chat/human-gate-card.js +16 -1
- package/dist/worker/console/chat/image-cache.js +39 -8
- package/dist/worker/console/chat/pi-runtime/custom-tools/apiworkbench-tools.js +120 -5
- package/dist/worker/console/chat/pi-runtime.js +2 -3
- package/dist/worker/console/chat/provider-error.js +12 -2
- package/dist/worker/console/chat/repo-walk.js +8 -0
- package/dist/worker/console/chat/routes.js +125 -13
- package/dist/worker/console/chat/todo-diff.js +90 -0
- package/dist/worker/console/chat/turn-process.js +3 -0
- package/dist/worker/console/network-proxy-settings.js +67 -1
- package/dist/worker/console/operator-actions.js +25 -0
- package/dist/worker/console/pi-compaction-settings.js +16 -13
- package/dist/worker/console/server.js +20 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-CR1jj_rz.js → abnfDiagram-N423BO3Z-9YdcTSkA.js} +1 -1
- package/dist/worker/console/static/assets/{arc-CjxcQfEu.js → arc-5o9a24RM.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-D-3u2qFL.js → architectureDiagram-T3A2C74G-kk-Y4K8w.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Bdr7gWVo.js → blockDiagram-VBNYF7ZC-BuMyp-i-.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-hQHNe5T3.js → c4Diagram-5PPSVZJV-BnAbUXQM.js} +1 -1
- package/dist/worker/console/static/assets/channel-DzpJs7JM.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-BEg_su6q.js → chunk-2GRJ4B5K-sQ2VjuFx.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-DZnV6VTC.js → chunk-2Q5K7J3B-CbkqzTV8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-Dg0LzAqO.js → chunk-5RXB4S5H-CaP8JTC3.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-D2vqr52W.js → chunk-5VM5RSS4-D7yUFtwu.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-D8We_g6R.js → chunk-6Q2QTUOP-zowLlgmO.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DbEU8drD.js → chunk-GF5L2VYU-KGzLFdSC.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-Boi8TJYN.js → chunk-JWPE2WC7-DuVIxg_I.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CjJmKa9f.js → chunk-KBJHAD2P-CXP8iZrQ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-C-KV-ag7.js → chunk-RYQCIY6F-DASfOCYV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DZlTonsZ.js → chunk-XXDRQBXY-DFwLDf-r.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-ClK7LSSv.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-ClK7LSSv.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BIvFe3yn.js → cose-bilkent-JH36ORCC-CIrJSuNM.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-BOBPfv8u.js → cynefinDiagram-MW4NZA55-BrI5M-XP.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BF54orLO.js → dagre-VZM6K2ZE-BEJlUQi2.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CxjAP2AP.js → diagram-7IWD3JNH-Buw7nAqS.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BXYkuNGt.js → diagram-B4RE2ZJO-DHURLBbb.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-DQTu-2Iy.js → diagram-LBJQPF4R-CEFuptxk.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-DNURuIYc.js → diagram-Q27KOJAE-Cejgl71p.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-D69uANY8.js → diagram-UB23O5K3-Bwxq3Xoa.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-C658EcrV.js → ebnfDiagram-BXEA7PRR-i4NNenm0.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-BRccYtAl.js → erDiagram-JOGREHBK-BaSp03BR.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-DnIR4sLs.js → flowDiagram-UKHOOZJN-CQtgCCPg.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Bo3eWFVC.js → ganttDiagram-PKOTCBZU-DkS9Vbt8.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-EyWDCNU_.js → gitGraphDiagram-DS77QQ5N-Dm64UQgY.js} +1 -1
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-B0Eld9u0.js → infoDiagram-6WML65LV-BpcLrRRV.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DsJQiJ27.js → ishikawaDiagram-WSZJBQD7-DFjxaE3Q.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-fpE0yqjC.js → journeyDiagram-NVQOT4AX-G6kuLGYK.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Dq9IrDdT.js → kanban-definition-27J2QSJJ-DistDdnp.js} +1 -1
- package/dist/worker/console/static/assets/{linear-CFV4BDyf.js → linear-Cadcj4Jf.js} +1 -1
- package/dist/worker/console/static/assets/main-CKu0wCrM.js +654 -0
- package/dist/worker/console/static/assets/main-DpBoCiky.css +1 -0
- package/dist/worker/console/static/assets/{mermaid.core-BMMXqtrB.js → mermaid.core-CVqQBsGx.js} +4 -4
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-DurrK_Gi.js → mindmap-definition-FAOFIHXS-oIAAXLn3.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-CzZayNy2.js → pegDiagram-VL7TDLO6-BgBPFLA0.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-B1W7Y0cE.js → pieDiagram-7S7Q4E2Y-RTyZdL9S.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BdbL83CU.js → quadrantDiagram-CIZ2JOQS-BHEYQMZx.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-W-bQpd18.js → railroadDiagram-AXF67PYL-B2JIrks2.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-C9bi4tQJ.js → requirementDiagram-LRYGKXZP-TJ5_MWbY.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-D4kO56Wd.js → sankeyDiagram-W5VNT64P-BzjUsr0j.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CIbesK1e.js → sequenceDiagram-SI44F4Z6-DrmrPPVE.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-kFN3yUBr.js → sheet-workbook-DCQgjy0Q.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-Dk4XAK7C.js → sizeCapture-X5ZJPWSS-BLp8F5fC.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-Bz9B6UZ7.js → stateDiagram-OKZ733FA-5MNm447q.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-gP-t-MQJ.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-qLEds93n.js → swimlanes-SLNWSIFB-Cs2RUkNq.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-D6MJJUTV.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-C9rVFC0h.js → timeline-definition-Z64GVDOM-BoeTHoWc.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-CoKJ9hU0.js → vennDiagram-T6HMQDX7-DFWej-Mm.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-tHz_S7-L.js → wardleyDiagram-T6FBY63Y-BcD0_2m5.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-DKzKYnvG.js → xychartDiagram-ELKLHX3M-y4PQYZiq.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/markdown-incremental.js +138 -0
- package/dist/worker/console/static-src/operator-chat/automation-catalog-model.js +43 -0
- package/dist/worker/console/static-src/operator-chat/composer-drop.js +138 -0
- package/dist/worker/console/static-src/operator-chat/composer-image-paths.js +25 -5
- package/dist/worker/console/static-src/operator-chat/composer-image-preview.js +115 -0
- package/dist/worker/console/static-src/operator-chat/composer-session-ledger.js +44 -2
- package/dist/worker/console/static-src/operator-chat/composer-upload.js +115 -0
- package/dist/worker/console/static-src/operator-chat/gate-expiry.js +43 -0
- package/dist/worker/console/static-src/operator-chat/process-label.js +15 -2
- package/dist/worker/console/static-src/operator-chat/schedule-relative-time.js +54 -0
- package/dist/worker/console/static-src/operator-chat/schedule-rule-summary.js +213 -0
- package/dist/worker/console/static-src/operator-chat/tasks-model.js +4 -0
- package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +8 -0
- package/dist/worker/console/static-src/operator-chat/turn-process-disclosure.js +12 -0
- package/dist/worker/console/static-src/operator-chat/turn-state-projection.js +51 -0
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +22 -2
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +15 -1
- package/dist/worker/console/static-src/operator-chat/useComposer.js +290 -21
- package/dist/worker/console/static-src/operator-chat/useSessionAutomationCounts.js +98 -0
- package/dist/worker/console/static-src/pages/api-request-template.js +144 -0
- package/dist/worker/console/static-src/session-search-shortcut.js +38 -0
- package/dist/worker/console/version-notes-comparison.js +52 -0
- package/dist/worker/console/version-notes.js +16 -1
- package/dist/worker/console/workspace-context.js +10 -0
- package/dist/worker/observe/static/console-theme.css +50 -3
- package/dist/worker/observe/static/console-theme.js +86 -1
- package/dist/worker/scheduler/automation-across-workspaces.js +120 -0
- package/docs/README.md +1 -0
- package/docs/operations/README.md +1 -0
- package/package.json +3 -3
- package/dist/worker/console/static/assets/channel-CBlJfald.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-mNUYCdDo.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-mNUYCdDo.js +0 -1
- package/dist/worker/console/static/assets/main-D-ZQ4gLb.css +0 -1
- package/dist/worker/console/static/assets/main-Dwhb3ZRq.js +0 -645
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BBRlxIq8.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-CRBvOMCQ.js +0 -8
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { findSpringProjects, generateSpringDocument, writeGeneratedSpec } from "./api-workbench-spring.js";
|
|
1
4
|
import { parseAssertions } from "./api-workbench-assertions.js";
|
|
2
5
|
import { sendJson } from "../routes.js";
|
|
3
|
-
import { scanSpecsSnapshot, parseQueryParams, ApiWorkbenchCoreError, } from "./api-workbench-core.js";
|
|
6
|
+
import { scanSpecsSnapshot, computeScanFingerprint, parseQueryParams, ApiWorkbenchCoreError, } from "./api-workbench-core.js";
|
|
4
7
|
/**
|
|
5
8
|
* API workbench (接口调试台) HTTP routes. All logic lives in
|
|
6
9
|
* api-workbench-core.ts, shared with the operator chat api_* tools.
|
|
@@ -44,10 +47,68 @@ function sendCoreError(res, cause) {
|
|
|
44
47
|
sendApiError(res, 500, "API_WB_INTERNAL", "工作台操作失败,请检查配置或重试");
|
|
45
48
|
}
|
|
46
49
|
}
|
|
50
|
+
/** Where generated OpenAPI documents live for one workspace. */
|
|
51
|
+
function generatedDirFor(deps) {
|
|
52
|
+
const key = createHash("sha256").update(path.resolve(deps.repoRoot)).digest("hex").slice(0, 16);
|
|
53
|
+
return path.join(deps.appData.root, "api-workbench", "generated", key);
|
|
54
|
+
}
|
|
47
55
|
async function handleScanSpecs(res, deps) {
|
|
48
|
-
const snapshot = await scanSpecsSnapshot(deps.repoRoot);
|
|
56
|
+
const snapshot = await scanSpecsSnapshot(deps.repoRoot, { generatedDir: generatedDirFor(deps) });
|
|
49
57
|
sendJson(res, 200, { ok: true, ...snapshot });
|
|
50
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate an OpenAPI document by running the workspace's Spring project.
|
|
61
|
+
*
|
|
62
|
+
* A source scan can find `@PostMapping("/x")` and nothing else — and it mis-reads
|
|
63
|
+
* the constant expressions real projects use for prefixes, emitting paths that look
|
|
64
|
+
* plausible and are wrong. springdoc resolves the real shape from the Java type
|
|
65
|
+
* system, so for a Spring project the workbench asks the project itself.
|
|
66
|
+
*
|
|
67
|
+
* This runs the user's build and application, so it is gated as a mutation and
|
|
68
|
+
* reports every failure with a code the UI can act on.
|
|
69
|
+
*/
|
|
70
|
+
async function handleGenerateSpringSpec(req, res, deps) {
|
|
71
|
+
const gate = deps.gateMutation(req);
|
|
72
|
+
if (!gate.ok) {
|
|
73
|
+
sendApiError(res, gate.status, gate.code, gate.message);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const projects = await findSpringProjects(deps.repoRoot);
|
|
77
|
+
if (projects.length === 0) {
|
|
78
|
+
sendJson(res, 200, { ok: true, generated: [], message: "未找到 Maven 或 Gradle 项目。" });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const dir = generatedDirFor(deps);
|
|
82
|
+
const generated = [];
|
|
83
|
+
const failures = [];
|
|
84
|
+
for (const project of projects) {
|
|
85
|
+
if (!project.hasOpenApiDependency) {
|
|
86
|
+
failures.push({ project: project.dir, code: "NOT_SPRING", message: "未引入 springdoc-openapi 依赖。" });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const result = await generateSpringDocument(project);
|
|
90
|
+
if (!result.ok) {
|
|
91
|
+
failures.push({ project: project.dir, code: result.code, message: result.message });
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
await writeGeneratedSpec(deps.appData.root, path.basename(dir), project.dir, result.document);
|
|
95
|
+
let endpoints = 0;
|
|
96
|
+
try {
|
|
97
|
+
const parsed = JSON.parse(result.document);
|
|
98
|
+
endpoints = parsed.paths === undefined ? 0 : Object.keys(parsed.paths).length;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// A document we just fetched failing to parse is reported as zero endpoints.
|
|
102
|
+
}
|
|
103
|
+
generated.push({ project: project.dir, endpoints, elapsedMs: result.elapsedMs });
|
|
104
|
+
}
|
|
105
|
+
sendJson(res, 200, {
|
|
106
|
+
ok: true, generated, failures,
|
|
107
|
+
message: generated.length > 0
|
|
108
|
+
? `已生成 ${generated.length} 个接口文档。`
|
|
109
|
+
: "未能生成接口文档,仍可使用代码扫描结果。",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
51
112
|
async function handleSend(req, res, deps) {
|
|
52
113
|
const gate = deps.gateMutation(req);
|
|
53
114
|
if (!gate.ok) {
|
|
@@ -256,10 +317,35 @@ export async function handleApiWorkbenchRequest(req, res, deps, pathname) {
|
|
|
256
317
|
return true;
|
|
257
318
|
}
|
|
258
319
|
}
|
|
320
|
+
/*
|
|
321
|
+
* A fingerprint-only probe.
|
|
322
|
+
*
|
|
323
|
+
* The panel checks this when the browser tab regains focus; transferring the
|
|
324
|
+
* whole spec list just to learn "nothing changed" would be wasteful on a project
|
|
325
|
+
* with hundreds of routes.
|
|
326
|
+
*/
|
|
327
|
+
/*
|
|
328
|
+
* No mutation gate: this reads the filesystem and returns a hash, exactly like
|
|
329
|
+
* `specs` just below. Falling back to `gateMutation` when `gateRead` was absent
|
|
330
|
+
* made it answer 403 for a plain GET, which silently disabled the automatic
|
|
331
|
+
* check that depends on it.
|
|
332
|
+
*/
|
|
333
|
+
if (route === "specs/fingerprint" && method === "GET") {
|
|
334
|
+
sendJson(res, 200, { ok: true, fingerprint: await computeScanFingerprint(deps.repoRoot) });
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
259
337
|
if (route === "specs" && method === "GET") {
|
|
260
338
|
await handleScanSpecs(res, deps);
|
|
261
339
|
return true;
|
|
262
340
|
}
|
|
341
|
+
/*
|
|
342
|
+
* Generating runs the user's build and application, so it is a POST behind the
|
|
343
|
+
* mutation gate rather than something a GET does as a side effect.
|
|
344
|
+
*/
|
|
345
|
+
if (route === "spring/generate" && method === "POST") {
|
|
346
|
+
await handleGenerateSpringSpec(req, res, deps);
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
263
349
|
if (route === "send" && method === "POST") {
|
|
264
350
|
await handleSend(req, res, deps);
|
|
265
351
|
return true;
|
|
@@ -15,12 +15,27 @@ export function makeHumanGateCard(input) {
|
|
|
15
15
|
const previewHash = `fnv1a-${(hash >>> 0).toString(16).padStart(8, "0")}`;
|
|
16
16
|
return { schemaVersion: 1, ...input, previewHash };
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether a payload names a gate type this UI can render.
|
|
20
|
+
*
|
|
21
|
+
* `"mutation"` is included because the Console emits it (`routes.ts` wraps an
|
|
22
|
+
* approved workspace mutation as a gate card) and because `HumanGateCard.tsx`
|
|
23
|
+
* has always had a branch for it — the parser was the only layer that did not
|
|
24
|
+
* accept it, so every mutation card was dropped at `chat-sse-events.ts` and the
|
|
25
|
+
* reader never saw the approval they were supposed to give.
|
|
26
|
+
*
|
|
27
|
+
* @param value - the payload's `gateType`, still untrusted.
|
|
28
|
+
* @returns true for a gate type with a rendering branch.
|
|
29
|
+
*/
|
|
30
|
+
function isGateType(value) {
|
|
31
|
+
return value === "contract-apply" || value === "dag-run" || value === "mutation";
|
|
32
|
+
}
|
|
18
33
|
export function humanGateCardFromEventPayload(value) {
|
|
19
34
|
if (!value || typeof value !== "object")
|
|
20
35
|
return undefined;
|
|
21
36
|
const card = value;
|
|
22
37
|
if (card.schemaVersion !== 1 || typeof card.cardId !== "string" ||
|
|
23
|
-
(card.gateType
|
|
38
|
+
!isGateType(card.gateType) ||
|
|
24
39
|
typeof card.taskId !== "string" || typeof card.state !== "string" ||
|
|
25
40
|
typeof card.expiresAt !== "string" || typeof card.inspectHref !== "string" ||
|
|
26
41
|
typeof card.previewHash !== "string")
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
/** Raster types the model reads as images rather than as files. */
|
|
5
6
|
const IMAGE_EXTENSIONS = {
|
|
6
7
|
"image/png": ".png",
|
|
7
8
|
"image/jpeg": ".jpg",
|
|
@@ -9,23 +10,53 @@ const IMAGE_EXTENSIONS = {
|
|
|
9
10
|
"image/webp": ".webp",
|
|
10
11
|
};
|
|
11
12
|
export const COMPOSER_IMAGE_CACHE_MAX_BYTES = 5 * 1024 * 1024;
|
|
13
|
+
/** Ceiling for a non-image attachment; larger than an image because text is cheap to read. */
|
|
14
|
+
export const COMPOSER_FILE_CACHE_MAX_BYTES = 10 * 1024 * 1024;
|
|
15
|
+
/** Cache directory for composer images and files. */
|
|
12
16
|
export function composerImageCacheDir(tmpdir = os.tmpdir()) {
|
|
13
17
|
return path.join(tmpdir, "loop-agent-image-cache");
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* Extension for a cached attachment.
|
|
21
|
+
*
|
|
22
|
+
* A non-image keeps the extension its name carried, because the model's `read`
|
|
23
|
+
* tool picks a syntax/language from it — dropping it would make a `.json` look
|
|
24
|
+
* like an extension-less blob. The name is sanitised to a short alphanumeric
|
|
25
|
+
* suffix so it cannot influence the path in any other way.
|
|
26
|
+
*
|
|
27
|
+
* @param mimeType - the declared type.
|
|
28
|
+
* @param name - the original filename, when known.
|
|
29
|
+
* @returns a leading-dot extension, always safe to concatenate.
|
|
30
|
+
*/
|
|
31
|
+
function extensionFor(mimeType, name) {
|
|
32
|
+
const image = IMAGE_EXTENSIONS[mimeType];
|
|
33
|
+
if (image !== undefined)
|
|
34
|
+
return image;
|
|
35
|
+
const fromName = /\.([A-Za-z0-9]{1,8})$/.exec(name ?? "")?.[1];
|
|
36
|
+
if (fromName !== undefined)
|
|
37
|
+
return `.${fromName.toLowerCase()}`;
|
|
38
|
+
return ".bin";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Write one composer attachment into the OS temp cache and return its path.
|
|
42
|
+
*
|
|
43
|
+
* The filename is generated here so callers cannot choose a path; only the
|
|
44
|
+
* extension is inherited, and only from a strict alphanumeric match.
|
|
45
|
+
*
|
|
46
|
+
* @param input - declared type, bytes, optional original name, optional tmpdir.
|
|
47
|
+
* @returns the absolute path the model reads through an `@path` mention.
|
|
18
48
|
*/
|
|
19
49
|
export async function cacheComposerImage(input) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
const isImage = IMAGE_EXTENSIONS[input.mimeType] !== undefined;
|
|
51
|
+
const limit = isImage ? COMPOSER_IMAGE_CACHE_MAX_BYTES : COMPOSER_FILE_CACHE_MAX_BYTES;
|
|
52
|
+
if (input.bytes.length === 0 || input.bytes.length > limit) {
|
|
53
|
+
throw new Error(isImage
|
|
54
|
+
? `image exceeds ${COMPOSER_IMAGE_CACHE_MAX_BYTES} bytes`
|
|
55
|
+
: `file exceeds ${COMPOSER_FILE_CACHE_MAX_BYTES} bytes`);
|
|
25
56
|
}
|
|
26
57
|
const dir = path.resolve(composerImageCacheDir(input.tmpdir));
|
|
27
58
|
await mkdir(dir, { recursive: true });
|
|
28
|
-
const file = path.resolve(dir, `${randomUUID()}${
|
|
59
|
+
const file = path.resolve(dir, `${randomUUID()}${extensionFor(input.mimeType, input.name)}`);
|
|
29
60
|
const relative = path.relative(dir, file);
|
|
30
61
|
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
31
62
|
throw new Error("cache path escaped the temp directory");
|
|
@@ -4,6 +4,7 @@ import { parseAssertions } from "../../api-workbench-assertions.js";
|
|
|
4
4
|
*
|
|
5
5
|
* Model-callable tools over the same workbench core the Console page uses:
|
|
6
6
|
* api_scan discover OpenAPI/Swagger specs + static code routes
|
|
7
|
+
* api_endpoint one endpoint's parameters, request body and responses
|
|
7
8
|
* api_send send one sandboxed HTTP request (env {{key}} substitution)
|
|
8
9
|
* api_environments list environments; upsert baseUrl + key=value variables
|
|
9
10
|
* api_history list / clear recent send history
|
|
@@ -13,12 +14,16 @@ import { parseAssertions } from "../../api-workbench-assertions.js";
|
|
|
13
14
|
* with stable APIWB_* error codes. Sends use the same validation,
|
|
14
15
|
* blocked-header list and timeout as the Console page.
|
|
15
16
|
*/
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import path from "node:path";
|
|
16
19
|
import { scanSpecsSnapshot, parseQueryParams, ApiWorkbenchCoreError, } from "../../api-workbench-core.js";
|
|
17
|
-
const APIWB_TOOLS_DESCRIPTION = "API workbench:
|
|
18
|
-
"send one sandboxed HTTP request with environment {{key}} substitution (api_send), " +
|
|
20
|
+
const APIWB_TOOLS_DESCRIPTION = "API workbench: list every endpoint (api_scan), look up ONE endpoint's parameters, request body and responses " +
|
|
21
|
+
"(api_endpoint), send one sandboxed HTTP request with environment {{key}} substitution (api_send), " +
|
|
19
22
|
"list/upsert environment prefixes + variables (api_environments), review send history (api_history), " +
|
|
20
23
|
"and pull a one-shot debugging brief (api_debug). " +
|
|
21
|
-
"
|
|
24
|
+
"Prefer api_endpoint over api_scan once you know the path: a real service has hundreds of routes and only " +
|
|
25
|
+
"one of them matters at a time. Use either before guessing endpoints; environments carry non-secret " +
|
|
26
|
+
"key=value variables. Never submit credential values through tool arguments.";
|
|
22
27
|
export async function buildApiWorkbenchTools(options) {
|
|
23
28
|
const [{ Type }, { defineTool }] = await Promise.all([
|
|
24
29
|
import("typebox"),
|
|
@@ -31,6 +36,22 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
31
36
|
...(sdkExposureForCatalogTool(tool.name, options.exposureMode ?? "full", apiExposureMode) ? { exposure: "deferred" } : {}),
|
|
32
37
|
});
|
|
33
38
|
const opts = options;
|
|
39
|
+
/**
|
|
40
|
+
* Where this workspace's generated OpenAPI documents live.
|
|
41
|
+
*
|
|
42
|
+
* Must match the route's key (`generatedDirFor` in `api-workbench.ts`) or the tools
|
|
43
|
+
* and the panel would read two different directories for the same workspace.
|
|
44
|
+
*/
|
|
45
|
+
function generatedDir() {
|
|
46
|
+
if (opts.appDataRoot === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const key = createHash("sha256").update(path.resolve(opts.repoRoot)).digest("hex").slice(0, 16);
|
|
49
|
+
return path.join(opts.appDataRoot, "api-workbench", "generated", key);
|
|
50
|
+
}
|
|
51
|
+
/** Scan with the generated documents included, so tools and panel agree. */
|
|
52
|
+
function scanWithGenerated() {
|
|
53
|
+
return scanSpecsSnapshot(opts.repoRoot, { generatedDir: generatedDir() });
|
|
54
|
+
}
|
|
34
55
|
async function run(code, op) {
|
|
35
56
|
let result;
|
|
36
57
|
try {
|
|
@@ -92,7 +113,67 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
92
113
|
promptSnippet: APIWB_TOOLS_DESCRIPTION,
|
|
93
114
|
parameters: Type.Object({}, { additionalProperties: false }),
|
|
94
115
|
async execute() {
|
|
95
|
-
return run("APIWB_SCAN_FAILED", () =>
|
|
116
|
+
return run("APIWB_SCAN_FAILED", () => scanWithGenerated());
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
defineTool({
|
|
120
|
+
name: "api_endpoint",
|
|
121
|
+
label: "API endpoint detail",
|
|
122
|
+
/*
|
|
123
|
+
* `api_scan` returns every endpoint, which is fine for a small project and
|
|
124
|
+
* wasteful for a real one: a service with 300 routes makes the model read 300
|
|
125
|
+
* rows to find one, and the bodies — the part that actually matters — are the
|
|
126
|
+
* bulk of it. This answers "what does this one endpoint take and return",
|
|
127
|
+
* including the field tables springdoc resolved from the Java type system.
|
|
128
|
+
*/
|
|
129
|
+
description: "Look up ONE endpoint's full definition: parameters, request body fields and declared responses. " +
|
|
130
|
+
"Match by path (exact or substring) and optionally method. Use this instead of api_scan when you " +
|
|
131
|
+
"already know which endpoint you need.",
|
|
132
|
+
promptSnippet: "Look up one endpoint's parameters, request body fields and responses.",
|
|
133
|
+
parameters: Type.Object({
|
|
134
|
+
path: Type.String({ minLength: 1, maxLength: 512, description: "Endpoint path, exact or substring" }),
|
|
135
|
+
method: Type.Optional(Type.String({ maxLength: 10, description: "HTTP method filter, e.g. POST" })),
|
|
136
|
+
}, { additionalProperties: false }),
|
|
137
|
+
async execute(_id, params) {
|
|
138
|
+
return run("APIWB_ENDPOINT_FAILED", async () => {
|
|
139
|
+
const snapshot = await scanWithGenerated();
|
|
140
|
+
const needle = params.path.trim().toLowerCase();
|
|
141
|
+
const wanted = params.method?.trim().toUpperCase();
|
|
142
|
+
const all = snapshot.specs.flatMap(spec => (spec.endpoints ?? []).map(endpoint => ({ spec, endpoint })));
|
|
143
|
+
const matches = all.filter(({ endpoint }) => (wanted === undefined || endpoint.method.toUpperCase() === wanted)
|
|
144
|
+
&& (endpoint.path.toLowerCase() === needle || endpoint.path.toLowerCase().includes(needle)));
|
|
145
|
+
if (matches.length === 0) {
|
|
146
|
+
return {
|
|
147
|
+
ok: false,
|
|
148
|
+
error: {
|
|
149
|
+
code: "APIWB_ENDPOINT_MISSING",
|
|
150
|
+
message: `没有匹配 ${wanted ?? ""} ${params.path} 的接口。可用 api_scan 查看全部接口。`,
|
|
151
|
+
},
|
|
152
|
+
// A short list is more useful than a bare miss: the model usually has
|
|
153
|
+
// the wrong prefix or a slightly different path.
|
|
154
|
+
candidates: all.slice(0, 20).map(({ endpoint }) => `${endpoint.method} ${endpoint.path}`),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// An exact path match wins over substring matches.
|
|
158
|
+
const exact = matches.filter(({ endpoint }) => endpoint.path.toLowerCase() === needle);
|
|
159
|
+
const chosen = (exact.length > 0 ? exact : matches).slice(0, 5).map(({ spec, endpoint }) => ({
|
|
160
|
+
spec: spec.title,
|
|
161
|
+
method: endpoint.method,
|
|
162
|
+
path: endpoint.path,
|
|
163
|
+
...(endpoint.summary === undefined ? {} : { summary: endpoint.summary }),
|
|
164
|
+
parameters: endpoint.parameters,
|
|
165
|
+
...(endpoint.requestBody === undefined ? {} : { requestBody: endpoint.requestBody }),
|
|
166
|
+
...(endpoint.responses === undefined ? {} : { responses: endpoint.responses }),
|
|
167
|
+
...(endpoint.origin === undefined ? {} : { origin: endpoint.origin }),
|
|
168
|
+
}));
|
|
169
|
+
return {
|
|
170
|
+
ok: true,
|
|
171
|
+
count: chosen.length,
|
|
172
|
+
// Substring search can match several; the caller asked for one, so say so.
|
|
173
|
+
...(matches.length > chosen.length ? { truncatedFrom: matches.length } : {}),
|
|
174
|
+
endpoints: chosen,
|
|
175
|
+
};
|
|
176
|
+
});
|
|
96
177
|
},
|
|
97
178
|
}),
|
|
98
179
|
defineTool({
|
|
@@ -141,7 +222,7 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
141
222
|
}, { additionalProperties: false }),
|
|
142
223
|
async execute(_id, params) {
|
|
143
224
|
return run("APIWB_DEBUG_FAILED", async () => {
|
|
144
|
-
const snapshot = await
|
|
225
|
+
const snapshot = await scanWithGenerated();
|
|
145
226
|
const needle = params.query?.trim().toLowerCase();
|
|
146
227
|
const endpoints = [];
|
|
147
228
|
for (const spec of snapshot.specs) {
|
|
@@ -220,6 +301,40 @@ export async function buildApiWorkbenchTools(options) {
|
|
|
220
301
|
});
|
|
221
302
|
},
|
|
222
303
|
}),
|
|
304
|
+
defineTool({
|
|
305
|
+
name: "api_credentials",
|
|
306
|
+
label: "API credential references",
|
|
307
|
+
/*
|
|
308
|
+
* `api_send` accepts `authRef: { id, version }`, but nothing told the model
|
|
309
|
+
* which references exist — so authenticated endpoints were effectively out of
|
|
310
|
+
* reach, and a model that needed auth had no way to discover it.
|
|
311
|
+
*
|
|
312
|
+
* Read-only and metadata-only by design: it lists ids, names and origins.
|
|
313
|
+
* Secrets are never returned, and there is deliberately no tool that writes a
|
|
314
|
+
* credential — a model must not be the thing that handles a token.
|
|
315
|
+
*/
|
|
316
|
+
description: "List the credential REFERENCES configured for this workspace (id, name, origin, version). " +
|
|
317
|
+
"Use the returned id + version in api_send's authRef to call an authenticated endpoint. " +
|
|
318
|
+
"Secret values are never returned and cannot be set through tools.",
|
|
319
|
+
promptSnippet: "List credential references available to api_send.",
|
|
320
|
+
parameters: Type.Object({}, { additionalProperties: false }),
|
|
321
|
+
async execute() {
|
|
322
|
+
return run("APIWB_CREDENTIALS_FAILED", async () => {
|
|
323
|
+
const state = await opts.apiWorkbench.auth.list();
|
|
324
|
+
return {
|
|
325
|
+
ok: true,
|
|
326
|
+
revision: state.revision,
|
|
327
|
+
credentials: (state.credentials ?? []).map(credential => ({
|
|
328
|
+
id: credential.id,
|
|
329
|
+
name: credential.name,
|
|
330
|
+
origin: credential.origin,
|
|
331
|
+
version: credential.version,
|
|
332
|
+
configured: credential.configured,
|
|
333
|
+
})),
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
223
338
|
defineTool({
|
|
224
339
|
name: "api_history",
|
|
225
340
|
label: "API history",
|
|
@@ -494,9 +494,6 @@ function withUserCompactionSettings(policy, settings) {
|
|
|
494
494
|
...(resolved.thresholdRatio === undefined
|
|
495
495
|
? {}
|
|
496
496
|
: { thresholdRatio: resolved.thresholdRatio }),
|
|
497
|
-
...(resolved.headroomTokens === undefined
|
|
498
|
-
? {}
|
|
499
|
-
: { headroomTokens: resolved.headroomTokens }),
|
|
500
497
|
...(resolved.retainRatio === undefined
|
|
501
498
|
? {}
|
|
502
499
|
: { retainRatio: resolved.retainRatio }),
|
|
@@ -1677,6 +1674,8 @@ export class ConsolePiRuntime {
|
|
|
1677
1674
|
sessionId,
|
|
1678
1675
|
repoRoot: this.options.cwd,
|
|
1679
1676
|
apiWorkbench: this.options.apiWorkbench,
|
|
1677
|
+
// So the model reads the same generated documents the panel shows.
|
|
1678
|
+
...(this.options.appDataRoot === undefined ? {} : { appDataRoot: this.options.appDataRoot }),
|
|
1680
1679
|
exposureMode,
|
|
1681
1680
|
apiExposureMode,
|
|
1682
1681
|
onDiscover: (target) => this.discoverApi(sessionId, target),
|
|
@@ -46,7 +46,17 @@ function codeField(record) {
|
|
|
46
46
|
}
|
|
47
47
|
return undefined;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Which kind of provider failure this is.
|
|
51
|
+
*
|
|
52
|
+
* Exported because the client needs the same decision: `turn_error` events
|
|
53
|
+
* carry only `message` / `code` / `raw`, not a category, so the error row
|
|
54
|
+
* re-derives it rather than growing a second, drifting classifier.
|
|
55
|
+
*
|
|
56
|
+
* @param input - the sanitized message, the raw envelope, and any recorded code.
|
|
57
|
+
* @returns the category the UI uses to pick its advice line.
|
|
58
|
+
*/
|
|
59
|
+
export function classifyProviderError(input) {
|
|
50
60
|
const haystack = `${input.message}\n${input.raw}`.toLowerCase();
|
|
51
61
|
const status = typeof input.code === "number" ? input.code : undefined;
|
|
52
62
|
if (status === 401 ||
|
|
@@ -82,6 +92,6 @@ export function parseProviderError(value) {
|
|
|
82
92
|
raw,
|
|
83
93
|
...(code === undefined ? {} : { code }),
|
|
84
94
|
...(type ? { type } : {}),
|
|
85
|
-
category:
|
|
95
|
+
category: classifyProviderError({ message, raw, code }),
|
|
86
96
|
};
|
|
87
97
|
}
|
|
@@ -16,6 +16,14 @@ const SKIP_DIRS = new Set([
|
|
|
16
16
|
"dist",
|
|
17
17
|
"build",
|
|
18
18
|
"out",
|
|
19
|
+
/*
|
|
20
|
+
* JVM build output. A Maven `target/` holds compiled classes, generated sources and
|
|
21
|
+
* a repackaged jar — easily tens of thousands of files in a multi-module project,
|
|
22
|
+
* which is enough to exhaust `maxFiles` before the walk reaches `src/main/java`.
|
|
23
|
+
* That was a real reason a Spring workspace scanned poorly.
|
|
24
|
+
*/
|
|
25
|
+
"target",
|
|
26
|
+
".gradle",
|
|
19
27
|
".cache",
|
|
20
28
|
".turbo",
|
|
21
29
|
".vite",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { access } from "node:fs/promises";
|
|
3
3
|
import { parseChatReferences, parseReferenceRecoveryDrafts, serializeChatReferences } from "./chat-references.js";
|
|
4
|
-
import { cacheComposerImage } from "./image-cache.js";
|
|
4
|
+
import { cacheComposerImage, COMPOSER_FILE_CACHE_MAX_BYTES } from "./image-cache.js";
|
|
5
5
|
import { projectStoredMessagesWithEventOrder, turnEventToStorePartial, } from "./chat-event-projection.js";
|
|
6
6
|
import { OPERATOR_CHAT_ALLOWED_TOOLS, OPERATOR_CHAT_DENIED_TOOLS, OPERATOR_CHAT_DENIED_OPERATOR_ACTIONS, OPERATOR_CHAT_SQL_TOOL_CAPABILITIES, OPERATOR_CHAT_APIWB_TOOL_CAPABILITIES, } from "./tools.js";
|
|
7
7
|
import { InvalidChatSessionModeError, SESSION_MODE_ACTION_DENIED_CODE, SESSION_MODE_ACTION_DENIED_MESSAGE, SESSION_MODE_IMMUTABLE_CODE, UnknownChatSessionModeError, isWorkflowSessionMode, parseCreateSessionMode, readStoredSessionMode, shouldAcceptOperatorSnapshot, } from "./session-mode.js";
|
|
@@ -167,10 +167,33 @@ function turnSummary(turn) {
|
|
|
167
167
|
abortRequestedAt: turn.abortRequestedAt ?? null,
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The turn fields the client needs to render a row's origin.
|
|
172
|
+
*
|
|
173
|
+
* `source` is recorded when the runtime wakes a turn on its own — a Goal round
|
|
174
|
+
* today (`chat-event-store.ts:2197-2203`). It is projected here, and only here:
|
|
175
|
+
* the field already exists in memory, and a separate query for "who started this
|
|
176
|
+
* turn" would duplicate the whole state-projection path.
|
|
177
|
+
*
|
|
178
|
+
* Only what the UI draws is sent: `goalId`/`revision` are internal identities
|
|
179
|
+
* with no display, so they stay on the server.
|
|
180
|
+
*
|
|
181
|
+
* @param turn - one stored turn.
|
|
182
|
+
* @returns the compact projection sent to the client.
|
|
183
|
+
*/
|
|
170
184
|
function turnStateSummary(turn) {
|
|
185
|
+
const source = turn.source;
|
|
171
186
|
return {
|
|
172
187
|
turnId: turn.turnId,
|
|
173
188
|
state: turn.state === "queued" ? "running" : turn.state,
|
|
189
|
+
...(source === undefined
|
|
190
|
+
? {}
|
|
191
|
+
: {
|
|
192
|
+
source: {
|
|
193
|
+
kind: source.kind,
|
|
194
|
+
...(typeof source.round === "number" ? { round: source.round } : {}),
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
174
197
|
};
|
|
175
198
|
}
|
|
176
199
|
function turnStatesForIds(events, sessionId, turnIds) {
|
|
@@ -1575,6 +1598,49 @@ function goalHttpStatus(code) {
|
|
|
1575
1598
|
return 400;
|
|
1576
1599
|
return 409;
|
|
1577
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Echo one `/goal` invocation into the transcript.
|
|
1603
|
+
*
|
|
1604
|
+
* The client intercepts `/goal` and calls this API directly, so no prompt and no
|
|
1605
|
+
* user message are produced — the operator typed a command and the transcript
|
|
1606
|
+
* stayed empty. Appending a `command` event gives the message stream the same
|
|
1607
|
+
* row a slash command has everywhere else, using the node kind that already
|
|
1608
|
+
* exists (`conversation-nodes.ts`, `kind: "command"`).
|
|
1609
|
+
*
|
|
1610
|
+
* The event's second argument is a TURN id, not a command id: a `command` node is
|
|
1611
|
+
* located on a turn, and `conversation-nodes.ts` filters out anything whose
|
|
1612
|
+
* `location` has no turn. The event is therefore attached to the session's
|
|
1613
|
+
* current turn when one is open, and skipped otherwise — a command typed with no
|
|
1614
|
+
* turn in flight has nowhere to sit in this transcript model.
|
|
1615
|
+
*
|
|
1616
|
+
* Fire-and-forget: the goal change is already committed, and a failed echo must
|
|
1617
|
+
* not turn a successful mutation into an error response.
|
|
1618
|
+
*
|
|
1619
|
+
* @param deps - route dependencies, for the event store.
|
|
1620
|
+
* @param sessionId - owning session.
|
|
1621
|
+
* @param input - command label, one-line argument preview, and outcome.
|
|
1622
|
+
*/
|
|
1623
|
+
function appendGoalCommandEcho(deps, sessionId, input) {
|
|
1624
|
+
try {
|
|
1625
|
+
const turnId = deps.events.getActiveTurn(sessionId)?.turnId;
|
|
1626
|
+
if (turnId === undefined)
|
|
1627
|
+
return;
|
|
1628
|
+
const commandId = `goal:${sessionId}:${input.action}:${Date.now().toString(36)}`;
|
|
1629
|
+
deps.events.append(sessionId, turnId, {
|
|
1630
|
+
kind: "command",
|
|
1631
|
+
data: {
|
|
1632
|
+
commandId,
|
|
1633
|
+
name: "goal",
|
|
1634
|
+
action: input.action,
|
|
1635
|
+
outcome: "completed",
|
|
1636
|
+
...(input.argsPreview ? { argsPreview: input.argsPreview } : {}),
|
|
1637
|
+
},
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
catch {
|
|
1641
|
+
// An echo is cosmetic; the goal mutation already succeeded.
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1578
1644
|
export async function handleChatGoal(req, res, deps, sessionId) {
|
|
1579
1645
|
const registry = deps.goalRegistry;
|
|
1580
1646
|
if (!registry) {
|
|
@@ -1632,6 +1698,10 @@ export async function handleChatGoal(req, res, deps, sessionId) {
|
|
|
1632
1698
|
return;
|
|
1633
1699
|
}
|
|
1634
1700
|
deps.goalRoundDriver?.wake(sessionId);
|
|
1701
|
+
appendGoalCommandEcho(deps, sessionId, {
|
|
1702
|
+
action: "create",
|
|
1703
|
+
argsPreview: typeof body.objective === "string" ? body.objective : undefined,
|
|
1704
|
+
});
|
|
1635
1705
|
sendJson(res, 201, { ok: true, goal: result.goal });
|
|
1636
1706
|
return;
|
|
1637
1707
|
}
|
|
@@ -1665,6 +1735,7 @@ export async function handleChatGoal(req, res, deps, sessionId) {
|
|
|
1665
1735
|
return;
|
|
1666
1736
|
}
|
|
1667
1737
|
deps.goalRoundDriver?.cancel(sessionId);
|
|
1738
|
+
appendGoalCommandEcho(deps, sessionId, { action: "clear" });
|
|
1668
1739
|
sendJson(res, 200, { ok: true, goal: null });
|
|
1669
1740
|
return;
|
|
1670
1741
|
}
|
|
@@ -5493,6 +5564,13 @@ async function dispatchChatRequest(req, res, deps, pathname, workspaceScope) {
|
|
|
5493
5564
|
},
|
|
5494
5565
|
repoRoot: deps.appData.repoRoot,
|
|
5495
5566
|
appData: deps.appData,
|
|
5567
|
+
/*
|
|
5568
|
+
* Lets the automation catalog span every registered workspace.
|
|
5569
|
+
*
|
|
5570
|
+
* A task lives in its own repository's ledger, so the panel used to show only
|
|
5571
|
+
* the current workspace's tasks. This reads the registry file the workspace
|
|
5572
|
+
* picker also uses; the aggregation labels each row with its workspace.
|
|
5573
|
+
*/
|
|
5496
5574
|
gateMutation: (r) => gateMutation(r, deps),
|
|
5497
5575
|
}, pathname)) {
|
|
5498
5576
|
return true;
|
|
@@ -5534,17 +5612,51 @@ async function dispatchChatRequest(req, res, deps, pathname, workspaceScope) {
|
|
|
5534
5612
|
return true;
|
|
5535
5613
|
}
|
|
5536
5614
|
try {
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5615
|
+
/*
|
|
5616
|
+
* Images AND plain files land here.
|
|
5617
|
+
*
|
|
5618
|
+
* Both reach the model the same way — an `@path` mention the read tool
|
|
5619
|
+
* follows — so a separate route would duplicate the write, the size
|
|
5620
|
+
* ceiling and the path confinement. Images still go through
|
|
5621
|
+
* `parseChatImages`, which enforces the raster types and per-image caps;
|
|
5622
|
+
* anything else is a file and gets its own ceiling.
|
|
5623
|
+
*
|
|
5624
|
+
* 10 MiB raw is ~13.4 MiB of base64 plus the JSON envelope.
|
|
5625
|
+
*/
|
|
5626
|
+
const body = await readJsonBody(req, 16 * 1024 * 1024);
|
|
5627
|
+
const declaredType = typeof body.mimeType === "string" ? body.mimeType : "";
|
|
5628
|
+
const originalName = typeof body.name === "string" ? body.name : undefined;
|
|
5629
|
+
const isImage = IMAGE_MIME_TYPES.has(declaredType);
|
|
5630
|
+
let filePath;
|
|
5631
|
+
if (isImage) {
|
|
5632
|
+
const [image] = parseChatImages([
|
|
5633
|
+
{ type: "image", mimeType: body.mimeType, data: body.data },
|
|
5634
|
+
]);
|
|
5635
|
+
if (!image)
|
|
5636
|
+
throw new Error("image is required");
|
|
5637
|
+
filePath = await cacheComposerImage({
|
|
5638
|
+
mimeType: image.mimeType,
|
|
5639
|
+
bytes: Buffer.from(image.data, "base64"),
|
|
5640
|
+
...(originalName === undefined ? {} : { name: originalName }),
|
|
5641
|
+
});
|
|
5642
|
+
}
|
|
5643
|
+
else {
|
|
5644
|
+
if (typeof body.data !== "string" || body.data.length === 0) {
|
|
5645
|
+
throw new Error("file data is required");
|
|
5646
|
+
}
|
|
5647
|
+
if (body.data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(body.data)) {
|
|
5648
|
+
throw new Error("file data must be valid base64");
|
|
5649
|
+
}
|
|
5650
|
+
const bytes = Buffer.from(body.data, "base64");
|
|
5651
|
+
if (bytes.length > COMPOSER_FILE_CACHE_MAX_BYTES) {
|
|
5652
|
+
throw new Error(`file exceeds ${COMPOSER_FILE_CACHE_MAX_BYTES} bytes`);
|
|
5653
|
+
}
|
|
5654
|
+
filePath = await cacheComposerImage({
|
|
5655
|
+
mimeType: declaredType || "application/octet-stream",
|
|
5656
|
+
bytes,
|
|
5657
|
+
...(originalName === undefined ? {} : { name: originalName }),
|
|
5658
|
+
});
|
|
5659
|
+
}
|
|
5548
5660
|
sendJson(res, 200, { ok: true, path: filePath });
|
|
5549
5661
|
}
|
|
5550
5662
|
catch (error) {
|
|
@@ -5552,7 +5664,7 @@ async function dispatchChatRequest(req, res, deps, pathname, workspaceScope) {
|
|
|
5552
5664
|
ok: false,
|
|
5553
5665
|
error: {
|
|
5554
5666
|
code: "INVALID_INPUT",
|
|
5555
|
-
message: error instanceof Error ? error.message : "
|
|
5667
|
+
message: error instanceof Error ? error.message : "attachment cache failed",
|
|
5556
5668
|
},
|
|
5557
5669
|
});
|
|
5558
5670
|
}
|