plugin-agent-orchestrator 1.1.8 → 1.2.1
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/LICENSE +201 -0
- package/README.md +207 -204
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/117.6c69b6a87751dd18.js +10 -0
- package/dist/client/253.52f62e1bc0e9520a.js +10 -0
- package/dist/client/325.8f7f509bdb35e142.js +10 -0
- package/dist/client/404.86593f98c9768ed5.js +10 -0
- package/dist/client/453.fa2d169576262213.js +10 -0
- package/dist/client/53.567db3ae078650c6.js +10 -0
- package/dist/client/619.01713281e5e951d3.js +10 -0
- package/dist/client/652.69da1598312b3a3f.js +10 -0
- package/dist/client/773.648965568ff476f9.js +10 -0
- package/dist/client/981.37e7aeecdb1ef6fa.js +10 -0
- package/dist/client/993.ac89f3852990918d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/117.c982d79ff68738f5.js +10 -0
- package/dist/client-v2/214.94c4257bf2838577.js +10 -0
- package/dist/client-v2/253.8e19956d2a44dfb8.js +10 -0
- package/dist/client-v2/264.80e8e358c8c6c2e5.js +10 -0
- package/dist/client-v2/325.fafe5a6e83ba9cb3.js +10 -0
- package/dist/client-v2/404.ab032b79c95dab6f.js +10 -0
- package/dist/client-v2/{41.3deb9e57a0f64fc4.js → 41.cd5610fcf7446127.js} +1 -1
- package/dist/client-v2/453.42c6d70628d56cc2.js +10 -0
- package/dist/client-v2/{53.349fff8db80b19d4.js → 53.37c08089a648f89a.js} +1 -1
- package/dist/client-v2/{619.0a2144aaffefe018.js → 619.6e9618550101e819.js} +1 -1
- package/dist/client-v2/652.eeba4e0c38367321.js +10 -0
- package/dist/client-v2/{70.ffff2997c10fd4b0.js → 70.332698e53eb59677.js} +1 -1
- package/dist/client-v2/773.4de2ba5acb07318c.js +10 -0
- package/dist/client-v2/981.76060f466e6f7c11.js +10 -0
- package/dist/client-v2/993.f8cdb5172566ce75.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +13 -7
- package/dist/locale/en-US.json +308 -1
- package/dist/locale/vi-VN.json +5 -1
- package/dist/locale/zh-CN.json +308 -1
- package/dist/node_modules/acorn/LICENSE +21 -0
- package/dist/node_modules/acorn/bin/acorn +4 -0
- package/dist/node_modules/acorn/dist/acorn.d.mts +857 -0
- package/dist/node_modules/acorn/dist/acorn.d.ts +857 -0
- package/dist/node_modules/acorn/dist/acorn.js +1 -0
- package/dist/node_modules/acorn/dist/bin.js +90 -0
- package/dist/node_modules/acorn/package.json +1 -0
- package/dist/node_modules/acorn-walk/LICENSE +21 -0
- package/dist/node_modules/acorn-walk/dist/walk.d.mts +177 -0
- package/dist/node_modules/acorn-walk/dist/walk.d.ts +177 -0
- package/dist/node_modules/acorn-walk/dist/walk.js +1 -0
- package/dist/node_modules/acorn-walk/node_modules/.bin/acorn +15 -0
- package/dist/node_modules/acorn-walk/node_modules/.bin/acorn.cmd +7 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/bin/acorn +4 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.mts +866 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.ts +866 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.js +6174 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/bin.js +90 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/package.json +50 -0
- package/dist/node_modules/acorn-walk/package.json +1 -0
- package/dist/node_modules/adm-zip/adm-zip.js +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/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/collections/agent-auto-approval-checkpoints.js +47 -0
- package/dist/server/collections/agent-execution-spans.js +148 -9
- package/dist/server/collections/agent-governance-audit-events.js +47 -0
- package/dist/server/collections/agent-governance-policies.js +47 -0
- package/dist/server/collections/agent-governance-policy-versions.js +48 -0
- package/dist/server/collections/agent-governance-prompt-bindings.js +50 -0
- package/dist/server/collections/agent-hierarchy-invocations.js +59 -0
- package/dist/server/collections/agent-loop-runs.js +23 -5
- package/dist/server/collections/agent-routing-graph-locks.js +40 -0
- package/dist/server/collections/agent-session-auto-approvals.js +45 -0
- package/dist/server/collections/orchestrator-config.js +17 -0
- package/dist/server/migrations/20261110000000-add-usage-pricing-snapshots.js +117 -0
- package/dist/server/migrations/20261110010000-add-usage-department-attribution.js +54 -0
- package/dist/server/migrations/20261119000000-widen-native-employee-identifiers.js +59 -0
- package/dist/server/plugin.js +169 -33
- package/dist/server/resources/agent-auto-approval.js +80 -0
- package/dist/server/resources/agent-governance.js +192 -0
- package/dist/server/resources/agent-harness-profile.js +11 -3
- package/dist/server/resources/agent-monitor.js +109 -339
- package/dist/server/resources/agent-usage.js +423 -0
- package/dist/server/resources/hierarchical-routing.js +60 -0
- package/dist/server/resources/native-monitor-format.js +179 -0
- package/dist/server/resources/tracing.js +35 -12
- package/dist/server/services/AgentGovernanceService.js +500 -0
- package/dist/server/services/AutoApprovalCheckpoint.js +133 -0
- package/dist/server/services/CodeValidator.js +8 -4
- package/dist/server/services/DepartmentAttribution.js +65 -0
- package/dist/server/services/ExecutionSpanService.js +96 -3
- package/dist/server/services/GovernanceAdmission.js +271 -0
- package/dist/server/services/HarnessCapabilities.js +118 -0
- package/dist/server/services/HarnessCompiler.js +3 -0
- package/dist/server/services/HarnessSchema.js +13 -1
- package/dist/server/services/HierarchicalAgentRuntime.js +925 -0
- package/dist/server/services/HierarchyEnrollmentGuard.js +216 -0
- package/dist/server/services/HierarchyInvocationJournal.js +157 -0
- package/dist/server/services/HierarchyRequestCancellation.js +150 -0
- package/dist/server/services/LoopBudgetService.js +29 -11
- package/dist/server/services/LoopRunRepository.js +16 -7
- package/dist/server/services/LoopRunStateMachine.js +20 -9
- package/dist/server/services/LoopTriggerService.js +1 -1
- package/dist/server/services/LoopWorkerService.js +71 -37
- package/dist/server/services/ManagedPromptProtection.js +99 -0
- package/dist/server/services/NativeAgentMonitorSyncService.js +584 -0
- package/dist/server/services/NativeSubAgentObserver.js +141 -508
- package/dist/server/services/NativeUsageAttribution.js +97 -0
- package/dist/server/services/PluginAiRuntimeAdapter.js +107 -9
- package/dist/server/services/RoutingBindingRepository.js +156 -0
- package/dist/server/services/RoutingBindingValidation.js +161 -0
- package/dist/server/services/SandboxRunner.js +19 -0
- package/dist/server/services/SessionAutoApproval.js +173 -0
- package/dist/server/services/TokenTracker.js +787 -104
- package/dist/server/services/TracingRetentionPolicy.js +66 -0
- package/dist/server/services/VerificationService.js +20 -10
- package/dist/server/skill-hub/plugin.js +17 -0
- package/dist/server/skill-hub/sandbox-config.json +6 -6
- package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +2 -2
- package/dist/server/skill-hub/services/registry-node-package.js +191 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +21 -6
- package/dist/server/tools/skill-execute.js +1 -0
- package/dist/server/utils/ensure-indexes.js +15 -5
- package/package.json +66 -53
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/AgentRunsTab.tsx +2 -2
- package/src/client/ApprovalsTab.tsx +2 -2
- package/src/client/HarnessProfilesTab.tsx +2 -2
- package/src/client/OrchestratorSettings.tsx +152 -152
- package/src/client/SkillPages.tsx +34 -0
- package/src/client/__tests__/embedded-settings.test.tsx +225 -0
- package/src/client/hooks/useRunEventStream.ts +76 -76
- package/src/client/index.tsx +2 -2
- package/src/client/plugin.tsx +71 -33
- package/src/client/skill-hub/components/ExecutionHistory.tsx +200 -200
- package/src/client/skill-hub/components/GitSkillImport.tsx +562 -562
- package/src/client/skill-hub/components/LoopSettings.tsx +331 -331
- package/src/client/skill-hub/components/SkillEditor.tsx +460 -460
- package/src/client/skill-hub/components/SkillManager.tsx +194 -194
- package/src/client/skill-hub/components/SkillMetrics.tsx +162 -162
- package/src/client/skill-hub/components/SkillTestPanel.tsx +141 -141
- package/src/client/skill-hub/index.tsx +6 -6
- package/src/client/skill-hub/locale.ts +16 -16
- package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +147 -132
- package/src/client/skill-hub/tools/SkillHubCard.tsx +110 -104
- package/src/client/skill-hub/tools/__tests__/skill-hub-card.test.tsx +255 -0
- package/src/client/skill-hub/tools/loopTemplates.ts +52 -52
- package/src/client/skill-hub/tools/registerSkillLoopCards.ts +80 -71
- package/src/client/skill-hub/utils/jsonFields.ts +41 -41
- package/src/client-v2/__tests__/embedded-settings.test.tsx +202 -0
- package/src/client-v2/__tests__/hierarchical-routing-settings.test.tsx +350 -0
- package/src/client-v2/auto-approval/AutoApprovalBridge.tsx +513 -0
- package/src/client-v2/auto-approval/AutoApprovalProvider.tsx +399 -0
- package/src/client-v2/auto-approval/__tests__/session-auto-approval.test.tsx +1676 -0
- package/src/client-v2/components/AIEmployeeSelect.tsx +47 -47
- package/src/client-v2/components/AIEmployeesContext.tsx +97 -97
- package/src/client-v2/components/AgentBindingsTab.tsx +541 -269
- package/src/client-v2/components/AgentRunsTab.tsx +85 -83
- package/src/client-v2/components/ApprovalsTab.tsx +337 -337
- package/src/client-v2/components/EmployeeGovernanceTab.tsx +695 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +700 -541
- package/src/client-v2/components/HarnessSettingsForm.tsx +221 -0
- package/src/client-v2/components/KnowledgeAccessTab.tsx +116 -116
- package/src/client-v2/components/RetrievalTraceTab.tsx +162 -162
- package/src/client-v2/components/UsageGovernanceTab.tsx +379 -0
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/pages/AgentBindingsPage.tsx +15 -13
- package/src/client-v2/pages/ApprovalsPage.tsx +12 -10
- package/src/client-v2/pages/EmployeeGovernancePage.tsx +15 -0
- package/src/client-v2/pages/ExecutionHistoryPage.tsx +12 -10
- package/src/client-v2/pages/HarnessProfilesPage.tsx +12 -10
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +12 -10
- package/src/client-v2/pages/LoopSettingsPage.tsx +12 -10
- package/src/client-v2/pages/MemoryInspectorPage.tsx +15 -13
- package/src/client-v2/pages/RetrievalTracePage.tsx +12 -10
- package/src/client-v2/pages/RulesPage.tsx +15 -13
- package/src/client-v2/pages/SkillDefinitionsPage.tsx +12 -10
- package/src/client-v2/pages/SkillMetricsPage.tsx +12 -10
- package/src/client-v2/pages/TracingPage.tsx +15 -13
- package/src/client-v2/pages/UsageGovernancePage.tsx +15 -0
- package/src/client-v2/plugin.tsx +134 -111
- package/src/client-v2/skill-hub/components/ExecutionHistory.tsx +196 -196
- package/src/client-v2/skill-hub/components/FileLinkList.tsx +37 -37
- package/src/client-v2/skill-hub/components/GitSkillImport.tsx +539 -539
- package/src/client-v2/skill-hub/components/LoopSettings.tsx +331 -331
- package/src/client-v2/skill-hub/components/SkillEditor.tsx +453 -453
- package/src/client-v2/skill-hub/components/SkillManager.tsx +191 -174
- package/src/client-v2/skill-hub/components/SkillMetrics.tsx +162 -162
- package/src/client-v2/skill-hub/components/SkillTestPanel.tsx +135 -135
- package/src/client-v2/skill-hub/locale.ts +13 -13
- package/src/client-v2/skill-hub/tools/InteractionSchemasProvider.tsx +62 -0
- package/src/client-v2/skill-hub/tools/SkillHubCard.tsx +104 -0
- package/src/client-v2/skill-hub/tools/__tests__/interactions.test.ts +126 -0
- package/src/client-v2/skill-hub/tools/interactions.ts +137 -0
- package/src/client-v2/skill-hub/tools/loopTemplates.ts +52 -52
- package/src/client-v2/skill-hub/utils/jsonFields.ts +41 -41
- package/src/client-v2/utils/jsonFields.ts +41 -41
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +308 -1
- package/src/locale/vi-VN.json +5 -1
- package/src/locale/zh-CN.json +308 -1
- package/src/server/__tests__/agent-execution-context.test.ts +18 -18
- package/src/server/__tests__/agent-governance.integration.test.ts +385 -0
- package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -123
- package/src/server/__tests__/agent-monitor-acl.integration.test.ts +267 -0
- package/src/server/__tests__/agent-registry-service.test.ts +147 -147
- package/src/server/__tests__/agent-runtime-lifecycle.test.ts +46 -46
- package/src/server/__tests__/agent-usage-report.integration.test.ts +335 -0
- package/src/server/__tests__/auto-approval-checkpoint.integration.test.ts +295 -0
- package/src/server/__tests__/code-validator.test.ts +63 -63
- package/src/server/__tests__/external-rag-search.test.ts +107 -107
- package/src/server/__tests__/harness-capabilities.test.ts +88 -0
- package/src/server/__tests__/harness-compiler.test.ts +278 -214
- package/src/server/__tests__/harness-profile-service.test.ts +167 -167
- package/src/server/__tests__/harness-runtime-policy.test.ts +293 -293
- package/src/server/__tests__/harness-tool-plan.test.ts +175 -172
- package/src/server/__tests__/hierarchical-routing.integration.test.ts +2318 -0
- package/src/server/__tests__/hierarchy-invocation-journal.integration.test.ts +119 -0
- package/src/server/__tests__/input-schema-validator.test.ts +26 -26
- package/src/server/__tests__/loop-approval-decision.test.ts +624 -512
- package/src/server/__tests__/loop-approval-expiry.test.ts +258 -258
- package/src/server/__tests__/loop-budget-service.test.ts +29 -0
- package/src/server/__tests__/loop-pattern-schema.test.ts +73 -73
- package/src/server/__tests__/loop-run-repository.test.ts +25 -0
- package/src/server/__tests__/loop-run-state-machine.test.ts +101 -101
- package/src/server/__tests__/loop-trigger-service.test.ts +185 -148
- package/src/server/__tests__/loop-worker-claim.test.ts +110 -10
- package/src/server/__tests__/loop-worker-execution.test.ts +375 -317
- package/src/server/__tests__/native-agent-monitor-sync.test.ts +343 -0
- package/src/server/__tests__/native-hierarchy-probe.integration.test.ts +527 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +463 -662
- package/src/server/__tests__/native-usage-attribution.integration.test.ts +168 -0
- package/src/server/__tests__/plugin-ai-runtime-adapter.test.ts +403 -0
- package/src/server/__tests__/registry-node-package.test.ts +299 -0
- package/src/server/__tests__/routing-binding-graph.integration.test.ts +217 -0
- package/src/server/__tests__/routing-binding-validation.test.ts +256 -0
- package/src/server/__tests__/session-auto-approval.integration.test.ts +329 -0
- package/src/server/__tests__/skill-access-service.test.ts +64 -64
- package/src/server/__tests__/skill-execute.test.ts +81 -70
- package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -140
- package/src/server/__tests__/skill-review-guard.test.ts +171 -0
- package/src/server/__tests__/skill-sandbox-worker-mode.test.ts +15 -15
- package/src/server/__tests__/skill-settings.test.ts +63 -63
- package/src/server/__tests__/skill-tool-name.test.ts +23 -23
- package/src/server/__tests__/token-tracker.test.ts +632 -0
- package/src/server/__tests__/tool-loop-detection.test.ts +276 -276
- package/src/server/__tests__/tracing-retention-policy.test.ts +30 -0
- package/src/server/__tests__/usage-ledger.integration.test.ts +187 -0
- package/src/server/collections/agent-auto-approval-checkpoints.ts +18 -0
- package/src/server/collections/agent-execution-spans.ts +386 -245
- package/src/server/collections/agent-governance-audit-events.ts +19 -0
- package/src/server/collections/agent-governance-policies.ts +19 -0
- package/src/server/collections/agent-governance-policy-versions.ts +20 -0
- package/src/server/collections/agent-governance-prompt-bindings.ts +22 -0
- package/src/server/collections/agent-hierarchy-invocations.ts +30 -0
- package/src/server/collections/agent-loop-action-approvals.ts +39 -39
- package/src/server/collections/agent-loop-runs.ts +389 -369
- package/src/server/collections/agent-loop-steps.ts +220 -220
- package/src/server/collections/agent-memory-contexts.ts +95 -95
- package/src/server/collections/agent-routing-graph-locks.ts +11 -0
- package/src/server/collections/agent-session-auto-approvals.ts +16 -0
- package/src/server/collections/orchestrator-config.ts +113 -87
- package/src/server/collections/orchestrator-logs.ts +116 -116
- package/src/server/collections/skill-definitions.ts +159 -159
- package/src/server/collections/skill-executions.ts +154 -154
- package/src/server/collections/skill-loop-configs.ts +65 -65
- package/src/server/collections/skill-metrics.ts +36 -36
- package/src/server/collections/skill-registry-installations.ts +41 -41
- package/src/server/collections/skill-worker-configs.ts +86 -86
- package/src/server/index.ts +1 -1
- package/src/server/migrations/20260423000000-add-progress-fields.ts +50 -50
- package/src/server/migrations/20260425000000-add-interaction-schema.ts +37 -37
- package/src/server/migrations/20260427000000-add-tracing-detail-fields.ts +41 -41
- package/src/server/migrations/20260427000001-change-other-json-to-text.ts +61 -61
- package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +145 -145
- package/src/server/migrations/20260601000000-add-token-fields.ts +89 -89
- package/src/server/migrations/20260615000000-normalize-ai-employee-tool-bindings.ts +39 -39
- package/src/server/migrations/20260621000000-native-policy-profile-defaults.ts +190 -190
- package/src/server/migrations/20260727000000-remove-unused-knowledge-scopes.ts +25 -25
- package/src/server/migrations/20260727010000-backfill-skill-tool-names.ts +45 -45
- package/src/server/migrations/20261110000000-add-usage-pricing-snapshots.ts +110 -0
- package/src/server/migrations/20261110010000-add-usage-department-attribution.ts +28 -0
- package/src/server/migrations/20261119000000-widen-native-employee-identifiers.ts +37 -0
- package/src/server/plugin.ts +724 -573
- package/src/server/resources/agent-auto-approval.ts +51 -0
- package/src/server/resources/agent-governance.ts +161 -0
- package/src/server/resources/agent-harness-profile.ts +103 -94
- package/src/server/resources/agent-knowledge-insights.ts +306 -306
- package/src/server/resources/agent-loop-approval.ts +84 -84
- package/src/server/resources/agent-loop-events-stream.ts +108 -108
- package/src/server/resources/agent-loop.ts +252 -252
- package/src/server/resources/agent-monitor.ts +208 -482
- package/src/server/resources/agent-usage.ts +413 -0
- package/src/server/resources/hierarchical-routing.ts +39 -0
- package/src/server/resources/native-monitor-format.ts +150 -0
- package/src/server/resources/tracing.ts +296 -267
- package/src/server/services/AgentExecutionContext.ts +23 -23
- package/src/server/services/AgentGovernanceService.ts +541 -0
- package/src/server/services/AgentMemoryContextService.ts +344 -344
- package/src/server/services/AgentRegistryService.ts +220 -220
- package/src/server/services/AgentRuntimeLifecycle.ts +64 -64
- package/src/server/services/AutoApprovalCheckpoint.ts +140 -0
- package/src/server/services/CodeValidator.ts +257 -238
- package/src/server/services/DepartmentAttribution.ts +47 -0
- package/src/server/services/DurableCircuitBreakerService.ts +235 -235
- package/src/server/services/ExecutionSpanService.ts +271 -146
- package/src/server/services/FileManager.ts +159 -159
- package/src/server/services/GovernanceAdmission.ts +314 -0
- package/src/server/services/HarnessCapabilities.ts +112 -0
- package/src/server/services/HarnessCompiler.ts +182 -170
- package/src/server/services/HarnessProfileService.ts +235 -235
- package/src/server/services/HarnessSchema.ts +224 -194
- package/src/server/services/HierarchicalAgentRuntime.ts +1052 -0
- package/src/server/services/HierarchyEnrollmentGuard.ts +211 -0
- package/src/server/services/HierarchyInvocationJournal.ts +172 -0
- package/src/server/services/HierarchyRequestCancellation.ts +132 -0
- package/src/server/services/InputSchemaValidator.ts +44 -44
- package/src/server/services/LoopBudgetService.ts +325 -271
- package/src/server/services/LoopControlService.ts +120 -120
- package/src/server/services/LoopPatternSchema.ts +231 -231
- package/src/server/services/LoopPatternService.ts +171 -171
- package/src/server/services/LoopRunRepository.ts +343 -332
- package/src/server/services/LoopRunStateMachine.ts +538 -525
- package/src/server/services/LoopSchedulerService.ts +195 -195
- package/src/server/services/LoopTriggerService.ts +162 -159
- package/src/server/services/LoopWorkerService.ts +975 -912
- package/src/server/services/ManagedPromptProtection.ts +81 -0
- package/src/server/services/NativeAgentMonitorSyncService.ts +684 -0
- package/src/server/services/NativeSubAgentObserver.ts +324 -757
- package/src/server/services/NativeUsageAttribution.ts +91 -0
- package/src/server/services/PathLockService.ts +317 -317
- package/src/server/services/PluginAiRuntimeAdapter.ts +518 -387
- package/src/server/services/RoutingBindingRepository.ts +146 -0
- package/src/server/services/RoutingBindingValidation.ts +161 -0
- package/src/server/services/RunEventBus.ts +58 -58
- package/src/server/services/SandboxRunner.ts +526 -492
- package/src/server/services/SessionAutoApproval.ts +167 -0
- package/src/server/services/SkillAccessService.ts +175 -175
- package/src/server/services/SkillManager.ts +585 -585
- package/src/server/services/SkillRepositoryService.ts +236 -236
- package/src/server/services/TokenTracker.ts +1151 -287
- package/src/server/services/ToolLoopDetectionService.ts +210 -210
- package/src/server/services/TracingRetentionPolicy.ts +49 -0
- package/src/server/services/VerificationSchema.ts +31 -31
- package/src/server/services/VerificationService.ts +325 -313
- package/src/server/services/WorkerEnvManager.ts +198 -198
- package/src/server/services/__tests__/SkillRepositoryService.test.ts +33 -33
- package/src/server/services/harness-runtime-policy.ts +134 -134
- package/src/server/services/pythonGuardTemplate.ts +87 -87
- package/src/server/services/sandboxCapabilities.ts +348 -348
- package/src/server/skill-hub/actions/__tests__/git-import.test.ts +563 -563
- package/src/server/skill-hub/actions/git-import.ts +936 -936
- package/src/server/skill-hub/mcp/McpController.ts +107 -107
- package/src/server/skill-hub/middlewares/git-import-request-method-policy.ts +51 -51
- package/src/server/skill-hub/plugin.ts +1272 -1232
- package/src/server/skill-hub/sandbox-config.json +6 -6
- package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +291 -281
- package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -295
- package/src/server/skill-hub/services/registry-node-package.ts +191 -0
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +597 -568
- package/src/server/skill-hub/utils/json-fields.ts +57 -57
- package/src/server/tools/delegate-task.ts +30 -30
- package/src/server/tools/external-rag-search.ts +329 -329
- package/src/server/tools/skill-execute.ts +226 -216
- package/src/server/types.ts +21 -21
- package/src/server/utils/ai-manager.ts +24 -24
- package/src/server/utils/ctx-utils.ts +132 -132
- package/src/server/utils/ensure-indexes.ts +113 -96
- package/src/server/utils/ha-lock.ts +80 -80
- package/src/server/utils/loop-pattern-context.ts +84 -84
- package/src/server/utils/record-utils.ts +19 -19
- package/src/server/utils/skill-settings.ts +135 -135
- package/src/server/utils/skill-tool-name.ts +58 -58
- package/dist/client-v2/117.7565cff57c39318a.js +0 -10
- package/dist/client-v2/214.106635011859dede.js +0 -10
- package/dist/client-v2/253.59577b40d9875be0.js +0 -10
- package/dist/client-v2/264.7ed8bee71fa5935c.js +0 -10
- package/dist/client-v2/418.41ed200e7d6da332.js +0 -10
- package/dist/client-v2/794.a67a2614405ba627.js +0 -10
- package/dist/client-v2/981.e4a1f41cfc94a856.js +0 -10
- package/dist/client-v2/993.b0688fdc5ccb000a.js +0 -10
- package/dist/node_modules/simple-git/dist/cjs/index.js +0 -7399
- package/dist/node_modules/simple-git/dist/esm/index.js +0 -4745
- package/dist/node_modules/simple-git/dist/esm/package.json +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/api.d.ts +0 -13
- package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-construct-error.d.ts +0 -15
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-error.d.ts +0 -30
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +0 -7
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-response-error.d.ts +0 -32
- package/dist/node_modules/simple-git/dist/src/lib/errors/task-configuration-error.d.ts +0 -12
- package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +0 -15
- package/dist/node_modules/simple-git/dist/src/lib/git-logger.d.ts +0 -21
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch-delete.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-commit.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-fetch.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-list-log-summary.d.ts +0 -6
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-merge.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-move.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-pull.d.ts +0 -6
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-push.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-messages.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-objects.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/command-config-prefixing-plugin.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/plugins/completion-detection.plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/error-detection.plugin.d.ts +0 -7
- package/dist/node_modules/simple-git/dist/src/lib/plugins/index.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/plugins/progress-monitor-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/simple-git-plugin.d.ts +0 -48
- package/dist/node_modules/simple-git/dist/src/lib/plugins/spawn-options-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchDeleteSummary.d.ts +0 -12
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +0 -14
- package/dist/node_modules/simple-git/dist/src/lib/responses/CheckIgnore.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/responses/CleanSummary.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/responses/ConfigList.d.ts +0 -13
- package/dist/node_modules/simple-git/dist/src/lib/responses/DiffSummary.d.ts +0 -10
- package/dist/node_modules/simple-git/dist/src/lib/responses/FileStatusSummary.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/responses/GetRemoteSummary.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/responses/InitSummary.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/responses/MergeSummary.d.ts +0 -16
- package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +0 -25
- package/dist/node_modules/simple-git/dist/src/lib/responses/StatusSummary.d.ts +0 -19
- package/dist/node_modules/simple-git/dist/src/lib/responses/TagList.d.ts +0 -7
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor-chain.d.ts +0 -25
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor.d.ts +0 -14
- package/dist/node_modules/simple-git/dist/src/lib/runners/promise-wrapped.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/runners/scheduler.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/runners/tasks-pending-queue.d.ts +0 -23
- package/dist/node_modules/simple-git/dist/src/lib/simple-git-api.d.ts +0 -20
- package/dist/node_modules/simple-git/dist/src/lib/task-callback.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/branch.d.ts +0 -7
- package/dist/node_modules/simple-git/dist/src/lib/tasks/change-working-directory.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-ignore.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-is-repo.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts +0 -25
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/config.d.ts +0 -8
- package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +0 -12
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +0 -12
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/tasks/fetch.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/grep.d.ts +0 -12
- package/dist/node_modules/simple-git/dist/src/lib/tasks/hash-object.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/tasks/init.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/log.d.ts +0 -32
- package/dist/node_modules/simple-git/dist/src/lib/tasks/merge.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/move.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/pull.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/push.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/tasks/remote.d.ts +0 -8
- package/dist/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts +0 -11
- package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +0 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/status.d.ts +0 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/sub-module.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/tasks/tag.d.ts +0 -18
- package/dist/node_modules/simple-git/dist/src/lib/tasks/task.d.ts +0 -14
- package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +0 -9
- package/dist/node_modules/simple-git/dist/src/lib/types/handlers.d.ts +0 -21
- package/dist/node_modules/simple-git/dist/src/lib/types/index.d.ts +0 -136
- package/dist/node_modules/simple-git/dist/src/lib/types/tasks.d.ts +0 -19
- package/dist/node_modules/simple-git/dist/src/lib/utils/argument-filters.d.ts +0 -14
- package/dist/node_modules/simple-git/dist/src/lib/utils/exit-codes.d.ts +0 -10
- package/dist/node_modules/simple-git/dist/src/lib/utils/git-output-streams.d.ts +0 -7
- package/dist/node_modules/simple-git/dist/src/lib/utils/index.d.ts +0 -8
- package/dist/node_modules/simple-git/dist/src/lib/utils/line-parser.d.ts +0 -15
- package/dist/node_modules/simple-git/dist/src/lib/utils/simple-git-options.d.ts +0 -2
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-options.d.ts +0 -13
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-parser.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/src/lib/utils/util.d.ts +0 -47
- package/dist/node_modules/simple-git/dist/typings/errors.d.ts +0 -5
- package/dist/node_modules/simple-git/dist/typings/index.d.ts +0 -14
- package/dist/node_modules/simple-git/dist/typings/response.d.ts +0 -556
- package/dist/node_modules/simple-git/dist/typings/simple-git.d.ts +0 -1033
- package/dist/node_modules/simple-git/dist/typings/types.d.ts +0 -22
- package/dist/node_modules/simple-git/node_modules/debug/package.json +0 -64
- package/dist/node_modules/simple-git/node_modules/debug/src/browser.js +0 -272
- package/dist/node_modules/simple-git/node_modules/debug/src/common.js +0 -292
- package/dist/node_modules/simple-git/node_modules/debug/src/index.js +0 -10
- package/dist/node_modules/simple-git/node_modules/debug/src/node.js +0 -263
- package/dist/node_modules/simple-git/package.json +0 -1
- package/dist/node_modules/simple-git/promise.js +0 -17
|
@@ -0,0 +1,133 @@
|
|
|
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 AutoApprovalCheckpoint_exports = {};
|
|
28
|
+
__export(AutoApprovalCheckpoint_exports, {
|
|
29
|
+
autoApprovalCheckpoint: () => autoApprovalCheckpoint,
|
|
30
|
+
coordinateAutoApprovalDecision: () => coordinateAutoApprovalDecision,
|
|
31
|
+
enrollAutoApprovalCheckpoint: () => enrollAutoApprovalCheckpoint
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(AutoApprovalCheckpoint_exports);
|
|
34
|
+
var import_node_crypto = require("node:crypto");
|
|
35
|
+
var import_record_utils = require("../utils/record-utils");
|
|
36
|
+
async function autoApprovalCheckpoint(ctx, call) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const ownerId = Number((_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id);
|
|
39
|
+
if (!Number.isSafeInteger(ownerId) || ownerId <= 0) return void 0;
|
|
40
|
+
const conversation = await ctx.db.getRepository("aiConversations").findOne({
|
|
41
|
+
filter: { sessionId: call.sessionId, userId: ownerId }
|
|
42
|
+
});
|
|
43
|
+
if (!conversation || (0, import_record_utils.read)(conversation, "from") === "sub-agent") return void 0;
|
|
44
|
+
const username = (0, import_record_utils.read)(conversation, "aiEmployeeUsername");
|
|
45
|
+
if (typeof username !== "string" || !username) return void 0;
|
|
46
|
+
const message = await ctx.db.getRepository("aiMessages").findOne({
|
|
47
|
+
filter: { sessionId: call.sessionId, messageId: call.messageId, role: username }
|
|
48
|
+
});
|
|
49
|
+
const calls = (0, import_record_utils.read)(message, "toolCalls");
|
|
50
|
+
if (!Array.isArray(calls) || !calls.length) return void 0;
|
|
51
|
+
const callIds = calls.map((item) => (0, import_record_utils.asRecord)(item).id);
|
|
52
|
+
if (call.messageId.length > 100 || callIds.some((id) => typeof id !== "string" || !id) || new Set(callIds).size !== callIds.length || !callIds.includes(call.toolCallId))
|
|
53
|
+
return void 0;
|
|
54
|
+
const interruptId = (0, import_record_utils.asRecord)((0, import_record_utils.read)(message, "metadata")).interruptId;
|
|
55
|
+
if (typeof interruptId !== "string" || !interruptId) return void 0;
|
|
56
|
+
if (callIds.length === 1) return null;
|
|
57
|
+
const checkpointKey = (0, import_node_crypto.createHash)("sha256").update(JSON.stringify([ownerId, call.sessionId, call.messageId, interruptId])).digest("hex");
|
|
58
|
+
return {
|
|
59
|
+
checkpointKey,
|
|
60
|
+
ownerId,
|
|
61
|
+
sessionId: call.sessionId,
|
|
62
|
+
messageId: call.messageId,
|
|
63
|
+
interruptId,
|
|
64
|
+
callIds
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function enrollAutoApprovalCheckpoint(ctx, checkpoint) {
|
|
68
|
+
const model = ctx.db.getModel("agentAutoApprovalCheckpoints");
|
|
69
|
+
const where = { checkpointKey: checkpoint.checkpointKey };
|
|
70
|
+
if (await model.findOne({ where })) return;
|
|
71
|
+
try {
|
|
72
|
+
await model.create({
|
|
73
|
+
...where,
|
|
74
|
+
ownerId: checkpoint.ownerId,
|
|
75
|
+
sessionId: checkpoint.sessionId,
|
|
76
|
+
messageId: checkpoint.messageId,
|
|
77
|
+
interruptId: checkpoint.interruptId,
|
|
78
|
+
status: "pending"
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (!(error instanceof Error) || error.name !== "SequelizeUniqueConstraintError") throw error;
|
|
82
|
+
if (!await model.findOne({ where })) throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function coordinateAutoApprovalDecision(ctx, checkpoint, call) {
|
|
86
|
+
const model = ctx.db.getModel("agentAutoApprovalCheckpoints");
|
|
87
|
+
const where = { checkpointKey: checkpoint.checkpointKey, ownerId: checkpoint.ownerId };
|
|
88
|
+
if (!await model.findOne({ where })) return;
|
|
89
|
+
const body = (0, import_record_utils.asRecord)(ctx.body);
|
|
90
|
+
const originalUpdated = body.updated;
|
|
91
|
+
const calls = Array.isArray(body.toolCalls) ? body.toolCalls.map(import_record_utils.asRecord) : [];
|
|
92
|
+
const ids = calls.map((item) => item.id);
|
|
93
|
+
const validSnapshot = calls.length === checkpoint.callIds.length && ids.every((id) => typeof id === "string" && checkpoint.callIds.includes(id)) && new Set(ids).size === ids.length && calls.every((item) => typeof item.willInterrupt === "boolean");
|
|
94
|
+
const current = await autoApprovalCheckpoint(ctx, call);
|
|
95
|
+
let sameCheckpoint = (current == null ? void 0 : current.checkpointKey) === checkpoint.checkpointKey && current.callIds.length === checkpoint.callIds.length && current.callIds.every((id) => checkpoint.callIds.includes(id));
|
|
96
|
+
const interruptedCalls = calls.filter((item) => item.willInterrupt === true);
|
|
97
|
+
const ready = validSnapshot && sameCheckpoint && interruptedCalls.some((item) => item.id === call.toolCallId) && interruptedCalls.every((item) => item.invokeStatus === "waiting");
|
|
98
|
+
let canFinalize = false;
|
|
99
|
+
if (originalUpdated === 1 && ready) {
|
|
100
|
+
canFinalize = await ctx.db.sequelize.transaction(async (transaction) => {
|
|
101
|
+
const message = await ctx.db.getModel("aiMessages").findOne({
|
|
102
|
+
where: { sessionId: checkpoint.sessionId, messageId: checkpoint.messageId },
|
|
103
|
+
transaction,
|
|
104
|
+
lock: transaction.LOCK.UPDATE
|
|
105
|
+
});
|
|
106
|
+
const messageCalls = (0, import_record_utils.read)(message, "toolCalls");
|
|
107
|
+
const messageIds = Array.isArray(messageCalls) ? messageCalls.map((item) => (0, import_record_utils.asRecord)(item).id) : [];
|
|
108
|
+
sameCheckpoint = (0, import_record_utils.asRecord)((0, import_record_utils.read)(message, "metadata")).interruptId === checkpoint.interruptId && messageIds.length === checkpoint.callIds.length && messageIds.every((id) => typeof id === "string" && checkpoint.callIds.includes(id)) && new Set(messageIds).size === messageIds.length;
|
|
109
|
+
if (!sameCheckpoint) return false;
|
|
110
|
+
const [updated] = await model.update(
|
|
111
|
+
{ status: "issued" },
|
|
112
|
+
{ where: { ...where, status: "pending" }, transaction }
|
|
113
|
+
);
|
|
114
|
+
return updated === 1;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
ctx.body = {
|
|
118
|
+
...body,
|
|
119
|
+
updated: canFinalize ? originalUpdated : 0,
|
|
120
|
+
agentAutoApprovalCheckpoint: {
|
|
121
|
+
interruptId: checkpoint.interruptId,
|
|
122
|
+
decisionRecorded: originalUpdated === 1,
|
|
123
|
+
canFinalize,
|
|
124
|
+
validSnapshot: validSnapshot && sameCheckpoint
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
autoApprovalCheckpoint,
|
|
131
|
+
coordinateAutoApprovalDecision,
|
|
132
|
+
enrollAutoApprovalCheckpoint
|
|
133
|
+
});
|
|
@@ -30,6 +30,8 @@ __export(CodeValidator_exports, {
|
|
|
30
30
|
CodeValidator: () => CodeValidator
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(CodeValidator_exports);
|
|
33
|
+
const NODE_ENV_PATTERN = /process\.env(?!\s*\.OUTPUT_DIR)/;
|
|
34
|
+
const REGISTRY_NODE_ENV_PATTERN = /process\.env(?!\s*\.OUTPUT_DIR)(?!\s*\.SKILL_INPUT_FILE(?![$\u200C\u200D\p{ID_Continue}\\]))/u;
|
|
33
35
|
const DANGEROUS_NODE_PATTERNS = [
|
|
34
36
|
{ pattern: /require\s*\(\s*['"]child_process['"]\s*\)/, reason: "child_process module not allowed" },
|
|
35
37
|
{ pattern: /require\s*\(\s*['"]cluster['"]\s*\)/, reason: "cluster module not allowed" },
|
|
@@ -42,7 +44,7 @@ const DANGEROUS_NODE_PATTERNS = [
|
|
|
42
44
|
{ pattern: /require\s*\(\s*['"]inspector['"]\s*\)/, reason: "inspector module not allowed" },
|
|
43
45
|
{ pattern: /require\s*\(\s*['"]v8['"]\s*\)/, reason: "v8 module not allowed" },
|
|
44
46
|
{ pattern: /process\.exit/, reason: "process.exit not allowed" },
|
|
45
|
-
{ pattern:
|
|
47
|
+
{ pattern: NODE_ENV_PATTERN, reason: "process.env access not allowed (use OUTPUT_DIR only)" },
|
|
46
48
|
{ pattern: /process\.kill/, reason: "process.kill not allowed" },
|
|
47
49
|
{ pattern: /process\.binding\s*\(/, reason: "process.binding not allowed" },
|
|
48
50
|
{ pattern: /\bglobalThis\b/, reason: "globalThis access not allowed" },
|
|
@@ -158,11 +160,13 @@ class CodeValidator {
|
|
|
158
160
|
* Check code against forbidden patterns (dangerous modules/functions).
|
|
159
161
|
* @throws CodeValidationError if a forbidden pattern is found.
|
|
160
162
|
*/
|
|
161
|
-
validate(code, language) {
|
|
163
|
+
validate(code, language, options) {
|
|
162
164
|
const patterns = language === "node" ? DANGEROUS_NODE_PATTERNS : DANGEROUS_PYTHON_PATTERNS;
|
|
163
165
|
for (const { pattern, reason } of patterns) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
const checkedPattern = (options == null ? void 0 : options.allowSkillInputFile) && pattern === NODE_ENV_PATTERN ? REGISTRY_NODE_ENV_PATTERN : pattern;
|
|
167
|
+
if (checkedPattern.test(code)) {
|
|
168
|
+
const message = checkedPattern === REGISTRY_NODE_ENV_PATTERN ? "process.env access not allowed (use OUTPUT_DIR or SKILL_INPUT_FILE only)" : reason;
|
|
169
|
+
throw new CodeValidationError(message, checkedPattern.source);
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 DepartmentAttribution_exports = {};
|
|
28
|
+
__export(DepartmentAttribution_exports, {
|
|
29
|
+
resolveUserDepartment: () => resolveUserDepartment
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(DepartmentAttribution_exports);
|
|
32
|
+
var import_sequelize = require("sequelize");
|
|
33
|
+
var import_record_utils = require("../utils/record-utils");
|
|
34
|
+
async function resolveUserDepartment(db, userId, transaction) {
|
|
35
|
+
if (!db.hasCollection("users") || !db.hasCollection("departmentsUsers")) {
|
|
36
|
+
return { departmentId: null, status: "departments_unavailable" };
|
|
37
|
+
}
|
|
38
|
+
if (typeof userId === "number" && !Number.isSafeInteger(userId)) {
|
|
39
|
+
return { departmentId: null, status: "invalid_membership" };
|
|
40
|
+
}
|
|
41
|
+
const users = db.getRepository("users");
|
|
42
|
+
const memberships = db.getRepository("departmentsUsers");
|
|
43
|
+
const mainDepartmentAttribute = users.model.rawAttributes.mainDepartmentId;
|
|
44
|
+
if (!mainDepartmentAttribute) return { departmentId: null, status: "departments_unavailable" };
|
|
45
|
+
const mainDepartmentField = mainDepartmentAttribute.field || "mainDepartmentId";
|
|
46
|
+
const query = db.sequelize.getQueryInterface().queryGenerator;
|
|
47
|
+
const castType = ["mysql", "mariadb"].includes(db.sequelize.getDialect()) ? "CHAR" : "TEXT";
|
|
48
|
+
const user = await users.model.findOne({
|
|
49
|
+
where: { id: userId },
|
|
50
|
+
attributes: [[(0, import_sequelize.literal)(`CAST(${query.quoteIdentifier(mainDepartmentField)} AS ${castType})`), "mainDepartmentId"]],
|
|
51
|
+
transaction,
|
|
52
|
+
raw: true
|
|
53
|
+
});
|
|
54
|
+
const departmentId = (0, import_record_utils.read)(user, "mainDepartmentId");
|
|
55
|
+
if (departmentId == null || departmentId === "") return { departmentId: null, status: "unassigned" };
|
|
56
|
+
if (typeof departmentId !== "string" && typeof departmentId !== "number") {
|
|
57
|
+
return { departmentId: null, status: "invalid_membership" };
|
|
58
|
+
}
|
|
59
|
+
const membership = await memberships.findOne({ filter: { userId, departmentId }, transaction });
|
|
60
|
+
return membership ? { departmentId, status: "resolved" } : { departmentId: null, status: "invalid_membership" };
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
resolveUserDepartment
|
|
65
|
+
});
|
|
@@ -53,7 +53,47 @@ class ExecutionSpanService {
|
|
|
53
53
|
});
|
|
54
54
|
return (0, import_ctx_utils.toPlain)(record);
|
|
55
55
|
} catch (error) {
|
|
56
|
-
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] Failed to create execution span", error);
|
|
56
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] Failed to create execution span", { error });
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async upsertNative(identity, values) {
|
|
61
|
+
if (!identity) return null;
|
|
62
|
+
const repo = this.plugin.db.getRepository("agentExecutionSpans");
|
|
63
|
+
if (!(repo == null ? void 0 : repo.findOne)) return this.create({ ...values, nativeIdentity: identity });
|
|
64
|
+
try {
|
|
65
|
+
const existing = await repo.findOne({ filter: { nativeIdentity: identity } });
|
|
66
|
+
if (existing) return this.updateNativeRecord(repo, existing, values, identity);
|
|
67
|
+
try {
|
|
68
|
+
if (values.type === "sub_agent" && values.parentSessionId && values.subSessionId && values.toolCallId) {
|
|
69
|
+
const legacy = await repo.findOne({
|
|
70
|
+
filter: {
|
|
71
|
+
nativeIdentity: null,
|
|
72
|
+
source: values.source,
|
|
73
|
+
type: "sub_agent",
|
|
74
|
+
parentSessionId: values.parentSessionId,
|
|
75
|
+
subSessionId: values.subSessionId,
|
|
76
|
+
toolCallId: values.toolCallId
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (legacy) return await this.updateNativeRecord(repo, legacy, values, identity);
|
|
80
|
+
}
|
|
81
|
+
const record = await repo.create({
|
|
82
|
+
values: {
|
|
83
|
+
...values,
|
|
84
|
+
nativeIdentity: identity,
|
|
85
|
+
startedAt: values.startedAt || /* @__PURE__ */ new Date(),
|
|
86
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return (0, import_ctx_utils.toPlain)(record);
|
|
90
|
+
} catch (createError) {
|
|
91
|
+
const raced = await repo.findOne({ filter: { nativeIdentity: identity } });
|
|
92
|
+
if (!raced) throw createError;
|
|
93
|
+
return this.updateNativeRecord(repo, raced, values, identity);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
this.warn(`[AgentOrchestrator] Failed to upsert native execution span ${identity}`, error);
|
|
57
97
|
return null;
|
|
58
98
|
}
|
|
59
99
|
}
|
|
@@ -72,7 +112,7 @@ class ExecutionSpanService {
|
|
|
72
112
|
});
|
|
73
113
|
return { id: spanId };
|
|
74
114
|
} catch (error) {
|
|
75
|
-
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, `[AgentOrchestrator] Failed to update execution span ${spanId}`, error);
|
|
115
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, `[AgentOrchestrator] Failed to update execution span ${spanId}`, { error });
|
|
76
116
|
return null;
|
|
77
117
|
}
|
|
78
118
|
}
|
|
@@ -84,6 +124,50 @@ class ExecutionSpanService {
|
|
|
84
124
|
durationMs: Date.now() - startedAt
|
|
85
125
|
});
|
|
86
126
|
}
|
|
127
|
+
async updateNativeRecord(repo, rawExisting, values, identity) {
|
|
128
|
+
const existing = (0, import_ctx_utils.toPlain)(rawExisting);
|
|
129
|
+
const nextValues = Object.fromEntries(Object.entries(values).filter(([, value]) => value !== void 0));
|
|
130
|
+
delete nextValues.nativeActivityAt;
|
|
131
|
+
const terminalStatuses = ["success", "error", "canceled", "timeout"];
|
|
132
|
+
const isNonTerminal = !terminalStatuses.includes(values.status);
|
|
133
|
+
if (isNonTerminal) delete nextValues.status;
|
|
134
|
+
const existingMetadata = existing.metadata && typeof existing.metadata === "object" && !Array.isArray(existing.metadata) ? existing.metadata : {};
|
|
135
|
+
const incomingMetadata = values.metadata && typeof values.metadata === "object" && !Array.isArray(values.metadata) ? values.metadata : {};
|
|
136
|
+
await repo.update({
|
|
137
|
+
filterByTk: existing.id,
|
|
138
|
+
values: {
|
|
139
|
+
...nextValues,
|
|
140
|
+
nativeIdentity: identity,
|
|
141
|
+
metadata: { ...existingMetadata, ...incomingMetadata },
|
|
142
|
+
startedAt: existing.startedAt || values.startedAt || /* @__PURE__ */ new Date(),
|
|
143
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (isNonTerminal) {
|
|
147
|
+
await repo.update({
|
|
148
|
+
filter: { id: existing.id, status: { $notIn: terminalStatuses } },
|
|
149
|
+
values: { status: values.status }
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (values.nativeActivityAt)
|
|
153
|
+
await this.advanceNativeActivity(existing.id, values.nativeActivityAt);
|
|
154
|
+
return { ...existing, ...nextValues, nativeIdentity: identity, id: existing.id };
|
|
155
|
+
}
|
|
156
|
+
async advanceNativeActivity(id, activityAt) {
|
|
157
|
+
const repo = this.plugin.db.getRepository("agentExecutionSpans");
|
|
158
|
+
if (!repo) throw new Error("Execution span repository is unavailable.");
|
|
159
|
+
await repo.update({
|
|
160
|
+
filter: { id, $or: [{ nativeActivityAt: null }, { nativeActivityAt: { $lt: activityAt.toISOString() } }] },
|
|
161
|
+
values: { nativeActivityAt: activityAt }
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
warn(message, error) {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
try {
|
|
167
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, message, { error });
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
87
171
|
}
|
|
88
172
|
function deepGet(obj, path) {
|
|
89
173
|
return path.split(".").reduce((current, key) => {
|
|
@@ -95,10 +179,19 @@ function getOrchestratorTraceContext(ctx) {
|
|
|
95
179
|
const requestContext = ctx[ORCHESTRATOR_TRACE_CONTEXT_KEY] || deepGet(ctx, "state.orchestratorTraceContext") || deepGet(ctx, "runtime.context.orchestratorTraceContext") || null;
|
|
96
180
|
const agentContext = (0, import_AgentExecutionContext.getAgentExecutionContext)();
|
|
97
181
|
if (!requestContext && !agentContext) return null;
|
|
182
|
+
const requestRootRunId = requestContext == null ? void 0 : requestContext.rootRunId;
|
|
183
|
+
const rootRunId = typeof requestRootRunId === "string" ? requestRootRunId : agentContext == null ? void 0 : agentContext.rootRunId;
|
|
184
|
+
if (!rootRunId) return null;
|
|
185
|
+
const toolCallId = [
|
|
186
|
+
deepGet(ctx, "runtime.toolCallId"),
|
|
187
|
+
requestContext == null ? void 0 : requestContext.toolCallId,
|
|
188
|
+
agentContext == null ? void 0 : agentContext.toolCallId
|
|
189
|
+
].find((value) => typeof value === "string");
|
|
98
190
|
return {
|
|
99
191
|
...agentContext || {},
|
|
100
192
|
...requestContext || {},
|
|
101
|
-
|
|
193
|
+
rootRunId,
|
|
194
|
+
toolCallId
|
|
102
195
|
};
|
|
103
196
|
}
|
|
104
197
|
function setOrchestratorTraceContext(ctx, traceContext) {
|
|
@@ -0,0 +1,271 @@
|
|
|
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 GovernanceAdmission_exports = {};
|
|
28
|
+
__export(GovernanceAdmission_exports, {
|
|
29
|
+
authorizeDelegatedEmployee: () => authorizeDelegatedEmployee,
|
|
30
|
+
createGovernanceAdmission: () => createGovernanceAdmission
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(GovernanceAdmission_exports);
|
|
33
|
+
var import_node_crypto = require("node:crypto");
|
|
34
|
+
var import_record_utils = require("../utils/record-utils");
|
|
35
|
+
var import_AgentGovernanceService = require("./AgentGovernanceService");
|
|
36
|
+
var import_DepartmentAttribution = require("./DepartmentAttribution");
|
|
37
|
+
var import_NativeUsageAttribution = require("./NativeUsageAttribution");
|
|
38
|
+
function valueString(value) {
|
|
39
|
+
return typeof value === "string" ? value : "";
|
|
40
|
+
}
|
|
41
|
+
function monthStart() {
|
|
42
|
+
const now = /* @__PURE__ */ new Date();
|
|
43
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)).toISOString();
|
|
44
|
+
}
|
|
45
|
+
function quotaError(ctx, message) {
|
|
46
|
+
return ctx.throw(403, ctx.t(message));
|
|
47
|
+
}
|
|
48
|
+
async function checkObservedQuota(ctx, policy, userId, departmentId) {
|
|
49
|
+
const { settings } = policy;
|
|
50
|
+
const checksTokens = settings.maxMonthlyTokens != null;
|
|
51
|
+
const checksCost = settings.maxMonthlyCost != null;
|
|
52
|
+
if (!checksTokens && !checksCost) return;
|
|
53
|
+
const db = ctx.db;
|
|
54
|
+
const repo = db.getRepository("agentExecutionSpans");
|
|
55
|
+
const start = monthStart();
|
|
56
|
+
const filter = {
|
|
57
|
+
type: "model_call",
|
|
58
|
+
$or: [{ usageOccurredAt: { $gte: start } }, { usageOccurredAt: null, createdAt: { $gte: start } }]
|
|
59
|
+
};
|
|
60
|
+
if (policy.scope === "user") filter.userId = userId;
|
|
61
|
+
if (policy.scope === "department") {
|
|
62
|
+
if (departmentId == null) quotaError(ctx, "AI governance requires an assigned primary department.");
|
|
63
|
+
filter.departmentId = departmentId;
|
|
64
|
+
filter.departmentAttribution = "snapshot";
|
|
65
|
+
}
|
|
66
|
+
if (policy.scope === "employee") filter.employeeUsername = policy.scopeId;
|
|
67
|
+
if (policy.employeeUsername) filter.employeeUsername = policy.employeeUsername;
|
|
68
|
+
const modelParts = policy.modelKey ? policy.modelKey.split(/:(.*)/s) : void 0;
|
|
69
|
+
if (modelParts) {
|
|
70
|
+
filter.$and = [
|
|
71
|
+
{ $or: [{ llmService: null }, { model: null }, { llmService: modelParts[0], model: modelParts[1] }] }
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
const rows = await repo.find({ filter, limit: 10001, sort: ["id"] });
|
|
75
|
+
if (rows.length > 1e4) quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
76
|
+
let tokens = 0;
|
|
77
|
+
let cost = 0;
|
|
78
|
+
for (const row of rows) {
|
|
79
|
+
const actualModel = `${valueString((0, import_record_utils.read)(row, "llmService"))}:${valueString((0, import_record_utils.read)(row, "model"))}`;
|
|
80
|
+
if (policy.modelKey && actualModel !== policy.modelKey) {
|
|
81
|
+
if (!(0, import_record_utils.read)(row, "llmService") || !(0, import_record_utils.read)(row, "model"))
|
|
82
|
+
quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const usage = (0, import_record_utils.read)(row, "totalTokens");
|
|
86
|
+
const amount = (0, import_record_utils.read)(row, "cost");
|
|
87
|
+
if (checksTokens) {
|
|
88
|
+
if ((0, import_record_utils.read)(row, "usageSource") !== "actual" || usage == null || !Number.isFinite(Number(usage))) {
|
|
89
|
+
quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
90
|
+
}
|
|
91
|
+
tokens += Number(usage);
|
|
92
|
+
}
|
|
93
|
+
if (checksCost) {
|
|
94
|
+
if ((0, import_record_utils.read)(row, "usageSource") !== "actual" || amount == null || !Number.isFinite(Number(amount)) || (0, import_record_utils.read)(row, "priceCurrency") !== "USD") {
|
|
95
|
+
quotaError(ctx, "AI quota cannot be checked because cost is incomplete or unpriced.");
|
|
96
|
+
}
|
|
97
|
+
cost += Number(amount);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (checksTokens && tokens >= Number(settings.maxMonthlyTokens)) quotaError(ctx, "AI token quota reached.");
|
|
101
|
+
if (checksCost && cost >= Number(settings.maxMonthlyCost)) quotaError(ctx, "AI cost quota reached.");
|
|
102
|
+
}
|
|
103
|
+
async function authorizeDelegatedEmployee(context, employee, model) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
const userId = Number((_b = (_a = context.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id);
|
|
106
|
+
if (!Number.isSafeInteger(userId) || userId <= 0) quotaError(context, "Authentication is required.");
|
|
107
|
+
const employeeUsername = valueString((0, import_record_utils.read)(employee, "username"));
|
|
108
|
+
if (!employeeUsername || !model.llmService || !model.model) {
|
|
109
|
+
quotaError(context, "AI governance could not resolve the model.");
|
|
110
|
+
}
|
|
111
|
+
const service = new import_AgentGovernanceService.AgentGovernanceService(context.db);
|
|
112
|
+
let department;
|
|
113
|
+
try {
|
|
114
|
+
department = await (0, import_DepartmentAttribution.resolveUserDepartment)(context.db, userId);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const departmentPolicies = await context.db.getRepository("agentGovernancePolicies").count({
|
|
117
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
118
|
+
});
|
|
119
|
+
if (departmentPolicies) throw error;
|
|
120
|
+
department = { departmentId: null, status: "departments_unavailable" };
|
|
121
|
+
}
|
|
122
|
+
const policyRepo = context.db.getRepository("agentGovernancePolicies");
|
|
123
|
+
const configured = await policyRepo.count({ filter: { currentVersionId: { $ne: null } } });
|
|
124
|
+
const binding = await context.db.getRepository("agentGovernancePromptBindings").findOne({ filter: { userId, employeeUsername } });
|
|
125
|
+
if (!configured && !binding) return { userId, departmentId: department.departmentId };
|
|
126
|
+
if (department.status === "departments_unavailable") {
|
|
127
|
+
const departmentPolicies = await policyRepo.count({
|
|
128
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
129
|
+
});
|
|
130
|
+
if (departmentPolicies) quotaError(context, "AI governance cannot check department policies.");
|
|
131
|
+
}
|
|
132
|
+
const modelKey = `${model.llmService}:${model.model}`;
|
|
133
|
+
const policies = configured ? await service.activePolicies(userId, employeeUsername, department.departmentId, void 0, modelKey) : [];
|
|
134
|
+
for (const policy of policies) {
|
|
135
|
+
if (policy.scope === "employee" && policy.settings.systemPrompt !== void 0 && ((0, import_record_utils.read)(employee, "about") ?? null) !== policy.settings.systemPrompt) {
|
|
136
|
+
quotaError(context, "The managed AI employee prompt changed and needs administrator review.");
|
|
137
|
+
}
|
|
138
|
+
if (policy.settings.allow === false || policy.settings.allowedModels && !policy.settings.allowedModels.includes(modelKey)) {
|
|
139
|
+
quotaError(context, "Your AI employee or model is not allowed by governance policy.");
|
|
140
|
+
}
|
|
141
|
+
await checkObservedQuota(context, policy, userId, department.departmentId);
|
|
142
|
+
}
|
|
143
|
+
const prompt = await service.preview({ userId, employeeUsername });
|
|
144
|
+
if (prompt.instruction || binding) {
|
|
145
|
+
if (!prompt.instruction || prompt.promptMode !== "default" || !binding) {
|
|
146
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
147
|
+
}
|
|
148
|
+
const expected = (0, import_node_crypto.createHash)("sha256").update(prompt.projectedPrompt).digest("hex");
|
|
149
|
+
const native = await context.db.getRepository("usersAiEmployees").findOne({ filter: { userId, aiEmployee: employeeUsername } });
|
|
150
|
+
const actual = (0, import_node_crypto.createHash)("sha256").update(valueString((0, import_record_utils.read)(native, "prompt"))).digest("hex");
|
|
151
|
+
const versions = prompt.policies.filter((policy) => {
|
|
152
|
+
var _a2;
|
|
153
|
+
return (_a2 = policy.settings.instruction) == null ? void 0 : _a2.trim();
|
|
154
|
+
}).map((policy) => ({ id: policy.id, versionId: policy.versionId }));
|
|
155
|
+
if (expected !== (0, import_record_utils.read)(binding, "contentHash") || expected !== actual || String(prompt.departmentId ?? "") !== String((0, import_record_utils.read)(binding, "departmentId") ?? "") || JSON.stringify(versions) !== JSON.stringify((0, import_record_utils.read)(binding, "policyVersions"))) {
|
|
156
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { userId, departmentId: department.departmentId };
|
|
160
|
+
}
|
|
161
|
+
function createGovernanceAdmission(plugin, enabled) {
|
|
162
|
+
const service = new import_AgentGovernanceService.AgentGovernanceService(plugin.db);
|
|
163
|
+
return async (context, next) => {
|
|
164
|
+
var _a, _b, _c, _d;
|
|
165
|
+
if (!enabled()) return next();
|
|
166
|
+
const { resourceName, actionName } = context.action || {};
|
|
167
|
+
if (resourceName !== "aiConversations" || !["sendMessages", "resendMessages", "resumeToolCall"].includes(actionName)) {
|
|
168
|
+
return next();
|
|
169
|
+
}
|
|
170
|
+
const rawUserId = (_b = (_a = context.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
171
|
+
const userId = Number(rawUserId);
|
|
172
|
+
const values = ((_d = (_c = context.action) == null ? void 0 : _c.params) == null ? void 0 : _d.values) || {};
|
|
173
|
+
const sessionId = valueString(values.sessionId);
|
|
174
|
+
if (!Number.isSafeInteger(userId) || userId <= 0 || !sessionId || !context.db.hasCollection("aiConversations")) {
|
|
175
|
+
return next();
|
|
176
|
+
}
|
|
177
|
+
const conversation = await context.db.getRepository("aiConversations").findOne({ filter: { sessionId, userId } });
|
|
178
|
+
if (!conversation) return next();
|
|
179
|
+
const employeeUsername = actionName === "sendMessages" ? valueString(values.aiEmployee) : valueString((0, import_record_utils.read)(conversation, "aiEmployeeUsername"));
|
|
180
|
+
if (!employeeUsername) return next();
|
|
181
|
+
const employee = await context.db.getRepository("aiEmployees").findOne({ filter: { username: employeeUsername } });
|
|
182
|
+
if (!employee) return next();
|
|
183
|
+
let department;
|
|
184
|
+
try {
|
|
185
|
+
department = await (0, import_DepartmentAttribution.resolveUserDepartment)(context.db, userId);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const departmentPolicies = await context.db.getRepository("agentGovernancePolicies").count({
|
|
188
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
189
|
+
});
|
|
190
|
+
if (departmentPolicies) throw error;
|
|
191
|
+
department = { departmentId: null, status: "departments_unavailable" };
|
|
192
|
+
}
|
|
193
|
+
const run = async () => {
|
|
194
|
+
var _a2;
|
|
195
|
+
const policyRepo = context.db.getRepository("agentGovernancePolicies");
|
|
196
|
+
const configured = await policyRepo.count({ filter: { currentVersionId: { $ne: null } } });
|
|
197
|
+
const binding = await context.db.getRepository("agentGovernancePromptBindings").findOne({ filter: { userId, employeeUsername } });
|
|
198
|
+
if (!configured && !binding) return next();
|
|
199
|
+
if (department.status === "departments_unavailable") {
|
|
200
|
+
const departmentPolicies = await policyRepo.count({
|
|
201
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
202
|
+
});
|
|
203
|
+
if (departmentPolicies) quotaError(context, "AI governance cannot check department policies.");
|
|
204
|
+
}
|
|
205
|
+
const storedEmployee = valueString((0, import_record_utils.read)(conversation, "aiEmployeeUsername"));
|
|
206
|
+
if (storedEmployee && storedEmployee !== employeeUsername) {
|
|
207
|
+
const [requestedPolicies, storedPolicies, storedBinding] = await Promise.all([
|
|
208
|
+
service.activePolicies(userId, employeeUsername, department.departmentId, void 0, void 0, true),
|
|
209
|
+
service.activePolicies(userId, storedEmployee, department.departmentId, void 0, void 0, true),
|
|
210
|
+
context.db.getRepository("agentGovernancePromptBindings").findOne({ filter: { userId, employeeUsername: storedEmployee } })
|
|
211
|
+
]);
|
|
212
|
+
if (requestedPolicies.length || storedPolicies.length || binding || storedBinding) {
|
|
213
|
+
quotaError(context, "The AI employee must match the conversation for managed usage.");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
let policies = [];
|
|
217
|
+
let modelKey = "";
|
|
218
|
+
if (configured) {
|
|
219
|
+
const aiPlugin = context.app.pm.get("ai");
|
|
220
|
+
if (!((_a2 = aiPlugin == null ? void 0 : aiPlugin.aiEmployeesManager) == null ? void 0 : _a2.resolveModel))
|
|
221
|
+
quotaError(context, "AI governance could not resolve the model.");
|
|
222
|
+
const rawModel = values.model;
|
|
223
|
+
const requestedModel = rawModel && typeof rawModel === "object" && typeof rawModel.llmService === "string" && typeof rawModel.model === "string" ? { llmService: rawModel.llmService, model: rawModel.model } : void 0;
|
|
224
|
+
const model = await aiPlugin.aiEmployeesManager.resolveModel(employee, requestedModel);
|
|
225
|
+
if (!(model == null ? void 0 : model.llmService) || !(model == null ? void 0 : model.model)) quotaError(context, "AI governance could not resolve the model.");
|
|
226
|
+
modelKey = `${model.llmService}:${model.model}`;
|
|
227
|
+
policies = await service.activePolicies(userId, employeeUsername, department.departmentId, void 0, modelKey);
|
|
228
|
+
}
|
|
229
|
+
for (const policy of policies) {
|
|
230
|
+
if (policy.scope === "employee" && policy.settings.systemPrompt !== void 0 && ((0, import_record_utils.read)(employee, "about") ?? null) !== policy.settings.systemPrompt) {
|
|
231
|
+
quotaError(context, "The managed AI employee prompt changed and needs administrator review.");
|
|
232
|
+
}
|
|
233
|
+
if (policy.settings.allow === false || policy.settings.allowedModels && !policy.settings.allowedModels.includes(modelKey)) {
|
|
234
|
+
quotaError(context, "Your AI employee or model is not allowed by governance policy.");
|
|
235
|
+
}
|
|
236
|
+
await checkObservedQuota(context, policy, userId, department.departmentId);
|
|
237
|
+
}
|
|
238
|
+
const prompt = await service.preview({ userId, employeeUsername });
|
|
239
|
+
if (prompt.instruction || binding) {
|
|
240
|
+
if (!prompt.instruction || prompt.promptMode !== "default" || !binding) {
|
|
241
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
242
|
+
}
|
|
243
|
+
const expected = (0, import_node_crypto.createHash)("sha256").update(prompt.projectedPrompt).digest("hex");
|
|
244
|
+
const native = await context.db.getRepository("usersAiEmployees").findOne({ filter: { userId, aiEmployee: employeeUsername } });
|
|
245
|
+
const actual = (0, import_node_crypto.createHash)("sha256").update(valueString((0, import_record_utils.read)(native, "prompt"))).digest("hex");
|
|
246
|
+
const versions = prompt.policies.filter((policy) => {
|
|
247
|
+
var _a3;
|
|
248
|
+
return (_a3 = policy.settings.instruction) == null ? void 0 : _a3.trim();
|
|
249
|
+
}).map((policy) => ({ id: policy.id, versionId: policy.versionId }));
|
|
250
|
+
if (expected !== (0, import_record_utils.read)(binding, "contentHash") || expected !== actual || String(prompt.departmentId ?? "") !== String((0, import_record_utils.read)(binding, "departmentId") ?? "") || JSON.stringify(versions) !== JSON.stringify((0, import_record_utils.read)(binding, "policyVersions"))) {
|
|
251
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return next();
|
|
255
|
+
};
|
|
256
|
+
return (0, import_NativeUsageAttribution.runWithNativeUsageAttribution)(
|
|
257
|
+
{
|
|
258
|
+
db: context.db,
|
|
259
|
+
userId,
|
|
260
|
+
sessionId,
|
|
261
|
+
...department.status === "resolved" && department.departmentId != null ? { departmentId: department.departmentId } : {}
|
|
262
|
+
},
|
|
263
|
+
run
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
268
|
+
0 && (module.exports = {
|
|
269
|
+
authorizeDelegatedEmployee,
|
|
270
|
+
createGovernanceAdmission
|
|
271
|
+
});
|