plugin-agent-orchestrator 1.2.1 → 1.2.3
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/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/adm-zip/package.json +1 -1
- package/dist/node_modules/ajv/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/plugin.js +28 -13
- package/dist/server/services/ParallelInterruptActionsPatch.js +132 -0
- package/dist/server/utils/normalize-hierarchy-invocation-index.js +55 -0
- package/package.json +2 -2
- package/src/server/__tests__/hierarchy-invocation-journal.integration.test.ts +65 -1
- package/src/server/__tests__/normalize-hierarchy-invocation-index.test.ts +72 -0
- package/src/server/__tests__/parallel-interrupt-actions.test.ts +342 -0
- package/src/server/plugin.ts +17 -1
- package/src/server/services/ParallelInterruptActionsPatch.ts +164 -0
- package/src/server/utils/normalize-hierarchy-invocation-index.ts +27 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"acorn","description":"ECMAScript parser","homepage":"https://github.com/acornjs/acorn","main":"dist/acorn.js","types":"dist/acorn.d.ts","module":"dist/acorn.mjs","exports":{".":[{"import":"./dist/acorn.mjs","require":"./dist/acorn.js","default":"./dist/acorn.js"},"./dist/acorn.js"],"./package.json":"./package.json"},"version":"8.11.2","engines":{"node":">=0.4.0"},"maintainers":[{"name":"Marijn Haverbeke","email":"marijnh@gmail.com","web":"https://marijnhaverbeke.nl"},{"name":"Ingvar Stepanyan","email":"me@rreverser.com","web":"https://rreverser.com/"},{"name":"Adrian Heine","web":"http://adrianheine.de"}],"repository":{"type":"git","url":"https://github.com/acornjs/acorn.git"},"license":"MIT","scripts":{"prepare":"cd ..; npm run build:main"},"bin":{"acorn":"./bin/acorn"},"_lastModified":"2026-11-
|
|
1
|
+
{"name":"acorn","description":"ECMAScript parser","homepage":"https://github.com/acornjs/acorn","main":"dist/acorn.js","types":"dist/acorn.d.ts","module":"dist/acorn.mjs","exports":{".":[{"import":"./dist/acorn.mjs","require":"./dist/acorn.js","default":"./dist/acorn.js"},"./dist/acorn.js"],"./package.json":"./package.json"},"version":"8.11.2","engines":{"node":">=0.4.0"},"maintainers":[{"name":"Marijn Haverbeke","email":"marijnh@gmail.com","web":"https://marijnhaverbeke.nl"},{"name":"Ingvar Stepanyan","email":"me@rreverser.com","web":"https://rreverser.com/"},{"name":"Adrian Heine","web":"http://adrianheine.de"}],"repository":{"type":"git","url":"https://github.com/acornjs/acorn.git"},"license":"MIT","scripts":{"prepare":"cd ..; npm run build:main"},"bin":{"acorn":"./bin/acorn"},"_lastModified":"2026-11-21T09:53:43.775Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"acorn-walk","description":"ECMAScript (ESTree) AST walker","homepage":"https://github.com/acornjs/acorn","main":"dist/walk.js","types":"dist/walk.d.ts","module":"dist/walk.mjs","exports":{".":[{"import":"./dist/walk.mjs","require":"./dist/walk.js","default":"./dist/walk.js"},"./dist/walk.js"],"./package.json":"./package.json"},"version":"8.3.4","engines":{"node":">=0.4.0"},"dependencies":{"acorn":"^8.11.0"},"maintainers":[{"name":"Marijn Haverbeke","email":"marijnh@gmail.com","web":"https://marijnhaverbeke.nl"},{"name":"Ingvar Stepanyan","email":"me@rreverser.com","web":"https://rreverser.com/"},{"name":"Adrian Heine","web":"http://adrianheine.de"}],"repository":{"type":"git","url":"https://github.com/acornjs/acorn.git"},"scripts":{"prepare":"cd ..; npm run build:walk"},"license":"MIT","_lastModified":"2026-11-
|
|
1
|
+
{"name":"acorn-walk","description":"ECMAScript (ESTree) AST walker","homepage":"https://github.com/acornjs/acorn","main":"dist/walk.js","types":"dist/walk.d.ts","module":"dist/walk.mjs","exports":{".":[{"import":"./dist/walk.mjs","require":"./dist/walk.js","default":"./dist/walk.js"},"./dist/walk.js"],"./package.json":"./package.json"},"version":"8.3.4","engines":{"node":">=0.4.0"},"dependencies":{"acorn":"^8.11.0"},"maintainers":[{"name":"Marijn Haverbeke","email":"marijnh@gmail.com","web":"https://marijnhaverbeke.nl"},{"name":"Ingvar Stepanyan","email":"me@rreverser.com","web":"https://rreverser.com/"},{"name":"Adrian Heine","web":"http://adrianheine.de"}],"repository":{"type":"git","url":"https://github.com/acornjs/acorn.git"},"scripts":{"prepare":"cd ..; npm run build:walk"},"license":"MIT","_lastModified":"2026-11-21T09:53:43.940Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"adm-zip","version":"0.5.17","description":"Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk","scripts":{"test":"mocha -R spec","test:format":"npm run format:prettier:raw -- --check","format":"npm run format:prettier","format:prettier":"npm run format:prettier:raw -- --write","format:prettier:raw":"prettier \"**/*.{js,yml,json}\""},"keywords":["zip","methods","archive","unzip"],"homepage":"https://github.com/cthackers/adm-zip","author":"Nasca Iacob <sy@another-d-mention.ro> (https://github.com/cthackers)","bugs":{"email":"sy@another-d-mention.ro","url":"https://github.com/cthackers/adm-zip/issues"},"license":"MIT","files":["adm-zip.js","headers","methods","util","zipEntry.js","zipFile.js","LICENSE"],"main":"adm-zip.js","repository":{"type":"git","url":"https://github.com/cthackers/adm-zip.git"},"engines":{"node":">=12.0"},"overrides":{"mocha":{"chokidar":"^4.0.3"}},"devDependencies":{"chai":"^6.2.2","iconv-lite":"^0.7.2","mocha":"12.0.0-beta-10","prettier":"^3.8.1","rimraf":"^3.0.2"},"_lastModified":"2026-11-
|
|
1
|
+
{"name":"adm-zip","version":"0.5.17","description":"Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk","scripts":{"test":"mocha -R spec","test:format":"npm run format:prettier:raw -- --check","format":"npm run format:prettier","format:prettier":"npm run format:prettier:raw -- --write","format:prettier:raw":"prettier \"**/*.{js,yml,json}\""},"keywords":["zip","methods","archive","unzip"],"homepage":"https://github.com/cthackers/adm-zip","author":"Nasca Iacob <sy@another-d-mention.ro> (https://github.com/cthackers)","bugs":{"email":"sy@another-d-mention.ro","url":"https://github.com/cthackers/adm-zip/issues"},"license":"MIT","files":["adm-zip.js","headers","methods","util","zipEntry.js","zipFile.js","LICENSE"],"main":"adm-zip.js","repository":{"type":"git","url":"https://github.com/cthackers/adm-zip.git"},"engines":{"node":">=12.0"},"overrides":{"mocha":{"chokidar":"^4.0.3"}},"devDependencies":{"chai":"^6.2.2","iconv-lite":"^0.7.2","mocha":"12.0.0-beta-10","prettier":"^3.8.1","rimraf":"^3.0.2"},"_lastModified":"2026-11-21T09:53:43.327Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ajv","version":"6.12.6","description":"Another JSON Schema Validator","main":"lib/ajv.js","typings":"lib/ajv.d.ts","files":["lib/","dist/","scripts/","LICENSE",".tonic_example.js"],"scripts":{"eslint":"eslint lib/{compile/,}*.js spec/{**/,}*.js scripts --ignore-pattern spec/JSON-Schema-Test-Suite","jshint":"jshint lib/{compile/,}*.js","lint":"npm run jshint && npm run eslint","test-spec":"mocha spec/{**/,}*.spec.js -R spec","test-fast":"AJV_FAST_TEST=true npm run test-spec","test-debug":"npm run test-spec -- --inspect-brk","test-cov":"nyc npm run test-spec","test-ts":"tsc --target ES5 --noImplicitAny --noEmit spec/typescript/index.ts","bundle":"del-cli dist && node ./scripts/bundle.js . Ajv pure_getters","bundle-beautify":"node ./scripts/bundle.js js-beautify","build":"del-cli lib/dotjs/*.js \"!lib/dotjs/index.js\" && node scripts/compile-dots.js","test-karma":"karma start","test-browser":"del-cli .browser && npm run bundle && scripts/prepare-tests && npm run test-karma","test-all":"npm run test-cov && if-node-version 10 npm run test-browser","test":"npm run lint && npm run build && npm run test-all","prepublish":"npm run build && npm run bundle","watch":"watch \"npm run build\" ./lib/dot"},"nyc":{"exclude":["**/spec/**","node_modules"],"reporter":["lcov","text-summary"]},"repository":{"type":"git","url":"https://github.com/ajv-validator/ajv.git"},"keywords":["JSON","schema","validator","validation","jsonschema","json-schema","json-schema-validator","json-schema-validation"],"author":"Evgeny Poberezkin","license":"MIT","bugs":{"url":"https://github.com/ajv-validator/ajv/issues"},"homepage":"https://github.com/ajv-validator/ajv","tonicExampleFilename":".tonic_example.js","dependencies":{"fast-deep-equal":"^3.1.1","fast-json-stable-stringify":"^2.0.0","json-schema-traverse":"^0.4.1","uri-js":"^4.2.2"},"devDependencies":{"ajv-async":"^1.0.0","bluebird":"^3.5.3","brfs":"^2.0.0","browserify":"^16.2.0","chai":"^4.0.1","coveralls":"^3.0.1","del-cli":"^3.0.0","dot":"^1.0.3","eslint":"^7.3.1","gh-pages-generator":"^0.2.3","glob":"^7.0.0","if-node-version":"^1.0.0","js-beautify":"^1.7.3","jshint":"^2.10.2","json-schema-test":"^2.0.0","karma":"^5.0.0","karma-chrome-launcher":"^3.0.0","karma-mocha":"^2.0.0","karma-sauce-launcher":"^4.1.3","mocha":"^8.0.1","nyc":"^15.0.0","pre-commit":"^1.1.1","require-globify":"^1.3.0","typescript":"^3.9.5","uglify-js":"^3.6.9","watch":"^1.0.0"},"collective":{"type":"opencollective","url":"https://opencollective.com/ajv"},"funding":{"type":"github","url":"https://github.com/sponsors/epoberezkin"},"_lastModified":"2026-11-
|
|
1
|
+
{"name":"ajv","version":"6.12.6","description":"Another JSON Schema Validator","main":"lib/ajv.js","typings":"lib/ajv.d.ts","files":["lib/","dist/","scripts/","LICENSE",".tonic_example.js"],"scripts":{"eslint":"eslint lib/{compile/,}*.js spec/{**/,}*.js scripts --ignore-pattern spec/JSON-Schema-Test-Suite","jshint":"jshint lib/{compile/,}*.js","lint":"npm run jshint && npm run eslint","test-spec":"mocha spec/{**/,}*.spec.js -R spec","test-fast":"AJV_FAST_TEST=true npm run test-spec","test-debug":"npm run test-spec -- --inspect-brk","test-cov":"nyc npm run test-spec","test-ts":"tsc --target ES5 --noImplicitAny --noEmit spec/typescript/index.ts","bundle":"del-cli dist && node ./scripts/bundle.js . Ajv pure_getters","bundle-beautify":"node ./scripts/bundle.js js-beautify","build":"del-cli lib/dotjs/*.js \"!lib/dotjs/index.js\" && node scripts/compile-dots.js","test-karma":"karma start","test-browser":"del-cli .browser && npm run bundle && scripts/prepare-tests && npm run test-karma","test-all":"npm run test-cov && if-node-version 10 npm run test-browser","test":"npm run lint && npm run build && npm run test-all","prepublish":"npm run build && npm run bundle","watch":"watch \"npm run build\" ./lib/dot"},"nyc":{"exclude":["**/spec/**","node_modules"],"reporter":["lcov","text-summary"]},"repository":{"type":"git","url":"https://github.com/ajv-validator/ajv.git"},"keywords":["JSON","schema","validator","validation","jsonschema","json-schema","json-schema-validator","json-schema-validation"],"author":"Evgeny Poberezkin","license":"MIT","bugs":{"url":"https://github.com/ajv-validator/ajv/issues"},"homepage":"https://github.com/ajv-validator/ajv","tonicExampleFilename":".tonic_example.js","dependencies":{"fast-deep-equal":"^3.1.1","fast-json-stable-stringify":"^2.0.0","json-schema-traverse":"^0.4.1","uri-js":"^4.2.2"},"devDependencies":{"ajv-async":"^1.0.0","bluebird":"^3.5.3","brfs":"^2.0.0","browserify":"^16.2.0","chai":"^4.0.1","coveralls":"^3.0.1","del-cli":"^3.0.0","dot":"^1.0.3","eslint":"^7.3.1","gh-pages-generator":"^0.2.3","glob":"^7.0.0","if-node-version":"^1.0.0","js-beautify":"^1.7.3","jshint":"^2.10.2","json-schema-test":"^2.0.0","karma":"^5.0.0","karma-chrome-launcher":"^3.0.0","karma-mocha":"^2.0.0","karma-sauce-launcher":"^4.1.3","mocha":"^8.0.1","nyc":"^15.0.0","pre-commit":"^1.1.1","require-globify":"^1.3.0","typescript":"^3.9.5","uglify-js":"^3.6.9","watch":"^1.0.0"},"collective":{"type":"opencollective","url":"https://opencollective.com/ajv"},"funding":{"type":"github","url":"https://github.com/sponsors/epoberezkin"},"_lastModified":"2026-11-21T09:53:42.942Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"zod","version":"3.25.76","type":"module","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts"],"funding":"https://github.com/sponsors/colinhacks","homepage":"https://zod.dev","keywords":["typescript","schema","validation","type","inference"],"license":"MIT","sideEffects":false,"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"sourceDialects":["@zod/source"]},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","bump:beta":"pnpm version \"v$(pnpm pkg get version | jq -r)-beta.$(date +%Y%m%dT%H%M%S)\"","pub:beta":"pnpm bump:beta && pnpm publish --tag next --publish-branch v4 --no-git-checks --dry-run"},"_lastModified":"2026-11-
|
|
1
|
+
{"name":"zod","version":"3.25.76","type":"module","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts"],"funding":"https://github.com/sponsors/colinhacks","homepage":"https://zod.dev","keywords":["typescript","schema","validation","type","inference"],"license":"MIT","sideEffects":false,"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"sourceDialects":["@zod/source"]},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","bump:beta":"pnpm version \"v$(pnpm pkg get version | jq -r)-beta.$(date +%Y%m%dT%H%M%S)\"","pub:beta":"pnpm bump:beta && pnpm publish --tag next --publish-branch v4 --no-git-checks --dry-run"},"_lastModified":"2026-11-21T09:53:41.997Z"}
|
package/dist/server/plugin.js
CHANGED
|
@@ -82,6 +82,8 @@ var import_RoutingBindingValidation = require("./services/RoutingBindingValidati
|
|
|
82
82
|
var import_RoutingBindingRepository = require("./services/RoutingBindingRepository");
|
|
83
83
|
var import_HierarchyEnrollmentGuard = require("./services/HierarchyEnrollmentGuard");
|
|
84
84
|
var import_HierarchyRequestCancellation = require("./services/HierarchyRequestCancellation");
|
|
85
|
+
var import_ParallelInterruptActionsPatch = require("./services/ParallelInterruptActionsPatch");
|
|
86
|
+
var import_normalize_hierarchy_invocation_index = require("./utils/normalize-hierarchy-invocation-index");
|
|
85
87
|
function normalizeOptionalString(value) {
|
|
86
88
|
return typeof value === "string" ? value.trim() : "";
|
|
87
89
|
}
|
|
@@ -192,6 +194,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
192
194
|
removeNativeMonitorHook;
|
|
193
195
|
removeManagedPromptProtection;
|
|
194
196
|
removeNativeUsageAttribution;
|
|
197
|
+
removeParallelInterruptActionsPatch;
|
|
195
198
|
governanceEnabled = true;
|
|
196
199
|
loopScheduler;
|
|
197
200
|
loopWorker;
|
|
@@ -218,7 +221,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
218
221
|
}
|
|
219
222
|
async beforeLoad() {
|
|
220
223
|
this.db.registerRepositories({ RoutingBindingRepository: import_RoutingBindingRepository.RoutingBindingRepository });
|
|
221
|
-
this.db.import({ directory: import_path.default.resolve(__dirname, "collections") });
|
|
224
|
+
await this.db.import({ directory: import_path.default.resolve(__dirname, "collections") });
|
|
222
225
|
this.db.addMigrations({
|
|
223
226
|
namespace: this.name,
|
|
224
227
|
directory: import_path.default.resolve(__dirname, "migrations"),
|
|
@@ -227,6 +230,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
227
230
|
}
|
|
228
231
|
async load() {
|
|
229
232
|
var _a, _b, _c, _d;
|
|
233
|
+
(0, import_normalize_hierarchy_invocation_index.normalizeHierarchyInvocationIndex)(this.db);
|
|
230
234
|
await this.skillHub.load();
|
|
231
235
|
this.app.acl.registerSnippet({
|
|
232
236
|
name: `pm.${this.name}`,
|
|
@@ -270,6 +274,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
270
274
|
this.app.acl.allow("agentLoopEventsStream", ["stream"], "loggedIn");
|
|
271
275
|
this.app.acl.allow("agentAutoApproval", ["get", "set", "eligible"], "loggedIn");
|
|
272
276
|
this.installGovernanceHooks();
|
|
277
|
+
this.installParallelInterruptActionsFix();
|
|
273
278
|
this.app.resourceManager.use(
|
|
274
279
|
async (ctx, next) => {
|
|
275
280
|
var _a2;
|
|
@@ -588,38 +593,43 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
588
593
|
async afterEnable() {
|
|
589
594
|
this.governanceEnabled = true;
|
|
590
595
|
this.installGovernanceHooks();
|
|
596
|
+
this.installParallelInterruptActionsFix();
|
|
591
597
|
this.installNativeMonitorHook();
|
|
592
598
|
}
|
|
593
599
|
async afterDisable() {
|
|
594
|
-
var _a, _b, _c, _d;
|
|
600
|
+
var _a, _b, _c, _d, _e;
|
|
595
601
|
this.governanceEnabled = false;
|
|
596
602
|
this.hierarchyCancellation.abortAll();
|
|
597
603
|
(_a = this.removeManagedPromptProtection) == null ? void 0 : _a.call(this);
|
|
598
604
|
this.removeManagedPromptProtection = void 0;
|
|
599
605
|
(_b = this.removeNativeUsageAttribution) == null ? void 0 : _b.call(this);
|
|
600
606
|
this.removeNativeUsageAttribution = void 0;
|
|
601
|
-
(_c = this.
|
|
602
|
-
|
|
607
|
+
(_c = this.removeParallelInterruptActionsPatch) == null ? void 0 : _c.call(this);
|
|
608
|
+
this.removeParallelInterruptActionsPatch = void 0;
|
|
609
|
+
(_d = this.nativeObserver) == null ? void 0 : _d.uninstall();
|
|
610
|
+
(_e = this.removeNativeMonitorHook) == null ? void 0 : _e.call(this);
|
|
603
611
|
this.removeNativeMonitorHook = void 0;
|
|
604
612
|
}
|
|
605
613
|
async remove() {
|
|
606
614
|
}
|
|
607
615
|
async beforeStop() {
|
|
608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
616
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
609
617
|
this.governanceEnabled = false;
|
|
610
618
|
this.hierarchyCancellation.abortAll();
|
|
611
619
|
(_a = this.removeManagedPromptProtection) == null ? void 0 : _a.call(this);
|
|
612
620
|
this.removeManagedPromptProtection = void 0;
|
|
613
621
|
(_b = this.removeNativeUsageAttribution) == null ? void 0 : _b.call(this);
|
|
614
622
|
this.removeNativeUsageAttribution = void 0;
|
|
615
|
-
(
|
|
616
|
-
|
|
617
|
-
(
|
|
618
|
-
(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
(
|
|
622
|
-
(
|
|
623
|
+
(_c = this.removeParallelInterruptActionsPatch) == null ? void 0 : _c.call(this);
|
|
624
|
+
this.removeParallelInterruptActionsPatch = void 0;
|
|
625
|
+
(_e = (_d = this.app).off) == null ? void 0 : _e.call(_d, "afterStart", this.installNativeObserver);
|
|
626
|
+
(_g = (_f = this.app).removeListener) == null ? void 0 : _g.call(_f, "afterStart", this.installNativeObserver);
|
|
627
|
+
(_i = (_h = this.app).off) == null ? void 0 : _i.call(_h, "afterStart", this.startLoopWorker);
|
|
628
|
+
(_k = (_j = this.app).removeListener) == null ? void 0 : _k.call(_j, "afterStart", this.startLoopWorker);
|
|
629
|
+
await ((_l = this.loopWorker) == null ? void 0 : _l.stop());
|
|
630
|
+
await ((_m = this.loopScheduler) == null ? void 0 : _m.dispose());
|
|
631
|
+
(_n = this.nativeObserver) == null ? void 0 : _n.uninstall();
|
|
632
|
+
(_o = this.removeNativeMonitorHook) == null ? void 0 : _o.call(this);
|
|
623
633
|
this.removeNativeMonitorHook = void 0;
|
|
624
634
|
await this.skillHub.beforeStop();
|
|
625
635
|
(0, import_RunEventBus.resetRunEventBus)();
|
|
@@ -639,6 +649,11 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
639
649
|
this.removeManagedPromptProtection = (0, import_ManagedPromptProtection.installManagedPromptProtection)(this.db);
|
|
640
650
|
if (!this.removeNativeUsageAttribution) this.removeNativeUsageAttribution = (0, import_NativeUsageAttribution.installNativeUsageAttribution)(this);
|
|
641
651
|
}
|
|
652
|
+
installParallelInterruptActionsFix() {
|
|
653
|
+
if (!this.removeParallelInterruptActionsPatch) {
|
|
654
|
+
this.removeParallelInterruptActionsPatch = (0, import_ParallelInterruptActionsPatch.installParallelInterruptActionsPatch)();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
642
657
|
installNativeMonitorHook() {
|
|
643
658
|
if (this.removeNativeMonitorHook || !this.agentRuntimeLifecycle || !this.nativeMonitorSyncService) return;
|
|
644
659
|
this.removeNativeMonitorHook = this.agentRuntimeLifecycle.registerAfterRunHook("native-monitor", (context) => {
|
|
@@ -0,0 +1,132 @@
|
|
|
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 ParallelInterruptActionsPatch_exports = {};
|
|
28
|
+
__export(ParallelInterruptActionsPatch_exports, {
|
|
29
|
+
installParallelInterruptActionsPatch: () => installParallelInterruptActionsPatch,
|
|
30
|
+
toInterruptActionsFixed: () => toInterruptActionsFixed
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(ParallelInterruptActionsPatch_exports);
|
|
33
|
+
var import_server = require("@nocobase/plugin-ai/server");
|
|
34
|
+
const PATCH_STATE_KEY = Symbol.for("plugin-agent-orchestrator.parallelInterruptActionsPatch");
|
|
35
|
+
function parseInterruptDescription(description) {
|
|
36
|
+
if (typeof description !== "string" || !description) return null;
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(description);
|
|
39
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function readOptionalString(record, key) {
|
|
45
|
+
const value = record[key];
|
|
46
|
+
return typeof value === "string" ? value : void 0;
|
|
47
|
+
}
|
|
48
|
+
function toInterruptActionsFixed(interrupt) {
|
|
49
|
+
var _a;
|
|
50
|
+
const result = /* @__PURE__ */ new Map();
|
|
51
|
+
const actionRequests = (interrupt == null ? void 0 : interrupt.actionRequests) ?? [];
|
|
52
|
+
const reviewConfigs = (interrupt == null ? void 0 : interrupt.reviewConfigs) ?? [];
|
|
53
|
+
if (!actionRequests.length) {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
const reviewConfigsMap = /* @__PURE__ */ new Map();
|
|
57
|
+
for (const config of reviewConfigs) {
|
|
58
|
+
reviewConfigsMap.set(config.actionName, config);
|
|
59
|
+
}
|
|
60
|
+
for (let order = 0; order < actionRequests.length; order++) {
|
|
61
|
+
const actionRequest = actionRequests[order];
|
|
62
|
+
const payload = parseInterruptDescription(actionRequest.description);
|
|
63
|
+
const matchingConfig = ((_a = reviewConfigs[order]) == null ? void 0 : _a.actionName) === actionRequest.name ? reviewConfigs[order] : reviewConfigsMap.get(actionRequest.name);
|
|
64
|
+
const toolCallId = payload ? readOptionalString(payload, "toolCallId") : void 0;
|
|
65
|
+
const toolCallName = payload ? readOptionalString(payload, "toolCallName") : void 0;
|
|
66
|
+
const sessionId = payload ? readOptionalString(payload, "sessionId") : void 0;
|
|
67
|
+
const from = payload ? readOptionalString(payload, "from") : void 0;
|
|
68
|
+
const username = payload ? readOptionalString(payload, "username") : void 0;
|
|
69
|
+
const toolCall = payload && toolCallId ? {
|
|
70
|
+
id: toolCallId,
|
|
71
|
+
name: toolCallName ?? actionRequest.name
|
|
72
|
+
} : void 0;
|
|
73
|
+
const currentConversation = payload && sessionId ? {
|
|
74
|
+
sessionId,
|
|
75
|
+
from: from ?? "",
|
|
76
|
+
username: username ?? ""
|
|
77
|
+
} : void 0;
|
|
78
|
+
const baseKey = (toolCall == null ? void 0 : toolCall.id) || `${actionRequest.name}:${order}`;
|
|
79
|
+
const key = result.has(baseKey) ? `${baseKey}:${order}` : baseKey;
|
|
80
|
+
result.set(key, {
|
|
81
|
+
order,
|
|
82
|
+
description: actionRequest.description,
|
|
83
|
+
allowedDecisions: matchingConfig == null ? void 0 : matchingConfig.allowedDecisions,
|
|
84
|
+
toolCall,
|
|
85
|
+
currentConversation
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
function installParallelInterruptActionsPatch(targetPrototype) {
|
|
91
|
+
var _a;
|
|
92
|
+
const target = targetPrototype ?? ((_a = import_server.AIEmployee) == null ? void 0 : _a.prototype);
|
|
93
|
+
if (!target || typeof target.toInterruptActions !== "function") {
|
|
94
|
+
return () => void 0;
|
|
95
|
+
}
|
|
96
|
+
const owner = Symbol("parallel-interrupt-actions-owner");
|
|
97
|
+
let state = target[PATCH_STATE_KEY];
|
|
98
|
+
if (state && target.toInterruptActions === state.wrapped) {
|
|
99
|
+
state.owners.add(owner);
|
|
100
|
+
} else {
|
|
101
|
+
const original = target.toInterruptActions;
|
|
102
|
+
const wrapped = function toInterruptActionsPatched(interrupt) {
|
|
103
|
+
return toInterruptActionsFixed(interrupt);
|
|
104
|
+
};
|
|
105
|
+
state = {
|
|
106
|
+
original,
|
|
107
|
+
wrapped,
|
|
108
|
+
owners: /* @__PURE__ */ new Set([owner])
|
|
109
|
+
};
|
|
110
|
+
target[PATCH_STATE_KEY] = state;
|
|
111
|
+
target.toInterruptActions = wrapped;
|
|
112
|
+
}
|
|
113
|
+
let disposed = false;
|
|
114
|
+
return () => {
|
|
115
|
+
if (disposed) return;
|
|
116
|
+
disposed = true;
|
|
117
|
+
const currentState = target[PATCH_STATE_KEY];
|
|
118
|
+
if (!currentState) return;
|
|
119
|
+
currentState.owners.delete(owner);
|
|
120
|
+
if (currentState.owners.size === 0) {
|
|
121
|
+
if (target.toInterruptActions === currentState.wrapped) {
|
|
122
|
+
target.toInterruptActions = currentState.original;
|
|
123
|
+
}
|
|
124
|
+
delete target[PATCH_STATE_KEY];
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
installParallelInterruptActionsPatch,
|
|
131
|
+
toInterruptActionsFixed
|
|
132
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 normalize_hierarchy_invocation_index_exports = {};
|
|
28
|
+
__export(normalize_hierarchy_invocation_index_exports, {
|
|
29
|
+
normalizeHierarchyInvocationIndex: () => normalizeHierarchyInvocationIndex
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(normalize_hierarchy_invocation_index_exports);
|
|
32
|
+
function normalizeHierarchyInvocationIndex(database) {
|
|
33
|
+
var _a;
|
|
34
|
+
if (!database.inDialect("postgres")) return;
|
|
35
|
+
const collection = database.getCollection("agentHierarchyInvocations");
|
|
36
|
+
const parentSessionField = collection.underscored ? "parent_session_id" : "parentSessionId";
|
|
37
|
+
const parentToolCallField = collection.underscored ? "parent_tool_call_id" : "parentToolCallId";
|
|
38
|
+
const index = (_a = collection.model.options.indexes) == null ? void 0 : _a.find(
|
|
39
|
+
(item) => {
|
|
40
|
+
var _a2;
|
|
41
|
+
return item.unique && ((_a2 = item.fields) == null ? void 0 : _a2.length) === 2 && item.fields[0] === parentSessionField && item.fields[1] === parentToolCallField;
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
if (!(index == null ? void 0 : index.name) || Buffer.byteLength(index.name, "utf8") <= 63) return;
|
|
45
|
+
let name = "";
|
|
46
|
+
for (const character of index.name) {
|
|
47
|
+
if (Buffer.byteLength(name + character, "utf8") > 63) break;
|
|
48
|
+
name += character;
|
|
49
|
+
}
|
|
50
|
+
index.name = name;
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
normalizeHierarchyInvocationIndex
|
|
55
|
+
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "代理协调器",
|
|
5
5
|
"displayName.vi-VN": "Điều phối Agent",
|
|
6
6
|
"description": "Native AI Employee sub-agent monitoring, policy, and memory context layer for NocoBase plugin-ai.",
|
|
7
|
-
"version": "1.2.
|
|
7
|
+
"version": "1.2.3",
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
9
|
"main": "dist/server/index.js",
|
|
10
10
|
"keywords": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"url": "git+https://github.com/OrgGem/nocobase-beta.git",
|
|
59
59
|
"directory": "packages/plugins/plugin-agent-orchestrator"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "168268aa4657eefd6c5632f6b5e5f51c2881df91",
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public",
|
|
64
64
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
11
|
+
import { QueryTypes } from 'sequelize';
|
|
11
12
|
import { beforeAll, afterAll, describe, expect, it } from 'vitest';
|
|
12
13
|
import { PluginAgentOrchestratorServer } from '../plugin';
|
|
13
14
|
import {
|
|
@@ -17,6 +18,22 @@ import {
|
|
|
17
18
|
} from '../services/HierarchyInvocationJournal';
|
|
18
19
|
|
|
19
20
|
const suffix = `${process.pid}-${Date.now()}`;
|
|
21
|
+
const pluginOptions = {
|
|
22
|
+
name: 'plugin-agent-orchestrator',
|
|
23
|
+
packageName: 'plugin-agent-orchestrator',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type DatabaseIndex = {
|
|
27
|
+
name?: string;
|
|
28
|
+
unique?: boolean;
|
|
29
|
+
fields?: Array<string | { attribute?: string; name?: string }>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function indexFieldNames(index: DatabaseIndex) {
|
|
33
|
+
return (index.fields || [])
|
|
34
|
+
.map((field) => (typeof field === 'string' ? field : field.attribute || field.name || ''))
|
|
35
|
+
.join(',');
|
|
36
|
+
}
|
|
20
37
|
|
|
21
38
|
function invocation(overrides: Partial<ReserveHierarchyInvocation> = {}): ReserveHierarchyInvocation {
|
|
22
39
|
return {
|
|
@@ -54,7 +71,7 @@ describe('hierarchy invocation journal persistence', () => {
|
|
|
54
71
|
|
|
55
72
|
beforeAll(async () => {
|
|
56
73
|
app = await createMockServer({
|
|
57
|
-
plugins: ['nocobase', PluginAgentOrchestratorServer],
|
|
74
|
+
plugins: ['nocobase', [PluginAgentOrchestratorServer, pluginOptions]],
|
|
58
75
|
name: `hierarchy-invocation-journal-${suffix}`,
|
|
59
76
|
skipSupervisor: true,
|
|
60
77
|
});
|
|
@@ -65,6 +82,53 @@ describe('hierarchy invocation journal persistence', () => {
|
|
|
65
82
|
await app?.destroy();
|
|
66
83
|
});
|
|
67
84
|
|
|
85
|
+
it('keeps the persisted hierarchy unique index stable through repeated model syncs', async () => {
|
|
86
|
+
const collection = app.db.getCollection('agentHierarchyInvocations');
|
|
87
|
+
const fieldNames = collection.underscored
|
|
88
|
+
? 'parent_session_id,parent_tool_call_id'
|
|
89
|
+
: 'parentSessionId,parentToolCallId';
|
|
90
|
+
const configuredIndex = collection.model.options.indexes?.find(
|
|
91
|
+
(index) => index.unique && indexFieldNames(index as DatabaseIndex) === fieldNames,
|
|
92
|
+
);
|
|
93
|
+
const readIndexOid = async () => {
|
|
94
|
+
const rows = await app.db.sequelize.query<{ index_oid: string }>(
|
|
95
|
+
`SELECT c.oid::text AS index_oid
|
|
96
|
+
FROM pg_class AS c
|
|
97
|
+
JOIN pg_namespace AS n ON n.oid = c.relnamespace
|
|
98
|
+
JOIN pg_index AS i ON i.indexrelid = c.oid
|
|
99
|
+
WHERE n.nspname = ? AND c.relname = ?`,
|
|
100
|
+
{
|
|
101
|
+
replacements: [collection.collectionSchema() || 'public', configuredIndex?.name],
|
|
102
|
+
type: QueryTypes.SELECT,
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
return rows[0]?.index_oid;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
expect(configuredIndex).toBeTruthy();
|
|
109
|
+
let initialIndexOid: string | undefined;
|
|
110
|
+
if (app.db.inDialect('postgres')) {
|
|
111
|
+
expect(Buffer.byteLength(configuredIndex?.name || '', 'utf8')).toBeLessThanOrEqual(63);
|
|
112
|
+
initialIndexOid = await readIndexOid();
|
|
113
|
+
expect(initialIndexOid).toBeTruthy();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await collection.sync();
|
|
117
|
+
await collection.sync();
|
|
118
|
+
|
|
119
|
+
if (app.db.inDialect('postgres')) {
|
|
120
|
+
expect(await readIndexOid()).toBe(initialIndexOid);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const indexes = (await app.db.sequelize
|
|
124
|
+
.getQueryInterface()
|
|
125
|
+
.showIndex(collection.getTableNameWithSchema())) as DatabaseIndex[];
|
|
126
|
+
const matchingIndexes = indexes.filter((index) => index.unique && indexFieldNames(index) === fieldNames);
|
|
127
|
+
|
|
128
|
+
expect(matchingIndexes).toHaveLength(1);
|
|
129
|
+
expect(matchingIndexes[0].name).toBe(configuredIndex?.name);
|
|
130
|
+
});
|
|
131
|
+
|
|
68
132
|
it('reserves one owner-scoped idempotency key and rejects conflicting reuse', async () => {
|
|
69
133
|
const input = invocation();
|
|
70
134
|
const first = await journal.reserve(input);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import type { Database } from '@nocobase/database';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { normalizeHierarchyInvocationIndex } from '../utils/normalize-hierarchy-invocation-index';
|
|
6
|
+
|
|
7
|
+
type TestIndex = {
|
|
8
|
+
name: string;
|
|
9
|
+
unique: boolean;
|
|
10
|
+
fields: string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type TestCollection = {
|
|
14
|
+
underscored: boolean;
|
|
15
|
+
model: {
|
|
16
|
+
options: { indexes: TestIndex[] };
|
|
17
|
+
_indexes: TestIndex[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function createDatabase(collection: TestCollection, dialect = 'postgres') {
|
|
22
|
+
return {
|
|
23
|
+
inDialect: (value: string) => value === dialect,
|
|
24
|
+
getCollection: () => collection,
|
|
25
|
+
} as unknown as Database;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createCollection(name: string, fields: string[], underscored = false): TestCollection {
|
|
29
|
+
const index = { name, unique: true, fields };
|
|
30
|
+
return {
|
|
31
|
+
underscored,
|
|
32
|
+
model: {
|
|
33
|
+
options: { indexes: [index] },
|
|
34
|
+
_indexes: [index],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('hierarchy invocation PostgreSQL index naming', () => {
|
|
40
|
+
it('keeps the stored 63-byte name on both Sequelize index lists', () => {
|
|
41
|
+
const fullName = 'agent_hierarchy_invocations_parent_session_id_parent_tool_call_id';
|
|
42
|
+
const collection = createCollection(fullName, ['parentSessionId', 'parentToolCallId']);
|
|
43
|
+
|
|
44
|
+
normalizeHierarchyInvocationIndex(createDatabase(collection));
|
|
45
|
+
|
|
46
|
+
const storedName = fullName.slice(0, 63);
|
|
47
|
+
expect(Buffer.byteLength(storedName, 'utf8')).toBe(63);
|
|
48
|
+
expect(collection.model.options.indexes[0].name).toBe(storedName);
|
|
49
|
+
expect(collection.model._indexes[0].name).toBe(storedName);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('recognizes underscored fields and preserves a table prefix within the PostgreSQL limit', () => {
|
|
53
|
+
const fullName = 'tenant_123456_agent_hierarchy_invocations_parent_session_id_parent_tool_call_id';
|
|
54
|
+
const collection = createCollection(fullName, ['parent_session_id', 'parent_tool_call_id'], true);
|
|
55
|
+
|
|
56
|
+
normalizeHierarchyInvocationIndex(createDatabase(collection));
|
|
57
|
+
|
|
58
|
+
const storedName = collection.model.options.indexes[0].name;
|
|
59
|
+
expect(storedName).toBe(fullName.slice(0, 63));
|
|
60
|
+
expect(storedName.startsWith('tenant_123456_')).toBe(true);
|
|
61
|
+
expect(Buffer.byteLength(storedName, 'utf8')).toBe(63);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('leaves other database dialects unchanged', () => {
|
|
65
|
+
const fullName = 'agent_hierarchy_invocations_parent_session_id_parent_tool_call_id';
|
|
66
|
+
const collection = createCollection(fullName, ['parentSessionId', 'parentToolCallId']);
|
|
67
|
+
|
|
68
|
+
normalizeHierarchyInvocationIndex(createDatabase(collection, 'sqlite'));
|
|
69
|
+
|
|
70
|
+
expect(collection.model.options.indexes[0].name).toBe(fullName);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { AIEmployee } from '@nocobase/plugin-ai/server';
|
|
4
|
+
import { AIMessage, BaseMessage } from '@langchain/core/messages';
|
|
5
|
+
import { BaseChatModel, type BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
|
|
6
|
+
import type { ChatResult } from '@langchain/core/outputs';
|
|
7
|
+
import { tool } from '@langchain/core/tools';
|
|
8
|
+
import { Command, MemorySaver } from '@langchain/langgraph';
|
|
9
|
+
import { createAgent, humanInTheLoopMiddleware } from 'langchain';
|
|
10
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import {
|
|
13
|
+
installParallelInterruptActionsPatch,
|
|
14
|
+
toInterruptActionsFixed,
|
|
15
|
+
type InterruptAction,
|
|
16
|
+
type InterruptPayload,
|
|
17
|
+
} from '../services/ParallelInterruptActionsPatch';
|
|
18
|
+
|
|
19
|
+
type PrivateAIEmployeeProto = {
|
|
20
|
+
toInterruptActions: (interrupt?: InterruptPayload) => Map<string, InterruptAction>;
|
|
21
|
+
handleInterruptedToolCalls: (
|
|
22
|
+
interrupt: { id?: string; value?: InterruptPayload } | undefined,
|
|
23
|
+
getMessageId: (sessionId: string) => string | undefined,
|
|
24
|
+
onInterrupted?: (params: {
|
|
25
|
+
messageId: string;
|
|
26
|
+
interruptId: string;
|
|
27
|
+
interruptAction: InterruptAction;
|
|
28
|
+
toolCall: { id: string; name: string };
|
|
29
|
+
currentConversation: { sessionId: string; from: string; username: string };
|
|
30
|
+
}) => Promise<void> | void,
|
|
31
|
+
) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function makeDescription(params: {
|
|
35
|
+
toolCallId: string;
|
|
36
|
+
toolCallName: string;
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
from?: string;
|
|
39
|
+
username?: string;
|
|
40
|
+
}): string {
|
|
41
|
+
return JSON.stringify({
|
|
42
|
+
toolCallId: params.toolCallId,
|
|
43
|
+
toolCallName: params.toolCallName,
|
|
44
|
+
sessionId: params.sessionId ?? 'session-1',
|
|
45
|
+
from: params.from ?? 'main-agent',
|
|
46
|
+
username: params.username ?? 'dex',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class ParallelSameToolMockChatModel extends BaseChatModel {
|
|
51
|
+
private callCount = 0;
|
|
52
|
+
|
|
53
|
+
constructor() {
|
|
54
|
+
super({});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_llmType(): string {
|
|
58
|
+
return 'parallel-same-tool-mock';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bindTools() {
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async _generate(_messages: BaseMessage[], _options: BaseChatModelCallOptions): Promise<ChatResult> {
|
|
66
|
+
this.callCount += 1;
|
|
67
|
+
if (this.callCount === 1) {
|
|
68
|
+
return {
|
|
69
|
+
generations: [
|
|
70
|
+
{
|
|
71
|
+
text: '',
|
|
72
|
+
message: new AIMessage({
|
|
73
|
+
content: '',
|
|
74
|
+
tool_calls: [
|
|
75
|
+
{
|
|
76
|
+
id: 'tooluse_first_call',
|
|
77
|
+
name: 'mcp-rpa-portainer-docker_proxy',
|
|
78
|
+
args: { container: 'web-1' },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'tooluse_second_call',
|
|
82
|
+
name: 'mcp-rpa-portainer-docker_proxy',
|
|
83
|
+
args: { container: 'api-2' },
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
generations: [
|
|
93
|
+
{
|
|
94
|
+
text: 'Both containers inspected.',
|
|
95
|
+
message: new AIMessage({ content: 'Both containers inspected.' }),
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe('ParallelInterruptActionsPatch', () => {
|
|
103
|
+
const cleanups: Array<() => void> = [];
|
|
104
|
+
|
|
105
|
+
afterEach(() => {
|
|
106
|
+
while (cleanups.length > 0) {
|
|
107
|
+
cleanups.pop()?.();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('preserves all parallel calls to the same tool name in exact actionRequests order', () => {
|
|
112
|
+
const toolName = 'mcp-rpa-portainer-docker_proxy';
|
|
113
|
+
const payload: InterruptPayload = {
|
|
114
|
+
actionRequests: [
|
|
115
|
+
{
|
|
116
|
+
name: toolName,
|
|
117
|
+
args: { container: 'c1' },
|
|
118
|
+
description: makeDescription({ toolCallId: 'tooluse_1', toolCallName: toolName }),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: toolName,
|
|
122
|
+
args: { container: 'c2' },
|
|
123
|
+
description: makeDescription({ toolCallId: 'tooluse_2', toolCallName: toolName }),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: toolName,
|
|
127
|
+
args: { container: 'c3' },
|
|
128
|
+
description: makeDescription({ toolCallId: 'tooluse_3', toolCallName: toolName }),
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
reviewConfigs: [
|
|
132
|
+
{ actionName: toolName, allowedDecisions: ['approve', 'reject'] },
|
|
133
|
+
{ actionName: toolName, allowedDecisions: ['approve', 'reject'] },
|
|
134
|
+
{ actionName: toolName, allowedDecisions: ['approve', 'reject'] },
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const result = toInterruptActionsFixed(payload);
|
|
139
|
+
expect(result.size).toBe(3);
|
|
140
|
+
expect([...result.keys()]).toEqual(['tooluse_1', 'tooluse_2', 'tooluse_3']);
|
|
141
|
+
expect([...result.values()].map((entry) => ({ order: entry.order, id: entry.toolCall?.id }))).toEqual([
|
|
142
|
+
{ order: 0, id: 'tooluse_1' },
|
|
143
|
+
{ order: 1, id: 'tooluse_2' },
|
|
144
|
+
{ order: 2, id: 'tooluse_3' },
|
|
145
|
+
]);
|
|
146
|
+
for (const entry of result.values()) {
|
|
147
|
+
expect(entry.allowedDecisions).toEqual(['approve', 'reject']);
|
|
148
|
+
expect(entry.currentConversation).toEqual({
|
|
149
|
+
sessionId: 'session-1',
|
|
150
|
+
from: 'main-agent',
|
|
151
|
+
username: 'dex',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('preserves mixed parallel calls and per-action allowedDecisions', () => {
|
|
157
|
+
const payload: InterruptPayload = {
|
|
158
|
+
actionRequests: [
|
|
159
|
+
{
|
|
160
|
+
name: 'tool_a',
|
|
161
|
+
description: makeDescription({ toolCallId: 'call_a1', toolCallName: 'tool_a' }),
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'tool_b',
|
|
165
|
+
description: makeDescription({ toolCallId: 'call_b1', toolCallName: 'tool_b' }),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'tool_a',
|
|
169
|
+
description: makeDescription({ toolCallId: 'call_a2', toolCallName: 'tool_a' }),
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
reviewConfigs: [
|
|
173
|
+
{ actionName: 'tool_a', allowedDecisions: ['approve', 'reject'] },
|
|
174
|
+
{ actionName: 'tool_b', allowedDecisions: ['approve', 'edit', 'reject'] },
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const result = toInterruptActionsFixed(payload);
|
|
179
|
+
expect(result.size).toBe(3);
|
|
180
|
+
expect(result.get('call_a1')?.order).toBe(0);
|
|
181
|
+
expect(result.get('call_a1')?.allowedDecisions).toEqual(['approve', 'reject']);
|
|
182
|
+
expect(result.get('call_b1')?.order).toBe(1);
|
|
183
|
+
expect(result.get('call_b1')?.allowedDecisions).toEqual(['approve', 'edit', 'reject']);
|
|
184
|
+
expect(result.get('call_a2')?.order).toBe(2);
|
|
185
|
+
expect(result.get('call_a2')?.allowedDecisions).toEqual(['approve', 'reject']);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('handles malformed or missing descriptions safely without throwing', () => {
|
|
189
|
+
const payload: InterruptPayload = {
|
|
190
|
+
actionRequests: [{ name: 'broken_tool', description: '{not-valid-json' }, { name: 'empty_tool' }],
|
|
191
|
+
reviewConfigs: [{ actionName: 'broken_tool', allowedDecisions: ['approve', 'reject'] }],
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const result = toInterruptActionsFixed(payload);
|
|
195
|
+
expect(result.size).toBe(2);
|
|
196
|
+
const values = [...result.values()];
|
|
197
|
+
expect(values[0].order).toBe(0);
|
|
198
|
+
expect(values[0].toolCall).toBeUndefined();
|
|
199
|
+
expect(values[0].currentConversation).toBeUndefined();
|
|
200
|
+
expect(values[1].order).toBe(1);
|
|
201
|
+
expect(values[1].toolCall).toBeUndefined();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('returns an empty map for undefined or empty payloads', () => {
|
|
205
|
+
expect(toInterruptActionsFixed(undefined).size).toBe(0);
|
|
206
|
+
expect(toInterruptActionsFixed({ actionRequests: [], reviewConfigs: [] }).size).toBe(0);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('patches AIEmployee.prototype with ref-counted install/uninstall and restores upstream method cleanly', () => {
|
|
210
|
+
const proto = AIEmployee.prototype as unknown as PrivateAIEmployeeProto;
|
|
211
|
+
const originalMethod = proto.toInterruptActions;
|
|
212
|
+
|
|
213
|
+
const sameToolPayload: InterruptPayload = {
|
|
214
|
+
actionRequests: [
|
|
215
|
+
{
|
|
216
|
+
name: 'mcp-rpa-portainer-docker_proxy',
|
|
217
|
+
description: makeDescription({ toolCallId: 'tooluse_1', toolCallName: 'mcp-rpa-portainer-docker_proxy' }),
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'mcp-rpa-portainer-docker_proxy',
|
|
221
|
+
description: makeDescription({ toolCallId: 'tooluse_2', toolCallName: 'mcp-rpa-portainer-docker_proxy' }),
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
reviewConfigs: [{ actionName: 'mcp-rpa-portainer-docker_proxy', allowedDecisions: ['approve', 'reject'] }],
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// Baseline check: upstream collapses duplicate tool names into a single entry.
|
|
228
|
+
expect(originalMethod.call({}, sameToolPayload).size).toBe(1);
|
|
229
|
+
|
|
230
|
+
const disposeA = installParallelInterruptActionsPatch();
|
|
231
|
+
cleanups.push(disposeA);
|
|
232
|
+
const disposeB = installParallelInterruptActionsPatch();
|
|
233
|
+
cleanups.push(disposeB);
|
|
234
|
+
|
|
235
|
+
expect(proto.toInterruptActions).not.toBe(originalMethod);
|
|
236
|
+
expect(proto.toInterruptActions.call({}, sameToolPayload).size).toBe(2);
|
|
237
|
+
|
|
238
|
+
// First dispose keeps patch active while a second owner remains; double-disposing owner A is a no-op.
|
|
239
|
+
disposeA();
|
|
240
|
+
disposeA();
|
|
241
|
+
expect(proto.toInterruptActions).not.toBe(originalMethod);
|
|
242
|
+
expect(proto.toInterruptActions.call({}, sameToolPayload).size).toBe(2);
|
|
243
|
+
|
|
244
|
+
// Last dispose restores the original upstream method.
|
|
245
|
+
disposeB();
|
|
246
|
+
expect(proto.toInterruptActions).toBe(originalMethod);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('marks every parallel same-tool call interrupted in handleInterruptedToolCalls and resumes both calls via LangChain HITL', async () => {
|
|
250
|
+
const dispose = installParallelInterruptActionsPatch();
|
|
251
|
+
cleanups.push(dispose);
|
|
252
|
+
|
|
253
|
+
const executedContainers: string[] = [];
|
|
254
|
+
const dockerProxyTool = tool(
|
|
255
|
+
async ({ container }) => {
|
|
256
|
+
executedContainers.push(container);
|
|
257
|
+
return `inspected:${container}`;
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'mcp-rpa-portainer-docker_proxy',
|
|
261
|
+
description: 'Inspect a docker container',
|
|
262
|
+
schema: z.object({ container: z.string() }),
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const sessionId = 'session-parallel-hitl';
|
|
267
|
+
const agent = createAgent({
|
|
268
|
+
model: new ParallelSameToolMockChatModel(),
|
|
269
|
+
tools: [dockerProxyTool],
|
|
270
|
+
checkpointer: new MemorySaver(),
|
|
271
|
+
middleware: [
|
|
272
|
+
humanInTheLoopMiddleware({
|
|
273
|
+
interruptOn: {
|
|
274
|
+
'mcp-rpa-portainer-docker_proxy': {
|
|
275
|
+
allowedDecisions: ['approve', 'reject'],
|
|
276
|
+
description: (toolCall) =>
|
|
277
|
+
makeDescription({
|
|
278
|
+
toolCallId: toolCall.id ?? '',
|
|
279
|
+
toolCallName: toolCall.name,
|
|
280
|
+
sessionId,
|
|
281
|
+
}),
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
}),
|
|
285
|
+
],
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const config = { configurable: { thread_id: sessionId } };
|
|
289
|
+
const firstResult = (await agent.invoke(
|
|
290
|
+
{ messages: [{ role: 'user', content: 'Inspect web-1 and api-2 in parallel.' }] },
|
|
291
|
+
config,
|
|
292
|
+
)) as { __interrupt__?: Array<{ id?: string; value?: InterruptPayload }> };
|
|
293
|
+
|
|
294
|
+
const interrupts = firstResult.__interrupt__ ?? [];
|
|
295
|
+
expect(interrupts).toHaveLength(1);
|
|
296
|
+
const interrupt = interrupts[0];
|
|
297
|
+
expect(interrupt.id).toBeTruthy();
|
|
298
|
+
|
|
299
|
+
const updateToolCallInterrupted = vi.fn().mockResolvedValue(undefined);
|
|
300
|
+
const onInterrupted = vi.fn().mockResolvedValue(undefined);
|
|
301
|
+
const fakeEmployeeInstance = {
|
|
302
|
+
toInterruptActions: (AIEmployee.prototype as unknown as PrivateAIEmployeeProto).toInterruptActions,
|
|
303
|
+
updateToolCallInterrupted,
|
|
304
|
+
logger: { warn: vi.fn() },
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
await (AIEmployee.prototype as unknown as PrivateAIEmployeeProto).handleInterruptedToolCalls.call(
|
|
308
|
+
fakeEmployeeInstance,
|
|
309
|
+
interrupt,
|
|
310
|
+
() => 'msg-148557048269798400',
|
|
311
|
+
onInterrupted,
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
expect(updateToolCallInterrupted).toHaveBeenCalledTimes(2);
|
|
315
|
+
expect(updateToolCallInterrupted.mock.calls.map((call) => ({ id: call[2], order: call[4].order }))).toEqual([
|
|
316
|
+
{ id: 'tooluse_first_call', order: 0 },
|
|
317
|
+
{ id: 'tooluse_second_call', order: 1 },
|
|
318
|
+
]);
|
|
319
|
+
expect(onInterrupted).toHaveBeenCalledTimes(2);
|
|
320
|
+
expect(onInterrupted.mock.calls.map((call) => call[0].toolCall.id)).toEqual([
|
|
321
|
+
'tooluse_first_call',
|
|
322
|
+
'tooluse_second_call',
|
|
323
|
+
]);
|
|
324
|
+
|
|
325
|
+
// Simulate getUserDecisions() ordering by interruptActionOrder ASC and resuming the graph.
|
|
326
|
+
const interruptId = String(interrupt.id);
|
|
327
|
+
const resumed = (await agent.invoke(
|
|
328
|
+
new Command({
|
|
329
|
+
resume: {
|
|
330
|
+
[interruptId]: {
|
|
331
|
+
decisions: [{ type: 'approve' }, { type: 'approve' }],
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
}),
|
|
335
|
+
config,
|
|
336
|
+
)) as { messages?: BaseMessage[] };
|
|
337
|
+
|
|
338
|
+
expect(executedContainers).toEqual(['web-1', 'api-2']);
|
|
339
|
+
const lastMessage = resumed.messages?.[resumed.messages.length - 1];
|
|
340
|
+
expect(lastMessage?.content).toBe('Both containers inspected.');
|
|
341
|
+
});
|
|
342
|
+
});
|
package/src/server/plugin.ts
CHANGED
|
@@ -43,6 +43,8 @@ import { validateRoutingBindingAction } from './services/RoutingBindingValidatio
|
|
|
43
43
|
import { initializeRoutingGraphLock, RoutingBindingRepository } from './services/RoutingBindingRepository';
|
|
44
44
|
import { guardHierarchyEnrollment, guardManagedChildActions } from './services/HierarchyEnrollmentGuard';
|
|
45
45
|
import { HierarchyRequestCancellation } from './services/HierarchyRequestCancellation';
|
|
46
|
+
import { installParallelInterruptActionsPatch } from './services/ParallelInterruptActionsPatch';
|
|
47
|
+
import { normalizeHierarchyInvocationIndex } from './utils/normalize-hierarchy-invocation-index';
|
|
46
48
|
|
|
47
49
|
function normalizeOptionalString(value: unknown) {
|
|
48
50
|
return typeof value === 'string' ? value.trim() : '';
|
|
@@ -172,6 +174,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
172
174
|
private removeNativeMonitorHook?: () => void;
|
|
173
175
|
private removeManagedPromptProtection?: () => void;
|
|
174
176
|
private removeNativeUsageAttribution?: () => void;
|
|
177
|
+
private removeParallelInterruptActionsPatch?: () => void;
|
|
175
178
|
private governanceEnabled = true;
|
|
176
179
|
loopScheduler: LoopSchedulerService;
|
|
177
180
|
loopWorker: LoopWorkerService;
|
|
@@ -200,7 +203,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
200
203
|
async beforeLoad() {
|
|
201
204
|
this.db.registerRepositories({ RoutingBindingRepository });
|
|
202
205
|
// Import collection definitions
|
|
203
|
-
this.db.import({ directory: path.resolve(__dirname, 'collections') });
|
|
206
|
+
await this.db.import({ directory: path.resolve(__dirname, 'collections') });
|
|
204
207
|
|
|
205
208
|
this.db.addMigrations({
|
|
206
209
|
namespace: this.name,
|
|
@@ -210,6 +213,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
async load() {
|
|
216
|
+
normalizeHierarchyInvocationIndex(this.db);
|
|
213
217
|
await this.skillHub.load();
|
|
214
218
|
|
|
215
219
|
// --- ACL ---
|
|
@@ -264,6 +268,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
264
268
|
this.app.acl.allow('agentAutoApproval', ['get', 'set', 'eligible'], 'loggedIn');
|
|
265
269
|
|
|
266
270
|
this.installGovernanceHooks();
|
|
271
|
+
this.installParallelInterruptActionsFix();
|
|
267
272
|
this.app.resourceManager.use(
|
|
268
273
|
async (ctx, next) => {
|
|
269
274
|
if (
|
|
@@ -653,6 +658,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
653
658
|
async afterEnable() {
|
|
654
659
|
this.governanceEnabled = true;
|
|
655
660
|
this.installGovernanceHooks();
|
|
661
|
+
this.installParallelInterruptActionsFix();
|
|
656
662
|
this.installNativeMonitorHook();
|
|
657
663
|
}
|
|
658
664
|
async afterDisable() {
|
|
@@ -662,6 +668,8 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
662
668
|
this.removeManagedPromptProtection = undefined;
|
|
663
669
|
this.removeNativeUsageAttribution?.();
|
|
664
670
|
this.removeNativeUsageAttribution = undefined;
|
|
671
|
+
this.removeParallelInterruptActionsPatch?.();
|
|
672
|
+
this.removeParallelInterruptActionsPatch = undefined;
|
|
665
673
|
this.nativeObserver?.uninstall();
|
|
666
674
|
this.removeNativeMonitorHook?.();
|
|
667
675
|
this.removeNativeMonitorHook = undefined;
|
|
@@ -675,6 +683,8 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
675
683
|
this.removeManagedPromptProtection = undefined;
|
|
676
684
|
this.removeNativeUsageAttribution?.();
|
|
677
685
|
this.removeNativeUsageAttribution = undefined;
|
|
686
|
+
this.removeParallelInterruptActionsPatch?.();
|
|
687
|
+
this.removeParallelInterruptActionsPatch = undefined;
|
|
678
688
|
this.app.off?.('afterStart', this.installNativeObserver);
|
|
679
689
|
this.app.removeListener?.('afterStart', this.installNativeObserver);
|
|
680
690
|
this.app.off?.('afterStart', this.startLoopWorker);
|
|
@@ -704,6 +714,12 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
704
714
|
if (!this.removeNativeUsageAttribution) this.removeNativeUsageAttribution = installNativeUsageAttribution(this);
|
|
705
715
|
}
|
|
706
716
|
|
|
717
|
+
private installParallelInterruptActionsFix() {
|
|
718
|
+
if (!this.removeParallelInterruptActionsPatch) {
|
|
719
|
+
this.removeParallelInterruptActionsPatch = installParallelInterruptActionsPatch();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
707
723
|
private installNativeMonitorHook() {
|
|
708
724
|
if (this.removeNativeMonitorHook || !this.agentRuntimeLifecycle || !this.nativeMonitorSyncService) return;
|
|
709
725
|
this.removeNativeMonitorHook = this.agentRuntimeLifecycle.registerAfterRunHook('native-monitor', (context) => {
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { AIEmployee } from '@nocobase/plugin-ai/server';
|
|
4
|
+
|
|
5
|
+
export type InterruptActionRequest = {
|
|
6
|
+
name: string;
|
|
7
|
+
args?: unknown;
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type InterruptReviewConfig = {
|
|
12
|
+
actionName: string;
|
|
13
|
+
allowedDecisions?: string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type InterruptPayload = {
|
|
17
|
+
actionRequests?: InterruptActionRequest[];
|
|
18
|
+
reviewConfigs?: InterruptReviewConfig[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type InterruptAction = {
|
|
22
|
+
order: number;
|
|
23
|
+
description?: string;
|
|
24
|
+
allowedDecisions?: string[];
|
|
25
|
+
toolCall?: { id: string; name: string };
|
|
26
|
+
currentConversation?: {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
from: string;
|
|
29
|
+
username: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ToInterruptActionsFn = (interrupt?: InterruptPayload) => Map<string, InterruptAction>;
|
|
34
|
+
|
|
35
|
+
const PATCH_STATE_KEY = Symbol.for('plugin-agent-orchestrator.parallelInterruptActionsPatch');
|
|
36
|
+
|
|
37
|
+
type PatchState = {
|
|
38
|
+
original: ToInterruptActionsFn;
|
|
39
|
+
wrapped: ToInterruptActionsFn;
|
|
40
|
+
owners: Set<symbol>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type PatchableAIEmployeePrototype = {
|
|
44
|
+
toInterruptActions?: ToInterruptActionsFn;
|
|
45
|
+
[PATCH_STATE_KEY]?: PatchState;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function parseInterruptDescription(description?: string): Record<string, unknown> | null {
|
|
49
|
+
if (typeof description !== 'string' || !description) return null;
|
|
50
|
+
try {
|
|
51
|
+
const parsed: unknown = JSON.parse(description);
|
|
52
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? (parsed as Record<string, unknown>) : null;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readOptionalString(record: Record<string, unknown>, key: string): string | undefined {
|
|
59
|
+
const value = record[key];
|
|
60
|
+
return typeof value === 'string' ? value : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Upstream @nocobase/plugin-ai indexes interrupt actionRequests by tool name, which overwrites earlier parallel calls
|
|
65
|
+
* to the same tool and leaves them stuck in invokeStatus="init". Iterate actionRequests directly and key by toolCallId.
|
|
66
|
+
*/
|
|
67
|
+
export function toInterruptActionsFixed(interrupt?: InterruptPayload): Map<string, InterruptAction> {
|
|
68
|
+
const result = new Map<string, InterruptAction>();
|
|
69
|
+
const actionRequests = interrupt?.actionRequests ?? [];
|
|
70
|
+
const reviewConfigs = interrupt?.reviewConfigs ?? [];
|
|
71
|
+
if (!actionRequests.length) {
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const reviewConfigsMap = new Map<string, InterruptReviewConfig>();
|
|
76
|
+
for (const config of reviewConfigs) {
|
|
77
|
+
reviewConfigsMap.set(config.actionName, config);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (let order = 0; order < actionRequests.length; order++) {
|
|
81
|
+
const actionRequest = actionRequests[order];
|
|
82
|
+
const payload = parseInterruptDescription(actionRequest.description);
|
|
83
|
+
const matchingConfig =
|
|
84
|
+
reviewConfigs[order]?.actionName === actionRequest.name
|
|
85
|
+
? reviewConfigs[order]
|
|
86
|
+
: reviewConfigsMap.get(actionRequest.name);
|
|
87
|
+
|
|
88
|
+
const toolCallId = payload ? readOptionalString(payload, 'toolCallId') : undefined;
|
|
89
|
+
const toolCallName = payload ? readOptionalString(payload, 'toolCallName') : undefined;
|
|
90
|
+
const sessionId = payload ? readOptionalString(payload, 'sessionId') : undefined;
|
|
91
|
+
const from = payload ? readOptionalString(payload, 'from') : undefined;
|
|
92
|
+
const username = payload ? readOptionalString(payload, 'username') : undefined;
|
|
93
|
+
|
|
94
|
+
const toolCall =
|
|
95
|
+
payload && toolCallId
|
|
96
|
+
? {
|
|
97
|
+
id: toolCallId,
|
|
98
|
+
name: toolCallName ?? actionRequest.name,
|
|
99
|
+
}
|
|
100
|
+
: undefined;
|
|
101
|
+
|
|
102
|
+
const currentConversation =
|
|
103
|
+
payload && sessionId
|
|
104
|
+
? {
|
|
105
|
+
sessionId,
|
|
106
|
+
from: from ?? '',
|
|
107
|
+
username: username ?? '',
|
|
108
|
+
}
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
const baseKey = toolCall?.id || `${actionRequest.name}:${order}`;
|
|
112
|
+
const key = result.has(baseKey) ? `${baseKey}:${order}` : baseKey;
|
|
113
|
+
|
|
114
|
+
result.set(key, {
|
|
115
|
+
order,
|
|
116
|
+
description: actionRequest.description,
|
|
117
|
+
allowedDecisions: matchingConfig?.allowedDecisions,
|
|
118
|
+
toolCall,
|
|
119
|
+
currentConversation,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function installParallelInterruptActionsPatch(targetPrototype?: PatchableAIEmployeePrototype): () => void {
|
|
127
|
+
const target = targetPrototype ?? (AIEmployee?.prototype as PatchableAIEmployeePrototype | undefined);
|
|
128
|
+
if (!target || typeof target.toInterruptActions !== 'function') {
|
|
129
|
+
return () => undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const owner = Symbol('parallel-interrupt-actions-owner');
|
|
133
|
+
let state = target[PATCH_STATE_KEY];
|
|
134
|
+
if (state && target.toInterruptActions === state.wrapped) {
|
|
135
|
+
state.owners.add(owner);
|
|
136
|
+
} else {
|
|
137
|
+
const original = target.toInterruptActions;
|
|
138
|
+
const wrapped: ToInterruptActionsFn = function toInterruptActionsPatched(interrupt?: InterruptPayload) {
|
|
139
|
+
return toInterruptActionsFixed(interrupt);
|
|
140
|
+
};
|
|
141
|
+
state = {
|
|
142
|
+
original,
|
|
143
|
+
wrapped,
|
|
144
|
+
owners: new Set([owner]),
|
|
145
|
+
};
|
|
146
|
+
target[PATCH_STATE_KEY] = state;
|
|
147
|
+
target.toInterruptActions = wrapped;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let disposed = false;
|
|
151
|
+
return () => {
|
|
152
|
+
if (disposed) return;
|
|
153
|
+
disposed = true;
|
|
154
|
+
const currentState = target[PATCH_STATE_KEY];
|
|
155
|
+
if (!currentState) return;
|
|
156
|
+
currentState.owners.delete(owner);
|
|
157
|
+
if (currentState.owners.size === 0) {
|
|
158
|
+
if (target.toInterruptActions === currentState.wrapped) {
|
|
159
|
+
target.toInterruptActions = currentState.original;
|
|
160
|
+
}
|
|
161
|
+
delete target[PATCH_STATE_KEY];
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import type { Database } from '@nocobase/database';
|
|
4
|
+
|
|
5
|
+
export function normalizeHierarchyInvocationIndex(database: Database) {
|
|
6
|
+
if (!database.inDialect('postgres')) return;
|
|
7
|
+
|
|
8
|
+
const collection = database.getCollection('agentHierarchyInvocations');
|
|
9
|
+
const parentSessionField = collection.underscored ? 'parent_session_id' : 'parentSessionId';
|
|
10
|
+
const parentToolCallField = collection.underscored ? 'parent_tool_call_id' : 'parentToolCallId';
|
|
11
|
+
const index = collection.model.options.indexes?.find(
|
|
12
|
+
(item) =>
|
|
13
|
+
item.unique &&
|
|
14
|
+
item.fields?.length === 2 &&
|
|
15
|
+
item.fields[0] === parentSessionField &&
|
|
16
|
+
item.fields[1] === parentToolCallField,
|
|
17
|
+
);
|
|
18
|
+
if (!index?.name || Buffer.byteLength(index.name, 'utf8') <= 63) return;
|
|
19
|
+
|
|
20
|
+
// Sequelize 6 reuses these index option objects during sync. Match PostgreSQL's stored name, including the table prefix.
|
|
21
|
+
let name = '';
|
|
22
|
+
for (const character of index.name) {
|
|
23
|
+
if (Buffer.byteLength(name + character, 'utf8') > 63) break;
|
|
24
|
+
name += character;
|
|
25
|
+
}
|
|
26
|
+
index.name = name;
|
|
27
|
+
}
|