dsh-browser-cdp 0.18.15 → 0.18.17
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/dsh-plugin.json +1 -1
- package/lib/client.js +173 -76
- package/lib/index.js +30 -17
- package/package.json +1 -1
package/dsh-plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -3099,22 +3099,31 @@ var TAB_CSS = `
|
|
|
3099
3099
|
* attachments are — the block carries its source CDP connection
|
|
3100
3100
|
* (endpoint + targetId) so the agent can find the element's DOM again
|
|
3101
3101
|
* (backendNodeId is directly addressable via bcdp_cdp DOM.describeNode).
|
|
3102
|
-
* Format inside the draft
|
|
3103
|
-
*
|
|
3104
|
-
*
|
|
3105
|
-
* [
|
|
3102
|
+
* Format inside the draft(@mention 精髓:被替换字段以 @ 开头):
|
|
3103
|
+
* @"picks/<file>.json"
|
|
3104
|
+
* — 显示层把该 token 替换成文件片;归档 JSON
|
|
3105
|
+
* {"cdpEndpoint":..., "targetId":..., "pageUrl":..., "elements":[...]}
|
|
3106
|
+
* 存 <workspace>/picks/<file>.json,dock 卡按引用取回渲染。
|
|
3106
3107
|
*/
|
|
3107
3108
|
function injectPickCardStyles() {
|
|
3108
3109
|
if (document.getElementById("dsh-cdp-picks-styles") !== null) return;
|
|
3109
3110
|
var style = document.createElement("style");
|
|
3110
3111
|
style.id = "dsh-cdp-picks-styles";
|
|
3111
|
-
style.textContent = "[data-dsh-cdp-picks-card] {\n box-sizing: border-box; flex: none;\n display: grid; gap: 4px; padding: 8px 10px;\n font: inherit; font-size: 12px;\n color: #1d1d1f; background: #f7f7f9;\n border: 1px solid rgba(0, 0, 0, 0.16); border-radius: 12px;\n box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);\n /* input-traffic
|
|
3112
|
+
style.textContent = "[data-dsh-cdp-picks-card] {\n box-sizing: border-box; flex: none;\n display: grid; gap: 4px; padding: 8px 10px;\n font: inherit; font-size: 12px;\n color: #1d1d1f; background: #f7f7f9;\n border: 1px solid rgba(0, 0, 0, 0.16); border-radius: 12px;\n box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);\n /* input-traffic 同款限宽 + 居中:卡宽限制在内容列(拖动范围)内,两侧留出\n clearance,auto margins 在 dock 带内居中,永不顶满整窗 */\n margin-left: auto;\n margin-right: auto;\n width: min(\n calc(100% - var(--dsh-composer-side-clearance, 16px) - var(--dsh-composer-side-clearance, 16px) - var(--dsh-composer-dock-inset, 8px) - var(--dsh-composer-dock-inset, 8px)),\n calc(var(--dsh-chat-content-width, 100%) - var(--dsh-composer-dock-inset, 8px) - var(--dsh-composer-dock-inset, 8px))\n );\n overflow-y: auto; max-height: 40vh;\n}\n@media (prefers-color-scheme: dark) {\n [data-dsh-cdp-picks-card] { color: #f2f2f7; background: #1c1c1e; border-color: rgba(255, 255, 255, 0.18); }\n}\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-sub { font-size: 11px; color: rgba(60, 60, 67, 0.62); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-chip { display: flex; align-items: baseline; gap: 6px; padding: 3px 8px; background: rgba(120, 120, 128, 0.12); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; min-width: 0; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-num { font-weight: 700; flex: none; color: rgba(60, 60, 67, 0.62); }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-tag { font-weight: 600; flex: none; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-close { margin-left: auto; flex: none; font: inherit; font-size: 12px; cursor: pointer; border: none; background: none; color: rgba(60, 60, 67, 0.62); padding: 0 2px; border-radius: 6px; }\n[data-dsh-cdp-picks-card] .dsh-cdp-picks-close:hover { background: rgba(120, 120, 128, 0.18); }\n@media (prefers-color-scheme: dark) {\n [data-dsh-cdp-picks-card] .dsh-cdp-picks-sub { color: rgba(235, 235, 245, 0.62); }\n [data-dsh-cdp-picks-card] .dsh-cdp-picks-chip { background: rgba(120, 120, 128, 0.24); border-color: rgba(255, 255, 255, 0.12); }\n [data-dsh-cdp-picks-card] .dsh-cdp-picks-num { color: rgba(235, 235, 245, 0.62); }\n [data-dsh-cdp-picks-card] .dsh-cdp-picks-close { color: rgba(235, 235, 245, 0.62); }\n [data-dsh-cdp-picks-card] .dsh-cdp-picks-close:hover { background: rgba(120, 120, 128, 0.3); }\n}";
|
|
3112
3113
|
document.head.appendChild(style);
|
|
3113
3114
|
}
|
|
3114
3115
|
function CdpPicksDockCard(props) {
|
|
3115
3116
|
var input = props.input;
|
|
3116
3117
|
var h = React.createElement;
|
|
3117
|
-
var
|
|
3118
|
+
var tick = React.useState(0);
|
|
3119
|
+
var setTick = tick[1];
|
|
3120
|
+
var offeredSession = props && props.sessionId !== void 0 && props.sessionId !== null ? String(props.sessionId) : null;
|
|
3121
|
+
var offeredActions = props && props.inputActions ? props.inputActions : null;
|
|
3122
|
+
React.useEffect(function() {
|
|
3123
|
+
if (offeredSession === null) return;
|
|
3124
|
+
latchPickInputActions(offeredSession, offeredActions);
|
|
3125
|
+
}, [offeredSession, offeredActions]);
|
|
3126
|
+
var sid = typeof props.session === "string" && props.session !== "" ? props.session : offeredSession;
|
|
3118
3127
|
React.useEffect(function() {
|
|
3119
3128
|
var timer = window.setInterval(function() {
|
|
3120
3129
|
setTick(function(n) {
|
|
@@ -3126,45 +3135,80 @@ function CdpPicksDockCard(props) {
|
|
|
3126
3135
|
};
|
|
3127
3136
|
}, []);
|
|
3128
3137
|
var snap = readDraftText(input);
|
|
3129
|
-
var refRe =
|
|
3138
|
+
var refRe = /@"(picks\/[^"\s]+\.json)"/g;
|
|
3130
3139
|
var refs = [], mm;
|
|
3131
3140
|
while ((mm = refRe.exec(snap)) !== null) refs.push({
|
|
3132
3141
|
file: mm[1],
|
|
3133
|
-
endpoint: mm[2],
|
|
3134
|
-
title: mm[3],
|
|
3135
|
-
count: Number(mm[4]),
|
|
3136
3142
|
line: mm[0]
|
|
3137
3143
|
});
|
|
3138
3144
|
try {
|
|
3139
3145
|
window.__dshBrowserCdpDeco = {
|
|
3140
3146
|
stage: refs.length ? "rendered" : "no-refs",
|
|
3141
3147
|
refs: refs.length,
|
|
3142
|
-
draftLen: snap.length
|
|
3148
|
+
draftLen: snap.length,
|
|
3149
|
+
sid: sid ? "yes" : "no",
|
|
3150
|
+
latch: pickInputActionsLatch.sessionId ? "yes" : "no"
|
|
3143
3151
|
};
|
|
3144
3152
|
} catch (e) {}
|
|
3145
3153
|
var loadedState = React.useState({});
|
|
3146
3154
|
var contents = loadedState[0], setContents = loadedState[1];
|
|
3155
|
+
var errState = React.useState({});
|
|
3156
|
+
var errs = errState[0], setErrs = errState[1];
|
|
3147
3157
|
var filesKey = refs.map(function(r) {
|
|
3148
3158
|
return r.file;
|
|
3149
3159
|
}).join("|");
|
|
3150
3160
|
React.useEffect(function() {
|
|
3151
3161
|
var cancelled = false;
|
|
3152
3162
|
refs.forEach(function(r) {
|
|
3153
|
-
|
|
3154
|
-
|
|
3163
|
+
postJson("/bcdp/api/picks-load", {
|
|
3164
|
+
file: r.file.slice(6),
|
|
3165
|
+
session: sid
|
|
3166
|
+
}).then(function(res) {
|
|
3167
|
+
if (cancelled) return;
|
|
3168
|
+
if (res && res.ok !== false && res.value) {
|
|
3169
|
+
var content = String(res.value.content || "");
|
|
3170
|
+
setContents(function(prev) {
|
|
3171
|
+
var n = Object.assign({}, prev);
|
|
3172
|
+
n[r.file] = content;
|
|
3173
|
+
return n;
|
|
3174
|
+
});
|
|
3175
|
+
setErrs(function(prev) {
|
|
3176
|
+
if (!(r.file in prev)) return prev;
|
|
3177
|
+
var n = Object.assign({}, prev);
|
|
3178
|
+
delete n[r.file];
|
|
3179
|
+
return n;
|
|
3180
|
+
});
|
|
3181
|
+
} else {
|
|
3182
|
+
var code = res && res.error && res.error.code ? String(res.error.code) : "load-failed";
|
|
3183
|
+
setContents(function(prev) {
|
|
3184
|
+
var n = Object.assign({}, prev);
|
|
3185
|
+
n[r.file] = "";
|
|
3186
|
+
return n;
|
|
3187
|
+
});
|
|
3188
|
+
setErrs(function(prev) {
|
|
3189
|
+
var n = Object.assign({}, prev);
|
|
3190
|
+
n[r.file] = code;
|
|
3191
|
+
return n;
|
|
3192
|
+
});
|
|
3193
|
+
}
|
|
3194
|
+
}).catch(function() {
|
|
3155
3195
|
if (cancelled) return;
|
|
3156
|
-
var content = res && res.ok !== false && res.value ? String(res.value.content || "") : "";
|
|
3157
3196
|
setContents(function(prev) {
|
|
3158
3197
|
var n = Object.assign({}, prev);
|
|
3159
|
-
n[r.file] =
|
|
3198
|
+
n[r.file] = "";
|
|
3160
3199
|
return n;
|
|
3161
3200
|
});
|
|
3162
|
-
|
|
3201
|
+
setErrs(function(prev) {
|
|
3202
|
+
var n = Object.assign({}, prev);
|
|
3203
|
+
n[r.file] = "load-failed";
|
|
3204
|
+
return n;
|
|
3205
|
+
});
|
|
3206
|
+
});
|
|
3163
3207
|
});
|
|
3164
3208
|
return function() {
|
|
3165
3209
|
cancelled = true;
|
|
3166
3210
|
};
|
|
3167
|
-
}, [filesKey]);
|
|
3211
|
+
}, [filesKey, Math.floor(tick[0] / 5)]);
|
|
3168
3212
|
if (refs.length === 0) return null;
|
|
3169
3213
|
function removeRef(line) {
|
|
3170
3214
|
var cur = readDraftText(input);
|
|
@@ -3180,11 +3224,18 @@ function CdpPicksDockCard(props) {
|
|
|
3180
3224
|
} }, refs.map(function(r) {
|
|
3181
3225
|
var content = contents[r.file];
|
|
3182
3226
|
var elements = [];
|
|
3227
|
+
var pageTitle = "";
|
|
3183
3228
|
if (typeof content === "string" && content !== "") try {
|
|
3184
3229
|
var obj = JSON.parse(content);
|
|
3185
3230
|
elements = obj && obj.elements || [];
|
|
3186
|
-
|
|
3187
|
-
|
|
3231
|
+
pageTitle = obj && obj.pageTitle || "";
|
|
3232
|
+
} catch (e) {
|
|
3233
|
+
pageTitle = "";
|
|
3234
|
+
}
|
|
3235
|
+
var countText;
|
|
3236
|
+
if (typeof content !== "string" || content === "") countText = errs[r.file] ? "⚠ " + errs[r.file] : "…";
|
|
3237
|
+
else countText = wt("pickCardElements", { n: elements.length });
|
|
3238
|
+
var head = h("div", { className: "dsh-cdp-picks-head" }, h("span", { style: { fontWeight: 700 } }, "🌐 " + wt("pickCardTitle")), h("span", { className: "dsh-cdp-picks-sub" }, "@" + r.file), h("span", { className: "dsh-cdp-picks-sub" }, pageTitle), h("span", { className: "dsh-cdp-picks-sub" }, countText), h("button", {
|
|
3188
3239
|
type: "button",
|
|
3189
3240
|
title: wt("pickCardRemove"),
|
|
3190
3241
|
className: "dsh-cdp-picks-close",
|
|
@@ -3232,14 +3283,9 @@ function CdpPicksBadge(props) {
|
|
|
3232
3283
|
if (props && props.sessionId !== void 0 && props.sessionId !== null ? String(props.sessionId) : null) {
|
|
3233
3284
|
var draft = typeof props.getDraft === "function" ? String(props.getDraft() || "") : "";
|
|
3234
3285
|
var countRefs = (draft.match(/\[(?:🌐 )?CDP-PICKS/g) || []).length;
|
|
3235
|
-
var refRe2 =
|
|
3286
|
+
var refRe2 = /@"(picks\/[^"\s]+\.json)"/g;
|
|
3236
3287
|
var mm;
|
|
3237
|
-
while ((mm = refRe2.exec(draft)) !== null) refs.push({
|
|
3238
|
-
file: mm[1],
|
|
3239
|
-
endpoint: mm[2],
|
|
3240
|
-
title: mm[3],
|
|
3241
|
-
count: Number(mm[4])
|
|
3242
|
-
});
|
|
3288
|
+
while ((mm = refRe2.exec(draft)) !== null) refs.push({ file: mm[1] });
|
|
3243
3289
|
}
|
|
3244
3290
|
} catch (e) {}
|
|
3245
3291
|
try {
|
|
@@ -3253,7 +3299,7 @@ function CdpPicksBadge(props) {
|
|
|
3253
3299
|
return h("span", {
|
|
3254
3300
|
key: r.file,
|
|
3255
3301
|
className: "dsh-cdp-picks-badge",
|
|
3256
|
-
title: "🌐 " +
|
|
3302
|
+
title: "🌐 @" + r.file
|
|
3257
3303
|
}, "🌐" + (refs.length > 1 ? " ×" + (i + 1) : ""));
|
|
3258
3304
|
}));
|
|
3259
3305
|
}
|
|
@@ -3279,15 +3325,18 @@ function mountPicksDockCard(ctx) {
|
|
|
3279
3325
|
locale: "dsh-browser-cdp",
|
|
3280
3326
|
order: 0,
|
|
3281
3327
|
inject: function(sessionId) {
|
|
3282
|
-
var input = null;
|
|
3328
|
+
var input = null, session = null;
|
|
3283
3329
|
try {
|
|
3284
3330
|
var actx = ctx.sessions.scope(sessionId);
|
|
3285
3331
|
input = actx.get("conversation").input.for(actx);
|
|
3332
|
+
session = String(sessionId);
|
|
3286
3333
|
} catch (e) {
|
|
3287
3334
|
input = null;
|
|
3335
|
+
session = null;
|
|
3288
3336
|
}
|
|
3289
3337
|
return {
|
|
3290
3338
|
input,
|
|
3339
|
+
session,
|
|
3291
3340
|
getDraft: function() {
|
|
3292
3341
|
return readDraftText(input);
|
|
3293
3342
|
}
|
|
@@ -3319,6 +3368,50 @@ function currentSessionId(list) {
|
|
|
3319
3368
|
}
|
|
3320
3369
|
return "";
|
|
3321
3370
|
}
|
|
3371
|
+
var pickInputActionsLatch = {
|
|
3372
|
+
sessionId: null,
|
|
3373
|
+
actions: null
|
|
3374
|
+
};
|
|
3375
|
+
function latchPickInputActions(sessionId, actions) {
|
|
3376
|
+
if (!sessionId || !actions || typeof actions.captureInsertion !== "function") return;
|
|
3377
|
+
pickInputActionsLatch = {
|
|
3378
|
+
sessionId: String(sessionId),
|
|
3379
|
+
actions
|
|
3380
|
+
};
|
|
3381
|
+
}
|
|
3382
|
+
function needsBoundarySpace() {
|
|
3383
|
+
var root = document.querySelector("[data-input-scroll] [contenteditable=\"true\"]");
|
|
3384
|
+
var selection = window.getSelection();
|
|
3385
|
+
if (root === null || selection === null || selection.rangeCount === 0) return true;
|
|
3386
|
+
var caret = selection.getRangeAt(0);
|
|
3387
|
+
if (!root.contains(caret.startContainer)) return true;
|
|
3388
|
+
var before = document.createRange();
|
|
3389
|
+
before.selectNodeContents(root);
|
|
3390
|
+
before.setEnd(caret.startContainer, caret.startOffset);
|
|
3391
|
+
var text = before.toString();
|
|
3392
|
+
if (text === "") return false;
|
|
3393
|
+
return !/\s/u.test(text.slice(-1));
|
|
3394
|
+
}
|
|
3395
|
+
async function tryInsertPickChip(ctx, sessionId, actx, input, token) {
|
|
3396
|
+
try {
|
|
3397
|
+
var latch = pickInputActionsLatch;
|
|
3398
|
+
if (!latch.actions || latch.sessionId !== String(sessionId)) return false;
|
|
3399
|
+
var triggers = typeof ctx.get === "function" ? ctx.get("inputTriggers") : null;
|
|
3400
|
+
var controller = triggers && typeof triggers.sessionOf === "function" ? triggers.sessionOf(actx) : null;
|
|
3401
|
+
if (typeof (controller && typeof controller.serializeReference === "function" ? await controller.serializeReference("reference", token, new AbortController().signal) : null) !== "string") return false;
|
|
3402
|
+
if (needsBoundarySpace() && typeof input.insertText === "function") input.insertText(" ", latch.actions.captureInsertion());
|
|
3403
|
+
var span = latch.actions.captureInsertion();
|
|
3404
|
+
return input.insertReference({
|
|
3405
|
+
source: "reference",
|
|
3406
|
+
ref: token,
|
|
3407
|
+
label: "🌐 " + token.slice(1, -1),
|
|
3408
|
+
appearance: "file",
|
|
3409
|
+
clipboardText: token
|
|
3410
|
+
}, span) === true;
|
|
3411
|
+
} catch (e) {
|
|
3412
|
+
return false;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3322
3415
|
function deliverPickToConversation(ctx, element, action) {
|
|
3323
3416
|
try {
|
|
3324
3417
|
var describe = element && typeof element.describe === "string" ? element.describe : "";
|
|
@@ -3366,67 +3459,71 @@ function deliverPickToConversation(ctx, element, action) {
|
|
|
3366
3459
|
focusable: !!element.keyboardFocusable,
|
|
3367
3460
|
describe
|
|
3368
3461
|
};
|
|
3369
|
-
var reRef =
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
mm[
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3462
|
+
var reRef = /@"(picks\/([^"\s]+\.json))"/g;
|
|
3463
|
+
var mentions = [], mm;
|
|
3464
|
+
while ((mm = reRef.exec(draft)) !== null) mentions.push({
|
|
3465
|
+
token: mm[0],
|
|
3466
|
+
file: mm[2]
|
|
3467
|
+
});
|
|
3468
|
+
(async function() {
|
|
3469
|
+
try {
|
|
3470
|
+
var found = null, hit = null, obj = null;
|
|
3471
|
+
for (var i = 0; i < mentions.length; i++) {
|
|
3472
|
+
var lres = await postJson("/bcdp/api/picks-load", {
|
|
3473
|
+
file: mentions[i].file,
|
|
3474
|
+
session: sessionId
|
|
3475
|
+
});
|
|
3476
|
+
if (!lres || lres.ok === false || !lres.value) continue;
|
|
3477
|
+
obj = JSON.parse(lres.value.content);
|
|
3478
|
+
if (obj && obj.cdpEndpoint === src.endpoint) {
|
|
3479
|
+
found = mentions[i];
|
|
3480
|
+
hit = obj.elements || [];
|
|
3481
|
+
break;
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
if (found) {
|
|
3383
3485
|
var maxN = 0;
|
|
3384
|
-
for (var k = 0; k <
|
|
3486
|
+
for (var k = 0; k < hit.length; k++) if (hit[k].n > maxN) maxN = hit[k].n;
|
|
3385
3487
|
entry.n = maxN + 1;
|
|
3386
|
-
|
|
3488
|
+
hit.push(Object.assign({}, entry));
|
|
3387
3489
|
var page = {
|
|
3388
3490
|
cdpEndpoint: obj.cdpEndpoint || src.endpoint,
|
|
3389
3491
|
targetId: obj.targetId || src.targetId,
|
|
3390
3492
|
pageUrl: obj.pageUrl || src.pageUrl,
|
|
3391
3493
|
pageTitle: obj.pageTitle || src.pageTitle,
|
|
3392
|
-
elements:
|
|
3494
|
+
elements: hit
|
|
3393
3495
|
};
|
|
3394
|
-
postJson("/bcdp/api/picks-save", {
|
|
3496
|
+
await postJson("/bcdp/api/picks-save", {
|
|
3395
3497
|
block: JSON.stringify(page, null, 2),
|
|
3396
|
-
file
|
|
3498
|
+
file: found.file,
|
|
3499
|
+
session: sessionId
|
|
3397
3500
|
});
|
|
3501
|
+
return;
|
|
3502
|
+
}
|
|
3503
|
+
var pageNew = {
|
|
3504
|
+
cdpEndpoint: src.endpoint,
|
|
3505
|
+
targetId: src.targetId,
|
|
3506
|
+
pageUrl: src.pageUrl,
|
|
3507
|
+
pageTitle: src.pageTitle,
|
|
3508
|
+
elements: [Object.assign({ n: 1 }, entry)]
|
|
3509
|
+
};
|
|
3510
|
+
var sres = await postJson("/bcdp/api/picks-save", {
|
|
3511
|
+
block: JSON.stringify(pageNew, null, 2),
|
|
3512
|
+
session: sessionId
|
|
3513
|
+
});
|
|
3514
|
+
if (!sres || sres.ok === false || !sres.value) return;
|
|
3515
|
+
var token = "@\"picks/" + sres.value.file + "\"";
|
|
3516
|
+
if (!await tryInsertPickChip(ctx, sessionId, actx, input, token)) {
|
|
3398
3517
|
var cur = readDraftText(input);
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
return {
|
|
3405
|
-
ok: true,
|
|
3406
|
-
code: "archiving"
|
|
3407
|
-
};
|
|
3408
|
-
}
|
|
3409
|
-
var pageNew = {
|
|
3410
|
-
cdpEndpoint: src.endpoint,
|
|
3411
|
-
targetId: src.targetId,
|
|
3412
|
-
pageUrl: src.pageUrl,
|
|
3413
|
-
pageTitle: src.pageTitle,
|
|
3414
|
-
elements: [Object.assign({ n: 1 }, entry)]
|
|
3415
|
-
};
|
|
3416
|
-
var newFile = "picks-" + Date.now() + ".json";
|
|
3417
|
-
postJson("/bcdp/api/picks-save", {
|
|
3418
|
-
block: JSON.stringify(pageNew, null, 2),
|
|
3419
|
-
file: newFile
|
|
3420
|
-
}).then(function(res) {
|
|
3421
|
-
if (!res || res.ok === false || !res.value) return;
|
|
3422
|
-
var cur = readDraftText(input);
|
|
3423
|
-
var line = "[🌐 CDP-PICKS → " + res.value.file + " | " + src.endpoint + " | " + (src.pageTitle || src.pageUrl || "") + " | elements:1]";
|
|
3424
|
-
cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + line : line;
|
|
3425
|
-
input.setDraft(cur);
|
|
3426
|
-
}).catch(function() {});
|
|
3518
|
+
cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + token : token;
|
|
3519
|
+
input.setDraft(cur);
|
|
3520
|
+
}
|
|
3521
|
+
} catch (e) {}
|
|
3522
|
+
})();
|
|
3427
3523
|
return {
|
|
3428
3524
|
ok: true,
|
|
3429
|
-
code: "archiving"
|
|
3525
|
+
code: "archiving",
|
|
3526
|
+
count: 1
|
|
3430
3527
|
};
|
|
3431
3528
|
} catch (err) {
|
|
3432
3529
|
return {
|
package/lib/index.js
CHANGED
|
@@ -2733,19 +2733,6 @@ function normalizeProbeState(link) {
|
|
|
2733
2733
|
/** HTTP route prefix owning every ego-browser API request. */
|
|
2734
2734
|
const API_PREFIX = "/bcdp/api";
|
|
2735
2735
|
/**
|
|
2736
|
-
* Archive dir for CDP-PICKS blocks: the composer holds a one-line reference
|
|
2737
|
-
* and the raw JSON lives here (the dsh-paste-dock content model — the raw
|
|
2738
|
-
* expanded text must not flood the input). Plugin-namespaced subdir under
|
|
2739
|
-
* the same state root the cast worker uses.
|
|
2740
|
-
*/
|
|
2741
|
-
function picksDir() {
|
|
2742
|
-
const e = process.env;
|
|
2743
|
-
const isWin = process.platform === "win32";
|
|
2744
|
-
const home = e.HOME || e.USERPROFILE || (isWin ? e.LOCALAPPDATA || "" : "/root");
|
|
2745
|
-
const stateHome = e.EGO_LINUX_STATE_DIR || (isWin ? e.LOCALAPPDATA || `${home}\\AppData\\Local` : e.XDG_STATE_HOME || `${home}/.local/state`);
|
|
2746
|
-
return stateHome.endsWith("ego-lite-linux") ? resolve(stateHome, "picks") : resolve(stateHome, "ego-lite-linux", "picks");
|
|
2747
|
-
}
|
|
2748
|
-
/**
|
|
2749
2736
|
* Register the `/bcdp/api` HTTP route on the host's web server.
|
|
2750
2737
|
*
|
|
2751
2738
|
* The route reads/writes the `ego-browser` settings namespace in-process
|
|
@@ -2753,7 +2740,7 @@ function picksDir() {
|
|
|
2753
2740
|
* when absent, `get` degrades to the entry source and `set` returns a
|
|
2754
2741
|
* clear error.
|
|
2755
2742
|
*/
|
|
2756
|
-
function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
|
|
2743
|
+
function registerEgoBrowserGateway(ctx, bridge, ffmpegManager, picks) {
|
|
2757
2744
|
ctx.effect?.(() => {
|
|
2758
2745
|
const webServer = ctx.get?.("webServer");
|
|
2759
2746
|
if (!webServer || typeof webServer.register !== "function") return;
|
|
@@ -2848,6 +2835,12 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
|
|
|
2848
2835
|
}
|
|
2849
2836
|
writeJson(res, 200, envelopeOk({ outcome: await probeEndpoint(endpoint, { timeoutMs: typeof body.timeoutMs === "number" && Number.isFinite(body.timeoutMs) ? body.timeoutMs : void 0 }) }));
|
|
2850
2837
|
} else if (method === "picks-save") {
|
|
2838
|
+
const picksSession = typeof body.session === "string" ? body.session : void 0;
|
|
2839
|
+
const picksDir0 = picks ? picks.resolveDir(picksSession) : void 0;
|
|
2840
|
+
if (!picksDir0) {
|
|
2841
|
+
writeJson(res, 409, envelopeError("no-workspace", "no registered workspace resolves for this session"));
|
|
2842
|
+
return;
|
|
2843
|
+
}
|
|
2851
2844
|
const saveBody = body;
|
|
2852
2845
|
const block = typeof saveBody.block === "string" ? saveBody.block : "";
|
|
2853
2846
|
if (block === "") {
|
|
@@ -2855,7 +2848,7 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
|
|
|
2855
2848
|
return;
|
|
2856
2849
|
}
|
|
2857
2850
|
const file = typeof saveBody.file === "string" && /^[A-Za-z0-9._-]+\.json$/.test(saveBody.file) ? saveBody.file : `picks-${Date.now()}.json`;
|
|
2858
|
-
const dir =
|
|
2851
|
+
const dir = picksDir0;
|
|
2859
2852
|
await mkdir(dir, { recursive: true });
|
|
2860
2853
|
const target = resolve(dir, file);
|
|
2861
2854
|
if (!target.startsWith(resolve(dir))) {
|
|
@@ -2868,6 +2861,12 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
|
|
|
2868
2861
|
file
|
|
2869
2862
|
}));
|
|
2870
2863
|
} else if (method === "picks-load") {
|
|
2864
|
+
const loadSession = typeof body.session === "string" ? body.session : void 0;
|
|
2865
|
+
const loadDir0 = picks ? picks.resolveDir(loadSession) : void 0;
|
|
2866
|
+
if (!loadDir0) {
|
|
2867
|
+
writeJson(res, 409, envelopeError("no-workspace", "no registered workspace resolves for this session"));
|
|
2868
|
+
return;
|
|
2869
|
+
}
|
|
2871
2870
|
const loadBody = body;
|
|
2872
2871
|
const file = typeof loadBody.file === "string" && /^[A-Za-z0-9._-]+\.json$/.test(loadBody.file) ? loadBody.file : "";
|
|
2873
2872
|
if (file === "") {
|
|
@@ -2875,7 +2874,7 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
|
|
|
2875
2874
|
return;
|
|
2876
2875
|
}
|
|
2877
2876
|
try {
|
|
2878
|
-
writeJson(res, 200, envelopeOk({ content: await readFile(resolve(
|
|
2877
|
+
writeJson(res, 200, envelopeOk({ content: await readFile(resolve(loadDir0, file), "utf8") }));
|
|
2879
2878
|
} catch (error) {
|
|
2880
2879
|
writeJson(res, 404, envelopeError("not-found", error instanceof Error ? error.message : String(error)));
|
|
2881
2880
|
}
|
|
@@ -7098,7 +7097,21 @@ function apply(ctx, config = {}) {
|
|
|
7098
7097
|
ctx.logger?.warn?.(`dsh-browser-cdp: cast server init failed: ${err?.message ?? err}`);
|
|
7099
7098
|
}
|
|
7100
7099
|
try {
|
|
7101
|
-
registerEgoBrowserGateway(wctx, bridge, ffmpegManager)
|
|
7100
|
+
registerEgoBrowserGateway(wctx, bridge, ffmpegManager, { resolveDir: (sessionId) => {
|
|
7101
|
+
try {
|
|
7102
|
+
const registry = typeof ctx.get === "function" ? ctx.get("workspaceRegistry") : void 0;
|
|
7103
|
+
const workspaces = (registry ? registry.list() : []) ?? [];
|
|
7104
|
+
if (workspaces.length === 0) return void 0;
|
|
7105
|
+
if (sessionId) {
|
|
7106
|
+
const owned = workspaces.find((w) => w.sessionIds.includes(sessionId));
|
|
7107
|
+
if (owned) return owned.path + "/picks";
|
|
7108
|
+
}
|
|
7109
|
+
if (workspaces.length === 1) return workspaces[0].path + "/picks";
|
|
7110
|
+
return;
|
|
7111
|
+
} catch {
|
|
7112
|
+
return;
|
|
7113
|
+
}
|
|
7114
|
+
} });
|
|
7102
7115
|
} catch (err) {
|
|
7103
7116
|
ctx.logger?.warn?.(`dsh-browser-cdp: capability gateway init failed: ${err?.message ?? err}`);
|
|
7104
7117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-cdp",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.17",
|
|
4
4
|
"description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.2.0-rc.1+ line: declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.7 use the 0.17.x line]",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|