@tea-agent/loop-agent 0.53.0-next.1 → 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 +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
|
@@ -8,6 +8,12 @@ import { completeSlashCommand, slashCompletionQuery } from "./slash-completion.j
|
|
|
8
8
|
import { attachRuntimeSnapshotController } from "./useRuntimeSnapshot.js";
|
|
9
9
|
import { isComposerImageFile, MAX_COMPOSER_IMAGES, normalizeComposerImageMime, } from "./composer-image-paths.js";
|
|
10
10
|
import { parseChatReferences } from "../../chat/chat-references.js";
|
|
11
|
+
import { uploadComposerAttachment, } from "./composer-upload.js";
|
|
12
|
+
import { createImagePreviewUrl, probeImageSize, releaseImagePreviews, revokeImagePreviewUrl, } from "./composer-image-preview.js";
|
|
13
|
+
/** How many non-image attachments one draft may carry. */
|
|
14
|
+
const MAX_COMPOSER_FILES = 4;
|
|
15
|
+
/** Ceiling for one non-image attachment, matching the server's cache limit. */
|
|
16
|
+
const MAX_COMPOSER_FILE_BYTES = 10 * 1024 * 1024;
|
|
11
17
|
function sameComposerSession(left, right) {
|
|
12
18
|
if (!left || !right)
|
|
13
19
|
return left === right;
|
|
@@ -21,25 +27,92 @@ function readFileAsDataUrl(file) {
|
|
|
21
27
|
reader.readAsDataURL(file);
|
|
22
28
|
});
|
|
23
29
|
}
|
|
24
|
-
async function cacheComposerImageFile(origin, workspaceId, file) {
|
|
30
|
+
async function cacheComposerImageFile(origin, workspaceId, file, onProgress) {
|
|
25
31
|
const dataUrl = await readFileAsDataUrl(file);
|
|
26
32
|
const data = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
|
27
33
|
const mimeType = normalizeComposerImageMime(file.type);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const path = await uploadComposerAttachment({
|
|
35
|
+
origin,
|
|
36
|
+
workspaceId,
|
|
37
|
+
mimeType,
|
|
38
|
+
data,
|
|
39
|
+
name: file.name,
|
|
40
|
+
confirmation: confirmationToken(),
|
|
41
|
+
...(onProgress === undefined ? {} : { onProgress }),
|
|
36
42
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const name = file.name.trim() || path.split(/[/\\]/).pop() || "image";
|
|
44
|
+
const previewUrl = createImagePreviewUrl(file);
|
|
45
|
+
/*
|
|
46
|
+
* A `blob:` preview, not a base64 copy.
|
|
47
|
+
*
|
|
48
|
+
* `data` must stay empty: `materializeComposerImages` treats an image with a
|
|
49
|
+
* `path` as an `@path` mention the model reads with the read tool, and any
|
|
50
|
+
* non-empty `data` would additionally ship the same bytes as an inline
|
|
51
|
+
* attachment — the picture would arrive twice.
|
|
52
|
+
*
|
|
53
|
+
* The preview is a URL that points at the operator's own `File`
|
|
54
|
+
* (`composer-image-preview`), so the pending state carries one short string
|
|
55
|
+
* instead of a base64 copy that is ~33% larger and cloned on every snapshot.
|
|
56
|
+
*/
|
|
57
|
+
return {
|
|
58
|
+
name,
|
|
59
|
+
type: "image",
|
|
60
|
+
mimeType,
|
|
61
|
+
data: "",
|
|
62
|
+
path,
|
|
63
|
+
...(previewUrl ? { previewUrl } : {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Upload one non-image attachment.
|
|
68
|
+
*
|
|
69
|
+
* The model reaches it through the same `@path` mention an image uses; the read
|
|
70
|
+
* tool opens whatever the extension says. Nothing here inspects the bytes — the
|
|
71
|
+
* size ceiling and the temp-cache confinement are the server's job.
|
|
72
|
+
*
|
|
73
|
+
* @param origin - console origin.
|
|
74
|
+
* @param workspaceId - owning workspace.
|
|
75
|
+
* @param file - the picked file.
|
|
76
|
+
* @param onProgress - upload progress sink.
|
|
77
|
+
* @returns the pending file card.
|
|
78
|
+
*/
|
|
79
|
+
async function cacheComposerFile(origin, workspaceId, file, onProgress) {
|
|
80
|
+
const dataUrl = await readFileAsDataUrl(file);
|
|
81
|
+
const data = dataUrl.slice(dataUrl.indexOf(",") + 1);
|
|
82
|
+
const path = await uploadComposerAttachment({
|
|
83
|
+
origin,
|
|
84
|
+
workspaceId,
|
|
85
|
+
mimeType: file.type || "application/octet-stream",
|
|
86
|
+
data,
|
|
87
|
+
name: file.name,
|
|
88
|
+
confirmation: confirmationToken(),
|
|
89
|
+
...(onProgress === undefined ? {} : { onProgress }),
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
name: file.name.trim() || path.split(/[/\\]/).pop() || "file",
|
|
93
|
+
type: "file",
|
|
94
|
+
mimeType: file.type || "application/octet-stream",
|
|
95
|
+
path,
|
|
96
|
+
byteLength: file.size,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Drop one pending image from the list.
|
|
101
|
+
*
|
|
102
|
+
* The ledger clones on both read and write, so a rendered tile never holds the
|
|
103
|
+
* same object the list does — matching by reference silently removes nothing.
|
|
104
|
+
* An image is identified by its temp-file path, or by its name for a pasted one.
|
|
105
|
+
*
|
|
106
|
+
* Exported rather than inlined into the hook so the test exercises the real
|
|
107
|
+
* predicate instead of a copy of it.
|
|
108
|
+
*
|
|
109
|
+
* @param items - the current list, as the state updater sees it.
|
|
110
|
+
* @param image - the tile the reader clicked (a clone of the stored entry).
|
|
111
|
+
* @returns the list without that image.
|
|
112
|
+
*/
|
|
113
|
+
export function removePendingImage(items, image) {
|
|
114
|
+
const key = image.path ?? image.name;
|
|
115
|
+
return items.filter((item) => (item.path ?? item.name) !== key);
|
|
43
116
|
}
|
|
44
117
|
/** Composer state: input text, @file palette, image attachments, /shortcuts,
|
|
45
118
|
* IME composition guards, auto-grow and server-side draft sync. */
|
|
@@ -47,8 +120,17 @@ export function useComposer(params) {
|
|
|
47
120
|
const { origin, sessionIdentity, sessionMode, sessionReady = true, refs, setError, onUnrecoverableSession, } = params;
|
|
48
121
|
const sessionId = sessionIdentity?.sessionId;
|
|
49
122
|
const ledgerRef = useRef(null);
|
|
50
|
-
if (!ledgerRef.current)
|
|
51
|
-
|
|
123
|
+
if (!ledgerRef.current) {
|
|
124
|
+
/*
|
|
125
|
+
* Release previews when a submitted image leaves the draft.
|
|
126
|
+
*
|
|
127
|
+
* The transcript loads the delivered image from the server, so the local
|
|
128
|
+
* blob — which pins the operator's `File` — is dead weight the moment the
|
|
129
|
+
* send is accepted. Without this, every sent image stayed in memory for
|
|
130
|
+
* the life of the tab.
|
|
131
|
+
*/
|
|
132
|
+
ledgerRef.current = new ComposerSessionLedger(Date.now, releaseImagePreviews);
|
|
133
|
+
}
|
|
52
134
|
const ledger = ledgerRef.current;
|
|
53
135
|
const draftSyncQueueRef = useRef(null);
|
|
54
136
|
if (!draftSyncQueueRef.current)
|
|
@@ -60,9 +142,10 @@ export function useComposer(params) {
|
|
|
60
142
|
const [, forceRender] = useReducer((version) => version + 1, 0);
|
|
61
143
|
const activeSnapshot = sessionIdentity
|
|
62
144
|
? ledger.snapshot(sessionIdentity)
|
|
63
|
-
: { draft: "", images: [], references: [], draftVersion: "", failedDrafts: [] };
|
|
145
|
+
: { draft: "", images: [], files: [], references: [], draftVersion: "", failedDrafts: [] };
|
|
64
146
|
const input = activeSnapshot.draft;
|
|
65
147
|
const pendingImages = activeSnapshot.images;
|
|
148
|
+
const pendingFiles = activeSnapshot.files;
|
|
66
149
|
const pendingReferences = activeSnapshot.references;
|
|
67
150
|
const failedDrafts = activeSnapshot.failedDrafts;
|
|
68
151
|
const referenceSyncKey = JSON.stringify(pendingReferences);
|
|
@@ -116,6 +199,15 @@ export function useComposer(params) {
|
|
|
116
199
|
ledger.setImages(identity, next);
|
|
117
200
|
forceRender();
|
|
118
201
|
}, [ledger]);
|
|
202
|
+
const setPendingFiles = useCallback((value) => {
|
|
203
|
+
const identity = activeIdentityRef.current;
|
|
204
|
+
if (!identity)
|
|
205
|
+
return;
|
|
206
|
+
const previous = ledger.snapshot(identity).files;
|
|
207
|
+
const next = typeof value === "function" ? value(previous) : value;
|
|
208
|
+
ledger.setFiles(identity, next);
|
|
209
|
+
forceRender();
|
|
210
|
+
}, [ledger]);
|
|
119
211
|
const addReference = useCallback((identity, reference, generation) => {
|
|
120
212
|
if (!sameComposerSession(activeIdentityRef.current, identity) || refs.sessionGenerationRef.current !== generation)
|
|
121
213
|
return false;
|
|
@@ -516,6 +608,34 @@ export function useComposer(params) {
|
|
|
516
608
|
}, [input]);
|
|
517
609
|
const imageSaveCountRef = useRef(0);
|
|
518
610
|
const [savingImages, setSavingImages] = useState(false);
|
|
611
|
+
const fileSaveCountRef = useRef(0);
|
|
612
|
+
const [savingFiles, setSavingFiles] = useState(false);
|
|
613
|
+
/*
|
|
614
|
+
* Per-file upload progress, keyed by filename.
|
|
615
|
+
*
|
|
616
|
+
* `XMLHttpRequest` is the only browser API that reports upload progress, so
|
|
617
|
+
* this is what makes「正在上传…」an actual percentage instead of a spinner.
|
|
618
|
+
* Keyed by name because a pending file has no id until its upload returns a
|
|
619
|
+
* path, and two files with the same name collapse into one entry — which is
|
|
620
|
+
* also what the card list shows at this point.
|
|
621
|
+
*/
|
|
622
|
+
const [fileProgress, setFileProgress] = useState({});
|
|
623
|
+
/*
|
|
624
|
+
* Upload state is per-session UI, so switching sessions clears it.
|
|
625
|
+
*
|
|
626
|
+
* Both banners are hook-level booleans fed by a per-session counter, and an
|
|
627
|
+
* upload can outlive the session it started in. Without this, switching away
|
|
628
|
+
* from an in-flight upload left「正在保存图片…」on the new session and made the
|
|
629
|
+
* drag overlay treat drops as unavailable.
|
|
630
|
+
*/
|
|
631
|
+
const sessionKeyForUploads = sessionIdentity ? composerSessionKey(sessionIdentity) : "";
|
|
632
|
+
useEffect(() => {
|
|
633
|
+
setSavingImages(false);
|
|
634
|
+
setSavingFiles(false);
|
|
635
|
+
setFileProgress({});
|
|
636
|
+
imageSaveCountRef.current = 0;
|
|
637
|
+
fileSaveCountRef.current = 0;
|
|
638
|
+
}, [sessionKeyForUploads]);
|
|
519
639
|
const addImagesFromFiles = useCallback((files) => {
|
|
520
640
|
const owner = activeIdentityRef.current;
|
|
521
641
|
if (!owner) {
|
|
@@ -547,13 +667,52 @@ export function useComposer(params) {
|
|
|
547
667
|
setSavingImages(true);
|
|
548
668
|
void Promise.all(valid.map((file) => cacheComposerImageFile(origin, workspaceId, file)))
|
|
549
669
|
.then((loaded) => {
|
|
550
|
-
if (!ledger.has(ownerIdentity) || loaded.length === 0)
|
|
670
|
+
if (!ledger.has(ownerIdentity) || loaded.length === 0) {
|
|
671
|
+
/*
|
|
672
|
+
* The session went away while the upload was in flight.
|
|
673
|
+
* These previews now have no owner, and a blob URL that is
|
|
674
|
+
* never revoked pins the whole file for the page's lifetime.
|
|
675
|
+
*/
|
|
676
|
+
releaseImagePreviews(loaded);
|
|
551
677
|
return;
|
|
678
|
+
}
|
|
552
679
|
const current = ledger.snapshot(ownerIdentity).images;
|
|
553
|
-
|
|
680
|
+
const accepted = [...current, ...loaded].slice(0, MAX_COMPOSER_IMAGES);
|
|
681
|
+
ledger.setImages(ownerIdentity, accepted);
|
|
682
|
+
/*
|
|
683
|
+
* A file past the composer's cap never reached the list, so its
|
|
684
|
+
* preview has no tile to draw it either.
|
|
685
|
+
*/
|
|
686
|
+
const kept = new Set(accepted
|
|
687
|
+
.map((image) => image.previewUrl)
|
|
688
|
+
.filter((url) => url !== undefined));
|
|
689
|
+
releaseImagePreviews(loaded, kept);
|
|
690
|
+
/*
|
|
691
|
+
* Learn intrinsic sizes once the browser has parsed the headers.
|
|
692
|
+
* The write is keyed by previewUrl rather than by object identity,
|
|
693
|
+
* because the ledger hands back clones.
|
|
694
|
+
*/
|
|
695
|
+
for (const image of accepted) {
|
|
696
|
+
if (image.previewUrl === undefined || image.width !== undefined)
|
|
697
|
+
continue;
|
|
698
|
+
probeImageSize(image.previewUrl, ({ width, height }) => {
|
|
699
|
+
if (!ledger.has(ownerIdentity))
|
|
700
|
+
return;
|
|
701
|
+
ledger.setImages(ownerIdentity, ledger.snapshot(ownerIdentity).images.map((entry) => entry.previewUrl === image.previewUrl
|
|
702
|
+
? { ...entry, width, height }
|
|
703
|
+
: entry));
|
|
704
|
+
if (sameComposerSession(activeIdentityRef.current, ownerIdentity))
|
|
705
|
+
forceRender();
|
|
706
|
+
});
|
|
707
|
+
}
|
|
554
708
|
if (sameComposerSession(activeIdentityRef.current, ownerIdentity))
|
|
555
709
|
forceRender();
|
|
556
710
|
}, (error) => {
|
|
711
|
+
/*
|
|
712
|
+
* No preview to release here: `cacheComposerImageFile` mints the
|
|
713
|
+
* URL only after the upload succeeds, so a rejection leaves nothing
|
|
714
|
+
* behind.
|
|
715
|
+
*/
|
|
557
716
|
if (sameComposerSession(activeIdentityRef.current, ownerIdentity))
|
|
558
717
|
setError(error instanceof Error ? error.message : "图片保存失败");
|
|
559
718
|
})
|
|
@@ -563,9 +722,114 @@ export function useComposer(params) {
|
|
|
563
722
|
setSavingImages(false);
|
|
564
723
|
});
|
|
565
724
|
}, [ledger, origin, refs, setError]);
|
|
725
|
+
/*
|
|
726
|
+
* Remove by IDENTITY, not by reference.
|
|
727
|
+
*
|
|
728
|
+
* `ComposerSessionLedger.snapshot()` returns `structuredClone`d images and
|
|
729
|
+
* `setImages()` clones again on the way in, so the object a rendered tile
|
|
730
|
+
* holds is never the object the updater's list contains. The previous
|
|
731
|
+
* `filter(item => item !== image)` therefore matched nothing: the × was
|
|
732
|
+
* reachable, its handler ran, and the list never changed.
|
|
733
|
+
*
|
|
734
|
+
* `removePendingImage` lives outside the hook so a test can exercise the real
|
|
735
|
+
* predicate instead of a copy of it.
|
|
736
|
+
*/
|
|
566
737
|
const removeImage = useCallback((image) => {
|
|
567
|
-
setPendingImages((items) => items
|
|
738
|
+
setPendingImages((items) => removePendingImage(items, image));
|
|
739
|
+
/*
|
|
740
|
+
* Release the preview only AFTER the list drops it.
|
|
741
|
+
*
|
|
742
|
+
* Revoking first would leave the tile rendering a dead URL for one frame —
|
|
743
|
+
* a visible flash of a broken image on the row the operator just clicked.
|
|
744
|
+
*/
|
|
745
|
+
revokeImagePreviewUrl(image.previewUrl);
|
|
568
746
|
}, [setPendingImages]);
|
|
747
|
+
/**
|
|
748
|
+
* Upload one picked non-image file.
|
|
749
|
+
*
|
|
750
|
+
* Files share the image path: the bytes land in the temp cache and the model
|
|
751
|
+
* receives an `@path` mention. Unlike an image there is no preview and no
|
|
752
|
+
* inline channel — a file card names it and the read tool opens it.
|
|
753
|
+
*/
|
|
754
|
+
const addFilesFromFiles = useCallback((files) => {
|
|
755
|
+
const owner = activeIdentityRef.current;
|
|
756
|
+
if (!owner) {
|
|
757
|
+
setError("请先打开会话再添加文件");
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const ownerIdentity = { ...owner };
|
|
761
|
+
const workspaceId = owner.workspaceId?.trim() ||
|
|
762
|
+
refs.sessionRef.current?.workspaceId?.trim() ||
|
|
763
|
+
"";
|
|
764
|
+
if (!workspaceId) {
|
|
765
|
+
setError("请先选择工作区再添加文件");
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
const room = MAX_COMPOSER_FILES -
|
|
769
|
+
ledger.snapshot(ownerIdentity).files.length -
|
|
770
|
+
fileSaveCountRef.current;
|
|
771
|
+
if (room <= 0) {
|
|
772
|
+
setError(`最多附加 ${MAX_COMPOSER_FILES} 个文件`);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const selected = Array.from(files).slice(0, room);
|
|
776
|
+
const oversized = selected.filter((file) => file.size > MAX_COMPOSER_FILE_BYTES);
|
|
777
|
+
if (oversized.length > 0) {
|
|
778
|
+
setError(`单个文件不超过 ${MAX_COMPOSER_FILE_BYTES / 1024 / 1024} MiB`);
|
|
779
|
+
}
|
|
780
|
+
const valid = selected.filter((file) => file.size > 0 && file.size <= MAX_COMPOSER_FILE_BYTES);
|
|
781
|
+
if (valid.length === 0)
|
|
782
|
+
return;
|
|
783
|
+
fileSaveCountRef.current += valid.length;
|
|
784
|
+
setSavingFiles(true);
|
|
785
|
+
void Promise.all(valid.map((file) => cacheComposerFile(origin, workspaceId, file, (progress) => {
|
|
786
|
+
setFileProgress((current) => ({ ...current, [file.name]: progress }));
|
|
787
|
+
})))
|
|
788
|
+
.then((loaded) => {
|
|
789
|
+
/*
|
|
790
|
+
* Keep the progress entries until AFTER the list has them.
|
|
791
|
+
*
|
|
792
|
+
* A card renders only from `pendingFiles`, and it reads its
|
|
793
|
+
* meter from `fileProgress[name]`. Clearing first (as this did)
|
|
794
|
+
* meant the entry was always gone by the time the card existed,
|
|
795
|
+
* so the percentage and bar described as shipped here could
|
|
796
|
+
* never appear. Clearing after the write, in the same tick, is
|
|
797
|
+
* what makes the meter live for the upload's final moment and
|
|
798
|
+
* still leaves no residue.
|
|
799
|
+
*/
|
|
800
|
+
if (!ledger.has(ownerIdentity) || loaded.length === 0) {
|
|
801
|
+
setFileProgress((current) => {
|
|
802
|
+
const next = { ...current };
|
|
803
|
+
for (const file of valid)
|
|
804
|
+
delete next[file.name];
|
|
805
|
+
return next;
|
|
806
|
+
});
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const current = ledger.snapshot(ownerIdentity).files;
|
|
810
|
+
ledger.setFiles(ownerIdentity, [...current, ...loaded].slice(0, MAX_COMPOSER_FILES));
|
|
811
|
+
setFileProgress((current) => {
|
|
812
|
+
const next = { ...current };
|
|
813
|
+
for (const file of valid)
|
|
814
|
+
delete next[file.name];
|
|
815
|
+
return next;
|
|
816
|
+
});
|
|
817
|
+
if (sameComposerSession(activeIdentityRef.current, ownerIdentity))
|
|
818
|
+
forceRender();
|
|
819
|
+
}, (error) => {
|
|
820
|
+
if (sameComposerSession(activeIdentityRef.current, ownerIdentity))
|
|
821
|
+
setError(error instanceof Error ? error.message : "文件上传失败");
|
|
822
|
+
})
|
|
823
|
+
.finally(() => {
|
|
824
|
+
fileSaveCountRef.current = Math.max(0, fileSaveCountRef.current - valid.length);
|
|
825
|
+
if (fileSaveCountRef.current === 0)
|
|
826
|
+
setSavingFiles(false);
|
|
827
|
+
});
|
|
828
|
+
}, [ledger, origin, refs, setError]);
|
|
829
|
+
/** Drop one pending file. Identity is the path, as with images. */
|
|
830
|
+
const removeFile = useCallback((file) => {
|
|
831
|
+
setPendingFiles((items) => items.filter((item) => item.path !== file.path));
|
|
832
|
+
}, [setPendingFiles]);
|
|
569
833
|
// Chromium handles growth in CSS without forcing a layout read on every key.
|
|
570
834
|
// Keep a deferred fallback for browsers that do not support field-sizing.
|
|
571
835
|
useEffect(() => {
|
|
@@ -690,6 +954,11 @@ export function useComposer(params) {
|
|
|
690
954
|
savingImages,
|
|
691
955
|
addImagesFromFiles,
|
|
692
956
|
removeImage,
|
|
957
|
+
pendingFiles,
|
|
958
|
+
savingFiles,
|
|
959
|
+
fileProgress,
|
|
960
|
+
addFilesFromFiles,
|
|
961
|
+
removeFile,
|
|
693
962
|
shortcutOpen,
|
|
694
963
|
setShortcutOpen,
|
|
695
964
|
shortcutIndex,
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { requestAutomation } from "./automation-catalog-model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Per-session count of enabled scheduled tasks.
|
|
5
|
+
*
|
|
6
|
+
* The sidebar row needs one number per session, and the server already projects
|
|
7
|
+
* exactly that: the automation catalog carries `activeReminders`, a
|
|
8
|
+
* `sessionId -> count` map (`automation-actions.ts:40`). This hook reads that one
|
|
9
|
+
* catalog so a row never costs a round-trip of its own — the same shape DSH uses
|
|
10
|
+
* with a single shared catalog behind every `SessionScheduleMark`.
|
|
11
|
+
*
|
|
12
|
+
* Polling matches the cadence of the automation page itself. A scheduled task
|
|
13
|
+
* changes state on the server's clock, not on anything this tab does, so there
|
|
14
|
+
* is no event to subscribe to here.
|
|
15
|
+
*
|
|
16
|
+
* @param origin - console origin.
|
|
17
|
+
* @param workspaceId - workspace whose catalog to read; empty disables the hook.
|
|
18
|
+
* @returns counts keyed by session id, empty until the first read resolves.
|
|
19
|
+
*/
|
|
20
|
+
/** How often the catalog is re-read; the automation page polls at the same rate. */
|
|
21
|
+
const REFRESH_MS = 15_000;
|
|
22
|
+
/**
|
|
23
|
+
* Read the `activeReminders` map out of a catalog response.
|
|
24
|
+
*
|
|
25
|
+
* Every entry is validated: the value reaches `aria-label` text, and a
|
|
26
|
+
* malformed count would announce nonsense to a screen reader.
|
|
27
|
+
*
|
|
28
|
+
* @param value - the raw response body.
|
|
29
|
+
* @returns a clean `sessionId -> count` map.
|
|
30
|
+
*/
|
|
31
|
+
export function parseActiveReminders(value) {
|
|
32
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
33
|
+
return {};
|
|
34
|
+
const counts = {};
|
|
35
|
+
for (const [sessionId, raw] of Object.entries(value)) {
|
|
36
|
+
if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) {
|
|
37
|
+
counts[sessionId] = raw;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return counts;
|
|
41
|
+
}
|
|
42
|
+
export function useSessionAutomationCounts(origin, workspaceId) {
|
|
43
|
+
const [counts, setCounts] = useState({});
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
/*
|
|
46
|
+
* Clear first, always.
|
|
47
|
+
*
|
|
48
|
+
* Switching workspaces must not leave the previous workspace's counts on
|
|
49
|
+
* screen: those session ids are not in the new list, but the map is keyed
|
|
50
|
+
* by id and a stale entry for a *reused* id would show a mark that is not
|
|
51
|
+
* there. Starting from empty also makes the dependency honest — the effect
|
|
52
|
+
* owns the read for exactly one workspace.
|
|
53
|
+
*/
|
|
54
|
+
setCounts({});
|
|
55
|
+
if (!workspaceId)
|
|
56
|
+
return;
|
|
57
|
+
let live = true;
|
|
58
|
+
const read = async () => {
|
|
59
|
+
try {
|
|
60
|
+
/*
|
|
61
|
+
* `schedule_list` is the action that returns the catalog; `limit: 1`
|
|
62
|
+
* keeps the payload to one task because only `activeReminders` is
|
|
63
|
+
* read here. The action name matters — `requestAutomation` posts it
|
|
64
|
+
* as the operation, and an unknown action answers 400.
|
|
65
|
+
*/
|
|
66
|
+
const body = await requestAutomation(origin, workspaceId, "schedule_list", { limit: 1 });
|
|
67
|
+
if (!live)
|
|
68
|
+
return;
|
|
69
|
+
setCounts((previous) => {
|
|
70
|
+
const next = parseActiveReminders(body.activeReminders);
|
|
71
|
+
/*
|
|
72
|
+
* Keep the previous object when the counts are unchanged: this
|
|
73
|
+
* feeds a list of rows, and a fresh identity on every poll would
|
|
74
|
+
* re-render all of them for no reason.
|
|
75
|
+
*/
|
|
76
|
+
const keys = Object.keys(next);
|
|
77
|
+
if (keys.length === Object.keys(previous).length
|
|
78
|
+
&& keys.every((key) => previous[key] === next[key]))
|
|
79
|
+
return previous;
|
|
80
|
+
return next;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
/*
|
|
85
|
+
* The count is a badge; a failed poll leaves the last known value in
|
|
86
|
+
* place rather than flashing every mark off and on.
|
|
87
|
+
*/
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
void read();
|
|
91
|
+
const timer = window.setInterval(() => { void read(); }, REFRESH_MS);
|
|
92
|
+
return () => {
|
|
93
|
+
live = false;
|
|
94
|
+
window.clearInterval(timer);
|
|
95
|
+
};
|
|
96
|
+
}, [origin, workspaceId]);
|
|
97
|
+
return counts;
|
|
98
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a request template from a documented body.
|
|
3
|
+
*
|
|
4
|
+
* Selecting an endpoint used to clear the body, so a caller staring at
|
|
5
|
+
* `CreateUserRequest` had to type `{"name": "...", "age": 0}` from the field table
|
|
6
|
+
* by hand — and got the shape wrong the first time. The document already states
|
|
7
|
+
* every field, its type, and often an example; the template is that information
|
|
8
|
+
* arranged into something sendable.
|
|
9
|
+
*
|
|
10
|
+
* Kept pure and separate from the page so the shape rules can be tested directly:
|
|
11
|
+
* nested paths, array elements, required-only, and value types all have to be right
|
|
12
|
+
* or the result is not valid JSON for the endpoint.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The value to put in one field.
|
|
16
|
+
*
|
|
17
|
+
* Order of preference: the document's own example, then the first enum member, then
|
|
18
|
+
* a type-appropriate zero. An example is what the author expected a caller to send,
|
|
19
|
+
* so it beats anything inferred from the type name.
|
|
20
|
+
*
|
|
21
|
+
* @param field - the documented field.
|
|
22
|
+
* @returns a JSON value for it.
|
|
23
|
+
*/
|
|
24
|
+
export function templateValue(field) {
|
|
25
|
+
if (field.allowed !== undefined && field.allowed.length > 0)
|
|
26
|
+
return field.allowed[0];
|
|
27
|
+
if (field.example !== undefined && field.example !== "") {
|
|
28
|
+
const type = field.type.toLowerCase();
|
|
29
|
+
// Only coerce when the type is unambiguous: a string field keeps "30" as text.
|
|
30
|
+
if (type.startsWith("integer") || type.startsWith("number")) {
|
|
31
|
+
const parsed = Number(field.example);
|
|
32
|
+
if (Number.isFinite(parsed))
|
|
33
|
+
return parsed;
|
|
34
|
+
}
|
|
35
|
+
if (type.startsWith("boolean"))
|
|
36
|
+
return field.example === "true";
|
|
37
|
+
if (type.endsWith("[]") || type.startsWith("array") || type.startsWith("object")) {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(field.example);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return field.example;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return field.example;
|
|
46
|
+
}
|
|
47
|
+
const type = field.type.toLowerCase();
|
|
48
|
+
// The server renders an array type as `string[]`, not `array`; both spellings
|
|
49
|
+
// reach here depending on where the type came from.
|
|
50
|
+
if (type.endsWith("[]") || type.startsWith("array"))
|
|
51
|
+
return [];
|
|
52
|
+
if (type.startsWith("integer") || type.startsWith("number"))
|
|
53
|
+
return 0;
|
|
54
|
+
if (type.startsWith("boolean"))
|
|
55
|
+
return false;
|
|
56
|
+
if (type.startsWith("object"))
|
|
57
|
+
return {};
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Place a value at a dotted path, creating intermediate objects.
|
|
62
|
+
*
|
|
63
|
+
* `items[].id` becomes `{ items: [{ id: … }] }`: an array path always contributes a
|
|
64
|
+
* single element, because a template with an empty array would show a caller
|
|
65
|
+
* nothing about the element's shape.
|
|
66
|
+
*
|
|
67
|
+
* @param root - the object being built.
|
|
68
|
+
* @param path - dotted path, with `[]` marking an array element.
|
|
69
|
+
* @param value - the value to place.
|
|
70
|
+
*/
|
|
71
|
+
function assign(root, path, value) {
|
|
72
|
+
const segments = path.split(".").filter((segment) => segment !== "");
|
|
73
|
+
let cursor = root;
|
|
74
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
75
|
+
const isLast = index === segments.length - 1;
|
|
76
|
+
const raw = segments[index];
|
|
77
|
+
const isArray = raw.endsWith("[]");
|
|
78
|
+
const name = isArray ? raw.slice(0, -2) : raw;
|
|
79
|
+
if (isLast && !isArray) {
|
|
80
|
+
cursor[name] = value;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (isArray) {
|
|
84
|
+
// Ensure one element exists and continue into it.
|
|
85
|
+
const existing = cursor[name];
|
|
86
|
+
let list;
|
|
87
|
+
if (Array.isArray(existing))
|
|
88
|
+
list = existing;
|
|
89
|
+
else {
|
|
90
|
+
list = [];
|
|
91
|
+
cursor[name] = list;
|
|
92
|
+
}
|
|
93
|
+
let element = list[0];
|
|
94
|
+
if (element === null || typeof element !== "object" || Array.isArray(element)) {
|
|
95
|
+
element = {};
|
|
96
|
+
list[0] = element;
|
|
97
|
+
}
|
|
98
|
+
if (isLast)
|
|
99
|
+
return;
|
|
100
|
+
cursor = element;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const existing = cursor[name];
|
|
104
|
+
if (existing === null || typeof existing !== "object" || Array.isArray(existing)) {
|
|
105
|
+
cursor[name] = {};
|
|
106
|
+
}
|
|
107
|
+
cursor = cursor[name];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Render a sendable JSON body for an endpoint.
|
|
112
|
+
*
|
|
113
|
+
* @param fields - the documented body fields.
|
|
114
|
+
* @param options - `requiredOnly` drops optional fields so the template stays short.
|
|
115
|
+
* @returns pretty-printed JSON, or an empty string when there is nothing to build.
|
|
116
|
+
*/
|
|
117
|
+
export function buildBodyTemplate(fields, options = {}) {
|
|
118
|
+
const chosen = options.requiredOnly === true ? fields.filter((field) => field.required) : [...fields];
|
|
119
|
+
if (chosen.length === 0)
|
|
120
|
+
return "";
|
|
121
|
+
const root = {};
|
|
122
|
+
for (const field of chosen)
|
|
123
|
+
assign(root, field.path, templateValue(field));
|
|
124
|
+
return JSON.stringify(root, null, 2);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Values for the path parameters, taken from their documented examples.
|
|
128
|
+
*
|
|
129
|
+
* A path placeholder that arrives pre-filled can be sent immediately; one that
|
|
130
|
+
* arrives empty makes the operator look up what `{version}` means.
|
|
131
|
+
*
|
|
132
|
+
* @param parameters - documented path parameters.
|
|
133
|
+
* @returns a name-to-value map, containing only the ones with an example.
|
|
134
|
+
*/
|
|
135
|
+
export function buildPathParamDefaults(parameters) {
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const parameter of parameters) {
|
|
138
|
+
if (parameter.in !== "path")
|
|
139
|
+
continue;
|
|
140
|
+
if (parameter.example !== undefined && parameter.example !== "")
|
|
141
|
+
out[parameter.name] = parameter.example;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elements that already own their keystrokes.
|
|
3
|
+
*
|
|
4
|
+
* A terminal counts because Ctrl+K is meaningful inside it, and a select
|
|
5
|
+
* because the browser uses it for type-ahead.
|
|
6
|
+
*/
|
|
7
|
+
const OWNS_KEYS = [
|
|
8
|
+
"input",
|
|
9
|
+
"textarea",
|
|
10
|
+
"select",
|
|
11
|
+
'[contenteditable="true"]',
|
|
12
|
+
"[data-terminal-surface]",
|
|
13
|
+
].join(", ");
|
|
14
|
+
/**
|
|
15
|
+
* Decide whether this keystroke should open the session search.
|
|
16
|
+
*
|
|
17
|
+
* @param event - the keydown, narrowed to the fields this decision reads.
|
|
18
|
+
* @returns true when the caller should open the search and prevent the default.
|
|
19
|
+
*/
|
|
20
|
+
export function isSessionSearchChord(event) {
|
|
21
|
+
if (event.key.toLowerCase() !== "k")
|
|
22
|
+
return false;
|
|
23
|
+
// `primary` in DSH means Cmd on macOS, Ctrl elsewhere. Accepting either on
|
|
24
|
+
// every platform is what browsers themselves do for this chord.
|
|
25
|
+
if (!(event.metaKey || event.ctrlKey))
|
|
26
|
+
return false;
|
|
27
|
+
// Ctrl+Shift+K and Ctrl+Alt+K belong to other gestures (devtools console,
|
|
28
|
+
// editor duplicate-line); claiming them would be a surprise.
|
|
29
|
+
if (event.shiftKey || event.altKey)
|
|
30
|
+
return false;
|
|
31
|
+
// A window/document target has no `closest`, which is exactly the case where
|
|
32
|
+
// nothing owns the keystroke.
|
|
33
|
+
const closest = event.target
|
|
34
|
+
?.closest;
|
|
35
|
+
if (typeof closest === "function" && closest.call(event.target, OWNS_KEYS))
|
|
36
|
+
return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|