@soffits/dsh-desktop-view 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +72 -2
- package/client.js +392 -0
- package/cordis.patch.yml +7 -0
- package/icon.svg +14 -0
- package/index.js +132 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +74 -4
- package/src/config.js +27 -0
- package/src/control.js +133 -0
- package/src/filter.js +56 -0
- package/src/http.js +161 -0
- package/src/keepalive.js +47 -0
- package/src/media.js +126 -0
- package/src/notify.js +103 -0
- package/src/proto.js +158 -0
- package/src/spacesd.js +122 -0
- package/src/status.js +178 -0
- package/src/tickets.js +120 -0
- package/src/viewer.js +246 -0
- package/viewer/page.css +20 -0
- package/viewer/page.html +26 -0
- package/viewer/page.js +117 -0
- package/viewer/session.js +197 -0
- package/viewer/shim.js +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sakina
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-desktop-view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Watch the desktop on the machine that runs your DeepSeek Harness agent, in real time through the Web UI, with audio, and step in when it needs help: a login via QR code, a CAPTCHA, or a dialog it wasn't ready for. Control also gives you the clipboard in both directions, along with file uploads and downloads.
|
|
4
|
+
|
|
5
|
+
The plugin passes the desktop stream along from cua-spacesd (the daemon that lives in Cua's desktop images) and from Cua's web viewer, using DSH's existing web server plus its login. No new port or subdomain is opened, and the daemon's credentials stay out of the browser.
|
|
6
|
+
|
|
7
|
+
## What you get
|
|
8
|
+
|
|
9
|
+
- **Desktop tab on the right sidebar.** You can launch it from the sidebar, or by clicking the session header's monitor button.
|
|
10
|
+
- **A page that fills the screen** at `/desktop-view/`, served from your DSH origin. It supports touch on a phone, and you can share a link to it. `?control=1` drops you right into control mode, so a stuck agent can send you one: it sends `/desktop-view/?control=1&help=1&session=<its session id>`, and once you give control back, the agent wakes up and keeps going.
|
|
11
|
+
- **By default, you watch.** You see the desktop and hear its audio, but clicks, keystrokes, clipboard, and files get blocked. "Take control" moves you in, and "Give back" puts you back in watch mode. Control also drops on its own after a stretch with no input, or if you close the view. If you only hide the Desktop tab (switch to another sidebar tab, collapse the sidebar, open another session), control stays with you; the stream goes quiet until you return.
|
|
12
|
+
- **The complete viewer once you take control**: mouse input, keyboard input, touch, an on-screen keyboard, clipboard sync, uploads by drag-and-drop, browsing and downloading files, display choice, scaling, and a microphone when the desktop has one.
|
|
13
|
+
- **The agent can tell when control is yours.** As long as you have it, the plugin drops a little JSON file for the agent to read before it works on the desktop, and each control change leaves a note in the session where the view was opened.
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- DSH 0.2.2-rc.1 or later.
|
|
18
|
+
- `cua-spacesd` 0.12 or later on the same machine, with the DSH process able to reach the env token (on Cua's desktop image that means `127.0.0.1:3211`, the token being at `/run/cua/env-token`).
|
|
19
|
+
- An up-to-date browser: Chrome, Edge, Firefox or Safari 17+. On mobile, both Safari for iOS and Chrome for Android are supported.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
From npm:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
dsh plugin --profile web add @soffits/dsh-desktop-view
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Alternatively, add the bundle through the Web UI's plugin manager. Restart DSH afterwards.
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
Every option appears as a field in the `desktop-view` plugin row.
|
|
34
|
+
|
|
35
|
+
| Setting | Default | Description |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| `endpoint` | `http://127.0.0.1:3211` | Where cua-spacesd listens. Keep it on loopback, since this address receives the env token. |
|
|
38
|
+
| `tokenFile` | `/run/cua/env-token` | File containing the env token; it stays on the server at all times. |
|
|
39
|
+
| `maxFps` | `30` | Frame rate requested by the viewer. Reducing it lowers CPU and bandwidth use. |
|
|
40
|
+
| `clipboard` | `true` | Clipboard syncing while you hold control. |
|
|
41
|
+
| `filesRoot` | `~` | Desktop folder you can browse, upload to and download from while you hold control. Leaving it empty disables file transfer. |
|
|
42
|
+
| `microphone` | `true` | Let your microphone reach the desktop while you hold control, where the desktop supports it. |
|
|
43
|
+
| `idleSeconds` | `120` | After this many seconds with no input, control reverts to watching. |
|
|
44
|
+
| `stateFile` | `/tmp/dsh-desktop-view/control.json` | Where the plugin writes the control state that the agent reads. |
|
|
45
|
+
| `notifyAgent` | `wake` | Notify the session that opened the view whenever control changes: `wake` (returning control wakes the agent if it is running or sent the help link; otherwise the note waits), `quiet` (notes always wait for the agent's next step), `off`. |
|
|
46
|
+
|
|
47
|
+
## What the agent can see
|
|
48
|
+
|
|
49
|
+
As an example, `stateFile` contains:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"controller": "user",
|
|
54
|
+
"since": "2026-11-08T12:00:00.000Z",
|
|
55
|
+
"sessionId": "01H…",
|
|
56
|
+
"updatedAt": "2026-11-08T12:00:04.120Z"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
When the owner holds control, `controller` is `"user"`; otherwise it is `null`. In the `null` case, the file also records the most recent reason control ended (`lastReason`: `released`, `idle`, `disconnected`, `replaced`, `stopped`). Any script or skill that drives the desktop should check it first and yield whenever the value is not `null`.
|
|
61
|
+
|
|
62
|
+
When `notifyAgent` is on, the session that opened a view gets a short note each time someone takes control (queued; the agent is never woken for it) and each time control returns. The return note wakes the agent only when it has to carry on: it is still running, or the view came from its help link (`help=1`). Otherwise it waits quietly for the agent's next step, so no turn starts for nothing. In the chat the notes appear as a small "Desktop control" row.
|
|
63
|
+
|
|
64
|
+
## Security
|
|
65
|
+
|
|
66
|
+
- All requests aimed at the plugin's paths pass through DSH's admission checks: the Host/Origin fence first, blocking cross-site and DNS-rebinding requests, then the browser's signed cookie, and only the owner gets in.
|
|
67
|
+
- The env token of cua-spacesd, along with the viewer tickets minted from it by the plugin, never leave the Host process. The browser keeps only short-lived relay tickets, which only work through this relay together with your DSH sign-in, and only for as long as the view (and, for control, your control) persists.
|
|
68
|
+
- The server decides what the browser is allowed to do. Watching uses a view-only viewer ticket, so input, clipboard and files are refused by the daemon itself; beyond that, only the media messages and calls that the viewer requires in each mode are forwarded by the relay. Only one view holds control at a time, and control ends once that view disappears.
|
|
69
|
+
- The plugin's own pages go out with `no-store`, no referrer, and a content security policy that is strict and same-origin.
|
|
70
|
+
|
|
71
|
+
## Licensing
|
|
72
|
+
|
|
73
|
+
MIT. The desktop viewer displayed is [Cua](https://github.com/trycua/cua)'s web viewer, which your own cua-spacesd serves at runtime under Cua's FSL-1.1-MIT licence; the plugin here is independent of Cua and neither includes nor redistributes that viewer.
|
package/client.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Browser half of dsh-desktop-view: a "Desktop" tab in the right sidebar
|
|
3
|
+
* (also offered in the sidebar's guide) and a button in the session header
|
|
4
|
+
* that opens and closes it.
|
|
5
|
+
*
|
|
6
|
+
* Plain JavaScript in DSH's Client module format (no build step). React
|
|
7
|
+
* comes from the page's module table. The tab shows the status bar (status,
|
|
8
|
+
* Take control / Give back) over a frame with the relayed Cua viewer; the
|
|
9
|
+
* status socket and the frame are driven by desktop-view/session.js, which
|
|
10
|
+
* the Host half serves and the full-screen page uses too. It is loaded when
|
|
11
|
+
* a tab first becomes visible. Styles use only the host theme tokens
|
|
12
|
+
* (--dsw-*), except the viewer's own dark stage.
|
|
13
|
+
*/
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: 'dsh-desktop-view',
|
|
16
|
+
factory(require) {
|
|
17
|
+
const React = require('react')
|
|
18
|
+
const h = React.createElement
|
|
19
|
+
const { useState, useEffect, useRef } = React
|
|
20
|
+
|
|
21
|
+
const NS = 'dsh-desktop-view'
|
|
22
|
+
const TAB_ID = 'dsh-desktop-view'
|
|
23
|
+
const KIND = 'desktop-view'
|
|
24
|
+
const STYLE_ID = 'dsh-desktop-view'
|
|
25
|
+
// Relative to the page, like DSH's own requests, so a sub-path deployment works.
|
|
26
|
+
const PREFIX = 'desktop-view/'
|
|
27
|
+
|
|
28
|
+
const en = {
|
|
29
|
+
title: 'Desktop',
|
|
30
|
+
'guide.description': 'Watch the agent\'s computer live, with sound, and take control when it needs a hand.',
|
|
31
|
+
'header.toggle': 'Agent\'s desktop',
|
|
32
|
+
'status.connecting': 'Connecting…',
|
|
33
|
+
'status.watching': 'Watching',
|
|
34
|
+
'status.watchingOther': 'Watching · controlled in another view',
|
|
35
|
+
'status.control': 'You are in control',
|
|
36
|
+
'status.error': 'Desktop unavailable',
|
|
37
|
+
'action.take': 'Take control',
|
|
38
|
+
'action.give': 'Give back',
|
|
39
|
+
'action.fullscreen': 'Open full screen',
|
|
40
|
+
'action.retry': 'Retry',
|
|
41
|
+
'ended.idle': 'Control returned to watching after a while without input.',
|
|
42
|
+
'ended.replaced': 'Control moved to another view.',
|
|
43
|
+
'ended.disconnected': 'The view disconnected, so control returned to watching.',
|
|
44
|
+
'ended.stopped': 'The desktop view stopped.',
|
|
45
|
+
'time.locale': 'en-US',
|
|
46
|
+
'notice.title': 'Desktop control',
|
|
47
|
+
'notice.taken': 'You took control',
|
|
48
|
+
'notice.released': 'You gave control back',
|
|
49
|
+
}
|
|
50
|
+
const zh = {
|
|
51
|
+
title: '桌面',
|
|
52
|
+
'guide.description': '实时查看智能体的电脑(含声音),需要时接管控制。',
|
|
53
|
+
'header.toggle': '智能体的桌面',
|
|
54
|
+
'status.connecting': '正在连接…',
|
|
55
|
+
'status.watching': '观看中',
|
|
56
|
+
'status.watchingOther': '观看中 · 另一个窗口正在控制',
|
|
57
|
+
'status.control': '你正在控制',
|
|
58
|
+
'status.error': '桌面暂时不可用',
|
|
59
|
+
'action.take': '接管控制',
|
|
60
|
+
'action.give': '交还控制',
|
|
61
|
+
'action.fullscreen': '全屏打开',
|
|
62
|
+
'action.retry': '重试',
|
|
63
|
+
'ended.idle': '一段时间没有操作,已回到观看模式。',
|
|
64
|
+
'ended.replaced': '控制已转到另一个窗口。',
|
|
65
|
+
'ended.disconnected': '连接中断,已回到观看模式。',
|
|
66
|
+
'ended.stopped': '桌面查看器已停止。',
|
|
67
|
+
'time.locale': 'zh-CN',
|
|
68
|
+
'notice.title': '桌面控制',
|
|
69
|
+
'notice.taken': '你接管了控制',
|
|
70
|
+
'notice.released': '你交还了控制',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// A monitor with a play mark: drawn for this plugin.
|
|
74
|
+
function IconDesktop({ size = 16, className }) {
|
|
75
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', className, 'aria-hidden': true, focusable: 'false' },
|
|
76
|
+
h('rect', { x: 1.5, y: 2.5, width: 13, height: 9, rx: 1.5, stroke: 'currentColor', strokeWidth: 1 }),
|
|
77
|
+
h('path', { d: 'M5.5 14H10.5M8 11.5V14', stroke: 'currentColor', strokeWidth: 1, strokeLinecap: 'round' }),
|
|
78
|
+
h('path', { d: 'M6.75 5.25V8.75L9.75 7L6.75 5.25Z', fill: 'currentColor' }))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const CSS = `
|
|
82
|
+
.ddv-tab{display:flex;flex-direction:column;height:100%;min-height:0;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
|
|
83
|
+
.ddv-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border-bottom:.5px solid var(--dsw-alias-border-l3);flex:none;flex-wrap:wrap;user-select:none;-webkit-user-select:none}
|
|
84
|
+
.ddv-status{display:inline-flex;align-items:center;gap:6px;min-width:0;color:var(--dsw-alias-label-secondary)}
|
|
85
|
+
.ddv-status:before{content:"";flex:none;width:7px;height:7px;border-radius:50%;background:var(--dsw-alias-label-caption)}
|
|
86
|
+
.ddv-status[data-tone=live]:before{background:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
87
|
+
.ddv-status[data-tone=control]{color:var(--dsw-alias-state-warning-primary,#d29922)}
|
|
88
|
+
.ddv-status[data-tone=control]:before{background:var(--dsw-alias-state-warning-primary,#d29922)}
|
|
89
|
+
.ddv-status[data-tone=error]:before{background:var(--dsw-alias-state-error-primary)}
|
|
90
|
+
.ddv-actions{display:inline-flex;gap:6px;flex:none}
|
|
91
|
+
.ddv-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 10px;border:none;border-radius:var(--dsw-radius-sm);font:inherit;font-size:12px;line-height:18px;cursor:pointer;color:var(--dsw-alias-label-primary);background:transparent;box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l3));text-decoration:none}
|
|
92
|
+
.ddv-btn:disabled{cursor:not-allowed;opacity:.4}
|
|
93
|
+
@media (pointer:coarse){.ddv-btn{height:40px;padding:0 14px;font-size:14px}.ddv-header{width:40px;height:40px}}
|
|
94
|
+
@media (hover:hover){.ddv-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}}
|
|
95
|
+
.ddv-primary{background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-on-color,#fff);box-shadow:none}
|
|
96
|
+
@media (hover:hover){.ddv-primary:hover:not(:disabled){background:var(--dsw-alias-state-business-primary);opacity:.9}}
|
|
97
|
+
.ddv-stage{position:relative;flex:1;min-height:0;display:flex;background:#000}
|
|
98
|
+
.ddv-stage[data-control=true]{box-shadow:inset 0 0 0 2px var(--dsw-alias-state-warning-primary,#d29922);padding:2px}
|
|
99
|
+
.ddv-frame{flex:1;width:100%;height:100%;border:0;display:block;background:#000}
|
|
100
|
+
.ddv-note{position:absolute;left:12px;right:12px;bottom:12px;margin:0;padding:8px 12px;border-radius:10px;background:var(--dsw-specific-sidebar-fill,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-secondary);font-size:12px}
|
|
101
|
+
.ddv-header{box-sizing:border-box;width:28px;height:28px;padding:0;display:inline-flex;align-items:center;justify-content:center;gap:4px;border:none;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;font-size:12px;line-height:18px}
|
|
102
|
+
.ddv-header svg{width:15px;height:15px}
|
|
103
|
+
.ddv-header:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
|
|
104
|
+
.ddv-header:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}
|
|
105
|
+
.ddv-tooltip{display:inline-flex;align-items:safe center;gap:8px;position:fixed;z-index:100;width:max-content;box-sizing:border-box;max-width:min(50vw,calc(100vw - 24px));padding:3px 7px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-tooltip-bg);color:var(--dsw-static-neutral-bluish-00);font-size:13px;line-height:20px;white-space:pre-line;overflow-wrap:break-word;pointer-events:none;transform:translate(-50%);animation:ddv-tooltip-in .15s var(--ds-ease-in-out)}
|
|
106
|
+
@keyframes ddv-tooltip-in{0%{opacity:0}}
|
|
107
|
+
.ddv-notice{border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-xl);background:var(--dsw-alias-turn-trigger-bg,var(--dsw-alias-markdown-code-block));color:var(--dsw-alias-label-tertiary);display:flex;align-items:center;gap:10px;padding:12px 16px;min-width:0}
|
|
108
|
+
.ddv-notice-icon{flex:none;display:inline-flex}
|
|
109
|
+
.ddv-notice-title{flex:none;font-size:var(--dsh-content-font-size,14px)}
|
|
110
|
+
.ddv-notice-summary{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:var(--dsw-font-xxs-12)}
|
|
111
|
+
.ddv-notice-time{flex:none;margin-left:auto;font:var(--dsw-font-xxs-12)}
|
|
112
|
+
@media (prefers-reduced-motion:reduce){.ddv-tooltip{animation:none}}
|
|
113
|
+
`
|
|
114
|
+
|
|
115
|
+
/** The shared session module (status socket + viewer frame), loaded once on first use. */
|
|
116
|
+
let sessionModule
|
|
117
|
+
const loadSession = () => {
|
|
118
|
+
sessionModule ??= import(new URL(`${PREFIX}session.js`, document.baseURI).href)
|
|
119
|
+
return sessionModule
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const NOTE_MS = 6000
|
|
123
|
+
|
|
124
|
+
function DesktopTab(props) {
|
|
125
|
+
const { t, sessionId, useTabInfo } = props
|
|
126
|
+
const info = typeof useTabInfo === 'function' ? useTabInfo() : undefined
|
|
127
|
+
const visible = info?.tab?.visible !== false
|
|
128
|
+
const frame = useRef(null)
|
|
129
|
+
const session = useRef(null)
|
|
130
|
+
const [status, setStatus] = useState({ phase: 'connecting', mode: 'watch', controller: null, mine: false, ended: null })
|
|
131
|
+
const [note, setNote] = useState(null)
|
|
132
|
+
|
|
133
|
+
// The view (status socket, grant, control) lives as long as the tab
|
|
134
|
+
// does; while the tab is hidden only the viewer frame is unloaded, so
|
|
135
|
+
// a hidden tab streams and decodes nothing but keeps control.
|
|
136
|
+
const visibleRef = useRef(visible)
|
|
137
|
+
visibleRef.current = visible
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
let cancelled = false
|
|
140
|
+
loadSession().then((module) => {
|
|
141
|
+
if (cancelled || frame.current === null) return
|
|
142
|
+
session.current = module.createDesktopSession({
|
|
143
|
+
frame: frame.current,
|
|
144
|
+
base: new URL(PREFIX, document.baseURI),
|
|
145
|
+
sessionId: sessionId ?? null,
|
|
146
|
+
onStatus: setStatus,
|
|
147
|
+
})
|
|
148
|
+
if (!visibleRef.current) session.current.pause()
|
|
149
|
+
}, () => { if (!cancelled) setStatus(current => ({ ...current, phase: 'error' })) })
|
|
150
|
+
return () => {
|
|
151
|
+
cancelled = true
|
|
152
|
+
session.current?.destroy()
|
|
153
|
+
session.current = null
|
|
154
|
+
}
|
|
155
|
+
}, [sessionId])
|
|
156
|
+
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (visible) session.current?.resume()
|
|
159
|
+
else session.current?.pause()
|
|
160
|
+
}, [visible])
|
|
161
|
+
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (status.ended === null) return undefined
|
|
164
|
+
setNote(t(`ended.${status.ended}`))
|
|
165
|
+
const timer = setTimeout(() => setNote(null), NOTE_MS)
|
|
166
|
+
return () => clearTimeout(timer)
|
|
167
|
+
}, [status.ended])
|
|
168
|
+
|
|
169
|
+
const inControl = status.mode === 'control' && status.mine
|
|
170
|
+
let label = t('status.connecting')
|
|
171
|
+
let tone = 'idle'
|
|
172
|
+
if (status.phase === 'error') {
|
|
173
|
+
label = t('status.error')
|
|
174
|
+
tone = 'error'
|
|
175
|
+
} else if (status.phase === 'live') {
|
|
176
|
+
label = inControl ? t('status.control') : status.controller !== null ? t('status.watchingOther') : t('status.watching')
|
|
177
|
+
tone = inControl ? 'control' : 'live'
|
|
178
|
+
}
|
|
179
|
+
const fullscreen = new URL(`${PREFIX}${sessionId ? `?session=${encodeURIComponent(sessionId)}` : ''}`, document.baseURI).href
|
|
180
|
+
|
|
181
|
+
return h('section', { className: 'ddv-tab', 'aria-label': t('title') },
|
|
182
|
+
h('div', { className: 'ddv-bar' },
|
|
183
|
+
h('span', { className: 'ddv-status', 'data-tone': tone, role: 'status', 'aria-live': 'polite' }, label),
|
|
184
|
+
h('span', { className: 'ddv-actions' },
|
|
185
|
+
status.phase === 'error' && h('button', { type: 'button', className: 'ddv-btn', onClick: () => session.current?.retry() }, t('action.retry')),
|
|
186
|
+
h('a', { className: 'ddv-btn', href: fullscreen, target: '_blank', rel: 'noopener noreferrer' }, t('action.fullscreen')),
|
|
187
|
+
h('button', {
|
|
188
|
+
type: 'button',
|
|
189
|
+
className: status.mode === 'control' ? 'ddv-btn' : 'ddv-btn ddv-primary',
|
|
190
|
+
onClick: () => session.current?.setMode(status.mode === 'control' ? 'watch' : 'control'),
|
|
191
|
+
}, status.mode === 'control' ? t('action.give') : t('action.take')))),
|
|
192
|
+
h('div', { className: 'ddv-stage', 'data-control': String(inControl) },
|
|
193
|
+
h('iframe', { ref: frame, className: 'ddv-frame', title: t('title') }),
|
|
194
|
+
note && h('p', { className: 'ddv-note', role: 'status' }, note)))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The host's tooltip, rebuilt from its behaviour (the shared primitive
|
|
199
|
+
* is not a module plugins may load): below its anchor, centred, after
|
|
200
|
+
* 500 ms of mouse hover or at once on keyboard focus, hidden on leave,
|
|
201
|
+
* blur, click and touch.
|
|
202
|
+
*/
|
|
203
|
+
const TOOLTIP_DELAY_MS = 500
|
|
204
|
+
const TOOLTIP_GAP_PX = 8
|
|
205
|
+
const VIEWPORT_MARGIN_PX = 12
|
|
206
|
+
function useTooltip(label) {
|
|
207
|
+
const anchor = useRef(null)
|
|
208
|
+
const timer = useRef(null)
|
|
209
|
+
const [at, setAt] = useState(null)
|
|
210
|
+
const clear = () => {
|
|
211
|
+
if (timer.current !== null) clearTimeout(timer.current)
|
|
212
|
+
timer.current = null
|
|
213
|
+
}
|
|
214
|
+
const show = () => {
|
|
215
|
+
const element = anchor.current
|
|
216
|
+
if (element === null) return
|
|
217
|
+
const rect = element.getBoundingClientRect()
|
|
218
|
+
setAt({ left: rect.left + rect.width / 2, top: rect.bottom + TOOLTIP_GAP_PX })
|
|
219
|
+
}
|
|
220
|
+
const hide = () => {
|
|
221
|
+
clear()
|
|
222
|
+
setAt(null)
|
|
223
|
+
}
|
|
224
|
+
useEffect(() => clear, [])
|
|
225
|
+
const bubble = useRef(null)
|
|
226
|
+
// Keep the bubble inside the viewport once its width is known.
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
const element = bubble.current
|
|
229
|
+
if (at === null || element === null) return
|
|
230
|
+
const half = element.offsetWidth / 2
|
|
231
|
+
const left = Math.min(Math.max(at.left, half + VIEWPORT_MARGIN_PX), window.innerWidth - half - VIEWPORT_MARGIN_PX)
|
|
232
|
+
element.style.left = `${left}px`
|
|
233
|
+
element.style.visibility = 'visible'
|
|
234
|
+
}, [at])
|
|
235
|
+
const handlers = {
|
|
236
|
+
ref: anchor,
|
|
237
|
+
onPointerEnter: (event) => {
|
|
238
|
+
if (event.pointerType === 'touch') return
|
|
239
|
+
if (event.pointerType === 'mouse' && !window.matchMedia('(any-hover: hover)').matches) return
|
|
240
|
+
clear()
|
|
241
|
+
timer.current = setTimeout(() => { timer.current = null; show() }, TOOLTIP_DELAY_MS)
|
|
242
|
+
},
|
|
243
|
+
onPointerLeave: hide,
|
|
244
|
+
onPointerDown: (event) => { if (event.pointerType === 'touch') hide() },
|
|
245
|
+
onFocus: (event) => { if (event.currentTarget.matches(':focus-visible')) show() },
|
|
246
|
+
onBlur: hide,
|
|
247
|
+
}
|
|
248
|
+
const tip = at === null ? null : h('span', {
|
|
249
|
+
ref: bubble,
|
|
250
|
+
className: 'ddv-tooltip',
|
|
251
|
+
role: 'tooltip',
|
|
252
|
+
'data-side': 'bottom',
|
|
253
|
+
style: { left: at.left, top: at.top, visibility: 'hidden' },
|
|
254
|
+
}, label)
|
|
255
|
+
return { handlers, tip, hide }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Source kind of the notes the Host half sends the agent (src/notify.js). */
|
|
259
|
+
const NOTICE_SOURCE = 'desktop-view'
|
|
260
|
+
const NOTICE_NODE = 'desktop-view-notice'
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The chat row for a control note: what it is ("Desktop control"), what
|
|
264
|
+
* happened, and when. It replaces the generic row DSH would show for an
|
|
265
|
+
* unknown message source.
|
|
266
|
+
*/
|
|
267
|
+
function DesktopNoticeNode({ node, t }) {
|
|
268
|
+
const data = node?.data ?? {}
|
|
269
|
+
const date = new Date(data.time)
|
|
270
|
+
const valid = !Number.isNaN(date.getTime())
|
|
271
|
+
return h('section', { className: 'ddv-notice', 'data-desktop-view-notice': data.change ?? true },
|
|
272
|
+
h('span', { className: 'ddv-notice-icon', 'aria-hidden': true }, h(IconDesktop, { size: 14 })),
|
|
273
|
+
h('span', { className: 'ddv-notice-title' }, t('notice.title')),
|
|
274
|
+
h('span', { className: 'ddv-notice-summary' }, t(data.change === 'taken' ? 'notice.taken' : 'notice.released')),
|
|
275
|
+
valid && h('time', { className: 'ddv-notice-time', dateTime: date.toISOString() },
|
|
276
|
+
new Intl.DateTimeFormat(t('time.locale'), { hour: '2-digit', minute: '2-digit' }).format(date)))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Claims the plugin's own notes in the chat timeline (exclusively, so the
|
|
281
|
+
* generic input-message definition does not also render them) and turns
|
|
282
|
+
* them into one `desktop-view-notice` node each.
|
|
283
|
+
*/
|
|
284
|
+
const noticeDefinition = {
|
|
285
|
+
kind: NOTICE_NODE,
|
|
286
|
+
target: 'chat',
|
|
287
|
+
match: event => event.type === 'user/message' && event.surfaceOp === 'append' && event.data?.source?.kind === NOTICE_SOURCE
|
|
288
|
+
? { id: String(event.data.id), role: 'start', exclusive: true }
|
|
289
|
+
: null,
|
|
290
|
+
start: (_context, match) => ({
|
|
291
|
+
seq: match.event.seq,
|
|
292
|
+
time: match.event.time,
|
|
293
|
+
change: match.event.data.source.change === 'taken' ? 'taken' : 'released',
|
|
294
|
+
}),
|
|
295
|
+
update: context => context.state,
|
|
296
|
+
buildViewNode: context => context.state === undefined ? null : {
|
|
297
|
+
key: context.key,
|
|
298
|
+
kind: NOTICE_NODE,
|
|
299
|
+
id: context.id,
|
|
300
|
+
target: 'chat',
|
|
301
|
+
anchorSeq: context.state.seq,
|
|
302
|
+
location: context.start?.location ?? context.matches[0]?.location ?? { kind: 'unresolved' },
|
|
303
|
+
visibility: 'visible',
|
|
304
|
+
data: context.state,
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Opens the Desktop tab, or hides it when it is the one showing. */
|
|
309
|
+
function HeaderButton({ t, sidebar }) {
|
|
310
|
+
const label = t('header.toggle')
|
|
311
|
+
const { handlers, tip, hide } = useTooltip(label)
|
|
312
|
+
return h(React.Fragment, null,
|
|
313
|
+
h('button', {
|
|
314
|
+
...handlers,
|
|
315
|
+
type: 'button',
|
|
316
|
+
className: 'ddv-header',
|
|
317
|
+
'aria-label': label,
|
|
318
|
+
onClick: () => {
|
|
319
|
+
hide()
|
|
320
|
+
const active = sidebar.active()
|
|
321
|
+
if (sidebar.isExpanded() && active?.kind === KIND) sidebar.hide(active.id)
|
|
322
|
+
else sidebar.openTab(KIND)
|
|
323
|
+
},
|
|
324
|
+
}, h(IconDesktop, { size: 16 })),
|
|
325
|
+
tip)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
inject: ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs'],
|
|
330
|
+
apply(ctx) {
|
|
331
|
+
ctx.effect(() => {
|
|
332
|
+
const disposers = [ctx.locale.register(NS, 'en', en), ctx.locale.register(NS, 'zh', zh)]
|
|
333
|
+
return () => { for (const dispose of disposers) dispose() }
|
|
334
|
+
}, 'desktop-view: dictionaries')
|
|
335
|
+
const t = ctx.locale.bind(NS)
|
|
336
|
+
|
|
337
|
+
ctx.effect(() => {
|
|
338
|
+
if (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return () => {}
|
|
339
|
+
const tag = document.createElement('style')
|
|
340
|
+
tag.id = STYLE_ID
|
|
341
|
+
tag.dataset.plugin = 'dsh-desktop-view'
|
|
342
|
+
tag.textContent = CSS
|
|
343
|
+
document.head.appendChild(tag)
|
|
344
|
+
return () => tag.remove()
|
|
345
|
+
}, 'desktop-view: styles')
|
|
346
|
+
|
|
347
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
348
|
+
id: TAB_ID,
|
|
349
|
+
kind: KIND,
|
|
350
|
+
priority: 'extension',
|
|
351
|
+
// Hiding the tab (another tab, a collapsed sidebar, another session)
|
|
352
|
+
// must not end the view: control lasts until Give back, idle or close.
|
|
353
|
+
keepMounted: true,
|
|
354
|
+
title: () => t('title'),
|
|
355
|
+
guide: [{
|
|
356
|
+
id: 'desktop',
|
|
357
|
+
order: 40,
|
|
358
|
+
title: () => t('title'),
|
|
359
|
+
description: () => t('guide.description'),
|
|
360
|
+
icon: IconDesktop,
|
|
361
|
+
}],
|
|
362
|
+
}), 'desktop-view: tab type')
|
|
363
|
+
|
|
364
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
365
|
+
name: 'sidebar.right.pane.tab',
|
|
366
|
+
key: TAB_ID,
|
|
367
|
+
locale: NS,
|
|
368
|
+
inject: sessionId => ({ t, sessionId }),
|
|
369
|
+
}, DesktopTab))
|
|
370
|
+
|
|
371
|
+
// Chat rows for the control notes; absent in hosts without the Conversation layer.
|
|
372
|
+
ctx.inject(['uiConversation'], (sub) => {
|
|
373
|
+
sub.effect(() => sub.uiConversation.events.register(noticeDefinition), 'desktop-view: notice rows')
|
|
374
|
+
})
|
|
375
|
+
ctx.slots.inject('conversation.chat.node', () => ctx.slots.register({
|
|
376
|
+
name: 'conversation.chat.node',
|
|
377
|
+
key: NOTICE_NODE,
|
|
378
|
+
locale: NS,
|
|
379
|
+
inject: () => ({ t }),
|
|
380
|
+
}, DesktopNoticeNode))
|
|
381
|
+
|
|
382
|
+
ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
383
|
+
name: 'conversation.session.header.utilities',
|
|
384
|
+
id: 'desktop-view',
|
|
385
|
+
order: 20,
|
|
386
|
+
locale: NS,
|
|
387
|
+
inject: () => ({ t, sidebar: ctx.sidebarRight }),
|
|
388
|
+
}, HeaderButton))
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Bundle layer for dsh-desktop-view: one row, configured on the plugin's
|
|
2
|
+
# settings page or in the profile patch. The defaults fit the Cua container
|
|
3
|
+
# image (cua-spacesd on loopback with its token in /run/cua/env-token).
|
|
4
|
+
- insert:
|
|
5
|
+
- id: desktop-view
|
|
6
|
+
name: 'dsh-desktop-view'
|
|
7
|
+
config: {}
|
package/icon.svg
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Desktop view">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="screen" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#2b5bd7"/>
|
|
5
|
+
<stop offset="1" stop-color="#17306f"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="4" y="8" width="56" height="38" rx="6" fill="url(#screen)"/>
|
|
9
|
+
<rect x="4" y="8" width="56" height="38" rx="6" fill="none" stroke="#0d1c3f" stroke-width="2"/>
|
|
10
|
+
<path d="M26 20l14 7-14 7z" fill="#f7f7f2"/>
|
|
11
|
+
<rect x="27" y="46" width="10" height="7" fill="#0d1c3f"/>
|
|
12
|
+
<rect x="16" y="53" width="32" height="4" rx="2" fill="#0d1c3f"/>
|
|
13
|
+
<circle cx="52" cy="15" r="3.5" fill="#ffb020"/>
|
|
14
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepSeek Harness Host plugin: relay the live desktop of this machine from
|
|
3
|
+
* cua-spacesd (Cua's in-guest daemon) through DSH's own web server and
|
|
4
|
+
* login, with the daemon's own web viewer (video, audio, clipboard, files,
|
|
5
|
+
* displays, presence).
|
|
6
|
+
*
|
|
7
|
+
* The approved flow stays the plugin's own: a view starts watching, "Take
|
|
8
|
+
* control" and "Give back" go over its status socket, and the relay enforces
|
|
9
|
+
* the difference. The daemon's env token and its viewer tickets stay on the
|
|
10
|
+
* server; the browser only holds relay tickets that work through this relay
|
|
11
|
+
* and only while their view (and, for control, its control) lasts.
|
|
12
|
+
*
|
|
13
|
+
* The Web UI half (client.js) adds a session-header button and a right
|
|
14
|
+
* sidebar tab; the full-screen page in viewer/ serves phones and direct links.
|
|
15
|
+
*/
|
|
16
|
+
import WebSocket, { WebSocketServer } from 'ws'
|
|
17
|
+
import { Config } from './src/config.js'
|
|
18
|
+
import { createControl, fileWriter } from './src/control.js'
|
|
19
|
+
import { MAX_CLIENT_MESSAGE_BYTES } from './src/filter.js'
|
|
20
|
+
import { MEDIA_PATH, PREFIX, STATUS_PATH, admitOwner, createPageHandler, refuseUpgrade, statusQuery } from './src/http.js'
|
|
21
|
+
import { keepAlive } from './src/keepalive.js'
|
|
22
|
+
import { CLOSE, mediaTicketOf, pipeMedia } from './src/media.js'
|
|
23
|
+
import { createNotifier } from './src/notify.js'
|
|
24
|
+
import { createSpacesd } from './src/spacesd.js'
|
|
25
|
+
import { createViews } from './src/status.js'
|
|
26
|
+
import { createTicketBook } from './src/tickets.js'
|
|
27
|
+
import { createViewerProxy } from './src/viewer.js'
|
|
28
|
+
|
|
29
|
+
export const name = 'dsh-desktop-view'
|
|
30
|
+
export const inject = ['webServer', 'connection']
|
|
31
|
+
export { Config }
|
|
32
|
+
|
|
33
|
+
/** Largest message the viewer's media socket may send up (microphone audio, input). */
|
|
34
|
+
const MAX_MEDIA_MESSAGE_BYTES = 1024 * 1024
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
38
|
+
* @param {import('@deepseek-ai/schemastery').default.infer<typeof Config>} config
|
|
39
|
+
*/
|
|
40
|
+
export function apply(ctx, config) {
|
|
41
|
+
const logger = ctx.logger('desktop-view')
|
|
42
|
+
const spacesd = createSpacesd({ endpoint: config.endpoint, tokenFile: config.tokenFile })
|
|
43
|
+
const write = fileWriter(config.stateFile)
|
|
44
|
+
const control = createControl({
|
|
45
|
+
idleMs: config.idleSeconds * 1000,
|
|
46
|
+
persist: state => write(state).catch(error => logger.warn('could not write %s: %s', config.stateFile, error.message)),
|
|
47
|
+
})
|
|
48
|
+
const notify = createNotifier({ ctx, mode: config.notifyAgent, stateFile: config.stateFile, logger })
|
|
49
|
+
const tickets = createTicketBook({
|
|
50
|
+
spacesd,
|
|
51
|
+
features: { clipboard: config.clipboard, filesRoot: config.filesRoot, microphone: config.microphone },
|
|
52
|
+
})
|
|
53
|
+
const mediaUrl = new URL('media', `${spacesd.base}/`)
|
|
54
|
+
mediaUrl.protocol = mediaUrl.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
55
|
+
|
|
56
|
+
ctx.effect(() => {
|
|
57
|
+
const unsubscribe = control.subscribe((state, change) => { notify(state, change) })
|
|
58
|
+
const views = createViews({ control, tickets, viewer: { maxFps: config.maxFps }, logger })
|
|
59
|
+
const media = new Map()
|
|
60
|
+
const statusServer = new WebSocketServer({ noServer: true, maxPayload: MAX_CLIENT_MESSAGE_BYTES, perMessageDeflate: false })
|
|
61
|
+
const mediaServer = new WebSocketServer({
|
|
62
|
+
noServer: true,
|
|
63
|
+
maxPayload: MAX_MEDIA_MESSAGE_BYTES,
|
|
64
|
+
perMessageDeflate: false,
|
|
65
|
+
handleProtocols: offered => (offered.has('rcdp.v2') ? 'rcdp.v2' : false),
|
|
66
|
+
})
|
|
67
|
+
control.flush()
|
|
68
|
+
|
|
69
|
+
// A revoked relay ticket (control given back, view closed) closes the
|
|
70
|
+
// media sockets it opened, so the input path ends with the control.
|
|
71
|
+
const stopRevoke = tickets.onRevoke((token) => {
|
|
72
|
+
for (const [piped, owner] of media) if (owner === token) piped.close(CLOSE.CONTROL_ENDED, 'control ended')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const viewer = createViewerProxy({ endpoint: config.endpoint, tickets, touch: id => control.touch(id), logger })
|
|
76
|
+
const disposePage = ctx.webServer.register({
|
|
77
|
+
kind: 'prefix',
|
|
78
|
+
path: PREFIX,
|
|
79
|
+
handler: createPageHandler({ connection: ctx.connection, viewer }),
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const disposeStatus = ctx.webServer.registerUpgrade({
|
|
83
|
+
path: STATUS_PATH,
|
|
84
|
+
handler(req, socket, head) {
|
|
85
|
+
const admitted = admitOwner(ctx.connection, req)
|
|
86
|
+
if (!admitted.ok) return refuseUpgrade(socket, admitted.status)
|
|
87
|
+
statusServer.handleUpgrade(req, socket, head, (browser) => {
|
|
88
|
+
views.attach(browser, statusQuery(req.url))
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const disposeMedia = ctx.webServer.registerUpgrade({
|
|
94
|
+
path: MEDIA_PATH,
|
|
95
|
+
handler(req, socket, head) {
|
|
96
|
+
const admitted = admitOwner(ctx.connection, req)
|
|
97
|
+
if (!admitted.ok) return refuseUpgrade(socket, admitted.status)
|
|
98
|
+
const ticket = mediaTicketOf(req.url, req.headers['sec-websocket-protocol'])
|
|
99
|
+
const binding = ticket === undefined ? undefined : tickets.media(ticket)
|
|
100
|
+
if (binding === undefined) return refuseUpgrade(socket, 401)
|
|
101
|
+
mediaServer.handleUpgrade(req, socket, head, (browser) => {
|
|
102
|
+
const url = new URL(mediaUrl)
|
|
103
|
+
url.searchParams.set('ticket', ticket)
|
|
104
|
+
const piped = pipeMedia({
|
|
105
|
+
browser,
|
|
106
|
+
mode: binding.grant.mode,
|
|
107
|
+
sessionId: binding.sessionId,
|
|
108
|
+
onInput: () => control.touch(binding.grant.holderId),
|
|
109
|
+
connect: () => new WebSocket(url, ['rcdp.v2'], { perMessageDeflate: false }),
|
|
110
|
+
logger,
|
|
111
|
+
})
|
|
112
|
+
media.set(piped, binding.relayToken)
|
|
113
|
+
keepAlive(browser)
|
|
114
|
+
browser.once('close', () => media.delete(piped))
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return async () => {
|
|
120
|
+
disposeMedia()
|
|
121
|
+
disposeStatus()
|
|
122
|
+
disposePage()
|
|
123
|
+
stopRevoke()
|
|
124
|
+
views.closeAll()
|
|
125
|
+
for (const piped of media.keys()) piped.close(1001, 'stopped')
|
|
126
|
+
statusServer.close()
|
|
127
|
+
mediaServer.close()
|
|
128
|
+
unsubscribe()
|
|
129
|
+
await control.flush()
|
|
130
|
+
}
|
|
131
|
+
}, 'desktop-view.relay()')
|
|
132
|
+
}
|
package/locale/en.json
ADDED