dsh-phone-link 0.1.0 → 0.2.0

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.md CHANGED
@@ -5,7 +5,9 @@
5
5
 
6
6
  **中文显示名:远程助手** · 包名:`dsh-phone-link`
7
7
 
8
- > 收录说明:可按 [docs/PUBLISHING.md](./docs/PUBLISHING.md) 提交到 DSH Plugin Hub(https://dsh-plugin.org/)与 awesome-dsh-plugin 目录;提交动作由维护者完成。
8
+ 本项目授权 [DSH Plugin](https://dsh-plugin.org/) 收录本仓库,并在该站展示插件信息。
9
+
10
+ > 其他收录渠道详见 [docs/PUBLISHING.md](./docs/PUBLISHING.md)。
9
11
 
10
12
  把手机 App 安全地接到本机正在运行的 DeepSeek Harness(DSH)会话:手机看会话、发消息、处理工具审批;插件只做进程内桥接,不新增端口、不启动子进程、不需要 Tailscale 或额外运行时。
11
13
 
package/client.js ADDED
@@ -0,0 +1,100 @@
1
+ /* dsh-phone-link 浏览器半区:左侧“远程助手”入口
2
+ * 通过官方 sidebar.footer.action 插槽挂载,点击后在右侧面板打开连接页。
3
+ * 产物入库,无构建步骤。 */
4
+ window.__ModuleLoader__.load({
5
+ id: 'dsh-phone-link-client',
6
+ factory: (require) => {
7
+ var module = { exports: {} }
8
+ var exports = module.exports
9
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
10
+
11
+ var React = require('react')
12
+ var LABEL = '远程助手'
13
+ var CONNECT_PATH = '/phone-link/connect'
14
+ var injected = function () {
15
+ return { open: open }
16
+ }
17
+
18
+ async function resolveUrl() {
19
+ // Web 版:同域相对路径即可;Desktop dsh-app 协议:向宿主问本机地址
20
+ if (location.protocol !== 'dsh-app:') return CONNECT_PATH
21
+ try {
22
+ var res = await fetch('/phone-link/launch', { credentials: 'same-origin' })
23
+ var data = await res.json()
24
+ if (data.ok && data.url) return data.url
25
+ } catch (_) {}
26
+ return CONNECT_PATH
27
+ }
28
+
29
+ async function open() {
30
+ var target = await resolveUrl()
31
+ if (location.protocol === 'dsh-app:') {
32
+ window.open(target, '_blank', 'noopener,noreferrer')
33
+ } else {
34
+ try {
35
+ var api = require('@deepseek-ai/dsh-client-ui-sidebar')
36
+ if (api && api.sidebarRight && api.sidebarRight.openTab) {
37
+ api.sidebarRight.openTab('browser', target, { title: LABEL })
38
+ return
39
+ }
40
+ } catch (_) {}
41
+ window.open(target, '_blank', 'noopener,noreferrer')
42
+ }
43
+ }
44
+
45
+ function Icon() {
46
+ return React.createElement('svg', {
47
+ viewBox: '0 0 24 24', 'aria-hidden': true, focusable: false,
48
+ style: { width: 16, height: 16, display: 'block', flexShrink: 0 },
49
+ fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
50
+ },
51
+ React.createElement('rect', { x: 6, y: 2, width: 12, height: 20, rx: 2 }),
52
+ React.createElement('path', { d: 'M11 18h2' })
53
+ )
54
+ }
55
+
56
+ function Entry(props) {
57
+ var onClick = function () {
58
+ if (props.onDismiss) props.onDismiss()
59
+ void props.inject.open()
60
+ }
61
+ var MenuItemButton
62
+ try { MenuItemButton = require('@deepseek-ai/dsh-client-ui-primitives').MenuItemButton } catch (_) {}
63
+ if (MenuItemButton) {
64
+ return React.createElement(MenuItemButton, { icon: React.createElement(Icon), onSelect: onClick }, LABEL)
65
+ }
66
+ return React.createElement('button', {
67
+ type: 'button', title: LABEL, onClick: onClick,
68
+ style: { display: 'flex', alignItems: 'center', gap: 8, padding: 8, border: 0, background: 'transparent', color: 'inherit', cursor: 'pointer', font: 'inherit' },
69
+ }, React.createElement(Icon), props.wide ? LABEL : null)
70
+ }
71
+
72
+ var inject = ['slots']
73
+
74
+ function apply(ctx) {
75
+ // 新版本宿主:侧边栏底部动作区(与“设置”同一行),并兼容折叠态
76
+ ctx.effect(function () {
77
+ return ctx.slots.inject('sidebar.footer.action', function () {
78
+ return ctx.slots.register(
79
+ { name: 'sidebar.footer.action', id: 'dsh-phone-link', inject: injected },
80
+ Entry
81
+ )
82
+ })
83
+ }, 'dsh-phone-link: sidebar entry')
84
+
85
+ // 兼容把入口收进“更多”菜单的宿主
86
+ ctx.effect(function () {
87
+ return ctx.slots.inject('sidebar.panellist.actions', function () {
88
+ return ctx.slots.register(
89
+ { name: 'sidebar.panellist.actions', id: 'dsh-phone-link-more', inject: injected },
90
+ Entry
91
+ )
92
+ })
93
+ }, 'dsh-phone-link: more menu entry')
94
+ }
95
+
96
+ exports.apply = apply
97
+ exports.inject = inject
98
+ return module.exports
99
+ },
100
+ })
package/cordis.patch.yml CHANGED
@@ -1,11 +1,11 @@
1
- - id: phone-link
2
- name: dsh-phone-link
3
- config:
4
- serverUrl: https://api.example.com
5
- relayPath: /ws/v1/connect
6
- pairPath: /phone-link/pair
7
- heartbeatMs: 30000
8
- reconnectMinMs: 1000
9
- reconnectMaxMs: 30000
10
- approvalTimeoutMs: 60000
11
- autoConnect: true
1
+ - id: phone-link
2
+ name: dsh-phone-link
3
+ config:
4
+ serverUrl: https://harness.xiangjianli.top
5
+ relayPath: /ws/v1/connect
6
+ pairPath: /phone-link/pair
7
+ heartbeatMs: 30000
8
+ reconnectMinMs: 1000
9
+ reconnectMaxMs: 30000
10
+ approvalTimeoutMs: 60000
11
+ autoConnect: true
@@ -2,6 +2,15 @@
2
2
 
3
3
  目标:用户执行 `dsh plugin --profile web add dsh-phone-link` 即可按名称安装,同时被插件市场收录。
4
4
 
5
+ ## 当前发布状态(2026-12-04)
6
+
7
+ - npm:`dsh-phone-link@0.1.0` 已发布,latest 指向 0.1.0,公开安装验证通过。
8
+ - GitHub 仓库:`https://github.com/mostcat1992-code/dsh-phone-link`(公开,分支 main,已设 dsh-plugin 等 topics)。
9
+ - dsh-plugin.org 收录 Issue:`https://github.com/dshplugin/dsh-plugin-hub/issues/1017`(待审核刷新)。
10
+ - awesome-dsh-plugins Curated PR:`https://github.com/cccakeee/awesome-dsh-plugins/pull/88`(合并后自动进入 deepseekharnessplugins.com 的 Curated 分类)。
11
+ - deepseekharnessplugins.com:已通过 `dsh-plugin` topic 进入自动收录路径(每日刷新,约 1–2 天出现)。
12
+ - 注意:npm 账户启用了 2FA,发布用 Granular Access Token(Bypass 2FA),该令牌 2027-01 失效;长期维护请改 GitHub Trusted Publishing。
13
+
5
14
  ## 1. 先锁定名称
6
15
 
7
16
  npm 上的 `dsh-phone-link` 目前未被占用。尽快发布 `0.1.0` 占住名字:
package/lib/index.js CHANGED
@@ -1,91 +1,91 @@
1
- import { createBridge } from './bridge.js'
2
- import { ensureState, registerRoutes, saveState } from './pairing.js'
3
- import { RelayTransport } from './transport.js'
4
-
5
- export const name = 'phone-link'
6
- export const inject = []
7
-
8
- let SchemaFallback = null
9
- try {
10
- const mod = await import('@deepseek-ai/schemastery')
11
- SchemaFallback = mod.default ?? mod
12
- } catch {
13
- SchemaFallback = null
14
- }
15
-
16
- export const Config = SchemaFallback
17
- ? SchemaFallback.object({
18
- serverUrl: SchemaFallback.string().default('https://api.example.com'),
19
- relayPath: SchemaFallback.string().default('/ws/v1/connect'),
20
- pairPath: SchemaFallback.string().default('/phone-link/pair'),
21
- deviceName: SchemaFallback.string().default('DSH desktop'),
22
- heartbeatMs: SchemaFallback.number().default(30000),
23
- reconnectMinMs: SchemaFallback.number().default(1000),
24
- reconnectMaxMs: SchemaFallback.number().default(30000),
25
- approvalTimeoutMs: SchemaFallback.number().default(60000),
26
- autoConnect: SchemaFallback.boolean().default(true),
27
- })
28
- : {
29
- serverUrl: 'https://api.example.com',
30
- relayPath: '/ws/v1/connect',
31
- pairPath: '/phone-link/pair',
32
- deviceName: 'DSH desktop',
33
- heartbeatMs: 30000,
34
- reconnectMinMs: 1000,
35
- reconnectMaxMs: 30000,
36
- approvalTimeoutMs: 60000,
37
- autoConnect: true,
38
- }
39
-
40
- export async function apply(ctx, config = {}) {
41
- const log = ctx.logger ?? console
42
- const state = await ensureState()
43
- let currentSession = null
44
-
45
- const transport = new RelayTransport({
46
- config,
47
- identity: state.identity,
48
- device: state.device,
49
- log,
50
- onRpc: (method, params) => bridge.handleRpc(method, params),
51
- onEvent: (type, payload) => {
52
- if (type === 'connected') log?.info?.('phone connected: %s', payload.connectionId)
53
- },
54
- })
55
-
56
- const bridge = createBridge({ ctx, transport, config, log })
57
- bridge.installEventBridge()
58
- bridge.installApprovalGate()
59
-
60
- registerRoutes(ctx, config, {
61
- setState: (s) => {
62
- state.deviceId = s.deviceId
63
- state.identity = s.identity
64
- },
65
- setSession: (s) => {
66
- currentSession = s
67
- },
68
- getSession: () => currentSession,
69
- onPaired: async (result) => {
70
- state.device = {
71
- deviceId: result.device?.deviceId ?? state.deviceId,
72
- tokens: result.tokens,
73
- phoneIdentityKey: result.peer?.identityKey ?? result.phone?.identityKey ?? null,
74
- }
75
- await saveState(state)
76
- transport.device = state.device
77
- if (config.autoConnect !== false) transport.start()
78
- },
79
- })
80
-
81
- if (config.autoConnect !== false && state.device?.tokens?.accessToken) {
82
- transport.start()
83
- } else if (config.serverUrl?.includes('example.com')) {
84
- log?.warn?.('[phone-link] set serverUrl in plugin config before pairing')
85
- }
86
-
87
- ctx.effect(() => () => {
88
- transport.stop()
89
- bridge.dispose()
90
- })
91
- }
1
+ import { createBridge } from './bridge.js'
2
+ import { ensureState, registerRoutes, saveState } from './pairing.js'
3
+ import { RelayTransport } from './transport.js'
4
+
5
+ export const name = 'phone-link'
6
+ export const inject = []
7
+
8
+ let SchemaFallback = null
9
+ try {
10
+ const mod = await import('@deepseek-ai/schemastery')
11
+ SchemaFallback = mod.default ?? mod
12
+ } catch {
13
+ SchemaFallback = null
14
+ }
15
+
16
+ export const Config = SchemaFallback
17
+ ? SchemaFallback.object({
18
+ serverUrl: SchemaFallback.string().default('https://harness.xiangjianli.top'),
19
+ relayPath: SchemaFallback.string().default('/ws/v1/connect'),
20
+ pairPath: SchemaFallback.string().default('/phone-link/pair'),
21
+ deviceName: SchemaFallback.string().default('DSH desktop'),
22
+ heartbeatMs: SchemaFallback.number().default(30000),
23
+ reconnectMinMs: SchemaFallback.number().default(1000),
24
+ reconnectMaxMs: SchemaFallback.number().default(30000),
25
+ approvalTimeoutMs: SchemaFallback.number().default(60000),
26
+ autoConnect: SchemaFallback.boolean().default(true),
27
+ })
28
+ : {
29
+ serverUrl: 'https://harness.xiangjianli.top',
30
+ relayPath: '/ws/v1/connect',
31
+ pairPath: '/phone-link/pair',
32
+ deviceName: 'DSH desktop',
33
+ heartbeatMs: 30000,
34
+ reconnectMinMs: 1000,
35
+ reconnectMaxMs: 30000,
36
+ approvalTimeoutMs: 60000,
37
+ autoConnect: true,
38
+ }
39
+
40
+ export async function apply(ctx, config = {}) {
41
+ const log = ctx.logger ?? console
42
+ const state = await ensureState()
43
+ let currentSession = null
44
+
45
+ const transport = new RelayTransport({
46
+ config,
47
+ identity: state.identity,
48
+ device: state.device,
49
+ log,
50
+ onRpc: (method, params) => bridge.handleRpc(method, params),
51
+ onEvent: (type, payload) => {
52
+ if (type === 'connected') log?.info?.('phone connected: %s', payload.connectionId)
53
+ },
54
+ })
55
+
56
+ const bridge = createBridge({ ctx, transport, config, log })
57
+ bridge.installEventBridge()
58
+ bridge.installApprovalGate()
59
+
60
+ registerRoutes(ctx, config, {
61
+ setState: (s) => {
62
+ state.deviceId = s.deviceId
63
+ state.identity = s.identity
64
+ },
65
+ setSession: (s) => {
66
+ currentSession = s
67
+ },
68
+ getSession: () => currentSession,
69
+ onPaired: async (result) => {
70
+ state.device = {
71
+ deviceId: result.device?.deviceId ?? state.deviceId,
72
+ tokens: result.tokens,
73
+ phoneIdentityKey: result.peer?.identityKey ?? result.phone?.identityKey ?? null,
74
+ }
75
+ await saveState(state)
76
+ transport.device = state.device
77
+ if (config.autoConnect !== false) transport.start()
78
+ },
79
+ })
80
+
81
+ if (config.autoConnect !== false && state.device?.tokens?.accessToken) {
82
+ transport.start()
83
+ } else if (config.serverUrl?.includes('example.com')) {
84
+ log?.warn?.('[phone-link] set serverUrl in plugin config before pairing')
85
+ }
86
+
87
+ ctx.effect(() => () => {
88
+ transport.stop()
89
+ bridge.dispose()
90
+ })
91
+ }
package/lib/pairing.js CHANGED
@@ -36,6 +36,7 @@ function api(config, p) {
36
36
  return new URL(p, config.serverUrl).toString()
37
37
  }
38
38
 
39
+ // ---- 旧版配对流程(保留兼容) ----
39
40
  export async function createPairing(config, state) {
40
41
  const res = await fetch(api(config, '/api/v1/pairing/sessions'), {
41
42
  method: 'POST',
@@ -68,10 +69,56 @@ export async function confirmPairing(config, sessionId, code) {
68
69
  return res.json()
69
70
  }
70
71
 
71
- export async function pairPage(session, config) {
72
- const qr = session.qrUrl || session.ticketUrl || `https://${new URL(config.serverUrl).host}/pair#v1.${session.ticket}`
72
+ // ---- 新版连接流程:6 位码 + PC 人工确认 ----
73
+ export async function createConnectSession(config, state) {
74
+ const res = await fetch(api(config, '/api/v1/connect/sessions'), {
75
+ method: 'POST',
76
+ headers: { 'content-type': 'application/json' },
77
+ body: JSON.stringify({
78
+ device: {
79
+ deviceId: state.deviceId,
80
+ name: config.deviceName || 'DSH desktop',
81
+ identityKey: state.identity.publicKey,
82
+ platform: 'desktop',
83
+ },
84
+ }),
85
+ })
86
+ if (!res.ok) throw new Error(`create connect session failed: HTTP ${res.status}`)
87
+ return res.json()
88
+ }
89
+
90
+ export async function pollConnect(config, sessionId) {
91
+ const res = await fetch(api(config, '/api/v1/connect/sessions/pending'), {
92
+ method: 'POST',
93
+ headers: { 'content-type': 'application/json' },
94
+ body: JSON.stringify({ sessionId }),
95
+ })
96
+ if (!res.ok) throw new Error(`poll failed: HTTP ${res.status}`)
97
+ return res.json()
98
+ }
99
+
100
+ export async function approveConnect(config, sessionId, action = 'approve') {
101
+ const res = await fetch(api(config, '/api/v1/connect/sessions/approve'), {
102
+ method: 'POST',
103
+ headers: { 'content-type': 'application/json' },
104
+ body: JSON.stringify({ sessionId, action }),
105
+ })
106
+ if (!res.ok) throw new Error(`approve failed: HTTP ${res.status}`)
107
+ return res.json()
108
+ }
109
+
110
+ function escapeHtml(s) {
111
+ return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]))
112
+ }
113
+
114
+ async function qrSvg(text, width = 220) {
73
115
  const { default: QRCode } = await import('qrcode')
74
- const svg = await QRCode.toString(qr, { type: 'svg', width: 240, margin: 1 })
116
+ return QRCode.toString(text, { type: 'svg', width, margin: 1 })
117
+ }
118
+
119
+ export async function pairPage(session, config) {
120
+ const qr = session.qrUrl || `https://${new URL(config.serverUrl).host}/pair#v1.${session.ticket}`
121
+ const svg = await qrSvg(qr, 240)
75
122
  return `<!doctype html>
76
123
  <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
77
124
  <title>dsh-phone-link 配对</title>
@@ -106,8 +153,94 @@ document.getElementById('f').addEventListener('submit', async (e) => {
106
153
  </script></body></html>`
107
154
  }
108
155
 
109
- function escapeHtml(s) {
110
- return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]))
156
+ export async function connectPage(session, config) {
157
+ const svg = await qrSvg(session.qrUrl, 220)
158
+ const seconds = Math.max(1, Math.round((session.expiresAt - Date.now()) / 1000))
159
+ return `<!doctype html>
160
+ <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
161
+ <title>远程助手 · 连接</title>
162
+ <style>
163
+ *{box-sizing:border-box}
164
+ body{font-family:system-ui,-apple-system,"PingFang SC","Microsoft YaHei",sans-serif;margin:0;background:#f7f8fa;color:#1f2329}
165
+ .wrap{max-width:560px;margin:0 auto;padding:28px 20px 60px}
166
+ h1{font-size:20px;margin:0 0 6px}
167
+ .sub{color:#646a73;font-size:13px;margin-bottom:24px}
168
+ .card{background:#fff;border:1px solid #e5e6eb;border-radius:12px;padding:20px;margin-bottom:16px}
169
+ .code{font-size:40px;letter-spacing:10px;font-weight:600;text-align:center;color:#1f2329;margin:8px 0 4px;font-variant-numeric:tabular-nums}
170
+ .timer{text-align:center;color:#8f959e;font-size:13px}
171
+ .qr{text-align:center;margin:14px 0}
172
+ .qr svg{border:1px solid #e5e6eb;border-radius:8px;padding:8px;background:#fff}
173
+ .row{display:flex;justify-content:space-between;font-size:13px;color:#646a73;margin-top:8px}
174
+ .badge{display:inline-block;padding:2px 8px;border-radius:10px;background:#e8f3ff;color:#1f6feb;font-size:12px}
175
+ .status{margin-top:14px;padding:12px;border-radius:8px;background:#f5f6f7;color:#646a73;font-size:14px;text-align:center}
176
+ .status.waiting{background:#fff8e6;color:#a06300}
177
+ .status.requested{background:#e8f3ff;color:#1f6feb}
178
+ .status.confirmed{background:#e8ffea;color:#1a7f37}
179
+ .btns{display:flex;gap:10px;margin-top:12px}
180
+ button{flex:1;padding:11px;border:0;border-radius:8px;font-size:14px;cursor:pointer}
181
+ .primary{background:#1f6feb;color:#fff}
182
+ .ghost{background:#f2f3f5;color:#1f2329}
183
+ .danger{background:#fef1f1;color:#c0392b}
184
+ .modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:none;align-items:center;justify-content:center;padding:20px}
185
+ .modal.on{display:flex}
186
+ .modal .box{background:#fff;border-radius:14px;padding:24px;max-width:400px;width:100%}
187
+ .modal h2{font-size:18px;margin:0 0 12px}
188
+ .modal p{font-size:14px;color:#646a73;line-height:1.7;word-break:break-all}
189
+ .fp{font-family:ui-monospace,monospace;background:#f5f6f7;padding:2px 6px;border-radius:4px;font-size:12px}
190
+ </style></head><body>
191
+ <div class="wrap">
192
+ <h1>远程助手 <span class="badge">连接设备</span></h1>
193
+ <div class="sub">用手机 App 扫描二维码,或输入下方 6 位连接码</div>
194
+ <div class="card">
195
+ <div class="code" id="code">${escapeHtml(session.code)}</div>
196
+ <div class="timer">有效期 <span id="timer">${seconds}</span> 秒 · 仅本次有效</div>
197
+ <div class="qr">${svg}</div>
198
+ <div class="row"><span>服务器</span><span>${escapeHtml(config.serverUrl)}</span></div>
199
+ <div class="row"><span>本机指纹</span><span class="fp">${escapeHtml(session.host?.identityKey ? fingerprint(session.host.identityKey).slice(0, 20) : '—')}</span></div>
200
+ </div>
201
+ <div class="card"><div class="status waiting" id="status" data-sid="${escapeHtml(session.sessionId)}">等待手机发起连接…</div><div id="action"></div></div>
202
+ <div class="sub" style="margin-top:18px">请在电脑上核实手机的显示名称与指纹后再同意。拒绝或超时会自动作废。</div>
203
+ </div>
204
+ <div class="modal" id="modal"><div class="box">
205
+ <h2>允许这台手机连接?</h2>
206
+ <p>设备名称:<b id="m-name"></b></p>
207
+ <p>手机指纹:<span class="fp" id="m-fp"></span></p>
208
+ <p style="color:#c0392b">同意后,该手机可查看会话列表、历史消息并发送消息。</p>
209
+ <div class="btns"><button class="ghost" id="m-reject">拒绝</button><button class="primary" id="m-approve">同意连接</button></div>
210
+ </div></div>
211
+ <script>
212
+ (function(){
213
+ var sid=${JSON.stringify(session.sessionId)};
214
+ var status=document.getElementById('status'), action=document.getElementById('action');
215
+ var modal=document.getElementById('modal'), decided=false;
216
+ function fmt(s){s=String(s||'');return s.length>18?s.slice(0,18)+'…':s}
217
+ async function decide(act){
218
+ decided=true;
219
+ var r=await fetch(location.pathname+'/approve',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({sessionId:sid,action:act})});
220
+ var d=await r.json().catch(()=>({}));
221
+ modal.classList.remove('on');
222
+ if(d.ok){status.className='status '+(act==='approve'?'confirmed':'waiting');status.textContent=act==='approve'?'已连接,可以关闭此页面。':'已拒绝本次连接。';action.innerHTML='';}
223
+ else{status.textContent=d.error||'操作失败';decided=false;}
224
+ }
225
+ document.getElementById('m-approve').onclick=function(){decide('approve')};
226
+ document.getElementById('m-reject').onclick=function(){decide('reject')};
227
+ async function poll(){
228
+ try{
229
+ var r=await fetch(location.pathname+'/pending',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({sessionId:sid})});
230
+ var d=await r.json().catch(()=>({}));
231
+ if(!d.ok){status.textContent=d.error||'会话已失效,请重新打开';return}
232
+ if(d.status==='requested'){
233
+ status.className='status requested';status.textContent='手机请求连接中,请在弹窗中确认';
234
+ if(!decided){document.getElementById('m-name').textContent=d.request?.name||'未知设备';document.getElementById('m-fp').textContent=fmt(d.request?.identityKey);modal.classList.add('on')}
235
+ }else if(d.status==='confirmed'){
236
+ status.className='status confirmed';status.textContent='已连接,可以关闭此页面。';action.innerHTML='';
237
+ }else if(d.status==='failed'){status.textContent='连接码已作废,请重新打开';}
238
+ }catch(e){}
239
+ }
240
+ var n=${seconds};var t=setInterval(function(){n--;var el=document.getElementById('timer');if(el)el.textContent=Math.max(0,n);if(n<=0){clearInterval(t);status.textContent='连接码已过期,请重新打开';}},1000);
241
+ poll();setInterval(poll,1500);
242
+ })();
243
+ </script></body></html>`
111
244
  }
112
245
 
113
246
  export function registerRoutes(ctx, config, handlers) {
@@ -154,5 +287,78 @@ export function registerRoutes(ctx, config, handlers) {
154
287
  }
155
288
  },
156
289
  }))
