plugin-agent-orchestrator 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +16 -291
  2. package/dist/client/AIEmployeesContext.d.ts +7 -0
  3. package/dist/client/OrchestratorSettings.d.ts +2 -1
  4. package/dist/client/index.js +1 -1
  5. package/dist/client/plugin.d.ts +1 -0
  6. package/dist/client/skill-hub/components/ExecutionHistory.d.ts +2 -0
  7. package/dist/client/skill-hub/components/ExecutionProgress.d.ts +20 -0
  8. package/dist/client/skill-hub/components/GitSkillImport.d.ts +7 -0
  9. package/dist/client/skill-hub/components/SkillEditor.d.ts +7 -0
  10. package/dist/client/skill-hub/components/SkillManager.d.ts +2 -0
  11. package/dist/client/skill-hub/components/SkillMetrics.d.ts +2 -0
  12. package/dist/client/skill-hub/components/SkillTestPanel.d.ts +7 -0
  13. package/dist/client/skill-hub/index.d.ts +10 -0
  14. package/dist/client/skill-hub/locale.d.ts +3 -0
  15. package/dist/client/skill-hub/tools/InteractionSchemasProvider.d.ts +19 -0
  16. package/dist/client/skill-hub/tools/SkillHubCard.d.ts +3 -0
  17. package/dist/client/skill-hub/utils/jsonFields.d.ts +3 -0
  18. package/dist/externalVersion.js +6 -6
  19. package/dist/node_modules/adm-zip/LICENSE +21 -0
  20. package/dist/node_modules/adm-zip/adm-zip.js +1 -0
  21. package/dist/node_modules/adm-zip/headers/entryHeader.js +377 -0
  22. package/dist/node_modules/adm-zip/headers/index.js +2 -0
  23. package/dist/node_modules/adm-zip/headers/mainHeader.js +130 -0
  24. package/dist/node_modules/adm-zip/methods/deflater.js +33 -0
  25. package/dist/node_modules/adm-zip/methods/index.js +3 -0
  26. package/dist/node_modules/adm-zip/methods/inflater.js +34 -0
  27. package/dist/node_modules/adm-zip/methods/zipcrypto.js +175 -0
  28. package/dist/node_modules/adm-zip/package.json +1 -0
  29. package/dist/node_modules/adm-zip/util/constants.js +142 -0
  30. package/dist/node_modules/adm-zip/util/decoder.js +5 -0
  31. package/dist/node_modules/adm-zip/util/errors.js +63 -0
  32. package/dist/node_modules/adm-zip/util/fattr.js +76 -0
  33. package/dist/node_modules/adm-zip/util/index.js +5 -0
  34. package/dist/node_modules/adm-zip/util/utils.js +339 -0
  35. package/dist/node_modules/adm-zip/zipEntry.js +405 -0
  36. package/dist/node_modules/adm-zip/zipFile.js +446 -0
  37. package/dist/node_modules/simple-git/dist/cjs/index.js +7399 -0
  38. package/dist/node_modules/simple-git/dist/esm/index.js +4745 -0
  39. package/dist/node_modules/simple-git/dist/esm/package.json +3 -0
  40. package/dist/node_modules/simple-git/dist/src/lib/api.d.ts +13 -0
  41. package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +9 -0
  42. package/dist/node_modules/simple-git/dist/src/lib/errors/git-construct-error.d.ts +15 -0
  43. package/dist/node_modules/simple-git/dist/src/lib/errors/git-error.d.ts +30 -0
  44. package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +7 -0
  45. package/dist/node_modules/simple-git/dist/src/lib/errors/git-response-error.d.ts +32 -0
  46. package/dist/node_modules/simple-git/dist/src/lib/errors/task-configuration-error.d.ts +12 -0
  47. package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +15 -0
  48. package/dist/node_modules/simple-git/dist/src/lib/git-logger.d.ts +21 -0
  49. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch-delete.d.ts +5 -0
  50. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch.d.ts +2 -0
  51. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-commit.d.ts +2 -0
  52. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +3 -0
  53. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-fetch.d.ts +2 -0
  54. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-list-log-summary.d.ts +6 -0
  55. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-merge.d.ts +11 -0
  56. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-move.d.ts +2 -0
  57. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-pull.d.ts +6 -0
  58. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-push.d.ts +4 -0
  59. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-messages.d.ts +5 -0
  60. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-objects.d.ts +3 -0
  61. package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +3 -0
  62. package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +3 -0
  63. package/dist/node_modules/simple-git/dist/src/lib/plugins/command-config-prefixing-plugin.d.ts +2 -0
  64. package/dist/node_modules/simple-git/dist/src/lib/plugins/completion-detection.plugin.d.ts +3 -0
  65. package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +3 -0
  66. package/dist/node_modules/simple-git/dist/src/lib/plugins/error-detection.plugin.d.ts +7 -0
  67. package/dist/node_modules/simple-git/dist/src/lib/plugins/index.d.ts +11 -0
  68. package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +11 -0
  69. package/dist/node_modules/simple-git/dist/src/lib/plugins/progress-monitor-plugin.d.ts +3 -0
  70. package/dist/node_modules/simple-git/dist/src/lib/plugins/simple-git-plugin.d.ts +48 -0
  71. package/dist/node_modules/simple-git/dist/src/lib/plugins/spawn-options-plugin.d.ts +3 -0
  72. package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +2 -0
  73. package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +3 -0
  74. package/dist/node_modules/simple-git/dist/src/lib/responses/BranchDeleteSummary.d.ts +12 -0
  75. package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +14 -0
  76. package/dist/node_modules/simple-git/dist/src/lib/responses/CheckIgnore.d.ts +4 -0
  77. package/dist/node_modules/simple-git/dist/src/lib/responses/CleanSummary.d.ts +9 -0
  78. package/dist/node_modules/simple-git/dist/src/lib/responses/ConfigList.d.ts +13 -0
  79. package/dist/node_modules/simple-git/dist/src/lib/responses/DiffSummary.d.ts +10 -0
  80. package/dist/node_modules/simple-git/dist/src/lib/responses/FileStatusSummary.d.ts +9 -0
  81. package/dist/node_modules/simple-git/dist/src/lib/responses/GetRemoteSummary.d.ts +11 -0
  82. package/dist/node_modules/simple-git/dist/src/lib/responses/InitSummary.d.ts +9 -0
  83. package/dist/node_modules/simple-git/dist/src/lib/responses/MergeSummary.d.ts +16 -0
  84. package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +25 -0
  85. package/dist/node_modules/simple-git/dist/src/lib/responses/StatusSummary.d.ts +19 -0
  86. package/dist/node_modules/simple-git/dist/src/lib/responses/TagList.d.ts +7 -0
  87. package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor-chain.d.ts +25 -0
  88. package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor.d.ts +14 -0
  89. package/dist/node_modules/simple-git/dist/src/lib/runners/promise-wrapped.d.ts +2 -0
  90. package/dist/node_modules/simple-git/dist/src/lib/runners/scheduler.d.ts +11 -0
  91. package/dist/node_modules/simple-git/dist/src/lib/runners/tasks-pending-queue.d.ts +23 -0
  92. package/dist/node_modules/simple-git/dist/src/lib/simple-git-api.d.ts +20 -0
  93. package/dist/node_modules/simple-git/dist/src/lib/task-callback.d.ts +2 -0
  94. package/dist/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts +3 -0
  95. package/dist/node_modules/simple-git/dist/src/lib/tasks/branch.d.ts +7 -0
  96. package/dist/node_modules/simple-git/dist/src/lib/tasks/change-working-directory.d.ts +2 -0
  97. package/dist/node_modules/simple-git/dist/src/lib/tasks/check-ignore.d.ts +2 -0
  98. package/dist/node_modules/simple-git/dist/src/lib/tasks/check-is-repo.d.ts +9 -0
  99. package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +2 -0
  100. package/dist/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts +25 -0
  101. package/dist/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts +9 -0
  102. package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +4 -0
  103. package/dist/node_modules/simple-git/dist/src/lib/tasks/config.d.ts +8 -0
  104. package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +12 -0
  105. package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +12 -0
  106. package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +5 -0
  107. package/dist/node_modules/simple-git/dist/src/lib/tasks/fetch.d.ts +4 -0
  108. package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +2 -0
  109. package/dist/node_modules/simple-git/dist/src/lib/tasks/grep.d.ts +12 -0
  110. package/dist/node_modules/simple-git/dist/src/lib/tasks/hash-object.d.ts +5 -0
  111. package/dist/node_modules/simple-git/dist/src/lib/tasks/init.d.ts +3 -0
  112. package/dist/node_modules/simple-git/dist/src/lib/tasks/log.d.ts +32 -0
  113. package/dist/node_modules/simple-git/dist/src/lib/tasks/merge.d.ts +4 -0
  114. package/dist/node_modules/simple-git/dist/src/lib/tasks/move.d.ts +3 -0
  115. package/dist/node_modules/simple-git/dist/src/lib/tasks/pull.d.ts +3 -0
  116. package/dist/node_modules/simple-git/dist/src/lib/tasks/push.d.ts +9 -0
  117. package/dist/node_modules/simple-git/dist/src/lib/tasks/remote.d.ts +8 -0
  118. package/dist/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts +11 -0
  119. package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +2 -0
  120. package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +4 -0
  121. package/dist/node_modules/simple-git/dist/src/lib/tasks/status.d.ts +3 -0
  122. package/dist/node_modules/simple-git/dist/src/lib/tasks/sub-module.d.ts +5 -0
  123. package/dist/node_modules/simple-git/dist/src/lib/tasks/tag.d.ts +18 -0
  124. package/dist/node_modules/simple-git/dist/src/lib/tasks/task.d.ts +14 -0
  125. package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +9 -0
  126. package/dist/node_modules/simple-git/dist/src/lib/types/handlers.d.ts +21 -0
  127. package/dist/node_modules/simple-git/dist/src/lib/types/index.d.ts +136 -0
  128. package/dist/node_modules/simple-git/dist/src/lib/types/tasks.d.ts +19 -0
  129. package/dist/node_modules/simple-git/dist/src/lib/utils/argument-filters.d.ts +14 -0
  130. package/dist/node_modules/simple-git/dist/src/lib/utils/exit-codes.d.ts +10 -0
  131. package/dist/node_modules/simple-git/dist/src/lib/utils/git-output-streams.d.ts +7 -0
  132. package/dist/node_modules/simple-git/dist/src/lib/utils/index.d.ts +8 -0
  133. package/dist/node_modules/simple-git/dist/src/lib/utils/line-parser.d.ts +15 -0
  134. package/dist/node_modules/simple-git/dist/src/lib/utils/simple-git-options.d.ts +2 -0
  135. package/dist/node_modules/simple-git/dist/src/lib/utils/task-options.d.ts +13 -0
  136. package/dist/node_modules/simple-git/dist/src/lib/utils/task-parser.d.ts +5 -0
  137. package/dist/node_modules/simple-git/dist/src/lib/utils/util.d.ts +47 -0
  138. package/dist/node_modules/simple-git/dist/typings/errors.d.ts +5 -0
  139. package/dist/node_modules/simple-git/dist/typings/index.d.ts +14 -0
  140. package/dist/node_modules/simple-git/dist/typings/response.d.ts +556 -0
  141. package/dist/node_modules/simple-git/dist/typings/simple-git.d.ts +1033 -0
  142. package/dist/node_modules/simple-git/dist/typings/types.d.ts +22 -0
  143. package/dist/node_modules/simple-git/node_modules/debug/package.json +64 -0
  144. package/dist/node_modules/simple-git/node_modules/debug/src/browser.js +272 -0
  145. package/dist/node_modules/simple-git/node_modules/debug/src/common.js +292 -0
  146. package/dist/node_modules/simple-git/node_modules/debug/src/index.js +10 -0
  147. package/dist/node_modules/simple-git/node_modules/debug/src/node.js +263 -0
  148. package/dist/node_modules/simple-git/package.json +1 -0
  149. package/dist/node_modules/simple-git/promise.js +17 -0
  150. package/dist/server/collections/agent-execution-spans.d.ts +9 -0
  151. package/dist/server/collections/agent-execution-spans.js +152 -0
  152. package/dist/server/collections/orchestrator-config.js +6 -0
  153. package/dist/server/collections/skill-definitions.d.ts +3 -0
  154. package/dist/server/collections/skill-definitions.js +158 -0
  155. package/dist/server/collections/skill-executions.d.ts +3 -0
  156. package/dist/server/collections/skill-executions.js +123 -0
  157. package/dist/server/collections/skill-worker-configs.d.ts +3 -0
  158. package/dist/server/collections/skill-worker-configs.js +115 -0
  159. package/dist/server/migrations/20260423000000-add-progress-fields.d.ts +4 -0
  160. package/dist/server/migrations/20260423000000-add-progress-fields.js +69 -0
  161. package/dist/server/migrations/20260425000000-add-interaction-schema.d.ts +4 -0
  162. package/dist/server/migrations/20260425000000-add-interaction-schema.js +61 -0
  163. package/dist/server/migrations/20260427000000-change-packages-to-text.d.ts +4 -0
  164. package/dist/server/migrations/20260427000000-change-packages-to-text.js +70 -0
  165. package/dist/server/migrations/20260427000001-change-other-json-to-text.d.ts +4 -0
  166. package/dist/server/migrations/20260427000001-change-other-json-to-text.js +80 -0
  167. package/dist/server/migrations/20260429000000-add-llm-fields.js +8 -0
  168. package/dist/server/migrations/20260429000000-fix-inputargs-json-to-text.d.ts +16 -0
  169. package/dist/server/migrations/20260429000000-fix-inputargs-json-to-text.js +51 -0
  170. package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.d.ts +7 -0
  171. package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +57 -0
  172. package/dist/server/plugin.d.ts +3 -0
  173. package/dist/server/plugin.js +37 -1
  174. package/dist/server/resources/tracing.js +154 -11
  175. package/dist/server/services/CodeValidator.d.ts +32 -0
  176. package/dist/server/services/CodeValidator.js +205 -0
  177. package/dist/server/services/ExecutionSpanService.d.ts +44 -0
  178. package/dist/server/services/ExecutionSpanService.js +104 -0
  179. package/dist/server/services/FileManager.d.ts +28 -0
  180. package/dist/server/services/FileManager.js +151 -0
  181. package/dist/server/services/SandboxRunner.d.ts +41 -0
  182. package/dist/server/services/SandboxRunner.js +167 -0
  183. package/dist/server/services/SkillManager.d.ts +6 -0
  184. package/dist/server/services/SkillManager.js +640 -0
  185. package/dist/server/services/SkillRepositoryService.d.ts +22 -0
  186. package/dist/server/services/SkillRepositoryService.js +157 -0
  187. package/dist/server/services/WorkerEnvManager.d.ts +26 -0
  188. package/dist/server/services/WorkerEnvManager.js +120 -0
  189. package/dist/server/skill-hub/actions/git-import.d.ts +21 -0
  190. package/dist/server/skill-hub/actions/git-import.js +413 -0
  191. package/dist/server/skill-hub/mcp/McpController.d.ts +15 -0
  192. package/dist/server/skill-hub/mcp/McpController.js +111 -0
  193. package/dist/server/skill-hub/plugin.d.ts +58 -0
  194. package/dist/server/skill-hub/plugin.js +694 -0
  195. package/dist/server/skill-hub/sandbox-config.json +6 -0
  196. package/dist/server/skill-hub/tasks/SkillExecutionTask.d.ts +14 -0
  197. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +267 -0
  198. package/dist/server/skill-hub/utils/json-fields.d.ts +7 -0
  199. package/dist/server/skill-hub/utils/json-fields.js +88 -0
  200. package/dist/server/tools/delegate-task.d.ts +4 -0
  201. package/dist/server/tools/delegate-task.js +606 -104
  202. package/dist/server/tools/skill-execute.d.ts +36 -0
  203. package/dist/server/tools/skill-execute.js +167 -0
  204. package/package.json +3 -1
  205. package/src/client/AIEmployeeSelect.tsx +1 -3
  206. package/src/client/AIEmployeesContext.tsx +28 -13
  207. package/src/client/OrchestratorSettings.tsx +43 -5
  208. package/src/client/RulesTab.tsx +253 -32
  209. package/src/client/TracingTab.tsx +277 -213
  210. package/src/client/plugin.tsx +39 -0
  211. package/src/client/skill-hub/components/ExecutionHistory.tsx +201 -0
  212. package/src/client/skill-hub/components/ExecutionProgress.tsx +55 -0
  213. package/src/client/skill-hub/components/GitSkillImport.tsx +555 -0
  214. package/src/client/skill-hub/components/SkillEditor.tsx +456 -0
  215. package/src/client/skill-hub/components/SkillManager.tsx +181 -0
  216. package/src/client/skill-hub/components/SkillMetrics.tsx +124 -0
  217. package/src/client/skill-hub/components/SkillTestPanel.tsx +144 -0
  218. package/src/client/skill-hub/index.tsx +75 -0
  219. package/src/client/skill-hub/locale.ts +16 -0
  220. package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +59 -0
  221. package/src/client/skill-hub/tools/SkillHubCard.tsx +78 -0
  222. package/src/client/skill-hub/utils/jsonFields.ts +37 -0
  223. package/src/server/collections/agent-execution-spans.ts +129 -0
  224. package/src/server/collections/orchestrator-config.ts +7 -0
  225. package/src/server/collections/skill-definitions.ts +128 -0
  226. package/src/server/collections/skill-executions.ts +94 -0
  227. package/src/server/collections/skill-worker-configs.ts +86 -0
  228. package/src/server/migrations/20260423000000-add-progress-fields.ts +50 -0
  229. package/src/server/migrations/20260425000000-add-interaction-schema.ts +35 -0
  230. package/src/server/migrations/20260427000000-change-packages-to-text.ts +47 -0
  231. package/src/server/migrations/20260427000001-change-other-json-to-text.ts +57 -0
  232. package/src/server/migrations/20260429000000-add-llm-fields.ts +9 -0
  233. package/src/server/migrations/20260429000000-fix-inputargs-json-to-text.ts +38 -0
  234. package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +32 -0
  235. package/src/server/plugin.ts +51 -3
  236. package/src/server/resources/tracing.ts +182 -15
  237. package/src/server/services/CodeValidator.ts +159 -0
  238. package/src/server/services/ExecutionSpanService.ts +106 -0
  239. package/src/server/services/FileManager.ts +144 -0
  240. package/src/server/services/SandboxRunner.ts +205 -0
  241. package/src/server/services/SkillManager.ts +623 -0
  242. package/src/server/services/SkillRepositoryService.ts +142 -0
  243. package/src/server/services/WorkerEnvManager.ts +113 -0
  244. package/src/server/skill-hub/actions/git-import.ts +486 -0
  245. package/src/server/skill-hub/mcp/McpController.ts +86 -0
  246. package/src/server/skill-hub/plugin.ts +771 -0
  247. package/src/server/skill-hub/sandbox-config.json +6 -0
  248. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +297 -0
  249. package/src/server/skill-hub/utils/json-fields.ts +57 -0
  250. package/src/server/tools/delegate-task.ts +803 -127
  251. package/src/server/tools/skill-execute.ts +157 -0
