dsh-browser-cdp 0.18.12 โ†’ 0.18.13

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.18.12",
5
+ "version": "0.18.13",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -3117,35 +3117,52 @@ function CdpPicksDockCard(props) {
3117
3117
  window.clearInterval(timer);
3118
3118
  };
3119
3119
  }, []);
3120
- var draft = readDraftText(input);
3121
- var re = /\[(?:๐ŸŒ )?CDP-PICKS\s+page="([^"]*)"\s+targetId="([^"]*)"\s+endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
3122
- var found = [], mm;
3123
- while ((mm = re.exec(draft)) !== null) {
3124
- var elements = [];
3125
- try {
3126
- var obj = JSON.parse(mm[4]);
3127
- elements = obj && obj.elements || [];
3128
- } catch (e) {}
3129
- found.push({
3130
- title: mm[1],
3131
- endpoint: mm[3],
3132
- elements,
3133
- block: mm[0]
3134
- });
3135
- }
3120
+ var snap = readDraftText(input);
3121
+ var refRe = /\[๐ŸŒ CDP-PICKS โ†’ ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g;
3122
+ var refs = [], mm;
3123
+ while ((mm = refRe.exec(snap)) !== null) refs.push({
3124
+ file: mm[1],
3125
+ endpoint: mm[2],
3126
+ title: mm[3],
3127
+ count: Number(mm[4]),
3128
+ line: mm[0]
3129
+ });
3136
3130
  try {
3137
3131
  window.__dshBrowserCdpDeco = {
3138
- stage: found.length ? "rendered" : "no-blocks",
3139
- blocks: found.length,
3140
- draftLen: draft.length
3132
+ stage: refs.length ? "rendered" : "no-refs",
3133
+ refs: refs.length,
3134
+ draftLen: snap.length
3141
3135
  };
3142
3136
  } catch (e) {}
3143
- function removeBlock(block) {
3144
- if (!input || typeof input.setDraft !== "function") return;
3137
+ var loadedState = React.useState({});
3138
+ var contents = loadedState[0], setContents = loadedState[1];
3139
+ var filesKey = refs.map(function(r) {
3140
+ return r.file;
3141
+ }).join("|");
3142
+ React.useEffect(function() {
3143
+ var cancelled = false;
3144
+ refs.forEach(function(r) {
3145
+ if (contents[r.file] !== void 0) return;
3146
+ postJson("/bcdp/api/picks-load", { file: r.file }).then(function(res) {
3147
+ if (cancelled) return;
3148
+ var content = res && res.ok !== false && res.value ? String(res.value.content || "") : "";
3149
+ setContents(function(prev) {
3150
+ var n = Object.assign({}, prev);
3151
+ n[r.file] = content;
3152
+ return n;
3153
+ });
3154
+ }).catch(function() {});
3155
+ });
3156
+ return function() {
3157
+ cancelled = true;
3158
+ };
3159
+ }, [filesKey]);
3160
+ if (refs.length === 0) return null;
3161
+ function removeRef(line) {
3145
3162
  var cur = readDraftText(input);
3146
- var idx = cur.indexOf(block);
3163
+ var idx = cur.indexOf(line);
3147
3164
  if (idx < 0) return;
3148
- var next = cur.slice(0, idx) + cur.slice(idx + block.length);
3165
+ var next = cur.slice(0, idx) + cur.slice(idx + line.length);
3149
3166
  next = next.replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
3150
3167
  input.setDraft(next);
3151
3168
  }
@@ -3214,24 +3231,39 @@ function CdpPicksDockCard(props) {
3214
3231
  return h("div", { style: {
3215
3232
  display: "grid",
3216
3233
  gap: "6px"
3217
- } }, found.map(function(f) {
3218
- 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", {
3234
+ } }, refs.map(function(r) {
3235
+ var content = contents[r.file];
3236
+ var elements = [];
3237
+ if (typeof content === "string" && content !== "") try {
3238
+ var obj = JSON.parse(content);
3239
+ elements = obj && obj.elements || [];
3240
+ } catch (e) {}
3241
+ 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", {
3219
3242
  type: "button",
3220
3243
  title: wt("pickCardRemove"),
3221
3244
  style: closeStyle,
3222
3245
  onClick: function() {
3223
- removeBlock(f.block);
3246
+ removeRef(r.line);
3224
3247
  }
3225
3248
  }, "โœ•"));
3226
- var chips = f.elements.slice(0, 6).map(function(el) {
3227
- return h("div", {
3228
- key: el.n,
3249
+ var chips = [];
3250
+ if (typeof content !== "string") chips.push(h("div", {
3251
+ key: "loading",
3252
+ style: subStyle
3253
+ }, "โ€ฆ"));
3254
+ for (var i = 0; i < elements.length && i < 6; i++) {
3255
+ var el = elements[i] || {};
3256
+ chips.push(h("div", {
3257
+ key: el.n || i,
3229
3258
  style: chipStyle
3230
- }, h("span", { style: numStyle }, "#" + (el.n || "")), h("span", { style: tagStyle }, el.tag || "?"), h("span", { style: descStyle }, el.describe || el.name || ""));
3231
- });
3232
- if (f.elements.length > 6) chips.push(h("div", { style: subStyle }, "โ€ฆ +" + (f.elements.length - 6)));
3259
+ }, h("span", { style: numStyle }, "#" + (el.n || i + 1)), h("span", { style: tagStyle }, el.tag || "?"), h("span", { style: descStyle }, el.describe || el.name || "")));
3260
+ }
3261
+ if (elements.length > 6) chips.push(h("div", {
3262
+ key: "more",
3263
+ style: subStyle
3264
+ }, "โ€ฆ +" + (elements.length - 6)));
3233
3265
  return h("div", {
3234
- key: f.targetId + ":" + f.endpoint,
3266
+ key: r.file,
3235
3267
  style: cardStyle
3236
3268
  }, head, chips);
3237
3269
  }));
@@ -3253,13 +3285,6 @@ function mountPicksDockCard(ctx) {
3253
3285
  input = actx.get("conversation").input.for(actx);
3254
3286
  } catch (e) {
3255
3287
  input = null;
3256
- try {
3257
- window.__dshBrowserCdpDeco = Object.assign({}, window.__dshBrowserCdpDeco, {
3258
- stage: "inject-failed",
3259
- error: String(e && e.message || e),
3260
- sessionId: String(sessionId)
3261
- });
3262
- } catch (e2) {}
3263
3288
  }
3264
3289
  return { input };
3265
3290
  }
@@ -3328,6 +3353,7 @@ function deliverPickToConversation(ctx, element, action) {
3328
3353
  pageTitle: ""
3329
3354
  };
3330
3355
  var entry = {
3356
+ n: 1,
3331
3357
  backendNodeId: element.backendNodeId,
3332
3358
  tag: element.tag,
3333
3359
  id: element.id,
@@ -3335,40 +3361,67 @@ function deliverPickToConversation(ctx, element, action) {
3335
3361
  focusable: !!element.keyboardFocusable,
3336
3362
  describe
3337
3363
  };
3338
- var re = /\[(?:๐ŸŒ )?CDP-PICKS[^\]]*\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g, found = null, mm;
3339
- while ((mm = re.exec(draft)) !== null) try {
3340
- var obj = JSON.parse(mm[1]);
3341
- if (obj && obj.targetId === src.targetId && obj.cdpEndpoint === src.endpoint) {
3342
- found = mm;
3343
- mm[0].split("\n")[0];
3344
- break;
3345
- }
3346
- } catch (e) {}
3347
- var elements = [Object.assign({ n: 1 }, entry)];
3348
- var page = {
3364
+ var reRef = /\[๐ŸŒ CDP-PICKS โ†’ ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g, file = null, oldLine = null, mm;
3365
+ while ((mm = reRef.exec(draft)) !== null) if (mm[2] === src.endpoint) {
3366
+ file = mm[1];
3367
+ mm[2];
3368
+ oldLine = mm[0];
3369
+ Number(mm[4]);
3370
+ break;
3371
+ }
3372
+ if (file !== null) {
3373
+ postJson("/bcdp/api/picks-load", { file }).then(function(lres) {
3374
+ try {
3375
+ if (!lres || lres.ok === false || !lres.value) return;
3376
+ var obj = JSON.parse(lres.value.content);
3377
+ var list = obj && obj.elements ? obj.elements : [];
3378
+ var maxN = 0;
3379
+ for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
3380
+ entry.n = maxN + 1;
3381
+ list.push(Object.assign({}, entry));
3382
+ var page = {
3383
+ cdpEndpoint: obj.cdpEndpoint || src.endpoint,
3384
+ targetId: obj.targetId || src.targetId,
3385
+ pageUrl: obj.pageUrl || src.pageUrl,
3386
+ pageTitle: obj.pageTitle || src.pageTitle,
3387
+ elements: list
3388
+ };
3389
+ postJson("/bcdp/api/picks-save", {
3390
+ block: JSON.stringify(page, null, 2),
3391
+ file
3392
+ });
3393
+ var cur = readDraftText(input);
3394
+ var newLine = "[๐ŸŒ CDP-PICKS โ†’ " + file + " | " + src.endpoint + " | " + (page.pageTitle || "") + " | elements:" + list.length + "]";
3395
+ var idx = cur.indexOf(oldLine);
3396
+ if (idx >= 0) input.setDraft(cur.slice(0, idx) + newLine + cur.slice(idx + oldLine.length));
3397
+ } catch (e) {}
3398
+ }).catch(function() {});
3399
+ return {
3400
+ ok: true,
3401
+ code: "archiving"
3402
+ };
3403
+ }
3404
+ var pageNew = {
3349
3405
  cdpEndpoint: src.endpoint,
3350
3406
  targetId: src.targetId,
3351
3407
  pageUrl: src.pageUrl,
3352
- pageTitle: src.pageTitle
3408
+ pageTitle: src.pageTitle,
3409
+ elements: [Object.assign({ n: 1 }, entry)]
3353
3410
  };
3354
- if (found) try {
3355
- var prev = JSON.parse(found[1]);
3356
- var list = prev && prev.elements ? prev.elements : [];
3357
- var maxN = 0;
3358
- for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
3359
- entry.n = maxN + 1;
3360
- list.push(entry);
3361
- page.elements = list;
3362
- draft = draft.slice(0, found.index) + draft.slice(found.index + found[0].length);
3363
- } catch (e) {}
3364
- if (!page.elements) page.elements = elements;
3365
- 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]";
3366
- draft = draft ? draft + (draft.charAt(draft.length - 1) === "\n" ? "" : "\n") + block : block;
3367
- input.setDraft(draft);
3411
+ var newFile = "picks-" + Date.now() + ".json";
3412
+ postJson("/bcdp/api/picks-save", {
3413
+ block: JSON.stringify(pageNew, null, 2),
3414
+ file: newFile
3415
+ }).then(function(res) {
3416
+ if (!res || res.ok === false || !res.value) return;
3417
+ var cur = readDraftText(input);
3418
+ var line = "[๐ŸŒ CDP-PICKS โ†’ " + res.value.file + " | " + src.endpoint + " | " + (src.pageTitle || src.pageUrl || "") + " | elements:1]";
3419
+ cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + line : line;
3420
+ input.setDraft(cur);
3421
+ }).catch(function() {});
3368
3422
  return {
3369
3423
  ok: true,
3370
- code: "drafted",
3371
- count: page.elements.length
3424
+ code: "archiving"
3372
3425
  };
3373
3426
  } catch (err) {
3374
3427
  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.18.12",
3
+ "version": "0.18.13",
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",