dsh-mobile-plugin 0.5.34 → 0.5.36
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/lib/impl.js +0 -11
- package/lib/mobile/answer-sources.js +223 -0
- package/lib/mobile/approval-facts.js +0 -13
- package/lib/mobile/approval-memory.js +1 -1
- package/lib/mobile/events.js +0 -20
- package/lib/mobile/extension-data.js +105 -5
- package/lib/mobile/history-derive.js +54 -1
- package/lib/mobile/notification-prefs.js +2 -2
- package/lib/mobile/permissions.js +13 -24
- package/lib/mobile/plugin-market.js +103 -4
- package/lib/mobile/run-timeline.js +317 -0
- package/lib/mobile/session-send.js +0 -1
- package/lib/mobile/session-stop-summary.js +122 -0
- package/lib/mobile/stats-ledger.cjs +45 -0
- package/lib/mobile/stop-summary.js +146 -0
- package/lib/mobile/third-party-extensions.js +86 -0
- package/lib/mobile/tool-result-cache.js +30 -2
- package/lib/panel/index.html +15 -15
- package/lib/relay/lan-proxy.js +20 -11
- package/lib/relay/tunnel.js +28 -12
- package/lib/routes/mobile-api.js +26 -58
- package/lib/shared/derived-cache.js +121 -0
- package/lib/shared/http-util.js +55 -18
- package/package.json +1 -3
- package/assets/pets/README.md +0 -9
- package/assets/pets/deepy-whale/attention.gif +0 -0
- package/assets/pets/deepy-whale/done.gif +0 -0
- package/assets/pets/deepy-whale/error.gif +0 -0
- package/assets/pets/deepy-whale/idle.gif +0 -0
- package/assets/pets/deepy-whale/pack.json +0 -54
- package/assets/pets/deepy-whale/sleeping.gif +0 -0
- package/assets/pets/deepy-whale/working-3.gif +0 -0
- package/assets/pets/deepy-whale/working.gif +0 -0
- package/config/agent-presets/supervisor/agent.cordis.yml +0 -237
- package/config/agent-presets/supervisor/preset.yml +0 -3
- package/knowledge/apps/alipay.md +0 -30
- package/knowledge/apps/android-settings.md +0 -30
- package/knowledge/apps/baijiahao.md +0 -30
- package/knowledge/apps/bilibili.md +0 -31
- package/knowledge/apps/boss-zhipin.md +0 -32
- package/knowledge/apps/dedao.md +0 -33
- package/knowledge/apps/douyin.md +0 -32
- package/knowledge/apps/feishu.md +0 -35
- package/knowledge/apps/gmail.md +0 -33
- package/knowledge/apps/jike.md +0 -31
- package/knowledge/apps/kuaishou.md +0 -34
- package/knowledge/apps/linkedin.md +0 -33
- package/knowledge/apps/qqmail.md +0 -30
- package/knowledge/apps/taobao.md +0 -33
- package/knowledge/apps/telegram.md +0 -27
- package/knowledge/apps/toutiao.md +0 -32
- package/knowledge/apps/uber-eats.md +0 -26
- package/knowledge/apps/uber.md +0 -27
- package/knowledge/apps/wechat.md +0 -33
- package/knowledge/apps/weibo.md +0 -31
- package/knowledge/apps/whatsapp.md +0 -27
- package/knowledge/apps/x.md +0 -32
- package/knowledge/apps/xiaohongshu.md +0 -30
- package/knowledge/apps/zhihu.md +0 -31
- package/knowledge/sites/bilibili.com/SITE.md +0 -50
- package/knowledge/sites/bilibili.com/references/view-fields.md +0 -17
- package/knowledge/sites/github.com/SITE.md +0 -51
- package/knowledge/sites/github.com/references/repo-fields.md +0 -13
- package/knowledge/sites/x.com/SITE.md +0 -47
- package/knowledge/sites/xiaohongshu.com/SITE.md +0 -48
- package/knowledge/sites/xiaohongshu.com/references/note-fields.md +0 -18
- package/knowledge/sites/youtube.com/SITE.md +0 -49
- package/knowledge/sites/youtube.com/references/innertube-fields.md +0 -14
- package/knowledge/sites/zhihu.com/SITE.md +0 -47
- package/knowledge/sites/zhihu.com/references/api-fields.md +0 -21
- package/lib/mobile/auto-review-log.js +0 -160
- package/lib/mobile/knowledge-base.js +0 -481
- package/lib/mobile/mail.js +0 -621
- package/lib/mobile/pet-tools.js +0 -261
- package/lib/mobile/pets.js +0 -755
- package/lib/mobile/phone/access.js +0 -140
- package/lib/mobile/phone/binding.js +0 -247
- package/lib/mobile/phone/confirm.js +0 -190
- package/lib/mobile/phone/evidence.js +0 -228
- package/lib/mobile/phone/gate.js +0 -290
- package/lib/mobile/phone/grounding.js +0 -314
- package/lib/mobile/phone/guard.js +0 -465
- package/lib/mobile/phone/guarded.js +0 -86
- package/lib/mobile/phone/index.js +0 -114
- package/lib/mobile/phone/irreversible.js +0 -226
- package/lib/mobile/phone/knowledge-tools.js +0 -665
- package/lib/mobile/phone/learn.js +0 -329
- package/lib/mobile/phone/pacing.js +0 -173
- package/lib/mobile/phone/redact.js +0 -237
- package/lib/mobile/phone/risk.js +0 -95
- package/lib/mobile/phone/route-extract.js +0 -460
- package/lib/mobile/phone/route-hint.js +0 -164
- package/lib/mobile/phone/routes-memory.js +0 -133
- package/lib/mobile/phone/routes.js +0 -287
- package/lib/mobile/phone/service.js +0 -520
- package/lib/mobile/phone/site-commands.js +0 -271
- package/lib/mobile/phone/skill-recall.js +0 -246
- package/lib/mobile/phone/skill-routes.js +0 -106
- package/lib/mobile/phone/step-summary.js +0 -201
- package/lib/mobile/phone/stop-summary.js +0 -235
- package/lib/mobile/phone/tool-groups.js +0 -125
- package/lib/mobile/phone/tools.js +0 -2590
- package/lib/mobile/phone/untrusted.js +0 -65
- package/lib/mobile/phone-knowledge.js +0 -317
- package/lib/mobile/route-store.js +0 -266
- package/lib/mobile/supervisor-broadcast.js +0 -503
- package/lib/mobile/supervisor-memory/index.js +0 -305
- package/lib/mobile/supervisor-runtime/index.js +0 -54
- package/lib/mobile/supervisor-runtime/inject.js +0 -218
- package/lib/mobile/supervisor-runtime/judgment.js +0 -113
- package/lib/mobile/supervisor-tools.js +0 -419
- package/lib/mobile/task-ledger.js +0 -381
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 成功路线记忆:把「这个 App 上一轮是怎么一步步做成的」记下来,下次打开同一个 App 时能翻出
|
|
5
|
-
* 以前成功过的路线给模型参考。
|
|
6
|
-
*
|
|
7
|
-
* 存一份 JSON 在 `<DSH_HOME>/storages/mobile-plugin/phone-routes.json`,按包名分桶:
|
|
8
|
-
*
|
|
9
|
-
* { "<包名>": [ { steps: [...], at: 1794…, hits: 0 } ] } // 每个包最多 20 条
|
|
10
|
-
*
|
|
11
|
-
* 三条边界:
|
|
12
|
-
* - **只在成功时记**:`record` 由调用方在结局判定为成功后调;失败、超时、取消一律不记。
|
|
13
|
-
* - **每个包封顶 20 条**:旧记录满了就挤掉最旧的,避免一个常用 App 把文件越攒越大。
|
|
14
|
-
* - **加载失败安静退化**:文件不存在、读坏、形状不对,都当「还没有记录」,绝不抛 —— 记忆是
|
|
15
|
-
* 锦上添花,不能因为它把一次操作或者整个插件装载掀翻。
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const fs = require('node:fs');
|
|
19
|
-
const path = require('node:path');
|
|
20
|
-
|
|
21
|
-
const { dshHome } = require('../../shared/paths');
|
|
22
|
-
|
|
23
|
-
/** 每个包名最多留这么多条历史路线。 */
|
|
24
|
-
const MAX_PER_PACKAGE = 20;
|
|
25
|
-
|
|
26
|
-
/** 落盘文件:`<DSH_HOME>/storages/mobile-plugin/phone-routes.json`,调用时解析。 */
|
|
27
|
-
function routesFile() {
|
|
28
|
-
return path.join(dshHome(), 'storages', 'mobile-plugin', 'phone-routes.json');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 只保留能落盘、也有意义的字段,别把整个 args 原样塞进去(可能很大)。 */
|
|
32
|
-
function normalizeSteps(steps) {
|
|
33
|
-
if (!Array.isArray(steps)) return [];
|
|
34
|
-
const out = [];
|
|
35
|
-
for (const step of steps) {
|
|
36
|
-
if (!step || typeof step !== 'object') continue;
|
|
37
|
-
const entry = {};
|
|
38
|
-
if (typeof step.action === 'string' && step.action.trim()) entry.action = step.action.trim();
|
|
39
|
-
if (step.args && typeof step.args === 'object' && !Array.isArray(step.args)) entry.args = step.args;
|
|
40
|
-
if (step.until && typeof step.until === 'object' && !Array.isArray(step.until)) entry.until = step.until;
|
|
41
|
-
if (entry.action) out.push(entry);
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** 读整份账本。读不到 / 读坏 / 形状不对都当空。 */
|
|
47
|
-
function readStore() {
|
|
48
|
-
let raw;
|
|
49
|
-
try {
|
|
50
|
-
raw = fs.readFileSync(routesFile(), 'utf8');
|
|
51
|
-
} catch {
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
54
|
-
let parsed;
|
|
55
|
-
try {
|
|
56
|
-
parsed = JSON.parse(raw);
|
|
57
|
-
} catch {
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
61
|
-
return parsed;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** 写整份账本。写不进去就安静放弃:这一轮照样算完成,只是这条没记住。 */
|
|
65
|
-
function writeStore(store) {
|
|
66
|
-
const file = routesFile();
|
|
67
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
68
|
-
fs.writeFileSync(file, `${JSON.stringify(store, null, 2)}\n`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 归一化包名。 */
|
|
72
|
-
function normalizePackage(packageName) {
|
|
73
|
-
return typeof packageName === 'string' ? packageName.trim() : '';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 记一条成功路线。只在成功时由调用方调;包名为空或步骤为空时不记。
|
|
78
|
-
* 返回这个包当前的全部记录(方便调用方/测试看结果)。
|
|
79
|
-
*/
|
|
80
|
-
function record(packageName, steps) {
|
|
81
|
-
const pkg = normalizePackage(packageName);
|
|
82
|
-
const cleaned = normalizeSteps(steps);
|
|
83
|
-
if (!pkg || cleaned.length === 0) return [];
|
|
84
|
-
|
|
85
|
-
const store = readStore();
|
|
86
|
-
const bucket = Array.isArray(store[pkg]) ? store[pkg].filter((item) => item && Array.isArray(item.steps)) : [];
|
|
87
|
-
bucket.push({ steps: cleaned, at: Date.now(), hits: 0 });
|
|
88
|
-
// 只留最近的 MAX_PER_PACKAGE 条:新记录在尾部,超了从头挤掉最旧的。
|
|
89
|
-
store[pkg] = bucket.slice(-MAX_PER_PACKAGE);
|
|
90
|
-
try {
|
|
91
|
-
writeStore(store);
|
|
92
|
-
} catch {
|
|
93
|
-
// 写失败不抛,记忆丢一条不影响这一轮已经成功的结果。
|
|
94
|
-
}
|
|
95
|
-
return store[pkg].map(copyRecord);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function copyRecord(item) {
|
|
99
|
-
return {
|
|
100
|
-
steps: Array.isArray(item.steps) ? item.steps.map((step) => ({ ...step })) : [],
|
|
101
|
-
at: Number.isFinite(item.at) ? item.at : 0,
|
|
102
|
-
hits: Number.isFinite(item.hits) ? item.hits : 0,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 读回某个 App 以前成功过的路线(按记录先后,旧的在前)。包名为空或没记录都回空数组。
|
|
108
|
-
* 返回的是副本,调用方改不到账本上。
|
|
109
|
-
*/
|
|
110
|
-
function list(packageName) {
|
|
111
|
-
const pkg = normalizePackage(packageName);
|
|
112
|
-
if (!pkg) return [];
|
|
113
|
-
const store = readStore();
|
|
114
|
-
const bucket = Array.isArray(store[pkg]) ? store[pkg] : [];
|
|
115
|
-
return bucket.filter((item) => item && Array.isArray(item.steps)).map(copyRecord);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** 单测用:删掉落盘文件,回到「还没有任何记录」。 */
|
|
119
|
-
function resetForTest() {
|
|
120
|
-
try {
|
|
121
|
-
fs.rmSync(routesFile(), { force: true });
|
|
122
|
-
} catch {
|
|
123
|
-
// 本来就没有。
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
module.exports = {
|
|
128
|
-
routesFile,
|
|
129
|
-
record,
|
|
130
|
-
list,
|
|
131
|
-
resetForTest,
|
|
132
|
-
MAX_PER_PACKAGE,
|
|
133
|
-
};
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 「让 AI 操作手机」的三条普通状态路由(动作字节流在 `phone/service.js` 的升级口上)。
|
|
5
|
-
*
|
|
6
|
-
* - `GET /api/mobile/v1/phone/status`:这台电脑上「操作手机」这一侧的状态 —— 服务在不在、
|
|
7
|
-
* 哪几台手机连着、这条会话绑的是哪台。App 的配对向导与设置页读它。
|
|
8
|
-
* - `GET /api/mobile/v1/phone/devices`:此刻认识哪几台手机。模型改绑、用户看「另一台」时
|
|
9
|
-
* 都读这份清单。
|
|
10
|
-
* - `POST /api/mobile/v1/phone/unbind`:解除。带 `sessionId` 只清这条会话的绑定;不带就断开
|
|
11
|
-
* 所有连接并清掉所有指向它们的绑定。
|
|
12
|
-
*
|
|
13
|
-
* 三条都只读状态或做收尾,**没有一条能往手机上发动作**:发动作只有 `phone/tools.js` 那条路,
|
|
14
|
-
* 且只由模型在会话里触发。这个分界是刻意的 —— 路由服务的是「正在看设置页的人」,工具服务的
|
|
15
|
-
* 是「正在替用户干活的模型」。
|
|
16
|
-
*
|
|
17
|
-
* 装配方式:路由表(`routes/mobile-api.js`)只认「路径 → handler」,所以这里给的是
|
|
18
|
-
* `createPhoneRoutes(deps)` 造出来的一组 handler,`deps` 由装配层从 `phone/index.js` 转来。
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const { sendJson, readJsonBody } = require('../../shared/http-util');
|
|
22
|
-
const binding = require('./binding.js');
|
|
23
|
-
const pacing = require('./pacing.js');
|
|
24
|
-
const routeHint = require('./route-hint.js');
|
|
25
|
-
const knowledge = require('../phone-knowledge.js');
|
|
26
|
-
const access = require('./access.js');
|
|
27
|
-
|
|
28
|
-
/** 设备标题:机型优先,没有机型才用 deviceId 的短尾巴。与凭据面板同一口径。 */
|
|
29
|
-
function deviceLabel(row) {
|
|
30
|
-
const model = row && typeof row.model === 'string' ? row.model.trim() : '';
|
|
31
|
-
if (model) return row.suffix ? `${model} · ${row.suffix}` : model;
|
|
32
|
-
const id = row && typeof row.deviceId === 'string' ? row.deviceId : '';
|
|
33
|
-
return id ? `手机 ${id.slice(0, 8)}` : '一台没认出身份的手机';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 这台电脑认识哪几台手机、哪几台此刻连着。
|
|
38
|
-
*
|
|
39
|
-
* 名字从凭据库拿(那里才是「这台电脑认识哪些手机」的真值),拿不到就退回 id 的短尾巴;
|
|
40
|
-
* 已经连上来但凭据库里没有的(老记录、刚重置过的库)也照样报出来 —— 否则模型看不见一台
|
|
41
|
-
* 明明能用的手机。
|
|
42
|
-
*/
|
|
43
|
-
function listDevices(deps) {
|
|
44
|
-
const known = [];
|
|
45
|
-
try {
|
|
46
|
-
if (deps.credentials && deps.instanceId) {
|
|
47
|
-
for (const row of deps.credentials.listDevices(deps.instanceId)) known.push(row);
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
// 凭据库读不出来不影响「谁在线」这件事:退化成只报 id。
|
|
51
|
-
}
|
|
52
|
-
const service = deps.getService ? deps.getService() : null;
|
|
53
|
-
const online = new Map();
|
|
54
|
-
if (service && service.devices) for (const [deviceId, link] of service.devices) online.set(deviceId, link);
|
|
55
|
-
|
|
56
|
-
const rows = new Map();
|
|
57
|
-
for (const row of known) {
|
|
58
|
-
const live = online.get(row.deviceId);
|
|
59
|
-
rows.set(row.deviceId, {
|
|
60
|
-
deviceId: row.deviceId,
|
|
61
|
-
name: deviceLabel(row),
|
|
62
|
-
model: row.model || '',
|
|
63
|
-
platform: row.platform || '',
|
|
64
|
-
osVersion: row.osVersion || '',
|
|
65
|
-
appVersion: row.appVersion || '',
|
|
66
|
-
online: Boolean(live),
|
|
67
|
-
// 能力清单只对「此刻连着」的那台有意义:设置页据此说「这台手机支持什么」。
|
|
68
|
-
// 没连上时报空表,界面那边按「还没连上」处理,不拿上一次的旧清单冒充。
|
|
69
|
-
capabilities: live && Array.isArray(live.capabilities) ? live.capabilities : [],
|
|
70
|
-
lastSeenAt: row.lastSeenAt || 0,
|
|
71
|
-
});
|
|
72
|
-
if (live) online.delete(row.deviceId);
|
|
73
|
-
}
|
|
74
|
-
for (const [deviceId, link] of online) {
|
|
75
|
-
const device = link.device || {};
|
|
76
|
-
rows.set(deviceId, {
|
|
77
|
-
deviceId,
|
|
78
|
-
name: deviceLabel({ deviceId, model: device.model }),
|
|
79
|
-
model: device.model || '',
|
|
80
|
-
platform: device.platform || '',
|
|
81
|
-
osVersion: device.osVersion || '',
|
|
82
|
-
appVersion: device.appVersion || '',
|
|
83
|
-
online: true,
|
|
84
|
-
capabilities: Array.isArray(link.capabilities) ? link.capabilities : [],
|
|
85
|
-
lastSeenAt: Date.now(),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return [...rows.values()].sort((a, b) => (Number(b.online) - Number(a.online)) || (b.lastSeenAt - a.lastSeenAt));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function describeDevice(deps, deviceId) {
|
|
92
|
-
const row = listDevices(deps).find((item) => item.deviceId === deviceId);
|
|
93
|
-
return row ? row.name : deviceId;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** GET /phone/status?sessionId=… */
|
|
97
|
-
async function handlePhoneStatus(deps, _ctx, req, res) {
|
|
98
|
-
const url = new URL(req.url || '/', 'http://x');
|
|
99
|
-
const sessionId = (url.searchParams.get('sessionId') || '').trim();
|
|
100
|
-
const service = deps.getService ? deps.getService() : null;
|
|
101
|
-
const devices = listDevices(deps);
|
|
102
|
-
const payload = {
|
|
103
|
-
ok: true,
|
|
104
|
-
running: Boolean(service),
|
|
105
|
-
online: devices.filter((row) => row.online).map((row) => row.deviceId),
|
|
106
|
-
devices,
|
|
107
|
-
};
|
|
108
|
-
if (sessionId) {
|
|
109
|
-
const bound = binding.boundDeviceOf(sessionId);
|
|
110
|
-
payload.binding = {
|
|
111
|
-
deviceId: bound || '',
|
|
112
|
-
name: bound ? describeDevice(deps, bound) : '',
|
|
113
|
-
lastSender: binding.lastSenderOf(sessionId) || '',
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
// 顶层再带一份「这台手机能做什么」:设置页问的是「我现在操作的是哪台、它能做什么」,
|
|
117
|
-
// 那条会话绑了就看绑的那台,没绑就看唯第一台在线的。都没有就是空表。
|
|
118
|
-
const focus = (payload.binding && payload.binding.deviceId)
|
|
119
|
-
? devices.find((row) => row.deviceId === payload.binding.deviceId)
|
|
120
|
-
: devices.find((row) => row.online);
|
|
121
|
-
payload.capabilities = focus && Array.isArray(focus.capabilities) ? focus.capabilities : [];
|
|
122
|
-
sendJson(res, 200, payload);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** GET /phone/devices */
|
|
126
|
-
async function handlePhoneDevices(deps, _ctx, _req, res) {
|
|
127
|
-
sendJson(res, 200, { ok: true, devices: listDevices(deps) });
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* POST /phone/unbind —— `{ sessionId?, deviceId? }`
|
|
132
|
-
*
|
|
133
|
-
* 不带参数是「这台电脑上操作手机这件事整个解除」:断开所有连接、清掉所有指向它们的绑定。
|
|
134
|
-
* 带 `sessionId` 只清这一条会话的绑定(用户只是想让这条对话别再用那台手机)。
|
|
135
|
-
*
|
|
136
|
-
* 卸掉手机上那枚 adb 钥匙这一步只能由手机侧自己做(壳在手机上,宿主碰不到它),所以回包里
|
|
137
|
-
* 如实写 `localReset: 'requested'`,界面据此提示「回手机上确认一下」。
|
|
138
|
-
*/
|
|
139
|
-
async function handlePhoneUnbind(deps, _ctx, req, res) {
|
|
140
|
-
const body = await readJsonBody(req);
|
|
141
|
-
const sessionId = body && typeof body.sessionId === 'string' ? body.sessionId.trim() : '';
|
|
142
|
-
const deviceId = body && typeof body.deviceId === 'string' ? body.deviceId.trim() : '';
|
|
143
|
-
if (sessionId) {
|
|
144
|
-
return sendJson(res, 200, {
|
|
145
|
-
ok: true,
|
|
146
|
-
clearedSession: binding.clearBinding(sessionId),
|
|
147
|
-
disconnected: [],
|
|
148
|
-
localReset: '',
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
const service = deps.getService ? deps.getService() : null;
|
|
152
|
-
const targets = deviceId ? [deviceId] : listDevices(deps).map((row) => row.deviceId);
|
|
153
|
-
for (const id of targets) service?.kick?.(id);
|
|
154
|
-
const cleared = targets.reduce((sum, id) => sum + binding.clearBindingForDevice(id), 0);
|
|
155
|
-
sendJson(res, 200, { ok: true, clearedSession: false, clearedBindings: cleared, disconnected: targets, localReset: 'requested' });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* GET /phone/knowledge?package=… —— 知识库里有哪些 App、有哪些网站,各自包名 / 域名,以及按就
|
|
160
|
-
* 包名查询时的命中情况。
|
|
161
|
-
*
|
|
162
|
-
* 只读:把 `knowledge/apps/*.md` 与 `knowledge/sites/*.md` 的目录清单摊平给设置页看,不碰手机、
|
|
163
|
-
* 不发任何动作。`package` 是可选的前台包名;给了就标出哪一条 App 命中(`hit`),并回填 `matched`。
|
|
164
|
-
*/
|
|
165
|
-
async function handlePhoneKnowledge(deps, _ctx, req, res) {
|
|
166
|
-
const url = new URL(req.url || '/', 'http://x');
|
|
167
|
-
const pkg = (url.searchParams.get('package') || '').trim();
|
|
168
|
-
const matched = pkg ? knowledge.matchApp(pkg) : null;
|
|
169
|
-
const apps = knowledge.listApps().map((app) => ({
|
|
170
|
-
name: app.name,
|
|
171
|
-
display: app.display,
|
|
172
|
-
packages: app.packages,
|
|
173
|
-
aliases: app.aliases,
|
|
174
|
-
open: app.open,
|
|
175
|
-
hit: Boolean(matched && matched.name === app.name),
|
|
176
|
-
}));
|
|
177
|
-
const sites = knowledge.listSites().map((site) => ({
|
|
178
|
-
name: site.name,
|
|
179
|
-
display: site.display,
|
|
180
|
-
description: site.description,
|
|
181
|
-
sites: site.domains,
|
|
182
|
-
aliases: site.aliases,
|
|
183
|
-
}));
|
|
184
|
-
sendJson(res, 200, { ok: true, apps, sites, matched: matched ? matched.name : '' });
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* GET /phone/routes?package=… —— 某个 App 以前成功过的路线(最多 5 条,只给步骤摘要)。
|
|
189
|
-
*
|
|
190
|
-
* 只读:从成功路线账本里读回,不碰手机、不发任何动作。**这些只是参考,不会自动执行** ——
|
|
191
|
-
* 模型看过之后仍要按当前屏重新判断。
|
|
192
|
-
*/
|
|
193
|
-
async function handlePhoneRoutes(_deps, _ctx, req, res) {
|
|
194
|
-
const url = new URL(req.url || '/', 'http://x');
|
|
195
|
-
const pkg = (url.searchParams.get('package') || '').trim();
|
|
196
|
-
const routes = pkg ? routeHint.hintFor(pkg) : [];
|
|
197
|
-
sendJson(res, 200, { ok: true, packageName: pkg, count: routes.length, routes });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* GET / POST /phone/pacing —— 读或改「操作节奏」那一档。
|
|
202
|
-
*
|
|
203
|
-
* 和上面几条一样只碰设置,不往手机上发动作:节奏改了下一轮动作才生效,正在跑的那一批
|
|
204
|
-
* 不跟着变(动作中途改停留会让边界很奇怪,重开一轮才干净)。
|
|
205
|
-
*/
|
|
206
|
-
async function handlePhonePacing(_deps, _ctx, req, res) {
|
|
207
|
-
if (req.method === 'GET' || !req.method) {
|
|
208
|
-
const mode = pacing.get();
|
|
209
|
-
return sendJson(res, 200, { ok: true, mode, pace: pacing.paceFor(mode) });
|
|
210
|
-
}
|
|
211
|
-
const body = await readJsonBody(req);
|
|
212
|
-
const wanted = body && typeof body.mode === 'string' ? body.mode.trim().toLowerCase() : '';
|
|
213
|
-
if (!wanted) return sendJson(res, 400, { ok: false, error: 'missing-mode' });
|
|
214
|
-
try {
|
|
215
|
-
const mode = pacing.set(wanted);
|
|
216
|
-
sendJson(res, 200, { ok: true, mode, pace: pacing.paceFor(mode) });
|
|
217
|
-
} catch {
|
|
218
|
-
// 不认识的档名:如实回 400 并把可选值带上,别让设置页自己维护一份枚举。
|
|
219
|
-
sendJson(res, 400, { ok: false, error: 'unknown-mode', modes: pacing.MODES });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* 逐 App 访问控制(三档):GET 读全部开关行,POST 改一个 App 的档 / 分享例外。
|
|
225
|
-
*
|
|
226
|
-
* 只是本地开关,不往手机上发动作;名单落 `$DSH_HOME/storages/mobile-plugin/phone-app-access.json`,
|
|
227
|
-
* 宿主 `tools.js` 执行前按同一份名单 gate。包名形状在这里先校验,挡住把路径/命令塞进来。
|
|
228
|
-
* GET/POST 成功都回同一份形状(`defaultMode` + `apps`),界面读一次就能显示「其余默认」。
|
|
229
|
-
*/
|
|
230
|
-
async function handlePhoneAppAccess(_deps, _ctx, req, res) {
|
|
231
|
-
const payload = () => ({ ok: true, defaultMode: access.DEFAULT_MODE, apps: access.rows() });
|
|
232
|
-
if (req.method === 'GET' || !req.method) {
|
|
233
|
-
return sendJson(res, 200, payload());
|
|
234
|
-
}
|
|
235
|
-
const body = await readJsonBody(req);
|
|
236
|
-
const packageName = body && typeof body.packageName === 'string' ? body.packageName : '';
|
|
237
|
-
const hasMode = Boolean(body) && body.mode !== undefined;
|
|
238
|
-
const hasShare = Boolean(body) && typeof body.shareAllowed === 'boolean';
|
|
239
|
-
if (!hasMode && !hasShare) {
|
|
240
|
-
return sendJson(res, 400, { ok: false, error: 'missing-flags' });
|
|
241
|
-
}
|
|
242
|
-
const patch = {};
|
|
243
|
-
if (hasMode) patch.mode = typeof body.mode === 'string' ? body.mode.trim().toLowerCase() : body.mode;
|
|
244
|
-
if (hasShare) patch.shareAllowed = body.shareAllowed;
|
|
245
|
-
const result = access.update(packageName, patch);
|
|
246
|
-
if (!result.ok) {
|
|
247
|
-
if (result.error === 'unknown-mode') {
|
|
248
|
-
return sendJson(res, 400, { ok: false, error: 'unknown-mode', modes: result.modes || access.MODES });
|
|
249
|
-
}
|
|
250
|
-
return sendJson(res, 400, { ok: false, error: result.error });
|
|
251
|
-
}
|
|
252
|
-
sendJson(res, 200, payload());
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 造出路由表要的那组 handler。
|
|
257
|
-
*
|
|
258
|
-
* @param {object} deps
|
|
259
|
-
* @param {() => object|null} deps.getService 取值器(服务随插件重载整体替换)
|
|
260
|
-
* @param {object} [deps.credentials] 凭据库
|
|
261
|
-
* @param {string} [deps.instanceId]
|
|
262
|
-
*/
|
|
263
|
-
function createPhoneRoutes(deps) {
|
|
264
|
-
return {
|
|
265
|
-
status: (ctx, req, res) => handlePhoneStatus(deps, ctx, req, res),
|
|
266
|
-
devices: (ctx, req, res) => handlePhoneDevices(deps, ctx, req, res),
|
|
267
|
-
unbind: (ctx, req, res) => handlePhoneUnbind(deps, ctx, req, res),
|
|
268
|
-
knowledge: (ctx, req, res) => handlePhoneKnowledge(deps, ctx, req, res),
|
|
269
|
-
routes: (ctx, req, res) => handlePhoneRoutes(deps, ctx, req, res),
|
|
270
|
-
pacing: (ctx, req, res) => handlePhonePacing(deps, ctx, req, res),
|
|
271
|
-
appAccess: (ctx, req, res) => handlePhoneAppAccess(deps, ctx, req, res),
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
module.exports = {
|
|
276
|
-
createPhoneRoutes,
|
|
277
|
-
handlePhoneStatus,
|
|
278
|
-
handlePhoneDevices,
|
|
279
|
-
handlePhoneUnbind,
|
|
280
|
-
handlePhoneKnowledge,
|
|
281
|
-
handlePhoneRoutes,
|
|
282
|
-
handlePhonePacing,
|
|
283
|
-
handlePhoneAppAccess,
|
|
284
|
-
listDevices,
|
|
285
|
-
describeDevice,
|
|
286
|
-
deviceLabel,
|
|
287
|
-
};
|