@@ -1,5 +1,108 @@
1
1
  import { Plugin } from '@nocobase/server';
2
2
 
3
+ function toPlain(row: any) {
4
+ return row?.toJSON?.() || row;
5
+ }
6
+
7
+ function normalizeSpanFilter(filter: any = {}) {
8
+ const next = { ...filter };
9
+ if (next.subAgentUsername) {
10
+ next.employeeUsername = next.subAgentUsername;
11
+ delete next.subAgentUsername;
12
+ }
13
+ return next;
14
+ }
15
+
16
+ function spanTitle(row: any) {
17
+ if (row.title) return row.title;
18
+ if (row.type === 'sub_agent') return `${row.leaderUsername || '-'} -> ${row.employeeUsername || '-'}`;
19
+ return row.toolName || row.type || 'span';
20
+ }
21
+
22
+ function formatSpanListRow(raw: any) {
23
+ const row = toPlain(raw);
24
+ const metadata = row.metadata || {};
25
+ const input = row.input || {};
26
+ return {
27
+ id: row.id,
28
+ rootRunId: row.rootRunId,
29
+ parentSpanId: row.parentSpanId,
30
+ type: row.type,
31
+ leaderUsername: row.leaderUsername,
32
+ subAgentUsername: row.employeeUsername,
33
+ employeeUsername: row.employeeUsername,
34
+ toolName: row.toolName,
35
+ task: input.task || metadata.task || row.title || '',
36
+ context: input.context || '',
37
+ result: row.output,
38
+ status: row.status,
39
+ depth: metadata.depth ?? 0,
40
+ durationMs: row.durationMs,
41
+ error: row.error,
42
+ userId: row.userId,
43
+ createdAt: row.createdAt || row.startedAt,
44
+ traceCount: metadata.traceCount || 0,
45
+ messageCount: Array.isArray(metadata.messages) ? metadata.messages.length : metadata.messageCount || 0,
46
+ hasUnifiedTrace: true,
47
+ };
48
+ }
49
+
50
+ function buildSpanTree(rows: any[]) {
51
+ const plainRows = rows.map(toPlain);
52
+ const byId = new Map<string, any>();
53
+ const roots: any[] = [];
54
+
55
+ for (const row of plainRows) {
56
+ const node = { ...row, children: [] };
57
+ byId.set(String(row.id), node);
58
+ }
59
+
60
+ for (const row of byId.values()) {
61
+ if (row.parentSpanId && byId.has(String(row.parentSpanId))) {
62
+ byId.get(String(row.parentSpanId)).children.push(row);
63
+ } else {
64
+ roots.push(row);
65
+ }
66
+ }
67
+
68
+ const sortTree = (items: any[]) => {
69
+ items.sort(
70
+ (a, b) =>
71
+ new Date(a.startedAt || a.createdAt || 0).getTime() -
72
+ new Date(b.startedAt || b.createdAt || 0).getTime(),
73
+ );
74
+ for (const item of items) sortTree(item.children || []);
75
+ };
76
+ sortTree(roots);
77
+ return roots;
78
+ }
79
+
80
+ function flattenSpanTimeline(rows: any[]) {
81
+ return rows
82
+ .map(toPlain)
83
+ .sort(
84
+ (a, b) =>
85
+ new Date(a.startedAt || a.createdAt || 0).getTime() -
86
+ new Date(b.startedAt || b.createdAt || 0).getTime(),
87
+ )
88
+ .map((row) => {
89
+ const input = row.input || {};
90
+ const metadata = row.metadata || {};
91
+ return {
92
+ type: row.type,
93
+ at: row.startedAt || row.createdAt,
94
+ title: spanTitle(row),
95
+ toolName: row.toolName,
96
+ args: row.type === 'tool' || row.type === 'skill' ? input : undefined,
97
+ status: row.status,
98
+ content: row.output || row.error || input.task || metadata.summary || '',
99
+ spanId: row.id,
100
+ parentSpanId: row.parentSpanId,
101
+ skillExecutionId: row.skillExecutionId,
102
+ };
103
+ });
104
+ }
105
+
3
106
  /**
4
107
  * Custom resource for the Swarm Tracing admin UI (Phase 5).
5
108
  * Queries the dedicated orchestratorLogs collection instead of
@@ -15,10 +118,39 @@ export function registerTracingResource(plugin: Plugin) {
15
118
  * List all delegation execution logs.
16
119
  */
