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,271 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 站点知识里的只读脚本:声明格式、清单与调用参数校验。
|
|
5
|
-
*
|
|
6
|
-
* 一条命令就是站点目录下的 `scripts/<name>.js`,文件以一段块注释开头(MARK 见下),后面是
|
|
7
|
-
* async 函数体,参数从 `args` 取。name 必须与文件名一致。头部一行一项:
|
|
8
|
-
*
|
|
9
|
-
* - `name: list_jobs`
|
|
10
|
-
* - `description: 列出当前搜索结果里的职位`
|
|
11
|
-
* - `arg: limit integer - 最多几条`
|
|
12
|
-
* - `arg: query string required - 只保留标题含这段字的`
|
|
13
|
-
* - `returns: [{title, company, salary, url}]`
|
|
14
|
-
* - `readOnly: true`(可选;站点命令只能是 true)
|
|
15
|
-
*
|
|
16
|
-
* 真正的页面内执行由原生侧做(真实页面、读取世界、同源只读),这个模块**不碰网络、不执行
|
|
17
|
-
* 任何代码**,只做两件事:把站点目录里的命令声明列出来,以及在调用前按声明校验参数。
|
|
18
|
-
*
|
|
19
|
-
* ## 执行契约(原生侧遵守,这里只定义,不在 JS 里强制执行)
|
|
20
|
-
*
|
|
21
|
-
* - 只读:脚本只能读 DOM 与页面已加载的数据,不得点击、输入、导航或改动页面状态。
|
|
22
|
-
* - 同源:只允许当前页面同源的 GET,禁止跨域请求。
|
|
23
|
-
* - 禁网:除同源只读外不得主动发起网络请求,不发 POST、不调站点的写接口。
|
|
24
|
-
* - 密码打码:返回值若来自密码 / 验证码等敏感输入,一律以 `***` 代替。
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const fs = require('node:fs');
|
|
28
|
-
const path = require('node:path');
|
|
29
|
-
|
|
30
|
-
/** 命令头的起始标记。与 Mika 的 `/* mika-command` 同构,换成我们自己的名字。 */
|
|
31
|
-
const COMMAND_MARK = '/* dsh-command';
|
|
32
|
-
/** 命令名的字符集:小写字母开头,字母数字下划线,至多 40 个。 */
|
|
33
|
-
const NAME_RE = /^[a-z][a-z0-9_]{0,39}$/;
|
|
34
|
-
/** 参数类型白名单。 */
|
|
35
|
-
const TYPES = ['string', 'integer', 'number', 'boolean'];
|
|
36
|
-
/** 说明文字上限。 */
|
|
37
|
-
const DESCRIPTION_LIMIT = 120;
|
|
38
|
-
/** 脚本正文上限(字符)。太长说明该拆,不放进一块。 */
|
|
39
|
-
const BODY_LIMIT = 12_000;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 站点知识里 `commands` 的字段规格(给写知识的人看,也给校验用)。
|
|
43
|
-
* 每条命令恒定只读。
|
|
44
|
-
*/
|
|
45
|
-
const COMMAND_SCHEMA = {
|
|
46
|
-
name: '小写字母开头,字母 / 数字 / 下划线,至多 40,必须与文件名 scripts/<name>.js 一致',
|
|
47
|
-
description: `一句话说清这条命令取什么,至多 ${DESCRIPTION_LIMIT} 字`,
|
|
48
|
-
readOnly: '恒为 true:站点命令只能读,不得写页面或改状态',
|
|
49
|
-
returns: '返回的字段说明,例如 [{title, url}]',
|
|
50
|
-
args: '[{ name, type: string|integer|number|boolean, required?, description? }]',
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/** 执行契约的文字版(给知识注入与原生实现对齐用)。 */
|
|
54
|
-
const EXECUTION_CONTRACT = {
|
|
55
|
-
readOnly: true,
|
|
56
|
-
sameOrigin: true,
|
|
57
|
-
network: false,
|
|
58
|
-
redactPasswords: true,
|
|
59
|
-
summary:
|
|
60
|
-
'只读、同源、禁网、密码打码:脚本只读当前页面同源数据,不点击不输入不改页面,'
|
|
61
|
-
+ '不主动发网络请求(含写接口),敏感输入一律打码后返回。',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const ARG_RE = /^([a-z][A-Za-z0-9_]{0,39})\s+(string|integer|number|boolean)(\s+required)?(?:\s+-\s+(.+))?$/;
|
|
65
|
-
|
|
66
|
-
/** 去掉 BOM、统一换行、去掉开头空白,便于认头部。 */
|
|
67
|
-
function clean(text) {
|
|
68
|
-
return String(text || '').replace(/^\uFEFF/, '').replace(/\r\n/g, '\n').replace(/^\s+/, '');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 这段文本是不是一条站点命令(以命令头开头)。 */
|
|
72
|
-
function isCommand(text) {
|
|
73
|
-
return clean(text).startsWith(COMMAND_MARK);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 解析一条站点命令文件。
|
|
78
|
-
*
|
|
79
|
-
* 返回 `{ decl, body, errors }`:`decl` 只在 `errors` 为空时给出,形状为
|
|
80
|
-
* `{ name, description, readOnly: true, returns, args, file }`;`body` 是头部之后的脚本正文。
|
|
81
|
-
*
|
|
82
|
-
* @param {string} file 站点目录下的相对路径,如 `scripts/list_jobs.js`
|
|
83
|
-
* @param {string} text 文件全文
|
|
84
|
-
*/
|
|
85
|
-
function parseCommand(file, text) {
|
|
86
|
-
const t = clean(text);
|
|
87
|
-
if (!t.startsWith(COMMAND_MARK)) {
|
|
88
|
-
return { decl: null, body: '', errors: [`文件要以 \`${COMMAND_MARK}\` 开头`] };
|
|
89
|
-
}
|
|
90
|
-
const end = t.indexOf('*/');
|
|
91
|
-
if (end < 0) return { decl: null, body: '', errors: ['命令头没有用 `*/` 结束'] };
|
|
92
|
-
|
|
93
|
-
const body = t.slice(end + 2).trim();
|
|
94
|
-
const errors = [];
|
|
95
|
-
let name = null;
|
|
96
|
-
let description = null;
|
|
97
|
-
let returns = null;
|
|
98
|
-
let readOnly = null;
|
|
99
|
-
const args = [];
|
|
100
|
-
|
|
101
|
-
for (const raw of t.slice(COMMAND_MARK.length, end).split('\n')) {
|
|
102
|
-
// 头部每行可能带一个多余的 `*` 前缀,去掉它再按 key: value 解析。
|
|
103
|
-
const line = raw.trim().replace(/^\*\s?/, '');
|
|
104
|
-
if (!line) continue;
|
|
105
|
-
const idx = line.indexOf(':');
|
|
106
|
-
if (idx <= 0) {
|
|
107
|
-
errors.push(`头部这一行看不懂:${line}`);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const key = line.slice(0, idx).trim();
|
|
111
|
-
const value = line.slice(idx + 1).trim();
|
|
112
|
-
switch (key) {
|
|
113
|
-
case 'name':
|
|
114
|
-
name = value;
|
|
115
|
-
break;
|
|
116
|
-
case 'description':
|
|
117
|
-
description = value;
|
|
118
|
-
break;
|
|
119
|
-
case 'returns':
|
|
120
|
-
returns = value;
|
|
121
|
-
break;
|
|
122
|
-
case 'readOnly':
|
|
123
|
-
case 'readonly':
|
|
124
|
-
readOnly = value.toLowerCase() === 'true';
|
|
125
|
-
break;
|
|
126
|
-
case 'arg':
|
|
127
|
-
{
|
|
128
|
-
const m = ARG_RE.exec(value);
|
|
129
|
-
if (m) {
|
|
130
|
-
args.push({
|
|
131
|
-
name: m[1],
|
|
132
|
-
type: m[2],
|
|
133
|
-
required: Boolean(m[3]),
|
|
134
|
-
description: (m[4] || '').trim(),
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
errors.push(`arg 要写作「名字 类型 [required] [- 说明]」,类型是 ${TYPES.join('/')}:${value}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
break;
|
|
141
|
-
default:
|
|
142
|
-
errors.push(`头部有不认得的键 ${key}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const base = path.basename(file).replace(/\.js$/i, '');
|
|
147
|
-
if (name == null) errors.push('缺少 name');
|
|
148
|
-
else if (!NAME_RE.test(name)) errors.push('name 只能用小写字母、数字与下划线,以字母开头,至多 40 个字符');
|
|
149
|
-
else if (name !== base) errors.push(`name(${name})必须与文件名(${base}.js)一致`);
|
|
150
|
-
if (description == null || description === '') errors.push('缺少 description');
|
|
151
|
-
else if ([...description].length > DESCRIPTION_LIMIT) errors.push(`description 超过 ${DESCRIPTION_LIMIT} 字`);
|
|
152
|
-
if (returns == null || returns === '') errors.push('缺少 returns');
|
|
153
|
-
if (readOnly === false) errors.push('站点命令只能只读,readOnly 不能是 false');
|
|
154
|
-
const dupNames = args.map((a) => a.name).filter((n, i, arr) => arr.indexOf(n) !== i);
|
|
155
|
-
for (const dup of new Set(dupNames)) errors.push(`arg ${dup} 重复`);
|
|
156
|
-
if (body === '') errors.push('脚本正文为空');
|
|
157
|
-
if (body.length > BODY_LIMIT) errors.push(`脚本正文 ${body.length} 字,超过 ${BODY_LIMIT}`);
|
|
158
|
-
|
|
159
|
-
const decl = errors.length === 0
|
|
160
|
-
? { name, description, readOnly: true, returns, args, file }
|
|
161
|
-
: null;
|
|
162
|
-
return { decl, body, errors };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** 值是否符合声明的类型。 */
|
|
166
|
-
function fitsType(value, type) {
|
|
167
|
-
switch (type) {
|
|
168
|
-
case 'string':
|
|
169
|
-
return typeof value === 'string';
|
|
170
|
-
case 'boolean':
|
|
171
|
-
return typeof value === 'boolean';
|
|
172
|
-
case 'integer':
|
|
173
|
-
return typeof value === 'number' && Number.isInteger(value);
|
|
174
|
-
case 'number':
|
|
175
|
-
return typeof value === 'number' && Number.isFinite(value);
|
|
176
|
-
default:
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 按声明校验一次调用的参数。没问题返回 null,有问题返回一句中文说明。
|
|
183
|
-
*
|
|
184
|
-
* @param {object} decl parseCommand 给出的命令声明
|
|
185
|
-
* @param {object} args 模型 / 调用方给的参数(名字 → 值)
|
|
186
|
-
*/
|
|
187
|
-
function validateCommand(decl, args) {
|
|
188
|
-
if (!decl || typeof decl !== 'object') return '命令声明无效';
|
|
189
|
-
const given = args && typeof args === 'object' && !Array.isArray(args) ? args : {};
|
|
190
|
-
const declared = new Map((decl.args || []).map((a) => [a.name, a]));
|
|
191
|
-
for (const key of Object.keys(given)) {
|
|
192
|
-
if (!declared.has(key)) {
|
|
193
|
-
const takes = (decl.args || []).map((a) => a.name).join('、') || '无参数';
|
|
194
|
-
return `'${key}' 不是 ${decl.name} 的参数;它接受 ${takes}`;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
for (const arg of decl.args || []) {
|
|
198
|
-
const value = given[arg.name];
|
|
199
|
-
const missing = value === undefined || value === null;
|
|
200
|
-
if (missing) {
|
|
201
|
-
if (arg.required) return `${decl.name} 需要参数 '${arg.name}'(${arg.type})`;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
if (!fitsType(value, arg.type)) return `参数 '${arg.name}' 必须是 ${arg.type}`;
|
|
205
|
-
}
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* 读一个站点目录下的 `scripts/*.js`,把带命令头的解析成声明清单。
|
|
211
|
-
*
|
|
212
|
-
* 返回 `{ commands, errors }`:`commands` 是合法声明(按名字排序),`errors` 收下坏掉的命令
|
|
213
|
-
* 及其具体问题。目录不存在或某文件读坏了都只跳过,不抛。
|
|
214
|
-
*
|
|
215
|
-
* @param {string} siteDir 站点知识目录,如 `knowledge/sites/github.com`
|
|
216
|
-
*/
|
|
217
|
-
function listCommands(siteDir) {
|
|
218
|
-
const dir = path.join(String(siteDir || ''), 'scripts');
|
|
219
|
-
let entries;
|
|
220
|
-
try {
|
|
221
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
222
|
-
} catch {
|
|
223
|
-
return { commands: [], errors: [] };
|
|
224
|
-
}
|
|
225
|
-
const commands = [];
|
|
226
|
-
const errors = [];
|
|
227
|
-
for (const entry of entries) {
|
|
228
|
-
if (!entry.isFile() || !entry.name.endsWith('.js')) continue;
|
|
229
|
-
let text;
|
|
230
|
-
try {
|
|
231
|
-
text = fs.readFileSync(path.join(dir, entry.name), 'utf8');
|
|
232
|
-
} catch {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (!isCommand(text)) continue;
|
|
236
|
-
const rel = `scripts/${entry.name}`;
|
|
237
|
-
const parsed = parseCommand(rel, text);
|
|
238
|
-
if (parsed.decl) commands.push(parsed.decl);
|
|
239
|
-
else errors.push({ file: rel, errors: parsed.errors });
|
|
240
|
-
}
|
|
241
|
-
commands.sort((a, b) => a.name.localeCompare(b.name));
|
|
242
|
-
return { commands, errors };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** 把一条命令声明写成知识块里的一行(供站点正文注入)。 */
|
|
246
|
-
function formatCommandLine(decl) {
|
|
247
|
-
const sig = (decl.args || [])
|
|
248
|
-
.map((a) => `${a.name}${a.required ? '' : '?'}: ${a.type}`)
|
|
249
|
-
.join(', ');
|
|
250
|
-
const notes = (decl.args || [])
|
|
251
|
-
.filter((a) => a.description)
|
|
252
|
-
.map((a) => `${a.name} ${a.description}`)
|
|
253
|
-
.join('; ');
|
|
254
|
-
return `- ${decl.name}(${sig}): ${decl.description}。返回 ${decl.returns}`
|
|
255
|
-
+ (notes ? `。参数:${notes}` : '');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
module.exports = {
|
|
259
|
-
COMMAND_MARK,
|
|
260
|
-
NAME_RE,
|
|
261
|
-
TYPES,
|
|
262
|
-
DESCRIPTION_LIMIT,
|
|
263
|
-
BODY_LIMIT,
|
|
264
|
-
COMMAND_SCHEMA,
|
|
265
|
-
EXECUTION_CONTRACT,
|
|
266
|
-
isCommand,
|
|
267
|
-
parseCommand,
|
|
268
|
-
validateCommand,
|
|
269
|
-
listCommands,
|
|
270
|
-
formatCommandLine,
|
|
271
|
-
};
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `phone_skill_recall`:把以前学成的那条路线找回来,**给模型照着一步步做**。
|
|
5
|
-
*
|
|
6
|
-
* ## 为什么不直接自动重放
|
|
7
|
-
*
|
|
8
|
-
* 自动重放要在插件里再写一套「读屏 → 认目标 → 下发动作 → 等条件」的循环,那等于把 `phone_steps`
|
|
9
|
-
* 已经做对的执行链复制一份,两份迟早不同步;更要紧的是能力面:重放一旦能自己往下推,就意味着
|
|
10
|
-
* 有了一条不受模型逐步判断约束的执行入口。所以这里只做「查 + 摆出来」:
|
|
11
|
-
*
|
|
12
|
-
* - 查到的是**这一步要动什么**(动作、目标文字、相对位置、等待条件),
|
|
13
|
-
* - 模型照它写成一串 `phone_steps` 调用,**走的还是原来那十几个动作**,
|
|
14
|
-
* - 付款 / 不可逆那一步照旧被 `phone_steps` 与 `phone_tap` 的熔断拦下。
|
|
15
|
-
*
|
|
16
|
-
* 换句话说:这是 `phone_route_hint` 的升级版 —— 那个给的是人话摘要,这个给的是能直接
|
|
17
|
-
* 落成动作的目标描述,但两者都**不自动执行**。
|
|
18
|
-
*
|
|
19
|
-
* 与 `phone_route_hint` 的分工:那个读的是「成功过的路线摘要」(每个 App 最多 20 条,人读的),
|
|
20
|
-
* 在还没学成技能时仍然有用;这个读的是学成并收下的**技能路线**(带定位骨架),更精确。
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const routeStore = require('../route-store.js');
|
|
24
|
-
|
|
25
|
-
/** 一条路线最多回几步给模型,多了一眼看不完。 */
|
|
26
|
-
const MAX_RENDER_STEPS = 20;
|
|
27
|
-
|
|
28
|
-
/** 注册方式与 `route-hint.js` 一致:走 `ctx.inject(['tools'])`,缺注入就静默跳过。 */
|
|
29
|
-
function installSkillRecall(ctx) {
|
|
30
|
-
if (!ctx || typeof ctx.inject !== 'function') return;
|
|
31
|
-
let defineTool;
|
|
32
|
-
try {
|
|
33
|
-
({ defineTool } = require('@deepseek-ai/dsh-tools'));
|
|
34
|
-
} catch {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
ctx.inject(['tools'], (scoped) => {
|
|
39
|
-
if (!scoped || !scoped.tools || typeof scoped.tools.register !== 'function') return;
|
|
40
|
-
scoped.tools.register(defineTool({
|
|
41
|
-
name: 'phone_skill_recall',
|
|
42
|
-
description: 'Look up a phone route that was learned earlier for this app and goal, as concrete step targets. This does NOT execute anything: read the screen, then drive the same phone_* tools yourself, one step at a time. Each step tells you what to act on (text/role/relative position) and what to wait for. If the screen does not match, stop and say so — never fire blind at a stale position.',
|
|
43
|
-
parameters: {
|
|
44
|
-
packageName: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
required: true,
|
|
47
|
-
description: 'Android package name of the app, e.g. "com.tencent.mm".',
|
|
48
|
-
},
|
|
49
|
-
intent: {
|
|
50
|
-
type: 'string',
|
|
51
|
-
description: 'What the user wants to do in that app, in their own words. Used to pick the closest learned route.',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
output: {
|
|
55
|
-
schema: {
|
|
56
|
-
type: 'object',
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
properties: {
|
|
59
|
-
ok: { type: 'boolean' },
|
|
60
|
-
found: { type: 'boolean' },
|
|
61
|
-
name: { type: 'string' },
|
|
62
|
-
steps: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
63
|
-
note: { type: 'string' },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
render: (_args, value) => {
|
|
67
|
-
if (!value.found) return [{ type: 'text', text: value.note || '没有学过这个 App 里这件事的路线。' }];
|
|
68
|
-
const lines = [
|
|
69
|
-
`找到一条已收下的路线「${value.name}」。`,
|
|
70
|
-
'照着它走,但每一步都先 phone_screen 看当前屏、按当前屏的 ref 动作;对不上就停下如实说,不要按旧位置硬点:',
|
|
71
|
-
];
|
|
72
|
-
for (const step of value.steps || []) lines.push(step.line);
|
|
73
|
-
if (value.note) lines.push(value.note);
|
|
74
|
-
return [{ type: 'text', text: lines.join('\n') }];
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
execute: async (args) => {
|
|
78
|
-
const pkg = typeof args.packageName === 'string' ? args.packageName.trim() : '';
|
|
79
|
-
if (!pkg) throw new Error('要给一个包名(例如 com.tencent.mm)才能查学过的路线。');
|
|
80
|
-
const intent = typeof args.intent === 'string' ? args.intent.trim() : '';
|
|
81
|
-
|
|
82
|
-
let found = null;
|
|
83
|
-
try {
|
|
84
|
-
found = routeStore.recall({ packageName: pkg, intentText: intent });
|
|
85
|
-
} catch {
|
|
86
|
-
found = null;
|
|
87
|
-
}
|
|
88
|
-
if (!found) {
|
|
89
|
-
return {
|
|
90
|
-
ok: true,
|
|
91
|
-
found: false,
|
|
92
|
-
steps: [],
|
|
93
|
-
note: '这个 App 里这件事还没有收下的路线。自己按当前屏想办法做;跑成一批之后会自动学成一条草稿,要用户在手机上的「学到的路线」里收下才会出现在这里。',
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const route = found.route;
|
|
98
|
-
const steps = route.steps.slice(0, MAX_RENDER_STEPS).map((step) => ({
|
|
99
|
-
index: step.i + 1,
|
|
100
|
-
action: step.action,
|
|
101
|
-
line: renderStep(step),
|
|
102
|
-
...(step.mustConfirmLive ? { mustConfirmLive: true } : {}),
|
|
103
|
-
}));
|
|
104
|
-
const value = { ok: true, found: true, name: found.name, steps };
|
|
105
|
-
if (steps.some((s) => s.mustConfirmLive)) {
|
|
106
|
-
value.note = '这条路线里有一步是付款 / 下单类:那一步必须单独做、当场让用户确认,不能并进批量。';
|
|
107
|
-
} else if (route.steps.length > MAX_RENDER_STEPS) {
|
|
108
|
-
value.note = `这条路线比这里露出来的长(共 ${route.steps.length} 步),后面几步先按当前屏自己判断。`;
|
|
109
|
-
}
|
|
110
|
-
return value;
|
|
111
|
-
},
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* `phone_skill_keep`:把一条学成的路线**收下**(或丢掉)。
|
|
118
|
-
*
|
|
119
|
-
* 学成之后一律先是待收下的草稿 —— 这是「学歪了不会被立刻用上」的保证。收下要人来点,
|
|
120
|
-
* 所以做成两步:先看清单,再按名字收下 / 丢掉,不按 id —— id 是随机串,用户看不见。
|
|
121
|
-
*/
|
|
122
|
-
function installSkillKeep(ctx) {
|
|
123
|
-
if (!ctx || typeof ctx.inject !== 'function') return;
|
|
124
|
-
let defineTool;
|
|
125
|
-
try {
|
|
126
|
-
({ defineTool } = require('@deepseek-ai/dsh-tools'));
|
|
127
|
-
} catch {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
ctx.inject(['tools'], (scoped) => {
|
|
132
|
-
if (!scoped || !scoped.tools || typeof scoped.tools.register !== 'function') return;
|
|
133
|
-
scoped.tools.register(defineTool({
|
|
134
|
-
name: 'phone_skill_keep',
|
|
135
|
-
description: 'List phone routes learned from past successful runs that are waiting for the user to accept them, or accept/discard one by name. Learning never takes effect on its own: a route stays a draft until accepted here, and only then can phone_skill_recall serve it. Listing and discarding are always safe; accepting is the one step that makes a learned route live, so do it only after the user says to keep that one.',
|
|
136
|
-
parameters: {
|
|
137
|
-
action: {
|
|
138
|
-
type: 'string',
|
|
139
|
-
description: 'list (default), accept, or discard.',
|
|
140
|
-
},
|
|
141
|
-
name: {
|
|
142
|
-
type: 'string',
|
|
143
|
-
description: 'Route name from the list, e.g. "phone-tencent-mm-ryysm9". Required for accept and discard.',
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
output: {
|
|
147
|
-
schema: {
|
|
148
|
-
type: 'object',
|
|
149
|
-
additionalProperties: false,
|
|
150
|
-
properties: {
|
|
151
|
-
ok: { type: 'boolean' },
|
|
152
|
-
routes: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
153
|
-
note: { type: 'string' },
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
render: (_args, value) => {
|
|
157
|
-
const rows = Array.isArray(value.routes) ? value.routes : [];
|
|
158
|
-
if (rows.length === 0) return [{ type: 'text', text: value.note || '现在没有等着收下的路线。' }];
|
|
159
|
-
const lines = [`${rows.length} 条学成、还没收下的路线:`];
|
|
160
|
-
for (const row of rows) lines.push(`- ${row.name}:${row.summary}`);
|
|
161
|
-
if (value.note) lines.push(value.note);
|
|
162
|
-
return [{ type: 'text', text: lines.join('\n') }];
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
execute: async (args) => {
|
|
166
|
-
const action = typeof args.action === 'string' && args.action.trim() ? args.action.trim().toLowerCase() : 'list';
|
|
167
|
-
if (action === 'list') {
|
|
168
|
-
const rows = listPending();
|
|
169
|
-
const value = { ok: true, routes: rows };
|
|
170
|
-
if (rows.length === 0) value.note = '现在没有等着收下的路线。跑成一批手机操作之后会自动学下来,等你确认。';
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
if (action !== 'accept' && action !== 'discard') {
|
|
174
|
-
throw new Error('action 只能是 list / accept / discard。');
|
|
175
|
-
}
|
|
176
|
-
const name = typeof args.name === 'string' ? args.name.trim() : '';
|
|
177
|
-
if (!name) throw new Error('要收下或丢掉哪一条?给名字(先用 list 看有哪些)。');
|
|
178
|
-
const target = listPending().find((row) => row.name === name);
|
|
179
|
-
if (!target) throw new Error(`没有叫「${name}」的待收下路线。先用 list 看现在有哪些。`);
|
|
180
|
-
const result = action === 'accept'
|
|
181
|
-
? routeStore.accept(target.id)
|
|
182
|
-
: (routeStore.discard(target.id) ? { ok: true } : { ok: false, problem: 'not_found' });
|
|
183
|
-
if (!result || result.ok !== true) {
|
|
184
|
-
const problem = (result && result.problem) || 'failed';
|
|
185
|
-
throw new Error(problem === 'sensitive'
|
|
186
|
-
? '这条路线里有像账号 / 卡号这类敏感内容,没有收下。'
|
|
187
|
-
: `这条路线没能${action === 'accept' ? '收下' : '丢掉'}(${problem})。`);
|
|
188
|
-
}
|
|
189
|
-
const left = listPending();
|
|
190
|
-
return {
|
|
191
|
-
ok: true,
|
|
192
|
-
routes: left,
|
|
193
|
-
note: action === 'accept'
|
|
194
|
-
? `收下了「${name}」,下次在同一个 App 里做同一件事时就能查到它。`
|
|
195
|
-
: `丢掉了「${name}」。`,
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
}));
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** 待收下的路线,压成「名字 + 一句话」。 */
|
|
203
|
-
function listPending() {
|
|
204
|
-
let rows = [];
|
|
205
|
-
try { rows = routeStore.pending(); } catch { rows = []; }
|
|
206
|
-
return rows.map((row) => ({
|
|
207
|
-
id: row.id,
|
|
208
|
-
name: row.name,
|
|
209
|
-
summary: routeStore.describeRoute(row.route) || '这条路线没有可读的步骤摘要',
|
|
210
|
-
}));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** 一步 → 一句能直接落成 phone_* 调用的话。 */function renderStep(step) {
|
|
214
|
-
const loc = step.locator || {};
|
|
215
|
-
const anchors = [];
|
|
216
|
-
if (loc.text) anchors.push(`文字「${loc.text}」`);
|
|
217
|
-
if (loc.role) anchors.push(`role ${loc.role}`);
|
|
218
|
-
if (loc.resourceId) anchors.push(`id ${loc.resourceId}`);
|
|
219
|
-
if (loc.relPos) anchors.push(`位置约 ${loc.relPos.x}% / ${loc.relPos.y}%`);
|
|
220
|
-
const bits = [`${step.i + 1}. ${step.action}`];
|
|
221
|
-
if (anchors.length > 0) bits.push(`:${anchors.join(',')}`);
|
|
222
|
-
const args = step.args || {};
|
|
223
|
-
if (typeof args.text === 'string') bits.push(`;输入 ${args.text}`);
|
|
224
|
-
if (typeof args.packageName === 'string' && step.action.startsWith('app.')) bits.push(`;包名 ${args.packageName}`);
|
|
225
|
-
if (typeof args.key === 'string') bits.push(`;按键 ${args.key}`);
|
|
226
|
-
if (typeof args.direction === 'string') bits.push(`;方向 ${args.direction}`);
|
|
227
|
-
if (step.until) bits.push(`;等 ${describeUntil(step.until)}`);
|
|
228
|
-
if (step.mustConfirmLive) bits.push(';付款类,单独一步并当场确认');
|
|
229
|
-
return bits.join('');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function describeUntil(until) {
|
|
233
|
-
const parts = [];
|
|
234
|
-
if (until.appears) parts.push(`出现「${until.appears}」`);
|
|
235
|
-
if (until.gone) parts.push(`「${until.gone}」消失`);
|
|
236
|
-
if (until.app) parts.push(`前台是 ${until.app}`);
|
|
237
|
-
if (until.stable === true) parts.push('界面稳定');
|
|
238
|
-
return parts.join(' + ') || '稍等';
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
module.exports = {
|
|
242
|
-
installSkillRecall,
|
|
243
|
-
installSkillKeep,
|
|
244
|
-
renderStep,
|
|
245
|
-
MAX_RENDER_STEPS,
|
|
246
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 学到的手机路线:在手机上**看草稿、收下、丢掉**(`GET/POST /api/mobile/v1/phone/skill/*`)。
|
|
5
|
-
*
|
|
6
|
-
* ## 为什么要这条路由
|
|
7
|
-
*
|
|
8
|
-
* `phone_skill_keep` 那个工具能做这三件事,但工具只能由模型在会话里调 —— 也就是说
|
|
9
|
-
* 「用户收下才知道能不能用」这条承诺的实际确认人一直是模型。用户手上没有出口,那这道
|
|
10
|
-
* 关卡就等于由 AI 自己盖章。这里把同一份 `route-store` 的读写接成一条人能点的路由。
|
|
11
|
-
*
|
|
12
|
-
* ## 与路由「/phone/*」那组的分工
|
|
13
|
-
*
|
|
14
|
-
* `phone/routes.js` 那三条是「这台电脑认识的手机、现在连着没有」这类**设备状态**;
|
|
15
|
-
* 这一条是**学到的内容**。分开放是因为它们的权限位不同:看草稿是只读(view),
|
|
16
|
-
* 收下会真的写进技能目录(files.write)。
|
|
17
|
-
*
|
|
18
|
-
* ## 收下 / 丢掉之后
|
|
19
|
-
*
|
|
20
|
-
* 收下 = `route-store.accept`,草稿落进技能目录,从那以后 `recall()` 才会把这条路线交给
|
|
21
|
-
* 模型;丢掉 = `route-store.discard`,草稿文件里删掉,不会「下次又冒出来」。两个动作都按
|
|
22
|
-
* 名字而不是 id 认目标 —— id 是随机串,用户看不见(与 `phone_skill_keep` 同一口径)。
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const { sendJson, readJsonBody } = require('../../shared/http-util');
|
|
26
|
-
const routeStore = require('../route-store.js');
|
|
27
|
-
|
|
28
|
-
/** 一条草稿压成界面上要的一行。 */
|
|
29
|
-
function rowOf(draft) {
|
|
30
|
-
const route = draft.route || {};
|
|
31
|
-
return {
|
|
32
|
-
id: draft.id,
|
|
33
|
-
name: draft.name,
|
|
34
|
-
summary: routeStore.describeRoute(route) || '',
|
|
35
|
-
packageName: (route.app && typeof route.app.package === 'string') ? route.app.package : '',
|
|
36
|
-
intent: (route.intent && typeof route.intent.raw === 'string') ? route.intent.raw : '',
|
|
37
|
-
stepCount: Array.isArray(route.steps) ? route.steps.length : 0,
|
|
38
|
-
createdAt: draft.createdAt || 0,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* GET /api/mobile/v1/phone/skill/routes(token)
|
|
44
|
-
* → { ok, routes: [...], accepted: N }
|
|
45
|
-
*
|
|
46
|
-
* 两半都回:`routes` 是等着收下的草稿(用户真正要处理的),`accepted` 是已收下的条数 ——
|
|
47
|
-
* 界面上要能回答「我现在一共攒了几条能用的」,那件事只能看技能目录。
|
|
48
|
-
*/
|
|
49
|
-
async function handleSkillRoutes(_ctx, _req, res) {
|
|
50
|
-
let drafts = [];
|
|
51
|
-
try { drafts = routeStore.pending(); } catch { drafts = []; }
|
|
52
|
-
let accepted = 0;
|
|
53
|
-
try { accepted = routeStore.scan().length; } catch { accepted = 0; }
|
|
54
|
-
sendJson(res, 200, { ok: true, routes: drafts.map(rowOf), accepted });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* POST /api/mobile/v1/phone/skill/keep(token){ name, action: 'accept' | 'discard' }
|
|
59
|
-
* → { ok, routes: [...], accepted: N }
|
|
60
|
-
*
|
|
61
|
-
* 按名字认目标:界面上显示的就是名字。收下会落进技能目录、从那以后进召回池;
|
|
62
|
-
* 丢掉只删草稿。两种都是幂等语义的正常失败(找不到就 404),不会把别的草稿带走。
|
|
63
|
-
*/
|
|
64
|
-
async function handleSkillKeep(_ctx, req, res) {
|
|
65
|
-
const body = await readJsonBody(req, 64 * 1024);
|
|
66
|
-
const action = body && typeof body.action === 'string' ? body.action.trim().toLowerCase() : '';
|
|
67
|
-
const name = body && typeof body.name === 'string' ? body.name.trim() : '';
|
|
68
|
-
if (action !== 'accept' && action !== 'discard') {
|
|
69
|
-
return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: "action 只能是 'accept' 或 'discard'" } });
|
|
70
|
-
}
|
|
71
|
-
if (!name) {
|
|
72
|
-
return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '需要 name(哪一条)' } });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let target = null;
|
|
76
|
-
try { target = routeStore.pending().find((row) => row.name === name) || null; } catch { target = null; }
|
|
77
|
-
if (!target) {
|
|
78
|
-
return sendJson(res, 404, { ok: false, error: { code: 'not-found', message: `没有叫「${name}」的待收下路线` } });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (action === 'accept') {
|
|
82
|
-
const result = routeStore.accept(target.id);
|
|
83
|
-
if (!result || result.ok !== true) {
|
|
84
|
-
const problem = (result && result.problem) || 'failed';
|
|
85
|
-
return sendJson(res, problem === 'sensitive' ? 400 : 409, {
|
|
86
|
-
ok: false,
|
|
87
|
-
error: {
|
|
88
|
-
code: problem === 'sensitive' ? 'sensitive' : 'accept-failed',
|
|
89
|
-
message: problem === 'sensitive'
|
|
90
|
-
? '这条路线里有像账号 / 卡号这类敏感内容,没有收下。'
|
|
91
|
-
: `这条路线没能收下(${problem})。`,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} else if (!routeStore.discard(target.id)) {
|
|
96
|
-
return sendJson(res, 409, { ok: false, error: { code: 'discard-failed', message: '这条路线没能丢掉,请再试一次' } });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let routes = [];
|
|
100
|
-
try { routes = routeStore.pending(); } catch { routes = []; }
|
|
101
|
-
let accepted = 0;
|
|
102
|
-
try { accepted = routeStore.scan().length; } catch { accepted = 0; }
|
|
103
|
-
sendJson(res, 200, { ok: true, action, name, routes: routes.map(rowOf), accepted });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = { handleSkillRoutes, handleSkillKeep };
|