plugin-agent-orchestrator 1.1.7 → 1.2.0
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/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.2e4cb0477da3db1f.js +10 -0
- package/dist/client/253.93deb9e0192e76a5.js +10 -0
- package/dist/client/325.8f7f509bdb35e142.js +10 -0
- package/dist/client/404.498d2d9516dd1dce.js +10 -0
- package/dist/client/418.6f01da17774a5a25.js +10 -0
- package/dist/client/53.774ff07505d521fa.js +10 -0
- package/dist/client/619.e342b0fa467d39ca.js +10 -0
- package/dist/client/627.fdd60bcc0f3a9cf6.js +10 -0
- package/dist/client/652.477e21bfff67bc1c.js +10 -0
- package/dist/client/981.e0546ffc34afedcd.js +10 -0
- package/dist/client/993.5d04b510835ab0d2.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/117.ccf43ae8631f7d74.js +10 -0
- package/dist/client-v2/214.cdf76752053a8990.js +10 -0
- package/dist/client-v2/253.1198df22f5baf304.js +10 -0
- package/dist/client-v2/264.78887ff88f969467.js +10 -0
- package/dist/client-v2/325.fafe5a6e83ba9cb3.js +10 -0
- package/dist/client-v2/404.9ba964c28a151c81.js +10 -0
- package/dist/client-v2/{41.3deb9e57a0f64fc4.js → 41.b28cf7a675a603d1.js} +1 -1
- package/dist/client-v2/418.55b6b28cda8bb5f3.js +10 -0
- package/dist/client-v2/{53.349fff8db80b19d4.js → 53.282081f97e4308c6.js} +1 -1
- package/dist/client-v2/{619.0a2144aaffefe018.js → 619.8c03913873785fb6.js} +1 -1
- package/dist/client-v2/627.e16f4a0dd596c3e6.js +10 -0
- package/dist/client-v2/652.1a48364774d5383a.js +10 -0
- package/dist/client-v2/{70.ffff2997c10fd4b0.js → 70.9166ed70906d041f.js} +1 -1
- package/dist/client-v2/{981.e4a1f41cfc94a856.js → 981.a81521f0296c7db8.js} +1 -1
- package/dist/client-v2/993.ca5b28f1e2b4c1ef.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +10 -7
- package/dist/locale/en-US.json +229 -1
- package/dist/locale/zh-CN.json +229 -1
- 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-execution-spans.js +145 -6
- 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-loop-runs.js +23 -5
- 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/plugin.js +114 -33
- 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/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/DepartmentAttribution.js +65 -0
- package/dist/server/services/ExecutionSpanService.js +96 -3
- package/dist/server/services/GovernanceAdmission.js +211 -0
- package/dist/server/services/HarnessCapabilities.js +118 -0
- package/dist/server/services/LoopBudgetService.js +29 -11
- package/dist/server/services/LoopRunRepository.js +15 -6
- package/dist/server/services/LoopRunStateMachine.js +18 -7
- package/dist/server/services/LoopTriggerService.js +1 -1
- package/dist/server/services/LoopWorkerService.js +66 -32
- 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/TokenTracker.js +787 -104
- package/dist/server/services/TracingRetentionPolicy.js +66 -0
- package/dist/server/services/VerificationService.js +18 -8
- package/dist/server/skill-hub/sandbox-config.json +6 -6
- package/dist/server/utils/ensure-indexes.js +14 -5
- package/package.json +63 -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 +41 -0
- package/src/client/__tests__/embedded-settings.test.tsx +232 -0
- package/src/client/hooks/useRunEventStream.ts +76 -76
- package/src/client/index.tsx +2 -2
- package/src/client/plugin.tsx +76 -32
- 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 +132 -132
- package/src/client/skill-hub/tools/SkillHubCard.tsx +104 -104
- package/src/client/skill-hub/tools/loopTemplates.ts +52 -52
- package/src/client/skill-hub/tools/registerSkillLoopCards.ts +71 -71
- package/src/client/skill-hub/utils/jsonFields.ts +41 -41
- package/src/client-v2/__tests__/embedded-settings.test.tsx +193 -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 +269 -269
- package/src/client-v2/components/AgentRunsTab.tsx +92 -83
- package/src/client-v2/components/ApprovalsTab.tsx +337 -337
- package/src/client-v2/components/EmployeeGovernanceTab.tsx +702 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +704 -541
- 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 +386 -0
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/pages/AgentBindingsPage.tsx +22 -13
- package/src/client-v2/pages/ApprovalsPage.tsx +19 -10
- package/src/client-v2/pages/EmployeeGovernancePage.tsx +22 -0
- package/src/client-v2/pages/ExecutionHistoryPage.tsx +19 -10
- package/src/client-v2/pages/HarnessProfilesPage.tsx +19 -10
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +19 -10
- package/src/client-v2/pages/LoopSettingsPage.tsx +19 -10
- package/src/client-v2/pages/MemoryInspectorPage.tsx +22 -13
- package/src/client-v2/pages/RetrievalTracePage.tsx +19 -10
- package/src/client-v2/pages/RulesPage.tsx +22 -13
- package/src/client-v2/pages/SkillDefinitionsPage.tsx +19 -10
- package/src/client-v2/pages/SkillMetricsPage.tsx +19 -10
- package/src/client-v2/pages/TracingPage.tsx +22 -13
- package/src/client-v2/pages/UsageGovernancePage.tsx +22 -0
- package/src/client-v2/plugin.tsx +139 -99
- 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 +110 -0
- package/src/client-v2/skill-hub/tools/interactions.ts +128 -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 +229 -1
- package/src/locale/zh-CN.json +229 -1
- package/src/server/__tests__/agent-execution-context.test.ts +18 -18
- package/src/server/__tests__/agent-governance.integration.test.ts +392 -0
- package/src/server/__tests__/agent-knowledge-insights.test.ts +123 -123
- package/src/server/__tests__/agent-monitor-acl.integration.test.ts +274 -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 +342 -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 +95 -0
- package/src/server/__tests__/harness-compiler.test.ts +214 -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 +182 -172
- package/src/server/__tests__/input-schema-validator.test.ts +26 -26
- package/src/server/__tests__/loop-approval-decision.test.ts +577 -512
- package/src/server/__tests__/loop-approval-expiry.test.ts +258 -258
- package/src/server/__tests__/loop-budget-service.test.ts +36 -0
- package/src/server/__tests__/loop-pattern-schema.test.ts +73 -73
- package/src/server/__tests__/loop-run-repository.test.ts +32 -0
- package/src/server/__tests__/loop-run-state-machine.test.ts +101 -101
- package/src/server/__tests__/loop-trigger-service.test.ts +192 -148
- package/src/server/__tests__/loop-worker-claim.test.ts +72 -9
- package/src/server/__tests__/loop-worker-execution.test.ts +382 -317
- package/src/server/__tests__/native-agent-monitor-sync.test.ts +350 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +470 -662
- package/src/server/__tests__/native-usage-attribution.integration.test.ts +175 -0
- package/src/server/__tests__/skill-access-service.test.ts +64 -64
- package/src/server/__tests__/skill-execute.test.ts +70 -70
- package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -140
- 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 +639 -0
- package/src/server/__tests__/tool-loop-detection.test.ts +276 -276
- package/src/server/__tests__/tracing-retention-policy.test.ts +37 -0
- package/src/server/__tests__/usage-ledger.integration.test.ts +194 -0
- package/src/server/collections/agent-execution-spans.ts +393 -245
- package/src/server/collections/agent-governance-audit-events.ts +26 -0
- package/src/server/collections/agent-governance-policies.ts +26 -0
- package/src/server/collections/agent-governance-policy-versions.ts +27 -0
- package/src/server/collections/agent-governance-prompt-bindings.ts +29 -0
- package/src/server/collections/agent-loop-action-approvals.ts +39 -39
- package/src/server/collections/agent-loop-runs.ts +396 -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/orchestrator-config.ts +87 -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 +117 -0
- package/src/server/migrations/20261110010000-add-usage-department-attribution.ts +35 -0
- package/src/server/plugin.ts +674 -573
- package/src/server/resources/agent-governance.ts +168 -0
- package/src/server/resources/agent-harness-profile.ts +110 -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 +215 -482
- package/src/server/resources/agent-usage.ts +420 -0
- package/src/server/resources/native-monitor-format.ts +157 -0
- package/src/server/resources/tracing.ts +303 -267
- package/src/server/services/AgentExecutionContext.ts +23 -23
- package/src/server/services/AgentGovernanceService.ts +548 -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/CodeValidator.ts +238 -238
- package/src/server/services/DepartmentAttribution.ts +54 -0
- package/src/server/services/DurableCircuitBreakerService.ts +235 -235
- package/src/server/services/ExecutionSpanService.ts +278 -146
- package/src/server/services/FileManager.ts +159 -159
- package/src/server/services/GovernanceAdmission.ts +239 -0
- package/src/server/services/HarnessCapabilities.ts +119 -0
- package/src/server/services/HarnessCompiler.ts +170 -170
- package/src/server/services/HarnessProfileService.ts +235 -235
- package/src/server/services/HarnessSchema.ts +194 -194
- package/src/server/services/InputSchemaValidator.ts +44 -44
- package/src/server/services/LoopBudgetService.ts +332 -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 +350 -332
- package/src/server/services/LoopRunStateMachine.ts +545 -525
- package/src/server/services/LoopSchedulerService.ts +195 -195
- package/src/server/services/LoopTriggerService.ts +169 -159
- package/src/server/services/LoopWorkerService.ts +986 -912
- package/src/server/services/ManagedPromptProtection.ts +88 -0
- package/src/server/services/NativeAgentMonitorSyncService.ts +691 -0
- package/src/server/services/NativeSubAgentObserver.ts +331 -757
- package/src/server/services/NativeUsageAttribution.ts +98 -0
- package/src/server/services/PathLockService.ts +317 -317
- package/src/server/services/PluginAiRuntimeAdapter.ts +387 -387
- package/src/server/services/RunEventBus.ts +58 -58
- package/src/server/services/SandboxRunner.ts +492 -492
- 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 +1158 -287
- package/src/server/services/ToolLoopDetectionService.ts +210 -210
- package/src/server/services/TracingRetentionPolicy.ts +56 -0
- package/src/server/services/VerificationSchema.ts +31 -31
- package/src/server/services/VerificationService.ts +332 -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 +1232 -1232
- package/src/server/skill-hub/sandbox-config.json +6 -6
- package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +281 -281
- package/src/server/skill-hub/services/__tests__/RegistrySkillInstallationService.test.ts +295 -295
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +568 -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 +216 -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 +119 -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/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
|
@@ -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,211 @@
|
|
|
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
|
+
createGovernanceAdmission: () => createGovernanceAdmission
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(GovernanceAdmission_exports);
|
|
32
|
+
var import_node_crypto = require("node:crypto");
|
|
33
|
+
var import_record_utils = require("../utils/record-utils");
|
|
34
|
+
var import_AgentGovernanceService = require("./AgentGovernanceService");
|
|
35
|
+
var import_DepartmentAttribution = require("./DepartmentAttribution");
|
|
36
|
+
var import_NativeUsageAttribution = require("./NativeUsageAttribution");
|
|
37
|
+
function valueString(value) {
|
|
38
|
+
return typeof value === "string" ? value : "";
|
|
39
|
+
}
|
|
40
|
+
function monthStart() {
|
|
41
|
+
const now = /* @__PURE__ */ new Date();
|
|
42
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)).toISOString();
|
|
43
|
+
}
|
|
44
|
+
function quotaError(ctx, message) {
|
|
45
|
+
return ctx.throw(403, ctx.t(message));
|
|
46
|
+
}
|
|
47
|
+
async function checkObservedQuota(ctx, policy, userId, departmentId) {
|
|
48
|
+
const { settings } = policy;
|
|
49
|
+
const checksTokens = settings.maxMonthlyTokens != null;
|
|
50
|
+
const checksCost = settings.maxMonthlyCost != null;
|
|
51
|
+
if (!checksTokens && !checksCost) return;
|
|
52
|
+
const db = ctx.db;
|
|
53
|
+
const repo = db.getRepository("agentExecutionSpans");
|
|
54
|
+
const start = monthStart();
|
|
55
|
+
const filter = {
|
|
56
|
+
type: "model_call",
|
|
57
|
+
$or: [{ usageOccurredAt: { $gte: start } }, { usageOccurredAt: null, createdAt: { $gte: start } }]
|
|
58
|
+
};
|
|
59
|
+
if (policy.scope === "user") filter.userId = userId;
|
|
60
|
+
if (policy.scope === "department") {
|
|
61
|
+
if (departmentId == null) quotaError(ctx, "AI governance requires an assigned primary department.");
|
|
62
|
+
filter.departmentId = departmentId;
|
|
63
|
+
filter.departmentAttribution = "snapshot";
|
|
64
|
+
}
|
|
65
|
+
if (policy.scope === "employee") filter.employeeUsername = policy.scopeId;
|
|
66
|
+
if (policy.employeeUsername) filter.employeeUsername = policy.employeeUsername;
|
|
67
|
+
const modelParts = policy.modelKey ? policy.modelKey.split(/:(.*)/s) : void 0;
|
|
68
|
+
if (modelParts) {
|
|
69
|
+
filter.$and = [
|
|
70
|
+
{ $or: [{ llmService: null }, { model: null }, { llmService: modelParts[0], model: modelParts[1] }] }
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
const rows = await repo.find({ filter, limit: 10001, sort: ["id"] });
|
|
74
|
+
if (rows.length > 1e4) quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
75
|
+
let tokens = 0;
|
|
76
|
+
let cost = 0;
|
|
77
|
+
for (const row of rows) {
|
|
78
|
+
const actualModel = `${valueString((0, import_record_utils.read)(row, "llmService"))}:${valueString((0, import_record_utils.read)(row, "model"))}`;
|
|
79
|
+
if (policy.modelKey && actualModel !== policy.modelKey) {
|
|
80
|
+
if (!(0, import_record_utils.read)(row, "llmService") || !(0, import_record_utils.read)(row, "model"))
|
|
81
|
+
quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const usage = (0, import_record_utils.read)(row, "totalTokens");
|
|
85
|
+
const amount = (0, import_record_utils.read)(row, "cost");
|
|
86
|
+
if (checksTokens) {
|
|
87
|
+
if ((0, import_record_utils.read)(row, "usageSource") !== "actual" || usage == null || !Number.isFinite(Number(usage))) {
|
|
88
|
+
quotaError(ctx, "AI quota cannot be checked because usage coverage is incomplete.");
|
|
89
|
+
}
|
|
90
|
+
tokens += Number(usage);
|
|
91
|
+
}
|
|
92
|
+
if (checksCost) {
|
|
93
|
+
if ((0, import_record_utils.read)(row, "usageSource") !== "actual" || amount == null || !Number.isFinite(Number(amount)) || (0, import_record_utils.read)(row, "priceCurrency") !== "USD") {
|
|
94
|
+
quotaError(ctx, "AI quota cannot be checked because cost is incomplete or unpriced.");
|
|
95
|
+
}
|
|
96
|
+
cost += Number(amount);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (checksTokens && tokens >= Number(settings.maxMonthlyTokens)) quotaError(ctx, "AI token quota reached.");
|
|
100
|
+
if (checksCost && cost >= Number(settings.maxMonthlyCost)) quotaError(ctx, "AI cost quota reached.");
|
|
101
|
+
}
|
|
102
|
+
function createGovernanceAdmission(plugin, enabled) {
|
|
103
|
+
const service = new import_AgentGovernanceService.AgentGovernanceService(plugin.db);
|
|
104
|
+
return async (context, next) => {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
if (!enabled()) return next();
|
|
107
|
+
const { resourceName, actionName } = context.action || {};
|
|
108
|
+
if (resourceName !== "aiConversations" || !["sendMessages", "resendMessages", "resumeToolCall"].includes(actionName)) {
|
|
109
|
+
return next();
|
|
110
|
+
}
|
|
111
|
+
const rawUserId = (_b = (_a = context.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
112
|
+
const userId = Number(rawUserId);
|
|
113
|
+
const values = ((_d = (_c = context.action) == null ? void 0 : _c.params) == null ? void 0 : _d.values) || {};
|
|
114
|
+
const sessionId = valueString(values.sessionId);
|
|
115
|
+
if (!Number.isSafeInteger(userId) || userId <= 0 || !sessionId || !context.db.hasCollection("aiConversations")) {
|
|
116
|
+
return next();
|
|
117
|
+
}
|
|
118
|
+
const conversation = await context.db.getRepository("aiConversations").findOne({ filter: { sessionId, userId } });
|
|
119
|
+
if (!conversation) return next();
|
|
120
|
+
const employeeUsername = actionName === "sendMessages" ? valueString(values.aiEmployee) : valueString((0, import_record_utils.read)(conversation, "aiEmployeeUsername"));
|
|
121
|
+
if (!employeeUsername) return next();
|
|
122
|
+
const employee = await context.db.getRepository("aiEmployees").findOne({ filter: { username: employeeUsername } });
|
|
123
|
+
if (!employee) return next();
|
|
124
|
+
let department;
|
|
125
|
+
try {
|
|
126
|
+
department = await (0, import_DepartmentAttribution.resolveUserDepartment)(context.db, userId);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const departmentPolicies = await context.db.getRepository("agentGovernancePolicies").count({
|
|
129
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
130
|
+
});
|
|
131
|
+
if (departmentPolicies) throw error;
|
|
132
|
+
department = { departmentId: null, status: "departments_unavailable" };
|
|
133
|
+
}
|
|
134
|
+
const run = async () => {
|
|
135
|
+
var _a2;
|
|
136
|
+
const policyRepo = context.db.getRepository("agentGovernancePolicies");
|
|
137
|
+
const configured = await policyRepo.count({ filter: { currentVersionId: { $ne: null } } });
|
|
138
|
+
const binding = await context.db.getRepository("agentGovernancePromptBindings").findOne({ filter: { userId, employeeUsername } });
|
|
139
|
+
if (!configured && !binding) return next();
|
|
140
|
+
if (department.status === "departments_unavailable") {
|
|
141
|
+
const departmentPolicies = await policyRepo.count({
|
|
142
|
+
filter: { scope: "department", currentVersionId: { $ne: null } }
|
|
143
|
+
});
|
|
144
|
+
if (departmentPolicies) quotaError(context, "AI governance cannot check department policies.");
|
|
145
|
+
}
|
|
146
|
+
const storedEmployee = valueString((0, import_record_utils.read)(conversation, "aiEmployeeUsername"));
|
|
147
|
+
if (storedEmployee && storedEmployee !== employeeUsername) {
|
|
148
|
+
const [requestedPolicies, storedPolicies, storedBinding] = await Promise.all([
|
|
149
|
+
service.activePolicies(userId, employeeUsername, department.departmentId, void 0, void 0, true),
|
|
150
|
+
service.activePolicies(userId, storedEmployee, department.departmentId, void 0, void 0, true),
|
|
151
|
+
context.db.getRepository("agentGovernancePromptBindings").findOne({ filter: { userId, employeeUsername: storedEmployee } })
|
|
152
|
+
]);
|
|
153
|
+
if (requestedPolicies.length || storedPolicies.length || binding || storedBinding) {
|
|
154
|
+
quotaError(context, "The AI employee must match the conversation for managed usage.");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let policies = [];
|
|
158
|
+
let modelKey = "";
|
|
159
|
+
if (configured) {
|
|
160
|
+
const aiPlugin = context.app.pm.get("ai");
|
|
161
|
+
if (!((_a2 = aiPlugin == null ? void 0 : aiPlugin.aiEmployeesManager) == null ? void 0 : _a2.resolveModel))
|
|
162
|
+
quotaError(context, "AI governance could not resolve the model.");
|
|
163
|
+
const rawModel = values.model;
|
|
164
|
+
const requestedModel = rawModel && typeof rawModel === "object" && typeof rawModel.llmService === "string" && typeof rawModel.model === "string" ? { llmService: rawModel.llmService, model: rawModel.model } : void 0;
|
|
165
|
+
const model = await aiPlugin.aiEmployeesManager.resolveModel(employee, requestedModel);
|
|
166
|
+
if (!(model == null ? void 0 : model.llmService) || !(model == null ? void 0 : model.model)) quotaError(context, "AI governance could not resolve the model.");
|
|
167
|
+
modelKey = `${model.llmService}:${model.model}`;
|
|
168
|
+
policies = await service.activePolicies(userId, employeeUsername, department.departmentId, void 0, modelKey);
|
|
169
|
+
}
|
|
170
|
+
for (const policy of policies) {
|
|
171
|
+
if (policy.scope === "employee" && policy.settings.systemPrompt !== void 0 && ((0, import_record_utils.read)(employee, "about") ?? null) !== policy.settings.systemPrompt) {
|
|
172
|
+
quotaError(context, "The managed AI employee prompt changed and needs administrator review.");
|
|
173
|
+
}
|
|
174
|
+
if (policy.settings.allow === false || policy.settings.allowedModels && !policy.settings.allowedModels.includes(modelKey)) {
|
|
175
|
+
quotaError(context, "Your AI employee or model is not allowed by governance policy.");
|
|
176
|
+
}
|
|
177
|
+
await checkObservedQuota(context, policy, userId, department.departmentId);
|
|
178
|
+
}
|
|
179
|
+
const prompt = await service.preview({ userId, employeeUsername });
|
|
180
|
+
if (prompt.instruction || binding) {
|
|
181
|
+
if (!prompt.instruction || prompt.promptMode !== "default" || !binding) {
|
|
182
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
183
|
+
}
|
|
184
|
+
const expected = (0, import_node_crypto.createHash)("sha256").update(prompt.projectedPrompt).digest("hex");
|
|
185
|
+
const native = await context.db.getRepository("usersAiEmployees").findOne({ filter: { userId, aiEmployee: employeeUsername } });
|
|
186
|
+
const actual = (0, import_node_crypto.createHash)("sha256").update(valueString((0, import_record_utils.read)(native, "prompt"))).digest("hex");
|
|
187
|
+
const versions = prompt.policies.filter((policy) => {
|
|
188
|
+
var _a3;
|
|
189
|
+
return (_a3 = policy.settings.instruction) == null ? void 0 : _a3.trim();
|
|
190
|
+
}).map((policy) => ({ id: policy.id, versionId: policy.versionId }));
|
|
191
|
+
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"))) {
|
|
192
|
+
quotaError(context, "Managed AI instructions need to be applied by an administrator.");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return next();
|
|
196
|
+
};
|
|
197
|
+
return (0, import_NativeUsageAttribution.runWithNativeUsageAttribution)(
|
|
198
|
+
{
|
|
199
|
+
db: context.db,
|
|
200
|
+
userId,
|
|
201
|
+
sessionId,
|
|
202
|
+
...department.status === "resolved" && department.departmentId != null ? { departmentId: department.departmentId } : {}
|
|
203
|
+
},
|
|
204
|
+
run
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
209
|
+
0 && (module.exports = {
|
|
210
|
+
createGovernanceAdmission
|
|
211
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
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 HarnessCapabilities_exports = {};
|
|
28
|
+
__export(HarnessCapabilities_exports, {
|
|
29
|
+
getHarnessCapabilities: () => getHarnessCapabilities
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(HarnessCapabilities_exports);
|
|
32
|
+
const scopes = ["chat", "api", "workflow", "sub-agent"];
|
|
33
|
+
const unsupportedForEveryScope = (reasonKey) => Object.fromEntries(scopes.map((scope) => [scope, { status: "unsupported", reasonKey }]));
|
|
34
|
+
function getHarnessCapabilities() {
|
|
35
|
+
const nativeCapabilities = [
|
|
36
|
+
{
|
|
37
|
+
id: "tool-access",
|
|
38
|
+
labelKey: "Native tool access and approval",
|
|
39
|
+
settings: ["tools.allow", "tools.ask", "tools.deny", "tools.escalate"],
|
|
40
|
+
byScope: unsupportedForEveryScope("Harness capability: no native tool gate")
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "runtime-limits",
|
|
44
|
+
labelKey: "Native runtime limits",
|
|
45
|
+
settings: ["tools.timeouts", "limits.*"],
|
|
46
|
+
byScope: unsupportedForEveryScope("Harness capability: no native runtime limit gate")
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "delegation",
|
|
50
|
+
labelKey: "Native delegation controls",
|
|
51
|
+
settings: ["delegation.*"],
|
|
52
|
+
byScope: unsupportedForEveryScope("Harness capability: core owns delegation")
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "memory-context",
|
|
56
|
+
labelKey: "Native memory and context controls",
|
|
57
|
+
settings: ["memory.*", "context.*"],
|
|
58
|
+
byScope: unsupportedForEveryScope("Harness capability: no native context extension")
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "isolation",
|
|
62
|
+
labelKey: "Native worktree and network isolation",
|
|
63
|
+
settings: ["isolation.*"],
|
|
64
|
+
byScope: unsupportedForEveryScope("Harness capability: native isolation unsupported")
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "flow-monitoring",
|
|
68
|
+
labelKey: "Native execution flow monitoring",
|
|
69
|
+
settings: ["observability.enabled"],
|
|
70
|
+
byScope: {
|
|
71
|
+
chat: { status: "observe-only", reasonKey: "Harness capability: chat monitoring scope" },
|
|
72
|
+
api: { status: "observe-only", reasonKey: "Harness capability: API monitoring scope" },
|
|
73
|
+
workflow: { status: "observe-only", reasonKey: "Harness capability: workflow monitoring scope" },
|
|
74
|
+
"sub-agent": { status: "observe-only", reasonKey: "Harness capability: sub-agent monitoring scope" }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
const scopedCapabilities = [
|
|
79
|
+
{
|
|
80
|
+
id: "skill-hub-timeout",
|
|
81
|
+
labelKey: "Skill Hub sandbox timeout cap",
|
|
82
|
+
settings: ["tools.timeouts[skill tool]", "tools.timeouts.skill_hub_execute"],
|
|
83
|
+
status: "enforced",
|
|
84
|
+
scopeKey: "Skill Hub sandbox execution",
|
|
85
|
+
detailKey: "Harness capability: Skill Hub timeout behavior"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "skill-hub-output-spill",
|
|
89
|
+
labelKey: "Skill Hub inline output spill",
|
|
90
|
+
settings: ["context.spill.maxInlineBytes"],
|
|
91
|
+
status: "observe-only",
|
|
92
|
+
scopeKey: "Skill Hub sandbox execution",
|
|
93
|
+
detailKey: "Harness capability: Skill Hub output spill behavior"
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
return {
|
|
97
|
+
version: 1,
|
|
98
|
+
scopes,
|
|
99
|
+
nativeCapabilities,
|
|
100
|
+
scopedCapabilities,
|
|
101
|
+
telemetrySettings: {
|
|
102
|
+
settings: [
|
|
103
|
+
"observability.enabled",
|
|
104
|
+
"observability.captureInputs",
|
|
105
|
+
"observability.captureOutputs",
|
|
106
|
+
"observability.redactSecrets",
|
|
107
|
+
"observability.sharing",
|
|
108
|
+
"observability.tracingRetentionDays"
|
|
109
|
+
],
|
|
110
|
+
noteKey: "Harness capability: telemetry settings scope"
|
|
111
|
+
},
|
|
112
|
+
noteKey: "Harness capability: native enforcement boundary"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
getHarnessCapabilities
|
|
118
|
+
});
|
|
@@ -152,15 +152,26 @@ class LoopBudgetService {
|
|
|
152
152
|
toolCallCount: storedCount((0, import_record_utils.read)(run, "toolCallCount"), "Run tool call") + delta.toolCalls,
|
|
153
153
|
delegationCount: storedCount((0, import_record_utils.read)(run, "delegationCount"), "Run delegation") + delta.delegations,
|
|
154
154
|
verificationCount: storedCount((0, import_record_utils.read)(run, "verificationCount"), "Run verification") + delta.verifications,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
...input.delta.inputTokens === void 0 ? {} : {
|
|
156
|
+
totalInputTokens: (0, import_record_utils.read)(run, "totalInputTokens") == null && (0, import_record_utils.read)(run, "usageStatus") ? null : storedCount((0, import_record_utils.read)(run, "totalInputTokens"), "Run input token") + delta.inputTokens
|
|
157
|
+
},
|
|
158
|
+
...input.delta.outputTokens === void 0 ? {} : {
|
|
159
|
+
totalOutputTokens: (0, import_record_utils.read)(run, "totalOutputTokens") == null && (0, import_record_utils.read)(run, "usageStatus") ? null : storedCount((0, import_record_utils.read)(run, "totalOutputTokens"), "Run output token") + delta.outputTokens
|
|
160
|
+
},
|
|
161
|
+
...input.delta.totalTokens === void 0 && input.delta.inputTokens === void 0 && input.delta.outputTokens === void 0 ? {} : {
|
|
162
|
+
totalTokens: (0, import_record_utils.read)(run, "totalTokens") == null && (0, import_record_utils.read)(run, "usageStatus") ? null : storedCount((0, import_record_utils.read)(run, "totalTokens"), "Run total token") + delta.totalTokens
|
|
163
|
+
},
|
|
164
|
+
...input.delta.cost === void 0 ? {} : {
|
|
165
|
+
totalCost: (0, import_record_utils.read)(run, "totalCost") == null && (0, import_record_utils.read)(run, "pricingStatus") ? null : storedCost((0, import_record_utils.read)(run, "totalCost"), "Run cost") + delta.cost
|
|
166
|
+
}
|
|
159
167
|
},
|
|
160
168
|
transaction
|
|
161
169
|
});
|
|
170
|
+
const bucketId = (0, import_record_utils.read)(bucket, "id");
|
|
171
|
+
if (typeof bucketId !== "string" && typeof bucketId !== "number")
|
|
172
|
+
throw new Error("Daily usage bucket has no identifier.");
|
|
162
173
|
await buckets.update({
|
|
163
|
-
filterByTk:
|
|
174
|
+
filterByTk: bucketId,
|
|
164
175
|
values: {
|
|
165
176
|
invocationCount: storedCount((0, import_record_utils.read)(bucket, "invocationCount"), "Daily invocation") + delta.invocations,
|
|
166
177
|
toolCallCount: storedCount((0, import_record_utils.read)(bucket, "toolCallCount"), "Daily tool call") + delta.toolCalls,
|
|
@@ -177,6 +188,17 @@ class LoopBudgetService {
|
|
|
177
188
|
}
|
|
178
189
|
assertRunBudget(run, policy, delta) {
|
|
179
190
|
const limits = policy.perRun;
|
|
191
|
+
const hasInvocations = storedCount((0, import_record_utils.read)(run, "invocationCount"), "Run invocation") > 0;
|
|
192
|
+
const usageStatus = String((0, import_record_utils.read)(run, "usageStatus") || "");
|
|
193
|
+
const pricingStatus = String((0, import_record_utils.read)(run, "pricingStatus") || "");
|
|
194
|
+
const incompleteSessions = (0, import_record_utils.read)(run, "usageIncompleteSessions");
|
|
195
|
+
const hasIncompleteSessions = Array.isArray(incompleteSessions) && incompleteSessions.length > 0;
|
|
196
|
+
if (limits.maxTokens !== null && (hasIncompleteSessions || usageStatus === "partial" || usageStatus === "missing" || (0, import_record_utils.read)(run, "totalTokens") == null && (usageStatus || hasInvocations))) {
|
|
197
|
+
throw new Error("Per-run token usage is unavailable for the configured budget.");
|
|
198
|
+
}
|
|
199
|
+
if (limits.maxCost !== null && (hasIncompleteSessions || pricingStatus === "unpriced" || pricingStatus === "non_usd" || (0, import_record_utils.read)(run, "totalCost") == null && (pricingStatus || hasInvocations))) {
|
|
200
|
+
throw new Error("Per-run model cost is unavailable for the configured budget.");
|
|
201
|
+
}
|
|
180
202
|
exceeds(
|
|
181
203
|
storedCount((0, import_record_utils.read)(run, "invocationCount"), "Run invocation"),
|
|
182
204
|
delta.invocations,
|
|
@@ -238,6 +260,7 @@ class LoopBudgetService {
|
|
|
238
260
|
exceeds(storedCost((0, import_record_utils.read)(bucket, "totalCost"), "Daily cost"), delta.cost, limits.maxCost, "Daily cost");
|
|
239
261
|
}
|
|
240
262
|
assertGlobalDailyBudget(buckets, control, delta) {
|
|
263
|
+
const globalCostLimit = storedLimit((0, import_record_utils.read)(control, "dailyMaxCost"), "Global daily cost");
|
|
241
264
|
const currentTokens = buckets.reduce(
|
|
242
265
|
(total, bucket) => total + storedCount((0, import_record_utils.read)(bucket, "totalTokens"), "Daily total token"),
|
|
243
266
|
0
|
|
@@ -252,12 +275,7 @@ class LoopBudgetService {
|
|
|
252
275
|
storedLimit((0, import_record_utils.read)(control, "dailyMaxTokens"), "Global daily token"),
|
|
253
276
|
"Global daily token"
|
|
254
277
|
);
|
|
255
|
-
exceeds(
|
|
256
|
-
currentCost,
|
|
257
|
-
delta.cost,
|
|
258
|
-
storedLimit((0, import_record_utils.read)(control, "dailyMaxCost"), "Global daily cost"),
|
|
259
|
-
"Global daily cost"
|
|
260
|
-
);
|
|
278
|
+
exceeds(currentCost, delta.cost, globalCostLimit, "Global daily cost");
|
|
261
279
|
}
|
|
262
280
|
}
|
|
263
281
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -110,7 +110,13 @@ class LoopRunRepository {
|
|
|
110
110
|
const pageSize = 5e3;
|
|
111
111
|
const ids = [];
|
|
112
112
|
for (let page = 1; ; page += 1) {
|
|
113
|
-
const rows = await repository.find({
|
|
113
|
+
const rows = await repository.find({
|
|
114
|
+
filter,
|
|
115
|
+
fields: ["id"],
|
|
116
|
+
sort: ["id"],
|
|
117
|
+
offset: (page - 1) * pageSize,
|
|
118
|
+
limit: pageSize
|
|
119
|
+
});
|
|
114
120
|
for (const row of rows) {
|
|
115
121
|
ids.push(positiveId((0, import_record_utils.read)(row, "id"), "Agent loop run"));
|
|
116
122
|
}
|
|
@@ -124,11 +130,11 @@ class LoopRunRepository {
|
|
|
124
130
|
const rootRunId = typeof run.rootRunId === "string" ? run.rootRunId : "";
|
|
125
131
|
const [steps, events, spans, artifacts, approvals, skillExecutions] = await Promise.all([
|
|
126
132
|
this.database.getRepository("agentLoopSteps").find({ filter: { runId: id }, sort: ["index", "createdAt"] }),
|
|
127
|
-
this.database.getRepository("agentLoopEvents").find({ filter: { runId: id }, sort: ["id"],
|
|
128
|
-
this.database.getRepository("agentExecutionSpans").find({ filter: { agentLoopRunId: id }, sort: ["createdAt"],
|
|
133
|
+
this.database.getRepository("agentLoopEvents").find({ filter: { runId: id }, sort: ["id"], limit: 1e3 }),
|
|
134
|
+
this.database.getRepository("agentExecutionSpans").find({ filter: { agentLoopRunId: id }, sort: ["createdAt"], limit: 1e3 }),
|
|
129
135
|
this.database.getRepository("agentLoopArtifacts").find({ filter: { runId: id }, sort: ["createdAt"] }),
|
|
130
136
|
this.database.getRepository("agentLoopActionApprovals").find({ filter: { runId: id }, sort: ["createdAt"] }),
|
|
131
|
-
this.database.getRepository("skillExecutions") ? this.database.getRepository("skillExecutions").find({ filter: { agentLoopRunId: String(id) }, sort: ["createdAt"],
|
|
137
|
+
this.database.getRepository("skillExecutions") ? this.database.getRepository("skillExecutions").find({ filter: { agentLoopRunId: String(id) }, sort: ["createdAt"], limit: 1e3 }) : []
|
|
132
138
|
]);
|
|
133
139
|
return {
|
|
134
140
|
run: {
|
|
@@ -209,12 +215,15 @@ class LoopRunRepository {
|
|
|
209
215
|
const remaining = await approvals.find({ filter: { runId, status: "pending" }, transaction });
|
|
210
216
|
let requeued = false;
|
|
211
217
|
let event = null;
|
|
212
|
-
if (!remaining.length
|
|
218
|
+
if (!remaining.length) {
|
|
213
219
|
await runs.update({
|
|
214
220
|
filterByTk: runId,
|
|
215
|
-
|
|
221
|
+
// A paused run keeps its pause but must be ready to consume decisions when the owner resumes it.
|
|
222
|
+
values: { approvalStatus: "decided", ...run.status === "waiting_approval" ? { status: "queued" } : {} },
|
|
216
223
|
transaction
|
|
217
224
|
});
|
|
225
|
+
}
|
|
226
|
+
if (!remaining.length && run.status === "waiting_approval") {
|
|
218
227
|
const created = await this.database.getRepository("agentLoopEvents").create({
|
|
219
228
|
values: {
|
|
220
229
|
runId,
|
|
@@ -75,7 +75,7 @@ const transitions = {
|
|
|
75
75
|
"canceled"
|
|
76
76
|
]),
|
|
77
77
|
waiting_approval: /* @__PURE__ */ new Set(["queued", "running", "waiting_human", "paused", "blocked", "failed", "canceled"]),
|
|
78
|
-
verifying: /* @__PURE__ */ new Set(["running", "waiting_human", "paused", "blocked", "succeeded", "failed", "canceled"]),
|
|
78
|
+
verifying: /* @__PURE__ */ new Set(["queued", "running", "waiting_human", "paused", "blocked", "succeeded", "failed", "canceled"]),
|
|
79
79
|
waiting_human: /* @__PURE__ */ new Set(["running", "succeeded", "failed", "canceled"]),
|
|
80
80
|
paused: /* @__PURE__ */ new Set(["queued", "preparing", "running", "waiting_approval", "verifying", "blocked", "canceled"]),
|
|
81
81
|
blocked: /* @__PURE__ */ new Set(["queued", "waiting_human", "failed", "canceled"]),
|
|
@@ -163,14 +163,25 @@ class LoopRunStateMachine {
|
|
|
163
163
|
if (!leaseIsReclaimable(candidate, now)) continue;
|
|
164
164
|
const runId = asPositiveInteger((0, import_record_utils.read)(candidate, "id"), "Run identifier");
|
|
165
165
|
const from = asStatus((0, import_record_utils.read)(candidate, "status"));
|
|
166
|
+
const finalAnswer = (0, import_record_utils.read)(candidate, "finalAnswer");
|
|
167
|
+
const verificationRecovery = from === "verifying" && typeof finalAnswer === "string" && !!finalAnswer.trim();
|
|
168
|
+
const requiresReview = from === "verifying" && !verificationRecovery;
|
|
169
|
+
const to = requiresReview ? "waiting_human" : "queued";
|
|
170
|
+
const reason = "Verification lease expired without a saved maker summary; operator review is required.";
|
|
166
171
|
assertRunTransition({
|
|
167
172
|
from,
|
|
168
|
-
to
|
|
173
|
+
to,
|
|
169
174
|
runtimeVersion: String((0, import_record_utils.read)(candidate, "runtimeVersion") || "")
|
|
170
175
|
});
|
|
171
176
|
await runs.update({
|
|
172
177
|
filterByTk: runId,
|
|
173
|
-
values: {
|
|
178
|
+
values: {
|
|
179
|
+
status: to,
|
|
180
|
+
lockedBy: null,
|
|
181
|
+
lockedUntil: null,
|
|
182
|
+
...verificationRecovery ? { resumeContext: { kind: "verification_lease_recovery", makerSummary: finalAnswer } } : {},
|
|
183
|
+
...requiresReview ? { escalationReason: reason } : {}
|
|
184
|
+
},
|
|
174
185
|
transaction
|
|
175
186
|
});
|
|
176
187
|
const event = await this.createEvent(
|
|
@@ -178,9 +189,9 @@ class LoopRunStateMachine {
|
|
|
178
189
|
runId,
|
|
179
190
|
type: "run_lease_expired",
|
|
180
191
|
title: "Worker lease expired",
|
|
181
|
-
content: `Run returned to the queue after its ${from} worker lease expired.`,
|
|
182
|
-
status:
|
|
183
|
-
payload: { from, previousOwner: (0, import_record_utils.read)(candidate, "lockedBy") ?? null },
|
|
192
|
+
content: requiresReview ? reason : verificationRecovery ? "Run returned to the queue to resume verification of the saved maker summary." : `Run returned to the queue after its ${from} worker lease expired.`,
|
|
193
|
+
status: to,
|
|
194
|
+
payload: { from, previousOwner: (0, import_record_utils.read)(candidate, "lockedBy") ?? null, verificationRecovery, requiresReview },
|
|
184
195
|
actorType: "system",
|
|
185
196
|
actorIdentity: normalizedWorkerId,
|
|
186
197
|
correlationKey: `lease-expired:${runId}:${String((0, import_record_utils.read)(candidate, "lockedBy") || "")}`,
|
|
@@ -246,7 +257,7 @@ class LoopRunStateMachine {
|
|
|
246
257
|
continue;
|
|
247
258
|
}
|
|
248
259
|
const activePattern = await this.countActive(runs, { patternId }, transaction, now);
|
|
249
|
-
if (activePattern >= parsedPolicy.data.maxConcurrency) continue;
|
|
260
|
+
if (activePattern >= (parsedPolicy.success ? parsedPolicy.data.maxConcurrency : 0)) continue;
|
|
250
261
|
const leaseToken = `${normalizedWorkerId}:${(0, import_node_crypto.randomUUID)()}`;
|
|
251
262
|
const leaseUntil = new Date(now.getTime() + leaseMs);
|
|
252
263
|
assertRunTransition({
|
|
@@ -151,7 +151,7 @@ class LoopTriggerService {
|
|
|
151
151
|
} catch (error) {
|
|
152
152
|
if (!isUniqueConstraintError(error)) throw error;
|
|
153
153
|
const existing = await this.database.getRepository("agentLoopRuns").findOne({
|
|
154
|
-
filter: { patternId: input.patternId, triggerKey }
|
|
154
|
+
filter: { patternId: input.patternId, triggerKey, userId: input.userId || null }
|
|
155
155
|
});
|
|
156
156
|
if (!existing) throw error;
|
|
157
157
|
(_c = (_a = this.logger) == null ? void 0 : _a.debug) == null ? void 0 : _c.call(
|