dsh-browser-cdp 0.17.14 โ†’ 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.14",
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 snap = input && input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
4329
- var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
4330
- var re = /\[(?:๐ŸŒ )?CDP-PICKS page="([^"]*)" targetId="([^"]*)" endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
4331
- var found = [], mm;
4332
- while ((mm = re.exec(draft)) !== null) {
4333
- var elements = [];
4334
- try {
4335
- var obj = JSON.parse(mm[4]);
4336
- elements = obj && obj.elements || [];
4337
- } catch (e) {}
4338
- found.push({
4339
- title: mm[1],
4340
- endpoint: mm[3],
4341
- elements,
4342
- block: mm[0]
4343
- });
4344
- }
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
+ });
4345
4338
  try {
4346
4339
  window.__dshBrowserCdpDeco = {
4347
- stage: found.length ? "rendered" : "no-blocks",
4348
- blocks: found.length,
4349
- draftLen: draft.length
4340
+ stage: refs.length ? "rendered" : "no-refs",
4341
+ refs: refs.length,
4342
+ draftLen: snap.length
4350
4343
  };
4351
4344
  } catch (e) {}
4352
- function removeBlock(block) {
4353
- if (!input || typeof input.setDraft !== "function") return;
4354
- var idx = draft.indexOf(block);
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) {
4370
+ var cur = readDraftText(input);
4371
+ var idx = cur.indexOf(line);
4355
4372
  if (idx < 0) return;
4356
- var next = draft.slice(0, idx) + draft.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,33 +4439,52 @@ 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
  }));
4446
4478
  }
4447
4479
  function mountPicksDockCard(ctx) {
4480
+ try {
4481
+ window.__dshBrowserCdpDeco = Object.assign({}, window.__dshBrowserCdpDeco, { stage: "registered" });
4482
+ } catch (e) {}
4448
4483
  ctx.slots.inject("conversation.input.dock", function() {
4449
4484
  return ctx.slots.register({
4450
4485
  name: "conversation.input.dock",
4451
4486
  id: "dsh-browser-cdp.picks",
4487
+ locale: "dsh-browser-cdp",
4452
4488
  order: 0,
4453
4489
  inject: function(sessionId) {
4454
4490
  var input = null;
@@ -4463,6 +4499,17 @@ function mountPicksDockCard(ctx) {
4463
4499
  }, CdpPicksDockCard);
4464
4500
  }, "dsh-browser-cdp: picks dock card");
4465
4501
  }
4502
+ function readDraftText(input) {
4503
+ if (!input) return "";
4504
+ try {
4505
+ if (typeof input.draft === "string") return input.draft;
4506
+ } catch (e) {}
4507
+ try {
4508
+ var snap = input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
4509
+ if (snap && typeof snap.draft === "string") return snap.draft;
4510
+ } catch (e) {}
4511
+ return "";
4512
+ }
4466
4513
  function currentSessionId(list) {
4467
4514
  if (!list || typeof list !== "object") return "";
4468
4515
  if (typeof list.current === "string") return list.current;
@@ -4506,8 +4553,7 @@ function deliverPickToConversation(ctx, element, action) {
4506
4553
  ok: false,
4507
4554
  code: "no-input-facade"
4508
4555
  };
4509
- var snap = input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
4510
- var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
4556
+ var draft = readDraftText(input);
4511
4557
  var src = element.source || {
4512
4558
  endpoint: "",
4513
4559
  targetId: "",
@@ -4515,6 +4561,7 @@ function deliverPickToConversation(ctx, element, action) {
4515
4561
  pageTitle: ""
4516
4562
  };
4517
4563
  var entry = {
4564
+ n: 1,
4518
4565
  backendNodeId: element.backendNodeId,
4519
4566
  tag: element.tag,
4520
4567
  id: element.id,
@@ -4522,40 +4569,67 @@ function deliverPickToConversation(ctx, element, action) {
4522
4569
  focusable: !!element.keyboardFocusable,
4523
4570
  describe
4524
4571
  };
4525
- var re = /\[(?:๐ŸŒ )?CDP-PICKS[^\]]*\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g, found = null, mm;
4526
- while ((mm = re.exec(draft)) !== null) try {
4527
- var obj = JSON.parse(mm[1]);
4528
- if (obj && obj.targetId === src.targetId && obj.cdpEndpoint === src.endpoint) {
4529
- found = mm;
4530
- mm[0].split("\n")[0];
4531
- break;
4532
- }
4533
- } catch (e) {}
4534
- var elements = [Object.assign({ n: 1 }, entry)];
4535
- 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 = {
4536
4613
  cdpEndpoint: src.endpoint,
4537
4614
  targetId: src.targetId,
4538
4615
  pageUrl: src.pageUrl,
4539
- pageTitle: src.pageTitle
4616
+ pageTitle: src.pageTitle,
4617
+ elements: [Object.assign({ n: 1 }, entry)]
4540
4618
  };
4541
- if (found) try {
4542
- var prev = JSON.parse(found[1]);
4543
- var list = prev && prev.elements ? prev.elements : [];
4544
- var maxN = 0;
4545
- for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
4546
- entry.n = maxN + 1;
4547
- list.push(entry);
4548
- page.elements = list;
4549
- draft = draft.slice(0, found.index) + draft.slice(found.index + found[0].length);
4550
- } catch (e) {}
4551
- if (!page.elements) page.elements = elements;
4552
- 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]";
4553
- draft = draft ? draft + (draft.charAt(draft.length - 1) === "\n" ? "" : "\n") + block : block;
4554
- 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() {});
4555
4630
  return {
4556
4631
  ok: true,
4557
- code: "drafted",
4558
- count: page.elements.length
4632
+ code: "archiving"
4559
4633
  };
4560
4634
  } catch (err) {
4561
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.14",
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",