17
120
  async list(ctx, next) {
18
- const repo = ctx.db.getRepository('orchestratorLogs');
19
121
  const { page = 1, pageSize = 50, sort = ['-createdAt'], filter = {} } = ctx.action.params;
20
122
 
21
123
  try {
124
+ const spanRepo = ctx.db.getRepository('agentExecutionSpans');
125
+ if (spanRepo) {
126
+ const spanFilter = {
127
+ ...normalizeSpanFilter(filter),
128
+ parentSpanId: null,
129
+ type: 'sub_agent',
130
+ };
131
+ const [spanRows, spanCount] = await spanRepo.findAndCount({
132
+ filter: spanFilter,
133
+ sort,
134
+ offset: (Number(page) - 1) * Number(pageSize),
135
+ limit: Number(pageSize),
136
+ });
137
+
138
+ if (spanCount > 0) {
139
+ ctx.body = {
140
+ data: spanRows.map(formatSpanListRow),
141
+ meta: {
142
+ count: spanCount,
143
+ page: Number(page),
144
+ pageSize: Number(pageSize),
145
+ totalPage: Math.ceil(spanCount / Number(pageSize)),
146
+ },
147
+ };
148
+ await next();
149
+ return;
150
+ }
151
+ }
152
+
153
+ const repo = ctx.db.getRepository('orchestratorLogs');
22
154
  const [rows, count] = await repo.findAndCount({
23
155
  filter,
24
156
  sort,
@@ -43,6 +175,7 @@ export function registerTracingResource(plugin: Plugin) {
43
175
  createdAt: row.createdAt,
44
176
  traceCount: Array.isArray(row.trace) ? row.trace.length : 0,
45
177
  messageCount: Array.isArray(row.messages) ? row.messages.length : 0,
178
+ hasUnifiedTrace: false,
46
179
  })),
47
180
  meta: {
48
181
  count,
@@ -51,9 +184,10 @@ export function registerTracingResource(plugin: Plugin) {
51
184
  totalPage: Math.ceil(count / Number(pageSize)),
52
185
  },
53
186
  };
54
- } catch (e) {
187
+ } catch (e: any) {
188
+ // Bubble up so the admin sees an error toast instead of an empty grid.
55
189
  ctx.log.error('[AgentOrchestrator] Tracing list error', e);
56
- ctx.body = { data: [], meta: { count: 0 } };
190
+ ctx.throw(500, e?.message || 'Failed to load tracing logs');
57
191
  }
58
192
 
59
193
  await next();
@@ -63,7 +197,7 @@ export function registerTracingResource(plugin: Plugin) {
63
197
  * Get a single delegation log by ID.
64
198
  */
65
199
  async get(ctx, next) {
66
- const { filterByTk } = ctx.action.params;
200
+ const { filterByTk, source } = ctx.action.params;
67
201
 
68
202
  if (!filterByTk) {
69
203
  ctx.throw(400, 'id is required');
@@ -71,15 +205,52 @@ export function registerTracingResource(plugin: Plugin) {
71
205
  }
72
206
 
73
207
  try {
208
+ const spanRepo = ctx.db.getRepository('agentExecutionSpans');
209
+ if (spanRepo && source !== 'log') {
210
+ const span = await spanRepo.findOne({
211
+ filter: { id: filterByTk },
212
+ });
213
+
214
+ if (span) {
215
+ const plainSpan = toPlain(span);
216
+ const rows = await spanRepo.find({
217
+ filter: { rootRunId: plainSpan.rootRunId },
218
+ sort: ['createdAt'],
219
+ });
220
+ const tree = buildSpanTree(rows);
221
+ const timeline = flattenSpanTimeline(rows);
222
+ const rootRow = formatSpanListRow(plainSpan);
223
+ const metadata = plainSpan.metadata || {};
224
+
225
+ ctx.body = {
226
+ data: {
227
+ ...rootRow,
228
+ input: plainSpan.input,
229
+ output: plainSpan.output,
230
+ metadata,
231
+ trace: timeline,
232
+ messages: metadata.messages || [],
233
+ children: tree,
234
+ },
235
+ };
236
+ await next();
237
+ return;
238
+ }
239
+ }
240
+
74
241
  const repo = ctx.db.getRepository('orchestratorLogs');
75
- const log = await repo.findOne({
76
- filter: { id: filterByTk },
77
- });
242
+ const log =
243
+ source === 'span'
244
+ ? null
245
+ : await repo.findOne({
246
+ filter: { id: filterByTk },
247
+ });
78
248
 
79
- ctx.body = { data: log?.toJSON?.() || log || null };
80
- } catch (e) {
249
+ const plainLog = log?.toJSON?.() || log;
250
+ ctx.body = { data: plainLog ? { ...plainLog, hasUnifiedTrace: false } : null };
251
+ } catch (e: any) {
81
252
  ctx.log.error('[AgentOrchestrator] Tracing get error', e);
82
- ctx.body = { data: null };
253
+ ctx.throw(500, e?.message || 'Failed to load tracing log');
83
254
  }
84
255
 
85
256
  await next();
@@ -87,9 +258,5 @@ export function registerTracingResource(plugin: Plugin) {
87
258
  },
88
259
  });
89
260
 
90
- // ACL: allow admin access to tracing endpoints
91
- app.acl.registerSnippet({
92
- name: `pm.${plugin.name}.tracing`,
93
- actions: ['orchestratorTracing:list', 'orchestratorTracing:get'],
94
- });
261
+ // ACL: access is granted by the parent plugin's snippet (pm.plugin-agent-orchestrator → orchestratorTracing:*)
95
262
  }
@@ -0,0 +1,159 @@
1
+ interface ForbiddenPattern {
2
+ pattern: RegExp;
3
+ reason: string;
4
+ }
5
+
6
+ const DANGEROUS_NODE_PATTERNS: ForbiddenPattern[] = [
7
+ { pattern: /require\s*\(\s*['"]child_process['"]\s*\)/, reason: 'child_process module not allowed' },
8
+ { pattern: /require\s*\(\s*['"]cluster['"]\s*\)/, reason: 'cluster module not allowed' },
9
+ { pattern: /require\s*\(\s*['"]dgram['"]\s*\)/, reason: 'dgram module not allowed' },
10
+ { pattern: /require\s*\(\s*['"]net['"]\s*\)/, reason: 'net module not allowed' },
11
+ { pattern: /require\s*\(\s*['"]http['"]\s*\)/, reason: 'http module not allowed' },
12
+ { pattern: /require\s*\(\s*['"]https['"]\s*\)/, reason: 'https module not allowed' },
13
+ { pattern: /require\s*\(\s*['"]vm['"]\s*\)/, reason: 'vm module not allowed' },
14
+ { pattern: /process\.exit/, reason: 'process.exit not allowed' },
15
+ { pattern: /process\.env(?!\s*\.OUTPUT_DIR)/, reason: 'process.env access not allowed (use OUTPUT_DIR only)' },
16
+ { pattern: /process\.kill/, reason: 'process.kill not allowed' },
17
+ ];
18
+
19
+ const DANGEROUS_PYTHON_PATTERNS: ForbiddenPattern[] = [
20
+ { pattern: /import\s+subprocess/, reason: 'subprocess module not allowed' },
21
+ { pattern: /from\s+subprocess\s+import/, reason: 'subprocess module not allowed' },
22
+ { pattern: /import\s+shutil/, reason: 'shutil module not allowed' },
23
+ { pattern: /__import__\s*\(/, reason: '__import__ not allowed' },
24
+ { pattern: /os\.system\s*\(/, reason: 'os.system not allowed' },
25
+ { pattern: /os\.popen\s*\(/, reason: 'os.popen not allowed' },
26
+ { pattern: /os\.exec\w*\s*\(/, reason: 'os.exec* not allowed' },
27
+ { pattern: /os\.spawn\w*\s*\(/, reason: 'os.spawn* not allowed' },
28
+ { pattern: /\beval\s*\(/, reason: 'eval not allowed' },
29
+ { pattern: /\bexec\s*\(/, reason: 'exec not allowed' },
30
+ { pattern: /\bcompile\s*\(/, reason: 'compile not allowed' },
31
+ ];
32
+
33
+ /** Built-in Node.js modules that are always allowed in sandbox code */
34
+ const NODE_BUILTINS = [
35
+ 'fs', 'path', 'os', 'crypto', 'util', 'stream', 'buffer',
36
+ 'querystring', 'url', 'assert', 'events', 'string_decoder', 'zlib',
37
+ ];
38
+
39
+ /** Built-in Python modules that are always allowed in sandbox code */
40
+ const PYTHON_BUILTINS = [
41
+ 'os', 'sys', 'json', 'math', 'datetime', 'collections', 'itertools',
42
+ 'functools', 'pathlib', 'typing', 'io', 'csv', 're', 'string', 'textwrap',
43
+ 'decimal', 'fractions', 'random', 'statistics', 'copy', 'enum', 'dataclasses',
44
+ 'abc', 'contextlib', 'operator', 'time', 'calendar', 'locale', 'struct',
45
+ 'hashlib', 'base64', 'binascii', 'codecs', 'unicodedata', 'pprint',
46
+ 'warnings', 'traceback', 'logging', 'unittest', 'argparse',
47
+ 'tempfile', 'xml', 'zipfile',
48
+ // Pre-installed local packages (trusted, bundled with plugin)
49
+ 'svg_to_pptx',
50
+ ];
51
+
52
+ /**
53
+ * Maps PyPI package names to their Python import names
54
+ * (only where they differ from the package name).
55
+ */
56
+ const PYTHON_IMPORT_NAME_MAP: Record<string, string> = {
57
+ 'python-docx': 'docx',
58
+ 'python-pptx': 'pptx',
59
+ 'Pillow': 'PIL',
60
+ 'pyyaml': 'yaml',
61
+ };
62
+
63
+ export class CodeValidator {
64
+ /**
65
+ * Check code against forbidden patterns (dangerous modules/functions).
66
+ * @throws CodeValidationError if a forbidden pattern is found.
67
+ */
68
+ validate(code: string, language: 'node' | 'python'): void {
69
+ const patterns = language === 'node'
70
+ ? DANGEROUS_NODE_PATTERNS
71
+ : DANGEROUS_PYTHON_PATTERNS;
72
+
73
+ for (const { pattern, reason } of patterns) {
74
+ if (pattern.test(code)) {
75
+ throw new CodeValidationError(reason, pattern.source);
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Validate that code only imports packages in the whitelist.
82
+ * Called after the basic forbidden pattern check.
83
+ * Skips validation if whitelist is empty (env not initialized yet).
84
+ *
85
+ * @param code - The code to validate
86
+ * @param language - 'node' or 'python'
87
+ * @param whitelist - Array of allowed package names (from skillWorkerConfigs.packageWhitelist)
88
+ */
89
+ validateImports(code: string, language: 'node' | 'python', whitelist: string[]): void {
90
+ if (!whitelist?.length) return; // Skip if env not initialized
91
+
92
+ if (language === 'node') {
93
+ this.validateNodeImports(code, whitelist);
94
+ } else if (language === 'python') {
95
+ this.validatePythonImports(code, whitelist);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Check Node.js require() calls against the whitelist.
101
+ * Built-in modules (fs, path, etc.) are always allowed.
102
+ */
103
+ private validateNodeImports(code: string, whitelist: string[]): void {
104
+ // Match require statements with string literal arguments (non-relative paths)
105
+ const requires = [...code.matchAll(/require\s*\(\s*['"]([^'"./][^'"]*)['"]\s*\)/g)];
106
+
107
+ for (const match of requires) {
108
+ const raw = match[1];
109
+ // Handle scoped packages (e.g. '@org/lib') and subpaths (e.g. 'lib/utils')
110
+ const pkgName = raw.startsWith('@')
111
+ ? raw.split('/').slice(0, 2).join('/')
112
+ : raw.split('/')[0];
113
+
114
+ if (NODE_BUILTINS.includes(pkgName)) continue;
115
+ if (whitelist.includes(pkgName)) continue;
116
+
117
+ throw new CodeValidationError(
118
+ `Package "${pkgName}" is not in the allowed whitelist. Allowed: ${whitelist.join(', ')}`,
119
+ `require('${pkgName}')`,
120
+ );
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Check Python import/from statements against the whitelist.
126
+ * Built-in modules (os, sys, json, etc.) are always allowed.
127
+ * Handles PyPI→import name mapping (e.g., python-docx → docx, Pillow → PIL).
128
+ */
129
+ private validatePythonImports(code: string, whitelist: string[]): void {
130
+ // Match: import pkg, from pkg import ..., import pkg.sub
131
+ const imports = [...code.matchAll(/(?:^|\n)\s*(?:import|from)\s+([a-zA-Z_][a-zA-Z0-9_]*)/g)];
132
+
133
+ // Build allowed import names from whitelist
134
+ const allowedImports = new Set([
135
+ ...PYTHON_BUILTINS,
136
+ ...whitelist.map((p) => PYTHON_IMPORT_NAME_MAP[p] || p),
137
+ ]);
138
+
139
+ for (const match of imports) {
140
+ const pkg = match[1];
141
+ if (allowedImports.has(pkg)) continue;
142
+
143
+ throw new CodeValidationError(
144
+ `Module "${pkg}" is not in the allowed whitelist. Allowed: ${[...allowedImports].join(', ')}`,
145
+ `import ${pkg}`,
146
+ );
147
+ }
148
+ }
149
+ }
150
+
151
+ export class CodeValidationError extends Error {
152
+ constructor(
153
+ message: string,
154
+ public matchedPattern: string,
155
+ ) {
156
+ super(`Code validation failed: ${message}`);
157
+ this.name = 'CodeValidationError';
158
+ }
159
+ }
@@ -0,0 +1,106 @@
1
+ export const ORCHESTRATOR_TRACE_CONTEXT_KEY = '__orchestratorTraceContext';
2
+
3
+ export type OrchestratorTraceContext = {
4
+ rootRunId: string;
5
+ spanId?: string;
6
+ parentSpanId?: string;
7
+ toolCallId?: string;
8
+ leaderUsername?: string;
9
+ employeeUsername?: string;
10
+ toolName?: string;
11
+ };
12
+
13
+ type SpanValues = {
14
+ rootRunId: string;
15
+ parentSpanId?: string;
16
+ type: string;
17
+ status: string;
18
+ leaderUsername?: string;
19
+ employeeUsername?: string;
20
+ toolName?: string;
21
+ title?: string;
22
+ input?: any;
23
+ output?: string;
24
+ error?: string;
25
+ durationMs?: number;
26
+ startedAt?: Date;
27
+ endedAt?: Date;
28
+ orchestratorLogId?: string | number;
29
+ skillExecutionId?: string | number;
30
+ metadata?: any;
31
+ userId?: string | number;
32
+ };
33
+
34
+ function toPlain(record: any) {
35
+ return record?.toJSON?.() || record;
36
+ }
37
+
38
+ export class ExecutionSpanService {
39
+ constructor(private readonly plugin: any) {}
40
+
41
+ async create(values: SpanValues) {
42
+ try {
43
+ const repo = this.plugin.db.getRepository('agentExecutionSpans');
44
+ if (!repo) return null;
45
+
46
+ const record = await repo.create({
47
+ values: {
48
+ ...values,
49
+ startedAt: values.startedAt || new Date(),
50
+ createdAt: new Date(),
51
+ },
52
+ });
53
+ return toPlain(record);
54
+ } catch (error) {
55
+ this.plugin.app.log?.warn?.('[AgentOrchestrator] Failed to create execution span', error);
56
+ return null;
57
+ }
58
+ }
59
+
60
+ async update(spanId: string | number | undefined, values: Record<string, any>) {
61
+ if (!spanId) return null;
62
+ try {
63
+ const repo = this.plugin.db.getRepository('agentExecutionSpans');
64
+ if (!repo) return null;
65
+ await repo.update({
66
+ filterByTk: spanId,
67
+ values: {
68
+ ...values,
69
+ updatedAt: new Date(),
70
+ },
71
+ });
72
+ return { id: spanId };
73
+ } catch (error) {
74
+ this.plugin.app.log?.warn?.(`[AgentOrchestrator] Failed to update execution span ${spanId}`, error);
75
+ return null;
76
+ }
77
+ }
78
+
79
+ async finish(
80
+ spanId: string | number | undefined,
81
+ status: 'success' | 'error' | 'canceled' | 'timeout',
82
+ startedAt: number,
83
+ values: Record<string, any> = {},
84
+ ) {
85
+ return this.update(spanId, {
86
+ ...values,
87
+ status,
88
+ endedAt: new Date(),
89
+ durationMs: Date.now() - startedAt,
90
+ });
91
+ }
92
+ }
93
+
94
+ export function getOrchestratorTraceContext(ctx: any): OrchestratorTraceContext | null {
95
+ return (
96
+ ctx?.[ORCHESTRATOR_TRACE_CONTEXT_KEY] ||
97
+ ctx?.state?.orchestratorTraceContext ||
98
+ ctx?.runtime?.context?.orchestratorTraceContext ||
99
+ null
100
+ );
101
+ }
102
+
103
+ export function setOrchestratorTraceContext(ctx: any, traceContext: OrchestratorTraceContext) {
104
+ ctx[ORCHESTRATOR_TRACE_CONTEXT_KEY] = traceContext;
105
+ return ctx;
106
+ }
@@ -0,0 +1,144 @@
1
+ import { mkdirSync, readdirSync, statSync, existsSync, rmSync } from 'fs';
2
+ import { resolve, join } from 'path';
3
+
4
+ export interface OutputFileInfo {
5
+ name: string;
6
+ size: number;
7
+ mimeType: string;
8
+ }
9
+
10
+ const MIME_MAP: Record<string, string> = {
11
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
12
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
13
+ '.pdf': 'application/pdf',
14
+ '.csv': 'text/csv',
15
+ '.json': 'application/json',
16
+ '.txt': 'text/plain',
17
+ '.png': 'image/png',
18
+ '.jpg': 'image/jpeg',
19
+ '.jpeg': 'image/jpeg',
20
+ '.svg': 'image/svg+xml',
21
+ '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
22
+ '.zip': 'application/zip',
23
+ '.html': 'text/html',
24
+ '.xml': 'application/xml',
25
+ };
26
+
27
+ function getMimeType(filename: string): string {
28
+ const ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
29
+ return MIME_MAP[ext] || 'application/octet-stream';
30
+ }
31
+
32
+ export class FileManager {
33
+ private executionsDir: string;
34
+
35
+ constructor(private storagePath: string) {
36
+ this.executionsDir = resolve(storagePath, 'executions');
37
+ mkdirSync(this.executionsDir, { recursive: true });
38
+ }
39
+
40
+ createExecDir(execId: string): string {
41
+ const dir = resolve(this.executionsDir, execId);
42
+ mkdirSync(dir, { recursive: true });
43
+ mkdirSync(resolve(dir, 'output'), { recursive: true });
44
+ return dir;
45
+ }
46
+
47
+ getExecDir(execId: string): string {
48
+ return resolve(this.executionsDir, execId);
49
+ }
50
+
51
+ getOutputDir(execId: string): string {
52
+ return resolve(this.executionsDir, execId, 'output');
53
+ }
54
+
55
+ /**
56
+ * Returns absolute path to an output file, or null if invalid/not found.
57
+ * Includes path traversal protection.
58
+ */
59
+ getOutputFilePath(execId: string, filename: string): string | null {
60
+ const safeBase = resolve(this.executionsDir, execId, 'output');
61
+ const filePath = resolve(safeBase, filename);
62
+
63
+ // Path traversal protection
64
+ if (!filePath.startsWith(safeBase)) {
65
+ return null;
66
+ }
67
+ if (!existsSync(filePath)) {
68
+ return null;
69
+ }
70
+ return filePath;
71
+ }
72
+
73
+ listOutputFiles(execId: string): OutputFileInfo[] {
74
+ const outputDir = this.getOutputDir(execId);
75
+ if (!existsSync(outputDir)) return [];
76
+
77
+ try {
78
+ return readdirSync(outputDir)
79
+ .filter((name) => {
80
+ const filePath = join(outputDir, name);
81
+ return statSync(filePath).isFile();
82
+ })
83
+ .map((name) => {
84
+ const filePath = join(outputDir, name);
85
+ const stat = statSync(filePath);
86
+ return {
87
+ name,
88
+ size: stat.size,
89
+ mimeType: getMimeType(name),
90
+ };
91
+ });
92
+ } catch {
93
+ return [];
94
+ }
95
+ }
96
+
97
+ getTotalOutputSize(execId: string): number {
98
+ const files = this.listOutputFiles(execId);
99
+ return files.reduce((sum, f) => sum + f.size, 0);
100
+ }
101
+
102
+ /**
103
+ * Remove a specific execution directory by execId.
104
+ */
105
+ removeExecDir(execId: string): void {
106
+ const dirPath = resolve(this.executionsDir, execId);
107
+ if (existsSync(dirPath)) {
108
+ try {
109
+ rmSync(dirPath, { recursive: true, force: true });
110
+ } catch {
111
+ // Skip errors
112
+ }
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Remove execution directories older than maxAgeMs.
118
+ */
119
+ cleanupOlderThan(maxAgeMs: number): number {
120
+ if (!existsSync(this.executionsDir)) return 0;
121
+
122
+ let cleaned = 0;
123
+ const now = Date.now();
124
+
125
+ try {
126
+ for (const dir of readdirSync(this.executionsDir)) {
127
+ const dirPath = resolve(this.executionsDir, dir);
128
+ try {
129
+ const stat = statSync(dirPath);
130
+ if (stat.isDirectory() && now - stat.mtimeMs > maxAgeMs) {
131
+ rmSync(dirPath, { recursive: true, force: true });
132
+ cleaned++;
133
+ }
134
+ } catch {
135
+ // Skip individual dir errors
136
+ }
137
+ }
138
+ } catch {
139
+ // Skip if executionsDir not accessible
140
+ }
141
+
142
+ return cleaned;
143
+ }
144
+ }