@silicaclaw/cli 2026.3.19-7 → 2026.3.19-9

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 (815) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +7 -0
  3. package/VERSION +1 -1
  4. package/apps/local-console/dist/apps/local-console/src/server.d.ts +728 -0
  5. package/apps/local-console/dist/apps/local-console/src/server.js +2721 -0
  6. package/apps/local-console/dist/apps/local-console/src/socialRoutes.d.ts +16 -0
  7. package/apps/local-console/dist/apps/local-console/src/socialRoutes.js +72 -0
  8. package/apps/local-console/dist/packages/core/src/crypto.d.ts +6 -0
  9. package/apps/local-console/dist/packages/core/src/crypto.js +50 -0
  10. package/apps/local-console/dist/packages/core/src/directory.d.ts +17 -0
  11. package/apps/local-console/dist/packages/core/src/directory.js +145 -0
  12. package/apps/local-console/dist/packages/core/src/identity.d.ts +2 -0
  13. package/apps/local-console/dist/packages/core/src/identity.js +18 -0
  14. package/apps/local-console/dist/packages/core/src/index.d.ts +12 -0
  15. package/apps/local-console/dist/packages/core/src/index.js +28 -0
  16. package/apps/local-console/dist/packages/core/src/indexing.d.ts +6 -0
  17. package/apps/local-console/dist/packages/core/src/indexing.js +43 -0
  18. package/apps/local-console/dist/packages/core/src/presence.d.ts +4 -0
  19. package/apps/local-console/dist/packages/core/src/presence.js +23 -0
  20. package/apps/local-console/dist/packages/core/src/profile.d.ts +4 -0
  21. package/apps/local-console/dist/packages/core/src/profile.js +39 -0
  22. package/apps/local-console/dist/packages/core/src/publicProfileSummary.d.ts +70 -0
  23. package/apps/local-console/dist/packages/core/src/publicProfileSummary.js +103 -0
  24. package/apps/local-console/dist/packages/core/src/socialConfig.d.ts +100 -0
  25. package/apps/local-console/dist/packages/core/src/socialConfig.js +296 -0
  26. package/apps/local-console/dist/packages/core/src/socialMessage.d.ts +19 -0
  27. package/apps/local-console/dist/packages/core/src/socialMessage.js +69 -0
  28. package/apps/local-console/dist/packages/core/src/socialResolver.d.ts +46 -0
  29. package/apps/local-console/dist/packages/core/src/socialResolver.js +237 -0
  30. package/apps/local-console/dist/packages/core/src/socialTemplate.d.ts +2 -0
  31. package/apps/local-console/dist/packages/core/src/socialTemplate.js +90 -0
  32. package/apps/local-console/dist/packages/core/src/types.d.ts +59 -0
  33. package/apps/local-console/dist/packages/core/src/types.js +2 -0
  34. package/apps/local-console/dist/packages/network/src/abstractions/messageEnvelope.d.ts +28 -0
  35. package/apps/local-console/dist/packages/network/src/abstractions/messageEnvelope.js +36 -0
  36. package/apps/local-console/dist/packages/network/src/abstractions/peerDiscovery.d.ts +43 -0
  37. package/apps/local-console/dist/packages/network/src/abstractions/peerDiscovery.js +2 -0
  38. package/apps/local-console/dist/packages/network/src/abstractions/topicCodec.d.ts +4 -0
  39. package/apps/local-console/dist/packages/network/src/abstractions/topicCodec.js +2 -0
  40. package/apps/local-console/dist/packages/network/src/abstractions/transport.d.ts +36 -0
  41. package/apps/local-console/dist/packages/network/src/abstractions/transport.js +2 -0
  42. package/apps/local-console/dist/packages/network/src/codec/jsonMessageEnvelopeCodec.d.ts +5 -0
  43. package/apps/local-console/dist/packages/network/src/codec/jsonMessageEnvelopeCodec.js +24 -0
  44. package/apps/local-console/dist/packages/network/src/codec/jsonTopicCodec.d.ts +5 -0
  45. package/apps/local-console/dist/packages/network/src/codec/jsonTopicCodec.js +12 -0
  46. package/apps/local-console/dist/packages/network/src/discovery/heartbeatPeerDiscovery.d.ts +28 -0
  47. package/apps/local-console/dist/packages/network/src/discovery/heartbeatPeerDiscovery.js +144 -0
  48. package/apps/local-console/dist/packages/network/src/index.d.ts +14 -0
  49. package/apps/local-console/dist/packages/network/src/index.js +30 -0
  50. package/apps/local-console/dist/packages/network/src/localEventBus.d.ts +9 -0
  51. package/apps/local-console/dist/packages/network/src/localEventBus.js +47 -0
  52. package/apps/local-console/dist/packages/network/src/mock.d.ts +8 -0
  53. package/apps/local-console/dist/packages/network/src/mock.js +24 -0
  54. package/apps/local-console/dist/packages/network/src/realPreview.d.ts +105 -0
  55. package/apps/local-console/dist/packages/network/src/realPreview.js +327 -0
  56. package/apps/local-console/dist/packages/network/src/relayPreview.d.ts +166 -0
  57. package/apps/local-console/dist/packages/network/src/relayPreview.js +442 -0
  58. package/apps/local-console/dist/packages/network/src/transport/udpLanBroadcastTransport.d.ts +23 -0
  59. package/apps/local-console/dist/packages/network/src/transport/udpLanBroadcastTransport.js +153 -0
  60. package/apps/local-console/dist/packages/network/src/types.d.ts +6 -0
  61. package/apps/local-console/dist/packages/network/src/types.js +2 -0
  62. package/apps/local-console/dist/packages/network/src/webrtcPreview.d.ts +163 -0
  63. package/apps/local-console/dist/packages/network/src/webrtcPreview.js +844 -0
  64. package/apps/local-console/dist/packages/storage/src/index.d.ts +3 -0
  65. package/apps/local-console/dist/packages/storage/src/index.js +19 -0
  66. package/apps/local-console/dist/packages/storage/src/jsonRepo.d.ts +7 -0
  67. package/apps/local-console/dist/packages/storage/src/jsonRepo.js +29 -0
  68. package/apps/local-console/dist/packages/storage/src/repos.d.ts +61 -0
  69. package/apps/local-console/dist/packages/storage/src/repos.js +67 -0
  70. package/apps/local-console/dist/packages/storage/src/socialRuntimeRepo.d.ts +5 -0
  71. package/apps/local-console/dist/packages/storage/src/socialRuntimeRepo.js +53 -0
  72. package/apps/local-console/package.json +1 -1
  73. package/apps/public-explorer/dist/server.d.ts +1 -0
  74. package/apps/public-explorer/dist/server.js +31 -0
  75. package/apps/public-explorer/package.json +1 -0
  76. package/node_modules/@silicaclaw/core/dist/crypto.d.ts +6 -0
  77. package/node_modules/@silicaclaw/core/dist/crypto.js +50 -0
  78. package/node_modules/@silicaclaw/core/dist/directory.d.ts +17 -0
  79. package/node_modules/@silicaclaw/core/dist/directory.js +145 -0
  80. package/node_modules/@silicaclaw/core/dist/identity.d.ts +2 -0
  81. package/node_modules/@silicaclaw/core/dist/identity.js +18 -0
  82. package/node_modules/@silicaclaw/core/dist/index.d.ts +12 -0
  83. package/node_modules/@silicaclaw/core/dist/index.js +28 -0
  84. package/node_modules/@silicaclaw/core/dist/indexing.d.ts +6 -0
  85. package/node_modules/@silicaclaw/core/dist/indexing.js +43 -0
  86. package/node_modules/@silicaclaw/core/dist/presence.d.ts +4 -0
  87. package/node_modules/@silicaclaw/core/dist/presence.js +23 -0
  88. package/node_modules/@silicaclaw/core/dist/profile.d.ts +4 -0
  89. package/node_modules/@silicaclaw/core/dist/profile.js +39 -0
  90. package/node_modules/@silicaclaw/core/dist/publicProfileSummary.d.ts +70 -0
  91. package/node_modules/@silicaclaw/core/dist/publicProfileSummary.js +103 -0
  92. package/node_modules/@silicaclaw/core/dist/socialConfig.d.ts +100 -0
  93. package/node_modules/@silicaclaw/core/dist/socialConfig.js +296 -0
  94. package/node_modules/@silicaclaw/core/dist/socialMessage.d.ts +19 -0
  95. package/node_modules/@silicaclaw/core/dist/socialMessage.js +69 -0
  96. package/node_modules/@silicaclaw/core/dist/socialResolver.d.ts +46 -0
  97. package/node_modules/@silicaclaw/core/dist/socialResolver.js +237 -0
  98. package/node_modules/@silicaclaw/core/dist/socialTemplate.d.ts +2 -0
  99. package/node_modules/@silicaclaw/core/dist/socialTemplate.js +90 -0
  100. package/node_modules/@silicaclaw/core/dist/types.d.ts +59 -0
  101. package/node_modules/@silicaclaw/core/dist/types.js +2 -0
  102. package/node_modules/@silicaclaw/core/package.json +13 -0
  103. package/node_modules/@silicaclaw/core/src/crypto.ts +55 -0
  104. package/node_modules/@silicaclaw/core/src/directory.ts +171 -0
  105. package/node_modules/@silicaclaw/core/src/identity.ts +14 -0
  106. package/node_modules/@silicaclaw/core/src/index.ts +12 -0
  107. package/node_modules/@silicaclaw/core/src/indexing.ts +42 -0
  108. package/node_modules/@silicaclaw/core/src/presence.ts +24 -0
  109. package/node_modules/@silicaclaw/core/src/profile.ts +39 -0
  110. package/node_modules/@silicaclaw/core/src/publicProfileSummary.ts +180 -0
  111. package/node_modules/@silicaclaw/core/src/socialConfig.ts +453 -0
  112. package/node_modules/@silicaclaw/core/src/socialMessage.ts +86 -0
  113. package/node_modules/@silicaclaw/core/src/socialResolver.ts +293 -0
  114. package/node_modules/@silicaclaw/core/src/socialTemplate.ts +99 -0
  115. package/node_modules/@silicaclaw/core/src/types.ts +67 -0
  116. package/node_modules/@silicaclaw/core/tsconfig.json +7 -0
  117. package/node_modules/@silicaclaw/network/dist/abstractions/messageEnvelope.d.ts +28 -0
  118. package/node_modules/@silicaclaw/network/dist/abstractions/messageEnvelope.js +36 -0
  119. package/node_modules/@silicaclaw/network/dist/abstractions/peerDiscovery.d.ts +43 -0
  120. package/node_modules/@silicaclaw/network/dist/abstractions/peerDiscovery.js +2 -0
  121. package/node_modules/@silicaclaw/network/dist/abstractions/topicCodec.d.ts +4 -0
  122. package/node_modules/@silicaclaw/network/dist/abstractions/topicCodec.js +2 -0
  123. package/node_modules/@silicaclaw/network/dist/abstractions/transport.d.ts +36 -0
  124. package/node_modules/@silicaclaw/network/dist/abstractions/transport.js +2 -0
  125. package/node_modules/@silicaclaw/network/dist/codec/jsonMessageEnvelopeCodec.d.ts +5 -0
  126. package/node_modules/@silicaclaw/network/dist/codec/jsonMessageEnvelopeCodec.js +24 -0
  127. package/node_modules/@silicaclaw/network/dist/codec/jsonTopicCodec.d.ts +5 -0
  128. package/node_modules/@silicaclaw/network/dist/codec/jsonTopicCodec.js +12 -0
  129. package/node_modules/@silicaclaw/network/dist/discovery/heartbeatPeerDiscovery.d.ts +28 -0
  130. package/node_modules/@silicaclaw/network/dist/discovery/heartbeatPeerDiscovery.js +144 -0
  131. package/node_modules/@silicaclaw/network/dist/index.d.ts +14 -0
  132. package/node_modules/@silicaclaw/network/dist/index.js +30 -0
  133. package/node_modules/@silicaclaw/network/dist/localEventBus.d.ts +9 -0
  134. package/node_modules/@silicaclaw/network/dist/localEventBus.js +47 -0
  135. package/node_modules/@silicaclaw/network/dist/mock.d.ts +8 -0
  136. package/node_modules/@silicaclaw/network/dist/mock.js +24 -0
  137. package/node_modules/@silicaclaw/network/dist/realPreview.d.ts +105 -0
  138. package/node_modules/@silicaclaw/network/dist/realPreview.js +327 -0
  139. package/node_modules/@silicaclaw/network/dist/relayPreview.d.ts +166 -0
  140. package/node_modules/@silicaclaw/network/dist/relayPreview.js +442 -0
  141. package/node_modules/@silicaclaw/network/dist/transport/udpLanBroadcastTransport.d.ts +23 -0
  142. package/node_modules/@silicaclaw/network/dist/transport/udpLanBroadcastTransport.js +153 -0
  143. package/node_modules/@silicaclaw/network/dist/types.d.ts +6 -0
  144. package/node_modules/@silicaclaw/network/dist/types.js +2 -0
  145. package/node_modules/@silicaclaw/network/dist/webrtcPreview.d.ts +163 -0
  146. package/node_modules/@silicaclaw/network/dist/webrtcPreview.js +844 -0
  147. package/node_modules/@silicaclaw/network/package.json +10 -0
  148. package/node_modules/@silicaclaw/network/src/abstractions/messageEnvelope.ts +80 -0
  149. package/node_modules/@silicaclaw/network/src/abstractions/peerDiscovery.ts +49 -0
  150. package/node_modules/@silicaclaw/network/src/abstractions/topicCodec.ts +4 -0
  151. package/node_modules/@silicaclaw/network/src/abstractions/transport.ts +40 -0
  152. package/node_modules/@silicaclaw/network/src/codec/jsonMessageEnvelopeCodec.ts +22 -0
  153. package/node_modules/@silicaclaw/network/src/codec/jsonTopicCodec.ts +11 -0
  154. package/node_modules/@silicaclaw/network/src/discovery/heartbeatPeerDiscovery.ts +173 -0
  155. package/node_modules/@silicaclaw/network/src/index.ts +17 -0
  156. package/node_modules/@silicaclaw/network/src/localEventBus.ts +61 -0
  157. package/node_modules/@silicaclaw/network/src/mock.ts +27 -0
  158. package/node_modules/@silicaclaw/network/src/realPreview.ts +436 -0
  159. package/node_modules/@silicaclaw/network/src/relayPreview.ts +565 -0
  160. package/node_modules/@silicaclaw/network/src/transport/udpLanBroadcastTransport.ts +173 -0
  161. package/node_modules/@silicaclaw/network/src/types.ts +6 -0
  162. package/node_modules/@silicaclaw/network/src/webrtcPreview.ts +1052 -0
  163. package/node_modules/@silicaclaw/network/tsconfig.json +7 -0
  164. package/node_modules/@silicaclaw/storage/dist/index.d.ts +3 -0
  165. package/node_modules/@silicaclaw/storage/dist/index.js +19 -0
  166. package/node_modules/@silicaclaw/storage/dist/jsonRepo.d.ts +7 -0
  167. package/node_modules/@silicaclaw/storage/dist/jsonRepo.js +29 -0
  168. package/node_modules/@silicaclaw/storage/dist/repos.d.ts +61 -0
  169. package/node_modules/@silicaclaw/storage/dist/repos.js +67 -0
  170. package/node_modules/@silicaclaw/storage/dist/socialRuntimeRepo.d.ts +5 -0
  171. package/node_modules/@silicaclaw/storage/dist/socialRuntimeRepo.js +53 -0
  172. package/node_modules/@silicaclaw/storage/package.json +13 -0
  173. package/node_modules/@silicaclaw/storage/src/index.ts +3 -0
  174. package/node_modules/@silicaclaw/storage/src/jsonRepo.ts +25 -0
  175. package/node_modules/@silicaclaw/storage/src/repos.ts +106 -0
  176. package/node_modules/@silicaclaw/storage/src/socialRuntimeRepo.ts +52 -0
  177. package/node_modules/@silicaclaw/storage/tsconfig.json +12 -0
  178. package/node_modules/accepts/HISTORY.md +243 -0
  179. package/node_modules/accepts/LICENSE +23 -0
  180. package/node_modules/accepts/README.md +140 -0
  181. package/node_modules/accepts/index.js +238 -0
  182. package/node_modules/accepts/package.json +47 -0
  183. package/node_modules/array-flatten/LICENSE +21 -0
  184. package/node_modules/array-flatten/README.md +43 -0
  185. package/node_modules/array-flatten/array-flatten.js +64 -0
  186. package/node_modules/array-flatten/package.json +39 -0
  187. package/node_modules/body-parser/HISTORY.md +680 -0
  188. package/node_modules/body-parser/LICENSE +23 -0
  189. package/node_modules/body-parser/README.md +476 -0
  190. package/node_modules/body-parser/index.js +156 -0
  191. package/node_modules/body-parser/lib/read.js +205 -0
  192. package/node_modules/body-parser/lib/types/json.js +247 -0
  193. package/node_modules/body-parser/lib/types/raw.js +101 -0
  194. package/node_modules/body-parser/lib/types/text.js +121 -0
  195. package/node_modules/body-parser/lib/types/urlencoded.js +300 -0
  196. package/node_modules/body-parser/package.json +55 -0
  197. package/node_modules/bytes/History.md +97 -0
  198. package/node_modules/bytes/LICENSE +23 -0
  199. package/node_modules/bytes/Readme.md +152 -0
  200. package/node_modules/bytes/index.js +170 -0
  201. package/node_modules/bytes/package.json +42 -0
  202. package/node_modules/call-bind-apply-helpers/.eslintrc +17 -0
  203. package/node_modules/call-bind-apply-helpers/.github/FUNDING.yml +12 -0
  204. package/node_modules/call-bind-apply-helpers/.nycrc +9 -0
  205. package/node_modules/call-bind-apply-helpers/CHANGELOG.md +30 -0
  206. package/node_modules/call-bind-apply-helpers/LICENSE +21 -0
  207. package/node_modules/call-bind-apply-helpers/README.md +62 -0
  208. package/node_modules/call-bind-apply-helpers/actualApply.d.ts +1 -0
  209. package/node_modules/call-bind-apply-helpers/actualApply.js +10 -0
  210. package/node_modules/call-bind-apply-helpers/applyBind.d.ts +19 -0
  211. package/node_modules/call-bind-apply-helpers/applyBind.js +10 -0
  212. package/node_modules/call-bind-apply-helpers/functionApply.d.ts +1 -0
  213. package/node_modules/call-bind-apply-helpers/functionApply.js +4 -0
  214. package/node_modules/call-bind-apply-helpers/functionCall.d.ts +1 -0
  215. package/node_modules/call-bind-apply-helpers/functionCall.js +4 -0
  216. package/node_modules/call-bind-apply-helpers/index.d.ts +64 -0
  217. package/node_modules/call-bind-apply-helpers/index.js +15 -0
  218. package/node_modules/call-bind-apply-helpers/package.json +85 -0
  219. package/node_modules/call-bind-apply-helpers/reflectApply.d.ts +3 -0
  220. package/node_modules/call-bind-apply-helpers/reflectApply.js +4 -0
  221. package/node_modules/call-bind-apply-helpers/test/index.js +63 -0
  222. package/node_modules/call-bind-apply-helpers/tsconfig.json +9 -0
  223. package/node_modules/call-bound/.eslintrc +13 -0
  224. package/node_modules/call-bound/.github/FUNDING.yml +12 -0
  225. package/node_modules/call-bound/.nycrc +9 -0
  226. package/node_modules/call-bound/CHANGELOG.md +42 -0
  227. package/node_modules/call-bound/LICENSE +21 -0
  228. package/node_modules/call-bound/README.md +53 -0
  229. package/node_modules/call-bound/index.d.ts +94 -0
  230. package/node_modules/call-bound/index.js +19 -0
  231. package/node_modules/call-bound/package.json +99 -0
  232. package/node_modules/call-bound/test/index.js +61 -0
  233. package/node_modules/call-bound/tsconfig.json +10 -0
  234. package/node_modules/content-disposition/HISTORY.md +60 -0
  235. package/node_modules/content-disposition/LICENSE +22 -0
  236. package/node_modules/content-disposition/README.md +142 -0
  237. package/node_modules/content-disposition/index.js +458 -0
  238. package/node_modules/content-disposition/package.json +44 -0
  239. package/node_modules/content-type/HISTORY.md +29 -0
  240. package/node_modules/content-type/LICENSE +22 -0
  241. package/node_modules/content-type/README.md +94 -0
  242. package/node_modules/content-type/index.js +225 -0
  243. package/node_modules/content-type/package.json +42 -0
  244. package/node_modules/cookie/LICENSE +24 -0
  245. package/node_modules/cookie/README.md +317 -0
  246. package/node_modules/cookie/SECURITY.md +25 -0
  247. package/node_modules/cookie/index.js +335 -0
  248. package/node_modules/cookie/package.json +44 -0
  249. package/node_modules/cookie-signature/History.md +42 -0
  250. package/node_modules/cookie-signature/Readme.md +42 -0
  251. package/node_modules/cookie-signature/index.js +51 -0
  252. package/node_modules/cookie-signature/package.json +18 -0
  253. package/node_modules/cors/LICENSE +22 -0
  254. package/node_modules/cors/README.md +277 -0
  255. package/node_modules/cors/lib/index.js +238 -0
  256. package/node_modules/cors/package.json +42 -0
  257. package/node_modules/debug/.coveralls.yml +1 -0
  258. package/node_modules/debug/.eslintrc +11 -0
  259. package/node_modules/debug/.npmignore +9 -0
  260. package/node_modules/debug/.travis.yml +14 -0
  261. package/node_modules/debug/CHANGELOG.md +362 -0
  262. package/node_modules/debug/LICENSE +19 -0
  263. package/node_modules/debug/Makefile +50 -0
  264. package/node_modules/debug/README.md +312 -0
  265. package/node_modules/debug/component.json +19 -0
  266. package/node_modules/debug/karma.conf.js +70 -0
  267. package/node_modules/debug/node.js +1 -0
  268. package/node_modules/debug/package.json +49 -0
  269. package/node_modules/debug/src/browser.js +185 -0
  270. package/node_modules/debug/src/debug.js +202 -0
  271. package/node_modules/debug/src/index.js +10 -0
  272. package/node_modules/debug/src/inspector-log.js +15 -0
  273. package/node_modules/debug/src/node.js +248 -0
  274. package/node_modules/depd/History.md +103 -0
  275. package/node_modules/depd/LICENSE +22 -0
  276. package/node_modules/depd/Readme.md +280 -0
  277. package/node_modules/depd/index.js +538 -0
  278. package/node_modules/depd/lib/browser/index.js +77 -0
  279. package/node_modules/depd/package.json +45 -0
  280. package/node_modules/destroy/LICENSE +23 -0
  281. package/node_modules/destroy/README.md +63 -0
  282. package/node_modules/destroy/index.js +209 -0
  283. package/node_modules/destroy/package.json +48 -0
  284. package/node_modules/dunder-proto/.eslintrc +5 -0
  285. package/node_modules/dunder-proto/.github/FUNDING.yml +12 -0
  286. package/node_modules/dunder-proto/.nycrc +13 -0
  287. package/node_modules/dunder-proto/CHANGELOG.md +24 -0
  288. package/node_modules/dunder-proto/LICENSE +21 -0
  289. package/node_modules/dunder-proto/README.md +54 -0
  290. package/node_modules/dunder-proto/get.d.ts +5 -0
  291. package/node_modules/dunder-proto/get.js +30 -0
  292. package/node_modules/dunder-proto/package.json +76 -0
  293. package/node_modules/dunder-proto/set.d.ts +5 -0
  294. package/node_modules/dunder-proto/set.js +35 -0
  295. package/node_modules/dunder-proto/test/get.js +34 -0
  296. package/node_modules/dunder-proto/test/index.js +4 -0
  297. package/node_modules/dunder-proto/test/set.js +50 -0
  298. package/node_modules/dunder-proto/tsconfig.json +9 -0
  299. package/node_modules/ee-first/LICENSE +22 -0
  300. package/node_modules/ee-first/README.md +80 -0
  301. package/node_modules/ee-first/index.js +95 -0
  302. package/node_modules/ee-first/package.json +29 -0
  303. package/node_modules/encodeurl/LICENSE +22 -0
  304. package/node_modules/encodeurl/README.md +109 -0
  305. package/node_modules/encodeurl/index.js +60 -0
  306. package/node_modules/encodeurl/package.json +40 -0
  307. package/node_modules/es-define-property/.eslintrc +13 -0
  308. package/node_modules/es-define-property/.github/FUNDING.yml +12 -0
  309. package/node_modules/es-define-property/.nycrc +9 -0
  310. package/node_modules/es-define-property/CHANGELOG.md +29 -0
  311. package/node_modules/es-define-property/LICENSE +21 -0
  312. package/node_modules/es-define-property/README.md +49 -0
  313. package/node_modules/es-define-property/index.d.ts +3 -0
  314. package/node_modules/es-define-property/index.js +14 -0
  315. package/node_modules/es-define-property/package.json +81 -0
  316. package/node_modules/es-define-property/test/index.js +56 -0
  317. package/node_modules/es-define-property/tsconfig.json +10 -0
  318. package/node_modules/es-errors/.eslintrc +5 -0
  319. package/node_modules/es-errors/.github/FUNDING.yml +12 -0
  320. package/node_modules/es-errors/CHANGELOG.md +40 -0
  321. package/node_modules/es-errors/LICENSE +21 -0
  322. package/node_modules/es-errors/README.md +55 -0
  323. package/node_modules/es-errors/eval.d.ts +3 -0
  324. package/node_modules/es-errors/eval.js +4 -0
  325. package/node_modules/es-errors/index.d.ts +3 -0
  326. package/node_modules/es-errors/index.js +4 -0
  327. package/node_modules/es-errors/package.json +80 -0
  328. package/node_modules/es-errors/range.d.ts +3 -0
  329. package/node_modules/es-errors/range.js +4 -0
  330. package/node_modules/es-errors/ref.d.ts +3 -0
  331. package/node_modules/es-errors/ref.js +4 -0
  332. package/node_modules/es-errors/syntax.d.ts +3 -0
  333. package/node_modules/es-errors/syntax.js +4 -0
  334. package/node_modules/es-errors/test/index.js +19 -0
  335. package/node_modules/es-errors/tsconfig.json +49 -0
  336. package/node_modules/es-errors/type.d.ts +3 -0
  337. package/node_modules/es-errors/type.js +4 -0
  338. package/node_modules/es-errors/uri.d.ts +3 -0
  339. package/node_modules/es-errors/uri.js +4 -0
  340. package/node_modules/es-object-atoms/.eslintrc +16 -0
  341. package/node_modules/es-object-atoms/.github/FUNDING.yml +12 -0
  342. package/node_modules/es-object-atoms/CHANGELOG.md +37 -0
  343. package/node_modules/es-object-atoms/LICENSE +21 -0
  344. package/node_modules/es-object-atoms/README.md +63 -0
  345. package/node_modules/es-object-atoms/RequireObjectCoercible.d.ts +3 -0
  346. package/node_modules/es-object-atoms/RequireObjectCoercible.js +11 -0
  347. package/node_modules/es-object-atoms/ToObject.d.ts +7 -0
  348. package/node_modules/es-object-atoms/ToObject.js +10 -0
  349. package/node_modules/es-object-atoms/index.d.ts +3 -0
  350. package/node_modules/es-object-atoms/index.js +4 -0
  351. package/node_modules/es-object-atoms/isObject.d.ts +3 -0
  352. package/node_modules/es-object-atoms/isObject.js +6 -0
  353. package/node_modules/es-object-atoms/package.json +80 -0
  354. package/node_modules/es-object-atoms/test/index.js +38 -0
  355. package/node_modules/es-object-atoms/tsconfig.json +6 -0
  356. package/node_modules/escape-html/LICENSE +24 -0
  357. package/node_modules/escape-html/Readme.md +43 -0
  358. package/node_modules/escape-html/index.js +78 -0
  359. package/node_modules/escape-html/package.json +24 -0
  360. package/node_modules/etag/HISTORY.md +83 -0
  361. package/node_modules/etag/LICENSE +22 -0
  362. package/node_modules/etag/README.md +159 -0
  363. package/node_modules/etag/index.js +131 -0
  364. package/node_modules/etag/package.json +47 -0
  365. package/node_modules/express/History.md +3667 -0
  366. package/node_modules/express/LICENSE +24 -0
  367. package/node_modules/express/Readme.md +260 -0
  368. package/node_modules/express/index.js +11 -0
  369. package/node_modules/express/lib/application.js +661 -0
  370. package/node_modules/express/lib/express.js +116 -0
  371. package/node_modules/express/lib/middleware/init.js +43 -0
  372. package/node_modules/express/lib/middleware/query.js +47 -0
  373. package/node_modules/express/lib/request.js +525 -0
  374. package/node_modules/express/lib/response.js +1179 -0
  375. package/node_modules/express/lib/router/index.js +673 -0
  376. package/node_modules/express/lib/router/layer.js +181 -0
  377. package/node_modules/express/lib/router/route.js +230 -0
  378. package/node_modules/express/lib/utils.js +303 -0
  379. package/node_modules/express/lib/view.js +182 -0
  380. package/node_modules/express/package.json +102 -0
  381. package/node_modules/finalhandler/HISTORY.md +216 -0
  382. package/node_modules/finalhandler/LICENSE +22 -0
  383. package/node_modules/finalhandler/README.md +147 -0
  384. package/node_modules/finalhandler/SECURITY.md +25 -0
  385. package/node_modules/finalhandler/index.js +341 -0
  386. package/node_modules/finalhandler/package.json +47 -0
  387. package/node_modules/forwarded/HISTORY.md +21 -0
  388. package/node_modules/forwarded/LICENSE +22 -0
  389. package/node_modules/forwarded/README.md +57 -0
  390. package/node_modules/forwarded/index.js +90 -0
  391. package/node_modules/forwarded/package.json +45 -0
  392. package/node_modules/fresh/HISTORY.md +70 -0
  393. package/node_modules/fresh/LICENSE +23 -0
  394. package/node_modules/fresh/README.md +119 -0
  395. package/node_modules/fresh/index.js +137 -0
  396. package/node_modules/fresh/package.json +46 -0
  397. package/node_modules/function-bind/.eslintrc +21 -0
  398. package/node_modules/function-bind/.github/FUNDING.yml +12 -0
  399. package/node_modules/function-bind/.github/SECURITY.md +3 -0
  400. package/node_modules/function-bind/.nycrc +13 -0
  401. package/node_modules/function-bind/CHANGELOG.md +136 -0
  402. package/node_modules/function-bind/LICENSE +20 -0
  403. package/node_modules/function-bind/README.md +46 -0
  404. package/node_modules/function-bind/implementation.js +84 -0
  405. package/node_modules/function-bind/index.js +5 -0
  406. package/node_modules/function-bind/package.json +87 -0
  407. package/node_modules/function-bind/test/.eslintrc +9 -0
  408. package/node_modules/function-bind/test/index.js +252 -0
  409. package/node_modules/get-intrinsic/.eslintrc +42 -0
  410. package/node_modules/get-intrinsic/.github/FUNDING.yml +12 -0
  411. package/node_modules/get-intrinsic/.nycrc +9 -0
  412. package/node_modules/get-intrinsic/CHANGELOG.md +186 -0
  413. package/node_modules/get-intrinsic/LICENSE +21 -0
  414. package/node_modules/get-intrinsic/README.md +71 -0
  415. package/node_modules/get-intrinsic/index.js +378 -0
  416. package/node_modules/get-intrinsic/package.json +97 -0
  417. package/node_modules/get-intrinsic/test/GetIntrinsic.js +274 -0
  418. package/node_modules/get-proto/.eslintrc +10 -0
  419. package/node_modules/get-proto/.github/FUNDING.yml +12 -0
  420. package/node_modules/get-proto/.nycrc +9 -0
  421. package/node_modules/get-proto/CHANGELOG.md +21 -0
  422. package/node_modules/get-proto/LICENSE +21 -0
  423. package/node_modules/get-proto/Object.getPrototypeOf.d.ts +5 -0
  424. package/node_modules/get-proto/Object.getPrototypeOf.js +6 -0
  425. package/node_modules/get-proto/README.md +50 -0
  426. package/node_modules/get-proto/Reflect.getPrototypeOf.d.ts +3 -0
  427. package/node_modules/get-proto/Reflect.getPrototypeOf.js +4 -0
  428. package/node_modules/get-proto/index.d.ts +5 -0
  429. package/node_modules/get-proto/index.js +27 -0
  430. package/node_modules/get-proto/package.json +81 -0
  431. package/node_modules/get-proto/test/index.js +68 -0
  432. package/node_modules/get-proto/tsconfig.json +9 -0
  433. package/node_modules/gopd/.eslintrc +16 -0
  434. package/node_modules/gopd/.github/FUNDING.yml +12 -0
  435. package/node_modules/gopd/CHANGELOG.md +45 -0
  436. package/node_modules/gopd/LICENSE +21 -0
  437. package/node_modules/gopd/README.md +40 -0
  438. package/node_modules/gopd/gOPD.d.ts +1 -0
  439. package/node_modules/gopd/gOPD.js +4 -0
  440. package/node_modules/gopd/index.d.ts +5 -0
  441. package/node_modules/gopd/index.js +15 -0
  442. package/node_modules/gopd/package.json +77 -0
  443. package/node_modules/gopd/test/index.js +36 -0
  444. package/node_modules/gopd/tsconfig.json +9 -0
  445. package/node_modules/has-symbols/.eslintrc +11 -0
  446. package/node_modules/has-symbols/.github/FUNDING.yml +12 -0
  447. package/node_modules/has-symbols/.nycrc +9 -0
  448. package/node_modules/has-symbols/CHANGELOG.md +91 -0
  449. package/node_modules/has-symbols/LICENSE +21 -0
  450. package/node_modules/has-symbols/README.md +46 -0
  451. package/node_modules/has-symbols/index.d.ts +3 -0
  452. package/node_modules/has-symbols/index.js +14 -0
  453. package/node_modules/has-symbols/package.json +111 -0
  454. package/node_modules/has-symbols/shams.d.ts +3 -0
  455. package/node_modules/has-symbols/shams.js +45 -0
  456. package/node_modules/has-symbols/test/index.js +22 -0
  457. package/node_modules/has-symbols/test/shams/core-js.js +29 -0
  458. package/node_modules/has-symbols/test/shams/get-own-property-symbols.js +29 -0
  459. package/node_modules/has-symbols/test/tests.js +58 -0
  460. package/node_modules/has-symbols/tsconfig.json +10 -0
  461. package/node_modules/hasown/.eslintrc +5 -0
  462. package/node_modules/hasown/.github/FUNDING.yml +12 -0
  463. package/node_modules/hasown/.nycrc +13 -0
  464. package/node_modules/hasown/CHANGELOG.md +40 -0
  465. package/node_modules/hasown/LICENSE +21 -0
  466. package/node_modules/hasown/README.md +40 -0
  467. package/node_modules/hasown/index.d.ts +3 -0
  468. package/node_modules/hasown/index.js +8 -0
  469. package/node_modules/hasown/package.json +92 -0
  470. package/node_modules/hasown/tsconfig.json +6 -0
  471. package/node_modules/http-errors/HISTORY.md +186 -0
  472. package/node_modules/http-errors/LICENSE +23 -0
  473. package/node_modules/http-errors/README.md +169 -0
  474. package/node_modules/http-errors/index.js +290 -0
  475. package/node_modules/http-errors/package.json +54 -0
  476. package/node_modules/iconv-lite/Changelog.md +162 -0
  477. package/node_modules/iconv-lite/LICENSE +21 -0
  478. package/node_modules/iconv-lite/README.md +156 -0
  479. package/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
  480. package/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
  481. package/node_modules/iconv-lite/encodings/index.js +22 -0
  482. package/node_modules/iconv-lite/encodings/internal.js +188 -0
  483. package/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  484. package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  485. package/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
  486. package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  487. package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  488. package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  489. package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  490. package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  491. package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  492. package/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
  493. package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  494. package/node_modules/iconv-lite/encodings/utf16.js +177 -0
  495. package/node_modules/iconv-lite/encodings/utf7.js +290 -0
  496. package/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  497. package/node_modules/iconv-lite/lib/extend-node.js +217 -0
  498. package/node_modules/iconv-lite/lib/index.d.ts +24 -0
  499. package/node_modules/iconv-lite/lib/index.js +153 -0
  500. package/node_modules/iconv-lite/lib/streams.js +121 -0
  501. package/node_modules/iconv-lite/package.json +46 -0
  502. package/node_modules/inherits/LICENSE +16 -0
  503. package/node_modules/inherits/README.md +42 -0
  504. package/node_modules/inherits/inherits.js +9 -0
  505. package/node_modules/inherits/inherits_browser.js +27 -0
  506. package/node_modules/inherits/package.json +29 -0
  507. package/node_modules/ipaddr.js/LICENSE +19 -0
  508. package/node_modules/ipaddr.js/README.md +233 -0
  509. package/node_modules/ipaddr.js/ipaddr.min.js +1 -0
  510. package/node_modules/ipaddr.js/lib/ipaddr.js +673 -0
  511. package/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +68 -0
  512. package/node_modules/ipaddr.js/package.json +35 -0
  513. package/node_modules/math-intrinsics/.eslintrc +16 -0
  514. package/node_modules/math-intrinsics/.github/FUNDING.yml +12 -0
  515. package/node_modules/math-intrinsics/CHANGELOG.md +24 -0
  516. package/node_modules/math-intrinsics/LICENSE +21 -0
  517. package/node_modules/math-intrinsics/README.md +50 -0
  518. package/node_modules/math-intrinsics/abs.d.ts +1 -0
  519. package/node_modules/math-intrinsics/abs.js +4 -0
  520. package/node_modules/math-intrinsics/constants/maxArrayLength.d.ts +3 -0
  521. package/node_modules/math-intrinsics/constants/maxArrayLength.js +4 -0
  522. package/node_modules/math-intrinsics/constants/maxSafeInteger.d.ts +3 -0
  523. package/node_modules/math-intrinsics/constants/maxSafeInteger.js +5 -0
  524. package/node_modules/math-intrinsics/constants/maxValue.d.ts +3 -0
  525. package/node_modules/math-intrinsics/constants/maxValue.js +5 -0
  526. package/node_modules/math-intrinsics/floor.d.ts +1 -0
  527. package/node_modules/math-intrinsics/floor.js +4 -0
  528. package/node_modules/math-intrinsics/isFinite.d.ts +3 -0
  529. package/node_modules/math-intrinsics/isFinite.js +12 -0
  530. package/node_modules/math-intrinsics/isInteger.d.ts +3 -0
  531. package/node_modules/math-intrinsics/isInteger.js +16 -0
  532. package/node_modules/math-intrinsics/isNaN.d.ts +1 -0
  533. package/node_modules/math-intrinsics/isNaN.js +6 -0
  534. package/node_modules/math-intrinsics/isNegativeZero.d.ts +3 -0
  535. package/node_modules/math-intrinsics/isNegativeZero.js +6 -0
  536. package/node_modules/math-intrinsics/max.d.ts +1 -0
  537. package/node_modules/math-intrinsics/max.js +4 -0
  538. package/node_modules/math-intrinsics/min.d.ts +1 -0
  539. package/node_modules/math-intrinsics/min.js +4 -0
  540. package/node_modules/math-intrinsics/mod.d.ts +3 -0
  541. package/node_modules/math-intrinsics/mod.js +9 -0
  542. package/node_modules/math-intrinsics/package.json +86 -0
  543. package/node_modules/math-intrinsics/pow.d.ts +1 -0
  544. package/node_modules/math-intrinsics/pow.js +4 -0
  545. package/node_modules/math-intrinsics/round.d.ts +1 -0
  546. package/node_modules/math-intrinsics/round.js +4 -0
  547. package/node_modules/math-intrinsics/sign.d.ts +3 -0
  548. package/node_modules/math-intrinsics/sign.js +11 -0
  549. package/node_modules/math-intrinsics/test/index.js +192 -0
  550. package/node_modules/math-intrinsics/tsconfig.json +3 -0
  551. package/node_modules/media-typer/HISTORY.md +22 -0
  552. package/node_modules/media-typer/LICENSE +22 -0
  553. package/node_modules/media-typer/README.md +81 -0
  554. package/node_modules/media-typer/index.js +270 -0
  555. package/node_modules/media-typer/package.json +26 -0
  556. package/node_modules/merge-descriptors/HISTORY.md +21 -0
  557. package/node_modules/merge-descriptors/LICENSE +23 -0
  558. package/node_modules/merge-descriptors/README.md +49 -0
  559. package/node_modules/merge-descriptors/index.js +60 -0
  560. package/node_modules/merge-descriptors/package.json +39 -0
  561. package/node_modules/methods/HISTORY.md +29 -0
  562. package/node_modules/methods/LICENSE +24 -0
  563. package/node_modules/methods/README.md +51 -0
  564. package/node_modules/methods/index.js +69 -0
  565. package/node_modules/methods/package.json +36 -0
  566. package/node_modules/mime/.npmignore +0 -0
  567. package/node_modules/mime/CHANGELOG.md +164 -0
  568. package/node_modules/mime/LICENSE +21 -0
  569. package/node_modules/mime/README.md +90 -0
  570. package/node_modules/mime/cli.js +8 -0
  571. package/node_modules/mime/mime.js +108 -0
  572. package/node_modules/mime/package.json +44 -0
  573. package/node_modules/mime/src/build.js +53 -0
  574. package/node_modules/mime/src/test.js +60 -0
  575. package/node_modules/mime/types.json +1 -0
  576. package/node_modules/mime-db/HISTORY.md +507 -0
  577. package/node_modules/mime-db/LICENSE +23 -0
  578. package/node_modules/mime-db/README.md +100 -0
  579. package/node_modules/mime-db/db.json +8519 -0
  580. package/node_modules/mime-db/index.js +12 -0
  581. package/node_modules/mime-db/package.json +60 -0
  582. package/node_modules/mime-types/HISTORY.md +397 -0
  583. package/node_modules/mime-types/LICENSE +23 -0
  584. package/node_modules/mime-types/README.md +113 -0
  585. package/node_modules/mime-types/index.js +188 -0
  586. package/node_modules/mime-types/package.json +44 -0
  587. package/node_modules/ms/index.js +152 -0
  588. package/node_modules/ms/license.md +21 -0
  589. package/node_modules/ms/package.json +37 -0
  590. package/node_modules/ms/readme.md +51 -0
  591. package/node_modules/negotiator/HISTORY.md +108 -0
  592. package/node_modules/negotiator/LICENSE +24 -0
  593. package/node_modules/negotiator/README.md +203 -0
  594. package/node_modules/negotiator/index.js +82 -0
  595. package/node_modules/negotiator/lib/charset.js +169 -0
  596. package/node_modules/negotiator/lib/encoding.js +184 -0
  597. package/node_modules/negotiator/lib/language.js +179 -0
  598. package/node_modules/negotiator/lib/mediaType.js +294 -0
  599. package/node_modules/negotiator/package.json +42 -0
  600. package/node_modules/object-assign/index.js +90 -0
  601. package/node_modules/object-assign/license +21 -0
  602. package/node_modules/object-assign/package.json +42 -0
  603. package/node_modules/object-assign/readme.md +61 -0
  604. package/node_modules/object-inspect/.eslintrc +53 -0
  605. package/node_modules/object-inspect/.github/FUNDING.yml +12 -0
  606. package/node_modules/object-inspect/.nycrc +13 -0
  607. package/node_modules/object-inspect/CHANGELOG.md +424 -0
  608. package/node_modules/object-inspect/LICENSE +21 -0
  609. package/node_modules/object-inspect/example/all.js +23 -0
  610. package/node_modules/object-inspect/example/circular.js +6 -0
  611. package/node_modules/object-inspect/example/fn.js +5 -0
  612. package/node_modules/object-inspect/example/inspect.js +10 -0
  613. package/node_modules/object-inspect/index.js +544 -0
  614. package/node_modules/object-inspect/package-support.json +20 -0
  615. package/node_modules/object-inspect/package.json +105 -0
  616. package/node_modules/object-inspect/readme.markdown +84 -0
  617. package/node_modules/object-inspect/test/bigint.js +58 -0
  618. package/node_modules/object-inspect/test/browser/dom.js +15 -0
  619. package/node_modules/object-inspect/test/circular.js +16 -0
  620. package/node_modules/object-inspect/test/deep.js +12 -0
  621. package/node_modules/object-inspect/test/element.js +53 -0
  622. package/node_modules/object-inspect/test/err.js +48 -0
  623. package/node_modules/object-inspect/test/fakes.js +29 -0
  624. package/node_modules/object-inspect/test/fn.js +76 -0
  625. package/node_modules/object-inspect/test/global.js +17 -0
  626. package/node_modules/object-inspect/test/has.js +15 -0
  627. package/node_modules/object-inspect/test/holes.js +15 -0
  628. package/node_modules/object-inspect/test/indent-option.js +271 -0
  629. package/node_modules/object-inspect/test/inspect.js +139 -0
  630. package/node_modules/object-inspect/test/lowbyte.js +12 -0
  631. package/node_modules/object-inspect/test/number.js +58 -0
  632. package/node_modules/object-inspect/test/quoteStyle.js +26 -0
  633. package/node_modules/object-inspect/test/toStringTag.js +40 -0
  634. package/node_modules/object-inspect/test/undef.js +12 -0
  635. package/node_modules/object-inspect/test/values.js +261 -0
  636. package/node_modules/object-inspect/test-core-js.js +26 -0
  637. package/node_modules/object-inspect/util.inspect.js +1 -0
  638. package/node_modules/on-finished/HISTORY.md +98 -0
  639. package/node_modules/on-finished/LICENSE +23 -0
  640. package/node_modules/on-finished/README.md +162 -0
  641. package/node_modules/on-finished/index.js +234 -0
  642. package/node_modules/on-finished/package.json +39 -0
  643. package/node_modules/parseurl/HISTORY.md +58 -0
  644. package/node_modules/parseurl/LICENSE +24 -0
  645. package/node_modules/parseurl/README.md +133 -0
  646. package/node_modules/parseurl/index.js +158 -0
  647. package/node_modules/parseurl/package.json +40 -0
  648. package/node_modules/path-to-regexp/LICENSE +21 -0
  649. package/node_modules/path-to-regexp/Readme.md +35 -0
  650. package/node_modules/path-to-regexp/index.js +156 -0
  651. package/node_modules/path-to-regexp/package.json +30 -0
  652. package/node_modules/proxy-addr/HISTORY.md +161 -0
  653. package/node_modules/proxy-addr/LICENSE +22 -0
  654. package/node_modules/proxy-addr/README.md +139 -0
  655. package/node_modules/proxy-addr/index.js +327 -0
  656. package/node_modules/proxy-addr/package.json +47 -0
  657. package/node_modules/qs/.editorconfig +46 -0
  658. package/node_modules/qs/.github/FUNDING.yml +12 -0
  659. package/node_modules/qs/.github/SECURITY.md +11 -0
  660. package/node_modules/qs/.github/THREAT_MODEL.md +78 -0
  661. package/node_modules/qs/.nycrc +13 -0
  662. package/node_modules/qs/CHANGELOG.md +644 -0
  663. package/node_modules/qs/LICENSE.md +29 -0
  664. package/node_modules/qs/README.md +740 -0
  665. package/node_modules/qs/dist/qs.js +141 -0
  666. package/node_modules/qs/eslint.config.mjs +56 -0
  667. package/node_modules/qs/lib/formats.js +23 -0
  668. package/node_modules/qs/lib/index.js +11 -0
  669. package/node_modules/qs/lib/parse.js +371 -0
  670. package/node_modules/qs/lib/stringify.js +356 -0
  671. package/node_modules/qs/lib/utils.js +340 -0
  672. package/node_modules/qs/package.json +94 -0
  673. package/node_modules/qs/test/empty-keys-cases.js +267 -0
  674. package/node_modules/qs/test/parse.js +1512 -0
  675. package/node_modules/qs/test/stringify.js +1310 -0
  676. package/node_modules/qs/test/utils.js +397 -0
  677. package/node_modules/range-parser/HISTORY.md +56 -0
  678. package/node_modules/range-parser/LICENSE +23 -0
  679. package/node_modules/range-parser/README.md +84 -0
  680. package/node_modules/range-parser/index.js +162 -0
  681. package/node_modules/range-parser/package.json +44 -0
  682. package/node_modules/raw-body/LICENSE +22 -0
  683. package/node_modules/raw-body/README.md +223 -0
  684. package/node_modules/raw-body/index.d.ts +87 -0
  685. package/node_modules/raw-body/index.js +336 -0
  686. package/node_modules/raw-body/package.json +47 -0
  687. package/node_modules/safe-buffer/LICENSE +21 -0
  688. package/node_modules/safe-buffer/README.md +584 -0
  689. package/node_modules/safe-buffer/index.d.ts +187 -0
  690. package/node_modules/safe-buffer/index.js +65 -0
  691. package/node_modules/safe-buffer/package.json +51 -0
  692. package/node_modules/safer-buffer/LICENSE +21 -0
  693. package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  694. package/node_modules/safer-buffer/Readme.md +156 -0
  695. package/node_modules/safer-buffer/dangerous.js +58 -0
  696. package/node_modules/safer-buffer/package.json +34 -0
  697. package/node_modules/safer-buffer/safer.js +77 -0
  698. package/node_modules/safer-buffer/tests.js +406 -0
  699. package/node_modules/send/HISTORY.md +538 -0
  700. package/node_modules/send/LICENSE +23 -0
  701. package/node_modules/send/README.md +327 -0
  702. package/node_modules/send/SECURITY.md +24 -0
  703. package/node_modules/send/index.js +1142 -0
  704. package/node_modules/send/node_modules/ms/index.js +162 -0
  705. package/node_modules/send/node_modules/ms/license.md +21 -0
  706. package/node_modules/send/node_modules/ms/package.json +38 -0
  707. package/node_modules/send/node_modules/ms/readme.md +59 -0
  708. package/node_modules/send/package.json +62 -0
  709. package/node_modules/serve-static/HISTORY.md +493 -0
  710. package/node_modules/serve-static/LICENSE +25 -0
  711. package/node_modules/serve-static/README.md +257 -0
  712. package/node_modules/serve-static/index.js +209 -0
  713. package/node_modules/serve-static/package.json +42 -0
  714. package/node_modules/setprototypeof/LICENSE +13 -0
  715. package/node_modules/setprototypeof/README.md +31 -0
  716. package/node_modules/setprototypeof/index.d.ts +2 -0
  717. package/node_modules/setprototypeof/index.js +17 -0
  718. package/node_modules/setprototypeof/package.json +38 -0
  719. package/node_modules/setprototypeof/test/index.js +24 -0
  720. package/node_modules/side-channel/.editorconfig +9 -0
  721. package/node_modules/side-channel/.eslintrc +12 -0
  722. package/node_modules/side-channel/.github/FUNDING.yml +12 -0
  723. package/node_modules/side-channel/.nycrc +13 -0
  724. package/node_modules/side-channel/CHANGELOG.md +110 -0
  725. package/node_modules/side-channel/LICENSE +21 -0
  726. package/node_modules/side-channel/README.md +61 -0
  727. package/node_modules/side-channel/index.d.ts +14 -0
  728. package/node_modules/side-channel/index.js +43 -0
  729. package/node_modules/side-channel/package.json +85 -0
  730. package/node_modules/side-channel/test/index.js +104 -0
  731. package/node_modules/side-channel/tsconfig.json +9 -0
  732. package/node_modules/side-channel-list/.editorconfig +9 -0
  733. package/node_modules/side-channel-list/.eslintrc +11 -0
  734. package/node_modules/side-channel-list/.github/FUNDING.yml +12 -0
  735. package/node_modules/side-channel-list/.nycrc +13 -0
  736. package/node_modules/side-channel-list/CHANGELOG.md +15 -0
  737. package/node_modules/side-channel-list/LICENSE +21 -0
  738. package/node_modules/side-channel-list/README.md +62 -0
  739. package/node_modules/side-channel-list/index.d.ts +13 -0
  740. package/node_modules/side-channel-list/index.js +113 -0
  741. package/node_modules/side-channel-list/list.d.ts +14 -0
  742. package/node_modules/side-channel-list/package.json +77 -0
  743. package/node_modules/side-channel-list/test/index.js +104 -0
  744. package/node_modules/side-channel-list/tsconfig.json +9 -0
  745. package/node_modules/side-channel-map/.editorconfig +9 -0
  746. package/node_modules/side-channel-map/.eslintrc +11 -0
  747. package/node_modules/side-channel-map/.github/FUNDING.yml +12 -0
  748. package/node_modules/side-channel-map/.nycrc +13 -0
  749. package/node_modules/side-channel-map/CHANGELOG.md +22 -0
  750. package/node_modules/side-channel-map/LICENSE +21 -0
  751. package/node_modules/side-channel-map/README.md +62 -0
  752. package/node_modules/side-channel-map/index.d.ts +15 -0
  753. package/node_modules/side-channel-map/index.js +68 -0
  754. package/node_modules/side-channel-map/package.json +80 -0
  755. package/node_modules/side-channel-map/test/index.js +114 -0
  756. package/node_modules/side-channel-map/tsconfig.json +9 -0
  757. package/node_modules/side-channel-weakmap/.editorconfig +9 -0
  758. package/node_modules/side-channel-weakmap/.eslintrc +12 -0
  759. package/node_modules/side-channel-weakmap/.github/FUNDING.yml +12 -0
  760. package/node_modules/side-channel-weakmap/.nycrc +13 -0
  761. package/node_modules/side-channel-weakmap/CHANGELOG.md +28 -0
  762. package/node_modules/side-channel-weakmap/LICENSE +21 -0
  763. package/node_modules/side-channel-weakmap/README.md +62 -0
  764. package/node_modules/side-channel-weakmap/index.d.ts +15 -0
  765. package/node_modules/side-channel-weakmap/index.js +84 -0
  766. package/node_modules/side-channel-weakmap/package.json +87 -0
  767. package/node_modules/side-channel-weakmap/test/index.js +114 -0
  768. package/node_modules/side-channel-weakmap/tsconfig.json +9 -0
  769. package/node_modules/statuses/HISTORY.md +87 -0
  770. package/node_modules/statuses/LICENSE +23 -0
  771. package/node_modules/statuses/README.md +139 -0
  772. package/node_modules/statuses/codes.json +65 -0
  773. package/node_modules/statuses/index.js +146 -0
  774. package/node_modules/statuses/package.json +49 -0
  775. package/node_modules/toidentifier/HISTORY.md +9 -0
  776. package/node_modules/toidentifier/LICENSE +21 -0
  777. package/node_modules/toidentifier/README.md +61 -0
  778. package/node_modules/toidentifier/index.js +32 -0
  779. package/node_modules/toidentifier/package.json +38 -0
  780. package/node_modules/tweetnacl/AUTHORS.md +27 -0
  781. package/node_modules/tweetnacl/CHANGELOG.md +283 -0
  782. package/node_modules/tweetnacl/LICENSE +24 -0
  783. package/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  784. package/node_modules/tweetnacl/README.md +494 -0
  785. package/node_modules/tweetnacl/nacl-fast.js +2391 -0
  786. package/node_modules/tweetnacl/nacl-fast.min.js +1 -0
  787. package/node_modules/tweetnacl/nacl.d.ts +98 -0
  788. package/node_modules/tweetnacl/nacl.js +1178 -0
  789. package/node_modules/tweetnacl/nacl.min.js +1 -0
  790. package/node_modules/tweetnacl/package.json +56 -0
  791. package/node_modules/type-is/HISTORY.md +259 -0
  792. package/node_modules/type-is/LICENSE +23 -0
  793. package/node_modules/type-is/README.md +170 -0
  794. package/node_modules/type-is/index.js +266 -0
  795. package/node_modules/type-is/package.json +45 -0
  796. package/node_modules/unpipe/HISTORY.md +4 -0
  797. package/node_modules/unpipe/LICENSE +22 -0
  798. package/node_modules/unpipe/README.md +43 -0
  799. package/node_modules/unpipe/index.js +69 -0
  800. package/node_modules/unpipe/package.json +27 -0
  801. package/node_modules/utils-merge/.npmignore +9 -0
  802. package/node_modules/utils-merge/LICENSE +20 -0
  803. package/node_modules/utils-merge/README.md +34 -0
  804. package/node_modules/utils-merge/index.js +23 -0
  805. package/node_modules/utils-merge/package.json +40 -0
  806. package/node_modules/vary/HISTORY.md +39 -0
  807. package/node_modules/vary/LICENSE +22 -0
  808. package/node_modules/vary/README.md +101 -0
  809. package/node_modules/vary/index.js +149 -0
  810. package/node_modules/vary/package.json +43 -0
  811. package/openclaw-skills/silicaclaw-broadcast/VERSION +1 -1
  812. package/openclaw-skills/silicaclaw-broadcast/manifest.json +1 -1
  813. package/package.json +20 -2
  814. package/scripts/release-pack.mjs +89 -0
  815. package/scripts/silicaclaw-gateway.mjs +31 -26
