dsh-qqbot-plus 0.0.0-stage → 0.1.2

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 (301) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/CHANGELOG_EN.md +188 -0
  3. package/LICENSE +21 -0
  4. package/README.md +281 -2
  5. package/README_EN.md +248 -0
  6. package/cordis.patch.yml +163 -0
  7. package/cordis.yml +112 -0
  8. package/install.sh +108 -0
  9. package/lib/alarms.js +371 -0
  10. package/lib/client.js +2411 -0
  11. package/lib/commands/auth.d.ts +18 -0
  12. package/lib/commands/auth.d.ts.map +1 -0
  13. package/lib/commands/auth.js +15 -0
  14. package/lib/commands/auth.js.map +1 -0
  15. package/lib/commands/help.d.ts +10 -0
  16. package/lib/commands/help.d.ts.map +1 -0
  17. package/lib/commands/help.js +39 -0
  18. package/lib/commands/help.js.map +1 -0
  19. package/lib/commands/index.d.ts +15 -0
  20. package/lib/commands/index.d.ts.map +1 -0
  21. package/lib/commands/index.js +30 -0
  22. package/lib/commands/index.js.map +1 -0
  23. package/lib/commands/misc.d.ts +21 -0
  24. package/lib/commands/misc.d.ts.map +1 -0
  25. package/lib/commands/misc.js +93 -0
  26. package/lib/commands/misc.js.map +1 -0
  27. package/lib/commands/model.d.ts +6 -0
  28. package/lib/commands/model.d.ts.map +1 -0
  29. package/lib/commands/model.js +63 -0
  30. package/lib/commands/model.js.map +1 -0
  31. package/lib/commands/new.js +17 -0
  32. package/lib/commands/preset.d.ts +8 -0
  33. package/lib/commands/preset.d.ts.map +1 -0
  34. package/lib/commands/preset.js +56 -0
  35. package/lib/commands/preset.js.map +1 -0
  36. package/lib/commands/session.d.ts +14 -0
  37. package/lib/commands/session.d.ts.map +1 -0
  38. package/lib/commands/session.js +34 -0
  39. package/lib/commands/session.js.map +1 -0
  40. package/lib/commands/status.d.ts +7 -0
  41. package/lib/commands/status.d.ts.map +1 -0
  42. package/lib/commands/status.js +26 -0
  43. package/lib/commands/status.js.map +1 -0
  44. package/lib/commands/types.d.ts +21 -0
  45. package/lib/commands/types.d.ts.map +1 -0
  46. package/lib/commands/types.js +2 -0
  47. package/lib/commands/types.js.map +1 -0
  48. package/lib/config.d.ts +95 -0
  49. package/lib/config.js +88 -0
  50. package/lib/features/answer-parser.d.ts +9 -0
  51. package/lib/features/answer-parser.d.ts.map +1 -0
  52. package/lib/features/answer-parser.js +23 -0
  53. package/lib/features/answer-parser.js.map +1 -0
  54. package/lib/features/approval-channel.d.ts +94 -0
  55. package/lib/features/approval-channel.d.ts.map +1 -0
  56. package/lib/features/approval-channel.js +158 -0
  57. package/lib/features/approval-channel.js.map +1 -0
  58. package/lib/features/approval-renderer.d.ts +18 -0
  59. package/lib/features/approval-renderer.d.ts.map +1 -0
  60. package/lib/features/approval-renderer.js +52 -0
  61. package/lib/features/approval-renderer.js.map +1 -0
  62. package/lib/features/button-utils.d.ts +34 -0
  63. package/lib/features/button-utils.d.ts.map +1 -0
  64. package/lib/features/button-utils.js +27 -0
  65. package/lib/features/button-utils.js.map +1 -0
  66. package/lib/features/history-store.d.ts +8 -0
  67. package/lib/features/history-store.d.ts.map +1 -0
  68. package/lib/features/history-store.js +23 -0
  69. package/lib/features/history-store.js.map +1 -0
  70. package/lib/features/question-channel.d.ts +96 -0
  71. package/lib/features/question-channel.d.ts.map +1 -0
  72. package/lib/features/question-channel.js +234 -0
  73. package/lib/features/question-channel.js.map +1 -0
  74. package/lib/features/question-renderer.d.ts +20 -0
  75. package/lib/features/question-renderer.d.ts.map +1 -0
  76. package/lib/features/question-renderer.js +70 -0
  77. package/lib/features/question-renderer.js.map +1 -0
  78. package/lib/fishcheck/measure.js +230 -0
  79. package/lib/fishcheck/rules.js +99 -0
  80. package/lib/fishmeme/plugin.js +605 -0
  81. package/lib/fishmeme/routes.js +141 -0
  82. package/lib/fishmemory/plugin.js +1052 -0
  83. package/lib/gateway/bootstrap.d.ts +12 -0
  84. package/lib/gateway/bootstrap.d.ts.map +1 -0
  85. package/lib/gateway/bootstrap.js +200 -0
  86. package/lib/gateway/bootstrap.js.map +1 -0
  87. package/lib/gateway/index.d.ts +3 -0
  88. package/lib/gateway/index.d.ts.map +1 -0
  89. package/lib/gateway/index.js +3 -0
  90. package/lib/gateway/index.js.map +1 -0
  91. package/lib/gateway/middleware-setup.d.ts +12 -0
  92. package/lib/gateway/middleware-setup.d.ts.map +1 -0
  93. package/lib/gateway/middleware-setup.js +82 -0
  94. package/lib/gateway/middleware-setup.js.map +1 -0
  95. package/lib/host/adapter.d.ts +48 -0
  96. package/lib/host/adapter.d.ts.map +1 -0
  97. package/lib/host/adapter.js +127 -0
  98. package/lib/host/adapter.js.map +1 -0
  99. package/lib/humanlike/ENV_PROMPT.md +28 -0
  100. package/lib/humanlike/affinity.js +316 -0
  101. package/lib/humanlike/learn.js +343 -0
  102. package/lib/humanlike/life.js +899 -0
  103. package/lib/humanlike/mind.js +323 -0
  104. package/lib/humanlike/plugin.js +587 -0
  105. package/lib/humanlike/reach.js +119 -0
  106. package/lib/humanlike/real.js +276 -0
  107. package/lib/humanlike/rules.js +67 -0
  108. package/lib/humanlike/settings-api.js +159 -0
  109. package/lib/humanlike/settings.js +370 -0
  110. package/lib/humanlike/together.js +251 -0
  111. package/lib/identity/paths.js +27 -0
  112. package/lib/identity/persona.js +75 -0
  113. package/lib/identity/portrait.js +25 -0
  114. package/lib/identity/runtime.js +78 -0
  115. package/lib/index.d.ts +15 -0
  116. package/lib/index.js +117 -0
  117. package/lib/media/draft-tool.js +442 -0
  118. package/lib/media/draft-tool.js.bak-to-182027 +389 -0
  119. package/lib/media/media-cleaner.d.ts +19 -0
  120. package/lib/media/media-cleaner.d.ts.map +1 -0
  121. package/lib/media/media-cleaner.js +81 -0
  122. package/lib/media/media-cleaner.js.map +1 -0
  123. package/lib/media/say-tool.js +72 -0
  124. package/lib/media/send-file-tool.d.ts +12 -0
  125. package/lib/media/send-file-tool.d.ts.map +1 -0
  126. package/lib/media/send-file-tool.js +122 -0
  127. package/lib/media/send-file-tool.js.map +1 -0
  128. package/lib/media/send-media.d.ts +61 -0
  129. package/lib/media/send-media.d.ts.map +1 -0
  130. package/lib/media/send-media.js +104 -0
  131. package/lib/media/send-media.js.map +1 -0
  132. package/lib/media/vision-tool.d.ts +22 -0
  133. package/lib/media/vision-tool.d.ts.map +1 -0
  134. package/lib/media/vision-tool.js +288 -0
  135. package/lib/media/vision-tool.js.map +1 -0
  136. package/lib/middleware/attachment.d.ts +11 -0
  137. package/lib/middleware/attachment.d.ts.map +1 -0
  138. package/lib/middleware/attachment.js +30 -0
  139. package/lib/middleware/attachment.js.map +1 -0
  140. package/lib/middleware/question-answer.d.ts +10 -0
  141. package/lib/middleware/question-answer.d.ts.map +1 -0
  142. package/lib/middleware/question-answer.js +19 -0
  143. package/lib/middleware/question-answer.js.map +1 -0
  144. package/lib/model/index.d.ts +10 -0
  145. package/lib/model/index.d.ts.map +1 -0
  146. package/lib/model/index.js +9 -0
  147. package/lib/model/index.js.map +1 -0
  148. package/lib/model/model-resolver.d.ts +102 -0
  149. package/lib/model/model-resolver.d.ts.map +1 -0
  150. package/lib/model/model-resolver.js +206 -0
  151. package/lib/model/model-resolver.js.map +1 -0
  152. package/lib/model/prefs-store.d.ts +50 -0
  153. package/lib/model/prefs-store.d.ts.map +1 -0
  154. package/lib/model/prefs-store.js +215 -0
  155. package/lib/model/prefs-store.js.map +1 -0
  156. package/lib/model/settings-reader.d.ts +19 -0
  157. package/lib/model/settings-reader.d.ts.map +1 -0
  158. package/lib/model/settings-reader.js +76 -0
  159. package/lib/model/settings-reader.js.map +1 -0
  160. package/lib/model/types.d.ts +15 -0
  161. package/lib/model/types.d.ts.map +1 -0
  162. package/lib/model/types.js +5 -0
  163. package/lib/model/types.js.map +1 -0
  164. package/lib/resume-check.js +122 -0
  165. package/lib/resume-tool.js +29 -0
  166. package/lib/rules.js +57 -0
  167. package/lib/session/idle-evictor.d.ts +18 -0
  168. package/lib/session/idle-evictor.d.ts.map +1 -0
  169. package/lib/session/idle-evictor.js +31 -0
  170. package/lib/session/idle-evictor.js.map +1 -0
  171. package/lib/session/index.d.ts +9 -0
  172. package/lib/session/index.d.ts.map +1 -0
  173. package/lib/session/index.js +8 -0
  174. package/lib/session/index.js.map +1 -0
  175. package/lib/session/pick-agent.js +116 -0
  176. package/lib/session/session-id.d.ts +5 -0
  177. package/lib/session/session-id.d.ts.map +1 -0
  178. package/lib/session/session-id.js +15 -0
  179. package/lib/session/session-id.js.map +1 -0
  180. package/lib/session/session-manager.d.ts +138 -0
  181. package/lib/session/session-manager.d.ts.map +1 -0
  182. package/lib/session/session-manager.js +1157 -0
  183. package/lib/session/session-manager.js.bak-target +1081 -0
  184. package/lib/session/session-manager.js.bak-title-20261118 +1119 -0
  185. package/lib/session/session-manager.js.map +1 -0
  186. package/lib/session/types.d.ts +162 -0
  187. package/lib/session/types.d.ts.map +1 -0
  188. package/lib/session/types.js +2 -0
  189. package/lib/session/types.js.map +1 -0
  190. package/lib/setup/bind-routes.d.ts +78 -0
  191. package/lib/setup/bind-routes.d.ts.map +1 -0
  192. package/lib/setup/bind-routes.js +588 -0
  193. package/lib/setup/bind-routes.js.bak-join-163944 +761 -0
  194. package/lib/setup/bind-routes.js.map +1 -0
  195. package/lib/setup/binding-service.d.ts +86 -0
  196. package/lib/setup/binding-service.d.ts.map +1 -0
  197. package/lib/setup/binding-service.js +175 -0
  198. package/lib/setup/binding-service.js.map +1 -0
  199. package/lib/setup/index.d.ts +50 -0
  200. package/lib/setup/index.d.ts.map +1 -0
  201. package/lib/setup/index.js +163 -0
  202. package/lib/setup/index.js.map +1 -0
  203. package/lib/setup/persist.d.ts +42 -0
  204. package/lib/setup/persist.d.ts.map +1 -0
  205. package/lib/setup/persist.js +344 -0
  206. package/lib/setup/persist.js.map +1 -0
  207. package/lib/setup/presenters.d.ts +40 -0
  208. package/lib/setup/presenters.d.ts.map +1 -0
  209. package/lib/setup/presenters.js +84 -0
  210. package/lib/setup/presenters.js.map +1 -0
  211. package/lib/setup/qr-svg.d.ts +9 -0
  212. package/lib/setup/qr-svg.d.ts.map +1 -0
  213. package/lib/setup/qr-svg.js +33 -0
  214. package/lib/setup/qr-svg.js.map +1 -0
  215. package/lib/shared/bind-protocol.d.ts +42 -0
  216. package/lib/shared/bind-protocol.d.ts.map +1 -0
  217. package/lib/shared/bind-protocol.js +33 -0
  218. package/lib/shared/bind-protocol.js.map +1 -0
  219. package/lib/shared/dirs.d.ts +10 -0
  220. package/lib/shared/dirs.d.ts.map +1 -0
  221. package/lib/shared/dirs.js +20 -0
  222. package/lib/shared/dirs.js.map +1 -0
  223. package/lib/shared/http-body.js +43 -0
  224. package/lib/shared/index.d.ts +8 -0
  225. package/lib/shared/index.d.ts.map +1 -0
  226. package/lib/shared/index.js +8 -0
  227. package/lib/shared/index.js.map +1 -0
  228. package/lib/shared/json-file.js +34 -0
  229. package/lib/shared/orders.js +26 -0
  230. package/lib/shared/scope.d.ts +14 -0
  231. package/lib/shared/scope.d.ts.map +1 -0
  232. package/lib/shared/scope.js +12 -0
  233. package/lib/shared/scope.js.map +1 -0
  234. package/lib/shared/send-helper.d.ts +11 -0
  235. package/lib/shared/send-helper.d.ts.map +1 -0
  236. package/lib/shared/send-helper.js +13 -0
  237. package/lib/shared/send-helper.js.map +1 -0
  238. package/lib/shared/utils.d.ts +31 -0
  239. package/lib/shared/utils.d.ts.map +1 -0
  240. package/lib/shared/utils.js +228 -0
  241. package/lib/shared/utils.js.map +1 -0
  242. package/lib/tool-guard.js +74 -0
  243. package/lib/transport/attachment.d.ts +41 -0
  244. package/lib/transport/attachment.d.ts.map +1 -0
  245. package/lib/transport/attachment.js +191 -0
  246. package/lib/transport/attachment.js.map +1 -0
  247. package/lib/transport/chunker.d.ts +14 -0
  248. package/lib/transport/chunker.d.ts.map +1 -0
  249. package/lib/transport/chunker.js +78 -0
  250. package/lib/transport/chunker.js.map +1 -0
  251. package/lib/transport/deliverables.d.ts +20 -0
  252. package/lib/transport/deliverables.d.ts.map +1 -0
  253. package/lib/transport/deliverables.js +72 -0
  254. package/lib/transport/deliverables.js.map +1 -0
  255. package/lib/transport/events.d.ts +117 -0
  256. package/lib/transport/events.d.ts.map +1 -0
  257. package/lib/transport/events.js +112 -0
  258. package/lib/transport/events.js.map +1 -0
  259. package/lib/transport/inbound.d.ts +11 -0
  260. package/lib/transport/inbound.d.ts.map +1 -0
  261. package/lib/transport/inbound.js +511 -0
  262. package/lib/transport/inbound.js.map +1 -0
  263. package/lib/transport/index.d.ts +10 -0
  264. package/lib/transport/index.d.ts.map +1 -0
  265. package/lib/transport/index.js +10 -0
  266. package/lib/transport/index.js.map +1 -0
  267. package/lib/transport/msgid-cache.d.ts +23 -0
  268. package/lib/transport/msgid-cache.d.ts.map +1 -0
  269. package/lib/transport/msgid-cache.js +57 -0
  270. package/lib/transport/msgid-cache.js.map +1 -0
  271. package/lib/transport/notify.js +147 -0
  272. package/lib/transport/outbound-buffer.d.ts +42 -0
  273. package/lib/transport/outbound-buffer.d.ts.map +1 -0
  274. package/lib/transport/outbound-buffer.js +68 -0
  275. package/lib/transport/outbound-buffer.js.map +1 -0
  276. package/lib/transport/outbound.d.ts +42 -0
  277. package/lib/transport/outbound.d.ts.map +1 -0
  278. package/lib/transport/outbound.js +183 -0
  279. package/lib/transport/outbound.js.map +1 -0
  280. package/lib/transport/reply-limiter.d.ts +31 -0
  281. package/lib/transport/reply-limiter.d.ts.map +1 -0
  282. package/lib/transport/reply-limiter.js +50 -0
  283. package/lib/transport/reply-limiter.js.map +1 -0
  284. package/lib/transport/reply-target.d.ts +32 -0
  285. package/lib/transport/reply-target.d.ts.map +1 -0
  286. package/lib/transport/reply-target.js +64 -0
  287. package/lib/transport/reply-target.js.map +1 -0
  288. package/lib/transport/streaming-writer.d.ts +55 -0
  289. package/lib/transport/streaming-writer.d.ts.map +1 -0
  290. package/lib/transport/streaming-writer.js +122 -0
  291. package/lib/transport/streaming-writer.js.map +1 -0
  292. package/lib/transport/tool-presenter.d.ts +37 -0
  293. package/lib/transport/tool-presenter.d.ts.map +1 -0
  294. package/lib/transport/tool-presenter.js +116 -0
  295. package/lib/transport/tool-presenter.js.map +1 -0
  296. package/lib/turn-check.js +85 -0
  297. package/lib/types.d.ts +39 -0
  298. package/lib/types.js +5 -0
  299. package/locale/en.json +6 -0
  300. package/locale/zh.json +6 -0
  301. package/package.json +127 -4
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 插件数据目录 — 单一事实源
3
+ *
4
+ * workspace / media / 模型偏好等子路径统一从 PLUGIN_HOME 派生,
5
+ * 避免各模块各自拼路径造成漂移。目录名与包名一致:dsh-qqbot-plus。
6
+ */
7
+ import { homedir } from 'node:os';
8
+ import { resolve } from 'node:path';
9
+ /** 插件数据根目录(区别于宿主的 ~/.dsh) */
10
+ export const PLUGIN_HOME = resolve(homedir(), '.dsh', 'dsh-qqbot-plus');
11
+ /**
12
+ * agent 工作目录:显式配置优先(空串视为未配置),缺省 PLUGIN_HOME/workspace。
13
+ *
14
+ * session 创建、路径白名单(send-file 工具与交付物投递)共用此解析,
15
+ * 保证「agent 在哪写文件」与「白名单允许哪个目录」不漂移。
16
+ */
17
+ export function resolveAgentCwd(cwdConfig) {
18
+ return cwdConfig || resolve(PLUGIN_HOME, 'workspace');
19
+ }
20
+ //# sourceMappingURL=dirs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dirs.js","sourceRoot":"","sources":["../../src/shared/dirs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,6BAA6B;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAA6B;IAC3D,OAAO,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,43 @@
1
+ // 读 HTTP 请求体并解析成 JSON —— qqbot 自己的接口和人味设置接口共用这一份。
2
+ //
3
+ // 以前有两份几乎一样的实现(lib/setup/bind-routes.js 与人味 settings-api.js),
4
+ // 上限与空体处理略不同,排查时要看两个地方。现在都走这里,行为由参数决定:
5
+ // maxBytes 请求体上限(字节)
6
+ // allowEmpty 空体返回 {}(人味接口如此)还是抛错(凭据提交接口如此)
7
+ //
8
+ // 抛出的错误带 `code`:'body-too-large' | 'body-empty' | 'body-invalid-json',
9
+ // 调用方自己决定映射成什么 HTTP 状态。
10
+
11
+ export class BodyError extends Error {
12
+ constructor (code, message) {
13
+ super(message)
14
+ this.name = 'BodyError'
15
+ this.code = code
16
+ }
17
+ }
18
+
19
+ /**
20
+ * @param {import('node:http').IncomingMessage} req
21
+ * @param {{ maxBytes?: number, allowEmpty?: boolean }} [options]
22
+ * @returns {Promise<any>}
23
+ */
24
+ export async function readJsonBody (req, options = {}) {
25
+ const maxBytes = options.maxBytes ?? 64 * 1024
26
+ const allowEmpty = options.allowEmpty ?? false
27
+ const chunks = []
28
+ let size = 0
29
+ for await (const chunk of req) {
30
+ size += chunk.length
31
+ if (size > maxBytes) throw new BodyError('body-too-large', '请求体过大')
32
+ chunks.push(chunk)
33
+ }
34
+ if (size === 0) {
35
+ if (allowEmpty) return {}
36
+ throw new BodyError('body-empty', '请求体是空的')
37
+ }
38
+ try {
39
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'))
40
+ } catch {
41
+ throw new BodyError('body-invalid-json', '请求体不是合法 JSON')
42
+ }
43
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 共享工具层
3
+ */
4
+ export { getProfileDir, resolveEnv, formatRelativeTime, buildUserAgent, PLUGIN_VERSION } from './utils.ts';
5
+ export { getScopePeer } from './scope.ts';
6
+ export { PLUGIN_HOME, resolveAgentCwd } from './dirs.ts';
7
+ export { sendMarkdownChunked } from './send-helper.ts';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 共享工具层
3
+ */
4
+ export { getProfileDir, resolveEnv, formatRelativeTime, buildUserAgent, PLUGIN_VERSION } from "./utils.js";
5
+ export { getScopePeer } from "./scope.js";
6
+ export { PLUGIN_HOME, resolveAgentCwd } from "./dirs.js";
7
+ export { sendMarkdownChunked } from "./send-helper.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ /**
5
+ * 原子地写一份 JSON:先写同目录临时文件再 rename 覆盖。
6
+ *
7
+ * 直接 writeFileSync 覆盖状态文件,赶上进程被杀 / 断电就会留下半截 JSON;
8
+ * 读的一方(settings.json 尤其明显)解析失败就当没文件、回落默认值,
9
+ * 面板设置就这么"自己回到默认"了。tmp + rename 在同一个文件系统上是原子的。
10
+ *
11
+ * @param {string} file 目标路径
12
+ * @param {unknown} data 要写的数据
13
+ * @param {{ indent?: number, trailingNewline?: boolean, mode?: number }} [options]
14
+ * @returns {boolean} 写成功返回 true(失败返回 false,不抛)
15
+ */
16
+ export function writeJsonAtomic (file, data, options = {}) {
17
+ const { indent = 2, trailingNewline = true, mode } = options
18
+ const dir = path.dirname(file)
19
+ const tmp = path.join(dir, `.${path.basename(file)}.${process.pid}.${Date.now()}.tmp`)
20
+ try {
21
+ fs.mkdirSync(dir, { recursive: true })
22
+ const body = JSON.stringify(data, null, indent) + (trailingNewline ? '\n' : '')
23
+ fs.writeFileSync(tmp, body, { encoding: 'utf8', ...(mode === undefined ? {} : { mode }) })
24
+ fs.renameSync(tmp, file)
25
+ return true
26
+ } catch {
27
+ try {
28
+ fs.rmSync(tmp, { force: true })
29
+ } catch {
30
+ // 临时文件清不掉就算了,别把真正要报的错盖掉
31
+ }
32
+ return false
33
+ }
34
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 系统提示段的 order,全插件唯一来源。
3
+ *
4
+ * 这些数字以前散在五个文件里,撞了不会报错、只会静默丢一段(later wins / 同 order 覆盖)。
5
+ * 改顺序只改这里。
6
+ *
7
+ * 顺带记一下邻居:dsh-map 的前缀段是 71,它不在本插件里。
8
+ */
9
+ export const ORDER = {
10
+ // QQ 会话的稳定人设与范围说明
11
+ persona: 20,
12
+ portrait: 4800,
13
+ // QQ 里怎么回话(硬规矩)
14
+ qqRules: 4950,
15
+ // 人味
16
+ humanlikeEnv: 70,
17
+ humanlikeRules: 73, // 72 让给记忆索引
18
+ humanlikeMissed: 9994,
19
+ // 记忆
20
+ memoryIndex: 72,
21
+ memoryRecall: 9990,
22
+ // 表情包(2026-11-21 从 dsh-fishmeme 并进来,沿用原来的 74)
23
+ memeRules: 74,
24
+ // 别人家的,别占
25
+ mapPrefix: 71,
26
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * scope 提取工具
3
+ *
4
+ * 从 SDK 命令上下文中提取 scope + peerId。
5
+ */
6
+ import type { SlashCommandHandlerContext } from '@tencent-connect/qqbot-nodejs';
7
+ /**
8
+ * 从命令上下文提取 scope + peerId
9
+ */
10
+ export declare function getScopePeer(cmdCtx: SlashCommandHandlerContext): {
11
+ scope: 'c2c' | 'group';
12
+ peerId: string;
13
+ };
14
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/shared/scope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,0BAA0B,GAAG;IAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAO3G"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 从命令上下文提取 scope + peerId
3
+ */
4
+ export function getScopePeer(cmdCtx) {
5
+ const msg = cmdCtx.message;
6
+ const scope = msg.kind === 'group' ? 'group' : 'c2c';
7
+ const peerId = scope === 'group'
8
+ ? (msg.groupOpenid ?? msg.senderId)
9
+ : msg.senderId;
10
+ return { scope, peerId };
11
+ }
12
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/shared/scope.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkC;IAC7D,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACrD,MAAM,MAAM,GAAG,KAAK,KAAK,OAAO;QAC9B,CAAC,CAAC,CAAE,GAA0C,CAAC,WAAqB,IAAI,GAAG,CAAC,QAAQ,CAAC;QACrF,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;IACjB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 分块发送 markdown 工具
3
+ *
4
+ * 长内容自动按 QQ 消息限制切分后逐条发送。
5
+ */
6
+ import type { SlashCommandHandlerContext } from '@tencent-connect/qqbot-nodejs';
7
+ /**
8
+ * 分块发送 markdown(长内容自动切分)
9
+ */
10
+ export declare function sendMarkdownChunked(cmdCtx: SlashCommandHandlerContext, content: string, chunkLimit: number): Promise<void>;
11
+ //# sourceMappingURL=send-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-helper.d.ts","sourceRoot":"","sources":["../../src/shared/send-helper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAGhF;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAOf"}
@@ -0,0 +1,13 @@
1
+ import { chunkMarkdownText } from "../transport/chunker.js";
2
+ /**
3
+ * 分块发送 markdown(长内容自动切分)
4
+ */
5
+ export async function sendMarkdownChunked(cmdCtx, content, chunkLimit) {
6
+ const bot = cmdCtx.bot;
7
+ const replyTarget = cmdCtx.replyTarget;
8
+ const chunks = chunkMarkdownText(content, chunkLimit);
9
+ for (const chunk of chunks) {
10
+ await bot.sendMarkdown(replyTarget, chunk);
11
+ }
12
+ }
13
+ //# sourceMappingURL=send-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-helper.js","sourceRoot":"","sources":["../../src/shared/send-helper.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAkC,EAClC,OAAe,EACf,UAAkB;IAElB,MAAM,GAAG,GAAI,MAA6C,CAAC,GAA2E,CAAC;IACvI,MAAM,WAAW,GAAI,MAA6C,CAAC,WAAW,CAAC;IAC/E,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACtD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ /** 插件版本号(从 package.json 读取,供 help/version 等展示真实版本) */
2
+ export declare const PLUGIN_VERSION: string;
3
+ /**
4
+ * 构造 User-Agent 头
5
+ *
6
+ * 格式: dsh-qqbot/{version} (Node/{nodeVersion}; {platform})
7
+ */
8
+ export declare function buildUserAgent(): string;
9
+ /**
10
+ * 从插件安装路径推导 profile 目录
11
+ *
12
+ * 主策略:逐级向上探测 profile 标志文件(cordis.patch.yml / pnpm-workspace.yaml)。
13
+ * Desktop profile 使用 pnpm workspace 布局(profiles/desktop/dependencies/
14
+ * node_modules/.pnpm/<pkg>/node_modules/...),插件嵌套于多级 node_modules,
15
+ * 仅按 node_modules 匹配会命中内层目录而返回错误位置。
16
+ *
17
+ * 兜底:无标志文件时沿用旧启发式(名为 node_modules 的目录的父目录),
18
+ * 覆盖 CLI profile 的浅层 npm 布局与未写入过 patch 的全新 profile。
19
+ *
20
+ * @param baseDir - 起始目录,缺省为插件根(可注入便于测试)
21
+ */
22
+ export declare function getProfileDir(baseDir?: string): string | null;
23
+ /**
24
+ * 解析环境变量占位配置
25
+ */
26
+ export declare function resolveEnv(configValue: string, envKey: string): string;
27
+ /**
28
+ * 格式化相对时间
29
+ */
30
+ export declare function formatRelativeTime(ts?: number): string;
31
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAcA,sDAAsD;AACtD,eAAO,MAAM,cAAc,QAAsB,CAAC;AAYlD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,MAAoB,GAAG,MAAM,GAAG,IAAI,CA2B1E;AA8ED;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKtE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAOtD"}
@@ -0,0 +1,228 @@
1
+ /**
2
+ * 通用工具函数
3
+ *
4
+ * 纯函数与常量,供插件入口与其他模块复用。
5
+ */
6
+ import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
7
+ import os from 'node:os';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { basename, dirname, resolve } from 'node:path';
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const PLUGIN_ROOT = resolve(__dirname, '../..');
13
+ /** 插件版本号(从 package.json 读取,供 help/version 等展示真实版本) */
14
+ export const PLUGIN_VERSION = readPluginVersion();
15
+ function readPluginVersion() {
16
+ try {
17
+ const pkgPath = resolve(PLUGIN_ROOT, 'package.json');
18
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
19
+ return pkg.version ?? '0.0.0';
20
+ }
21
+ catch {
22
+ return '0.0.0';
23
+ }
24
+ }
25
+ /**
26
+ * 构造 User-Agent 头
27
+ *
28
+ * 格式: dsh-qqbot/{version} (Node/{nodeVersion}; {platform})
29
+ */
30
+ export function buildUserAgent() {
31
+ return `dsh-qqbot/${PLUGIN_VERSION} (Node/${process.versions.node}; ${os.platform()})`;
32
+ }
33
+ /**
34
+ * 从插件安装路径推导 profile 目录
35
+ *
36
+ * 主策略:逐级向上探测 profile 标志文件(cordis.patch.yml / pnpm-workspace.yaml)。
37
+ * Desktop profile 使用 pnpm workspace 布局(profiles/desktop/dependencies/
38
+ * node_modules/.pnpm/<pkg>/node_modules/...),插件嵌套于多级 node_modules,
39
+ * 仅按 node_modules 匹配会命中内层目录而返回错误位置。
40
+ *
41
+ * 兜底:无标志文件时沿用旧启发式(名为 node_modules 的目录的父目录),
42
+ * 覆盖 CLI profile 的浅层 npm 布局与未写入过 patch 的全新 profile。
43
+ *
44
+ * @param baseDir - 起始目录,缺省为插件根(可注入便于测试)
45
+ */
46
+ export function getProfileDir(baseDir = PLUGIN_ROOT) {
47
+ // 主策略:跨过 node_modules 边界后,优先命中 cordis.patch.yml(凭据写入
48
+ // 目标),其次 pnpm-workspace.yaml。跨越守卫是关键——插件包自身随包携带
49
+ // cordis.patch.yml(dsh.bundle.patch 分发物)、源码 checkout 根也有同名
50
+ // 仓库文件,二者都会让「从 PLUGIN_ROOT 起步的探测」命中插件自己;只有
51
+ // 位于 node_modules 之上的目录才可能是拥有该插件的 profile。
52
+ const byPatch = findProfileAncestor(baseDir, (dir) => existsSync(resolve(dir, 'cordis.patch.yml')) ? dir : null);
53
+ if (byPatch !== null)
54
+ return byPatch;
55
+ const byWorkspace = findProfileAncestor(baseDir, (dir) => existsSync(resolve(dir, 'pnpm-workspace.yaml')) ? dir : null);
56
+ if (byWorkspace !== null)
57
+ return byWorkspace;
58
+ // 兜底:npm 浅层布局 / 尚未写入任何标志文件的全新 profile
59
+ // (第一个 node_modules 目录的父目录,与旧版行为一致)
60
+ let dir = baseDir;
61
+ for (let i = 0; i < 32; i++) {
62
+ if (basename(dir) === 'node_modules')
63
+ return dirname(dir);
64
+ const parent = dirname(dir);
65
+ if (parent === dir)
66
+ break;
67
+ dir = parent;
68
+ }
69
+ // link: 安装(symlink)下插件真实路径在 node_modules 之外,正向反推必失败;
70
+ // 反查 profiles/*/node_modules 里指向本插件根的 symlink(#78)
71
+ return findProfileBySymlink(baseDir);
72
+ }
73
+ /** 反查 symlink 命中 profile;多 profile 共享源码时优先当前进程的 profile */
74
+ function findProfileBySymlink(baseDir) {
75
+ const home = process.env.DSH_HOME ?? resolve(os.homedir(), '.dsh');
76
+ const profilesRoot = resolve(home, 'profiles');
77
+ if (!existsSync(profilesRoot))
78
+ return null;
79
+ let realBase;
80
+ try {
81
+ realBase = realpathSync(baseDir);
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ const match = (name) => {
87
+ const profileDir = resolve(profilesRoot, name);
88
+ const nodeModules = resolve(profileDir, 'node_modules');
89
+ // 已知包名先直接试:本 fork 改名成 dsh-qqbot-plus,旧名仍保留兼容。
90
+ const known = ['dsh-qqbot-plus', resolve('@tencent-connect', 'dsh-qqbot')];
91
+ for (const entry of known) {
92
+ try {
93
+ if (realpathSync(resolve(nodeModules, entry)) === realBase)
94
+ return profileDir;
95
+ }
96
+ catch {
97
+ // 未安装或链接损坏,继续试下一个
98
+ }
99
+ }
100
+ // 包名以后再改也能命中:扫一层 node_modules,找指向本包根的 symlink。
101
+ let items;
102
+ try {
103
+ items = readdirSync(nodeModules);
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ for (const item of items) {
109
+ if (item.startsWith('.'))
110
+ continue;
111
+ if (item.startsWith('@')) {
112
+ let scoped = [];
113
+ try {
114
+ scoped = readdirSync(resolve(nodeModules, item));
115
+ }
116
+ catch {
117
+ continue;
118
+ }
119
+ for (const sub of scoped) {
120
+ try {
121
+ if (realpathSync(resolve(nodeModules, item, sub)) === realBase)
122
+ return profileDir;
123
+ }
124
+ catch {
125
+ // ignore
126
+ }
127
+ }
128
+ continue;
129
+ }
130
+ try {
131
+ if (realpathSync(resolve(nodeModules, item)) === realBase)
132
+ return profileDir;
133
+ }
134
+ catch {
135
+ // ignore
136
+ }
137
+ }
138
+ return null;
139
+ };
140
+ const current = currentProfileName();
141
+ if (current !== undefined) {
142
+ const exact = match(current);
143
+ if (exact !== null)
144
+ return exact;
145
+ }
146
+ let entries;
147
+ try {
148
+ entries = readdirSync(profilesRoot);
149
+ }
150
+ catch {
151
+ return null;
152
+ }
153
+ for (const name of entries) {
154
+ const hit = match(name);
155
+ if (hit !== null)
156
+ return hit;
157
+ }
158
+ return null;
159
+ }
160
+ /** 从进程判据解析 profile 名:Electron → desktop;argv 的 --profile 或裸子命令缩写 */
161
+ function currentProfileName() {
162
+ if (process.versions.electron !== undefined)
163
+ return 'desktop';
164
+ const argv = process.argv.slice(2);
165
+ for (let i = 0; i < argv.length; i++) {
166
+ const arg = argv[i] ?? '';
167
+ if (arg === '--profile') {
168
+ const next = argv[i + 1];
169
+ if (next !== undefined && !next.startsWith('-'))
170
+ return next;
171
+ }
172
+ else if (arg.startsWith('--profile=')) {
173
+ return arg.slice('--profile='.length);
174
+ }
175
+ }
176
+ const first = argv.find((a) => !a.startsWith('-'));
177
+ if (first !== undefined && first !== 'plugin')
178
+ return first;
179
+ return undefined;
180
+ }
181
+ /**
182
+ * 沿目录树向上探测 profile 候选:仅接受「已经跨过至少一个名为
183
+ * node_modules 的路径组件」之后命中的目录(兼容 Windows 分隔符与
184
+ * pnpm 嵌套结构;dev 源码 checkout 不跨边界 → 返回 null → 环境变量引导)。
185
+ */
186
+ function findProfileAncestor(baseDir, probe) {
187
+ let crossedNodeModules = false;
188
+ let dir = baseDir;
189
+ for (let i = 0; i < 32; i++) {
190
+ if (basename(dir) === 'node_modules')
191
+ crossedNodeModules = true;
192
+ if (crossedNodeModules) {
193
+ const hit = probe(dir);
194
+ if (hit !== null)
195
+ return hit;
196
+ }
197
+ const parent = dirname(dir);
198
+ if (parent === dir)
199
+ break;
200
+ dir = parent;
201
+ }
202
+ return null;
203
+ }
204
+ /**
205
+ * 解析环境变量占位配置
206
+ */
207
+ export function resolveEnv(configValue, envKey) {
208
+ if (configValue && configValue !== '__FROM_ENV__' && !configValue.startsWith('process.env')) {
209
+ return configValue;
210
+ }
211
+ return process.env[envKey] ?? '';
212
+ }
213
+ /**
214
+ * 格式化相对时间
215
+ */
216
+ export function formatRelativeTime(ts) {
217
+ if (!ts)
218
+ return '—';
219
+ const diff = Date.now() - ts;
220
+ if (diff < 60_000)
221
+ return `${Math.floor(diff / 1000)}s 前`;
222
+ if (diff < 3_600_000)
223
+ return `${Math.floor(diff / 60_000)}m 前`;
224
+ if (diff < 86_400_000)
225
+ return `${Math.floor(diff / 3_600_000)}h 前`;
226
+ return `${Math.floor(diff / 86_400_000)}d 前`;
227
+ }
228
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAEhD,sDAAsD;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;AAElD,SAAS,iBAAiB;IACxB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAyB,CAAC;QAC9E,OAAO,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC;IAChC,CAAC;IAAC,M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;IAC1D,IAAI,IAAI,GAAG,SAAS;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/D,IAAI,IAAI,GAAG,UAAU;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC;IACnE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * 拦住「QQ 机器人用 plugin_manager 动自己」这一类调用。
3
+ *
4
+ * 为什么要有它:QQ 的 agent 就跑在本插件自己的 fiber 里,它对自己调
5
+ * `plugin_manager {action:"set_plugin", target:"include:im-qqbot", enabled:true}`
6
+ * 重载时,插件被卸载而这次工具调用永远不返回——整个回合卡死,之后的消息
7
+ * 只能堆进收件箱(2026-11-15 连卡两次,都是这一条调用)。
8
+ *
9
+ * 只拦「瞄准自己」的写操作:管理别的插件照旧(list 之类也不动)。
10
+ * 用 tools.guard 而不是 tools/pre-execute:guard 是同步、单调的,
11
+ * 后注册的监听者无法把拒绝翻回允许。
12
+ */
13
+ import { readFileSync } from 'node:fs'
14
+
15
+ /** 本插件的入口 id / bundle 包名,两个都算「自己」。 */
16
+ const SELF_TARGETS = new Set(['im-qqbot'])
17
+ try {
18
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
19
+ if (typeof pkg?.name === 'string' && pkg.name !== '') SELF_TARGETS.add(pkg.name)
20
+ } catch {
21
+ // 读不到 package.json 就只按入口 id 判,不影响拦截
22
+ SELF_TARGETS.add('dsh-qqbot-plus')
23
+ }
24
+
25
+ /** 会改变插件装载状态的动作(list_* 是只读,不管)。 */
26
+ const MUTATING_ACTIONS = new Set(['set_plugin', 'set_bundle', 'install_bundle', 'remove_bundle'])
27
+
28
+ /**
29
+ * target 是不是本插件。
30
+ * 形态有 `im-qqbot`、`include:im-qqbot`、`dsh-qqbot-plus`、`dsh-qqbot-plus@1.2.3`、
31
+ * 以及 install_bundle 的 `file:/x/y/dsh-qqbot-plus`,所以按包名段判。
32
+ */
33
+ export function targetsSelf(raw) {
34
+ const text = String(raw ?? '').trim().toLowerCase()
35
+ if (text === '') return false
36
+ const bare = text.replace(/^(include|exclude):/, '')
37
+ for (const name of SELF_TARGETS) {
38
+ if (bare === name) return true
39
+ if (bare.startsWith(`${name}@`)) return true
40
+ if (bare.endsWith(`/${name}`)) return true
41
+ }
42
+ return false
43
+ }
44
+
45
+ /**
46
+ * 注册守卫。
47
+ * @param ctx - 插件 ctx(用它挂 effect,插件卸载时守卫一起撤)
48
+ * @param manager - SessionManager,用来判断这次调用是不是 QQ 会话发起的
49
+ * @returns 是否注册成功
50
+ */
51
+ export function installSelfGuard(ctx, manager, logger) {
52
+ let tools
53
+ try {
54
+ tools = ctx.get('tools')
55
+ } catch {
56
+ tools = undefined
57
+ }
58
+ if (typeof tools?.guard !== 'function') {
59
+ logger.warn?.('im-qqbot: tools.guard 不可用,plugin_manager 自毁未拦')
60
+ return false
61
+ }
62
+ ctx.effect(() => tools.guard((exec) => {
63
+ if (exec?.name !== 'plugin_manager') return undefined
64
+ // 只拦 QQ 会话:桌面/其它 agent 想重载本插件仍然允许
65
+ if (manager.findByAgent(exec.agent) === undefined) return undefined
66
+ const args = exec.arguments ?? {}
67
+ if (!MUTATING_ACTIONS.has(args.action)) return undefined
68
+ if (!targetsSelf(args.target)) return undefined
69
+ logger.warn?.(`im-qqbot: 拦下 plugin_manager ${args.action} ${args.target}(QQ 会话不能动本插件自己)`)
70
+ return 'plugin_manager 不能动 dsh-qqbot-plus 自己(im-qqbot):这条回合就跑在这个插件里,重载/卸载它会把当前回合卡死。管理别的插件没问题;本插件的代码改动请让主人重启 DSH 再生效。'
71
+ }), 'qqbot self guard')
72
+ logger.info('im-qqbot: 已拦截「plugin_manager 动自己」')
73
+ return true
74
+ }
@@ -0,0 +1,41 @@
1
+ import type { Logger, RawAttachment } from '../types.ts';
2
+ import type { MediaConfig } from '../config.ts';
3
+ /** 下载结果 */
4
+ export interface DownloadedFile {
5
+ /** QQ 下发的原始文件名(仅作来源标注,扩展名不可信——可能与 localPath 不一致) */
6
+ filename: string;
7
+ /** 附件类型 */
8
+ contentType: 'image' | 'video' | 'file';
9
+ /** 本地绝对路径;图片扩展名已按 magic bytes 校正(判类型以此为准,勿用 filename) */
10
+ localPath: string;
11
+ }
12
+ /** 附件归类(QQ 网关的 content_type 是 MIME 类型,如 image/png、video/mp4、audio/silk) */
13
+ export type MediaKind = 'image' | 'video' | 'voice' | 'file';
14
+ /** 是否为图片(兼容裸值 'image' 与 MIME 'image/png') */
15
+ export declare function isImageContentType(contentType?: string): boolean;
16
+ /** 是否为视频(兼容裸值 'video' 与 MIME 'video/mp4') */
17
+ export declare function isVideoContentType(contentType?: string): boolean;
18
+ /** 是否为语音(兼容裸值 'voice' 与 MIME 'audio/silk') */
19
+ export declare function isVoiceContentType(contentType?: string): boolean;
20
+ /** 归类附件 content_type 为统一类型 */
21
+ export declare function classifyContentType(contentType?: string): MediaKind;
22
+ /**
23
+ * 按魔数(magic bytes)识别图片真实扩展名,无法识别返回 undefined。
24
+ *
25
+ * 纯函数、零 I/O:QQ 网关的 content_type 统一标 image/png 不可信,只有文件头
26
+ * 可靠。每个分支都带长度守卫,短于所需字节的 buffer 直接落到末尾 undefined。
27
+ */
28
+ export declare function imageExtension(buf: Buffer): string | undefined;
29
+ /**
30
+ * 按图片真实格式修正路径扩展名,保留文件名主体(纯函数)。
31
+ * 未识别 / 已一致 / jpg≈jpeg 时原样返回,避免无意义改名。
32
+ */
33
+ export declare function correctImageExt(path: string, buf: Buffer): string;
34
+ /**
35
+ * 下载消息中的富媒体附件(image/video/file)到本地
36
+ *
37
+ * 下载目录固定为 ~/.dsh-qqbot/media,文件名用时间戳+随机数防重名。
38
+ * 下载失败不阻断(由调用方回退描述)。
39
+ */
40
+ export declare function downloadMediaAttachments(attachments: RawAttachment[] | undefined, media: MediaConfig, logger: Logger): Promise<DownloadedFile[]>;
41
+ //# sourceMappingURL=attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../../src/transport/attachment.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQhD,WAAW;AACX,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;IACxC,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7D,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,8BAA8B;AAC9B,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAKnE;AAiCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAY9D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjE;AA0DD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,EACxC,KAAK,EAA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