@sususgh/gamer-dsh-plugin 1.0.2 → 1.0.5
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 +20 -1
- package/desktop-runtime/engine/safety-gate.js +51 -0
- package/desktop-runtime/server.js +50 -1
- package/desktop-ui/app.js +68 -35
- package/dsh/client.js +25 -12
- package/dsh/index.js +94 -31
- package/package.json +6 -4
- package/start-linux.sh +18 -0
- package/start-windows.bat +30 -0
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
|
|
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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { readFile } from 'node:fs/promises';
|
|
@@ -9,7 +10,12 @@ import { PairingManager } from './pairing.js';
|
|
|
9
10
|
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
11
|
const UI_ROOT = path.join(ROOT, 'desktop-ui');
|
|
11
12
|
const PORT = Number.parseInt(process.env.GAMER_PORT || '8765', 10);
|
|
13
|
+
if (!Number.isInteger(PORT) || PORT < 1 || PORT > 65535) {
|
|
14
|
+
console.error('[gamer-desktop] Invalid GAMER_PORT. Use an integer from 1 to 65535.');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
12
17
|
const manager = new PairingManager();
|
|
18
|
+
const pairedSessions = new Map();
|
|
13
19
|
const MIME = {
|
|
14
20
|
'.html': 'text/html; charset=utf-8',
|
|
15
21
|
'.js': 'text/javascript; charset=utf-8',
|
|
@@ -162,12 +168,55 @@ async function handle(req, res) {
|
|
|
162
168
|
});
|
|
163
169
|
}
|
|
164
170
|
|
|
171
|
+
if (url.pathname === '/api/pairing/claim' && req.method === 'POST') {
|
|
172
|
+
let body;
|
|
173
|
+
try { body = await readJson(req); }
|
|
174
|
+
catch (error) { return sendJson(res, 400, { error: error.message }); }
|
|
175
|
+
if (body.protocol !== 'gamer-runtime/1' || body.instance_id !== manager.instanceId
|
|
176
|
+
|| typeof body.device_id !== 'string' || body.device_id.length < 8 || body.device_id.length > 128
|
|
177
|
+
|| typeof body.device_name !== 'string' || body.device_name.length > 120) {
|
|
178
|
+
return sendJson(res, 400, { error: 'INVALID_PAIRING_REQUEST' });
|
|
179
|
+
}
|
|
180
|
+
if (!manager.verify(body.token, { consume: true })) {
|
|
181
|
+
return sendJson(res, 410, { error: 'PAIRING_TOKEN_INVALID_EXPIRED_OR_USED' });
|
|
182
|
+
}
|
|
183
|
+
const sessionId = randomBytes(18).toString('base64url');
|
|
184
|
+
const sessionToken = randomBytes(32).toString('base64url');
|
|
185
|
+
pairedSessions.set(sessionId, {
|
|
186
|
+
tokenHash: createHash('sha256').update(sessionToken).digest('hex'),
|
|
187
|
+
deviceId: body.device_id,
|
|
188
|
+
deviceName: body.device_name,
|
|
189
|
+
createdAt: Date.now(),
|
|
190
|
+
lastSeenAt: Date.now(),
|
|
191
|
+
});
|
|
192
|
+
return sendJson(res, 200, {
|
|
193
|
+
paired: true,
|
|
194
|
+
protocol: 'gamer-runtime/1',
|
|
195
|
+
instanceId: manager.instanceId,
|
|
196
|
+
sessionId,
|
|
197
|
+
sessionToken,
|
|
198
|
+
device: { id: body.device_id, name: body.device_name },
|
|
199
|
+
capabilities: { pairing: true, heartbeat: true, screenCapture: false, inputControl: false, modelInference: false },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (url.pathname === '/api/pairing/heartbeat' && req.method === 'POST') {
|
|
204
|
+
const auth = req.headers.authorization || '';
|
|
205
|
+
const token = auth.startsWith('Bearer ') ? auth.slice(7) : '';
|
|
206
|
+
const hash = createHash('sha256').update(token).digest('hex');
|
|
207
|
+
const entry = [...pairedSessions.entries()].find(([, value]) => value.tokenHash === hash);
|
|
208
|
+
if (!entry) return sendJson(res, 401, { error: 'SESSION_UNAUTHORIZED' });
|
|
209
|
+
entry[1].lastSeenAt = Date.now();
|
|
210
|
+
return sendJson(res, 200, { connected: true, sessionId: entry[0], serverTime: Date.now() });
|
|
211
|
+
}
|
|
212
|
+
|
|
165
213
|
if (url.pathname === '/api/pairing/stop' && req.method === 'POST') {
|
|
166
214
|
if (!isLoopback(req.socket.remoteAddress)) {
|
|
167
215
|
return sendJson(res, 403, { error: 'PAIRING_CONTROL_LOCAL_ONLY' });
|
|
168
216
|
}
|
|
169
217
|
manager.stop();
|
|
170
|
-
|
|
218
|
+
pairedSessions.clear();
|
|
219
|
+
return sendJson(res, 200, { active: false, sessionsRevoked: true });
|
|
171
220
|
}
|
|
172
221
|
|
|
173
222
|
if (url.pathname === '/pair' && req.method === 'GET') {
|
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
|
|
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
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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',()=>{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
@@ -7,7 +7,7 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
|
|
8
8
|
const COPY = {
|
|
9
9
|
zh: {
|
|
10
|
-
title: 'Gamer 游戏智能体', subtitle: 'PC 游戏控制中心 · Android 手机伴侣', version: '版本 1.0.
|
|
10
|
+
title: 'Gamer 游戏智能体', subtitle: 'PC 游戏控制中心 · Android 手机伴侣', version: '版本 1.0.5',
|
|
11
11
|
overview: '运行状态', ready: 'DSH 插件入口已加载',
|
|
12
12
|
desktop: '桌面端控制台', desktopValue: '界面框架已提供,游戏运行时尚未接入',
|
|
13
13
|
android: 'Android 手机伴侣', androidValue: '通信服务尚未接入',
|
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
status: '未连接', noGameControl: '当前版本不会控制游戏或发送键鼠/触控指令。'
|
|
24
24
|
},
|
|
25
25
|
en: {
|
|
26
|
-
title: 'Gamer AI Agent', subtitle: 'PC game control center · Android companion', version: 'Version 1.0.
|
|
26
|
+
title: 'Gamer AI Agent', subtitle: 'PC game control center · Android companion', version: 'Version 1.0.5',
|
|
27
27
|
overview: 'Runtime status', ready: 'Native DSH plugin entry loaded',
|
|
28
28
|
desktop: 'Desktop control center', desktopValue: 'UI shell is present; game runtime is not connected',
|
|
29
29
|
android: 'Android companion', androidValue: 'Communication service is not connected',
|
|
@@ -31,7 +31,7 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
automation: 'Automatic gameplay', automationValue: 'Not implemented; no game actions are executed',
|
|
32
32
|
pairing: 'QR device pairing', pairingHint: 'Pair an Android phone securely after the companion service is available.',
|
|
33
33
|
qrUnavailable: 'QR pairing service is not connected',
|
|
34
|
-
qrDetail: '
|
|
34
|
+
qrDetail: 'The desktop pairing service must be running locally. Set the same custom port here and in the startup script to generate a real QR code.',
|
|
35
35
|
qrNote: 'No fake QR code is shown and no device is reported as connected.',
|
|
36
36
|
roadmap: 'Next steps', roadmapText: 'Implement the desktop pairing service and Android companion before enabling QR generation, two-sided authentication and device status sync.',
|
|
37
37
|
repo: 'View GitHub project and development progress', language: 'Language', chinese: '简体中文', english: 'English',
|
|
@@ -60,8 +60,10 @@ window.__ModuleLoader__.load({
|
|
|
60
60
|
const [error, setError] = React.useState('');
|
|
61
61
|
const [busy, setBusy] = React.useState(false);
|
|
62
62
|
const [addresses, setAddresses] = React.useState([]);
|
|
63
|
+
const [port, setPort] = React.useState(() => { try { return localStorage.getItem('gamer.desktop.port') || '8765'; } catch { return '8765'; } });
|
|
63
64
|
const c = COPY[language];
|
|
64
|
-
const
|
|
65
|
+
const validPort = /^([1-9][0-9]{0,4})$/.test(port) && Number(port) <= 65535;
|
|
66
|
+
const base = 'http://127.0.0.1:' + (validPort ? port : '8765');
|
|
65
67
|
|
|
66
68
|
const generateQr = React.useCallback(async (selectedHost) => {
|
|
67
69
|
if (!selectedHost) return;
|
|
@@ -82,7 +84,7 @@ window.__ModuleLoader__.load({
|
|
|
82
84
|
} catch (e) {
|
|
83
85
|
setQr(''); setPairState('二维码生成失败'); setError(e.message || String(e));
|
|
84
86
|
} finally { setBusy(false); }
|
|
85
|
-
}, []);
|
|
87
|
+
}, [base]);
|
|
86
88
|
|
|
87
89
|
const detectAndGenerate = React.useCallback(async () => {
|
|
88
90
|
setBusy(true); setError(''); setPairState('正在检测桌面配对服务…');
|
|
@@ -97,10 +99,10 @@ window.__ModuleLoader__.load({
|
|
|
97
99
|
await generateQr(selected);
|
|
98
100
|
} catch (e) {
|
|
99
101
|
setQr(''); setPairState('桌面配对服务不可用');
|
|
100
|
-
setError((e.message || String(e)) + '。请先在电脑运行 Gamer
|
|
102
|
+
setError((e.message || String(e)) + '。请先在电脑运行 Gamer 桌面端启动脚本,并确认本机端口 ' + port + ' 可用;如修改端口,请确保启动脚本与此处填写一致。');
|
|
101
103
|
setBusy(false);
|
|
102
104
|
}
|
|
103
|
-
}, [generateQr]);
|
|
105
|
+
}, [generateQr, base]);
|
|
104
106
|
|
|
105
107
|
React.useEffect(() => {
|
|
106
108
|
let alive = true;
|
|
@@ -116,8 +118,13 @@ window.__ModuleLoader__.load({
|
|
|
116
118
|
}, [qr, remaining > 0]);
|
|
117
119
|
|
|
118
120
|
React.useEffect(() => {
|
|
119
|
-
if (qr && remaining === 0) {
|
|
120
|
-
|
|
121
|
+
if (qr && remaining === 0) {
|
|
122
|
+
setQr('');
|
|
123
|
+
setPairState('二维码已过期,正在自动刷新…');
|
|
124
|
+
const address = host.split(':')[0];
|
|
125
|
+
if (address) generateQr(address);
|
|
126
|
+
}
|
|
127
|
+
}, [remaining, qr, host, generateQr]);
|
|
121
128
|
|
|
122
129
|
const revoke = async () => {
|
|
123
130
|
try {
|
|
@@ -145,8 +152,14 @@ window.__ModuleLoader__.load({
|
|
|
145
152
|
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))' } },
|
|
146
153
|
h('div', { style: { minWidth: 0 } },
|
|
147
154
|
h('div', { style: { fontSize: '15px', fontWeight: 700 } }, c.pairing),
|
|
148
|
-
h('p', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, '页面加载后会自动连接本机 Gamer
|
|
149
|
-
h('div', { style: {
|
|
155
|
+
h('p', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, '页面加载后会自动连接本机 Gamer 桌面服务并生成真实二维码。电脑与手机需要处于同一局域网。可自定义桌面服务端口,并与启动脚本中的端口保持一致。'),
|
|
156
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap', margin: '10px 0' } },
|
|
157
|
+
h('label', { htmlFor: 'gamer-local-port', style: { fontSize: '12px' } }, '桌面服务端口 / Desktop port'),
|
|
158
|
+
h('input', { id: 'gamer-local-port', type: 'number', min: 1, max: 65535, step: 1, value: port, onChange: e => setPort(e.target.value), onBlur: () => { try { localStorage.setItem('gamer.desktop.port', port); } catch {} }, style: { width: '92px', padding: '7px 9px', borderRadius: '8px', border: '1px solid var(--dsw-alias-border-l2, #aaa)', background: 'var(--dsw-alias-bg-layer-1, transparent)', color: 'inherit' } }),
|
|
159
|
+
h('button', { type: 'button', disabled: busy || !validPort, onClick: () => { try { localStorage.setItem('gamer.desktop.port', port); } catch {} detectAndGenerate(); }, style: { borderRadius: '8px', padding: '7px 10px' } }, '应用端口并重连')
|
|
160
|
+
),
|
|
161
|
+
!validPort ? h('p', { role: 'alert', style: { color: '#c45b50', fontSize: '12px' } }, '端口必须是 1–65535 的整数。') : null,
|
|
162
|
+
h('div', { style: { fontSize: '13px', fontWeight: 650 } }, pairState),
|
|
150
163
|
host ? h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, '电脑地址:' + host) : null,
|
|
151
164
|
h('p', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #777)' } }, qr ? ('有效期:' + Math.floor(remaining / 60) + ':' + String(remaining % 60).padStart(2, '0')) : '有效期:未生成'),
|
|
152
165
|
error ? h('p', { role: 'alert', style: { color: '#c45b50', fontSize: '12px', lineHeight: 1.6 } }, error) : null,
|
|
@@ -168,7 +181,7 @@ window.__ModuleLoader__.load({
|
|
|
168
181
|
),
|
|
169
182
|
h('section', { style: { padding: '14px', borderRadius: '12px', background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))' } },
|
|
170
183
|
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
|
|
184
|
+
h('div', { style: { fontSize: '12px', lineHeight: 1.65, color: 'var(--dsw-alias-label-secondary, #777)' } }, 'DSH 插件界面与桌面配对服务通过本机回环地址通信。若服务未启动,请先运行桌面端启动脚本。端口可在上方自定义;若仍出现 Failed to fetch,请检查服务是否运行、端口是否一致以及 DSH 是否允许本地网络访问。游戏控制、视觉识别和 Android 双端认证仍需各自运行时实现。')
|
|
172
185
|
),
|
|
173
186
|
h('a', { href: 'https://github.com/sususgh/Gamer-DSH-Plugin', target: '_blank', rel: 'noreferrer',
|
|
174
187
|
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
|
|
2
|
+
* Gamer DSH Plugin — model-aware native Harness integration.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
|
11
|
+
const EMPTY_SCHEMA = {
|
|
14
12
|
type: 'object',
|
|
15
13
|
properties: {},
|
|
16
14
|
additionalProperties: false,
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
29
|
-
parameters:
|
|
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
|
-
|
|
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', '
|
|
50
|
-
'
|
|
51
|
-
'
|
|
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.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
androidCompanion: 'not
|
|
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
|
|
71
|
-
qrPairing: 'not implemented',
|
|
135
|
+
gameControlRuntime: 'not connected; no game actions can be executed',
|
|
72
136
|
canControlGames: false,
|
|
73
|
-
nextStep: 'Complete
|
|
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.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Gamer 游戏智能体:PC 游戏控制中心与 Android 手机伴侣,支持本地配对服务和自定义端口。 | Gamer AI game agent for PC and Android with local QR pairing and a configurable desktop port.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "sususgh",
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"LICENSE",
|
|
30
30
|
"docs/DSH-INSTALL.zh-CN.md",
|
|
31
31
|
"docs/runtime-protocol-v1.md",
|
|
32
|
-
"locale"
|
|
32
|
+
"locale",
|
|
33
|
+
"start-windows.bat",
|
|
34
|
+
"start-linux.sh"
|
|
33
35
|
],
|
|
34
36
|
"exports": {
|
|
35
37
|
".": "./dsh/index.js",
|
|
@@ -52,7 +54,7 @@
|
|
|
52
54
|
},
|
|
53
55
|
"scripts": {
|
|
54
56
|
"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",
|
|
57
|
+
"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
58
|
"desktop": "node desktop-runtime/server.js",
|
|
57
59
|
"start:desktop": "node desktop-runtime/server.js"
|
|
58
60
|
},
|
package/start-linux.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
DEFAULT_PORT=8765
|
|
4
|
+
read -r -p "Gamer desktop port [${DEFAULT_PORT}]: " GAMER_PORT
|
|
5
|
+
GAMER_PORT="${GAMER_PORT:-$DEFAULT_PORT}"
|
|
6
|
+
if ! [[ "$GAMER_PORT" =~ ^[0-9]+$ ]] || (( GAMER_PORT < 1 || GAMER_PORT > 65535 )); then
|
|
7
|
+
echo "Invalid port. Enter an integer from 1 to 65535."
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
cd "$(dirname "$0")/desktop-runtime"
|
|
11
|
+
if [[ ! -d node_modules/qrcode ]]; then
|
|
12
|
+
echo "Installing desktop runtime dependencies..."
|
|
13
|
+
npm install
|
|
14
|
+
fi
|
|
15
|
+
export GAMER_PORT
|
|
16
|
+
echo "Starting Gamer desktop service on port $GAMER_PORT..."
|
|
17
|
+
echo "Keep this terminal open while using the DSH plugin."
|
|
18
|
+
npm start
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
title Gamer Desktop Pairing Service
|
|
4
|
+
echo ==========================================
|
|
5
|
+
echo Gamer Desktop - QR Pairing Service
|
|
6
|
+
echo ==========================================
|
|
7
|
+
set "GAMER_PORT=8765"
|
|
8
|
+
set /p "GAMER_PORT=Enter port (1-65535) [8765]: "
|
|
9
|
+
if "%GAMER_PORT%"=="" set "GAMER_PORT=8765"
|
|
10
|
+
powershell -NoProfile -Command "if ([int]::TryParse('%GAMER_PORT%', [ref]$p) -and $p -ge 1 -and $p -le 65535) { exit 0 } else { exit 1 }"
|
|
11
|
+
if errorlevel 1 (
|
|
12
|
+
echo Invalid port. Please enter a number from 1 to 65535.
|
|
13
|
+
pause
|
|
14
|
+
exit /b 1
|
|
15
|
+
)
|
|
16
|
+
cd /d "%~dp0desktop-runtime"
|
|
17
|
+
if not exist "node_modules\qrcode" (
|
|
18
|
+
echo Installing desktop runtime dependencies...
|
|
19
|
+
call npm install
|
|
20
|
+
if errorlevel 1 (
|
|
21
|
+
echo Dependency installation failed.
|
|
22
|
+
pause
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
set "GAMER_PORT=%GAMER_PORT%"
|
|
27
|
+
echo Starting Gamer on port %GAMER_PORT%...
|
|
28
|
+
echo Keep this window open while using the DSH plugin.
|
|
29
|
+
call npm start
|
|
30
|
+
pause
|