plugin-agent-orchestrator 1.0.28 → 1.0.32

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 (108) hide show
  1. package/README.md +9 -7
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/{214.723affb37c13bf7a.js → 214.79650a549273f163.js} +1 -1
  4. package/dist/client-v2/264.718a107e43fc163c.js +10 -0
  5. package/dist/client-v2/373.f5d5292e53c4e832.js +10 -0
  6. package/dist/client-v2/{41.1805b2edfaa4afe2.js → 41.ba6e080cc0488143.js} +1 -1
  7. package/dist/client-v2/418.29e713f79131eece.js +10 -0
  8. package/dist/client-v2/619.bd3c5698b40705c3.js +10 -0
  9. package/dist/client-v2/677.a991ce0250ff5c77.js +10 -0
  10. package/dist/client-v2/{70.a15d7fcec7c41768.js → 70.bda9518881c05360.js} +1 -1
  11. package/dist/client-v2/925.f5370de8f6632d65.js +10 -0
  12. package/dist/client-v2/index.js +1 -1
  13. package/dist/externalVersion.js +7 -10
  14. package/dist/locale/en-US.json +94 -25
  15. package/dist/locale/vi-VN.json +94 -25
  16. package/dist/locale/zh-CN.json +94 -25
  17. package/dist/server/collections/agent-execution-spans.js +37 -0
  18. package/dist/server/collections/agent-harness-profiles.js +2 -2
  19. package/dist/server/collections/agent-memory-contexts.js +125 -0
  20. package/dist/server/collections/orchestrator-logs.js +2 -2
  21. package/dist/server/migrations/20260425000000-add-interaction-schema.js +3 -1
  22. package/dist/server/migrations/20260427000000-change-packages-to-text.js +3 -1
  23. package/dist/server/migrations/20260427000001-change-other-json-to-text.js +6 -2
  24. package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.js +21 -19
  25. package/dist/server/migrations/20260621000000-native-policy-profile-defaults.js +193 -0
  26. package/dist/server/plugin.js +128 -74
  27. package/dist/server/resources/agent-monitor.js +454 -0
  28. package/dist/server/services/AgentHarness.js +24 -499
  29. package/dist/server/services/AgentMemoryContextService.js +216 -0
  30. package/dist/server/services/ExecutionSpanService.js +2 -2
  31. package/dist/server/services/NativeSubAgentObserver.js +413 -0
  32. package/dist/server/skill-hub/plugin.js +81 -5
  33. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +9 -3
  34. package/dist/server/tools/delegate-task.js +11 -589
  35. package/dist/server/utils/skill-settings.js +18 -1
  36. package/package.json +47 -49
  37. package/src/client/AIEmployeesContext.tsx +5 -18
  38. package/src/client/AgentRunsTab.tsx +2 -771
  39. package/src/client/HarnessProfilesTab.tsx +2 -257
  40. package/src/client/OrchestratorSettings.tsx +97 -106
  41. package/src/client/RulesTab.tsx +2 -788
  42. package/src/client/plugin.tsx +0 -2
  43. package/src/client/skill-hub/components/ExecutionHistory.tsx +200 -202
  44. package/src/client/skill-hub/components/ExecutionProgress.tsx +51 -55
  45. package/src/client/skill-hub/components/LoopSettings.tsx +331 -331
  46. package/src/client/skill-hub/components/SkillEditor.tsx +43 -39
  47. package/src/client/skill-hub/components/SkillManager.tsx +194 -181
  48. package/src/client/skill-hub/components/SkillTestPanel.tsx +141 -145
  49. package/src/client/skill-hub/locale.ts +16 -16
  50. package/src/client/skill-hub/tools/SkillHubCard.tsx +104 -109
  51. package/src/client/skill-hub/tools/loopTemplates.ts +52 -52
  52. package/src/client/skill-hub/utils/jsonFields.ts +7 -3
  53. package/src/client-v2/components/AIEmployeesContext.tsx +3 -16
  54. package/src/client-v2/components/AgentRunsTab.tsx +182 -455
  55. package/src/client-v2/components/HarnessProfilesTab.tsx +34 -31
  56. package/src/client-v2/components/RulesTab.tsx +2 -782
  57. package/src/client-v2/components/TracingTab.tsx +1 -1
  58. package/src/client-v2/hooks/useApiRequest.ts +8 -1
  59. package/src/client-v2/pages/RulesPage.tsx +2 -2
  60. package/src/client-v2/plugin.tsx +3 -3
  61. package/src/locale/en-US.json +94 -25
  62. package/src/locale/vi-VN.json +94 -25
  63. package/src/locale/zh-CN.json +94 -25
  64. package/src/server/__tests__/native-sub-agent-observer.test.ts +246 -0
  65. package/src/server/__tests__/skill-settings.test.ts +6 -6
  66. package/src/server/__tests__/smoke.test.ts +1 -0
  67. package/src/server/collections/agent-execution-spans.ts +37 -0
  68. package/src/server/collections/agent-harness-profiles.ts +59 -59
  69. package/src/server/collections/agent-loop-events.ts +71 -71
  70. package/src/server/collections/agent-loop-steps.ts +144 -144
  71. package/src/server/collections/agent-memory-contexts.ts +95 -0
  72. package/src/server/collections/orchestrator-logs.ts +4 -4
  73. package/src/server/collections/skill-definitions.ts +111 -111
  74. package/src/server/collections/skill-executions.ts +106 -106
  75. package/src/server/collections/skill-loop-configs.ts +65 -65
  76. package/src/server/migrations/20260423000000-add-progress-fields.ts +14 -14
  77. package/src/server/migrations/20260425000000-add-interaction-schema.ts +3 -1
  78. package/src/server/migrations/20260427000000-change-packages-to-text.ts +4 -2
  79. package/src/server/migrations/20260427000001-change-other-json-to-text.ts +9 -5
  80. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +30 -30
  81. package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +145 -142
  82. package/src/server/migrations/20260615000000-normalize-ai-employee-tool-bindings.ts +2 -2
  83. package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +193 -0
  84. package/src/server/plugin.ts +151 -94
  85. package/src/server/resources/agent-monitor.ts +482 -0
  86. package/src/server/services/AgentHarness.ts +38 -623
  87. package/src/server/services/AgentMemoryContextService.ts +256 -0
  88. package/src/server/services/AgentPlanValidator.ts +73 -73
  89. package/src/server/services/ExecutionSpanService.ts +6 -2
  90. package/src/server/services/FileManager.ts +144 -144
  91. package/src/server/services/NativeSubAgentObserver.ts +507 -0
  92. package/src/server/services/SkillManager.ts +583 -583
  93. package/src/server/services/SkillRepositoryService.ts +5 -7
  94. package/src/server/services/TokenTracker.ts +3 -3
  95. package/src/server/services/WorkerEnvManager.ts +1 -2
  96. package/src/server/skill-hub/actions/git-import.ts +5 -7
  97. package/src/server/skill-hub/plugin.ts +89 -6
  98. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +470 -460
  99. package/src/server/skill-hub/utils/json-fields.ts +1 -1
  100. package/src/server/tools/delegate-task.ts +13 -847
  101. package/src/server/utils/skill-settings.ts +24 -6
  102. package/dist/client-v2/264.0533912e6c5ea2d7.js +0 -10
  103. package/dist/client-v2/418.5ae055abf141820e.js +0 -10
  104. package/dist/client-v2/619.d99d3c9e61c99064.js +0 -10
  105. package/dist/client-v2/892.72db4161511c8a16.js +0 -10
  106. package/dist/client-v2/926.87f660b670d85bcc.js +0 -10
  107. package/src/client/tools/PlanApprovalCard.tsx +0 -176
  108. package/src/client/tools/registerOrchestratorCards.ts +0 -17
