dsh-shlr-bilitoolkit 0.1.29 → 0.1.31

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/AGENTS.md CHANGED
@@ -2,19 +2,17 @@
2
2
 
3
3
  ## 登录(务必遵守)
4
4
  用户要登录 B 站,或任何操作返回未登录(-101 / 未登录 / CookieError)时:
5
- **必须调用 bili_gen_qr,并把返回的二维码图片展示给用户扫码**——用 qrDataUrl 以 Markdown 图片 `![qr](<qrDataUrl>)` 渲染(或引用 qrImageUrl / qrImagePath)。
6
- 禁止只给链接、用 ASCII、让用户自己跑命令。用户确认后调 bili_login_status 完成登录。
5
+ 1. 先 `bili_open({ group: "auth" })` 打开登录组(**下一轮起**才可用);
6
+ 2. **必须调用 bili_gen_qr,并把返回的二维码图片展示给用户扫码**——用 qrDataUrl 以 Markdown 图片 `![qr](<qrDataUrl>)` 渲染(或引用 qrImageUrl / qrImagePath);
7
+ 3. 用户扫码确认后调 `bili_login_status` 完成登录。
8
+
9
+ 禁止只给链接、用 ASCII、让用户自己跑命令。
7
10
 
8
11
  ## 能力按需加载
9
- 除常驻工具(bili_gen_qr / bili_login_status / bili_recommend / bili_video_detail / bili_search / bili_open)外,其它 B 站能力默认**懒加载**:
12
+ 除常驻工具(`bili_recommend` / `bili_video_detail` / `bili_search` / `bili_open`)外,其它 B 站能力默认**懒加载**:
10
13
  1. 先调 `bili_open()`(不带参数)看有哪些分组、每组含哪些工具;
11
14
  2. 再 `bili_open({ group: "comment" })` 或直接 `bili_open({ tool: "bili_comment_list" })` 打开;
12
15
  3. **下一轮起**该组工具才可调用。同时最多保留 3 组,超出会关掉最久没用的——顺序使用不同领域时不受影响,只有频繁在 4+ 个领域间往返才需要重新开组。
13
16
 
14
- ## 多步查询走 run_code(省 token)
15
- 需要多个 B 站数据时(如「视频详情 + 热评 + UP主资料」),写进 `run_code` 一段代码里完成,不要连续调用多个工具:
16
- - 独立的只读调用用 `Promise.all` 并发;写操作保持逐条 `await`(串行,也避免风控)。
17
- - **只 `return` / `console.log` 你需要的字段**——中间工具的完整返回不会进对话,能大幅减少 token。
18
-
19
17
  ## 其它
20
18
  写操作(点赞 / 收藏 / 投币 / 关注 / 评论 / 私信 / 三连 / 发动态 / 改资料)会真实修改账号状态,执行前先与用户确认。
package/README.md CHANGED
@@ -80,7 +80,7 @@ const [ups, _] = await client.space.videos(574115689, 1, 10);
80
80
  - **数据目录**:Cookie / 缓存 / 二维码 / 设备号统一放在一个目录里,默认 `bili_data/`(相对 dsh 工作目录),避免散落污染工作目录。可用 `BILI_DATA_DIR` 改目录;`BILI_COOKIE_FILE` / `BILI_CACHE_FILE` / `BILI_QR_FILE` / `BILI_DEVICE_FILE` 可精确指定单个文件。设备号(私信 `dev_id`)会落盘到 `bili_data/bili_device.json`,跨重启保持稳定,避免被 B 站当成新设备触发风控。兼容旧版:若新目录还没有 Cookie、而旧位置(`./bili_cookies.json`)有,会继续沿用旧的。
81
81
  - **扫码登录(独立获取 Cookie)**:运行 `npm run login`,终端会打印 ASCII 二维码,用「哔哩哔哩」App 扫码并确认后,Cookie 自动写入 `bili_data/bili_cookies.json`。也可在对话里先调 `bili_login_status` 查登录态、调 `bili_gen_qr` 拿二维码链接与可直接展示的 `ascii` 二维码。写操作(点赞 / 收藏 / 投币 / 关注 / 评论 / 私信 / 三连)都依赖该 Cookie 中的 `SESSDATA` / `bili_jct`。
82
82
  - **缓存持久化**:除 Cookie 外,客户端还会把 WBI 签名密钥(`B 站每天轮换`)、`bvid→aid` 映射这类稳定 / 带 TTL 的数据写入本地 JSON 缓存(`BILI_CACHE_FILE`,默认 `bili_data/bili_cache.json`),用临时文件 + 原子替换落盘、文件损坏会自动自愈。冷启动或跨进程时直接复用,避免每次都请求 `nav` 接口;密钥过期或失效时 `refresh()` 会重新拉取并覆盖缓存。若签名反复报 `-403/-352`,可调用 `bili_cache_clear` 强制清空缓存后重试(不影响 Cookie / 登录态)。
