dsh-mobile-plugin 0.5.34 → 0.5.35

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.
Files changed (82) hide show
  1. package/lib/impl.js +0 -4
  2. package/lib/mobile/approval-facts.js +0 -13
  3. package/lib/mobile/permissions.js +5 -19
  4. package/lib/mobile/session-send.js +0 -1
  5. package/lib/routes/mobile-api.js +1 -39
  6. package/package.json +1 -2
  7. package/assets/pets/README.md +0 -9
  8. package/assets/pets/deepy-whale/attention.gif +0 -0
  9. package/assets/pets/deepy-whale/done.gif +0 -0
  10. package/assets/pets/deepy-whale/error.gif +0 -0
  11. package/assets/pets/deepy-whale/idle.gif +0 -0
  12. package/assets/pets/deepy-whale/pack.json +0 -54
  13. package/assets/pets/deepy-whale/sleeping.gif +0 -0
  14. package/assets/pets/deepy-whale/working-3.gif +0 -0
  15. package/assets/pets/deepy-whale/working.gif +0 -0
  16. package/knowledge/apps/alipay.md +0 -30
  17. package/knowledge/apps/android-settings.md +0 -30
  18. package/knowledge/apps/baijiahao.md +0 -30
  19. package/knowledge/apps/bilibili.md +0 -31
  20. package/knowledge/apps/boss-zhipin.md +0 -32
  21. package/knowledge/apps/dedao.md +0 -33
  22. package/knowledge/apps/douyin.md +0 -32
  23. package/knowledge/apps/feishu.md +0 -35
  24. package/knowledge/apps/gmail.md +0 -33
  25. package/knowledge/apps/jike.md +0 -31
  26. package/knowledge/apps/kuaishou.md +0 -34
  27. package/knowledge/apps/linkedin.md +0 -33
  28. package/knowledge/apps/qqmail.md +0 -30
  29. package/knowledge/apps/taobao.md +0 -33
  30. package/knowledge/apps/telegram.md +0 -27
  31. package/knowledge/apps/toutiao.md +0 -32
  32. package/knowledge/apps/uber-eats.md +0 -26
  33. package/knowledge/apps/uber.md +0 -27
  34. package/knowledge/apps/wechat.md +0 -33
  35. package/knowledge/apps/weibo.md +0 -31
  36. package/knowledge/apps/whatsapp.md +0 -27
  37. package/knowledge/apps/x.md +0 -32
  38. package/knowledge/apps/xiaohongshu.md +0 -30
  39. package/knowledge/apps/zhihu.md +0 -31
  40. package/knowledge/sites/bilibili.com/SITE.md +0 -50
  41. package/knowledge/sites/bilibili.com/references/view-fields.md +0 -17
  42. package/knowledge/sites/github.com/SITE.md +0 -51
  43. package/knowledge/sites/github.com/references/repo-fields.md +0 -13
  44. package/knowledge/sites/x.com/SITE.md +0 -47
  45. package/knowledge/sites/xiaohongshu.com/SITE.md +0 -48
  46. package/knowledge/sites/xiaohongshu.com/references/note-fields.md +0 -18
  47. package/knowledge/sites/youtube.com/SITE.md +0 -49
  48. package/knowledge/sites/youtube.com/references/innertube-fields.md +0 -14
  49. package/knowledge/sites/zhihu.com/SITE.md +0 -47
  50. package/knowledge/sites/zhihu.com/references/api-fields.md +0 -21
  51. package/lib/mobile/pet-tools.js +0 -261
  52. package/lib/mobile/pets.js +0 -755
  53. package/lib/mobile/phone/access.js +0 -140
  54. package/lib/mobile/phone/binding.js +0 -247
  55. package/lib/mobile/phone/confirm.js +0 -190
  56. package/lib/mobile/phone/evidence.js +0 -228
  57. package/lib/mobile/phone/gate.js +0 -290
  58. package/lib/mobile/phone/grounding.js +0 -314
  59. package/lib/mobile/phone/guard.js +0 -465
  60. package/lib/mobile/phone/guarded.js +0 -86
  61. package/lib/mobile/phone/index.js +0 -114
  62. package/lib/mobile/phone/irreversible.js +0 -226
  63. package/lib/mobile/phone/knowledge-tools.js +0 -665
  64. package/lib/mobile/phone/learn.js +0 -329
  65. package/lib/mobile/phone/pacing.js +0 -173
  66. package/lib/mobile/phone/redact.js +0 -237
  67. package/lib/mobile/phone/risk.js +0 -95
  68. package/lib/mobile/phone/route-extract.js +0 -460
  69. package/lib/mobile/phone/route-hint.js +0 -164
  70. package/lib/mobile/phone/routes-memory.js +0 -133
  71. package/lib/mobile/phone/routes.js +0 -287
  72. package/lib/mobile/phone/service.js +0 -520
  73. package/lib/mobile/phone/site-commands.js +0 -271
  74. package/lib/mobile/phone/skill-recall.js +0 -246
  75. package/lib/mobile/phone/skill-routes.js +0 -106
  76. package/lib/mobile/phone/step-summary.js +0 -201
  77. package/lib/mobile/phone/stop-summary.js +0 -235
  78. package/lib/mobile/phone/tool-groups.js +0 -125
  79. package/lib/mobile/phone/tools.js +0 -2590
  80. package/lib/mobile/phone/untrusted.js +0 -65
  81. package/lib/mobile/phone-knowledge.js +0 -317
  82. package/lib/mobile/route-store.js +0 -266
