dsh-inner-browser-use 0.35.1 → 0.35.2
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.zh.md +1 -1
- package/index.js +72 -3
- package/package.json +1 -1
- package/tools.js +13 -1
package/README.zh.md
CHANGED
|
@@ -18,7 +18,7 @@ profile,不是产品自带的那个浏览页签:右栏放的是它的画面
|
|
|
18
18
|
| `browser_type` | 往焦点输入框输入文字,也可以先点一个编号控件。中文整段送进去。`submit: true` 回车提交。 |
|
|
19
19
|
| `browser_key` | 按一个键:Enter、Tab、Escape、Backspace、Delete、上下左右、Home、End、PageUp、PageDown。 |
|
|
20
20
|
| `browser_scroll` | 在页面中心滚轮,也可以指定 `x`/`y`。`dy: 600` 约一屏。 |
|
|
21
|
-
| `browser_shot` |
|
|
21
|
+
| `browser_shot` | 存一张 PNG 到 `~/.dsh/inner-browser-use/screenshots`,返回路径;`region: [x, y, w, h]` 只截一块(游戏、图表、看局部)。 |
|
|
22
22
|
| `browser_state` | 报浏览器在不在跑、用的哪个 profile、地址、标题,以及有几个右栏在看它。 |
|
|
23
23
|
|
|
24
24
|
点、输入、按键之后的那一行会多一句结果:`· navigated to …`(换页了)、`· content changed`(页内有变化)、`· no visible change`(点了没动)、Flash 页则是 `· screen updated` / `· no frame change`;`read: true` 时不再多说。
|
package/index.js
CHANGED
|
@@ -117,6 +117,11 @@ export class Bridge {
|
|
|
117
117
|
is not on screen has no stream, so a push at ask time is lost; remembering
|
|
118
118
|
the ask is what makes the mirror appear when the person returns. */
|
|
119
119
|
this.wanted = { session: '', at: 0 }
|
|
120
|
+
/* Frame streams by chat. A close can arrive while a stream is still
|
|
121
|
+
attaching, so closing the mirror hangs up what that chat started: a
|
|
122
|
+
browser nobody watches is what lets it go to rest. */
|
|
123
|
+
/** @type {Map<string, Set<() => void>>} */
|
|
124
|
+
this.viewers = new Map()
|
|
120
125
|
/* A running plugin keeps the note; a bare Bridge in a test does not. */
|
|
121
126
|
this.persist = options.persist === true
|
|
122
127
|
const kept = this.persist ? readMirror() : { owner: '', session: '', at: 0 }
|
|
@@ -208,6 +213,42 @@ export class Bridge {
|
|
|
208
213
|
return [...this.seats.keys()]
|
|
209
214
|
}
|
|
210
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Remember one open frame stream so the chat can hang it up later.
|
|
218
|
+
* @param {string} sessionId - chat drawing the mirror.
|
|
219
|
+
* @param {() => void} off - ends that one stream.
|
|
220
|
+
*/
|
|
221
|
+
watch(sessionId, off) {
|
|
222
|
+
const id = this.canon(sessionId)
|
|
223
|
+
if (id === '' || typeof off !== 'function') return
|
|
224
|
+
const set = this.viewers.get(id) ?? new Set()
|
|
225
|
+
set.add(off)
|
|
226
|
+
/* A tab that reloads faster than its old socket closes must not pile up
|
|
227
|
+
streams: the oldest goes, which is the one no page is reading. */
|
|
228
|
+
while (set.size > 4) {
|
|
229
|
+
const oldest = set.values().next().value
|
|
230
|
+
set.delete(oldest)
|
|
231
|
+
try { oldest() } catch { /* a stream already gone is already gone */ }
|
|
232
|
+
}
|
|
233
|
+
this.viewers.set(id, set)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Hang up every frame stream one chat started.
|
|
238
|
+
* @param {string} sessionId - chat whose streams go away.
|
|
239
|
+
* @returns {number} how many streams were hanging up.
|
|
240
|
+
*/
|
|
241
|
+
unwatch(sessionId) {
|
|
242
|
+
const id = this.canon(sessionId)
|
|
243
|
+
const set = this.viewers.get(id)
|
|
244
|
+
if (set === undefined) return 0
|
|
245
|
+
this.viewers.delete(id)
|
|
246
|
+
for (const off of set) {
|
|
247
|
+
try { off() } catch { /* a stream already gone is already gone */ }
|
|
248
|
+
}
|
|
249
|
+
return set.size
|
|
250
|
+
}
|
|
251
|
+
|
|
211
252
|
/**
|
|
212
253
|
* Give the mirror up: the person closed the column, so the chat stops owning
|
|
213
254
|
* it and no keepalive may ask for it again. Ownership is what the column
|
|
@@ -219,6 +260,9 @@ export class Bridge {
|
|
|
219
260
|
const id = this.canon(sessionId)
|
|
220
261
|
if (id === '') return false
|
|
221
262
|
const held = this.owner === id || this.wanted.session === id
|
|
263
|
+
/* The picture goes with the ask: a stream left attached after the column
|
|
264
|
+
closed keeps the browser awake with nobody looking at it. */
|
|
265
|
+
this.unwatch(id)
|
|
222
266
|
this.wanted = { session: '', at: 0 }
|
|
223
267
|
if (this.owner === id) this.owner = ''
|
|
224
268
|
if (this.persist === true) writeMirror({ owner: this.owner, session: '', at: 0 })
|
|
@@ -229,6 +273,7 @@ export class Bridge {
|
|
|
229
273
|
dispose() {
|
|
230
274
|
for (const res of this.seats.values()) res.end()
|
|
231
275
|
this.seats.clear()
|
|
276
|
+
for (const id of [...this.viewers.keys()]) this.unwatch(id)
|
|
232
277
|
}
|
|
233
278
|
}
|
|
234
279
|
|
|
@@ -447,17 +492,33 @@ export function apply(ctx) {
|
|
|
447
492
|
res.socket?.setNoDelay?.(true)
|
|
448
493
|
res.write('retry: 2000\n\n')
|
|
449
494
|
/** @type {() => void} */
|
|
450
|
-
let
|
|
451
|
-
|
|
495
|
+
let off = () => {}
|
|
496
|
+
/* The stream can end while `watch` is still waiting for a browser to come
|
|
497
|
+
up: that close has to be remembered, or the sink added a second later is
|
|
498
|
+
never taken away and the browser is kept awake with nobody looking. */
|
|
499
|
+
let shut = false
|
|
500
|
+
let done = false
|
|
501
|
+
const hang = () => {
|
|
502
|
+
if (done) return
|
|
503
|
+
done = true
|
|
504
|
+
try { off() } catch { /* a stream already gone is already gone */ }
|
|
505
|
+
try { res.end() } catch { /* the socket may be the thing that closed */ }
|
|
506
|
+
}
|
|
507
|
+
const drop = () => {
|
|
508
|
+
shut = true
|
|
509
|
+
hang()
|
|
510
|
+
}
|
|
452
511
|
req.on('close', drop)
|
|
453
512
|
res.on('error', drop)
|
|
454
513
|
try {
|
|
455
|
-
|
|
514
|
+
off = await sidecar.watch((frame) => {
|
|
456
515
|
/* A viewer that cannot keep up loses frames instead of making the
|
|
457
516
|
page wait: the newest picture is the only one worth sending. */
|
|
458
517
|
if (res.writableLength > 3 * 1024 * 1024) return
|
|
459
518
|
res.write(`data: ${JSON.stringify(frame)}\n\n`)
|
|
460
519
|
}, streaming)
|
|
520
|
+
if (shut) hang()
|
|
521
|
+
else if (watching !== '') bridge.watch(watching, hang)
|
|
461
522
|
const info = await sidecar.state()
|
|
462
523
|
/* The pane needs one address to offer back when this chat's own page
|
|
463
524
|
went away; the state route answers the same question for the tab
|
|
@@ -725,6 +786,13 @@ export function apply(ctx) {
|
|
|
725
786
|
} else {
|
|
726
787
|
await sidecar.useTab(at, actor)
|
|
727
788
|
}
|
|
789
|
+
/* Closing the last page is this chat saying it is done with the mirror.
|
|
790
|
+
An owner left behind is what the next poll reads as "put my tab back":
|
|
791
|
+
the pane reappeared right after the person closed it. */
|
|
792
|
+
if (body.op === 'close') {
|
|
793
|
+
const left = await sidecar.chatState(actor)
|
|
794
|
+
if (left?.alive !== true && bridge.forget(actor) && sidecar.watched() === 0) sidecar.touch(REST_MS)
|
|
795
|
+
}
|
|
728
796
|
const tabs = await sidecar.windowsFor(actor)
|
|
729
797
|
json(200, { ok: true, tabs })
|
|
730
798
|
} catch (error) {
|
|
@@ -876,6 +944,7 @@ export function apply(ctx) {
|
|
|
876
944
|
'先接着用已有的页:`browser_view`(拿编号控件与可见文字)→ `browser_click` / `browser_type` → 再 `browser_view` 直到出现要的结果;页面要等就重复读,不 sleep。`browser_open` 只用于没有页、要换新地址、或要明确刷新;同一个地址不要反复重开。',
|
|
877
945
|
'页面很长、只想确认某句话/按钮在哪时用 `browser_find`,别整页读。要读长文(文章、文档、issue、论坛帖)用 `browser_read`:它回 Markdown,只花几十分之一的 token,链接可点;要动手点、填表才用 `browser_view` 拿编号。',
|
|
878
946
|
'要保存页面样子用 `browser_shot`,它会给出 PNG 绝对路径;要交给人看的文件,把绝对路径写进回复。',
|
|
947
|
+
'游戏、canvas、Flash:画面自己画的地方,`browser_view` 和 `browser_read` 读不出里面是什么。先 `browser_prepare` 拿画面位置、帧率、按键是否到达和下一步;之后看 `browser_shot` 的图定位置,按坐标点、按住、按组合键,再拍一张看画面变了没有——变了就是这一步生效了。当年用 Flash 做的游戏用 `browser_open` 带 `flash:true` 在栏内跑,不装播放器、不开窗口。',
|
|
879
948
|
].join('\n'),
|
|
880
949
|
}), 'dsh-inner-browser-use: system prompt section')
|
|
881
950
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inner-browser-use",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.2",
|
|
4
4
|
"description": "An agent-owned Chromium sidecar mirrored into the DeepSeek Harness right column: the agent drives it, the person watches and can take the mouse, and logins survive restarts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/tools.js
CHANGED
|
@@ -2738,13 +2738,14 @@ export function sidecarTools(sidecar, refs, host = {}) { // ui-copy-ignore
|
|
|
2738
2738
|
},
|
|
2739
2739
|
{
|
|
2740
2740
|
name: 'browser_shot', // ui-copy-ignore
|
|
2741
|
-
description: 'Save a PNG of the sidecar browser into the session folder and return its absolute path; when the current model accepts images the picture comes back in the same call, so a captcha, a chart or a broken layout can be looked at instead of guessed. Default is the visible screen; full takes the whole page, ref takes one control.',
|
|
2741
|
+
description: 'Save a PNG of the sidecar browser into the session folder and return its absolute path; when the current model accepts images the picture comes back in the same call, so a captcha, a chart or a broken layout can be looked at instead of guessed. Default is the visible screen; full takes the whole page, ref takes one control, region takes one box of it.',
|
|
2742
2742
|
parameters: {
|
|
2743
2743
|
type: 'object', // ui-copy-ignore
|
|
2744
2744
|
properties: {
|
|
2745
2745
|
name: { type: 'string', description: 'File name without extension.' },
|
|
2746
2746
|
full: { type: 'boolean', description: 'The whole page, not just the screen.' },
|
|
2747
2747
|
ref: { type: 'integer', description: 'One control from browser_view.' },
|
|
2748
|
+
region: { type: 'array', items: { type: 'number' }, description: 'One box instead of the whole screen: [x, y, width, height] in page pixels, the same numbers browser_prepare and browser_find report.' },
|
|
2748
2749
|
scale: { type: 'integer', description: 'Pixel ratio. Default 1; 2 is sharper and heavier.' },
|
|
2749
2750
|
},
|
|
2750
2751
|
additionalProperties: false,
|
|
@@ -2766,6 +2767,17 @@ export function sidecarTools(sidecar, refs, host = {}) { // ui-copy-ignore
|
|
|
2766
2767
|
const said = await withRead(async (page) => {
|
|
2767
2768
|
const scale = Math.max(1, Math.min(3, Number(args?.scale ?? 1)))
|
|
2768
2769
|
let clip = undefined
|
|
2770
|
+
/* A game or a chart does not need the whole screen: one box costs a
|
|
2771
|
+
fraction of the picture, and a picture is billed by area. */
|
|
2772
|
+
if (args?.ref === undefined && Array.isArray(args?.region) && args.region.length === 4) {
|
|
2773
|
+
const box = args.region.map((part) => Number(part))
|
|
2774
|
+
clip = {
|
|
2775
|
+
x: Math.max(0, Math.round(Number.isFinite(box[0]) ? box[0] : 0)),
|
|
2776
|
+
y: Math.max(0, Math.round(Number.isFinite(box[1]) ? box[1] : 0)),
|
|
2777
|
+
width: Math.max(8, Math.min(4000, Math.round(Number.isFinite(box[2]) ? box[2] : 0) || 8)),
|
|
2778
|
+
height: Math.max(8, Math.min(4000, Math.round(Number.isFinite(box[3]) ? box[3] : 0) || 8)),
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2769
2781
|
if (args?.ref !== undefined) {
|
|
2770
2782
|
const spot = await findAgain(page, Number(args.ref))
|
|
2771
2783
|
if (spot.gone === true) return spot.why ?? REF_GONE
|