@linxin666/dsh-client-ui-browser-view 0.4.18 → 0.4.19

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/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: 0cd2c3239c6bedb05d31262009f48104d332c21c
6
- README.zh.md: 1b0c650f24d8e69705e4fe3ca78ef5beeed4b75a
5
+ README.md: 8857b4d14e18825f749a62c7e751dcc3b41d9f74
6
+ README.zh.md: d883397d3451bed76085a847b568d2838bb1d06a
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  English | [中文](README.zh.md)
4
4
 
5
5
  <p align="center">
6
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
6
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
7
7
  &nbsp;
8
8
  <img src="https://img.shields.io/badge/license-BSD--3--Clause-blue?style=flat-square" alt="License">
9
9
  </p>
package/README.zh.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [English](README.md) | 中文
4
4
 
5
5
  <p align="center">
6
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
6
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
7
7
  &nbsp;
8
8
  <img src="https://img.shields.io/badge/license-BSD--3--Clause-blue?style=flat-square" alt="License">
9
9
  </p>
package/lib/index.js CHANGED
@@ -127,11 +127,11 @@ var CdpClient = class CdpClient {
127
127
  });
128
128
  this.socket.send(JSON.stringify(payload), (error) => {
129
129
  if (error === null || error === void 0) return;
130
- const call = this.pending.get(id);
131
- if (call === void 0) return;
132
- this.pending.delete(id);
133
- clearTimeout(call.timer);
134
- call.reject(new CdpError(method, -1, error.message));
130
+ const reason = `the DevTools socket write failed: ${error.message}`;
131
+ this.failAll(reason);
132
+ try {
133
+ this.socket.close();
134
+ } catch {}
135
135
  });
136
136
  });
137
137
  }
@@ -491,6 +491,20 @@ var ChromeProcess = class ChromeProcess {
491
491
  return this.disposed;
492
492
  }
493
493
  /**
494
+ * Subscribe to child-process exit so attached transports mark themselves
495
+ * closed without waiting for idle WebSocket teardown (#2051).
496
+ */
497
+ onExit(listener) {
498
+ if (this.child.exitCode !== null || this.child.signalCode !== null) {
499
+ listener();
500
+ return () => void 0;
501
+ }
502
+ this.child.once("exit", listener);
503
+ return () => {
504
+ this.child.off("exit", listener);
505
+ };
506
+ }
507
+ /**
494
508
  * What the disposal achieved, once it ran. A caller that needs to know
495
509
  * whether a browser survived the shutdown reads this instead of assuming.
496
510
  * @returns the recorded outcome, or undefined before {@link dispose}.
@@ -549,6 +563,9 @@ function describeExitHint(port) {
549
563
  }
550
564
  /**
551
565
  * Terminate one child process, escalating to SIGKILL after a grace period.
566
+ * On Windows, `child.kill()` stops only the parent PID while Chrome's GPU and
567
+ * Crashpad children linger and lock the temp profile; invoke `taskkill /T /F`
568
+ * beside it so the whole process tree shuts down cleanly (#2051).
552
569
  * @param child - the process launched for this browser.
553
570
  */
554
571
  async function terminate(child) {
@@ -557,6 +574,11 @@ async function terminate(child) {
557
574
  child.once("exit", () => resolve());
558
575
  child.once("error", () => resolve());
559
576
  });
577
+ if (process.platform === "win32" && child.pid !== void 0) await killProcessTreeWin32(child.pid);
578
+ if (child.exitCode !== null || child.signalCode !== null) {
579
+ await exited;
580
+ return;
581
+ }
560
582
  try {
561
583
  child.kill();
562
584
  } catch {
@@ -574,9 +596,40 @@ async function terminate(child) {
574
596
  setTimeout(resolve, CHROME_EXIT_TIMEOUT_MS);
575
597
  })]);
576
598
  }
