@sususgh/gamer-dsh-plugin 1.0.1 → 1.0.4

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
@@ -19,10 +19,29 @@ The phone is not expected to host a large language model. It can perform lightwe
19
19
  - **Desktop role:** main processing, local game control, model routing, device bridge and telemetry
20
20
  - **Android role:** mobile game runtime, screen/audio/sensor observations when permitted, touch execution and acknowledgements
21
21
 
22
- > **Project status:** This repository is being bootstrapped. The first desktop UI shell is a visual prototype. Network values, model health and device status are not real until their runtime adapters are connected and tested. This README describes the intended architecture and integration contract; it does not claim that every planned feature is already implemented.
22
+ > **Project status:** This repository is being bootstrapped. The DSH plugin page now attempts to connect to the local desktop pairing service at `127.0.0.1:8765` and automatically generates a short-lived QR code when that service is running. The desktop server provides QR generation and a scan landing page; Android companion authentication is not yet implemented. Network values, model health and device status are not real until their runtime adapters are connected and tested. This README describes the intended architecture and integration contract; it does not claim that every planned feature is already implemented.
23
23
 
24
24
  ---
25
25
 
26
+ ## Start the desktop QR pairing service
27
+
28
+ Requirements: Node.js 22.13 or newer.
29
+
30
+ ```bash
31
+ npm install
32
+ npm run desktop
33
+ ```
34
+
35
+ The desktop service listens on port 8765 and prints the computer's private LAN IPv4 address. Keep it running while using the DSH plugin page. The plugin page connects to `http://127.0.0.1:8765`, discovers a private LAN address and requests a fresh QR code automatically. On Windows, run the same commands in PowerShell or Command Prompt.
36
+
37
+ If the browser blocks local-network access, allow the DSH application to access the local network and retry. The local API accepts browser origins from `deepseek.com` subdomains and localhost only. QR tokens expire after five minutes. Scanning the QR currently validates the one-time token and opens a landing page; it does **not** complete Android authentication or establish a connected companion session.
38
+
39
+ ## DSH model registry integration
40
+
41
+ The plugin now injects the Harness `llm` service and registers the model-callable tool `gamer_list_ai_models`. When invoked by the active DSH model, it reads currently registered provider routes with `ctx.llm.listProviders()` and each provider's advertised models with `ctx.llm.listModels(provider)`. It returns provider/model identifiers and availability only; it never returns API keys or secret values.
42
+
43
+ This confirms model-registry discovery, not phone gameplay. The active conversation model can call Gamer tools because they are registered through `ctx.tools`; however, authenticated Android transport, screen capture, vision inference, and device input adapters must all be implemented and validated before the model can actually play a phone game. The plugin must report those capabilities as unavailable until they pass runtime checks.
44
+
26
45
  ## 1. What the project does
27
46
 
28
47
  Gamer is designed to let an AI agent play supported games through a closed feedback loop:
