dsh-remote-plugin 0.8.0-rc.9 → 0.8.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/README.en.md +4 -2
- package/README.md +4 -2
- package/apk/dsh-remote.apk +0 -0
- package/client.js +96 -115
- package/file-delivery.mjs +84 -0
- package/gateway.cjs +248 -3
- package/index.mjs +594 -52
- package/insights.mjs +33 -2
- package/package.json +4 -2
- package/plugin-center.mjs +14 -1
- package/public/activity.js +8 -3
- package/public/announcements.json +10 -0
- package/public/app.js +65 -20
- package/public/approval-records.js +75 -3
- package/public/build.json +2 -2
- package/public/desktop/desktop.css +10 -2
- package/public/desktop/desktop.html +24 -4
- package/public/desktop/desktop.js +32 -13
- package/public/extensions.css +109 -1
- package/public/extensions.js +116 -7
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/index.html +26 -9
- package/public/insights.css +5 -0
- package/public/insights.js +40 -11
- package/public/md.js +7 -1
- package/public/plugin-center.css +3 -0
- package/public/plugin-center.js +58 -9
- package/public/plugin.js +21 -6
- package/public/session-deck.css +73 -0
- package/public/session-deck.js +180 -0
- package/public/skills.js +16 -5
- package/public/skins/blue-fish/skin.css +39 -0
- package/public/styles.css +22 -2
- package/public/task-board.js +109 -0
- package/public/teams.js +35 -13
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/public/workflow.css +6 -12
- package/skills/dsh-remote-doctor/SKILL.md +16 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +74 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +29 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/task-board.mjs +57 -0
package/README.en.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# dsh-remote-plugin
|
|
2
2
|
|
|
3
|
-
The DSH bundle plugin for DSH Remote adds a
|
|
3
|
+
The DSH bundle plugin for DSH Remote adds a More → Phone connection entry, a browser admin console, and a bundled gateway that respects the user's start/stop intent.
|
|
4
4
|
|
|
5
5
|
[English](README.en.md) · [中文](README.md)
|
|
6
6
|
|
|
7
|
+
The [operation and troubleshooting knowledge base (Chinese)](https://github.com/Blank-not-black/dsh-Remote/blob/main/docs/wiki/README.md) provides task, symptom and error-code navigation. Offline copies ship in `skills/dsh-remote-doctor/references/wiki/` for the bundled Doctor; external AI assistants can start from the repository's llms.txt.
|
|
8
|
+
|
|
7
9
|
## Install and connect
|
|
8
10
|
|
|
9
11
|
```sh
|
|
@@ -11,7 +13,7 @@ dsh plugin --profile web add dsh-remote-plugin@latest
|
|
|
11
13
|
dsh plugin --profile web list --depth 0
|
|
12
14
|
```
|
|
13
15
|
|
|
14
|
-
Use the actual profile for custom setups. DSH Desktop uses its own plugin manager and needs a complete exit/reopen. For Web, fully restart DSH Web, hard-refresh with Ctrl+F5
|
|
16
|
+
Use the actual profile for custom setups. DSH Desktop uses its own plugin manager and needs a complete exit/reopen. For Web, fully restart DSH Web, hard-refresh with Ctrl+F5, then use the left navigation's More → 手机连接(DSH Remote) to open pairing in a browser. A first-use card explains this location once; starting or dismissing it remembers that acknowledgement. Older hosts without the More extension keep a bottom-left Phone connection button.
|
|
15
17
|
|
|
16
18
|
On the host, open `http://127.0.0.1:8787/health`, then display a connection QR in the plugin wizard or admin console. Scan it at More → Hosts and connections → Scan to connect; the APK download QR only installs the app. A phone connects to `http://PC-LAN-IP:8787` with its token, not its own localhost. Pin a published version with `@<version>`; check the actual `@next` and `@latest` tags separately.
|
|
17
19
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# dsh-remote-plugin
|
|
2
2
|
|
|
3
|
-
DSH Remote 的 DSH bundle
|
|
3
|
+
DSH Remote 的 DSH bundle 插件:提供「更多 → 手机连接」入口、浏览器管理控制台及受用户启停意图约束的内置网关。
|
|
4
4
|
|
|
5
5
|
**中文** · [English](README.en.md)
|
|
6
6
|
|
|
7
|
+
[操作与排障知识库](https://github.com/Blank-not-black/dsh-Remote/blob/main/docs/wiki/README.md)按任务、症状和错误码导航;用户 AI 可从仓库根 llms.txt 开始。包内离线副本位于 `skills/dsh-remote-doctor/references/wiki/`,内置 Doctor 按需读取并引用 KB 编号。
|
|
8
|
+
|
|
7
9
|
## 安装与连接
|
|
8
10
|
|
|
9
11
|
```sh
|
|
@@ -11,7 +13,7 @@ dsh plugin --profile web add dsh-remote-plugin@latest
|
|
|
11
13
|
dsh plugin --profile web list --depth 0
|
|
12
14
|
```
|
|
13
15
|
|
|
14
|
-
示例针对 Web profile;自定义 profile 使用实际名称。DSH Desktop 从自身插件管理入口安装,完整退出并重开。Web 安装完成后完整重启 DSH Web,Ctrl+F5
|
|
16
|
+
示例针对 Web profile;自定义 profile 使用实际名称。DSH Desktop 从自身插件管理入口安装,完整退出并重开。Web 安装完成后完整重启 DSH Web,Ctrl+F5,从左侧导航「更多 → 手机连接(DSH Remote)」进入浏览器配对页。首次加载会提示入口位置;选择「开始连接」或「稍后」后不再重复提示。旧宿主缺少该菜单扩展点时,入口保留在左下角。
|
|
15
17
|
|
|
16
18
|
在主机访问 `http://127.0.0.1:8787/health`,然后在插件连接向导或管理控制台显示连接二维码。手机通过「更多 → 主机与连接 → 扫码连接」配对;APK 下载码只用于安装。手动连接填 `http://电脑局域网IP:8787` 与令牌,不能填手机 localhost。固定版本使用 `@<已发布版本>`,`@next` 与 `@latest` 的指向需另行查询。
|
|
17
19
|
|
package/apk/dsh-remote.apk
CHANGED
|
Binary file
|
package/client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* dsh-remote 插件 client half
|
|
2
|
-
*
|
|
3
|
-
* 抽屉内 iframe 懒加载 /remote/plugin.html —— 插件端快速状态面板;深入管理再打开控制台。
|
|
2
|
+
* 更多菜单中的手机连接入口;首次使用显示可关闭的路径提示。
|
|
4
3
|
* 产物入库, 无构建步骤; 参考 @openbiliclaw/dsh-plugin 的官方 slot 注册模式。
|
|
5
4
|
*/
|
|
6
5
|
window.__ModuleLoader__.load({
|
|
@@ -19,22 +18,6 @@ window.__ModuleLoader__.load({
|
|
|
19
18
|
storeRuntime = require('@deepseek-ai/dsh-client-runtime/client')
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
var DRAWER_STYLE = {
|
|
23
|
-
// Desktop's hidden title bar overlays the page (40px on Windows).
|
|
24
|
-
// Electron exposes its current height through the CSS environment value;
|
|
25
|
-
// keep a safe fallback for Desktop hosts without that value.
|
|
26
|
-
position: 'fixed', top: window.location && window.location.protocol === 'dsh-app:' ? 'calc(12px + env(titlebar-area-height, 40px))' : 12,
|
|
27
|
-
right: 12, bottom: 12, zIndex: 2147483000,
|
|
28
|
-
width: 'min(520px, calc(100vw - 24px))', background: 'transparent',
|
|
29
|
-
border: '1px solid rgba(128,128,128,.25)', borderRadius: 16, overflow: 'hidden',
|
|
30
|
-
boxShadow: '-12px 16px 42px rgba(0,0,0,.24)',
|
|
31
|
-
transform: 'translateX(102%)', transition: 'transform .22s ease',
|
|
32
|
-
display: 'flex', flexDirection: 'column',
|
|
33
|
-
}
|
|
34
|
-
// DSH 原生 footerActions 容器默认 flex-row(官方类名已编译定型);
|
|
35
|
-
// 动态注入列布局, 让各 footer action 上下堆叠。
|
|
36
|
-
var FOOTER_FIX_ID = 'dsh-remote-footer-stack'
|
|
37
|
-
var FOOTER_FIX_CSS = '.kIs9zW_footerActions{flex-direction:column!important;align-items:stretch!important}'
|
|
38
21
|
var PLUGIN_THEMES = ['default', 'dark', 'light', 'neutral', 'mono', 'fish']
|
|
39
22
|
var ICON_PALETTES = {
|
|
40
23
|
default: { bg: '#F6F9FF', upper: '#4F7FEF', lower: '#8A64D8' },
|
|
@@ -93,122 +76,120 @@ window.__ModuleLoader__.load({
|
|
|
93
76
|
React.createElement('path', Object.assign({ d: 'M6 10l4 4-4 4m4-4 4 4', stroke: palette.lower }, common)))
|
|
94
77
|
}
|
|
95
78
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
79
|
+
var SEEN_KEY = 'dshRemoteConnectionEntrySeenV1'
|
|
80
|
+
var ENTRY_HASH = '#dsh-remote-connect'
|
|
81
|
+
var MenuItemButton
|
|
82
|
+
try { MenuItemButton = require('@deepseek-ai/dsh-client-ui-primitives').MenuItemButton } catch (_) {}
|
|
83
|
+
function seen() { try { return localStorage.getItem(SEEN_KEY) === '1' } catch (_) { return false } }
|
|
84
|
+
function remember() { try { localStorage.setItem(SEEN_KEY, '1') } catch (_) {} }
|
|
85
|
+
|
|
86
|
+
function MoreEntry(props) {
|
|
87
|
+
var opening = props.useStore(function (s) { return s.opening })
|
|
88
|
+
var select = function () { props.onDismiss?.(); void props.openConsole(props.actions) }
|
|
89
|
+
if (MenuItemButton) return React.createElement(MenuItemButton, { icon: React.createElement(PluginIcon), disabled: opening, onSelect: select }, '手机连接(DSH Remote)')
|
|
90
|
+
return React.createElement('button', { type: 'button', role: 'menuitem', disabled: opening, onClick: select,
|
|
91
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, width: '100%', padding: '10px 12px', border: 0, background: 'transparent', color: 'inherit', font: 'inherit', cursor: 'pointer' } },
|
|
92
|
+
React.createElement(PluginIcon), '手机连接(DSH Remote)')
|
|
104
93
|
}
|
|
105
94
|
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var setHover = hoverState[1]
|
|
112
|
-
return React.createElement('button', {
|
|
113
|
-
type: 'button',
|
|
114
|
-
title: 'DSH Remote',
|
|
115
|
-
'aria-haspopup': 'dialog',
|
|
116
|
-
'aria-expanded': open,
|
|
117
|
-
onClick: function () { props.actions.toggle() },
|
|
118
|
-
onMouseEnter: function () { setHover(true) },
|
|
119
|
-
onMouseLeave: function () { setHover(false) },
|
|
120
|
-
style: {
|
|
121
|
-
display: 'flex', alignItems: 'center', gap: 7, width: '100%',
|
|
122
|
-
padding: '6px 10px', border: 'none', borderRadius: 8,
|
|
123
|
-
background: open ? 'rgba(125, 207, 255, .14)' : hover ? 'rgba(125, 207, 255, .10)' : 'transparent',
|
|
124
|
-
border: open ? '1px solid rgba(125, 207, 255, .24)' : '1px solid transparent',
|
|
125
|
-
transition: 'background .15s ease, border-color .15s ease',
|
|
126
|
-
cursor: 'pointer', color: open ? '#5df2d6' : 'inherit',
|
|
127
|
-
font: '500 13px/1.3 system-ui, sans-serif', textAlign: 'left',
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
React.createElement(PluginIcon),
|
|
131
|
-
props.wide ? React.createElement('span', null, 'DSH Remote') : null)
|
|
95
|
+
function LegacyEntry(props) {
|
|
96
|
+
if (props.useMore()) return null
|
|
97
|
+
return React.createElement('button', { type: 'button', title: '手机连接(DSH Remote)', onClick: function () { void props.openConsole(props.actions) },
|
|
98
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, padding: 8, border: 0, background: 'transparent', color: 'inherit', cursor: 'pointer' } },
|
|
99
|
+
React.createElement(PluginIcon), props.wide ? '手机连接' : null)
|
|
132
100
|
}
|
|
133
101
|
|
|
134
|
-
function
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return function () { window.removeEventListener('message', onMsg) }
|
|
153
|
-
}, [])
|
|
154
|
-
return React.createElement('div', {
|
|
155
|
-
'aria-hidden': !open,
|
|
156
|
-
style: Object.assign({}, DRAWER_STYLE, {
|
|
157
|
-
transform: open ? 'translateX(0)' : 'translateX(102%)',
|
|
158
|
-
boxShadow: open ? DRAWER_STYLE.boxShadow : 'none',
|
|
159
|
-
pointerEvents: open ? 'auto' : 'none',
|
|
160
|
-
visibility: open ? 'visible' : 'hidden',
|
|
161
|
-
transition: open ? 'transform .22s ease' : 'transform .22s ease, visibility 0s linear .22s',
|
|
162
|
-
}),
|
|
163
|
-
},
|
|
164
|
-
loaded.current ? React.createElement('iframe', {
|
|
165
|
-
ref: frame,
|
|
166
|
-
src: '/remote/plugin.html',
|
|
167
|
-
title: 'DSH Remote 快速状态面板',
|
|
168
|
-
sandbox: 'allow-scripts allow-same-origin allow-forms allow-modals allow-popups',
|
|
169
|
-
style: { flex: 1, width: '100%', border: 'none', background: '#0b0e1a' },
|
|
170
|
-
}) : null)
|
|
102
|
+
function EntryNotice(props) {
|
|
103
|
+
var state = props.useStore(function (s) { return s })
|
|
104
|
+
var more = props.useMore()
|
|
105
|
+
if (!state.notice) return null
|
|
106
|
+
var button = { minHeight: 36, padding: '7px 12px', borderRadius: 8, cursor: 'pointer', font: 'inherit', border: '1px solid var(--dsw-alias-border-l3, #ccd2da)' }
|
|
107
|
+
return React.createElement('aside', { 'data-dsh-remote-entry-notice': true, role: 'region', 'aria-label': '手机连接提示',
|
|
108
|
+
style: { position: 'fixed', right: 16, bottom: 16, width: 'min(352px, calc(100vw - 32px))', boxSizing: 'border-box', padding: 16, zIndex: 100,
|
|
109
|
+
border: '1px solid var(--dsw-alias-border-l3, #ccd2da)', borderRadius: 12, background: 'var(--dsw-alias-button-elevated-fill, #fff)', color: 'var(--dsw-alias-label-primary, #17212f)',
|
|
110
|
+
boxShadow: '0 6px 24px rgba(0,0,0,.14)', font: '13px/1.6 system-ui, sans-serif', WebkitAppRegion: 'no-drag' } },
|
|
111
|
+
React.createElement('strong', { style: { fontSize: 15 } }, '用手机连接这台电脑'),
|
|
112
|
+
React.createElement('p', { style: { margin: '8px 0' } }, more ? '以后在左侧「更多 → 手机连接(DSH Remote)」打开配对和连接管理。' : '以后点击左侧底部的「手机连接」打开配对和连接管理。'),
|
|
113
|
+
React.createElement('p', { style: { margin: '8px 0' } }, '点击后在浏览器打开,按步骤安装 App、扫码连接。'),
|
|
114
|
+
state.error ? React.createElement('p', { role: 'alert' }, '浏览器打开失败。请重试;也可在 DSH 的插件管理中检查 Remote 是否正常运行。') : null,
|
|
115
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 12 } },
|
|
116
|
+
React.createElement('button', { type: 'button', disabled: state.opening, style: Object.assign({}, button, { background: 'var(--dsw-alias-state-business-primary, #2665cf)', color: '#fff' }),
|
|
117
|
+
onClick: function () { void props.openConsole(props.actions) } }, state.opening ? '正在打开…' : state.error ? '重试打开' : '开始连接'),
|
|
118
|
+
React.createElement('button', { type: 'button', style: Object.assign({}, button, { background: 'transparent', color: 'inherit' }),
|
|
119
|
+
onClick: function () { remember(); props.actions.dismiss() } }, '稍后')))
|
|
171
120
|
}
|
|
172
121
|
|
|
173
122
|
var inject = ['slots']
|
|
174
123
|
function apply(ctx) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
124
|
+
// The authenticated browser landing is fixed; no caller-controlled redirect.
|
|
125
|
+
if (location.protocol !== 'dsh-app:' && location.hash === ENTRY_HASH) {
|
|
126
|
+
remember()
|
|
127
|
+
location.replace('/remote/admin/#remote/devices')
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
var moreAvailable = false, listeners = new Set(), active = true, pending = null
|
|
131
|
+
function notifyMore() { listeners.forEach(function (fn) { fn(moreAvailable) }) }
|
|
132
|
+
function useMore() {
|
|
133
|
+
var value = React.useState(function () { return moreAvailable })
|
|
134
|
+
React.useEffect(function () { listeners.add(value[1]); value[1](moreAvailable); return function () { listeners.delete(value[1]) } }, [])
|
|
135
|
+
return value[0]
|
|
136
|
+
}
|
|
182
137
|
var store = storeRuntime.defineStore({
|
|
183
|
-
init: function () { return {
|
|
138
|
+
init: function () { return { notice: !seen(), opening: false, error: false } },
|
|
184
139
|
actions: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
140
|
+
start: function (d) { d.opening = true; d.error = false },
|
|
141
|
+
opened: function (d) { d.opening = false; d.notice = false; d.error = false },
|
|
142
|
+
failed: function (d) { d.opening = false; d.notice = true; d.error = true },
|
|
143
|
+
dismiss: function (d) { d.notice = false },
|
|
188
144
|
},
|
|
189
145
|
})
|
|
146
|
+
async function openConsole(actions) {
|
|
147
|
+
if (pending || !active) return
|
|
148
|
+
var request = new AbortController()
|
|
149
|
+
pending = request
|
|
150
|
+
actions.start()
|
|
151
|
+
var timer = setTimeout(function () { request.abort() }, 8000)
|
|
152
|
+
try {
|
|
153
|
+
var target = '/remote/admin/#remote/devices'
|
|
154
|
+
if (location.protocol === 'dsh-app:') {
|
|
155
|
+
var response = await fetch('/remote/admin/api/browser-launch', { method: 'POST', credentials: 'same-origin',
|
|
156
|
+
headers: { 'x-dsh-remote-client': 'entry' }, signal: request.signal })
|
|
157
|
+
if (!response.ok) throw new Error('launch-unavailable')
|
|
158
|
+
var result = await response.json(), url = new URL(result.url)
|
|
159
|
+
if (result.ok !== true || !['http:', 'https:'].includes(url.protocol) || !['127.0.0.1', '[::1]'].includes(url.hostname)
|
|
160
|
+
|| url.username || url.password || url.pathname !== '/' || url.hash !== ENTRY_HASH) throw new Error('invalid-launch')
|
|
161
|
+
target = url.href
|
|
162
|
+
}
|
|
163
|
+
if (!active) return
|
|
164
|
+
if (request.signal.aborted) throw new Error('launch-cancelled')
|
|
165
|
+
// Desktop handles HTTP(S) window.open with its external browser handler.
|
|
166
|
+
// noopener browsers and Electron can return null on successful handoff.
|
|
167
|
+
window.open(target, '_blank', 'noopener,noreferrer')
|
|
168
|
+
remember()
|
|
169
|
+
actions.opened()
|
|
170
|
+
} catch (_) { if (active) actions.failed() }
|
|
171
|
+
finally { clearTimeout(timer); if (pending === request) pending = null }
|
|
172
|
+
}
|
|
173
|
+
var injected = function () { return { openConsole: openConsole, useMore: useMore } }
|
|
174
|
+
ctx.effect(function () { return function () { active = false; pending?.abort(); listeners.clear() } }, 'dsh-remote: entry lifetime')
|
|
175
|
+
ctx.effect(function () {
|
|
176
|
+
return ctx.slots.inject('sidebar.panellist.actions', function () {
|
|
177
|
+
var dispose = ctx.slots.register({ name: 'sidebar.panellist.actions', id: 'dsh-remote', order: 100, store, inject: injected }, MoreEntry)
|
|
178
|
+
moreAvailable = true; notifyMore()
|
|
179
|
+
return function () { moreAvailable = false; notifyMore(); dispose() }
|
|
180
|
+
})
|
|
181
|
+
}, 'dsh-remote: More menu entry')
|
|
190
182
|
ctx.effect(function () {
|
|
191
183
|
return ctx.slots.inject('sidebar.footer.action', function () {
|
|
192
|
-
return ctx.slots.register({
|
|
193
|
-
name: 'sidebar.footer.action',
|
|
194
|
-
id: 'dsh-remote',
|
|
195
|
-
order: 1,
|
|
196
|
-
store,
|
|
197
|
-
}, SidebarButton)
|
|
184
|
+
return ctx.slots.register({ name: 'sidebar.footer.action', id: 'dsh-remote', store, inject: injected }, LegacyEntry)
|
|
198
185
|
})
|
|
199
|
-
}, 'dsh-remote:
|
|
186
|
+
}, 'dsh-remote: old host entry fallback')
|
|
200
187
|
ctx.effect(function () {
|
|
201
188
|
return ctx.slots.inject('shell.overlay', function () {
|
|
202
|
-
return ctx.slots.register({
|
|
203
|
-
name: 'shell.overlay',
|
|
204
|
-
id: 'dsh-remote-drawer',
|
|
205
|
-
store,
|
|
206
|
-
inject: function () { return {openSession:function(id){try{if(typeof navigation?.openSession!=='function')return false;navigation.openSession(id);return true}catch(_){return false}}} },
|
|
207
|
-
}, Drawer)
|
|
189
|
+
return ctx.slots.register({ name: 'shell.overlay', id: 'dsh-remote-entry-notice', store, inject: injected }, EntryNotice)
|
|
208
190
|
})
|
|
209
|
-
}, 'dsh-remote:
|
|
191
|
+
}, 'dsh-remote: first-use entry notice')
|
|
210
192
|
}
|
|
211
|
-
|
|
212
193
|
exports.apply = apply
|
|
213
194
|
exports.inject = inject
|
|
214
195
|
return module.exports
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// DSH model-facing file delivery tools. Host services are optional; no SDK dependency.
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { realpathSync } from 'node:fs'
|
|
4
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path'
|
|
5
|
+
|
|
6
|
+
const description = 'Send a single existing local file to a paired DSH Remote device. The recipient must explicitly accept before downloading. A queued delivery is NOT a successful receipt. Use remote_devices first and remote_file_status to check results. Do not repeatedly send after an uncertain response.'
|
|
7
|
+
const objectSchema = properties => ({ type: 'object', additionalProperties: false, properties })
|
|
8
|
+
const string = description => ({ type: 'string', description })
|
|
9
|
+
const output = {
|
|
10
|
+
schema: { ...objectSchema({ ok: { type: 'boolean' }, message: { type: 'string' }, details: { type: 'string' } }), required: ['ok', 'message', 'details'] },
|
|
11
|
+
render: (_args, value) => [{ type: 'text', text: value.message + '\n' + value.details }],
|
|
12
|
+
}
|
|
13
|
+
const result = (value, message) => ({ ok: true, message, details: JSON.stringify(value) })
|
|
14
|
+
export function createDeliveryTools(ctx, request) {
|
|
15
|
+
const context = exec => {
|
|
16
|
+
const sessionId = exec?.agent?.session?.id
|
|
17
|
+
if (!sessionId || !exec.callId) throw new Error('Remote 文件工具需要有效的 DSH 会话与工具调用编号')
|
|
18
|
+
exec.signal?.throwIfAborted()
|
|
19
|
+
return sessionId
|
|
20
|
+
}
|
|
21
|
+
const definition = (name, description, properties, required, execute) => ({ name, description, parameters: { ...objectSchema(properties), required }, output, execute, timeoutMs: 60000 })
|
|
22
|
+
return [
|
|
23
|
+
definition('remote_devices', 'List paired Remote receiving devices, including offline devices. Ask the user which device to use if ambiguous. Devices appear after opening the Remote file inbox.', {}, [], async (args, exec) => {
|
|
24
|
+
context(exec)
|
|
25
|
+
if (!args || Object.keys(args).length) throw new Error('remote_devices 不接受参数')
|
|
26
|
+
return result(await request('GET', null, exec.signal), '选择明确的接收设备;离线设备可以暂存文件,24 小时内打开 Remote 接收。')
|
|
27
|
+
}),
|
|
28
|
+
definition('remote_send_file', description, { path: string('Existing local regular file inside the calling session working directory, at most 50 MiB.'), device_id: string('Exact receiver id returned by remote_devices.'), title: string('Short title for the recipient.'), message: string('Optional explanation for the recipient, at most 600 characters.') }, ['path', 'device_id'], async (args, exec) => {
|
|
29
|
+
const sessionId = context(exec)
|
|
30
|
+
if (!args || Object.keys(args).some(k => !['path', 'device_id', 'title', 'message'].includes(k)) || typeof args.path !== 'string' || !args.path.trim() || typeof args.device_id !== 'string' || !args.device_id || args.title !== undefined && (typeof args.title !== 'string' || args.title.length > 120) || args.message !== undefined && (typeof args.message !== 'string' || args.message.length > 600)) throw new Error('文件、设备编号或说明参数无效')
|
|
31
|
+
// Resolve in the session's execution world first. Remote v1 additionally
|
|
32
|
+
// requires a host-local path under the current working directory.
|
|
33
|
+
const cwd = await ctx.workingDirectory.ensure(exec.agent, exec.signal)
|
|
34
|
+
const target = await ctx.fs.resolve(args.path, { cwd, signal: exec.signal })
|
|
35
|
+
const info = await ctx.fs.stat(target, exec.signal)
|
|
36
|
+
if (!info || info.type !== 'file' || info.size > 50 * 1024 * 1024) throw new Error('仅支持不超过 50 MiB 的本地普通文件')
|
|
37
|
+
const local = ctx.fs.processPath(target)
|
|
38
|
+
if (!isAbsolute(local) || !isAbsolute(cwd)) throw new Error('第一版仅支持主机本地工作目录中的文件')
|
|
39
|
+
const workspaceRoot = realpathSync(cwd), source = realpathSync(local), rel = relative(workspaceRoot, source)
|
|
40
|
+
if (!rel || rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) throw new Error('文件必须位于当前会话工作目录内,不能通过链接越界')
|
|
41
|
+
exec.signal?.throwIfAborted()
|
|
42
|
+
const id = createHash('sha256').update(sessionId + '\0' + exec.callId).digest('hex')
|
|
43
|
+
try {
|
|
44
|
+
const receipt = await request('POST', { action: 'send', id, path: resolve(source), workspaceRoot, deviceId: args.device_id, sessionId, title: args.title || '', message: args.message || '' }, exec.signal)
|
|
45
|
+
return result(receipt, '文件已投递待确认,尚未接收。使用 remote_file_status 查询;不要报告已保存。')
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error.confirmed) throw error
|
|
48
|
+
throw new Error('投递结果未确认,请勿重复发送。使用 remote_file_status 查询编号:' + id)
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
definition('remote_file_status', 'Check a delivery from this session. pending/accepted/downloading are not success; downloaded means handed to a browser, complete means the device reported saving it.', { transfer_id: string('Transfer id from remote_send_file, including an uncertain send error.') }, ['transfer_id'], async (args, exec) => {
|
|
52
|
+
const sessionId = context(exec)
|
|
53
|
+
if (!args || Object.keys(args).some(k => k !== 'transfer_id') || typeof args.transfer_id !== 'string' || !/^[a-zA-Z0-9-]{16,80}$/.test(args.transfer_id)) throw new Error('传输编号无效')
|
|
54
|
+
return result(await request('POST', { action: 'status', id: args.transfer_id, sessionId }, exec.signal), '状态以接收设备回执为准;downloaded 只表示交给浏览器保存,不能证明文件已落盘。')
|
|
55
|
+
}),
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function registerFileDeliveryTools(ctx, { gatewayBase, gatewayToken, fetchImpl = fetch }) {
|
|
60
|
+
if (typeof ctx.inject !== 'function') return false
|
|
61
|
+
ctx.inject(['tools', 'fs', 'workingDirectory'], child => {
|
|
62
|
+
const service = name => child.get?.(name) ?? child[name]
|
|
63
|
+
const scoped = { fs: service('fs'), workingDirectory: service('workingDirectory') }
|
|
64
|
+
const tools = service('tools')
|
|
65
|
+
if (!tools?.register || !scoped.fs?.resolve || !scoped.workingDirectory?.ensure) return
|
|
66
|
+
const request = async (method, body, signal) => {
|
|
67
|
+
const token = gatewayToken()
|
|
68
|
+
if (!token) throw Object.assign(new Error('Remote 网关尚未就绪,请先启动网关'), { confirmed: true })
|
|
69
|
+
const timeout = AbortSignal.timeout(55000)
|
|
70
|
+
const combined = new AbortController()
|
|
71
|
+
const abort = () => combined.abort()
|
|
72
|
+
signal?.addEventListener('abort', abort, { once: true }); timeout.addEventListener('abort', abort, { once: true })
|
|
73
|
+
if (signal?.aborted) abort()
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetchImpl(gatewayBase() + '/admin/api/file-inbox', { method, headers: { authorization: 'Bearer ' + token, 'content-type': 'application/json' }, ...(body ? { body: JSON.stringify(body) } : {}), signal: combined.signal, redirect: 'error' })
|
|
76
|
+
const data = await response.json()
|
|
77
|
+
if (!response.ok) throw Object.assign(new Error('Remote 文件投递被拒绝:' + String(data.error || response.status).slice(0, 100)), { confirmed: response.status < 500 })
|
|
78
|
+
return data
|
|
79
|
+
} finally { signal?.removeEventListener('abort', abort); timeout.removeEventListener('abort', abort) }
|
|
80
|
+
}
|
|
81
|
+
for (const definition of createDeliveryTools(scoped, request)) child.effect(() => tools.register(definition), 'dsh-remote: ' + definition.name)
|
|
82
|
+
})
|
|
83
|
+
return true
|
|
84
|
+
}
|