@@ -0,0 +1,125 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var agent_memory_contexts_exports = {};
28
+ __export(agent_memory_contexts_exports, {
29
+ default: () => agent_memory_contexts_default
30
+ });
31
+ module.exports = __toCommonJS(agent_memory_contexts_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var agent_memory_contexts_default = (0, import_database.defineCollection)({
34
+ name: "agentMemoryContexts",
35
+ title: "Agent Memory Contexts",
36
+ fields: [
37
+ {
38
+ name: "id",
39
+ type: "bigInt",
40
+ autoIncrement: true,
41
+ primaryKey: true
42
+ },
43
+ {
44
+ name: "scope",
45
+ type: "string",
46
+ length: 30,
47
+ allowNull: false,
48
+ comment: "public, user, or agent_user"
49
+ },
50
+ {
51
+ name: "contextKey",
52
+ type: "string",
53
+ length: 300,
54
+ allowNull: false,
55
+ comment: "Normalized unique key: scope:userId:aiEmployeeUsername."
56
+ },
57
+ {
58
+ name: "userId",
59
+ type: "bigInt",
60
+ comment: "Null for public agent knowledge; required for user/private scopes."
61
+ },
62
+ {
63
+ name: "user",
64
+ type: "belongsTo",
65
+ target: "users",
66
+ targetKey: "id",
67
+ foreignKey: "userId"
68
+ },
69
+ {
70
+ name: "aiEmployeeUsername",
71
+ type: "string",
72
+ length: 100,
73
+ comment: "Target AI employee username; null/empty means shared within the scope."
74
+ },
75
+ {
76
+ name: "contentMd",
77
+ type: "text",
78
+ comment: "Markdown facts, preferences, or operating notes for the agent context."
79
+ },
80
+ {
81
+ name: "graphMd",
82
+ type: "text",
83
+ comment: "Markdown graph or relationship notes for the agent context."
84
+ },
85
+ {
86
+ name: "enabled",
87
+ type: "boolean",
88
+ defaultValue: true
89
+ },
90
+ {
91
+ name: "metadata",
92
+ type: "json",
93
+ defaultValue: {}
94
+ },
95
+ {
96
+ name: "createdAt",
97
+ type: "date"
98
+ },
99
+ {
100
+ name: "updatedAt",
101
+ type: "date"
102
+ }
103
+ ],
104
+ indexes: [
105
+ {
106
+ unique: true,
107
+ fields: ["contextKey"]
108
+ },
109
+ {
110
+ fields: ["scope", "userId", "aiEmployeeUsername"]
111
+ },
112
+ {
113
+ fields: ["scope"]
114
+ },
115
+ {
116
+ fields: ["userId"]
117
+ },
118
+ {
119
+ fields: ["aiEmployeeUsername"]
120
+ },
121
+ {
122
+ fields: ["enabled"]
123
+ }
124
+ ]
125
+ });
@@ -55,7 +55,7 @@ var orchestrator_logs_default = (0, import_database.defineCollection)({
55
55
  {
56
56
  name: "toolName",
57
57
  type: "string",
58
- comment: "The tool name used for delegation (e.g., delegate_pm_to_sql_expert)"
58
+ comment: "Legacy delegation or native dispatch tool name"
59
59
  },
60
60
  {
61
61
  name: "context",
@@ -103,7 +103,7 @@ var orchestrator_logs_default = (0, import_database.defineCollection)({
103
103
  name: "messages",
104
104
  type: "json",
105
105
  defaultValue: [],
106
- comment: "Serialized LangChain messages from the sub-agent run"
106
+ comment: "Serialized message snapshots from the sub-agent run"
107
107
  },
108
108
  {
109
109
  name: "userId",
@@ -52,7 +52,9 @@ class AddInteractionSchemaMigration extends import_server.Migration {
52
52
  interface: "textarea"
53
53
  }
54
54
  });
55
- this.app.logger.info("[skill-hub] Restored NocoBase metadata for preexisting column interactionSchema");
55
+ this.app.logger.info(
56
+ "[skill-hub] Restored NocoBase metadata for preexisting column interactionSchema"
57
+ );
56
58
  }
57
59
  } catch (error) {
58
60
  this.app.logger.error(`[skill-hub] Failed to check interactionSchema field: ${error.message}`);
@@ -45,7 +45,9 @@ class ChangePackagesToTextMigration extends import_server.Migration {
45
45
  if (tableDesc[col]) {
46
46
  const dialect = this.db.sequelize.getDialect();
47
47
  if (dialect === "postgres") {
48
- await this.db.sequelize.query(`ALTER TABLE "${tableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`);
48
+ await this.db.sequelize.query(
49
+ `ALTER TABLE "${tableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`
50
+ );
49
51
  } else {
50
52
  await queryInterface.changeColumn(tableName, col, {
51
53
  type: "TEXT"
@@ -44,7 +44,9 @@ class ChangeOtherJsonToTextMigration extends import_server.Migration {
44
44
  for (const col of columns) {
45
45
  if (tableDesc[col]) {
46
46
  if (dialect === "postgres") {
47
- await this.db.sequelize.query(`ALTER TABLE "${workerTableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`);
47
+ await this.db.sequelize.query(
48
+ `ALTER TABLE "${workerTableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`
49
+ );
48
50
  } else {
49
51
  await queryInterface.changeColumn(workerTableName, col, { type: "TEXT" });
50
52
  }
@@ -64,7 +66,9 @@ class ChangeOtherJsonToTextMigration extends import_server.Migration {
64
66
  const col = "outputFiles";
65
67
  if (tableDesc[col]) {
66
68
  if (dialect === "postgres") {
67
- await this.db.sequelize.query(`ALTER TABLE "${execTableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`);
69
+ await this.db.sequelize.query(
70
+ `ALTER TABLE "${execTableName}" ALTER COLUMN "${col}" TYPE text USING "${col}"::text;`
71
+ );
68
72
  } else {
69
73
  await queryInterface.changeColumn(execTableName, col, { type: "TEXT" });
70
74
  }
@@ -108,38 +108,40 @@ class AddPlanApprovalAndHarnessProfiles extends import_server.Migration {
108
108
  {
109
109
  tag: "default",
110
110
  title: "Default",
111
- description: "Balanced profile for normal multi-agent work.",
111
+ description: "Default native observer and memory policy for normal AI employee work.",
112
112
  settings: {
113
- requirePlanApproval: true,
114
- allowSubAgents: true,
115
- allowToolCalls: true,
116
- maxParallelSubAgents: 3,
117
- maxControllerSteps: 100
113
+ nativeObserverEnabled: true,
114
+ memoryInjectionEnabled: true,
115
+ memoryScopes: ["public", "user", "agent_user"],
116
+ knowledgeScopes: ["public", "private"],
117
+ maxMemoryContextChars: 6e3,
118
+ tracingRetentionDays: 30
118
119
  }
119
120
  },
120
121
  {
121
122
  tag: "safe",
122
123
  title: "Safe",
123
- description: "Strict approval-first profile for higher-risk work.",
124
+ description: "Conservative native observer policy with private context enabled only for matching user/agent pairs.",
124
125
  settings: {
125
- requirePlanApproval: true,
126
- allowSubAgents: true,
127
- allowToolCalls: true,
128
- maxParallelSubAgents: 1,
129
- maxControllerSteps: 50,
130
- requireVerification: true
126
+ nativeObserverEnabled: true,
127
+ memoryInjectionEnabled: true,
128
+ memoryScopes: ["public", "user", "agent_user"],
129
+ knowledgeScopes: ["public", "private"],
130
+ maxMemoryContextChars: 4e3,
131
+ tracingRetentionDays: 14
131
132
  }
132
133
  },
133
134
  {
134
135
  tag: "file-heavy",
135
136
  title: "File Heavy",
136
- description: "Profile for tasks that inspect or transform many attachments/files.",
137
+ description: "Native observer policy for agents that need more context while working with files and artifacts.",
137
138
  settings: {
138
- requirePlanApproval: true,
139
- allowSubAgents: true,
140
- allowToolCalls: true,
141
- maxParallelSubAgents: 2,
142
- maxControllerSteps: 120,
139
+ nativeObserverEnabled: true,
140
+ memoryInjectionEnabled: true,
141
+ memoryScopes: ["public", "user", "agent_user"],
142
+ knowledgeScopes: ["public", "private"],
143
+ maxMemoryContextChars: 8e3,
144
+ tracingRetentionDays: 30,
143
145
  preferFileTools: true
144
146
  }
145
147
  }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var native_policy_profile_defaults_exports = {};
28
+ __export(native_policy_profile_defaults_exports, {
29
+ default: () => NativePolicyProfileDefaults
30
+ });
31
+ module.exports = __toCommonJS(native_policy_profile_defaults_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var import_server = require("@nocobase/server");
34
+ var import_skill_settings = require("../utils/skill-settings");
35
+ const nativePolicyProfiles = [
36
+ {
37
+ tag: "default",
38
+ title: "Default",
39
+ description: "Default native observer and memory policy for normal AI employee work.",
40
+ settings: {
41
+ nativeObserverEnabled: true,
42
+ memoryInjectionEnabled: true,
43
+ memoryScopes: ["public", "user", "agent_user"],
44
+ knowledgeScopes: ["public", "private"],
45
+ maxMemoryContextChars: 6e3,
46
+ tracingRetentionDays: 30
47
+ }
48
+ },
49
+ {
50
+ tag: "safe",
51
+ title: "Safe",
52
+ description: "Conservative native observer policy with private context enabled only for matching user/agent pairs.",
53
+ settings: {
54
+ nativeObserverEnabled: true,
55
+ memoryInjectionEnabled: true,
56
+ memoryScopes: ["public", "user", "agent_user"],
57
+ knowledgeScopes: ["public", "private"],
58
+ maxMemoryContextChars: 4e3,
59
+ tracingRetentionDays: 14
60
+ }
61
+ },
62
+ {
63
+ tag: "file-heavy",
64
+ title: "File Heavy",
65
+ description: "Native observer policy for agents that need more context while working with files and artifacts.",
66
+ settings: {
67
+ nativeObserverEnabled: true,
68
+ memoryInjectionEnabled: true,
69
+ memoryScopes: ["public", "user", "agent_user"],
70
+ knowledgeScopes: ["public", "private"],
71
+ maxMemoryContextChars: 8e3,
72
+ tracingRetentionDays: 30,
73
+ preferFileTools: true
74
+ }
75
+ }
76
+ ];
77
+ function readModelValue(record, key) {
78
+ const model = record;
79
+ return typeof (model == null ? void 0 : model.get) === "function" ? model.get(key) : model == null ? void 0 : model[key];
80
+ }
81
+ function asObject(value) {
82
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
83
+ }
84
+ function dropRetiredPolicyKeys(settings) {
85
+ const retired = /* @__PURE__ */ new Set([
86
+ "requirePlanApproval",
87
+ "allowSubAgents",
88
+ "allowToolCalls",
89
+ "maxParallelSubAgents",
90
+ "maxControllerSteps",
91
+ "requireVerification"
92
+ ]);
93
+ return Object.fromEntries(Object.entries(settings).filter(([key]) => !retired.has(key)));
94
+ }
95
+ function normalizeOptionalString(value) {
96
+ return typeof value === "string" ? value.trim() : "";
97
+ }
98
+ function buildContextKey(record) {
99
+ const scope = normalizeOptionalString(record.scope);
100
+ const userPart = scope === "public" ? "public" : String(record.userId || "");
101
+ const agentPart = normalizeOptionalString(record.aiEmployeeUsername) || "*";
102
+ return `${scope}:${userPart}:${agentPart}`;
103
+ }
104
+ class NativePolicyProfileDefaults extends import_server.Migration {
105
+ on = "afterLoad";
106
+ appVersion = ">=0.1.0";
107
+ async up() {
108
+ await this.ensureNativePolicyProfiles();
109
+ await this.ensureAgentMemoryContextKeys();
110
+ await this.normalizeAIEmployeeToolBindings();
111
+ }
112
+ async ensureNativePolicyProfiles() {
113
+ const repo = this.db.getRepository(
114
+ "agentHarnessProfiles"
115
+ );
116
+ if (!repo) return;
117
+ for (const profile of nativePolicyProfiles) {
118
+ const existing = await repo.findOne({ filter: { tag: profile.tag } });
119
+ if (!existing) {
120
+ await repo.create({
121
+ values: {
122
+ ...profile,
123
+ enabled: true,
124
+ createdAt: /* @__PURE__ */ new Date(),
125
+ updatedAt: /* @__PURE__ */ new Date()
126
+ }
127
+ });
128
+ continue;
129
+ }
130
+ const currentSettings = asObject(readModelValue(existing, "settings"));
131
+ const nextSettings = {
132
+ ...profile.settings,
133
+ ...dropRetiredPolicyKeys(currentSettings)
134
+ };
135
+ await existing.update({
136
+ settings: nextSettings,
137
+ updatedAt: /* @__PURE__ */ new Date()
138
+ });
139
+ }
140
+ }
141
+ async ensureAgentMemoryContextKeys() {
142
+ var _a;
143
+ const db = this.db;
144
+ const queryInterface = db.sequelize.getQueryInterface();
145
+ const tableName = `${db.options.tablePrefix || ""}agentMemoryContexts`;
146
+ const tableExists = await queryInterface.describeTable(tableName).then(() => true).catch(() => false);
147
+ if (!tableExists) return;
148
+ const tableDesc = await queryInterface.describeTable(tableName);
149
+ if (!tableDesc.contextKey) {
150
+ await queryInterface.addColumn(tableName, "contextKey", {
151
+ type: import_database.DataTypes.STRING(300),
152
+ allowNull: true
153
+ });
154
+ }
155
+ const repo = db.getRepository("agentMemoryContexts");
156
+ const rows = await repo.find({});
157
+ for (const row of rows) {
158
+ const data = ((_a = row.toJSON) == null ? void 0 : _a.call(row)) || row;
159
+ if (!normalizeOptionalString(data.scope)) continue;
160
+ const contextKey = normalizeOptionalString(data.contextKey) || buildContextKey(data);
161
+ if (!contextKey) continue;
162
+ if (contextKey !== data.contextKey) {
163
+ await row.update({ contextKey });
164
+ }
165
+ }
166
+ await queryInterface.changeColumn(tableName, "contextKey", {
167
+ type: import_database.DataTypes.STRING(300),
168
+ allowNull: false
169
+ }).catch(() => {
170
+ });
171
+ await queryInterface.addIndex(tableName, ["contextKey"], {
172
+ unique: true,
173
+ name: `${tableName}_contextKey_unique`
174
+ }).catch(() => {
175
+ });
176
+ }
177
+ async normalizeAIEmployeeToolBindings() {
178
+ var _a;
179
+ const repo = this.db.getRepository("aiEmployees");
180
+ if (!repo) return;
181
+ const rows = await repo.find({});
182
+ for (const row of rows) {
183
+ const skillSettings = ((_a = row.get) == null ? void 0 : _a.call(row, "skillSettings")) ?? row.skillSettings;
184
+ const normalized = (0, import_skill_settings.normalizeAIEmployeeSkillSettings)(skillSettings);
185
+ if (!normalized.changed) continue;
186
+ await row.update({
187
+ skillSettings: normalized.skillSettings
188
+ });
189
+ }
190
+ }
191
+ async down() {
192
+ }
193
+ }