dsh-browser-plus 0.5.0 → 0.5.1
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/CHANGELOG.md +131 -144
- package/README.en.md +27 -8
- package/README.md +27 -8
- package/client/index.js +185 -0
- package/cordis.patch.yml +24 -0
- package/docs/README.md +1 -1
- package/docs/SOAK-CHECKLIST.md +1 -1
- package/docs/tool-reference.md +5 -3
- package/docs/user-guide.md +20 -4
- package/lib/browser/runtime.d.ts +14 -1
- package/lib/browser/runtime.js +28 -0
- package/lib/browser/types.d.ts +96 -6
- package/lib/browser-electron/chrome-state.d.ts +24 -0
- package/lib/browser-electron/entry.d.ts +12 -5
- package/lib/browser-electron/entry.js +5 -2
- package/lib/browser-electron/host-main.d.ts +2 -1
- package/lib/browser-electron/host-main.js +205 -8
- package/lib/browser-electron/page-chrome.js +249 -14
- package/lib/browser-electron/provider.d.ts +60 -2
- package/lib/browser-electron/provider.js +300 -50
- package/lib/browser-electron/remote-host.d.ts +3 -1
- package/lib/browser-electron/remote-host.js +42 -1
- package/lib/client.js +185 -0
- package/lib/command-browser/index.d.ts +20 -0
- package/lib/command-browser/index.js +35 -0
- package/lib/http-browser/index.d.ts +28 -0
- package/lib/http-browser/index.js +110 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/task-todos/index.d.ts +25 -0
- package/lib/task-todos/index.js +100 -0
- package/lib/tool-browser/index.js +190 -95
- package/package.json +27 -2
- package/scripts/build-client.mjs +20 -0
- package/scripts/smoke-browser-tools.mjs +84 -1
- package/scripts/smoke-chrome-world.mjs +6 -4
- package/scripts/test-orb-drag.mjs +83 -0
- package/src/browser/runtime.ts +36 -0
- package/src/browser/types.ts +98 -6
- package/src/browser-electron/chrome-state.ts +18 -0
- package/src/browser-electron/entry.ts +17 -7
- package/src/browser-electron/host-main.ts +207 -11
- package/src/browser-electron/page-chrome.ts +249 -14
- package/src/browser-electron/provider.ts +328 -50
- package/src/browser-electron/remote-host.ts +49 -2
- package/src/command-browser/index.ts +61 -0
- package/src/http-browser/index.ts +139 -0
- package/src/index.ts +13 -0
- package/src/task-todos/index.ts +114 -0
- package/src/tool-browser/index.ts +193 -96
package/lib/client.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-browser-plus — client half.
|
|
3
|
+
*
|
|
4
|
+
* One right-sidebar tab whose whole job is to put the shared browser window on
|
|
5
|
+
* screen: picking it from the rightbar's add list opens the window, and the
|
|
6
|
+
* panel keeps a button for raising it again. It is named after the plugin and
|
|
7
|
+
* carries the plugin's own mark, so it is not confused with the product's
|
|
8
|
+
* built-in browser tab. It talks to the plugin's own
|
|
9
|
+
* HTTP route (`src/http-browser/index.ts`), because a third-party client bundle
|
|
10
|
+
* has no generated Remote surface to call a server-side method through.
|
|
11
|
+
*
|
|
12
|
+
* This file is the browser bundle's source in the client-modules factory
|
|
13
|
+
* format: running it only registers the factory, and the module body runs when
|
|
14
|
+
* the plugin is first materialized. `scripts/build-client.mjs` copies it to
|
|
15
|
+
* `lib/client.js` — it is one file with no imports beyond the platform table,
|
|
16
|
+
* so no bundler is involved.
|
|
17
|
+
*/
|
|
18
|
+
window.__ModuleLoader__.load({
|
|
19
|
+
id: 'dsh-browser-plus',
|
|
20
|
+
factory: (require) => {
|
|
21
|
+
var module = { exports: {} }
|
|
22
|
+
var exports = module.exports
|
|
23
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
24
|
+
const React = require('react')
|
|
25
|
+
|
|
26
|
+
/** Implementation identity; also the key its body registers under. */
|
|
27
|
+
const IMPLEMENTATION_ID = 'dsh-browser-plus'
|
|
28
|
+
/** Tab kind: a page type, opened by kind and recognizing no address. */
|
|
29
|
+
const KIND = 'dsh-browser-plus'
|
|
30
|
+
const OPEN_PATH = '/api/dsh-browser-plus/open'
|
|
31
|
+
const STATUS_PATH = '/api/dsh-browser-plus/status'
|
|
32
|
+
|
|
33
|
+
const COPY = {
|
|
34
|
+
zh: {
|
|
35
|
+
title: 'DSH-Browser-Plus',
|
|
36
|
+
description: '打开共享浏览器窗口',
|
|
37
|
+
open: '打开浏览器窗口',
|
|
38
|
+
busy: '正在打开…',
|
|
39
|
+
opened: '浏览器窗口已打开。',
|
|
40
|
+
failed: '打开失败:',
|
|
41
|
+
tasks: (count) => (count > 0 ? '当前有 ' + String(count) + ' 个浏览器任务' : '还没有浏览器任务'),
|
|
42
|
+
},
|
|
43
|
+
en: {
|
|
44
|
+
title: 'DSH-Browser-Plus',
|
|
45
|
+
description: 'Open the shared browser window',
|
|
46
|
+
open: 'Open browser window',
|
|
47
|
+
busy: 'Opening…',
|
|
48
|
+
opened: 'The browser window is open.',
|
|
49
|
+
failed: 'Could not open it: ',
|
|
50
|
+
tasks: (count) => (count > 0 ? String(count) + ' browser task(s) open' : 'no browser task yet'),
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The panel's copy, read at render so a language switch needs no reload. */
|
|
55
|
+
function copy() {
|
|
56
|
+
try {
|
|
57
|
+
const declared = String(document.documentElement.getAttribute('lang') || navigator.language || '')
|
|
58
|
+
return declared.toLowerCase().indexOf('zh') === 0 ? COPY.zh : COPY.en
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return COPY.zh
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** POST the open endpoint; resolve to a message, never throw at the renderer. */
|
|
65
|
+
function requestOpen() {
|
|
66
|
+
return fetch(OPEN_PATH, { method: 'POST' }).then((response) => response.json().catch(() => null).then((body) => {
|
|
67
|
+
if (!response.ok || body === null || body.ok !== true) {
|
|
68
|
+
throw new Error(body !== null && typeof body.error === 'string' ? body.error : 'HTTP ' + String(response.status))
|
|
69
|
+
}
|
|
70
|
+
return true
|
|
71
|
+
}))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Read the task count for the status line; a failure is not worth a notice. */
|
|
75
|
+
function requestStatus() {
|
|
76
|
+
return fetch(STATUS_PATH).then((response) => response.json()).then((body) => (body !== null && body.ok === true && typeof body.tasks === 'number' ? body.tasks : null)).catch(() => null)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The plugin's own mark, inlined from assets/dsh-browser-plus.svg so the
|
|
81
|
+
* bundle keeps requiring nothing but the platform table. The plate is part
|
|
82
|
+
* of the art: it is what keeps a white outline legible on a light surface.
|
|
83
|
+
*/
|
|
84
|
+
function BrowserIcon(props) {
|
|
85
|
+
const size = props !== null && props !== undefined && props.size !== undefined ? props.size : 36
|
|
86
|
+
return React.createElement('svg', {
|
|
87
|
+
width: size,
|
|
88
|
+
height: size,
|
|
89
|
+
className: props !== null && props !== undefined ? props.className : undefined,
|
|
90
|
+
'aria-hidden': 'true',
|
|
91
|
+
viewBox: '0 0 256 256',
|
|
92
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
93
|
+
},
|
|
94
|
+
React.createElement('rect', { x: 10, y: 10, width: 236, height: 236, rx: 54, fill: '#202124' }),
|
|
95
|
+
React.createElement('g', { transform: 'translate(20 20) scale(9)', fill: 'none', stroke: '#ffffff', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round' },
|
|
96
|
+
React.createElement('rect', { x: 3.25, y: 4.75, width: 17.5, height: 14.5, rx: 3.25 }),
|
|
97
|
+
React.createElement('path', { d: 'M3.25 9.4h17.5' }),
|
|
98
|
+
React.createElement('circle', { cx: 6.15, cy: 7.05, r: 0.9, fill: '#ffffff', stroke: 'none' }),
|
|
99
|
+
React.createElement('circle', { cx: 8.75, cy: 7.05, r: 0.9, fill: '#ffffff', stroke: 'none' }),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const PANEL_STYLE = {
|
|
105
|
+
display: 'flex',
|
|
106
|
+
flexDirection: 'column',
|
|
107
|
+
gap: '10px',
|
|
108
|
+
padding: '16px',
|
|
109
|
+
color: 'inherit',
|
|
110
|
+
font: 'inherit',
|
|
111
|
+
}
|
|
112
|
+
const BUTTON_STYLE = {
|
|
113
|
+
alignSelf: 'flex-start',
|
|
114
|
+
padding: '6px 14px',
|
|
115
|
+
border: '1px solid currentColor',
|
|
116
|
+
borderRadius: '6px',
|
|
117
|
+
background: 'transparent',
|
|
118
|
+
color: 'inherit',
|
|
119
|
+
font: 'inherit',
|
|
120
|
+
cursor: 'pointer',
|
|
121
|
+
}
|
|
122
|
+
const NOTE_STYLE = { opacity: 0.7, fontSize: '12px' }
|
|
123
|
+
|
|
124
|
+
/** The panel body: it opens the window as soon as it is mounted. */
|
|
125
|
+
function BrowserPanel() {
|
|
126
|
+
const t = copy()
|
|
127
|
+
const [busy, setBusy] = React.useState(false)
|
|
128
|
+
const [note, setNote] = React.useState(null)
|
|
129
|
+
const [tasks, setTasks] = React.useState(null)
|
|
130
|
+
|
|
131
|
+
const open = React.useCallback(() => {
|
|
132
|
+
setBusy(true)
|
|
133
|
+
setNote(null)
|
|
134
|
+
requestOpen()
|
|
135
|
+
.then(() => {
|
|
136
|
+
setBusy(false)
|
|
137
|
+
setNote({ ok: true, text: t.opened })
|
|
138
|
+
return requestStatus().then((count) => setTasks(count))
|
|
139
|
+
})
|
|
140
|
+
.catch((error) => {
|
|
141
|
+
setBusy(false)
|
|
142
|
+
setNote({ ok: false, text: t.failed + String(error !== null && error !== undefined && error.message !== undefined ? error.message : error) })
|
|
143
|
+
})
|
|
144
|
+
}, [t])
|
|
145
|
+
|
|
146
|
+
// The tab itself is the affordance: opening it opens the window.
|
|
147
|
+
React.useEffect(() => {
|
|
148
|
+
open()
|
|
149
|
+
requestStatus().then((count) => setTasks(count))
|
|
150
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
151
|
+
}, [])
|
|
152
|
+
|
|
153
|
+
return React.createElement('div', { style: PANEL_STYLE },
|
|
154
|
+
React.createElement('button', { type: 'button', style: BUTTON_STYLE, disabled: busy, onClick: open }, busy ? t.busy : t.open),
|
|
155
|
+
note !== null ? React.createElement('div', { style: NOTE_STYLE, role: 'status' }, note.text) : null,
|
|
156
|
+
tasks !== null ? React.createElement('div', { style: NOTE_STYLE }, t.tasks(tasks)) : null,
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
exports.inject = ['slots', 'sidebarRightTabs']
|
|
161
|
+
exports.apply = (ctx) => {
|
|
162
|
+
const slots = ctx.get('slots')
|
|
163
|
+
const tabs = ctx.get('sidebarRightTabs')
|
|
164
|
+
if (slots === undefined || tabs === undefined) return
|
|
165
|
+
ctx.effect(() => tabs.register({
|
|
166
|
+
id: IMPLEMENTATION_ID,
|
|
167
|
+
kind: KIND,
|
|
168
|
+
priority: 'extension',
|
|
169
|
+
title: () => copy().title,
|
|
170
|
+
guide: [{
|
|
171
|
+
id: 'open',
|
|
172
|
+
order: 40,
|
|
173
|
+
title: () => copy().title,
|
|
174
|
+
description: () => copy().description,
|
|
175
|
+
icon: BrowserIcon,
|
|
176
|
+
}],
|
|
177
|
+
}), 'dsh-browser-plus:type')
|
|
178
|
+
ctx.effect(() => slots.inject('sidebar.right.pane.tab', () => slots.register({
|
|
179
|
+
name: 'sidebar.right.pane.tab',
|
|
180
|
+
key: IMPLEMENTATION_ID,
|
|
181
|
+
}, BrowserPanel)), 'dsh-browser-plus:body')
|
|
182
|
+
}
|
|
183
|
+
return module.exports
|
|
184
|
+
},
|
|
185
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-facing `/browser` command: puts the shared browser window on screen
|
|
3
|
+
* without going through the model.
|
|
4
|
+
*
|
|
5
|
+
* The window is normally created as a side effect of the first browser tool
|
|
6
|
+
* call, so a human who wants to browse (or take over) before any agent call had
|
|
7
|
+
* no way to raise it. `/browser` is that way in: it spawns the host and shows
|
|
8
|
+
* the window when nothing is open, and raises the existing window otherwise.
|
|
9
|
+
*
|
|
10
|
+
* The command registry is declared structurally instead of imported from
|
|
11
|
+
* `@deepseek-ai/dsh-commands`: the registry is a peer service the profile
|
|
12
|
+
* provides, and depending on that package only for its types would make this
|
|
13
|
+
* row fail to load wherever the service exists but the dependency does not.
|
|
14
|
+
* @module dsh-browser-plus/command-browser
|
|
15
|
+
*/
|
|
16
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
17
|
+
export declare const name = "browser-command";
|
|
18
|
+
export declare const inject: string[];
|
|
19
|
+
/** Register the command. */
|
|
20
|
+
export declare function apply(ctx: Context, _config?: unknown): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-facing `/browser` command: puts the shared browser window on screen
|
|
3
|
+
* without going through the model.
|
|
4
|
+
*
|
|
5
|
+
* The window is normally created as a side effect of the first browser tool
|
|
6
|
+
* call, so a human who wants to browse (or take over) before any agent call had
|
|
7
|
+
* no way to raise it. `/browser` is that way in: it spawns the host and shows
|
|
8
|
+
* the window when nothing is open, and raises the existing window otherwise.
|
|
9
|
+
*
|
|
10
|
+
* The command registry is declared structurally instead of imported from
|
|
11
|
+
* `@deepseek-ai/dsh-commands`: the registry is a peer service the profile
|
|
12
|
+
* provides, and depending on that package only for its types would make this
|
|
13
|
+
* row fail to load wherever the service exists but the dependency does not.
|
|
14
|
+
* @module dsh-browser-plus/command-browser
|
|
15
|
+
*/
|
|
16
|
+
export const name = 'browser-command';
|
|
17
|
+
export const inject = ['browser', 'commands'];
|
|
18
|
+
/** Register the command. */
|
|
19
|
+
export function apply(ctx, _config = {}) {
|
|
20
|
+
const commands = ctx.commands;
|
|
21
|
+
commands.register({
|
|
22
|
+
name: 'browser',
|
|
23
|
+
description: '打开并前置共享浏览器窗口',
|
|
24
|
+
handler: async () => {
|
|
25
|
+
try {
|
|
26
|
+
await ctx.browser.ensureWindowVisible();
|
|
27
|
+
return { kind: 'success', text: '浏览器窗口已打开。' };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
31
|
+
return { kind: 'error', text: `打开浏览器窗口失败:${detail}` };
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP bridge the browser panel talks to.
|
|
3
|
+
*
|
|
4
|
+
* The panel lives in the Web GUI, the window lives in the DSH process, and a
|
|
5
|
+
* client bundle has no way to call a server-side plugin method directly: the
|
|
6
|
+
* generated Remote/Typert surface exists for product packages, not for a
|
|
7
|
+
* third-party plugin built with plain tsc. The DSH web server, however, is a
|
|
8
|
+
* service this plugin can register routes on, and the GUI is served from that
|
|
9
|
+
* same origin — so one POST is the whole bridge.
|
|
10
|
+
*
|
|
11
|
+
* Routes (all JSON, no-store):
|
|
12
|
+
* POST /api/dsh-browser-plus/open -> { ok: true } once the window is up
|
|
13
|
+
* GET /api/dsh-browser-plus/status -> { ok: true, tasks: number }
|
|
14
|
+
*
|
|
15
|
+
* The `webServer` service is declared structurally rather than imported from
|
|
16
|
+
* `@deepseek-ai/dsh-host-webserver`: this row must load wherever the service
|
|
17
|
+
* exists, without taking a build-time dependency on the package that owns it.
|
|
18
|
+
* @module dsh-browser-plus/http-browser
|
|
19
|
+
*/
|
|
20
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
21
|
+
/** Absolute path of the "open the window" endpoint. */
|
|
22
|
+
export declare const OPEN_PATH = "/api/dsh-browser-plus/open";
|
|
23
|
+
/** Absolute path of the status endpoint. */
|
|
24
|
+
export declare const STATUS_PATH = "/api/dsh-browser-plus/status";
|
|
25
|
+
export declare const name = "browser-http";
|
|
26
|
+
export declare const inject: string[];
|
|
27
|
+
/** Register the browser-panel bridge. */
|
|
28
|
+
export declare function apply(ctx: Context, _config?: unknown): void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP bridge the browser panel talks to.
|
|
3
|
+
*
|
|
4
|
+
* The panel lives in the Web GUI, the window lives in the DSH process, and a
|
|
5
|
+
* client bundle has no way to call a server-side plugin method directly: the
|
|
6
|
+
* generated Remote/Typert surface exists for product packages, not for a
|
|
7
|
+
* third-party plugin built with plain tsc. The DSH web server, however, is a
|
|
8
|
+
* service this plugin can register routes on, and the GUI is served from that
|
|
9
|
+
* same origin — so one POST is the whole bridge.
|
|
10
|
+
*
|
|
11
|
+
* Routes (all JSON, no-store):
|
|
12
|
+
* POST /api/dsh-browser-plus/open -> { ok: true } once the window is up
|
|
13
|
+
* GET /api/dsh-browser-plus/status -> { ok: true, tasks: number }
|
|
14
|
+
*
|
|
15
|
+
* The `webServer` service is declared structurally rather than imported from
|
|
16
|
+
* `@deepseek-ai/dsh-host-webserver`: this row must load wherever the service
|
|
17
|
+
* exists, without taking a build-time dependency on the package that owns it.
|
|
18
|
+
* @module dsh-browser-plus/http-browser
|
|
19
|
+
*/
|
|
20
|
+
/** Absolute path of the "open the window" endpoint. */
|
|
21
|
+
export const OPEN_PATH = '/api/dsh-browser-plus/open';
|
|
22
|
+
/** Absolute path of the status endpoint. */
|
|
23
|
+
export const STATUS_PATH = '/api/dsh-browser-plus/status';
|
|
24
|
+
export const name = 'browser-http';
|
|
25
|
+
export const inject = ['browser', 'webServer'];
|
|
26
|
+
/** Write one JSON response. */
|
|
27
|
+
function sendJson(res, status, payload) {
|
|
28
|
+
res.statusCode = status;
|
|
29
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
30
|
+
res.setHeader('cache-control', 'no-store');
|
|
31
|
+
res.end(JSON.stringify(payload));
|
|
32
|
+
}
|
|
33
|
+
/** Read one request header as a single string. */
|
|
34
|
+
function headerValue(req, name) {
|
|
35
|
+
const raw = req.headers?.[name];
|
|
36
|
+
return Array.isArray(raw) ? (raw[0] ?? '') : (raw ?? '');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Refuse a request that a page on another site made.
|
|
40
|
+
*
|
|
41
|
+
* These two endpoints are unauthenticated and only open a window / report a task
|
|
42
|
+
* count — but any web page can POST to localhost without a preflight, so without
|
|
43
|
+
* this check a random site could pop our browser window open. The panel's own
|
|
44
|
+
* fetch is same-origin, so its Origin always matches the Host we were reached on.
|
|
45
|
+
*/
|
|
46
|
+
function fromAnotherSite(req) {
|
|
47
|
+
const origin = headerValue(req, 'origin');
|
|
48
|
+
if (origin === '')
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
const parsed = new URL(origin);
|
|
52
|
+
const host = headerValue(req, 'host');
|
|
53
|
+
return host === '' || parsed.host !== host;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** One line for the panel to show; never a stack. */
|
|
60
|
+
function describe(error) {
|
|
61
|
+
return error instanceof Error ? error.message : String(error);
|
|
62
|
+
}
|
|
63
|
+
/** Register the browser-panel bridge. */
|
|
64
|
+
export function apply(ctx, _config = {}) {
|
|
65
|
+
const server = ctx.webServer;
|
|
66
|
+
if (server === undefined)
|
|
67
|
+
return;
|
|
68
|
+
ctx.effect(() => server.register({
|
|
69
|
+
kind: 'exact',
|
|
70
|
+
path: OPEN_PATH,
|
|
71
|
+
handler: async (req, res) => {
|
|
72
|
+
if (req.method !== 'POST') {
|
|
73
|
+
sendJson(res, 405, { ok: false, error: 'method not allowed' });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (fromAnotherSite(req)) {
|
|
77
|
+
sendJson(res, 403, { ok: false, error: 'cross-site request refused' });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await ctx.browser.ensureWindowVisible();
|
|
82
|
+
sendJson(res, 200, { ok: true });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
sendJson(res, 500, { ok: false, error: describe(error) });
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
}), 'dsh-browser-plus:open route');
|
|
89
|
+
ctx.effect(() => server.register({
|
|
90
|
+
kind: 'exact',
|
|
91
|
+
path: STATUS_PATH,
|
|
92
|
+
handler: async (req, res) => {
|
|
93
|
+
if (req.method !== 'GET') {
|
|
94
|
+
sendJson(res, 405, { ok: false, error: 'method not allowed' });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (fromAnotherSite(req)) {
|
|
98
|
+
sendJson(res, 403, { ok: false, error: 'cross-site request refused' });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const tasks = await ctx.browser.listTasks();
|
|
103
|
+
sendJson(res, 200, { ok: true, tasks: tasks.length });
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
sendJson(res, 500, { ok: false, error: describe(error) });
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
}), 'dsh-browser-plus:status route');
|
|
110
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,8 +6,19 @@
|
|
|
6
6
|
* - `dsh-browser-plus/tool-browser` -> the model-facing browser_* tools
|
|
7
7
|
* This root entry only re-exports for programmatic use; the loader rows are
|
|
8
8
|
* the composition surface.
|
|
9
|
+
*
|
|
10
|
+
* It IS also mounted as a row of its own — an empty one — because the client
|
|
11
|
+
* module system only scans Loader rows whose specifier is an exact package root
|
|
12
|
+
* (`exactPackageSpecifier` in `@deepseek-ai/dsh-client-modules` returns
|
|
13
|
+
* undefined for a subpath). Without a root row the package's `dsh.client`
|
|
14
|
+
* declaration is never read and the browser panel never reaches the GUI, no
|
|
15
|
+
* matter how many subpath rows the bundle patch adds.
|
|
9
16
|
* @module dsh-browser-plus
|
|
10
17
|
*/
|
|
18
|
+
/** Plugin name for the root row. */
|
|
19
|
+
export declare const name = "browser-plus";
|
|
20
|
+
/** The root row has no behaviour of its own; it exists to carry the package identity. */
|
|
21
|
+
export declare function apply(): void;
|
|
11
22
|
export { BrowserError } from './browser/types.ts';
|
|
12
23
|
export type { BrowserChallenge, BrowserContentFormat, BrowserControlOwner, BrowserContentRequest, BrowserContentResult, BrowserDragRequest, BrowserDragResult, BrowserExecuteRequest, BrowserPointerResult, BrowserPointerTarget, BrowserExecuteResult, BrowserFillField, BrowserFillRequest, BrowserFillResult, BrowserHandoffState, BrowserNavigateRequest, BrowserOpenRequest, BrowserProvider, BrowserRefRequest, BrowserScreenshotRequest, BrowserScrollIntoViewRequest, BrowserScrollRequest, BrowserScrollResult, BrowserScreenshotResult, BrowserSessionId, BrowserSnapshotElement, BrowserSnapshotResult, BrowserTab, BrowserTaskInfo, BrowserTaskStatus, BrowserTaskUpdate, BrowserTypeRequest, ExportedCookie, } from './browser/types.ts';
|
|
13
24
|
export { BrowserRuntime } from './browser/runtime.ts';
|
package/lib/index.js
CHANGED
|
@@ -6,8 +6,19 @@
|
|
|
6
6
|
* - `dsh-browser-plus/tool-browser` -> the model-facing browser_* tools
|
|
7
7
|
* This root entry only re-exports for programmatic use; the loader rows are
|
|
8
8
|
* the composition surface.
|
|
9
|
+
*
|
|
10
|
+
* It IS also mounted as a row of its own — an empty one — because the client
|
|
11
|
+
* module system only scans Loader rows whose specifier is an exact package root
|
|
12
|
+
* (`exactPackageSpecifier` in `@deepseek-ai/dsh-client-modules` returns
|
|
13
|
+
* undefined for a subpath). Without a root row the package's `dsh.client`
|
|
14
|
+
* declaration is never read and the browser panel never reaches the GUI, no
|
|
15
|
+
* matter how many subpath rows the bundle patch adds.
|
|
9
16
|
* @module dsh-browser-plus
|
|
10
17
|
*/
|
|
18
|
+
/** Plugin name for the root row. */
|
|
19
|
+
export const name = 'browser-plus';
|
|
20
|
+
/** The root row has no behaviour of its own; it exists to carry the package identity. */
|
|
21
|
+
export function apply() { }
|
|
11
22
|
export { BrowserError } from "./browser/types.js";
|
|
12
23
|
export { BrowserRuntime } from "./browser/runtime.js";
|
|
13
24
|
export { ElectronBrowserProvider } from "./browser-electron/provider.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge between the Agent's todo list and the shared browser window.
|
|
3
|
+
*
|
|
4
|
+
* DSH keeps each Agent's plan as a session projection (`todos`, written by
|
|
5
|
+
* `todo_write` and folded from `todo/write` events). The floating orb in the
|
|
6
|
+
* browser window renders that plan, but the browser host is a child process that
|
|
7
|
+
* can only see what the parent hands it — so this row subscribes to the
|
|
8
|
+
* projection change feed and mirrors the plan into the browser provider.
|
|
9
|
+
*
|
|
10
|
+
* Every dependency here is optional on purpose. A deployment without the
|
|
11
|
+
* projection registry, or without the todo tool mounted at all, must still get a
|
|
12
|
+
* working browser: the orb then simply has no plan to show and falls back to the
|
|
13
|
+
* task's own status and last browser action.
|
|
14
|
+
* @module dsh-browser-plus/task-todos
|
|
15
|
+
*/
|
|
16
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
17
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
18
|
+
export declare const name = "browser-task-todos";
|
|
19
|
+
/** The browser seam; the projection registry is injected optionally below. */
|
|
20
|
+
export declare const inject: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Register the bridge.
|
|
23
|
+
* @param ctx - plugin context carrying the browser seam.
|
|
24
|
+
*/
|
|
25
|
+
export declare function apply(ctx: Context): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge between the Agent's todo list and the shared browser window.
|
|
3
|
+
*
|
|
4
|
+
* DSH keeps each Agent's plan as a session projection (`todos`, written by
|
|
5
|
+
* `todo_write` and folded from `todo/write` events). The floating orb in the
|
|
6
|
+
* browser window renders that plan, but the browser host is a child process that
|
|
7
|
+
* can only see what the parent hands it — so this row subscribes to the
|
|
8
|
+
* projection change feed and mirrors the plan into the browser provider.
|
|
9
|
+
*
|
|
10
|
+
* Every dependency here is optional on purpose. A deployment without the
|
|
11
|
+
* projection registry, or without the todo tool mounted at all, must still get a
|
|
12
|
+
* working browser: the orb then simply has no plan to show and falls back to the
|
|
13
|
+
* task's own status and last browser action.
|
|
14
|
+
* @module dsh-browser-plus/task-todos
|
|
15
|
+
*/
|
|
16
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
17
|
+
export const name = 'browser-task-todos';
|
|
18
|
+
/** The browser seam; the projection registry is injected optionally below. */
|
|
19
|
+
export const inject = ['browser'];
|
|
20
|
+
/** Keep at most this many entries — the orb shows a short list, not a backlog. */
|
|
21
|
+
const MAX_ITEMS = 40;
|
|
22
|
+
/** Keep one entry short enough to read in a popover. */
|
|
23
|
+
const MAX_CONTENT = 160;
|
|
24
|
+
/**
|
|
25
|
+
* Normalize whatever the projection holds into the orb's three states. Anything
|
|
26
|
+
* unrecognized becomes `pending` rather than being dropped: a plan line the UI
|
|
27
|
+
* cannot classify is still a line the human asked to see.
|
|
28
|
+
* @param value - the projection's raw `todos` value.
|
|
29
|
+
* @returns the entries to forward.
|
|
30
|
+
*/
|
|
31
|
+
function normalize(value) {
|
|
32
|
+
if (!Array.isArray(value))
|
|
33
|
+
return [];
|
|
34
|
+
const items = [];
|
|
35
|
+
for (const raw of value) {
|
|
36
|
+
const entry = raw;
|
|
37
|
+
if (typeof entry?.content !== 'string')
|
|
38
|
+
continue;
|
|
39
|
+
const content = entry.content.trim();
|
|
40
|
+
if (content === '')
|
|
41
|
+
continue;
|
|
42
|
+
const status = entry.status === 'completed' || entry.status === 'in_progress' ? entry.status : 'pending';
|
|
43
|
+
items.push({ content: content.slice(0, MAX_CONTENT), status });
|
|
44
|
+
if (items.length >= MAX_ITEMS)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return items;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Register the bridge.
|
|
51
|
+
* @param ctx - plugin context carrying the browser seam.
|
|
52
|
+
*/
|
|
53
|
+
export function apply(ctx) {
|
|
54
|
+
// 只在**失败**路径上留话:这条链横跨「会话投影 → 桥接行 → provider → 宿主 → 页面」,
|
|
55
|
+
// 任一环断掉在页面上都只表现为「球上没有清单」,正常路径一声不响。
|
|
56
|
+
const trace = (line) => { try {
|
|
57
|
+
process.stderr.write('[browser-task-todos] ' + line + '\n');
|
|
58
|
+
}
|
|
59
|
+
catch { /* no stderr */ } };
|
|
60
|
+
const browser = ctx.browser;
|
|
61
|
+
if (browser === undefined || typeof browser.pushTaskTodos !== 'function') {
|
|
62
|
+
trace('skip: the browser seam has no pushTaskTodos');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const push = browser.pushTaskTodos.bind(browser);
|
|
66
|
+
// `ctx.inject` keeps the row loadable when the registry is absent: the
|
|
67
|
+
// callback simply never runs and the browser keeps working without a plan.
|
|
68
|
+
ctx.inject(['sessionProjections'], (scoped) => {
|
|
69
|
+
const registry = scoped.sessionProjections;
|
|
70
|
+
if (registry === undefined || typeof registry.onChanged !== 'function') {
|
|
71
|
+
trace('sessionProjections arrived without onChanged');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// 每个会话最后一份清单。宿主重启会丢掉它内存里那份,而桥接只在**变化**时推 ——
|
|
75
|
+
// 存一份就能在「这个会话又发生了什么」时顺手补推(见下面的 !isTodos 分支)。
|
|
76
|
+
const lastTodos = new Map();
|
|
77
|
+
const off = registry.onChanged((session, key, value) => {
|
|
78
|
+
const taskKey = typeof session?.id === 'string' ? session.id : '';
|
|
79
|
+
if (taskKey === '')
|
|
80
|
+
return;
|
|
81
|
+
if (key !== 'todos') {
|
|
82
|
+
// 该会话的**其它**投影变了 —— 说明它活着,把手里那份计划补推一次。
|
|
83
|
+
// 这覆盖「DSH 重启后 / 宿主重启后球上一直空着」:只要会话再有任何活动,清单就回来。
|
|
84
|
+
const known = lastTodos.get(taskKey);
|
|
85
|
+
if (known !== undefined)
|
|
86
|
+
void push(taskKey, known).catch(() => undefined);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// The tool layer keys browser tasks by the calling Agent's id, which is the
|
|
90
|
+
// session id — so a plan written by an Agent lands on that Agent's task.
|
|
91
|
+
const todos = normalize(value);
|
|
92
|
+
lastTodos.set(taskKey, todos);
|
|
93
|
+
void push(taskKey, todos).catch(() => undefined);
|
|
94
|
+
});
|
|
95
|
+
// 监听器挂在 registry 自己的 fiber 上,插件被卸载/重载时要自己摘掉,
|
|
96
|
+
// 否则会残留一条绑在旧 seam 上的推送(review 报的 L5)。
|
|
97
|
+
if (typeof off === 'function')
|
|
98
|
+
ctx.effect(() => off);
|
|
99
|
+
});
|
|
100
|
+
}
|