@sususgh/gamer-dsh-plugin 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +545 -2
- package/cordis.patch.yml +4 -0
- package/desktop-runtime/package.json +17 -0
- package/desktop-runtime/pairing.js +75 -0
- package/desktop-runtime/server.js +203 -0
- package/desktop-runtime/start-linux.sh +11 -0
- package/desktop-runtime/start-windows.bat +26 -0
- package/desktop-ui/app.js +133 -0
- package/desktop-ui/index.html +141 -0
- package/desktop-ui/style.css +150 -0
- package/docs/DSH-INSTALL.zh-CN.md +78 -0
- package/docs/runtime-protocol-v1.md +266 -0
- package/dsh/client.js +124 -0
- package/dsh/index.js +79 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +60 -3
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import QRCode from 'qrcode';
|
|
7
|
+
import { PairingManager } from './pairing.js';
|
|
8
|
+
|
|
9
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
+
const UI_ROOT = path.join(ROOT, 'desktop-ui');
|
|
11
|
+
const PORT = Number.parseInt(process.env.GAMER_PORT || '8765', 10);
|
|
12
|
+
const manager = new PairingManager();
|
|
13
|
+
const MIME = {
|
|
14
|
+
'.html': 'text/html; charset=utf-8',
|
|
15
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
16
|
+
'.css': 'text/css; charset=utf-8',
|
|
17
|
+
'.svg': 'image/svg+xml',
|
|
18
|
+
'.png': 'image/png',
|
|
19
|
+
'.ico': 'image/x-icon',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function isPrivateIPv4(address) {
|
|
23
|
+
const parts = address.split('.').map(Number);
|
|
24
|
+
if (parts.length !== 4 || parts.some(n => !Number.isInteger(n) || n < 0 || n > 255)) return false;
|
|
25
|
+
return parts[0] === 10
|
|
26
|
+
|| (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31)
|
|
27
|
+
|| (parts[0] === 192 && parts[1] === 168)
|
|
28
|
+
|| (parts[0] === 169 && parts[1] === 254);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getLanAddresses() {
|
|
32
|
+
const found = [];
|
|
33
|
+
for (const [name, entries] of Object.entries(os.networkInterfaces())) {
|
|
34
|
+
for (const item of entries || []) {
|
|
35
|
+
if (item.family === 'IPv4' && !item.internal && isPrivateIPv4(item.address)) {
|
|
36
|
+
found.push({ name, address: item.address });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isLoopback(remoteAddress = '') {
|
|
44
|
+
return remoteAddress === '127.0.0.1'
|
|
45
|
+
|| remoteAddress === '::1'
|
|
46
|
+
|| remoteAddress === '::ffff:127.0.0.1';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function sendJson(res, status, value) {
|
|
50
|
+
res.writeHead(status, {
|
|
51
|
+
'content-type': 'application/json; charset=utf-8',
|
|
52
|
+
'cache-control': 'no-store',
|
|
53
|
+
'x-content-type-options': 'nosniff',
|
|
54
|
+
});
|
|
55
|
+
res.end(JSON.stringify(value));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readJson(req) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
let body = '';
|
|
61
|
+
req.on('data', chunk => {
|
|
62
|
+
body += chunk;
|
|
63
|
+
if (body.length > 8_192) {
|
|
64
|
+
reject(new Error('Request body too large'));
|
|
65
|
+
req.destroy();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
req.on('end', () => {
|
|
69
|
+
try { resolve(body ? JSON.parse(body) : {}); }
|
|
70
|
+
catch { reject(new Error('Invalid JSON body')); }
|
|
71
|
+
});
|
|
72
|
+
req.on('error', reject);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function pairLandingPage(valid) {
|
|
77
|
+
const title = valid ? 'Gamer 配对码已识别' : 'Gamer 配对码无效或已过期';
|
|
78
|
+
const detail = valid
|
|
79
|
+
? '电脑端已生成真实配对二维码。下一步需要安装 Gamer Android Companion,才能提交设备身份并完成双端认证。当前尚未建立连接。'
|
|
80
|
+
: '请回到电脑端重新生成二维码,再使用 Gamer 手机伴侣扫码。';
|
|
81
|
+
return `<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="referrer" content="no-referrer"><title>${title}</title><body style="margin:0;min-height:100vh;display:grid;place-items:center;background:#edf5fa;color:#30465d;font:16px system-ui,'Noto Sans SC',sans-serif"><main style="max-width:480px;margin:24px;padding:28px;border-radius:20px;background:#fff;box-shadow:0 12px 40px #496b841c"><h2>${title}</h2><p style="line-height:1.8;color:#71869a">${detail}</p><small style="color:#9aa9b5">Gamer · gamer-runtime/1</small></main></body></html>`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function handle(req, res) {
|
|
85
|
+
const url = new URL(req.url, 'http://127.0.0.1');
|
|
86
|
+
res.setHeader('x-content-type-options', 'nosniff');
|
|
87
|
+
res.setHeader('referrer-policy', 'no-referrer');
|
|
88
|
+
res.setHeader('cache-control', 'no-store');
|
|
89
|
+
|
|
90
|
+
if (url.pathname === '/api/network/interfaces' && req.method === 'GET') {
|
|
91
|
+
return sendJson(res, 200, { addresses: getLanAddresses() });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (url.pathname === '/api/pairing/status' && req.method === 'GET') {
|
|
95
|
+
return sendJson(res, 200, manager.status());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (url.pathname === '/api/pairing/start' && req.method === 'POST') {
|
|
99
|
+
if (!isLoopback(req.socket.remoteAddress)) {
|
|
100
|
+
return sendJson(res, 403, { error: 'PAIRING_CONTROL_LOCAL_ONLY' });
|
|
101
|
+
}
|
|
102
|
+
let body;
|
|
103
|
+
try { body = await readJson(req); }
|
|
104
|
+
catch (error) { return sendJson(res, 400, { error: error.message }); }
|
|
105
|
+
|
|
106
|
+
const addresses = getLanAddresses();
|
|
107
|
+
if (!addresses.length) return sendJson(res, 400, { error: 'NO_PRIVATE_LAN_IPV4' });
|
|
108
|
+
const requestedHost = body.host;
|
|
109
|
+
const selected = addresses.find(item => item.address === requestedHost);
|
|
110
|
+
const host = selected?.address || null;
|
|
111
|
+
if (!host) return sendJson(res, 400, { error: 'INVALID_LAN_ADDRESS', addresses });
|
|
112
|
+
|
|
113
|
+
const pairing = manager.create({ host, port: PORT });
|
|
114
|
+
const pairingUrl = new URL('/pair', `http://${host}:${PORT}`);
|
|
115
|
+
pairingUrl.searchParams.set('protocol', pairing.protocol);
|
|
116
|
+
pairingUrl.searchParams.set('instance_id', pairing.instanceId);
|
|
117
|
+
pairingUrl.searchParams.set('token', pairing.token);
|
|
118
|
+
const qrDataUrl = await QRCode.toDataURL(pairingUrl.toString(), {
|
|
119
|
+
errorCorrectionLevel: 'M',
|
|
120
|
+
margin: 2,
|
|
121
|
+
width: 360,
|
|
122
|
+
color: { dark: '#26394a', light: '#ffffff' },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return sendJson(res, 200, {
|
|
126
|
+
active: true,
|
|
127
|
+
host,
|
|
128
|
+
port: PORT,
|
|
129
|
+
instanceId: pairing.instanceId,
|
|
130
|
+
createdAt: pairing.createdAt,
|
|
131
|
+
expiresAt: pairing.expiresAt,
|
|
132
|
+
qrDataUrl,
|
|
133
|
+
message: 'QR generated. Scanning is not the same as a completed device pairing.',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (url.pathname === '/api/pairing/stop' && req.method === 'POST') {
|
|
138
|
+
if (!isLoopback(req.socket.remoteAddress)) {
|
|
139
|
+
return sendJson(res, 403, { error: 'PAIRING_CONTROL_LOCAL_ONLY' });
|
|
140
|
+
}
|
|
141
|
+
manager.stop();
|
|
142
|
+
return sendJson(res, 200, { active: false });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (url.pathname === '/pair' && req.method === 'GET') {
|
|
146
|
+
const valid = url.searchParams.get('protocol') === 'gamer-runtime/1'
|
|
147
|
+
&& url.searchParams.get('instance_id') === manager.instanceId
|
|
148
|
+
&& manager.verify(url.searchParams.get('token'));
|
|
149
|
+
res.writeHead(valid ? 200 : 410, {
|
|
150
|
+
'content-type': 'text/html; charset=utf-8',
|
|
151
|
+
'cache-control': 'no-store',
|
|
152
|
+
'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
|
|
153
|
+
});
|
|
154
|
+
return res.end(pairLandingPage(valid));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (url.pathname.startsWith('/api/')) {
|
|
158
|
+
return sendJson(res, 404, { error: 'NOT_FOUND' });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const requested = url.pathname === '/' ? '/index.html' : decodeURIComponent(url.pathname);
|
|
162
|
+
const target = path.resolve(UI_ROOT, '.' + requested);
|
|
163
|
+
if (!target.startsWith(UI_ROOT + path.sep) && target !== path.join(UI_ROOT, 'index.html')) {
|
|
164
|
+
return sendJson(res, 403, { error: 'PATH_NOT_ALLOWED' });
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const content = await readFile(target);
|
|
168
|
+
res.writeHead(200, {
|
|
169
|
+
'content-type': MIME[path.extname(target)] || 'application/octet-stream',
|
|
170
|
+
'cache-control': 'no-cache',
|
|
171
|
+
});
|
|
172
|
+
res.end(content);
|
|
173
|
+
} catch {
|
|
174
|
+
sendJson(res, 404, { error: 'NOT_FOUND' });
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const server = http.createServer((req, res) => {
|
|
179
|
+
Promise.resolve(handle(req, res)).catch(error => {
|
|
180
|
+
console.error('[gamer-desktop] request failed:', error.message);
|
|
181
|
+
if (!res.headersSent) sendJson(res, 500, { error: 'INTERNAL_ERROR' });
|
|
182
|
+
else res.end();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
server.listen(PORT, '0.0.0.0', () => {
|
|
187
|
+
const addresses = getLanAddresses();
|
|
188
|
+
console.log(`Gamer Desktop UI: http://127.0.0.1:${PORT}`);
|
|
189
|
+
if (addresses.length) {
|
|
190
|
+
for (const item of addresses) console.log(`Phone LAN URL: http://${item.address}:${PORT}`);
|
|
191
|
+
} else {
|
|
192
|
+
console.warn('No private IPv4 LAN address found. QR pairing will use loopback and cannot be reached by a phone.');
|
|
193
|
+
}
|
|
194
|
+
console.log('Pairing QR tokens expire in 5 minutes. Pairing control endpoints accept loopback requests only.');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
function shutdown() {
|
|
198
|
+
manager.stop();
|
|
199
|
+
server.close(() => process.exit(0));
|
|
200
|
+
setTimeout(() => process.exit(1), 3_000).unref();
|
|
201
|
+
}
|
|
202
|
+
process.on('SIGINT', shutdown);
|
|
203
|
+
process.on('SIGTERM', shutdown);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
cd "$(dirname "$0")"
|
|
4
|
+
command -v node >/dev/null 2>&1 || { echo "[Gamer] Node.js 22.13+ is required."; exit 1; }
|
|
5
|
+
node -e "const [a,b]=process.versions.node.split('.').map(Number);process.exit(a>22||(a===22&&b>=13)?0:1)" || { echo "[Gamer] Please upgrade Node.js to 22.13 or newer."; exit 1; }
|
|
6
|
+
if [[ ! -d node_modules/qrcode ]]; then
|
|
7
|
+
echo "[Gamer] Installing desktop QR dependencies..."
|
|
8
|
+
npm install --no-audit --no-fund
|
|
9
|
+
fi
|
|
10
|
+
echo "[Gamer] Starting desktop pairing service..."
|
|
11
|
+
npm start
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
cd /d "%~dp0"
|
|
4
|
+
where node >nul 2>nul
|
|
5
|
+
if errorlevel 1 (
|
|
6
|
+
echo [Gamer] Node.js 22.13+ is required. Install it from https://nodejs.org/
|
|
7
|
+
pause
|
|
8
|
+
exit /b 1
|
|
9
|
+
)
|
|
10
|
+
node -e "const [a,b]=process.versions.node.split('.').map(Number);process.exit(a>22||(a===22&&b>=13)?0:1)"
|
|
11
|
+
if errorlevel 1 (
|
|
12
|
+
echo [Gamer] Please upgrade Node.js to 22.13 or newer.
|
|
13
|
+
pause
|
|
14
|
+
exit /b 1
|
|
15
|
+
)
|
|
16
|
+
if not exist "node_modules\qrcode" (
|
|
17
|
+
echo [Gamer] Installing desktop QR dependencies...
|
|
18
|
+
npm install --no-audit --no-fund
|
|
19
|
+
if errorlevel 1 (
|
|
20
|
+
pause
|
|
21
|
+
exit /b 1
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
echo [Gamer] Starting desktop pairing service...
|
|
25
|
+
npm start
|
|
26
|
+
pause
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const $=id=>document.getElementById(id);
|
|
2
|
+
const log=(message)=>{const list=$('eventLog');const row=document.createElement('div');row.className='event';const t=document.createElement('time');t.textContent=new Date().toLocaleTimeString('zh-CN',{hour12:false});const dot=document.createElement('span');dot.className='event-dot';const p=document.createElement('p');p.textContent=message;row.append(t,dot,p);list.prepend(row);while(list.children.length>8)list.lastChild.remove();};
|
|
3
|
+
let mode='USB';
|
|
4
|
+
document.querySelectorAll('.choice').forEach(btn=>btn.addEventListener('click',()=>{document.querySelectorAll('.choice').forEach(x=>x.classList.remove('selected'));btn.classList.add('selected');mode=btn.dataset.mode;$('transportMode').textContent=mode==='USB'?'USB / ADB':'Wi-Fi / LAN';log('连接方式已选择:'+mode+'。等待设备桥接服务接入。');}));
|
|
5
|
+
$('connectBtn').addEventListener('click',()=>{log('已请求设备连接;当前原型尚未接入 ADB / Wi-Fi 桥接服务。');$('globalState').textContent='等待设备桥接服务';});
|
|
6
|
+
$('stopBtn').addEventListener('click',()=>{log('停止请求已记录。真实运行时接入后,此按钮将向 Agent Coordinator 发送紧急停止指令。');});
|
|
7
|
+
$('probeBtn').addEventListener('click',()=>{log('模型健康检查暂不可执行:尚未配置本地推理运行时。');$('modelState').textContent='等待推理适配器';});
|
|
8
|
+
$('modelConfigBtn').addEventListener('click',()=>{const primary=prompt('主模型标识(例如本地服务中的模型 ID):');if(primary){$('activeModel').textContent=primary;$('modelState').textContent='已保存到本次界面会话;尚未连接模型服务';log('主模型候选已填写:'+primary+'。等待运行时探测。');}const fallback=prompt('备用模型标识(可留空):');if(fallback!==null&&fallback.trim()){$('fallbackModel').textContent=fallback.trim();log('备用模型候选已填写:'+fallback.trim()+'。尚未执行真实健康检查。');}});
|
|
9
|
+
$('clearLog').addEventListener('click',()=>{$('eventLog').replaceChildren();log('日志已清空。');});
|
|
10
|
+
const canvas=$('flowCanvas'),ctx=canvas.getContext('2d');let phase=0;
|
|
11
|
+
function draw(){const dpr=Math.max(1,window.devicePixelRatio||1),w=canvas.clientWidth,h=150;if(canvas.width!==Math.round(w*dpr)||canvas.height!==Math.round(h*dpr)){canvas.width=Math.round(w*dpr);canvas.height=Math.round(h*dpr);}ctx.setTransform(dpr,0,0,dpr,0,0);ctx.clearRect(0,0,w,h);for(let j=0;j<2;j++){ctx.beginPath();for(let x=0;x<=w;x+=3){const y=h/2+Math.sin(x*.023+phase+j*1.5)*(15+j*8)+Math.sin(x*.009-phase*.7)*(7+j*4);if(x===0)ctx.moveTo(x,y);else ctx.lineTo(x,y);}ctx.strokeStyle=j===0?'rgba(91,190,199,.72)':'rgba(160,145,211,.58)';ctx.lineWidth=j===0?2:1.6;ctx.stroke();}phase+=.025;requestAnimationFrame(draw);}draw();window.addEventListener('resize',()=>{canvas.width=0;});
|
|
12
|
+
|
|
13
|
+
/* Model selection UI is intentionally empty until the real local-model registry reports installed models. */
|
|
14
|
+
$('selectAllModels')?.addEventListener('click',()=>{log('模型列表尚未从本地运行时加载,暂时没有可选择的模型。');});
|
|
15
|
+
/* Desktop-generated, real QR pairing. The UI must be served by desktop-runtime/server.js. */
|
|
16
|
+
const pairQrImage=$('pairQrImage');
|
|
17
|
+
const pairQrEmpty=$('pairQrEmpty');
|
|
18
|
+
const pairHostSelect=$('pairHostSelect');
|
|
19
|
+
const pairRefresh=$('pairRefresh');
|
|
20
|
+
const pairStop=$('pairStop');
|
|
21
|
+
let pairExpiryTimer=null;
|
|
22
|
+
|
|
23
|
+
function setPairState(text){$('pairState').textContent=text;}
|
|
24
|
+
function clearPairQr(){
|
|
25
|
+
if(pairQrImage){pairQrImage.hidden=true;pairQrImage.removeAttribute('src');}
|
|
26
|
+
if(pairQrEmpty)pairQrEmpty.hidden=false;
|
|
27
|
+
$('pairQrCaption').textContent='点击生成二维码';
|
|
28
|
+
$('pairExpires').textContent='5 分钟 · 未生成';
|
|
29
|
+
if(pairStop)pairStop.disabled=true;
|
|
30
|
+
if(pairExpiryTimer){clearInterval(pairExpiryTimer);pairExpiryTimer=null;}
|
|
31
|
+
}
|
|
32
|
+
async function loadPairNetworks(){
|
|
33
|
+
try{
|
|
34
|
+
const response=await fetch('/api/network/interfaces',{cache:'no-store'});
|
|
35
|
+
if(!response.ok)throw new Error('HTTP '+response.status);
|
|
36
|
+
const data=await response.json();
|
|
37
|
+
pairHostSelect.replaceChildren();
|
|
38
|
+
for(const item of data.addresses||[]){
|
|
39
|
+
const option=document.createElement('option');
|
|
40
|
+
option.value=item.address;option.textContent=item.name+' · '+item.address;
|
|
41
|
+
pairHostSelect.append(option);
|
|
42
|
+
}
|
|
43
|
+
if(!pairHostSelect.options.length){
|
|
44
|
+
const option=document.createElement('option');option.value='';option.textContent='未发现局域网 IPv4 地址';pairHostSelect.append(option);
|
|
45
|
+
$('pairHost').textContent='未发现局域网地址';
|
|
46
|
+
setPairState('请连接 Wi-Fi 或检查网络');
|
|
47
|
+
pairRefresh.disabled=true;
|
|
48
|
+
}else{
|
|
49
|
+
$('pairHost').textContent=pairHostSelect.value;
|
|
50
|
+
setPairState('配对服务已就绪');
|
|
51
|
+
pairRefresh.disabled=false;
|
|
52
|
+
}
|
|
53
|
+
}catch(error){
|
|
54
|
+
pairHostSelect.replaceChildren();
|
|
55
|
+
const option=document.createElement('option');option.value='';option.textContent='桌面配对服务未启动';pairHostSelect.append(option);
|
|
56
|
+
setPairState('请通过启动脚本打开桌面控制台');
|
|
57
|
+
pairRefresh.disabled=true;
|
|
58
|
+
log('无法连接桌面配对服务:'+error.message+'。请勿直接双击 index.html。');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
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;}
|
|
87
|
+
});
|
|
88
|
+
pairStop?.addEventListener('click',async()=>{
|
|
89
|
+
try{
|
|
90
|
+
const response=await fetch('/api/pairing/stop',{method:'POST'});
|
|
91
|
+
if(!response.ok)throw new Error('HTTP '+response.status);
|
|
92
|
+
clearPairQr();setPairState('二维码已撤销');log('电脑端配对二维码已撤销。');
|
|
93
|
+
}catch(error){setPairState('撤销失败:'+error.message);log('撤销二维码失败:'+error.message);}
|
|
94
|
+
});
|
|
95
|
+
loadPairNetworks();
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
$('visionTestBtn')?.addEventListener('click',()=>{log('视觉自检请求已记录;当前仓库尚未接入帧采集、OCR 或目标检测运行时。');$('visionEngineState').textContent='运行时未接入';});
|
|
99
|
+
$('researchBtn')?.addEventListener('click',()=>{log('攻略检索检查请求已记录;联网搜索适配器尚未接入,当前不会生成未经来源核验的攻略。');$('researchState').textContent='搜索适配器未接入';});
|
|
100
|
+
$('memoryBtn')?.addEventListener('click',()=>{log('经验记忆检查请求已记录;本地存储、检索与用户清除接口尚未接入。');$('memoryState').textContent='记忆库未接入';});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/* Optional community TTS bridge. The model weights stay outside this repository. */
|
|
104
|
+
const ttsEndpoint=$('ttsEndpoint');
|
|
105
|
+
const ttsAudio=$('ttsAudio');
|
|
106
|
+
const savedTtsEndpoint=localStorage.getItem('gamer.tts.endpoint');
|
|
107
|
+
if(savedTtsEndpoint&&ttsEndpoint)ttsEndpoint.value=savedTtsEndpoint;
|
|
108
|
+
const getTtsBase=()=>{const raw=(ttsEndpoint?.value||'').trim().replace(/\/+$/,'');if(!raw)throw new Error('请填写 TTS 服务地址');const u=new URL(raw);if(!['http:','https:'].includes(u.protocol))throw new Error('只支持 HTTP(S) 地址');return raw;};
|
|
109
|
+
$('ttsHealthBtn')?.addEventListener('click',async()=>{
|
|
110
|
+
try{
|
|
111
|
+
const base=getTtsBase();localStorage.setItem('gamer.tts.endpoint',base);
|
|
112
|
+
$('ttsState').textContent='正在检测…';
|
|
113
|
+
const response=await fetch(base+'/health',{method:'GET'});
|
|
114
|
+
if(!response.ok)throw new Error('HTTP '+response.status);
|
|
115
|
+
const data=await response.json();
|
|
116
|
+
if(data.status!=='ok'||data.loaded!==true)throw new Error('服务在线,但音色模型尚未加载');
|
|
117
|
+
$('ttsState').textContent='已连接 · '+(data.model||'TTS 模型')+' · '+(data.device||'device');
|
|
118
|
+
log('派蒙 TTS 服务健康检查通过。');
|
|
119
|
+
}catch(e){$('ttsState').textContent='连接失败:'+e.message;log('派蒙 TTS 检查失败:'+e.message);}
|
|
120
|
+
});
|
|
121
|
+
$('ttsPreviewBtn')?.addEventListener('click',async()=>{
|
|
122
|
+
try{
|
|
123
|
+
const base=getTtsBase();localStorage.setItem('gamer.tts.endpoint',base);
|
|
124
|
+
const text=($('ttsText')?.value||'').trim();if(!text)throw new Error('请输入试听文本');
|
|
125
|
+
$('ttsState').textContent='正在合成语音…';
|
|
126
|
+
const response=await fetch(base+'/tts_to_audio',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({text,length_scale:1.0})});
|
|
127
|
+
if(!response.ok){let detail='HTTP '+response.status;try{const data=await response.json();detail=data.error?.message||detail;}catch{}throw new Error(detail);}
|
|
128
|
+
const blob=await response.blob();if(!blob.type.includes('audio'))throw new Error('服务返回的不是音频文件');
|
|
129
|
+
if(ttsAudio.dataset.objectUrl)URL.revokeObjectURL(ttsAudio.dataset.objectUrl);
|
|
130
|
+
const objectUrl=URL.createObjectURL(blob);ttsAudio.dataset.objectUrl=objectUrl;ttsAudio.src=objectUrl;
|
|
131
|
+
await ttsAudio.play();$('ttsState').textContent='语音合成成功 · 正在播放';log('派蒙 TTS 试听合成成功。');
|
|
132
|
+
}catch(e){$('ttsState').textContent='试听失败:'+e.message;log('派蒙 TTS 试听失败:'+e.message);}
|
|
133
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<meta name="theme-color" content="#eaf3f8">
|
|
7
|
+
<title>Gamer · 派蒙星光控制中心</title>
|
|
8
|
+
<link rel="stylesheet" href="style.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div class="sky-glow"></div>
|
|
12
|
+
<header class="topbar">
|
|
13
|
+
<div class="brand"><div class="brand-mark">✧</div><div><b>GAMER</b><small>PAIMON STARLIGHT CONTROL</small></div></div>
|
|
14
|
+
<div class="top-status"><span class="pulse"></span><span id="globalState">等待设备连接</span><span class="tag">DESKTOP</span></div>
|
|
15
|
+
<button class="icon-btn" aria-label="设置">⚙</button>
|
|
16
|
+
</header>
|
|
17
|
+
|
|
18
|
+
<main class="layout">
|
|
19
|
+
<section class="hero panel">
|
|
20
|
+
<div class="hero-copy">
|
|
21
|
+
<div class="eyebrow">PAIMON COMPANION / ADVENTURE SYSTEM</div>
|
|
22
|
+
<h1>旅行者,派蒙陪你开启下一场冒险!</h1>
|
|
23
|
+
<p>星光连接 · 画面感知 · AI 思考 · 安全执行</p>
|
|
24
|
+
<div class="hero-actions"><button class="primary" id="connectBtn">连接设备</button><button class="soft" id="stopBtn">停止自动操作</button></div>
|
|
25
|
+
</div>
|
|
26
|
+
<div class="orb-wrap"><div class="orb"><span>✧</span></div><i class="orbit orbit-a"></i><i class="orbit orbit-b"></i><div class="orb-caption">PAIMON COMPANION · LOCAL AI</div></div>
|
|
27
|
+
<div class="hero-foot"><span>✦ 设备桥接 <b id="deviceBadge">未连接</b></span><span>✦ 推理服务 <b id="inferenceBadge">未连接</b></span><span class="prototype">UI 原型 · 等待真实运行时</span></div>
|
|
28
|
+
</section>
|
|
29
|
+
|
|
30
|
+
<section class="panel pairing-panel">
|
|
31
|
+
<div class="section-head"><div><div class="eyebrow">CROSS-DEVICE PAIRING</div><h2>手机 · 电脑 · AI 模型配对</h2></div><span class="tag pale">ONE ACCOUNT · TWO SCREENS</span></div>
|
|
32
|
+
<div class="pairing-layout">
|
|
33
|
+
<div class="qr-frame">
|
|
34
|
+
<div class="qr-placeholder" id="pairQrEmpty" aria-label="尚未生成二维码"><div class="qr-corner tl"></div><div class="qr-corner tr"></div><div class="qr-center">✦<small>READY</small></div><div class="qr-corner bl"></div><div class="qr-corner br"></div></div>
|
|
35
|
+
<img id="pairQrImage" class="pair-qr-image" alt="电脑生成的 Gamer 手机配对二维码" hidden>
|
|
36
|
+
<small id="pairQrCaption">点击生成二维码</small>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="pairing-copy">
|
|
39
|
+
<h3>手机扫描电脑二维码</h3>
|
|
40
|
+
<p>电脑生成一次性配对二维码,手机与电脑需处于同一局域网。二维码只包含短期配对凭证和电脑地址,不包含模型 API Key。</p>
|
|
41
|
+
<div class="pairing-meta"><span>配对状态</span><b id="pairState">服务尚未启动</b></div>
|
|
42
|
+
<div class="pairing-meta"><span>电脑地址</span><b id="pairHost">等待选择网络</b></div>
|
|
43
|
+
<div class="pairing-meta"><span>二维码有效期</span><b id="pairExpires">5 分钟 · 未生成</b></div>
|
|
44
|
+
<label class="pair-host-label" for="pairHostSelect">选择手机可访问的电脑网络</label>
|
|
45
|
+
<select id="pairHostSelect" class="pair-host-select"><option value="">正在检测局域网地址…</option></select>
|
|
46
|
+
<div class="pairing-buttons"><button class="primary" id="pairRefresh" disabled>正在检测网络…</button><button class="soft" id="pairStop" disabled>撤销二维码</button></div>
|
|
47
|
+
<p class="pair-mobile-note">说明:当前版本已实现电脑端真实二维码生成和扫码落地页;Android Companion 尚未接入,扫码识别不等于手机已配对。</p>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
<p class="hint">二维码 5 分钟后过期,可随时撤销并重新生成。配对控制接口仅允许电脑本机访问,手机只能访问配对落地页。</p>
|
|
51
|
+
</section>
|
|
52
|
+
|
|
53
|
+
<section class="stats-grid">
|
|
54
|
+
<article class="panel stat"><label>TCP 延迟</label><strong id="tcpLatency">—</strong><small>RTT · 等待采样</small><div class="mini-line"></div></article>
|
|
55
|
+
<article class="panel stat"><label>UDP 丢包率</label><strong id="udpLoss">—</strong><small>独立 UDP 统计</small><div class="mini-line alt"></div></article>
|
|
56
|
+
<article class="panel stat"><label>上行速率</label><strong id="uploadRate">—</strong><small>手机 / PC → 对端</small></article>
|
|
57
|
+
<article class="panel stat"><label>下行速率</label><strong id="downloadRate">—</strong><small>对端 → 手机 / PC</small></article>
|
|
58
|
+
</section>
|
|
59
|
+
|
|
60
|
+
<section class="panel flow-panel">
|
|
61
|
+
<div class="section-head"><div><div class="eyebrow">LIVE TRANSMISSION</div><h2>实时数据流</h2></div><span class="waiting"><i></i> 尚未接入真实数据</span></div>
|
|
62
|
+
<div class="flow-legend"><span><i class="dot cyan"></i> TCP 通道</span><span><i class="dot violet"></i> UDP 通道</span><span class="right">动态波形为视觉预览,不代表实际流量</span></div>
|
|
63
|
+
<canvas id="flowCanvas" height="150"></canvas>
|
|
64
|
+
<div class="flow-bottom"><span>TCP <b>DISCONNECTED</b></span><span>UDP <b>DISCONNECTED</b></span><span>最后采样 <b id="lastSample">暂无</b></span></div>
|
|
65
|
+
</section>
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
<section class="panel intelligence-panel">
|
|
69
|
+
<div class="section-head"><div><div class="eyebrow">PERCEPTION · RESEARCH · MEMORY</div><h2>游戏智能核心</h2></div><span class="tag pale">LOCAL-FIRST AI</span></div>
|
|
70
|
+
<div class="intelligence-grid">
|
|
71
|
+
<article class="intel-card"><div class="intel-icon">◉</div><div class="intel-title">视觉识别引擎</div><p>画面采集 → 场景识别 → OCR → 目标检测 → 游戏状态结构化</p><div class="intel-status"><i></i><b id="visionEngineState">等待视觉运行时</b></div><div class="intel-meta">帧时间戳 · 识别置信度 · 画面新鲜度</div><button class="soft" id="visionTestBtn">视觉模块自检</button></article>
|
|
72
|
+
<article class="intel-card"><div class="intel-icon">⌕</div><div class="intel-title">联网攻略研究</div><p>按游戏、任务、区域或 BOSS 搜索资料,提取步骤并核对当前版本。</p><div class="intel-status"><i></i><b id="researchState">等待搜索服务</b></div><div class="intel-meta">来源链接 · 更新时间 · 可信度 · 版本匹配</div><button class="soft" id="researchBtn">检查攻略检索</button></article>
|
|
73
|
+
<article class="intel-card"><div class="intel-icon">⌘</div><div class="intel-title">游戏经验记忆</div><p>记录动作、结果、失败原因和有效策略;按游戏配置隔离保存。</p><div class="intel-status"><i></i><b id="memoryState">等待本地记忆库</b></div><div class="intel-meta">成功率 · 最近经验 · 可查看与清除</div><button class="soft" id="memoryBtn">检查经验记忆</button></article>
|
|
74
|
+
</div>
|
|
75
|
+
<p class="hint">当前为控制台功能入口与状态展示。视觉推理、联网检索和持久化记忆须由真实运行时接入后才会启用;未接入时不会伪造识别结果或攻略结论。</p>
|
|
76
|
+
</section>
|
|
77
|
+
<section class="panel game-profile-panel">
|
|
78
|
+
<div class="section-head"><div><div class="eyebrow">GAME ADAPTERS</div><h2>游戏配置与兼容性</h2></div><span class="tag pale">PROFILE-BASED</span></div>
|
|
79
|
+
<div class="profile-grid">
|
|
80
|
+
<div class="profile-item"><div><b>Minecraft</b><small>目标适配 · 生存 / 创造 / 建造</small></div><span class="status-pill neutral">待测试</span></div>
|
|
81
|
+
<div class="profile-item"><div><b>原神</b><small>目标适配 · 探索 / 任务 / 战斗</small></div><span class="status-pill neutral">待测试</span></div>
|
|
82
|
+
<div class="profile-item"><div><b>其他游戏</b><small>通过独立视觉与控制配置扩展</small></div><span class="status-pill neutral">可扩展</span></div>
|
|
83
|
+
</div>
|
|
84
|
+
<div class="profile-note">每款游戏需要独立的 UI 识别规则、坐标校准、动作映射、任务状态和回归测试。游戏名称出现在列表中不代表已经兼容。</div>
|
|
85
|
+
</section>
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
<section class="panel voice-panel">
|
|
89
|
+
<div class="section-head"><div><div class="eyebrow">OPTIONAL COMMUNITY TTS</div><h2>派蒙语音助手</h2></div><span class="tag pale">USER-OPT-IN</span></div>
|
|
90
|
+
<div class="voice-layout">
|
|
91
|
+
<div class="voice-avatar">✧</div>
|
|
92
|
+
<div class="voice-settings">
|
|
93
|
+
<div class="voice-title">社区训练的派蒙音色(可选)</div>
|
|
94
|
+
<p>可连接网友制作的 Paimon VITS / TTS 服务,让 AI 游戏助手用语音播报任务、攻略摘要、战斗提醒和操作结果。</p>
|
|
95
|
+
<label for="ttsEndpoint">本地 TTS 服务地址</label>
|
|
96
|
+
<input id="ttsEndpoint" type="url" placeholder="http://127.0.0.1:8020" value="http://127.0.0.1:8020">
|
|
97
|
+
<label for="ttsText">试听文本</label>
|
|
98
|
+
<input id="ttsText" type="text" maxlength="240" value="旅行者,前面好像有新的任务!">
|
|
99
|
+
<div class="voice-actions"><button class="soft" id="ttsHealthBtn">检测语音服务</button><button class="primary" id="ttsPreviewBtn">试听派蒙语音</button></div>
|
|
100
|
+
<div class="intel-status"><i></i><b id="ttsState">尚未连接语音服务</b></div>
|
|
101
|
+
<audio id="ttsAudio" controls preload="none"></audio>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
<p class="hint">此处只接入可选 TTS 服务,不在 Gamer 仓库内分发第三方音色权重。社区模型的授权、用途限制和来源请以原作者说明为准;已知示例模型仅允许个人非商业用途。请将服务限制在本机或可信局域网,不要公开暴露。</p>
|
|
105
|
+
<p class="voice-source">参考社区项目:<a href="https://github.com/gaaiyun/ai-paimon" target="_blank" rel="noopener noreferrer">gaaiyun/ai-paimon</a> · TTS 引擎:<a href="https://github.com/RVC-Boss/GPT-SoVITS" target="_blank" rel="noopener noreferrer">GPT-SoVITS</a></p>
|
|
106
|
+
</section>
|
|
107
|
+
|
|
108
|
+
<div class="two-col">
|
|
109
|
+
<section class="panel model-panel">
|
|
110
|
+
<div class="section-head"><div><div class="eyebrow">MODEL ORCHESTRATION</div><h2>AI 模型管理</h2></div><span class="tag pale">AUTO ROUTER</span></div>
|
|
111
|
+
<div class="model-select-head"><b>已发现的本地模型</b><button class="text-btn" id="selectAllModels">全选</button></div>
|
|
112
|
+
<div id="modelChoices" class="model-choices"><div class="empty-models">尚未连接本地模型管理服务<br><small>接入后自动扫描已安装模型,并显示视觉识别 / 推理能力</small></div></div>
|
|
113
|
+
<div class="model-select-foot"><span id="selectedModelCount">已选择 0 个模型</span><span>故障时按优先级自动尝试下一个健康模型</span></div>
|
|
114
|
+
<div class="model-active"><div class="model-icon">✧</div><div class="model-info"><small>当前主模型</small><b id="activeModel">尚未检测</b><span id="modelState">请配置本地模型运行时</span></div><span class="status-pill neutral" id="modelPill">未连接</span></div>
|
|
115
|
+
<div class="model-row"><span>备用模型</span><b id="fallbackModel">尚未配置</b></div>
|
|
116
|
+
<div class="model-row"><span>视觉识别能力</span><b id="visionState">待检测</b></div>
|
|
117
|
+
<div class="model-row"><span>自动故障切换</span><b class="enabled">策略待接入</b></div>
|
|
118
|
+
<div class="model-actions"><button class="soft" id="probeBtn">检查模型</button><button class="soft" id="modelConfigBtn">模型配置</button></div>
|
|
119
|
+
<p class="hint">模型进程存在不等于推理可用。上线后将执行真实健康检查与推理探针,备用模型验证成功后才切换。</p>
|
|
120
|
+
</section>
|
|
121
|
+
|
|
122
|
+
<section class="panel device-panel">
|
|
123
|
+
<div class="section-head"><div><div class="eyebrow">DEVICE LINK</div><h2>设备与网络</h2></div><span class="tag pale">USB / WI-FI</span></div>
|
|
124
|
+
<div class="device-choice"><button class="choice selected" data-mode="USB">⌁ USB 连接</button><button class="choice" data-mode="Wi-Fi">◉ Wi-Fi 连接</button></div>
|
|
125
|
+
<div class="device-state"><div class="phone-icon">▯</div><div><b id="deviceName">尚未发现 Android 设备</b><small id="deviceDetail">连接手机后显示设备信息</small></div></div>
|
|
126
|
+
<div class="model-row"><span>传输协议</span><b id="transportMode">USB / ADB</b></div>
|
|
127
|
+
<div class="model-row"><span>TCP 状态</span><b class="muted">未连接</b></div>
|
|
128
|
+
<div class="model-row"><span>UDP 状态</span><b class="muted">未连接</b></div>
|
|
129
|
+
<p class="hint">Wi-Fi 模式仅用于受信任的本地网络;不会将 ADB 调试端口暴露到公网。</p>
|
|
130
|
+
</section>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<section class="panel log-panel">
|
|
134
|
+
<div class="section-head"><div><div class="eyebrow">SYSTEM EVENTS</div><h2>运行日志</h2></div><button class="text-btn" id="clearLog">清空</button></div>
|
|
135
|
+
<div id="eventLog" class="event-list"><div class="event"><time>--:--:--</time><span class="event-dot"></span><p>控制中心已启动,等待设备桥接与本地推理服务。</p></div></div>
|
|
136
|
+
</section>
|
|
137
|
+
<footer>GAMER · BUILT FOR YOUR NEXT ADVENTURE <span>本地优先 · 用户可控 · 状态透明</span></footer>
|
|
138
|
+
</main>
|
|
139
|
+
<script src="app.js"></script>
|
|
140
|
+
</body>
|
|
141
|
+
</html>
|