290
+
291
+ // 新版连接页:展示 6 位码 + 二维码 + 手机请求确认弹窗
292
+ child.effect(() => child.webServer.register({
293
+ kind: 'exact',
294
+ path: '/phone-link/connect',
295
+ handler: async (_req, res) => {
296
+ res.setHeader('content-type', 'text/html; charset=utf-8')
297
+ res.setHeader('cache-control', 'no-store')
298
+ try {
299
+ if (config.serverUrl.includes('example.com')) throw new Error('请先在插件配置中设置 serverUrl')
300
+ const state = await ensureState()
301
+ handlers.setState(state)
302
+ const session = await createConnectSession(config, state)
303
+ handlers.setSession(session)
304
+ res.end(await connectPage(session, config))
305
+ } catch (err) {
306
+ res.statusCode = 500
307
+ res.end(`<pre>${escapeHtml(err.message)}</pre>`)
308
+ }
309
+ },
310
+ }))
311
+
312
+ child.effect(() => child.webServer.register({
313
+ kind: 'exact',
314
+ path: '/phone-link/connect/pending',
315
+ handler: async (req, res) => {
316
+ res.setHeader('content-type', 'application/json; charset=utf-8')
317
+ res.setHeader('cache-control', 'no-store')
318
+ try {
319
+ const chunks = []
320
+ for await (const c of req) chunks.push(c)
321
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}')
322
+ const data = await pollConnect(config, body.sessionId)
323
+ res.end(JSON.stringify({ ok: true, status: data.status, request: data.request }))
324
+ } catch (err) {
325
+ res.end(JSON.stringify({ ok: false, error: err.message }))
326
+ }
327
+ },
328
+ }))
329
+
330
+ child.effect(() => child.webServer.register({
331
+ kind: 'exact',
332
+ path: '/phone-link/connect/approve',
333
+ handler: async (req, res) => {
334
+ res.setHeader('content-type', 'application/json; charset=utf-8')
335
+ res.setHeader('cache-control', 'no-store')
336
+ try {
337
+ const chunks = []
338
+ for await (const c of req) chunks.push(c)
339
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}')
340
+ const sessionId = body.sessionId || handlers.getSession()?.sessionId
341
+ if (!sessionId) throw new Error('会话不存在,请重新打开连接页')
342
+ const result = await approveConnect(config, sessionId, body.action || 'approve')
343
+ if (body.action !== 'reject') handlers.onPaired(result)
344
+ res.end(JSON.stringify({ ok: true }))
345
+ } catch (err) {
346
+ res.end(JSON.stringify({ ok: false, error: err.message }))
347
+ }
348
+ },
349
+ }))
350
+
351
+ // 供浏览器半区取连接页地址(Desktop dsh-app 协议下用外部浏览器打开)
352
+ child.effect(() => child.webServer.register({
353
+ kind: 'exact',
354
+ path: '/phone-link/launch',
355
+ handler: async (_req, res) => {
356
+ res.setHeader('content-type', 'application/json; charset=utf-8')
357
+ res.setHeader('cache-control', 'no-store')
358
+ const port = config.connectPagePort || ctx.webServer?.port || ctx.webServer?.options?.port || null
359
+ const url = config.connectPageUrl || (port ? `http://127.0.0.1:${port}/phone-link/connect` : null)
360
+ res.end(JSON.stringify({ ok: !!url, url }))
361
+ },
362
+ }))
157
363
  })