83
- - **计费 / 缓存与懒加载**:默认**按需加载(懒加载)**——49 个工具 schema 约 5200 token,常驻太占上下文窗口;默认只注册「常驻核心 + `bili_open`」约 700 token,其余 `bili_open({ group })` 按需开组(下一轮生效)。同时最多保留 **3 组**(LRU,超出关掉最久未用的)——前缀被压在「核心 + 3 组」约 1800 token 以内;顺序使用不同领域时 LRU 自然轮换、不产生额外开销。`BILI_LAZY=0` 退回全量注册(前缀稳定、命中最大化,适合不在意窗口);`BILI_LAZY_EVICT=0` 可改成完全不淘汰;`BILI_LAZY_EVICT_MAX` 可调组数上限(默认 3)。列表类工具默认**精简返回**(`full=true` 取全量)。
83
+ - **计费 / 缓存与懒加载**:默认**按需加载(懒加载)**——49 个工具 schema 约 5200 token,常驻太占上下文窗口;默认只注册「常驻核心 3 个 + `bili_open`」约 540 token,其余 `bili_open({ group })` 按需开组(下一轮生效)。登录工具在 `auth` 组(未登录时先 `bili_open({ group: "auth" })` 再 `bili_gen_qr`)。同时最多保留 **3 组**(LRU,超出关掉最久未用的)——前缀被压在「核心 + 3 组」约 1800 token 以内;顺序使用不同领域时 LRU 自然轮换、不产生额外开销。`BILI_LAZY=0` 退回全量注册(前缀稳定、命中最大化,适合不在意窗口);`BILI_LAZY_EVICT=0` 可改成完全不淘汰;`BILI_LAZY_EVICT_MAX` 可调组数上限(默认 3)。列表类工具默认**精简返回**(`full=true` 取全量)。
84
84
 
85
85
  > **给 Agent 的约定**:仓库根目录的 [`AGENTS.md`](./AGENTS.md) 写明了登录流程——需要登录时必须调用 `bili_gen_qr` 并把二维码**图片**展示给用户,而不是只给链接或 ASCII。把这份 `AGENTS.md` 放到 dsh 的工作目录(或确保你的 dsh 会读取它),agent 就会按约定输出登录二维码。
86
86
 
@@ -88,7 +88,7 @@ const [ups, _] = await client.space.videos(574115689, 1, 10);
88
88
 
89
89
  ```bash
90
90
  dsh plugin --profile <name> add dsh-shlr-bilitoolkit # 已发布到 npm
91
- dsh plugin --profile <name> add github:your-name/dsh-shlr-bilitoolkit#<ref>
91
+ dsh plugin --profile <name> add github:shiodd/dsh-shlr-bilitoolkit#<ref>
92
92
  ```
93
93
 
94
94
  > 插件入口已对齐 **官方 DeepSeek Harness(cordis 体系)** 的约定:模块导出 `name` / `inject = ["tools"]` / `apply(ctx)`,并在 `apply` 内用官方 `ctx.tools.register(defineTool({ name, description, parameters, output, execute }))` 注册每个工具(`defineTool` 来自 `@deepseek-ai/dsh-tools`,由宿主提供、插件不打包,保证单实例)。`parameters` 用官方简化 schema(`{ 参数名: { type, required, description, enum? } }`),工具返回规范 JSON 值,由 `output.render` 转成面向模型的文本。`cordis.patch.yml` 是官方组合包配置层(`- insert: - id: bili name: dsh-shlr-bilitoolkit`,按包名解析到 `main` 入口)。若你的 dsh 版本较旧、没有 `ctx.tools`,`apply` 仍保留了 `ctx.registerTool` / `ctx.services.tools.register` 的回退路径。
package/dist/dsh.js CHANGED
@@ -1145,14 +1145,9 @@ const groupLru = [];
1145
1145
  // 想完全不淘汰设 BILI_LAZY_EVICT=0,想更宽设 BILI_LAZY_EVICT_MAX。
1146
1146
  const MAX_OPEN_GROUPS = Number(process.env.BILI_LAZY_EVICT_MAX ?? 3) || 3;
1147
1147
  const EVICT_GROUPS = process.env.BILI_LAZY_EVICT !== "0" && process.env.BILI_LAZY_EVICT !== "false";
1148
- // 常驻核心:登录链路必须随时可用 + 最常用的几个读取
1149
- export const CORE_IDS = [
1150
- "bili_gen_qr",
1151
- "bili_login_status",
1152
- "bili_recommend",
1153
- "bili_video_detail",
1154
- "bili_search",
1155
- ];
1148
+ // 常驻核心:只留最高频的读取。登录工具(gen_qr / login_status)是一次性操作,
1149
+ // 放在 auth 懒加载组里,省 ~283 token/轮;AGENTS.md 与 bili_open 描述会引导模型先开组。
1150
+ export const CORE_IDS = ["bili_recommend", "bili_video_detail", "bili_search"];
1156
1151
  // 能力分组(group -> 提示 + 工具 id)。核心工具也会出现在所属组里,便于目录展示,
