dsh-browser-cdp 0.17.18 → 0.17.20
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
|
@@ -4307,22 +4307,31 @@ var TAB_CSS = `
|
|
|
4307
4307
|
* attachments are — the block carries its source CDP connection
|
|
4308
4308
|
* (endpoint + targetId) so the agent can find the element's DOM again
|
|
4309
4309
|
* (backendNodeId is directly addressable via bcdp_cdp DOM.describeNode).
|
|
4310
|
-
* Format inside the draft
|
|
4311
|
-
*
|
|
4312
|
-
*
|
|
4313
|
-
* [
|
|
4310
|
+
* Format inside the draft(@mention 精髓:被替换字段以 @ 开头):
|
|
4311
|
+
* @"picks/<file>.json"
|
|
4312
|
+
* — 显示层把该 token 替换成文件片;归档 JSON
|
|
4313
|
+
* {"cdpEndpoint":..., "targetId":..., "pageUrl":..., "elements":[...]}
|
|
4314
|
+
* 存 <workspace>/picks/<file>.json,dock 卡按引用取回渲染。
|
|
4314
4315
|
*/
|
|
4315
4316
|
function injectPickCardStyles() {
|
|
4316
4317
|
if (document.getElementById("dsh-cdp-picks-styles") !== null) return;
|
|
4317
4318
|
var style = document.createElement("style");
|
|
4318
4319
|
style.id = "dsh-cdp-picks-styles";
|
|
4319
|
-
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
|
|
4320
|
+
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}";
|
|
4320
4321
|
document.head.appendChild(style);
|
|
4321
4322
|
}
|
|
4322
4323
|
function CdpPicksDockCard(props) {
|
|
4323
4324
|
var input = props.input;
|
|
4324
4325
|
var h = React.createElement;
|
|
4325
|
-
var
|
|
4326
|
+
var tick = React.useState(0);
|
|
4327
|
+
var setTick = tick[1];
|
|
4328
|
+
var offeredSession = props && props.sessionId !== void 0 && props.sessionId !== null ? String(props.sessionId) : null;
|
|
4329
|
+
var offeredActions = props && props.inputActions ? props.inputActions : null;
|
|
4330
|
+
React.useEffect(function() {
|
|
4331
|
+
if (offeredSession === null) return;
|
|
4332
|
+
latchPickInputActions(offeredSession, offeredActions);
|
|
4333
|
+
}, [offeredSession, offeredActions]);
|
|
4334
|
+
var sid = typeof props.session === "string" && props.session !== "" ? props.session : offeredSession;
|
|
4326
4335
|
React.useEffect(function() {
|
|
4327
4336
|
var timer = window.setInterval(function() {
|
|
4328
4337
|
setTick(function(n) {
|
|
@@ -4334,45 +4343,80 @@ function CdpPicksDockCard(props) {
|
|
|
4334
4343
|
};
|
|
4335
4344
|
}, []);
|
|
4336
4345
|
var snap = readDraftText(input);
|
|
4337
|
-
var refRe =
|
|
4346
|
+
var refRe = /@"(picks\/[^"\s]+\.json)"/g;
|
|
4338
4347
|
var refs = [], mm;
|
|
4339
4348
|
while ((mm = refRe.exec(snap)) !== null) refs.push({
|
|
4340
4349
|
file: mm[1],
|
|
4341
|
-
endpoint: mm[2],
|
|
4342
|
-
title: mm[3],
|
|
4343
|
-
count: Number(mm[4]),
|
|
4344
4350
|
line: mm[0]
|
|
4345
4351
|
});
|
|
4346
4352
|
try {
|
|
4347
4353
|
window.__dshBrowserCdpDeco = {
|
|
4348
4354
|
stage: refs.length ? "rendered" : "no-refs",
|
|
4349
4355
|
refs: refs.length,
|
|
4350
|
-
draftLen: snap.length
|
|
4356
|
+
draftLen: snap.length,
|
|
4357
|
+
sid: sid ? "yes" : "no",
|
|
4358
|
+
latch: pickInputActionsLatch.sessionId ? "yes" : "no"
|
|
4351
4359
|
};
|
|
4352
4360
|
} catch (e) {}
|
|
4353
4361
|
var loadedState = React.useState({});
|
|
4354
4362
|
var contents = loadedState[0], setContents = loadedState[1];
|
|
4363
|
+
var errState = React.useState({});
|
|
4364
|
+
var errs = errState[0], setErrs = errState[1];
|
|
4355
4365
|
var filesKey = refs.map(function(r) {
|
|
4356
4366
|
return r.file;
|
|
4357
4367
|
}).join("|");
|
|
4358
4368
|
React.useEffect(function() {
|
|
4359
4369
|
var cancelled = false;
|
|
4360
4370
|
refs.forEach(function(r) {
|
|
4361
|
-
|
|
4362
|
-
|
|
4371
|
+
postJson("/bcdp/api/picks-load", {
|
|
4372
|
+
file: r.file.slice(6),
|
|
4373
|
+
session: sid
|
|
4374
|
+
}).then(function(res) {
|
|
4375
|
+
if (cancelled) return;
|
|
4376
|
+
if (res && res.ok !== false && res.value) {
|
|
4377
|
+
var content = String(res.value.content || "");
|
|
4378
|
+
setContents(function(prev) {
|
|
4379
|
+
var n = Object.assign({}, prev);
|
|
4380
|
+
n[r.file] = content;
|
|
4381
|
+
return n;
|
|
4382
|
+
});
|
|
4383
|
+
setErrs(function(prev) {
|
|
4384
|
+
if (!(r.file in prev)) return prev;
|
|
4385
|
+
var n = Object.assign({}, prev);
|
|
4386
|
+
delete n[r.file];
|
|
4387
|
+
return n;
|
|
4388
|
+
});
|
|
4389
|
+
} else {
|
|
4390
|
+
var code = res && res.error && res.error.code ? String(res.error.code) : "load-failed";
|
|
4391
|
+
setContents(function(prev) {
|
|
4392
|
+
var n = Object.assign({}, prev);
|
|
4393
|
+
n[r.file] = "";
|
|
4394
|
+
return n;
|
|
4395
|
+
});
|
|
4396
|
+
setErrs(function(prev) {
|
|
4397
|
+
var n = Object.assign({}, prev);
|
|
4398
|
+
n[r.file] = code;
|
|
4399
|
+
return n;
|
|
4400
|
+
});
|
|
4401
|
+
}
|
|
4402
|
+
}).catch(function() {
|
|
4363
4403
|
if (cancelled) return;
|
|
4364
|
-
var content = res && res.ok !== false && res.value ? String(res.value.content || "") : "";
|
|
4365
4404
|
setContents(function(prev) {
|
|
4366
4405
|
var n = Object.assign({}, prev);
|
|
4367
|
-
n[r.file] =
|
|
4406
|
+
n[r.file] = "";
|
|
4368
4407
|
return n;
|
|
4369
4408
|
});
|
|
4370
|
-
|
|
4409
|
+
setErrs(function(prev) {
|
|
4410
|
+
var n = Object.assign({}, prev);
|
|
4411
|
+
n[r.file] = "load-failed";
|
|
4412
|
+
return n;
|
|
4413
|
+
});
|
|
4414
|
+
});
|
|
4371
4415
|
});
|
|
4372
4416
|
return function() {
|
|
4373
4417
|
cancelled = true;
|
|
4374
4418
|
};
|
|
4375
|
-
}, [filesKey]);
|
|
4419
|
+
}, [filesKey, Math.floor(tick[0] / 5)]);
|
|
4376
4420
|
if (refs.length === 0) return null;
|
|
4377
4421
|
function removeRef(line) {
|
|
4378
4422
|
var cur = readDraftText(input);
|
|
@@ -4388,11 +4432,18 @@ function CdpPicksDockCard(props) {
|
|
|
4388
4432
|
} }, refs.map(function(r) {
|
|
4389
4433
|
var content = contents[r.file];
|
|
4390
4434
|
var elements = [];
|
|
4435
|
+
var pageTitle = "";
|
|
4391
4436
|
if (typeof content === "string" && content !== "") try {
|
|
4392
4437
|
var obj = JSON.parse(content);
|
|
4393
4438
|
elements = obj && obj.elements || [];
|
|
4394
|
-
|
|
4395
|
-
|
|
4439
|
+
pageTitle = obj && obj.pageTitle || "";
|
|
4440
|
+
} catch (e) {
|
|
4441
|
+
pageTitle = "";
|
|
4442
|
+
}
|
|
4443
|
+
var countText;
|
|
4444
|
+
if (typeof content !== "string" || content === "") countText = errs[r.file] ? "⚠ " + errs[r.file] : "…";
|
|
4445
|
+
else countText = wt("pickCardElements", { n: elements.length });
|
|
4446
|
+
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", {
|
|
4396
4447
|
type: "button",
|
|
4397
4448
|
title: wt("pickCardRemove"),
|
|
4398
4449
|
className: "dsh-cdp-picks-close",
|
|
@@ -4439,14 +4490,9 @@ function CdpPicksBadge(props) {
|
|
|
4439
4490
|
try {
|
|
4440
4491
|
if (props && props.sessionId !== void 0 && props.sessionId !== null ? String(props.sessionId) : null) {
|
|
4441
4492
|
var draft = typeof props.getDraft === "function" ? String(props.getDraft() || "") : "";
|
|
4442
|
-
var refRe =
|
|
4493
|
+
var refRe = /@"(picks\/[^"\s]+\.json)"/g;
|
|
4443
4494
|
var mm;
|
|
4444
|
-
while ((mm = refRe.exec(draft)) !== null) refs.push({
|
|
4445
|
-
file: mm[1],
|
|
4446
|
-
endpoint: mm[2],
|
|
4447
|
-
title: mm[3],
|
|
4448
|
-
count: Number(mm[4])
|
|
4449
|
-
});
|
|
4495
|
+
while ((mm = refRe.exec(draft)) !== null) refs.push({ file: mm[1] });
|
|
4450
4496
|
}
|
|
4451
4497
|
} catch (e) {}
|
|
4452
4498
|
try {
|
|
@@ -4457,7 +4503,7 @@ function CdpPicksBadge(props) {
|
|
|
4457
4503
|
return h("span", {
|
|
4458
4504
|
key: r.file,
|
|
4459
4505
|
className: "dsh-cdp-picks-badge",
|
|
4460
|
-
title: "🌐 " +
|
|
4506
|
+
title: "🌐 @" + r.file
|
|
4461
4507
|
}, "🌐" + (refs.length > 1 ? " " + (i + 1) : ""));
|
|
4462
4508
|
}));
|
|
4463
4509
|
}
|
|
@@ -4483,15 +4529,18 @@ function mountPicksDockCard(ctx) {
|
|
|
4483
4529
|
locale: "dsh-browser-cdp",
|
|
4484
4530
|
order: 0,
|
|
4485
4531
|
inject: function(sessionId) {
|
|
4486
|
-
var input = null;
|
|
4532
|
+
var input = null, session = null;
|
|
4487
4533
|
try {
|
|
4488
4534
|
var actx = ctx.sessions.scope(sessionId);
|
|
4489
4535
|
input = actx.get("conversation").input.for(actx);
|
|
4536
|
+
session = String(sessionId);
|
|
4490
4537
|
} catch (e) {
|
|
4491
4538
|
input = null;
|
|
4539
|
+
session = null;
|
|
4492
4540
|
}
|
|
4493
4541
|
return {
|
|
4494
4542
|
input,
|
|
4543
|
+
session,
|
|
4495
4544
|
getDraft: function() {
|
|
4496
4545
|
return readDraftText(input);
|
|
4497
4546
|
}
|
|
@@ -4523,6 +4572,50 @@ function currentSessionId(list) {
|
|
|
4523
4572
|
}
|
|
4524
4573
|
return "";
|
|
4525
4574
|
}
|
|
4575
|
+
var pickInputActionsLatch = {
|
|
4576
|
+
sessionId: null,
|
|
4577
|
+
actions: null
|
|
4578
|
+
};
|
|
4579
|
+
function latchPickInputActions(sessionId, actions) {
|
|
4580
|
+
if (!sessionId || !actions || typeof actions.captureInsertion !== "function") return;
|
|
4581
|
+
pickInputActionsLatch = {
|
|
4582
|
+
sessionId: String(sessionId),
|
|
4583
|
+
actions
|
|
4584
|
+
};
|
|
4585
|
+
}
|
|
4586
|
+
function needsBoundarySpace() {
|
|
4587
|
+
var root = document.querySelector("[data-input-scroll] [contenteditable=\"true\"]");
|
|
4588
|
+
var selection = window.getSelection();
|
|
4589
|
+
if (root === null || selection === null || selection.rangeCount === 0) return true;
|
|
4590
|
+
var caret = selection.getRangeAt(0);
|
|
4591
|
+
if (!root.contains(caret.startContainer)) return true;
|
|
4592
|
+
var before = document.createRange();
|
|
4593
|
+
before.selectNodeContents(root);
|
|
4594
|
+
before.setEnd(caret.startContainer, caret.startOffset);
|
|
4595
|
+
var text = before.toString();
|
|
4596
|
+
if (text === "") return false;
|
|
4597
|
+
return !/\s/u.test(text.slice(-1));
|
|
4598
|
+
}
|
|
4599
|
+
async function tryInsertPickChip(ctx, sessionId, actx, input, token) {
|
|
4600
|
+
try {
|
|
4601
|
+
var latch = pickInputActionsLatch;
|
|
4602
|
+
if (!latch.actions || latch.sessionId !== String(sessionId)) return false;
|
|
4603
|
+
var triggers = typeof ctx.get === "function" ? ctx.get("inputTriggers") : null;
|
|
4604
|
+
var controller = triggers && typeof triggers.sessionOf === "function" ? triggers.sessionOf(actx) : null;
|
|
4605
|
+
if (typeof (controller && typeof controller.serializeReference === "function" ? await controller.serializeReference("reference", token, new AbortController().signal) : null) !== "string") return false;
|
|
4606
|
+
if (needsBoundarySpace() && typeof input.insertText === "function") input.insertText(" ", latch.actions.captureInsertion());
|
|
4607
|
+
var span = latch.actions.captureInsertion();
|
|
4608
|
+
return input.insertReference({
|
|
4609
|
+
source: "reference",
|
|
4610
|
+
ref: token,
|
|
4611
|
+
label: "🌐 " + token.slice(1, -1),
|
|
4612
|
+
appearance: "file",
|
|
4613
|
+
clipboardText: token
|
|
4614
|
+
}, span) === true;
|
|
4615
|
+
} catch (e) {
|
|
4616
|
+
return false;
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4526
4619
|
function deliverPickToConversation(ctx, element, action) {
|
|
4527
4620
|
try {
|
|
4528
4621
|
var describe = element && typeof element.describe === "string" ? element.describe : "";
|
|
@@ -4570,67 +4663,71 @@ function deliverPickToConversation(ctx, element, action) {
|
|
|
4570
4663
|
focusable: !!element.keyboardFocusable,
|
|
4571
4664
|
describe
|
|
4572
4665
|
};
|
|
4573
|
-
var reRef =
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
mm[
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4666
|
+
var reRef = /@"(picks\/([^"\s]+\.json))"/g;
|
|
4667
|
+
var mentions = [], mm;
|
|
4668
|
+
while ((mm = reRef.exec(draft)) !== null) mentions.push({
|
|
4669
|
+
token: mm[0],
|
|
4670
|
+
file: mm[2]
|
|
4671
|
+
});
|
|
4672
|
+
(async function() {
|
|
4673
|
+
try {
|
|
4674
|
+
var found = null, hit = null, obj = null;
|
|
4675
|
+
for (var i = 0; i < mentions.length; i++) {
|
|
4676
|
+
var lres = await postJson("/bcdp/api/picks-load", {
|
|
4677
|
+
file: mentions[i].file,
|
|
4678
|
+
session: sessionId
|
|
4679
|
+
});
|
|
4680
|
+
if (!lres || lres.ok === false || !lres.value) continue;
|
|
4681
|
+
obj = JSON.parse(lres.value.content);
|
|
4682
|
+
if (obj && obj.cdpEndpoint === src.endpoint) {
|
|
4683
|
+
found = mentions[i];
|
|
4684
|
+
hit = obj.elements || [];
|
|
4685
|
+
break;
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
if (found) {
|
|
4587
4689
|
var maxN = 0;
|
|
4588
|
-
for (var k = 0; k <
|
|
4690
|
+
for (var k = 0; k < hit.length; k++) if (hit[k].n > maxN) maxN = hit[k].n;
|
|
4589
4691
|
entry.n = maxN + 1;
|
|
4590
|
-
|
|
4692
|
+
hit.push(Object.assign({}, entry));
|
|
4591
4693
|
var page = {
|
|
4592
4694
|
cdpEndpoint: obj.cdpEndpoint || src.endpoint,
|
|
4593
4695
|
targetId: obj.targetId || src.targetId,
|
|
4594
4696
|
pageUrl: obj.pageUrl || src.pageUrl,
|
|
4595
4697
|
pageTitle: obj.pageTitle || src.pageTitle,
|
|
4596
|
-
elements:
|
|
4698
|
+
elements: hit
|
|
4597
4699
|
};
|
|
4598
|
-
postJson("/bcdp/api/picks-save", {
|
|
4700
|
+
await postJson("/bcdp/api/picks-save", {
|
|
4599
4701
|
block: JSON.stringify(page, null, 2),
|
|
4600
|
-
file
|
|
4702
|
+
file: found.file,
|
|
4703
|
+
session: sessionId
|
|
4601
4704
|
});
|
|
4705
|
+
return;
|
|
4706
|
+
}
|
|
4707
|
+
var pageNew = {
|
|
4708
|
+
cdpEndpoint: src.endpoint,
|
|
4709
|
+
targetId: src.targetId,
|
|
4710
|
+
pageUrl: src.pageUrl,
|
|
4711
|
+
pageTitle: src.pageTitle,
|
|
4712
|
+
elements: [Object.assign({ n: 1 }, entry)]
|
|
4713
|
+
};
|
|
4714
|
+
var sres = await postJson("/bcdp/api/picks-save", {
|
|
4715
|
+
block: JSON.stringify(pageNew, null, 2),
|
|
4716
|
+
session: sessionId
|
|
4717
|
+
});
|
|
4718
|
+
if (!sres || sres.ok === false || !sres.value) return;
|
|
4719
|
+
var token = "@\"picks/" + sres.value.file + "\"";
|
|
4720
|
+
if (!await tryInsertPickChip(ctx, sessionId, actx, input, token)) {
|
|
4602
4721
|
var cur = readDraftText(input);
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
return {
|
|
4609
|
-
ok: true,
|
|
4610
|
-
code: "archiving"
|
|
4611
|
-
};
|
|
4612
|
-
}
|
|
4613
|
-
var pageNew = {
|
|
4614
|
-
cdpEndpoint: src.endpoint,
|
|
4615
|
-
targetId: src.targetId,
|
|
4616
|
-
pageUrl: src.pageUrl,
|
|
4617
|
-
pageTitle: src.pageTitle,
|
|
4618
|
-
elements: [Object.assign({ n: 1 }, entry)]
|
|
4619
|
-
};
|
|
4620
|
-
var newFile = "picks-" + Date.now() + ".json";
|
|
4621
|
-
postJson("/bcdp/api/picks-save", {
|
|
4622
|
-
block: JSON.stringify(pageNew, null, 2),
|
|
4623
|
-
file: newFile
|
|
4624
|
-
}).then(function(res) {
|
|
4625
|
-
if (!res || res.ok === false || !res.value) return;
|
|
4626
|
-
var cur = readDraftText(input);
|
|
4627
|
-
var line = "[🌐 CDP-PICKS → " + res.value.file + " | " + src.endpoint + " | " + (src.pageTitle || src.pageUrl || "") + " | elements:1]";
|
|
4628
|
-
cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + line : line;
|
|
4629
|
-
input.setDraft(cur);
|
|
4630
|
-
}).catch(function() {});
|
|
4722
|
+
cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + token : token;
|
|
4723
|
+
input.setDraft(cur);
|
|
4724
|
+
}
|
|
4725
|
+
} catch (e) {}
|
|
4726
|
+
})();
|
|
4631
4727
|
return {
|
|
4632
4728
|
ok: true,
|
|
4633
|
-
code: "archiving"
|
|
4729
|
+
code: "archiving",
|
|
4730
|
+
count: 1
|
|
4634
4731
|
};
|
|
4635
4732
|
} catch (err) {
|
|
4636
4733
|
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.17.
|
|
3
|
+
"version": "0.17.20",
|
|
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.1.7+ line: declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.6 use the 0.16.x line]",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|