lightclawbot 1.1.2 → 1.2.0-beta.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.
Files changed (397) hide show
  1. package/README.md +0 -1
  2. package/dist/index.js +38 -31
  3. package/dist/setup-entry.js +32 -0
  4. package/dist/src/channel.js +166 -253
  5. package/dist/src/channel.setup.js +16 -0
  6. package/dist/src/config.js +31 -124
  7. package/dist/src/dedup.js +0 -1
  8. package/dist/src/download-tool.js +0 -1
  9. package/dist/src/file-storage.js +2 -2
  10. package/dist/src/gateway.js +224 -178
  11. package/dist/src/history/cron-utils.js +0 -1
  12. package/dist/src/history/index.js +0 -1
  13. package/dist/src/history/message-parser.js +0 -1
  14. package/dist/src/history/session-reader.js +3 -1
  15. package/dist/src/history/session-store.js +0 -1
  16. package/dist/src/history/text-processing.js +0 -1
  17. package/dist/src/history/types.js +0 -1
  18. package/dist/src/inbound.js +165 -234
  19. package/dist/src/media.js +0 -1
  20. package/dist/src/messaging.js +65 -0
  21. package/dist/src/outbound.js +129 -45
  22. package/dist/src/runtime.js +9 -11
  23. package/dist/src/setup-core.js +27 -0
  24. package/dist/src/shared.js +141 -0
  25. package/dist/src/socket/handlers.js +72 -49
  26. package/dist/src/socket/index.js +0 -1
  27. package/dist/src/socket/native-socket.js +385 -0
  28. package/dist/src/socket/registry.js +0 -1
  29. package/dist/src/socket/reliable-emitter.js +188 -50
  30. package/dist/src/streaming/delta-tracker.js +140 -0
  31. package/dist/src/streaming/index.js +12 -0
  32. package/dist/src/streaming/stream-reply-sink.js +387 -0
  33. package/dist/src/streaming/types.js +4 -0
  34. package/dist/src/tools.js +13 -0
  35. package/dist/src/types.js +22 -2
  36. package/dist/src/upload-tool.js +0 -1
  37. package/dist/src/utils/account.js +73 -0
  38. package/dist/src/utils/common.js +48 -0
  39. package/dist/src/utils/index.js +2 -0
  40. package/node_modules/ws/index.js +22 -0
  41. package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/constants.js +1 -0
  42. package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/permessage-deflate.js +6 -6
  43. package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/websocket-server.js +10 -6
  44. package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/websocket.js +19 -14
  45. package/node_modules/{engine.io-client/node_modules/ws → ws}/package.json +4 -3
  46. package/node_modules/ws/wrapper.mjs +21 -0
  47. package/openclaw.plugin.json +0 -7
  48. package/package.json +8 -5
  49. package/dist/index.d.ts +0 -24
  50. package/dist/index.d.ts.map +0 -1
  51. package/dist/index.js.map +0 -1
  52. package/dist/public/data/scripts/manifest.json +0 -11
  53. package/dist/public/data/scripts/preflight.9af62b39.sh +0 -191
  54. package/dist/public/data/scripts/preflight.sh +0 -191
  55. package/dist/src/channel.d.ts +0 -11
  56. package/dist/src/channel.d.ts.map +0 -1
  57. package/dist/src/channel.js.map +0 -1
  58. package/dist/src/config.d.ts +0 -129
  59. package/dist/src/config.d.ts.map +0 -1
  60. package/dist/src/config.js.map +0 -1
  61. package/dist/src/dedup.d.ts +0 -12
  62. package/dist/src/dedup.d.ts.map +0 -1
  63. package/dist/src/dedup.js.map +0 -1
  64. package/dist/src/download-tool.d.ts +0 -32
  65. package/dist/src/download-tool.d.ts.map +0 -1
  66. package/dist/src/download-tool.js.map +0 -1
  67. package/dist/src/file-storage.d.ts +0 -74
  68. package/dist/src/file-storage.d.ts.map +0 -1
  69. package/dist/src/file-storage.js.map +0 -1
  70. package/dist/src/format-urls.d.ts +0 -26
  71. package/dist/src/format-urls.d.ts.map +0 -1
  72. package/dist/src/format-urls.js +0 -53
  73. package/dist/src/format-urls.js.map +0 -1
  74. package/dist/src/gateway.d.ts +0 -16
  75. package/dist/src/gateway.d.ts.map +0 -1
  76. package/dist/src/gateway.js.map +0 -1
  77. package/dist/src/history/cron-utils.d.ts +0 -76
  78. package/dist/src/history/cron-utils.d.ts.map +0 -1
  79. package/dist/src/history/cron-utils.js.map +0 -1
  80. package/dist/src/history/index.d.ts +0 -20
  81. package/dist/src/history/index.d.ts.map +0 -1
  82. package/dist/src/history/index.js.map +0 -1
  83. package/dist/src/history/message-parser.d.ts +0 -52
  84. package/dist/src/history/message-parser.d.ts.map +0 -1
  85. package/dist/src/history/message-parser.js.map +0 -1
  86. package/dist/src/history/session-reader.d.ts +0 -58
  87. package/dist/src/history/session-reader.d.ts.map +0 -1
  88. package/dist/src/history/session-reader.js.map +0 -1
  89. package/dist/src/history/session-store.d.ts +0 -42
  90. package/dist/src/history/session-store.d.ts.map +0 -1
  91. package/dist/src/history/session-store.js.map +0 -1
  92. package/dist/src/history/text-processing.d.ts +0 -41
  93. package/dist/src/history/text-processing.d.ts.map +0 -1
  94. package/dist/src/history/text-processing.js.map +0 -1
  95. package/dist/src/history/types.d.ts +0 -134
  96. package/dist/src/history/types.d.ts.map +0 -1
  97. package/dist/src/history/types.js.map +0 -1
  98. package/dist/src/inbound.d.ts +0 -18
  99. package/dist/src/inbound.d.ts.map +0 -1
  100. package/dist/src/inbound.js.map +0 -1
  101. package/dist/src/media.d.ts +0 -12
  102. package/dist/src/media.d.ts.map +0 -1
  103. package/dist/src/media.js.map +0 -1
  104. package/dist/src/outbound.d.ts +0 -28
  105. package/dist/src/outbound.d.ts.map +0 -1
  106. package/dist/src/outbound.js.map +0 -1
  107. package/dist/src/runtime.d.ts +0 -4
  108. package/dist/src/runtime.d.ts.map +0 -1
  109. package/dist/src/runtime.js.map +0 -1
  110. package/dist/src/socket/handlers.d.ts +0 -26
  111. package/dist/src/socket/handlers.d.ts.map +0 -1
  112. package/dist/src/socket/handlers.js.map +0 -1
  113. package/dist/src/socket/index.d.ts +0 -11
  114. package/dist/src/socket/index.d.ts.map +0 -1
  115. package/dist/src/socket/index.js.map +0 -1
  116. package/dist/src/socket/registry.d.ts +0 -59
  117. package/dist/src/socket/registry.d.ts.map +0 -1
  118. package/dist/src/socket/registry.js.map +0 -1
  119. package/dist/src/socket/reliable-emitter.d.ts +0 -79
  120. package/dist/src/socket/reliable-emitter.d.ts.map +0 -1
  121. package/dist/src/socket/reliable-emitter.js.map +0 -1
  122. package/dist/src/types.d.ts +0 -112
  123. package/dist/src/types.d.ts.map +0 -1
  124. package/dist/src/types.js.map +0 -1
  125. package/dist/src/upload-tool.d.ts +0 -27
  126. package/dist/src/upload-tool.d.ts.map +0 -1
  127. package/dist/src/upload-tool.js.map +0 -1
  128. package/node_modules/@socket.io/component-emitter/LICENSE +0 -24
  129. package/node_modules/@socket.io/component-emitter/Readme.md +0 -79
  130. package/node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts +0 -179
  131. package/node_modules/@socket.io/component-emitter/lib/cjs/index.js +0 -176
  132. package/node_modules/@socket.io/component-emitter/lib/cjs/package.json +0 -4
  133. package/node_modules/@socket.io/component-emitter/lib/esm/index.d.ts +0 -179
  134. package/node_modules/@socket.io/component-emitter/lib/esm/index.js +0 -169
  135. package/node_modules/@socket.io/component-emitter/lib/esm/package.json +0 -4
  136. package/node_modules/@socket.io/component-emitter/package.json +0 -28
  137. package/node_modules/debug/LICENSE +0 -20
  138. package/node_modules/debug/README.md +0 -481
  139. package/node_modules/debug/package.json +0 -64
  140. package/node_modules/debug/src/browser.js +0 -272
  141. package/node_modules/debug/src/common.js +0 -292
  142. package/node_modules/debug/src/index.js +0 -10
  143. package/node_modules/debug/src/node.js +0 -263
  144. package/node_modules/engine.io-client/LICENSE +0 -22
  145. package/node_modules/engine.io-client/README.md +0 -331
  146. package/node_modules/engine.io-client/build/cjs/browser-entrypoint.d.ts +0 -3
  147. package/node_modules/engine.io-client/build/cjs/browser-entrypoint.js +0 -4
  148. package/node_modules/engine.io-client/build/cjs/contrib/has-cors.d.ts +0 -1
  149. package/node_modules/engine.io-client/build/cjs/contrib/has-cors.js +0 -14
  150. package/node_modules/engine.io-client/build/cjs/contrib/parseqs.d.ts +0 -15
  151. package/node_modules/engine.io-client/build/cjs/contrib/parseqs.js +0 -38
  152. package/node_modules/engine.io-client/build/cjs/contrib/parseuri.d.ts +0 -1
  153. package/node_modules/engine.io-client/build/cjs/contrib/parseuri.js +0 -67
  154. package/node_modules/engine.io-client/build/cjs/globals.d.ts +0 -4
  155. package/node_modules/engine.io-client/build/cjs/globals.js +0 -26
  156. package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +0 -21
  157. package/node_modules/engine.io-client/build/cjs/globals.node.js +0 -97
  158. package/node_modules/engine.io-client/build/cjs/index.d.ts +0 -15
  159. package/node_modules/engine.io-client/build/cjs/index.js +0 -32
  160. package/node_modules/engine.io-client/build/cjs/package.json +0 -10
  161. package/node_modules/engine.io-client/build/cjs/socket.d.ts +0 -482
  162. package/node_modules/engine.io-client/build/cjs/socket.js +0 -765
  163. package/node_modules/engine.io-client/build/cjs/transport.d.ts +0 -106
  164. package/node_modules/engine.io-client/build/cjs/transport.js +0 -153
  165. package/node_modules/engine.io-client/build/cjs/transports/index.d.ts +0 -8
  166. package/node_modules/engine.io-client/build/cjs/transports/index.js +0 -11
  167. package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts +0 -15
  168. package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.js +0 -60
  169. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +0 -108
  170. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +0 -285
  171. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts +0 -11
  172. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +0 -44
  173. package/node_modules/engine.io-client/build/cjs/transports/polling.d.ts +0 -52
  174. package/node_modules/engine.io-client/build/cjs/transports/polling.js +0 -165
  175. package/node_modules/engine.io-client/build/cjs/transports/websocket.d.ts +0 -36
  176. package/node_modules/engine.io-client/build/cjs/transports/websocket.js +0 -136
  177. package/node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts +0 -14
  178. package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +0 -68
  179. package/node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts +0 -18
  180. package/node_modules/engine.io-client/build/cjs/transports/webtransport.js +0 -94
  181. package/node_modules/engine.io-client/build/cjs/util.d.ts +0 -7
  182. package/node_modules/engine.io-client/build/cjs/util.js +0 -65
  183. package/node_modules/engine.io-client/build/esm/browser-entrypoint.d.ts +0 -3
  184. package/node_modules/engine.io-client/build/esm/browser-entrypoint.js +0 -2
  185. package/node_modules/engine.io-client/build/esm/contrib/has-cors.d.ts +0 -1
  186. package/node_modules/engine.io-client/build/esm/contrib/has-cors.js +0 -11
  187. package/node_modules/engine.io-client/build/esm/contrib/parseqs.d.ts +0 -15
  188. package/node_modules/engine.io-client/build/esm/contrib/parseqs.js +0 -34
  189. package/node_modules/engine.io-client/build/esm/contrib/parseuri.d.ts +0 -1
  190. package/node_modules/engine.io-client/build/esm/contrib/parseuri.js +0 -64
  191. package/node_modules/engine.io-client/build/esm/globals.d.ts +0 -4
  192. package/node_modules/engine.io-client/build/esm/globals.js +0 -22
  193. package/node_modules/engine.io-client/build/esm/globals.node.d.ts +0 -21
  194. package/node_modules/engine.io-client/build/esm/globals.node.js +0 -91
  195. package/node_modules/engine.io-client/build/esm/index.d.ts +0 -15
  196. package/node_modules/engine.io-client/build/esm/index.js +0 -15
  197. package/node_modules/engine.io-client/build/esm/package.json +0 -10
  198. package/node_modules/engine.io-client/build/esm/socket.d.ts +0 -482
  199. package/node_modules/engine.io-client/build/esm/socket.js +0 -727
  200. package/node_modules/engine.io-client/build/esm/transport.d.ts +0 -106
  201. package/node_modules/engine.io-client/build/esm/transport.js +0 -142
  202. package/node_modules/engine.io-client/build/esm/transports/index.d.ts +0 -8
  203. package/node_modules/engine.io-client/build/esm/transports/index.js +0 -8
  204. package/node_modules/engine.io-client/build/esm/transports/polling-fetch.d.ts +0 -15
  205. package/node_modules/engine.io-client/build/esm/transports/polling-fetch.js +0 -56
  206. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +0 -108
  207. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +0 -271
  208. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.d.ts +0 -11
  209. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +0 -17
  210. package/node_modules/engine.io-client/build/esm/transports/polling.d.ts +0 -52
  211. package/node_modules/engine.io-client/build/esm/transports/polling.js +0 -145
  212. package/node_modules/engine.io-client/build/esm/transports/websocket.d.ts +0 -36
  213. package/node_modules/engine.io-client/build/esm/transports/websocket.js +0 -125
  214. package/node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts +0 -14
  215. package/node_modules/engine.io-client/build/esm/transports/websocket.node.js +0 -41
  216. package/node_modules/engine.io-client/build/esm/transports/webtransport.d.ts +0 -18
  217. package/node_modules/engine.io-client/build/esm/transports/webtransport.js +0 -80
  218. package/node_modules/engine.io-client/build/esm/util.d.ts +0 -7
  219. package/node_modules/engine.io-client/build/esm/util.js +0 -59
  220. package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.d.ts +0 -3
  221. package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.js +0 -2
  222. package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.d.ts +0 -1
  223. package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js +0 -11
  224. package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.d.ts +0 -15
  225. package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js +0 -34
  226. package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.d.ts +0 -1
  227. package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js +0 -64
  228. package/node_modules/engine.io-client/build/esm-debug/globals.d.ts +0 -4
  229. package/node_modules/engine.io-client/build/esm-debug/globals.js +0 -22
  230. package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +0 -21
  231. package/node_modules/engine.io-client/build/esm-debug/globals.node.js +0 -91
  232. package/node_modules/engine.io-client/build/esm-debug/index.d.ts +0 -15
  233. package/node_modules/engine.io-client/build/esm-debug/index.js +0 -15
  234. package/node_modules/engine.io-client/build/esm-debug/package.json +0 -10
  235. package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +0 -482
  236. package/node_modules/engine.io-client/build/esm-debug/socket.js +0 -756
  237. package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +0 -106
  238. package/node_modules/engine.io-client/build/esm-debug/transport.js +0 -145
  239. package/node_modules/engine.io-client/build/esm-debug/transports/index.d.ts +0 -8
  240. package/node_modules/engine.io-client/build/esm-debug/transports/index.js +0 -8
  241. package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.d.ts +0 -15
  242. package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.js +0 -56
  243. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +0 -108
  244. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +0 -276
  245. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.d.ts +0 -11
  246. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js +0 -17
  247. package/node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts +0 -52
  248. package/node_modules/engine.io-client/build/esm-debug/transports/polling.js +0 -158
  249. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts +0 -36
  250. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.js +0 -128
  251. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.d.ts +0 -14
  252. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js +0 -41
  253. package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.d.ts +0 -18
  254. package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.js +0 -87
  255. package/node_modules/engine.io-client/build/esm-debug/util.d.ts +0 -7
  256. package/node_modules/engine.io-client/build/esm-debug/util.js +0 -59
  257. package/node_modules/engine.io-client/dist/engine.io.esm.min.js +0 -7
  258. package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +0 -1
  259. package/node_modules/engine.io-client/dist/engine.io.js +0 -3064
  260. package/node_modules/engine.io-client/dist/engine.io.js.map +0 -1
  261. package/node_modules/engine.io-client/dist/engine.io.min.js +0 -7
  262. package/node_modules/engine.io-client/dist/engine.io.min.js.map +0 -1
  263. package/node_modules/engine.io-client/node_modules/ws/index.js +0 -13
  264. package/node_modules/engine.io-client/node_modules/ws/wrapper.mjs +0 -8
  265. package/node_modules/engine.io-client/package.json +0 -95
  266. package/node_modules/engine.io-parser/LICENSE +0 -22
  267. package/node_modules/engine.io-parser/Readme.md +0 -158
  268. package/node_modules/engine.io-parser/build/cjs/commons.d.ts +0 -14
  269. package/node_modules/engine.io-parser/build/cjs/commons.js +0 -19
  270. package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.d.ts +0 -2
  271. package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.js +0 -48
  272. package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.d.ts +0 -2
  273. package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.js +0 -66
  274. package/node_modules/engine.io-parser/build/cjs/decodePacket.d.ts +0 -2
  275. package/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -59
  276. package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.d.ts +0 -4
  277. package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.js +0 -72
  278. package/node_modules/engine.io-parser/build/cjs/encodePacket.d.ts +0 -3
  279. package/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -38
  280. package/node_modules/engine.io-parser/build/cjs/index.d.ts +0 -9
  281. package/node_modules/engine.io-parser/build/cjs/index.js +0 -164
  282. package/node_modules/engine.io-parser/build/cjs/package.json +0 -8
  283. package/node_modules/engine.io-parser/build/esm/commons.d.ts +0 -14
  284. package/node_modules/engine.io-parser/build/esm/commons.js +0 -14
  285. package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.d.ts +0 -2
  286. package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js +0 -43
  287. package/node_modules/engine.io-parser/build/esm/decodePacket.browser.d.ts +0 -2
  288. package/node_modules/engine.io-parser/build/esm/decodePacket.browser.js +0 -62
  289. package/node_modules/engine.io-parser/build/esm/decodePacket.d.ts +0 -2
  290. package/node_modules/engine.io-parser/build/esm/decodePacket.js +0 -55
  291. package/node_modules/engine.io-parser/build/esm/encodePacket.browser.d.ts +0 -4
  292. package/node_modules/engine.io-parser/build/esm/encodePacket.browser.js +0 -68
  293. package/node_modules/engine.io-parser/build/esm/encodePacket.d.ts +0 -3
  294. package/node_modules/engine.io-parser/build/esm/encodePacket.js +0 -33
  295. package/node_modules/engine.io-parser/build/esm/index.d.ts +0 -9
  296. package/node_modules/engine.io-parser/build/esm/index.js +0 -156
  297. package/node_modules/engine.io-parser/build/esm/package.json +0 -8
  298. package/node_modules/engine.io-parser/package.json +0 -46
  299. package/node_modules/ms/index.js +0 -162
  300. package/node_modules/ms/license.md +0 -21
  301. package/node_modules/ms/package.json +0 -38
  302. package/node_modules/ms/readme.md +0 -59
  303. package/node_modules/socket.io-client/LICENSE +0 -21
  304. package/node_modules/socket.io-client/README.md +0 -29
  305. package/node_modules/socket.io-client/build/cjs/browser-entrypoint.d.ts +0 -2
  306. package/node_modules/socket.io-client/build/cjs/browser-entrypoint.js +0 -4
  307. package/node_modules/socket.io-client/build/cjs/contrib/backo2.d.ts +0 -12
  308. package/node_modules/socket.io-client/build/cjs/contrib/backo2.js +0 -69
  309. package/node_modules/socket.io-client/build/cjs/index.d.ts +0 -29
  310. package/node_modules/socket.io-client/build/cjs/index.js +0 -76
  311. package/node_modules/socket.io-client/build/cjs/manager.d.ts +0 -295
  312. package/node_modules/socket.io-client/build/cjs/manager.js +0 -416
  313. package/node_modules/socket.io-client/build/cjs/on.d.ts +0 -2
  314. package/node_modules/socket.io-client/build/cjs/on.js +0 -9
  315. package/node_modules/socket.io-client/build/cjs/socket.d.ts +0 -593
  316. package/node_modules/socket.io-client/build/cjs/socket.js +0 -909
  317. package/node_modules/socket.io-client/build/cjs/url.d.ts +0 -33
  318. package/node_modules/socket.io-client/build/cjs/url.js +0 -69
  319. package/node_modules/socket.io-client/build/esm/browser-entrypoint.d.ts +0 -2
  320. package/node_modules/socket.io-client/build/esm/browser-entrypoint.js +0 -2
  321. package/node_modules/socket.io-client/build/esm/contrib/backo2.d.ts +0 -12
  322. package/node_modules/socket.io-client/build/esm/contrib/backo2.js +0 -66
  323. package/node_modules/socket.io-client/build/esm/index.d.ts +0 -29
  324. package/node_modules/socket.io-client/build/esm/index.js +0 -58
  325. package/node_modules/socket.io-client/build/esm/manager.d.ts +0 -295
  326. package/node_modules/socket.io-client/build/esm/manager.js +0 -367
  327. package/node_modules/socket.io-client/build/esm/on.d.ts +0 -2
  328. package/node_modules/socket.io-client/build/esm/on.js +0 -6
  329. package/node_modules/socket.io-client/build/esm/package.json +0 -5
  330. package/node_modules/socket.io-client/build/esm/socket.d.ts +0 -593
  331. package/node_modules/socket.io-client/build/esm/socket.js +0 -880
  332. package/node_modules/socket.io-client/build/esm/url.d.ts +0 -33
  333. package/node_modules/socket.io-client/build/esm/url.js +0 -59
  334. package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.d.ts +0 -2
  335. package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.js +0 -2
  336. package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.d.ts +0 -12
  337. package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.js +0 -66
  338. package/node_modules/socket.io-client/build/esm-debug/index.d.ts +0 -29
  339. package/node_modules/socket.io-client/build/esm-debug/index.js +0 -62
  340. package/node_modules/socket.io-client/build/esm-debug/manager.d.ts +0 -295
  341. package/node_modules/socket.io-client/build/esm-debug/manager.js +0 -386
  342. package/node_modules/socket.io-client/build/esm-debug/on.d.ts +0 -2
  343. package/node_modules/socket.io-client/build/esm-debug/on.js +0 -6
  344. package/node_modules/socket.io-client/build/esm-debug/package.json +0 -5
  345. package/node_modules/socket.io-client/build/esm-debug/socket.d.ts +0 -593
  346. package/node_modules/socket.io-client/build/esm-debug/socket.js +0 -902
  347. package/node_modules/socket.io-client/build/esm-debug/url.d.ts +0 -33
  348. package/node_modules/socket.io-client/build/esm-debug/url.js +0 -63
  349. package/node_modules/socket.io-client/dist/socket.io.esm.min.js +0 -7
  350. package/node_modules/socket.io-client/dist/socket.io.esm.min.js.map +0 -1
  351. package/node_modules/socket.io-client/dist/socket.io.js +0 -4955
  352. package/node_modules/socket.io-client/dist/socket.io.js.map +0 -1
  353. package/node_modules/socket.io-client/dist/socket.io.min.js +0 -7
  354. package/node_modules/socket.io-client/dist/socket.io.min.js.map +0 -1
  355. package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js +0 -7
  356. package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js.map +0 -1
  357. package/node_modules/socket.io-client/package.json +0 -101
  358. package/node_modules/socket.io-parser/LICENSE +0 -20
  359. package/node_modules/socket.io-parser/Readme.md +0 -81
  360. package/node_modules/socket.io-parser/build/cjs/binary.d.ts +0 -20
  361. package/node_modules/socket.io-parser/build/cjs/binary.js +0 -87
  362. package/node_modules/socket.io-parser/build/cjs/index.d.ts +0 -101
  363. package/node_modules/socket.io-parser/build/cjs/index.js +0 -367
  364. package/node_modules/socket.io-parser/build/cjs/is-binary.d.ts +0 -7
  365. package/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -54
  366. package/node_modules/socket.io-parser/build/cjs/package.json +0 -3
  367. package/node_modules/socket.io-parser/build/esm/binary.d.ts +0 -20
  368. package/node_modules/socket.io-parser/build/esm/binary.js +0 -83
  369. package/node_modules/socket.io-parser/build/esm/index.d.ts +0 -101
  370. package/node_modules/socket.io-parser/build/esm/index.js +0 -356
  371. package/node_modules/socket.io-parser/build/esm/is-binary.d.ts +0 -7
  372. package/node_modules/socket.io-parser/build/esm/is-binary.js +0 -50
  373. package/node_modules/socket.io-parser/build/esm/package.json +0 -3
  374. package/node_modules/socket.io-parser/build/esm-debug/binary.d.ts +0 -20
  375. package/node_modules/socket.io-parser/build/esm-debug/binary.js +0 -83
  376. package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +0 -101
  377. package/node_modules/socket.io-parser/build/esm-debug/index.js +0 -361
  378. package/node_modules/socket.io-parser/build/esm-debug/is-binary.d.ts +0 -7
  379. package/node_modules/socket.io-parser/build/esm-debug/is-binary.js +0 -50
  380. package/node_modules/socket.io-parser/build/esm-debug/package.json +0 -3
  381. package/node_modules/socket.io-parser/package.json +0 -44
  382. package/node_modules/xmlhttprequest-ssl/LICENSE +0 -22
  383. package/node_modules/xmlhttprequest-ssl/README.md +0 -67
  384. package/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +0 -689
  385. package/node_modules/xmlhttprequest-ssl/package.json +0 -40
  386. /package/node_modules/{engine.io-client/node_modules/ws → ws}/LICENSE +0 -0
  387. /package/node_modules/{engine.io-client/node_modules/ws → ws}/README.md +0 -0
  388. /package/node_modules/{engine.io-client/node_modules/ws → ws}/browser.js +0 -0
  389. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/buffer-util.js +0 -0
  390. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/event-target.js +0 -0
  391. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/extension.js +0 -0
  392. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/limiter.js +0 -0
  393. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/receiver.js +0 -0
  394. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/sender.js +0 -0
  395. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/stream.js +0 -0
  396. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/subprotocol.js +0 -0
  397. /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/validation.js +0 -0
