@tea-agent/loop-agent 0.52.0 → 0.53.0-next.2
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 +62 -4
- package/dist/build-stamp.json +3 -3
- package/dist/executors/dag-pi/plan/finalize-tools.js +13 -0
- package/dist/executors/dag-pi/plan/record-tools.js +37 -11
- package/dist/executors/dag-pi/sessions/plan-batches.js +1 -1
- package/dist/executors/dag-pi/sessions/segmented-plan.js +28 -20
- package/dist/executors/dag-pi/tools/plan-decision-tools.js +2 -1
- package/dist/executors/dag-pi-executor.js +50 -5
- package/dist/executors/pi-executor.js +12 -0
- package/dist/executors/pi-sdk-executor.js +2 -2
- package/dist/shared/frontend-execution-policy.js +28 -2
- package/dist/shared/pi-context-pressure/compaction-policy.js +22 -34
- package/dist/shared/pi-context-pressure/index.js +1 -1
- package/dist/task/config-types.js +2 -2
- package/dist/task/source-prepare/prepare.js +1 -1
- package/dist/task/source-prepare/semantic-intake.js +2 -2
- package/dist/task/source-prepare/source-fidelity-pi.js +2 -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/dist/workflows/dag/checkpoint.js +6 -1
- package/dist/workflows/dag/frontend-committed-facts.js +38 -5
- package/dist/workflows/dag/frontend-design-policy.js +22 -0
- package/dist/workflows/dag/frontend-implementation-contract.js +39 -12
- package/dist/workflows/dag/frontend-imported-run-artifacts.js +126 -0
- package/dist/workflows/dag/frontend-recovery-run.js +7 -110
- package/dist/workflows/dag/frontend-test-framework-adapters.js +14 -0
- package/dist/workflows/dag/frontend-verification-trace.js +20 -8
- package/dist/workflows/dag/frontend-writer-reuse.js +104 -0
- package/dist/workflows/dag/frontend-writer-status.js +0 -4
- package/dist/workflows/dag/hybrid/templates/frontend.js +15 -8
- package/dist/workflows/dag/init-hybrid.js +1 -1
- package/dist/workflows/dag/reconcile-run.js +11 -1
- package/dist/workflows/dag/recovery-lease.js +23 -0
- package/dist/workflows/dag/rerun-feedback.js +4 -2
- package/dist/workflows/dag/rerun-run.js +40 -0
- package/dist/workflows/dag/runner.js +11 -0
- package/dist/workflows/dag/terminal-status.js +2 -1
- 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
|
@@ -21,11 +21,22 @@ export function isComposerImageFile(file) {
|
|
|
21
21
|
export function composerImageMention(filePath) {
|
|
22
22
|
return `@${filePath}`;
|
|
23
23
|
}
|
|
24
|
+
/** Extra line for a plain file, so the model opens it rather than guessing. */
|
|
25
|
+
export const COMPOSER_FILE_READ_HINT = "文件已保存在本地临时文件。请按需用 read 工具打开;二进制文件只能看到路径。";
|
|
24
26
|
/**
|
|
25
27
|
* Turn temp-file images into `@path` lines on the message and leave real
|
|
26
28
|
* binary attachments out of the model image channel.
|
|
29
|
+
*
|
|
30
|
+
* Plain files are appended the same way. They have no binary channel at all, so
|
|
31
|
+
* every file becomes a mention — the read tool is the only way the model sees
|
|
32
|
+
* one.
|
|
33
|
+
*
|
|
34
|
+
* @param text - the draft.
|
|
35
|
+
* @param images - pending images.
|
|
36
|
+
* @param files - pending non-image attachments.
|
|
37
|
+
* @returns the rewritten text and the images that still travel inline.
|
|
27
38
|
*/
|
|
28
|
-
export function materializeComposerImages(text, images) {
|
|
39
|
+
export function materializeComposerImages(text, images, files = []) {
|
|
29
40
|
const paths = [];
|
|
30
41
|
const binary = [];
|
|
31
42
|
for (const image of images) {
|
|
@@ -34,12 +45,21 @@ export function materializeComposerImages(text, images) {
|
|
|
34
45
|
else if (image.data)
|
|
35
46
|
binary.push(image);
|
|
36
47
|
}
|
|
37
|
-
|
|
48
|
+
const filePaths = files.map((file) => file.path);
|
|
49
|
+
if (paths.length === 0 && filePaths.length === 0)
|
|
38
50
|
return { text, images: [...binary] };
|
|
39
|
-
const mentions = paths.map(composerImageMention).join("\n");
|
|
40
|
-
|
|
51
|
+
const mentions = [...paths, ...filePaths].map(composerImageMention).join("\n");
|
|
52
|
+
/*
|
|
53
|
+
* One hint, chosen by what is attached: an image wants the image skill, a
|
|
54
|
+
* file wants `read`. Emitting both would tell the model to use a skill on a
|
|
55
|
+
* `.zip`.
|
|
56
|
+
*/
|
|
57
|
+
const hint = paths.length > 0
|
|
58
|
+
? COMPOSER_IMAGE_READ_HINT
|
|
59
|
+
: COMPOSER_FILE_READ_HINT;
|
|
60
|
+
const suffix = text.includes(hint) ? "" : hint;
|
|
41
61
|
return {
|
|
42
|
-
text: [text.trim(), mentions,
|
|
62
|
+
text: [text.trim(), mentions, suffix].filter(Boolean).join("\n"),
|
|
43
63
|
images: binary,
|
|
44
64
|
};
|
|
45
65
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-owned preview URLs for images awaiting submission.
|
|
3
|
+
*
|
|
4
|
+
* A composer image is uploaded to the temp cache and reaches the model as an
|
|
5
|
+
* `@path` mention, so its `data` is deliberately empty — the bytes live on disk.
|
|
6
|
+
* That left the tile with nothing to draw. The first fix copied the base64 into
|
|
7
|
+
* the pending state, which works but is the wrong shape: base64 is ~33% larger
|
|
8
|
+
* than the file, and this state is cloned on every ledger snapshot.
|
|
9
|
+
*
|
|
10
|
+
* This module follows DSH instead (`ui-conversation/src/client/service.ts:74-81`):
|
|
11
|
+
* the `File` stays here in a registry, the pending image carries only a
|
|
12
|
+
* `blob:` URL that points at it, and the URL is revoked when the image leaves
|
|
13
|
+
* the composer or its history image takes over.
|
|
14
|
+
*
|
|
15
|
+
* The URL is a string, so it survives `structuredClone` — unlike the `File`,
|
|
16
|
+
* which is why that part must live outside React state at all.
|
|
17
|
+
*/
|
|
18
|
+
/** Files kept alive for preview URLs, keyed by the URL itself. */
|
|
19
|
+
const filesByUrl = new Map();
|
|
20
|
+
/** Intrinsic sizes learned from a header-only decode, keyed by URL. */
|
|
21
|
+
const sizesByUrl = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Whether this runtime can mint a blob URL.
|
|
24
|
+
* @returns true when `URL.createObjectURL` is available.
|
|
25
|
+
*/
|
|
26
|
+
function canUseBlobUrl() {
|
|
27
|
+
return typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a preview URL for one picked file and remember the file behind it.
|
|
31
|
+
*
|
|
32
|
+
* @param file - the image the operator chose.
|
|
33
|
+
* @returns the blob URL, or undefined when this runtime cannot create one — the
|
|
34
|
+
* caller then falls back to an icon tile rather than a broken frame.
|
|
35
|
+
*/
|
|
36
|
+
export function createImagePreviewUrl(file) {
|
|
37
|
+
if (!canUseBlobUrl())
|
|
38
|
+
return undefined;
|
|
39
|
+
try {
|
|
40
|
+
const url = URL.createObjectURL(file);
|
|
41
|
+
filesByUrl.set(url, file);
|
|
42
|
+
return url;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Release a preview URL.
|
|
50
|
+
*
|
|
51
|
+
* Safe to call with a URL this module never minted, and safe to call twice: the
|
|
52
|
+
* registry entry is the guard, and a non-blob string is ignored.
|
|
53
|
+
*
|
|
54
|
+
* @param url - the preview URL to release, when the image has one.
|
|
55
|
+
*/
|
|
56
|
+
export function revokeImagePreviewUrl(url) {
|
|
57
|
+
if (url === undefined || !url.startsWith("blob:"))
|
|
58
|
+
return;
|
|
59
|
+
if (!filesByUrl.delete(url) && !sizesByUrl.has(url))
|
|
60
|
+
return;
|
|
61
|
+
sizesByUrl.delete(url);
|
|
62
|
+
try {
|
|
63
|
+
URL.revokeObjectURL(url);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Already revoked, or the runtime lacks the method; nothing to recover.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Learn an image's intrinsic size from its header.
|
|
71
|
+
*
|
|
72
|
+
* The size travels with the uploaded image metadata, so the viewer can lay the
|
|
73
|
+
* picture out before the bytes arrive. A header read is not a full decode, and
|
|
74
|
+
* any failure just leaves the size unknown — consumers fall back to CSS.
|
|
75
|
+
*
|
|
76
|
+
* @param url - the preview URL to measure.
|
|
77
|
+
* @param onSize - receives the size once known.
|
|
78
|
+
*/
|
|
79
|
+
export function probeImageSize(url, onSize) {
|
|
80
|
+
if (url === undefined || typeof Image !== "function")
|
|
81
|
+
return;
|
|
82
|
+
const known = sizesByUrl.get(url);
|
|
83
|
+
if (known !== undefined) {
|
|
84
|
+
onSize(known);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const probe = new Image();
|
|
88
|
+
probe.onload = () => {
|
|
89
|
+
const size = { width: probe.naturalWidth, height: probe.naturalHeight };
|
|
90
|
+
if (size.width > 0 && size.height > 0) {
|
|
91
|
+
sizesByUrl.set(url, size);
|
|
92
|
+
onSize(size);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
probe.onerror = () => {
|
|
96
|
+
// Leave the size absent; the tile uses its CSS box.
|
|
97
|
+
};
|
|
98
|
+
probe.src = url;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Release every preview held for one list of pending images.
|
|
102
|
+
*
|
|
103
|
+
* Called when a session's composer images are discarded wholesale — the images
|
|
104
|
+
* whose URLs are not in `keep` are dropped.
|
|
105
|
+
*
|
|
106
|
+
* @param images - images leaving the composer.
|
|
107
|
+
* @param keep - URLs that must survive because something else now owns them.
|
|
108
|
+
*/
|
|
109
|
+
export function releaseImagePreviews(images, keep = new Set()) {
|
|
110
|
+
for (const image of images) {
|
|
111
|
+
if (image.previewUrl !== undefined && !keep.has(image.previewUrl)) {
|
|
112
|
+
revokeImagePreviewUrl(image.previewUrl);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -15,6 +15,7 @@ function createRecord() {
|
|
|
15
15
|
return {
|
|
16
16
|
draft: "",
|
|
17
17
|
images: [],
|
|
18
|
+
files: [],
|
|
18
19
|
history: createInputHistoryState(),
|
|
19
20
|
revision: 0,
|
|
20
21
|
instanceId: crypto.randomUUID(),
|
|
@@ -47,9 +48,20 @@ function sameImages(left, right) {
|
|
|
47
48
|
*/
|
|
48
49
|
export class ComposerSessionLedger {
|
|
49
50
|
now;
|
|
51
|
+
onReleaseImages;
|
|
50
52
|
records = new Map();
|
|
51
|
-
constructor(now = Date.now
|
|
53
|
+
constructor(now = Date.now,
|
|
54
|
+
/**
|
|
55
|
+
* Release browser resources attached to images that are leaving the draft.
|
|
56
|
+
*
|
|
57
|
+
* Injected rather than imported: the ledger is a plain data structure and
|
|
58
|
+
* has no business knowing about blob URLs. Without this the URL and the
|
|
59
|
+
* `File` behind it stayed alive after a successful send — the transcript
|
|
60
|
+
* loads the delivered image from the server, so nothing else kept them.
|
|
61
|
+
*/
|
|
62
|
+
onReleaseImages) {
|
|
52
63
|
this.now = now;
|
|
64
|
+
this.onReleaseImages = onReleaseImages;
|
|
53
65
|
}
|
|
54
66
|
has(identity) {
|
|
55
67
|
return this.records.has(composerSessionKey(identity));
|
|
@@ -59,6 +71,7 @@ export class ComposerSessionLedger {
|
|
|
59
71
|
return {
|
|
60
72
|
draft: record.draft,
|
|
61
73
|
images: cloneImages(record.images),
|
|
74
|
+
files: structuredClone(record.files),
|
|
62
75
|
history: cloneHistory(record.history),
|
|
63
76
|
revision: record.revision,
|
|
64
77
|
draftVersion: record.revision === 0 && record.seededVersion ? record.seededVersion : `${record.instanceId}:${record.revision}`,
|
|
@@ -102,6 +115,24 @@ export class ComposerSessionLedger {
|
|
|
102
115
|
record.initialized = true;
|
|
103
116
|
return true;
|
|
104
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Replace the pending non-image attachments.
|
|
120
|
+
*
|
|
121
|
+
* Cloned on the way in for the same reason images are: the ledger is the
|
|
122
|
+
* single owner, so a caller that keeps mutating its own array must not change
|
|
123
|
+
* what a snapshot already returned.
|
|
124
|
+
*
|
|
125
|
+
* @param identity - owning composer session.
|
|
126
|
+
* @param files - the complete list.
|
|
127
|
+
* @returns whether the write was accepted.
|
|
128
|
+
*/
|
|
129
|
+
setFiles(identity, files) {
|
|
130
|
+
const record = this.record(identity);
|
|
131
|
+
record.files = structuredClone([...files]);
|
|
132
|
+
record.revision += 1;
|
|
133
|
+
record.initialized = true;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
105
136
|
recordHistory(identity, text) {
|
|
106
137
|
const record = this.record(identity);
|
|
107
138
|
record.history = recordInputHistoryEntry(record.history, text);
|
|
@@ -139,7 +170,7 @@ export class ComposerSessionLedger {
|
|
|
139
170
|
record.sequence += 1;
|
|
140
171
|
const sequence = record.sequence;
|
|
141
172
|
const controller = new AbortController();
|
|
142
|
-
const materialized = materializeComposerImages(record.draft, record.images);
|
|
173
|
+
const materialized = materializeComposerImages(record.draft, record.images, record.files);
|
|
143
174
|
const draftSnapshot = materialized.text;
|
|
144
175
|
const imageSnapshot = cloneImages(materialized.images);
|
|
145
176
|
const referenceSnapshot = structuredClone(record.references);
|
|
@@ -152,7 +183,9 @@ export class ComposerSessionLedger {
|
|
|
152
183
|
};
|
|
153
184
|
record.history = recordInputHistoryEntry(record.history, draftSnapshot);
|
|
154
185
|
record.draft = "";
|
|
186
|
+
this.onReleaseImages?.(record.images);
|
|
155
187
|
record.images = [];
|
|
188
|
+
record.files = [];
|
|
156
189
|
record.references = [];
|
|
157
190
|
record.revision += 1;
|
|
158
191
|
record.initialized = true;
|
|
@@ -233,6 +266,15 @@ export class ComposerSessionLedger {
|
|
|
233
266
|
for (const owned of record.attempts.values())
|
|
234
267
|
owned.controller.abort();
|
|
235
268
|
record.attempts.clear();
|
|
269
|
+
/*
|
|
270
|
+
* A session going away takes its unsent previews with it.
|
|
271
|
+
*
|
|
272
|
+
* These images were never sent, so nothing else will ever reference their
|
|
273
|
+
* blob URLs; dropping the record alone would leak every one of them.
|
|
274
|
+
*/
|
|
275
|
+
this.onReleaseImages?.(record.images);
|
|
276
|
+
for (const failed of record.failedImages)
|
|
277
|
+
this.onReleaseImages?.(failed);
|
|
236
278
|
this.records.delete(key);
|
|
237
279
|
}
|
|
238
280
|
record(identity) {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One attachment upload with progress.
|
|
3
|
+
*
|
|
4
|
+
* `fetch` has no upload-progress event, so the composer could only say
|
|
5
|
+
* "正在保存图片…" while a 5 MiB file went up. `XMLHttpRequest` reports
|
|
6
|
+
* `upload.onprogress`, which is what DSH uses too; this module keeps the whole
|
|
7
|
+
* difference contained so callers keep an async interface.
|
|
8
|
+
*
|
|
9
|
+
* It also carries the non-image path: the server takes any attachment, writes it
|
|
10
|
+
* to the temp cache and returns a path the model reads through an `@path`
|
|
11
|
+
* mention.
|
|
12
|
+
*/
|
|
13
|
+
/** How long one attachment upload may stay silent before it is failed. */
|
|
14
|
+
const UPLOAD_TIMEOUT_MS = 120_000;
|
|
15
|
+
/**
|
|
16
|
+
* Read the server's `{ path }` out of a response body.
|
|
17
|
+
*
|
|
18
|
+
* @param text - the raw response text.
|
|
19
|
+
* @returns the path, or undefined when the body is not the expected shape.
|
|
20
|
+
*/
|
|
21
|
+
function pathFrom(text) {
|
|
22
|
+
try {
|
|
23
|
+
const body = JSON.parse(text);
|
|
24
|
+
return typeof body.path === "string" && body.path !== "" ? body.path : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read a server error message out of a failed response.
|
|
32
|
+
*
|
|
33
|
+
* @param text - the raw response text.
|
|
34
|
+
* @param status - the HTTP status, used as a last resort.
|
|
35
|
+
* @returns a message safe to show.
|
|
36
|
+
*/
|
|
37
|
+
function errorFrom(text, status) {
|
|
38
|
+
try {
|
|
39
|
+
const body = JSON.parse(text);
|
|
40
|
+
const message = body.error?.message;
|
|
41
|
+
if (typeof message === "string" && message !== "")
|
|
42
|
+
return message;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Not JSON: fall through to the status.
|
|
46
|
+
}
|
|
47
|
+
return `HTTP ${status}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Upload one attachment into the temp cache.
|
|
51
|
+
*
|
|
52
|
+
* @param request - endpoint, payload, and progress/abort hooks.
|
|
53
|
+
* @returns the absolute path the model reads.
|
|
54
|
+
*/
|
|
55
|
+
export function uploadComposerAttachment(request) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const url = `${request.origin}/api/operator/v1/chat/image-cache?workspaceId=${encodeURIComponent(request.workspaceId)}`;
|
|
58
|
+
const xhr = new XMLHttpRequest();
|
|
59
|
+
xhr.open("POST", url, true);
|
|
60
|
+
/*
|
|
61
|
+
* A stalled upload must fail rather than hang.
|
|
62
|
+
*
|
|
63
|
+
* `ontimeout` was registered without ever setting `timeout`, so the handler
|
|
64
|
+
* could not fire: on a network black hole the composer stayed at
|
|
65
|
+
*「正在上传…」forever and the drag overlay then reported drops as
|
|
66
|
+
* unavailable, with no way out but a reload.
|
|
67
|
+
*/
|
|
68
|
+
xhr.timeout = UPLOAD_TIMEOUT_MS;
|
|
69
|
+
xhr.withCredentials = true;
|
|
70
|
+
xhr.setRequestHeader("content-type", "application/json");
|
|
71
|
+
xhr.setRequestHeader("x-loop-console-confirmation", request.confirmation);
|
|
72
|
+
if (request.onProgress !== undefined) {
|
|
73
|
+
const report = request.onProgress;
|
|
74
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
75
|
+
// `lengthComputable` is false for a streamed body; report what we know.
|
|
76
|
+
report(event.lengthComputable
|
|
77
|
+
? { loaded: event.loaded, total: event.total }
|
|
78
|
+
: { loaded: event.loaded });
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const onAbort = () => xhr.abort();
|
|
82
|
+
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
83
|
+
const settle = () => {
|
|
84
|
+
request.signal?.removeEventListener("abort", onAbort);
|
|
85
|
+
};
|
|
86
|
+
xhr.onload = () => {
|
|
87
|
+
settle();
|
|
88
|
+
const path = pathFrom(xhr.responseText);
|
|
89
|
+
if (xhr.status >= 200 && xhr.status < 300 && path !== undefined) {
|
|
90
|
+
resolve(path);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
reject(new Error(errorFrom(xhr.responseText, xhr.status)));
|
|
94
|
+
};
|
|
95
|
+
xhr.onerror = () => {
|
|
96
|
+
settle();
|
|
97
|
+
reject(new Error("网络错误,附件上传失败"));
|
|
98
|
+
};
|
|
99
|
+
xhr.ontimeout = () => {
|
|
100
|
+
settle();
|
|
101
|
+
reject(new Error("附件上传超时"));
|
|
102
|
+
};
|
|
103
|
+
xhr.onabort = () => {
|
|
104
|
+
settle();
|
|
105
|
+
// An abort is a cancellation, not a failure: keep the wording neutral so
|
|
106
|
+
// a deliberate Stop does not look like a bug.
|
|
107
|
+
reject(new Error("附件上传已取消"));
|
|
108
|
+
};
|
|
109
|
+
xhr.send(JSON.stringify({
|
|
110
|
+
mimeType: request.mimeType,
|
|
111
|
+
data: request.data,
|
|
112
|
+
...(request.name === undefined ? {} : { name: request.name }),
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remaining time for a gate card's expiry.
|
|
3
|
+
*
|
|
4
|
+
* Kept as a pure function so the wording and the rounding can be tested without
|
|
5
|
+
* mounting a component or faking timers.
|
|
6
|
+
*/
|
|
7
|
+
/** One minute: the finest granularity the card needs. */
|
|
8
|
+
const MINUTE = 60_000;
|
|
9
|
+
const HOUR = 60 * MINUTE;
|
|
10
|
+
const DAY = 24 * HOUR;
|
|
11
|
+
/**
|
|
12
|
+
* Describe how long a gate card stays actionable.
|
|
13
|
+
*
|
|
14
|
+
* Both a relative and an absolute reading are given: "还剩 12 分钟" alone drifts
|
|
15
|
+
* as the reader leaves the card open, and the clock time alone forces them to do
|
|
16
|
+
* the subtraction. Past a day the relative part stops being useful, so only the
|
|
17
|
+
* clock time is shown.
|
|
18
|
+
*
|
|
19
|
+
* @param expiresAt - the card's ISO deadline.
|
|
20
|
+
* @param now - current epoch ms, injectable so tests need no fake timers.
|
|
21
|
+
* @returns the rendered text plus the machine-readable state.
|
|
22
|
+
*/
|
|
23
|
+
export function describeGateExpiry(expiresAt, now = Date.now()) {
|
|
24
|
+
const deadline = Date.parse(expiresAt);
|
|
25
|
+
if (!Number.isFinite(deadline))
|
|
26
|
+
return { text: "", expired: false, remainingMs: Number.NaN };
|
|
27
|
+
const remainingMs = deadline - now;
|
|
28
|
+
if (remainingMs <= 0)
|
|
29
|
+
return { text: "已过期", expired: true, remainingMs };
|
|
30
|
+
const clock = new Date(deadline).toLocaleTimeString("zh-CN", {
|
|
31
|
+
hour: "2-digit",
|
|
32
|
+
minute: "2-digit",
|
|
33
|
+
hour12: false,
|
|
34
|
+
});
|
|
35
|
+
if (remainingMs >= DAY)
|
|
36
|
+
return { text: `${clock} 过期`, expired: false, remainingMs };
|
|
37
|
+
// Round up: with 30 seconds left the honest reading is "还剩 1 分钟", not 0.
|
|
38
|
+
const minutes = Math.ceil(remainingMs / MINUTE);
|
|
39
|
+
const relative = remainingMs >= HOUR
|
|
40
|
+
? `还剩 ${Math.floor(remainingMs / HOUR)} 小时 ${Math.ceil((remainingMs % HOUR) / MINUTE)} 分钟`
|
|
41
|
+
: `还剩 ${minutes} 分钟`;
|
|
42
|
+
return { text: `${relative}(${clock} 过期)`, expired: false, remainingMs };
|
|
43
|
+
}
|
|
@@ -49,10 +49,23 @@ export function countTurnFlowItems(entries) {
|
|
|
49
49
|
/**
|
|
50
50
|
* Summary label for a completed turn's process disclosure.
|
|
51
51
|
*
|
|
52
|
+
* A turn that stopped or failed reports that state INSTEAD of its counts. The
|
|
53
|
+
* counts describe work that was carried out; when the reader stopped the turn
|
|
54
|
+
* early, or it died mid-flight, "12 次工具调用" reads as a finished job and
|
|
55
|
+
* hides the one fact worth knowing. DSH makes the same split
|
|
56
|
+
* (`TurnProcessNodeView.tsx:27-30`): stopped and failed replace the duration
|
|
57
|
+
* and counts rather than sitting beside them.
|
|
58
|
+
*
|
|
52
59
|
* @param counts - bucket counts from {@link countTurnProcessItems}.
|
|
53
|
-
* @
|
|
60
|
+
* @param turnState - durable turn state, when the server has reported one.
|
|
61
|
+
* @returns `已停止`/`处理失败` for a stopped or failed turn, otherwise
|
|
62
|
+
* `N 次工具调用 · M 条消息 · K 个 subagent`, or「已思考」when empty.
|
|
54
63
|
*/
|
|
55
|
-
export function buildTurnProcessLabel(counts) {
|
|
64
|
+
export function buildTurnProcessLabel(counts, turnState) {
|
|
65
|
+
if (turnState === "aborted")
|
|
66
|
+
return "已停止";
|
|
67
|
+
if (turnState === "failed")
|
|
68
|
+
return "处理失败";
|
|
56
69
|
return ([
|
|
57
70
|
counts.toolCalls > 0 ? `${counts.toolCalls} 次工具调用` : "",
|
|
58
71
|
counts.messages > 0 ? `${counts.messages} 条消息` : "",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far away a scheduled instant is, in words.
|
|
3
|
+
*
|
|
4
|
+
* A bare timestamp cannot answer the question an operator actually has — "is
|
|
5
|
+
* this about to fire, or has it been stuck for hours?". DSH renders both halves
|
|
6
|
+
* (`schedule-format.ts`: `nextRunParts` → `{ absolute, relative }`), and the
|
|
7
|
+
* relative half is what distinguishes「3 分钟后」from「已逾期 2 小时」at a glance.
|
|
8
|
+
*
|
|
9
|
+
* The unit is the largest one that the gap fills, rounded the way the direction
|
|
10
|
+
* demands: a future time rounds up (「2 分钟后」, never「1 分钟后」for something
|
|
11
|
+
* 90 seconds away) and a past time rounds down, so a task that missed by 90
|
|
12
|
+
* seconds reads 「已逾期 1 分钟」rather than overstating the delay.
|
|
13
|
+
*/
|
|
14
|
+
const MINUTE = 60_000;
|
|
15
|
+
const HOUR = 60 * MINUTE;
|
|
16
|
+
const DAY = 24 * HOUR;
|
|
17
|
+
/** Units from largest to smallest; the first that fits is used. */
|
|
18
|
+
const UNITS = [
|
|
19
|
+
{ ms: DAY, label: "天" },
|
|
20
|
+
{ ms: HOUR, label: "小时" },
|
|
21
|
+
{ ms: MINUTE, label: "分钟" },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Describe the distance to a scheduled instant.
|
|
25
|
+
*
|
|
26
|
+
* @param scheduledAt - the target instant, as an ISO string.
|
|
27
|
+
* @param now - the current epoch milliseconds.
|
|
28
|
+
* @returns 「N 分钟/小时/天后」、「已逾期 N …」、or「已到时间」.
|
|
29
|
+
*/
|
|
30
|
+
export function describeRelativeTime(scheduledAt, now) {
|
|
31
|
+
if (scheduledAt === undefined || scheduledAt === "")
|
|
32
|
+
return "";
|
|
33
|
+
const target = Date.parse(scheduledAt);
|
|
34
|
+
if (Number.isNaN(target))
|
|
35
|
+
return "";
|
|
36
|
+
const difference = target - now;
|
|
37
|
+
if (Math.abs(difference) < 30_000)
|
|
38
|
+
return "已到时间";
|
|
39
|
+
const magnitude = Math.abs(difference);
|
|
40
|
+
const unit = UNITS.find((candidate) => magnitude >= candidate.ms) ?? { ms: 1000, label: "秒" };
|
|
41
|
+
const value = Math.max(1, difference > 0 ? Math.ceil(magnitude / unit.ms) : Math.floor(magnitude / unit.ms));
|
|
42
|
+
return difference > 0 ? `${value} ${unit.label}后` : `已逾期 ${value} ${unit.label}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Both halves of a next-run label, for callers that show them together.
|
|
46
|
+
*
|
|
47
|
+
* @param scheduledAt - the target instant, as an ISO string.
|
|
48
|
+
* @param now - the current epoch milliseconds.
|
|
49
|
+
* @param absolute - the already-formatted absolute time.
|
|
50
|
+
* @returns the absolute text and the relative text (empty when unknown).
|
|
51
|
+
*/
|
|
52
|
+
export function nextRunLabel(scheduledAt, now, absolute) {
|
|
53
|
+
return { absolute, relative: describeRelativeTime(scheduledAt, now) };
|
|
54
|
+
}
|