dsh-browser-cdp 0.18.11 โ†’ 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.11",
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 snap = input && input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
3121
- var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
3122
- var re = /\[(?:๐ŸŒ )?CDP-PICKS\s+page="([^"]*)"\s+targetId="([^"]*)"\s+endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
3123
- var found = [], mm;
3124
- while ((mm = re.exec(draft)) !== null) {
3125
- var elements = [];
3126
- try {
3127
- var obj = JSON.parse(mm[4]);
3128
- elements = obj && obj.elements || [];
3129
- } catch (e) {}
3130
- found.push({
3131
- title: mm[1],
3132
- endpoint: mm[3],
3133
- elements,
3134
- block: mm[0]
3135
- });
3136
- }
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
+ });
3137
3130
  try {
3138
3131
  window.__dshBrowserCdpDeco = {
3139
- stage: found.length ? "rendered" : "no-blocks",
3140
- blocks: found.length,
3141
- draftLen: draft.length
3132
+ stage: refs.length ? "rendered" : "no-refs",
3133
+ refs: refs.length,
3134
+ draftLen: snap.length
3142
3135
  };
3143
3136
  } catch (e) {}
3144
- function removeBlock(block) {
3145
- if (!input || typeof input.setDraft !== "function") return;
3146
- var idx = draft.indexOf(block);
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) {
3162
+ var cur = readDraftText(input);
3163
+ var idx = cur.indexOf(line);
3147
3164
  if (idx < 0) return;
3148
- var next = draft.slice(0, idx) + draft.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,19 +3285,23 @@ 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
  }
3266
3291
  }, CdpPicksDockCard);
3267
3292
  }, "dsh-browser-cdp: picks dock card");
3268
3293
  }
3294
+ function readDraftText(input) {
3295
+ if (!input) return "";
3296
+ try {
3297
+ if (typeof input.draft === "string") return input.draft;
3298
+ } catch (e) {}
3299
+ try {
3300
+ var snap = input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
3301
+ if (snap && typeof snap.draft === "string") return snap.draft;
3302
+ } catch (e) {}
3303
+ return "";
3304
+ }
3269
3305
  function currentSessionId(list) {
3270
3306
  if (!list || typeof list !== "object") return "";
3271
3307
  if (typeof list.current === "string") return list.current;
@@ -3309,8 +3345,7 @@ function deliverPickToConversation(ctx, element, action) {
3309
3345
  ok: false,
3310
3346
  code: "no-input-facade"
3311
3347
  };
3312
- var snap = input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
3313
- var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
3348
+ var draft = readDraftText(input);
3314
3349
  var src = element.source || {
3315
3350
  endpoint: "",
3316
3351
  targetId: "",
@@ -3318,6 +3353,7 @@ function deliverPickToConversation(ctx, element, action) {
3318
3353
  pageTitle: ""
3319
3354
  };
3320
3355
  var entry = {
3356
+ n: 1,
3321
3357
  backendNodeId: element.backendNodeId,
3322
3358
  tag: element.tag,
3323
3359
  id: element.id,
@@ -3325,40 +3361,67 @@ function deliverPickToConversation(ctx, element, action) {
3325
3361
  focusable: !!element.keyboardFocusable,
3326
3362
  describe
3327
3363
  };
3328
- var re = /\[(?:๐ŸŒ )?CDP-PICKS[^\]]*\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g, found = null, mm;
3329
- while ((mm = re.exec(draft)) !== null) try {
3330
- var obj = JSON.parse(mm[1]);
3331
- if (obj && obj.targetId === src.targetId && obj.cdpEndpoint === src.endpoint) {
3332
- found = mm;
3333
- mm[0].split("\n")[0];
3334
- break;
3335
- }
3336
- } catch (e) {}
3337
- var elements = [Object.assign({ n: 1 }, entry)];
3338
- 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 = {
3339
3405
  cdpEndpoint: src.endpoint,
3340
3406
  targetId: src.targetId,
3341
3407
  pageUrl: src.pageUrl,
3342
- pageTitle: src.pageTitle
3408
+ pageTitle: src.pageTitle,
3409
+ elements: [Object.assign({ n: 1 }, entry)]
3343
3410
  };
3344
- if (found) try {
3345
- var prev = JSON.parse(found[1]);
3346
- var list = prev && prev.elements ? prev.elements : [];
3347
- var maxN = 0;
3348
- for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
3349
- entry.n = maxN + 1;
3350
- list.push(entry);
3351
- page.elements = list;
3352
- draft = draft.slice(0, found.index) + draft.slice(found.index + found[0].length);
3353
- } catch (e) {}
3354
- if (!page.elements) page.elements = elements;
3355
- 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]";
3356
- draft = draft ? draft + (draft.charAt(draft.length - 1) === "\n" ? "" : "\n") + block : block;
3357
- 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() {});
3358
3422
  return {
3359
3423
  ok: true,
3360
- code: "drafted",
3361
- count: page.elements.length
3424
+ code: "archiving"
3362
3425
  };
3363
3426
  } catch (err) {
3364
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.11",
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",