plugin-agent-orchestrator 1.2.1 → 1.2.2
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 +25 -12
- package/dist/server/services/ParallelInterruptActionsPatch.js +132 -0
- package/package.json +2 -2
- package/src/server/__tests__/parallel-interrupt-actions.test.ts +342 -0
- package/src/server/plugin.ts +14 -0
- package/src/server/services/ParallelInterruptActionsPatch.ts +164 -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-20T07:15:39.703Z"}
|
|
@@ -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-20T07:15:39.883Z"}
|
|
@@ -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-20T07:15:39.220Z"}
|
|
@@ -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-20T07:15:38.813Z"}
|
|
@@ -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-20T07:15:37.783Z"}
|
package/dist/server/plugin.js
CHANGED
|
@@ -82,6 +82,7 @@ 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");
|
|
85
86
|
function normalizeOptionalString(value) {
|
|
86
87
|
return typeof value === "string" ? value.trim() : "";
|
|
87
88
|
}
|
|
@@ -192,6 +193,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
192
193
|
removeNativeMonitorHook;
|
|
193
194
|
removeManagedPromptProtection;
|
|
194
195
|
removeNativeUsageAttribution;
|
|
196
|
+
removeParallelInterruptActionsPatch;
|
|
195
197
|
governanceEnabled = true;
|
|
196
198
|
loopScheduler;
|
|
197
199
|
loopWorker;
|
|
@@ -270,6 +272,7 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
270
272
|
this.app.acl.allow("agentLoopEventsStream", ["stream"], "loggedIn");
|
|
271
273
|
this.app.acl.allow("agentAutoApproval", ["get", "set", "eligible"], "loggedIn");
|
|
272
274
|
this.installGovernanceHooks();
|
|
275
|
+
this.installParallelInterruptActionsFix();
|
|
273
276
|
this.app.resourceManager.use(
|
|
274
277
|
async (ctx, next) => {
|
|
275
278
|
var _a2;
|
|
@@ -588,38 +591,43 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
588
591
|
async afterEnable() {
|
|
589
592
|
this.governanceEnabled = true;
|
|
590
593
|
this.installGovernanceHooks();
|
|
594
|
+
this.installParallelInterruptActionsFix();
|
|
591
595
|
this.installNativeMonitorHook();
|
|
592
596
|
}
|
|
593
597
|
async afterDisable() {
|
|
594
|
-
var _a, _b, _c, _d;
|
|
598
|
+
var _a, _b, _c, _d, _e;
|
|
595
599
|
this.governanceEnabled = false;
|
|
596
600
|
this.hierarchyCancellation.abortAll();
|
|
597
601
|
(_a = this.removeManagedPromptProtection) == null ? void 0 : _a.call(this);
|
|
598
602
|
this.removeManagedPromptProtection = void 0;
|
|
599
603
|
(_b = this.removeNativeUsageAttribution) == null ? void 0 : _b.call(this);
|
|
600
604
|
this.removeNativeUsageAttribution = void 0;
|
|
601
|
-
(_c = this.
|
|
602
|
-
|
|
605
|
+
(_c = this.removeParallelInterruptActionsPatch) == null ? void 0 : _c.call(this);
|
|
606
|
+
this.removeParallelInterruptActionsPatch = void 0;
|
|
607
|
+
(_d = this.nativeObserver) == null ? void 0 : _d.uninstall();
|
|
608
|
+
(_e = this.removeNativeMonitorHook) == null ? void 0 : _e.call(this);
|
|
603
609
|
this.removeNativeMonitorHook = void 0;
|
|
604
610
|
}
|
|
605
611
|
async remove() {
|
|
606
612
|
}
|
|
607
613
|
async beforeStop() {
|
|
608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
614
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
609
615
|
this.governanceEnabled = false;
|
|
610
616
|
this.hierarchyCancellation.abortAll();
|
|
611
617
|
(_a = this.removeManagedPromptProtection) == null ? void 0 : _a.call(this);
|
|
612
618
|
this.removeManagedPromptProtection = void 0;
|
|
613
619
|
(_b = this.removeNativeUsageAttribution) == null ? void 0 : _b.call(this);
|
|
614
620
|
this.removeNativeUsageAttribution = void 0;
|
|
615
|
-
(
|
|
616
|
-
|
|
617
|
-
(
|
|
618
|
-
(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
(
|
|
622
|
-
(
|
|
621
|
+
(_c = this.removeParallelInterruptActionsPatch) == null ? void 0 : _c.call(this);
|
|
622
|
+
this.removeParallelInterruptActionsPatch = void 0;
|
|
623
|
+
(_e = (_d = this.app).off) == null ? void 0 : _e.call(_d, "afterStart", this.installNativeObserver);
|
|
624
|
+
(_g = (_f = this.app).removeListener) == null ? void 0 : _g.call(_f, "afterStart", this.installNativeObserver);
|
|
625
|
+
(_i = (_h = this.app).off) == null ? void 0 : _i.call(_h, "afterStart", this.startLoopWorker);
|
|
626
|
+
(_k = (_j = this.app).removeListener) == null ? void 0 : _k.call(_j, "afterStart", this.startLoopWorker);
|
|
627
|
+
await ((_l = this.loopWorker) == null ? void 0 : _l.stop());
|
|
628
|
+
await ((_m = this.loopScheduler) == null ? void 0 : _m.dispose());
|
|
629
|
+
(_n = this.nativeObserver) == null ? void 0 : _n.uninstall();
|
|
630
|
+
(_o = this.removeNativeMonitorHook) == null ? void 0 : _o.call(this);
|
|
623
631
|
this.removeNativeMonitorHook = void 0;
|
|
624
632
|
await this.skillHub.beforeStop();
|
|
625
633
|
(0, import_RunEventBus.resetRunEventBus)();
|
|
@@ -639,6 +647,11 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
639
647
|
this.removeManagedPromptProtection = (0, import_ManagedPromptProtection.installManagedPromptProtection)(this.db);
|
|
640
648
|
if (!this.removeNativeUsageAttribution) this.removeNativeUsageAttribution = (0, import_NativeUsageAttribution.installNativeUsageAttribution)(this);
|
|
641
649
|
}
|
|
650
|
+
installParallelInterruptActionsFix() {
|
|
651
|
+
if (!this.removeParallelInterruptActionsPatch) {
|
|
652
|
+
this.removeParallelInterruptActionsPatch = (0, import_ParallelInterruptActionsPatch.installParallelInterruptActionsPatch)();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
642
655
|
installNativeMonitorHook() {
|
|
643
656
|
if (this.removeNativeMonitorHook || !this.agentRuntimeLifecycle || !this.nativeMonitorSyncService) return;
|
|
644
657
|
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
|
+
});
|
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.2",
|
|
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": "abdffdb80dfba1d7797bbbafa90e0633677a14d9",
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public",
|
|
64
64
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -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,7 @@ 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';
|
|
46
47
|
|
|
47
48
|
function normalizeOptionalString(value: unknown) {
|
|
48
49
|
return typeof value === 'string' ? value.trim() : '';
|
|
@@ -172,6 +173,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
172
173
|
private removeNativeMonitorHook?: () => void;
|
|
173
174
|
private removeManagedPromptProtection?: () => void;
|
|
174
175
|
private removeNativeUsageAttribution?: () => void;
|
|
176
|
+
private removeParallelInterruptActionsPatch?: () => void;
|
|
175
177
|
private governanceEnabled = true;
|
|
176
178
|
loopScheduler: LoopSchedulerService;
|
|
177
179
|
loopWorker: LoopWorkerService;
|
|
@@ -264,6 +266,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
264
266
|
this.app.acl.allow('agentAutoApproval', ['get', 'set', 'eligible'], 'loggedIn');
|
|
265
267
|
|
|
266
268
|
this.installGovernanceHooks();
|
|
269
|
+
this.installParallelInterruptActionsFix();
|
|
267
270
|
this.app.resourceManager.use(
|
|
268
271
|
async (ctx, next) => {
|
|
269
272
|
if (
|
|
@@ -653,6 +656,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
653
656
|
async afterEnable() {
|
|
654
657
|
this.governanceEnabled = true;
|
|
655
658
|
this.installGovernanceHooks();
|
|
659
|
+
this.installParallelInterruptActionsFix();
|
|
656
660
|
this.installNativeMonitorHook();
|
|
657
661
|
}
|
|
658
662
|
async afterDisable() {
|
|
@@ -662,6 +666,8 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
662
666
|
this.removeManagedPromptProtection = undefined;
|
|
663
667
|
this.removeNativeUsageAttribution?.();
|
|
664
668
|
this.removeNativeUsageAttribution = undefined;
|
|
669
|
+
this.removeParallelInterruptActionsPatch?.();
|
|
670
|
+
this.removeParallelInterruptActionsPatch = undefined;
|
|
665
671
|
this.nativeObserver?.uninstall();
|
|
666
672
|
this.removeNativeMonitorHook?.();
|
|
667
673
|
this.removeNativeMonitorHook = undefined;
|
|
@@ -675,6 +681,8 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
675
681
|
this.removeManagedPromptProtection = undefined;
|
|
676
682
|
this.removeNativeUsageAttribution?.();
|
|
677
683
|
this.removeNativeUsageAttribution = undefined;
|
|
684
|
+
this.removeParallelInterruptActionsPatch?.();
|
|
685
|
+
this.removeParallelInterruptActionsPatch = undefined;
|
|
678
686
|
this.app.off?.('afterStart', this.installNativeObserver);
|
|
679
687
|
this.app.removeListener?.('afterStart', this.installNativeObserver);
|
|
680
688
|
this.app.off?.('afterStart', this.startLoopWorker);
|
|
@@ -704,6 +712,12 @@ export class PluginAgentOrchestratorServer extends Plugin {
|
|
|
704
712
|
if (!this.removeNativeUsageAttribution) this.removeNativeUsageAttribution = installNativeUsageAttribution(this);
|
|
705
713
|
}
|
|
706
714
|
|
|
715
|
+
private installParallelInterruptActionsFix() {
|
|
716
|
+
if (!this.removeParallelInterruptActionsPatch) {
|
|
717
|
+
this.removeParallelInterruptActionsPatch = installParallelInterruptActionsPatch();
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
707
721
|
private installNativeMonitorHook() {
|
|
708
722
|
if (this.removeNativeMonitorHook || !this.agentRuntimeLifecycle || !this.nativeMonitorSyncService) return;
|
|
709
723
|
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
|
+
}
|