dsh-browser-cdp 0.17.15 โ†’ 0.17.16

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "0.17.15",
5
+ "version": "0.17.16",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -4325,35 +4325,52 @@ function CdpPicksDockCard(props) {
4325
4325
  window.clearInterval(timer);
4326
4326
  };
4327
4327
  }, []);
4328
- var draft = readDraftText(input);
4329
- var re = /\[(?:๐ŸŒ )?CDP-PICKS\s+page="([^"]*)"\s+targetId="([^"]*)"\s+endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
4330
- var found = [], mm;
4331
- while ((mm = re.exec(draft)) !== null) {
4332
- var elements = [];
4333
- try {
4334
- var obj = JSON.parse(mm[4]);
4335
- elements = obj && obj.elements || [];
4336
- } catch (e) {}
4337
- found.push({
4338
- title: mm[1],
4339
- endpoint: mm[3],
4340
- elements,
4341
- block: mm[0]
4342
- });
4343
- }
4328
+ var snap = readDraftText(input);
4329
+ var refRe = /\[๐ŸŒ CDP-PICKS โ†’ ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g;
4330
+ var refs = [], mm;
4331
+ while ((mm = refRe.exec(snap)) !== null) refs.push({
4332
+ file: mm[1],
4333
+ endpoint: mm[2],
4334
+ title: mm[3],
4335
+ count: Number(mm[4]),
4336
+ line: mm[0]
4337
+ });
4344
4338
  try {
4345
4339
  window.__dshBrowserCdpDeco = {
4346
- stage: found.length ? "rendered" : "no-blocks",
4347
- blocks: found.length,
4348
- draftLen: draft.length
4340
+ stage: refs.length ? "rendered" : "no-refs",
4341
+ refs: refs.length,
4342
+ draftLen: snap.length
4349
4343
  };
4350
4344
  } catch (e) {}
4351
- function removeBlock(block) {
4352
- if (!input || typeof input.setDraft !== "function") return;
4345
+ var loadedState = React.useState({});
4346
+ var contents = loadedState[0], setContents = loadedState[1];
4347
+ var filesKey = refs.map(function(r) {
4348
+ return r.file;
4349
+ }).join("|");
4350
+ React.useEffect(function() {
4351
+ var cancelled = false;
4352
+ refs.forEach(function(r) {
4353
+ if (contents[r.file] !== void 0) return;
4354
+ postJson("/bcdp/api/picks-load", { file: r.file }).then(function(res) {
4355
+ if (cancelled) return;
4356
+ var content = res && res.ok !== false && res.value ? String(res.value.content || "") : "";
4357
+ setContents(function(prev) {
4358
+ var n = Object.assign({}, prev);
4359
+ n[r.file] = content;
4360
+ return n;
4361
+ });
4362
+ }).catch(function() {});
4363
+ });
4364
+ return function() {
4365
+ cancelled = true;
4366
+ };
4367
+ }, [filesKey]);
4368
+ if (refs.length === 0) return null;
4369
+ function removeRef(line) {
4353
4370
  var cur = readDraftText(input);
4354
- var idx = cur.indexOf(block);
4371
+ var idx = cur.indexOf(line);
4355
4372
  if (idx < 0) return;
4356
- var next = cur.slice(0, idx) + cur.slice(idx + block.length);
4373
+ var next = cur.slice(0, idx) + cur.slice(idx + line.length);
4357
4374
  next = next.replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
4358
4375
  input.setDraft(next);
4359
4376
  }
@@ -4422,24 +4439,39 @@ function CdpPicksDockCard(props) {
4422
4439
  return h("div", { style: {
4423
4440
  display: "grid",
4424
4441
  gap: "6px"
4425
- } }, found.map(function(f) {
4426
- var head = h("div", { style: headStyle }, h("span", { style: { fontWeight: 700 } }, "๐ŸŒ " + wt("pickCardTitle")), h("span", { style: subStyle }, (f.endpoint || "") + " ยท " + (f.title || "")), h("span", { style: subStyle }, wt("pickCardElements", { n: f.elements.length })), h("button", {
4442
+ } }, refs.map(function(r) {
4443
+ var content = contents[r.file];
4444
+ var elements = [];
4445
+ if (typeof content === "string" && content !== "") try {
4446
+ var obj = JSON.parse(content);
4447
+ elements = obj && obj.elements || [];
4448
+ } catch (e) {}
4449
+ var head = h("div", { style: headStyle }, h("span", { style: { fontWeight: 700 } }, "๐ŸŒ " + wt("pickCardTitle")), h("span", { style: subStyle }, (r.endpoint || "") + " ยท " + (r.title || "")), h("span", { style: subStyle }, wt("pickCardElements", { n: r.count })), h("button", {
4427
4450
  type: "button",
4428
4451
  title: wt("pickCardRemove"),
4429
4452
  style: closeStyle,
4430
4453
  onClick: function() {
4431
- removeBlock(f.block);
4454
+ removeRef(r.line);
4432
4455
  }
4433
4456
  }, "โœ•"));
4434
- var chips = f.elements.slice(0, 6).map(function(el) {
4435
- return h("div", {
4436
- key: el.n,
4457
+ var chips = [];
4458
+ if (typeof content !== "string") chips.push(h("div", {
4459
+ key: "loading",
4460
+ style: subStyle
4461
+ }, "โ€ฆ"));
4462
+ for (var i = 0; i < elements.length && i < 6; i++) {
4463
+ var el = elements[i] || {};
4464
+ chips.push(h("div", {
4465
+ key: el.n || i,
4437
4466
  style: chipStyle
4438
- }, h("span", { style: numStyle }, "#" + (el.n || "")), h("span", { style: tagStyle }, el.tag || "?"), h("span", { style: descStyle }, el.describe || el.name || ""));
4439
- });
4440
- if (f.elements.length > 6) chips.push(h("div", { style: subStyle }, "โ€ฆ +" + (f.elements.length - 6)));
4467
+ }, h("span", { style: numStyle }, "#" + (el.n || i + 1)), h("span", { style: tagStyle }, el.tag || "?"), h("span", { style: descStyle }, el.describe || el.name || "")));
4468
+ }
4469
+ if (elements.length > 6) chips.push(h("div", {
4470
+ key: "more",
4471
+ style: subStyle
4472
+ }, "โ€ฆ +" + (elements.length - 6)));
4441
4473
  return h("div", {
4442
- key: f.targetId + ":" + f.endpoint,
4474
+ key: r.file,
4443
4475
  style: cardStyle
4444
4476
  }, head, chips);
4445
4477
  }));
@@ -4461,13 +4493,6 @@ function mountPicksDockCard(ctx) {
4461
4493
  input = actx.get("conversation").input.for(actx);
4462
4494
  } catch (e) {
4463
4495
  input = null;
4464
- try {
4465
- window.__dshBrowserCdpDeco = Object.assign({}, window.__dshBrowserCdpDeco, {
4466
- stage: "inject-failed",
4467
- error: String(e && e.message || e),
4468
- sessionId: String(sessionId)
4469
- });
4470
- } catch (e2) {}
4471
4496
  }
4472
4497
  return { input };
4473
4498
  }
@@ -4536,6 +4561,7 @@ function deliverPickToConversation(ctx, element, action) {
4536
4561
  pageTitle: ""
4537
4562
  };
4538
4563
  var entry = {
4564
+ n: 1,
4539
4565
  backendNodeId: element.backendNodeId,
4540
4566
  tag: element.tag,
4541
4567
  id: element.id,
@@ -4543,40 +4569,67 @@ function deliverPickToConversation(ctx, element, action) {
4543
4569
  focusable: !!element.keyboardFocusable,
4544
4570
  describe
4545
4571
  };
4546
- var re = /\[(?:๐ŸŒ )?CDP-PICKS[^\]]*\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g, found = null, mm;
4547
- while ((mm = re.exec(draft)) !== null) try {
4548
- var obj = JSON.parse(mm[1]);
4549
- if (obj && obj.targetId === src.targetId && obj.cdpEndpoint === src.endpoint) {
4550
- found = mm;
4551
- mm[0].split("\n")[0];
4552
- break;
4553
- }
4554
- } catch (e) {}
4555
- var elements = [Object.assign({ n: 1 }, entry)];
4556
- var page = {
4572
+ var reRef = /\[๐ŸŒ CDP-PICKS โ†’ ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g, file = null, oldLine = null, mm;
4573
+ while ((mm = reRef.exec(draft)) !== null) if (mm[2] === src.endpoint) {
4574
+ file = mm[1];
4575
+ mm[2];
4576
+ oldLine = mm[0];
4577
+ Number(mm[4]);
4578
+ break;
4579
+ }
4580
+ if (file !== null) {
4581
+ postJson("/bcdp/api/picks-load", { file }).then(function(lres) {
4582
+ try {
4583
+ if (!lres || lres.ok === false || !lres.value) return;
4584
+ var obj = JSON.parse(lres.value.content);
4585
+ var list = obj && obj.elements ? obj.elements : [];
4586
+ var maxN = 0;
4587
+ for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
4588
+ entry.n = maxN + 1;
4589
+ list.push(Object.assign({}, entry));
4590
+ var page = {
4591
+ cdpEndpoint: obj.cdpEndpoint || src.endpoint,
4592
+ targetId: obj.targetId || src.targetId,
4593
+ pageUrl: obj.pageUrl || src.pageUrl,
4594
+ pageTitle: obj.pageTitle || src.pageTitle,
4595
+ elements: list
4596
+ };
4597
+ postJson("/bcdp/api/picks-save", {
4598
+ block: JSON.stringify(page, null, 2),
4599
+ file
4600
+ });
4601
+ var cur = readDraftText(input);
4602
+ var newLine = "[๐ŸŒ CDP-PICKS โ†’ " + file + " | " + src.endpoint + " | " + (page.pageTitle || "") + " | elements:" + list.length + "]";
4603
+ var idx = cur.indexOf(oldLine);
4604
+ if (idx >= 0) input.setDraft(cur.slice(0, idx) + newLine + cur.slice(idx + oldLine.length));
4605
+ } catch (e) {}
4606
+ }).catch(function() {});
4607
+ return {
4608
+ ok: true,
4609
+ code: "archiving"
4610
+ };
4611
+ }
4612
+ var pageNew = {
4557
4613
  cdpEndpoint: src.endpoint,
4558
4614
  targetId: src.targetId,
4559
4615
  pageUrl: src.pageUrl,
4560
- pageTitle: src.pageTitle
4616
+ pageTitle: src.pageTitle,
4617
+ elements: [Object.assign({ n: 1 }, entry)]
4561
4618
  };
4562
- if (found) try {
4563
- var prev = JSON.parse(found[1]);
4564
- var list = prev && prev.elements ? prev.elements : [];
4565
- var maxN = 0;
4566
- for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
4567
- entry.n = maxN + 1;
4568
- list.push(entry);
4569
- page.elements = list;
4570
- draft = draft.slice(0, found.index) + draft.slice(found.index + found[0].length);
4571
- } catch (e) {}
4572
- if (!page.elements) page.elements = elements;
4573
- var block = "[๐ŸŒ CDP-PICKS page=\"" + String(src.pageTitle || src.pageUrl || "").replace(/"/g, "'") + "\" targetId=\"" + src.targetId + "\" endpoint=\"" + src.endpoint + "\"]\n" + JSON.stringify(page, null, 2) + "\n[/CDP-PICKS]";
4574
- draft = draft ? draft + (draft.charAt(draft.length - 1) === "\n" ? "" : "\n") + block : block;
4575
- input.setDraft(draft);
4619
+ var newFile = "picks-" + Date.now() + ".json";
4620
+ postJson("/bcdp/api/picks-save", {
4621
+ block: JSON.stringify(pageNew, null, 2),
4622
+ file: newFile
4623
+ }).then(function(res) {
4624
+ if (!res || res.ok === false || !res.value) return;
4625
+ var cur = readDraftText(input);
4626
+ var line = "[๐ŸŒ CDP-PICKS โ†’ " + res.value.file + " | " + src.endpoint + " | " + (src.pageTitle || src.pageUrl || "") + " | elements:1]";
4627
+ cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + line : line;
4628
+ input.setDraft(cur);
4629
+ }).catch(function() {});
4576
4630
  return {
4577
4631
  ok: true,
4578
- code: "drafted",
4579
- count: page.elements.length
4632
+ code: "archiving"
4580
4633
  };
4581
4634
  } catch (err) {
4582
4635
  return {
package/lib/index.js CHANGED
@@ -2733,6 +2733,19 @@ 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
+ /**
2736
2749
  * Register the `/bcdp/api` HTTP route on the host's web server.
2737
2750
  *
2738
2751
  * The route reads/writes the `ego-browser` settings namespace in-process
@@ -2834,6 +2847,38 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager) {
2834
2847
  return;
2835
2848
  }
2836
2849
  writeJson(res, 200, envelopeOk({ outcome: await probeEndpoint(endpoint, { timeoutMs: typeof body.timeoutMs === "number" && Number.isFinite(body.timeoutMs) ? body.timeoutMs : void 0 }) }));
2850
+ } else if (method === "picks-save") {
2851
+ const saveBody = body;
2852
+ const block = typeof saveBody.block === "string" ? saveBody.block : "";
2853
+ if (block === "") {
2854
+ writeJson(res, 400, envelopeError("invalid-block", "block is required"));
2855
+ return;
2856
+ }
2857
+ const file = typeof saveBody.file === "string" && /^[A-Za-z0-9._-]+\.json$/.test(saveBody.file) ? saveBody.file : `picks-${Date.now()}.json`;
2858
+ const dir = picksDir();
2859
+ await mkdir(dir, { recursive: true });
2860
+ const target = resolve(dir, file);
2861
+ if (!target.startsWith(resolve(dir))) {
2862
+ writeJson(res, 400, envelopeError("invalid-path", "path escapes the picks dir"));
2863
+ return;
2864
+ }
2865
+ await writeFile(target, block, "utf8");
2866
+ writeJson(res, 200, envelopeOk({
2867
+ path: target,
2868
+ file
2869
+ }));
2870
+ } else if (method === "picks-load") {
2871
+ const loadBody = body;
2872
+ const file = typeof loadBody.file === "string" && /^[A-Za-z0-9._-]+\.json$/.test(loadBody.file) ? loadBody.file : "";
2873
+ if (file === "") {
2874
+ writeJson(res, 400, envelopeError("invalid-file", "file is required"));
2875
+ return;
2876
+ }
2877
+ try {
2878
+ writeJson(res, 200, envelopeOk({ content: await readFile(resolve(picksDir(), file), "utf8") }));
2879
+ } catch (error) {
2880
+ writeJson(res, 404, envelopeError("not-found", error instanceof Error ? error.message : String(error)));
2881
+ }
2837
2882
  } else writeJson(res, 404, envelopeError("not-found", `unknown ego-browser API method "${method}"`));
2838
2883
  } catch (error) {
2839
2884
  const e = error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "0.17.15",
3
+ "version": "0.17.16",
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",