599
+ /** Force-terminate a Windows process tree rooted at `pid`, ignoring already-gone errors. */
600
+ async function killProcessTreeWin32(pid) {
601
+ await new Promise((resolve) => {
602
+ let settled = false;
603
+ const finish = () => {
604
+ if (settled) return;
605
+ settled = true;
606
+ clearTimeout(timer);
607
+ resolve();
608
+ };
609
+ const timer = setTimeout(finish, CHROME_EXIT_TIMEOUT_MS);
610
+ const unref = timer.unref;
611
+ if (typeof unref === "function") unref.call(timer);
612
+ try {
613
+ const killer = spawn("taskkill", [
614
+ "/PID",
615
+ String(pid),
616
+ "/T",
617
+ "/F"
618
+ ], {
619
+ stdio: "ignore",
620
+ windowsHide: true
621
+ });
622
+ killer.once("close", finish);
623
+ killer.once("error", finish);
624
+ } catch {
625
+ finish();
626
+ }
627
+ });
628
+ }
577
629
  /**
578
630
  * Delete the profile directory this launch created, without ever following a
579
- * link out of it.
631
+ * link out of it. Retries briefly on transient file locks left behind while
632
+ * browser subprocesses release handles (#2051).
580
633
  *
581
634
  * `fs.rm({ recursive: true })` is banned repository-wide: recursion walks a
582
635
  * junction or symlink happily and deletes whatever it points at, so a temp
@@ -586,12 +639,29 @@ async function terminate(child) {
586
639
  * Failures are swallowed: a leftover file in the OS temp directory is a lesser
587
640
  * problem than failing the dispose path that the caller is awaiting.
588
641
  * @param dir - absolute path of the profile directory created by this launch.
642
+ * @param retryDelaysMs - backoff delays after locked removals.
589
643
  */
