opclawtm 1.4.0

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 (350) hide show
  1. package/README.md +136 -0
  2. package/dist/bin/team-manager.d.ts +6 -0
  3. package/dist/bin/team-manager.d.ts.map +1 -0
  4. package/dist/bin/team-manager.js +36 -0
  5. package/dist/bin/team-manager.js.map +1 -0
  6. package/dist/bin/team-setup.d.ts +7 -0
  7. package/dist/bin/team-setup.d.ts.map +1 -0
  8. package/dist/bin/team-setup.js +66 -0
  9. package/dist/bin/team-setup.js.map +1 -0
  10. package/dist/bin/team-uninstall.d.ts +6 -0
  11. package/dist/bin/team-uninstall.d.ts.map +1 -0
  12. package/dist/bin/team-uninstall.js +91 -0
  13. package/dist/bin/team-uninstall.js.map +1 -0
  14. package/dist/cli/commands/agent.command.d.ts +43 -0
  15. package/dist/cli/commands/agent.command.d.ts.map +1 -0
  16. package/dist/cli/commands/agent.command.js +223 -0
  17. package/dist/cli/commands/agent.command.js.map +1 -0
  18. package/dist/cli/commands/checklist.command.d.ts +35 -0
  19. package/dist/cli/commands/checklist.command.d.ts.map +1 -0
  20. package/dist/cli/commands/checklist.command.js +77 -0
  21. package/dist/cli/commands/checklist.command.js.map +1 -0
  22. package/dist/cli/commands/dept.command.d.ts +32 -0
  23. package/dist/cli/commands/dept.command.d.ts.map +1 -0
  24. package/dist/cli/commands/dept.command.js +92 -0
  25. package/dist/cli/commands/dept.command.js.map +1 -0
  26. package/dist/cli/commands/document.command.d.ts +37 -0
  27. package/dist/cli/commands/document.command.d.ts.map +1 -0
  28. package/dist/cli/commands/document.command.js +146 -0
  29. package/dist/cli/commands/document.command.js.map +1 -0
  30. package/dist/cli/commands/domain.command.d.ts +36 -0
  31. package/dist/cli/commands/domain.command.d.ts.map +1 -0
  32. package/dist/cli/commands/domain.command.js +97 -0
  33. package/dist/cli/commands/domain.command.js.map +1 -0
  34. package/dist/cli/commands/feishu.command.d.ts +63 -0
  35. package/dist/cli/commands/feishu.command.d.ts.map +1 -0
  36. package/dist/cli/commands/feishu.command.js +433 -0
  37. package/dist/cli/commands/feishu.command.js.map +1 -0
  38. package/dist/cli/commands/job.command.d.ts +39 -0
  39. package/dist/cli/commands/job.command.d.ts.map +1 -0
  40. package/dist/cli/commands/job.command.js +168 -0
  41. package/dist/cli/commands/job.command.js.map +1 -0
  42. package/dist/cli/commands/license.command.d.ts +22 -0
  43. package/dist/cli/commands/license.command.d.ts.map +1 -0
  44. package/dist/cli/commands/license.command.js +68 -0
  45. package/dist/cli/commands/license.command.js.map +1 -0
  46. package/dist/cli/commands/message-failure.command.d.ts +44 -0
  47. package/dist/cli/commands/message-failure.command.d.ts.map +1 -0
  48. package/dist/cli/commands/message-failure.command.js +137 -0
  49. package/dist/cli/commands/message-failure.command.js.map +1 -0
  50. package/dist/cli/commands/message.command.d.ts +47 -0
  51. package/dist/cli/commands/message.command.d.ts.map +1 -0
  52. package/dist/cli/commands/message.command.js +129 -0
  53. package/dist/cli/commands/message.command.js.map +1 -0
  54. package/dist/cli/commands/node.command.d.ts +76 -0
  55. package/dist/cli/commands/node.command.d.ts.map +1 -0
  56. package/dist/cli/commands/node.command.js +251 -0
  57. package/dist/cli/commands/node.command.js.map +1 -0
  58. package/dist/cli/commands/role-flow.command.d.ts +12 -0
  59. package/dist/cli/commands/role-flow.command.d.ts.map +1 -0
  60. package/dist/cli/commands/role-flow.command.js +54 -0
  61. package/dist/cli/commands/role-flow.command.js.map +1 -0
  62. package/dist/cli/commands/skill-pack.command.d.ts +41 -0
  63. package/dist/cli/commands/skill-pack.command.d.ts.map +1 -0
  64. package/dist/cli/commands/skill-pack.command.js +137 -0
  65. package/dist/cli/commands/skill-pack.command.js.map +1 -0
  66. package/dist/cli/commands/status.command.d.ts +8 -0
  67. package/dist/cli/commands/status.command.d.ts.map +1 -0
  68. package/dist/cli/commands/status.command.js +61 -0
  69. package/dist/cli/commands/status.command.js.map +1 -0
  70. package/dist/cli/commands/task.command.d.ts +105 -0
  71. package/dist/cli/commands/task.command.d.ts.map +1 -0
  72. package/dist/cli/commands/task.command.js +402 -0
  73. package/dist/cli/commands/task.command.js.map +1 -0
  74. package/dist/cli/commands/user.command.d.ts +43 -0
  75. package/dist/cli/commands/user.command.d.ts.map +1 -0
  76. package/dist/cli/commands/user.command.js +134 -0
  77. package/dist/cli/commands/user.command.js.map +1 -0
  78. package/dist/cli/index.d.ts +7 -0
  79. package/dist/cli/index.d.ts.map +1 -0
  80. package/dist/cli/index.js +863 -0
  81. package/dist/cli/index.js.map +1 -0
  82. package/dist/cli/tui/index.d.ts +45 -0
  83. package/dist/cli/tui/index.d.ts.map +1 -0
  84. package/dist/cli/tui/index.js +470 -0
  85. package/dist/cli/tui/index.js.map +1 -0
  86. package/dist/cli/tui/menus/agent-manage.menu.d.ts +8 -0
  87. package/dist/cli/tui/menus/agent-manage.menu.d.ts.map +1 -0
  88. package/dist/cli/tui/menus/agent-manage.menu.js +614 -0
  89. package/dist/cli/tui/menus/agent-manage.menu.js.map +1 -0
  90. package/dist/cli/tui/menus/dept-manage.menu.d.ts +8 -0
  91. package/dist/cli/tui/menus/dept-manage.menu.d.ts.map +1 -0
  92. package/dist/cli/tui/menus/dept-manage.menu.js +299 -0
  93. package/dist/cli/tui/menus/dept-manage.menu.js.map +1 -0
  94. package/dist/cli/tui/menus/domain-manage.menu.d.ts +8 -0
  95. package/dist/cli/tui/menus/domain-manage.menu.d.ts.map +1 -0
  96. package/dist/cli/tui/menus/domain-manage.menu.js +208 -0
  97. package/dist/cli/tui/menus/domain-manage.menu.js.map +1 -0
  98. package/dist/cli/tui/menus/feishu.menu.d.ts +8 -0
  99. package/dist/cli/tui/menus/feishu.menu.d.ts.map +1 -0
  100. package/dist/cli/tui/menus/feishu.menu.js +1727 -0
  101. package/dist/cli/tui/menus/feishu.menu.js.map +1 -0
  102. package/dist/cli/tui/menus/job-manage.menu.d.ts +16 -0
  103. package/dist/cli/tui/menus/job-manage.menu.d.ts.map +1 -0
  104. package/dist/cli/tui/menus/job-manage.menu.js +734 -0
  105. package/dist/cli/tui/menus/job-manage.menu.js.map +1 -0
  106. package/dist/cli/tui/menus/license.menu.d.ts +12 -0
  107. package/dist/cli/tui/menus/license.menu.d.ts.map +1 -0
  108. package/dist/cli/tui/menus/license.menu.js +164 -0
  109. package/dist/cli/tui/menus/license.menu.js.map +1 -0
  110. package/dist/cli/tui/menus/main.menu.d.ts +10 -0
  111. package/dist/cli/tui/menus/main.menu.d.ts.map +1 -0
  112. package/dist/cli/tui/menus/main.menu.js +94 -0
  113. package/dist/cli/tui/menus/main.menu.js.map +1 -0
  114. package/dist/cli/tui/menus/reset.menu.d.ts +10 -0
  115. package/dist/cli/tui/menus/reset.menu.d.ts.map +1 -0
  116. package/dist/cli/tui/menus/reset.menu.js +767 -0
  117. package/dist/cli/tui/menus/reset.menu.js.map +1 -0
  118. package/dist/cli/tui/menus/status.menu.d.ts +8 -0
  119. package/dist/cli/tui/menus/status.menu.d.ts.map +1 -0
  120. package/dist/cli/tui/menus/status.menu.js +123 -0
  121. package/dist/cli/tui/menus/status.menu.js.map +1 -0
  122. package/dist/cli/tui/menus/task-manage.menu.d.ts +11 -0
  123. package/dist/cli/tui/menus/task-manage.menu.d.ts.map +1 -0
  124. package/dist/cli/tui/menus/task-manage.menu.js +129 -0
  125. package/dist/cli/tui/menus/task-manage.menu.js.map +1 -0
  126. package/dist/cli/tui/menus/team-create.menu.d.ts +8 -0
  127. package/dist/cli/tui/menus/team-create.menu.d.ts.map +1 -0
  128. package/dist/cli/tui/menus/team-create.menu.js +353 -0
  129. package/dist/cli/tui/menus/team-create.menu.js.map +1 -0
  130. package/dist/config.d.ts +9 -0
  131. package/dist/config.d.ts.map +1 -0
  132. package/dist/config.js +74 -0
  133. package/dist/config.js.map +1 -0
  134. package/dist/core/auth/index.d.ts +6 -0
  135. package/dist/core/auth/index.d.ts.map +1 -0
  136. package/dist/core/auth/index.js +22 -0
  137. package/dist/core/auth/index.js.map +1 -0
  138. package/dist/core/auth/middleware.d.ts +73 -0
  139. package/dist/core/auth/middleware.d.ts.map +1 -0
  140. package/dist/core/auth/middleware.js +456 -0
  141. package/dist/core/auth/middleware.js.map +1 -0
  142. package/dist/core/auth/storage.d.ts +38 -0
  143. package/dist/core/auth/storage.d.ts.map +1 -0
  144. package/dist/core/auth/storage.js +280 -0
  145. package/dist/core/auth/storage.js.map +1 -0
  146. package/dist/core/keys/public.pem +9 -0
  147. package/dist/core/models/types.d.ts +426 -0
  148. package/dist/core/models/types.d.ts.map +1 -0
  149. package/dist/core/models/types.js +9 -0
  150. package/dist/core/models/types.js.map +1 -0
  151. package/dist/core/services/agent-template.service.d.ts +49 -0
  152. package/dist/core/services/agent-template.service.d.ts.map +1 -0
  153. package/dist/core/services/agent-template.service.js +88 -0
  154. package/dist/core/services/agent-template.service.js.map +1 -0
  155. package/dist/core/services/agent.service.d.ts +120 -0
  156. package/dist/core/services/agent.service.d.ts.map +1 -0
  157. package/dist/core/services/agent.service.js +381 -0
  158. package/dist/core/services/agent.service.js.map +1 -0
  159. package/dist/core/services/auth-profiles.service.d.ts +93 -0
  160. package/dist/core/services/auth-profiles.service.d.ts.map +1 -0
  161. package/dist/core/services/auth-profiles.service.js +220 -0
  162. package/dist/core/services/auth-profiles.service.js.map +1 -0
  163. package/dist/core/services/checklist.service.d.ts +58 -0
  164. package/dist/core/services/checklist.service.d.ts.map +1 -0
  165. package/dist/core/services/checklist.service.js +240 -0
  166. package/dist/core/services/checklist.service.js.map +1 -0
  167. package/dist/core/services/config-tracker.service.d.ts +119 -0
  168. package/dist/core/services/config-tracker.service.d.ts.map +1 -0
  169. package/dist/core/services/config-tracker.service.js +1093 -0
  170. package/dist/core/services/config-tracker.service.js.map +1 -0
  171. package/dist/core/services/crypto.service.d.ts +102 -0
  172. package/dist/core/services/crypto.service.d.ts.map +1 -0
  173. package/dist/core/services/crypto.service.js +377 -0
  174. package/dist/core/services/crypto.service.js.map +1 -0
  175. package/dist/core/services/dept.service.d.ts +92 -0
  176. package/dist/core/services/dept.service.d.ts.map +1 -0
  177. package/dist/core/services/dept.service.js +260 -0
  178. package/dist/core/services/dept.service.js.map +1 -0
  179. package/dist/core/services/document.service.d.ts +131 -0
  180. package/dist/core/services/document.service.d.ts.map +1 -0
  181. package/dist/core/services/document.service.js +368 -0
  182. package/dist/core/services/document.service.js.map +1 -0
  183. package/dist/core/services/domain.service.d.ts +50 -0
  184. package/dist/core/services/domain.service.d.ts.map +1 -0
  185. package/dist/core/services/domain.service.js +98 -0
  186. package/dist/core/services/domain.service.js.map +1 -0
  187. package/dist/core/services/feishu.service.d.ts +124 -0
  188. package/dist/core/services/feishu.service.d.ts.map +1 -0
  189. package/dist/core/services/feishu.service.js +165 -0
  190. package/dist/core/services/feishu.service.js.map +1 -0
  191. package/dist/core/services/index.d.ts +27 -0
  192. package/dist/core/services/index.d.ts.map +1 -0
  193. package/dist/core/services/index.js +89 -0
  194. package/dist/core/services/index.js.map +1 -0
  195. package/dist/core/services/job.service.d.ts +60 -0
  196. package/dist/core/services/job.service.d.ts.map +1 -0
  197. package/dist/core/services/job.service.js +190 -0
  198. package/dist/core/services/job.service.js.map +1 -0
  199. package/dist/core/services/log.service.d.ts +111 -0
  200. package/dist/core/services/log.service.d.ts.map +1 -0
  201. package/dist/core/services/log.service.js +237 -0
  202. package/dist/core/services/log.service.js.map +1 -0
  203. package/dist/core/services/message-failure.service.d.ts +65 -0
  204. package/dist/core/services/message-failure.service.d.ts.map +1 -0
  205. package/dist/core/services/message-failure.service.js +112 -0
  206. package/dist/core/services/message-failure.service.js.map +1 -0
  207. package/dist/core/services/message.service.d.ts +122 -0
  208. package/dist/core/services/message.service.d.ts.map +1 -0
  209. package/dist/core/services/message.service.js +374 -0
  210. package/dist/core/services/message.service.js.map +1 -0
  211. package/dist/core/services/node.service.d.ts +150 -0
  212. package/dist/core/services/node.service.d.ts.map +1 -0
  213. package/dist/core/services/node.service.js +257 -0
  214. package/dist/core/services/node.service.js.map +1 -0
  215. package/dist/core/services/openclaw-config.service.d.ts +187 -0
  216. package/dist/core/services/openclaw-config.service.d.ts.map +1 -0
  217. package/dist/core/services/openclaw-config.service.js +268 -0
  218. package/dist/core/services/openclaw-config.service.js.map +1 -0
  219. package/dist/core/services/preset-loader.service.d.ts +80 -0
  220. package/dist/core/services/preset-loader.service.d.ts.map +1 -0
  221. package/dist/core/services/preset-loader.service.js +379 -0
  222. package/dist/core/services/preset-loader.service.js.map +1 -0
  223. package/dist/core/services/role-flow.service.d.ts +21 -0
  224. package/dist/core/services/role-flow.service.d.ts.map +1 -0
  225. package/dist/core/services/role-flow.service.js +47 -0
  226. package/dist/core/services/role-flow.service.js.map +1 -0
  227. package/dist/core/services/setup.service.d.ts +46 -0
  228. package/dist/core/services/setup.service.d.ts.map +1 -0
  229. package/dist/core/services/setup.service.js +336 -0
  230. package/dist/core/services/setup.service.js.map +1 -0
  231. package/dist/core/services/skill-pack.service.d.ts +56 -0
  232. package/dist/core/services/skill-pack.service.d.ts.map +1 -0
  233. package/dist/core/services/skill-pack.service.js +113 -0
  234. package/dist/core/services/skill-pack.service.js.map +1 -0
  235. package/dist/core/services/task.service.d.ts +177 -0
  236. package/dist/core/services/task.service.d.ts.map +1 -0
  237. package/dist/core/services/task.service.js +397 -0
  238. package/dist/core/services/task.service.js.map +1 -0
  239. package/dist/core/services/template.service.d.ts +51 -0
  240. package/dist/core/services/template.service.d.ts.map +1 -0
  241. package/dist/core/services/template.service.js +88 -0
  242. package/dist/core/services/template.service.js.map +1 -0
  243. package/dist/core/services/user.service.d.ts +50 -0
  244. package/dist/core/services/user.service.d.ts.map +1 -0
  245. package/dist/core/services/user.service.js +111 -0
  246. package/dist/core/services/user.service.js.map +1 -0
  247. package/dist/core/utils/agent-guide-generator.d.ts +38 -0
  248. package/dist/core/utils/agent-guide-generator.d.ts.map +1 -0
  249. package/dist/core/utils/agent-guide-generator.js +187 -0
  250. package/dist/core/utils/agent-guide-generator.js.map +1 -0
  251. package/dist/core/utils/credentials-cleanup.d.ts +81 -0
  252. package/dist/core/utils/credentials-cleanup.d.ts.map +1 -0
  253. package/dist/core/utils/credentials-cleanup.js +256 -0
  254. package/dist/core/utils/credentials-cleanup.js.map +1 -0
  255. package/dist/core/utils/index.d.ts +215 -0
  256. package/dist/core/utils/index.d.ts.map +1 -0
  257. package/dist/core/utils/index.js +462 -0
  258. package/dist/core/utils/index.js.map +1 -0
  259. package/dist/core/utils/openclaw-helper.d.ts +250 -0
  260. package/dist/core/utils/openclaw-helper.d.ts.map +1 -0
  261. package/dist/core/utils/openclaw-helper.js +1629 -0
  262. package/dist/core/utils/openclaw-helper.js.map +1 -0
  263. package/dist/core/utils/template-generator.d.ts +67 -0
  264. package/dist/core/utils/template-generator.d.ts.map +1 -0
  265. package/dist/core/utils/template-generator.js +170 -0
  266. package/dist/core/utils/template-generator.js.map +1 -0
  267. package/dist/db/index.d.ts +54 -0
  268. package/dist/db/index.d.ts.map +1 -0
  269. package/dist/db/index.js +403 -0
  270. package/dist/db/index.js.map +1 -0
  271. package/dist/db/repositories/agent-template.repo.d.ts +47 -0
  272. package/dist/db/repositories/agent-template.repo.d.ts.map +1 -0
  273. package/dist/db/repositories/agent-template.repo.js +108 -0
  274. package/dist/db/repositories/agent-template.repo.js.map +1 -0
  275. package/dist/db/repositories/agent.repo.d.ts +64 -0
  276. package/dist/db/repositories/agent.repo.d.ts.map +1 -0
  277. package/dist/db/repositories/agent.repo.js +103 -0
  278. package/dist/db/repositories/agent.repo.js.map +1 -0
  279. package/dist/db/repositories/base.repository.d.ts +51 -0
  280. package/dist/db/repositories/base.repository.d.ts.map +1 -0
  281. package/dist/db/repositories/base.repository.js +107 -0
  282. package/dist/db/repositories/base.repository.js.map +1 -0
  283. package/dist/db/repositories/company.repo.d.ts +18 -0
  284. package/dist/db/repositories/company.repo.d.ts.map +1 -0
  285. package/dist/db/repositories/company.repo.js +33 -0
  286. package/dist/db/repositories/company.repo.js.map +1 -0
  287. package/dist/db/repositories/config-change.repo.d.ts +65 -0
  288. package/dist/db/repositories/config-change.repo.d.ts.map +1 -0
  289. package/dist/db/repositories/config-change.repo.js +119 -0
  290. package/dist/db/repositories/config-change.repo.js.map +1 -0
  291. package/dist/db/repositories/dept.repo.d.ts +37 -0
  292. package/dist/db/repositories/dept.repo.d.ts.map +1 -0
  293. package/dist/db/repositories/dept.repo.js +66 -0
  294. package/dist/db/repositories/dept.repo.js.map +1 -0
  295. package/dist/db/repositories/document.repo.d.ts +25 -0
  296. package/dist/db/repositories/document.repo.d.ts.map +1 -0
  297. package/dist/db/repositories/document.repo.js +51 -0
  298. package/dist/db/repositories/document.repo.js.map +1 -0
  299. package/dist/db/repositories/domain.repo.d.ts +42 -0
  300. package/dist/db/repositories/domain.repo.d.ts.map +1 -0
  301. package/dist/db/repositories/domain.repo.js +79 -0
  302. package/dist/db/repositories/domain.repo.js.map +1 -0
  303. package/dist/db/repositories/index.d.ts +24 -0
  304. package/dist/db/repositories/index.d.ts.map +1 -0
  305. package/dist/db/repositories/index.js +81 -0
  306. package/dist/db/repositories/index.js.map +1 -0
  307. package/dist/db/repositories/init-session.repo.d.ts +38 -0
  308. package/dist/db/repositories/init-session.repo.d.ts.map +1 -0
  309. package/dist/db/repositories/init-session.repo.js +112 -0
  310. package/dist/db/repositories/init-session.repo.js.map +1 -0
  311. package/dist/db/repositories/job.repo.d.ts +54 -0
  312. package/dist/db/repositories/job.repo.d.ts.map +1 -0
  313. package/dist/db/repositories/job.repo.js +119 -0
  314. package/dist/db/repositories/job.repo.js.map +1 -0
  315. package/dist/db/repositories/message-failure.repo.d.ts +92 -0
  316. package/dist/db/repositories/message-failure.repo.d.ts.map +1 -0
  317. package/dist/db/repositories/message-failure.repo.js +141 -0
  318. package/dist/db/repositories/message-failure.repo.js.map +1 -0
  319. package/dist/db/repositories/message-log.repo.d.ts +36 -0
  320. package/dist/db/repositories/message-log.repo.d.ts.map +1 -0
  321. package/dist/db/repositories/message-log.repo.js +64 -0
  322. package/dist/db/repositories/message-log.repo.js.map +1 -0
  323. package/dist/db/repositories/node.repo.d.ts +107 -0
  324. package/dist/db/repositories/node.repo.d.ts.map +1 -0
  325. package/dist/db/repositories/node.repo.js +276 -0
  326. package/dist/db/repositories/node.repo.js.map +1 -0
  327. package/dist/db/repositories/role-flow.repo.d.ts +43 -0
  328. package/dist/db/repositories/role-flow.repo.d.ts.map +1 -0
  329. package/dist/db/repositories/role-flow.repo.js +83 -0
  330. package/dist/db/repositories/role-flow.repo.js.map +1 -0
  331. package/dist/db/repositories/skill-pack.repo.d.ts +45 -0
  332. package/dist/db/repositories/skill-pack.repo.d.ts.map +1 -0
  333. package/dist/db/repositories/skill-pack.repo.js +149 -0
  334. package/dist/db/repositories/skill-pack.repo.js.map +1 -0
  335. package/dist/db/repositories/task.repo.d.ts +168 -0
  336. package/dist/db/repositories/task.repo.d.ts.map +1 -0
  337. package/dist/db/repositories/task.repo.js +381 -0
  338. package/dist/db/repositories/task.repo.js.map +1 -0
  339. package/dist/db/repositories/template.repo.d.ts +40 -0
  340. package/dist/db/repositories/template.repo.d.ts.map +1 -0
  341. package/dist/db/repositories/template.repo.js +66 -0
  342. package/dist/db/repositories/template.repo.js.map +1 -0
  343. package/dist/db/repositories/user.repo.d.ts +46 -0
  344. package/dist/db/repositories/user.repo.d.ts.map +1 -0
  345. package/dist/db/repositories/user.repo.js +75 -0
  346. package/dist/db/repositories/user.repo.js.map +1 -0
  347. package/dist/db/schema.sql +364 -0
  348. package/package.json +90 -0
  349. package/resources/preset-data-hash.enc +1 -0
  350. package/resources/preset-data.enc +1 -0
