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
@@ -0,0 +1,387 @@
1
+ /**
2
+ * LightClaw — 真流式回复分发 (StreamReplySink)
3
+ *
4
+ * 通过 `dispatchReplyFromConfig` 的回调实现逐 token 流式输出:
5
+ * - onPartialReply → 计算增量 → emit stream_chunk
6
+ * - onToolStart → emit tool_start(前端决定如何渲染)
7
+ * - sendFinalReply → 跨轮次去重后发送剩余增量(或丢弃)
8
+ * - markComplete → 发 typing_stop;NO_REPLY 场景兜底一条提示
9
+ *
10
+ * 关键状态:
11
+ * streamedText 当前 assistant 轮已流式推送的文本
12
+ * streamedHistory 历史轮次已推送的快照,用于跨轮次去重
13
+ * counts / *Count 计数器,供 markComplete 推断 NO_REPLY 原因
14
+ */
15
+ import { CHANNEL_KEY } from "../config.js";
16
+ import { uploadFileToCos } from "../file-storage.js";
17
+ import { mediaUrlsToFiles } from "../media.js";
18
+ import { createDeltaTrackerState, toStreamDeltaText } from "./delta-tracker.js";
19
+ import { emitSignal } from "../types.js";
20
+ /** 派生/管理 subagent 的工具名;前端可据此特化渲染 tool_start。 */
21
+ const SUBAGENT_TOOL_NAMES = new Set([
22
+ "sessions_spawn",
23
+ "sessions.spawn",
24
+ "subagents",
25
+ ]);
26
+ /** 匹配 openclaw 原生 abort 回执(见 abort.ts:formatAbortReplyText)并汉化。 */
27
+ const OPENCLAW_ABORT_REPLY_RE = /^⚙️ Agent was aborted\.(?: Stopped \d+ sub-agents?\.)?$/;
28
+ const LOCALIZED_ABORT_REPLY = "已停止当前回复。";
29
+ function localizeAbortReplyText(text) {
30
+ return OPENCLAW_ABORT_REPLY_RE.test(text.trim()) ? LOCALIZED_ABORT_REPLY : text;
31
+ }
32
+ export function createStreamReplyConfig(opts, prefixOptions, signalCtx) {
33
+ const { emitter, targetId, originalMsgId, log, effectiveApiKey, typingAlreadyStarted } = opts;
34
+ // ── 增量追踪 & 已推送文本 ──
35
+ let partialReplyState = createDeltaTrackerState();
36
+ let streamedText = "";
37
+ const streamedHistory = [];
38
+ // ── 是否已经给用户推送过任何可见内容 ──
39
+ //
40
+ // 在真正向用户发送 stream_chunk / sendReply / sendFiles 时置 true。
41
+ // 上层据此决定"是否需要 NO_REPLY 兜底"——业务决策放在 inbound,sink 只如实记录。
42
+ let emittedUserVisible = false;
43
+ // ── 计数器(仅用于 NO_REPLY 诊断) ──
44
+ const counts = { tool: 0, block: 0, final: 0 };
45
+ let toolStartCount = 0;
46
+ let assistantMessageCount = 0;
47
+ // ── thinking/reasoning 观测(不面向用户,仅为首字延迟归因) ──
48
+ let reasoningChars = 0;
49
+ let reasoningFirstAt = 0;
50
+ let reasoningLastAt = 0;
51
+ // ── typing / 完成态 ──
52
+ let typingStartSent = !!typingAlreadyStarted;
53
+ let typingStopSent = false;
54
+ let completed = false;
55
+ /** openclaw abort 检测:sendFinalReply 收到 abort 文案时置 true,markComplete 据此跳过 NO_REPLY。 */
56
+ let abortDetected = false;
57
+ // ── 串行化回调队列:保证 COS 上传等异步操作按顺序执行 ──
58
+ let queuePromise = Promise.resolve();
59
+ const enqueue = (fn) => {
60
+ if (completed)
61
+ return;
62
+ queuePromise = queuePromise.then(fn, fn).then(() => { }, () => { });
63
+ };
64
+ const ensureTypingStart = () => {
65
+ if (typingStartSent)
66
+ return;
67
+ typingStartSent = true;
68
+ emitSignal(signalCtx, "typing_start");
69
+ };
70
+ const sendTypingStop = () => {
71
+ if (typingStopSent)
72
+ return;
73
+ typingStopSent = true;
74
+ emitSignal(signalCtx, "typing_stop");
75
+ };
76
+ /**
77
+ * 处理 payload 中的 mediaUrls:COS 上传 → 拼 Markdown 链接 → emit sendReply/sendFiles。
78
+ * 仅在 mediaList 非空时调用。
79
+ */
80
+ const handleMediaFinal = async (replyText, mediaList) => {
81
+ const files = await mediaUrlsToFiles(mediaList, log);
82
+ const storageConfig = { apiKey: effectiveApiKey };
83
+ const publicUrls = [];
84
+ for (const mediaUrl of mediaList) {
85
+ try {
86
+ const localPath = mediaUrl.startsWith("file://") ? mediaUrl.slice(7) : mediaUrl;
87
+ if (localPath.startsWith("/") || localPath.match(/^[A-Za-z]:\\/)) {
88
+ const { existsSync } = await import("node:fs");
89
+ if (existsSync(localPath)) {
90
+ const result = await uploadFileToCos(localPath, storageConfig);
91
+ publicUrls.push(result.url || "");
92
+ log?.info(`[${CHANNEL_KEY}] [stream] Uploaded to COS: ${localPath} → ${result.url}`);
93
+ }
94
+ }
95
+ }
96
+ catch (uploadErr) {
97
+ log?.warn(`[${CHANNEL_KEY}] [stream] COS upload failed for ${mediaUrl}: ${uploadErr}`);
98
+ }
99
+ }
100
+ let enrichedText = replyText;
101
+ if (publicUrls.length > 0) {
102
+ const urlSection = publicUrls
103
+ .map((url, i) => {
104
+ const match = url.match(/filePath=([^&]+)/);
105
+ const filePath = match ? decodeURIComponent(match[1]) : "";
106
+ const fileName = filePath.split("/").pop() || `file${publicUrls.length > 1 ? ` (${i + 1})` : ""}`;
107
+ return `📎 [${fileName}](${url})`;
108
+ })
109
+ .join("\n");
110
+ enrichedText = enrichedText ? `${enrichedText}\n\n${urlSection}` : urlSection;
111
+ }
112
+ if (files.length > 0) {
113
+ emitter.sendFiles(targetId, enrichedText, files, originalMsgId);
114
+ emittedUserVisible = true;
115
+ }
116
+ else if (enrichedText.trim()) {
117
+ emitter.sendReply(targetId, enrichedText, originalMsgId);
118
+ emittedUserVisible = true;
119
+ }
120
+ };
121
+ // ────────────────────────────────────────
122
+ // dispatcher
123
+ // ────────────────────────────────────────
124
+ const dispatcher = {
125
+ /**
126
+ * 工具调用结束:openclaw runtime 在每个工具执行完(成功/失败)后调此回调。
127
+ *
128
+ * payload 里没有 toolName,但由于 LLM 的工具调用是串行的(等上一个返回才发下一个),
129
+ * 前端按"最近一次 tool_start"配对即可。透传 isError 让前端标示失败态。
130
+ */
131
+ sendToolResult: (payload) => {
132
+ if (completed)
133
+ return false;
134
+ counts.tool++;
135
+ const isError = !!payload.isError;
136
+ log?.info(`[${CHANNEL_KEY}] [stream] sendToolResult: textLen=${payload.text?.length ?? 0} isError=${isError}`);
137
+ emitSignal(signalCtx, "tool_end", "", { toolIsError: isError });
138
+ return true;
139
+ },
140
+ /** 块回复:文本已由 onPartialReply 推送,这里只处理媒体。 */
141
+ sendBlockReply: (payload) => {
142
+ if (completed)
143
+ return false;
144
+ counts.block++;
145
+ const mediaList = payload.mediaUrls?.length
146
+ ? payload.mediaUrls
147
+ : payload.mediaUrl ? [payload.mediaUrl] : [];
148
+ if (mediaList.length > 0) {
149
+ log?.info(`[${CHANNEL_KEY}] [stream] sendBlockReply: processing ${mediaList.length} media files`);
150
+ enqueue(() => handleMediaFinal(payload.text ?? "", mediaList).catch((err) => {
151
+ log?.error(`[${CHANNEL_KEY}] [stream] sendBlockReply media error: ${err}`);
152
+ }));
153
+ }
154
+ return true;
155
+ },
156
+ /**
157
+ * 最终回复去重逻辑:
158
+ * A. payload.text 命中 streamedHistory 任一轮次快照 → 已在历史轮推送过,丢弃
159
+ * B. 当前轮已有 streamedText:
160
+ * - 完全相同 → 跳过
161
+ * - 以 streamedText 为前缀 → 只发尾部增量
162
+ * - 其他 → 丢弃(已通过 onPartialReply 推送)
163
+ * C. 当前轮未推送过 → 作为完整 chunk 发送
164
+ */
165
+ sendFinalReply: (payload) => {
166
+ if (completed)
167
+ return false;
168
+ counts.final++;
169
+ // abort fast-path 也走 sendFinalReply,这里汉化英文回执。
170
+ const rawText = payload.text ?? "";
171
+ const replyText = localizeAbortReplyText(rawText);
172
+ if (replyText !== rawText) {
173
+ abortDetected = true;
174
+ }
175
+ const mediaList = payload.mediaUrls?.length
176
+ ? payload.mediaUrls
177
+ : payload.mediaUrl ? [payload.mediaUrl] : [];
178
+ log?.info(`[${CHANNEL_KEY}] [stream] sendFinalReply: textLen=${replyText.length} mediaCount=${mediaList.length} streamedLen=${streamedText.length} historyRounds=${streamedHistory.length}`);
179
+ if (mediaList.length > 0) {
180
+ enqueue(() => handleMediaFinal(replyText, mediaList).catch((err) => {
181
+ log?.error(`[${CHANNEL_KEY}] [stream] sendFinalReply media error: ${err}`);
182
+ }));
183
+ }
184
+ if (replyText.length === 0)
185
+ return true;
186
+ let delta;
187
+ const hitHistory = streamedHistory.some((prev) => prev === replyText || prev.startsWith(replyText));
188
+ if (hitHistory) {
189
+ log?.debug?.(`[${CHANNEL_KEY}] [stream] Final text hit history, suppressed`);
190
+ }
191
+ else if (streamedText) {
192
+ if (replyText === streamedText) {
193
+ log?.debug?.(`[${CHANNEL_KEY}] [stream] Final text identical to streamed, skipping`);
194
+ }
195
+ else if (replyText.startsWith(streamedText)) {
196
+ const remaining = replyText.slice(streamedText.length);
197
+ if (remaining.length > 0) {
198
+ delta = remaining;
199
+ streamedText += remaining;
200
+ partialReplyState.latest = replyText;
201
+ }
202
+ }
203
+ else {
204
+ log?.debug?.(`[${CHANNEL_KEY}] [stream] Final text mismatch with streamed, suppressed`);
205
+ }
206
+ }
207
+ else {
208
+ delta = replyText;
209
+ streamedText = replyText;
210
+ partialReplyState.latest = replyText;
211
+ }
212
+ if (delta) {
213
+ emitSignal(signalCtx, "stream_chunk", delta);
214
+ emittedUserVisible = true;
215
+ log?.debug?.(`[${CHANNEL_KEY}] [stream] Final delta: ${delta.length} chars`);
216
+ }
217
+ return true;
218
+ },
219
+ waitForIdle: async () => {
220
+ await queuePromise;
221
+ },
222
+ // 下面两个 getter 是 openclaw ReplyDispatcher 契约要求的,这里直接返回 counts 快照
223
+ getQueuedCounts: () => ({ ...counts }),
224
+ getFailedCounts: () => ({ tool: 0, block: 0, final: 0 }),
225
+ /**
226
+ * 标记本次 dispatch 完成 → 发 typing_stop。
227
+ *
228
+ * NO_REPLY 仅在"LLM 正常完成一次完整 run 但没产出可见文本"时才触发。
229
+ * 以下场景均不发:
230
+ * - isAborted / abortDetected:/stop 或 abort 触发
231
+ * - hadLLMActivity 但 hadDispatch=false:LLM 启动但被中途打断(abort 没来得及 sendFinalReply)
232
+ * - !hadLLMActivity:followup 被 collect 合并 / plugin 拦截
233
+ */
234
+ markComplete: (markOpts) => {
235
+ completed = true;
236
+ const hadStreamedText = streamedText.length > 0 || streamedHistory.length > 0;
237
+ const hadDispatch = counts.tool > 0 || counts.block > 0 || counts.final > 0;
238
+ const hadLLMActivity = toolStartCount > 0 || assistantMessageCount > 0;
239
+ const isAborted = markOpts?.aborted === true || abortDetected;
240
+ if (isAborted) {
241
+ log?.info(`[${CHANNEL_KEY}] [stream] markComplete: aborted`);
242
+ }
243
+ else if (!hadLLMActivity) {
244
+ // 静默 dispatch(followup 被合并 / plugin 拦截)
245
+ log?.info(`[${CHANNEL_KEY}] [stream] markComplete: silent dispatch (likely followup merged by openclaw queue)`);
246
+ }
247
+ else if (!hadStreamedText && !hadDispatch) {
248
+ // LLM 启动但未完成 dispatch(被 abort 中断但本 sink 没收到 abort 文案)
249
+ log?.info(`[${CHANNEL_KEY}] [stream] markComplete: LLM interrupted before output ` +
250
+ `(toolStart=${toolStartCount} assistantMsg=${assistantMessageCount})`);
251
+ }
252
+ else if (!hadStreamedText && hadDispatch) {
253
+ // LLM 完成了 dispatch 但没有可见文本输出 → 真正的 NO_REPLY
254
+ const cause = toolStartCount > 0
255
+ ? "LLM invoked tool(s) but produced no visible text"
256
+ : "LLM only produced thinking, no visible text";
257
+ log?.warn(`[${CHANNEL_KEY}] [stream] NO_REPLY: counts=${JSON.stringify(counts)} ` +
258
+ `toolStart=${toolStartCount} assistantMsg=${assistantMessageCount}. Cause: ${cause}`);
259
+ emitter.sendReply(targetId, "NO_REPLY", originalMsgId);
260
+ }
261
+ else {
262
+ log?.info(`[${CHANNEL_KEY}] [stream] markComplete: counts=${JSON.stringify(counts)} ` +
263
+ `toolStart=${toolStartCount} assistantMsg=${assistantMessageCount} ` +
264
+ `streamedLen=${streamedText.length} historyRounds=${streamedHistory.length}`);
265
+ }
266
+ sendTypingStop();
267
+ },
268
+ };
269
+ // ────────────────────────────────────────
270
+ // replyOptions
271
+ // ────────────────────────────────────────
272
+ const replyOptions = {
273
+ ...prefixOptions,
274
+ /** AI 每产 token 回调,计算增量后 emit stream_chunk。 */
275
+ onPartialReply: (payload) => {
276
+ if (completed || !payload.text)
277
+ return;
278
+ ensureTypingStart();
279
+ const delta = toStreamDeltaText(partialReplyState, payload.text);
280
+ if (delta) {
281
+ streamedText += delta;
282
+ emitSignal(signalCtx, "stream_chunk", delta);
283
+ emittedUserVisible = true;
284
+ }
285
+ },
286
+ /**
287
+ * 工具调用开始:透传 toolName 给前端。
288
+ * 命中 SUBAGENT_TOOL_NAMES 时视为派生子任务,前端可据此显示"处理中"提示;
289
+ * 子任务完成后会由 openclaw announce 机制回灌,主 agent 下一轮 assistant 消息会输出结果。
290
+ */
291
+ onToolStart: (payload) => {
292
+ if (completed)
293
+ return;
294
+ toolStartCount++;
295
+ const toolName = payload.name ?? "unknown";
296
+ const toolPhase = payload.phase ?? "";
297
+ const isSubagentSpawn = SUBAGENT_TOOL_NAMES.has(toolName);
298
+ log?.info(`[${CHANNEL_KEY}] [stream] onToolStart: name=${toolName} phase=${toolPhase}` +
299
+ (isSubagentSpawn ? " (subagent-spawn)" : ""));
300
+ emitSignal(signalCtx, "tool_start", "\n\n", { toolName, toolPhase });
301
+ },
302
+ onReplyStart: () => {
303
+ if (completed)
304
+ return;
305
+ ensureTypingStart();
306
+ },
307
+ onAgentRunStart: (runId) => {
308
+ if (completed)
309
+ return;
310
+ log?.info(`[${CHANNEL_KEY}] [stream] Agent run started: runId=${runId}`);
311
+ },
312
+ /**
313
+ * 模型 thinking/reasoning 增量。仅用于观测首字延迟归因,不向用户 emit。
314
+ * - 第一次命中时记录 reasoningFirstAt(distance to onAgentRunStart = LLM prefill + 开始思考耗时)
315
+ * - 每次累加字符数
316
+ * 与 onPartialReply 互斥:reasoning 期间不会有 text delta。
317
+ */
318
+ onReasoningStream: (payload) => {
319
+ if (completed || !payload.text)
320
+ return;
321
+ const now = Date.now();
322
+ if (reasoningFirstAt === 0) {
323
+ reasoningFirstAt = now;
324
+ log?.info(`[${CHANNEL_KEY}] [stream] onReasoningStream:first len=${payload.text.length}`);
325
+ }
326
+ reasoningLastAt = now;
327
+ reasoningChars += payload.text.length;
328
+ },
329
+ /** thinking block 结束:首个可见 token 的出现 ≈ 此刻 + 模型从 reasoning 切到 content 的微小间隙 */
330
+ onReasoningEnd: () => {
331
+ if (completed)
332
+ return;
333
+ // 仅在有实际 reasoning 内容时打日志,避免噪音(如 GLM-4-7 在工具调用前无内容触发)
334
+ if (reasoningChars === 0)
335
+ return;
336
+ const duration = reasoningLastAt && reasoningFirstAt ? reasoningLastAt - reasoningFirstAt : 0;
337
+ log?.info(`[${CHANNEL_KEY}] [stream] onReasoningEnd: chars=${reasoningChars} durationMs=${duration}`);
338
+ },
339
+ /**
340
+ * 新一轮 assistant 消息开始(多轮 tool call 场景)。
341
+ * 先把当前轮已推文本存入 streamedHistory 供跨轮去重,再重置当前轮状态。
342
+ */
343
+ onAssistantMessageStart: () => {
344
+ if (completed)
345
+ return;
346
+ assistantMessageCount++;
347
+ if (streamedText)
348
+ streamedHistory.push(streamedText);
349
+ partialReplyState = createDeltaTrackerState();
350
+ streamedText = "";
351
+ log?.info(`[${CHANNEL_KEY}] [stream] onAssistantMessageStart: round=${assistantMessageCount}` +
352
+ (reasoningChars > 0 ? ` prevReasoningChars=${reasoningChars} prevReasoningMs=${reasoningLastAt && reasoningFirstAt ? reasoningLastAt - reasoningFirstAt : 0}` : ""));
353
+ // 复位本轮 reasoning 计数
354
+ reasoningChars = 0;
355
+ reasoningFirstAt = 0;
356
+ reasoningLastAt = 0;
357
+ },
358
+ /**
359
+ * work item 生命周期事件(纯日志观测)。
360
+ *
361
+ * openclaw 的 agent event 里 `stream === "item"` 的事件会命中这里,payload 字段较多
362
+ * (itemId / kind / name / phase / status / summary / progressText / approvalId / approvalSlug)。
363
+ *
364
+ * 目的:先跑一轮拿到线上真实 payload 分布(kind / status 的可能取值、触发时机),
365
+ * 再决定是否要用它替代/增强现有 tool_start / tool_end 事件。在此之前不向前端 emit,
366
+ * 避免协议面扩散。
367
+ */
368
+ onItemEvent: (payload) => {
369
+ if (completed)
370
+ return;
371
+ log?.info(`[${CHANNEL_KEY}] [stream] onItemEvent: ${JSON.stringify(payload)}`);
372
+ },
373
+ onTypingCleanup: () => {
374
+ log?.info(`[${CHANNEL_KEY}] [stream] onTypingCleanup: counts=${JSON.stringify(counts)} ` +
375
+ `toolStart=${toolStartCount} assistantMsg=${assistantMessageCount} ` +
376
+ `streamedLen=${streamedText.length} historyRounds=${streamedHistory.length}`);
377
+ },
378
+ // 禁用框架内部的 block streaming,避免与 onPartialReply 重复分发。
379
+ disableBlockStreaming: true,
380
+ };
381
+ return {
382
+ dispatcher,
383
+ replyOptions,
384
+ // 业务辅助:独立于 openclaw ReplyDispatcher 契约暴露,避免污染 dispatcher
385
+ hasEmittedContent: () => emittedUserVisible,
386
+ };
387
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * LightClaw — 流式输出类型定义
3
+ */
4
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * LightClaw — 工具注册入口
3
+ *
4
+ * 在 defineChannelPluginEntry 的 registerFull 回调中注册所有 Agent Tools。
5
+ * 此模块仅在插件完全激活后加载,避免 setup-only 模式拉起不必要的依赖。
6
+ */
7
+ import { registerUploadTool } from './upload-tool.js';
8
+ // import { registerDownloadTool } from "./download-tool.js";
9
+ export function registerLightclawTools(api) {
10
+ // 注册文件存储工具(飞书工厂函数模式:execute 时动态从 api.config 解析 apiKey)
11
+ registerUploadTool(api);
12
+ // registerDownloadTool(api);
13
+ }
package/dist/src/types.js CHANGED
@@ -5,6 +5,26 @@
5
5
  * { msgId, from, to, content, files, timestamp }
6
6
  *
7
7
  * files 格式为 FileAttachment[],每个文件包含 name, mimeType, bytes(data URL)。
8
+ *
9
+ * @format
10
+ */
11
+ /**
12
+ * 统一的信号发送出口,收敛 typing / stream / tool 控制帧的构造逻辑。
13
+ *
14
+ * - typing_start 不带 replyToMsgId(协议要求);其余帧都携带。
15
+ * - extra 用于透传 kind 相关字段(如 tool_start 的 toolName/toolPhase、tool_end 的 toolIsError)。
8
16
  */
9
- export {};
10
- //# sourceMappingURL=types.js.map
17
+ export function emitSignal(ctx, kind, content = "", extra) {
18
+ const { emitter, targetId, replyMsgId, originalMsgId, agentId } = ctx;
19
+ return emitter.emit({
20
+ msgId: replyMsgId,
21
+ from: emitter.botClientId,
22
+ to: targetId,
23
+ content,
24
+ timestamp: Date.now(),
25
+ kind,
26
+ ...(kind !== "typing_start" ? { replyToMsgId: originalMsgId } : {}),
27
+ ...extra,
28
+ agentId,
29
+ });
30
+ }
@@ -142,4 +142,3 @@ export function registerUploadTool(api) {
142
142
  };
143
143
  }, { name: UPLOAD_TOOL_NAME });
