@linxin666/dsh-client-ui-browser-view 0.0.0-stage → 0.4.9
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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +77 -2
- package/README.zh.md +78 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +953 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +10555 -0
- package/lib/types/client/guide-icon.d.ts +21 -0
- package/lib/types/client/index.d.ts +51 -0
- package/lib/types/client/live-title.d.ts +39 -0
- package/lib/types/client/locales.d.ts +37 -0
- package/lib/types/client/panel.d.ts +28 -0
- package/lib/types/client/semantic.d.ts +37 -0
- package/lib/types/client/socket.d.ts +113 -0
- package/lib/types/client/tab-title.d.ts +17 -0
- package/lib/types/client/tab-type.d.ts +59 -0
- package/lib/types/core/actions.d.ts +112 -0
- package/lib/types/core/cdp.d.ts +95 -0
- package/lib/types/core/chrome.d.ts +209 -0
- package/lib/types/core/protocol.d.ts +179 -0
- package/lib/types/core/snapshot.d.ts +106 -0
- package/lib/types/core/tabs.d.ts +229 -0
- package/lib/types/host/auth.d.ts +52 -0
- package/lib/types/host/loopback.d.ts +64 -0
- package/lib/types/host/routes.d.ts +73 -0
- package/lib/types/host/service.d.ts +395 -0
- package/lib/types/host/tools.d.ts +64 -0
- package/lib/types/index.d.ts +31 -0
- package/package.json +81 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guide capsule's glyph: this plugin's own mark, not a product artwork.
|
|
3
|
+
*
|
|
4
|
+
* The right sidebar's guide lists one capsule per registered tab type and draws
|
|
5
|
+
* the type's `icon` (a `ComponentType<IconProps>`) at 22px, or 26px beside a
|
|
6
|
+
* description. Drawing locally keeps the plugin free of icon-set coupling: the
|
|
7
|
+
* only thing borrowed is the IconProps shape, as a type, and the glyph itself
|
|
8
|
+
* inherits its colour from the capsule through currentColor.
|
|
9
|
+
*
|
|
10
|
+
* It restates the mark the chip already uses - a browser
|
|
11
|
+
* window with the agent's cursor inside - so a user who has seen one recognises
|
|
12
|
+
* the other. It is deliberately not the shipped browser tab's artwork: this tab
|
|
13
|
+
* is a different implementation and does not pass itself off as that one.
|
|
14
|
+
*/
|
|
15
|
+
import type { IconProps } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
16
|
+
/**
|
|
17
|
+
* Render the guide glyph.
|
|
18
|
+
* @param props - square edge in px (the guide passes 22 or 26) and a layout class.
|
|
19
|
+
* @returns the window-and-cursor mark.
|
|
20
|
+
*/
|
|
21
|
+
export declare function BrowserViewGuideGlyph({ size, className }: IconProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-half entry for the browser-view plugin - runs inside the dsh web GUI.
|
|
3
|
+
*
|
|
4
|
+
* The browser view is a tab in the official right sidebar, beside the
|
|
5
|
+
* conversation, not a page that takes the whole window. It contributes exactly
|
|
6
|
+
* the seats a tab type needs, and only those:
|
|
7
|
+
* - `sidebarRightTabs.register` (stage one): the static tab type - its id, its
|
|
8
|
+
* kind ('browser-view'), the band it ranks in, the chip's initial text and the
|
|
9
|
+
* guide capsule that opens it from the column's own tab strip.
|
|
10
|
+
* - 'sidebar.right.pane.tab' + 'sidebar.right.pane.tab.title' (stage two, one
|
|
11
|
+
* keyed registration each under the SAME id): the tab's body and its chip
|
|
12
|
+
* contents, which is exactly the shape the shipped terminal tab uses.
|
|
13
|
+
*
|
|
14
|
+
* The session-header shortcut is deliberately gone: the column's tab strip and
|
|
15
|
+
* the guide capsule already open the tab, so a second entry in the conversation
|
|
16
|
+
* header only crowded that row.
|
|
17
|
+
*
|
|
18
|
+
* `main` and 'sidebar.panellist' are deliberately NOT registered any more: the
|
|
19
|
+
* first took the whole center column over, and the second put a row in the
|
|
20
|
+
* shell's global panel list that addressed that column. A right-sidebar tab
|
|
21
|
+
* needs neither.
|
|
22
|
+
*
|
|
23
|
+
* The two slot seats go through `ctx.slots.inject` so the contribution waits for
|
|
24
|
+
* the owning plugin to declare the seat: load order between this plugin and the
|
|
25
|
+
* sidebar plugin therefore does not matter, and a shell that cannot serve a seat
|
|
26
|
+
* simply leaves the surface absent.
|
|
27
|
+
*
|
|
28
|
+
* Export discipline (packages/AGENTS.md): the /client surface carries only what
|
|
29
|
+
* cordis loading needs plus types.
|
|
30
|
+
*/
|
|
31
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
32
|
+
import { type BrowserViewKey } from './locales.ts';
|
|
33
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
34
|
+
interface LocaleNamespaceMap {
|
|
35
|
+
/** Browser-view surface copy. */
|
|
36
|
+
'browser-view': BrowserViewKey;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Services required by this plugin. */
|
|
40
|
+
export declare const inject: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Register the browser-view tab type and its surfaces.
|
|
43
|
+
* @param ctx - client root context.
|
|
44
|
+
*/
|
|
45
|
+
export declare function apply(ctx: ClientContext): void;
|
|
46
|
+
export type { BrowserViewPanelFace, BrowserViewPanelProps, BrowserViewSocketFactory } from './panel.tsx';
|
|
47
|
+
export type { BrowserViewLiveTitleStore } from './live-title.ts';
|
|
48
|
+
export type { BrowserViewTabParams } from './tab-type.ts';
|
|
49
|
+
export type { BrowserViewTabTitleFace, BrowserViewTabTitleProps } from './tab-title.tsx';
|
|
50
|
+
export type { BrowserViewFrame, BrowserViewSocketStatus } from './socket.ts';
|
|
51
|
+
export type { BrowserViewKey } from './locales.ts';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page title the tab body last saw, published for the tab's chip.
|
|
3
|
+
*
|
|
4
|
+
* The chip is drawn by the shell beside a body this plugin owns, so the two
|
|
5
|
+
* cannot exchange props: the body learns the streamed page's title from its
|
|
6
|
+
* socket, and the title component reads it here. A chip that says "Browser
|
|
7
|
+
* view" for a session whose page is called "Checkout" is the worse of the two
|
|
8
|
+
* labels, so the body publishes and the title prefers what it published.
|
|
9
|
+
*
|
|
10
|
+
* One browser-view tab per session is what the kind declares (no `multiple`),
|
|
11
|
+
* so the session id alone identifies the entry: there is no second tab whose
|
|
12
|
+
* title could overwrite the first one's.
|
|
13
|
+
*/
|
|
14
|
+
/** Cross-component title channel, keyed by session. */
|
|
15
|
+
export interface BrowserViewLiveTitleStore {
|
|
16
|
+
/**
|
|
17
|
+
* The last published title for a session.
|
|
18
|
+
* @param sessionId - session key, or undefined when the component has none.
|
|
19
|
+
* @returns the title, or undefined when nothing is published.
|
|
20
|
+
*/
|
|
21
|
+
get(sessionId: string | undefined): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Publish a session's page title, or clear it with undefined or an empty one.
|
|
24
|
+
* @param sessionId - session key, or undefined to drop the write.
|
|
25
|
+
* @param title - the page title, or undefined when the page has none.
|
|
26
|
+
*/
|
|
27
|
+
set(sessionId: string | undefined, title: string | undefined): void;
|
|
28
|
+
/**
|
|
29
|
+
* Observe publications.
|
|
30
|
+
* @param listener - synchronous invalidation callback.
|
|
31
|
+
* @returns unsubscribe.
|
|
32
|
+
*/
|
|
33
|
+
subscribe(listener: () => void): () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create one store for the plugin's lifetime.
|
|
37
|
+
* @returns the channel.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createLiveTitleStore(): BrowserViewLiveTitleStore;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale dictionaries for the browser-view plugin. `zh` is the key-set source
|
|
3
|
+
* of truth; `en` keeps a full key-for-key mirror (packages/AGENTS.md bilingual
|
|
4
|
+
* rules). Registered through ctx.locale.register(NS, { zh, en }); the components
|
|
5
|
+
* read every string through the injected `t` seat, so no copy is hardcoded in
|
|
6
|
+
* JSX.
|
|
7
|
+
*
|
|
8
|
+
* The page-title keys are gone with the page header: a right-sidebar tab is
|
|
9
|
+
* named by the shell's chip, and the chip's text comes from the tab type and
|
|
10
|
+
* the published page title instead ('panel.title' / 'panel.close' had no
|
|
11
|
+
* reader left once the "back to the conversation" control was removed).
|
|
12
|
+
*
|
|
13
|
+
* 'panel.tabs.empty' went with the always-drawn tab strip: the controlled
|
|
14
|
+
* browser's chips now appear only when it holds more than one page, so there is
|
|
15
|
+
* no empty strip left to caption.
|
|
16
|
+
*/
|
|
17
|
+
/** Simplified Chinese dictionary (key-set source of truth). */
|
|
18
|
+
export declare const zh: {
|
|
19
|
+
'tab.title': string;
|
|
20
|
+
'guide.description': string;
|
|
21
|
+
'panel.tab.untitled': string;
|
|
22
|
+
'panel.url.empty': string;
|
|
23
|
+
'panel.address.label': string;
|
|
24
|
+
'panel.toolbar.refresh': string;
|
|
25
|
+
'panel.frame.alt': string;
|
|
26
|
+
'panel.empty.title': string;
|
|
27
|
+
'panel.empty.hint': string;
|
|
28
|
+
'panel.error.title': string;
|
|
29
|
+
'panel.trace.idle': string;
|
|
30
|
+
'panel.status.connecting': string;
|
|
31
|
+
'panel.status.loading': string;
|
|
32
|
+
'panel.status.live': string;
|
|
33
|
+
};
|
|
34
|
+
/** The browser-view namespace key union. */
|
|
35
|
+
export type BrowserViewKey = keyof typeof zh;
|
|
36
|
+
/** English dictionary, key-for-key complete against zh. */
|
|
37
|
+
export declare const en: Record<BrowserViewKey, string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
import type { BrowserViewLiveTitleStore } from './live-title.ts';
|
|
3
|
+
import { type BrowserViewSocket, type BrowserViewSocketHandlers } from './socket.ts';
|
|
4
|
+
/** Page-side socket factory; tests inject a fake transport through it. */
|
|
5
|
+
export type BrowserViewSocketFactory = (handlers: BrowserViewSocketHandlers) => BrowserViewSocket;
|
|
6
|
+
/** Business face injected into the tab body. */
|
|
7
|
+
export interface BrowserViewPanelFace {
|
|
8
|
+
/** Session whose screencast this body shows. */
|
|
9
|
+
readonly sessionId?: string;
|
|
10
|
+
/** Channel the chip reads this body's page title from. */
|
|
11
|
+
readonly liveTitle?: BrowserViewLiveTitleStore;
|
|
12
|
+
}
|
|
13
|
+
/** Panel props: the locale seat, the injected face, and the seams a test may supply. */
|
|
14
|
+
export type BrowserViewPanelProps = PropsLocale<'browser-view'> & Partial<BrowserViewPanelFace> & {
|
|
15
|
+
/** Socket factory override; defaults to the real same-origin connection. */
|
|
16
|
+
readonly socketFactory?: BrowserViewSocketFactory;
|
|
17
|
+
/** Origin override; defaults to the page's own location. */
|
|
18
|
+
readonly location?: {
|
|
19
|
+
readonly protocol: string;
|
|
20
|
+
readonly host: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Render the browser view tab body.
|
|
25
|
+
* @param props - composed slot props.
|
|
26
|
+
* @returns the tab content.
|
|
27
|
+
*/
|
|
28
|
+
export declare function BrowserViewPanel({ t, sessionId, liveTitle, socketFactory, location }: BrowserViewPanelProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic attributes for the browser-view surface (semantic-attrs-v1).
|
|
3
|
+
*
|
|
4
|
+
* The plugin name lives on the root element of each surface so part values stay
|
|
5
|
+
* bare words; a theme anchors on the pair, never on a part name that repeats
|
|
6
|
+
* the plugin. The right-sidebar chip and the shell's tab strip around it are
|
|
7
|
+
* not ours, so only this plugin's own elements are stamped.
|
|
8
|
+
*
|
|
9
|
+
* The body's part names follow the shipped browser tab's structure - a toolbar
|
|
10
|
+
* with an address display, the frame, and the action trace - so a theme that
|
|
11
|
+
* already anchors on that chrome reaches this tab the same way.
|
|
12
|
+
*/
|
|
13
|
+
/** Root plugin attribute value carried by every top-level browser-view element. */
|
|
14
|
+
export declare const BROWSER_VIEW_PLUGIN = "browser-view";
|
|
15
|
+
/** Part names this plugin emits, in surface order. */
|
|
16
|
+
export declare const BROWSER_VIEW_PARTS: {
|
|
17
|
+
/** The tab body the sidebar mounts in its content area. */
|
|
18
|
+
readonly panel: "panel";
|
|
19
|
+
/** Top chrome row: address display, connection state, refresh. */
|
|
20
|
+
readonly toolbar: "toolbar";
|
|
21
|
+
/** The read-only address display of the streamed page. */
|
|
22
|
+
readonly address: "address";
|
|
23
|
+
/** The controlled browser's tab chips; drawn only when it holds several. */
|
|
24
|
+
readonly tabs: "tabs";
|
|
25
|
+
/** The live frame image. */
|
|
26
|
+
readonly frame: "frame";
|
|
27
|
+
/** Bottom action trace. */
|
|
28
|
+
readonly trace: "trace";
|
|
29
|
+
/** Connection state marker in the toolbar. */
|
|
30
|
+
readonly status: "status";
|
|
31
|
+
/** No-frame placeholder. */
|
|
32
|
+
readonly empty: "empty";
|
|
33
|
+
/** Host-reported failure placeholder. */
|
|
34
|
+
readonly error: "error";
|
|
35
|
+
/** This plugin's share of the right-sidebar chip. */
|
|
36
|
+
readonly tabTitle: "tab-title";
|
|
37
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { BrowserActionTrace, BrowserPanelState, BrowserViewCommand, BrowserViewEvent } from '../core/protocol.ts';
|
|
2
|
+
/** Connection phase the panel renders in its status line. */
|
|
3
|
+
export type BrowserViewSocketStatus = 'connecting' | 'open' | 'reconnecting' | 'closed';
|
|
4
|
+
/** First reconnect delay, doubled per failed attempt. */
|
|
5
|
+
export declare const RECONNECT_BASE_MS = 500;
|
|
6
|
+
/** Reconnect ceiling; a host that stays down must not spin the tab. */
|
|
7
|
+
export declare const RECONNECT_MAX_MS = 15000;
|
|
8
|
+
/** One decoded frame, exactly as the panel needs it. */
|
|
9
|
+
export interface BrowserViewFrame {
|
|
10
|
+
/** Tab the frame belongs to. */
|
|
11
|
+
readonly tabId: string;
|
|
12
|
+
/** Host-side monotonic counter for this tab. */
|
|
13
|
+
readonly seq: number;
|
|
14
|
+
/** Frame width in CSS pixels. */
|
|
15
|
+
readonly width: number;
|
|
16
|
+
/** Frame height in CSS pixels. */
|
|
17
|
+
readonly height: number;
|
|
18
|
+
/** Base64 JPEG, no data: prefix. */
|
|
19
|
+
readonly data: string;
|
|
20
|
+
}
|
|
21
|
+
/** Callbacks the panel installs on a connection. */
|
|
22
|
+
export interface BrowserViewSocketHandlers {
|
|
23
|
+
/** Connection phase changed. */
|
|
24
|
+
onStatus?(status: BrowserViewSocketStatus): void;
|
|
25
|
+
/** Tabs, active tab and running flag were (re)published. */
|
|
26
|
+
onState(state: BrowserPanelState): void;
|
|
27
|
+
/** A fresh frame arrived, already filtered for staleness. */
|
|
28
|
+
onFrame(frame: BrowserViewFrame): void;
|
|
29
|
+
/** The agent performed one tool action. */
|
|
30
|
+
onAction(trace: BrowserActionTrace): void;
|
|
31
|
+
/** The host reported a failure the panel must show instead of a frame. */
|
|
32
|
+
onError(code: string, message: string): void;
|
|
33
|
+
}
|
|
34
|
+
/** The minimal socket face this client needs; the DOM WebSocket satisfies it. */
|
|
35
|
+
export interface BrowserViewWebSocketLike {
|
|
36
|
+
send(data: string): void;
|
|
37
|
+
close(code?: number, reason?: string): void;
|
|
38
|
+
onopen: ((event: unknown) => void) | null;
|
|
39
|
+
onmessage: ((event: {
|
|
40
|
+
data: unknown;
|
|
41
|
+
}) => void) | null;
|
|
42
|
+
onclose: ((event: unknown) => void) | null;
|
|
43
|
+
onerror: ((event: unknown) => void) | null;
|
|
44
|
+
}
|
|
45
|
+
/** Constructor shape of the transport; injectable for tests. */
|
|
46
|
+
export type BrowserViewWebSocketCtor = new (url: string) => BrowserViewWebSocketLike;
|
|
47
|
+
/** Options for one connection. */
|
|
48
|
+
export interface BrowserViewSocketOptions {
|
|
49
|
+
/** Transport constructor; defaults to the page's WebSocket. */
|
|
50
|
+
readonly WebSocketImpl?: BrowserViewWebSocketCtor;
|
|
51
|
+
/** Origin source for the URL; defaults to `globalThis.location`. */
|
|
52
|
+
readonly location?: {
|
|
53
|
+
readonly protocol: string;
|
|
54
|
+
readonly host: string;
|
|
55
|
+
};
|
|
56
|
+
/** Session the panel attaches to, forwarded in the `attach` command. */
|
|
57
|
+
readonly sessionId?: string;
|
|
58
|
+
/** Timer seam so backoff can be advanced deterministically in tests. */
|
|
59
|
+
readonly setTimer?: (handler: () => void, ms: number) => unknown;
|
|
60
|
+
/** Timer cancellation seam paired with `setTimer`. */
|
|
61
|
+
readonly clearTimer?: (handle: unknown) => void;
|
|
62
|
+
}
|
|
63
|
+
/** The handle a panel keeps for the lifetime of one mounted connection. */
|
|
64
|
+
export interface BrowserViewSocket {
|
|
65
|
+
/** Send one command, buffered while the socket is not open. */
|
|
66
|
+
send(command: BrowserViewCommand): void;
|
|
67
|
+
/** Stop reconnecting and close the transport. */
|
|
68
|
+
close(): void;
|
|
69
|
+
/** Current connection phase. */
|
|
70
|
+
status(): BrowserViewSocketStatus;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Derive the same-origin socket URL from a location.
|
|
74
|
+
*
|
|
75
|
+
* Only http/https are transport candidates: a page delivered by any other
|
|
76
|
+
* scheme (the desktop shell's dsh-app:, a file: snapshot) has no host the host
|
|
77
|
+
* half could be reached on, and guessing would produce a socket that fails on
|
|
78
|
+
* every retry.
|
|
79
|
+
* @param location - origin the panel is rendered on.
|
|
80
|
+
* @returns the absolute ws/wss URL, or null when this page cannot carry one.
|
|
81
|
+
*/
|
|
82
|
+
export declare function browserViewSocketUrl(location: {
|
|
83
|
+
readonly protocol: string;
|
|
84
|
+
readonly host: string;
|
|
85
|
+
}): string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Backoff for one reconnect attempt.
|
|
88
|
+
* @param attempt - zero-based attempt index.
|
|
89
|
+
* @returns delay in milliseconds, capped at RECONNECT_MAX_MS.
|
|
90
|
+
*/
|
|
91
|
+
export declare function reconnectDelay(attempt: number): number;
|
|
92
|
+
/**
|
|
93
|
+
* Narrow one decoded payload into a protocol event.
|
|
94
|
+
*
|
|
95
|
+
* The protocol is a discriminated union over `kind`, so an unknown kind or a
|
|
96
|
+
* wrong field type is a shape this panel cannot render: it is dropped rather
|
|
97
|
+
* than half-applied, which keeps one malformed push from corrupting the view.
|
|
98
|
+
* @param value - parsed JSON value (or a raw frame string).
|
|
99
|
+
* @returns the event, or null when the payload is not one this version reads.
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseBrowserViewEvent(value: unknown): BrowserViewEvent | null;
|
|
102
|
+
/**
|
|
103
|
+
* Open one connection to the host half and keep it alive.
|
|
104
|
+
*
|
|
105
|
+
* Sequencing: every successful open sends `attach` (the host answers with
|
|
106
|
+
* `hello` plus frames), and the per-tab frame counter is cleared because the
|
|
107
|
+
* host restarts its `seq` for a new connection — keeping the old high-water
|
|
108
|
+
* mark would drop the whole fresh stream.
|
|
109
|
+
* @param handlers - panel callbacks.
|
|
110
|
+
* @param options - transport, origin, session and timer seams.
|
|
111
|
+
* @returns the handle the panel closes on unmount.
|
|
112
|
+
*/
|
|
113
|
+
export declare function connectBrowserViewSocket(handlers: BrowserViewSocketHandlers, options?: BrowserViewSocketOptions): BrowserViewSocket;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
|
+
import type { BrowserViewLiveTitleStore } from './live-title.ts';
|
|
3
|
+
/** Business face injected into the chip. */
|
|
4
|
+
export interface BrowserViewTabTitleFace {
|
|
5
|
+
/** Session whose tab this chip names. */
|
|
6
|
+
readonly sessionId?: string;
|
|
7
|
+
/** Channel the body publishes the streamed page's title on. */
|
|
8
|
+
readonly liveTitle?: BrowserViewLiveTitleStore;
|
|
9
|
+
}
|
|
10
|
+
/** Chip props: the locale seat plus the injected face. */
|
|
11
|
+
export type BrowserViewTabTitleProps = PropsLocale<'browser-view'> & Partial<BrowserViewTabTitleFace>;
|
|
12
|
+
/**
|
|
13
|
+
* Render the chip contents.
|
|
14
|
+
* @param props - composed slot props.
|
|
15
|
+
* @returns the mark and the tab's name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function BrowserViewTabTitle({ t, sessionId, liveTitle }: BrowserViewTabTitleProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The right-sidebar tab type this plugin contributes: its kind, its identity,
|
|
3
|
+
* the navigation parameters it accepts, and the guide capsule that opens it.
|
|
4
|
+
*
|
|
5
|
+
* A tab type is registered in two stages. Stage one is a purely static
|
|
6
|
+
* declaration (ctx.sidebarRightTabs.register) naming the kind, the chip's
|
|
7
|
+
* initial text and the guide entry; stage two is the keyed 'sidebar.right.pane.tab'
|
|
8
|
+
* body and 'sidebar.right.pane.tab.title' registration under this same id, which
|
|
9
|
+
* is what the seat dispatches on. The kind is what openTabIn/openTab name, and
|
|
10
|
+
* it is also the key of the params map below.
|
|
11
|
+
*
|
|
12
|
+
* The `guide` entry is what puts this type on the right sidebar's guide page -
|
|
13
|
+
* the list a user sees when the column has no page in front. It is the one place
|
|
14
|
+
* that opens the tab now that the conversation header carries no entry of its
|
|
15
|
+
* own, and the guide owns the click:
|
|
16
|
+
* it renders one capsule per registered entry and opens the entry's own `kind`
|
|
17
|
+
* (GuideBody: tab.actions.openTab(entry.kind, { replaceTab: true })), so this
|
|
18
|
+
* plugin declares the capsule and never wires a handler of its own. No
|
|
19
|
+
* commandId is declared: the plugin registers no keyboard shortcut, and the
|
|
20
|
+
* guide would draw a key hint the shortcut table cannot honour.
|
|
21
|
+
*
|
|
22
|
+
* The kind is deliberately NOT 'browser': the shipped
|
|
23
|
+
* @deepseek-ai/dsh-client-ui-sidebar-browser registers that kind, and a
|
|
24
|
+
* registration in the extension band takes a kind over, so reusing it would
|
|
25
|
+
* shadow the shipped browser tab out of existence - the one thing this
|
|
26
|
+
* package's AGENTS.md forbids. A distinct kind is what lets both live in the
|
|
27
|
+
* same column.
|
|
28
|
+
*/
|
|
29
|
+
import type { SidebarRightTabDefinition } from '@deepseek-ai/dsh-client-ui-sidebar-right/client';
|
|
30
|
+
import type { BrowserViewKey } from './locales.ts';
|
|
31
|
+
/** What this plugin's tabs are, and what openTabIn/openTab name. */
|
|
32
|
+
export declare const BROWSER_VIEW_TAB_KIND = "browser-view";
|
|
33
|
+
/** This implementation's identity in the tab system; also the keyed slot dispatch key. */
|
|
34
|
+
export declare const BROWSER_VIEW_TAB_ID = "@linxin666/dsh-client-ui-browser-view";
|
|
35
|
+
/** Identity of this type's capsule on the guide page, stable within the provider. */
|
|
36
|
+
export declare const BROWSER_VIEW_GUIDE_ENTRY_ID = "open";
|
|
37
|
+
/**
|
|
38
|
+
* Position of this type's capsule among every registered type's entries. The
|
|
39
|
+
* shipped browser tab sits at 30; this one follows it instead of competing for
|
|
40
|
+
* the same slot, because it is a companion view rather than a replacement.
|
|
41
|
+
*/
|
|
42
|
+
export declare const BROWSER_VIEW_GUIDE_ENTRY_ORDER = 40;
|
|
43
|
+
/** Navigation parameters this tab type accepts. */
|
|
44
|
+
export interface BrowserViewTabParams {
|
|
45
|
+
/** Chrome tab the pane should stream first, when the opener knows one. */
|
|
46
|
+
readonly tabId?: string;
|
|
47
|
+
}
|
|
48
|
+
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
|
|
49
|
+
interface SidebarRightTabParamsMap {
|
|
50
|
+
/** Parameters of a browser-view page. */
|
|
51
|
+
'browser-view': BrowserViewTabParams;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build stage one of the registration.
|
|
56
|
+
* @param t - translate function of this plugin's dictionary.
|
|
57
|
+
* @returns the static tab type the registry keeps.
|
|
58
|
+
*/
|
|
59
|
+
export declare function browserViewTabDefinition(t: (key: BrowserViewKey) => string): SidebarRightTabDefinition;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The five things an agent does to a page: navigate, click, type, press a key,
|
|
3
|
+
* and scroll.
|
|
4
|
+
*
|
|
5
|
+
* Two rules shape every action here.
|
|
6
|
+
*
|
|
7
|
+
* Coordinates, not synthetic events. `element.click()` from a script skips
|
|
8
|
+
* focus, hover, and the trusted-event path, so a page that checks
|
|
9
|
+
* `isTrusted` or listens on a parent behaves differently from a real click.
|
|
10
|
+
* Every element-level action therefore resolves a box and dispatches real
|
|
11
|
+
* input events at its centre.
|
|
12
|
+
*
|
|
13
|
+
* Every action refreshes the frame. The screencast only emits when the
|
|
14
|
+
* compositor sees a change, so a scroll back to the same place, a click that
|
|
15
|
+
* opens nothing, or a key that is swallowed would leave the panel showing the
|
|
16
|
+
* pre-action state. Each action ends with an explicit capture, which is also
|
|
17
|
+
* what makes "the panel shows what just happened" true for every action
|
|
18
|
+
* instead of only the visual ones.
|
|
19
|
+
*
|
|
20
|
+
* Each action also returns one readable trace line: it is the only thing the
|
|
21
|
+
* panel puts in front of the user, and the model gets it back as the action's
|
|
22
|
+
* own summary.
|
|
23
|
+
*
|
|
24
|
+
* @module @linxin666/dsh-client-ui-browser-view/core/actions
|
|
25
|
+
*/
|
|
26
|
+
import type { CdpTransport } from './cdp.ts';
|
|
27
|
+
import type { TabManager } from './tabs.ts';
|
|
28
|
+
/** The collaborators one action needs. */
|
|
29
|
+
export interface ActionScope {
|
|
30
|
+
/** Protocol transport shared with the tab manager. */
|
|
31
|
+
transport: CdpTransport;
|
|
32
|
+
/** Tab bookkeeping, ref resolution, and frame refresh. */
|
|
33
|
+
tabs: TabManager;
|
|
34
|
+
}
|
|
35
|
+
/** What one action reports back. */
|
|
36
|
+
export interface ActionOutcome {
|
|
37
|
+
/** Tab that changed. */
|
|
38
|
+
tabId: string;
|
|
39
|
+
/** One-line human description, also used as the panel trace. */
|
|
40
|
+
summary: string;
|
|
41
|
+
}
|
|
42
|
+
/** Which element a click or a type targets. Exactly one form is used. */
|
|
43
|
+
export interface ElementTarget {
|
|
44
|
+
/** Depth-first ref from the last `browser_snapshot`. */
|
|
45
|
+
ref?: number;
|
|
46
|
+
/** CSS selector, for a caller that already knows the page. */
|
|
47
|
+
selector?: string;
|
|
48
|
+
/** Viewport x coordinate, when the caller measured the element itself. */
|
|
49
|
+
x?: number;
|
|
50
|
+
/** Viewport y coordinate. */
|
|
51
|
+
y?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Navigate the tab and refresh the panel frame.
|
|
55
|
+
* @param scope - transport and tab manager.
|
|
56
|
+
* @param tabId - target tab.
|
|
57
|
+
* @param url - absolute, `data:`, or `about:` url.
|
|
58
|
+
* @returns the action outcome.
|
|
59
|
+
*/
|
|
60
|
+
export declare function navigateTo(scope: ActionScope, tabId: string, url: string): Promise<ActionOutcome>;
|
|
61
|
+
/**
|
|
62
|
+
* Click an element or a coordinate.
|
|
63
|
+
* @param scope - transport and tab manager.
|
|
64
|
+
* @param tabId - target tab.
|
|
65
|
+
* @param target - ref, selector, or coordinates.
|
|
66
|
+
* @returns the action outcome.
|
|
67
|
+
*/
|
|
68
|
+
export declare function clickElement(scope: ActionScope, tabId: string, target: ElementTarget): Promise<ActionOutcome>;
|
|
69
|
+
/**
|
|
70
|
+
* Type text into the focused element, or into one element first.
|
|
71
|
+
* @param scope - transport and tab manager.
|
|
72
|
+
* @param tabId - target tab.
|
|
73
|
+
* @param text - text to insert.
|
|
74
|
+
* @param target - optional element to focus before typing.
|
|
75
|
+
* @returns the action outcome.
|
|
76
|
+
*/
|
|
77
|
+
export declare function typeText(scope: ActionScope, tabId: string, text: string, target?: ElementTarget): Promise<ActionOutcome>;
|
|
78
|
+
/** One key definition for `Input.dispatchKeyEvent`. */
|
|
79
|
+
interface KeyDefinition {
|
|
80
|
+
key: string;
|
|
81
|
+
code: string;
|
|
82
|
+
windowsVirtualKeyCode: number;
|
|
83
|
+
text?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolve a key name to its dispatch definition.
|
|
87
|
+
* @param key - `Enter`, `Tab`, ... or a single character.
|
|
88
|
+
* @returns the definition.
|
|
89
|
+
*/
|
|
90
|
+
export declare function keyDefinition(key: string): KeyDefinition;
|
|
91
|
+
/**
|
|
92
|
+
* Press one key on whatever has focus.
|
|
93
|
+
* @param scope - transport and tab manager.
|
|
94
|
+
* @param tabId - target tab.
|
|
95
|
+
* @param key - key name or single character.
|
|
96
|
+
* @returns the action outcome.
|
|
97
|
+
*/
|
|
98
|
+
export declare function pressKey(scope: ActionScope, tabId: string, key: string): Promise<ActionOutcome>;
|
|
99
|
+
/**
|
|
100
|
+
* Scroll the page with a synthetic wheel event at a viewport point.
|
|
101
|
+
* @param scope - transport and tab manager.
|
|
102
|
+
* @param tabId - target tab.
|
|
103
|
+
* @param delta - horizontal and vertical scroll distance in CSS pixels.
|
|
104
|
+
* @returns the action outcome.
|
|
105
|
+
*/
|
|
106
|
+
export declare function scrollBy(scope: ActionScope, tabId: string, delta: {
|
|
107
|
+
deltaX?: number;
|
|
108
|
+
deltaY?: number;
|
|
109
|
+
x?: number;
|
|
110
|
+
y?: number;
|
|
111
|
+
}): Promise<ActionOutcome>;
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Chrome DevTools Protocol client — the only transport the host half
|
|
3
|
+
* uses to reach the browser it launched.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately small: one WebSocket, an auto-incrementing request id, a pending
|
|
6
|
+
* map, and per-method event listeners. Everything above this file (tabs,
|
|
7
|
+
* snapshot, actions) speaks CdpTransport, so tests drive those layers with a
|
|
8
|
+
* fake transport and never start Chrome.
|
|
9
|
+
*
|
|
10
|
+
* Flat-mode sessions: with `Target.setDiscoverTargets` + `Target.attachToTarget
|
|
11
|
+
* ({flatten: true})` every message for one tab carries its `sessionId`, so a
|
|
12
|
+
* single socket multiplexes browser-level and page-level commands.
|
|
13
|
+
*
|
|
14
|
+
* @module @linxin666/dsh-client-ui-browser-view/core/cdp
|
|
15
|
+
*/
|
|
16
|
+
/** Protocol failure returned by the browser, or raised by this client. */
|
|
17
|
+
export declare class CdpError extends Error {
|
|
18
|
+
/** CDP error code, or `-1` for client-side failures (timeout, closed socket). */
|
|
19
|
+
readonly code: number;
|
|
20
|
+
/** Method whose round-trip failed. */
|
|
21
|
+
readonly method: string;
|
|
22
|
+
/**
|
|
23
|
+
* @param method - the protocol method that failed.
|
|
24
|
+
* @param code - CDP error code, `-1` for client-side failures.
|
|
25
|
+
* @param message - the browser's own message, kept verbatim for diagnosis.
|
|
26
|
+
*/
|
|
27
|
+
constructor(method: string, code: number, message: string);
|
|
28
|
+
}
|
|
29
|
+
/** The subset of the client the upper layers depend on; tests supply a fake. */
|
|
30
|
+
export interface CdpTransport {
|
|
31
|
+
/**
|
|
32
|
+
* Send one protocol command and resolve with its result.
|
|
33
|
+
* @param method - CDP method, for example `Page.navigate`.
|
|
34
|
+
* @param params - command parameters.
|
|
35
|
+
* @param sessionId - flat-mode session to address; omitted sends browser-level.
|
|
36
|
+
* @returns the `result` object of the response.
|
|
37
|
+
*/
|
|
38
|
+
send<T = Record<string, unknown>>(method: string, params?: Record<string, unknown>, sessionId?: string): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to one protocol event.
|
|
41
|
+
* @param method - event name, for example `Page.screencastFrame`.
|
|
42
|
+
* @param handler - receives event params and the originating session, if any.
|
|
43
|
+
* @returns the unsubscribe function.
|
|
44
|
+
*/
|
|
45
|
+
on(method: string, handler: CdpEventListener): () => void;
|
|
46
|
+
/** Drop the socket; every pending round-trip rejects. */
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
/** One protocol event delivery. */
|
|
50
|
+
export type CdpEventListener = (params: Record<string, unknown>, sessionId: string | undefined) => void;
|
|
51
|
+
/** Default per-command deadline; long enough for a navigation, short enough to fail a wedged tab. */
|
|
52
|
+
export declare const CDP_COMMAND_TIMEOUT_MS = 30000;
|
|
53
|
+
/**
|
|
54
|
+
* A single WebSocket carrying browser-level and flat-session protocol traffic.
|
|
55
|
+
*/
|
|
56
|
+
export declare class CdpClient implements CdpTransport {
|
|
57
|
+
private readonly socket;
|
|
58
|
+
private readonly timeoutMs;
|
|
59
|
+
private readonly pending;
|
|
60
|
+
private readonly listeners;
|
|
61
|
+
private nextId;
|
|
62
|
+
private closedReason;
|
|
63
|
+
private constructor();
|
|
64
|
+
/**
|
|
65
|
+
* Open a client against an already-discovered DevTools endpoint.
|
|
66
|
+
* @param url - `webSocketDebuggerUrl` from `/json/version`.
|
|
67
|
+
* @param options - command deadline override.
|
|
68
|
+
* @returns a connected client.
|
|
69
|
+
* @throws CdpError when the socket cannot be established in time.
|
|
70
|
+
*/
|
|
71
|
+
static connect(url: string, options?: {
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
}): Promise<CdpClient>;
|
|
74
|
+
/**
|
|
75
|
+
* Address one protocol command.
|
|
76
|
+
* @param method - CDP method.
|
|
77
|
+
* @param params - command parameters.
|
|
78
|
+
* @param sessionId - flat-mode session to address.
|
|
79
|
+
* @returns the response `result`.
|
|
80
|
+
*/
|
|
81
|
+
send<T = Record<string, unknown>>(method: string, params?: Record<string, unknown>, sessionId?: string): Promise<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Subscribe to one protocol event.
|
|
84
|
+
* @param method - event name.
|
|
85
|
+
* @param handler - event callback.
|
|
86
|
+
* @returns the unsubscribe function.
|
|
87
|
+
*/
|
|
88
|
+
on(method: string, handler: CdpEventListener): () => void;
|
|
89
|
+
/** Drop the socket and reject every in-flight command. */
|
|
90
|
+
close(): void;
|
|
91
|
+
/** Route one decoded frame to the pending map or the event listeners. */
|
|
92
|
+
private handleMessage;
|
|
93
|
+
/** Reject every in-flight command with one reason. */
|
|
94
|
+
private failAll;
|
|
95
|
+
}
|