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.
- package/README.md +136 -0
- package/dist/bin/team-manager.d.ts +6 -0
- package/dist/bin/team-manager.d.ts.map +1 -0
- package/dist/bin/team-manager.js +36 -0
- package/dist/bin/team-manager.js.map +1 -0
- package/dist/bin/team-setup.d.ts +7 -0
- package/dist/bin/team-setup.d.ts.map +1 -0
- package/dist/bin/team-setup.js +66 -0
- package/dist/bin/team-setup.js.map +1 -0
- package/dist/bin/team-uninstall.d.ts +6 -0
- package/dist/bin/team-uninstall.d.ts.map +1 -0
- package/dist/bin/team-uninstall.js +91 -0
- package/dist/bin/team-uninstall.js.map +1 -0
- package/dist/cli/commands/agent.command.d.ts +43 -0
- package/dist/cli/commands/agent.command.d.ts.map +1 -0
- package/dist/cli/commands/agent.command.js +223 -0
- package/dist/cli/commands/agent.command.js.map +1 -0
- package/dist/cli/commands/checklist.command.d.ts +35 -0
- package/dist/cli/commands/checklist.command.d.ts.map +1 -0
- package/dist/cli/commands/checklist.command.js +77 -0
- package/dist/cli/commands/checklist.command.js.map +1 -0
- package/dist/cli/commands/dept.command.d.ts +32 -0
- package/dist/cli/commands/dept.command.d.ts.map +1 -0
- package/dist/cli/commands/dept.command.js +92 -0
- package/dist/cli/commands/dept.command.js.map +1 -0
- package/dist/cli/commands/document.command.d.ts +37 -0
- package/dist/cli/commands/document.command.d.ts.map +1 -0
- package/dist/cli/commands/document.command.js +146 -0
- package/dist/cli/commands/document.command.js.map +1 -0
- package/dist/cli/commands/domain.command.d.ts +36 -0
- package/dist/cli/commands/domain.command.d.ts.map +1 -0
- package/dist/cli/commands/domain.command.js +97 -0
- package/dist/cli/commands/domain.command.js.map +1 -0
- package/dist/cli/commands/feishu.command.d.ts +63 -0
- package/dist/cli/commands/feishu.command.d.ts.map +1 -0
- package/dist/cli/commands/feishu.command.js +433 -0
- package/dist/cli/commands/feishu.command.js.map +1 -0
- package/dist/cli/commands/job.command.d.ts +39 -0
- package/dist/cli/commands/job.command.d.ts.map +1 -0
- package/dist/cli/commands/job.command.js +168 -0
- package/dist/cli/commands/job.command.js.map +1 -0
- package/dist/cli/commands/license.command.d.ts +22 -0
- package/dist/cli/commands/license.command.d.ts.map +1 -0
- package/dist/cli/commands/license.command.js +68 -0
- package/dist/cli/commands/license.command.js.map +1 -0
- package/dist/cli/commands/message-failure.command.d.ts +44 -0
- package/dist/cli/commands/message-failure.command.d.ts.map +1 -0
- package/dist/cli/commands/message-failure.command.js +137 -0
- package/dist/cli/commands/message-failure.command.js.map +1 -0
- package/dist/cli/commands/message.command.d.ts +47 -0
- package/dist/cli/commands/message.command.d.ts.map +1 -0
- package/dist/cli/commands/message.command.js +129 -0
- package/dist/cli/commands/message.command.js.map +1 -0
- package/dist/cli/commands/node.command.d.ts +76 -0
- package/dist/cli/commands/node.command.d.ts.map +1 -0
- package/dist/cli/commands/node.command.js +251 -0
- package/dist/cli/commands/node.command.js.map +1 -0
- package/dist/cli/commands/role-flow.command.d.ts +12 -0
- package/dist/cli/commands/role-flow.command.d.ts.map +1 -0
- package/dist/cli/commands/role-flow.command.js +54 -0
- package/dist/cli/commands/role-flow.command.js.map +1 -0
- package/dist/cli/commands/skill-pack.command.d.ts +41 -0
- package/dist/cli/commands/skill-pack.command.d.ts.map +1 -0
- package/dist/cli/commands/skill-pack.command.js +137 -0
- package/dist/cli/commands/skill-pack.command.js.map +1 -0
- package/dist/cli/commands/status.command.d.ts +8 -0
- package/dist/cli/commands/status.command.d.ts.map +1 -0
- package/dist/cli/commands/status.command.js +61 -0
- package/dist/cli/commands/status.command.js.map +1 -0
- package/dist/cli/commands/task.command.d.ts +105 -0
- package/dist/cli/commands/task.command.d.ts.map +1 -0
- package/dist/cli/commands/task.command.js +402 -0
- package/dist/cli/commands/task.command.js.map +1 -0
- package/dist/cli/commands/user.command.d.ts +43 -0
- package/dist/cli/commands/user.command.d.ts.map +1 -0
- package/dist/cli/commands/user.command.js +134 -0
- package/dist/cli/commands/user.command.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +863 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/tui/index.d.ts +45 -0
- package/dist/cli/tui/index.d.ts.map +1 -0
- package/dist/cli/tui/index.js +470 -0
- package/dist/cli/tui/index.js.map +1 -0
- package/dist/cli/tui/menus/agent-manage.menu.d.ts +8 -0
- package/dist/cli/tui/menus/agent-manage.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/agent-manage.menu.js +614 -0
- package/dist/cli/tui/menus/agent-manage.menu.js.map +1 -0
- package/dist/cli/tui/menus/dept-manage.menu.d.ts +8 -0
- package/dist/cli/tui/menus/dept-manage.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/dept-manage.menu.js +299 -0
- package/dist/cli/tui/menus/dept-manage.menu.js.map +1 -0
- package/dist/cli/tui/menus/domain-manage.menu.d.ts +8 -0
- package/dist/cli/tui/menus/domain-manage.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/domain-manage.menu.js +208 -0
- package/dist/cli/tui/menus/domain-manage.menu.js.map +1 -0
- package/dist/cli/tui/menus/feishu.menu.d.ts +8 -0
- package/dist/cli/tui/menus/feishu.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/feishu.menu.js +1727 -0
- package/dist/cli/tui/menus/feishu.menu.js.map +1 -0
- package/dist/cli/tui/menus/job-manage.menu.d.ts +16 -0
- package/dist/cli/tui/menus/job-manage.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/job-manage.menu.js +734 -0
- package/dist/cli/tui/menus/job-manage.menu.js.map +1 -0
- package/dist/cli/tui/menus/license.menu.d.ts +12 -0
- package/dist/cli/tui/menus/license.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/license.menu.js +164 -0
- package/dist/cli/tui/menus/license.menu.js.map +1 -0
- package/dist/cli/tui/menus/main.menu.d.ts +10 -0
- package/dist/cli/tui/menus/main.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/main.menu.js +94 -0
- package/dist/cli/tui/menus/main.menu.js.map +1 -0
- package/dist/cli/tui/menus/reset.menu.d.ts +10 -0
- package/dist/cli/tui/menus/reset.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/reset.menu.js +767 -0
- package/dist/cli/tui/menus/reset.menu.js.map +1 -0
- package/dist/cli/tui/menus/status.menu.d.ts +8 -0
- package/dist/cli/tui/menus/status.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/status.menu.js +123 -0
- package/dist/cli/tui/menus/status.menu.js.map +1 -0
- package/dist/cli/tui/menus/task-manage.menu.d.ts +11 -0
- package/dist/cli/tui/menus/task-manage.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/task-manage.menu.js +129 -0
- package/dist/cli/tui/menus/task-manage.menu.js.map +1 -0
- package/dist/cli/tui/menus/team-create.menu.d.ts +8 -0
- package/dist/cli/tui/menus/team-create.menu.d.ts.map +1 -0
- package/dist/cli/tui/menus/team-create.menu.js +353 -0
- package/dist/cli/tui/menus/team-create.menu.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +74 -0
- package/dist/config.js.map +1 -0
- package/dist/core/auth/index.d.ts +6 -0
- package/dist/core/auth/index.d.ts.map +1 -0
- package/dist/core/auth/index.js +22 -0
- package/dist/core/auth/index.js.map +1 -0
- package/dist/core/auth/middleware.d.ts +73 -0
- package/dist/core/auth/middleware.d.ts.map +1 -0
- package/dist/core/auth/middleware.js +456 -0
- package/dist/core/auth/middleware.js.map +1 -0
- package/dist/core/auth/storage.d.ts +38 -0
- package/dist/core/auth/storage.d.ts.map +1 -0
- package/dist/core/auth/storage.js +280 -0
- package/dist/core/auth/storage.js.map +1 -0
- package/dist/core/keys/public.pem +9 -0
- package/dist/core/models/types.d.ts +426 -0
- package/dist/core/models/types.d.ts.map +1 -0
- package/dist/core/models/types.js +9 -0
- package/dist/core/models/types.js.map +1 -0
- package/dist/core/services/agent-template.service.d.ts +49 -0
- package/dist/core/services/agent-template.service.d.ts.map +1 -0
- package/dist/core/services/agent-template.service.js +88 -0
- package/dist/core/services/agent-template.service.js.map +1 -0
- package/dist/core/services/agent.service.d.ts +120 -0
- package/dist/core/services/agent.service.d.ts.map +1 -0
- package/dist/core/services/agent.service.js +381 -0
- package/dist/core/services/agent.service.js.map +1 -0
- package/dist/core/services/auth-profiles.service.d.ts +93 -0
- package/dist/core/services/auth-profiles.service.d.ts.map +1 -0
- package/dist/core/services/auth-profiles.service.js +220 -0
- package/dist/core/services/auth-profiles.service.js.map +1 -0
- package/dist/core/services/checklist.service.d.ts +58 -0
- package/dist/core/services/checklist.service.d.ts.map +1 -0
- package/dist/core/services/checklist.service.js +240 -0
- package/dist/core/services/checklist.service.js.map +1 -0
- package/dist/core/services/config-tracker.service.d.ts +119 -0
- package/dist/core/services/config-tracker.service.d.ts.map +1 -0
- package/dist/core/services/config-tracker.service.js +1093 -0
- package/dist/core/services/config-tracker.service.js.map +1 -0
- package/dist/core/services/crypto.service.d.ts +102 -0
- package/dist/core/services/crypto.service.d.ts.map +1 -0
- package/dist/core/services/crypto.service.js +377 -0
- package/dist/core/services/crypto.service.js.map +1 -0
- package/dist/core/services/dept.service.d.ts +92 -0
- package/dist/core/services/dept.service.d.ts.map +1 -0
- package/dist/core/services/dept.service.js +260 -0
- package/dist/core/services/dept.service.js.map +1 -0
- package/dist/core/services/document.service.d.ts +131 -0
- package/dist/core/services/document.service.d.ts.map +1 -0
- package/dist/core/services/document.service.js +368 -0
- package/dist/core/services/document.service.js.map +1 -0
- package/dist/core/services/domain.service.d.ts +50 -0
- package/dist/core/services/domain.service.d.ts.map +1 -0
- package/dist/core/services/domain.service.js +98 -0
- package/dist/core/services/domain.service.js.map +1 -0
- package/dist/core/services/feishu.service.d.ts +124 -0
- package/dist/core/services/feishu.service.d.ts.map +1 -0
- package/dist/core/services/feishu.service.js +165 -0
- package/dist/core/services/feishu.service.js.map +1 -0
- package/dist/core/services/index.d.ts +27 -0
- package/dist/core/services/index.d.ts.map +1 -0
- package/dist/core/services/index.js +89 -0
- package/dist/core/services/index.js.map +1 -0
- package/dist/core/services/job.service.d.ts +60 -0
- package/dist/core/services/job.service.d.ts.map +1 -0
- package/dist/core/services/job.service.js +190 -0
- package/dist/core/services/job.service.js.map +1 -0
- package/dist/core/services/log.service.d.ts +111 -0
- package/dist/core/services/log.service.d.ts.map +1 -0
- package/dist/core/services/log.service.js +237 -0
- package/dist/core/services/log.service.js.map +1 -0
- package/dist/core/services/message-failure.service.d.ts +65 -0
- package/dist/core/services/message-failure.service.d.ts.map +1 -0
- package/dist/core/services/message-failure.service.js +112 -0
- package/dist/core/services/message-failure.service.js.map +1 -0
- package/dist/core/services/message.service.d.ts +122 -0
- package/dist/core/services/message.service.d.ts.map +1 -0
- package/dist/core/services/message.service.js +374 -0
- package/dist/core/services/message.service.js.map +1 -0
- package/dist/core/services/node.service.d.ts +150 -0
- package/dist/core/services/node.service.d.ts.map +1 -0
- package/dist/core/services/node.service.js +257 -0
- package/dist/core/services/node.service.js.map +1 -0
- package/dist/core/services/openclaw-config.service.d.ts +187 -0
- package/dist/core/services/openclaw-config.service.d.ts.map +1 -0
- package/dist/core/services/openclaw-config.service.js +268 -0
- package/dist/core/services/openclaw-config.service.js.map +1 -0
- package/dist/core/services/preset-loader.service.d.ts +80 -0
- package/dist/core/services/preset-loader.service.d.ts.map +1 -0
- package/dist/core/services/preset-loader.service.js +379 -0
- package/dist/core/services/preset-loader.service.js.map +1 -0
- package/dist/core/services/role-flow.service.d.ts +21 -0
- package/dist/core/services/role-flow.service.d.ts.map +1 -0
- package/dist/core/services/role-flow.service.js +47 -0
- package/dist/core/services/role-flow.service.js.map +1 -0
- package/dist/core/services/setup.service.d.ts +46 -0
- package/dist/core/services/setup.service.d.ts.map +1 -0
- package/dist/core/services/setup.service.js +336 -0
- package/dist/core/services/setup.service.js.map +1 -0
- package/dist/core/services/skill-pack.service.d.ts +56 -0
- package/dist/core/services/skill-pack.service.d.ts.map +1 -0
- package/dist/core/services/skill-pack.service.js +113 -0
- package/dist/core/services/skill-pack.service.js.map +1 -0
- package/dist/core/services/task.service.d.ts +177 -0
- package/dist/core/services/task.service.d.ts.map +1 -0
- package/dist/core/services/task.service.js +397 -0
- package/dist/core/services/task.service.js.map +1 -0
- package/dist/core/services/template.service.d.ts +51 -0
- package/dist/core/services/template.service.d.ts.map +1 -0
- package/dist/core/services/template.service.js +88 -0
- package/dist/core/services/template.service.js.map +1 -0
- package/dist/core/services/user.service.d.ts +50 -0
- package/dist/core/services/user.service.d.ts.map +1 -0
- package/dist/core/services/user.service.js +111 -0
- package/dist/core/services/user.service.js.map +1 -0
- package/dist/core/utils/agent-guide-generator.d.ts +38 -0
- package/dist/core/utils/agent-guide-generator.d.ts.map +1 -0
- package/dist/core/utils/agent-guide-generator.js +187 -0
- package/dist/core/utils/agent-guide-generator.js.map +1 -0
- package/dist/core/utils/credentials-cleanup.d.ts +81 -0
- package/dist/core/utils/credentials-cleanup.d.ts.map +1 -0
- package/dist/core/utils/credentials-cleanup.js +256 -0
- package/dist/core/utils/credentials-cleanup.js.map +1 -0
- package/dist/core/utils/index.d.ts +215 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/index.js +462 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/openclaw-helper.d.ts +250 -0
- package/dist/core/utils/openclaw-helper.d.ts.map +1 -0
- package/dist/core/utils/openclaw-helper.js +1629 -0
- package/dist/core/utils/openclaw-helper.js.map +1 -0
- package/dist/core/utils/template-generator.d.ts +67 -0
- package/dist/core/utils/template-generator.d.ts.map +1 -0
- package/dist/core/utils/template-generator.js +170 -0
- package/dist/core/utils/template-generator.js.map +1 -0
- package/dist/db/index.d.ts +54 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +403 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/repositories/agent-template.repo.d.ts +47 -0
- package/dist/db/repositories/agent-template.repo.d.ts.map +1 -0
- package/dist/db/repositories/agent-template.repo.js +108 -0
- package/dist/db/repositories/agent-template.repo.js.map +1 -0
- package/dist/db/repositories/agent.repo.d.ts +64 -0
- package/dist/db/repositories/agent.repo.d.ts.map +1 -0
- package/dist/db/repositories/agent.repo.js +103 -0
- package/dist/db/repositories/agent.repo.js.map +1 -0
- package/dist/db/repositories/base.repository.d.ts +51 -0
- package/dist/db/repositories/base.repository.d.ts.map +1 -0
- package/dist/db/repositories/base.repository.js +107 -0
- package/dist/db/repositories/base.repository.js.map +1 -0
- package/dist/db/repositories/company.repo.d.ts +18 -0
- package/dist/db/repositories/company.repo.d.ts.map +1 -0
- package/dist/db/repositories/company.repo.js +33 -0
- package/dist/db/repositories/company.repo.js.map +1 -0
- package/dist/db/repositories/config-change.repo.d.ts +65 -0
- package/dist/db/repositories/config-change.repo.d.ts.map +1 -0
- package/dist/db/repositories/config-change.repo.js +119 -0
- package/dist/db/repositories/config-change.repo.js.map +1 -0
- package/dist/db/repositories/dept.repo.d.ts +37 -0
- package/dist/db/repositories/dept.repo.d.ts.map +1 -0
- package/dist/db/repositories/dept.repo.js +66 -0
- package/dist/db/repositories/dept.repo.js.map +1 -0
- package/dist/db/repositories/document.repo.d.ts +25 -0
- package/dist/db/repositories/document.repo.d.ts.map +1 -0
- package/dist/db/repositories/document.repo.js +51 -0
- package/dist/db/repositories/document.repo.js.map +1 -0
- package/dist/db/repositories/domain.repo.d.ts +42 -0
- package/dist/db/repositories/domain.repo.d.ts.map +1 -0
- package/dist/db/repositories/domain.repo.js +79 -0
- package/dist/db/repositories/domain.repo.js.map +1 -0
- package/dist/db/repositories/index.d.ts +24 -0
- package/dist/db/repositories/index.d.ts.map +1 -0
- package/dist/db/repositories/index.js +81 -0
- package/dist/db/repositories/index.js.map +1 -0
- package/dist/db/repositories/init-session.repo.d.ts +38 -0
- package/dist/db/repositories/init-session.repo.d.ts.map +1 -0
- package/dist/db/repositories/init-session.repo.js +112 -0
- package/dist/db/repositories/init-session.repo.js.map +1 -0
- package/dist/db/repositories/job.repo.d.ts +54 -0
- package/dist/db/repositories/job.repo.d.ts.map +1 -0
- package/dist/db/repositories/job.repo.js +119 -0
- package/dist/db/repositories/job.repo.js.map +1 -0
- package/dist/db/repositories/message-failure.repo.d.ts +92 -0
- package/dist/db/repositories/message-failure.repo.d.ts.map +1 -0
- package/dist/db/repositories/message-failure.repo.js +141 -0
- package/dist/db/repositories/message-failure.repo.js.map +1 -0
- package/dist/db/repositories/message-log.repo.d.ts +36 -0
- package/dist/db/repositories/message-log.repo.d.ts.map +1 -0
- package/dist/db/repositories/message-log.repo.js +64 -0
- package/dist/db/repositories/message-log.repo.js.map +1 -0
- package/dist/db/repositories/node.repo.d.ts +107 -0
- package/dist/db/repositories/node.repo.d.ts.map +1 -0
- package/dist/db/repositories/node.repo.js +276 -0
- package/dist/db/repositories/node.repo.js.map +1 -0
- package/dist/db/repositories/role-flow.repo.d.ts +43 -0
- package/dist/db/repositories/role-flow.repo.d.ts.map +1 -0
- package/dist/db/repositories/role-flow.repo.js +83 -0
- package/dist/db/repositories/role-flow.repo.js.map +1 -0
- package/dist/db/repositories/skill-pack.repo.d.ts +45 -0
- package/dist/db/repositories/skill-pack.repo.d.ts.map +1 -0
- package/dist/db/repositories/skill-pack.repo.js +149 -0
- package/dist/db/repositories/skill-pack.repo.js.map +1 -0
- package/dist/db/repositories/task.repo.d.ts +168 -0
- package/dist/db/repositories/task.repo.d.ts.map +1 -0
- package/dist/db/repositories/task.repo.js +381 -0
- package/dist/db/repositories/task.repo.js.map +1 -0
- package/dist/db/repositories/template.repo.d.ts +40 -0
- package/dist/db/repositories/template.repo.d.ts.map +1 -0
- package/dist/db/repositories/template.repo.js +66 -0
- package/dist/db/repositories/template.repo.js.map +1 -0
- package/dist/db/repositories/user.repo.d.ts +46 -0
- package/dist/db/repositories/user.repo.d.ts.map +1 -0
- package/dist/db/repositories/user.repo.js +75 -0
- package/dist/db/repositories/user.repo.js.map +1 -0
- package/dist/db/schema.sql +364 -0
- package/package.json +90 -0
- package/resources/preset-data-hash.enc +1 -0
- 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
|