@@ -4,20 +4,39 @@
4
4
  * 处理 OpenClaw 框架层的主动消息发送(非 deliver 回调场景)。
5
5
  * 例如:用户通过 /message 命令发消息、cron 定时任务触发等。
6
6
  *
7
- * 发送策略:
7
+ * 发送策略(双通道 + 自动降级):
8
8
  * 1. 优先通过 gateway 的 WS 长连接发送(socket-registry)
9
+ * - 连接正常 → 走可靠发送(emitWithAck + 自动重试)
10
+ * - 连接断开但 entry 存在(重连中)→ 缓冲消息,重连后自动 flush
9
11
  * 2. WS 不可用时 fallback 到 REST API(需配置 apiBaseUrl)
10
12
  */
11
- import { resolveAccount, CHANNEL_KEY, DEFAULT_ACCOUNT_ID, EVENT_MESSAGE_PRIVATE } from "./config.js";
12
- import { getAssistantRuntime } from "./runtime.js";
13
- import { getSocket, bufferMessage, hasEntry, getBotClientId, getReliableEmitter } from "./socket/index.js";
14
- import { formatCosUrls } from "./format-urls.js";
15
- /** 获取日志器 */
13
+ import { CHANNEL_KEY, DEFAULT_ACCOUNT_ID, EVENT_MESSAGE_PRIVATE } from './config.js';
14
+ import { getLightclawRuntime } from './runtime.js';
15
+ import { getSocket, bufferMessage, hasEntry, getBotClientId, getReliableEmitter } from './socket/index.js';
16
+ import { resolveAccount } from './utils/index.js';
17
+ /**
18
+ * 获取出站模块专属日志器。
19
+ * 通过 getChildLogger 注入 module 标签,方便在日志系统中过滤出站相关日志。
20
+ */
16
21
  function getLogger() {
17
- return getAssistantRuntime().logging.getChildLogger({ module: "outbound" });
22
+ return getLightclawRuntime().logging.getChildLogger({ module: 'outbound' });
18
23
  }
