dsh-mobile-plugin 0.5.68 → 0.5.70
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/docs/extension-authoring.md +28 -3
- package/dsh-mobile-credentials/lib/credentials.js +49 -1
- package/extension-registry/README.md +81 -0
- package/extension-registry/index.json +69 -0
- package/lib/impl.js +15 -0
- package/lib/mobile/feedback.js +277 -0
- package/lib/mobile/plugin-catalog.js +73 -24
- package/lib/panel/index.html +68 -8
- package/lib/relay/core.js +51 -0
- package/lib/routes/control-plane.js +23 -1
- package/lib/routes/mobile-api.js +7 -1
- package/lib/shared/device-headers.js +18 -1
- package/package.json +2 -1
|
@@ -824,9 +824,8 @@ body {
|
|
|
824
824
|
|
|
825
825
|
- `manifest.json` 是你写的自述(能力、版本、入口、`hostData`);逐文件的 `size` 与
|
|
826
826
|
`sha256` 由宿主扫目录现算,不是你填的,别混。
|
|
827
|
-
- 官方扩展(Office
|
|
828
|
-
|
|
829
|
-
也不用和它对齐版本。
|
|
827
|
+
- 官方扩展(Office 预览)走 APP 分发系统那条路(`platform = extension`);你自己发插件走的是
|
|
828
|
+
第 8 节那条「插件装到用户电脑上、手机现扫」的路。两条互不影响,你不用和它对齐版本。
|
|
830
829
|
- 作者自己写、自己在手机上边改边看的那条调试路(第 9 节)与发布是两回事:那条走电脑上的
|
|
831
830
|
本地目录,不经过插件包,也不带声明。
|
|
832
831
|
|
|
@@ -858,6 +857,32 @@ body {
|
|
|
858
857
|
> 做样板:`docs/extension-sample/` 那份就是能直接装的最小扩展,先把它跑起来,再照第 8 节
|
|
859
858
|
> 那三步把它搬进你自己的插件包里。
|
|
860
859
|
|
|
860
|
+
## 8.6 上扩展市场:投稿规范
|
|
861
|
+
|
|
862
|
+
上一节那条「自己发插件、用户自己装」是扩展触达用户的默认路子,**不经过任何审核、也不用登记**。
|
|
863
|
+
在这一条之外,我们另有一个**扩展市场**(App 设置 → 扩展 → 「+」那一页):它是一份随
|
|
864
|
+
`dsh-mobile-plugin` 发布的精选清单,用户不用先装你的插件就能在里面看到你的扩展、一键装到电脑上。
|
|
865
|
+
想进这个市场,按下面给公开仓 `WNLUO/dsh-mobile-plugin` 提一个 PR;**不投也能用**——第 8 节那条路
|
|
866
|
+
照常把扩展送到装了你插件的用户手机上。
|
|
867
|
+
|
|
868
|
+
投稿是在 `extension-registry/entries/` 加一个 `<owner>__<repo>.json` 文件(一个插件一个文件,
|
|
869
|
+
提 PR)。三条硬规范,缺一条构建就不过:
|
|
870
|
+
|
|
871
|
+
1. **`name` 写这个插件的 npm 包名**(合法 npm 名,形如 `dsh-xxx` 或 `@scope/xxx`)。它是身份、
|
|
872
|
+
不是给人看的标题;显示名写在 `title`。若填 `npm` 字段必须与 `name` 一致,只写 `name` 最省事。
|
|
873
|
+
2. **`title` 和 `description` 必须齐 App 的 11 门语言**:`zh-Hans`、`zh-Hant`、`en`、`ja`、`ko`、
|
|
874
|
+
`de`、`es`、`fr`、`pt`、`ru`、`tr`。用户用哪门语言就显示哪门,少一门那门用户只能看到回退的
|
|
875
|
+
英文。建议用机器翻译生成,再把数字、命令、API 名核对一遍别被改坏;标签务必是 `zh-Hans` /
|
|
876
|
+
`zh-Hant`(不是 `zh` / `zh-TW`),多一门少一门都不行。
|
|
877
|
+
3. **`repo` 写 GitHub 地址,`owner` 与之相符**。仓库要真实、未归档,包里声明了 `dsh.bundle` 或
|
|
878
|
+
`dshMobileExtensions`(只收带手机扩展的 DSH 插件)。
|
|
879
|
+
|
|
880
|
+
`icon` 可选:贴你仓库里一张图片的 https raw 地址(注意用对默认分支),不贴就显示名字首字母。
|
|
881
|
+
没有上传流程,图放进仓库、贴地址即可。其余可选字段与完整样例见该仓 `extension-registry/README.md`。
|
|
882
|
+
|
|
883
|
+
收录要等一次 `dsh-mobile-plugin` 发版才到用户手里(清单随插件包发);合并前维护者会读一遍源码,
|
|
884
|
+
描述写了数字或 API 名的会对着代码核 —— 夸大是被打回的主要原因。
|
|
885
|
+
|
|
861
886
|
## 9. 调试
|
|
862
887
|
|
|
863
888
|
改一次就发一版太慢。手机这边有一条不走发布的路:**把包放在电脑上,手机上直接装进来。**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
// 安装包身份(包名 / 构建号 / 渠道)随设备记录存下,AI 反馈提交要从这里取(2026-11-18)。
|
|
2
3
|
// 有效设备记录保留本地重新发现能力,未知设备禁止自动换入口。
|
|
3
4
|
// 电脑网页授权独立于手机权限;调整设备权限会同步收回该授权。
|
|
4
5
|
|
|
@@ -21,6 +22,12 @@
|
|
|
21
22
|
* 设备清单(`listDevices`)只画还活着的;已解绑的那部分由 `listHistory` 聚合出来。
|
|
22
23
|
* 两份是同一趟扫描的两半(`scanDevices`):键与「取最新有值」的口径只写一份,路由要两份时
|
|
23
24
|
* 也只扫一遍。历史那半与清理共用同一个保留窗口,纯读、不写盘。
|
|
25
|
+
*
|
|
26
|
+
* `clearHistory` 是面板「一键清空历史」的落点:只删本实例**已结束**的手机记录,活着的凭据
|
|
27
|
+
* 与电脑网页授权一条不碰(同一个 deviceId 解绑后又重配的,旧记录删掉、新记录留着)。它比
|
|
28
|
+
* `prune` 更彻底——一次把所有已结束的都清掉,包括超出窗口、原本要等下次写入才被 prune 的
|
|
29
|
+
* 残余;两者都不轮换密钥、不影响任何还能用的通行证。只读副本拒绝,与 `revoke` 同理:清了
|
|
30
|
+
* 不落盘、下次重载复活。
|
|
24
31
|
*/
|
|
25
32
|
const crypto = require('node:crypto');
|
|
26
33
|
const fs = require('node:fs');
|
|
@@ -151,6 +158,14 @@ function deviceMeta(device) {
|
|
|
151
158
|
if (osVersion) meta.osVersion = osVersion;
|
|
152
159
|
const appVersion = truncate(device?.appVersion, FIELD_MAX);
|
|
153
160
|
if (appVersion) meta.appVersion = appVersion;
|
|
161
|
+
// 安装包三格(2026-11-18):包名 / 构建号 / 渠道。反馈工具提交到分发平台时要按真实安装包
|
|
162
|
+
// 报,缺了就不写(老 App 不带这几格,不能把已有值冲成空)。
|
|
163
|
+
const packageId = truncate(device?.packageId, FIELD_MAX);
|
|
164
|
+
if (packageId) meta.packageId = packageId;
|
|
165
|
+
const buildNumber = truncate(device?.buildNumber, FIELD_MAX);
|
|
166
|
+
if (buildNumber) meta.buildNumber = buildNumber;
|
|
167
|
+
const channel = truncate(device?.channel, FIELD_MAX);
|
|
168
|
+
if (channel) meta.channel = channel;
|
|
154
169
|
if (device?.lanDiscovery === 1 || device?.lanDiscovery === 0) meta.lanDiscovery = device.lanDiscovery;
|
|
155
170
|
return meta;
|
|
156
171
|
}
|
|
@@ -512,6 +527,9 @@ function activeRow(deviceId, createdAt) {
|
|
|
512
527
|
platform: '',
|
|
513
528
|
osVersion: '',
|
|
514
529
|
appVersion: '',
|
|
530
|
+
packageId: '',
|
|
531
|
+
buildNumber: '',
|
|
532
|
+
channel: '',
|
|
515
533
|
boundAt: createdAt,
|
|
516
534
|
lastSeenAt: 0,
|
|
517
535
|
lastChannel: '',
|
|
@@ -556,6 +574,9 @@ function accumulateDevice(row, record, createdAt) {
|
|
|
556
574
|
if (record.platform && createdAt >= (row.platformAt || 0)) { row.platform = record.platform; row.platformAt = createdAt; }
|
|
557
575
|
if (record.osVersion && createdAt >= (row.osVersionAt || 0)) { row.osVersion = record.osVersion; row.osVersionAt = createdAt; }
|
|
558
576
|
if (record.appVersion && createdAt >= (row.appVersionAt || 0)) { row.appVersion = record.appVersion; row.appVersionAt = createdAt; }
|
|
577
|
+
if (record.packageId && createdAt >= (row.packageIdAt || 0)) { row.packageId = record.packageId; row.packageIdAt = createdAt; }
|
|
578
|
+
if (record.buildNumber && createdAt >= (row.buildNumberAt || 0)) { row.buildNumber = record.buildNumber; row.buildNumberAt = createdAt; }
|
|
579
|
+
if (record.channel && createdAt >= (row.channelAt || 0)) { row.channel = record.channel; row.channelAt = createdAt; }
|
|
559
580
|
const seenAt = Number(record.lastSeenAt) || 0;
|
|
560
581
|
if (seenAt >= row.lastSeenFrom) {
|
|
561
582
|
row.lastSeenFrom = seenAt;
|
|
@@ -582,7 +603,7 @@ function activeOut(rows) {
|
|
|
582
603
|
}
|
|
583
604
|
const out = [];
|
|
584
605
|
for (const row of rows.values()) {
|
|
585
|
-
const { modelAt, nameAt, platformAt, osVersionAt, appVersionAt, lastSeenFrom, permissionsAt, ...rest } = row;
|
|
606
|
+
const { modelAt, nameAt, platformAt, osVersionAt, appVersionAt, packageIdAt, buildNumberAt, channelAt, lastSeenFrom, permissionsAt, ...rest } = row;
|
|
586
607
|
out.push(rest);
|
|
587
608
|
}
|
|
588
609
|
// 最近连着的排前面;从没连过的按绑定时间倒序垫后。
|
|
@@ -662,6 +683,32 @@ function listDevicesWithHistory(instanceId) {
|
|
|
662
683
|
return { devices: active, history };
|
|
663
684
|
}
|
|
664
685
|
|
|
686
|
+
/**
|
|
687
|
+
* 清空本实例的「已解绑」历史:所有已结束的手机记录整条删掉,活着的与电脑网页授权一条不动。
|
|
688
|
+
*
|
|
689
|
+
* 「已结束」只认 `isLive` 的反面,与 `scanDevices` 里聚历史那半完全同源 —— 面板看得到的
|
|
690
|
+
* 历史清得到,同一台重配过就留活 record、删旧 record。超出 30 天窗口的残余也一起收走
|
|
691
|
+
* (它们本就该被 `prune` 删掉)。返回删掉的条数。只读副本拒绝,理由同 `revoke`。
|
|
692
|
+
*/
|
|
693
|
+
function clearHistory(instanceId) {
|
|
694
|
+
load();
|
|
695
|
+
if (readOnly) {
|
|
696
|
+
const error = new Error('凭据库的只读副本不能清空历史;旁路子进程请经 IPC 交给主进程');
|
|
697
|
+
error.code = 'READ_ONLY';
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
const now = Date.now();
|
|
701
|
+
const before = records.length;
|
|
702
|
+
records = records.filter((record) => {
|
|
703
|
+
if (record.instanceId !== instanceId || record.kind === 'computer') return true;
|
|
704
|
+
// isLive 为假即已结束(吊销或过期);活记录留下。判据只有这一处。
|
|
705
|
+
return isLive(record, now);
|
|
706
|
+
});
|
|
707
|
+
const cleared = before - records.length;
|
|
708
|
+
if (cleared) { rebuildIndex(); save(); }
|
|
709
|
+
return cleared;
|
|
710
|
+
}
|
|
711
|
+
|
|
665
712
|
/**
|
|
666
713
|
* 本实例签发过、仍然有效的凭据摘要,按签发时间从新到旧。
|
|
667
714
|
*
|
|
@@ -714,6 +761,7 @@ module.exports = {
|
|
|
714
761
|
listDevices,
|
|
715
762
|
listHistory,
|
|
716
763
|
listDevicesWithHistory,
|
|
764
|
+
clearHistory,
|
|
717
765
|
setDevicePermissions,
|
|
718
766
|
activeDigests,
|
|
719
767
|
revoke,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# DSH 手机扩展清单
|
|
2
|
+
|
|
3
|
+
这是一个**简易的扩展市场清单**:只收录能在 DSH 手机上用的扩展,也就是「带手机扩展声明的 DSH 插件」。作者投稿、CI 扫描核对、App 里展示,装的时候由 DSH 宿主装到它自己那台电脑上。
|
|
4
|
+
|
|
5
|
+
它是 dsh-market / awesome-dsh-plugin 那套思路的轻量版,只借两件事:**一个插件一个文件地投稿**,和**扫描核对条目还活着**。不做账号、评分、审核流水线——扩展跑在隔离网页框里、能力受 App 白名单约束,来源由作者与用户自己负责。
|
|
6
|
+
|
|
7
|
+
清单随 `dsh-mobile-plugin` 这个 npm 包发版:合进条目、发一版插件,用户就拿到新目录。宿主直接从自己包里读 `index.json`,不走网络、不依赖任何外部托管。
|
|
8
|
+
|
|
9
|
+
## 投稿
|
|
10
|
+
|
|
11
|
+
在 `entries/` 加一个 JSON 文件,文件名 `<owner>__<repo>.json`(owner/repo 用你 GitHub 仓库的地址),提 PR。一个插件一个文件,永不和别人的条目冲突。字段:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"name": "dsh-your-plugin",
|
|
16
|
+
"repo": "https://github.com/owner/dsh-your-plugin",
|
|
17
|
+
"owner": "owner",
|
|
18
|
+
"title": { "zh-Hans": "你的插件", "zh-Hant": "你的插件", "en": "Your Plugin", "ja": "…", "ko": "…", "de": "…", "es": "…", "fr": "…", "pt": "…", "ru": "…", "tr": "…" },
|
|
19
|
+
"description": { "zh-Hans": "一句功能说明,句号结尾。", "zh-Hant": "…", "en": "…", "ja": "…", "ko": "…", "de": "…", "es": "…", "fr": "…", "pt": "…", "ru": "…", "tr": "…" },
|
|
20
|
+
"category": "tools",
|
|
21
|
+
"npm": "dsh-your-plugin",
|
|
22
|
+
"icon": "https://raw.githubusercontent.com/owner/dsh-your-plugin/master/icon.png",
|
|
23
|
+
"capabilities": ["host.data"],
|
|
24
|
+
"added": "2026-11-18"
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
三条硬规范(build 会挡,缺一不可):
|
|
29
|
+
|
|
30
|
+
- **`name` 就是这个插件的 npm 包名**,必须是合法 npm 名(形如 `dsh-xxx` 或 `@scope/xxx`)。
|
|
31
|
+
显示名另写在 `title`(`name` 是身份、不是给人看的标题)。填了 `npm` 字段就必须与 `name` 一致,
|
|
32
|
+
**只写一个更省事**:安装目标直接从 `name` 取。
|
|
33
|
+
- **`title` 和 `description` 必须齐 App 的全部 11 门语言**:`zh-Hans`、`zh-Hant`、`en`、`ja`、
|
|
34
|
+
`ko`、`de`、`es`、`fr`、`pt`、`ru`、`tr`。用户用哪门语言就显示哪门,缺一门那门用户就会看到
|
|
35
|
+
回退的英文。**建议用机器翻译生成**,维护者抽查准确性;数字、命令、API 名别让机翻改坏。
|
|
36
|
+
注意标签是 `zh-Hans`/`zh-Hant`(不是 `zh`/`zh-TW`),多写一门或少写一门都 build 不过。
|
|
37
|
+
- **`repo` / `owner`**:repo 写 GitHub 地址,owner 写了就必须和 repo 对得上。
|
|
38
|
+
|
|
39
|
+
可选字段:
|
|
40
|
+
|
|
41
|
+
- `icon` 可选:填你仓库里一张图片的 **https raw 地址**(注意用对默认分支,magpie 是 `master`),
|
|
42
|
+
市场卡片显示这张图;不填就显示名字首字母。**没有上传流程**,你把自己的图片放进仓库、贴地址即可。
|
|
43
|
+
- `category` 取值:`tools` / `office` / `life` / `fun` / `dev`;别的也可,只是没有中文名。
|
|
44
|
+
- `screenshots`(最多 4 张 https 图)、`capabilities`、`version`、`added`(`YYYY-MM-DD`)按需填。
|
|
45
|
+
- 描述只说功能,不写营销词,数字与 API 名要与代码对得上。
|
|
46
|
+
|
|
47
|
+
### 准入
|
|
48
|
+
|
|
49
|
+
自动扫描(`scan.mjs`)核的是硬事实:仓库在、没归档没禁用、包里声明了 `dsh.bundle` 或
|
|
50
|
+
`dshMobileExtensions`(只收「带手机扩展的 DSH 插件」)。这几条不过,维护者不会合并。
|
|
51
|
+
|
|
52
|
+
其余靠维护者读源码把关,CI 不替他判断:
|
|
53
|
+
|
|
54
|
+
1. 描述里写的数字、命令、API 名是否与代码对得上——夸大是被打回的主要原因。
|
|
55
|
+
2. 是不是真在维护、有没有可疑行为(空壳、混淆代码、凭据外传)。仓库刚建、还没成形的,先做完再投。
|
|
56
|
+
3. 聚合包(自己不干活、只列一堆依赖)不单独收录,收它依赖的那些插件;依赖要指向原作者。
|
|
57
|
+
4. 同一功能已有更好的条目时择善收录,不重复堆。
|
|
58
|
+
|
|
59
|
+
一个 PR 建议只加少数几条:评审是逐条读源码的,堆一大包没人能认真看完。
|
|
60
|
+
|
|
61
|
+
## 生成与扫描
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
node scripts/build.mjs # entries/*.json → index.json(宿主读的就是它)
|
|
65
|
+
node scripts/build.mjs --check # CI 校验 index.json 是不是当前 entries 生成的
|
|
66
|
+
node scripts/scan.mjs # 联网扫描每个仓库是否还活着、是否还带扩展声明
|
|
67
|
+
node scripts/test-registry.mjs # 本地守卫,不联网
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
改了条目一定要重新 `build.mjs`,把 `index.json` 一起提交——宿主读的是它,不是 `entries/`。
|
|
71
|
+
|
|
72
|
+
扫描失败(仓库没了、归档了、把声明删了)**不自动删条目**,只在报告里标出来、提 issue 等人确认。被收录不是永久的:停更、失效、行为异常的条目会被移除。
|
|
73
|
+
|
|
74
|
+
## 数据怎么到 App
|
|
75
|
+
|
|
76
|
+
`index.json` 在 `dsh-mobile-plugin` 的 npm 包 `files` 白名单里,随插件发版到用户电脑上。
|
|
77
|
+
宿主读到后经已配对的隧道给 App;App 点安装走宿主既有的插件管理器,装到宿主那台电脑上。
|
|
78
|
+
App 自己不连公网、不跑 pnpm,也没有任何清单地址要配置——换台电脑装了这版插件,目录就在那。
|
|
79
|
+
|
|
80
|
+
收录新插件的流程:条目合并进 `entries/` → 重新 `build.mjs` 生成 `index.json` → 发一版
|
|
81
|
+
`dsh-mobile-plugin`。**不另发清单、不更新托管地址**;代价是新目录要等这次发版才到用户手里。
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "DSH Mobile Extension Market",
|
|
3
|
+
"categories": {
|
|
4
|
+
"tools": {
|
|
5
|
+
"en": "Tools",
|
|
6
|
+
"zh": "工具"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"languages": [
|
|
10
|
+
"zh-Hans",
|
|
11
|
+
"zh-Hant",
|
|
12
|
+
"en",
|
|
13
|
+
"ja",
|
|
14
|
+
"ko",
|
|
15
|
+
"de",
|
|
16
|
+
"es",
|
|
17
|
+
"fr",
|
|
18
|
+
"pt",
|
|
19
|
+
"ru",
|
|
20
|
+
"tr"
|
|
21
|
+
],
|
|
22
|
+
"plugins": [
|
|
23
|
+
{
|
|
24
|
+
"name": "dsh-magpie-plugin",
|
|
25
|
+
"url": "https://github.com/WNLUO/dsh-magpie-plugin",
|
|
26
|
+
"repository": {
|
|
27
|
+
"url": "https://github.com/WNLUO/dsh-magpie-plugin"
|
|
28
|
+
},
|
|
29
|
+
"owner": "WNLUO",
|
|
30
|
+
"title": {
|
|
31
|
+
"zh-Hans": "Magpie",
|
|
32
|
+
"zh-Hant": "Magpie",
|
|
33
|
+
"en": "Magpie",
|
|
34
|
+
"ja": "Magpie",
|
|
35
|
+
"ko": "Magpie",
|
|
36
|
+
"de": "Magpie",
|
|
37
|
+
"es": "Magpie",
|
|
38
|
+
"fr": "Magpie",
|
|
39
|
+
"pt": "Magpie",
|
|
40
|
+
"ru": "Magpie",
|
|
41
|
+
"tr": "Magpie"
|
|
42
|
+
},
|
|
43
|
+
"description": {
|
|
44
|
+
"zh-Hans": "在手机上打开 magpie 自己的界面,宿主按需拉起本机的 magpie 网页服务。",
|
|
45
|
+
"zh-Hant": "在手機上打開 magpie 自己的介面,宿主按需拉起本機的 magpie 網頁服務。",
|
|
46
|
+
"en": "Open magpie's own interface on your phone; the host starts the local magpie web service on demand.",
|
|
47
|
+
"ja": "スマートフォンで magpie 独自のインターフェースを開きます。ホストがローカルの magpie Web サービスを必要に応じて起動します。",
|
|
48
|
+
"ko": "휴대폰에서 magpie 고유의 인터페이스를 엽니다. 호스트가 필요할 때 로컬 magpie 웹 서비스를 실행합니다.",
|
|
49
|
+
"de": "Öffne magpies eigene Oberfläche auf deinem Telefon; der Host startet den lokalen magpie-Webdienst bei Bedarf.",
|
|
50
|
+
"es": "Abre la interfaz propia de magpie en tu teléfono; el host inicia el servicio web local de magpie cuando hace falta.",
|
|
51
|
+
"fr": "Ouvre l'interface propre à magpie sur votre téléphone ; l'hôte démarre le service web local de magpie à la demande.",
|
|
52
|
+
"pt": "Abra a interface própria do magpie no seu telemóvel; o host inicia o serviço web local do magpie quando necessário.",
|
|
53
|
+
"ru": "Открывает собственный интерфейс magpie на телефоне; хост при необходимости запускает локальный веб-сервис magpie.",
|
|
54
|
+
"tr": "magpie'nin kendi arayüzünü telefonunuzda açar; host, yerel magpie web servisini gerektiğinde başlatır."
|
|
55
|
+
},
|
|
56
|
+
"npm": "dsh-magpie-plugin",
|
|
57
|
+
"category": "tools",
|
|
58
|
+
"stars": 0,
|
|
59
|
+
"downloads": null,
|
|
60
|
+
"icon": "https://raw.githubusercontent.com/WNLUO/dsh-magpie-plugin/master/extensions/magpie/icons/icon-512.png",
|
|
61
|
+
"screenshots": [],
|
|
62
|
+
"capabilities": [
|
|
63
|
+
"host.data"
|
|
64
|
+
],
|
|
65
|
+
"added": "2026-11-18",
|
|
66
|
+
"version": "0.1.1"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
package/lib/impl.js
CHANGED
|
@@ -66,6 +66,8 @@ const statsScheduler = require('./mobile/stats-scheduler.cjs')
|
|
|
66
66
|
const { installExtensions } = require('./mobile/extensions.js')
|
|
67
67
|
// 给模型用的工作区 / 会话能力:列、读、发、停、新建与整理(见 mobile/workspace-tools.js)。
|
|
68
68
|
const { installWorkspaceTools } = require('./mobile/workspace-tools.js')
|
|
69
|
+
// 给模型用的反馈能力:AI 查清问题后直接提交到分发平台(见 mobile/feedback.js)。
|
|
70
|
+
const { installFeedback } = require('./mobile/feedback.js')
|
|
69
71
|
const { activeGuard } = require('./host-guard.cjs')
|
|
70
72
|
// 桌面端侧栏展开态的快照存储。桌面把这份状态只记在浏览器 localStorage 里,宿主必须
|
|
71
73
|
// 有一个落盘处:客户端半边(lib/client.js)上报 → 这里 → 移动端读取。
|
|
@@ -219,6 +221,12 @@ function createConfigStore(state) {
|
|
|
219
221
|
throw new Error(`invalid remote-control setting: ${error && error.message ? error.message : String(error)}`)
|
|
220
222
|
}
|
|
221
223
|
core.normalizeRelayAddresses(parsed)
|
|
224
|
+
// 用户配了公网可达的自建服务(自建中转 / 直连 / TCP 直连,排除局域网与 IPv6)时,
|
|
225
|
+
// 公用中转必须自动、强制停用:从地址列表里剔除公用项,存下去的那份就不含公用地址,
|
|
226
|
+
// 手机也就不可能再走公用。判据与面板 status 的 publicRelayBlocked 同源(core 里那一个
|
|
227
|
+
// 函数),否则界面说停用了、实际还在连公用。放在收敛之后、落盘之前,保证
|
|
228
|
+
// relayUrls[0] === relayUrl 的不变式与「真停用」一起成立。
|
|
229
|
+
core.stripPublicRelay(parsed)
|
|
222
230
|
Object.assign(state, parsed)
|
|
223
231
|
core.saveState(state)
|
|
224
232
|
if (options.notify !== false) notify()
|
|
@@ -405,6 +413,13 @@ function apply(ctx) {
|
|
|
405
413
|
}
|
|
406
414
|
return undefined
|
|
407
415
|
}, `${name}: workspace tool`)
|
|
416
|
+
ctx.effect(() => {
|
|
417
|
+
// 反馈工具:设备身份从凭据库取(手机每条请求都上报,宿主写回记录),提交到分发平台。
|
|
418
|
+
try { installFeedback(ctx, { credentials, instanceId: () => state.instanceId }) } catch (error) {
|
|
419
|
+
if (!String(error).includes('without inject')) throw error
|
|
420
|
+
}
|
|
421
|
+
return undefined
|
|
422
|
+
}, `${name}: feedback tool`)
|
|
408
423
|
mount('统计采集', () => ctx.effect(() => statsScheduler.start(ctx), `${name}: stats collect`))
|
|
409
424
|
mount('过程播报', () => ctx.effect(() => installNarration(ctx), `${name}: process narration`))
|
|
410
425
|
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// AI 查清问题后直接把反馈提交到分发平台;GitHub PR 这条只写进说明(2026-11-18)。
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 给模型的「反馈」能力:用户在用插件 / App 时遇到问题,AI 先排查;真查出原因后,由 AI
|
|
6
|
+
* 直接把反馈提交到分发平台,不用用户自己回 App 里手填。
|
|
7
|
+
*
|
|
8
|
+
* ## 两条途径
|
|
9
|
+
*
|
|
10
|
+
* - **分发平台**:公开反馈接口,与 App 里的反馈页同一个(`/api/sdk/feedback`)。插件把
|
|
11
|
+
* 当前连接的设备身份一并带上,提交后能收到官方回复。这条本模块能真的替用户提交。
|
|
12
|
+
* - **GitHub**:插件代码本身的 bug 可以直接提 PR。这条路依赖用户自己登录 GitHub,
|
|
13
|
+
* 插件无法代提,所以只把仓库与前提写进说明,由 AI 自己判断走不走。
|
|
14
|
+
*
|
|
15
|
+
* ## 身份从哪来
|
|
16
|
+
*
|
|
17
|
+
* 手机的机型 / 平台 / 系统版本 / App 版本 / 包名 / 构建号 / 渠道跟着每条请求的身份头上报,
|
|
18
|
+
* 宿主在鉴权通过时写回凭据记录(`lib/shared/device-headers.js` → 凭据库)。这里读最新一条
|
|
19
|
+
* 活动记录里的那几格,不另开接口、也不在 App 里输任何东西。
|
|
20
|
+
*
|
|
21
|
+
* ## 为什么没有附件
|
|
22
|
+
*
|
|
23
|
+
* 反馈页能带上截图,但 AI 提交的是「查出来的问题与复现」,正文就够;附件要读手机本地文件、
|
|
24
|
+
* 走 20MB 上传,是另一条路,这一版不做。
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const PLATFORM_ORIGIN = 'https://app.wnluo.com';
|
|
28
|
+
const FEEDBACK_PATH = '/api/sdk/feedback';
|
|
29
|
+
const GITHUB_REPO = 'https://github.com/WNLUO/dsh-mobile-plugin';
|
|
30
|
+
|
|
31
|
+
/** 与平台侧对齐的正文上限(App 的反馈页也是这个数)。 */
|
|
32
|
+
const CONTENT_MAX = 4000;
|
|
33
|
+
/** 只有文字、没有附件上传,30 秒足够。 */
|
|
34
|
+
const SUBMIT_TIMEOUT_MS = 30_000;
|
|
35
|
+
/**
|
|
36
|
+
* 读不到安装包包名时的兜底:与 App 的 `buildPackageName() || PACKAGE_ID` 同一条。
|
|
37
|
+
* 插件就是给这个 App 用的,所以这个常量是这台电脑上那份安装包的默认产品号。
|
|
38
|
+
*/
|
|
39
|
+
const DEFAULT_PACKAGE_ID = 'com.dsh.mobile';
|
|
40
|
+
|
|
41
|
+
/** 两条反馈途径:写进工具说明,也能被 `channels` 动作单独取出来。 */
|
|
42
|
+
function feedbackChannels() {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
kind: 'distribution',
|
|
46
|
+
name: 'APP 分发系统反馈',
|
|
47
|
+
description: '提交到分发平台的公开反馈接口(与 App 里的反馈页同一个)。插件会自动带上当前连接的设备身份;提交后能在 App 里收到官方回复。',
|
|
48
|
+
endpoint: `${PLATFORM_ORIGIN}${FEEDBACK_PATH}`,
|
|
49
|
+
requiresLogin: false,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
kind: 'github',
|
|
53
|
+
name: 'GitHub PR',
|
|
54
|
+
description: '如果确定是插件代码本身的 bug,可以在公开仓库提交 PR 或 issue;这条路需要用户已登录 GitHub,插件不代提交。',
|
|
55
|
+
repo: GITHUB_REPO,
|
|
56
|
+
requiresLogin: true,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 选一台设备的身份来提交:给了 `deviceId` 就按它找,没给就用最近连着的那台。
|
|
63
|
+
*
|
|
64
|
+
* 活动清单本身已按「最近连着」排好序(凭据库的 `activeOut`),所以没指定时取第一台。
|
|
65
|
+
* 指定了却找不到,照实报错 —— 不能悄悄换一台,那会把反馈挂到错误的设备上。
|
|
66
|
+
*/
|
|
67
|
+
function pickDevice(devices, deviceId) {
|
|
68
|
+
const list = Array.isArray(devices) ? devices : [];
|
|
69
|
+
const wanted = typeof deviceId === 'string' ? deviceId.trim() : '';
|
|
70
|
+
if (wanted) {
|
|
71
|
+
const found = list.find((device) => device && device.deviceId === wanted);
|
|
72
|
+
if (!found) throw new Error(`找不到设备 ${wanted}(可用 \`channels\` 之后按已配对的设备号指定)`);
|
|
73
|
+
return found;
|
|
74
|
+
}
|
|
75
|
+
if (list.length === 0) throw new Error('当前没有已连接的手机,拿不到设备身份,无法提交反馈');
|
|
76
|
+
return list[0];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 拼提交给分发平台的表单。字段名与 App 的反馈页逐字对齐(`app/src/services/feedback.ts`
|
|
81
|
+
* 的 `feedbackForm`),这样平台那边看到的是同一种形状。
|
|
82
|
+
*
|
|
83
|
+
* **不填 `context`**:那是 `{runtime_version, language}`,两样只有 App 自己知道;宿主拿不到,
|
|
84
|
+
* 硬编一个只会让平台看到假的运行时。版本相关信息已经由 `version_name` / `build_number` 带着。
|
|
85
|
+
*/
|
|
86
|
+
function buildFeedbackForm(device, content, threadKey) {
|
|
87
|
+
const form = new FormData();
|
|
88
|
+
form.append('package_id', device.packageId || DEFAULT_PACKAGE_ID);
|
|
89
|
+
form.append('platform', device.platform || '');
|
|
90
|
+
form.append('version_name', device.appVersion || '');
|
|
91
|
+
form.append('build_number', device.buildNumber || '');
|
|
92
|
+
form.append('model', device.model || '');
|
|
93
|
+
form.append('system_version', device.osVersion || '');
|
|
94
|
+
form.append('channel', device.channel || '');
|
|
95
|
+
form.append('content', content);
|
|
96
|
+
const key = typeof threadKey === 'string' ? threadKey.trim() : '';
|
|
97
|
+
if (key) form.append('thread_key', key);
|
|
98
|
+
form.append('device_id', device.deviceId || '');
|
|
99
|
+
return form;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 发 multipart 到分发平台。返回平台给的线程对象(含 `thread_key`)。
|
|
104
|
+
*
|
|
105
|
+
* 网络与状态码的收口与 App 的 `postMultipart` 同口径:2xx 取 `data`,其余尽量读平台回的
|
|
106
|
+
* `error` 文案,429 单独说「太频繁」,超时说「超时」。
|
|
107
|
+
*/
|
|
108
|
+
async function postMultipart(form) {
|
|
109
|
+
const controller = new AbortController();
|
|
110
|
+
const timer = setTimeout(() => controller.abort(), SUBMIT_TIMEOUT_MS);
|
|
111
|
+
try {
|
|
112
|
+
const response = await fetch(`${PLATFORM_ORIGIN}${FEEDBACK_PATH}`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
body: form,
|
|
115
|
+
signal: controller.signal,
|
|
116
|
+
});
|
|
117
|
+
let body = null;
|
|
118
|
+
try { body = await response.json(); } catch { body = null; }
|
|
119
|
+
if (response.status >= 200 && response.status < 300) {
|
|
120
|
+
const data = body && typeof body === 'object' ? body.data : null;
|
|
121
|
+
if (data && typeof data === 'object') return data;
|
|
122
|
+
throw new Error('反馈接口没有返回线程信息');
|
|
123
|
+
}
|
|
124
|
+
const text = body && typeof body === 'object' && typeof body.error === 'string'
|
|
125
|
+
? body.error.trim()
|
|
126
|
+
: '';
|
|
127
|
+
if (text) throw new Error(text);
|
|
128
|
+
if (response.status === 429) throw new Error('反馈提交太频繁,稍后再试');
|
|
129
|
+
throw new Error(`反馈提交失败(HTTP ${response.status})`);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error && error.name === 'AbortError') throw new Error('反馈提交超时,网络可能不通');
|
|
132
|
+
throw error;
|
|
133
|
+
} finally {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 真正提交一次:读设备身份 → 拼表单 → 发给平台 → 把线程 key 与一句结论还给 AI。
|
|
140
|
+
*
|
|
141
|
+
* `deps` 是装配层给的 `{ credentials, instanceId }`:`instanceId` 是取值器(不是值),
|
|
142
|
+
* 与本插件其它「必须传取值器」的地方同一理由 —— 重载后实例号可能变。
|
|
143
|
+
*/
|
|
144
|
+
async function submitFeedback(deps, content, threadKey, deviceId) {
|
|
145
|
+
const devices = deps.credentials.listDevices(deps.instanceId());
|
|
146
|
+
const device = pickDevice(devices, deviceId);
|
|
147
|
+
const form = buildFeedbackForm(device, content, threadKey);
|
|
148
|
+
const thread = await postMultipart(form);
|
|
149
|
+
const key = typeof thread.thread_key === 'string' ? thread.thread_key : '';
|
|
150
|
+
return {
|
|
151
|
+
threadKey: key,
|
|
152
|
+
message: key
|
|
153
|
+
? `已提交到分发平台,反馈线程 ${key}。之后 App 里能收到官方回复。`
|
|
154
|
+
: '已提交到分发平台。',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 工具注册。`deps` 只给这次装配的凭据库与实例号取值器。 */
|
|
159
|
+
function registerFeedbackTool(ctx, deps) {
|
|
160
|
+
const { defineTool } = require('@deepseek-ai/dsh-tools');
|
|
161
|
+
if (!deps || !deps.credentials || typeof deps.instanceId !== 'function') {
|
|
162
|
+
throw new Error('反馈工具缺少凭据库或实例号取值器');
|
|
163
|
+
}
|
|
164
|
+
const channels = feedbackChannels();
|
|
165
|
+
ctx.tools.register(defineTool({
|
|
166
|
+
name: 'dsh_feedback',
|
|
167
|
+
description: 'Report a real problem with this mobile plugin or the AI-HUB app. '
|
|
168
|
+
+ 'Feedback routes: (1) the APP distribution platform — `submit` sends the content to it, and the plugin fills in the connected device identity automatically; the user gets official replies in the app. '
|
|
169
|
+
+ '(2) GitHub — code-level bugs can go to https://github.com/WNLUO/dsh-mobile-plugin as a pull request or issue, but that needs the user to be logged into GitHub and is not submitted by this tool. '
|
|
170
|
+
+ 'Use `channels` to list both routes. Only submit after you have actually found the cause: describe the problem, what you checked, and the reproduction or suggested fix.',
|
|
171
|
+
parameters: {
|
|
172
|
+
action: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
required: true,
|
|
175
|
+
enum: ['channels', 'submit'],
|
|
176
|
+
description: 'channels: list the feedback routes. submit: send the content to the distribution platform.',
|
|
177
|
+
},
|
|
178
|
+
content: {
|
|
179
|
+
type: 'string',
|
|
180
|
+
description: 'Feedback text for submit: the problem, what you found, and the reproduction or suggested fix. Required for submit (max 4000 chars).',
|
|
181
|
+
},
|
|
182
|
+
threadKey: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
description: 'Optional for submit: append to an existing feedback thread instead of opening a new one.',
|
|
185
|
+
},
|
|
186
|
+
deviceId: {
|
|
187
|
+
type: 'string',
|
|
188
|
+
description: 'Optional for submit: which paired device identity to report. Omit to use the most recently connected device.',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
output: {
|
|
192
|
+
schema: {
|
|
193
|
+
type: 'object',
|
|
194
|
+
additionalProperties: false,
|
|
195
|
+
properties: {
|
|
196
|
+
action: { type: 'string' },
|
|
197
|
+
channels: {
|
|
198
|
+
type: 'array',
|
|
199
|
+
items: {
|
|
200
|
+
type: 'object',
|
|
201
|
+
additionalProperties: false,
|
|
202
|
+
properties: {
|
|
203
|
+
kind: { type: 'string' },
|
|
204
|
+
name: { type: 'string' },
|
|
205
|
+
description: { type: 'string' },
|
|
206
|
+
endpoint: { type: 'string' },
|
|
207
|
+
repo: { type: 'string' },
|
|
208
|
+
requiresLogin: { type: 'boolean' },
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
submitted: { type: 'boolean' },
|
|
213
|
+
threadKey: { type: 'string' },
|
|
214
|
+
message: { type: 'string' },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
render: (_args, value) => [{ type: 'text', text: renderSummary(value) }],
|
|
218
|
+
},
|
|
219
|
+
execute: async (args) => {
|
|
220
|
+
switch (args.action) {
|
|
221
|
+
case 'channels':
|
|
222
|
+
return { action: 'channels', channels };
|
|
223
|
+
case 'submit': {
|
|
224
|
+
const content = typeof args.content === 'string' ? args.content.trim() : '';
|
|
225
|
+
if (!content) throw new Error('submit 需要 content');
|
|
226
|
+
if (content.length > CONTENT_MAX) throw new Error(`content 超长(上限 ${CONTENT_MAX} 字)`);
|
|
227
|
+
const submitted = await submitFeedback(deps, content, args.threadKey, args.deviceId);
|
|
228
|
+
return { action: 'submit', submitted: true, threadKey: submitted.threadKey, message: submitted.message };
|
|
229
|
+
}
|
|
230
|
+
default:
|
|
231
|
+
throw new Error(`未知的 action:${args.action}`);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** 结果压成一句话,给模型看的那份正文。 */
|
|
238
|
+
function renderSummary(value) {
|
|
239
|
+
switch (value.action) {
|
|
240
|
+
case 'channels': {
|
|
241
|
+
const names = (value.channels || []).map((channel) => channel.name).join('、');
|
|
242
|
+
return `两条反馈途径:${names || '(空)'}`;
|
|
243
|
+
}
|
|
244
|
+
case 'submit':
|
|
245
|
+
return value.message || '已提交反馈。';
|
|
246
|
+
default:
|
|
247
|
+
return '完成。';
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 装配层入口:挂 `dsh_feedback` 工具。
|
|
253
|
+
*
|
|
254
|
+
* 与另外几个工具同一个口径:没有 tools 注入的 profile 只少这个工具,插件其余部分照常装;
|
|
255
|
+
* 缺注入时 cordis 抛的是 "without inject"。别的错误照抛,不能把真的注册失败也吞掉。
|
|
256
|
+
*/
|
|
257
|
+
function installFeedback(ctx, deps) {
|
|
258
|
+
try {
|
|
259
|
+
registerFeedbackTool(ctx, deps);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
const message = error && error.message ? error.message : String(error);
|
|
262
|
+
if (!message.includes('without inject')) throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
module.exports = {
|
|
267
|
+
DEFAULT_PACKAGE_ID,
|
|
268
|
+
FEEDBACK_PATH,
|
|
269
|
+
GITHUB_REPO,
|
|
270
|
+
PLATFORM_ORIGIN,
|
|
271
|
+
buildFeedbackForm,
|
|
272
|
+
feedbackChannels,
|
|
273
|
+
installFeedback,
|
|
274
|
+
pickDevice,
|
|
275
|
+
registerFeedbackTool,
|
|
276
|
+
submitFeedback,
|
|
277
|
+
};
|