feat: harness.discover (apiProxy inventory) + harness.pair (device pairing link assist); repack tgz

This commit is contained in:
2026-09-02 01:24:58 +08:00
parent f4e14d8513
commit a17b1705fe
2 changed files with 44 additions and 0 deletions
+44
View File
@@ -106,6 +106,48 @@ function apply(ctx, config) {
};
}
async function harnessDiscover() {
const out = {};
if (!api) return { error: 'apiProxy unavailable' };
for (const domain of Object.keys(api)) {
const d = api[domain];
const methods = [];
if (d) {
for (const k of Object.keys(d)) {
if (typeof d[k] === 'function') methods.push(k);
}
}
out[domain] = methods.sort();
}
return { domains: out };
}
async function harnessPair(params) {
// 尝试常见命名:取到主电脑的设备配对链接,供手机端自动完成配对
const candidates = [
['remote', 'createPairingLink'],
['remote', 'createDeviceLink'],
['remote', 'pair'],
['device', 'createPairingLink'],
['device', 'pair'],
['remote', 'deviceLink'],
['pairing', 'createLink']
];
const errors = [];
for (const [domain, method] of candidates) {
try {
const d = api && api[domain];
if (d && typeof d[method] === 'function') {
const res = await d[method](params || {});
return { domain, method, result: res };
}
} catch (e) {
errors.push(domain + '.' + method + ': ' + (e && e.message || e));
}
}
throw new Error('无可用配对接口: ' + (errors.join(' | ') || 'unknown'));
}
async function sessionList() {
const status = await computeStatus();
return {
@@ -135,6 +177,8 @@ function apply(ctx, config) {
if (method === 'harness.balance') return harnessBalance();
if (method === 'session.list') return sessionList();
if (method === 'session.history') return sessionHistory(params);
if (method === 'harness.discover') return harnessDiscover();
if (method === 'harness.pair') return harnessPair(params);
const dot = method.indexOf('.');
if (dot <= 0) throw new Error('unknown method ' + method);
const domain = method.slice(0, dot);