dsh-browser-cdp 0.18.14 → 0.18.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.18.14",
5
+ "version": "0.18.15",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -1857,6 +1857,7 @@ function apply(ctx) {
1857
1857
  mountFamilySettingsCard(ctx);
1858
1858
  mountPluginsPageCard(ctx);
1859
1859
  mountPicksDockCard(ctx);
1860
+ mountPicksBadge(ctx);
1860
1861
  var betterSidebarService;
1861
1862
  try {
1862
1863
  betterSidebarService = typeof ctx.get === "function" ? ctx.get("betterSidebar") : void 0;
@@ -3098,22 +3099,24 @@ var TAB_CSS = `
3098
3099
  * attachments are — the block carries its source CDP connection
3099
3100
  * (endpoint + targetId) so the agent can find the element's DOM again
3100
3101
  * (backendNodeId is directly addressable via bcdp_cdp DOM.describeNode).
3101
- * Format inside the draft:
3102
- * [CDP-PICKS page="..." targetId="..." endpoint="..."]
3103
- * {"cdpEndpoint":..., "targetId":..., "pageUrl":..., "elements":[{n,backendNodeId,tag,id,name,focusable,describe}]}
3104
- * [/CDP-PICKS]
3102
+ * Format inside the draft(@mention 精髓:被替换字段以 @ 开头):
3103
+ * @"picks/<file>.json"
3104
+ * — 显示层把该 token 替换成文件片;归档 JSON
3105
+ * {"cdpEndpoint":..., "targetId":..., "pageUrl":..., "elements":[...]}
3106
+ * 存 <workspace>/picks/<file>.json,dock 卡按引用取回渲染。
3105
3107
  */
3106
3108
  function injectPickCardStyles() {
3107
3109
  if (document.getElementById("dsh-cdp-picks-styles") !== null) return;
3108
3110
  var style = document.createElement("style");
3109
3111
  style.id = "dsh-cdp-picks-styles";
3110
- 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,永不顶满整窗 */\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}";
3112
+ 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}";
3111
3113
  document.head.appendChild(style);
3112
3114
  }
3113
3115
  function CdpPicksDockCard(props) {
3114
3116
  var input = props.input;
3115
3117
  var h = React.createElement;
3116
- var setTick = React.useState(0)[1];
3118
+ var tick = React.useState(0);
3119
+ var setTick = tick[1];
3117
3120
  React.useEffect(function() {
3118
3121
  var timer = window.setInterval(function() {
3119
3122
  setTick(function(n) {
@@ -3125,13 +3128,10 @@ function CdpPicksDockCard(props) {
3125
3128
  };
3126
3129
  }, []);
3127
3130
  var snap = readDraftText(input);
3128
- var refRe = /\[🌐 CDP-PICKS → ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g;
3131
+ var refRe = /@"(picks\/[^"\s]+\.json)"/g;
3129
3132
  var refs = [], mm;
3130
3133
  while ((mm = refRe.exec(snap)) !== null) refs.push({
3131
3134
  file: mm[1],
3132
- endpoint: mm[2],
3133
- title: mm[3],
3134
- count: Number(mm[4]),
3135
3135
  line: mm[0]
3136
3136
  });
3137
3137
  try {
@@ -3149,8 +3149,10 @@ function CdpPicksDockCard(props) {
3149
3149
  React.useEffect(function() {
3150
3150
  var cancelled = false;
3151
3151
  refs.forEach(function(r) {
3152
- if (contents[r.file] !== void 0) return;
3153
- postJson("/bcdp/api/picks-load", { file: r.file }).then(function(res) {
3152
+ postJson("/bcdp/api/picks-load", {
3153
+ file: r.file.slice(6),
3154
+ session: props.session
3155
+ }).then(function(res) {
3154
3156
  if (cancelled) return;
3155
3157
  var content = res && res.ok !== false && res.value ? String(res.value.content || "") : "";
3156
3158
  setContents(function(prev) {
@@ -3163,7 +3165,7 @@ function CdpPicksDockCard(props) {
3163
3165
  return function() {
3164
3166
  cancelled = true;
3165
3167
  };
3166
- }, [filesKey]);
3168
+ }, [filesKey, Math.floor(tick[0] / 5)]);
3167
3169
  if (refs.length === 0) return null;
3168
3170
  function removeRef(line) {
3169
3171
  var cur = readDraftText(input);
@@ -3179,11 +3181,13 @@ function CdpPicksDockCard(props) {
3179
3181
  } }, refs.map(function(r) {
3180
3182
  var content = contents[r.file];
3181
3183
  var elements = [];
3184
+ var pageTitle = "";
3182
3185
  if (typeof content === "string" && content !== "") try {
3183
3186
  var obj = JSON.parse(content);
3184
3187
  elements = obj && obj.elements || [];
3188
+ pageTitle = obj && obj.pageTitle || "";
3185
3189
  } catch (e) {}
3186
- var head = h("div", { className: "dsh-cdp-picks-head" }, h("span", { style: { fontWeight: 700 } }, "🌐 " + wt("pickCardTitle")), h("span", { className: "dsh-cdp-picks-sub" }, (r.endpoint || "") + " · " + (r.title || "")), h("span", { className: "dsh-cdp-picks-sub" }, wt("pickCardElements", { n: r.count })), h("button", {
3190
+ 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" }, typeof content === "string" ? wt("pickCardElements", { n: elements.length }) : "…"), h("button", {
3187
3191
  type: "button",
3188
3192
  title: wt("pickCardRemove"),
3189
3193
  className: "dsh-cdp-picks-close",
@@ -3213,6 +3217,54 @@ function CdpPicksDockCard(props) {
3213
3217
  }, head, chips);
3214
3218
  }));
3215
3219
  }
3220
+ function CdpPicksBadge(props) {
3221
+ var h = React.createElement;
3222
+ var setTick = React.useState(0)[1];
3223
+ React.useEffect(function() {
3224
+ var timer = window.setInterval(function() {
3225
+ setTick(function(n) {
3226
+ return n + 1;
3227
+ });
3228
+ }, 1e3);
3229
+ return function() {
3230
+ window.clearInterval(timer);
3231
+ };
3232
+ }, []);
3233
+ var refs = [];
3234
+ try {
3235
+ if (props && props.sessionId !== void 0 && props.sessionId !== null ? String(props.sessionId) : null) {
3236
+ var draft = typeof props.getDraft === "function" ? String(props.getDraft() || "") : "";
3237
+ var countRefs = (draft.match(/\[(?:🌐 )?CDP-PICKS/g) || []).length;
3238
+ var refRe2 = /@"(picks\/[^"\s]+\.json)"/g;
3239
+ var mm;
3240
+ while ((mm = refRe2.exec(draft)) !== null) refs.push({ file: mm[1] });
3241
+ }
3242
+ } catch (e) {}
3243
+ try {
3244
+ window.__dshBrowserCdpDeco = Object.assign({}, window.__dshBrowserCdpDeco, {
3245
+ badgeRefs: refs.length,
3246
+ blockMarkers: countRefs
3247
+ });
3248
+ } catch (e) {}
3249
+ if (refs.length === 0) return null;
3250
+ return h("div", { className: "dsh-cdp-picks-badges" }, refs.map(function(r, i) {
3251
+ return h("span", {
3252
+ key: r.file,
3253
+ className: "dsh-cdp-picks-badge",
3254
+ title: "🌐 @" + r.file
3255
+ }, "🌐" + (refs.length > 1 ? " ×" + (i + 1) : ""));
3256
+ }));
3257
+ }
3258
+ function mountPicksBadge(ctx) {
3259
+ ctx.slots.inject("conversation.input.overlay", function() {
3260
+ return ctx.slots.register({
3261
+ name: "conversation.input.overlay",
3262
+ id: "dsh-browser-cdp.picks-badge",
3263
+ order: 110,
3264
+ label: "dsh-browser-cdp picks badge"
3265
+ }, CdpPicksBadge);
3266
+ }, "dsh-browser-cdp: picks badge");
3267
+ }
3216
3268
  function mountPicksDockCard(ctx) {
3217
3269
  injectPickCardStyles();
3218
3270
  try {
@@ -3225,14 +3277,22 @@ function mountPicksDockCard(ctx) {
3225
3277
  locale: "dsh-browser-cdp",
3226
3278
  order: 0,
3227
3279
  inject: function(sessionId) {
3228
- var input = null;
3280
+ var input = null, session = null;
3229
3281
  try {
3230
3282
  var actx = ctx.sessions.scope(sessionId);
3231
3283
  input = actx.get("conversation").input.for(actx);
3284
+ session = String(sessionId);
3232
3285
  } catch (e) {
3233
3286
  input = null;
3287
+ session = null;
3234
3288
  }
3235
- return { input };
3289
+ return {
3290
+ input,
3291
+ session,
3292
+ getDraft: function() {
3293
+ return readDraftText(input);
3294
+ }
3295
+ };
3236
3296
  }
3237
3297
  }, CdpPicksDockCard);
3238
3298
  }, "dsh-browser-cdp: picks dock card");
@@ -3307,67 +3367,69 @@ function deliverPickToConversation(ctx, element, action) {
3307
3367
  focusable: !!element.keyboardFocusable,
3308
3368
  describe
3309
3369
  };
3310
- var reRef = /\[🌐 CDP-PICKS → ([^\s|]+) \| ([^|]*) \| ([^|]*) \| elements:(\d+)[^\]]*\]/g, file = null, oldLine = null, mm;
3311
- while ((mm = reRef.exec(draft)) !== null) if (mm[2] === src.endpoint) {
3312
- file = mm[1];
3313
- mm[2];
3314
- oldLine = mm[0];
3315
- Number(mm[4]);
3316
- break;
3317
- }
3318
- if (file !== null) {
3319
- postJson("/bcdp/api/picks-load", { file }).then(function(lres) {
3320
- try {
3321
- if (!lres || lres.ok === false || !lres.value) return;
3322
- var obj = JSON.parse(lres.value.content);
3323
- var list = obj && obj.elements ? obj.elements : [];
3370
+ var reRef = /@"(picks\/([^"\s]+\.json))"/g;
3371
+ var mentions = [], mm;
3372
+ while ((mm = reRef.exec(draft)) !== null) mentions.push({
3373
+ token: mm[0],
3374
+ file: mm[2]
3375
+ });
3376
+ (async function() {
3377
+ try {
3378
+ var found = null, hit = null, obj = null;
3379
+ for (var i = 0; i < mentions.length; i++) {
3380
+ var lres = await postJson("/bcdp/api/picks-load", {
3381
+ file: mentions[i].file,
3382
+ session: sessionId
3383
+ });
3384
+ if (!lres || lres.ok === false || !lres.value) continue;
3385
+ obj = JSON.parse(lres.value.content);
3386
+ if (obj && obj.cdpEndpoint === src.endpoint) {
3387
+ found = mentions[i];
3388
+ hit = obj.elements || [];
3389
+ break;
3390
+ }
3391
+ }
3392
+ if (found) {
3324
3393
  var maxN = 0;
3325
- for (var k = 0; k < list.length; k++) if (list[k].n > maxN) maxN = list[k].n;
3394
+ for (var k = 0; k < hit.length; k++) if (hit[k].n > maxN) maxN = hit[k].n;
3326
3395
  entry.n = maxN + 1;
3327
- list.push(Object.assign({}, entry));
3396
+ hit.push(Object.assign({}, entry));
3328
3397
  var page = {
3329
3398
  cdpEndpoint: obj.cdpEndpoint || src.endpoint,
3330
3399
  targetId: obj.targetId || src.targetId,
3331
3400
  pageUrl: obj.pageUrl || src.pageUrl,
3332
3401
  pageTitle: obj.pageTitle || src.pageTitle,
3333
- elements: list
3402
+ elements: hit
3334
3403
  };
3335
- postJson("/bcdp/api/picks-save", {
3404
+ await postJson("/bcdp/api/picks-save", {
3336
3405
  block: JSON.stringify(page, null, 2),
3337
- file
3406
+ file: found.file,
3407
+ session: sessionId
3338
3408
  });
3339
- var cur = readDraftText(input);
3340
- var newLine = "[🌐 CDP-PICKS → " + file + " | " + src.endpoint + " | " + (page.pageTitle || "") + " | elements:" + list.length + "]";
3341
- var idx = cur.indexOf(oldLine);
3342
- if (idx >= 0) input.setDraft(cur.slice(0, idx) + newLine + cur.slice(idx + oldLine.length));
3343
- } catch (e) {}
3344
- }).catch(function() {});
3345
- return {
3346
- ok: true,
3347
- code: "archiving"
3348
- };
3349
- }
3350
- var pageNew = {
3351
- cdpEndpoint: src.endpoint,
3352
- targetId: src.targetId,
3353
- pageUrl: src.pageUrl,
3354
- pageTitle: src.pageTitle,
3355
- elements: [Object.assign({ n: 1 }, entry)]
3356
- };
3357
- var newFile = "picks-" + Date.now() + ".json";
3358
- postJson("/bcdp/api/picks-save", {
3359
- block: JSON.stringify(pageNew, null, 2),
3360
- file: newFile
3361
- }).then(function(res) {
3362
- if (!res || res.ok === false || !res.value) return;
3363
- var cur = readDraftText(input);
3364
- var line = "[🌐 CDP-PICKS → " + res.value.file + " | " + src.endpoint + " | " + (src.pageTitle || src.pageUrl || "") + " | elements:1]";
3365
- cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + line : line;
3366
- input.setDraft(cur);
3367
- }).catch(function() {});
3409
+ return;
3410
+ }
3411
+ var pageNew = {
3412
+ cdpEndpoint: src.endpoint,
3413
+ targetId: src.targetId,
3414
+ pageUrl: src.pageUrl,
3415
+ pageTitle: src.pageTitle,
3416
+ elements: [Object.assign({ n: 1 }, entry)]
3417
+ };
3418
+ var sres = await postJson("/bcdp/api/picks-save", {
3419
+ block: JSON.stringify(pageNew, null, 2),
3420
+ session: sessionId
3421
+ });
3422
+ if (!sres || sres.ok === false || !sres.value) return;
3423
+ var token = "@\"picks/" + sres.value.file + "\"";
3424
+ var cur = readDraftText(input);
3425
+ cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + token : token;
3426
+ input.setDraft(cur);
3427
+ } catch (e) {}
3428
+ })();
3368
3429
  return {
3369
3430
  ok: true,
3370
- code: "archiving"
3431
+ code: "archiving",
3432
+ count: 1
3371
3433
  };
3372
3434
  } catch (err) {
3373
3435
  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 = picksDir();
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(picksDir(), file), "utf8") }));
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.18.14",
3
+ "version": "0.18.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.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",