dsh-mobile-plugin 0.5.122 → 0.5.124
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/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +2 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/frp.md +17 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ont-gateway.md +43 -0
- package/lib/impl.js +2 -1
- package/lib/jdxb/probe.cjs +16 -7
- package/lib/mobile/device-profile.js +355 -0
- package/lib/mobile/events.js +26 -0
- package/lib/mobile/feedback.js +16 -0
- package/lib/mobile/local-images.js +213 -30
- package/lib/mobile/permissions.js +9 -0
- package/lib/mobile/session-cache.js +20 -1
- package/lib/panel/index.html +26 -26
- package/lib/routes/mobile-api.js +86 -0
- package/lib/zeronews/runner.cjs +41 -1
- package/lib/zeronews/wiring.cjs +25 -4
- package/package.json +15 -14
|
@@ -23,11 +23,19 @@
|
|
|
23
23
|
* - 只认 png/jpg/jpeg/webp/gif,并核对魔术字节,不按扩展名撒谎;
|
|
24
24
|
* - 宽高只读文件头(最多 64KB);读不出来就不带宽高,App 那边照旧现量;
|
|
25
25
|
* - 围栏代码块与行内代码里的图片语法不碰,那是写法示例。
|
|
26
|
+
*
|
|
27
|
+
* 字节要落在持久目录(2026-11-26 修):原图常在临时目录,第一台手机正看着的时候还在,另一台
|
|
28
|
+
* 重新投影会话时已经被清掉 —— 那时连编号都换不出来,正文就露 `` 源码。登记时把
|
|
29
|
+
* 字节复制到 `~/.dsh/storages/mobile-plugin/local-images/`,并记住「原路径 → 编号」;插件重启后
|
|
30
|
+
* 按编号从副本重建登记项,老会话里的编号也不会失效。取图口仍只认编号,不认请求里的路径。
|
|
31
|
+
* 副本按总量上限回收最旧的那几张;复制不成功就不发编号,宁可留字面 markdown 也不留死链。
|
|
26
32
|
*/
|
|
27
33
|
const fs = require('node:fs/promises');
|
|
34
|
+
const fsSync = require('node:fs');
|
|
28
35
|
const os = require('node:os');
|
|
29
36
|
const path = require('node:path');
|
|
30
37
|
const crypto = require('node:crypto');
|
|
38
|
+
const { dshHome } = require('../shared/paths.js');
|
|
31
39
|
|
|
32
40
|
/**
|
|
33
41
|
* ``。dest 两种写法都认:裸路径(不含空白与右括号)与 `<>` 包裹(里面可以有空格,
|
|
@@ -52,15 +60,78 @@ const MAX_IMAGE_BYTES = 2.5 * 1024 * 1024;
|
|
|
52
60
|
const HEAD_BYTES = 64 * 1024;
|
|
53
61
|
/** 登记表上限:翻历史时同一张图反复出现也只登记一次,512 条够一两百个会话轮着用。 */
|
|
54
62
|
const MAX_REGISTRY_ENTRIES = 512;
|
|
63
|
+
/** 持久副本总量上限:老会话要留,但也不能让这台电脑的缓存无限涨。 */
|
|
64
|
+
const MAX_STORED_BYTES = 128 * 1024 * 1024;
|
|
55
65
|
/** 一张响应(一页历史 / 一帧 SSE / 一次镜像快照)里最多换几张:防一段文字里几十上百个图片语法。 */
|
|
56
66
|
const MAX_TEXT_IMAGES = 64;
|
|
57
67
|
|
|
68
|
+
/** 编号 → { filePath, mediaType, width?, height? }。 */
|
|
69
|
+
const registry = new Map();
|
|
58
70
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* 只由本模块登记,取图口只认这里面的编号 —— 这是「不扩能力面」的全部依据(见文件头)。
|
|
71
|
+
* 原图目的地 → 编号。原图被清掉之后,同一段 markdown 重新投影仍要拿回同一个编号,
|
|
72
|
+
* 否则手机只能收到 `` 并把源码铺在正文里。
|
|
62
73
|
*/
|
|
63
|
-
const
|
|
74
|
+
const pathIndex = new Map();
|
|
75
|
+
|
|
76
|
+
/** 持久副本目录(与收件箱、技能同在 DSH_HOME 下的插件存储里)。 */
|
|
77
|
+
function imageStoreDir() {
|
|
78
|
+
return path.join(dshHome(), 'storages', 'mobile-plugin', 'local-images');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const INDEX_FILE = 'index.json';
|
|
82
|
+
/** 编号只可能是我们自己生成的 16 位十六进制;取图口按这个形状挡住目录穿越。 */
|
|
83
|
+
const ID_RE = /^[a-f0-9]{16}$/i;
|
|
84
|
+
|
|
85
|
+
/** 从持久索引恢复登记表(插件重启后内存表是空的)。读不到就按空表起手。 */
|
|
86
|
+
function loadIndex() {
|
|
87
|
+
try {
|
|
88
|
+
const data = JSON.parse(fsSync.readFileSync(path.join(imageStoreDir(), INDEX_FILE), 'utf8'));
|
|
89
|
+
if (!data || data.version !== 1 || !data.entries || !data.paths) return;
|
|
90
|
+
for (const [id, entry] of Object.entries(data.entries)) {
|
|
91
|
+
if (ID_RE.test(id) && entry && typeof entry.mediaType === 'string') registry.set(id, entry);
|
|
92
|
+
}
|
|
93
|
+
for (const [destination, id] of Object.entries(data.paths)) {
|
|
94
|
+
if (ID_RE.test(id) && registry.has(id)) pathIndex.set(destination, id);
|
|
95
|
+
}
|
|
96
|
+
} catch { /* 没有索引 / 索引坏了:这一轮按空表走,老图退回字面 markdown。 */ }
|
|
97
|
+
}
|
|
98
|
+
loadIndex();
|
|
99
|
+
|
|
100
|
+
let saveSequence = 0;
|
|
101
|
+
let indexWriting = Promise.resolve();
|
|
102
|
+
/** 索引很小(上限 512 条),整体重写;排队写避免同一页并发内联时互相覆盖。 */
|
|
103
|
+
function saveIndex() {
|
|
104
|
+
const payload = JSON.stringify({
|
|
105
|
+
version: 1,
|
|
106
|
+
entries: Object.fromEntries(registry),
|
|
107
|
+
paths: Object.fromEntries(pathIndex),
|
|
108
|
+
});
|
|
109
|
+
const file = path.join(imageStoreDir(), INDEX_FILE);
|
|
110
|
+
const tmp = `${file}.${process.pid}.${++saveSequence}.tmp`;
|
|
111
|
+
indexWriting = indexWriting
|
|
112
|
+
.then(() => fs.mkdir(imageStoreDir(), { recursive: true }))
|
|
113
|
+
.then(() => fs.writeFile(tmp, payload, 'utf8'))
|
|
114
|
+
.then(() => fs.rename(tmp, file))
|
|
115
|
+
.catch(() => { /* 索引写不进去只影响重启后的恢复,本轮投影照常。 */ });
|
|
116
|
+
return indexWriting;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 同步读文件头:给 `localImageOf` 在重启后重建登记项用。 */
|
|
120
|
+
function headSyncOf(file) {
|
|
121
|
+
let fd;
|
|
122
|
+
try {
|
|
123
|
+
fd = fsSync.openSync(file, 'r');
|
|
124
|
+
const size = fsSync.fstatSync(fd).size;
|
|
125
|
+
if (!size) return null;
|
|
126
|
+
const buf = Buffer.alloc(Math.min(size, HEAD_BYTES));
|
|
127
|
+
fsSync.readSync(fd, buf, 0, buf.length, 0);
|
|
128
|
+
return buf;
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
} finally {
|
|
132
|
+
if (fd !== undefined) fsSync.closeSync(fd);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
64
135
|
|
|
65
136
|
function mediaTypeFor(filePath) {
|
|
66
137
|
return MEDIA_TYPES[path.extname(filePath).toLowerCase()] || null;
|
|
@@ -249,6 +320,42 @@ async function readHead(filePath, size) {
|
|
|
249
320
|
}
|
|
250
321
|
}
|
|
251
322
|
|
|
323
|
+
/** 持久副本的扩展名:与 App 侧按编号找缓存文件的那四种一致。 */
|
|
324
|
+
function extensionOf(mediaType) {
|
|
325
|
+
return mediaType === 'image/jpeg' ? '.jpg'
|
|
326
|
+
: mediaType === 'image/gif' ? '.gif'
|
|
327
|
+
: mediaType === 'image/webp' ? '.webp' : '.png';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 副本超过总量上限时回收最旧的那几张。新登记的那张(keepId)一定留着,
|
|
332
|
+
* 被回收的编号同时撤掉登记与路径映射 —— 下次投影会照常重新登记,不会发死编号。
|
|
333
|
+
*/
|
|
334
|
+
async function trimStoredFiles(keepId) {
|
|
335
|
+
const dir = imageStoreDir();
|
|
336
|
+
let names;
|
|
337
|
+
try { names = await fs.readdir(dir); } catch { return; }
|
|
338
|
+
let bytes = 0;
|
|
339
|
+
const files = [];
|
|
340
|
+
for (const name of names) {
|
|
341
|
+
const id = path.parse(name).name;
|
|
342
|
+
if (!ID_RE.test(id) || id === keepId) continue;
|
|
343
|
+
try {
|
|
344
|
+
const stat = await fs.stat(path.join(dir, name));
|
|
345
|
+
bytes += stat.size;
|
|
346
|
+
files.push({ id, name, at: stat.mtimeMs, size: stat.size });
|
|
347
|
+
} catch { /* 半截文件 / 正在写的索引不算 */ }
|
|
348
|
+
}
|
|
349
|
+
files.sort((a, b) => a.at - b.at);
|
|
350
|
+
for (const file of files) {
|
|
351
|
+
if (bytes <= MAX_STORED_BYTES) break;
|
|
352
|
+
await fs.unlink(path.join(dir, file.name)).catch(() => {});
|
|
353
|
+
registry.delete(file.id);
|
|
354
|
+
for (const [destination, id] of pathIndex) if (id === file.id) pathIndex.delete(destination);
|
|
355
|
+
bytes -= file.size;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
252
359
|
/**
|
|
253
360
|
* 登记一张本机图片,返回它的编号与宽高。
|
|
254
361
|
*
|
|
@@ -259,17 +366,31 @@ async function readHead(filePath, size) {
|
|
|
259
366
|
* markdown,用户在手机上看到的是一串 `` 源码 —— 既不知道发生过什么,也没有任何
|
|
260
367
|
* 入口。标了之后取图口如实回 413,App 画成「图片太大」的占位块,这才是用户能读懂的一句话。
|
|
261
368
|
*/
|
|
262
|
-
async function registerLocalImage(filePath) {
|
|
369
|
+
async function registerLocalImage(filePath, destination = '') {
|
|
263
370
|
let stat;
|
|
264
371
|
try {
|
|
265
372
|
stat = await fs.stat(filePath);
|
|
266
373
|
} catch {
|
|
267
|
-
|
|
374
|
+
// 原图已经不在(临时目录被清):同一路径以前登记过就继续用那个编号,
|
|
375
|
+
// 字节取的是我们自己的持久副本 —— 另一台设备重新打开会话时走的就是这条路。
|
|
376
|
+
const knownId = pathIndex.get(filePath) || (destination && pathIndex.get(destination));
|
|
377
|
+
const known = knownId ? registry.get(knownId) : null;
|
|
378
|
+
if (known && destination) {
|
|
379
|
+
pathIndex.set(destination, knownId);
|
|
380
|
+
await saveIndex();
|
|
381
|
+
}
|
|
382
|
+
return known ? { id: knownId, ...known } : null;
|
|
268
383
|
}
|
|
269
384
|
if (!stat.isFile() || stat.size <= 0) return null;
|
|
270
385
|
const id = crypto.createHash('sha1').update(`${filePath}:${stat.size}:${stat.mtimeMs}`).digest('hex').slice(0, 16);
|
|
271
386
|
const known = registry.get(id);
|
|
272
|
-
if (known)
|
|
387
|
+
if (known) {
|
|
388
|
+
if (destination) {
|
|
389
|
+
pathIndex.set(destination, id);
|
|
390
|
+
await saveIndex();
|
|
391
|
+
}
|
|
392
|
+
return { id, ...known };
|
|
393
|
+
}
|
|
273
394
|
const head = await readHead(filePath, stat.size);
|
|
274
395
|
if (!head) return null;
|
|
275
396
|
const mediaType = sniffMediaType(head);
|
|
@@ -280,34 +401,78 @@ async function registerLocalImage(filePath) {
|
|
|
280
401
|
&& parsed.width <= 30000 && parsed.height <= 30000;
|
|
281
402
|
const size = sane ? parsed : {};
|
|
282
403
|
const entry = { filePath, mediaType, ...size, ...(over ? { tooLarge: true } : {}) };
|
|
404
|
+
if (!over) {
|
|
405
|
+
// 副本必须落稳才发编号:留一个指向临时路径的编号,文件被清后那一格会永远失败。
|
|
406
|
+
const dest = path.join(imageStoreDir(), `${id}${extensionOf(mediaType)}`);
|
|
407
|
+
try {
|
|
408
|
+
await fs.mkdir(imageStoreDir(), { recursive: true });
|
|
409
|
+
await fs.copyFile(filePath, dest);
|
|
410
|
+
entry.filePath = dest;
|
|
411
|
+
await trimStoredFiles(id);
|
|
412
|
+
} catch {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
283
416
|
registry.set(id, entry);
|
|
417
|
+
pathIndex.set(filePath, id);
|
|
418
|
+
if (destination) pathIndex.set(destination, id);
|
|
284
419
|
trimRegistry();
|
|
420
|
+
await saveIndex();
|
|
285
421
|
return { id, ...entry };
|
|
286
422
|
}
|
|
287
423
|
|
|
288
|
-
/**
|
|
424
|
+
/**
|
|
425
|
+
* 登记表满了就淘汰最老的一条。**持久副本不删**:老会话里的编号还要靠它取回字节
|
|
426
|
+
* (另一台手机上没有缓存,删了就真的取不到了)。
|
|
427
|
+
*/
|
|
289
428
|
function trimRegistry() {
|
|
429
|
+
let dropped = false;
|
|
290
430
|
while (registry.size > MAX_REGISTRY_ENTRIES) {
|
|
291
431
|
const oldestId = registry.keys().next().value;
|
|
292
|
-
const entry = registry.get(oldestId);
|
|
293
432
|
registry.delete(oldestId);
|
|
294
|
-
|
|
433
|
+
for (const [destination, id] of pathIndex) if (id === oldestId) pathIndex.delete(destination);
|
|
434
|
+
dropped = true;
|
|
295
435
|
}
|
|
436
|
+
if (dropped) void saveIndex();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** 目的地字符串归一:尖括号与首尾空白不参与「原路径 → 编号」的查找。 */
|
|
440
|
+
function destinationKey(raw) {
|
|
441
|
+
if (typeof raw !== 'string') return '';
|
|
442
|
+
let value = raw.trim();
|
|
443
|
+
if (value.startsWith('<') && value.endsWith('>')) value = value.slice(1, -1).trim();
|
|
444
|
+
return value;
|
|
296
445
|
}
|
|
297
446
|
|
|
298
447
|
/** 取图口用:只认登记表里的编号(构造不出来的编号一律 null → 404)。 */
|
|
299
448
|
function localImageOf(id) {
|
|
300
|
-
if (typeof id !== 'string' || !id) return null;
|
|
301
|
-
|
|
449
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) return null;
|
|
450
|
+
const hit = registry.get(id);
|
|
451
|
+
if (hit) return hit;
|
|
452
|
+
// 插件重启:内存表空了,但字节和索引都在持久目录里。按编号找回自己写过的那份。
|
|
453
|
+
for (const ext of ['png', 'jpg', 'webp', 'gif']) {
|
|
454
|
+
const file = path.join(imageStoreDir(), `${id}.${ext}`);
|
|
455
|
+
const head = headSyncOf(file);
|
|
456
|
+
if (!head) continue;
|
|
457
|
+
const mediaType = sniffMediaType(head);
|
|
458
|
+
if (!mediaType) continue;
|
|
459
|
+
const parsed = imageSizeOf(head);
|
|
460
|
+
const sane = parsed && parsed.width > 0 && parsed.height > 0
|
|
461
|
+
&& parsed.width <= 30000 && parsed.height <= 30000;
|
|
462
|
+
const entry = { filePath: file, mediaType, ...(sane ? parsed : {}) };
|
|
463
|
+
registry.set(id, entry);
|
|
464
|
+
void saveIndex();
|
|
465
|
+
return entry;
|
|
466
|
+
}
|
|
467
|
+
return null;
|
|
302
468
|
}
|
|
303
469
|
|
|
304
|
-
/**
|
|
470
|
+
/** 清空登记表与持久副本(只在测试里调用,用例之间不串味)。 */
|
|
305
471
|
function clearLocalImages() {
|
|
306
|
-
for (const entry of registry.values()) {
|
|
307
|
-
if (entry && entry.fetched && entry.filePath) fs.unlink(entry.filePath).catch(() => {});
|
|
308
|
-
}
|
|
309
472
|
registry.clear();
|
|
473
|
+
pathIndex.clear();
|
|
310
474
|
loopbackUrlCache.clear();
|
|
475
|
+
fsSync.rmSync(imageStoreDir(), { recursive: true, force: true });
|
|
311
476
|
}
|
|
312
477
|
|
|
313
478
|
/**
|
|
@@ -347,16 +512,22 @@ function loopbackImageUrlOf(url) {
|
|
|
347
512
|
}
|
|
348
513
|
|
|
349
514
|
/**
|
|
350
|
-
*
|
|
515
|
+
* 取回的图片字节落成持久副本再登记:取图口按编号读 `filePath`,与磁盘上的图同一条路。
|
|
351
516
|
*
|
|
352
517
|
* 编号取内容哈希:同一张图反复出现只落一份。超过单张上限的照样登记、但标 `tooLarge`
|
|
353
518
|
* (取图口回 413,App 画「图片太大」占位),与磁盘图片那条口径一致。
|
|
354
519
|
*/
|
|
355
|
-
async function registerLocalImageBytes(buffer, mediaType) {
|
|
520
|
+
async function registerLocalImageBytes(buffer, mediaType, source = '') {
|
|
356
521
|
if (!buffer || buffer.length === 0) return null;
|
|
357
522
|
const id = crypto.createHash('sha1').update(buffer).digest('hex').slice(0, 16);
|
|
358
523
|
const known = registry.get(id);
|
|
359
|
-
if (known)
|
|
524
|
+
if (known) {
|
|
525
|
+
if (source) {
|
|
526
|
+
pathIndex.set(source, id);
|
|
527
|
+
await saveIndex();
|
|
528
|
+
}
|
|
529
|
+
return { id, ...known };
|
|
530
|
+
}
|
|
360
531
|
const over = buffer.length > MAX_IMAGE_BYTES;
|
|
361
532
|
const parsed = over ? null : imageSizeOf(buffer);
|
|
362
533
|
const sane = parsed && parsed.width > 0 && parsed.height > 0
|
|
@@ -365,24 +536,27 @@ async function registerLocalImageBytes(buffer, mediaType) {
|
|
|
365
536
|
if (over) {
|
|
366
537
|
const entry = { filePath: '', mediaType, ...size, tooLarge: true, fetched: true };
|
|
367
538
|
registry.set(id, entry);
|
|
539
|
+
if (source) pathIndex.set(source, id);
|
|
368
540
|
trimRegistry();
|
|
541
|
+
await saveIndex();
|
|
369
542
|
return { id, ...entry };
|
|
370
543
|
}
|
|
371
|
-
const ext = mediaType
|
|
372
|
-
: mediaType === 'image/gif' ? '.gif'
|
|
373
|
-
: mediaType === 'image/webp' ? '.webp' : '.png';
|
|
544
|
+
const ext = extensionOf(mediaType);
|
|
374
545
|
let filePath;
|
|
375
546
|
try {
|
|
376
|
-
const dir =
|
|
547
|
+
const dir = imageStoreDir();
|
|
377
548
|
await fs.mkdir(dir, { recursive: true });
|
|
378
549
|
filePath = path.join(dir, `${id}${ext}`);
|
|
379
550
|
await fs.writeFile(filePath, buffer);
|
|
551
|
+
await trimStoredFiles(id);
|
|
380
552
|
} catch {
|
|
381
553
|
return null;
|
|
382
554
|
}
|
|
383
555
|
const entry = { filePath, mediaType, ...size, fetched: true };
|
|
384
556
|
registry.set(id, entry);
|
|
557
|
+
if (source) pathIndex.set(source, id);
|
|
385
558
|
trimRegistry();
|
|
559
|
+
await saveIndex();
|
|
386
560
|
return { id, ...entry };
|
|
387
561
|
}
|
|
388
562
|
|
|
@@ -422,7 +596,7 @@ async function fetchLoopbackImage(url) {
|
|
|
422
596
|
loopbackUrlCache.set(url, { failedAt: Date.now() });
|
|
423
597
|
return null;
|
|
424
598
|
}
|
|
425
|
-
const entry = await registerLocalImageBytes(buffer, mediaType);
|
|
599
|
+
const entry = await registerLocalImageBytes(buffer, mediaType, url);
|
|
426
600
|
if (!entry) {
|
|
427
601
|
loopbackUrlCache.set(url, { failedAt: Date.now() });
|
|
428
602
|
return null;
|
|
@@ -528,13 +702,22 @@ async function inlineTextImages(text, budget) {
|
|
|
528
702
|
let entry = null;
|
|
529
703
|
const filePath = localImagePathOf(m[2], pool.cwd);
|
|
530
704
|
if (filePath) {
|
|
531
|
-
|
|
705
|
+
// 一并记住正文里原本的写法:相对地址按工作区解开后是绝对路径,但另一台设备
|
|
706
|
+
// 可能查不到工作区目录,那时只能靠这个原始写法找回同一编号。
|
|
707
|
+
entry = await registerLocalImage(filePath, destinationKey(m[2]));
|
|
532
708
|
} else {
|
|
533
|
-
//
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
709
|
+
// 回环地址以前取回过的图:插件重启、那台小服务也关了,仍按同一编号给手机。
|
|
710
|
+
const knownId = pathIndex.get(destinationKey(m[2]));
|
|
711
|
+
const known = knownId ? registry.get(knownId) : null;
|
|
712
|
+
if (known) {
|
|
713
|
+
entry = { id: knownId, ...known };
|
|
714
|
+
} else {
|
|
715
|
+
// 第二种「本机图片」:生图插件把成品图挂在自己电脑的一个回环小服务上,回的是
|
|
716
|
+
// `http://127.0.0.1:<端口>/…`。手机拿着它只会指回手机自己,所以由电脑去取回来、
|
|
717
|
+
// 按编号给手机(与磁盘图片同一条路,宽高/缓存/重试全现成)。
|
|
718
|
+
const loopbackUrl = loopbackImageUrlOf(m[2]);
|
|
719
|
+
if (loopbackUrl) entry = await fetchLoopbackImage(loopbackUrl);
|
|
720
|
+
}
|
|
538
721
|
}
|
|
539
722
|
if (!entry) continue;
|
|
540
723
|
count -= 1;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 2026-11-26:画像 / 学习开关五条路由登记权限档,读归 view,写与归纳归 config。
|
|
1
2
|
// 升级权限优先使用本次已认证记录,身份轮换后不回查过期实例快照。
|
|
2
3
|
'use strict';
|
|
3
4
|
|
|
@@ -431,6 +432,14 @@ const MAP = Object.freeze({
|
|
|
431
432
|
'/api/mobile/v1/agent-presets/remove': V.CONFIG,
|
|
432
433
|
'/api/mobile/v1/agent-presets/default': V.CONFIG,
|
|
433
434
|
'/api/mobile/v1/magpie/web': V.CONFIG,
|
|
435
|
+
|
|
436
|
+
// ── 学习画像与开关(契约 B 块):读画像 / 读开关归 view;刷新画像、写开关与归纳归 config。
|
|
437
|
+
// study 会花电脑侧渠道的额度,按「花额度的 config」与 channels/chat 同档,不放给只读设备。
|
|
438
|
+
'/api/mobile/v1/device-profile': V.VIEW,
|
|
439
|
+
'/api/mobile/v1/device-profile/refresh': V.CONFIG,
|
|
440
|
+
'/api/mobile/v1/device-profile/study': V.CONFIG,
|
|
441
|
+
// 同路径按方法分读写:GET 看当前开关、POST 写开关(宿主注册器不分方法)。
|
|
442
|
+
'/api/mobile/v1/learning-switches': { GET: V.VIEW, POST: V.CONFIG },
|
|
434
443
|
});
|
|
435
444
|
|
|
436
445
|
const BASE_SET = new Set(BASE);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* 会话侧的按 ctx
|
|
6
|
+
* 会话侧的按 ctx 隔离状态:二十一张表,一个入口。
|
|
7
7
|
*
|
|
8
8
|
* 这些表此前全是 sessions.js 的模块级 WeakMap。它们之所以必须按 ctx 隔离,是因为
|
|
9
9
|
* 它们的值属于**宿主进程状态**(某个会话正在跑、某个列表刚构建完、某条发送已经
|
|
@@ -76,6 +76,10 @@ const workflowLiveStates = new WeakMap();
|
|
|
76
76
|
// 收尾那一发挂在会话列表刷新上,是热点路径 —— 每台宿主各一份,不能跨 ctx 串。
|
|
77
77
|
const isolationSweepStates = new WeakMap();
|
|
78
78
|
|
|
79
|
+
// 学习画像的变化检测节流(见 device-profile.js):上次重算的时刻与在途那一次。
|
|
80
|
+
// 它挂在会话 / 工作区清单帧上,每台宿主各算各的 —— 串了就是「A 宿主算过,B 宿主这一轮直接跳过」。
|
|
81
|
+
const deviceProfileRefreshStates = new WeakMap();
|
|
82
|
+
|
|
79
83
|
// 交付声明补格的账(见 presented-file-stats.js):这一台宿主上「`deriveMessages` 交回来的
|
|
80
84
|
// 数组 → 那次补齐的结果(可能还在飞)」。**下面那层按数组引用认**:派生缓存对同一份输入交回
|
|
81
85
|
// 的就是同一个数组,于是「同指纹第二次调用」连 stat 都不用发;换一份输入就是新数组,自然重算。
|
|
@@ -313,6 +317,20 @@ function isolationSweepStateOf(ctx) {
|
|
|
313
317
|
return state;
|
|
314
318
|
}
|
|
315
319
|
|
|
320
|
+
/**
|
|
321
|
+
* 学习画像变化检测的节流状态:`{ lastAt, inFlight }`。
|
|
322
|
+
*
|
|
323
|
+
* 与其它访问器同一口径 —— 保证返回的一定是给这个 ctx 建好的那个对象,调用方拿到直接用。
|
|
324
|
+
*/
|
|
325
|
+
function deviceProfileRefreshStateOf(ctx) {
|
|
326
|
+
let state = deviceProfileRefreshStates.get(ctx);
|
|
327
|
+
if (!state) {
|
|
328
|
+
state = { lastAt: 0, inFlight: null };
|
|
329
|
+
deviceProfileRefreshStates.set(ctx, state);
|
|
330
|
+
}
|
|
331
|
+
return state;
|
|
332
|
+
}
|
|
333
|
+
|
|
316
334
|
/**
|
|
317
335
|
* 交付声明补格的账:这一台宿主上「`deriveMessages` 交回来的数组 → 那次补齐的结果
|
|
318
336
|
* (可能还在飞的 promise)」。
|
|
@@ -553,6 +571,7 @@ module.exports = {
|
|
|
553
571
|
workspaceShortcutStateOf,
|
|
554
572
|
autoContinueTurnsOf,
|
|
555
573
|
isolationSweepStateOf,
|
|
574
|
+
deviceProfileRefreshStateOf,
|
|
556
575
|
presentedFileStatsOf,
|
|
557
576
|
rememberPresentedFileStats,
|
|
558
577
|
forgetPresentedFileStats,
|