@@ -0,0 +1,51 @@
1
+ const ACTIONS = new Set(['tap', 'swipe', 'key', 'wait']);
2
+
3
+ export class SafetyGate {
4
+ #stopped = true;
5
+ #paired = false;
6
+ #permissions = new Set();
7
+
8
+ setPaired(value) { this.#paired = value === true; }
9
+ grant(permission) { this.#permissions.add(permission); }
10
+ revoke(permission) { this.#permissions.delete(permission); }
11
+ stop() { this.#stopped = true; }
12
+ arm() {
13
+ if (!this.#paired) throw new Error('DEVICE_NOT_PAIRED');
14
+ if (!this.#permissions.has('input')) throw new Error('INPUT_PERMISSION_REQUIRED');
15
+ this.#stopped = false;
16
+ }
17
+ get stopped() { return this.#stopped; }
18
+
19
+ validate(action) {
20
+ if (this.#stopped) throw new Error('AGENT_STOPPED');
21
+ if (!this.#paired) throw new Error('DEVICE_NOT_PAIRED');
22
+ if (!action || typeof action !== 'object' || !ACTIONS.has(action.type)) {
23
+ throw new Error('ACTION_TYPE_NOT_ALLOWED');
24
+ }
25
+ if (action.type === 'tap') {
26
+ for (const key of ['x', 'y']) {
27
+ if (!Number.isFinite(action[key]) || action[key] < 0 || action[key] > 1) {
28
+ throw new Error('INVALID_NORMALIZED_COORDINATE');
29
+ }
30
+ }
31
+ } else if (action.type === 'swipe') {
32
+ for (const key of ['x1', 'y1', 'x2', 'y2']) {
33
+ if (!Number.isFinite(action[key]) || action[key] < 0 || action[key] > 1) {
34
+ throw new Error('INVALID_NORMALIZED_COORDINATE');
35
+ }
36
+ }
37
+ if (!Number.isInteger(action.durationMs) || action.durationMs < 50 || action.durationMs > 3000) {
38
+ throw new Error('INVALID_ACTION_DURATION');
39
+ }
40
+ } else if (action.type === 'key') {
41
+ if (typeof action.key !== 'string' || !/^[A-Z0-9_]{1,24}$/.test(action.key)) {
42
+ throw new Error('INVALID_KEY');
43
+ }
44
+ } else if (action.type === 'wait') {
45
+ if (!Number.isInteger(action.durationMs) || action.durationMs < 0 || action.durationMs > 5000) {
46
+ throw new Error('INVALID_ACTION_DURATION');
47
+ }
48
+ }
49
+ return Object.freeze({ ...action });
50
+ }
51
+ }
@@ -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');
@@ -145,7 +173,7 @@ async function handle(req, res) {
145
173
  if (url.pathname === '/pair' && req.method === 'GET') {
146
174
  const valid = url.searchParams.get('protocol') === 'gamer-runtime/1'
147
175
  && url.searchParams.get('instance_id') === manager.instanceId
148
- && manager.verify(url.searchParams.get('token'));
176
+ && manager.verify(url.searchParams.get('token'), { consume: true });
149
177
  res.writeHead(valid ? 200 : 410, {
150
178
  'content-type': 'text/html; charset=utf-8',
151
179
  'cache-control': 'no-store',
package/desktop-ui/app.js CHANGED
@@ -19,23 +19,67 @@ const pairHostSelect=$('pairHostSelect');
19
19
  const pairRefresh=$('pairRefresh');
20
20
  const pairStop=$('pairStop');
21
21
  let pairExpiryTimer=null;
22
+ let pairGenerating=false;
23
+ let lastPairHost='';
22
24
 
23
25
  function setPairState(text){$('pairState').textContent=text;}
24
26
  function clearPairQr(){
25
27
  if(pairQrImage){pairQrImage.hidden=true;pairQrImage.removeAttribute('src');}
26
28
  if(pairQrEmpty)pairQrEmpty.hidden=false;
27
- $('pairQrCaption').textContent='点击生成二维码';
29
+ $('pairQrCaption').textContent='正在等待自动生成…';
28
30
  $('pairExpires').textContent='5 分钟 · 未生成';
29
31
  if(pairStop)pairStop.disabled=true;
30
32
  if(pairExpiryTimer){clearInterval(pairExpiryTimer);pairExpiryTimer=null;}
31
33
  }
32
- async function loadPairNetworks(){
34
+ async function generatePairQr({automatic=false}={}){
35
+ if(pairGenerating||!pairHostSelect?.value)return;
36
+ pairGenerating=true;
37
+ try{
38
+ pairRefresh.disabled=true;
39
+ setPairState(automatic?'正在自动生成安全二维码…':'正在生成安全二维码…');
40
+ const response=await fetch('/api/pairing/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({host:pairHostSelect.value}),cache:'no-store'});
41
+ const data=await response.json();
42
+ if(!response.ok)throw new Error(data.error||'HTTP '+response.status);
43
+ if(!data.qrDataUrl||!Number.isFinite(data.expiresAt))throw new Error('二维码服务返回数据不完整');
44
+ pairQrImage.src=data.qrDataUrl;pairQrImage.hidden=false;pairQrEmpty.hidden=true;
45
+ $('pairQrCaption').textContent='真实二维码 · 手机扫码';
46
+ $('pairHost').textContent=data.host+':'+data.port;
47
+ $('pairExpires').textContent='05:00';
48
+ setPairState('二维码已自动生成 · 等待手机扫码');
49
+ pairStop.disabled=false;
50
+ if(pairExpiryTimer)clearInterval(pairExpiryTimer);
51
+ const expiresAt=data.expiresAt;
52
+ pairExpiryTimer=setInterval(()=>{
53
+ const remaining=Math.max(0,expiresAt-Date.now());
54
+ const mm=String(Math.floor(remaining/60000)).padStart(2,'0');
55
+ const ss=String(Math.floor((remaining%60000)/1000)).padStart(2,'0');
56
+ $('pairExpires').textContent=mm+':'+ss;
57
+ if(remaining<=0){
58
+ clearInterval(pairExpiryTimer);pairExpiryTimer=null;clearPairQr();
59
+ setPairState('二维码已过期,正在自动刷新…');
60
+ log('配对二维码已过期,正在自动生成新二维码。');
61
+ setTimeout(()=>generatePairQr({automatic:true}),1200);
62
+ }
63
+ },250);
64
+ log((automatic?'自动':'手动')+'生成电脑端安全二维码:'+data.host+':'+data.port+',有效期 5 分钟。');
65
+ }catch(error){
66
+ setPairState('生成失败:'+error.message);
67
+ $('pairQrCaption').textContent='生成失败,请点击重新生成';
68
+ log('二维码生成失败:'+error.message);
69
+ }finally{
70
+ pairGenerating=false;
71
+ pairRefresh.disabled=!pairHostSelect?.value;
72
+ }
73
+ }
74
+ async function loadPairNetworks({autoGenerate=false}={}){
33
75
  try{
34
76
  const response=await fetch('/api/network/interfaces',{cache:'no-store'});
35
77
  if(!response.ok)throw new Error('HTTP '+response.status);
36
78
  const data=await response.json();
79
+ const addresses=data.addresses||[];
80
+ const previous=pairHostSelect.value;
37
81
  pairHostSelect.replaceChildren();
38
- for(const item of data.addresses||[]){
82
+ for(const item of addresses){
39
83
  const option=document.createElement('option');
40
84
  option.value=item.address;option.textContent=item.name+' · '+item.address;
41
85
  pairHostSelect.append(option);
@@ -45,10 +89,18 @@ async function loadPairNetworks(){
45
89
  $('pairHost').textContent='未发现局域网地址';
46
90
  setPairState('请连接 Wi-Fi 或检查网络');
47
91
  pairRefresh.disabled=true;
48
- }else{
49
- $('pairHost').textContent=pairHostSelect.value;
50
- setPairState('配对服务已就绪');
51
- pairRefresh.disabled=false;
92
+ return;
93
+ }
94
+ if(addresses.some(item=>item.address===previous))pairHostSelect.value=previous;
95
+ const host=pairHostSelect.value;
96
+ $('pairHost').textContent=host;
97
+ pairRefresh.disabled=false;
98
+ if(autoGenerate||host!==lastPairHost){
99
+ lastPairHost=host;
100
+ await generatePairQr({automatic:true});
101
+ }else if(!pairQrImage.src||pairQrImage.hidden){
102
+ setPairState('配对服务已就绪,正在自动生成二维码…');
103
+ await generatePairQr({automatic:true});
52
104
  }
53
105
  }catch(error){
54
106
  pairHostSelect.replaceChildren();
@@ -58,41 +110,22 @@ async function loadPairNetworks(){
58
110
  log('无法连接桌面配对服务:'+error.message+'。请勿直接双击 index.html。');
59
111
  }
60
112
  }
61
- pairHostSelect?.addEventListener('change',()=>{$('pairHost').textContent=pairHostSelect.value||'未选择';});
62
- pairRefresh?.addEventListener('click',async()=>{
63
- try{
64
- pairRefresh.disabled=true;setPairState('正在生成安全二维码…');
65
- const response=await fetch('/api/pairing/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({host:pairHostSelect.value})});
66
- const data=await response.json();
67
- if(!response.ok)throw new Error(data.error||'HTTP '+response.status);
68
- pairQrImage.src=data.qrDataUrl;pairQrImage.hidden=false;pairQrEmpty.hidden=true;
69
- $('pairQrCaption').textContent='真实二维码 · 手机扫码';
70
- $('pairHost').textContent=data.host+':'+data.port;
71
- $('pairExpires').textContent='05:00';
72
- setPairState('二维码已生成 · 等待手机扫码');
73
- pairStop.disabled=false;
74
- if(pairExpiryTimer)clearInterval(pairExpiryTimer);
75
- const expiresAt=data.expiresAt;
76
- pairExpiryTimer=setInterval(()=>{
77
- const remaining=Math.max(0,expiresAt-Date.now());
78
- const mm=String(Math.floor(remaining/60000)).padStart(2,'0');
79
- const ss=String(Math.floor((remaining%60000)/1000)).padStart(2,'0');
80
- $('pairExpires').textContent=mm+':'+ss;
81
- if(remaining<=0){clearInterval(pairExpiryTimer);pairExpiryTimer=null;clearPairQr();setPairState('二维码已过期,请重新生成');log('手机配对二维码已过期。');}
82
- },250);
83
- log('电脑端已生成真实配对二维码:'+data.host+':'+data.port+',有效期 5 分钟。');
84
- }catch(error){
85
- setPairState('生成失败:'+error.message);log('二维码生成失败:'+error.message);
86
- }finally{pairRefresh.disabled=!pairHostSelect.value;}
113
+ pairHostSelect?.addEventListener('change',()=>{
114
+ $('pairHost').textContent=pairHostSelect.value||'未选择';
115
+ lastPairHost=pairHostSelect.value;
116
+ generatePairQr({automatic:true});
87
117
  });
118
+ pairRefresh?.addEventListener('click',()=>generatePairQr());
88
119
  pairStop?.addEventListener('click',async()=>{
89
120
  try{
90
- const response=await fetch('/api/pairing/stop',{method:'POST'});
121
+ const response=await fetch('/api/pairing/stop',{method:'POST',cache:'no-store'});
91
122
  if(!response.ok)throw new Error('HTTP '+response.status);
92
123
  clearPairQr();setPairState('二维码已撤销');log('电脑端配对二维码已撤销。');
93
124
  }catch(error){setPairState('撤销失败:'+error.message);log('撤销二维码失败:'+error.message);}
94
125
  });
95
- loadPairNetworks();
126
+ loadPairNetworks({autoGenerate:true});
127
+ window.addEventListener('online',()=>loadPairNetworks({autoGenerate:true}));
128
+ setInterval(()=>loadPairNetworks(),30000);
96
129
 
97
130
 
98
131
  $('visionTestBtn')?.addEventListener('click',()=>{log('视觉自检请求已记录;当前仓库尚未接入帧采集、OCR 或目标检测运行时。');$('visionEngineState').textContent='运行时未接入';});
package/dsh/client.js CHANGED
@@ -53,13 +53,90 @@ 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) {
120
+ setQr('');
121
+ setPairState('二维码已过期,正在自动刷新…');
122
+ const address = host.split(':')[0];
123
+ if (address) generateQr(address);
124
+ }
125
+ }, [remaining, qr, host, generateQr]);
126
+
127
+ const revoke = async () => {
128
+ try {
129
+ await fetch(base + '/api/pairing/stop', { method: 'POST' });
130
+ setQr(''); setRemaining(0); setPairState('二维码已撤销');
131
+ } catch (e) { setError('撤销失败:' + (e.message || String(e))); }
132
+ };
133
+
57
134
  return h('section', { style: { display: 'flex', flexDirection: 'column', gap: '18px', width: '100%', color: 'var(--dsw-alias-label-primary, inherit)' } },
58
135
  h('header', { style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '16px', flexWrap: 'wrap' } },
59
136
  h('div', null,
60
- h('div', { style: { fontSize: '19px', fontWeight: 700, letterSpacing: '-.02em' } }, c.title),
137
+ h('div', { style: { fontSize: '19px', fontWeight: 700 } }, c.title),
61
138
  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)
139
+ h('div', { style: { marginTop: '5px', fontSize: '11px', color: 'var(--dsw-alias-label-tertiary, #888)' } }, '版本 1.0.2')
63
140
  ),
64
141
  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
142
  ...[['zh', c.chinese], ['en', c.english]].map(([key, label]) => h('button', {
@@ -70,39 +147,33 @@ window.__ModuleLoader__.load({
70
147
  }, label))
71
148
  )
72
149
  ),
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' } },
150
+ 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
151
  h('div', { style: { minWidth: 0 } },
86
152
  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' })
153
+ h('p', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, '页面加载后会自动连接本机 Gamer 桌面服务并生成真实二维码。电脑与手机需要处于同一局域网。'),
154
+ h('div', { style: { fontSize: '13px', fontWeight: 650 } }, pairState),
155
+ host ? h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, '电脑地址:' + host) : null,
156
+ h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, qr ? ('有效期:' + Math.floor(remaining / 60) + ':' + String(remaining % 60).padStart(2, '0')) : '有效期:未生成'),
157
+ error ? h('p', { role: 'alert', style: { color: '#c45b50', fontSize: '12px', lineHeight: 1.6 } }, error) : null,
158
+ addresses.length > 1 ? h('label', { style: { display: 'block', fontSize: '12px', marginTop: '8px' } }, '可用网络:',
159
+ h('select', { value: host.split(':')[0], onChange: e => generateQr(e.target.value), style: { marginLeft: '6px', maxWidth: '100%' } },
160
+ ...addresses.map(item => h('option', { key: item.address, value: item.address }, item.name + ' · ' + item.address))
161
+ )
162
+ ) : null,
163
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap', marginTop: '12px' } },
164
+ h('button', { type: 'button', disabled: busy, onClick: detectAndGenerate, style: { border: 0, borderRadius: '8px', padding: '9px 13px', cursor: busy ? 'wait' : 'pointer' } }, busy ? '正在处理…' : '重新生成二维码'),
165
+ h('button', { type: 'button', disabled: !qr, onClick: revoke, style: { borderRadius: '8px', padding: '9px 13px', cursor: qr ? 'pointer' : 'not-allowed' } }, '撤销二维码')
97
166
  ),
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')
167
+ h('p', { style: { fontSize: '11px', lineHeight: 1.55, color: 'var(--dsw-alias-label-tertiary, #888)' } }, '安全提示:二维码仅包含 5 分钟有效的一次性配对令牌,不包含模型 API Key。扫码识别不等于认证完成;Android Companion 尚未接入前不会显示已连接。')
168
+ ),
169
+ 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' } },
170
+ 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' } }, '等待真实二维码…'),
171
+ h('div', { style: { fontSize: '12px', fontWeight: 650 } }, qr ? 'QR · READY' : 'QR · PENDING')
100
172
  )
101
173
  ),
102
174
  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)
175
+ h('div', { style: { fontSize: '13px', fontWeight: 700, marginBottom: '5px' } }, c.overview),
176
+ h('div', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, 'DSH 插件界面与桌面配对服务通过本机回环地址通信。若服务未启动,请先运行桌面端启动脚本。游戏控制、视觉识别和 Android 双端认证仍需各自运行时实现。')
106
177
  ),
107
178
  h('a', { href: 'https://github.com/sususgh/Gamer-DSH-Plugin', target: '_blank', rel: 'noreferrer',
108
179
  style: { fontSize: '12px', color: 'var(--dsw-alias-label-link, #4b91d1)', textDecoration: 'none' } }, c.repo + ' ↗')
package/dsh/index.js CHANGED
@@ -1,54 +1,118 @@
1
1
  /**
2
- * Gamer DSH Plugin — native DeepSeek Harness entry point.
2
+ * Gamer DSH Plugin — model-aware native Harness integration.
3
3
  *
4
- * This first installable integration deliberately reports the current runtime
5
- * honestly: the repository currently contains a desktop UI prototype, not a
6
- * connected game-control engine. No game input is sent and no device is
7
- * paired by this plugin yet.
4
+ * The plugin reads the registered DSH model routes through ctx.llm and exposes
5
+ * that inventory as a model-callable tool. It does not claim gameplay control
6
+ * until an authenticated desktop/Android runtime is connected.
8
7
  */
9
-
10
8
  export const name = 'gamer-dsh-plugin';
11
- export const inject = ['tools'];
9
+ export const inject = ['tools', 'llm'];
12
10
 
13
- const STATUS_SCHEMA = {
11
+ const EMPTY_SCHEMA = {
14
12
  type: 'object',
15
13
  properties: {},
16
14
  additionalProperties: false,
17
15
  };
18
16
 
19
- export function apply(ctx) {
17
+ const JSON_OUTPUT = {
18
+ schema: {
19
+ type: 'object',
20
+ properties: {
21
+ status: { type: 'string' },
22
+ providers: { type: 'array', items: { type: 'object' } },
23
+ count: { type: 'integer' },
24
+ message: { type: 'string' },
25
+ },
26
+ required: ['status', 'providers', 'count', 'message'],
27
+ additionalProperties: false,
28
+ },
29
+ render: (_args, value) => [{
30
+ type: 'text',
31
+ text: JSON.stringify(value, null, 2),
32
+ }],
33
+ presentationMeta: () => ({}),
34
+ };
35
+
36
+ function register(ctx, definition) {
20
37
  if (typeof ctx?.tools?.register !== 'function') {
21
- console.error('[gamer-dsh-plugin] DSH tools service is unavailable; status tool was not registered.');
38
+ throw new Error('DSH_TOOLS_SERVICE_UNAVAILABLE');
39
+ }
40
+ ctx.tools.register(definition);
41
+ }
42
+
43
+ export function apply(ctx) {
44
+ if (!ctx?.llm || typeof ctx.llm.listProviders !== 'function'
45
+ || typeof ctx.llm.listModels !== 'function') {
46
+ console.error('[gamer-dsh-plugin] DSH llm service unavailable; model discovery tool was not registered.');
22
47
  return;
23
48
  }
24
49
 
25
- ctx.tools.register({
50
+ register(ctx, {
51
+ name: 'gamer_list_ai_models',
52
+ description:
53
+ 'List AI model providers and models currently registered in this DeepSeek Harness instance. Use this before selecting a model for Gamer gameplay. This reads the Harness model registry; it does not expose API keys or secrets.',
54
+ parameters: EMPTY_SCHEMA,
55
+ output: JSON_OUTPUT,
56
+ async execute() {
57
+ const providers = await ctx.llm.listProviders();
58
+ const inventory = await Promise.all(providers.map(async provider => {
59
+ try {
60
+ const models = await ctx.llm.listModels(provider.id);
61
+ return {
62
+ provider: provider.id,
63
+ providerName: provider.name,
64
+ models: models.map(model => ({
65
+ id: model.id,
66
+ name: model.name ?? model.id,
67
+ ...(model.contextWindow ? { contextWindow: model.contextWindow } : {}),
68
+ })),
69
+ available: true,
70
+ };
71
+ } catch (error) {
72
+ return {
73
+ provider: provider.id,
74
+ providerName: provider.name,
75
+ models: [],
76
+ available: false,
77
+ error: error?.message || 'MODEL_DISCOVERY_FAILED',
78
+ };
79
+ }
80
+ }));
81
+ const count = inventory.reduce((sum, item) => sum + item.models.length, 0);
82
+ return {
83
+ status: inventory.length ? 'providers_found' : 'no_provider_registered',
84
+ providers: inventory,
85
+ count,
86
+ message: inventory.length
87
+ ? 'Model registry read from DSH. The model calling this tool remains the active conversation model; API credentials were not returned.'
88
+ : 'No active LLM provider adapter is registered in DSH. Configure and enable a provider before starting Gamer.',
89
+ };
90
+ },
91
+ });
92
+
93
+ register(ctx, {
26
94
  name: 'gamer_project_status',
27
95
  description:
28
- 'Return the verified implementation and runtime status of Gamer-DSH-Plugin. The v1.0.1 release includes a bilingual DSH plugin configuration page, but it does not yet include a connected game-control runtime, desktop pairing server or Android companion bridge.',
29
- parameters: STATUS_SCHEMA,
96
+ 'Return verified Gamer runtime status. Distinguish model discovery from an authenticated Android connection and real gameplay control.',
97
+ parameters: EMPTY_SCHEMA,
30
98
  output: {
31
99
  schema: {
32
100
  type: 'object',
33
101
  properties: {
34
102
  project: { type: 'string' },
35
103
  version: { type: 'string' },
36
- integration: { type: 'string' },
37
- pluginLoaded: { type: 'boolean' },
38
- desktopUi: { type: 'string' },
104
+ modelDiscovery: { type: 'string' },
39
105
  androidCompanion: { type: 'string' },
40
106
  visionRuntime: { type: 'string' },
41
107
  gameControlRuntime: { type: 'string' },
42
- qrPairing: { type: 'string' },
43
108
  canControlGames: { type: 'boolean' },
44
109
  nextStep: { type: 'string' },
45
110
  repository: { type: 'string' },
46
- release: { type: 'string' },
47
111
  },
48
112
  required: [
49
- 'project', 'version', 'integration', 'pluginLoaded', 'desktopUi',
50
- 'androidCompanion', 'visionRuntime', 'gameControlRuntime', 'qrPairing',
51
- 'canControlGames', 'nextStep', 'repository', 'release',
113
+ 'project', 'version', 'modelDiscovery', 'androidCompanion',
114
+ 'visionRuntime', 'gameControlRuntime', 'canControlGames',
115
+ 'nextStep', 'repository',
52
116
  ],
53
117
  additionalProperties: false,
54
118
  },
@@ -59,21 +123,20 @@ export function apply(ctx) {
59
123
  presentationMeta: () => ({}),
60
124
  },
61
125
  async execute() {
126
+ const providers = await ctx.llm.listProviders();
62
127
  return {
63
128
  project: 'Gamer-DSH-Plugin',
64
- version: '1.0.1',
65
- integration: 'native DSH bundle',
66
- pluginLoaded: true,
67
- desktopUi: 'plugin configuration page available; game-control dashboard prototype',
68
- androidCompanion: 'not connected',
129
+ version: '1.0.2-dev',
130
+ modelDiscovery: providers.length
131
+ ? providers.map(item => item.name || item.id).join(', ')
132
+ : 'No registered model provider',
133
+ androidCompanion: 'not authenticated; Android handshake not implemented',
69
134
  visionRuntime: 'not implemented',
70
- gameControlRuntime: 'not implemented',
71
- qrPairing: 'not implemented',
135
+ gameControlRuntime: 'not connected; no game actions can be executed',
72
136
  canControlGames: false,
73
- nextStep: 'Complete and validate the desktop engine and Android companion before enabling game-control tools.',
137
+ nextStep: 'Complete authenticated desktop-to-Android session transport, screen capture, vision inference and input adapters; run device acceptance tests.',
74
138
  repository: 'https://github.com/sususgh/Gamer-DSH-Plugin',
75
- release: 'https://github.com/sususgh/Gamer-DSH-Plugin/releases/tag/v1.0.1'
76
139
  };
77
- }
140
+ },
78
141
  });
79
142
  }
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.4",
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 && node --check desktop-runtime/engine/safety-gate.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
+ }