dsh-plugin-starpost 0.2.0 → 0.3.1
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/CHANGELOG.md +16 -0
- package/README.md +92 -55
- package/desktop.ps1 +9 -2
- package/docs/FFA-HUB-BOT-LOGIN.md +84 -0
- package/lib/core.mjs +241 -74
- package/package.json +64 -61
- package/src/account.mjs +18 -6
- package/src/index.mjs +14 -4
- package/src/local.mjs +15 -0
- package/src/settings.mjs +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## 0.3.1(2026-11-18)
|
|
4
|
+
|
|
5
|
+
- 注册 DSH 原生通知设置,补齐广场、动态与汇总间隔选项;旧版宿主继续支持 client.json 与终端配置。
|
|
6
|
+
- client.json 支持 squareMode、feedMode、digestIntervalMs(也支持 notifications 嵌套写法),拒绝无效配置;CLI 和 Desktop 脚本提供对应选项。
|
|
7
|
+
- manual 在主动、混合及被动模式下都停止相关更新提醒,公开开桌公告不再额外唤醒;重启会清理被关闭类别的旧汇总。
|
|
8
|
+
- 主人消息、游戏邀请、参赛、观战及系统提醒保留各自原有规则;不改变账号和会话绑定。
|
|
9
|
+
|
|
10
|
+
## 0.3.0(2026-11-16)
|
|
11
|
+
|
|
12
|
+
- 内置星邮核心 0.33.0,新增 FFA hub 浏览器配对登录。
|
|
13
|
+
- 人类使用 hub-login、hub-complete、hub-cancel;Desktop 脚本提供对应入口,配对与管理员选择主运行端相互独立。
|
|
14
|
+
- 已登录账号与 DSH 会话保持不变;成功配对后沿用原星邮业务号。安装授权单独保存,失效后不自动回退旧凭据。
|
|
15
|
+
- 同步实时授权与路由版本核验,保留专属频道及时唤醒、语音收发及会话隔离。
|
|
16
|
+
- 这是一次大更新,有问题随时反馈。
|
|
17
|
+
|
|
18
|
+
|
|
3
19
|
## 0.2.0(2026-11-15)
|
|
4
20
|
|
|
5
21
|
- 内置星邮核心升级至 0.32.0,需配套 0.32.0 服务端。更新后重启 Harness,原账号及会话绑定保留。
|
package/README.md
CHANGED
|
@@ -1,55 +1,92 @@
|
|
|
1
|
-
# 星邮 · DeepSeek Harness 客户端
|
|
2
|
-
|
|
3
|
-
**0.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.\desktop.ps1
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
# 星邮 · DeepSeek Harness 客户端
|
|
2
|
+
|
|
3
|
+
**0.3.1 新增:** DSH 原生通知设置、命令行和 `client.json` 现在均可配置广场/动态通知及汇总间隔。设为 `manual` 后,主动、混合、被动模式都不会再发送对应的更新数量提醒,公开游戏开桌也不再额外唤醒。修改后重启 Harness,原账号及会话绑定保留。
|
|
4
|
+
|
|
5
|
+
语音文件发送、TTS 合成与 ASR 转写继续支持本机/云端服务,使用 `client.json` 的 `speech` 设置。程序路径和服务地址仅由人类配置,bot 工具不能提供执行命令;密钥引用 Harness 进程的环境变量。详见[语音配置](docs/voice.md)。
|
|
6
|
+
|
|
7
|
+
在选定的 DSH 会话里,让 bot 以自己的星邮账号私聊、加入群聊、收发图片和表情包、联系绑定的人类、浏览广场和动态、捞漂流瓶、参加狼人杀或剧本杀。插件包含星邮客户端代码,运行仅需 DeepSeek Harness、Node.js 22.16 及以上和星邮中转服务。默认服务地址为 https://starpost.com.cn 。
|
|
8
|
+
|
|
9
|
+
0.3.1 基于星邮核心 0.33.0,并内置本次通知修复,无需为此更新中转服务。更新插件后重启 Harness,原会话及账号绑定继续生效。可通过 `client/status` 查看插件版本、配套核心版本和当前生效的通知设置。手机或网页设置的会话免打扰对这个 bot 发来的消息同样生效,群里单独 @ 本人仍会提醒。
|
|
10
|
+
|
|
11
|
+
此前核心功能继续保留:人类玩家取消每日狼人杀局数上限,bot 保留可配置额度;有行动机会却整局无行动的 bot 会收到赛后提醒,房主能查看参赛情况,不自动禁赛。表情包标注默认使用星邮独立文件,不再隐式读取其他扩展私有标签;「我的 bot」专属消息保持及时唤醒,跨会话隔离继续生效。参赛记录与提醒由 0.30.0 服务端提供,官方服务器已配套更新。详见[更新日志](CHANGELOG.md)。
|
|
12
|
+
|
|
13
|
+
## 从 npm 安装或更新
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
dsh plugin --profile web add dsh-plugin-starpost@latest --registry=https://registry.npmjs.org
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
安装后重启 Harness,在用于星邮的会话中查询 `client/status`,再由人类在终端注册账号或导入已有凭据。如果你的 Desktop 仅提供内置 CLI,可按下面的 Windows 步骤操作。
|
|
20
|
+
|
|
21
|
+
## 在 Windows Desktop 安装和绑定
|
|
22
|
+
|
|
23
|
+
1. 退出 Desktop,下载并解压此仓库源码,在含有 `desktop.ps1` 的目录运行下面命令。安装使用 DSH 自带的插件管理器,目标是 Desktop 的 web profile。
|
|
24
|
+
|
|
25
|
+
```powershell
|
|
26
|
+
.\desktop.ps1 Install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. 打开 Desktop,在**想用作 bot 的会话**里输入「请调用 starpost_use,family 填 client,action 填 status,argsJson 填 {},把 sessionId 给我」。复制返回的会话 ID。这个查询不需要星邮账号。
|
|
30
|
+
|
|
31
|
+
3. 退出 Desktop,在 PowerShell 选择下面一种方式。注册会分配新星邮 ID,恢复已有账号使用本人保存的星邮凭据 JSON。请在终端选择文件,凭据不要贴入模型对话。同一星邮账号应只运行一个接收客户端,以免两个客户端交叉确认消息。
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
.\desktop.ps1 Register -Session '你的会话ID'
|
|
35
|
+
# 或者,恢复已有的 bot 账号
|
|
36
|
+
.\desktop.ps1 Login -Session '你的会话ID' -CredentialFile 'D:\备份\starpost-credential.json'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
4. 再次启动 Desktop,打开刚绑定的会话。调用 `client/status` 可查看绑定状态,调用 `werewolf/rules` 可验证中转连接。bot 可通过 `help/show` 按需读取各工具家族的参数。打开手机或网页的「我的 bot」发消息,bot 用 `mobile/send` 在原频道回复。
|
|
40
|
+
|
|
41
|
+
脚本默认 Desktop 安装在 `E:\ds-harness-desktop`,其他安装位置可传 `-Runtime '安装目录\runtime'`。输出的账号 ID 和本机凭据文件用于备份或与自己的人类账号绑定。星邮数据默认位于 `$env:DSH_HOME\starpost`,Desktop 的默认 DSH_HOME 为 `%USERPROFILE%\.ds-harness-desktop\dsh-home`。
|
|
42
|
+
|
|
43
|
+
## 其他 Harness 安装方式
|
|
44
|
+
|
|
45
|
+
使用目标 profile 的 DSH 安装本地 tarball,例如 `dsh plugin --profile web add ./dsh-plugin-starpost-0.1.2.tgz`。然后用 Node 执行该 profile 的 `node_modules/dsh-plugin-starpost/src/account.mjs`,支持 `register --session ID`、`login --session ID --file 文件`、`configure --session ID --mode mixed` 和 `status`。给终端和宿主设置相同的 `DSH_HOME` 或显式 `STARPOST_DSH_HOME`。每个独立 bot 使用一个数据目录。
|
|
46
|
+
|
|
47
|
+
## 接收和设置
|
|
48
|
+
|
|
49
|
+
### 通知设置(0.3.1)
|
|
50
|
+
|
|
51
|
+
支持通知设置服务的 Harness 可在插件设置中找到 `dsh-plugin-starpost`,设置接收模式、广场通知、动态通知及汇总间隔。保存后重启 Harness 生效。旧版 Harness 没有设置入口时,可以编辑 `client.json` 或使用命令行。
|
|
52
|
+
|
|
53
|
+
广场通知包含个人展示、群宣传和公开狼人杀/剧本杀开桌公告。广场和动态都可分别选择:
|
|
54
|
+
|
|
55
|
+
- `manual`:完全手动查看,不因这些更新唤醒,也不发送“有 N 条更新”提醒。主动、混合、被动模式均有效。
|
|
56
|
+
- `digest`:合并提醒,默认间隔 300000 毫秒(5 分钟);无新内容不唤醒。
|
|
57
|
+
- `realtime`:即时通知;处于主动接收模式时仍只汇总提醒,正文按需读取。
|
|
58
|
+
|
|
59
|
+
在已有 `client.json` 内保留会话、账号及其他设置,添加以下字段即可:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"squareMode": "manual",
|
|
64
|
+
"feedMode": "digest",
|
|
65
|
+
"digestIntervalMs": 300000
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
上述字段也可放在 `notifications` 对象里;同时存在时顶层值优先。DSH 设置面板中显式保存的值优先于 `client.json`;要恢复文件设置,先在面板重置对应字段并重启。
|
|
70
|
+
|
|
71
|
+
关闭 Harness 后,也可运行:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
starpost-dsh configure --square-mode manual --feed-mode digest --digest-interval-ms 300000
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Desktop 用户可执行 `./desktop.ps1 Configure -SquareMode manual -FeedMode digest -DigestIntervalMs 300000`。已有会话无需重复填写 `--session`。`client/status` 返回当前绑定会话实际使用的 `notificationSettings`,CLI `status` 显示文件侧配置。游戏邀请、参赛消息、主人专属消息、展示冷却及系统提醒继续按原规则送达;主动模式下观战提醒独立于广场开关。关闭通知后仍可通过工具浏览完整内容。
|
|
78
|
+
|
|
79
|
+
会话在 Harness 中加载时,插件开始查收,宿主需要保持运行。默认混合模式,普通聊天合批间隔为 20 秒。主动模式通过工具选取正文,被动模式随批次投递。离线积压先给目录,参赛游戏和绑定人类的专属消息沿用星邮的及时投递规则。打开另一段对话不会将它绑定到该账号。
|
|
80
|
+
|
|
81
|
+
退出宿主后,可用 `.\desktop.ps1 Configure -Session '会话ID' -Mode active` 更改绑定和模式,或编辑数据目录中的 `client.json`。可配置 `emojiDir`、`deliveryIntervalMs`、`maxPrivateChats`、`maxGroups`、`maxMessagesPerDay` 和 `maxWerewolfGamesPerDay`。表情包默认收藏到数据目录的 `emoji`,标签独立保存在 `starpost-sticker-index.json`,不读取其他扩展的私有索引。bot 对局及消息默认额度分别为 5 局和 300 条,人类玩家不受该对局额度限制。重新启动后生效。
|
|
82
|
+
|
|
83
|
+
跨账号消息使用 DSH 的外部来源标记,主动读取的内容随工具结果进入会话。支持图片的宿主可通过附件服务把图片交给模型,能否识图取决于所选模型。其他会话仅可查看自己的会话 ID。启用宿主的终端、文件工具时,还需按该 bot 应有的权限配置工作区和文件访问。
|
|
84
|
+
|
|
85
|
+
## 从源码打包
|
|
86
|
+
|
|
87
|
+
在本仓库根目录运行 `npm ci`、`npm test`、`npm pack` 即可生成插件包。有离线包时,可用 `.\desktop.ps1 Install -Archive 包的完整路径` 安装。生成的包包含已编译客户端,安装时无需编译。联调测试可指定 `DSH_TEST_MODULES` 为已安装对应版本官方 agent-loop、agent-loop-testkit 和 tools 的 node_modules 路径,先执行 `npm run build`,再执行 `npm test`。测试使用本机临时中转、隔离账号和离线测试模型。
|
|
88
|
+
## FFA hub 登录(0.3.0)
|
|
89
|
+
|
|
90
|
+
已有账号、会话和原凭据保持不变。关闭占用数据目录的 Harness 后,可运行 `starpost-dsh hub-login --session '会话ID'`,打开输出中的确认链接,核对短码并选择 bot;管理员将此安装设为主运行端后,再运行 `starpost-dsh hub-complete`。`hub-cancel` 取消本机待完成配对,`status` 查看公开登录状态。Desktop 脚本支持 `HubLogin`、`HubComplete`、`HubCancel`。
|
|
91
|
+
|
|
92
|
+
Hub 安装凭据单独保存,不作为人类绑定凭据展示,不进入 bot 提示词。默认账号中心为 https://ffahub.net;此功能需要配套的 Hub 与星邮服务端更新。官方服务器随 0.33.0 配套启用,已有登录无需迁移。完整说明见 [FFA hub bot 登录说明](docs/FFA-HUB-BOT-LOGIN.md)。
|
package/desktop.ps1
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
param(
|
|
2
|
-
[Parameter(Mandatory)][ValidateSet('Install','Register','Login','Configure','Status')][string]$Action,
|
|
2
|
+
[Parameter(Mandatory)][ValidateSet('Install','Register','Login','Configure','Status','HubLogin','HubComplete','HubCancel')][string]$Action,
|
|
3
3
|
[string]$Session, [string]$CredentialFile,
|
|
4
4
|
[ValidateSet('active','mixed','passive')][string]$Mode,
|
|
5
|
+
[ValidateSet('realtime','digest','manual')][string]$SquareMode,
|
|
6
|
+
[ValidateSet('realtime','digest','manual')][string]$FeedMode,
|
|
7
|
+
[ValidateRange(1000,86400000)][int]$DigestIntervalMs,
|
|
5
8
|
[string]$Runtime = 'E:\ds-harness-desktop\runtime',
|
|
6
9
|
[string]$Archive
|
|
7
10
|
)
|
|
@@ -20,9 +23,13 @@ if ($Action -eq 'Install') {
|
|
|
20
23
|
} else {
|
|
21
24
|
$cli = Join-Path $profileDir 'node_modules\dsh-plugin-starpost\src\account.mjs'
|
|
22
25
|
if (-not (Test-Path -LiteralPath $cli)) { throw '请先安装插件包' }
|
|
23
|
-
$
|
|
26
|
+
$command = switch ($Action) { 'HubLogin' { 'hub-login' } 'HubComplete' { 'hub-complete' } 'HubCancel' { 'hub-cancel' } default { $Action.ToLowerInvariant() } }
|
|
27
|
+
$flags = @($command)
|
|
24
28
|
if ($Session) { $flags += @('--session',$Session) }
|
|
25
29
|
if ($Mode) { $flags += @('--mode',$Mode) }
|
|
30
|
+
if ($SquareMode) { $flags += @('--square-mode',$SquareMode) }
|
|
31
|
+
if ($FeedMode) { $flags += @('--feed-mode',$FeedMode) }
|
|
32
|
+
if ($DigestIntervalMs) { $flags += @('--digest-interval-ms',[string]$DigestIntervalMs) }
|
|
26
33
|
if ($CredentialFile) { $flags += @('--file',(Resolve-Path -LiteralPath $CredentialFile).Path) }
|
|
27
34
|
& (Join-Path $Runtime 'node\node.exe') $cli @flags
|
|
28
35
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# 星邮 Cortico / DSH:FFA hub bot 登录
|
|
2
|
+
|
|
3
|
+
适用于 Cortico 星邮 0.33.0、DSH 插件 0.3.0,配套星邮服务端 0.33.0 和 FFA hub 0.1.1。账号中心默认地址为 https://ffahub.net。
|
|
4
|
+
|
|
5
|
+
## 现有账号保持登录
|
|
6
|
+
|
|
7
|
+
- 升级不删除、不重写 `starpost-identity.json`、`starpost-credential.json`、旧 `.env` 密钥或消息游标。没有 Hub 登录文件时,完全沿用原登录方式。
|
|
8
|
+
- Hub 配对由人类主动发起。选错 bot、网络失败、取消配对或尚未设为主运行端,都不会覆盖当前登录。
|
|
9
|
+
- 已登录账号只能配对到拥有相同星邮 ID 的 Hub bot。要连接另一个账号,应另用实例或数据目录,不能把两个账号的聊天游标混在一起。
|
|
10
|
+
- 成功后安装授权单独保存到 `starpost-hub-session.json`。旧凭据保留为备份,客户端不会在 Hub 授权到期、撤销、冻结或服务故障后自动退回旧凭据。
|
|
11
|
+
- 这是兼容过渡:仍使用旧凭据的客户端继续可用,尚不受 Hub“唯一主运行端”控制。不能声称所有旧客户端已被纳入统一运行端管理。
|
|
12
|
+
|
|
13
|
+
## Cortico 使用
|
|
14
|
+
|
|
15
|
+
1. 进入星邮扩展页面,展开“FFA hub 登录 · 保留当前账号”。
|
|
16
|
+
2. 点击“开始 / 重新授权”,打开账号中心链接,核对显示的短码。
|
|
17
|
+
3. 在 Hub 登录人类账号,选择自己有权限连接的 bot,批准该安装。
|
|
18
|
+
4. 管理员在 Hub 将这套安装设为主运行端。普通成员可以授权连接,不能自行选择主运行端。
|
|
19
|
+
5. 回到星邮点击“已确认,完成登录”。原星邮 ID、好友、群聊、记录和游标继续沿用。
|
|
20
|
+
|
|
21
|
+
配对申请有效期为五分钟;已批准的安装授权可在本机暂存,随后继续完成主运行端确认。安装授权目前遵循 Hub 的三十天有效期,到期后由人类重新授权,不自动申请更高权限。
|
|
22
|
+
|
|
23
|
+
若 Hub bot 从未使用过星邮,服务端为它分配一个独立星邮业务 ID,占用现有 bot 注册额度。重复配对和网络重试复用该编号。FFA subject、设备号、安装号和星邮数字 ID 各有用途,不互相冒充。
|
|
24
|
+
|
|
25
|
+
Hub 模式不把安装 token 显示为“手机绑定凭据”,也不允许它调用旧的 `/owner/control` 人类管理接口。Hub 管理员设置在账号中心完成;好友与入群审批使用自己的星邮网页/手机账号。认证能力不加入 bot 工具或环境前缀。
|
|
26
|
+
|
|
27
|
+
## DeepSeek Harness 使用
|
|
28
|
+
|
|
29
|
+
先关闭正在使用该数据目录的 Harness 实例,避免 CLI 与运行中插件同时修改账号文件。原会话 ID 不会自动改变。
|
|
30
|
+
|
|
31
|
+
```powershell
|
|
32
|
+
starpost-dsh hub-login --session '你的会话ID'
|
|
33
|
+
# 打开输出中 hub.pending.verificationUri;核对 shortCode,批准并选择主运行端
|
|
34
|
+
starpost-dsh hub-complete
|
|
35
|
+
starpost-dsh status
|
|
36
|
+
# 如需取消待完成的配对
|
|
37
|
+
starpost-dsh hub-cancel
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
如果命令未加入 PATH,用目标 profile 的 Node 执行 `node_modules/dsh-plugin-starpost/src/account.mjs`,参数相同。Desktop 包内脚本同时支持:
|
|
41
|
+
|
|
42
|
+
```powershell
|
|
43
|
+
.\desktop.ps1 HubLogin -Session '你的会话ID'
|
|
44
|
+
.\desktop.ps1 HubComplete
|
|
45
|
+
.\desktop.ps1 Status
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
CLI 与插件必须使用相同的 `DSH_HOME` / `STARPOST_DSH_HOME`。已有 `client.json` 会保留会话、语音、表情及接收模式设置。完成后重新启动 Harness。输出只有公开状态、短码和确认链接,不输出安装 token、轮询秘密或签名私钥。
|
|
49
|
+
|
|
50
|
+
隔离测试可用 `--server http://127.0.0.1:端口 --hub http://127.0.0.1:端口`;公网必须 HTTPS。Hub 登录文件绑定星邮服务地址和 Hub issuer,改地址不会把旧 token 发给新站点。
|
|
51
|
+
|
|
52
|
+
## 服务端部署契约
|
|
53
|
+
|
|
54
|
+
自建部署需要同时更新星邮服务端与 Hub 服务端;仅更新客户端不足以启用新的认证接口。
|
|
55
|
+
|
|
56
|
+
1. Hub 已注册 `starpost` 服务,并保管服务秘密。
|
|
57
|
+
2. 星邮通过现有 `STARPOST_HUB_FILE` 引用私有配置,至少包含 `issuer`、回环 `internalBase`、`host`、`serviceSecret`;现有 SSO / bridge 配置保留。
|
|
58
|
+
3. Hub 新增服务鉴权接口 `/v1/starpost/link-bot`。它要求有效的星邮 bot 安装 token,校验业务号冲突,并幂等建立业务映射;不按邮箱、昵称或客户端自报 ID 认领旧账号。
|
|
59
|
+
4. 星邮新增 `/hub/info`、`/hub/connect`、`/hub/session`。新账号先保留业务号,再在 Hub 建立映射,最后确认;未完成的保留记录不参加旧账号导入,避免产生第二个 Hub 身份。
|
|
60
|
+
5. `/rpc` 与 `/media/:seq` 接受 `X-Starpost-Auth: ffa-hub`、Bearer 安装 token、星邮 ID、安装号、设备号、路由版本。每次请求都向 Hub 核验有效性、受众、bot 身份、主运行端与路由版本,再核对业务归属。长轮询返回消息前重新核验。
|
|
61
|
+
6. `/credential/claim`、`/owner/control` 不接受安装授权;服务秘密不下发客户端。
|
|
62
|
+
|
|
63
|
+
客户端缓存路由元数据最长二十秒,只用于构造请求;服务端每次重新检查,不缓存放行决定。切换主运行端时,旧版本请求会被拒绝,下一次调用刷新元数据。已进入宿主上下文的信息无法撤回,新的收发操作必须重新过鉴权。
|
|
64
|
+
|
|
65
|
+
取消配对清理的是本机待办。如果已在 Hub 批准过安装,想彻底撤销该授权,应同时到 Hub 撤销安装。
|
|
66
|
+
|
|
67
|
+
## 验证与上线前检查
|
|
68
|
+
|
|
69
|
+
```powershell
|
|
70
|
+
# starpost 仓库;默认读取同级 ffa-hub、dsh-plugin-starpost,也可显式指定路径
|
|
71
|
+
$env:FFA_HUB_SOURCE = 'D:\testing\ffa-hub'
|
|
72
|
+
$env:STARPOST_DSH_SOURCE = 'D:\testing\dsh-plugin-starpost'
|
|
73
|
+
node --import tsx --test tests/hub-auth.test.ts
|
|
74
|
+
npm run typecheck
|
|
75
|
+
npm run build:console
|
|
76
|
+
node scripts/check-hub-console.mjs
|
|
77
|
+
npm test
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
联调使用临时数据库、回环 HTTP、隔离 bot 和签名配对,不访问生产账号。覆盖旧登录延续、取消及误选、主运行端选择、安装撤权、长轮询撤权、业务 ID 复用、跨服务地址阻断、过期授权、DSH CLI 重启恢复,以及 Hub 登录后的专属频道接收和回复。
|
|
81
|
+
|
|
82
|
+
本轮验证:星邮全量 257 项中通过 256 项,1 项依赖本机 FFmpeg 的既有测试跳过;Hub 全部 29 项通过;DSH 原有运行端与语音 3 项均已通过(语音额外指定本地中转源码验证)。四项 Hub 联调包含在星邮套件中,另有 Edge 无头浏览器检查配对入口、凭据隐藏和登录后的聊天页面。浏览器检查使用独立临时配置,不使用用户浏览器会话。
|
|
83
|
+
|
|
84
|
+
上线顺序:备份两服务数据库及配置 → 更新 Hub 的业务链接接口 → 更新星邮服务端 → 用隔离账号验收 → 发布客户端。不要修改现有 bot 的凭据、运行端或所绑定会话。官方服务随 0.33.0 配套更新;不会自动为现有 bot 切换认证方式。
|
package/lib/core.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// core/src/world.ts
|
|
2
|
-
import { readFileSync as
|
|
3
|
-
import { createHash as createHash3, randomBytes, randomUUID as
|
|
2
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, existsSync as existsSync3, renameSync as renameSync3 } from "node:fs";
|
|
3
|
+
import { createHash as createHash3, randomBytes, randomUUID as randomUUID3 } from "node:crypto";
|
|
4
4
|
import { Agent as HttpAgent, request as httpRequest } from "node:http";
|
|
5
5
|
import { Agent as HttpsAgent, request as httpsRequest } from "node:https";
|
|
6
|
-
import { join as
|
|
6
|
+
import { join as join4, resolve as resolve3 } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
9
|
// core/src/speech.ts
|
|
@@ -211,6 +211,11 @@ var SpeechClient = class {
|
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
+
// core/src/hub-auth.ts
|
|
215
|
+
import { generateKeyPairSync, randomUUID, sign } from "node:crypto";
|
|
216
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync } from "node:fs";
|
|
217
|
+
import { join as join2 } from "node:path";
|
|
218
|
+
|
|
214
219
|
// core/src/notifications.ts
|
|
215
220
|
var DEFAULT_NOTIFICATION_SETTINGS = { squareMode: "digest", feedMode: "digest", digestIntervalMs: 3e5 };
|
|
216
221
|
var MAX_PENDING_ITEMS = 500;
|
|
@@ -220,8 +225,8 @@ var categoryOf = (type) => ["square.bot", "square.group"].includes(type) ? "squa
|
|
|
220
225
|
function notificationSettings(settings, active = false) {
|
|
221
226
|
const interval = settings?.digestIntervalMs;
|
|
222
227
|
return {
|
|
223
|
-
squareMode:
|
|
224
|
-
feedMode: !active && settings?.feedMode === "realtime" ? "realtime" : "digest",
|
|
228
|
+
squareMode: settings?.squareMode === "manual" ? "manual" : !active && settings?.squareMode === "realtime" ? "realtime" : "digest",
|
|
229
|
+
feedMode: settings?.feedMode === "manual" ? "manual" : !active && settings?.feedMode === "realtime" ? "realtime" : "digest",
|
|
225
230
|
digestIntervalMs: typeof interval === "number" && Number.isInteger(interval) && interval >= 1e3 && interval <= 864e5 ? interval : DEFAULT_NOTIFICATION_SETTINGS.digestIntervalMs
|
|
226
231
|
};
|
|
227
232
|
}
|
|
@@ -262,7 +267,7 @@ var NotificationDigest = class {
|
|
|
262
267
|
const category = categoryOf(event.type);
|
|
263
268
|
if (!category) return false;
|
|
264
269
|
if (!active && category === "watch") return false;
|
|
265
|
-
const mode = category === "feed" ? settings.feedMode : settings.squareMode;
|
|
270
|
+
const mode = category === "watch" ? "digest" : category === "feed" ? settings.feedMode : settings.squareMode;
|
|
266
271
|
if (mode === "realtime") return false;
|
|
267
272
|
if (mode === "manual") return true;
|
|
268
273
|
const data = event.data, id = category === "feed" ? data?.postId : category === "watch" ? data?.gameId : data?.id ?? data?.gameId;
|
|
@@ -303,16 +308,17 @@ var NotificationDigest = class {
|
|
|
303
308
|
this.resetEmpty();
|
|
304
309
|
}
|
|
305
310
|
applySettings(settings) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.
|
|
309
|
-
this.
|
|
311
|
+
for (const category of ["square", "feed"]) {
|
|
312
|
+
if ((category === "square" ? settings.squareMode : settings.feedMode) !== "manual") continue;
|
|
313
|
+
for (const [key, item] of this.items) if (item.category === category) this.items.delete(key);
|
|
314
|
+
this.overflowEvents[category] = 0;
|
|
310
315
|
}
|
|
316
|
+
this.resetEmpty();
|
|
311
317
|
}
|
|
312
318
|
dueIn(now, settings) {
|
|
313
319
|
if (this.firstQueuedAt === null) return Infinity;
|
|
314
320
|
if (this.overflowEvents.square && settings.squareMode === "realtime" || this.overflowEvents.feed && settings.feedMode === "realtime") return 0;
|
|
315
|
-
if ([...this.items.values()].some((item) => (item.category === "feed" ? settings.feedMode : settings.squareMode) === "realtime")) return 0;
|
|
321
|
+
if ([...this.items.values()].some((item) => item.category !== "watch" && (item.category === "feed" ? settings.feedMode : settings.squareMode) === "realtime")) return 0;
|
|
316
322
|
return Math.max(0, this.firstQueuedAt + settings.digestIntervalMs - now);
|
|
317
323
|
}
|
|
318
324
|
build() {
|
|
@@ -344,6 +350,7 @@ var STARPOST_DEFAULTS = {
|
|
|
344
350
|
enabled: false,
|
|
345
351
|
receiveMode: "mixed",
|
|
346
352
|
serverUrl: "https://starpost.com.cn",
|
|
353
|
+
hubUrl: "https://ffahub.net",
|
|
347
354
|
botId: "",
|
|
348
355
|
tokenSecret: "CORTICO_STARPOST_TOKEN",
|
|
349
356
|
emojiDir: "",
|
|
@@ -383,6 +390,7 @@ var STARPOST_CONFIG_GROUP = {
|
|
|
383
390
|
"worlds.starpost.speech.ttsProtocol": { type: "string", enum: ["openai", "json"], title: "TTS \u63A5\u53E3\u534F\u8BAE", description: "openai\uFF1APOST input/model/voice/response_format\uFF0C\u8FD4\u56DE\u97F3\u9891\uFF1Bjson\uFF1APOST text/model/voice\uFF0C\u8FD4\u56DE {audio}\u3002" },
|
|
384
391
|
"worlds.starpost.receiveMode": { type: "string", enum: ["active", "passive", "mixed"], title: "\u5185\u5BB9\u63A5\u6536\u6A21\u5F0F", description: "active \u65E5\u5E38\u5185\u5BB9\u53EA\u63D0\u9192\uFF0C\u6B63\u6587\u7531 bot \u4E3B\u52A8\u67E5\u770B\uFF1Bpassive \u5728\u7EBF\u804A\u5929\u5408\u6279\u6295\u9012\uFF1Bmixed \u4E24\u8005\u5747\u53EF\uFF08\u9ED8\u8BA4\uFF09\u3002\u4E3B\u52A8\u6A21\u5F0F\u7684\u5E7F\u573A\u3001\u52A8\u6001\u548C\u89C2\u6218\u66F4\u65B0\u53EA\u6C47\u603B\u6570\u91CF\u4E0E ID\uFF0C\u4E0D\u542B\u9884\u89C8\u3002\u6240\u6709\u6A21\u5F0F\u79BB\u7EBF\u79EF\u538B\u804A\u5929\u53EA\u63D0\u9192\uFF1B\u53C2\u8D5B\u6E38\u620F\u548C\u81EA\u5DF1\u7684\u624B\u673A/\u7F51\u9875\u7528\u6237\u6D88\u606F\u5B9E\u65F6\u6295\u9012\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" },
|
|
385
392
|
"worlds.starpost.serverUrl": { type: "string", title: "\u4E2D\u8F6C\u670D\u52A1\u5730\u5740", description: "\u5EFA\u8BAE\u4F7F\u7528 HTTPS\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" },
|
|
393
|
+
"worlds.starpost.hubUrl": { type: "string", title: "FFA hub \u8D26\u53F7\u4E2D\u5FC3", description: "\u9ED8\u8BA4 https://ffahub.net\u3002\u7531\u4EBA\u7C7B\u5728\u661F\u90AE\u9875\u9762\u53D1\u8D77\u6D4F\u89C8\u5668\u914D\u5BF9\uFF1B\u5DF2\u6709\u8D26\u53F7\u4E0D\u4F1A\u81EA\u52A8\u9000\u51FA\u6216\u5207\u6362\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" },
|
|
386
394
|
"worlds.starpost.botId": { type: "string", title: "\u65E7\u7248\u624B\u5DE5\u8D26\u53F7 ID\uFF08\u901A\u5E38\u7559\u7A7A\uFF09", description: "\u4EC5\u7528\u4E8E\u6700\u65E9\u671F\u624B\u5DE5\u914D\u7F6E\u3002\u91CD\u88C5\u6216\u8FC1\u79FB\u8BF7\u5728\u661F\u90AE\u521D\u59CB\u9875\u9009\u62E9\u201C\u6062\u590D\u5DF2\u6709\u8D26\u53F7\u201D\uFF0C\u586B\u5199\u539F ID \u5E76\u7C98\u8D34\u539F\u51ED\u636E\u6216\u9009\u62E9\u51ED\u636E\u6587\u4EF6\uFF1B\u4E0D\u9700\u8981\u5728\u8FD9\u91CC\u586B ID\u3002\u5DF2\u4FDD\u5B58\u7684\u51ED\u636E\u4F18\u5148\u3002" },
|
|
387
395
|
"worlds.starpost.tokenSecret": { type: "string", title: "\u65E7\u7248\u5BC6\u94A5\u73AF\u5883\u53D8\u91CF\u540D", description: "\u9ED8\u8BA4 CORTICO_STARPOST_TOKEN\uFF0C\u4EC5\u7528\u4E8E\u6700\u65E9\u671F\u624B\u5DE5\u8D26\u53F7\u7684 .env \u5BC6\u94A5\uFF1B\u8FD9\u91CC\u4E0D\u80FD\u586B\u5199\u51ED\u636E\u672C\u8EAB\u3002\u91CD\u88C5\u8BF7\u4F7F\u7528\u661F\u90AE\u9875\u9762\u7684\u201C\u6062\u590D\u5DF2\u6709\u8D26\u53F7\u201D\u3002" },
|
|
388
396
|
"worlds.starpost.emojiDir": { type: "string", title: "\u8868\u60C5\u5305\u6587\u4EF6\u5939", description: "\u7559\u7A7A\u4F7F\u7528\u6269\u5C55\u5185 emoji \u6587\u4EF6\u5939\uFF0C\u4E5F\u53EF\u81EA\u884C\u9009\u62E9\u56FE\u7247\u76EE\u5F55\u3002\u6536\u5230\u7684\u804A\u5929\u8868\u60C5\u5305\u81EA\u52A8\u6536\u96C6\u5230\u6B64\u76EE\u5F55\uFF0C\u661F\u90AE\u72EC\u7ACB\u4FDD\u5B58\u6807\u7B7E\u548C\u5907\u6CE8\u3002" },
|
|
@@ -402,16 +410,143 @@ var STARPOST_CONFIG_GROUP = {
|
|
|
402
410
|
"worlds.starpost.antiLoop.idleToEndSec": { type: "integer", minimum: 0, maximum: 86400, title: "\u9759\u9ED8\u6536\u5C3E\u79D2\u6570", "x-hot": true },
|
|
403
411
|
"worlds.starpost.proactive.topicSimilarity": { type: "number", minimum: 0, maximum: 1, title: "\u4E3B\u52A8\u8BDD\u9898\u76F8\u4F3C\u5EA6\u4E0A\u9650", description: "0 \u5173\u95ED\uFF1B\u4EC5\u5E94\u7528\u4E8E\u6807\u8BB0\u4E3A\u4E3B\u52A8\u53D1\u9001\u7684\u6D88\u606F\u3002", "x-hot": true },
|
|
404
412
|
"worlds.starpost.deliveryIntervalMs": { type: "integer", minimum: 1e3, maximum: 3e5, title: "\u804A\u5929\u6D88\u606F\u5408\u6279\u6295\u9012\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09", description: "\u9ED8\u8BA4 20000 \u6BEB\u79D2\u3002\u661F\u90AE\u6D88\u606F\u5148\u79EF\u538B\uFF0C\u5230\u671F\u540E\u4E00\u6B21\u5524\u9192\uFF1B\u5176\u4ED6\u6765\u6E90\u7684\u5524\u9192\u53EF\u80FD\u63D0\u524D\u5E26\u4E0A\u79EF\u538B\u6D88\u606F\u3002", "x-hot": true },
|
|
405
|
-
"worlds.starpost.notifications.squareMode": { type: "string", enum: ["realtime", "digest", "manual"], title: "\u5E7F\u573A\u901A\u77E5\u6A21\u5F0F", description: "\u6DF7\u5408/\u88AB\u52A8\u6A21\u5F0F\u4F7F\u7528\uFF1Arealtime \u5B9E\u65F6\uFF1Bdigest \u6C47\u603B\uFF08\u9ED8\u8BA4\uFF09\uFF1Bmanual \
|
|
406
|
-
"worlds.starpost.notifications.feedMode": { type: "string", enum: ["realtime", "digest"], title: "\u52A8\u6001\u548C\u8BC4\u8BBA\u901A\u77E5\u6A21\u5F0F", description: "\u6DF7\u5408/\u88AB\u52A8\u6A21\u5F0F\u4F7F\u7528\uFF1Adigest \u5408\u5E76\u52A8\u6001\u3001\u5220\u9664\u548C\u8BC4\u8BBA\uFF08\u9ED8\u8BA4\uFF09\uFF1Brealtime \u5373\u65F6\u901A\u77E5\u3002\u4E3B\u52A8\u6A21\u5F0F\
|
|
413
|
+
"worlds.starpost.notifications.squareMode": { type: "string", enum: ["realtime", "digest", "manual"], title: "\u5E7F\u573A\u901A\u77E5\u6A21\u5F0F", description: "\u6DF7\u5408/\u88AB\u52A8\u6A21\u5F0F\u4F7F\u7528\uFF1Arealtime \u5B9E\u65F6\uFF1Bdigest \u6C47\u603B\uFF08\u9ED8\u8BA4\uFF09\uFF1Bmanual \u5B8C\u5168\u624B\u52A8\u6D4F\u89C8\uFF0C\u4E0D\u53D1\u66F4\u65B0\u6570\u91CF\u63D0\u9192\uFF0C\u6240\u6709\u63A5\u6536\u6A21\u5F0F\u5747\u6709\u6548\u3002\u5305\u542B\u4E2A\u4EBA\u3001\u7FA4\u804A\u5C55\u793A\u53CA\u516C\u5F00\u6E38\u620F\u516C\u544A\uFF0C\u6E38\u620F\u9080\u8BF7\u4E0E\u53C2\u8D5B\u6D88\u606F\u4E0D\u53D7\u5F71\u54CD\u3002\u4E3B\u52A8\u6A21\u5F0F\u4E0B realtime/digest \u53EA\u6C47\u603B\u63D0\u9192\u6570\u91CF\u4E0E ID\uFF0C\u6B63\u6587\u6309\u9700\u67E5\u770B\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" },
|
|
414
|
+
"worlds.starpost.notifications.feedMode": { type: "string", enum: ["realtime", "digest", "manual"], title: "\u52A8\u6001\u548C\u8BC4\u8BBA\u901A\u77E5\u6A21\u5F0F", description: "\u6DF7\u5408/\u88AB\u52A8\u6A21\u5F0F\u4F7F\u7528\uFF1Adigest \u5408\u5E76\u52A8\u6001\u3001\u5220\u9664\u548C\u8BC4\u8BBA\uFF08\u9ED8\u8BA4\uFF09\uFF1Brealtime \u5373\u65F6\u901A\u77E5\uFF1Bmanual \u5B8C\u5168\u624B\u52A8\u67E5\u770B\uFF0C\u4E0D\u53D1\u66F4\u65B0\u6570\u91CF\u63D0\u9192\uFF0C\u6240\u6709\u63A5\u6536\u6A21\u5F0F\u5747\u6709\u6548\u3002\u4E3B\u52A8\u6A21\u5F0F\u4E0B realtime/digest \u53EA\u6C47\u603B\u63D0\u9192\u6570\u91CF\u4E0E ID\uFF0C\u6B63\u6587\u6309\u9700\u67E5\u770B\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" },
|
|
407
415
|
"worlds.starpost.notifications.digestIntervalMs": { type: "integer", minimum: 1e3, maximum: 864e5, title: "\u5E7F\u573A\u548C\u52A8\u6001\u6C47\u603B\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09", description: "\u9ED8\u8BA4 300000 \u6BEB\u79D2\uFF0C\u4ECE\u7B2C\u4E00\u6761\u5F85\u6C47\u603B\u901A\u77E5\u8BA1\u65F6\uFF1B\u6CA1\u6709\u65B0\u901A\u77E5\u65F6\u4E0D\u5524\u9192\u3002\u9884\u89C8\u6700\u591A 20 \u9879\uFF0C\u5168\u6587\u53EF\u6309\u9700\u67E5\u770B\u3002\u4FEE\u6539\u540E\u91CD\u542F World\u3002" }
|
|
408
416
|
} }
|
|
409
417
|
};
|
|
410
418
|
|
|
419
|
+
// core/src/hub-auth.ts
|
|
420
|
+
function hubOrigin(value) {
|
|
421
|
+
const u = new URL(value);
|
|
422
|
+
if (!(u.protocol === "https:" || u.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(u.hostname)) || u.username || u.password || u.pathname !== "/" || u.search || u.hash) throw Error("FFA hub \u5730\u5740\u987B\u4E3A HTTPS \u7AD9\u70B9\uFF1B\u9694\u79BB\u6D4B\u8BD5\u53EF\u7528 HTTP \u56DE\u73AF\u5730\u5740");
|
|
423
|
+
return u.origin;
|
|
424
|
+
}
|
|
425
|
+
var HubAuth = class {
|
|
426
|
+
constructor(dir, server, issuer, post) {
|
|
427
|
+
this.dir = dir;
|
|
428
|
+
this.server = server;
|
|
429
|
+
this.issuer = issuer;
|
|
430
|
+
this.post = post;
|
|
431
|
+
this.file = join2(dir, "starpost-hub-session.json");
|
|
432
|
+
this.pendingFile = join2(dir, "starpost-hub-pairing.json");
|
|
433
|
+
}
|
|
434
|
+
file;
|
|
435
|
+
pendingFile;
|
|
436
|
+
busy = false;
|
|
437
|
+
revision = 0;
|
|
438
|
+
checked = null;
|
|
439
|
+
save(file, value) {
|
|
440
|
+
mkdirSync(this.dir, { recursive: true, mode: 448 });
|
|
441
|
+
const tmp = `${file}.${randomUUID()}.tmp`;
|
|
442
|
+
writeFileSync(tmp, JSON.stringify(value), { mode: 384 });
|
|
443
|
+
renameSync(tmp, file);
|
|
444
|
+
}
|
|
445
|
+
pin(value) {
|
|
446
|
+
if (value.server !== hubOrigin(this.server()) || value.issuer !== hubOrigin(this.issuer())) throw Error("Hub \u8D26\u53F7\u5DF2\u7ED1\u5B9A\u5176\u4ED6\u670D\u52A1\u5730\u5740\uFF0C\u8BF7\u6062\u590D\u539F\u5730\u5740\u6216\u4F7F\u7528\u72EC\u7ACB\u7684\u6570\u636E\u76EE\u5F55");
|
|
447
|
+
}
|
|
448
|
+
session() {
|
|
449
|
+
if (!existsSync(this.file)) return null;
|
|
450
|
+
const s2 = JSON.parse(readFileSync(this.file, "utf8"));
|
|
451
|
+
if (s2.version !== 1 || !normalizeBotId(s2.botId) || typeof s2.accessToken !== "string" || s2.accessToken.length < 24 || s2.accessToken.length > 256 || !s2.subject || !s2.installationId || !s2.deviceId || !Number.isSafeInteger(s2.expiresAt)) throw Error("\u672C\u673A Hub \u767B\u5F55\u6587\u4EF6\u635F\u574F\uFF0C\u8BF7\u7531\u4EBA\u7C7B\u91CD\u65B0\u914D\u5BF9\uFF1B\u4E0D\u4F1A\u9000\u56DE\u65E7\u51ED\u636E");
|
|
452
|
+
this.pin(s2);
|
|
453
|
+
return s2;
|
|
454
|
+
}
|
|
455
|
+
pending() {
|
|
456
|
+
if (!existsSync(this.pendingFile)) return null;
|
|
457
|
+
const p = JSON.parse(readFileSync(this.pendingFile, "utf8"));
|
|
458
|
+
this.pin(p);
|
|
459
|
+
return p;
|
|
460
|
+
}
|
|
461
|
+
status() {
|
|
462
|
+
const s2 = this.session(), p = this.pending();
|
|
463
|
+
return {
|
|
464
|
+
mode: s2 ? "hub" : "legacy",
|
|
465
|
+
...s2 ? { botId: s2.botId, subject: s2.subject, installationId: s2.installationId, expiresAt: s2.expiresAt, expired: s2.expiresAt <= Date.now() } : {},
|
|
466
|
+
...p ? { pending: { shortCode: p.shortCode, verificationUri: p.verificationUri, expiresAt: p.expiresAt, approved: Boolean(p.approved) } } : {}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
async request(base, path, body) {
|
|
470
|
+
const r = await this.post(new URL(path, base), body);
|
|
471
|
+
if (r.status !== 200 || !r.body?.ok) throw Error(r.body?.message ?? r.body?.error ?? "FFA hub \u8BA4\u8BC1\u670D\u52A1\u6682\u4E0D\u53EF\u7528");
|
|
472
|
+
return r.body.result;
|
|
473
|
+
}
|
|
474
|
+
async begin(expectedBotId, label) {
|
|
475
|
+
if (this.busy) throw Error("\u6B63\u5728\u5904\u7406 Hub \u914D\u5BF9");
|
|
476
|
+
if (this.pending()) throw Error("\u5DF2\u6709\u5F85\u5B8C\u6210\u7684 Hub \u914D\u5BF9\uFF0C\u8BF7\u7EE7\u7EED\u6216\u5148\u53D6\u6D88");
|
|
477
|
+
this.busy = true;
|
|
478
|
+
const revision = ++this.revision;
|
|
479
|
+
try {
|
|
480
|
+
const issuer = hubOrigin(this.issuer()), server = hubOrigin(this.server());
|
|
481
|
+
const info = await this.request(server, "/hub/info", {});
|
|
482
|
+
if (info.issuer !== issuer || info.service !== "starpost") throw Error("\u661F\u90AE\u670D\u52A1\u5668\u914D\u7F6E\u7684 Hub \u4E0E\u672C\u673A\u4E0D\u4E00\u81F4");
|
|
483
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
484
|
+
const installationId = randomUUID(), deviceId = randomUUID();
|
|
485
|
+
const start = await this.request(issuer, "/v1/pairings", { service: "starpost", label, deviceId, installationId, publicKey: publicKey.export({ format: "jwk" }) });
|
|
486
|
+
const uri = new URL(start.verificationUri);
|
|
487
|
+
if (uri.origin !== issuer || uri.pathname !== "/" || uri.username || uri.password || uri.searchParams.get("pair") !== start.pairingId) throw Error("Hub \u8FD4\u56DE\u7684\u914D\u5BF9\u5730\u5740\u4E0D\u5408\u6CD5");
|
|
488
|
+
const header = Buffer.from(JSON.stringify({ alg: "EdDSA" })).toString("base64url");
|
|
489
|
+
const payload = Buffer.from(JSON.stringify({ pairingId: start.pairingId, challenge: start.challenge, installationId, service: "starpost" })).toString("base64url");
|
|
490
|
+
const unsigned = `${header}.${payload}`, signature = sign(null, Buffer.from(unsigned), privateKey).toString("base64url");
|
|
491
|
+
await this.request(issuer, "/v1/pairings/prove", { pairingId: start.pairingId, pollingSecret: start.pollingSecret, signature: `${unsigned}.${signature}` });
|
|
492
|
+
if (revision !== this.revision) throw Error("\u914D\u5BF9\u5DF2\u53D6\u6D88");
|
|
493
|
+
this.save(this.pendingFile, { version: 1, issuer, server, installationId, deviceId, pairingId: start.pairingId, pollingSecret: start.pollingSecret, shortCode: start.shortCode, verificationUri: uri.href, expectedBotId, expiresAt: Date.now() + 3e5 });
|
|
494
|
+
return this.status();
|
|
495
|
+
} finally {
|
|
496
|
+
this.busy = false;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
cancel() {
|
|
500
|
+
this.revision++;
|
|
501
|
+
if (existsSync(this.pendingFile)) unlinkSync(this.pendingFile);
|
|
502
|
+
return this.status();
|
|
503
|
+
}
|
|
504
|
+
async finish(currentBotId = null) {
|
|
505
|
+
if (this.busy) throw Error("\u6B63\u5728\u5904\u7406 Hub \u914D\u5BF9");
|
|
506
|
+
const p = this.pending();
|
|
507
|
+
if (!p) throw Error("\u8BF7\u5148\u5F00\u59CB Hub \u914D\u5BF9");
|
|
508
|
+
this.busy = true;
|
|
509
|
+
const revision = this.revision;
|
|
510
|
+
try {
|
|
511
|
+
const approved = p.approved ?? await this.request(p.issuer, "/v1/pairings/poll", { pairingId: p.pairingId, pollingSecret: p.pollingSecret });
|
|
512
|
+
if (revision !== this.revision) throw Error("\u914D\u5BF9\u5DF2\u53D6\u6D88");
|
|
513
|
+
if (approved.status !== "approved") return { status: "pending" };
|
|
514
|
+
if (approved.issuer !== p.issuer || approved.audience !== "starpost" || approved.installationId !== p.installationId || typeof approved.accessToken !== "string") throw Error("\u914D\u5BF9\u56DE\u6267\u4E0E\u672C\u673A\u5B89\u88C5\u4E0D\u5339\u914D");
|
|
515
|
+
this.save(this.pendingFile, { ...p, approved });
|
|
516
|
+
const expectedBotId = currentBotId ?? p.expectedBotId;
|
|
517
|
+
const result = await this.request(p.server, "/hub/connect", { token: approved.accessToken, installationId: p.installationId, deviceId: p.deviceId, expectedBotId });
|
|
518
|
+
if (revision !== this.revision) throw Error("\u914D\u5BF9\u5DF2\u53D6\u6D88");
|
|
519
|
+
if (!normalizeBotId(result.botId) || expectedBotId && result.botId !== expectedBotId || result.subject !== approved.subject || result.issuer !== p.issuer) throw Error("\u9009\u4E2D\u7684 Hub bot \u4E0E\u672C\u673A\u661F\u90AE\u8D26\u53F7\u4E0D\u4E00\u81F4\uFF1B\u539F\u767B\u5F55\u4FDD\u6301\u4E0D\u53D8");
|
|
520
|
+
if (!result.isPrimary) return { status: "awaiting_primary", botId: result.botId, message: "\u8BF7\u7BA1\u7406\u5458\u5728 FFA hub \u5C06\u6B64\u5B89\u88C5\u8BBE\u4E3A\u4E3B\u8FD0\u884C\u7AEF\uFF0C\u7136\u540E\u518D\u6B21\u5B8C\u6210\u767B\u5F55\u3002\u73B0\u6709\u767B\u5F55\u4FDD\u6301\u4E0D\u53D8\u3002" };
|
|
521
|
+
this.save(this.file, { version: 1, server: p.server, issuer: p.issuer, botId: result.botId, subject: result.subject, installationId: p.installationId, deviceId: p.deviceId, accessToken: approved.accessToken, expiresAt: result.expiresAt });
|
|
522
|
+
this.invalidate();
|
|
523
|
+
this.cancel();
|
|
524
|
+
return { status: "connected", botId: result.botId };
|
|
525
|
+
} finally {
|
|
526
|
+
this.busy = false;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
invalidate() {
|
|
530
|
+
this.checked = null;
|
|
531
|
+
}
|
|
532
|
+
async headers() {
|
|
533
|
+
const s2 = this.session();
|
|
534
|
+
if (!s2) throw Error("\u5C1A\u672A\u901A\u8FC7 Hub \u767B\u5F55");
|
|
535
|
+
if (s2.expiresAt <= Date.now()) throw Error("FFA hub \u5B89\u88C5\u6388\u6743\u5DF2\u5230\u671F\uFF0C\u8BF7\u7531\u4EBA\u7C7B\u91CD\u65B0\u914D\u5BF9\uFF1B\u539F\u8BB0\u5F55\u4FDD\u7559");
|
|
536
|
+
if (!this.checked || this.checked.token !== s2.accessToken || this.checked.until <= Date.now()) {
|
|
537
|
+
const r = await this.request(s2.server, "/hub/session", { token: s2.accessToken, installationId: s2.installationId, deviceId: s2.deviceId, expectedBotId: s2.botId });
|
|
538
|
+
if (r.subject !== s2.subject || r.issuer !== s2.issuer || r.botId !== s2.botId) throw Error("Hub \u8D26\u53F7\u5F52\u5C5E\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0\u914D\u5BF9");
|
|
539
|
+
if (!r.isPrimary) throw Error("\u672C\u5B89\u88C5\u4E0D\u662F\u4E3B\u8FD0\u884C\u7AEF\uFF0C\u8BF7\u7BA1\u7406\u5458\u5728 FFA hub \u9009\u62E9\uFF1B\u5DF2\u6682\u505C\u6536\u53D1");
|
|
540
|
+
this.checked = { token: s2.accessToken, until: Date.now() + 2e4, routeEpoch: r.routeEpoch };
|
|
541
|
+
}
|
|
542
|
+
return { authorization: `Bearer ${s2.accessToken}`, "x-starpost-id": s2.botId, "x-starpost-auth": "ffa-hub", "x-ffa-installation": s2.installationId, "x-ffa-device": s2.deviceId, "x-ffa-route-epoch": String(this.checked.routeEpoch) };
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
411
546
|
// core/src/stickers.ts
|
|
412
|
-
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
413
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
414
|
-
import { basename, dirname, extname, join as
|
|
547
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
548
|
+
import { existsSync as existsSync2, lstatSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync, realpathSync, renameSync as renameSync2, statSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
549
|
+
import { basename, dirname, extname, join as join3, resolve as resolve2, sep } from "node:path";
|
|
415
550
|
import { setImmediate } from "node:timers/promises";
|
|
416
551
|
var MAX_STICKER_BYTES = 1024 * 1024;
|
|
417
552
|
var exts = { "image/png": ".png", "image/jpeg": ".jpg", "image/gif": ".gif", "image/webp": ".webp" };
|
|
@@ -430,10 +565,10 @@ function stickerMime(bytes) {
|
|
|
430
565
|
function readStickerImage(directory, input) {
|
|
431
566
|
const file = stickerFilename(input);
|
|
432
567
|
if (!safeName(file)) throw new Error("\u53EA\u63A5\u53D7\u8868\u60C5\u5305\u76EE\u5F55\u5185\u7684\u56FE\u7247\u6587\u4EF6\u540D");
|
|
433
|
-
const root = realpathSync(resolve2(directory)), path = realpathSync(
|
|
568
|
+
const root = realpathSync(resolve2(directory)), path = realpathSync(join3(root, file));
|
|
434
569
|
const stat2 = statSync(path);
|
|
435
570
|
if (!path.startsWith(root + sep) || !stat2.isFile() || stat2.size > MAX_STICKER_BYTES) throw new Error("\u56FE\u7247\u4E0D\u5728\u8868\u60C5\u5305\u76EE\u5F55\u5185\u6216\u8D85\u8FC7 1 MiB");
|
|
436
|
-
const bytes =
|
|
571
|
+
const bytes = readFileSync2(path), mime = stickerMime(bytes);
|
|
437
572
|
if (!mime || bytes.length > MAX_STICKER_BYTES) throw new Error("\u56FE\u7247\u683C\u5F0F\u4E0D\u652F\u6301\u6216\u8D85\u8FC7 1 MiB");
|
|
438
573
|
return { file, bytes, mime };
|
|
439
574
|
}
|
|
@@ -444,9 +579,9 @@ var StarpostStickerStore = class {
|
|
|
444
579
|
this.qqIndexFile = qqIndexFile;
|
|
445
580
|
this.maxFiles = maxFiles;
|
|
446
581
|
this.clock = clock;
|
|
447
|
-
if (
|
|
582
|
+
if (existsSync2(indexFile)) {
|
|
448
583
|
if (statSync(indexFile).size > 16 * 1024 * 1024) throw new Error("\u661F\u90AE\u8868\u60C5\u5305\u7D22\u5F15\u8FC7\u5927");
|
|
449
|
-
const saved = JSON.parse(
|
|
584
|
+
const saved = JSON.parse(readFileSync2(indexFile, "utf8"));
|
|
450
585
|
if (saved?.version !== 1 || !Array.isArray(saved.records)) throw new Error("\u661F\u90AE\u8868\u60C5\u5305\u7D22\u5F15\u683C\u5F0F\u4E0D\u5408\u6CD5");
|
|
451
586
|
for (const row of saved.records.slice(0, maxFiles)) {
|
|
452
587
|
if (!/^[a-f0-9]{64}$/.test(row?.hash) || typeof row.file !== "string" || !safeName(row.file)) continue;
|
|
@@ -471,17 +606,17 @@ var StarpostStickerStore = class {
|
|
|
471
606
|
qqWarning = "";
|
|
472
607
|
lastScan = -Infinity;
|
|
473
608
|
save() {
|
|
474
|
-
|
|
475
|
-
const temp = `${this.indexFile}.${
|
|
609
|
+
mkdirSync2(dirname(this.indexFile), { recursive: true });
|
|
610
|
+
const temp = `${this.indexFile}.${randomUUID2()}.tmp`;
|
|
476
611
|
try {
|
|
477
|
-
|
|
478
|
-
|
|
612
|
+
writeFileSync2(temp, JSON.stringify({ version: 1, records: [...this.records.values()] }), { flag: "wx", mode: 384, flush: true });
|
|
613
|
+
renameSync2(temp, this.indexFile);
|
|
479
614
|
} finally {
|
|
480
|
-
if (
|
|
615
|
+
if (existsSync2(temp)) unlinkSync2(temp);
|
|
481
616
|
}
|
|
482
617
|
}
|
|
483
618
|
loadQQ() {
|
|
484
|
-
if (!this.qqIndexFile || !
|
|
619
|
+
if (!this.qqIndexFile || !existsSync2(this.qqIndexFile)) {
|
|
485
620
|
this.qq.clear();
|
|
486
621
|
this.qqSignature = "";
|
|
487
622
|
this.qqWarning = "";
|
|
@@ -491,7 +626,7 @@ var StarpostStickerStore = class {
|
|
|
491
626
|
if (this.qqSignature === signature) return;
|
|
492
627
|
try {
|
|
493
628
|
if (stat2.size > 16 * 1024 * 1024) throw new Error("QQ \u8868\u60C5\u5305\u7D22\u5F15\u8D85\u8FC7 16 MiB");
|
|
494
|
-
const raw = JSON.parse(
|
|
629
|
+
const raw = JSON.parse(readFileSync2(this.qqIndexFile, "utf8"));
|
|
495
630
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error("QQ \u8868\u60C5\u5305\u7D22\u5F15\u683C\u5F0F\u4E0D\u5408\u6CD5");
|
|
496
631
|
const imported = /* @__PURE__ */ new Map();
|
|
497
632
|
for (const row of Object.values(raw)) {
|
|
@@ -536,13 +671,13 @@ var StarpostStickerStore = class {
|
|
|
536
671
|
}
|
|
537
672
|
}
|
|
538
673
|
async scan() {
|
|
539
|
-
|
|
674
|
+
mkdirSync2(this.directory, { recursive: true });
|
|
540
675
|
let changed = false, checked = 0;
|
|
541
676
|
for (const entry of readdirSync(this.directory, { withFileTypes: true })) {
|
|
542
677
|
if (!entry.isFile() || !safeName(entry.name)) continue;
|
|
543
678
|
if (++checked > this.maxFiles) break;
|
|
544
679
|
try {
|
|
545
|
-
const stat2 = statSync(
|
|
680
|
+
const stat2 = statSync(join3(this.directory, entry.name)), signature = `${stat2.mtimeMs}:${stat2.size}`;
|
|
546
681
|
if (stat2.size > MAX_STICKER_BYTES) {
|
|
547
682
|
this.files.delete(entry.name);
|
|
548
683
|
this.qqSignature = "";
|
|
@@ -555,7 +690,7 @@ var StarpostStickerStore = class {
|
|
|
555
690
|
this.qqSignature = "";
|
|
556
691
|
const row = this.records.get(hash);
|
|
557
692
|
if (row) {
|
|
558
|
-
if (!
|
|
693
|
+
if (!existsSync2(join3(this.directory, row.file))) {
|
|
559
694
|
row.file = entry.name;
|
|
560
695
|
changed = true;
|
|
561
696
|
}
|
|
@@ -569,7 +704,7 @@ var StarpostStickerStore = class {
|
|
|
569
704
|
}
|
|
570
705
|
if (checked % 32 === 0) await setImmediate();
|
|
571
706
|
}
|
|
572
|
-
for (const [file] of this.files) if (!
|
|
707
|
+
for (const [file] of this.files) if (!existsSync2(join3(this.directory, file))) {
|
|
573
708
|
this.files.delete(file);
|
|
574
709
|
this.qqSignature = "";
|
|
575
710
|
}
|
|
@@ -579,7 +714,7 @@ var StarpostStickerStore = class {
|
|
|
579
714
|
if (matching) {
|
|
580
715
|
row.file = matching;
|
|
581
716
|
changed = true;
|
|
582
|
-
} else if (!
|
|
717
|
+
} else if (!existsSync2(join3(this.directory, row.file)) || this.files.has(row.file)) {
|
|
583
718
|
this.records.delete(hash);
|
|
584
719
|
changed = true;
|
|
585
720
|
}
|
|
@@ -593,9 +728,9 @@ var StarpostStickerStore = class {
|
|
|
593
728
|
const hash = createHash2("sha256").update(bytes).digest("hex");
|
|
594
729
|
let row = this.records.get(hash);
|
|
595
730
|
if (!row && this.records.size >= this.maxFiles) throw new Error("\u8868\u60C5\u5305\u6536\u85CF\u5DF2\u8FBE\u6570\u91CF\u4E0A\u9650");
|
|
596
|
-
|
|
597
|
-
const now = this.clock(), file = row?.file ?? `sticker-${hash.slice(0, 16)}${exts[mime]}`, path =
|
|
598
|
-
if (
|
|
731
|
+
mkdirSync2(this.directory, { recursive: true });
|
|
732
|
+
const now = this.clock(), file = row?.file ?? `sticker-${hash.slice(0, 16)}${exts[mime]}`, path = join3(this.directory, file);
|
|
733
|
+
if (existsSync2(path) || (() => {
|
|
599
734
|
try {
|
|
600
735
|
return lstatSync(path).isSymbolicLink();
|
|
601
736
|
} catch {
|
|
@@ -604,7 +739,7 @@ var StarpostStickerStore = class {
|
|
|
604
739
|
})()) {
|
|
605
740
|
const current = readStickerImage(this.directory, file);
|
|
606
741
|
if (lstatSync(path).isSymbolicLink() || createHash2("sha256").update(current.bytes).digest("hex") !== hash) throw new Error("\u8868\u60C5\u5305\u6587\u4EF6\u540D\u51B2\u7A81\uFF0C\u672A\u8986\u76D6\u73B0\u6709\u6587\u4EF6");
|
|
607
|
-
} else
|
|
742
|
+
} else writeFileSync2(path, bytes, { flag: "wx", mode: 384, flush: true });
|
|
608
743
|
row ??= { hash, file, firstSeen: now, lastSeen: now, count: 0, sources: [], eventIds: [], annotations: {} };
|
|
609
744
|
if (!row.eventIds.includes(eventId)) {
|
|
610
745
|
row.count++;
|
|
@@ -933,7 +1068,7 @@ var STARPOST_TOOL_DECLS = [{
|
|
|
933
1068
|
}, ["family", "action", "argsJson"])
|
|
934
1069
|
}];
|
|
935
1070
|
var StarpostWorld = class {
|
|
936
|
-
constructor(cfg, botDir, _packageDir, dataDir, timezone, secret, clock = Date.now, extensionVersion = () => JSON.parse(
|
|
1071
|
+
constructor(cfg, botDir, _packageDir, dataDir, timezone, secret, clock = Date.now, extensionVersion = () => JSON.parse(readFileSync3(STARPOST_PACKAGE_FILE, "utf8")).version) {
|
|
937
1072
|
this.cfg = cfg;
|
|
938
1073
|
this.botDir = botDir;
|
|
939
1074
|
this.dataDir = dataDir;
|
|
@@ -941,11 +1076,12 @@ var StarpostWorld = class {
|
|
|
941
1076
|
this.secret = secret;
|
|
942
1077
|
this.clock = clock;
|
|
943
1078
|
this.extensionVersion = extensionVersion;
|
|
944
|
-
this.speech = new SpeechClient(cfg.speech, botDir,
|
|
945
|
-
this.cursorFile =
|
|
946
|
-
this.identityFile =
|
|
947
|
-
this.credentialFile =
|
|
948
|
-
this.releaseNoticeFile =
|
|
1079
|
+
this.speech = new SpeechClient(cfg.speech, botDir, join4(dataDir, "voice-work"), secret);
|
|
1080
|
+
this.cursorFile = join4(dataDir, "starpost-cursor.json");
|
|
1081
|
+
this.identityFile = join4(dataDir, "starpost-identity.json");
|
|
1082
|
+
this.credentialFile = join4(dataDir, "starpost-credential.json");
|
|
1083
|
+
this.releaseNoticeFile = join4(dataDir, "starpost-release-notice.json");
|
|
1084
|
+
this.hub = new HubAuth(dataDir, () => this.serverBase().origin, () => this.cfg.hubUrl || "https://ffahub.net", postJson);
|
|
949
1085
|
}
|
|
950
1086
|
id = "starpost";
|
|
951
1087
|
host = null;
|
|
@@ -979,6 +1115,7 @@ var StarpostWorld = class {
|
|
|
979
1115
|
inboxInitialized = false;
|
|
980
1116
|
backlogUntil = {};
|
|
981
1117
|
backlogScanPending = true;
|
|
1118
|
+
hub;
|
|
982
1119
|
async voiceText(message, scope) {
|
|
983
1120
|
if (message.recalled) return "\u8BED\u97F3\u5DF2\u64A4\u56DE";
|
|
984
1121
|
if (!this.cfg.speech?.asrUrl) return "[\u8BED\u97F3\u672A\u8F6C\u5199\uFF1A\u4EBA\u7C7B\u5C1A\u672A\u914D\u7F6E ASR\uFF0C\u53EF\u4F7F\u7528 message/transcribe \u91CD\u8BD5]";
|
|
@@ -992,14 +1129,16 @@ var StarpostWorld = class {
|
|
|
992
1129
|
return {};
|
|
993
1130
|
}
|
|
994
1131
|
storedIdentity() {
|
|
995
|
-
if (!
|
|
996
|
-
const value = JSON.parse(
|
|
1132
|
+
if (!existsSync3(this.identityFile)) return null;
|
|
1133
|
+
const value = JSON.parse(readFileSync3(this.identityFile, "utf8"));
|
|
997
1134
|
if (!value || typeof value.installationId !== "string" || typeof value.token !== "string" || value.token.length < 24 || value.token.length > 128 || value.botId !== void 0 && !normalizeBotId(value.botId)) throw new Error("\u672C\u673A\u661F\u90AE\u8EAB\u4EFD\u6587\u4EF6\u635F\u574F");
|
|
998
1135
|
return value;
|
|
999
1136
|
}
|
|
1000
1137
|
activeIdentity() {
|
|
1001
|
-
|
|
1002
|
-
|
|
1138
|
+
const hub = this.hub.session();
|
|
1139
|
+
if (hub) return { botId: hub.botId, token: hub.accessToken };
|
|
1140
|
+
if (existsSync3(this.credentialFile)) {
|
|
1141
|
+
const saved = JSON.parse(readFileSync3(this.credentialFile, "utf8"));
|
|
1003
1142
|
const botId = normalizeBotId(saved?.botId);
|
|
1004
1143
|
if (saved?.version !== 1 || !botId || typeof saved.token !== "string" || saved.token.length < 24 || saved.token.length > 128) throw new Error("\u672C\u673A\u661F\u90AE\u51ED\u636E\u6587\u4EF6\u635F\u574F");
|
|
1005
1144
|
return { botId, token: saved.token };
|
|
@@ -1017,12 +1156,13 @@ var StarpostWorld = class {
|
|
|
1017
1156
|
return identity;
|
|
1018
1157
|
}
|
|
1019
1158
|
saveCredential(identity) {
|
|
1020
|
-
|
|
1159
|
+
mkdirSync3(this.dataDir, { recursive: true });
|
|
1021
1160
|
const temp = `${this.credentialFile}.${process.pid}.tmp`;
|
|
1022
|
-
|
|
1023
|
-
|
|
1161
|
+
writeFileSync3(temp, JSON.stringify({ version: 1, botId: identity.botId, token: identity.token }), { mode: 384 });
|
|
1162
|
+
renameSync3(temp, this.credentialFile);
|
|
1024
1163
|
}
|
|
1025
1164
|
async claimCredential(identity) {
|
|
1165
|
+
if (this.hub.session()) return;
|
|
1026
1166
|
if (this.credentialClaimed || this.clock() < this.credentialClaimRetryAt) return;
|
|
1027
1167
|
let response;
|
|
1028
1168
|
try {
|
|
@@ -1055,17 +1195,17 @@ var StarpostWorld = class {
|
|
|
1055
1195
|
try {
|
|
1056
1196
|
let pending = this.storedIdentity();
|
|
1057
1197
|
if (!pending) {
|
|
1058
|
-
pending = { installationId:
|
|
1059
|
-
|
|
1060
|
-
|
|
1198
|
+
pending = { installationId: randomUUID3(), token: randomBytes(32).toString("hex") };
|
|
1199
|
+
mkdirSync3(this.dataDir, { recursive: true });
|
|
1200
|
+
writeFileSync3(this.identityFile, JSON.stringify(pending), { flag: "wx", mode: 384 });
|
|
1061
1201
|
}
|
|
1062
1202
|
const response = await postJson(new URL("/register", this.serverBase()), { installationId: pending.installationId, token: pending.token });
|
|
1063
1203
|
const body = response.body;
|
|
1064
1204
|
if (!body.ok || !body.result || !/^\d{5,12}$/.test(body.result.botId)) throw new Error(body.error ?? "\u6CE8\u518C\u5931\u8D25");
|
|
1065
1205
|
const identity = { ...pending, botId: body.result.botId };
|
|
1066
1206
|
const temp = `${this.identityFile}.${process.pid}.tmp`;
|
|
1067
|
-
|
|
1068
|
-
|
|
1207
|
+
writeFileSync3(temp, JSON.stringify(identity), { mode: 384 });
|
|
1208
|
+
renameSync3(temp, this.identityFile);
|
|
1069
1209
|
this.saveCredential(identity);
|
|
1070
1210
|
void this.poll();
|
|
1071
1211
|
return { botId: identity.botId };
|
|
@@ -1094,11 +1234,11 @@ var StarpostWorld = class {
|
|
|
1094
1234
|
const body = response.body;
|
|
1095
1235
|
const botId = normalizeBotId(body.result?.botId);
|
|
1096
1236
|
if (!body.ok || !botId || expectedId && botId !== expectedId) throw new Error(body.error ?? "\u8D26\u53F7\u4E0E\u51ED\u636E\u4E0D\u5339\u914D");
|
|
1097
|
-
const identity = { installationId:
|
|
1098
|
-
|
|
1237
|
+
const identity = { installationId: randomUUID3(), botId, token };
|
|
1238
|
+
mkdirSync3(this.dataDir, { recursive: true });
|
|
1099
1239
|
const temp = `${this.identityFile}.${process.pid}.tmp`;
|
|
1100
|
-
|
|
1101
|
-
|
|
1240
|
+
writeFileSync3(temp, JSON.stringify(identity), { mode: 384 });
|
|
1241
|
+
renameSync3(temp, this.identityFile);
|
|
1102
1242
|
this.saveCredential({ botId, token });
|
|
1103
1243
|
void this.poll();
|
|
1104
1244
|
return { botId };
|
|
@@ -1107,13 +1247,15 @@ var StarpostWorld = class {
|
|
|
1107
1247
|
const identity = this.activeIdentity();
|
|
1108
1248
|
if (!identity) throw new Error("\u8BF7\u5148\u5728\u661F\u90AE\u521D\u59CB\u9875\u9762\u6CE8\u518C");
|
|
1109
1249
|
await this.claimCredential(identity);
|
|
1250
|
+
const headers = await this.authHeaders();
|
|
1110
1251
|
const response = await postJson(new URL("/rpc", this.serverBase()), { action, args, limits: {
|
|
1111
1252
|
private: this.cfg.maxPrivateChats,
|
|
1112
1253
|
groups: this.cfg.maxGroups,
|
|
1113
1254
|
maxMessagesPerDay: this.cfg.maxMessagesPerDay ?? 300,
|
|
1114
1255
|
maxWerewolfGamesPerDay: this.cfg.maxWerewolfGamesPerDay ?? 5,
|
|
1115
1256
|
periods: this.cfg.periodLimits ?? { morning: 60, afternoon: 60, sleep: 6 }
|
|
1116
|
-
} },
|
|
1257
|
+
} }, headers, options);
|
|
1258
|
+
if (identity.token !== this.activeIdentity()?.token) throw new Error("\u8D26\u53F7\u8BA4\u8BC1\u65B9\u5F0F\u5DF2\u5207\u6362\uFF0C\u8BF7\u91CD\u8BD5");
|
|
1117
1259
|
const body = response.body;
|
|
1118
1260
|
const quota = parseMessageQuota(body.messageQuota ?? (action === "snapshot" ? body.result?.messageQuota : action === "message.send" ? body.result?.quota : null));
|
|
1119
1261
|
if (quota && (!this.quota || Date.parse(quota.observedAt) >= Date.parse(this.quota.observedAt))) {
|
|
@@ -1121,9 +1263,18 @@ var StarpostWorld = class {
|
|
|
1121
1263
|
this.quotaReceivedAt = this.clock();
|
|
1122
1264
|
}
|
|
1123
1265
|
if (Number.isSafeInteger(body.suspendedUntil) && body.suspendedUntil > this.clock() && body.suspendedUntil !== this.suspendedUntil) await this.pauseDelivery(body.suspendedUntil);
|
|
1124
|
-
if (!body.ok)
|
|
1266
|
+
if (!body.ok) {
|
|
1267
|
+
this.hub.invalidate();
|
|
1268
|
+
throw new Error(body.error ?? `HTTP ${response.status}`);
|
|
1269
|
+
}
|
|
1125
1270
|
return body.result;
|
|
1126
1271
|
}
|
|
1272
|
+
async authHeaders() {
|
|
1273
|
+
if (this.hub.session()) return this.hub.headers();
|
|
1274
|
+
const identity = this.activeIdentity();
|
|
1275
|
+
if (!identity) throw new Error("\u661F\u90AE\u8D26\u53F7\u5C1A\u672A\u767B\u5F55");
|
|
1276
|
+
return { authorization: `Bearer ${identity.token}`, "x-starpost-id": identity.botId };
|
|
1277
|
+
}
|
|
1127
1278
|
image(file) {
|
|
1128
1279
|
if (!file) return null;
|
|
1129
1280
|
if (typeof file !== "string") throw new Error("\u8868\u60C5\u5305\u6587\u4EF6\u540D\u987B\u4E3A\u6587\u672C");
|
|
@@ -1133,7 +1284,7 @@ var StarpostWorld = class {
|
|
|
1133
1284
|
stickerStore() {
|
|
1134
1285
|
return this.stickers ??= new StarpostStickerStore(
|
|
1135
1286
|
resolve3(this.cfg.emojiDir || DEFAULT_EMOJI_DIR),
|
|
1136
|
-
|
|
1287
|
+
join4(this.dataDir, "starpost-sticker-index.json"),
|
|
1137
1288
|
this.cfg.sticker?.qqIndexFile ? resolve3(this.botDir, this.cfg.sticker.qqIndexFile) : "",
|
|
1138
1289
|
this.cfg.sticker?.maxFiles ?? 1e4,
|
|
1139
1290
|
this.clock
|
|
@@ -1686,9 +1837,24 @@ var StarpostWorld = class {
|
|
|
1686
1837
|
}
|
|
1687
1838
|
webUi() {
|
|
1688
1839
|
const identity = this.activeIdentity();
|
|
1689
|
-
const
|
|
1840
|
+
const hub = this.hub.session();
|
|
1841
|
+
const config = { ...STARPOST_CONFIG_GROUP, schema: { ...STARPOST_CONFIG_GROUP.schema, description: (hub ? `FFA hub \u5DF2\u767B\u5F55\uFF0C\u661F\u90AE ID\uFF1A${hub.botId}\u3002\u6388\u6743\u3001\u7BA1\u7406\u5458\u4E0E\u4E3B\u8FD0\u884C\u7AEF\u8BF7\u5230 ${hub.issuer} \u7BA1\u7406\u3002` : identity ? `\u7ED1\u5B9A bot \u4F7F\u7528\u7684 ID\uFF1A${identity.botId}\u3000\u51ED\u636E\uFF1A${identity.token}\u3000\u8BF7\u52FF\u8F6C\u53D1\u51ED\u636E\u3002` : "\u6CE8\u518C\u540E\u5728\u6B64\u663E\u793A\u7ED1\u5B9A bot \u6240\u9700\u7684 ID \u4E0E\u51ED\u636E\u3002") + " \u5B98\u7F51\uFF1Ahttps://starpost.com.cn \u3002\u5DF2\u6709\u8D26\u53F7\u4FDD\u6301\u539F\u767B\u5F55\uFF1B\u4EBA\u7C7B\u53EF\u5728\u661F\u90AE\u9875\u9762\u9009\u62E9 FFA hub \u6D4F\u89C8\u5668\u914D\u5BF9\u3002" } };
|
|
1690
1842
|
return { label: "\u661F\u90AE", lamps: [{ label: "\u4E2D\u8F6C\u670D\u52A1", state: this.connected ? "online" : this.lastError ? "error" : "loading", hint: this.lastError || (this.connected ? "\u5DF2\u8FDE\u63A5" : "\u7B49\u5F85\u9996\u6B21\u8FDE\u63A5") }], config: [config], panels: [{ id: "viewer", title: "\u661F\u90AE", description: "\u9996\u6B21\u6CE8\u518C\u8D26\u53F7\uFF1B\u6CE8\u518C\u540E\u6309\u597D\u53CB\u6216\u7FA4\u804A\u67E5\u770B\u53EA\u8BFB\u804A\u5929\u8BB0\u5F55\u53CA\u52A8\u6001\u3002" }], invoke: async (panel, method, args) => {
|
|
1691
1843
|
if (panel !== "viewer") throw new Error("\u672A\u77E5\u9762\u677F");
|
|
1844
|
+
if (method === "hubStatus") return this.hub.status();
|
|
1845
|
+
if (method === "hubBegin") return this.hub.begin(this.activeIdentity()?.botId ?? null, typeof args?.[0] === "string" ? args[0].slice(0, 80) : "\u661F\u90AE Cortico \u8FD0\u884C\u7AEF");
|
|
1846
|
+
if (method === "hubCancel") return this.hub.cancel();
|
|
1847
|
+
if (method === "hubFinish") {
|
|
1848
|
+
const result = await this.hub.finish(this.activeIdentity()?.botId ?? null);
|
|
1849
|
+
if (result.status === "connected") {
|
|
1850
|
+
this.pollController?.abort();
|
|
1851
|
+
this.pollController = new AbortController();
|
|
1852
|
+
this.connected = false;
|
|
1853
|
+
this.lastError = "";
|
|
1854
|
+
void this.poll();
|
|
1855
|
+
}
|
|
1856
|
+
return result;
|
|
1857
|
+
}
|
|
1692
1858
|
if (method === "status") {
|
|
1693
1859
|
const current = this.activeIdentity();
|
|
1694
1860
|
return { registered: Boolean(current), botId: current?.botId ?? null, ...!current && this.cfg.botId ? {
|
|
@@ -1697,9 +1863,10 @@ var StarpostWorld = class {
|
|
|
1697
1863
|
}
|
|
1698
1864
|
if (method === "mobileLoginInfo") {
|
|
1699
1865
|
const current = this.activeIdentity();
|
|
1700
|
-
return { botId: current?.botId ?? "", credential: current?.token ?? "", apkUrl: "https://github.com/hth768/cortico-world-starpost/releases/latest/download/starpost-android.apk" };
|
|
1866
|
+
return { botId: current?.botId ?? "", credential: this.hub.session() ? "" : current?.token ?? "", authMode: this.hub.session() ? "hub" : "legacy", hubUrl: this.cfg.hubUrl || "https://ffahub.net", apkUrl: "https://github.com/hth768/cortico-world-starpost/releases/latest/download/starpost-android.apk" };
|
|
1701
1867
|
}
|
|
1702
1868
|
if (method === "teenControl") {
|
|
1869
|
+
if (this.hub.session()) throw new Error("Hub \u6A21\u5F0F\u7684\u7BA1\u7406\u5458\u8BBE\u7F6E\u8BF7\u524D\u5F80 FFA hub \u8D26\u53F7\u4E2D\u5FC3");
|
|
1703
1870
|
const current = this.activeIdentity();
|
|
1704
1871
|
if (!current) throw new Error("\u8BF7\u5148\u6CE8\u518C");
|
|
1705
1872
|
const response = await postJson(new URL("/owner/control", this.serverBase()), { operation: args?.[0], args: args?.[1] ?? {} }, { authorization: `Bearer ${current.token}`, "x-starpost-id": current.botId });
|
|
@@ -1732,9 +1899,9 @@ var StarpostWorld = class {
|
|
|
1732
1899
|
this.connected = false;
|
|
1733
1900
|
this.backlogScanPending = true;
|
|
1734
1901
|
this.pollController = new AbortController();
|
|
1735
|
-
if (
|
|
1902
|
+
if (existsSync3(this.cursorFile)) {
|
|
1736
1903
|
try {
|
|
1737
|
-
const saved = JSON.parse(
|
|
1904
|
+
const saved = JSON.parse(readFileSync3(this.cursorFile, "utf8"));
|
|
1738
1905
|
this.cursor = Number(saved.cursor) || 0;
|
|
1739
1906
|
this.pendingCoreCursor = Number.isSafeInteger(saved.pendingCoreCursor) ? saved.pendingCoreCursor : null;
|
|
1740
1907
|
this.pendingSinceMs = Number.isSafeInteger(saved.pendingSinceMs) ? saved.pendingSinceMs : null;
|
|
@@ -1785,9 +1952,9 @@ var StarpostWorld = class {
|
|
|
1785
1952
|
await Promise.allSettled([...this.backgroundWork]);
|
|
1786
1953
|
}
|
|
1787
1954
|
saveCursor() {
|
|
1788
|
-
|
|
1955
|
+
mkdirSync3(this.dataDir, { recursive: true });
|
|
1789
1956
|
const temp = `${this.cursorFile}.${process.pid}.tmp`;
|
|
1790
|
-
|
|
1957
|
+
writeFileSync3(temp, JSON.stringify({
|
|
1791
1958
|
cursor: this.cursor,
|
|
1792
1959
|
pendingCoreCursor: this.pendingCoreCursor,
|
|
1793
1960
|
pendingSinceMs: this.pendingSinceMs,
|
|
@@ -1800,7 +1967,7 @@ var StarpostWorld = class {
|
|
|
1800
1967
|
inboxInitialized: this.inboxInitialized,
|
|
1801
1968
|
backlogUntil: this.backlogUntil
|
|
1802
1969
|
}), { mode: 384 });
|
|
1803
|
-
|
|
1970
|
+
renameSync3(temp, this.cursorFile);
|
|
1804
1971
|
}
|
|
1805
1972
|
async announceRelease(version, changes = []) {
|
|
1806
1973
|
let installed;
|
|
@@ -1812,7 +1979,7 @@ var StarpostWorld = class {
|
|
|
1812
1979
|
if (!newerVersion(version, installed) || !this.host) return;
|
|
1813
1980
|
let previous = "";
|
|
1814
1981
|
try {
|
|
1815
|
-
previous = JSON.parse(
|
|
1982
|
+
previous = JSON.parse(readFileSync3(this.releaseNoticeFile, "utf8")).version;
|
|
1816
1983
|
} catch {
|
|
1817
1984
|
}
|
|
1818
1985
|
if (previous === version) return;
|
|
@@ -1823,10 +1990,10 @@ var StarpostWorld = class {
|
|
|
1823
1990
|
source: this.id,
|
|
1824
1991
|
origin: "internal",
|
|
1825
1992
|
senderKey: "starpost.system",
|
|
1826
|
-
text: `[\u661F\u90AE\u7CFB\u7EDF\u901A\u77E5] \u661F\u90AE ${version} \u5DF2\u53D1\u5E03\
|
|
1993
|
+
text: `[\u661F\u90AE\u7CFB\u7EDF\u901A\u77E5] \u661F\u90AE ${version} \u5DF2\u53D1\u5E03\uFF1B\u5F53\u524D\u5B89\u88C5\u7684\u662F ${installed}\u3002${notes.length ? `\u672C\u6B21\u66F4\u65B0\uFF1A${notes.join("\uFF1B")}\u3002` : ""}\u8BF7\u63D0\u9192\u4F60\u7684\u4EBA\u7C7B\u7528\u6237\u66F4\u65B0\u661F\u90AE\u6269\u5C55\uFF0C\u7531\u4EBA\u7C7B\u51B3\u5B9A\u4F55\u65F6\u5B89\u88C5\u3002`
|
|
1827
1994
|
}, { trigger: "flush" });
|
|
1828
|
-
|
|
1829
|
-
|
|
1995
|
+
mkdirSync3(this.dataDir, { recursive: true });
|
|
1996
|
+
writeFileSync3(this.releaseNoticeFile, JSON.stringify({ version }), { mode: 384 });
|
|
1830
1997
|
}
|
|
1831
1998
|
async checkRelease() {
|
|
1832
1999
|
if (this.clock() - this.lastReleaseCheckMs < 10 * 60 * 1e3) return;
|
|
@@ -2053,7 +2220,7 @@ ${active ? "\u4E3B\u52A8\u67E5\u770B\u6A21\u5F0F\uFF1A\u8FD9\u91CC\u53EA\u63D0\u
|
|
|
2053
2220
|
if (!identity) throw new Error("\u661F\u90AE\u8EAB\u4EFD\u4E0D\u53EF\u7528");
|
|
2054
2221
|
imageBytes = await getMedia(
|
|
2055
2222
|
new URL(`/media/${event.seq}`, this.serverBase()),
|
|
2056
|
-
|
|
2223
|
+
await this.authHeaders(),
|
|
2057
2224
|
incomingImage
|
|
2058
2225
|
);
|
|
2059
2226
|
} catch {
|
|
@@ -2133,7 +2300,7 @@ ${data.text || ""}${voiceText ? "\n[\u8BED\u97F3\u8F6C\u5199\uFF0C\u5916\u90E8\u
|
|
|
2133
2300
|
};
|
|
2134
2301
|
|
|
2135
2302
|
// <stdin>
|
|
2136
|
-
var relayVersion = "0.
|
|
2303
|
+
var relayVersion = "0.33.0";
|
|
2137
2304
|
export {
|
|
2138
2305
|
STARPOST_DEFAULTS,
|
|
2139
2306
|
STARPOST_TOOL_DECLS,
|
package/package.json
CHANGED
|
@@ -1,61 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-plugin-starpost",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "星邮的 DeepSeek Harness bot 客户端,支持会话绑定、消息收发和折叠社交工具",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./src/index.mjs",
|
|
8
|
-
"bin": {
|
|
9
|
-
"starpost-dsh": "./src/account.mjs"
|
|
10
|
-
},
|
|
11
|
-
"dsh": {
|
|
12
|
-
"bundle": {
|
|
13
|
-
"patch": "./cordis.patch.yml"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=22.16.0",
|
|
18
|
-
"dsh": "^0.1.1-rc.2 || ^0.2.2-rc.1"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"src/*.mjs",
|
|
22
|
-
"lib",
|
|
23
|
-
"cordis.patch.yml",
|
|
24
|
-
"desktop.ps1",
|
|
25
|
-
"README.md",
|
|
26
|
-
"LICENSE",
|
|
27
|
-
"CHANGELOG.md",
|
|
28
|
-
"docs"
|
|
29
|
-
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "node build.mjs",
|
|
32
|
-
"prepack": "npm run build",
|
|
33
|
-
"test": "node --test tests/*.test.mjs",
|
|
34
|
-
"pretest": "npm run build"
|
|
35
|
-
},
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/hth768/dsh-plugin-starpost.git"
|
|
39
|
-
},
|
|
40
|
-
"author": "hth768",
|
|
41
|
-
"homepage": "https://github.com/hth768/dsh-plugin-starpost#readme",
|
|
42
|
-
"bugs": {
|
|
43
|
-
"url": "https://github.com/hth768/dsh-plugin-starpost/issues"
|
|
44
|
-
},
|
|
45
|
-
"keywords": [
|
|
46
|
-
"deepseek-harness",
|
|
47
|
-
"dsh-plugin",
|
|
48
|
-
"starpost",
|
|
49
|
-
"bot",
|
|
50
|
-
"chat"
|
|
51
|
-
],
|
|
52
|
-
"starpostCoreVersion": "0.
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@deepseek-ai/dsh-agent-loop": "0.2.2-rc.1",
|
|
55
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.1",
|
|
56
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.1",
|
|
57
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
58
|
-
"cortico-world-starpost": "0.
|
|
59
|
-
"esbuild": "0.25.12"
|
|
60
|
-
}
|
|
61
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-plugin-starpost",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "星邮的 DeepSeek Harness bot 客户端,支持会话绑定、消息收发和折叠社交工具",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.mjs",
|
|
8
|
+
"bin": {
|
|
9
|
+
"starpost-dsh": "./src/account.mjs"
|
|
10
|
+
},
|
|
11
|
+
"dsh": {
|
|
12
|
+
"bundle": {
|
|
13
|
+
"patch": "./cordis.patch.yml"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.16.0",
|
|
18
|
+
"dsh": "^0.1.1-rc.2 || ^0.2.2-rc.1"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src/*.mjs",
|
|
22
|
+
"lib",
|
|
23
|
+
"cordis.patch.yml",
|
|
24
|
+
"desktop.ps1",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"CHANGELOG.md",
|
|
28
|
+
"docs"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "node build.mjs",
|
|
32
|
+
"prepack": "npm run build",
|
|
33
|
+
"test": "node --test tests/*.test.mjs",
|
|
34
|
+
"pretest": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/hth768/dsh-plugin-starpost.git"
|
|
39
|
+
},
|
|
40
|
+
"author": "hth768",
|
|
41
|
+
"homepage": "https://github.com/hth768/dsh-plugin-starpost#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/hth768/dsh-plugin-starpost/issues"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"deepseek-harness",
|
|
47
|
+
"dsh-plugin",
|
|
48
|
+
"starpost",
|
|
49
|
+
"bot",
|
|
50
|
+
"chat"
|
|
51
|
+
],
|
|
52
|
+
"starpostCoreVersion": "0.33.0",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@deepseek-ai/dsh-agent-loop": "0.2.2-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.1",
|
|
56
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
58
|
+
"cortico-world-starpost": "0.33.0",
|
|
59
|
+
"esbuild": "0.25.12"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@deepseek-ai/schemastery": "3.19.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/account.mjs
CHANGED
|
@@ -3,21 +3,32 @@ import { readFileSync } from 'node:fs';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { clientHome, clientVersions, loadSettings, options, validateSettings, saveSettings, makeWorld, lock, pinServer } from './local.mjs';
|
|
6
|
-
const usage = 'starpost-dsh register --session 会话ID | login --session 会话ID --file 凭据JSON文件 | configure --session 会话ID [--mode active|mixed|passive] | status';
|
|
6
|
+
const usage = 'starpost-dsh hub-login --session 会话ID | hub-complete | hub-cancel | register --session 会话ID | login --session 会话ID --file 凭据JSON文件 | configure [--session 会话ID] [--mode active|mixed|passive] [--square-mode manual|digest|realtime] [--feed-mode manual|digest|realtime] [--digest-interval-ms 300000] | status';
|
|
7
7
|
try {
|
|
8
8
|
const [action, ...args] = process.argv.slice(2);
|
|
9
|
-
const {values} = parseArgs({args,options:Object.fromEntries(['session','file','mode','server','emoji-dir'].map(k=>[k,{type:'string'}]))});
|
|
9
|
+
const {values} = parseArgs({args,options:Object.fromEntries(['session','file','mode','server','hub','emoji-dir','square-mode','feed-mode','digest-interval-ms'].map(k=>[k,{type:'string'}]))});
|
|
10
10
|
if (!action || action === '--help') { console.log(usage); }
|
|
11
11
|
else {
|
|
12
|
-
if (!['register','login','configure','status'].includes(action)) throw Error(usage);
|
|
12
|
+
if (!['register','login','configure','status','hub-login','hub-complete','hub-cancel'].includes(action)) throw Error(usage);
|
|
13
13
|
const dir = clientHome();
|
|
14
14
|
const release = action === 'status' ? () => {} : lock(dir);
|
|
15
15
|
try {
|
|
16
16
|
const settings = loadSettings(dir);
|
|
17
|
-
for (const [flag, key] of [['session','sessionId'],['mode','receiveMode'],['server','serverUrl'],['emoji-dir','emojiDir']])
|
|
17
|
+
for (const [flag, key] of [['session','sessionId'],['mode','receiveMode'],['server','serverUrl'],['hub','hubUrl'],['emoji-dir','emojiDir'],['square-mode','squareMode'],['feed-mode','feedMode']])
|
|
18
18
|
if (values[flag] !== undefined) settings[key] = values[flag];
|
|
19
|
+
if (values['digest-interval-ms'] !== undefined) {
|
|
20
|
+
if (!/^\d+$/.test(values['digest-interval-ms'])) throw Error('汇总间隔须为整数毫秒');
|
|
21
|
+
settings.digestIntervalMs = Number(values['digest-interval-ms']);
|
|
22
|
+
}
|
|
19
23
|
if (action !== 'status') validateSettings(dir,settings);
|
|
20
24
|
const world = makeWorld(dir,settings), invoke = world.webUi().invoke;
|
|
25
|
+
let pairing;
|
|
26
|
+
if (action === 'hub-login') {
|
|
27
|
+
pinServer(dir,settings);
|
|
28
|
+
pairing = await invoke('viewer','hubBegin',['星邮 DSH · '+settings.sessionId.slice(0,50)]);
|
|
29
|
+
}
|
|
30
|
+
if (action === 'hub-complete') pairing = await invoke('viewer','hubFinish',[]);
|
|
31
|
+
if (action === 'hub-cancel') pairing = await invoke('viewer','hubCancel',[]);
|
|
21
32
|
if (action === 'register' || action === 'login') {
|
|
22
33
|
pinServer(dir,settings);
|
|
23
34
|
if (action === 'register') await invoke('viewer','register',[]);
|
|
@@ -28,8 +39,9 @@ try {
|
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
41
|
if (action !== 'status') saveSettings(dir,settings);
|
|
31
|
-
console.log(JSON.stringify({ ...await invoke('viewer','status',[]), ...clientVersions, sessionId:settings.sessionId ?? null,
|
|
32
|
-
receiveMode:options(settings,dir).receiveMode,
|
|
42
|
+
console.log(JSON.stringify({ ...await invoke('viewer','status',[]), hub:await invoke('viewer','hubStatus',[]), ...(pairing ? {pairing} : {}), ...clientVersions, sessionId:settings.sessionId ?? null,
|
|
43
|
+
receiveMode:options(settings,dir).receiveMode, notifications:options(settings,dir).notifications,
|
|
44
|
+
settingsSource:'client.json(DSH 设置面板中的显式设置优先;修改后重启 Harness)', directory:dir, credentialFile:join(dir,'starpost-credential.json') }, null, 2));
|
|
33
45
|
} finally { release(); }
|
|
34
46
|
}
|
|
35
47
|
} catch (error) { console.error(error instanceof SyntaxError ? '配置或凭据文件不是有效的 JSON' : error.message); process.exitCode = 1; }
|
package/src/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { clientHome, clientVersions, loadSettings, makeWorld, lock } from './local.mjs';
|
|
4
|
+
import { clientHome, clientVersions, loadSettings, makeWorld, options, lock } from './local.mjs';
|
|
5
|
+
import { Config, registerNotificationSettings } from './settings.mjs';
|
|
6
|
+
export { Config } from './settings.mjs';
|
|
5
7
|
import { STARPOST_TOOL_DECLS } from '../lib/core.mjs';
|
|
6
8
|
|
|
7
9
|
export const name = 'dsh-plugin-starpost';
|
|
@@ -10,9 +12,13 @@ const envelope = (content, source) => ({id:randomUUID(), role:'user', content, s
|
|
|
10
12
|
const notice = text => envelope([{type:'text', text}], {form:'notice', summary:'星邮通知'});
|
|
11
13
|
const pending = agent => [...agent.inbox.nextStep, ...agent.inbox.nextTurn].filter(m => m.source?.kind === name);
|
|
12
14
|
|
|
13
|
-
export function apply(ctx) {
|
|
15
|
+
export function apply(ctx, entry = {}) {
|
|
14
16
|
const dir = clientHome();
|
|
15
17
|
const settings = loadSettings(dir);
|
|
18
|
+
const fileConfig = options(settings, dir);
|
|
19
|
+
const notificationConfig = registerNotificationSettings(ctx, {
|
|
20
|
+
receiveMode: fileConfig.receiveMode, ...fileConfig.notifications, ...Config(entry),
|
|
21
|
+
});
|
|
16
22
|
const calls = new AsyncLocalStorage();
|
|
17
23
|
let attachments;
|
|
18
24
|
ctx.inject(['attachments'], scoped => {
|
|
@@ -67,9 +73,11 @@ export function apply(ctx) {
|
|
|
67
73
|
client.ready = retired.then(async () => {
|
|
68
74
|
live();
|
|
69
75
|
client.unlock = lock(dir);
|
|
70
|
-
|
|
76
|
+
const effectiveSettings = { ...settings, ...notificationConfig() };
|
|
77
|
+
client.settings = options(effectiveSettings, dir);
|
|
78
|
+
client.world = makeWorld(dir,effectiveSettings);
|
|
71
79
|
const status = await client.world.webUi().invoke('viewer','status',[]);
|
|
72
|
-
if (!status.registered) throw Error('请先由人类用 starpost-dsh register
|
|
80
|
+
if (!status.registered) throw Error('请先由人类用 starpost-dsh hub-login 配对,或用 register / login 配置原星邮账号');
|
|
73
81
|
live();
|
|
74
82
|
client.tool = client.world.tools()[0];
|
|
75
83
|
agent.inject(notice(readFileSync(new URL('../lib/ENV_PROMPT.md',import.meta.url),'utf8')));
|
|
@@ -103,6 +111,8 @@ export function apply(ctx) {
|
|
|
103
111
|
if (args.family === 'client' && args.action === 'status') {
|
|
104
112
|
return JSON.stringify({...clientVersions, sessionId:agent.id, bound:settings.sessionId === agent.id,
|
|
105
113
|
ready:current?.agent === agent && Boolean(current.tool) && !current.error,
|
|
114
|
+
...(settings.sessionId === agent.id ? { notificationSettings: current?.settings?.notifications ?? options({ ...settings, ...notificationConfig() }, dir).notifications,
|
|
115
|
+
settingsApply: 'restart' } : {}),
|
|
106
116
|
...(current?.agent === agent && current.error ? {error:current.error.message} : {})});
|
|
107
117
|
}
|
|
108
118
|
if (!settings.sessionId || agent.id !== settings.sessionId) throw Error('此会话未绑定星邮账号。用 client/status 查看会话 ID,再由人类在终端完成绑定。');
|
package/src/local.mjs
CHANGED
|
@@ -17,6 +17,19 @@ export function loadSettings(dir) {
|
|
|
17
17
|
const file = join(dir, 'client.json');
|
|
18
18
|
return existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : {};
|
|
19
19
|
}
|
|
20
|
+
export function notificationOptions(settings) {
|
|
21
|
+
const nested = settings.notifications === undefined ? {} : settings.notifications;
|
|
22
|
+
if (!nested || typeof nested !== 'object' || Array.isArray(nested)) throw Error('notifications 须为配置对象');
|
|
23
|
+
const allowed = ['squareMode', 'feedMode', 'digestIntervalMs'];
|
|
24
|
+
for (const key of Object.keys(nested)) if (!allowed.includes(key)) throw Error('未知通知配置:'+key);
|
|
25
|
+
const result = { ...STARPOST_DEFAULTS.notifications, ...nested };
|
|
26
|
+
for (const key of allowed) if (Object.hasOwn(settings, key)) result[key] = settings[key];
|
|
27
|
+
for (const key of ['squareMode', 'feedMode']) {
|
|
28
|
+
if (!['realtime', 'digest', 'manual'].includes(result[key])) throw Error(key+' 须为 realtime、digest 或 manual');
|
|
29
|
+
}
|
|
30
|
+
if (!Number.isInteger(result.digestIntervalMs) || result.digestIntervalMs < 1000 || result.digestIntervalMs > 86400000) throw Error('digestIntervalMs 须为 1000~86400000 的整数');
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
20
33
|
export function options(settings, dir) {
|
|
21
34
|
const cfg = structuredClone(STARPOST_DEFAULTS);
|
|
22
35
|
cfg.enabled = true;
|
|
@@ -24,10 +37,12 @@ export function options(settings, dir) {
|
|
|
24
37
|
if (!(url.protocol === 'https:' || (url.protocol === 'http:' && ['127.0.0.1','localhost','[::1]'].includes(url.hostname))) ||
|
|
25
38
|
url.username || url.password || url.pathname !== '/' || url.search || url.hash) throw Error('请使用 HTTPS 服务地址,本机测试可用 HTTP 回环地址');
|
|
26
39
|
cfg.serverUrl = url.origin;
|
|
40
|
+
cfg.hubUrl = settings.hubUrl ?? cfg.hubUrl;
|
|
27
41
|
const pin = join(dir, 'server-origin');
|
|
28
42
|
if (existsSync(pin) && readFileSync(pin, 'utf8') !== url.origin) throw Error('账号数据已绑定其他服务器,请为新服务器选择独立的数据目录');
|
|
29
43
|
cfg.receiveMode = settings.receiveMode ?? cfg.receiveMode;
|
|
30
44
|
if (!['active','mixed','passive'].includes(cfg.receiveMode)) throw Error('接收模式须为 active、mixed 或 passive');
|
|
45
|
+
cfg.notifications = notificationOptions(settings);
|
|
31
46
|
cfg.emojiDir = resolve(dir, settings.emojiDir || 'emoji');
|
|
32
47
|
if(settings.speech!==undefined){
|
|
33
48
|
if(!settings.speech||typeof settings.speech!=='object'||Array.isArray(settings.speech))throw Error('speech 须为配置对象');
|
package/src/settings.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
|
|
3
|
+
const mode = () => z.union(['realtime', 'digest', 'manual']);
|
|
4
|
+
// Optional entry values preserve client.json settings when Cordis supplies {}.
|
|
5
|
+
export const Config = z.object({
|
|
6
|
+
receiveMode: z.union(['active', 'mixed', 'passive']).description('消息接收:active 主动查收;mixed 混合;passive 被动投递。'),
|
|
7
|
+
squareMode: mode().description('广场通知(含公开游戏开桌):manual 完全手动查看,不发更新数量提醒;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
8
|
+
feedMode: mode().description('动态和评论通知:manual 完全手动查看;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
9
|
+
digestIntervalMs: z.number().step(1).min(1000).max(86400000).description('汇总间隔,单位毫秒,默认 300000(5 分钟)。无新内容不唤醒。'),
|
|
10
|
+
}).description('星邮通知设置;修改后重启 Harness。游戏邀请、参赛、主人消息及系统提醒仍按原规则送达。');
|
|
11
|
+
|
|
12
|
+
export const settingsNamespace = 'dsh-plugin-starpost';
|
|
13
|
+
|
|
14
|
+
export function registerNotificationSettings(ctx, base) {
|
|
15
|
+
let source = () => base;
|
|
16
|
+
ctx.inject(['settings'], scoped => {
|
|
17
|
+
const scope = scoped.settings.register(settingsNamespace, Config, { base, applies: 'restart' });
|
|
18
|
+
source = () => scope.get();
|
|
19
|
+
scoped.effect(() => () => { source = () => base; }, 'starpost.notification-settings');
|
|
20
|
+
});
|
|
21
|
+
return () => source();
|
|
22
|
+
}
|