feat: harness.discover (apiProxy inventory) + harness.pair (device pairing link assist); repack tgz
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user