@@ -0,0 +1,2721 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LocalNodeService = void 0;
7
+ exports.main = main;
8
+ const express_1 = __importDefault(require("express"));
9
+ const cors_1 = __importDefault(require("cors"));
10
+ const child_process_1 = require("child_process");
11
+ const path_1 = require("path");
12
+ const fs_1 = require("fs");
13
+ const crypto_1 = require("crypto");
14
+ const os_1 = require("os");
15
+ const util_1 = require("util");
16
+ const core_1 = require("@silicaclaw/core");
17
+ const network_1 = require("@silicaclaw/network");
18
+ const storage_1 = require("@silicaclaw/storage");
19
+ const socialRoutes_1 = require("./socialRoutes");
20
+ const BROADCAST_INTERVAL_MS = Number(process.env.BROADCAST_INTERVAL_MS || 20_000);
21
+ const PRESENCE_TTL_MS = Number(process.env.PRESENCE_TTL_MS || 90_000);
22
+ const NETWORK_MAX_MESSAGE_BYTES = Number(process.env.NETWORK_MAX_MESSAGE_BYTES || 64 * 1024);
23
+ const NETWORK_DEDUPE_WINDOW_MS = Number(process.env.NETWORK_DEDUPE_WINDOW_MS || 90_000);
24
+ const NETWORK_DEDUPE_MAX_ENTRIES = Number(process.env.NETWORK_DEDUPE_MAX_ENTRIES || 10_000);
25
+ const NETWORK_MAX_FUTURE_DRIFT_MS = Number(process.env.NETWORK_MAX_FUTURE_DRIFT_MS || 30_000);
26
+ const NETWORK_MAX_PAST_DRIFT_MS = Number(process.env.NETWORK_MAX_PAST_DRIFT_MS || 120_000);
27
+ const NETWORK_HEARTBEAT_INTERVAL_MS = Number(process.env.NETWORK_HEARTBEAT_INTERVAL_MS || 12_000);
28
+ const NETWORK_PEER_STALE_AFTER_MS = Number(process.env.NETWORK_PEER_STALE_AFTER_MS || 45_000);
29
+ const OPENCLAW_GATEWAY_HOST = "127.0.0.1";
30
+ const OPENCLAW_GATEWAY_PORT = 18_789;
31
+ const OPENCLAW_GATEWAY_URL = `http://${OPENCLAW_GATEWAY_HOST}:${OPENCLAW_GATEWAY_PORT}/`;
32
+ const NETWORK_PEER_REMOVE_AFTER_MS = Number(process.env.NETWORK_PEER_REMOVE_AFTER_MS || 180_000);
33
+ const NETWORK_UDP_BIND_ADDRESS = process.env.NETWORK_UDP_BIND_ADDRESS || "0.0.0.0";
34
+ const NETWORK_UDP_BROADCAST_ADDRESS = process.env.NETWORK_UDP_BROADCAST_ADDRESS || "255.255.255.255";
35
+ const NETWORK_PEER_ID = process.env.NETWORK_PEER_ID;
36
+ const NETWORK_MODE = process.env.NETWORK_MODE || "";
37
+ const WEBRTC_SIGNALING_URL = process.env.WEBRTC_SIGNALING_URL || "https://relay.silicaclaw.com";
38
+ const WEBRTC_SIGNALING_URLS = process.env.WEBRTC_SIGNALING_URLS || "";
39
+ const WEBRTC_ROOM = process.env.WEBRTC_ROOM || "silicaclaw-global-preview";
40
+ const WEBRTC_SEED_PEERS = process.env.WEBRTC_SEED_PEERS || "";
41
+ const WEBRTC_BOOTSTRAP_HINTS = process.env.WEBRTC_BOOTSTRAP_HINTS || "";
42
+ const PROFILE_VERSION = "v0.9";
43
+ const SOCIAL_MESSAGE_TOPIC = "social.message";
44
+ const SOCIAL_MESSAGE_OBSERVATION_TOPIC = "social.message.observation";
45
+ const DEFAULT_SOCIAL_MESSAGE_CHANNEL = "global";
46
+ const SOCIAL_MESSAGE_MAX_BODY_CHARS = Number(process.env.SOCIAL_MESSAGE_MAX_BODY_CHARS || 500);
47
+ const SOCIAL_MESSAGE_HISTORY_LIMIT = Number(process.env.SOCIAL_MESSAGE_HISTORY_LIMIT || 100);
48
+ const SOCIAL_MESSAGE_SEND_WINDOW_MS = Number(process.env.SOCIAL_MESSAGE_SEND_WINDOW_MS || 60_000);
49
+ const SOCIAL_MESSAGE_SEND_MAX_PER_WINDOW = Number(process.env.SOCIAL_MESSAGE_SEND_MAX_PER_WINDOW || 5);
50
+ const SOCIAL_MESSAGE_RECEIVE_WINDOW_MS = Number(process.env.SOCIAL_MESSAGE_RECEIVE_WINDOW_MS || 60_000);
51
+ const SOCIAL_MESSAGE_RECEIVE_MAX_PER_WINDOW = Number(process.env.SOCIAL_MESSAGE_RECEIVE_MAX_PER_WINDOW || 8);
52
+ const SOCIAL_MESSAGE_DUPLICATE_WINDOW_MS = Number(process.env.SOCIAL_MESSAGE_DUPLICATE_WINDOW_MS || 180_000);
53
+ const SOCIAL_MESSAGE_MAX_FUTURE_MS = Number(process.env.SOCIAL_MESSAGE_MAX_FUTURE_MS || 30_000);
54
+ const SOCIAL_MESSAGE_MAX_AGE_MS = Number(process.env.SOCIAL_MESSAGE_MAX_AGE_MS || 15 * 60_000);
55
+ const SOCIAL_MESSAGE_OBSERVATION_HISTORY_LIMIT = Number(process.env.SOCIAL_MESSAGE_OBSERVATION_HISTORY_LIMIT || 500);
56
+ const SOCIAL_MESSAGE_BLOCKED_AGENT_IDS = new Set(dedupeStrings(parseListEnv(process.env.SOCIAL_MESSAGE_BLOCKED_AGENT_IDS || "")));
57
+ const SOCIAL_MESSAGE_BLOCKED_TERMS = dedupeStrings(parseListEnv(process.env.SOCIAL_MESSAGE_BLOCKED_TERMS || ""))
58
+ .map((term) => term.trim().toLowerCase())
59
+ .filter(Boolean);
60
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
61
+ const OPENCLAW_SKILL_NAME = "silicaclaw-broadcast";
62
+ function readWorkspaceVersion(workspaceRoot) {
63
+ const pkgFile = (0, path_1.resolve)(workspaceRoot, "package.json");
64
+ if ((0, fs_1.existsSync)(pkgFile)) {
65
+ try {
66
+ const pkg = JSON.parse((0, fs_1.readFileSync)(pkgFile, "utf8"));
67
+ if (pkg.version)
68
+ return String(pkg.version);
69
+ }
70
+ catch {
71
+ // ignore
72
+ }
73
+ }
74
+ const versionFile = (0, path_1.resolve)(workspaceRoot, "VERSION");
75
+ if ((0, fs_1.existsSync)(versionFile)) {
76
+ const raw = (0, fs_1.readFileSync)(versionFile, "utf8").trim();
77
+ if (raw)
78
+ return raw;
79
+ }
80
+ return "unknown";
81
+ }
82
+ function resolveWorkspaceRoot(cwd = process.cwd()) {
83
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(cwd, "apps", "local-console", "package.json"))) {
84
+ return cwd;
85
+ }
86
+ const candidate = (0, path_1.resolve)(cwd, "..", "..");
87
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(candidate, "apps", "local-console", "package.json"))) {
88
+ return candidate;
89
+ }
90
+ return cwd;
91
+ }
92
+ function resolveStorageRoot(workspaceRoot, cwd = process.cwd()) {
93
+ const appRoot = (0, path_1.resolve)(workspaceRoot, "apps", "local-console");
94
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(appRoot, "package.json"))) {
95
+ return appRoot;
96
+ }
97
+ return cwd;
98
+ }
99
+ function resolveExecutableInPath(binName) {
100
+ const pathValue = String(process.env.PATH || "").trim();
101
+ if (!pathValue)
102
+ return null;
103
+ const pathEntries = pathValue.split(":").map((item) => item.trim()).filter(Boolean);
104
+ for (const entry of pathEntries) {
105
+ const candidate = (0, path_1.resolve)(entry, binName);
106
+ if (!(0, fs_1.existsSync)(candidate))
107
+ continue;
108
+ try {
109
+ (0, fs_1.accessSync)(candidate, fs_1.constants.X_OK);
110
+ return candidate;
111
+ }
112
+ catch {
113
+ // ignore non-executable matches
114
+ }
115
+ }
116
+ return null;
117
+ }
118
+ function existingPathOrNull(filePath) {
119
+ return (0, fs_1.existsSync)(filePath) ? filePath : null;
120
+ }
121
+ function listDirectories(root) {
122
+ if (!root || !(0, fs_1.existsSync)(root))
123
+ return [];
124
+ try {
125
+ return (0, fs_1.readdirSync)(root)
126
+ .map((name) => {
127
+ const fullPath = (0, path_1.resolve)(root, name);
128
+ try {
129
+ return (0, fs_1.statSync)(fullPath).isDirectory() ? { name, path: fullPath } : null;
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ })
135
+ .filter((item) => Boolean(item));
136
+ }
137
+ catch {
138
+ return [];
139
+ }
140
+ }
141
+ function readJsonFileSafe(filePath) {
142
+ try {
143
+ return JSON.parse((0, fs_1.readFileSync)(filePath, "utf8"));
144
+ }
145
+ catch {
146
+ return null;
147
+ }
148
+ }
149
+ function summarizeSkillReadme(filePath) {
150
+ if (!filePath || !(0, fs_1.existsSync)(filePath))
151
+ return "";
152
+ try {
153
+ const raw = (0, fs_1.readFileSync)(filePath, "utf8");
154
+ const lines = raw
155
+ .split(/\r?\n/)
156
+ .map((line) => line.trim())
157
+ .filter(Boolean)
158
+ .filter((line) => !line.startsWith("#"));
159
+ return String(lines[0] || "").slice(0, 220);
160
+ }
161
+ catch {
162
+ return "";
163
+ }
164
+ }
165
+ function detectOpenClawInstallation(workspaceRoot) {
166
+ const workspaceDir = (0, path_1.resolve)(workspaceRoot, ".openclaw");
167
+ const homeDir = (0, path_1.resolve)(process.env.HOME || "", ".openclaw");
168
+ const commandPath = resolveExecutableInPath("openclaw");
169
+ const workspaceIdentityPath = existingPathOrNull((0, path_1.resolve)(workspaceDir, "identity.json"));
170
+ const workspaceProfilePath = existingPathOrNull((0, path_1.resolve)(workspaceDir, "profile.json"));
171
+ const workspaceSocialPath = existingPathOrNull((0, path_1.resolve)(workspaceDir, "social.md"));
172
+ const workspaceSkillsPath = existingPathOrNull((0, path_1.resolve)(workspaceDir, "skills"));
173
+ const homeIdentityPath = existingPathOrNull((0, path_1.resolve)(homeDir, "identity.json"));
174
+ const homeProfilePath = existingPathOrNull((0, path_1.resolve)(homeDir, "profile.json"));
175
+ const homeSocialPath = existingPathOrNull((0, path_1.resolve)(homeDir, "social.md"));
176
+ const homeSkillsPath = existingPathOrNull((0, path_1.resolve)(homeDir, "skills"));
177
+ const workspaceDetected = Boolean((0, fs_1.existsSync)(workspaceDir) ||
178
+ workspaceIdentityPath ||
179
+ workspaceProfilePath ||
180
+ workspaceSocialPath ||
181
+ workspaceSkillsPath);
182
+ const homeDetected = Boolean((0, fs_1.existsSync)(homeDir) || homeIdentityPath || homeProfilePath || homeSocialPath || homeSkillsPath);
183
+ return {
184
+ detected: Boolean(commandPath || workspaceDetected || homeDetected),
185
+ detection_mode: commandPath
186
+ ? "command"
187
+ : workspaceDetected
188
+ ? "workspace"
189
+ : homeDetected
190
+ ? "home"
191
+ : "not_found",
192
+ command_path: commandPath,
193
+ workspace_dir: workspaceDir,
194
+ home_dir: homeDir,
195
+ workspace_dir_exists: (0, fs_1.existsSync)(workspaceDir),
196
+ home_dir_exists: (0, fs_1.existsSync)(homeDir),
197
+ workspace_identity_path: workspaceIdentityPath,
198
+ workspace_profile_path: workspaceProfilePath,
199
+ workspace_social_path: workspaceSocialPath,
200
+ workspace_skills_path: workspaceSkillsPath,
201
+ home_identity_path: homeIdentityPath,
202
+ home_profile_path: homeProfilePath,
203
+ home_social_path: homeSocialPath,
204
+ home_skills_path: homeSkillsPath,
205
+ };
206
+ }
207
+ function readOpenClawConfiguredGateway(workspaceRoot) {
208
+ const configuredSourceDir = String(process.env.OPENCLAW_SOURCE_DIR || "").trim();
209
+ const defaultSourceDir = (0, path_1.resolve)(workspaceRoot, "..", "openclaw");
210
+ const sourceDir = configuredSourceDir || defaultSourceDir;
211
+ const homeDir = (0, path_1.resolve)(process.env.HOME || "", ".openclaw");
212
+ const explicitConfigPath = String(process.env.OPENCLAW_CONFIG_PATH || "").trim();
213
+ const explicitStateDir = String(process.env.OPENCLAW_STATE_DIR || "").trim();
214
+ const candidates = dedupeStrings([
215
+ explicitConfigPath,
216
+ explicitStateDir ? (0, path_1.resolve)(explicitStateDir, "openclaw.json") : "",
217
+ (0, path_1.resolve)(homeDir, "openclaw.json"),
218
+ (0, path_1.resolve)(homeDir, "clawdbot.json"),
219
+ (0, path_1.resolve)(sourceDir, ".openclaw", "openclaw.json"),
220
+ ]);
221
+ for (const candidate of candidates) {
222
+ if (!candidate || !(0, fs_1.existsSync)(candidate))
223
+ continue;
224
+ try {
225
+ const raw = (0, fs_1.readFileSync)(candidate, "utf8");
226
+ const portMatch = raw.match(/["']?port["']?\s*:\s*(\d{2,5})/);
227
+ const bindMatch = raw.match(/["']?bind["']?\s*:\s*["']([^"']+)["']/);
228
+ const port = portMatch ? Number(portMatch[1]) : OPENCLAW_GATEWAY_PORT;
229
+ if (!Number.isFinite(port) || port <= 0)
230
+ continue;
231
+ return {
232
+ config_path: candidate,
233
+ gateway_port: port,
234
+ gateway_host: OPENCLAW_GATEWAY_HOST,
235
+ gateway_bind: bindMatch?.[1] || null,
236
+ gateway_url: `http://${OPENCLAW_GATEWAY_HOST}:${port}/`,
237
+ };
238
+ }
239
+ catch {
240
+ continue;
241
+ }
242
+ }
243
+ return {
244
+ config_path: null,
245
+ gateway_port: OPENCLAW_GATEWAY_PORT,
246
+ gateway_host: OPENCLAW_GATEWAY_HOST,
247
+ gateway_bind: null,
248
+ gateway_url: OPENCLAW_GATEWAY_URL,
249
+ };
250
+ }
251
+ function detectOpenClawRuntime(workspaceRoot) {
252
+ const configuredGateway = readOpenClawConfiguredGateway(workspaceRoot);
253
+ const result = (0, child_process_1.spawnSync)("ps", ["-Ao", "pid=,ppid=,command="], {
254
+ encoding: "utf8",
255
+ });
256
+ const stdout = String(result.stdout || "");
257
+ const lines = stdout
258
+ .split("\n")
259
+ .map((line) => line.trim())
260
+ .filter(Boolean);
261
+ const processes = lines
262
+ .map((line) => {
263
+ const match = line.match(/^(\d+)\s+(\d+)\s+(.+)$/);
264
+ if (!match)
265
+ return null;
266
+ const command = match[3] || "";
267
+ const lower = command.toLowerCase();
268
+ const isOpenClaw = lower.includes(" openclaw ") ||
269
+ lower.endsWith(" openclaw") ||
270
+ lower.includes("/openclaw ") ||
271
+ lower.includes("openclaw.mjs") ||
272
+ lower.includes("openclaw gateway") ||
273
+ lower.includes("openclaw agent") ||
274
+ lower.includes("openclaw message");
275
+ if (!isOpenClaw)
276
+ return null;
277
+ return {
278
+ pid: Number(match[1]),
279
+ ppid: Number(match[2]),
280
+ command,
281
+ };
282
+ })
283
+ .filter((item) => Boolean(item));
284
+ const openclawPids = new Set(processes.map((item) => item.pid));
285
+ const gatewayProbe = (0, child_process_1.spawnSync)("lsof", ["-nP", "-iTCP", "-sTCP:LISTEN"], {
286
+ encoding: "utf8",
287
+ });
288
+ const gatewayLines = String(gatewayProbe.stdout || "")
289
+ .split("\n")
290
+ .map((line) => line.trim())
291
+ .filter(Boolean);
292
+ const gatewayListeners = gatewayLines
293
+ .slice(1)
294
+ .map((line) => {
295
+ const parts = line.split(/\s+/);
296
+ const pid = Number(parts[1] || 0);
297
+ const command = parts[0] || "";
298
+ const lowerCommand = command.toLowerCase();
299
+ const endpoint = parts[8] || parts[parts.length - 1] || "";
300
+ const portMatch = endpoint.match(/:(\d+)(?:\s*\(|$)/);
301
+ if (!pid || !command || !portMatch)
302
+ return null;
303
+ const isOpenClawListener = openclawPids.has(pid) ||
304
+ lowerCommand.includes("openclaw");
305
+ if (!isOpenClawListener)
306
+ return null;
307
+ const port = Number(portMatch[1]);
308
+ if (!Number.isFinite(port) || port <= 0)
309
+ return null;
310
+ return {
311
+ pid,
312
+ ppid: 0,
313
+ port,
314
+ command: `${command} listening on ${OPENCLAW_GATEWAY_HOST}:${port}`,
315
+ };
316
+ })
317
+ .filter((item) => Boolean(item));
318
+ const preferredListener = gatewayListeners.find((item) => item.port === configuredGateway.gateway_port) ||
319
+ gatewayListeners[0] ||
320
+ null;
321
+ const combinedProcesses = new Map();
322
+ for (const process of [...processes, ...gatewayListeners]) {
323
+ if (!combinedProcesses.has(process.pid)) {
324
+ combinedProcesses.set(process.pid, process);
325
+ continue;
326
+ }
327
+ const current = combinedProcesses.get(process.pid);
328
+ if (current && current.command.length < process.command.length) {
329
+ combinedProcesses.set(process.pid, process);
330
+ }
331
+ }
332
+ const allProcesses = Array.from(combinedProcesses.values());
333
+ const gatewayReachable = gatewayListeners.length > 0;
334
+ const detectionNotes = [];
335
+ if (result.status !== 0)
336
+ detectionNotes.push(String(result.stderr || "ps failed").trim());
337
+ if (gatewayProbe.status !== 0 && gatewayLines.length === 0) {
338
+ detectionNotes.push(String(gatewayProbe.stderr || "lsof failed").trim());
339
+ }
340
+ const gatewayPort = preferredListener?.port || configuredGateway.gateway_port;
341
+ const gatewayUrl = `http://${OPENCLAW_GATEWAY_HOST}:${gatewayPort}/`;
342
+ return {
343
+ running: allProcesses.length > 0 || gatewayReachable,
344
+ process_count: allProcesses.length,
345
+ processes: allProcesses.slice(0, 10),
346
+ detection_error: detectionNotes.filter(Boolean).join(" | ") || null,
347
+ gateway_url: gatewayUrl,
348
+ gateway_port: gatewayPort,
349
+ gateway_reachable: gatewayReachable,
350
+ configured_gateway_url: configuredGateway.gateway_url,
351
+ configured_gateway_port: configuredGateway.gateway_port,
352
+ configured_gateway_bind: configuredGateway.gateway_bind,
353
+ configured_gateway_config_path: configuredGateway.config_path,
354
+ detection_mode: processes.length > 0 && gatewayReachable
355
+ ? "process+gateway"
356
+ : gatewayReachable
357
+ ? "gateway"
358
+ : processes.length > 0
359
+ ? "process"
360
+ : "not_running",
361
+ };
362
+ }
363
+ function detectOpenClawSkillInstallation() {
364
+ const homeDir = (0, path_1.resolve)(process.env.HOME || "", ".openclaw");
365
+ const workspaceSkillRoot = (0, path_1.resolve)(homeDir, "workspace", "skills");
366
+ const legacySkillRoot = (0, path_1.resolve)(homeDir, "skills");
367
+ const workspaceSkillPath = (0, path_1.resolve)(workspaceSkillRoot, OPENCLAW_SKILL_NAME, "SKILL.md");
368
+ const legacySkillPath = (0, path_1.resolve)(legacySkillRoot, OPENCLAW_SKILL_NAME, "SKILL.md");
369
+ const workspaceInstalled = (0, fs_1.existsSync)(workspaceSkillPath);
370
+ const legacyInstalled = (0, fs_1.existsSync)(legacySkillPath);
371
+ return {
372
+ installed: workspaceInstalled || legacyInstalled,
373
+ install_mode: workspaceInstalled ? "workspace" : legacyInstalled ? "legacy" : "not_installed",
374
+ workspace_skill_root: workspaceSkillRoot,
375
+ legacy_skill_root: legacySkillRoot,
376
+ workspace_skill_path: workspaceInstalled ? workspaceSkillPath : null,
377
+ legacy_skill_path: legacyInstalled ? legacySkillPath : null,
378
+ };
379
+ }
380
+ function detectOwnerDeliveryStatus(params) {
381
+ const forwardCommand = String(process.env.OPENCLAW_OWNER_FORWARD_CMD || "").trim();
382
+ const ownerChannel = String(process.env.OPENCLAW_OWNER_CHANNEL || "").trim();
383
+ const ownerTarget = String(process.env.OPENCLAW_OWNER_TARGET || "").trim();
384
+ const ownerAccount = String(process.env.OPENCLAW_OWNER_ACCOUNT || "").trim();
385
+ const explicitOpenClawBin = String(process.env.OPENCLAW_BIN || "").trim();
386
+ const configuredSourceDir = String(process.env.OPENCLAW_SOURCE_DIR || "").trim();
387
+ const defaultSourceDir = (0, path_1.resolve)(params.workspaceRoot, "..", "openclaw");
388
+ const openclawSourceDir = configuredSourceDir || defaultSourceDir;
389
+ const openclawSourceEntry = existingPathOrNull((0, path_1.resolve)(openclawSourceDir, "openclaw.mjs"));
390
+ const openclawCommandResolvable = Boolean(explicitOpenClawBin || resolveExecutableInPath("openclaw") || openclawSourceEntry);
391
+ const bridgeMessagesReadable = params.connectedToSilicaclaw && params.openclawRunning && params.skillInstalled;
392
+ const forwardCommandConfigured = Boolean(forwardCommand);
393
+ const ownerRouteConfigured = Boolean(ownerChannel && ownerTarget);
394
+ const ready = bridgeMessagesReadable && forwardCommandConfigured && ownerRouteConfigured && openclawCommandResolvable;
395
+ let reason = "";
396
+ if (!params.connectedToSilicaclaw) {
397
+ reason = "SilicaClaw social bridge is not connected yet, so there is no broadcast stream for OpenClaw to learn.";
398
+ }
399
+ else if (!params.openclawRunning) {
400
+ reason = "OpenClaw is not running on this machine yet, so broadcast learning and owner forwarding are idle.";
401
+ }
402
+ else if (!params.skillInstalled) {
403
+ reason = "OpenClaw is running, but the silicaclaw-broadcast skill is not installed yet.";
404
+ }
405
+ else if (!forwardCommandConfigured) {
406
+ reason = "Broadcast learning is ready, but OPENCLAW_OWNER_FORWARD_CMD is not configured yet.";
407
+ }
408
+ else if (!ownerRouteConfigured) {
409
+ reason = "The owner forward command exists, but OPENCLAW_OWNER_CHANNEL and OPENCLAW_OWNER_TARGET are still missing.";
410
+ }
411
+ else if (!openclawCommandResolvable) {
412
+ reason = "Owner forwarding is configured, but no runnable OpenClaw CLI or source checkout was found.";
413
+ }
414
+ else {
415
+ reason = "This machine can read SilicaClaw broadcasts and route owner summaries through OpenClaw.";
416
+ }
417
+ return {
418
+ supported: bridgeMessagesReadable,
419
+ mode: "public-broadcast-via-openclaw",
420
+ send_to_owner_via_openclaw: ready,
421
+ bridge_messages_readable: bridgeMessagesReadable,
422
+ forward_command_configured: forwardCommandConfigured,
423
+ openclaw_command_resolvable: openclawCommandResolvable,
424
+ ready,
425
+ forward_command: forwardCommand || null,
426
+ owner_channel: ownerChannel || null,
427
+ owner_target: ownerTarget || null,
428
+ owner_account: ownerAccount || null,
429
+ openclaw_source_dir: openclawSourceEntry ? openclawSourceDir : null,
430
+ reason,
431
+ };
432
+ }
433
+ function hasMeaningfulJson(filePath) {
434
+ if (!(0, fs_1.existsSync)(filePath))
435
+ return false;
436
+ try {
437
+ const raw = (0, fs_1.readFileSync)(filePath, "utf8").trim();
438
+ if (!raw)
439
+ return false;
440
+ const parsed = JSON.parse(raw);
441
+ if (parsed == null)
442
+ return false;
443
+ if (Array.isArray(parsed))
444
+ return parsed.length > 0;
445
+ if (typeof parsed === "object")
446
+ return Object.keys(parsed).length > 0;
447
+ return false;
448
+ }
449
+ catch {
450
+ return false;
451
+ }
452
+ }
453
+ function migrateLegacyDataIfNeeded(workspaceRoot, storageRoot) {
454
+ const legacyDataDir = (0, path_1.resolve)(workspaceRoot, "data");
455
+ const targetDataDir = (0, path_1.resolve)(storageRoot, "data");
456
+ if (legacyDataDir === targetDataDir)
457
+ return;
458
+ const files = [
459
+ "identity.json",
460
+ "profile.json",
461
+ "cache.json",
462
+ "logs.json",
463
+ "social-messages.json",
464
+ "social-message-observations.json",
465
+ ];
466
+ for (const file of files) {
467
+ const src = (0, path_1.resolve)(legacyDataDir, file);
468
+ const dst = (0, path_1.resolve)(targetDataDir, file);
469
+ if (!(0, fs_1.existsSync)(src))
470
+ continue;
471
+ if (hasMeaningfulJson(dst))
472
+ continue;
473
+ if (!hasMeaningfulJson(src))
474
+ continue;
475
+ (0, fs_1.mkdirSync)(targetDataDir, { recursive: true });
476
+ (0, fs_1.copyFileSync)(src, dst);
477
+ }
478
+ }
479
+ function parseListEnv(raw) {
480
+ return raw
481
+ .split(/[,\n]/g)
482
+ .map((item) => item.trim())
483
+ .filter(Boolean);
484
+ }
485
+ function dedupeStrings(values) {
486
+ return Array.from(new Set(values.map((item) => item.trim()).filter(Boolean)));
487
+ }
488
+ class LocalNodeService {
489
+ workspaceRoot;
490
+ storageRoot;
491
+ identityRepo;
492
+ profileRepo;
493
+ cacheRepo;
494
+ logRepo;
495
+ socialMessageGovernanceRepo;
496
+ socialMessageRepo;
497
+ socialMessageObservationRepo;
498
+ socialRuntimeRepo;
499
+ identity = null;
500
+ profile = null;
501
+ directory = (0, core_1.createEmptyDirectoryState)();
502
+ socialMessages = [];
503
+ socialMessageObservations = [];
504
+ messageGovernance;
505
+ receivedCount = 0;
506
+ broadcastCount = 0;
507
+ lastMessageAt = 0;
508
+ lastBroadcastAt = 0;
509
+ lastBroadcastErrorAt = 0;
510
+ lastBroadcastError = null;
511
+ broadcastFailureCount = 0;
512
+ broadcaster = null;
513
+ subscriptionsBound = false;
514
+ broadcastEnabled = true;
515
+ receivedByTopic = {};
516
+ publishedByTopic = {};
517
+ outboundMessageTimestamps = [];
518
+ inboundMessageTimestampsByAgent = {};
519
+ initState = {
520
+ identity_auto_created: false,
521
+ profile_auto_created: false,
522
+ social_auto_created: false,
523
+ initialized_at: 0,
524
+ };
525
+ network;
526
+ adapterMode;
527
+ networkMode = "global-preview";
528
+ networkNamespace;
529
+ networkPort;
530
+ socialConfig;
531
+ socialSourcePath = null;
532
+ socialFound = false;
533
+ socialParseError = null;
534
+ socialRawFrontmatter = null;
535
+ socialRuntime = null;
536
+ socialNetworkRequiresRestart = false;
537
+ resolvedIdentitySource = "silicaclaw-existing";
538
+ resolvedOpenClawIdentityPath = null;
539
+ webrtcSignalingUrls = [];
540
+ webrtcRoom = "silicaclaw-global-preview";
541
+ webrtcSeedPeers = [];
542
+ webrtcBootstrapHints = [];
543
+ webrtcBootstrapSources = [];
544
+ appVersion = "unknown";
545
+ constructor(options) {
546
+ this.workspaceRoot = options?.workspaceRoot || resolveWorkspaceRoot();
547
+ this.storageRoot = options?.storageRoot || resolveStorageRoot(this.workspaceRoot);
548
+ this.appVersion = readWorkspaceVersion(this.workspaceRoot);
549
+ migrateLegacyDataIfNeeded(this.workspaceRoot, this.storageRoot);
550
+ this.identityRepo = new storage_1.IdentityRepo(this.storageRoot);
551
+ this.profileRepo = new storage_1.ProfileRepo(this.storageRoot);
552
+ this.cacheRepo = new storage_1.CacheRepo(this.storageRoot);
553
+ this.logRepo = new storage_1.LogRepo(this.storageRoot);
554
+ this.socialMessageGovernanceRepo = new storage_1.SocialMessageGovernanceRepo(this.storageRoot);
555
+ this.socialMessageRepo = new storage_1.SocialMessageRepo(this.storageRoot);
556
+ this.socialMessageObservationRepo = new storage_1.SocialMessageObservationRepo(this.storageRoot);
557
+ this.socialRuntimeRepo = new storage_1.SocialRuntimeRepo(this.storageRoot);
558
+ this.messageGovernance = this.defaultMessageGovernance();
559
+ let loadedSocial = (0, core_1.loadSocialConfig)(this.workspaceRoot);
560
+ if (!loadedSocial.meta.found) {
561
+ (0, core_1.ensureDefaultSocialMd)(this.workspaceRoot, {
562
+ display_name: this.getDefaultDisplayName(),
563
+ bio: "Local AI agent connected to SilicaClaw",
564
+ tags: ["openclaw", "local-first"],
565
+ mode: "global-preview",
566
+ public_enabled: false,
567
+ });
568
+ loadedSocial = (0, core_1.loadSocialConfig)(this.workspaceRoot);
569
+ this.initState.social_auto_created = true;
570
+ }
571
+ this.socialConfig = loadedSocial.config;
572
+ this.socialSourcePath = loadedSocial.meta.source_path;
573
+ this.socialFound = loadedSocial.meta.found;
574
+ this.socialParseError = loadedSocial.meta.parse_error;
575
+ this.socialRawFrontmatter = loadedSocial.raw_frontmatter;
576
+ this.networkNamespace = this.socialConfig.network.namespace || process.env.NETWORK_NAMESPACE || "silicaclaw.preview";
577
+ this.networkPort = Number(this.socialConfig.network.port || process.env.NETWORK_PORT || 44123);
578
+ this.applyResolvedNetworkConfig();
579
+ const resolved = this.buildNetworkAdapter();
580
+ this.network = resolved.adapter;
581
+ this.adapterMode = resolved.mode;
582
+ this.networkPort = resolved.port;
583
+ }
584
+ async start() {
585
+ await this.hydrateFromDisk();
586
+ this.bindNetworkSubscriptions();
587
+ await this.network.start();
588
+ await this.log("info", `Local node started (${this.adapterMode}, mode=${this.networkMode}, signaling=${this.webrtcSignalingUrls[0] || "-"}, room=${this.webrtcRoom})`);
589
+ if (this.profile?.public_enabled && this.broadcastEnabled) {
590
+ try {
591
+ await this.broadcastNow("adapter_start");
592
+ }
593
+ catch (error) {
594
+ await this.log("warn", `Initial broadcast failed: ${error instanceof Error ? error.message : String(error)}`);
595
+ }
596
+ }
597
+ this.startBroadcastLoop();
598
+ }
599
+ async stop() {
600
+ if (this.broadcaster) {
601
+ clearInterval(this.broadcaster);
602
+ this.broadcaster = null;
603
+ }
604
+ await this.network.stop();
605
+ }
606
+ ensureLocalDirectoryBaseline() {
607
+ if (this.profile) {
608
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, { type: "profile", profile: this.profile });
609
+ }
610
+ if (this.identity && this.profile?.public_enabled && this.broadcastEnabled) {
611
+ const currentSeenAt = this.directory.presence[this.identity.agent_id] ?? 0;
612
+ const baselineSeenAt = Math.max(currentSeenAt, this.lastBroadcastAt || Date.now());
613
+ this.directory = (0, core_1.ingestPresenceRecord)(this.directory, (0, core_1.signPresence)(this.identity, baselineSeenAt));
614
+ }
615
+ }
616
+ getOverview() {
617
+ this.ensureLocalDirectoryBaseline();
618
+ this.compactCacheInMemory();
619
+ const profiles = Object.values(this.directory.profiles);
620
+ const onlineCount = profiles.filter((profile) => (0, core_1.isAgentOnline)(this.directory.presence[profile.agent_id], Date.now(), PRESENCE_TTL_MS)).length;
621
+ return {
622
+ app_version: this.appVersion,
623
+ agent_id: this.identity?.agent_id ?? "",
624
+ public_enabled: Boolean(this.profile?.public_enabled),
625
+ broadcast_enabled: this.broadcastEnabled,
626
+ last_broadcast_at: this.lastBroadcastAt,
627
+ last_broadcast_error_at: this.lastBroadcastErrorAt,
628
+ last_broadcast_error: this.lastBroadcastError,
629
+ broadcast_failure_count: this.broadcastFailureCount,
630
+ discovered_count: profiles.length,
631
+ online_count: onlineCount,
632
+ offline_count: Math.max(0, profiles.length - onlineCount),
633
+ init_state: this.initState,
634
+ presence_ttl_ms: PRESENCE_TTL_MS,
635
+ onboarding: this.getOnboardingSummary(),
636
+ social: {
637
+ found: this.socialFound,
638
+ enabled: this.socialConfig.enabled,
639
+ source_path: this.socialSourcePath,
640
+ network_mode: this.networkMode,
641
+ mode_explainer: this.getModeExplainer(),
642
+ governance: {
643
+ send_limit: { max: this.messageGovernance.send_limit_max, window_ms: this.messageGovernance.send_window_ms },
644
+ receive_limit: { max: this.messageGovernance.receive_limit_max, window_ms: this.messageGovernance.receive_window_ms },
645
+ duplicate_window_ms: this.messageGovernance.duplicate_window_ms,
646
+ blocked_agent_count: this.messageGovernance.blocked_agent_ids.length,
647
+ blocked_term_count: this.messageGovernance.blocked_terms.length,
648
+ },
649
+ },
650
+ };
651
+ }
652
+ getNetworkSummary() {
653
+ const diagnostics = this.getAdapterDiagnostics();
654
+ const peerCount = diagnostics?.peers.total ?? 0;
655
+ return {
656
+ status: "running",
657
+ adapter: this.adapterMode,
658
+ mode: this.networkMode,
659
+ received_count: this.receivedCount,
660
+ broadcast_count: this.broadcastCount,
661
+ broadcast_failure_count: this.broadcastFailureCount,
662
+ last_message_at: this.lastMessageAt,
663
+ last_broadcast_at: this.lastBroadcastAt,
664
+ last_broadcast_error_at: this.lastBroadcastErrorAt,
665
+ last_broadcast_error: this.lastBroadcastError,
666
+ received_by_topic: this.receivedByTopic,
667
+ published_by_topic: this.publishedByTopic,
668
+ peers_discovered: peerCount,
669
+ namespace: diagnostics?.namespace ?? this.networkNamespace,
670
+ port: this.networkPort,
671
+ components: diagnostics?.components ?? {
672
+ transport: "-",
673
+ discovery: "-",
674
+ envelope_codec: "-",
675
+ topic_codec: "-",
676
+ },
677
+ real_preview_stats: diagnostics?.stats ?? null,
678
+ real_preview_transport_stats: diagnostics?.transport_stats ?? null,
679
+ real_preview_discovery_stats: diagnostics?.discovery_stats ?? null,
680
+ webrtc_preview: diagnostics && (diagnostics.adapter === "webrtc-preview" || diagnostics.adapter === "relay-preview")
681
+ ? {
682
+ signaling_url: diagnostics.signaling_url ?? null,
683
+ signaling_endpoints: diagnostics.signaling_endpoints ?? [],
684
+ room: diagnostics.room ?? null,
685
+ bootstrap_sources: diagnostics.bootstrap_sources ?? [],
686
+ seed_peers_count: diagnostics.seed_peers_count ?? 0,
687
+ discovery_events_total: diagnostics.discovery_events_total ?? 0,
688
+ last_discovery_event_at: diagnostics.last_discovery_event_at ?? 0,
689
+ active_webrtc_peers: diagnostics.active_webrtc_peers ?? 0,
690
+ reconnect_attempts_total: diagnostics.reconnect_attempts_total ?? 0,
691
+ last_join_at: diagnostics.last_join_at ?? 0,
692
+ last_poll_at: diagnostics.last_poll_at ?? 0,
693
+ last_publish_at: diagnostics.last_publish_at ?? 0,
694
+ last_peer_refresh_at: diagnostics.last_peer_refresh_at ?? 0,
695
+ last_error_at: diagnostics.last_error_at ?? 0,
696
+ last_error: diagnostics.last_error ?? null,
697
+ }
698
+ : null,
699
+ };
700
+ }
701
+ getNetworkConfig() {
702
+ const diagnostics = this.getAdapterDiagnostics();
703
+ return {
704
+ adapter: this.adapterMode,
705
+ mode: this.networkMode,
706
+ namespace: diagnostics?.namespace ?? this.networkNamespace,
707
+ port: this.networkPort,
708
+ components: diagnostics?.components ?? {
709
+ transport: "-",
710
+ discovery: "-",
711
+ envelope_codec: "-",
712
+ topic_codec: "-",
713
+ },
714
+ limits: diagnostics?.limits ?? null,
715
+ adapter_config: diagnostics?.config ?? null,
716
+ adapter_extra: diagnostics && (diagnostics.adapter === "webrtc-preview" || diagnostics.adapter === "relay-preview")
717
+ ? {
718
+ signaling_url: diagnostics.signaling_url ?? null,
719
+ signaling_endpoints: diagnostics.signaling_endpoints ?? [],
720
+ room: diagnostics.room ?? null,
721
+ bootstrap_sources: diagnostics.bootstrap_sources ?? [],
722
+ seed_peers_count: diagnostics.seed_peers_count ?? 0,
723
+ discovery_events_total: diagnostics.discovery_events_total ?? 0,
724
+ last_discovery_event_at: diagnostics.last_discovery_event_at ?? 0,
725
+ connection_states_summary: diagnostics.connection_states_summary ?? null,
726
+ datachannel_states_summary: diagnostics.datachannel_states_summary ?? null,
727
+ last_join_at: diagnostics.last_join_at ?? 0,
728
+ last_poll_at: diagnostics.last_poll_at ?? 0,
729
+ last_publish_at: diagnostics.last_publish_at ?? 0,
730
+ last_peer_refresh_at: diagnostics.last_peer_refresh_at ?? 0,
731
+ last_error_at: diagnostics.last_error_at ?? 0,
732
+ last_error: diagnostics.last_error ?? null,
733
+ }
734
+ : null,
735
+ env: {
736
+ NETWORK_ADAPTER: this.adapterMode,
737
+ NETWORK_NAMESPACE: this.networkNamespace,
738
+ NETWORK_PORT: this.networkPort,
739
+ NETWORK_MAX_MESSAGE_BYTES,
740
+ NETWORK_DEDUPE_WINDOW_MS,
741
+ NETWORK_DEDUPE_MAX_ENTRIES,
742
+ NETWORK_MAX_FUTURE_DRIFT_MS,
743
+ NETWORK_MAX_PAST_DRIFT_MS,
744
+ NETWORK_HEARTBEAT_INTERVAL_MS,
745
+ NETWORK_PEER_STALE_AFTER_MS,
746
+ NETWORK_PEER_REMOVE_AFTER_MS,
747
+ NETWORK_UDP_BIND_ADDRESS,
748
+ NETWORK_UDP_BROADCAST_ADDRESS,
749
+ NETWORK_PEER_ID: NETWORK_PEER_ID ?? null,
750
+ WEBRTC_SIGNALING_URLS,
751
+ WEBRTC_SIGNALING_URL,
752
+ WEBRTC_ROOM,
753
+ WEBRTC_SEED_PEERS,
754
+ WEBRTC_BOOTSTRAP_HINTS,
755
+ },
756
+ demo_mode: this.adapterMode === "real-preview"
757
+ ? "lan-preview"
758
+ : this.adapterMode === "webrtc-preview" || this.adapterMode === "relay-preview"
759
+ ? "internet-preview"
760
+ : "local-process",
761
+ mode_explainer: this.getModeExplainer(),
762
+ };
763
+ }
764
+ getNetworkStats() {
765
+ const diagnostics = this.getAdapterDiagnostics();
766
+ const peers = diagnostics?.peers?.items ?? [];
767
+ const online = peers.filter((peer) => peer.status === "online").length;
768
+ return {
769
+ adapter: this.adapterMode,
770
+ mode: this.networkMode,
771
+ message_counters: {
772
+ received_total: this.receivedCount,
773
+ broadcast_total: this.broadcastCount,
774
+ broadcast_failures_total: this.broadcastFailureCount,
775
+ last_message_at: this.lastMessageAt,
776
+ last_broadcast_at: this.lastBroadcastAt,
777
+ last_broadcast_error_at: this.lastBroadcastErrorAt,
778
+ last_broadcast_error: this.lastBroadcastError,
779
+ received_by_topic: this.receivedByTopic,
780
+ published_by_topic: this.publishedByTopic,
781
+ },
782
+ peer_counters: {
783
+ total: peers.length,
784
+ online,
785
+ stale: Math.max(0, peers.length - online),
786
+ },
787
+ adapter_config: diagnostics?.config ?? null,
788
+ adapter_stats: diagnostics?.stats ?? null,
789
+ adapter_transport_stats: diagnostics?.transport_stats ?? null,
790
+ adapter_discovery_stats: diagnostics?.discovery_stats ?? null,
791
+ adapter_diagnostics_summary: diagnostics
792
+ ? {
793
+ signaling_url: diagnostics.signaling_url ?? null,
794
+ signaling_endpoints: diagnostics.signaling_endpoints ?? [],
795
+ room: diagnostics.room ?? null,
796
+ bootstrap_sources: diagnostics.bootstrap_sources ?? [],
797
+ seed_peers_count: diagnostics.seed_peers_count ?? 0,
798
+ discovery_events_total: diagnostics.discovery_events_total ?? 0,
799
+ last_discovery_event_at: diagnostics.last_discovery_event_at ?? 0,
800
+ connection_states_summary: diagnostics.connection_states_summary ?? null,
801
+ datachannel_states_summary: diagnostics.datachannel_states_summary ?? null,
802
+ signaling_messages_sent_total: diagnostics.signaling_messages_sent_total ?? null,
803
+ signaling_messages_received_total: diagnostics.signaling_messages_received_total ?? null,
804
+ reconnect_attempts_total: diagnostics.reconnect_attempts_total ?? null,
805
+ active_webrtc_peers: diagnostics.active_webrtc_peers ?? null,
806
+ last_join_at: diagnostics.last_join_at ?? 0,
807
+ last_poll_at: diagnostics.last_poll_at ?? 0,
808
+ last_publish_at: diagnostics.last_publish_at ?? 0,
809
+ last_peer_refresh_at: diagnostics.last_peer_refresh_at ?? 0,
810
+ last_error_at: diagnostics.last_error_at ?? 0,
811
+ last_error: diagnostics.last_error ?? null,
812
+ }
813
+ : null,
814
+ };
815
+ }
816
+ getPeersSummary() {
817
+ const diagnostics = this.getAdapterDiagnostics();
818
+ if (!diagnostics) {
819
+ return {
820
+ adapter: this.adapterMode,
821
+ namespace: this.networkNamespace,
822
+ total: 0,
823
+ online: 0,
824
+ stale: 0,
825
+ items: [],
826
+ stats: null,
827
+ };
828
+ }
829
+ return {
830
+ adapter: diagnostics.adapter,
831
+ namespace: diagnostics.namespace,
832
+ total: diagnostics.peers.total,
833
+ online: diagnostics.peers.online,
834
+ stale: diagnostics.peers.stale,
835
+ items: diagnostics.peers.items,
836
+ stats: diagnostics.stats,
837
+ components: diagnostics.components,
838
+ limits: diagnostics.limits,
839
+ diagnostics_summary: {
840
+ signaling_url: diagnostics.signaling_url ?? null,
841
+ signaling_endpoints: diagnostics.signaling_endpoints ?? [],
842
+ room: diagnostics.room ?? null,
843
+ bootstrap_sources: diagnostics.bootstrap_sources ?? [],
844
+ seed_peers_count: diagnostics.seed_peers_count ?? 0,
845
+ discovery_events_total: diagnostics.discovery_events_total ?? 0,
846
+ last_discovery_event_at: diagnostics.last_discovery_event_at ?? 0,
847
+ connection_states_summary: diagnostics.connection_states_summary ?? null,
848
+ datachannel_states_summary: diagnostics.datachannel_states_summary ?? null,
849
+ active_webrtc_peers: diagnostics.active_webrtc_peers ?? null,
850
+ last_join_at: diagnostics.last_join_at ?? 0,
851
+ last_poll_at: diagnostics.last_poll_at ?? 0,
852
+ last_publish_at: diagnostics.last_publish_at ?? 0,
853
+ last_peer_refresh_at: diagnostics.last_peer_refresh_at ?? 0,
854
+ last_error_at: diagnostics.last_error_at ?? 0,
855
+ last_error: diagnostics.last_error ?? null,
856
+ },
857
+ };
858
+ }
859
+ getDiscoveryEvents() {
860
+ const diagnostics = this.getAdapterDiagnostics();
861
+ return {
862
+ adapter: this.adapterMode,
863
+ mode: this.networkMode,
864
+ namespace: diagnostics?.namespace ?? this.networkNamespace,
865
+ total: diagnostics?.discovery_events_total ?? 0,
866
+ last_event_at: diagnostics?.last_discovery_event_at ?? 0,
867
+ items: Array.isArray(diagnostics?.discovery_events) ? diagnostics.discovery_events : [],
868
+ bootstrap_sources: diagnostics?.bootstrap_sources ?? this.webrtcBootstrapSources,
869
+ signaling_endpoints: diagnostics?.signaling_endpoints ?? this.webrtcSignalingUrls,
870
+ seed_peers_count: diagnostics?.seed_peers_count ?? this.webrtcSeedPeers.length,
871
+ };
872
+ }
873
+ getSocialConfigView() {
874
+ return {
875
+ found: this.socialFound,
876
+ source_path: this.socialSourcePath,
877
+ parse_error: this.socialParseError,
878
+ network_requires_restart: this.socialNetworkRequiresRestart,
879
+ social_config: this.socialConfig,
880
+ raw_frontmatter: this.socialRawFrontmatter,
881
+ runtime: this.socialRuntime,
882
+ init_state: this.initState,
883
+ };
884
+ }
885
+ getRuntimePaths() {
886
+ return {
887
+ workspace_root: this.workspaceRoot,
888
+ storage_root: this.storageRoot,
889
+ data_dir: (0, path_1.resolve)(this.storageRoot, "data"),
890
+ social_runtime_path: (0, path_1.resolve)(this.storageRoot, ".silicaclaw", "social.runtime.json"),
891
+ local_console_public_dir: (0, path_1.resolve)(this.workspaceRoot, "apps", "local-console", "public"),
892
+ social_lookup_paths: (0, core_1.getSocialConfigSearchPaths)(this.workspaceRoot),
893
+ social_source_path: this.socialSourcePath,
894
+ };
895
+ }
896
+ getIntegrationSummary() {
897
+ const status = this.getIntegrationStatus();
898
+ const runtimeGenerated = Boolean(this.socialRuntime && this.socialRuntime.last_loaded_at > 0);
899
+ const identitySource = this.socialRuntime?.resolved_identity?.source ?? this.resolvedIdentitySource;
900
+ return {
901
+ connected: status.connected_to_silicaclaw,
902
+ discoverable: status.discoverable,
903
+ summary_line: status.status_line,
904
+ social_md_found: this.socialFound,
905
+ social_md_source_path: this.socialSourcePath,
906
+ runtime_generated: runtimeGenerated,
907
+ reused_openclaw_identity: identitySource === "openclaw-existing",
908
+ openclaw_identity_source_path: this.resolvedOpenClawIdentityPath,
909
+ current_public_enabled: status.public_enabled,
910
+ current_network_mode: status.network_mode,
911
+ current_adapter: this.adapterMode,
912
+ current_namespace: this.networkNamespace,
913
+ current_broadcast_status: this.broadcastEnabled ? "running" : "paused",
914
+ configured_enabled: this.socialConfig.enabled,
915
+ configured_public_enabled: this.socialConfig.public_enabled,
916
+ configured_discoverable: this.socialConfig.discovery.discoverable,
917
+ configured: status.configured,
918
+ running: status.running,
919
+ configured_reason: status.configured_reason,
920
+ running_reason: status.running_reason,
921
+ discoverable_reason: status.discoverable_reason,
922
+ agent_id: status.agent_id,
923
+ display_name: status.display_name,
924
+ };
925
+ }
926
+ getIntegrationStatus() {
927
+ const runtimeGenerated = Boolean(this.socialRuntime && this.socialRuntime.last_loaded_at > 0);
928
+ const connected = this.socialFound && runtimeGenerated && !this.socialParseError;
929
+ const configured = connected && this.socialConfig.enabled;
930
+ const running = configured && this.broadcastEnabled;
931
+ const publicEnabled = Boolean(this.profile?.public_enabled);
932
+ const discoveryEnabled = this.socialConfig.discovery.discoverable &&
933
+ this.socialConfig.discovery.allow_profile_broadcast &&
934
+ this.socialConfig.discovery.allow_presence_broadcast;
935
+ const discoverable = running && publicEnabled && discoveryEnabled;
936
+ const configuredReason = configured
937
+ ? "configured"
938
+ : !this.socialFound
939
+ ? "social.md not found"
940
+ : this.socialParseError
941
+ ? "social.md parse error"
942
+ : !this.socialConfig.enabled
943
+ ? "integration disabled"
944
+ : "runtime not ready";
945
+ const runningReason = running
946
+ ? "running"
947
+ : !configured
948
+ ? "not configured"
949
+ : !this.broadcastEnabled
950
+ ? "broadcast paused"
951
+ : "not running";
952
+ const discoverableReason = discoverable
953
+ ? "discoverable"
954
+ : !running
955
+ ? "not running"
956
+ : !publicEnabled
957
+ ? "Public discovery is disabled"
958
+ : !this.socialConfig.discovery.discoverable
959
+ ? "discovery disabled"
960
+ : !this.socialConfig.discovery.allow_profile_broadcast
961
+ ? "profile broadcast disabled"
962
+ : !this.socialConfig.discovery.allow_presence_broadcast
963
+ ? "presence broadcast disabled"
964
+ : "not discoverable";
965
+ return {
966
+ configured,
967
+ running,
968
+ discoverable,
969
+ network_mode: this.networkMode,
970
+ public_enabled: publicEnabled,
971
+ agent_id: this.identity?.agent_id ?? "",
972
+ display_name: this.profile?.display_name ?? "",
973
+ connected_to_silicaclaw: connected,
974
+ configured_reason: configuredReason,
975
+ running_reason: runningReason,
976
+ discoverable_reason: discoverableReason,
977
+ status_line: `${connected ? "Connected to SilicaClaw" : "Not connected to SilicaClaw"} · ${publicEnabled ? "Public discovery enabled" : "Public discovery disabled"} · Using ${this.networkMode}`,
978
+ };
979
+ }
980
+ async setPublicDiscoveryRuntime(enabled) {
981
+ const profile = await this.updateProfile({ public_enabled: enabled });
982
+ this.socialConfig.public_enabled = enabled;
983
+ await this.writeSocialRuntime();
984
+ return {
985
+ public_enabled: profile.public_enabled,
986
+ note: "Runtime public discovery updated. Existing social.md is unchanged.",
987
+ };
988
+ }
989
+ async setNetworkModeRuntime(mode) {
990
+ const currentMode = this.networkMode;
991
+ if (mode !== "local" && mode !== "lan" && mode !== "global-preview") {
992
+ throw new Error("invalid_network_mode");
993
+ }
994
+ this.socialConfig.network.mode = mode;
995
+ this.socialConfig.network.adapter = this.adapterForMode(mode);
996
+ this.applyResolvedNetworkConfig();
997
+ this.socialNetworkRequiresRestart = currentMode !== mode || this.adapterMode !== this.socialConfig.network.adapter;
998
+ await this.writeSocialRuntime();
999
+ return {
1000
+ mode: this.networkMode,
1001
+ adapter: this.socialConfig.network.adapter,
1002
+ network_requires_restart: this.socialNetworkRequiresRestart,
1003
+ note: "Runtime mode updated. Existing social.md is unchanged.",
1004
+ };
1005
+ }
1006
+ async quickConnectGlobalPreview(options) {
1007
+ const signalingUrl = String(options?.signaling_url || "").trim();
1008
+ const room = String(options?.room || "").trim();
1009
+ if (!signalingUrl) {
1010
+ throw new Error("missing_signaling_url");
1011
+ }
1012
+ this.socialConfig.network.mode = "global-preview";
1013
+ this.socialConfig.network.adapter = "relay-preview";
1014
+ this.socialConfig.network.signaling_url = signalingUrl;
1015
+ this.socialConfig.network.signaling_urls = [signalingUrl];
1016
+ this.socialConfig.network.room = room || "silicaclaw-global-preview";
1017
+ this.applyResolvedNetworkConfig();
1018
+ await this.restartNetworkAdapter("quick_connect_global_preview");
1019
+ this.socialNetworkRequiresRestart = false;
1020
+ await this.writeSocialRuntime();
1021
+ await this.log("info", `Quick connect enabled (relay-preview, room=${this.webrtcRoom})`);
1022
+ return {
1023
+ mode: this.networkMode,
1024
+ adapter: this.adapterMode,
1025
+ signaling_url: this.webrtcSignalingUrls[0] ?? null,
1026
+ room: this.webrtcRoom,
1027
+ network_requires_restart: false,
1028
+ note: "Cross-network preview enabled.",
1029
+ };
1030
+ }
1031
+ async reloadSocialConfig() {
1032
+ const before = {
1033
+ mode: this.networkMode,
1034
+ adapter: this.adapterMode,
1035
+ namespace: this.networkNamespace,
1036
+ port: this.networkPort,
1037
+ };
1038
+ const loaded = (0, core_1.loadSocialConfig)(this.workspaceRoot);
1039
+ this.socialConfig = loaded.config;
1040
+ this.socialSourcePath = loaded.meta.source_path;
1041
+ this.socialFound = loaded.meta.found;
1042
+ this.socialParseError = loaded.meta.parse_error;
1043
+ this.socialRawFrontmatter = loaded.raw_frontmatter;
1044
+ this.applyResolvedNetworkConfig();
1045
+ await this.applySocialConfigOnCurrentState();
1046
+ const after = {
1047
+ mode: this.networkMode,
1048
+ adapter: this.socialConfig.network.adapter,
1049
+ namespace: this.networkNamespace,
1050
+ port: this.networkPort,
1051
+ };
1052
+ this.socialNetworkRequiresRestart =
1053
+ before.mode !== after.mode ||
1054
+ before.adapter !== after.adapter ||
1055
+ before.namespace !== after.namespace ||
1056
+ (before.port ?? null) !== (after.port ?? null);
1057
+ await this.writeSocialRuntime();
1058
+ return this.getSocialConfigView();
1059
+ }
1060
+ async generateDefaultSocialMd() {
1061
+ const result = (0, core_1.ensureDefaultSocialMd)(this.workspaceRoot, {
1062
+ display_name: this.getDefaultDisplayName(),
1063
+ bio: "Local AI agent connected to SilicaClaw",
1064
+ tags: ["openclaw", "local-first"],
1065
+ mode: this.networkMode,
1066
+ public_enabled: Boolean(this.profile?.public_enabled),
1067
+ });
1068
+ await this.reloadSocialConfig();
1069
+ return result;
1070
+ }
1071
+ exportSocialTemplate() {
1072
+ return {
1073
+ filename: "social.md",
1074
+ content: (0, core_1.generateSocialMdTemplate)(this.socialRuntime),
1075
+ };
1076
+ }
1077
+ getDirectory() {
1078
+ this.ensureLocalDirectoryBaseline();
1079
+ this.compactCacheInMemory();
1080
+ return this.directory;
1081
+ }
1082
+ search(keyword) {
1083
+ this.ensureLocalDirectoryBaseline();
1084
+ this.compactCacheInMemory();
1085
+ return (0, core_1.searchDirectory)(this.directory, keyword, { presenceTTLms: PRESENCE_TTL_MS }).map((profile) => {
1086
+ const lastSeenAt = this.directory.presence[profile.agent_id] ?? 0;
1087
+ return this.toPublicProfileSummary(profile, { last_seen_at: lastSeenAt });
1088
+ });
1089
+ }
1090
+ getPublicProfilePreview() {
1091
+ if (!this.profile) {
1092
+ return null;
1093
+ }
1094
+ const lastSeenAt = this.directory.presence[this.profile.agent_id] ?? 0;
1095
+ return this.toPublicProfileSummary(this.profile, { last_seen_at: lastSeenAt });
1096
+ }
1097
+ getAgentPublicSummary(agentId) {
1098
+ const profile = this.directory.profiles[agentId];
1099
+ if (!profile) {
1100
+ return null;
1101
+ }
1102
+ const lastSeenAt = this.directory.presence[agentId] ?? 0;
1103
+ return this.toPublicProfileSummary(profile, { last_seen_at: lastSeenAt });
1104
+ }
1105
+ getProfile() {
1106
+ return this.profile;
1107
+ }
1108
+ getIdentity() {
1109
+ return this.identity;
1110
+ }
1111
+ getSocialMessages(limit = 50, options) {
1112
+ const resolvedLimit = Math.max(1, Math.min(200, Number(limit) || 50));
1113
+ this.ensureLocalDirectoryBaseline();
1114
+ this.compactCacheInMemory();
1115
+ const agentId = String(options?.agent_id || "").trim();
1116
+ const filtered = agentId
1117
+ ? this.socialMessages.filter((message) => message.agent_id === agentId)
1118
+ : this.socialMessages;
1119
+ return {
1120
+ total: filtered.length,
1121
+ items: filtered.slice(0, resolvedLimit).map((message) => {
1122
+ const profile = this.directory.profiles[message.agent_id];
1123
+ const lastSeenAt = this.directory.presence[message.agent_id] ?? 0;
1124
+ const observations = this.socialMessageObservations.filter((item) => item.message_id === message.message_id);
1125
+ const remoteObservationCount = observations.filter((item) => item.observer_agent_id !== message.agent_id).length;
1126
+ const lastObservedAt = observations.length > 0 ? Math.max(...observations.map((item) => item.observed_at)) : 0;
1127
+ return {
1128
+ ...message,
1129
+ display_name: profile?.display_name || message.display_name || "Unnamed",
1130
+ is_self: message.agent_id === this.identity?.agent_id,
1131
+ online: (0, core_1.isAgentOnline)(lastSeenAt, Date.now(), PRESENCE_TTL_MS),
1132
+ last_seen_at: lastSeenAt || null,
1133
+ observation_count: observations.length,
1134
+ remote_observation_count: remoteObservationCount,
1135
+ last_observed_at: lastObservedAt || null,
1136
+ delivery_status: remoteObservationCount > 0 ? "remote-observed" : "local-only",
1137
+ };
1138
+ }),
1139
+ governance: {
1140
+ send_limit: { max: this.messageGovernance.send_limit_max, window_ms: this.messageGovernance.send_window_ms },
1141
+ receive_limit: { max: this.messageGovernance.receive_limit_max, window_ms: this.messageGovernance.receive_window_ms },
1142
+ duplicate_window_ms: this.messageGovernance.duplicate_window_ms,
1143
+ blocked_agent_count: this.messageGovernance.blocked_agent_ids.length,
1144
+ blocked_term_count: this.messageGovernance.blocked_terms.length,
1145
+ },
1146
+ };
1147
+ }
1148
+ getOpenClawBridgeStatus() {
1149
+ const integration = this.getIntegrationStatus();
1150
+ const openclawInstallation = detectOpenClawInstallation(this.workspaceRoot);
1151
+ const openclawRuntime = detectOpenClawRuntime(this.workspaceRoot);
1152
+ const skillInstallation = detectOpenClawSkillInstallation();
1153
+ const ownerDelivery = detectOwnerDeliveryStatus({
1154
+ workspaceRoot: this.workspaceRoot,
1155
+ connectedToSilicaclaw: integration.connected_to_silicaclaw,
1156
+ openclawRunning: openclawRuntime.running,
1157
+ skillInstalled: skillInstallation.installed,
1158
+ });
1159
+ return {
1160
+ enabled: this.socialConfig.enabled,
1161
+ connected_to_silicaclaw: integration.connected_to_silicaclaw,
1162
+ public_enabled: integration.public_enabled,
1163
+ message_broadcast_enabled: this.socialConfig.discovery.allow_message_broadcast && this.broadcastEnabled,
1164
+ network_mode: this.networkMode,
1165
+ adapter: this.adapterMode,
1166
+ agent_id: this.identity?.agent_id ?? "",
1167
+ display_name: this.profile?.display_name ?? "",
1168
+ identity_source: this.resolvedIdentitySource,
1169
+ openclaw_identity_source_path: this.resolvedOpenClawIdentityPath,
1170
+ social_source_path: this.socialSourcePath,
1171
+ openclaw_installation: openclawInstallation,
1172
+ openclaw_runtime: openclawRuntime,
1173
+ skill_learning: {
1174
+ available: integration.connected_to_silicaclaw && openclawRuntime.running,
1175
+ installed: skillInstallation.installed,
1176
+ install_mode: skillInstallation.install_mode,
1177
+ installed_skill_path: skillInstallation.workspace_skill_path || skillInstallation.legacy_skill_path,
1178
+ install_action: {
1179
+ supported: true,
1180
+ endpoint: "/api/openclaw/bridge/skill-install",
1181
+ recommended_command: "silicaclaw openclaw-skill-install",
1182
+ },
1183
+ skills: [
1184
+ {
1185
+ key: "get_profile",
1186
+ summary: "Read SilicaClaw identity/profile so OpenClaw can align its runtime persona.",
1187
+ endpoint: "/api/openclaw/bridge/profile",
1188
+ },
1189
+ {
1190
+ key: "list_messages",
1191
+ summary: "Read recent public broadcast messages observed by this SilicaClaw node.",
1192
+ endpoint: "/api/openclaw/bridge/messages",
1193
+ },
1194
+ {
1195
+ key: "watch_messages",
1196
+ summary: "Poll the recent broadcast feed so OpenClaw can learn from new public messages.",
1197
+ endpoint: "/api/openclaw/bridge/messages",
1198
+ },
1199
+ {
1200
+ key: "send_message",
1201
+ summary: "Publish a signed public broadcast through SilicaClaw on behalf of OpenClaw.",
1202
+ endpoint: "/api/openclaw/bridge/message",
1203
+ },
1204
+ ],
1205
+ },
1206
+ owner_delivery: ownerDelivery,
1207
+ endpoints: {
1208
+ status: "/api/openclaw/bridge",
1209
+ profile: "/api/openclaw/bridge/profile",
1210
+ messages: "/api/openclaw/bridge/messages",
1211
+ send_message: "/api/openclaw/bridge/message",
1212
+ install_skill: "/api/openclaw/bridge/skill-install",
1213
+ },
1214
+ };
1215
+ }
1216
+ async installOpenClawSkill() {
1217
+ const scriptPath = (0, path_1.resolve)(this.workspaceRoot, "scripts", "install-openclaw-skill.mjs");
1218
+ const { stdout } = await execFileAsync(process.execPath, [scriptPath], {
1219
+ cwd: this.workspaceRoot,
1220
+ env: process.env,
1221
+ maxBuffer: 1024 * 1024,
1222
+ });
1223
+ const parsed = JSON.parse(String(stdout || "{}"));
1224
+ return {
1225
+ ...parsed,
1226
+ bridge: this.getOpenClawBridgeStatus(),
1227
+ };
1228
+ }
1229
+ getOpenClawBridgeProfile() {
1230
+ return {
1231
+ identity: this.getIdentity(),
1232
+ profile: this.getProfile(),
1233
+ public_profile_preview: this.getPublicProfilePreview(),
1234
+ integration: this.getIntegrationSummary(),
1235
+ bridge: this.getOpenClawBridgeStatus(),
1236
+ };
1237
+ }
1238
+ getOpenClawBridgeConfig() {
1239
+ const homeDir = (0, path_1.resolve)(process.env.HOME || "", ".openclaw");
1240
+ const workspaceSkillDir = (0, path_1.resolve)(homeDir, "workspace", "skills");
1241
+ const legacySkillDir = (0, path_1.resolve)(homeDir, "skills");
1242
+ const openclawSourceDir = (0, path_1.resolve)(this.workspaceRoot, "..", "openclaw");
1243
+ const openclawRuntime = detectOpenClawRuntime(this.workspaceRoot);
1244
+ return {
1245
+ bridge_api_base: "http://localhost:4310",
1246
+ openclaw_detected: detectOpenClawInstallation(this.workspaceRoot).detected,
1247
+ openclaw_running: openclawRuntime.running,
1248
+ openclaw_gateway_host: OPENCLAW_GATEWAY_HOST,
1249
+ openclaw_gateway_port: openclawRuntime.configured_gateway_port,
1250
+ openclaw_gateway_url: openclawRuntime.configured_gateway_url,
1251
+ openclaw_gateway_config_path: openclawRuntime.configured_gateway_config_path,
1252
+ openclaw_workspace_skill_dir: workspaceSkillDir,
1253
+ openclaw_legacy_skill_dir: legacySkillDir,
1254
+ silicaclaw_env_template_path: (0, path_1.resolve)(this.workspaceRoot, "openclaw-owner-forward.env.example"),
1255
+ recommended_skill_name: "silicaclaw-broadcast",
1256
+ recommended_install_command: "silicaclaw openclaw-skill-install",
1257
+ recommended_owner_forward_env: {
1258
+ OPENCLAW_SOURCE_DIR: openclawSourceDir,
1259
+ OPENCLAW_OWNER_CHANNEL: "<channel>",
1260
+ OPENCLAW_OWNER_TARGET: "<target>",
1261
+ OPENCLAW_OWNER_ACCOUNT: "",
1262
+ OPENCLAW_OWNER_FORWARD_CMD: "node scripts/send-to-owner-via-openclaw.mjs",
1263
+ },
1264
+ owner_forward_command_example: [
1265
+ `OPENCLAW_SOURCE_DIR='${openclawSourceDir}'`,
1266
+ "OPENCLAW_OWNER_CHANNEL='<channel>'",
1267
+ "OPENCLAW_OWNER_TARGET='<target>'",
1268
+ "OPENCLAW_OWNER_FORWARD_CMD='node scripts/send-to-owner-via-openclaw.mjs'",
1269
+ "node scripts/owner-forwarder-demo.mjs",
1270
+ ].join(" "),
1271
+ notes: [
1272
+ "Install and maintain the skill from SilicaClaw; do not edit OpenClaw core source for this integration.",
1273
+ "OpenClaw learns broadcasts via the installed skill under ~/.openclaw/workspace/skills/.",
1274
+ "Runtime detection prefers the actual OpenClaw gateway listener port, then falls back to OpenClaw's own openclaw.json gateway.port.",
1275
+ "Owner delivery runs through OpenClaw's own message channel stack after the skill forwards a summary.",
1276
+ "Sensitive computer control still requires OpenClaw's own owner approval and node permission flow.",
1277
+ ],
1278
+ };
1279
+ }
1280
+ getSkillsView() {
1281
+ const bundledRoot = (0, path_1.resolve)(this.workspaceRoot, "openclaw-skills");
1282
+ const openclawHome = (0, path_1.resolve)(process.env.HOME || "", ".openclaw");
1283
+ const workspaceInstallRoot = (0, path_1.resolve)(openclawHome, "workspace", "skills");
1284
+ const legacyInstallRoot = (0, path_1.resolve)(openclawHome, "skills");
1285
+ const bridge = this.getOpenClawBridgeStatus();
1286
+ const bundledSkills = listDirectories(bundledRoot).map((dir) => {
1287
+ const manifestPath = (0, path_1.resolve)(dir.path, "manifest.json");
1288
+ const skillPath = (0, path_1.resolve)(dir.path, "SKILL.md");
1289
+ const versionPath = (0, path_1.resolve)(dir.path, "VERSION");
1290
+ const manifest = readJsonFileSafe(manifestPath);
1291
+ const name = String(manifest?.name || dir.name);
1292
+ const capabilities = Array.isArray(manifest?.capabilities)
1293
+ ? manifest.capabilities.map((item) => String(item))
1294
+ : [];
1295
+ const installedWorkspacePath = (0, path_1.resolve)(workspaceInstallRoot, name);
1296
+ const installedLegacyPath = (0, path_1.resolve)(legacyInstallRoot, name);
1297
+ const installedInWorkspace = (0, fs_1.existsSync)(installedWorkspacePath);
1298
+ const installedInLegacy = (0, fs_1.existsSync)(installedLegacyPath);
1299
+ return {
1300
+ key: name,
1301
+ name,
1302
+ display_name: String(manifest?.display_name || name),
1303
+ description: String(manifest?.description || summarizeSkillReadme(skillPath) || ""),
1304
+ version: (0, fs_1.existsSync)(versionPath) ? (0, fs_1.readFileSync)(versionPath, "utf8").trim() : String(manifest?.version || ""),
1305
+ source_path: dir.path,
1306
+ manifest_path: (0, fs_1.existsSync)(manifestPath) ? manifestPath : null,
1307
+ skill_path: (0, fs_1.existsSync)(skillPath) ? skillPath : null,
1308
+ capabilities,
1309
+ transport: manifest?.transport || null,
1310
+ installed_in_openclaw: installedInWorkspace || installedInLegacy,
1311
+ install_mode: installedInWorkspace ? "workspace" : installedInLegacy ? "legacy" : "not_installed",
1312
+ installed_path: installedInWorkspace ? installedWorkspacePath : installedInLegacy ? installedLegacyPath : null,
1313
+ };
1314
+ });
1315
+ const installedSkills = [
1316
+ ...listDirectories(workspaceInstallRoot).map((dir) => ({ ...dir, install_mode: "workspace" })),
1317
+ ...listDirectories(legacyInstallRoot).map((dir) => ({ ...dir, install_mode: "legacy" })),
1318
+ ].map((dir) => {
1319
+ const manifestPath = (0, path_1.resolve)(dir.path, "manifest.json");
1320
+ const skillPath = (0, path_1.resolve)(dir.path, "SKILL.md");
1321
+ const versionPath = (0, path_1.resolve)(dir.path, "VERSION");
1322
+ const manifest = readJsonFileSafe(manifestPath);
1323
+ return {
1324
+ key: `${dir.install_mode}:${dir.name}`,
1325
+ name: String(manifest?.name || dir.name),
1326
+ display_name: String(manifest?.display_name || dir.name),
1327
+ description: String(manifest?.description || summarizeSkillReadme(skillPath) || ""),
1328
+ version: (0, fs_1.existsSync)(versionPath) ? (0, fs_1.readFileSync)(versionPath, "utf8").trim() : String(manifest?.version || ""),
1329
+ install_mode: dir.install_mode,
1330
+ installed_path: dir.path,
1331
+ manifest_path: (0, fs_1.existsSync)(manifestPath) ? manifestPath : null,
1332
+ skill_path: (0, fs_1.existsSync)(skillPath) ? skillPath : null,
1333
+ capabilities: Array.isArray(manifest?.capabilities) ? manifest.capabilities.map((item) => String(item)) : [],
1334
+ bundled_source_path: bundledSkills.find((item) => item.name === String(manifest?.name || dir.name))?.source_path || null,
1335
+ };
1336
+ });
1337
+ return {
1338
+ openclaw: {
1339
+ detected: bridge.openclaw_installation.detected,
1340
+ running: bridge.openclaw_runtime.running,
1341
+ detection_mode: bridge.openclaw_runtime.detection_mode,
1342
+ gateway_url: bridge.openclaw_runtime.gateway_url,
1343
+ workspace_install_root: workspaceInstallRoot,
1344
+ legacy_install_root: legacyInstallRoot,
1345
+ },
1346
+ summary: {
1347
+ bundled_count: bundledSkills.length,
1348
+ installed_count: installedSkills.length,
1349
+ installed_bundled_count: bundledSkills.filter((item) => item.installed_in_openclaw).length,
1350
+ },
1351
+ install_action: bridge.skill_learning.install_action,
1352
+ bundled_skills: bundledSkills,
1353
+ installed_skills: installedSkills,
1354
+ };
1355
+ }
1356
+ getRuntimeMessageGovernance() {
1357
+ return this.messageGovernance;
1358
+ }
1359
+ async getMessageGovernanceView() {
1360
+ const logs = await this.logRepo.get();
1361
+ const recentEvents = logs
1362
+ .filter((entry) => (entry.message.includes("Rejected social message") ||
1363
+ entry.message.includes("Social message blocked") ||
1364
+ entry.message.includes("Social message throttled")))
1365
+ .slice(0, 20);
1366
+ return {
1367
+ policy: {
1368
+ send_limit: { max: this.messageGovernance.send_limit_max, window_ms: this.messageGovernance.send_window_ms },
1369
+ receive_limit: { max: this.messageGovernance.receive_limit_max, window_ms: this.messageGovernance.receive_window_ms },
1370
+ duplicate_window_ms: this.messageGovernance.duplicate_window_ms,
1371
+ blocked_agent_ids: Array.from(this.messageGovernance.blocked_agent_ids),
1372
+ blocked_terms: Array.from(this.messageGovernance.blocked_terms),
1373
+ },
1374
+ recent_events: recentEvents,
1375
+ };
1376
+ }
1377
+ async updateMessageGovernance(input) {
1378
+ const next = {
1379
+ send_limit_max: Math.max(1, Math.min(100, Number(input.send_limit_max ?? this.messageGovernance.send_limit_max) || this.messageGovernance.send_limit_max)),
1380
+ send_window_ms: Math.max(5_000, Math.min(3_600_000, Number(input.send_window_ms ?? this.messageGovernance.send_window_ms) || this.messageGovernance.send_window_ms)),
1381
+ receive_limit_max: Math.max(1, Math.min(200, Number(input.receive_limit_max ?? this.messageGovernance.receive_limit_max) || this.messageGovernance.receive_limit_max)),
1382
+ receive_window_ms: Math.max(5_000, Math.min(3_600_000, Number(input.receive_window_ms ?? this.messageGovernance.receive_window_ms) || this.messageGovernance.receive_window_ms)),
1383
+ duplicate_window_ms: Math.max(5_000, Math.min(3_600_000, Number(input.duplicate_window_ms ?? this.messageGovernance.duplicate_window_ms) || this.messageGovernance.duplicate_window_ms)),
1384
+ blocked_agent_ids: dedupeStrings(Array.isArray(input.blocked_agent_ids) ? input.blocked_agent_ids.map((item) => String(item || "").trim()) : this.messageGovernance.blocked_agent_ids),
1385
+ blocked_terms: dedupeStrings(Array.isArray(input.blocked_terms) ? input.blocked_terms.map((item) => String(item || "").trim().toLowerCase()) : this.messageGovernance.blocked_terms),
1386
+ };
1387
+ this.messageGovernance = next;
1388
+ await this.socialMessageGovernanceRepo.set(next);
1389
+ await this.log("info", "Runtime message governance updated");
1390
+ return this.getMessageGovernanceView();
1391
+ }
1392
+ async sendSocialMessage(body, topic = DEFAULT_SOCIAL_MESSAGE_CHANNEL) {
1393
+ if (!this.identity || !this.profile) {
1394
+ return { sent: false, reason: "missing_identity_or_profile" };
1395
+ }
1396
+ if (!this.profile.public_enabled) {
1397
+ return { sent: false, reason: "public_disabled" };
1398
+ }
1399
+ if (!this.broadcastEnabled) {
1400
+ return { sent: false, reason: "broadcast_paused" };
1401
+ }
1402
+ if (!this.socialConfig.discovery.allow_message_broadcast) {
1403
+ return { sent: false, reason: "message_broadcast_disabled" };
1404
+ }
1405
+ const normalizedBody = this.normalizeSocialMessageBody(body);
1406
+ const normalizedTopic = String(topic || DEFAULT_SOCIAL_MESSAGE_CHANNEL).trim() || DEFAULT_SOCIAL_MESSAGE_CHANNEL;
1407
+ if (!normalizedBody) {
1408
+ return { sent: false, reason: "empty_message" };
1409
+ }
1410
+ if (normalizedBody.length > SOCIAL_MESSAGE_MAX_BODY_CHARS) {
1411
+ return { sent: false, reason: "message_too_long" };
1412
+ }
1413
+ if (this.containsBlockedMessageTerm(normalizedBody)) {
1414
+ await this.log("warn", `Social message blocked: blocked_term (${this.identity.agent_id.slice(0, 10)})`);
1415
+ return { sent: false, reason: "blocked_term" };
1416
+ }
1417
+ if (this.isRateLimited(this.outboundMessageTimestamps, this.messageGovernance.send_window_ms, this.messageGovernance.send_limit_max)) {
1418
+ await this.log("warn", `Social message throttled: rate_limited (${this.identity.agent_id.slice(0, 10)})`);
1419
+ return { sent: false, reason: "rate_limited" };
1420
+ }
1421
+ if (this.hasRecentDuplicateMessage(this.identity.agent_id, normalizedBody, normalizedTopic)) {
1422
+ await this.log("warn", `Social message blocked: duplicate_recent_message (${this.identity.agent_id.slice(0, 10)})`);
1423
+ return { sent: false, reason: "duplicate_recent_message" };
1424
+ }
1425
+ const message = (0, core_1.signSocialMessage)({
1426
+ identity: this.identity,
1427
+ message_id: (0, crypto_1.createHash)("sha256")
1428
+ .update(`${this.identity.agent_id}:${normalizedTopic}:${Date.now()}:${normalizedBody}:${Math.random()}`, "utf8")
1429
+ .digest("hex"),
1430
+ display_name: this.profile.display_name,
1431
+ topic: normalizedTopic,
1432
+ body: normalizedBody,
1433
+ created_at: Date.now(),
1434
+ });
1435
+ this.recordTimestamp(this.outboundMessageTimestamps, this.messageGovernance.send_window_ms, message.created_at);
1436
+ this.ingestSocialMessage(message);
1437
+ try {
1438
+ await this.publish(SOCIAL_MESSAGE_TOPIC, message);
1439
+ }
1440
+ catch (error) {
1441
+ const messageText = error instanceof Error ? error.message : String(error);
1442
+ this.lastBroadcastErrorAt = Date.now();
1443
+ this.lastBroadcastError = messageText;
1444
+ this.broadcastFailureCount += 1;
1445
+ await this.persistSocialMessages();
1446
+ await this.log("error", `Social message broadcast failed (${message.message_id.slice(0, 10)}): ${messageText}`);
1447
+ return {
1448
+ sent: false,
1449
+ reason: "publish_failed",
1450
+ error: messageText,
1451
+ message: this.getSocialMessages(1).items[0],
1452
+ };
1453
+ }
1454
+ await this.persistSocialMessages();
1455
+ await this.log("info", `Social message broadcast (${message.message_id.slice(0, 10)})`);
1456
+ return {
1457
+ sent: true,
1458
+ reason: "sent",
1459
+ message: this.getSocialMessages(1).items[0],
1460
+ };
1461
+ }
1462
+ async getLogs() {
1463
+ return this.logRepo.get();
1464
+ }
1465
+ async ensureIdentity() {
1466
+ if (this.identity) {
1467
+ return this.identity;
1468
+ }
1469
+ const identity = (0, core_1.createIdentity)();
1470
+ this.identity = identity;
1471
+ await this.identityRepo.set(identity);
1472
+ this.initState.identity_auto_created = true;
1473
+ const seededProfile = (0, core_1.signProfile)((0, core_1.createDefaultProfileInput)(identity.agent_id), identity);
1474
+ this.profile = seededProfile;
1475
+ await this.profileRepo.set(seededProfile);
1476
+ this.initState.profile_auto_created = true;
1477
+ await this.log("info", `Identity created automatically: ${identity.agent_id.slice(0, 12)}`);
1478
+ return identity;
1479
+ }
1480
+ async updateProfile(input) {
1481
+ const identity = await this.ensureIdentity();
1482
+ const base = this.profile ?? (0, core_1.signProfile)((0, core_1.createDefaultProfileInput)(identity.agent_id), identity);
1483
+ const next = (0, core_1.signProfile)({
1484
+ agent_id: identity.agent_id,
1485
+ display_name: input.display_name ?? base.display_name,
1486
+ bio: input.bio ?? base.bio,
1487
+ tags: input.tags ?? base.tags,
1488
+ avatar_url: input.avatar_url ?? base.avatar_url,
1489
+ public_enabled: input.public_enabled ?? base.public_enabled,
1490
+ }, identity);
1491
+ this.profile = next;
1492
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, { type: "profile", profile: next });
1493
+ await this.profileRepo.set(next);
1494
+ await this.persistCache();
1495
+ await this.log("info", `Profile updated (public=${next.public_enabled})`);
1496
+ if (next.public_enabled && this.broadcastEnabled) {
1497
+ await this.broadcastNow("profile_update");
1498
+ }
1499
+ await this.writeSocialRuntime();
1500
+ return next;
1501
+ }
1502
+ async refreshCache() {
1503
+ const removed = this.compactCacheInMemory();
1504
+ await this.persistCache();
1505
+ await this.log("info", `Cache refreshed (expired presence removed=${removed})`);
1506
+ return {
1507
+ removed_presence: removed,
1508
+ profile_count: Object.keys(this.directory.profiles).length,
1509
+ index_key_count: Object.keys(this.directory.index).length,
1510
+ };
1511
+ }
1512
+ async clearDiscoveredCache() {
1513
+ const selfAgentId = this.profile?.agent_id || this.identity?.agent_id || "";
1514
+ const profileEntries = Object.entries(this.directory.profiles);
1515
+ const removedProfiles = profileEntries.filter(([agentId]) => agentId !== selfAgentId).length;
1516
+ const removedPresence = Object.entries(this.directory.presence).filter(([agentId]) => agentId !== selfAgentId).length;
1517
+ const removedIndexRefs = Object.values(this.directory.index).reduce((acc, agentIds) => {
1518
+ const removed = agentIds.filter((agentId) => agentId !== selfAgentId).length;
1519
+ return acc + removed;
1520
+ }, 0);
1521
+ this.directory = (0, core_1.createEmptyDirectoryState)();
1522
+ if (this.profile) {
1523
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, {
1524
+ type: "profile",
1525
+ profile: this.profile,
1526
+ });
1527
+ }
1528
+ await this.persistCache();
1529
+ await this.log("warn", `Discovered cache cleared (profiles=${removedProfiles}, presence=${removedPresence}, index_refs=${removedIndexRefs})`);
1530
+ return {
1531
+ removed_profiles: removedProfiles,
1532
+ removed_presence: removedPresence,
1533
+ removed_index_refs: removedIndexRefs,
1534
+ kept_self_profile: Boolean(this.profile),
1535
+ };
1536
+ }
1537
+ async setBroadcastEnabled(enabled) {
1538
+ this.broadcastEnabled = enabled;
1539
+ if (enabled) {
1540
+ this.startBroadcastLoop();
1541
+ await this.log("info", "Broadcast loop enabled");
1542
+ if (this.profile?.public_enabled) {
1543
+ await this.broadcastNow("manual_start");
1544
+ }
1545
+ }
1546
+ else {
1547
+ if (this.broadcaster) {
1548
+ clearInterval(this.broadcaster);
1549
+ this.broadcaster = null;
1550
+ }
1551
+ await this.log("warn", "Broadcast loop paused");
1552
+ }
1553
+ await this.writeSocialRuntime();
1554
+ return { broadcast_enabled: this.broadcastEnabled };
1555
+ }
1556
+ async broadcastNow(reason = "manual") {
1557
+ if (!this.identity || !this.profile) {
1558
+ return { sent: false, reason: "missing_identity_or_profile" };
1559
+ }
1560
+ if (!this.profile.public_enabled) {
1561
+ return { sent: false, reason: "public_disabled" };
1562
+ }
1563
+ if (!this.broadcastEnabled) {
1564
+ return { sent: false, reason: "broadcast_paused" };
1565
+ }
1566
+ const profileRecord = {
1567
+ type: "profile",
1568
+ profile: this.profile,
1569
+ };
1570
+ const presenceRecord = (0, core_1.signPresence)(this.identity, Date.now());
1571
+ const indexRecords = (0, core_1.buildIndexRecords)(this.profile);
1572
+ try {
1573
+ await this.publish("profile", profileRecord);
1574
+ await this.publish("presence", presenceRecord);
1575
+ for (const record of indexRecords) {
1576
+ await this.publish("index", record);
1577
+ }
1578
+ }
1579
+ catch (error) {
1580
+ const message = error instanceof Error ? error.message : String(error);
1581
+ this.lastBroadcastErrorAt = Date.now();
1582
+ this.lastBroadcastError = message;
1583
+ this.broadcastFailureCount += 1;
1584
+ await this.log("error", `Broadcast failed (reason=${reason}): ${message}`);
1585
+ return { sent: false, reason: "publish_failed", error: message };
1586
+ }
1587
+ this.lastBroadcastAt = Date.now();
1588
+ this.broadcastCount += 1;
1589
+ this.lastBroadcastError = null;
1590
+ this.lastBroadcastErrorAt = 0;
1591
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, profileRecord);
1592
+ this.directory = (0, core_1.ingestPresenceRecord)(this.directory, presenceRecord);
1593
+ for (const record of indexRecords) {
1594
+ this.directory = (0, core_1.ingestIndexRecord)(this.directory, record);
1595
+ }
1596
+ this.compactCacheInMemory();
1597
+ await this.persistCache();
1598
+ await this.log("info", `Broadcast sent (${indexRecords.length} index refs, reason=${reason})`);
1599
+ return { sent: true, reason };
1600
+ }
1601
+ async hydrateFromDisk() {
1602
+ this.initState = {
1603
+ identity_auto_created: false,
1604
+ profile_auto_created: false,
1605
+ social_auto_created: this.initState.social_auto_created,
1606
+ initialized_at: Date.now(),
1607
+ };
1608
+ if (this.initState.social_auto_created) {
1609
+ await this.log("info", "social.md missing, auto-generated minimal default template");
1610
+ }
1611
+ const existingIdentity = await this.identityRepo.get();
1612
+ const resolvedIdentity = (0, core_1.resolveIdentityWithSocial)({
1613
+ socialConfig: this.socialConfig,
1614
+ existingIdentity,
1615
+ generatedIdentity: (0, core_1.createIdentity)(),
1616
+ rootDir: this.workspaceRoot,
1617
+ });
1618
+ this.identity = resolvedIdentity.identity;
1619
+ this.resolvedIdentitySource = resolvedIdentity.source;
1620
+ this.resolvedOpenClawIdentityPath = resolvedIdentity.openclaw_source_path;
1621
+ if (resolvedIdentity.source === "silicaclaw-generated") {
1622
+ this.initState.identity_auto_created = true;
1623
+ await this.log("info", "identity.json missing, auto-generated SilicaClaw identity");
1624
+ }
1625
+ if (resolvedIdentity.source === "openclaw-existing" && resolvedIdentity.openclaw_source_path) {
1626
+ await this.log("info", `Bound existing OpenClaw identity: ${resolvedIdentity.openclaw_source_path}`);
1627
+ }
1628
+ await this.identityRepo.set(this.identity);
1629
+ const existingProfile = await this.profileRepo.get();
1630
+ const profileInput = (0, core_1.resolveProfileInputWithSocial)({
1631
+ socialConfig: this.socialConfig,
1632
+ agentId: this.identity.agent_id,
1633
+ existingProfile: existingProfile && existingProfile.agent_id === this.identity.agent_id ? existingProfile : null,
1634
+ rootDir: this.workspaceRoot,
1635
+ });
1636
+ this.profile = (0, core_1.signProfile)(profileInput, this.identity);
1637
+ if (!existingProfile || existingProfile.agent_id !== this.identity.agent_id) {
1638
+ this.initState.profile_auto_created = true;
1639
+ await this.log("info", "profile.json missing/invalid, initialized from social/default profile");
1640
+ }
1641
+ await this.profileRepo.set(this.profile);
1642
+ this.directory = (0, core_1.dedupeIndex)(await this.cacheRepo.get());
1643
+ this.messageGovernance = {
1644
+ ...this.defaultMessageGovernance(),
1645
+ ...(await this.socialMessageGovernanceRepo.get()),
1646
+ };
1647
+ this.socialMessages = this.normalizeSocialMessages(await this.socialMessageRepo.get());
1648
+ this.socialMessageObservations = this.normalizeSocialMessageObservations(await this.socialMessageObservationRepo.get());
1649
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, { type: "profile", profile: this.profile });
1650
+ this.compactCacheInMemory();
1651
+ await this.persistCache();
1652
+ await this.applySocialConfigOnCurrentState();
1653
+ await this.writeSocialRuntime();
1654
+ }
1655
+ async applySocialConfigOnCurrentState() {
1656
+ if (!this.identity || !this.profile) {
1657
+ return;
1658
+ }
1659
+ const nextProfileInput = (0, core_1.resolveProfileInputWithSocial)({
1660
+ socialConfig: this.socialConfig,
1661
+ agentId: this.identity.agent_id,
1662
+ existingProfile: this.profile,
1663
+ rootDir: this.workspaceRoot,
1664
+ });
1665
+ const nextProfile = (0, core_1.signProfile)(nextProfileInput, this.identity);
1666
+ this.profile = nextProfile;
1667
+ await this.profileRepo.set(nextProfile);
1668
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, { type: "profile", profile: nextProfile });
1669
+ this.compactCacheInMemory();
1670
+ await this.persistCache();
1671
+ if (!this.socialConfig.enabled) {
1672
+ await this.setBroadcastEnabled(false);
1673
+ return;
1674
+ }
1675
+ if (!this.broadcastEnabled) {
1676
+ await this.setBroadcastEnabled(true);
1677
+ }
1678
+ }
1679
+ async writeSocialRuntime() {
1680
+ const runtime = {
1681
+ enabled: this.socialConfig.enabled,
1682
+ public_enabled: this.socialConfig.public_enabled,
1683
+ source_path: this.socialSourcePath,
1684
+ last_loaded_at: Date.now(),
1685
+ social_found: this.socialFound,
1686
+ parse_error: this.socialParseError,
1687
+ resolved_identity: this.identity
1688
+ ? {
1689
+ agent_id: this.identity.agent_id,
1690
+ public_key: this.identity.public_key,
1691
+ created_at: this.identity.created_at,
1692
+ source: this.resolvedIdentitySource,
1693
+ }
1694
+ : null,
1695
+ resolved_profile: this.profile
1696
+ ? {
1697
+ display_name: this.profile.display_name,
1698
+ bio: this.profile.bio,
1699
+ avatar_url: this.profile.avatar_url,
1700
+ tags: this.profile.tags,
1701
+ public_enabled: this.profile.public_enabled,
1702
+ }
1703
+ : null,
1704
+ resolved_network: {
1705
+ mode: this.networkMode,
1706
+ adapter: this.adapterMode,
1707
+ namespace: this.networkNamespace,
1708
+ port: this.networkPort,
1709
+ signaling_url: this.webrtcSignalingUrls[0] ?? WEBRTC_SIGNALING_URL,
1710
+ signaling_urls: this.webrtcSignalingUrls,
1711
+ room: this.webrtcRoom,
1712
+ seed_peers: this.webrtcSeedPeers,
1713
+ bootstrap_hints: this.webrtcBootstrapHints,
1714
+ bootstrap_sources: this.webrtcBootstrapSources,
1715
+ },
1716
+ resolved_discovery: this.socialConfig.discovery,
1717
+ visibility: this.socialConfig.visibility,
1718
+ openclaw: this.socialConfig.openclaw,
1719
+ };
1720
+ this.socialRuntime = runtime;
1721
+ await this.socialRuntimeRepo.set(runtime);
1722
+ }
1723
+ async onMessage(topic, data) {
1724
+ this.receivedCount += 1;
1725
+ this.receivedByTopic[topic] = (this.receivedByTopic[topic] ?? 0) + 1;
1726
+ this.lastMessageAt = Date.now();
1727
+ if (topic === "profile") {
1728
+ const record = data;
1729
+ if (!record?.profile?.agent_id || !record?.profile?.signature) {
1730
+ return;
1731
+ }
1732
+ if (record.profile.agent_id === this.identity?.agent_id && this.identity) {
1733
+ if (!(0, core_1.verifyProfile)(record.profile, this.identity.public_key)) {
1734
+ await this.log("warn", "Rejected self profile with invalid signature");
1735
+ return;
1736
+ }
1737
+ }
1738
+ this.directory = (0, core_1.ingestProfileRecord)(this.directory, record);
1739
+ this.compactCacheInMemory();
1740
+ await this.persistCache();
1741
+ return;
1742
+ }
1743
+ if (topic === "presence") {
1744
+ const record = data;
1745
+ if (!record?.agent_id || !record?.signature || typeof record.timestamp !== "number") {
1746
+ return;
1747
+ }
1748
+ if (record.agent_id === this.identity?.agent_id && this.identity) {
1749
+ if (!(0, core_1.verifyPresence)(record, this.identity.public_key)) {
1750
+ await this.log("warn", "Rejected invalid self presence signature");
1751
+ return;
1752
+ }
1753
+ }
1754
+ this.directory = (0, core_1.ingestPresenceRecord)(this.directory, record);
1755
+ this.compactCacheInMemory();
1756
+ await this.persistCache();
1757
+ return;
1758
+ }
1759
+ if (topic === SOCIAL_MESSAGE_TOPIC) {
1760
+ const record = this.normalizeIncomingSocialMessage(data);
1761
+ if (!record) {
1762
+ return;
1763
+ }
1764
+ if (!(0, core_1.verifySocialMessage)(record)) {
1765
+ await this.log("warn", `Rejected social message with invalid signature (${record.message_id.slice(0, 10)})`);
1766
+ return;
1767
+ }
1768
+ const governanceReason = this.getIncomingSocialMessageRejectionReason(record);
1769
+ if (governanceReason) {
1770
+ await this.log("warn", `Rejected social message (${record.message_id.slice(0, 10)}): ${governanceReason}`);
1771
+ return;
1772
+ }
1773
+ this.ingestSocialMessage(record);
1774
+ await this.persistSocialMessages();
1775
+ await this.publishObservationForMessage(record);
1776
+ return;
1777
+ }
1778
+ if (topic === SOCIAL_MESSAGE_OBSERVATION_TOPIC) {
1779
+ const record = this.normalizeIncomingSocialMessageObservation(data);
1780
+ if (!record) {
1781
+ return;
1782
+ }
1783
+ if (!(0, core_1.verifySocialMessageObservation)(record)) {
1784
+ await this.log("warn", `Rejected message observation with invalid signature (${record.observation_id.slice(0, 10)})`);
1785
+ return;
1786
+ }
1787
+ this.ingestSocialMessageObservation(record);
1788
+ await this.persistSocialMessageObservations();
1789
+ return;
1790
+ }
1791
+ const record = data;
1792
+ if (!record?.key || !record?.agent_id) {
1793
+ return;
1794
+ }
1795
+ this.directory = (0, core_1.ingestIndexRecord)(this.directory, record);
1796
+ this.directory = (0, core_1.dedupeIndex)(this.directory);
1797
+ await this.persistCache();
1798
+ }
1799
+ startBroadcastLoop() {
1800
+ if (this.broadcaster) {
1801
+ clearInterval(this.broadcaster);
1802
+ }
1803
+ if (!this.broadcastEnabled) {
1804
+ return;
1805
+ }
1806
+ this.broadcaster = setInterval(async () => {
1807
+ try {
1808
+ await this.broadcastNow("interval");
1809
+ }
1810
+ catch (error) {
1811
+ await this.log("warn", `Scheduled broadcast failed: ${error instanceof Error ? error.message : String(error)}`);
1812
+ }
1813
+ }, BROADCAST_INTERVAL_MS);
1814
+ }
1815
+ bindNetworkSubscriptions() {
1816
+ if (this.subscriptionsBound) {
1817
+ return;
1818
+ }
1819
+ this.network.subscribe("profile", (data) => {
1820
+ this.onMessage("profile", data);
1821
+ });
1822
+ this.network.subscribe("presence", (data) => {
1823
+ this.onMessage("presence", data);
1824
+ });
1825
+ this.network.subscribe("index", (data) => {
1826
+ this.onMessage("index", data);
1827
+ });
1828
+ this.network.subscribe(SOCIAL_MESSAGE_TOPIC, (data) => {
1829
+ this.onMessage(SOCIAL_MESSAGE_TOPIC, data);
1830
+ });
1831
+ this.network.subscribe(SOCIAL_MESSAGE_OBSERVATION_TOPIC, (data) => {
1832
+ this.onMessage(SOCIAL_MESSAGE_OBSERVATION_TOPIC, data);
1833
+ });
1834
+ this.subscriptionsBound = true;
1835
+ }
1836
+ buildNetworkAdapter() {
1837
+ const mode = process.env.NETWORK_ADAPTER || this.socialConfig.network.adapter;
1838
+ if (mode === "mock") {
1839
+ return {
1840
+ adapter: new network_1.MockNetworkAdapter(),
1841
+ mode: "mock",
1842
+ port: null,
1843
+ };
1844
+ }
1845
+ if (mode === "real-preview") {
1846
+ return {
1847
+ adapter: new network_1.RealNetworkAdapterPreview({
1848
+ peerId: NETWORK_PEER_ID,
1849
+ namespace: this.networkNamespace,
1850
+ transport: new network_1.UdpLanBroadcastTransport({
1851
+ port: this.networkPort ?? undefined,
1852
+ bindAddress: NETWORK_UDP_BIND_ADDRESS,
1853
+ broadcastAddress: NETWORK_UDP_BROADCAST_ADDRESS,
1854
+ }),
1855
+ peerDiscovery: new network_1.HeartbeatPeerDiscovery({
1856
+ heartbeatIntervalMs: NETWORK_HEARTBEAT_INTERVAL_MS,
1857
+ staleAfterMs: NETWORK_PEER_STALE_AFTER_MS,
1858
+ removeAfterMs: NETWORK_PEER_REMOVE_AFTER_MS,
1859
+ }),
1860
+ maxMessageBytes: NETWORK_MAX_MESSAGE_BYTES,
1861
+ dedupeWindowMs: NETWORK_DEDUPE_WINDOW_MS,
1862
+ dedupeMaxEntries: NETWORK_DEDUPE_MAX_ENTRIES,
1863
+ maxFutureDriftMs: NETWORK_MAX_FUTURE_DRIFT_MS,
1864
+ maxPastDriftMs: NETWORK_MAX_PAST_DRIFT_MS,
1865
+ }),
1866
+ mode: "real-preview",
1867
+ port: this.networkPort,
1868
+ };
1869
+ }
1870
+ if (mode === "webrtc-preview") {
1871
+ return {
1872
+ adapter: new network_1.WebRTCPreviewAdapter({
1873
+ peerId: NETWORK_PEER_ID,
1874
+ namespace: this.networkNamespace,
1875
+ signalingUrl: this.webrtcSignalingUrls[0] ?? WEBRTC_SIGNALING_URL,
1876
+ signalingUrls: this.webrtcSignalingUrls,
1877
+ room: this.webrtcRoom,
1878
+ seedPeers: this.webrtcSeedPeers,
1879
+ bootstrapHints: this.webrtcBootstrapHints,
1880
+ bootstrapSources: this.webrtcBootstrapSources,
1881
+ maxMessageBytes: NETWORK_MAX_MESSAGE_BYTES,
1882
+ maxFutureDriftMs: NETWORK_MAX_FUTURE_DRIFT_MS,
1883
+ maxPastDriftMs: NETWORK_MAX_PAST_DRIFT_MS,
1884
+ }),
1885
+ mode: "webrtc-preview",
1886
+ port: this.networkPort,
1887
+ };
1888
+ }
1889
+ if (mode === "relay-preview") {
1890
+ return {
1891
+ adapter: new network_1.RelayPreviewAdapter({
1892
+ peerId: NETWORK_PEER_ID,
1893
+ namespace: this.networkNamespace,
1894
+ signalingUrl: this.webrtcSignalingUrls[0] ?? WEBRTC_SIGNALING_URL,
1895
+ signalingUrls: this.webrtcSignalingUrls,
1896
+ room: this.webrtcRoom,
1897
+ seedPeers: this.webrtcSeedPeers,
1898
+ bootstrapHints: this.webrtcBootstrapHints,
1899
+ bootstrapSources: this.webrtcBootstrapSources,
1900
+ maxMessageBytes: NETWORK_MAX_MESSAGE_BYTES,
1901
+ maxFutureDriftMs: NETWORK_MAX_FUTURE_DRIFT_MS,
1902
+ maxPastDriftMs: NETWORK_MAX_PAST_DRIFT_MS,
1903
+ }),
1904
+ mode: "relay-preview",
1905
+ port: this.networkPort,
1906
+ };
1907
+ }
1908
+ return {
1909
+ adapter: new network_1.LocalEventBusAdapter(),
1910
+ mode: "local-event-bus",
1911
+ port: null,
1912
+ };
1913
+ }
1914
+ async restartNetworkAdapter(reason) {
1915
+ const previous = this.network;
1916
+ try {
1917
+ await previous.stop();
1918
+ }
1919
+ catch (error) {
1920
+ await this.log("warn", `Old adapter stop error during restart (${reason}): ${error instanceof Error ? error.message : String(error)}`);
1921
+ }
1922
+ const next = this.buildNetworkAdapter();
1923
+ this.network = next.adapter;
1924
+ this.adapterMode = next.mode;
1925
+ this.networkPort = next.port;
1926
+ await this.network.start();
1927
+ this.bindNetworkSubscriptions();
1928
+ this.startBroadcastLoop();
1929
+ if (this.broadcastEnabled && this.profile?.public_enabled) {
1930
+ await this.broadcastNow("adapter_restart");
1931
+ }
1932
+ }
1933
+ compactCacheInMemory() {
1934
+ const cleaned = (0, core_1.cleanupExpiredPresence)(this.directory, Date.now(), PRESENCE_TTL_MS);
1935
+ this.directory = (0, core_1.dedupeIndex)(cleaned.state);
1936
+ return cleaned.removed;
1937
+ }
1938
+ async publish(topic, data) {
1939
+ await this.network.publish(topic, data);
1940
+ this.publishedByTopic[topic] = (this.publishedByTopic[topic] ?? 0) + 1;
1941
+ }
1942
+ async persistCache() {
1943
+ await this.cacheRepo.set(this.directory);
1944
+ }
1945
+ async persistSocialMessages() {
1946
+ await this.socialMessageRepo.set(this.socialMessages);
1947
+ }
1948
+ async persistSocialMessageObservations() {
1949
+ await this.socialMessageObservationRepo.set(this.socialMessageObservations);
1950
+ }
1951
+ async log(level, message) {
1952
+ await this.logRepo.append({
1953
+ level,
1954
+ message,
1955
+ timestamp: Date.now(),
1956
+ });
1957
+ }
1958
+ getAdapterDiagnostics() {
1959
+ if (typeof this.network.getDiagnostics !== "function") {
1960
+ return null;
1961
+ }
1962
+ return this.network.getDiagnostics();
1963
+ }
1964
+ toPublicProfileSummary(profile, options) {
1965
+ const lastSeenAt = options?.last_seen_at ?? this.directory.presence[profile.agent_id] ?? 0;
1966
+ const online = (0, core_1.isAgentOnline)(lastSeenAt, Date.now(), PRESENCE_TTL_MS);
1967
+ const isSelf = profile.agent_id === this.identity?.agent_id;
1968
+ const visibility = isSelf
1969
+ ? {
1970
+ show_tags: this.socialConfig.visibility.show_tags,
1971
+ show_last_seen: this.socialConfig.visibility.show_last_seen,
1972
+ show_capabilities_summary: this.socialConfig.visibility.show_capabilities_summary,
1973
+ }
1974
+ : {
1975
+ show_tags: true,
1976
+ show_last_seen: true,
1977
+ show_capabilities_summary: true,
1978
+ };
1979
+ const selfPublicKey = isSelf ? this.identity?.public_key ?? null : null;
1980
+ const verifiedProfile = Boolean(isSelf &&
1981
+ selfPublicKey &&
1982
+ (0, core_1.verifyProfile)(profile, selfPublicKey));
1983
+ return (0, core_1.buildPublicProfileSummary)({
1984
+ profile,
1985
+ online,
1986
+ last_seen_at: lastSeenAt || null,
1987
+ network_mode: isSelf ? this.networkMode : "unknown",
1988
+ openclaw_bound: isSelf
1989
+ ? this.resolvedIdentitySource === "openclaw-existing"
1990
+ : profile.tags.some((tag) => String(tag).trim().toLowerCase() === "openclaw"),
1991
+ visibility,
1992
+ profile_version: PROFILE_VERSION,
1993
+ public_key_fingerprint: selfPublicKey ? this.fingerprintPublicKey(selfPublicKey) : null,
1994
+ verified_profile: verifiedProfile,
1995
+ now: Date.now(),
1996
+ presence_ttl_ms: PRESENCE_TTL_MS,
1997
+ });
1998
+ }
1999
+ fingerprintPublicKey(publicKey) {
2000
+ const digest = (0, crypto_1.createHash)("sha256").update(publicKey, "utf8").digest("hex");
2001
+ return `${digest.slice(0, 12)}:${digest.slice(-8)}`;
2002
+ }
2003
+ getOnboardingSummary() {
2004
+ const summary = this.getIntegrationSummary();
2005
+ const publicEnabled = Boolean(this.profile?.public_enabled);
2006
+ return {
2007
+ first_run: Boolean(this.initState.social_auto_created ||
2008
+ this.initState.identity_auto_created ||
2009
+ this.initState.profile_auto_created),
2010
+ connected: summary.connected,
2011
+ discoverable: summary.discoverable,
2012
+ mode: this.networkMode,
2013
+ public_enabled: publicEnabled,
2014
+ can_enable_public_discovery: !publicEnabled,
2015
+ next_steps: [
2016
+ "Update display name in Profile page",
2017
+ "Export social.md from Social Config",
2018
+ ],
2019
+ };
2020
+ }
2021
+ getDefaultDisplayName() {
2022
+ const host = (0, os_1.hostname)().trim().replace(/\s+/g, "-").slice(0, 24);
2023
+ return host ? `OpenClaw @ ${host}` : "OpenClaw Agent";
2024
+ }
2025
+ getModeExplainer() {
2026
+ if (this.networkMode === "local") {
2027
+ return {
2028
+ mode: "local",
2029
+ short_label: "Local only",
2030
+ summary: "Only nodes inside the same local process bus are visible.",
2031
+ };
2032
+ }
2033
+ if (this.networkMode === "lan") {
2034
+ return {
2035
+ mode: "lan",
2036
+ short_label: "LAN broadcast",
2037
+ summary: "Uses UDP LAN broadcast. Peers usually need to be on the same local network.",
2038
+ };
2039
+ }
2040
+ return {
2041
+ mode: "global-preview",
2042
+ short_label: "Relay preview",
2043
+ summary: "Uses the public relay preview room so public nodes can find each other across the internet.",
2044
+ };
2045
+ }
2046
+ defaultMessageGovernance() {
2047
+ return {
2048
+ send_limit_max: SOCIAL_MESSAGE_SEND_MAX_PER_WINDOW,
2049
+ send_window_ms: SOCIAL_MESSAGE_SEND_WINDOW_MS,
2050
+ receive_limit_max: SOCIAL_MESSAGE_RECEIVE_MAX_PER_WINDOW,
2051
+ receive_window_ms: SOCIAL_MESSAGE_RECEIVE_WINDOW_MS,
2052
+ duplicate_window_ms: SOCIAL_MESSAGE_DUPLICATE_WINDOW_MS,
2053
+ blocked_agent_ids: Array.from(SOCIAL_MESSAGE_BLOCKED_AGENT_IDS),
2054
+ blocked_terms: Array.from(SOCIAL_MESSAGE_BLOCKED_TERMS),
2055
+ };
2056
+ }
2057
+ adapterForMode(mode) {
2058
+ if (mode === "local")
2059
+ return "local-event-bus";
2060
+ if (mode === "lan")
2061
+ return "real-preview";
2062
+ return "relay-preview";
2063
+ }
2064
+ applyResolvedNetworkConfig() {
2065
+ const modeEnv = String(NETWORK_MODE || "").trim();
2066
+ const resolvedMode = this.socialConfig.network.mode ||
2067
+ (modeEnv === "local" || modeEnv === "lan" || modeEnv === "global-preview"
2068
+ ? modeEnv
2069
+ : "global-preview");
2070
+ this.networkMode = resolvedMode;
2071
+ this.networkNamespace = this.socialConfig.network.namespace || process.env.NETWORK_NAMESPACE || "silicaclaw.preview";
2072
+ this.networkPort = Number(this.socialConfig.network.port || process.env.NETWORK_PORT || 44123);
2073
+ const builtInGlobalSignalingUrls = ["https://relay.silicaclaw.com"];
2074
+ const builtInGlobalRoom = "silicaclaw-global-preview";
2075
+ const signalingUrlsSocial = dedupeStrings(this.socialConfig.network.signaling_urls || []);
2076
+ const signalingUrlSocial = String(this.socialConfig.network.signaling_url || "").trim();
2077
+ const signalingUrlsEnv = dedupeStrings(parseListEnv(WEBRTC_SIGNALING_URLS));
2078
+ const signalingUrlEnvSingle = String(WEBRTC_SIGNALING_URL || "").trim();
2079
+ let signalingUrls = [];
2080
+ let signalingSource = "";
2081
+ if (signalingUrlsSocial.length > 0) {
2082
+ signalingUrls = signalingUrlsSocial;
2083
+ signalingSource = "social.md:network.signaling_urls";
2084
+ }
2085
+ else if (signalingUrlSocial) {
2086
+ signalingUrls = [signalingUrlSocial];
2087
+ signalingSource = "social.md:network.signaling_url";
2088
+ }
2089
+ else if (signalingUrlsEnv.length > 0) {
2090
+ signalingUrls = signalingUrlsEnv;
2091
+ signalingSource = "env:WEBRTC_SIGNALING_URLS";
2092
+ }
2093
+ else if (signalingUrlEnvSingle) {
2094
+ signalingUrls = [signalingUrlEnvSingle];
2095
+ signalingSource = "env:WEBRTC_SIGNALING_URL";
2096
+ }
2097
+ else if (this.networkMode === "global-preview") {
2098
+ signalingUrls = builtInGlobalSignalingUrls;
2099
+ signalingSource = "built-in-defaults:global-preview.signaling_urls";
2100
+ }
2101
+ else {
2102
+ signalingUrls = ["https://relay.silicaclaw.com"];
2103
+ signalingSource = "default:https://relay.silicaclaw.com";
2104
+ }
2105
+ const roomSocial = String(this.socialConfig.network.room || "").trim();
2106
+ const roomEnv = String(WEBRTC_ROOM || "").trim();
2107
+ const room = roomSocial ||
2108
+ roomEnv ||
2109
+ (this.networkMode === "global-preview" ? builtInGlobalRoom : "") ||
2110
+ "silicaclaw-global-preview";
2111
+ const roomSource = roomSocial
2112
+ ? "social.md:network.room"
2113
+ : roomEnv
2114
+ ? "env:WEBRTC_ROOM"
2115
+ : this.networkMode === "global-preview"
2116
+ ? "built-in-defaults:global-preview.room"
2117
+ : "default:silicaclaw-global-preview";
2118
+ const seedPeersSocial = dedupeStrings(this.socialConfig.network.seed_peers || []);
2119
+ const seedPeersEnv = dedupeStrings(parseListEnv(WEBRTC_SEED_PEERS));
2120
+ const seedPeers = seedPeersSocial.length > 0 ? seedPeersSocial : seedPeersEnv;
2121
+ const seedPeersSource = seedPeersSocial.length > 0
2122
+ ? "social.md:network.seed_peers"
2123
+ : seedPeersEnv.length > 0
2124
+ ? "env:WEBRTC_SEED_PEERS"
2125
+ : "default:none";
2126
+ const bootstrapHintsSocial = dedupeStrings(this.socialConfig.network.bootstrap_hints || []);
2127
+ const bootstrapHintsEnv = dedupeStrings(parseListEnv(WEBRTC_BOOTSTRAP_HINTS));
2128
+ const bootstrapHints = bootstrapHintsSocial.length > 0 ? bootstrapHintsSocial : bootstrapHintsEnv;
2129
+ const bootstrapHintsSource = bootstrapHintsSocial.length > 0
2130
+ ? "social.md:network.bootstrap_hints"
2131
+ : bootstrapHintsEnv.length > 0
2132
+ ? "env:WEBRTC_BOOTSTRAP_HINTS"
2133
+ : "default:none";
2134
+ this.webrtcSignalingUrls = signalingUrls;
2135
+ this.webrtcRoom = room;
2136
+ this.webrtcSeedPeers = seedPeers;
2137
+ this.webrtcBootstrapHints = bootstrapHints;
2138
+ this.webrtcBootstrapSources = [signalingSource, roomSource, seedPeersSource, bootstrapHintsSource];
2139
+ }
2140
+ normalizeSocialMessageBody(body) {
2141
+ return String(body || "")
2142
+ .replace(/\r\n/g, "\n")
2143
+ .split("\n")
2144
+ .map((line) => line.trimEnd())
2145
+ .join("\n")
2146
+ .trim();
2147
+ }
2148
+ normalizeWindowTimestamps(timestamps, windowMs, now = Date.now()) {
2149
+ return timestamps.filter((timestamp) => now - timestamp <= windowMs);
2150
+ }
2151
+ recordTimestamp(timestamps, windowMs, at = Date.now()) {
2152
+ const cleaned = this.normalizeWindowTimestamps(timestamps, windowMs, at);
2153
+ cleaned.push(at);
2154
+ timestamps.splice(0, timestamps.length, ...cleaned);
2155
+ }
2156
+ isRateLimited(timestamps, windowMs, maxCount, now = Date.now()) {
2157
+ const cleaned = this.normalizeWindowTimestamps(timestamps, windowMs, now);
2158
+ timestamps.splice(0, timestamps.length, ...cleaned);
2159
+ return cleaned.length >= maxCount;
2160
+ }
2161
+ containsBlockedMessageTerm(body) {
2162
+ const normalized = String(body || "").toLowerCase();
2163
+ return this.messageGovernance.blocked_terms.some((term) => normalized.includes(term));
2164
+ }
2165
+ hasRecentDuplicateMessage(agentId, body, topic, now = Date.now()) {
2166
+ return this.socialMessages.some((item) => (item.agent_id === agentId &&
2167
+ item.topic === topic &&
2168
+ item.body === body &&
2169
+ now - item.created_at <= this.messageGovernance.duplicate_window_ms));
2170
+ }
2171
+ getIncomingSocialMessageRejectionReason(record) {
2172
+ const now = Date.now();
2173
+ if (this.messageGovernance.blocked_agent_ids.includes(record.agent_id)) {
2174
+ return "blocked_agent";
2175
+ }
2176
+ if (this.containsBlockedMessageTerm(record.body)) {
2177
+ return "blocked_term";
2178
+ }
2179
+ if (record.created_at - now > SOCIAL_MESSAGE_MAX_FUTURE_MS) {
2180
+ return "message_from_future";
2181
+ }
2182
+ if (now - record.created_at > SOCIAL_MESSAGE_MAX_AGE_MS) {
2183
+ return "message_too_old";
2184
+ }
2185
+ const timestamps = this.inboundMessageTimestampsByAgent[record.agent_id] || [];
2186
+ this.inboundMessageTimestampsByAgent[record.agent_id] = timestamps;
2187
+ if (this.isRateLimited(timestamps, this.messageGovernance.receive_window_ms, this.messageGovernance.receive_limit_max, now)) {
2188
+ return "remote_rate_limited";
2189
+ }
2190
+ if (this.hasRecentDuplicateMessage(record.agent_id, record.body, record.topic, now)) {
2191
+ return "duplicate_recent_message";
2192
+ }
2193
+ this.recordTimestamp(timestamps, this.messageGovernance.receive_window_ms, now);
2194
+ return null;
2195
+ }
2196
+ canPublishMessageObservation() {
2197
+ return Boolean(this.identity &&
2198
+ this.profile?.public_enabled &&
2199
+ this.broadcastEnabled &&
2200
+ this.socialConfig.discovery.allow_message_broadcast);
2201
+ }
2202
+ async publishObservationForMessage(message) {
2203
+ if (!this.identity || !this.profile || !this.canPublishMessageObservation()) {
2204
+ return;
2205
+ }
2206
+ if (message.agent_id === this.identity.agent_id) {
2207
+ return;
2208
+ }
2209
+ const existing = this.socialMessageObservations.find((item) => (item.message_id === message.message_id && item.observer_agent_id === this.identity?.agent_id));
2210
+ if (existing) {
2211
+ return;
2212
+ }
2213
+ const observation = (0, core_1.signSocialMessageObservation)({
2214
+ identity: this.identity,
2215
+ observation_id: (0, crypto_1.createHash)("sha256")
2216
+ .update(`${message.message_id}:${this.identity.agent_id}:${Date.now()}`, "utf8")
2217
+ .digest("hex"),
2218
+ message_id: message.message_id,
2219
+ observed_agent_id: message.agent_id,
2220
+ observer_display_name: this.profile.display_name,
2221
+ observed_at: Date.now(),
2222
+ });
2223
+ this.ingestSocialMessageObservation(observation);
2224
+ await this.publish(SOCIAL_MESSAGE_OBSERVATION_TOPIC, observation);
2225
+ await this.persistSocialMessageObservations();
2226
+ }
2227
+ normalizeIncomingSocialMessage(value) {
2228
+ if (typeof value !== "object" || value === null) {
2229
+ return null;
2230
+ }
2231
+ const record = value;
2232
+ const body = this.normalizeSocialMessageBody(String(record.body || ""));
2233
+ const agentId = String(record.agent_id || "").trim();
2234
+ const displayName = String(record.display_name || "").trim();
2235
+ const topic = String(record.topic || DEFAULT_SOCIAL_MESSAGE_CHANNEL).trim() || DEFAULT_SOCIAL_MESSAGE_CHANNEL;
2236
+ const messageId = String(record.message_id || "").trim();
2237
+ const createdAt = Number(record.created_at || 0);
2238
+ if (record.type !== SOCIAL_MESSAGE_TOPIC ||
2239
+ !messageId ||
2240
+ !agentId ||
2241
+ typeof record.public_key !== "string" ||
2242
+ !String(record.public_key).trim() ||
2243
+ !body ||
2244
+ typeof record.signature !== "string" ||
2245
+ !String(record.signature).trim() ||
2246
+ !Number.isFinite(createdAt) ||
2247
+ body.length > SOCIAL_MESSAGE_MAX_BODY_CHARS) {
2248
+ return null;
2249
+ }
2250
+ return {
2251
+ type: SOCIAL_MESSAGE_TOPIC,
2252
+ message_id: messageId,
2253
+ agent_id: agentId,
2254
+ public_key: String(record.public_key).trim(),
2255
+ display_name: displayName || "Unnamed",
2256
+ topic,
2257
+ body,
2258
+ created_at: createdAt,
2259
+ signature: String(record.signature).trim(),
2260
+ };
2261
+ }
2262
+ normalizeSocialMessages(items) {
2263
+ if (!Array.isArray(items)) {
2264
+ return [];
2265
+ }
2266
+ const deduped = new Set();
2267
+ return items
2268
+ .map((item) => this.normalizeIncomingSocialMessage(item))
2269
+ .filter((item) => Boolean(item))
2270
+ .sort((a, b) => b.created_at - a.created_at)
2271
+ .filter((item) => {
2272
+ if (deduped.has(item.message_id)) {
2273
+ return false;
2274
+ }
2275
+ deduped.add(item.message_id);
2276
+ return true;
2277
+ })
2278
+ .slice(0, SOCIAL_MESSAGE_HISTORY_LIMIT);
2279
+ }
2280
+ normalizeIncomingSocialMessageObservation(value) {
2281
+ if (typeof value !== "object" || value === null) {
2282
+ return null;
2283
+ }
2284
+ const record = value;
2285
+ const observationId = String(record.observation_id || "").trim();
2286
+ const messageId = String(record.message_id || "").trim();
2287
+ const observedAgentId = String(record.observed_agent_id || "").trim();
2288
+ const observerAgentId = String(record.observer_agent_id || "").trim();
2289
+ const observerDisplayName = String(record.observer_display_name || "").trim();
2290
+ const observedAt = Number(record.observed_at || 0);
2291
+ if (record.type !== SOCIAL_MESSAGE_OBSERVATION_TOPIC ||
2292
+ !observationId ||
2293
+ !messageId ||
2294
+ !observedAgentId ||
2295
+ !observerAgentId ||
2296
+ typeof record.observer_public_key !== "string" ||
2297
+ !String(record.observer_public_key).trim() ||
2298
+ typeof record.signature !== "string" ||
2299
+ !String(record.signature).trim() ||
2300
+ !Number.isFinite(observedAt)) {
2301
+ return null;
2302
+ }
2303
+ return {
2304
+ type: SOCIAL_MESSAGE_OBSERVATION_TOPIC,
2305
+ observation_id: observationId,
2306
+ message_id: messageId,
2307
+ observed_agent_id: observedAgentId,
2308
+ observer_agent_id: observerAgentId,
2309
+ observer_public_key: String(record.observer_public_key).trim(),
2310
+ observer_display_name: observerDisplayName || "Unnamed",
2311
+ observed_at: observedAt,
2312
+ signature: String(record.signature).trim(),
2313
+ };
2314
+ }
2315
+ normalizeSocialMessageObservations(items) {
2316
+ if (!Array.isArray(items)) {
2317
+ return [];
2318
+ }
2319
+ const deduped = new Set();
2320
+ return items
2321
+ .map((item) => this.normalizeIncomingSocialMessageObservation(item))
2322
+ .filter((item) => Boolean(item))
2323
+ .sort((a, b) => b.observed_at - a.observed_at)
2324
+ .filter((item) => {
2325
+ if (deduped.has(item.observation_id)) {
2326
+ return false;
2327
+ }
2328
+ deduped.add(item.observation_id);
2329
+ return true;
2330
+ })
2331
+ .slice(0, SOCIAL_MESSAGE_OBSERVATION_HISTORY_LIMIT);
2332
+ }
2333
+ ingestSocialMessage(message) {
2334
+ const existing = this.socialMessages.findIndex((item) => item.message_id === message.message_id);
2335
+ if (existing >= 0) {
2336
+ this.socialMessages[existing] = message;
2337
+ }
2338
+ else {
2339
+ this.socialMessages.unshift(message);
2340
+ }
2341
+ this.socialMessages = this.normalizeSocialMessages(this.socialMessages);
2342
+ }
2343
+ ingestSocialMessageObservation(observation) {
2344
+ const existing = this.socialMessageObservations.findIndex((item) => item.observation_id === observation.observation_id);
2345
+ if (existing >= 0) {
2346
+ this.socialMessageObservations[existing] = observation;
2347
+ }
2348
+ else {
2349
+ this.socialMessageObservations.unshift(observation);
2350
+ }
2351
+ this.socialMessageObservations = this.normalizeSocialMessageObservations(this.socialMessageObservations);
2352
+ }
2353
+ }
2354
+ exports.LocalNodeService = LocalNodeService;
2355
+ function sendOk(res, data, meta) {
2356
+ res.json({ ok: true, data, meta });
2357
+ }
2358
+ function sendError(res, status, code, message, details) {
2359
+ const error = { code, message };
2360
+ if (details !== undefined) {
2361
+ error.details = details;
2362
+ }
2363
+ res.status(status).json({ ok: false, error });
2364
+ }
2365
+ function asyncRoute(handler) {
2366
+ return (req, res, next) => {
2367
+ Promise.resolve(handler(req, res)).catch(next);
2368
+ };
2369
+ }
2370
+ function resolveLocalConsoleStaticDir() {
2371
+ const candidates = [
2372
+ (0, path_1.resolve)(process.cwd(), "public"),
2373
+ (0, path_1.resolve)(process.cwd(), "apps", "local-console", "public"),
2374
+ (0, path_1.resolve)(__dirname, "..", "public"),
2375
+ (0, path_1.resolve)(__dirname, "..", "..", "apps", "local-console", "public"),
2376
+ ];
2377
+ for (const dir of candidates) {
2378
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(dir, "index.html"))) {
2379
+ return dir;
2380
+ }
2381
+ }
2382
+ return candidates[0];
2383
+ }
2384
+ function escapeHtml(text) {
2385
+ return String(text)
2386
+ .replace(/&/g, "&amp;")
2387
+ .replace(/</g, "&lt;")
2388
+ .replace(/>/g, "&gt;")
2389
+ .replace(/"/g, "&quot;")
2390
+ .replace(/'/g, "&#39;");
2391
+ }
2392
+ function shortId(id) {
2393
+ if (!id)
2394
+ return "-";
2395
+ return `${id.slice(0, 10)}...${id.slice(-6)}`;
2396
+ }
2397
+ function ago(ts) {
2398
+ if (!ts)
2399
+ return "-";
2400
+ const seconds = Math.max(0, Math.floor((Date.now() - ts) / 1000));
2401
+ if (seconds < 60)
2402
+ return `${seconds}s ago`;
2403
+ if (seconds < 3600)
2404
+ return `${Math.floor(seconds / 60)}m ago`;
2405
+ return `${Math.floor(seconds / 3600)}h ago`;
2406
+ }
2407
+ function renderBootstrapScript(payload) {
2408
+ const encoded = JSON.stringify(payload).replace(/</g, "\\u003c");
2409
+ return `
2410
+ <script>
2411
+ (() => {
2412
+ const data = ${encoded};
2413
+ if (!data) return;
2414
+ const setText = (id, value) => {
2415
+ const el = document.getElementById(id);
2416
+ if (el) el.textContent = value;
2417
+ };
2418
+ const setHtml = (id, value) => {
2419
+ const el = document.getElementById(id);
2420
+ if (el) el.innerHTML = value;
2421
+ };
2422
+ if (data.integrationStatusText) {
2423
+ const bar = document.getElementById('integrationStatusBar');
2424
+ if (bar) {
2425
+ bar.textContent = data.integrationStatusText;
2426
+ if (data.integrationStatusClassName) bar.className = data.integrationStatusClassName;
2427
+ }
2428
+ }
2429
+ setText('socialStatusLine', data.socialStatusLineText || '');
2430
+ setText('socialStatusSubline', data.socialStatusSublineText || '');
2431
+ setText('brandVersion', data.brandVersionText || '-');
2432
+ setText('snapshot', data.snapshotText || '');
2433
+ setText('heroMode', data.heroModeText || '-');
2434
+ setText('heroAdapter', data.heroAdapterText || '-');
2435
+ setText('heroRelay', data.heroRelayText || '-');
2436
+ setText('heroRoom', data.heroRoomText || '-');
2437
+ setText('pillAdapter', data.pillAdapterText || 'adapter: -');
2438
+ const pillBroadcast = document.getElementById('pillBroadcast');
2439
+ if (pillBroadcast) {
2440
+ pillBroadcast.textContent = data.pillBroadcastText || 'broadcast: -';
2441
+ if (data.pillBroadcastClassName) pillBroadcast.className = data.pillBroadcastClassName;
2442
+ }
2443
+ setHtml('overviewCards', data.overviewCardsHtml || '');
2444
+ setText('agentsCountHint', data.agentsCountHintText || '0 agents');
2445
+ setHtml('agentsWrap', data.agentsWrapHtml || '<div class="label">No discovered agents yet.</div>');
2446
+ })();
2447
+ </script>`;
2448
+ }
2449
+ async function main() {
2450
+ const app = (0, express_1.default)();
2451
+ const port = Number(process.env.PORT || 4310);
2452
+ const staticDir = resolveLocalConsoleStaticDir();
2453
+ const staticIndexFile = (0, path_1.resolve)(staticDir, "index.html");
2454
+ const node = new LocalNodeService();
2455
+ await node.start();
2456
+ app.use((0, cors_1.default)({ origin: true }));
2457
+ app.use(express_1.default.json());
2458
+ app.get("/api/identity", (_req, res) => {
2459
+ sendOk(res, node.getIdentity());
2460
+ });
2461
+ app.post("/api/identity/create", asyncRoute(async (_req, res) => {
2462
+ const identity = await node.ensureIdentity();
2463
+ sendOk(res, identity, { message: "Identity is ready" });
2464
+ }));
2465
+ app.get("/api/profile", (_req, res) => {
2466
+ sendOk(res, node.getProfile());
2467
+ });
2468
+ app.get("/api/public-profile/preview", (_req, res) => {
2469
+ sendOk(res, node.getPublicProfilePreview());
2470
+ });
2471
+ app.get("/api/runtime/paths", (_req, res) => {
2472
+ sendOk(res, node.getRuntimePaths());
2473
+ });
2474
+ app.put("/api/profile", asyncRoute(async (req, res) => {
2475
+ const body = req.body;
2476
+ const tags = Array.isArray(body.tags)
2477
+ ? body.tags.map((tag) => String(tag).trim()).filter(Boolean)
2478
+ : undefined;
2479
+ const profile = await node.updateProfile({
2480
+ ...body,
2481
+ tags,
2482
+ display_name: body.display_name?.toString() ?? undefined,
2483
+ bio: body.bio?.toString() ?? undefined,
2484
+ avatar_url: body.avatar_url?.toString() ?? undefined,
2485
+ public_enabled: typeof body.public_enabled === "boolean" ? body.public_enabled : undefined,
2486
+ });
2487
+ sendOk(res, profile, { message: "Profile saved" });
2488
+ }));
2489
+ app.get("/api/overview", (_req, res) => {
2490
+ sendOk(res, node.getOverview());
2491
+ });
2492
+ app.get("/api/integration/status", (_req, res) => {
2493
+ sendOk(res, node.getIntegrationStatus());
2494
+ });
2495
+ app.get("/api/network", (_req, res) => {
2496
+ sendOk(res, node.getNetworkSummary());
2497
+ });
2498
+ app.get("/api/network/config", (_req, res) => {
2499
+ sendOk(res, node.getNetworkConfig());
2500
+ });
2501
+ app.get("/api/network/stats", (_req, res) => {
2502
+ sendOk(res, node.getNetworkStats());
2503
+ });
2504
+ app.get("/api/skills", (_req, res) => {
2505
+ sendOk(res, node.getSkillsView());
2506
+ });
2507
+ app.post("/api/network/quick-connect-global-preview", asyncRoute(async (req, res) => {
2508
+ const body = (req.body ?? {});
2509
+ const signalingUrl = String(body.signaling_url || "").trim();
2510
+ const room = String(body.room || "").trim();
2511
+ if (!signalingUrl) {
2512
+ sendError(res, 400, "invalid_request", "signaling_url is required");
2513
+ return;
2514
+ }
2515
+ const result = await node.quickConnectGlobalPreview({
2516
+ signaling_url: signalingUrl,
2517
+ room,
2518
+ });
2519
+ sendOk(res, result, { message: "Cross-network preview enabled" });
2520
+ }));
2521
+ app.get("/api/peers", (_req, res) => {
2522
+ sendOk(res, node.getPeersSummary());
2523
+ });
2524
+ app.get("/api/discovery/events", (_req, res) => {
2525
+ sendOk(res, node.getDiscoveryEvents());
2526
+ });
2527
+ (0, socialRoutes_1.registerSocialRoutes)(app, {
2528
+ getSocialConfigView: () => node.getSocialConfigView(),
2529
+ getIntegrationSummary: () => node.getIntegrationSummary(),
2530
+ getMessageGovernanceView: () => node.getMessageGovernanceView(),
2531
+ updateMessageGovernance: (input) => node.updateMessageGovernance(input),
2532
+ exportSocialTemplate: () => node.exportSocialTemplate(),
2533
+ setNetworkModeRuntime: (mode) => node.setNetworkModeRuntime(mode),
2534
+ reloadSocialConfig: () => node.reloadSocialConfig(),
2535
+ generateDefaultSocialMd: () => node.generateDefaultSocialMd(),
2536
+ });
2537
+ app.post("/api/broadcast/start", asyncRoute(async (_req, res) => {
2538
+ const summary = await node.setBroadcastEnabled(true);
2539
+ sendOk(res, summary, { message: "Broadcast started" });
2540
+ }));
2541
+ app.post("/api/public-discovery/enable", asyncRoute(async (_req, res) => {
2542
+ const result = await node.setPublicDiscoveryRuntime(true);
2543
+ sendOk(res, result, { message: "Public discovery enabled (runtime)" });
2544
+ }));
2545
+ app.post("/api/public-discovery/disable", asyncRoute(async (_req, res) => {
2546
+ const result = await node.setPublicDiscoveryRuntime(false);
2547
+ sendOk(res, result, { message: "Public discovery disabled (runtime)" });
2548
+ }));
2549
+ app.post("/api/broadcast/stop", asyncRoute(async (_req, res) => {
2550
+ const summary = await node.setBroadcastEnabled(false);
2551
+ sendOk(res, summary, { message: "Broadcast stopped" });
2552
+ }));
2553
+ app.post("/api/broadcast/now", asyncRoute(async (_req, res) => {
2554
+ const result = await node.broadcastNow("manual_button");
2555
+ sendOk(res, result, {
2556
+ message: result.sent ? "Broadcast published" : `Broadcast skipped: ${result.reason}`,
2557
+ });
2558
+ }));
2559
+ app.post("/api/messages/broadcast", asyncRoute(async (req, res) => {
2560
+ const body = String(req.body?.body || "");
2561
+ const topic = String(req.body?.topic || DEFAULT_SOCIAL_MESSAGE_CHANNEL);
2562
+ const result = await node.sendSocialMessage(body, topic);
2563
+ sendOk(res, result, {
2564
+ message: result.sent ? "Message broadcast published" : `Message broadcast skipped: ${result.reason}`,
2565
+ });
2566
+ }));
2567
+ app.get("/api/messages", (req, res) => {
2568
+ const limit = Number(req.query.limit ?? 50);
2569
+ const agentId = String(req.query.agent_id ?? "").trim();
2570
+ sendOk(res, node.getSocialMessages(limit, { agent_id: agentId || null }));
2571
+ });
2572
+ app.get("/api/openclaw/bridge", (_req, res) => {
2573
+ sendOk(res, node.getOpenClawBridgeStatus());
2574
+ });
2575
+ app.get("/api/openclaw/bridge/config", (_req, res) => {
2576
+ sendOk(res, node.getOpenClawBridgeConfig());
2577
+ });
2578
+ app.get("/api/openclaw/bridge/profile", (_req, res) => {
2579
+ sendOk(res, node.getOpenClawBridgeProfile());
2580
+ });
2581
+ app.get("/api/openclaw/bridge/messages", (req, res) => {
2582
+ const limit = Number(req.query.limit ?? 50);
2583
+ const agentId = String(req.query.agent_id ?? "").trim();
2584
+ sendOk(res, node.getSocialMessages(limit, { agent_id: agentId || null }));
2585
+ });
2586
+ app.post("/api/openclaw/bridge/message", asyncRoute(async (req, res) => {
2587
+ const body = String(req.body?.body || "");
2588
+ const topic = String(req.body?.topic || DEFAULT_SOCIAL_MESSAGE_CHANNEL);
2589
+ const result = await node.sendSocialMessage(body, topic);
2590
+ sendOk(res, result, {
2591
+ message: result.sent ? "OpenClaw bridge message published" : `OpenClaw bridge message skipped: ${result.reason}`,
2592
+ });
2593
+ }));
2594
+ app.post("/api/openclaw/bridge/skill-install", asyncRoute(async (_req, res) => {
2595
+ try {
2596
+ const result = await node.installOpenClawSkill();
2597
+ sendOk(res, result, {
2598
+ message: "OpenClaw skill installed",
2599
+ });
2600
+ }
2601
+ catch (error) {
2602
+ sendError(res, 500, "OPENCLAW_SKILL_INSTALL_FAILED", error instanceof Error ? error.message : "OpenClaw skill install failed");
2603
+ }
2604
+ }));
2605
+ app.post("/api/cache/refresh", asyncRoute(async (_req, res) => {
2606
+ const result = await node.refreshCache();
2607
+ sendOk(res, result, { message: "Cache refreshed" });
2608
+ }));
2609
+ app.post("/api/cache/clear", asyncRoute(async (_req, res) => {
2610
+ const result = await node.clearDiscoveredCache();
2611
+ sendOk(res, result, { message: "Discovered cache cleared (self profile kept)" });
2612
+ }));
2613
+ app.get("/api/logs", asyncRoute(async (_req, res) => {
2614
+ sendOk(res, await node.getLogs());
2615
+ }));
2616
+ app.get("/api/search", (req, res) => {
2617
+ const q = String(req.query.q ?? "");
2618
+ sendOk(res, node.search(q));
2619
+ });
2620
+ app.get("/api/agents/:agentId", (req, res) => {
2621
+ const state = node.getDirectory();
2622
+ const agentId = req.params.agentId;
2623
+ const profile = state.profiles[agentId];
2624
+ if (!profile) {
2625
+ sendError(res, 404, "AGENT_NOT_FOUND", "Agent not found", { agent_id: agentId });
2626
+ return;
2627
+ }
2628
+ const lastSeenAt = state.presence[agentId] ?? 0;
2629
+ const summary = node.getAgentPublicSummary(agentId);
2630
+ sendOk(res, {
2631
+ profile,
2632
+ summary,
2633
+ last_seen_at: summary?.last_seen_at ?? null,
2634
+ online: (0, core_1.isAgentOnline)(lastSeenAt, Date.now(), PRESENCE_TTL_MS),
2635
+ presence_ttl_ms: PRESENCE_TTL_MS,
2636
+ });
2637
+ });
2638
+ app.get("/api/health", (_req, res) => {
2639
+ sendOk(res, { ok: true });
2640
+ });
2641
+ app.get(["/", "/index.html"], (_req, res) => {
2642
+ const overview = node.getOverview();
2643
+ const discovered = node.search("");
2644
+ const network = node.getNetworkConfig();
2645
+ const integration = node.getIntegrationStatus();
2646
+ const overviewCardsHtml = [
2647
+ ["Discovered", overview.discovered_count],
2648
+ ["Online", overview.online_count],
2649
+ ["Offline", overview.offline_count],
2650
+ ["Presence TTL", `${Math.floor(overview.presence_ttl_ms / 1000)}s`],
2651
+ ]
2652
+ .map(([k, v]) => `<div class="card"><div class="label">${escapeHtml(String(k))}</div><div class="value">${escapeHtml(String(v))}</div></div>`)
2653
+ .join("");
2654
+ const agentsWrapHtml = discovered.length === 0
2655
+ ? `<div class="label">No discovered agents yet.</div>`
2656
+ : `
2657
+ <table class="table">
2658
+ <thead><tr><th>Name</th><th>Agent ID</th><th>Status</th><th>Updated</th></tr></thead>
2659
+ <tbody>
2660
+ ${discovered
2661
+ .map((agent) => `
2662
+ <tr>
2663
+ <td>${escapeHtml(agent.display_name || "Unnamed")}</td>
2664
+ <td class="mono">${escapeHtml(shortId(agent.agent_id || ""))}</td>
2665
+ <td class="${agent.online ? "online" : "offline"}">${agent.online ? "online" : "offline"}</td>
2666
+ <td>${escapeHtml(ago(agent.updated_at))}</td>
2667
+ </tr>`)
2668
+ .join("")}
2669
+ </tbody>
2670
+ </table>
2671
+ `;
2672
+ const payload = {
2673
+ brandVersionText: overview.app_version ? `v${overview.app_version}` : "-",
2674
+ snapshotText: [
2675
+ `app_version: ${overview.app_version || "-"}`,
2676
+ `agent_id: ${overview.agent_id || "-"}`,
2677
+ `public_enabled: ${overview.public_enabled}`,
2678
+ `broadcast_enabled: ${overview.broadcast_enabled}`,
2679
+ `last_broadcast: ${ago(overview.last_broadcast_at)}`,
2680
+ ].join("\n"),
2681
+ heroModeText: overview.social?.network_mode || "-",
2682
+ heroAdapterText: network.adapter || "-",
2683
+ heroRelayText: network.adapter_extra?.signaling_url || "-",
2684
+ heroRoomText: network.adapter_extra?.room || "-",
2685
+ pillAdapterText: `adapter: ${network.adapter || "-"}`,
2686
+ pillBroadcastText: overview.broadcast_enabled ? "broadcast: running" : "broadcast: paused",
2687
+ pillBroadcastClassName: `pill ${overview.broadcast_enabled ? "ok" : "warn"}`,
2688
+ overviewCardsHtml,
2689
+ agentsCountHintText: `${discovered.length} agents discovered`,
2690
+ agentsWrapHtml,
2691
+ integrationStatusText: `Connected to SilicaClaw: ${integration.connected_to_silicaclaw ? "yes" : "no"} · Network mode: ${integration.network_mode || "-"} · Public discovery: ${integration.public_enabled ? "enabled" : "disabled"}`,
2692
+ integrationStatusClassName: `integration-strip ${integration.connected_to_silicaclaw && integration.public_enabled ? "ok" : "warn"}`,
2693
+ socialStatusLineText: integration.status_line || "",
2694
+ socialStatusSublineText: `Connected to SilicaClaw · ${integration.public_enabled ? "Public discovery enabled" : "Public discovery disabled"} · mode ${integration.network_mode || "-"}`,
2695
+ };
2696
+ let html = (0, fs_1.readFileSync)(staticIndexFile, "utf8");
2697
+ html = html.replace("</body>", `${renderBootstrapScript(payload)}\n</body>`);
2698
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
2699
+ res.send(html);
2700
+ });
2701
+ app.use(express_1.default.static(staticDir));
2702
+ app.use((error, _req, res, _next) => {
2703
+ const message = error instanceof Error ? error.message : "Unknown error";
2704
+ sendError(res, 500, "INTERNAL_ERROR", message);
2705
+ });
2706
+ app.listen(port, () => {
2707
+ // eslint-disable-next-line no-console
2708
+ console.log(`SilicaClaw local-console running: http://localhost:${port}`);
2709
+ });
2710
+ process.on("SIGINT", async () => {
2711
+ await node.stop();
2712
+ process.exit(0);
2713
+ });
2714
+ }
2715
+ if (require.main === module) {
2716
+ main().catch((error) => {
2717
+ // eslint-disable-next-line no-console
2718
+ console.error(error);
2719
+ process.exit(1);
2720
+ });
2721
+ }