158
364
  }
package/lib/transport.js CHANGED
@@ -207,6 +207,13 @@ export class RelayTransport {
207
207
  if (p.retryable === false) this.stop()
208
208
  else this._scheduleReconnect(p.message || 'server error')
209
209
  break
210
+ case 'host.query': {
211
+ const { requestId, method, params } = p
212
+ Promise.resolve(this.onRpc?.(method, params || {}))
213
+ .then((result) => this.send('query.response', { requestId, result: result ?? null }))
214
+ .catch((err) => this.send('query.response', { requestId, error: { code: err.code || 'RPC_FAILED', message: err.message } }))
215
+ break
216
+ }
210
217
  case 'pong':
211
218
  break
212
219
  default:
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "dsh-phone-link",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "displayName": "远程助手",
5
5
  "description": "远程助手 — Link a phone app to a local DeepSeek Harness session through your own relay and backend. · 把手机 App 经自建中继接到本机 DSH 会话。",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
8
8
  "exports": {
9
9
  ".": "./lib/index.js",
10
+ "./client": "./client.js",
10
11
  "./package.json": "./package.json",
11
12
  "./cordis.patch.yml": "./cordis.patch.yml"
12
13
  },
13
14
  "files": [
14
15
  "lib",
16
+ "client.js",
15
17
  "cordis.patch.yml",
16
18
  "README.md",
17
19
  "CHANGELOG.md",
@@ -26,6 +28,13 @@
26
28
  },
27
29
  "bundle": {
28
30
  "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "inject": [
34
+ "@deepseek-ai/dsh-client-runtime",
35
+ "@deepseek-ai/dsh-client-ui-slots"
36
+ ],
37
+ "platform": "web"
29
38
  }
30
39
  },
31
40
  "keywords": [
@@ -46,7 +55,7 @@
46
55
  },
47
56
  "scripts": {
48
57
  "test": "node --test test/*.test.js",
49
- "verify": "node --check lib/index.js && node --check lib/crypto.js && node --check lib/transport.js && node --check lib/bridge.js && node --check lib/pairing.js && node --test test/*.test.js",
58
+ "verify": "node --check lib/index.js && node --check lib/crypto.js && node --check lib/transport.js && node --check lib/bridge.js && node --check lib/pairing.js && node --check client.js && node --test test/*.test.js",
50
59
  "pack:check": "npm pack --dry-run"
51
60
  },
52
61
  "dependencies": {