590
- async function removeTempProfile(dir) {
644
+ async function removeTempProfile(dir, retryDelaysMs = [
645
+ 50,
646
+ 150,
647
+ 350
648
+ ]) {
591
649
  const root = tmpdir();
592
650
  if (!dir.startsWith(root) || dir === root) return;
593
- await emptyDirectory(dir);
594
- await rmdir(dir).catch(() => void 0);
651
+ for (let attempt = 0; attempt <= retryDelaysMs.length; attempt++) {
652
+ await emptyDirectory(dir);
653
+ try {
654
+ await rmdir(dir);
655
+ return;
656
+ } catch (error) {
657
+ if (error?.code === "ENOENT") return;
658
+ const delay = retryDelaysMs[attempt];
659
+ if (delay === void 0) return;
660
+ await new Promise((resolve) => {
661
+ setTimeout(resolve, delay);
662
+ });
663
+ }
664
+ }
595
665
  }
596
666
  /** Recursively empty one directory, refusing to descend through links. */
597
667
  async function emptyDirectory(dir) {
@@ -2103,9 +2173,14 @@ async function scrollBy(scope, tabId, delta) {
2103
2173
  async function openIsolatedSession(options) {
2104
2174
  const chrome = await ChromeProcess.launch({ viewport: options.viewport });
2105
2175
  let cdp;
2176
+ let unbindExit;
2106
2177
  try {
2107
2178
  cdp = await CdpClient.connect(chrome.info.webSocketDebuggerUrl);
2179
+ unbindExit = chrome.onExit(() => {
2180
+ cdp.close();
2181
+ });
2108
2182
  } catch (error) {
2183
+ unbindExit?.();
2109
2184
  await chrome.dispose();
2110
2185
  throw error;
2111
2186
  }
@@ -2122,6 +2197,7 @@ async function openIsolatedSession(options) {
2122
2197
  tabs,
2123
2198
  chrome,
2124
2199
  async dispose() {
2200
+ unbindExit?.();
2125
2201
  await tabs.dispose();
2126
2202
  cdp.close();
2127
2203
  await chrome.dispose();
@@ -2239,17 +2315,18 @@ var BrowserViewService = class {
2239
2315
  this.idleTimer = timer;
2240
2316
  }
2241
2317
  }
2242
- /** Whether a browser is currently running. */
2318
+ /** Whether a browser is currently running with an open transport. */
2243
2319
  get running() {
2244
- return this.session !== void 0;
2320
+ return this.session !== void 0 && !this.session.transport.closed;
2245
2321
  }
2246
2322
  /** The current panel-facing state; safe to call before anything started. */
2247
2323
  state() {
2248
2324
  const config = this.resolveConfig();
2325
+ const live = this.session !== void 0 && !this.session.transport.closed ? this.session : void 0;
2249
2326
  const state = {
2250
- tabs: this.session?.tabs.list() ?? [],
2251
- activeTabId: this.session === void 0 ? null : this.displayedOrDefault(),
2252
- running: this.session !== void 0,
2327
+ tabs: live?.tabs.list() ?? [],
2328
+ activeTabId: live === void 0 ? null : this.displayedOrDefault(),
2329
+ running: live !== void 0,
2253
2330
  mode: config.mode
2254
2331
  };
2255
2332
  if (config.mode === "cdp" && config.cdpEndpoint !== void 0) try {
@@ -2430,6 +2507,9 @@ var BrowserViewService = class {
2430
2507
  * @returns the tab view.
2431
2508
  */
2432
2509
  async tabFor(sessionId, tabId) {
2510
+ return await this.runWithSession(async () => await this.doTabFor(sessionId, tabId));
2511
+ }
2512
+ async doTabFor(sessionId, tabId) {
2433
2513
  const tabs = await this.requireTabs();
2434
2514
  const tab = await this.resolveTabFor(tabs, sessionId, tabId);
2435
2515
  tabs.touch(tab.id);
@@ -2488,6 +2568,9 @@ var BrowserViewService = class {
2488
2568
  * @returns the tab view.
2489
2569
  */
2490
2570
  async ensureTab(sessionId) {
2571
+ return await this.runWithSession(async () => await this.doEnsureTab(sessionId));
2572
+ }
2573
+ async doEnsureTab(sessionId) {
2491
2574
  const tabs = await this.requireTabs();
2492
2575
  if (sessionId !== void 0) {
2493
2576
  const bound = this.bindings.get(sessionId);
@@ -2543,17 +2626,19 @@ var BrowserViewService = class {
2543
2626
  * @returns the action outcome plus the resulting tab view.
2544
2627
  */
2545
2628
  async navigate(sessionId, url, tabId, options = {}) {
2546
- const tab = options.newTab === true ? await this.openTab(sessionId) : await this.tabFor(sessionId, tabId);
2547
- try {
2548
- const outcome = await navigateTo(this.scope(), tab.id, url);
2549
- await this.topUpAuthTicket(tab.id, url);
2550
- return {
2551
- outcome: this.trace("navigate", outcome),
2552
- tab: this.refreshTab(tab.id)
2553
- };
2554
- } finally {
2555
- this.authTopUpSpent.delete(tab.id);
2556
- }
2629
+ return await this.runWithSession(async () => {
2630
+ const tab = options.newTab === true ? await this.openTab(sessionId) : await this.doTabFor(sessionId, tabId);
2631
+ try {
2632
+ const outcome = await navigateTo(this.scope(), tab.id, url);
2633
+ await this.topUpAuthTicket(tab.id, url);
2634
+ return {
2635
+ outcome: this.trace("navigate", outcome),
2636
+ tab: this.refreshTab(tab.id)
2637
+ };
2638
+ } finally {
2639
+ this.authTopUpSpent.delete(tab.id);
2640
+ }
2641
+ });
2557
2642
  }
2558
2643
  /**
2559
2644
  * Give a loopback navigation that landed on DSH's own authentication page
@@ -2622,9 +2707,11 @@ var BrowserViewService = class {
2622
2707
  * @returns the recorded outcome.
2623
2708
  */
2624
2709
  async click(sessionId, target, tabId) {
2625
- const tab = await this.tabFor(sessionId, tabId);
2626
- const outcome = await clickElement(this.scope(), tab.id, target);
2627
- return this.trace("click", outcome);
2710
+ return await this.runWithSession(async () => {
2711
+ const tab = await this.doTabFor(sessionId, tabId);
2712
+ const outcome = await clickElement(this.scope(), tab.id, target);
2713
+ return this.trace("click", outcome);
2714
+ });
2628
2715
  }
2629
2716
  /**
2630
2717
  * Type into a tab and trace the action.
@@ -2635,9 +2722,11 @@ var BrowserViewService = class {
2635
2722
  * @returns the recorded outcome.
2636
2723
  */
2637
2724
  async type(sessionId, text, target = {}, tabId) {
2638
- const tab = await this.tabFor(sessionId, tabId);
2639
- const outcome = await typeText(this.scope(), tab.id, text, target);
2640
- return this.trace("type", outcome);
2725
+ return await this.runWithSession(async () => {
2726
+ const tab = await this.doTabFor(sessionId, tabId);
2727
+ const outcome = await typeText(this.scope(), tab.id, text, target);
2728
+ return this.trace("type", outcome);
2729
+ });
2641
2730
  }
2642
2731
  /**
2643
2732
  * Press one key and trace the action.
@@ -2647,9 +2736,11 @@ var BrowserViewService = class {
2647
2736
  * @returns the recorded outcome.
2648
2737
  */
2649
2738
  async press(sessionId, key, tabId) {
2650
- const tab = await this.tabFor(sessionId, tabId);
2651
- const outcome = await pressKey(this.scope(), tab.id, key);
2652
- return this.trace("press", outcome);
2739
+ return await this.runWithSession(async () => {
2740
+ const tab = await this.doTabFor(sessionId, tabId);
2741
+ const outcome = await pressKey(this.scope(), tab.id, key);
2742
+ return this.trace("press", outcome);
2743
+ });
2653
2744
  }
2654
2745
  /**
2655
2746
  * Scroll a tab and trace the action.
@@ -2659,9 +2750,11 @@ var BrowserViewService = class {
2659
2750
  * @returns the recorded outcome.
2660
2751
  */
2661
2752
  async scroll(sessionId, delta, tabId) {
2662
- const tab = await this.tabFor(sessionId, tabId);
2663
- const outcome = await scrollBy(this.scope(), tab.id, delta);
2664
- return this.trace("scroll", outcome);
2753
+ return await this.runWithSession(async () => {
2754
+ const tab = await this.doTabFor(sessionId, tabId);
2755
+ const outcome = await scrollBy(this.scope(), tab.id, delta);
2756
+ return this.trace("scroll", outcome);
2757
+ });
2665
2758
  }
2666
2759
  /**
2667
2760
  * Walk the tab's DOM and remember the ref map for later clicks.
@@ -2670,14 +2763,16 @@ var BrowserViewService = class {
2670
2763
  * @returns the snapshot the model sees.
2671
2764
  */
2672
2765
  async snapshot(sessionId, tabId) {
2673
- const tab = await this.tabFor(sessionId, tabId);
2674
- const tabs = await this.requireTabs();
2675
- const result = await buildSnapshot(this.transport(), tab.id, tabs.sessionOf(tab.id), {
2676
- url: tab.url,
2677
- title: tab.title
2766
+ return await this.runWithSession(async () => {
2767
+ const tab = await this.doTabFor(sessionId, tabId);
2768
+ const tabs = this.scope().tabs;
2769
+ const result = await buildSnapshot(this.transport(), tab.id, tabs.sessionOf(tab.id), {
2770
+ url: tab.url,
2771
+ title: tab.title
2772
+ });
2773
+ tabs.setSnapshotRefs(tab.id, result.refs);
2774
+ return result.snapshot;
2678
2775
  });
2679
- tabs.setSnapshotRefs(tab.id, result.refs);
2680
- return result.snapshot;
2681
2776
  }
2682
2777
  /**
2683
2778
  * Capture one image of the tab.
@@ -2697,20 +2792,22 @@ var BrowserViewService = class {
2697
2792
  * @throws when the request cannot be honoured by this viewport or the size limits.
2698
2793
  */
2699
2794
  async screenshot(sessionId, tabId, request = {}) {
2700
- const tab = await this.tabFor(sessionId, tabId);
2701
- const tabs = await this.requireTabs();
2702
- const plan = planScreenshot(await tabs.viewportOf(tab.id), request, this.jpegQuality);
2703
- const data = await tabs.captureScreenshot(tab.id, plan.params);
2704
- const current = tabs.list().find((candidate) => candidate.id === tab.id) ?? tab;
2705
- return {
2706
- tabId: current.id,
2707
- url: current.url,
2708
- title: current.title,
2709
- data,
2710
- mediaType: plan.mediaType,
2711
- width: plan.width,
2712
- height: plan.height
2713
- };
2795
+ return await this.runWithSession(async () => {
2796
+ const tab = await this.doTabFor(sessionId, tabId);
2797
+ const tabs = this.scope().tabs;
2798
+ const plan = planScreenshot(await tabs.viewportOf(tab.id), request, this.jpegQuality);
2799
+ const data = await tabs.captureScreenshot(tab.id, plan.params);
2800
+ const current = tabs.list().find((candidate) => candidate.id === tab.id) ?? tab;
2801
+ return {
2802
+ tabId: current.id,
2803
+ url: current.url,
2804
+ title: current.title,
2805
+ data,
2806
+ mediaType: plan.mediaType,
2807
+ width: plan.width,
2808
+ height: plan.height
2809
+ };
2810
+ });
2714
2811
  }
2715
2812
  /**
2716
2813
  * Console entries of one tab, newest last.
@@ -2745,10 +2842,21 @@ var BrowserViewService = class {
2745
2842
  /** Open tabs, for `browser_tabs`. */
2746
2843
  async listTabs() {
2747
2844
  if (this.session === void 0 || this.session.transport.closed) {
2748
- if (this.resolveConfig().mode !== "cdp") return {
2749
- tabs: [],
2750
- activeTabId: null
2751
- };
2845
+ if (this.resolveConfig().mode !== "cdp") {
2846
+ if (this.session !== void 0 && this.session.transport.closed) {
2847
+ const stale = this.forgetSession();
2848
+ if (stale !== void 0) stale.dispose().catch(() => void 0);
2849
+ this.broadcast({
2850
+ v: 1,
2851
+ kind: "state",
2852
+ state: this.state()
2853
+ });
2854
+ }
2855
+ return {
2856
+ tabs: [],
2857
+ activeTabId: null
2858
+ };
2859
+ }
2752
2860
  await this.requireSession();
2753
2861
  }
2754
2862
  const session = this.session;
@@ -2884,11 +2992,29 @@ var BrowserViewService = class {
2884
2992
  if (this.sinks.size > 0) this.startStreaming().catch(() => void 0);
2885
2993
  return session;
2886
2994
  }
2887
- /** Start the browser once, recording failures for the panel. */
2995
+ /**
2996
+ * Run one operation against a live session; if a reused transport closes
2997
+ * mid-command, recycle the dead session and replay once so transient socket
2998
+ * drops self-heal in-flight (#2051).
2999
+ */
3000
+ async runWithSession(operation) {
3001
+ const session = await this.requireSession();
3002
+ try {
3003
+ return await operation();
3004
+ } catch (error) {
3005
+ if (!session.transport.closed || this.disposed) throw error;
3006
+ await this.requireSession();
3007
+ return await operation();
3008
+ }
3009
+ }
3010
+ /**
3011
+ * Start the browser once (retrying isolated launches once on transient
3012
+ * startup errors), recording persistent failures for the panel.
3013
+ */
2888
3014
  async startSession() {
2889
3015
  const generation = this.generation;
2890
3016
  const config = this.resolveConfig();
2891
- try {
3017
+ const attemptOpen = async () => {
2892
3018
  const session = await this.openSession({
2893
3019
  ...config,
2894
3020
  jpegQuality: this.jpegQuality,
@@ -2912,6 +3038,17 @@ var BrowserViewService = class {
2912
3038
  await session.dispose();
2913
3039
  throw new Error("the browser configuration changed while the session was opening");
2914
3040
  }
3041
+ return session;
3042
+ };
3043
+ try {
3044
+ let session;
3045
+ try {
3046
+ session = await attemptOpen();
3047
+ } catch (firstError) {
3048
+ const message = firstError instanceof Error ? firstError.message : String(firstError);
3049
+ if (!(config.mode === "isolated" && generation === this.generation && !this.disposed && !/No Chrome binary found/i.test(message))) throw firstError;
3050
+ session = await attemptOpen();
3051
+ }
2915
3052
  this.session = session;
2916
3053
  this.lastError = void 0;
2917
3054
  this.broadcast({
@@ -3214,7 +3351,7 @@ function writeJson(res, status, body) {
3214
3351
  res.end(text);
3215
3352
  }
3216
3353
  //#endregion
3217
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
3354
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
3218
3355
  /** The one Remote failure class shared by owners, the Gateway, and consumers. */
3219
3356
  /**
3220
3357
  * One Remote call failure: a real Error carrying its stable code and typed
@@ -3396,7 +3533,7 @@ function validateName(subject, value) {
3396
3533
  if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
3397
3534
  }
3398
3535
  //#endregion
3399
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
3536
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
3400
3537
  /**
3401
3538
  * Lazily scanned view of one JSON object's top-level fields, built from text
3402
3539
  * that may still be streaming or from an already parsed object. Nothing is
@@ -5102,11 +5239,11 @@ defineMethod("transform", [
5102
5239
  "preserve"
5103
5240
  ], ({ inner }, isInner) => inner.toString(isInner));
5104
5241
  //#endregion
5105
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
5242
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
5106
5243
  /** Largest delay Node schedules without clamping it to one millisecond. */
5107
5244
  const MAX_TIMER_DELAY_MS = 2147483647;
5108
5245
  //#endregion
5109
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-error/lib/index.js
5246
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-error/lib/index.js
5110
5247
  /**
5111
5248
  * Harness error base with a stable machine-routable code and chained cause.
5112
5249
  * Package errors extend it so tool results and replay can retain failure class.
@@ -5128,7 +5265,7 @@ var HarnessError = class extends Error {
5128
5265
  }
5129
5266
  };
5130
5267
  //#endregion
5131
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-error@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_/node_modules/@deepseek-ai/dsh-llm/lib/index.js
5268
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_/node_modules/@deepseek-ai/dsh-llm/lib/index.js
5132
5269
  /**
5133
5270
  * Detach and deep-freeze a message whose identity already exists.
5134
5271
  * @param message - complete message, including its stable identity.
@@ -6397,7 +6534,7 @@ function detachDirectoryEntry(entry) {
6397
6534
  };
6398
6535
  }
6399
6536
  //#endregion
6400
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-agent@0.2._d54d331d737d4347e4d7b0f13cb396ba/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
6537
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
6401
6538
  /** The selected provider is missing or unloaded; another provider must not take its calls. */
6402
6539
  var ToolExecutorUnavailableError = class extends HarnessError {
6403
6540
  constructor() {
@@ -6934,7 +7071,7 @@ var ToolActivationError = class extends HarnessError {
6934
7071
  }
6935
7072
  };
6936
7073
  //#endregion
6937
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-scope/lib/index.js
7074
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-scope/lib/index.js
6938
7075
  /**
6939
7076
  * Shared insertion-ordered storage and effect ownership for scope-aware registries.
6940
7077
  *
@@ -7187,7 +7324,7 @@ function scopeOf(ctx) {
7187
7324
  return ctx[kScope];
7188
7325
  }
7189
7326
  //#endregion
7190
- //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-agent@0.2._d54d331d737d4347e4d7b0f13cb396ba/node_modules/@deepseek-ai/dsh-tools/lib/index.js
7327
+ //#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/index.js
7191
7328
  /** Unified JSON-value schema DSL, inference, compilation, and tool definition helpers. @module dsh-tools/schema */
7192
7329
  const ANNOTATION_KEYS = [
7193
7330
  "description",
@@ -8556,6 +8693,44 @@ function effectiveConfig(config) {
8556
8693
  const name = "browser-view";
8557
8694
  /** Services required before the routes and the tools can mount. */
8558
8695
  const inject = ["webServer", "tools"];
8696
+ function readWebServer(ctx) {
8697
+ if (ctx.webServer !== void 0) return ctx.webServer;
8698
+ if (typeof ctx.get !== "function") return void 0;
8699
+ try {
8700
+ return ctx.get("webServer");
8701
+ } catch {
8702
+ return;
8703
+ }
8704
+ }
8705
+ /**
8706
+ * Resolve the host's authenticated entry URL for `url` across SDK cohorts:
8707
+ * legacy hosts expose `connection.authenticatedUrl(url)`, while peer-auth
8708
+ * hosts collect entry URLs via `ctx.emit(webServer, 'webserver/entry-url', url, entries)`.
8709
+ */
8710
+ function resolveAuthenticatedUrl(ctx, url) {
8711
+ let connection;
8712
+ if (typeof ctx.get === "function") try {
8713
+ connection = ctx.get("connection");
8714
+ } catch {
8715
+ connection = void 0;
8716
+ }
8717
+ if (connection !== void 0 && typeof connection.authenticatedUrl === "function") try {
8718
+ return connection.authenticatedUrl(url);
8719
+ } catch {
8720
+ return;
8721
+ }
8722
+ const webServer = readWebServer(ctx);
8723
+ if (webServer === void 0 || typeof ctx.emit !== "function") return void 0;
8724
+ const entries = [];
8725
+ try {
8726
+ ctx.emit(webServer, "webserver/entry-url", url, entries);
8727
+ } catch {
8728
+ return;
8729
+ }
8730
+ const preferred = entries.find((entry) => entry.open === true && typeof entry.url === "string" && entry.url.length > 0);
8731
+ if (preferred?.url !== void 0) return preferred.url;
8732
+ return entries.find((entry) => typeof entry.url === "string" && entry.url.length > 0)?.url;
8733
+ }
8559
8734
  /**
8560
8735
  * Mount the routes, the tools, and the browser lifetime.
8561
8736
  * @param ctx - host plugin context carrying webServer and tools.
@@ -8570,15 +8745,7 @@ function apply(ctx, config) {
8570
8745
  } : { mode: "isolated" };
8571
8746
  },
8572
8747
  idleCloseDays: () => effectiveConfig(config).idleCloseDays,
8573
- authenticatedUrl: (url) => {
8574
- const connection = ctx.get("connection");
8575
- if (connection === void 0 || typeof connection.authenticatedUrl !== "function") return void 0;
8576
- try {
8577
- return connection.authenticatedUrl(url);
8578
- } catch {
8579
- return;
8580
- }
8581
- }
8748
+ authenticatedUrl: (url) => resolveAuthenticatedUrl(ctx, url)
8582
8749
  });
8583
8750
  const saveImage = async (input) => {
8584
8751
  const attachments = ctx.get("attachments");
@@ -8617,4 +8784,4 @@ function apply(ctx, config) {
8617
8784
  }, "browser-view: browser");
8618
8785
  }
8619
8786
  //#endregion
8620
- export { Config, apply, inject, name };
8787
+ export { Config, apply, inject, name, resolveAuthenticatedUrl };
@@ -180,6 +180,11 @@ export declare class ChromeProcess {
180
180
  get info(): Readonly<ChromeHandle>;
181
181
  /** Whether {@link dispose} already ran. */
182
182
  get isDisposed(): boolean;
183
+ /**
184
+ * Subscribe to child-process exit so attached transports mark themselves
185
+ * closed without waiting for idle WebSocket teardown (#2051).
186
+ */
187
+ onExit(listener: () => void): () => void;
183
188
  /**
184
189
  * What the disposal achieved, once it ran. A caller that needs to know
185
190
  * whether a browser survived the shutdown reads this instead of assuming.
@@ -195,7 +200,8 @@ export declare class ChromeProcess {
195
200
  }
196
201
  /**
197
202
  * Delete the profile directory this launch created, without ever following a
198
- * link out of it.
203
+ * link out of it. Retries briefly on transient file locks left behind while
204
+ * browser subprocesses release handles (#2051).
199
205
  *
200
206
  * `fs.rm({ recursive: true })` is banned repository-wide: recursion walks a
201
207
  * junction or symlink happily and deletes whatever it points at, so a temp
@@ -205,5 +211,6 @@ export declare class ChromeProcess {
205
211
  * Failures are swallowed: a leftover file in the OS temp directory is a lesser
206
212
  * problem than failing the dispose path that the caller is awaiting.
207
213
  * @param dir - absolute path of the profile directory created by this launch.
214
+ * @param retryDelaysMs - backoff delays after locked removals.
208
215
  */
209
- export declare function removeTempProfile(dir: string): Promise<void>;
216
+ export declare function removeTempProfile(dir: string, retryDelaysMs?: readonly number[]): Promise<void>;
@@ -177,7 +177,7 @@ export declare class BrowserViewService implements BrowserViewBackend {
177
177
  * @param options - quality, viewport, clock, and the browser factory seam.
178
178
  */
179
179
  constructor(options?: BrowserViewServiceOptions);
180
- /** Whether a browser is currently running. */
180
+ /** Whether a browser is currently running with an open transport. */
181
181
  get running(): boolean;
182
182
  /** The current panel-facing state; safe to call before anything started. */
183
183
  state(): BrowserPanelState;
@@ -252,6 +252,7 @@ export declare class BrowserViewService implements BrowserViewBackend {
252
252
  * @returns the tab view.
253
253
  */
254
254
  tabFor(sessionId: string | undefined, tabId?: string): Promise<BrowserTabView>;
255
+ private doTabFor;
255
256
  /**
256
257
  * Apply {@link tabFor}'s resolution order against an already open manager.
257
258
  * @param tabs - the live tab manager.
@@ -273,6 +274,7 @@ export declare class BrowserViewService implements BrowserViewBackend {
273
274
  * @returns the tab view.
274
275
  */
275
276
  ensureTab(sessionId?: string): Promise<BrowserTabView>;
277
+ private doEnsureTab;
276
278
  /** Create a tab, bind it, and make it the one the panel watches. */
277
279
  private createBoundTab;
278
280
  /**
@@ -470,7 +472,16 @@ export declare class BrowserViewService implements BrowserViewBackend {
470
472
  * @returns the live session.
471
473
  */
472
474
  private replaceSession;
473
- /** Start the browser once, recording failures for the panel. */
475
+ /**
476
+ * Run one operation against a live session; if a reused transport closes
477
+ * mid-command, recycle the dead session and replay once so transient socket
478
+ * drops self-heal in-flight (#2051).
479
+ */
480
+ private runWithSession;
481
+ /**
482
+ * Start the browser once (retrying isolated launches once on transient
483
+ * startup errors), recording persistent failures for the panel.
484
+ */
474
485
  private startSession;
475
486
  /** Start the screencast for the tab the panel watches. */
476
487
  private startStreaming;
@@ -33,6 +33,22 @@ declare module '@deepseek-ai/cordis' {
33
33
  export declare const name = "browser-view";
34
34
  /** Services required before the routes and the tools can mount. */
35
35
  export declare const inject: string[];
36
+ interface EntryUrlCandidate {
37
+ readonly url?: string;
38
+ readonly open?: boolean;
39
+ }
40
+ /** Minimal Cordis context surface needed to resolve an authenticated DSH URL. */
41
+ export interface AuthenticatedUrlContext {
42
+ get?(name: string): unknown;
43
+ readonly webServer?: unknown;
44
+ emit?(subject: unknown, event: string, baseUrl: string, entries: EntryUrlCandidate[]): unknown;
45
+ }
46
+ /**
47
+ * Resolve the host's authenticated entry URL for `url` across SDK cohorts:
48
+ * legacy hosts expose `connection.authenticatedUrl(url)`, while peer-auth
49
+ * hosts collect entry URLs via `ctx.emit(webServer, 'webserver/entry-url', url, entries)`.
50
+ */
51
+ export declare function resolveAuthenticatedUrl(ctx: AuthenticatedUrlContext, url: string): string | undefined;
36
52
  /**
37
53
  * Mount the routes, the tools, and the browser lifetime.
38
54
  * @param ctx - host plugin context carrying webServer and tools.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-client-ui-browser-view",
3
3
  "description": "Right-docked live browser view for the DSH Web GUI: a CDP-driven Chromium the agent operates, a screencast panel the user watches, and screenshots attached to every tool result.",
4
- "version": "0.4.18",
4
+ "version": "0.4.19",
5
5
  "icon": "icon.svg",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dsh": {
24
24
  "engines": {
25
- "dsh": ">=0.2.2-rc.2"
25
+ "dsh": ">=0.2.2-rc.3"
26
26
  },
27
27
  "bundle": {
28
28
  "patch": "./cordis.patch.yml"
@@ -45,25 +45,25 @@
45
45
  "ws": "^8.18.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@deepseek-ai/dsh": ">=0.2.2-rc.2",
48
+ "@deepseek-ai/dsh": ">=0.2.2-rc.3",
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@deepseek-ai/cordis": "^4.1.0",
54
- "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.2",
55
- "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.2",
56
- "@deepseek-ai/dsh-client-store": "0.2.2-rc.2",
57
- "@deepseek-ai/dsh-client-ui-layout": "^0.2.2-rc.2",
58
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.2",
59
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.2",
60
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.2",
61
- "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.2",
62
- "@deepseek-ai/dsh-client-ui-sidebar-right": "^0.2.2-rc.2",
63
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.2",
64
- "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.2",
65
- "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.2",
66
- "@deepseek-ai/dsh-tools": "^0.2.2-rc.2",
54
+ "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.3",
55
+ "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.3",
56
+ "@deepseek-ai/dsh-client-store": "0.2.2-rc.3",
57
+ "@deepseek-ai/dsh-client-ui-layout": "^0.2.2-rc.3",
58
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.3",
59
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.3",
60
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.3",
61
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.3",
62
+ "@deepseek-ai/dsh-client-ui-sidebar-right": "^0.2.2-rc.3",
63
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.3",
64
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.3",
65
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.3",
66
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.3",
67
67
  "@deepseek-ai/schemastery": "^3.19.0",
68
68
  "@types/node": "^22.20.0",
69
69
  "@types/react": "~18.3.1",