@@ -1,48 +0,0 @@
1
- ---
2
- name: xiaohongshu.com
3
- display: 小红书
4
- domains: ["xiaohongshu.com", "xhslink.com"]
5
- aliases: ["小红书", "xiaohongshu", "RED"]
6
- apps: ["xiaohongshu"]
7
- open: www.xiaohongshu.com
8
- mode: desktop
9
- pace: careful
10
- description: 生活方式内容社区,图文与视频笔记
11
- ---
12
- ## 是什么
13
- 小红书是生活方式内容社区,主域名 `xiaohongshu.com`,分享链接常见 `xhslink.com` 短链。基本单位是「笔记」:图文或视频配上标题、正文和标签。另有同名手机 App(见 `xiaohongshu`)。
14
-
15
- ## 页面与网址
16
- - 笔记详情:`https://www.xiaohongshu.com/explore/<noteId>`,noteId 是 24 位十六进制;旧式 `/discovery/item/<noteId>` 也能打开。
17
- - 发现/首页:`https://www.xiaohongshu.com/explore`。
18
- - 搜索:`https://www.xiaohongshu.com/search_result?keyword=<关键词>&source=web_explore_feed`(`type=` 等筛排序/类型的取值待确认现值)。
19
- - 用户主页:`/user/profile/<userId>`,userId 24 位十六进制。
20
- - 话题页:`/page/topics/<id>`。
21
- - 短链 `xhslink.com/<code>` 会 302 跳到上面地址,App 里分享出来的多为短链。
22
- - 参数:笔记 URL 后面常跟 `xsec_token`、`xsec_source`,缺了有些笔记会打不开(风控),待确认。
23
-
24
- ## 界面
25
- 首页是瀑布流的信息流,一张张笔记卡片带封面、标题、作者头像和点赞数;顶部是搜索框,左侧导航有发现、发布、通知、我。
26
-
27
- 笔记详情页:上方是图片轮播(或视频播放器),下面是标题、正文、话题标签、点赞/收藏/评论数、作者信息与关注按钮,再往下是评论区与相关推荐。个人主页有笔记、收藏、赞过等标签。
28
-
29
- ## 功能
30
- - 发布图文或视频笔记,可加标题、正文、话题标签和地点。
31
- - 搜索笔记、用户、商品等,可按最新、最热排序。
32
- - 点赞、收藏(可建专辑)、评论、关注作者。
33
- - 关注页看关注的人发的笔记;消息里有评论、赞、新增关注等分类。
34
- - 有直播入口;商品笔记可关联店铺或商品卡。
35
-
36
- ## 接口
37
- - 笔记详情:页面调 `https://edith.xiaohongshu.com/api/sns/web/v1/feed`(POST,body 里 `source_note_id`)。返回 `data.items[]`,每项 `note_card` 里含 `display_title`、`user.nickname`、`user.user_id`、`interact_info.liked_count`/`collected_count`/`comment_count`、`cover.url_default`、`type`(normal|video)。字段全表见 `references/note-fields.md`。
38
- - 搜索:`https://edith.xiaohongshu.com/api/sns/web/v1/search/notes`(POST),返回结构同上,另带 `xsec_token`。
39
- - 这些请求必须带 `x-s`、`x-t` 签名头(前端 JS 现算)和登录 Cookie,不签名直连会被拒(返回空或 `code` 非 0);签名算法随版本变,待确认。
40
- - 图片/视频直链在 `cover.url_default`、`video.media.stream...` 里,是 CDN 域名(`sns-img-*.xhscdn.com` 一类),带时效。
41
- - 结论:读页面已发出的响应正文(web_capture)最稳;自己重放要签名,不建议。
42
-
43
- ## 已知现象
44
- - 未登录时浏览和互动功能受限,常提示登录。
45
- - 信息流按推荐算法分发,不完全按发布时间。
46
- - 图片是竖向长图轮播,视频笔记会自动播放。
47
- - 部分笔记的评论或收藏需要登录后才看得到。
48
- - 少带 `xsec_token` 的笔记链接会打不开或跳登录。
@@ -1,18 +0,0 @@
1
- # 笔记卡片字段(sns/web/v1/feed 的 data.items[])
2
-
3
- - `id`:笔记 ID(24 位十六进制)。
4
- - `model_type`:条目类型。
5
- - `note_card`:
6
- - `type`:`normal`(图文)或 `video`(视频)。
7
- - `display_title`:标题。
8
- - `user`:`{ user_id, nickname, avatar, images }`。
9
- - `interact_info`:`{ liked, liked_count, collected, collected_count, comment_count, share_count, followed }`。
10
- - `cover`:`{ url_default, url_pre, width, height }`。
11
- - `image_list[]`:`{ url_default, width, height, live_photo }`。
12
- - `video`:`{ media: { stream: { h264[]{master_url}, h265[] } }, image{...} }`。
13
- - `tag_list[]`:`{ name, type }`。
14
- - `time`、`last_update_time`、`ip_location`。
15
-
16
- 搜索接口 `sns/web/v1/search/notes` 的条目结构相同,另带每条自己的 `xsec_token`。
17
-
18
- 注:需 `x-s` / `x-t` 签名头与登录 Cookie,签名算法随版本变。
@@ -1,49 +0,0 @@
1
- ---
2
- name: youtube.com
3
- display: YouTube
4
- domains: ["youtube.com", "youtu.be"]
5
- aliases: ["YouTube", "油管", "youtube"]
6
- apps: []
7
- open: www.youtube.com
8
- mode: desktop
9
- pace: standard
10
- description: 视频平台,看视频、订阅频道与 shorts
11
- ---
12
- ## 是什么
13
- YouTube 是视频平台,主域名 `youtube.com`,短链域名 `youtu.be`。内容以频道上传的视频为核心,另有 Shorts 短视频、直播和播放列表。我们暂无 YouTube 的 App 知识,`apps` 先留空。
14
-
15
- ## 页面与网址
16
- - 观看页:`https://www.youtube.com/watch?v=<videoId>`,videoId 固定 11 位(字母数字加 `-`、`_`)。
17
- - Shorts:`https://www.youtube.com/shorts/<videoId>`。
18
- - 频道:新式 `https://www.youtube.com/@<handle>`;旧式 `/channel/<UC...>`、`/c/<name>`、`/user/<name>`。
19
- - 播放列表:`/playlist?list=<listId>`,listId 常以 `PL`、`UU`、`LL` 开头。
20
- - 搜索:`/results?search_query=<关键词>&sp=<筛选串>`。
21
- - 起播位置:`/watch?v=<id>&t=90s`;嵌入:`/embed/<videoId>`。
22
- - 短链 `youtu.be/<videoId>` 会 302 跳到 watch 页。
23
- - 参数 `sp=` 是筛选编码(上传时间/类型/时长/排序),是位压缩串,不宜手拼,在页面上选即可。
24
-
25
- ## 界面
26
- 桌面网页左侧是导航:首页、Shorts、订阅、我(媒体库)、历史、播放列表,顶部是搜索框。首页是缩略图组成的视频网格,每张卡片带时长、标题、频道名、观看数和发布时间。
27
-
28
- 观看页分三块:上方是播放器(进度条、播放/暂停、音量、字幕、设置、剧场模式、全屏);播放器下方是标题、频道与订阅按钮、点赞/点踩、分享、保存,再接简介和评论区;右侧是相关推荐列表。
29
-
30
- ## 功能
31
- - 搜索可按上传时间、类型、时长、排序方式过滤(即 URL 里的 `sp=`)。
32
- - 播放器里可调画质、播放速度、字幕(含自动生成字幕)、循环。
33
- - 播放列表、稍后观看、点赞的视频都在「媒体库」里。
34
- - Shorts 是上下滑动切换的竖屏短视频流。
35
- - 频道页有首页、视频、Shorts、直播、播放列表、社区、简介等标签。
36
- - 直播页有实时聊天栏。
37
-
38
- ## 接口
39
- - 观看页背后是 InnerTube:`https://www.youtube.com/youtubei/v1/player`(POST JSON),body 里 `videoId` 加 `context.client`(`clientName`、`clientVersion`、`hl`、`gl`)。返回 `playabilityStatus.status`(OK / LOGIN_REQUIRED / AGE_VERIFICATION_REQUIRED 等)、`videoDetails`(`title`、`author`、`channelId`、`lengthSeconds`、`viewCount`、`shortDescription`、`keywords[]`)、`streamingData`(`formats`/`adaptiveFormats`,含直链与 `signatureCipher`)、`captions`。字段全表见 `references/innertube-fields.md`。
40
- - 轻量公开接口:`https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=<id>&format=json`,返回 `title`、`author_name`、`thumbnail_url`,不需要 key,但只有标题/作者,没有播放量。
41
- - 首屏数据也塞在页面 HTML 的 `ytInitialData` / `ytInitialPlayerResponse` 里,可从页面源码直接取。
42
- - 注:InnerTube 的 `context.client` 版本号与相关请求头会随前端变化,待确认;oEmbed 最稳。
43
-
44
- ## 已知现象
45
- - 播放前和播放中会插播广告。
46
- - 点赞、订阅、看年龄限制内容通常要先登录。
47
- - 部分视频有地区限制或会员(Premium)限制。
48
- - 自动生成的字幕可能不完全准确;评论默认按「热门」排序。
49
- - `sp=` 筛选码手改容易失效,用页面勾选更稳。
@@ -1,14 +0,0 @@
1
- # InnerTube /player 响应字段
2
-
3
- `POST https://www.youtube.com/youtubei/v1/player`,body:`{ videoId, context: { client: { clientName: "WEB", clientVersion: "2.xxxxx", hl, gl } } }`。
4
-
5
- 响应:
6
-
7
- - `playabilityStatus`:`{ status, reason, playableInEmbed }`。`status` 常见 `OK`、`LOGIN_REQUIRED`、`AGE_VERIFICATION_REQUIRED`、`UNPLAYABLE`。
8
- - `videoDetails`:`{ videoId, title, lengthSeconds, keywords[], channelId, shortDescription, thumbnail.thumbnails[], viewCount, author, isLiveContent }`。
9
- - `streamingData`:`{ expiresInSeconds, formats[]{ itag, url, mimeType, bitrate, width, height, contentLength, qualityLabel, audioQuality }, adaptiveFormats[]{ ..., signatureCipher } }`。
10
- - `captions.playerCaptionsTracklistRenderer.captionTracks[]`:`{ baseUrl, name.simpleText, languageCode }`。
11
- - `microformat.playerMicroformatRenderer`:`{ publishDate, uploadDate, category, viewCount, ownerChannelName }`。
12
-
13
- ## oEmbed
14
- `GET https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=<id>&format=json`:`title`、`author_name`、`author_url`、`thumbnail_url`、`thumbnail_width`、`thumbnail_height`、`html`。
@@ -1,47 +0,0 @@
1
- ---
2
- name: zhihu.com
3
- display: 知乎
4
- domains: ["zhihu.com"]
5
- aliases: ["知乎", "zhihu"]
6
- apps: ["zhihu"]
7
- open: www.zhihu.com
8
- mode: desktop
9
- pace: careful
10
- description: 问答社区,问题、回答、文章与话题
11
- ---
12
- ## 是什么
13
- 知乎是问答社区,主域名 `zhihu.com`。核心内容是「问题」下方的一条条「回答」,另有文章、专栏、想法等内容形式。另有同名手机 App(见 `zhihu`)。
14
-
15
- ## 页面与网址
16
- - 问题页:`https://www.zhihu.com/question/<qid>`,qid 是数字。
17
- - 单条回答:`https://www.zhihu.com/question/<qid>/answer/<answerId>`。
18
- - 文章:`https://zhuanlan.zhihu.com/p/<id>`(专栏子域名,按 `zhihu.com` 子域命中)。
19
- - 用户:`/people/<slug>`;专栏:`/column/<slug>`;想法:`/pin/<id>`;话题:`/topic/<id>`。
20
- - 搜索:`https://www.zhihu.com/search?type=content&q=<关键词>`(`type=content|people|topic`)。
21
- - 热榜:`https://www.zhihu.com/hot`。
22
- - 分页:回答列表滚动时前端按 `limit`/`offset` 自动取(见接口节),URL 不变。
23
-
24
- ## 界面
25
- 首页默认是推荐流,顶部有「关注 / 推荐 / 热榜」等切换;左侧或顶部是搜索框。问题页顶部是问题标题与描述,下面是回答列表,每条回答带作者、正文、赞同/反对、评论数,长回答会折叠成「展开阅读全文」。右侧常有「相关问题」和话题标签。
26
-
27
- 导航栏有首页、会员、发现、等待回答、我的等入口。个人主页分动态、回答、提问、文章、专栏等标签。
28
-
29
- ## 功能
30
- - 提问、写回答、评论、赞同或反对,赞同可在赞同/喜欢之间切换。
31
- - 收藏回答到收藏夹;关注问题、话题、用户。
32
- - 写文章与专栏;发「想法」(短内容)。
33
- - 搜索覆盖问题、回答、文章、用户、话题,可只看某一类。
34
- - 盐选专栏是付费内容;私信与通知在消息入口。
35
-
36
- ## 接口
37
- - 回答列表:`https://www.zhihu.com/api/v4/questions/<qid>/answers?include=data[*].content,voteup_count,comment_count,author.name,author.headline,created_time&limit=20&offset=0&sort_by=default|created`。返回 `data[]`,每条 `id`、`content`(HTML)、`voteup_count`、`comment_count`、`author.name`、`created_time`;`paging.is_end` 判断到底。字段全表见 `references/api-fields.md`。
38
- - 问题信息:`https://www.zhihu.com/api/v4/questions/<qid>?include=title,detail,answer_count,follower_count`,返回 `title`、`detail`、`answer_count`、`follower_count`。
39
- - 单条回答:`https://www.zhihu.com/api/v4/answers/<answerId>?include=content,voteup_count,comment_count,author.name,created_time`。
40
- - 注:`include` 里的字段用 `,` 或 `;` 分组指定,不加 `include` 只回默认字段;未登录/风控时可能返回 `error` 或跳登录,需要带常规浏览器头与 Cookie,是否需要额外签名/验证待确认。
41
-
42
- ## 已知现象
43
- - 未登录浏览常弹出登录框,或只能看部分内容。
44
- - 长回答显示为摘要,点「展开阅读全文」才展开。
45
- - 推荐流里会混入广告和推广内容。
46
- - 部分回答和盐选内容需要会员或付费才能看全。
47
- - 列表接口有风控,连续快速请求或缺少浏览器头会返回错误或空。
@@ -1,21 +0,0 @@
1
- # 知乎 v4 接口字段
2
-
3
- ## GET /api/v4/questions/{qid}/answers
4
- 参数:`limit`(每页,最大 20)、`offset`(从 0 开始)、`sort_by`(`default` 或 `created`)、`include`(逗号分隔,或 `;` 分组)。
5
-
6
- 返回 `data[]`,每条回答:
7
- - `id`:回答 ID。
8
- - `content`:回答正文(HTML)。
9
- - `voteup_count`:赞同数。
10
- - `comment_count`:评论数。
11
- - `author`:`{ name, headline, url_token, avatar_url_template }`。
12
- - `created_time`、`updated_time`:时间戳(秒)。
13
- - `is_collapsed`:是否被折叠。
14
-
15
- `paging`:`{ is_end, next, totals }`。
16
-
17
- ## GET /api/v4/questions/{qid}
18
- `include=title,detail,answer_count,follower_count,comment_count` → 返回 `title`、`detail`(问题描述 HTML)、`answer_count`、`follower_count`、`comment_count`。
19
-
20
- ## GET /api/v4/answers/{answerId}
21
- `include=content,voteup_count,comment_count,author.name,created_time` → 单条回答同上的字段。
@@ -1,261 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 给模型的两个工具:看一眼这台电脑上有哪些宠物包、做一只新的(或者改现有的)。
5
- *
6
- * ## 为什么要有工具
7
- *
8
- * 宠物包是「一个目录 + 一份 pack.json + 几张图」,而素材基本都已经是电脑上的图片文件了。
9
- * 让模型自己往目录里写,它记不住放哪儿、id 什么形状、状态键叫什么;写完还得自己回一句
10
- * 「好了」,用户那边刷半天也不一定看得到。工具负责的正是这几件它记不住的事。
11
- *
12
- * ## 为什么不收 base64 为主
13
- *
14
- * 让模型把几 MB 的图抄进工具参数,抄不动也抄不对。它手里真有的是
15
- * 「那张图在这台电脑上的路径」,所以 `filePath` 是主路,`base64` 只在它手上真有字节时兜底。
16
- *
17
- * ## 能力面的边界
18
- *
19
- * 只碰这个库:id 形状卡死、图片只认单层 `.gif` / `.png`、单张与整包都有上限。**没有删除** ——
20
- * 删是人的动作(设置页那边有个按钮),不该由模型顺手做掉。
21
- *
22
- * `pack` 整份透传给 `writePack`,不在工具这一层做字段白名单:包格式以后加可选字段(彩蛋 /
23
- * 时序 / 待机池 / 点按反应 / 命中框…)时,工具这边不用跟着改一遍。判据只有一处,在 pets.js。
24
- */
25
-
26
- const { defineTool } = require('@deepseek-ai/dsh-tools');
27
-
28
- const {
29
- listPacks,
30
- writePack,
31
- isImageName,
32
- ID_RE,
33
- KNOWN_STATES,
34
- } = require('./pets.js');
35
-
36
- /** 列表里一行一只:名字、id、内置还是自己做的、状态齐不齐。 */
37
- function packLine(pack) {
38
- const tags = [pack.builtin ? '内置' : '自己做的'];
39
- tags.push(`id ${pack.id}`);
40
- // `pack.states` 到这一层已经是状态名数组(execute 那步折过),按名字查键永远是 undefined。
41
- const missing = KNOWN_STATES.filter((state) => state !== 'sleeping' && !pack.states.includes(state));
42
- tags.push(missing.length === 0 ? '五个状态都有' : `缺 ${missing.join(' / ')}(将回退到 idle)`);
43
- if (pack.author) tags.push(pack.author);
44
- return `· 《${pack.name}》${tags.join(',')}`;
45
- }
46
-
47
- /**
48
- * 注册这两个工具。
49
- *
50
- * 必须走 `ctx.inject(['tools'], …)`:宿主里 `tools` 是子代理作用域提供的服务,插件这一层
51
- * 直接读 `ctx.tools` 拿到的常常是 undefined(见 `phone/tools.js` 那一整段教训)。缺失时
52
- * 静默跳过,别把整块装配掀掉。
53
- */
54
- function installPetTools(ctx) {
55
- if (typeof ctx.inject !== 'function') return;
56
- try {
57
- ctx.inject(['tools'], mountTools);
58
- } catch (error) {
59
- // 没有 tools 注入的 profile(cordis 抛 "… without inject"):只少这两个工具,包目录与
60
- // 三条路由照常可用。其余错误照抛 —— 别把真的注册失败也当成「这个 profile 没注入」。
61
- const message = error && error.message ? error.message : String(error);
62
- if (!message.includes('without inject')) throw error;
63
- }
64
- }
65
-
66
- /** `ctx.inject` 的回调体。单独拎出来只为让上面那层 try/catch 短一点。 */
67
- function mountTools(scoped) {
68
- if (!scoped || !scoped.tools || typeof scoped.tools.register !== 'function') return;
69
-
70
- scoped.tools.register(defineTool({
71
- name: 'pet_pack_list',
72
- description: 'List the desktop-pet packages on this computer: the built-in ones that ship with the app, plus any the user made. Each line gives the id, name, whether it is built-in, and which animation states it has. Use this when the user asks what pets they have or what their pet looks like, and before writing a pack so you pick an id that is free.',
73
- parameters: {},
74
- output: {
75
- schema: {
76
- type: 'object',
77
- additionalProperties: false,
78
- properties: {
79
- packs: {
80
- type: 'array',
81
- required: true,
82
- items: {
83
- type: 'object',
84
- additionalProperties: false,
85
- properties: {
86
- id: { type: 'string' },
87
- name: { type: 'string' },
88
- builtin: { type: 'boolean' },
89
- states: { type: 'array', items: { type: 'string' } },
90
- },
91
-
92
- },
93
- },
94
- },
95
- },
96
- render: (_args, value) => {
97
- const packs = Array.isArray(value.packs) ? value.packs : [];
98
- return [{
99
- type: 'text',
100
- text: packs.length === 0
101
- ? '这台电脑上一个宠物包都还没有。用户想做一只的话,用 pet_pack_write 建一个。'
102
- : `这台电脑上有 ${packs.length} 只:\n${packs.map(packLine).join('\n')}`,
103
- }];
104
- },
105
- },
106
- execute: async () => ({
107
- packs: listPacks().map((pack) => ({
108
- id: pack.id,
109
- name: pack.name,
110
- builtin: pack.builtin,
111
- states: Object.keys(pack.states),
112
- })),
113
- }),
114
- }));
115
-
116
- scoped.tools.register(defineTool({
117
- name: 'pet_pack_write',
118
- description: 'Create or replace a desktop-pet package on this computer, so it shows up on the user\'s phone under Settings → floating pet. Use this whenever the user wants to change their pet, make a new one, or drop in their own artwork. A pack is one directory with a pack.json plus the images it references. States are idle / working / attention / done / error / sleeping (plus optional thinking / juggling / sweeping / carrying / waking / notification), and idle is required; a state you leave out falls back to idle. Pictures are GIF (animated) or PNG (static). Give each picture the PATH of the file on this computer — the host reads it — rather than its bytes; base64 is only for when you already hold the bytes. Optional richer fields: bonus (an Easter egg per state), timings (minDisplay / autoReturn), idlePool (random idle extras), reactions (tap / tickle / drag art), hitBoxes (with wideAnims / sleepingAnims), roam ({anim, faces}), sleep ({afterMs}), tiers.juggling, pixelArt, scale, contentBox, source. Existing packs with the same id are replaced wholesale, including a built-in one (warn the user before doing that). You cannot delete packs; that is the user\'s job in Settings.',
119
- parameters: {
120
- id: {
121
- type: 'string',
122
- description: 'Pack id, also the folder name: 1-64 lowercase letters, digits and dashes, not starting with a dash, e.g. deepy-whale.',
123
- },
124
- pack: {
125
- type: 'object',
126
- additionalProperties: true,
127
- description: 'The whole pack.json as an object. Required keys: name and states (with at least idle). Optional: author, license, source, pixelArt, scale, canvas {w,h}, anchor {x,baseline}, contentBox {x,y,w,h}, tiers.working / tiers.juggling [{min,file}] (largest min wins), loop [], sleepAfterMs (or the nested sleep.afterMs), bonus {state:{anims:[file],chance}}, timings {minDisplay:{state:ms},autoReturn:{state:ms}}, idlePool {everyMs:{mean,min,max},anims:[{file,ms,weight}]}, reactions {tapLeft,tapRight,tickle,drag}, hitBoxes {default,wide,sleeping,byAnim:{anim:{x,y,w,h}},wideAnims:[...],sleepingAnims:[...]}, roam {anim,faces:left|right|front}. Every file named here must be one you pass in files[].',
128
- properties: {
129
- name: { type: 'string', description: 'Shown in the picker on the phone.' },
130
- author: { type: 'string', description: 'Credited in the picker footer. Fill it in whenever the artwork is not yours.' },
131
- license: { type: 'string', description: 'License note, shown next to the author.' },
132
- source: { type: 'string', description: 'Where the artwork came from, shown in the picker footer.' },
133
- pixelArt: { type: 'boolean', description: 'Nearest-neighbour scaling. Default true.' },
134
- scale: { type: 'number', description: 'Sheet pixels per art pixel, e.g. 5 for a 5x export.' },
135
- contentBox: {
136
- type: 'object',
137
- additionalProperties: true,
138
- description: 'The idle body in art pixels {x,y,w,h}: the hit box and where bubbles sit.',
139
- },
140
- states: {
141
- type: 'object',
142
- additionalProperties: true,
143
- description: 'State name → { file }. Recognised: idle, working, attention, done, error, sleeping, plus the optional thinking / juggling / sweeping / carrying / waking / notification. At least idle is required.',
144
- },
145
- tiers: {
146
- type: 'object',
147
- additionalProperties: true,
148
- description: 'Optional. tiers.working / tiers.juggling are [{min, file}]: pick the image by how many conversations (or sub-agents) are running.',
149
- },
150
- loop: { type: 'array', items: { type: 'string' }, description: 'States that loop. Defaults to idle, working, attention.' },
151
- sleepAfterMs: { type: 'number', description: 'Idle time before switching to sleeping. Only meaningful when the sleeping state exists.' },
152
- bonus: {
153
- type: 'object',
154
- additionalProperties: true,
155
- description: 'Optional Easter egg: state → { anims: [file], chance: 0..1 }. An extra animation played instead of the state main art when the dice hit.',
156
- },
157
- timings: {
158
- type: 'object',
159
- additionalProperties: true,
160
- description: 'Optional { minDisplay: {state: ms}, autoReturn: {state: ms} }: how long a one-off state stays up and when it folds back.',
161
- },
162
- idlePool: {
163
- type: 'object',
164
- additionalProperties: true,
165
- description: 'Optional { everyMs: {mean,min,max}, anims: [{file,ms,weight}] }: random small idle animations while nothing is happening.',
166
- },
167
- reactions: {
168
- type: 'object',
169
- additionalProperties: true,
170
- description: 'Optional { tapLeft, tapRight, tickle, drag }: the animation played for each touch gesture, each a file in this pack.',
171
- },
172
- hitBoxes: {
173
- type: 'object',
174
- additionalProperties: true,
175
- description: 'Optional { default, wide, sleeping, byAnim: { anim: {x,y,w,h} }, wideAnims: [anim], sleepingAnims: [anim] } in art pixels: where the window takes touches. The host picks byAnim → sleepingAnims → wideAnims → default.',
176
- },
177
- roam: {
178
- type: 'object',
179
- additionalProperties: true,
180
- description: 'Optional { anim, faces }: the walking animation and which way it looks (left / right / front). anim must be a file in this pack.',
181
- },
182
- sleep: {
183
- type: 'object',
184
- additionalProperties: true,
185
- description: 'Optional { afterMs }: idle time before sleeping. The top-level sleepAfterMs is the older spelling; both are accepted.',
186
- },
187
- },
188
- },
189
- files: {
190
- type: 'array',
191
- description: 'The images this pack uses. Each one is written into the pack folder under that name.',
192
- items: {
193
- type: 'object',
194
- additionalProperties: false,
195
- properties: {
196
- path: { type: 'string', required: true, description: 'File name inside the pack, e.g. idle.gif. Single level, .gif or .png, no slashes.' },
197
- filePath: { type: 'string', description: 'Absolute path of the picture on this computer. This is the normal way.' },
198
- base64: { type: 'string', description: 'The image bytes, base64 encoded. Only when you already hold the bytes and have no file to point at.' },
199
- },
200
- },
201
- },
202
- },
203
- output: {
204
- schema: {
205
- type: 'object',
206
- additionalProperties: false,
207
- properties: {
208
- id: { type: 'string', required: true },
209
- name: { type: 'string', required: true },
210
- states: { type: 'array', items: { type: 'string' } },
211
- written: { type: 'array', items: { type: 'string' } },
212
- note: { type: 'string' },
213
- },
214
- },
215
- render: (_args, value) => {
216
- const lines = [`《${value.name}》存好了,id ${value.id},状态:${(value.states || []).join(' / ') || 'idle'}。`];
217
- if (Array.isArray(value.written) && value.written.length > 0) lines.push(`图片已存:${value.written.join('、')}。`);
218
- if (value.note) lines.push(value.note);
219
- return [{ type: 'text', text: lines.join('\n') }];
220
- },
221
- },
222
- execute: async (args) => {
223
- const id = typeof args.id === 'string' ? args.id.trim() : '';
224
- if (!ID_RE.test(id)) {
225
- throw new Error(`"${id}" 不是合法的宠物包 id:只认 1-64 位小写字母、数字与连字符,且不以连字符开头。`);
226
- }
227
- // 文件名先收窄一遍再交给库:这样「哪几个名字不合规矩」能在写之前就一趟说清。
228
- const files = Array.isArray(args.files) ? args.files : [];
229
- const badNames = files
230
- .map((item) => (item && typeof item.path === 'string' ? item.path.trim() : ''))
231
- .filter((name) => !isImageName(name));
232
- if (badNames.length > 0) {
233
- throw new Error(`这几个文件名不合规矩:${badNames.map((name) => `"${name}"`).join('、')}。只认单层 .gif / .png(不含斜杠),例如 idle.gif。`);
234
- }
235
-
236
- let result;
237
- try {
238
- result = await writePack({ id, pack: args.pack, files });
239
- } catch (error) {
240
- throw new Error(error && error.message ? error.message : '没能写进去。');
241
- }
242
- const { pack, rejected, written, overriddenBuiltin } = result;
243
- const notes = [];
244
- if (overriddenBuiltin) {
245
- notes.push(`这个 id 原本有一只内置的宠物,现在被这份盖住了(手机上显示的是新的这只)。内置那份没被改动。`);
246
- }
247
- if (rejected.length > 0) {
248
- notes.push(`这几张没能收进来:${rejected.join('、')}(读不到,或者不是 .gif / .png)。`);
249
- }
250
- return {
251
- id: pack.id,
252
- name: pack.name,
253
- states: Object.keys(pack.states),
254
- written,
255
- ...(notes.length > 0 ? { note: notes.join('\n') } : {}),
256
- };
257
- },
258
- }));
259
- }
260
-
261
- module.exports = { installPetTools };