1157
1152
  // 但打开时不会重复注册(见 bili_open 里的 CORE_IDS 判断)。
1158
1153
  export const GROUPS = {
@@ -1171,6 +1166,7 @@ export const GROUPS = {
1171
1166
  message: { hint: "私信:发送 / 未读 / 聊天记录 / 撤回", ids: ["bili_send_message", "bili_message_unread", "bili_message_history", "bili_message_recall"] },
1172
1167
  notify: { hint: "消息中心:未读 / 回复·@·赞 列表", ids: ["bili_notify_unread", "bili_notify_list"] },
1173
1168
  profile: { hint: "个人资料:查看 / 修改", ids: ["bili_profile_info", "bili_profile_update"] },
1169
+ auth: { hint: "登录:生成扫码二维码 / 查询登录态(未登录或要登录时先开本组)", ids: ["bili_gen_qr", "bili_login_status"] },
1174
1170
  misc: { hint: "维护:清空本地缓存", ids: ["bili_cache_clear"] },
1175
1171
  };
1176
1172
  const TOOL_BY_ID = new Map(TOOLS.map((t) => [t.id, t]));
@@ -1226,7 +1222,7 @@ function buildDef(tool) {
1226
1222
  const lazyTools = [
1227
1223
  {
1228
1224
  id: "bili_open",
1229
- description: "B 站能力开关。不带参数调用=列出所有能力分组;带 group(分组名)或 tool(工具名)调用=打开该组,打开后下一轮起可调用。同时最多保留 3 组,超出自动关闭最久未用的。",
1225
+ description: "B 站能力开关。不带参数调用=列出所有能力分组;带 group(分组名)或 tool(工具名)调用=打开该组,打开后下一轮起可调用。同时最多保留 3 组,超出自动关闭最久未用的。登录相关在 auth 组(未登录 / 要登录时先 bili_open({ group: \"auth\" }))。",
1230
1226
  parameters: {
1231
1227
  type: "object",
1232
1228
  properties: {
@@ -1335,6 +1331,6 @@ export function apply(ctx) {
1335
1331
  }
1336
1332
  }
1337
1333
  // 同时导出库的全部公共 API(BiliClient / 各 API 类 / 模型等),
1338
- // 让 `import "dsh-bili-toolkit"` 既可作为插件入口,也可当普通库使用。
1334
+ // 让 `import "dsh-shlr-bilitoolkit"` 既可作为插件入口,也可当普通库使用。
1339
1335
  export * from "./index.js";
1340
1336
  export { BiliClient, Video, User, Page, PlayInfo, Subtitle, Collection };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /** dsh-bili-toolkit 对外导出入口。 */
1
+ /** dsh-shlr-bilitoolkit 对外导出入口。 */
2
2
  export { BiliClient, USER_AGENT, DEFAULT_HEADERS } from "./client.js";
3
3
  export type { BiliClientOptions } from "./client.js";
4
4
  export { BiliApiError, CaptchaRequired, CookieError, ERROR_HINTS, } from "./errors.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** dsh-bili-toolkit 对外导出入口。 */
1
+ /** dsh-shlr-bilitoolkit 对外导出入口。 */
2
2
  export { BiliClient, USER_AGENT, DEFAULT_HEADERS } from "./client.js";
3
3
  export { BiliApiError, CaptchaRequired, CookieError, ERROR_HINTS, } from "./errors.js";
4
4
  export { WbiSigner, mixinKey } from "./wbi.js";
@@ -0,0 +1,30 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "dsh-shlr-bilitoolkit",
4
+ "source": "community",
5
+ "displayName": "哔哩哔哩工具箱",
6
+ "description": "B站接口工具箱。可在dsh中作为工具调用。",
7
+ "descriptionZh": "B站接口工具箱。可在dsh中作为工具调用。",
8
+ "author": {
9
+ "name": "shiodd",
10
+ "url": "https://github.com/shiodd/dsh-shlr-bilitoolkit"
11
+ },
12
+ "links": {
13
+ "repo": "https://github.com/shiodd/dsh-shlr-bilitoolkit",
14
+ "docs": "https://github.com/shiodd/dsh-shlr-bilitoolkit#readme",
15
+ "npm": "dsh-shlr-bilitoolkit"
16
+ },
17
+ "license": "MIT",
18
+ "category": "tools",
19
+ "status": "beta",
20
+ "surfaces": ["server", "web"],
21
+ "install": {
22
+ "rows": [
23
+ { "npm": "dsh-shlr-bilitoolkit" }
24
+ ]
25
+ },
26
+ "verified": {
27
+ "at": "",
28
+ "packages": []
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-shlr-bilitoolkit",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "深海猎人专用B站接口工具箱 dsh 插件。",
5
5
  "type": "module",
6
6
  "main": "dist/dsh.js",
@@ -12,6 +12,7 @@
12
12
  "files": [
13
13
  "dist",
14
14
  "cordis.patch.yml",
15
+ "dsh-manifest.json",
15
16
  "AGENTS.md"
16
17
  ],
17
18
  "scripts": {