@linxin666/dsh-client-ui-browser-view 0.4.13 → 0.4.15

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.
@@ -56,7 +56,7 @@ export interface PluginCardContext {
56
56
  /** Service lookup; absent on a context double that only models the slots. */
57
57
  get?(name: string): unknown;
58
58
  /** Event subscription seat; absent on an event-less test double. */
59
- on?(event: string, listener: (...args: never[]) => void): unknown;
59
+ on?(event: never, listener: never): unknown;
60
60
  }
61
61
  /** Owner share of a family list-seat card (that seat supplies nothing). */
62
62
  export interface SettingsPluginItemOwnerProps {
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Screenshot planning: the one place that turns a screenshot request into
3
+ * `Page.captureScreenshot` parameters and the pixel size the encoded image will
4
+ * have.
5
+ *
6
+ * Two things are decided here rather than at the call site. The format decides
7
+ * the media type the attachment service is asked to store, and a clip with a
8
+ * scale turns one capture into a cropped render, so both the tool result and the
9
+ * attachment metadata come from the same plan instead of being re-derived from
10
+ * each other.
11
+ *
12
+ * The limits are hard because every pixel is encoded, base64-encoded again, and
13
+ * pushed through the protocol: a full-viewport capture at scale 3 is 9.2 million
14
+ * pixels of JPEG on a socket, and a caller that asked for it by accident would
15
+ * stall the host rather than produce a screenshot anyone can read. The output
16
+ * budget matches the attachment service's own downscale threshold, so a plan
17
+ * that passes here never gets silently resized afterwards.
18
+ *
19
+ * @module @linxin666/dsh-client-ui-browser-view/core/screenshot
20
+ */
21
+ /** Encoded image formats this package requests from CDP. */
22
+ export type ScreenshotFormat = 'png' | 'jpeg';
23
+ /** A rectangular crop in CSS pixels, relative to the viewport origin. */
24
+ export interface ScreenshotClip {
25
+ /** Left edge in CSS pixels. */
26
+ x: number;
27
+ /** Top edge in CSS pixels. */
28
+ y: number;
29
+ /** Crop width in CSS pixels. */
30
+ width: number;
31
+ /** Crop height in CSS pixels. */
32
+ height: number;
33
+ }
34
+ /** The tool-level screenshot request, before any planning. */
35
+ export interface ScreenshotRequest {
36
+ /** Encoded format. @default 'png' */
37
+ format?: ScreenshotFormat;
38
+ /** Crop to this rectangle instead of the whole viewport. */
39
+ clip?: ScreenshotClip;
40
+ /**
41
+ * Device pixels per CSS pixel. Defaults to 1 without a clip and to 2 with one,
42
+ * because a cropped capture is a detail view.
43
+ */
44
+ scale?: number;
45
+ }
46
+ /** CDP `Page.captureScreenshot` parameters; the only place this package builds them. */
47
+ export interface CdpScreenshotParams {
48
+ /** Encoded format. */
49
+ format: ScreenshotFormat;
50
+ /** JPEG quality, 0-100; CDP ignores it for PNG. */
51
+ quality?: number;
52
+ /** Always false: capture only what the pinned viewport shows. */
53
+ captureBeyondViewport: false;
54
+ /** Optional crop plus the scale it renders at. */
55
+ clip?: {
56
+ x: number;
57
+ y: number;
58
+ width: number;
59
+ height: number;
60
+ scale: number;
61
+ };
62
+ }
63
+ /** Everything the caller and the attachment need to know about one capture. */
64
+ export interface ScreenshotPlan {
65
+ /** Parameters to hand to `Page.captureScreenshot`. */
66
+ params: CdpScreenshotParams;
67
+ /** Media type of the encoded bytes. */
68
+ mediaType: 'image/png' | 'image/jpeg';
69
+ /** Encoded width in device pixels: the viewport or clip width times the scale. */
70
+ width: number;
71
+ /** Encoded height in device pixels: the viewport or clip height times the scale. */
72
+ height: number;
73
+ /** Scale the capture renders at. */
74
+ scale: number;
75
+ }
76
+ /** Matches the attachment service's `normalizedImageMaxPixels`: 2048*2048. */
77
+ export declare const SCREENSHOT_MAX_OUTPUT_PIXELS: number;
78
+ /** Largest scale a request may ask for. */
79
+ export declare const SCREENSHOT_MAX_SCALE = 3;
80
+ /**
81
+ * Plan one screenshot capture.
82
+ *
83
+ * Pure: the same three arguments always produce the same plan, and nothing here
84
+ * reads configuration, the clock, or the environment.
85
+ * @param viewport - the CSS-pixel viewport the page is pinned to.
86
+ * @param request - what the caller asked for; every field is optional.
87
+ * @param jpegQuality - quality to request for a JPEG capture, 0-100.
88
+ * @returns the CDP parameters, the media type, and the encoded pixel size.
89
+ * @throws when the format, scale, clip, or resulting size cannot be honoured.
90
+ */
91
+ export declare function planScreenshot(viewport: {
92
+ width: number;
93
+ height: number;
94
+ }, request: ScreenshotRequest, jpegQuality: number): ScreenshotPlan;
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import type { CdpTransport } from './cdp.ts';
21
21
  import { type BrowserConsoleEntry, type BrowserNetworkEntry, type BrowserTabView } from './protocol.ts';
22
+ import type { CdpScreenshotParams } from './screenshot.ts';
22
23
  /** One JPEG frame as the panel receives it. */
23
24
  export interface ScreencastFrame {
24
25
  /** Tab the frame belongs to. */
@@ -188,11 +189,18 @@ export declare class TabManager {
188
189
  */
189
190
  stopScreencast(tabId: string): Promise<void>;
190
191
  /**
191
- * Capture one JPEG frame on demand.
192
+ * Capture one screenshot on demand.
193
+ *
194
+ * Without explicit parameters this is exactly the frame the screencast path
195
+ * has always asked for: a JPEG at the configured quality, bounded to the
196
+ * viewport. A caller that wants a clip or a scale plans it with
197
+ * `planScreenshot` and passes those parameters, so this method stays the
198
+ * single send point without deciding any of it.
192
199
  * @param tabId - target tab.
193
- * @returns base64 JPEG without the `data:` prefix.
200
+ * @param params - CDP parameters from `planScreenshot`; omitted keeps the plain JPEG capture.
201
+ * @returns base64 payload without the `data:` prefix.
194
202
  */
195
- captureScreenshot(tabId: string): Promise<string>;
203
+ captureScreenshot(tabId: string, params?: CdpScreenshotParams): Promise<string>;
196
204
  /**
197
205
  * Capture a frame and hand it to the panel. An action calls this because a
198
206
  * screencast only emits when the compositor sees a change: a click that
@@ -202,6 +210,22 @@ export declare class TabManager {
202
210
  * @returns the emitted frame.
203
211
  */
204
212
  refreshFrame(tabId: string): Promise<ScreencastFrame>;
213
+ /**
214
+ * Report the CSS viewport a capture of this tab renders.
215
+ *
216
+ * A pinned tab answers from configuration, so this costs no protocol
217
+ * round-trip. A tab this host adopted from a real browser is never pinned —
218
+ * the page keeps whatever size its window has — so the real CSS layout
219
+ * viewport is read from the page instead. Screenshot planning needs exactly
220
+ * this number: clip bounds and the output budget are both expressed in the
221
+ * viewport the pixels are measured against.
222
+ * @param tabId - target tab.
223
+ * @returns the CSS viewport size in pixels.
224
+ */
225
+ viewportOf(tabId: string): Promise<{
226
+ width: number;
227
+ height: number;
228
+ }>;
205
229
  /** Read the real CSS viewport without changing it in external-browser mode. */
206
230
  private frameViewport;
207
231
  /**
@@ -22,6 +22,7 @@
22
22
  import type { CdpTransport } from '../core/cdp.ts';
23
23
  import { ChromeProcess } from '../core/chrome.ts';
24
24
  import { TabManager, type ScreencastFrame } from '../core/tabs.ts';
25
+ import { type ScreenshotPlan, type ScreenshotRequest } from '../core/screenshot.ts';
25
26
  import { type ActionOutcome, type ElementTarget } from '../core/actions.ts';
26
27
  import { type BrowserConsoleEntry, type BrowserNetworkEntry, type BrowserPanelState, type BrowserSnapshot, type BrowserTabView, type BrowserViewCommand, type BrowserViewEvent } from '../core/protocol.ts';
27
28
  /** One attached panel socket as the service sees it. */
@@ -315,16 +316,30 @@ export declare class BrowserViewService implements BrowserViewBackend {
315
316
  */
316
317
  snapshot(sessionId: string | undefined, tabId?: string): Promise<BrowserSnapshot>;
317
318
  /**
318
- * Capture one JPEG of the tab.
319
+ * Capture one image of the tab.
320
+ *
321
+ * The plan decides everything the caller is told about the bytes: the format
322
+ * becomes the media type the attachment service stores, and the scale turns
323
+ * one capture into a cropped render whose encoded size has to be reported
324
+ * rather than guessed from the viewport. Planning before the capture is what
325
+ * makes an impossible request fail here, with the numbers, instead of
326
+ * producing a truncated or silently downscaled image. The viewport it plans
327
+ * against is the tab's own: a pinned tab answers from configuration, and an
328
+ * adopted real-browser tab reports the page's real layout viewport.
319
329
  * @param sessionId - calling agent session.
320
330
  * @param tabId - explicit tab.
321
- * @returns the tab and the base64 JPEG.
331
+ * @param request - format, clip, and scale; every field is optional.
332
+ * @returns the tab, the base64 payload, and the media type and encoded size the plan produced.
333
+ * @throws when the request cannot be honoured by this viewport or the size limits.
322
334
  */
323
- screenshot(sessionId: string | undefined, tabId?: string): Promise<{
335
+ screenshot(sessionId: string | undefined, tabId?: string, request?: ScreenshotRequest): Promise<{
324
336
  tabId: string;
325
337
  url: string;
326
338
  title: string;
327
339
  data: string;
340
+ mediaType: ScreenshotPlan['mediaType'];
341
+ width: number;
342
+ height: number;
328
343
  }>;
329
344
  /**
330
345
  * Console entries of one tab, newest last.
@@ -5,8 +5,8 @@
5
5
  * JSON, rendered as one pretty-printed text block: the model reads fields, not
6
6
  * prose, and the GUI can present the same value later. `browser_screenshot`
7
7
  * returns a real image part — an `ImageBlock` carrying a durable attachment
8
- * reference — because a JPEG smuggled in as base64 text is not an image to any
9
- * model that can see one.
8
+ * reference — because a screenshot smuggled in as base64 text is not an image to
9
+ * any model that can see one.
10
10
  *
11
11
  * The screenshot path therefore needs the host's attachment service: the bytes
12
12
  * are committed through it, and the block only carries the reference. The
@@ -42,7 +42,7 @@ export interface BrowserToolDeps {
42
42
  /** The browser service every tool drives. */
43
43
  service: BrowserViewService;
44
44
  /**
45
- * Commit one JPEG to the host's durable attachment store.
45
+ * Commit one screenshot (PNG or JPEG) to the host's durable attachment store.
46
46
  *
47
47
  * Absent when the composing host mounts no attachment service; the screenshot
48
48
  * tool then refuses with an explanation instead of returning text pretending
@@ -50,7 +50,7 @@ export interface BrowserToolDeps {
50
50
  */
51
51
  saveImage?: (input: {
52
52
  data: Uint8Array;
53
- mediaType: 'image/jpeg';
53
+ mediaType: 'image/png' | 'image/jpeg';
54
54
  name?: string;
55
55
  }) => Promise<DurableImageRef>;
56
56
  }
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.13",
4
+ "version": "0.4.15",
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.1-rc.3"
25
+ "dsh": ">=0.2.2-rc.1"
26
26
  },
27
27
  "bundle": {
28
28
  "patch": "./cordis.patch.yml"
@@ -45,26 +45,26 @@
45
45
  "ws": "^8.18.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@deepseek-ai/dsh": ">=0.2.1-rc.3",
48
+ "@deepseek-ai/dsh": ">=0.2.2-rc.1",
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@deepseek-ai/cordis": "^4.0.5",
54
- "@deepseek-ai/dsh-api-remotes": "0.2.1-rc.3",
55
- "@deepseek-ai/dsh-client-locale": "^0.2.1-rc.3",
56
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
57
- "@deepseek-ai/dsh-client-ui-layout": "^0.2.1-rc.3",
58
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.3",
59
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.1-rc.3",
60
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.3",
61
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
62
- "@deepseek-ai/dsh-client-ui-sidebar-right": "^0.2.1-rc.3",
63
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.3",
64
- "@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
65
- "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.3",
66
- "@deepseek-ai/dsh-tools": "^0.2.1-rc.3",
67
- "@deepseek-ai/schemastery": "^3.18.5",
53
+ "@deepseek-ai/cordis": "^4.1.0",
54
+ "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.1",
55
+ "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.1",
56
+ "@deepseek-ai/dsh-client-store": "0.2.2-rc.1",
57
+ "@deepseek-ai/dsh-client-ui-layout": "^0.2.2-rc.1",
58
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-rc.1",
59
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.1",
60
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.1",
61
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.1",
62
+ "@deepseek-ai/dsh-client-ui-sidebar-right": "^0.2.2-rc.1",
63
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.1",
64
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.1",
65
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.1",
66
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
67
+ "@deepseek-ai/schemastery": "^3.19.0",
68
68
  "@types/node": "^22.20.0",
69
69
  "@types/react": "~18.3.1",
70
70
  "@types/react-dom": "^18.3.5",