144
144
  }
145
- //# sourceMappingURL=upload-tool.js.map
@@ -0,0 +1,73 @@
1
+ import { CHANNEL_KEY, DEFAULT_ACCOUNT_ID } from '../config.js';
2
+ /**
3
+ * 从全局配置中提取当前渠道(LightClaw)的配置对象。
4
+ *
5
+ * @param cfg - OpenClaw 全局配置
6
+ * @returns 当前渠道的配置对象;若未配置则返回空对象 `{}`
7
+ */
8
+ export function getChannelConfig(cfg) {
9
+ // 通过 CHANNEL_KEY 定位渠道配置,未配置时降级为空对象,避免后续访问报错
10
+ return (cfg.channels?.[CHANNEL_KEY] ?? {});
11
+ }
12
+ /**
13
+ * 列出当前渠道配置中所有已注册的账户 ID。
14
+ *
15
+ * @param cfg - OpenClaw 全局配置
16
+ * @returns 账户 ID 数组;若未配置任何账户则返回空数组
17
+ */
18
+ export function listAccountIds(cfg) {
19
+ const channelConfig = getChannelConfig(cfg);
20
+ // getChannelConfig 始终返回对象,此处防御性判断以应对极端情况
21
+ if (!channelConfig)
22
+ return [];
23
+ const ids = [];
24
+ // accounts 的结构为 Record<accountId, AssistantAccountConfig>
25
+ const accounts = channelConfig?.accounts;
26
+ if (accounts && typeof accounts === 'object') {
27
+ // 将所有账户 ID(即 accounts 的 key)收集到结果数组
28
+ ids.push(...Object.keys(accounts));
29
+ }
30
+ return ids;
31
+ }
32
+ /**
33
+ * 根据账户 ID 从配置中解析出完整的账户信息(含默认值填充)。
34
+ *
35
+ * 若指定的 accountId 在配置中不存在,则所有字段均使用默认值,
36
+ * 不会抛出异常,调用方可安全使用返回值。
37
+ *
38
+ * @param cfg - OpenClaw 全局配置
39
+ * @param accountId - 目标账户 ID;为空或 null 时使用空字符串作为 key 查找
40
+ * @returns 解析后的完整账户对象 {@link ResolvedAssistantAccount}
41
+ */
42
+ export function resolveAccount(cfg, accountId) {
43
+ const channelConfig = getChannelConfig(cfg);
44
+ // 去除首尾空白,null/undefined 统一转为空字符串
45
+ const id = accountId?.trim() || '';
46
+ // accounts 结构:{ [accountId]: AssistantAccountConfig }
47
+ const accounts = channelConfig.accounts;
48
+ // 若账户不存在则降级为空对象,后续字段均使用默认值
49
+ const raw = accounts?.[id] ?? {};
50
+ return {
51
+ accountId: id,
52
+ apiKey: raw.apiKey || '', // API 密钥,未配置时为空字符串
53
+ apiBaseUrl: raw.apiBaseUrl || '', // REST API 基础地址,未配置时为空字符串
54
+ enabled: raw.enabled ?? true, // 是否启用,默认开启
55
+ name: raw.name || '', // 账户显示名称,未配置时为空字符串
56
+ dmPolicy: raw.dmPolicy ?? 'open', // DM 策略,默认 open(所有人可发消息)
57
+ allowFrom: raw.allowFrom ?? ['*'], // 允许发消息的用户列表,默认不限制
58
+ systemPrompt: raw.systemPrompt || '', // 自定义系统提示词,未配置时为空字符串
59
+ };
60
+ }
61
+ /**
62
+ * 获取当前渠道的默认账户 ID。
63
+ *
64
+ * 默认账户 ID 由常量 {@link DEFAULT_ACCOUNT_ID} 定义,
65
+ * 与具体配置无关,可在未指定账户时作为 fallback 使用。
66
+ *
67
+ * @param _cfg - OpenClaw 全局配置(当前未使用,保留以统一函数签名)
68
+ * @returns 默认账户 ID 字符串
69
+ */
70
+ export function defaultAccountId(cfg) {
71
+ const ids = listAccountIds(cfg);
72
+ return ids[0] || DEFAULT_ACCOUNT_ID;
73
+ }
@@ -0,0 +1,48 @@
1
+ import { X_PRODUCT } from '../config.js';
2
+ /**
3
+ * 将长文本按指定长度拆分为多个文本块。
4
+ *
5
+ * 拆分策略(优先级从高到低):
6
+ * 1. 优先在换行符(\n)处切割,保持段落完整性;
7
+ * 2. 若换行符位置过靠前(< limit 的 50%),则退而求其次在空格处切割;
8
+ * 3. 若仍找不到合适的空格,则强制在 limit 处硬切。
9
+ *
10
+ * @param text - 待拆分的原始文本
11
+ * @param limit - 每个文本块的最大字符数
12
+ * @returns 拆分后的文本块数组
13
+ */
14
+ export function chunkText(text, limit) {
15
+ // 文本长度未超限,直接返回原文本
16
+ if (text.length <= limit)
17
+ return [text];
18
+ const chunks = [];
19
+ let remaining = text;
20
+ while (remaining.length > 0) {
21
+ // 剩余文本已在限制内,直接作为最后一块
22
+ if (remaining.length <= limit) {
23
+ chunks.push(remaining);
24
+ break;
25
+ }
26
+ // 策略 1:尝试在换行符处切割
27
+ let splitAt = remaining.lastIndexOf('\n', limit);
28
+ // 策略 2:换行符位置过靠前时,改为在空格处切割
29
+ if (splitAt <= 0 || splitAt < limit * 0.5) {
30
+ splitAt = remaining.lastIndexOf(' ', limit);
31
+ }
32
+ // 策略 3:仍找不到合适位置,强制硬切
33
+ if (splitAt <= 0 || splitAt < limit * 0.5) {
34
+ splitAt = limit;
35
+ }
36
+ chunks.push(remaining.slice(0, splitAt));
37
+ // trimStart 去除下一块开头的空白,避免段首多余空格
38
+ remaining = remaining.slice(splitAt).trimStart();
39
+ }
40
+ return chunks;
41
+ }
42
+ /** 构建通用认证 headers */
43
+ export function buildAuthHeaders(apiKey) {
44
+ return {
45
+ authorization: `Bearer ${apiKey}`,
46
+ 'x-product': X_PRODUCT,
47
+ };
48
+ }
@@ -0,0 +1,2 @@
1
+ export * from './common.js';
2
+ export * from './account.js';
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const createWebSocketStream = require('./lib/stream');
4
+ const extension = require('./lib/extension');
5
+ const PerMessageDeflate = require('./lib/permessage-deflate');
6
+ const Receiver = require('./lib/receiver');
7
+ const Sender = require('./lib/sender');
8
+ const subprotocol = require('./lib/subprotocol');
9
+ const WebSocket = require('./lib/websocket');
10
+ const WebSocketServer = require('./lib/websocket-server');
11
+
12
+ WebSocket.createWebSocketStream = createWebSocketStream;
13
+ WebSocket.extension = extension;
14
+ WebSocket.PerMessageDeflate = PerMessageDeflate;
15
+ WebSocket.Receiver = Receiver;
16
+ WebSocket.Sender = Sender;
17
+ WebSocket.Server = WebSocketServer;
18
+ WebSocket.subprotocol = subprotocol;
19
+ WebSocket.WebSocket = WebSocket;
20
+ WebSocket.WebSocketServer = WebSocketServer;
21
+
22
+ module.exports = WebSocket;
@@ -7,6 +7,7 @@ if (hasBlob) BINARY_TYPES.push('blob');
7
7
 