@@ -0,0 +1,1093 @@
1
+ "use strict";
2
+ /**
3
+ * Config Tracker Service
4
+ *
5
+ * Responsible for recording and reverting configuration changes
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.setCurrentSession = setCurrentSession;
42
+ exports.getCurrentSession = getCurrentSession;
43
+ exports.recordAgentCreate = recordAgentCreate;
44
+ exports.recordAgentDelete = recordAgentDelete;
45
+ exports.recordAgentAllowListChange = recordAgentAllowListChange;
46
+ exports.recordAgentToAgentChange = recordAgentToAgentChange;
47
+ exports.recordBindingCreate = recordBindingCreate;
48
+ exports.recordBindingDelete = recordBindingDelete;
49
+ exports.recordConfigChange = recordConfigChange;
50
+ exports.recordGatewayConfigChange = recordGatewayConfigChange;
51
+ exports.recordFeishuConfig = recordFeishuConfig;
52
+ exports.recordSkillPackCreate = recordSkillPackCreate;
53
+ exports.recordSkillPackDelete = recordSkillPackDelete;
54
+ exports.recordJobCreate = recordJobCreate;
55
+ exports.recordJobDelete = recordJobDelete;
56
+ exports.recordDirectoryCreate = recordDirectoryCreate;
57
+ exports.recordFeishuGroupBind = recordFeishuGroupBind;
58
+ exports.recordFeishuGroupUnbind = recordFeishuGroupUnbind;
59
+ exports.revertSessionConfigChanges = revertSessionConfigChanges;
60
+ exports.revertAllConfigChanges = revertAllConfigChanges;
61
+ exports.getChangesSummary = getChangesSummary;
62
+ const fs = __importStar(require("fs"));
63
+ const path = __importStar(require("path"));
64
+ const os = __importStar(require("os"));
65
+ const utils_1 = require("../../core/utils");
66
+ const configChangeRepo = __importStar(require("../../db/repositories/config-change.repo"));
67
+ // Current session ID (stored in memory)
68
+ let currentSessionId = null;
69
+ /**
70
+ * Set current session ID
71
+ */
72
+ function setCurrentSession(sessionId) {
73
+ currentSessionId = sessionId;
74
+ }
75
+ /**
76
+ * Get current session ID
77
+ */
78
+ function getCurrentSession() {
79
+ return currentSessionId;
80
+ }
81
+ /**
82
+ * Record agent creation
83
+ */
84
+ function recordAgentCreate(agentId, agentConfig) {
85
+ if (!currentSessionId) {
86
+ console.warn('警告:未设置会话ID,无法记录变更');
87
+ return;
88
+ }
89
+ configChangeRepo.recordChange(currentSessionId, {
90
+ change_type: 'agent_create',
91
+ target_type: 'agents.list',
92
+ target_path: `agents.list[?(@.id==='${agentId}')]`,
93
+ action: 'add',
94
+ new_value: JSON.stringify(agentConfig),
95
+ related_id: agentId,
96
+ description: `创建 Agent: ${agentConfig.name || agentId}`
97
+ });
98
+ }
99
+ /**
100
+ * Record agent deletion
101
+ */
102
+ function recordAgentDelete(agentId, oldConfig) {
103
+ if (!currentSessionId) {
104
+ console.warn('警告:未设置会话ID,无法记录变更');
105
+ return;
106
+ }
107
+ configChangeRepo.recordChange(currentSessionId, {
108
+ change_type: 'agent_delete',
109
+ target_type: 'agents.list',
110
+ target_path: `agents.list[?(@.id==='${agentId}')]`,
111
+ action: 'remove',
112
+ old_value: JSON.stringify(oldConfig),
113
+ related_id: agentId,
114
+ description: `删除 Agent: ${oldConfig.name || agentId}`
115
+ });
116
+ }
117
+ /**
118
+ * Record agent allow list change (legacy, for backward compatibility)
119
+ *
120
+ * Records changes to agents.list[].subagents.allowAgents
121
+ * @deprecated Use recordAgentToAgentChange instead
122
+ */
123
+ function recordAgentAllowListChange(agentId, oldAllowList, newAllowList, reason) {
124
+ if (!currentSessionId)
125
+ return;
126
+ configChangeRepo.recordChange(currentSessionId, {
127
+ change_type: 'agent_allow_list_update',
128
+ target_type: 'agents.list.allow_agents',
129
+ target_path: `agents.list[${agentId}].subagents.allowAgents`,
130
+ action: 'update',
131
+ old_value: JSON.stringify(oldAllowList),
132
+ new_value: JSON.stringify(newAllowList),
133
+ related_id: agentId,
134
+ description: reason
135
+ });
136
+ }
137
+ /**
138
+ * Record agent-to-agent communication allow list change
139
+ *
140
+ * Records changes to tools.agentToAgent.allow
141
+ * This is the official OpenClaw configuration for agent-to-agent communication control.
142
+ */
143
+ function recordAgentToAgentChange(oldAllowList, newAllowList, reason) {
144
+ if (!currentSessionId)
145
+ return;
146
+ configChangeRepo.recordChange(currentSessionId, {
147
+ change_type: 'agent_to_agent_update',
148
+ target_type: 'tools.agentToAgent',
149
+ target_path: 'tools.agentToAgent.allow',
150
+ action: 'update',
151
+ old_value: JSON.stringify(oldAllowList),
152
+ new_value: JSON.stringify(newAllowList),
153
+ related_id: 'agentToAgent',
154
+ description: reason
155
+ });
156
+ }
157
+ /**
158
+ * Record binding creation
159
+ */
160
+ function recordBindingCreate(binding, relatedId) {
161
+ if (!currentSessionId)
162
+ return;
163
+ configChangeRepo.recordChange(currentSessionId, {
164
+ change_type: 'binding_create',
165
+ target_type: 'bindings',
166
+ target_path: `bindings[${Date.now()}]`,
167
+ action: 'add',
168
+ new_value: JSON.stringify(binding),
169
+ related_id: relatedId,
170
+ description: `创建绑定: ${binding.agentId || 'unknown'}`
171
+ });
172
+ }
173
+ /**
174
+ * Record binding deletion
175
+ */
176
+ function recordBindingDelete(binding, relatedId) {
177
+ if (!currentSessionId)
178
+ return;
179
+ configChangeRepo.recordChange(currentSessionId, {
180
+ change_type: 'binding_delete',
181
+ target_type: 'bindings',
182
+ target_path: `bindings[?]`,
183
+ action: 'remove',
184
+ old_value: JSON.stringify(binding),
185
+ related_id: relatedId,
186
+ description: `删除绑定: ${binding.agentId || 'unknown'}`
187
+ });
188
+ }
189
+ /**
190
+ * Record config change (generic)
191
+ */
192
+ function recordConfigChange(change) {
193
+ if (!currentSessionId) {
194
+ console.warn('警告:未设置会话ID,无法记录变更');
195
+ return;
196
+ }
197
+ configChangeRepo.recordChange(currentSessionId, {
198
+ change_type: change.change_type,
199
+ target_type: change.target_type || 'other',
200
+ target_path: change.target_path,
201
+ action: change.action,
202
+ old_value: change.old_value,
203
+ new_value: change.new_value,
204
+ related_id: change.related_id,
205
+ description: change.description
206
+ });
207
+ }
208
+ /**
209
+ * Record gateway config change
210
+ */
211
+ function recordGatewayConfigChange(configPath, oldValue, newValue, description) {
212
+ if (!currentSessionId)
213
+ return;
214
+ configChangeRepo.recordChange(currentSessionId, {
215
+ change_type: 'config_update',
216
+ target_type: 'gateway',
217
+ target_path: configPath,
218
+ action: 'update',
219
+ old_value: oldValue !== undefined ? JSON.stringify(oldValue) : undefined,
220
+ new_value: JSON.stringify(newValue),
221
+ description: description
222
+ });
223
+ }
224
+ /**
225
+ * Record feishu channel config
226
+ */
227
+ function recordFeishuConfig(config, oldConfig) {
228
+ if (!currentSessionId)
229
+ return;
230
+ configChangeRepo.recordChange(currentSessionId, {
231
+ change_type: 'channel_config',
232
+ target_type: 'channels.feishu',
233
+ target_path: 'channels.feishu',
234
+ action: oldConfig ? 'update' : 'add',
235
+ old_value: oldConfig ? JSON.stringify(oldConfig) : undefined,
236
+ new_value: JSON.stringify(config),
237
+ description: '配置飞书渠道'
238
+ });
239
+ }
240
+ /**
241
+ * Record skill pack creation
242
+ */
243
+ function recordSkillPackCreate(skillPackId, skillPackConfig) {
244
+ if (!currentSessionId)
245
+ return;
246
+ configChangeRepo.recordChange(currentSessionId, {
247
+ change_type: 'skill_pack_create',
248
+ target_type: 'skill_packs',
249
+ target_path: `skill_packs[${skillPackId}]`,
250
+ action: 'add',
251
+ new_value: JSON.stringify(skillPackConfig),
252
+ related_id: skillPackId,
253
+ description: `创建技能包: ${skillPackConfig.name || skillPackId}`
254
+ });
255
+ }
256
+ /**
257
+ * Record skill pack deletion
258
+ */
259
+ function recordSkillPackDelete(skillPackId, oldConfig) {
260
+ if (!currentSessionId)
261
+ return;
262
+ configChangeRepo.recordChange(currentSessionId, {
263
+ change_type: 'skill_pack_delete',
264
+ target_type: 'skill_packs',
265
+ target_path: `skill_packs[${skillPackId}]`,
266
+ action: 'remove',
267
+ old_value: JSON.stringify(oldConfig),
268
+ related_id: skillPackId,
269
+ description: `删除技能包: ${oldConfig.name || skillPackId}`
270
+ });
271
+ }
272
+ /**
273
+ * Record job creation
274
+ */
275
+ function recordJobCreate(jobId, jobConfig) {
276
+ if (!currentSessionId)
277
+ return;
278
+ configChangeRepo.recordChange(currentSessionId, {
279
+ change_type: 'job_create',
280
+ target_type: 'jobs',
281
+ target_path: `jobs[${jobId}]`,
282
+ action: 'add',
283
+ new_value: JSON.stringify(jobConfig),
284
+ related_id: jobId,
285
+ description: `创建职业: ${jobConfig.name || jobId}`
286
+ });
287
+ }
288
+ /**
289
+ * Record job deletion
290
+ */
291
+ function recordJobDelete(jobId, oldConfig) {
292
+ if (!currentSessionId)
293
+ return;
294
+ configChangeRepo.recordChange(currentSessionId, {
295
+ change_type: 'job_delete',
296
+ target_type: 'jobs',
297
+ target_path: `jobs[${jobId}]`,
298
+ action: 'remove',
299
+ old_value: JSON.stringify(oldConfig),
300
+ related_id: jobId,
301
+ description: `删除职业: ${oldConfig.name || jobId}`
302
+ });
303
+ }
304
+ /**
305
+ * Record directory creation
306
+ */
307
+ function recordDirectoryCreate(dirPath, description) {
308
+ if (!currentSessionId)
309
+ return;
310
+ configChangeRepo.recordChange(currentSessionId, {
311
+ change_type: 'directory_create',
312
+ target_type: 'directories',
313
+ target_path: dirPath,
314
+ action: 'add',
315
+ new_value: JSON.stringify({ path: dirPath }),
316
+ related_id: dirPath.replace(/[^a-zA-Z0-9_-]/g, '_'),
317
+ description: description || `创建目录: ${dirPath}`
318
+ });
319
+ }
320
+ /**
321
+ * Record feishu group binding
322
+ */
323
+ function recordFeishuGroupBind(deptId, deptName, groupId, oldGroupId) {
324
+ if (!currentSessionId)
325
+ return;
326
+ // Get current group config from openclaw.json for potential restoration
327
+ const configPath = (0, utils_1.getOpenClawJsonPath)();
328
+ let groupConfig;
329
+ try {
330
+ if (fs.existsSync(configPath)) {
331
+ const content = fs.readFileSync(configPath, 'utf-8');
332
+ const config = JSON.parse(content);
333
+ const channels = config.channels;
334
+ const feishuConfig = channels?.feishu;
335
+ const groups = feishuConfig?.groups;
336
+ if (groups?.[groupId]) {
337
+ groupConfig = groups[groupId];
338
+ }
339
+ }
340
+ }
341
+ catch {
342
+ // Ignore errors
343
+ }
344
+ configChangeRepo.recordChange(currentSessionId, {
345
+ change_type: 'feishu_group_bind',
346
+ target_type: 'channels.feishu.groups',
347
+ target_path: `channels.feishu.groups[${groupId}]`,
348
+ action: oldGroupId ? 'update' : 'add',
349
+ old_value: oldGroupId || undefined,
350
+ new_value: JSON.stringify({
351
+ groupId,
352
+ groupConfig,
353
+ deptId,
354
+ deptName
355
+ }),
356
+ related_id: deptId,
357
+ description: `绑定飞书群: ${deptName} → ${groupId}`
358
+ });
359
+ }
360
+ /**
361
+ * Record feishu group unbinding
362
+ */
363
+ function recordFeishuGroupUnbind(deptId, deptName, oldGroupId) {
364
+ if (!currentSessionId)
365
+ return;
366
+ // Get current group config from openclaw.json for potential restoration
367
+ const configPath = (0, utils_1.getOpenClawJsonPath)();
368
+ let oldGroupConfig;
369
+ let oldGroupAllowFrom;
370
+ try {
371
+ if (fs.existsSync(configPath)) {
372
+ const content = fs.readFileSync(configPath, 'utf-8');
373
+ const config = JSON.parse(content);
374
+ const channels = config.channels;
375
+ const feishuConfig = channels?.feishu;
376
+ const groups = feishuConfig?.groups;
377
+ if (groups?.[oldGroupId]) {
378
+ oldGroupConfig = groups[oldGroupId];
379
+ }
380
+ // Also save the groupAllowFrom for restoration
381
+ if (feishuConfig?.groupAllowFrom && Array.isArray(feishuConfig.groupAllowFrom)) {
382
+ oldGroupAllowFrom = [...feishuConfig.groupAllowFrom];
383
+ }
384
+ }
385
+ }
386
+ catch {
387
+ // Ignore errors
388
+ }
389
+ configChangeRepo.recordChange(currentSessionId, {
390
+ change_type: 'feishu_group_unbind',
391
+ target_type: 'channels.feishu.groups',
392
+ target_path: `channels.feishu.groups[${oldGroupId}]`,
393
+ action: 'remove',
394
+ old_value: JSON.stringify({
395
+ groupId: oldGroupId,
396
+ groupConfig: oldGroupConfig,
397
+ groupAllowFrom: oldGroupAllowFrom,
398
+ deptId,
399
+ deptName
400
+ }),
401
+ related_id: deptId,
402
+ description: `解绑飞书群: ${deptName} (${oldGroupId})`
403
+ });
404
+ }
405
+ /**
406
+ * Revert all config changes for a session
407
+ */
408
+ function revertSessionConfigChanges(sessionId) {
409
+ try {
410
+ const configPath = (0, utils_1.getOpenClawJsonPath)();
411
+ if (!fs.existsSync(configPath)) {
412
+ return { success: true, message: '配置文件不存在', revertedCount: 0 };
413
+ }
414
+ // Read config
415
+ let content = fs.readFileSync(configPath, 'utf-8');
416
+ // Remove BOM if present
417
+ if (content.charCodeAt(0) === 0xFEFF) {
418
+ content = content.slice(1);
419
+ }
420
+ // Parse JSON directly (standard JSON doesn't support comments)
421
+ const config = JSON.parse(content);
422
+ // Get uncleaned changes for this session (in reverse order)
423
+ const changes = configChangeRepo.getUncleanedBySession(sessionId).reverse();
424
+ let revertedCount = 0;
425
+ for (const change of changes) {
426
+ try {
427
+ revertChange(config, change);
428
+ revertedCount++;
429
+ }
430
+ catch (e) {
431
+ console.warn(`撤销变更失败: ${change.id}`, e);
432
+ }
433
+ }
434
+ // Write back config
435
+ // 在写入前清理所有 null 值和空对象,避免配置无效
436
+ cleanupConfigNulls(config);
437
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
438
+ // Mark as cleaned
439
+ configChangeRepo.markAllCleanedBySession(sessionId);
440
+ return { success: true, message: '配置已撤销', revertedCount };
441
+ }
442
+ catch (error) {
443
+ return {
444
+ success: false,
445
+ message: error instanceof Error ? error.message : String(error),
446
+ revertedCount: 0
447
+ };
448
+ }
449
+ }
450
+ /**
451
+ * Revert all config changes (legacy compatibility)
452
+ */
453
+ function revertAllConfigChanges() {
454
+ if (!currentSessionId) {
455
+ return { success: false, message: '未设置会话ID', revertedCount: 0 };
456
+ }
457
+ return revertSessionConfigChanges(currentSessionId);
458
+ }
459
+ /**
460
+ * Revert single change
461
+ */
462
+ function revertChange(config, change) {
463
+ switch (change.target_type) {
464
+ case 'agents.list':
465
+ revertAgentChange(config, change);
466
+ break;
467
+ case 'agents.list.allow_agents':
468
+ revertAgentAllowListChange(config, change);
469
+ break;
470
+ case 'tools.agentToAgent':
471
+ revertAgentToAgentChange(config, change);
472
+ break;
473
+ case 'bindings':
474
+ revertBindingChange(config, change);
475
+ break;
476
+ case 'channels.feishu':
477
+ revertFeishuChange(config, change);
478
+ break;
479
+ case 'gateway':
480
+ // 跳过 gateway 配置的撤销
481
+ // gateway.controlUi.allowInsecureAuth 是工具运行需要的基础配置
482
+ // 重置时应该保留,不应该撤销
483
+ console.log(`[重置] 跳过 gateway 配置撤销: ${change.target_path}`);
484
+ break;
485
+ case 'directories':
486
+ // Directory deletion handled separately during reset
487
+ break;
488
+ case 'skill_packs':
489
+ case 'jobs':
490
+ // Skill packs and jobs are in database tables, cleared during reset
491
+ break;
492
+ case 'departments':
493
+ // Department group binding is in database, needs separate handling
494
+ revertDepartmentChange(change);
495
+ break;
496
+ case 'credentials':
497
+ // Credentials changes (feishu pairing etc.)
498
+ revertCredentialsChange(change);
499
+ break;
500
+ default:
501
+ console.warn(`未知的变更类型: ${change.target_type}`);
502
+ }
503
+ }
504
+ /**
505
+ * Revert agent related changes
506
+ *
507
+ * Note: Only 'main' (OpenClaw native default agent) is protected.
508
+ * 'assistant_main' is created by team-manager and should be cleaned during reset.
509
+ */
510
+ function revertAgentChange(config, change) {
511
+ if (!config.agents)
512
+ config.agents = { list: [] };
513
+ const agents = config.agents;
514
+ if (!agents.list)
515
+ agents.list = [];
516
+ const agentsList = agents.list;
517
+ // Protected agent IDs - only 'main' (OpenClaw native, created before team-manager init)
518
+ // 'assistant_main' is created by team-manager and should be cleaned during reset
519
+ const PROTECTED_AGENT_IDS = ['main'];
520
+ if (change.action === 'add') {
521
+ // Revert add: remove the agent
522
+ // But skip protected agents (OpenClaw native, not created by team-manager)
523
+ if (PROTECTED_AGENT_IDS.includes(change.related_id || '')) {
524
+ console.log(`[重置] 跳过移除受保护的 agent: ${change.related_id}`);
525
+ return;
526
+ }
527
+ const index = agentsList.findIndex(a => a.id === change.related_id);
528
+ if (index >= 0) {
529
+ agentsList.splice(index, 1);
530
+ }
531
+ }
532
+ else if (change.action === 'remove') {
533
+ // Revert remove: restore the agent
534
+ if (change.old_value) {
535
+ const agentConfig = JSON.parse(change.old_value);
536
+ agentsList.push(agentConfig);
537
+ }
538
+ }
539
+ else if (change.action === 'update' && change.old_value) {
540
+ // Revert update: restore old config
541
+ const index = agentsList.findIndex(a => a.id === change.related_id);
542
+ if (index >= 0) {
543
+ const oldAgentConfig = JSON.parse(change.old_value);
544
+ agentsList[index] = oldAgentConfig;
545
+ }
546
+ }
547
+ }
548
+ /**
549
+ * Revert agent allow list changes (legacy)
550
+ */
551
+ function revertAgentAllowListChange(config, change) {
552
+ if (!config.agents)
553
+ config.agents = { list: [] };
554
+ const agents = config.agents;
555
+ if (!agents.list)
556
+ agents.list = [];
557
+ const agentsList = agents.list;
558
+ // Find the agent by related_id
559
+ const agentId = change.related_id;
560
+ const agentConfig = agentsList.find((a) => a.id === agentId);
561
+ if (!agentConfig) {
562
+ console.log(`[重置] 未找到 agent ${agentId},跳过 allowAgents 恢复`);
563
+ return;
564
+ }
565
+ // Restore old allowAgents list
566
+ if (change.old_value) {
567
+ try {
568
+ const oldAllowList = JSON.parse(change.old_value);
569
+ const subagents = agentConfig.subagents;
570
+ if (!subagents) {
571
+ agentConfig.subagents = { allowAgents: oldAllowList };
572
+ }
573
+ else {
574
+ subagents.allowAgents = oldAllowList;
575
+ }
576
+ console.log(`[重置] 已恢复 ${agentId} 的通信权限: [${oldAllowList.join(', ')}]`);
577
+ }
578
+ catch (e) {
579
+ console.warn(`恢复 agent allow list 失败:`, e);
580
+ }
581
+ }
582
+ }
583
+ /**
584
+ * Revert agent-to-agent communication allow list changes
585
+ */
586
+ function revertAgentToAgentChange(config, change) {
587
+ // Restore old allow list
588
+ if (change.old_value) {
589
+ try {
590
+ const oldAllowList = JSON.parse(change.old_value);
591
+ // Ensure tools.agentToAgent structure exists
592
+ if (!config['tools']) {
593
+ config['tools'] = {};
594
+ }
595
+ const tools = config['tools'];
596
+ if (!tools['agentToAgent']) {
597
+ tools['agentToAgent'] = { enabled: true, allow: [] };
598
+ }
599
+ const agentToAgent = tools['agentToAgent'];
600
+ agentToAgent['enabled'] = true;
601
+ agentToAgent['allow'] = oldAllowList;
602
+ console.log(`[重置] 已恢复 agentToAgent.allow: [${oldAllowList.slice(0, 5).join(', ')}${oldAllowList.length > 5 ? '...' : ''}]`);
603
+ }
604
+ catch (e) {
605
+ console.warn(`恢复 agentToAgent 配置失败:`, e);
606
+ }
607
+ }
608
+ }
609
+ /**
610
+ * Revert binding related changes
611
+ */
612
+ function revertBindingChange(config, change) {
613
+ if (!config.bindings)
614
+ config.bindings = [];
615
+ const bindings = config.bindings;
616
+ if (change.action === 'add') {
617
+ // Revert add: remove the binding
618
+ if (change.new_value) {
619
+ const binding = JSON.parse(change.new_value);
620
+ const index = bindings.findIndex(b => b.agentId === binding.agentId &&
621
+ JSON.stringify(b.match) === JSON.stringify(binding.match));
622
+ if (index >= 0) {
623
+ bindings.splice(index, 1);
624
+ }
625
+ }
626
+ }
627
+ else if (change.action === 'remove') {
628
+ // Revert remove: restore the binding
629
+ if (change.old_value) {
630
+ const binding = JSON.parse(change.old_value);
631
+ bindings.push(binding);
632
+ }
633
+ }
634
+ else if (change.action === 'update' && change.old_value) {
635
+ // Revert update: restore old config
636
+ const oldBinding = JSON.parse(change.old_value);
637
+ const index = bindings.findIndex(b => b.agentId === oldBinding.agentId);
638
+ if (index >= 0) {
639
+ bindings[index] = oldBinding;
640
+ }
641
+ }
642
+ }
643
+ /**
644
+ * Revert feishu config changes
645
+ *
646
+ * 支持两种粒度的变更:
647
+ * 1. 整体配置变更 (target_path: 'channels.feishu')
648
+ * 2. 单个账号变更 (target_path: 'channels.feishu.accounts.{agentId}')
649
+ */
650
+ function revertFeishuChange(config, change) {
651
+ if (!config.channels)
652
+ config.channels = {};
653
+ const channels = config.channels;
654
+ // 确保飞书配置存在
655
+ if (!channels.feishu) {
656
+ return;
657
+ }
658
+ const feishuConfig = channels.feishu;
659
+ // 根据 target_path 判断变更粒度
660
+ if (change.target_path.startsWith('channels.feishu.accounts.')) {
661
+ // 单个账号变更:只删除/恢复该账号
662
+ const agentId = change.target_path.replace('channels.feishu.accounts.', '');
663
+ if (!feishuConfig.accounts) {
664
+ return;
665
+ }
666
+ const feishuAccounts = feishuConfig.accounts;
667
+ if (change.action === 'add') {
668
+ // 新增账号:删除该账号
669
+ if (feishuAccounts[agentId]) {
670
+ delete feishuAccounts[agentId];
671
+ console.log(`[重置] 已删除飞书账号配置: ${agentId}`);
672
+ }
673
+ }
674
+ else if (change.action === 'update' && change.old_value) {
675
+ // 更新账号:恢复旧配置
676
+ try {
677
+ const oldConfig = JSON.parse(change.old_value);
678
+ if (oldConfig[agentId]) {
679
+ feishuAccounts[agentId] = oldConfig[agentId];
680
+ console.log(`[重置] 已恢复飞书账号配置: ${agentId}`);
681
+ }
682
+ }
683
+ catch (e) {
684
+ console.warn('恢复飞书账号配置失败:', e);
685
+ }
686
+ }
687
+ else if (change.action === 'remove' && change.old_value) {
688
+ // 删除账号:恢复该账号
689
+ try {
690
+ const oldConfig = JSON.parse(change.old_value);
691
+ if (oldConfig[agentId]) {
692
+ feishuAccounts[agentId] = oldConfig[agentId];
693
+ console.log(`[重置] 已恢复飞书账号配置: ${agentId}`);
694
+ }
695
+ }
696
+ catch (e) {
697
+ console.warn('恢复飞书账号配置失败:', e);
698
+ }
699
+ }
700
+ // 如果没有账号了,删除 accounts 字段
701
+ if (Object.keys(feishuAccounts).length === 0) {
702
+ delete feishuConfig.accounts;
703
+ }
704
+ }
705
+ else if (change.target_path === 'channels.feishu') {
706
+ // 整体配置变更
707
+ if (change.action === 'add') {
708
+ // 新增整体配置:只删除该会话添加的账号,保留基础配置
709
+ if (change.new_value) {
710
+ try {
711
+ const newConfig = JSON.parse(change.new_value);
712
+ if (newConfig.accounts && feishuConfig.accounts) {
713
+ const feishuAccounts = feishuConfig.accounts;
714
+ const newAccounts = newConfig.accounts;
715
+ for (const accountId of Object.keys(newAccounts)) {
716
+ if (feishuAccounts[accountId]) {
717
+ delete feishuAccounts[accountId];
718
+ console.log(`[重置] 已删除飞书账号配置: ${accountId}`);
719
+ }
720
+ }
721
+ if (Object.keys(feishuAccounts).length === 0) {
722
+ delete feishuConfig.accounts;
723
+ }
724
+ }
725
+ }
726
+ catch (e) {
727
+ console.warn('解析飞书配置变更失败:', e);
728
+ }
729
+ }
730
+ }
731
+ else if (change.action === 'update' && change.old_value) {
732
+ // 更新整体配置:合并旧配置
733
+ try {
734
+ const oldConfig = JSON.parse(change.old_value);
735
+ if (oldConfig.accounts) {
736
+ if (!feishuConfig.accounts) {
737
+ feishuConfig.accounts = {};
738
+ }
739
+ const feishuAccounts = feishuConfig.accounts;
740
+ const oldAccounts = oldConfig.accounts;
741
+ for (const [accountId, accountConfig] of Object.entries(oldAccounts)) {
742
+ feishuAccounts[accountId] = accountConfig;
743
+ }
744
+ }
745
+ }
746
+ catch (e) {
747
+ console.warn('恢复飞书配置失败:', e);
748
+ }
749
+ }
750
+ }
751
+ }
752
+ /**
753
+ * Revert gateway config changes
754
+ */
755
+ function revertGatewayChange(config, change) {
756
+ if (!config.gateway)
757
+ config.gateway = {};
758
+ const gateway = config.gateway;
759
+ // Parse target_path, e.g. "gateway.controlUi.allowInsecureAuth"
760
+ const pathParts = change.target_path.split('.');
761
+ if (pathParts.length >= 2) {
762
+ // Skip the first "gateway" part
763
+ const configPath = pathParts.slice(1);
764
+ // Navigate to target location
765
+ let target = gateway;
766
+ for (let i = 0; i < configPath.length - 1; i++) {
767
+ const key = configPath[i];
768
+ if (!target[key]) {
769
+ target[key] = {};
770
+ }
771
+ target = target[key];
772
+ }
773
+ const lastKey = configPath[configPath.length - 1];
774
+ if (change.action === 'add' || change.action === 'update') {
775
+ // Revert add/update: restore old value or delete
776
+ if (change.old_value !== undefined && change.old_value !== 'undefined' && change.old_value !== null && change.old_value !== 'null') {
777
+ try {
778
+ const parsed = JSON.parse(change.old_value);
779
+ // 确保不是 null
780
+ if (parsed !== null) {
781
+ target[lastKey] = parsed;
782
+ }
783
+ else {
784
+ delete target[lastKey];
785
+ }
786
+ }
787
+ catch {
788
+ // 尝试直接转换
789
+ if (change.old_value === 'true') {
790
+ target[lastKey] = true;
791
+ }
792
+ else if (change.old_value === 'false') {
793
+ target[lastKey] = false;
794
+ }
795
+ else if (change.old_value !== 'null') {
796
+ target[lastKey] = change.old_value;
797
+ }
798
+ else {
799
+ delete target[lastKey];
800
+ }
801
+ }
802
+ }
803
+ else {
804
+ // No old value or old value is null, delete the config
805
+ delete target[lastKey];
806
+ }
807
+ }
808
+ }
809
+ // 清理空对象
810
+ cleanupEmptyObjects(gateway);
811
+ }
812
+ /**
813
+ * 递归清理空对象
814
+ */
815
+ function cleanupEmptyObjects(obj) {
816
+ for (const key of Object.keys(obj)) {
817
+ const value = obj[key];
818
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
819
+ const nested = value;
820
+ cleanupEmptyObjects(nested);
821
+ if (Object.keys(nested).length === 0) {
822
+ delete obj[key];
823
+ }
824
+ }
825
+ // 删除 null 值
826
+ if (value === null) {
827
+ delete obj[key];
828
+ }
829
+ }
830
+ }
831
+ /**
832
+ * 清理配置中的 null 值和空对象
833
+ */
834
+ function cleanupConfigNulls(config) {
835
+ cleanupEmptyObjects(config);
836
+ // 特殊处理 gateway.controlUi
837
+ const gateway = config.gateway;
838
+ if (gateway?.controlUi) {
839
+ const controlUi = gateway.controlUi;
840
+ // 删除 null 值
841
+ for (const key of Object.keys(controlUi)) {
842
+ if (controlUi[key] === null) {
843
+ delete controlUi[key];
844
+ }
845
+ }
846
+ // 如果 controlUi 为空,删除整个对象
847
+ if (Object.keys(controlUi).length === 0) {
848
+ delete gateway.controlUi;
849
+ }
850
+ }
851
+ }
852
+ /**
853
+ * Get change summary (for display)
854
+ */
855
+ function getChangesSummary() {
856
+ const stats = configChangeRepo.getChangeStats();
857
+ const changes = configChangeRepo.getAllChanges();
858
+ if (changes.length === 0) {
859
+ return '无配置变更记录';
860
+ }
861
+ const lines = ['配置变更记录:'];
862
+ for (const [type, count] of Object.entries(stats)) {
863
+ lines.push(` ${type}: ${count} 条`);
864
+ }
865
+ lines.push(` 总计: ${changes.length} 条`);
866
+ return lines.join('\n');
867
+ }
868
+ /**
869
+ * Revert department related changes (feishu group binding etc.)
870
+ */
871
+ function revertDepartmentChange(change) {
872
+ // Need to operate through database
873
+ // Use dynamic import to avoid circular dependency
874
+ try {
875
+ const { departmentRepository } = require('../../db/repositories/dept.repo');
876
+ if (!change.related_id)
877
+ return;
878
+ const deptId = change.related_id;
879
+ if (change.change_type === 'feishu_group_bind') {
880
+ // Revert binding: clear group ID from database and clean up openclaw.json
881
+ if (change.action === 'add') {
882
+ // Binding was added, need to remove it
883
+ departmentRepository.update(deptId, { feishu_group_id: null });
884
+ // Clean up openclaw.json group config
885
+ if (change.new_value) {
886
+ try {
887
+ const data = JSON.parse(change.new_value);
888
+ if (data.groupId) {
889
+ removeFeishuGroupConfig(data.groupId);
890
+ }
891
+ }
892
+ catch {
893
+ // Ignore parse errors
894
+ }
895
+ }
896
+ }
897
+ else if (change.action === 'update' && change.old_value) {
898
+ // Binding was updated, restore old group ID
899
+ departmentRepository.update(deptId, { feishu_group_id: change.old_value });
900
+ }
901
+ }
902
+ else if (change.change_type === 'feishu_group_unbind') {
903
+ // Revert unbinding: restore group ID to database and restore openclaw.json config
904
+ if (change.action === 'remove' && change.old_value) {
905
+ try {
906
+ const data = JSON.parse(change.old_value);
907
+ // Restore group ID to database
908
+ departmentRepository.update(deptId, { feishu_group_id: data.groupId });
909
+ // Restore openclaw.json group config
910
+ restoreFeishuGroupConfig(data);
911
+ }
912
+ catch {
913
+ // Ignore parse errors
914
+ }
915
+ }
916
+ }
917
+ }
918
+ catch (e) {
919
+ console.warn('撤销事业部变更失败:', e);
920
+ }
921
+ }
922
+ /**
923
+ * Remove feishu group config from openclaw.json
924
+ */
925
+ function removeFeishuGroupConfig(groupId) {
926
+ try {
927
+ const configPath = (0, utils_1.getOpenClawJsonPath)();
928
+ if (!fs.existsSync(configPath))
929
+ return;
930
+ const content = fs.readFileSync(configPath, 'utf-8');
931
+ const config = JSON.parse(content);
932
+ let configChanged = false;
933
+ const channels = config.channels;
934
+ const feishuConfig = channels?.feishu;
935
+ // Remove from groupAllowFrom
936
+ if (feishuConfig?.groupAllowFrom && Array.isArray(feishuConfig.groupAllowFrom)) {
937
+ const groupAllowFrom = feishuConfig.groupAllowFrom;
938
+ const index = groupAllowFrom.indexOf(groupId);
939
+ if (index >= 0) {
940
+ groupAllowFrom.splice(index, 1);
941
+ configChanged = true;
942
+ console.log(`[重置] 已从群组白名单移除: ${groupId}`);
943
+ }
944
+ }
945
+ // Remove group config
946
+ if (feishuConfig?.groups && typeof feishuConfig.groups === 'object') {
947
+ const groups = feishuConfig.groups;
948
+ if (groups[groupId]) {
949
+ delete groups[groupId];
950
+ configChanged = true;
951
+ console.log(`[重置] 已移除群组配置: ${groupId}`);
952
+ }
953
+ }
954
+ // Remove bindings for this group
955
+ if (config.bindings && Array.isArray(config.bindings)) {
956
+ const originalLength = config.bindings.length;
957
+ config.bindings = config.bindings.filter((b) => {
958
+ const match = b.match;
959
+ return !(match?.channel === 'feishu' &&
960
+ match?.peer?.kind === 'group' &&
961
+ match?.peer?.id === groupId);
962
+ });
963
+ if (config.bindings.length < originalLength) {
964
+ configChanged = true;
965
+ console.log(`[重置] 已移除 ${originalLength - config.bindings.length} 个群组绑定`);
966
+ }
967
+ }
968
+ if (configChanged) {
969
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
970
+ }
971
+ }
972
+ catch (e) {
973
+ console.warn('移除飞书群组配置失败:', e);
974
+ }
975
+ }
976
+ /**
977
+ * Restore feishu group config to openclaw.json
978
+ */
979
+ function restoreFeishuGroupConfig(data) {
980
+ try {
981
+ const configPath = (0, utils_1.getOpenClawJsonPath)();
982
+ if (!fs.existsSync(configPath))
983
+ return;
984
+ const content = fs.readFileSync(configPath, 'utf-8');
985
+ const config = JSON.parse(content);
986
+ let configChanged = false;
987
+ // Ensure channels.feishu structure exists
988
+ if (!config.channels)
989
+ config.channels = {};
990
+ const channels = config.channels;
991
+ if (!channels.feishu) {
992
+ channels.feishu = {
993
+ enabled: true,
994
+ groupPolicy: 'allowlist'
995
+ };
996
+ }
997
+ const feishuConfig = channels.feishu;
998
+ // Restore groupAllowFrom
999
+ if (data.groupAllowFrom) {
1000
+ if (!feishuConfig.groupAllowFrom) {
1001
+ feishuConfig.groupAllowFrom = [];
1002
+ }
1003
+ const groupAllowFrom = feishuConfig.groupAllowFrom;
1004
+ for (const id of data.groupAllowFrom) {
1005
+ if (!groupAllowFrom.includes(id)) {
1006
+ groupAllowFrom.push(id);
1007
+ configChanged = true;
1008
+ }
1009
+ }
1010
+ if (configChanged) {
1011
+ console.log(`[重置] 已恢复群组白名单: ${data.groupId}`);
1012
+ }
1013
+ }
1014
+ // Restore group config (requireMention etc.)
1015
+ if (data.groupConfig) {
1016
+ if (!feishuConfig.groups) {
1017
+ feishuConfig.groups = {};
1018
+ }
1019
+ const groups = feishuConfig.groups;
1020
+ groups[data.groupId] = data.groupConfig;
1021
+ configChanged = true;
1022
+ console.log(`[重置] 已恢复群组配置: ${data.groupId}`);
1023
+ }
1024
+ if (configChanged) {
1025
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
1026
+ }
1027
+ }
1028
+ catch (e) {
1029
+ console.warn('恢复飞书群组配置失败:', e);
1030
+ }
1031
+ }
1032
+ /**
1033
+ * Revert credentials related changes (feishu pairing etc.)
1034
+ *
1035
+ * 清除飞书配对授权信息:
1036
+ * - 从 feishu-{accountId}-allowFrom.json 中移除用户
1037
+ * - 从 feishu-allowFrom.json 中移除用户
1038
+ */
1039
+ function revertCredentialsChange(change) {
1040
+ if (change.change_type === 'feishu_pairing_approve' && change.action === 'add') {
1041
+ // 解析变更内容
1042
+ if (!change.new_value)
1043
+ return;
1044
+ try {
1045
+ const data = JSON.parse(change.new_value);
1046
+ const accountId = data.accountId;
1047
+ const userId = data.userId;
1048
+ if (!accountId || !userId)
1049
+ return;
1050
+ // 获取凭证目录
1051
+ const openclawRoot = (0, utils_1.getOpenClawRoot)();
1052
+ const credentialsDir = openclawRoot
1053
+ ? path.join(openclawRoot, 'credentials')
1054
+ : path.join(os.homedir(), '.openclaw', 'credentials');
1055
+ // 要清理的文件列表
1056
+ const fileNames = [
1057
+ 'feishu-allowFrom.json',
1058
+ `feishu-${accountId}-allowFrom.json`,
1059
+ 'feishu-default-allowFrom.json'
1060
+ ];
1061
+ for (const fileName of fileNames) {
1062
+ const filePath = path.join(credentialsDir, fileName);
1063
+ if (!fs.existsSync(filePath))
1064
+ continue;
1065
+ try {
1066
+ const content = fs.readFileSync(filePath, 'utf-8');
1067
+ let allowFrom = JSON.parse(content) || [];
1068
+ // 移除该用户
1069
+ const index = allowFrom.indexOf(userId);
1070
+ if (index >= 0) {
1071
+ allowFrom.splice(index, 1);
1072
+ console.log(`[重置] 已从 ${fileName} 移除用户: ${userId}`);
1073
+ if (allowFrom.length > 0) {
1074
+ fs.writeFileSync(filePath, JSON.stringify(allowFrom, null, 2), 'utf-8');
1075
+ }
1076
+ else {
1077
+ // 如果没有用户了,删除文件
1078
+ fs.unlinkSync(filePath);
1079
+ console.log(`[重置] 已删除空文件: ${fileName}`);
1080
+ }
1081
+ }
1082
+ }
1083
+ catch (e) {
1084
+ console.warn(`处理 ${fileName} 失败:`, e);
1085
+ }
1086
+ }
1087
+ }
1088
+ catch (e) {
1089
+ console.warn('撤销飞书配对授权失败:', e);
1090
+ }
1091
+ }
1092
+ }
1093
+ //# sourceMappingURL=config-tracker.service.js.map