19
- /** 生成消息 ID */
24
+ /**
25
+ * 出站消息 ID 计数器,用于生成全局唯一的消息序号。
26
+ * 模块级变量,进程生命周期内单调递增,不会重置。
27
+ */
20
28
  let outboundMsgCounter = 0;
29
+ /**
30
+ * 生成出站消息的唯一 ID。
31
+ *
32
+ * ID 格式:`ob-<时间戳base36>-<随机串>-<序号base36>`
33
+ * - `ob-` 前缀:标识来源为 outbound 模块,便于日志追踪
34
+ * - 时间戳(base36):毫秒级,保证时间有序性
35
+ * - 随机串(6位):防止同一毫秒内的碰撞
36
+ * - 序号(base36):进程内单调递增,兜底保证唯一性
37
+ *
38
+ * @returns 格式为 `ob-<ts>-<rand>-<seq>` 的唯一消息 ID
39
+ */
21
40
  function generateOutboundMsgId() {
22
41
  const ts = Date.now().toString(36);
23
42
  const rand = Math.random().toString(36).substring(2, 8);
@@ -25,40 +44,68 @@ function generateOutboundMsgId() {
25
44
  return `ob-${ts}-${rand}-${seq}`;
26
45
  }
27
46
  /**
28
- * 解析目标用户 ID:去掉各种前缀,提取纯 ID
29
- * 支持格式: user:xxx, channel:xxx, lightclawbot:dm:xxx, lightclawbot:group:xxx, dm:xxx, 纯ID
47
+ * 解析消息目标地址,提取纯用户/群组 ID
48
+ *
49
+ * 支持的输入格式(均会被剥离前缀,返回纯 ID):
50
+ * - `lightclawbot:dm:123` → `123`
51
+ * - `lightclawbot:group:456` → `456`
52
+ * - `user:123` → `123`
53
+ * - `channel:456` → `456`
54
+ * - `dm:123` → `123`
55
+ * - `group:456` → `456`
56
+ * - `123` → `123`(纯 ID,原样返回)
57
+ *
58
+ * @param to - 原始目标地址字符串
59
+ * @returns 去除所有前缀后的纯 ID 字符串
30
60
  */
31
61
  function resolveTarget(to) {
32
- return to
33
- .replace(new RegExp(`^${CHANNEL_KEY}:`, "i"), "")
34
- .replace(/^(user|channel|dm|group):/, "");
62
+ return (to
63
+ // 第一步:去掉通道名前缀(如 "lightclawbot:"
64
+ .replace(new RegExp(`^${CHANNEL_KEY}:`, 'i'), '')
65
+ // 第二步:去掉类型前缀(user: / channel: / dm: / group:)
66
+ .replace(/^(user|channel|dm|group):/, ''));
35
67
  }
36
68
  /**
37
- * 通过 WS 发送消息。
69
+ * 通过 WebSocket 长连接发送消息。
38
70
  *
39
- * 策略:
40
- * 1. socket connected直接发送
41
- * 2. socket 断开但 entry 存在(正在重连中)→ 缓冲消息,重连后自动 flush
42
- * 3. entry 不存在 → 返回 null(gateway 尚未启动或已销毁)
71
+ * 内部策略(按优先级):
72
+ * 1. **可靠发送**:entry 存在且 socket 已连接使用 `emitWithAck` 发送,
73
+ * 内置 ACK 确认 + 自动重试,发送失败时记录错误日志。
74
+ * 2. **直接 emit(兜底)**:可靠发送器不可用时,直接调用 `socket.emit`,
75
+ * 不保证送达,仅作为最后防线。
76
+ * 3. **消息缓冲**:socket 断开但 entry 仍存在(正在自动重连)→
77
+ * 将消息写入缓冲队列,重连成功后由 gateway 自动 flush。
78
+ * 4. **返回 null**:entry 不存在(gateway 未启动或已销毁)→
79
+ * 调用方应降级到 REST API。
80
+ *
81
+ * @param accountId - 发送账户 ID,为空时使用 DEFAULT_ACCOUNT_ID
82
+ * @param target - 已解析的纯目标 ID(用户 ID 或群组 ID)
83
+ * @param text - 消息文本内容
84
+ * @param replyToId - 回复的原始消息 ID(可选)
85
+ * @returns 成功时返回消息 ID 字符串;无法通过 WS 发送时返回 null
43
86
  */
44
87
  function sendViaSocket(accountId, target, text, replyToId) {
45
88
  const resolvedAccountId = accountId || DEFAULT_ACCOUNT_ID;
89
+ // 从 socket-registry 中获取当前账户的 socket entry
46
90
  const entry = getSocket(resolvedAccountId);
47
91
  const msgId = generateOutboundMsgId();
92
+ // 构造标准消息体,格式与 gateway 入站消息保持一致
48
93
  const message = {
49
94
  msgId,
50
- from: entry?.botClientId ?? getBotClientId(resolvedAccountId) ?? "",
95
+ // 优先使用 entry 中缓存的 botClientId,entry 不存在时从 registry 直接查询
96
+ from: entry?.botClientId ?? getBotClientId(resolvedAccountId) ?? '',
51
97
  to: target,
52
- content: formatCosUrls(text),
98
+ content: text,
53
99
  timestamp: Date.now(),
100
+ // undefined 表示非回复消息,避免发送多余字段
54
101
  replyToMsgId: replyToId ?? undefined,
55
102
  };
56
103
  if (entry) {
57
- // Socket connected 优先走可靠发送
104
+ // 策略 1:Socket 已连接,优先走可靠发送(emitWithAck + 自动重试)
58
105
  const emitter = getReliableEmitter(resolvedAccountId);
59
106
  if (emitter) {
60
- emitter.emitWithAck(EVENT_MESSAGE_PRIVATE, message, msgId)
61
- .then(ok => {
107
+ emitter.emitWithAck(EVENT_MESSAGE_PRIVATE, message, msgId).then((ok) => {
108
+ // ok=false 表示重试耗尽仍未收到 ACK,记录错误供告警系统捕获
62
109
  if (!ok) {
63
110
  getLogger().error(`[${CHANNEL_KEY}] outbound delivery failed after retries: msgId=${msgId}`);
64
111
  }
@@ -66,18 +113,20 @@ function sendViaSocket(accountId, target, text, replyToId) {
66
113
  getLogger().info(`[${CHANNEL_KEY}] outbound sent via reliable WS: to=${target} msgId=${msgId}`);
67
114
  return msgId;
68
115
  }
69
- // fallback: 直接 emit(不应走到这里,但保留兜底)
116
+ // 策略 2:可靠发送器不可用,直接 emit(兜底,正常情况不应走到此分支)
70
117
  try {
71
118
  entry.socket.emit(EVENT_MESSAGE_PRIVATE, message);
72
119
  getLogger().info(`[${CHANNEL_KEY}] outbound sent via WS (fallback): to=${target} msgId=${msgId}`);
73
120
  return msgId;
74
121
  }
75
122
  catch (err) {
123
+ // emit 本身抛异常(如 socket 已关闭),降级到 REST API
76
124
  getLogger().warn(`[${CHANNEL_KEY}] outbound WS emit failed: ${err}`);
77
125
  return null;
78
126
  }
79
127
  }
80
- // Socket 断开但 entry 存在(正在自动重连),缓冲消息
128
+ // 策略 3:Socket 断开但 entry 存在(正在自动重连),将消息写入缓冲队列
129
+ // 重连成功后,gateway 会自动 flush 缓冲队列,保证消息最终送达
81
130
  if (hasEntry(resolvedAccountId)) {
82
131
  const buffered = bufferMessage(resolvedAccountId, message);
83
132
  if (buffered) {
@@ -85,32 +134,47 @@ function sendViaSocket(accountId, target, text, replyToId) {
85
134
  return msgId;
86
135
  }
87
136
  }
88
- // Entry 不存在,gateway 未启动或已销毁
137
+ // 策略 4:entry 不存在,gateway 未启动或已销毁,返回 null 触发 REST 降级
89
138
  return null;
90
139
  }
91
140
  /**
92
- * 发送文本消息
93
- * 由 channel.outbound.sendText 调用
141
+ * 发送纯文本消息。
142
+ *
143
+ * 由 `channel.outbound.sendText` 调用,是框架层文本消息的统一出口。
144
+ *
145
+ * 发送流程:
146
+ * 1. 解析账户配置(API Key、Base URL 等)
147
+ * 2. 规范化目标地址(去除前缀,提取纯 ID)
148
+ * 3. 优先通过 WS 发送;WS 不可用时降级到 REST API
149
+ * 4. REST API 也不可用时抛出错误,由框架层统一处理
150
+ *
151
+ * @param ctx - OpenClaw 框架注入的出站上下文,包含 to、text、accountId、replyToId、cfg 等字段
152
+ * @returns `{ channel, messageId }` — 发送成功后的通道标识和消息 ID
153
+ * @throws 当 WS 和 REST API 均不可用时抛出 Error
94
154
  */
95
155
  export async function sendText(ctx) {
96
156
  const log = getLogger();
97
157
  try {
158
+ // 解析账户配置(含 apiKey、apiBaseUrl、accountId 等)
98
159
  const account = resolveAccount(ctx.cfg, ctx.accountId);
160
+ // 将框架格式的目标地址转换为纯 ID
99
161
  const target = resolveTarget(ctx.to);
100
- // 优先走 WS
162
+ // 优先走 WS 长连接(低延迟、无额外网络开销)
101
163
  const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
102
164
  if (wsMsgId) {
103
165
  return { channel: CHANNEL_KEY, messageId: wsMsgId };
104
166
  }
105
- // Fallback: REST API
167
+ // WS 不可用,降级到 REST API
168
+ // 若未配置 apiBaseUrl,则无法降级,直接抛出错误
106
169
  if (!account.apiBaseUrl) {
107
- throw new Error("WS not connected and apiBaseUrl not configured, cannot send outbound message");
170
+ throw new Error('WS not connected and apiBaseUrl not configured, cannot send outbound message');
108
171
  }
109
172
  log.info(`[${CHANNEL_KEY}] outbound fallback to REST API: to=${target}`);
110
173
  const resp = await fetch(`${account.apiBaseUrl}/send`, {
111
- method: "POST",
174
+ method: 'POST',
112
175
  headers: {
113
- "Content-Type": "application/json",
176
+ 'Content-Type': 'application/json',
177
+ // Bearer Token 鉴权,apiKey 来自账户配置
114
178
  Authorization: `Bearer ${account.apiKey}`,
115
179
  },
116
180
  body: JSON.stringify({
@@ -119,11 +183,13 @@ export async function sendText(ctx) {
119
183
  replyToMessageId: ctx.replyToId,
120
184
  }),
121
185
  });
186
+ // HTTP 非 2xx 状态码视为发送失败,读取响应体作为错误信息
122
187
  if (!resp.ok) {
123
188
  const errText = await resp.text();
124
189
  throw new Error(`Send failed (${resp.status}): ${errText}`);
125
190
  }
126
191
  const data = (await resp.json());
192
+ // 服务端未返回 messageId 时,使用时间戳兜底,保证返回值非空
127
193
  return { channel: CHANNEL_KEY, messageId: data.messageId ?? `msg_${Date.now()}` };
128
194
  }
129
195
  catch (err) {
@@ -132,50 +198,69 @@ export async function sendText(ctx) {
132
198
  }
133
199
  }
134
200
  /**
135
- * 发送媒体消息
136
- * 由 channel.outbound.sendMedia 调用
201
+ * 发送媒体消息(图片、文件、视频等)。
202
+ *
203
+ * 由 `channel.outbound.sendMedia` 调用,是框架层媒体消息的统一出口。
204
+ *
205
+ * 发送策略(媒体消息比文本消息更复杂,需区分是否有 mediaUrl):
206
+ * - **无 mediaUrl**:仅发送文字说明,走 WS → REST 降级链路(与 sendText 一致)
207
+ * - **有 mediaUrl + 有 REST API**:走 REST API 发送完整媒体消息(含 URL)
208
+ * - **有 mediaUrl + 无 REST API**:WS 不支持大文件传输,仅发送文字说明部分
209
+ * - **WS 和 REST 均不可用**:抛出错误
210
+ *
211
+ * 注意:WS 通道不适合传输大文件(二进制数据),因此媒体文件始终通过 REST API 发送;
212
+ * WS 仅用于发送媒体消息的文字说明部分(作为降级兜底)。
213
+ *
214
+ * @param ctx - OpenClaw 框架注入的出站上下文,包含 to、text、mediaUrl、accountId、replyToId、cfg 等字段
215
+ * @returns `{ channel, messageId }` — 发送成功后的通道标识和消息 ID
216
+ * @throws 当 WS 和 REST API 均不可用时抛出 Error
137
217
  */
138
218
  export async function sendMedia(ctx) {
139
219
  const log = getLogger();
140
220
  try {
221
+ // 解析账户配置
141
222
  const account = resolveAccount(ctx.cfg, ctx.accountId);
223
+ // 规范化目标地址
142
224
  const target = resolveTarget(ctx.to);
143
- // 优先走 WS(媒体消息只发文本部分,因为 WS 不方便传大文件)
144
- // 如果有 mediaUrl 且没有 REST API,仍用 WS 发文本
225
+ // mediaUrl 时,退化为纯文本发送,走 WS → REST 降级链路
145
226
  if (!ctx.mediaUrl) {
146
227
  const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
147
228
  if (wsMsgId) {
148
229
  return { channel: CHANNEL_KEY, messageId: wsMsgId };
149
230
  }
150
231
  }
151
- // Fallback: REST API
232
+ // 未配置 REST API 时的兜底处理:
233
+ // 即使有 mediaUrl 也无法发送完整媒体,退而发送文字说明部分(通过 WS)
152
234
  if (!account.apiBaseUrl) {
153
- // 没有 REST API 也没有 mediaUrl,用 WS 发文本
154
235
  const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
155
236
  if (wsMsgId) {
156
237
  return { channel: CHANNEL_KEY, messageId: wsMsgId };
157
238
  }
158
- throw new Error("WS not connected and apiBaseUrl not configured, cannot send outbound media");
239
+ // WS 也不可用,彻底无法发送,抛出错误
240
+ throw new Error('WS not connected and apiBaseUrl not configured, cannot send outbound media');
159
241
  }
242
+ // 通过 REST API 发送完整媒体消息(含 mediaUrl)
160
243
  log.info(`[${CHANNEL_KEY}] outbound media via REST API: to=${target}`);
161
244
  const resp = await fetch(`${account.apiBaseUrl}/send-media`, {
162
- method: "POST",
245
+ method: 'POST',
163
246
  headers: {
164
- "Content-Type": "application/json",
247
+ 'Content-Type': 'application/json',
165
248
  Authorization: `Bearer ${account.apiKey}`,
166
249
  },
167
250
  body: JSON.stringify({
168
251
  target,
169
- text: ctx.text,
170
- mediaUrl: ctx.mediaUrl,
252
+ text: ctx.text, // 媒体消息的文字说明(可选)
253
+ mediaUrl: ctx.mediaUrl, // 媒体资源 URL(图片/文件/视频等)
171
254
  replyToMessageId: ctx.replyToId,
172
255
  }),
173
256
  });
257
+ // HTTP 非 2xx 状态码视为发送失败
174
258
  if (!resp.ok) {
175
259
  const errText = await resp.text();
176
260
  throw new Error(`Send media failed (${resp.status}): ${errText}`);
177
261
  }
178
262
  const data = (await resp.json());
263
+ // 服务端未返回 messageId 时,使用时间戳兜底
179
264
  return { channel: CHANNEL_KEY, messageId: data.messageId ?? `msg_${Date.now()}` };
180
265
  }
181
266
  catch (err) {
@@ -183,4 +268,3 @@ export async function sendMedia(ctx) {
183
268
  throw err;
184
269
  }
185
270
  }
186
- //# sourceMappingURL=outbound.js.map
@@ -1,11 +1,9 @@
1
- import { CHANNEL_KEY } from "./config.js";
2
- let runtime;
3
- export function setAssistantRuntime(rt) {
4
- runtime = rt;
5
- }
6
- export function getAssistantRuntime() {
7
- if (!runtime)
8
- throw new Error(`[${CHANNEL_KEY}] PluginRuntime not initialized register() not called yet`);
9
- return runtime;
10
- }
11
- //# sourceMappingURL=runtime.js.map
1
+ /**
2
+ * LightClaw — 插件运行时存储
3
+ *
4
+ * 使用 SDK 标准的 createPluginRuntimeStore 替代手动单例管理,
5
+ * 确保与官方 channel 插件(Discord/Slack)的模式一致。
6
+ */
7
+ import { createPluginRuntimeStore } from 'openclaw/plugin-sdk/runtime-store';
8
+ const { setRuntime: setLightclawRuntime, getRuntime: getLightclawRuntime } = createPluginRuntimeStore('LightClaw runtime not initialized');
9
+ export { getLightclawRuntime, setLightclawRuntime };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * LightClaw — Setup 核心逻辑
3
+ *
4
+ * 从 channel.ts 中提取的 setup 适配器,
5
+ * 被 channel.ts(完整插件)和 channel.setup.ts(轻量 setup 插件)共享。
6
+ */
7
+ import { applyAccountNameToChannelSection } from 'openclaw/plugin-sdk/core';
8
+ import { CHANNEL_KEY, applyAccountConfig } from './config.js';
9
+ import { defaultAccountId } from './utils/account.js';
10
+ export const lightclawSetupAdapter = {
11
+ resolveAccountId: ({ accountId, cfg }) => accountId?.trim().toLowerCase() || defaultAccountId(cfg),
12
+ applyAccountName: ({ cfg, accountId, name }) => applyAccountNameToChannelSection({ cfg, channelKey: CHANNEL_KEY, accountId, name }),
13
+ validateInput: ({ input }) => {
14
+ if (!input.token && !input.useEnv) {
15
+ return 'Requires --token <apiKey> or --use-env (set LIGHTCLAW_API_KEY, LIGHTCLAW_API_BASE_URL)';
16
+ }
17
+ return null;
18
+ },
19
+ applyAccountConfig: ({ cfg, accountId, input }) => {
20
+ const token = input.token;
21
+ return applyAccountConfig(cfg, accountId, {
22
+ apiKey: token,
23
+ apiBaseUrl: input.apiBaseUrl,
24
+ name: input.name,
25
+ });
26
+ },
27
+ };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * LightClaw — 插件基础定义(shared)
3
+ *
4
+ * 参照官方 Discord/Slack 的 shared.ts 模式:
5
+ * - 提供 createLightclawPluginBase() 工厂函数
6
+ * - 共享 config adapter 和常量
7
+ *
8
+ * 此模块被 channel.ts(完整插件)和 channel.setup.ts(轻量 setup 插件)同时使用。
9
+ */
10
+ import { createChannelPluginBase, deleteAccountFromConfigSection, setAccountEnabledInConfigSection, } from 'openclaw/plugin-sdk/core';
11
+ import { CHANNEL_KEY, DEFAULT_ACCOUNT_ID } from './config.js';
12
+ import { listAccountIds, resolveAccount, defaultAccountId } from './utils/account.js';
13
+ // ============================================================
14
+ // 配置适配器
15
+ // ============================================================
16
+ /**
17
+ * LightClaw 配置适配器(config section)
18
+ *
19
+ * 官方渠道使用 createScopedChannelConfigAdapter,
20
+ * LightClaw 因有自定义的 apiKeys 数组等特殊配置,保留自定义实现。
21
+ */
22
+ export const lightclawConfigAdapter = {
23
+ /**
24
+ * 列出当前配置中所有已注册的账户 ID。
25
+ * @param cfg - 全局 OpenClaw 配置对象
26
+ */
27
+ listAccountIds: (cfg) => listAccountIds(cfg),
28
+ /**
29
+ * 根据账户 ID 解析出完整的账户配置对象(含 API Key、Base URL 等)。
30
+ * @param cfg - 全局配置对象
31
+ * @param accountId - 目标账户 ID
32
+ */
33
+ resolveAccount: (cfg, accountId) => {
34
+ return resolveAccount(cfg, accountId);
35
+ },
36
+ /**
37
+ * 获取默认账户 ID(通常为 DEFAULT_ACCOUNT_ID 常量)。
38
+ * @param cfg - 全局配置对象
39
+ */
40
+ defaultAccountId: (cfg) => defaultAccountId(cfg),
41
+ /**
42
+ * 启用或禁用指定账户。
43
+ * 委托给 SDK 的 setAccountEnabledInConfigSection 工具函数,
44
+ * allowTopLevel=true 表示允许在顶层配置节(非 accounts 子对象)中操作。
45
+ */
46
+ setAccountEnabled: ({ cfg, accountId, enabled }) => {
47
+ return setAccountEnabledInConfigSection({
48
+ cfg,
49
+ sectionKey: CHANNEL_KEY,
50
+ accountId,
51
+ enabled,
52
+ allowTopLevel: true,
53
+ });
54
+ },
55
+ /**
56
+ * 从配置中删除指定账户,同时清除关联的基础字段。
57
+ * clearBaseFields 指定了删除账户时需要一并清空的顶层字段。
58
+ */
59
+ deleteAccount: ({ cfg, accountId }) => {
60
+ return deleteAccountFromConfigSection({
61
+ cfg,
62
+ sectionKey: CHANNEL_KEY,
63
+ accountId,
64
+ clearBaseFields: ['apiBaseUrl', 'name'],
65
+ });
66
+ },
67
+ /**
68
+ * 判断账户是否已完成配置, apiKey是否存在。
69
+ * @param account - 已解析的账户对象
70
+ */
71
+ isConfigured: (account) => {
72
+ return Boolean(account?.apiKey);
73
+ },
74
+ /**
75
+ * 将账户信息序列化为框架可展示的摘要对象。
76
+ * 用于 CLI 的 `status` 命令和 UI 的账户列表展示。
77
+ * @param account - 已解析的账户对象
78
+ */
79
+ describeAccount: (account) => ({
80
+ accountId: account.accountId ?? DEFAULT_ACCOUNT_ID,
81
+ name: account.name || '',
82
+ enabled: account.enabled ?? false,
83
+ configured: Boolean(account?.apiKey),
84
+ }),
85
+ /**
86
+ * 解析账户的 allowFrom 白名单列表(允许接收消息的来源 ID)。
87
+ * 返回字符串数组,供框架做入站消息过滤。
88
+ * @param cfg - 全局配置对象
89
+ * @param accountId - 目标账户 ID
90
+ */
91
+ resolveAllowFrom: ({ cfg, accountId }) => {
92
+ const account = resolveAccount(cfg, accountId);
93
+ return account.allowFrom?.map(String) ?? [];
94
+ },
95
+ };
96
+ // ============================================================
97
+ // 插件基础工厂
98
+ // ============================================================
99
+ /**
100
+ * createLightclawPluginBase
101
+ *
102
+ * 参照 Discord 的 createDiscordPluginBase / Slack 的 createSlackPluginBase 模式,
103
+ * 使用 SDK 提供的 createChannelPluginBase 构建插件骨架。
104
+ *
105
+ * 返回的字段集(id, meta, capabilities, streaming, configSchema, config, setup)
106
+ * 被 channel.ts 和 channel.setup.ts 共享。
107
+ */
108
+ export function createLightclawPluginBase(params) {
109
+ return createChannelPluginBase({
110
+ id: CHANNEL_KEY,
111
+ meta: {
112
+ id: CHANNEL_KEY,
113
+ label: 'LightClawBot',
114
+ selectionLabel: 'LightClawBot',
115
+ docsPath: '/docs/channels/lightclawbot',
116
+ blurb: 'Connect OpenClaw to your LightClawBot via WebSocket long-connection',
117
+ order: 60,
118
+ },
119
+ capabilities: {
120
+ chatTypes: ['direct'],
121
+ media: true,
122
+ reactions: false,
123
+ threads: false,
124
+ // true = deliver 回调会收到 kind="block" 的中间块,实现流式推送
125
+ blockStreaming: true,
126
+ },
127
+ streaming: {
128
+ blockStreamingCoalesceDefaults: { minChars: 1500, idleMs: 1000 },
129
+ },
130
+ reload: { configPrefixes: [`channels.${CHANNEL_KEY}`] },
131
+ configSchema: {
132
+ schema: {
133
+ type: 'object',
134
+ additionalProperties: false,
135
+ properties: {},
136
+ },
137
+ },
138
+ config: lightclawConfigAdapter,
139
+ setup: params.setup,
140
+ });
141
+ }