8
8
  module.exports = {
9
9
  BINARY_TYPES,
10
+ CLOSE_TIMEOUT: 30000,
10
11
  EMPTY_BUFFER: Buffer.alloc(0),
11
12
  GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
12
13
  hasBlob,
@@ -37,6 +37,9 @@ class PerMessageDeflate {
37
37
  * acknowledge disabling of client context takeover
38
38
  * @param {Number} [options.concurrencyLimit=10] The number of concurrent
39
39
  * calls to zlib
40
+ * @param {Boolean} [options.isServer=false] Create the instance in either
41
+ * server or client mode
42
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
40
43
  * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
41
44
  * use of a custom server window size
42
45
  * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
@@ -47,16 +50,13 @@ class PerMessageDeflate {
47
50
  * deflate
48
51
  * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
49
52
  * inflate
50
- * @param {Boolean} [isServer=false] Create the instance in either server or
51
- * client mode
52
- * @param {Number} [maxPayload=0] The maximum allowed message length
53
53
  */
54
- constructor(options, isServer, maxPayload) {
55
- this._maxPayload = maxPayload | 0;
54
+ constructor(options) {
56
55
  this._options = options || {};
57
56
  this._threshold =
58
57
  this._options.threshold !== undefined ? this._options.threshold : 1024;
59
- this._isServer = !!isServer;
58
+ this._maxPayload = this._options.maxPayload | 0;
59
+ this._isServer = !!this._options.isServer;
60
60
  this._deflate = null;
61
61
  this._inflate = null;
62
62