@linxin666/dsh-client-ui-browser-view 0.4.15 → 0.4.17
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 +2 -2
- package/README.md +9 -5
- package/README.zh.md +9 -5
- package/lib/client.js +126 -31
- package/lib/client.js.map +1 -1
- package/lib/index.js +316 -71
- package/lib/types/client/BrowserViewSettingsCard.d.ts +2 -0
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/core/cdp.d.ts +29 -5
- package/lib/types/core/tabs.d.ts +24 -0
- package/lib/types/host/config.d.ts +3 -0
- package/lib/types/host/service.d.ts +86 -2
- package/package.json +16 -16
|
@@ -11,11 +11,13 @@ import { type CardActions, type CardShell, type FieldState } from './settings-fo
|
|
|
11
11
|
export interface BrowserViewSettings {
|
|
12
12
|
realBrowserEnabled?: boolean;
|
|
13
13
|
cdpEndpoint?: string;
|
|
14
|
+
idleCloseDays?: number;
|
|
14
15
|
}
|
|
15
16
|
/** Card projection bound by the renderer. */
|
|
16
17
|
export interface BrowserViewSettingsCardState extends CardShell {
|
|
17
18
|
realBrowserEnabled: FieldState;
|
|
18
19
|
cdpEndpoint: FieldState;
|
|
20
|
+
idleCloseDays: FieldState;
|
|
19
21
|
}
|
|
20
22
|
/** Registration-side snapshot and write actions. */
|
|
21
23
|
export interface BrowserViewSettingsCardFace extends CardActions {
|
|
@@ -37,6 +37,8 @@ export declare const zh: {
|
|
|
37
37
|
'config.realBrowserEnabled.hint': string;
|
|
38
38
|
'config.cdpEndpoint': string;
|
|
39
39
|
'config.cdpEndpoint.hint': string;
|
|
40
|
+
'config.idleCloseDays': string;
|
|
41
|
+
'config.idleCloseDays.hint': string;
|
|
40
42
|
'config.unavailable': string;
|
|
41
43
|
'config.failed': string;
|
|
42
44
|
'settings.title': string;
|
|
@@ -45,6 +47,8 @@ export declare const zh: {
|
|
|
45
47
|
'settings.enabledHint': string;
|
|
46
48
|
'settings.cdpEndpoint': string;
|
|
47
49
|
'settings.cdpEndpointHint': string;
|
|
50
|
+
'settings.idleCloseDays': string;
|
|
51
|
+
'settings.idleCloseDaysHint': string;
|
|
48
52
|
'settings.inherit': string;
|
|
49
53
|
'settings.on': string;
|
|
50
54
|
'settings.off': string;
|
package/lib/types/core/cdp.d.ts
CHANGED
|
@@ -43,19 +43,43 @@ export interface CdpTransport {
|
|
|
43
43
|
* @returns the unsubscribe function.
|
|
44
44
|
*/
|
|
45
45
|
on(method: string, handler: CdpEventListener): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the transport can still carry commands. False once the socket is
|
|
48
|
+
* gone — a peer that closed, a failed write, or {@link close} — because every
|
|
49
|
+
* later command would reject with the same stale reason.
|
|
50
|
+
*/
|
|
51
|
+
readonly closed: boolean;
|
|
46
52
|
/** Drop the socket; every pending round-trip rejects. */
|
|
47
53
|
close(): void;
|
|
48
54
|
}
|
|
49
55
|
/** One protocol event delivery. */
|
|
50
56
|
export type CdpEventListener = (params: Record<string, unknown>, sessionId: string | undefined) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default deadline for opening the DevTools socket. A freshly launched browser
|
|
59
|
+
* answers at once, so this only bounds a wedged endpoint; an external browser
|
|
60
|
+
* is reached over a network path the caller controls and sets its own.
|
|
61
|
+
*/
|
|
62
|
+
export declare const CDP_HANDSHAKE_TIMEOUT_MS = 30000;
|
|
51
63
|
/** Default per-command deadline; long enough for a navigation, short enough to fail a wedged tab. */
|
|
52
64
|
export declare const CDP_COMMAND_TIMEOUT_MS = 30000;
|
|
65
|
+
/**
|
|
66
|
+
* Deadlines for one connection. They bound different phases and are therefore
|
|
67
|
+
* separate knobs: opening the socket is bounded once, while every command gets
|
|
68
|
+
* the command budget, so a caller may wait seconds for a browser to answer
|
|
69
|
+
* without shortening the time a navigation is allowed to take.
|
|
70
|
+
*/
|
|
71
|
+
export interface CdpConnectOptions {
|
|
72
|
+
/** Deadline for the WebSocket handshake. @default CDP_HANDSHAKE_TIMEOUT_MS */
|
|
73
|
+
handshakeTimeoutMs?: number;
|
|
74
|
+
/** Deadline for each protocol command. @default CDP_COMMAND_TIMEOUT_MS */
|
|
75
|
+
commandTimeoutMs?: number;
|
|
76
|
+
}
|
|
53
77
|
/**
|
|
54
78
|
* A single WebSocket carrying browser-level and flat-session protocol traffic.
|
|
55
79
|
*/
|
|
56
80
|
export declare class CdpClient implements CdpTransport {
|
|
57
81
|
private readonly socket;
|
|
58
|
-
private readonly
|
|
82
|
+
private readonly commandTimeoutMs;
|
|
59
83
|
private readonly pending;
|
|
60
84
|
private readonly listeners;
|
|
61
85
|
private nextId;
|
|
@@ -64,13 +88,13 @@ export declare class CdpClient implements CdpTransport {
|
|
|
64
88
|
/**
|
|
65
89
|
* Open a client against an already-discovered DevTools endpoint.
|
|
66
90
|
* @param url - `webSocketDebuggerUrl` from `/json/version`.
|
|
67
|
-
* @param options - command
|
|
91
|
+
* @param options - handshake and per-command deadlines, independently.
|
|
68
92
|
* @returns a connected client.
|
|
69
93
|
* @throws CdpError when the socket cannot be established in time.
|
|
70
94
|
*/
|
|
71
|
-
static connect(url: string, options?:
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
static connect(url: string, options?: CdpConnectOptions): Promise<CdpClient>;
|
|
96
|
+
/** Whether the socket is gone and every later command will be refused. */
|
|
97
|
+
get closed(): boolean;
|
|
74
98
|
/**
|
|
75
99
|
* Address one protocol command.
|
|
76
100
|
* @param method - CDP method.
|
package/lib/types/core/tabs.d.ts
CHANGED
|
@@ -72,6 +72,11 @@ interface TabRecord {
|
|
|
72
72
|
loaderId: string | undefined;
|
|
73
73
|
ownerSessionId: string | undefined;
|
|
74
74
|
origin: 'created' | 'adopted';
|
|
75
|
+
/**
|
|
76
|
+
* Clock reading of the last tool call that worked on this tab. Seeded at
|
|
77
|
+
* attach, so a page DSH just opened counts as active; nothing else writes it.
|
|
78
|
+
*/
|
|
79
|
+
lastActiveAt: number;
|
|
75
80
|
console: BrowserConsoleEntry[];
|
|
76
81
|
network: BrowserNetworkEntry[];
|
|
77
82
|
/** Pending requests keyed by network request id, so response frames update in place. */
|
|
@@ -127,6 +132,25 @@ export declare class TabManager {
|
|
|
127
132
|
* @returns the tab record.
|
|
128
133
|
*/
|
|
129
134
|
tab(tabId: string): BrowserTabView;
|
|
135
|
+
/**
|
|
136
|
+
* Record that a tool call just worked on this tab.
|
|
137
|
+
*
|
|
138
|
+
* Only the host's own tool paths call this. A panel that keeps watching a
|
|
139
|
+
* page is not activity: a page nobody drives must still age out, or a viewer
|
|
140
|
+
* left open on one tab keeps the cleanup from ever running.
|
|
141
|
+
* @param tabId - the tab the call used; an id that closed meanwhile is ignored.
|
|
142
|
+
*/
|
|
143
|
+
touch(tabId: string): void;
|
|
144
|
+
/**
|
|
145
|
+
* Tabs DSH opened itself that no tool call has touched within `maxAgeMs`.
|
|
146
|
+
*
|
|
147
|
+
* Adopted real-browser pages are never candidates: they belong to the person
|
|
148
|
+
* using that browser, and the real-browser contract closes them only when a
|
|
149
|
+
* caller names the tab explicitly.
|
|
150
|
+
* @param maxAgeMs - idle window in milliseconds; zero or less selects nothing.
|
|
151
|
+
* @returns ids in creation order.
|
|
152
|
+
*/
|
|
153
|
+
idleCandidates(maxAgeMs: number): string[];
|
|
130
154
|
/** Internal record access for the layers that need the CDP session. */
|
|
131
155
|
sessionOf(tabId: string): string;
|
|
132
156
|
/**
|
|
@@ -9,16 +9,19 @@ import z from '@deepseek-ai/schemastery';
|
|
|
9
9
|
export interface Config {
|
|
10
10
|
realBrowserEnabled: Volatile<boolean>;
|
|
11
11
|
cdpEndpoint: Volatile<string>;
|
|
12
|
+
idleCloseDays: Volatile<number>;
|
|
12
13
|
}
|
|
13
14
|
/** Profile-patch shape before the schema adds defaults and live references. */
|
|
14
15
|
export interface ConfigInput {
|
|
15
16
|
realBrowserEnabled?: boolean;
|
|
16
17
|
cdpEndpoint?: string;
|
|
18
|
+
idleCloseDays?: number;
|
|
17
19
|
}
|
|
18
20
|
/** Values after defaults and live references have been resolved. */
|
|
19
21
|
export interface ResolvedConfig {
|
|
20
22
|
realBrowserEnabled: boolean;
|
|
21
23
|
cdpEndpoint: string;
|
|
24
|
+
idleCloseDays: number;
|
|
22
25
|
}
|
|
23
26
|
/** Settings schema exported through the host loader entry. */
|
|
24
27
|
export declare const Config: z<ConfigInput, Config>;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module @linxin666/dsh-client-ui-browser-view/host/service
|
|
21
21
|
*/
|
|
22
|
-
import type { CdpTransport } from '../core/cdp.ts';
|
|
22
|
+
import type { CdpConnectOptions, CdpTransport } from '../core/cdp.ts';
|
|
23
23
|
import { ChromeProcess } from '../core/chrome.ts';
|
|
24
24
|
import { TabManager, type ScreencastFrame } from '../core/tabs.ts';
|
|
25
25
|
import { type ScreenshotPlan, type ScreenshotRequest } from '../core/screenshot.ts';
|
|
@@ -97,9 +97,42 @@ export interface BrowserViewServiceOptions {
|
|
|
97
97
|
authenticatedUrl?: (url: string) => string | undefined;
|
|
98
98
|
/** Live browser source; called for state and every new connection. */
|
|
99
99
|
resolveConfig?: () => BrowserConnectionConfig;
|
|
100
|
+
/**
|
|
101
|
+
* Idle window in days for the tab sweep, read per sweep so a settings edit
|
|
102
|
+
* applies on the next one. Zero or less disables the sweep. @default () => 0
|
|
103
|
+
*/
|
|
104
|
+
idleCloseDays?: () => number;
|
|
105
|
+
/** How often the idle sweep runs; zero disables it. @default IDLE_SWEEP_INTERVAL_MS */
|
|
106
|
+
sweepIntervalMs?: number;
|
|
100
107
|
/** Browser factory, replaced by tests. */
|
|
101
108
|
openSession?: (options: OpenSessionOptions) => Promise<BrowserSession>;
|
|
102
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Handshake deadline for an external browser. Its debugger port is already
|
|
112
|
+
* listening, so an endpoint that does not complete the upgrade within this
|
|
113
|
+
* window is wedged; the per-command budget is a separate setting and is left at
|
|
114
|
+
* `CDP_COMMAND_TIMEOUT_MS`, exactly as in the isolated mode.
|
|
115
|
+
*/
|
|
116
|
+
export declare const REAL_BROWSER_HANDSHAKE_TIMEOUT_MS = 5000;
|
|
117
|
+
/**
|
|
118
|
+
* How often the service looks for tabs that went idle.
|
|
119
|
+
*
|
|
120
|
+
* Ten minutes is a compromise between two costs that both land on the host:
|
|
121
|
+
* a shorter period wakes the process for nothing on a window measured in days,
|
|
122
|
+
* and a longer one leaves a page running well past its window.
|
|
123
|
+
*/
|
|
124
|
+
export declare const IDLE_SWEEP_INTERVAL_MS: number;
|
|
125
|
+
/**
|
|
126
|
+
* Seams the external session factory resolves when it connects. The defaults
|
|
127
|
+
* are the production transport; a test injects one to observe what a
|
|
128
|
+
* real-browser attach asks for without starting a browser.
|
|
129
|
+
*/
|
|
130
|
+
export interface ExternalSessionSeams {
|
|
131
|
+
/** Open the DevTools transport. @default CdpClient.connect */
|
|
132
|
+
connect?: (url: string, timeouts: CdpConnectOptions) => Promise<CdpTransport>;
|
|
133
|
+
}
|
|
134
|
+
/** Connect to an existing real browser without owning its process or tabs. */
|
|
135
|
+
export declare function openExternalSession(options: OpenSessionOptions, seams?: ExternalSessionSeams): Promise<BrowserSession>;
|
|
103
136
|
/**
|
|
104
137
|
* The plugin's single browser service.
|
|
105
138
|
*/
|
|
@@ -110,6 +143,9 @@ export declare class BrowserViewService implements BrowserViewBackend {
|
|
|
110
143
|
private readonly openSession;
|
|
111
144
|
private readonly resolveConfig;
|
|
112
145
|
private readonly authenticatedUrl;
|
|
146
|
+
private readonly idleCloseDays;
|
|
147
|
+
private readonly sweepIntervalMs;
|
|
148
|
+
private idleTimer;
|
|
113
149
|
private readonly sinks;
|
|
114
150
|
private readonly bindings;
|
|
115
151
|
/**
|
|
@@ -183,6 +219,18 @@ export declare class BrowserViewService implements BrowserViewBackend {
|
|
|
183
219
|
* @returns ids of the tabs actually closed, in close order.
|
|
184
220
|
*/
|
|
185
221
|
closeOwnTabs(sessionId: string | undefined, tabId?: string): Promise<string[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Close the tabs no browser tool has touched for the configured idle window.
|
|
224
|
+
*
|
|
225
|
+
* Scope is what the real-browser contract allows: only tabs DSH created are
|
|
226
|
+
* candidates, and a page adopted from the person's own browser is never closed
|
|
227
|
+
* by a timer — that contract keeps adopted pages closable only through an
|
|
228
|
+
* explicit `tab_id`. The window is read per sweep, so a settings edit applies
|
|
229
|
+
* to the next one, and a host with no browser running closes nothing and
|
|
230
|
+
* starts none: cleanup must never cost a process.
|
|
231
|
+
* @returns ids of the tabs actually closed, in close order.
|
|
232
|
+
*/
|
|
233
|
+
sweepIdle(): Promise<string[]>;
|
|
186
234
|
/**
|
|
187
235
|
* Resolve the tab a tool call from `sessionId` should act on.
|
|
188
236
|
*
|
|
@@ -204,6 +252,14 @@ export declare class BrowserViewService implements BrowserViewBackend {
|
|
|
204
252
|
* @returns the tab view.
|
|
205
253
|
*/
|
|
206
254
|
tabFor(sessionId: string | undefined, tabId?: string): Promise<BrowserTabView>;
|
|
255
|
+
/**
|
|
256
|
+
* Apply {@link tabFor}'s resolution order against an already open manager.
|
|
257
|
+
* @param tabs - the live tab manager.
|
|
258
|
+
* @param sessionId - calling agent session, when the host provides one.
|
|
259
|
+
* @param tabId - explicit tab from the tool arguments.
|
|
260
|
+
* @returns the tab the call should act on.
|
|
261
|
+
*/
|
|
262
|
+
private resolveTabFor;
|
|
207
263
|
/**
|
|
208
264
|
* Whether a tab is bound to some other session.
|
|
209
265
|
* @param tabId - the tab being considered.
|
|
@@ -384,8 +440,36 @@ export declare class BrowserViewService implements BrowserViewBackend {
|
|
|
384
440
|
private transport;
|
|
385
441
|
/** Resolve the live session or start one. */
|
|
386
442
|
private requireTabs;
|
|
387
|
-
/**
|
|
443
|
+
/**
|
|
444
|
+
* Forget everything bound to the current session without disposing it: the
|
|
445
|
+
* per-session tab bindings, the watched tab, the pinned selection and the
|
|
446
|
+
* spent auth tickets all describe a browser that is going away.
|
|
447
|
+
* @returns the session that was dropped, if any.
|
|
448
|
+
*/
|
|
449
|
+
private forgetSession;
|
|
450
|
+
/**
|
|
451
|
+
* Resolve the live session, starting the browser on first use.
|
|
452
|
+
*
|
|
453
|
+
* A session whose transport has closed is dead even though its record still
|
|
454
|
+
* exists: the external browser restarted, crashed, or dropped the socket, and
|
|
455
|
+
* every command would reject with that one stale reason for the rest of the
|
|
456
|
+
* host's life. The next call therefore drops it exactly the way a settings
|
|
457
|
+
* change does and opens a replacement, so the caller recovers instead of
|
|
458
|
+
* needing a reconfigure or a restart. The replacement goes through `opening`,
|
|
459
|
+
* so concurrent callers share one session instead of opening two.
|
|
460
|
+
*/
|
|
388
461
|
private requireSession;
|
|
462
|
+
/**
|
|
463
|
+
* Drop a closed session and open its replacement.
|
|
464
|
+
*
|
|
465
|
+
* The cleanup is the settings-change cleanup: an external browser is only
|
|
466
|
+
* detached, never closed, and its tabs stay open. A teardown that throws is
|
|
467
|
+
* swallowed because the dead session has nothing left to deliver — its
|
|
468
|
+
* failure must not be the reason no replacement starts.
|
|
469
|
+
* @param stale - the dead session, or undefined for an ordinary first start.
|
|
470
|
+
* @returns the live session.
|
|
471
|
+
*/
|
|
472
|
+
private replaceSession;
|
|
389
473
|
/** Start the browser once, recording failures for the panel. */
|
|
390
474
|
private startSession;
|
|
391
475
|
/** Start the screencast for the tab the panel watches. */
|
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.
|
|
4
|
+
"version": "0.4.17",
|
|
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.
|
|
25
|
+
"dsh": ">=0.2.2-rc.2"
|
|
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.
|
|
48
|
+
"@deepseek-ai/dsh": ">=0.2.2-rc.2",
|
|
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.
|
|
55
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.
|
|
56
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-rc.
|
|
57
|
-
"@deepseek-ai/dsh-client-ui-layout": "^0.2.2-rc.
|
|
58
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.
|
|
60
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.
|
|
61
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.
|
|
62
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right": "^0.2.2-rc.
|
|
63
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.
|
|
64
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.
|
|
65
|
-
"@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.
|
|
66
|
-
"@deepseek-ai/dsh-tools": "^0.2.2-rc.
|
|
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",
|
|
67
67
|
"@deepseek-ai/schemastery": "^3.19.0",
|
|
68
68
|
"@types/node": "^22.20.0",
|
|
69
69
|
"@types/react": "~18.3.1",
|