@sususgh/gamer-dsh-plugin 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,34 @@ function pairLandingPage(valid) {
83
83
 
84
84
  async function handle(req, res) {
85
85
  const url = new URL(req.url, 'http://127.0.0.1');
86
+ const origin = req.headers.origin;
87
+ const allowedOrigin = !origin || (() => {
88
+ try {
89
+ const parsed = new URL(origin);
90
+ const host = parsed.hostname.toLowerCase();
91
+ return host === 'deepseek.com' || host.endsWith('.deepseek.com')
92
+ || host === 'localhost' || host === '127.0.0.1';
93
+ } catch { return false; }
94
+ })();
95
+ if (origin && allowedOrigin) {
96
+ res.setHeader('access-control-allow-origin', origin);
97
+ res.setHeader('vary', 'Origin');
98
+ }
99
+ if (url.pathname.startsWith('/api/') && origin && !allowedOrigin) {
100
+ return sendJson(res, 403, { error: 'ORIGIN_NOT_ALLOWED' });
101
+ }
102
+ if (url.pathname.startsWith('/api/') && req.method === 'OPTIONS') {
103
+ if (!allowedOrigin) return sendJson(res, 403, { error: 'ORIGIN_NOT_ALLOWED' });
104
+ res.writeHead(204, {
105
+ 'access-control-allow-methods': 'GET, POST, OPTIONS',
106
+ 'access-control-allow-headers': 'content-type',
107
+ 'access-control-allow-private-network': 'true',
108
+ 'access-control-max-age': '600',
109
+ 'cache-control': 'no-store',
110
+ 'vary': 'Origin',
111
+ });
112
+ return res.end();
113
+ }
86
114
  res.setHeader('x-content-type-options', 'nosniff');
87
115
  res.setHeader('referrer-policy', 'no-referrer');
88
116
  res.setHeader('cache-control', 'no-store');
package/dsh/client.js CHANGED
@@ -53,13 +53,85 @@ window.__ModuleLoader__.load({
53
53
 
54
54
  function GamerConfig() {
55
55
  const [language, setLanguage] = React.useState('zh');
56
+ const [pairState, setPairState] = React.useState('正在连接桌面配对服务…');
57
+ const [qr, setQr] = React.useState('');
58
+ const [host, setHost] = React.useState('');
59
+ const [remaining, setRemaining] = React.useState(0);
60
+ const [error, setError] = React.useState('');
61
+ const [busy, setBusy] = React.useState(false);
62
+ const [addresses, setAddresses] = React.useState([]);
56
63
  const c = COPY[language];
64
+ const base = 'http://127.0.0.1:8765';
65
+
66
+ const generateQr = React.useCallback(async (selectedHost) => {
67
+ if (!selectedHost) return;
68
+ setBusy(true); setError(''); setPairState('正在生成安全二维码…');
69
+ try {
70
+ const response = await fetch(base + '/api/pairing/start', {
71
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
72
+ body: JSON.stringify({ host: selectedHost }),
73
+ cache: 'no-store'
74
+ });
75
+ const data = await response.json();
76
+ if (!response.ok) throw new Error(data.error || ('HTTP ' + response.status));
77
+ if (!data.qrDataUrl || !data.expiresAt) throw new Error('桌面服务未返回有效二维码');
78
+ setQr(data.qrDataUrl);
79
+ setHost(data.host + ':' + data.port);
80
+ setRemaining(Math.max(0, Math.floor((data.expiresAt - Date.now()) / 1000)));
81
+ setPairState('二维码已生成 · 等待手机扫码');
82
+ } catch (e) {
83
+ setQr(''); setPairState('二维码生成失败'); setError(e.message || String(e));
84
+ } finally { setBusy(false); }
85
+ }, []);
86
+
87
+ const detectAndGenerate = React.useCallback(async () => {
88
+ setBusy(true); setError(''); setPairState('正在检测桌面配对服务…');
89
+ try {
90
+ const response = await fetch(base + '/api/network/interfaces', { cache: 'no-store' });
91
+ if (!response.ok) throw new Error('桌面配对服务返回 HTTP ' + response.status);
92
+ const data = await response.json();
93
+ const list = Array.isArray(data.addresses) ? data.addresses : [];
94
+ setAddresses(list);
95
+ if (!list.length) throw new Error('未发现可供手机访问的局域网 IPv4 地址;请让电脑和手机连接同一 Wi-Fi。');
96
+ const selected = list[0].address;
97
+ await generateQr(selected);
98
+ } catch (e) {
99
+ setQr(''); setPairState('桌面配对服务不可用');
100
+ setError((e.message || String(e)) + '。请先在电脑运行 Gamer 桌面端启动脚本,并确认端口 8765 可用。');
101
+ setBusy(false);
102
+ }
103
+ }, [generateQr]);
104
+
105
+ React.useEffect(() => {
106
+ let alive = true;
107
+ const boot = async () => { if (alive) await detectAndGenerate(); };
108
+ boot();
109
+ return () => { alive = false; };
110
+ }, [detectAndGenerate]);
111
+
112
+ React.useEffect(() => {
113
+ if (!qr || remaining <= 0) return undefined;
114
+ const timer = setInterval(() => setRemaining(value => Math.max(0, value - 1)), 1000);
115
+ return () => clearInterval(timer);
116
+ }, [qr, remaining > 0]);
117
+
118
+ React.useEffect(() => {
119
+ if (qr && remaining === 0) { setQr(''); setPairState('二维码已过期,请重新生成'); }
120
+ }, [remaining, qr]);
121
+
122
+ const revoke = async () => {
123
+ try {
124
+ await fetch(base + '/api/pairing/stop', { method: 'POST' });
125
+ setQr(''); setRemaining(0); setPairState('二维码已撤销');
126
+ } catch (e) { setError('撤销失败:' + (e.message || String(e))); }
127
+ };
128
+
57
129
  return h('section', { style: { display: 'flex', flexDirection: 'column', gap: '18px', width: '100%', color: 'var(--dsw-alias-label-primary, inherit)' } },
58
130
  h('header', { style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '16px', flexWrap: 'wrap' } },
59
131
  h('div', null,
60
- h('div', { style: { fontSize: '19px', fontWeight: 700, letterSpacing: '-.02em' } }, c.title),
132
+ h('div', { style: { fontSize: '19px', fontWeight: 700 } }, c.title),
61
133
  h('div', { style: { marginTop: '5px', fontSize: '12px', color: 'var(--dsw-alias-label-tertiary, #888)' } }, c.subtitle),
62
- h('div', { style: { marginTop: '5px', fontSize: '11px', color: 'var(--dsw-alias-label-tertiary, #888)' } }, c.version)
134
+ h('div', { style: { marginTop: '5px', fontSize: '11px', color: 'var(--dsw-alias-label-tertiary, #888)' } }, '版本 1.0.2')
63
135
  ),
64
136
  h('div', { role: 'group', 'aria-label': c.language, style: { display: 'flex', gap: '4px', padding: '3px', borderRadius: '10px', background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.08))' } },
65
137
  ...[['zh', c.chinese], ['en', c.english]].map(([key, label]) => h('button', {
@@ -70,39 +142,33 @@ window.__ModuleLoader__.load({
70
142
  }, label))
71
143
  )
72
144
  ),
73
- h('section', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
74
- h('div', { style: { fontSize: '14px', fontWeight: 650 } }, c.overview),
75
- h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } },
76
- h('span', { style: { width: '8px', height: '8px', borderRadius: '50%', background: '#2eaa72', display: 'inline-block' } }), c.ready),
77
- h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(190px,1fr))', gap: '9px' } },
78
- h(StatusTile, { label: c.desktop, value: c.desktopValue }),
79
- h(StatusTile, { label: c.android, value: c.androidValue }),
80
- h(StatusTile, { label: c.vision, value: c.visionValue }),
81
- h(StatusTile, { label: c.automation, value: c.automationValue })
82
- )
83
- ),
84
- h('section', { style: { padding: '16px', borderRadius: '14px', border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))', display: 'grid', gridTemplateColumns: 'minmax(0,1fr) minmax(180px,220px)', gap: '18px', alignItems: 'center' } },
145
+ h('section', { style: { display: 'grid', gridTemplateColumns: 'minmax(0,1fr) minmax(180px,220px)', gap: '18px', alignItems: 'center', padding: '16px', borderRadius: '14px', border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))' } },
85
146
  h('div', { style: { minWidth: 0 } },
86
147
  h('div', { style: { fontSize: '15px', fontWeight: 700 } }, c.pairing),
87
- h('p', { style: { margin: '7px 0 10px', fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, c.pairingHint),
88
- h('div', { style: { fontSize: '13px', fontWeight: 650 } }, c.qrUnavailable),
89
- h('p', { style: { margin: '6px 0 0', fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-tertiary, #888)' } }, c.qrDetail),
90
- h('p', { style: { margin: '7px 0 0', fontSize: '11px', lineHeight: 1.5, color: 'var(--dsw-alias-label-tertiary, #888)' } }, c.qrNote)
91
- ),
92
- h('div', { style: { minHeight: '176px', borderRadius: '12px', border: '1px dashed var(--dsw-alias-border-l2, rgba(127,127,127,.35))', background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.05))', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '10px', textAlign: 'center', padding: '14px' } },
93
- h('svg', { width: 52, height: 52, viewBox: '0 0 52 52', fill: 'none', 'aria-hidden': true },
94
- h('rect', { x: 8, y: 3, width: 26, height: 44, rx: 5, stroke: 'currentColor', strokeWidth: 2 }),
95
- h('path', { d: 'M17 10h8M19 40h4', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }),
96
- h('path', { d: 'M38 17l7 7-7 7M45 24H30', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round' })
148
+ h('p', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, '页面加载后会自动连接本机 Gamer 桌面服务并生成真实二维码。电脑与手机需要处于同一局域网。'),
149
+ h('div', { style: { fontSize: '13px', fontWeight: 650 } }, pairState),
150
+ host ? h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, '电脑地址:' + host) : null,
151
+ h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, qr ? ('有效期:' + Math.floor(remaining / 60) + ':' + String(remaining % 60).padStart(2, '0')) : '有效期:未生成'),
152
+ error ? h('p', { role: 'alert', style: { color: '#c45b50', fontSize: '12px', lineHeight: 1.6 } }, error) : null,
153
+ addresses.length > 1 ? h('label', { style: { display: 'block', fontSize: '12px', marginTop: '8px' } }, '可用网络:',
154
+ h('select', { value: host.split(':')[0], onChange: e => generateQr(e.target.value), style: { marginLeft: '6px', maxWidth: '100%' } },
155
+ ...addresses.map(item => h('option', { key: item.address, value: item.address }, item.name + ' · ' + item.address))
156
+ )
157
+ ) : null,
158
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap', marginTop: '12px' } },
159
+ h('button', { type: 'button', disabled: busy, onClick: detectAndGenerate, style: { border: 0, borderRadius: '8px', padding: '9px 13px', cursor: busy ? 'wait' : 'pointer' } }, busy ? '正在处理…' : '重新生成二维码'),
160
+ h('button', { type: 'button', disabled: !qr, onClick: revoke, style: { borderRadius: '8px', padding: '9px 13px', cursor: qr ? 'pointer' : 'not-allowed' } }, '撤销二维码')
97
161
  ),
98
- h('div', { style: { fontSize: '12px', fontWeight: 650 } }, c.status),
99
- h('div', { style: { fontSize: '11px', color: 'var(--dsw-alias-label-tertiary, #888)' } }, 'QR · Pending')
162
+ h('p', { style: { fontSize: '11px', lineHeight: 1.55, color: 'var(--dsw-alias-label-tertiary, #888)' } }, '安全提示:二维码仅包含 5 分钟有效的一次性配对令牌,不包含模型 API Key。扫码识别不等于认证完成;Android Companion 尚未接入前不会显示已连接。')
163
+ ),
164
+ h('div', { style: { minHeight: '190px', borderRadius: '12px', border: '1px dashed var(--dsw-alias-border-l2, rgba(127,127,127,.35))', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '8px', padding: '12px' } },
165
+ qr ? h('img', { src: qr, alt: 'Gamer 一次性设备配对二维码', style: { width: '100%', maxWidth: '190px', imageRendering: 'pixelated' } }) : h('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-tertiary, #888)', textAlign: 'center' } }, '等待真实二维码…'),
166
+ h('div', { style: { fontSize: '12px', fontWeight: 650 } }, qr ? 'QR · READY' : 'QR · PENDING')
100
167
  )
101
168
  ),
102
169
  h('section', { style: { padding: '14px', borderRadius: '12px', background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))' } },
103
- h('div', { style: { fontSize: '13px', fontWeight: 700, marginBottom: '5px' } }, c.roadmap),
104
- h('div', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, c.roadmapText),
105
- h('div', { style: { marginTop: '8px', fontSize: '11px', lineHeight: 1.5, color: 'var(--dsw-alias-label-tertiary, #888)' } }, c.noGameControl)
170
+ h('div', { style: { fontSize: '13px', fontWeight: 700, marginBottom: '5px' } }, c.overview),
171
+ h('div', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, 'DSH 插件界面与桌面配对服务通过本机回环地址通信。若服务未启动,请先运行桌面端启动脚本。游戏控制、视觉识别和 Android 双端认证仍需各自运行时实现。')
106
172
  ),
107
173
  h('a', { href: 'https://github.com/sususgh/Gamer-DSH-Plugin', target: '_blank', rel: 'noreferrer',
108
174
  style: { fontSize: '12px', color: 'var(--dsw-alias-label-link, #4b91d1)', textDecoration: 'none' } }, c.repo + ' ↗')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sususgh/gamer-dsh-plugin",
3
- "version": "1.0.1",
4
- "description": "Native DeepSeek Harness plugin with desktop QR pairing runtime and UI for the Gamer AI game-agent project",
3
+ "version": "1.0.2",
4
+ "description": "Native DeepSeek Harness plugin with automatic desktop QR pairing and Gamer runtime UI",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "author": "sususgh",
@@ -52,12 +52,17 @@
52
52
  },
53
53
  "scripts": {
54
54
  "test": "node --test",
55
- "check": "node --check dsh/index.js && node --check dsh/client.js && node --check desktop-runtime/pairing.js && node --check desktop-runtime/server.js && node --check desktop-ui/app.js"
55
+ "check": "node --check dsh/index.js && node --check dsh/client.js && node --check desktop-runtime/pairing.js && node --check desktop-runtime/server.js && node --check desktop-ui/app.js",
56
+ "desktop": "node desktop-runtime/server.js",
57
+ "start:desktop": "node desktop-runtime/server.js"
56
58
  },
57
59
  "publishConfig": {
58
60
  "access": "public"
59
61
  },
60
62
  "engines": {
61
63
  "node": ">=22.13"
64
+ },
65
+ "dependencies": {
66
+ "qrcode": "^1.5.4"
62
67
  }
63
- }
68
+ }