dsh-coding-sidebar 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-coding-sidebar",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "DSH web plugin: a VSCode-like right sidebar (explorer / editor / terminal / git / browser), isolated per conversation session. Exposes the betterSidebar service for other plugins to register sidebar tabs and file viewers. KCoder-maintained fork of DSH-better-sidebar 0.17.2 (bottom panel removed, upstream-decoupled release line).",
5
5
  "type": "module",
6
6
  "repository": {
@@ -16,7 +16,7 @@
16
16
  * address-bar navigations (in-frame link clicks are cross-origin and
17
17
  * invisible — a documented limitation).
18
18
  */
19
- import { useEffect, useState } from 'react'
19
+ import { useEffect, useRef, useState } from 'react'
20
20
  import {
21
21
  IconChevronLeftOutline14,
22
22
  IconChevronRightOutline14,
@@ -81,7 +81,7 @@ export function iframeSandboxFor(url: string | undefined, allowedLoopback: strin
81
81
  }
82
82
 
83
83
  export function BrowserView(props: TabComponentProps) {
84
- const { store, tab } = props
84
+ const { store, tab, ctx } = props
85
85
  // The current address (initialized from the persisted tab.path so a
86
86
  // reload restores the visited page).
87
87
  const [url, setUrl] = useState<string | undefined>(tab.path)
@@ -121,6 +121,32 @@ export function BrowserView(props: TabComponentProps) {
121
121
  return () => { cancelled = true }
122
122
  }, [url])
123
123
 
124
+ // Agent 实况自动切换(2026-09-12):非实况态轮询浏览器宿主的 page
125
+ // target——出现 agent 页面(非 about: 空页)即自动开实况并把浏览器 tab
126
+ // 顶到前台。一次性:首次自动切换后不再抢控制权(用户手动关掉实况
127
+ // 也不会被再次强制打开)。
128
+ const autoRaised = useRef(false)
129
+ useEffect(() => {
130
+ if (live || autoRaised.current) return
131
+ const timer = setInterval(async () => {
132
+ if (autoRaised.current) return
133
+ try {
134
+ const { targets: list } = await api.cdpTargets()
135
+ const agentPages = list.filter((t) => t.url !== '' && !t.url.startsWith('about:'))
136
+ const had = autoRaised.current
137
+ if (agentPages.length > 0 && !had) {
138
+ autoRaised.current = true
139
+ setLive(true)
140
+ try {
141
+ const better = (ctx as unknown as { betterSidebar?: { openTab?: (r: { type: string }) => unknown } }).betterSidebar
142
+ better?.openTab?.({ type: 'browser' })
143
+ } catch { /* 顶起失败:实况仍已在 tab 内容里生效 */ }
144
+ }
145
+ } catch { /* 宿主未起:静默等下次轮询 */ }
146
+ }, 3000)
147
+ return () => { clearInterval(timer) }
148
+ }, [live, ctx])
149
+
124
150
  const persist = (nextUrl: string): void => {
125
151
  let host = nextUrl
126
152
  try { host = new URL(nextUrl).hostname } catch { /* keep the URL as title */ }