plugin-agent-orchestrator 1.1.8 → 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 -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 +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 -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 +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
|
@@ -32,594 +32,227 @@ __export(NativeSubAgentObserver_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(NativeSubAgentObserver_exports);
|
|
34
34
|
var import_crypto = require("crypto");
|
|
35
|
-
var import_fs = require("fs");
|
|
36
|
-
var import_path = require("path");
|
|
37
35
|
var import_ExecutionSpanService = require("./ExecutionSpanService");
|
|
38
36
|
var import_AgentMemoryContextService = require("./AgentMemoryContextService");
|
|
39
|
-
var import_TokenTracker = require("./TokenTracker");
|
|
40
|
-
var import_AgentExecutionContext = require("./AgentExecutionContext");
|
|
41
|
-
var import_HarnessCompiler = require("./HarnessCompiler");
|
|
42
|
-
var import_harness_runtime_policy = require("./harness-runtime-policy");
|
|
43
37
|
var import_ctx_utils = require("../utils/ctx-utils");
|
|
44
|
-
const WRAP_STATE_KEY = Symbol.for("plugin-agent-orchestrator.nativeSubAgentObserver");
|
|
45
38
|
const NATIVE_SOURCE = "native-plugin-ai";
|
|
39
|
+
const WRAP_STATE_KEY = Symbol.for("plugin-agent-orchestrator.nativeSubAgentObserver");
|
|
40
|
+
function objectValue(value) {
|
|
41
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
42
|
+
}
|
|
46
43
|
function readValue(record, key) {
|
|
47
44
|
const model = record;
|
|
48
45
|
return typeof (model == null ? void 0 : model.get) === "function" ? model.get(key) : model == null ? void 0 : model[key];
|
|
49
46
|
}
|
|
50
|
-
function
|
|
47
|
+
function stringValue(value) {
|
|
51
48
|
return typeof value === "string" ? value.trim() : "";
|
|
52
49
|
}
|
|
53
|
-
function modelUsername(model) {
|
|
54
|
-
return normalizeString(readValue(model, "username")) || normalizeString(readValue(model, "aiEmployeeUsername")) || normalizeString(readValue(model, "name")) || void 0;
|
|
55
|
-
}
|
|
56
50
|
function makeNativeRunId(parts) {
|
|
57
51
|
const source = parts.map((part) => String(part || "")).join("|");
|
|
58
|
-
return
|
|
52
|
+
return "native_" + (0, import_crypto.createHash)("sha1").update(source || String(Date.now())).digest("hex").slice(0, 24);
|
|
59
53
|
}
|
|
60
|
-
function
|
|
61
|
-
return error instanceof Error ? error.message : String(error || "Unknown error");
|
|
62
|
-
}
|
|
63
|
-
function chunkBody(chunk) {
|
|
64
|
-
return (0, import_ctx_utils.asObject)(chunk.body);
|
|
65
|
-
}
|
|
66
|
-
function chunkCurrentConversation(chunk) {
|
|
67
|
-
return (0, import_ctx_utils.asObject)(chunk.currentConversation);
|
|
68
|
-
}
|
|
69
|
-
function readSkillExecutionId(result) {
|
|
70
|
-
const nestedResult = (0, import_ctx_utils.asObject)(result.result);
|
|
71
|
-
const direct = nestedResult.execId || result.execId;
|
|
72
|
-
if (typeof direct === "string" || typeof direct === "number") return direct;
|
|
73
|
-
if (typeof result.content !== "string") return void 0;
|
|
54
|
+
function errorText(error) {
|
|
74
55
|
try {
|
|
75
|
-
|
|
76
|
-
return typeof content.execId === "string" || typeof content.execId === "number" ? content.execId : void 0;
|
|
56
|
+
return error instanceof Error ? error.message : String(error || "Unknown error");
|
|
77
57
|
} catch {
|
|
78
|
-
return
|
|
58
|
+
return "Unknown error";
|
|
79
59
|
}
|
|
80
60
|
}
|
|
61
|
+
function rowAsObject(value) {
|
|
62
|
+
const record = value;
|
|
63
|
+
const resolved = typeof (record == null ? void 0 : record.toJSON) === "function" ? record.toJSON() : value;
|
|
64
|
+
return objectValue(resolved);
|
|
65
|
+
}
|
|
81
66
|
class NativeSubAgentObserver {
|
|
82
67
|
constructor(plugin) {
|
|
83
68
|
this.plugin = plugin;
|
|
84
69
|
this.spanService = new import_ExecutionSpanService.ExecutionSpanService(plugin);
|
|
85
|
-
this.
|
|
86
|
-
this.tokenTracker = new import_TokenTracker.TokenTracker(plugin);
|
|
70
|
+
this.policyService = new import_AgentMemoryContextService.AgentMemoryContextService(plugin);
|
|
87
71
|
}
|
|
88
72
|
spanService;
|
|
89
|
-
|
|
90
|
-
tokenTracker;
|
|
73
|
+
policyService;
|
|
91
74
|
install() {
|
|
92
|
-
var _a, _b
|
|
75
|
+
var _a, _b;
|
|
93
76
|
const aiPlugin = (_b = (_a = this.plugin.app.pm) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "ai");
|
|
94
|
-
const dispatcher = aiPlugin
|
|
77
|
+
const dispatcher = objectValue(aiPlugin).subAgentsDispatcher;
|
|
95
78
|
if (!(dispatcher == null ? void 0 : dispatcher.run)) {
|
|
96
|
-
(
|
|
97
|
-
_c,
|
|
98
|
-
"[AgentOrchestrator] plugin-ai subAgentsDispatcher not available; observer skipped."
|
|
99
|
-
);
|
|
79
|
+
this.warn("[AgentOrchestrator] plugin-ai subAgentsDispatcher not available; observer skipped.");
|
|
100
80
|
return false;
|
|
101
81
|
}
|
|
102
82
|
const existing = dispatcher[WRAP_STATE_KEY];
|
|
103
|
-
if ((existing == null ? void 0 : existing.wrappedRun) === dispatcher.run)
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
83
|
+
if ((existing == null ? void 0 : existing.wrappedRun) === dispatcher.run) return false;
|
|
106
84
|
const originalRun = (existing == null ? void 0 : existing.originalRun) || dispatcher.run.bind(dispatcher);
|
|
107
85
|
const observer = this;
|
|
108
86
|
const wrappedRun = async function wrappedNativeSubAgentRun(task) {
|
|
109
87
|
return observer.runObserved(originalRun, task);
|
|
110
88
|
};
|
|
111
89
|
dispatcher.run = wrappedRun;
|
|
112
|
-
dispatcher[WRAP_STATE_KEY] = {
|
|
113
|
-
|
|
114
|
-
wrappedRun
|
|
115
|
-
};
|
|
116
|
-
(_f = (_e = this.plugin.app.logger) == null ? void 0 : _e.info) == null ? void 0 : _f.call(_e, "[AgentOrchestrator] Native plugin-ai sub-agent observer installed.");
|
|
90
|
+
dispatcher[WRAP_STATE_KEY] = { originalRun, wrappedRun };
|
|
91
|
+
this.info("[AgentOrchestrator] Native plugin-ai sub-agent observer installed.");
|
|
117
92
|
return true;
|
|
118
93
|
}
|
|
119
94
|
uninstall() {
|
|
120
|
-
var _a, _b
|
|
95
|
+
var _a, _b;
|
|
121
96
|
const aiPlugin = (_b = (_a = this.plugin.app.pm) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "ai");
|
|
122
|
-
const dispatcher = aiPlugin
|
|
97
|
+
const dispatcher = objectValue(aiPlugin).subAgentsDispatcher;
|
|
123
98
|
const existing = dispatcher == null ? void 0 : dispatcher[WRAP_STATE_KEY];
|
|
124
|
-
if (!(dispatcher == null ? void 0 : dispatcher.run) || !existing || existing.wrappedRun !== dispatcher.run)
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
99
|
+
if (!(dispatcher == null ? void 0 : dispatcher.run) || !existing || existing.wrappedRun !== dispatcher.run) return false;
|
|
127
100
|
dispatcher.run = existing.originalRun;
|
|
128
101
|
delete dispatcher[WRAP_STATE_KEY];
|
|
129
|
-
|
|
102
|
+
this.info("[AgentOrchestrator] Native plugin-ai sub-agent observer uninstalled.");
|
|
130
103
|
return true;
|
|
131
104
|
}
|
|
132
105
|
async runObserved(originalRun, task) {
|
|
133
|
-
|
|
134
|
-
const settings = await this.safeResolvePolicy(task);
|
|
135
|
-
if (settings.nativeObserverEnabled === false) {
|
|
136
|
-
return originalRun(task);
|
|
137
|
-
}
|
|
138
|
-
const parentSessionId = this.resolveParentSessionId(task) || void 0;
|
|
139
|
-
const parentConversation = await this.safeFindParentConversation(task.ctx, parentSessionId);
|
|
140
|
-
const parentRunId = this.controlPlaneRunIdOf(parentConversation);
|
|
141
|
-
const parentRunHarness = parentRunId ? await this.safeResolveParentRunHarness(
|
|
142
|
-
parentRunId,
|
|
143
|
-
normalizeString(readValue(parentConversation, "aiEmployeeUsername"))
|
|
144
|
-
) : null;
|
|
145
|
-
const policy = this.compilePolicy(settings, parentRunHarness);
|
|
146
|
-
const spansEnabled = policy.observability.sharing !== "disabled";
|
|
147
|
-
const subSessionId = normalizeString(task.sessionId) || void 0;
|
|
148
|
-
const employeeUsername = modelUsername(task.employee);
|
|
149
|
-
const userId = (0, import_ctx_utils.currentUserId)(task.ctx) || ((_c = (_b = (_a = task.ctx) == null ? void 0 : _a.auth) == null ? void 0 : _b.user) == null ? void 0 : _c.id);
|
|
150
|
-
const dispatchToolMessage = await this.resolveDispatchToolMessage(task.ctx, parentSessionId, subSessionId);
|
|
151
|
-
const toolCallId = dispatchToolMessage == null ? void 0 : dispatchToolMessage.toolCallId;
|
|
152
|
-
const leaderUsername = this.leaderUsernameFor(task.ctx, parentConversation);
|
|
153
|
-
const rootRunId = makeNativeRunId([parentSessionId, subSessionId, toolCallId, employeeUsername]);
|
|
154
|
-
const delegation = await this.resolveDelegationContext(parentSessionId);
|
|
155
|
-
const childDepth = delegation.depth + 1;
|
|
156
|
-
const memory = await this.safeBuildMemoryContext({
|
|
157
|
-
userId,
|
|
158
|
-
aiEmployeeUsername: employeeUsername,
|
|
159
|
-
settings
|
|
160
|
-
});
|
|
161
|
-
const observedTask = {
|
|
162
|
-
...task,
|
|
163
|
-
// Native dispatch passes the leader conversation's skillSettings to the
|
|
164
|
-
// sub-agent. Clear that inherited filter so plugin-ai resolves tools from
|
|
165
|
-
// the sub-agent employee's own bindings instead.
|
|
166
|
-
skillSettings: void 0,
|
|
167
|
-
question: memory.context ? `${memory.context}
|
|
168
|
-
|
|
169
|
-
<agent_task>
|
|
170
|
-
${task.question}
|
|
171
|
-
</agent_task>` : task.question
|
|
172
|
-
};
|
|
173
|
-
const state = {
|
|
174
|
-
rootRunId,
|
|
175
|
-
rootStartedAt: Date.now(),
|
|
176
|
-
rootMetadata: {
|
|
177
|
-
source: NATIVE_SOURCE,
|
|
178
|
-
parentSessionId,
|
|
179
|
-
subSessionId,
|
|
180
|
-
toolCallId,
|
|
181
|
-
dispatchToolMessageId: dispatchToolMessage == null ? void 0 : dispatchToolMessage.id,
|
|
182
|
-
dispatchMessageId: dispatchToolMessage == null ? void 0 : dispatchToolMessage.messageId,
|
|
183
|
-
memoryContextApplied: Boolean(memory.context),
|
|
184
|
-
memoryScopes: memory.appliedScopes,
|
|
185
|
-
memoryContextChars: memory.chars,
|
|
186
|
-
harnessTag: settings.harnessTag || "default",
|
|
187
|
-
...parentRunId ? { agentLoopRunId: parentRunId } : {}
|
|
188
|
-
},
|
|
189
|
-
parentSessionId,
|
|
190
|
-
subSessionId,
|
|
191
|
-
toolCallId,
|
|
192
|
-
leaderUsername,
|
|
193
|
-
employeeUsername,
|
|
194
|
-
userId,
|
|
195
|
-
policy,
|
|
196
|
-
toolSpans: /* @__PURE__ */ new Map(),
|
|
197
|
-
pending: /* @__PURE__ */ new Set()
|
|
198
|
-
};
|
|
199
|
-
if (spansEnabled) {
|
|
200
|
-
await this.safeCreateRootSpan(state, task.question, {
|
|
201
|
-
depth: childDepth,
|
|
202
|
-
parentSpanId: delegation.parentSpanId,
|
|
203
|
-
agentLoopRunId: parentRunId
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const maxDepth = policy.delegation.maxDepth;
|
|
207
|
-
if (maxDepth !== null && childDepth > maxDepth) {
|
|
208
|
-
const message = `Sub-agent delegation depth ${childDepth} exceeds the harness limit of ${maxDepth}.`;
|
|
209
|
-
await this.spanService.finish(state.rootSpanId, "error", state.rootStartedAt, {
|
|
210
|
-
error: message,
|
|
211
|
-
metadata: {
|
|
212
|
-
...state.rootMetadata,
|
|
213
|
-
failedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
throw new Error(message);
|
|
217
|
-
}
|
|
218
|
-
const originalWriter = task.writer;
|
|
219
|
-
observedTask.writer = (chunk) => {
|
|
220
|
-
const pending = this.handleWriterChunk(state, chunk).catch((error) => {
|
|
221
|
-
var _a2, _b2;
|
|
222
|
-
(_b2 = (_a2 = this.plugin.app.logger) == null ? void 0 : _a2.warn) == null ? void 0 : _b2.call(_a2, "[AgentOrchestrator] Native writer observer failed", error);
|
|
223
|
-
});
|
|
224
|
-
state.pending.add(pending);
|
|
225
|
-
return originalWriter == null ? void 0 : originalWriter(chunk);
|
|
226
|
-
};
|
|
106
|
+
const startedAt = Date.now();
|
|
227
107
|
try {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
spanId: state.rootSpanId ? String(state.rootSpanId) : void 0,
|
|
232
|
-
toolCallId,
|
|
233
|
-
leaderUsername,
|
|
234
|
-
employeeUsername,
|
|
235
|
-
sessionId: subSessionId
|
|
236
|
-
},
|
|
237
|
-
() => this.runWithKnowledgeBaseAgentContext(employeeUsername, () => originalRun(observedTask))
|
|
238
|
-
);
|
|
239
|
-
const result = this.spillLargeResult(state, rawResult);
|
|
240
|
-
await this.flushPending(state);
|
|
241
|
-
const capturedOutput = this.spanOutput(state, (0, import_ctx_utils.trimText)(result, 2e4));
|
|
242
|
-
await this.spanService.finish(state.rootSpanId, "success", state.rootStartedAt, {
|
|
243
|
-
...capturedOutput !== void 0 ? { output: capturedOutput } : {},
|
|
244
|
-
metadata: {
|
|
245
|
-
...state.rootMetadata,
|
|
246
|
-
completedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
247
|
-
}
|
|
108
|
+
const result = await originalRun(task);
|
|
109
|
+
this.observeDispatch(task, "success", startedAt).catch((error) => {
|
|
110
|
+
this.warn("[AgentOrchestrator] Native dispatch telemetry failed; continuing native execution.", error);
|
|
248
111
|
});
|
|
249
|
-
await this.tokenTracker.estimateAndTrack(
|
|
250
|
-
state.rootSpanId,
|
|
251
|
-
task.question,
|
|
252
|
-
result,
|
|
253
|
-
state.rootMetadata.agentLoopRunId ? Number(state.rootMetadata.agentLoopRunId) : void 0
|
|
254
|
-
);
|
|
255
112
|
return result;
|
|
256
113
|
} catch (error) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
await this.spanService.finish(state.rootSpanId, "error", state.rootStartedAt, {
|
|
260
|
-
...capturedError !== void 0 ? { error: capturedError } : {},
|
|
261
|
-
metadata: {
|
|
262
|
-
...state.rootMetadata,
|
|
263
|
-
failedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
264
|
-
}
|
|
114
|
+
this.observeDispatch(task, "error", startedAt).catch((telemetryError) => {
|
|
115
|
+
this.warn("[AgentOrchestrator] Native dispatch telemetry failed; continuing native execution.", telemetryError);
|
|
265
116
|
});
|
|
266
|
-
await this.tokenTracker.estimateAndTrack(
|
|
267
|
-
state.rootSpanId,
|
|
268
|
-
task.question,
|
|
269
|
-
errorMessage(error),
|
|
270
|
-
state.rootMetadata.agentLoopRunId ? Number(state.rootMetadata.agentLoopRunId) : void 0
|
|
271
|
-
);
|
|
272
117
|
throw error;
|
|
273
118
|
}
|
|
274
119
|
}
|
|
275
|
-
async
|
|
276
|
-
var _a, _b;
|
|
120
|
+
async observeDispatch(task, status, startedAt) {
|
|
121
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
277
122
|
try {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
(_b =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return result;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
async safeBuildMemoryContext(options) {
|
|
338
|
-
var _a, _b;
|
|
339
|
-
try {
|
|
340
|
-
return await this.memoryService.buildContext(options);
|
|
123
|
+
const settings = await this.policyService.resolvePolicySettings(task);
|
|
124
|
+
if (settings.nativeObserverEnabled === false || ((_a = settings.observability) == null ? void 0 : _a.enabled) === false) return;
|
|
125
|
+
if (((_b = settings.observability) == null ? void 0 : _b.sharing) === "disabled") return;
|
|
126
|
+
const parentSessionId = stringValue((_f = (_e = (_d = (_c = task.ctx) == null ? void 0 : _c.action) == null ? void 0 : _d.params) == null ? void 0 : _e.values) == null ? void 0 : _f.sessionId);
|
|
127
|
+
const subSessionId = stringValue(task.sessionId);
|
|
128
|
+
const employeeUsername = stringValue(readValue(task.employee, "username")) || stringValue(readValue(task.employee, "aiEmployeeUsername")) || stringValue(readValue(task.employee, "name")) || void 0;
|
|
129
|
+
const dispatch = await this.resolveDispatch(parentSessionId, subSessionId, task.ctx.db);
|
|
130
|
+
const toolCallId = dispatch == null ? void 0 : dispatch.toolCallId;
|
|
131
|
+
if (!parentSessionId || !subSessionId || !toolCallId) return;
|
|
132
|
+
const parentConversation = await this.findOne(task.ctx.db, "aiConversations", {
|
|
133
|
+
filter: { sessionId: parentSessionId }
|
|
134
|
+
});
|
|
135
|
+
const parentSpan = await this.findParentSpan(parentConversation, parentSessionId);
|
|
136
|
+
if (!parentSpan) return;
|
|
137
|
+
const rootRunId = stringValue(parentSpan.rootRunId);
|
|
138
|
+
if (!rootRunId) return;
|
|
139
|
+
const parentSpanId = (parentSpan == null ? void 0 : parentSpan.id) === void 0 ? void 0 : String(parentSpan.id);
|
|
140
|
+
const endedAt = /* @__PURE__ */ new Date();
|
|
141
|
+
const nativeIdentity = "native:tool-call:" + toolCallId;
|
|
142
|
+
const span = await this.spanService.upsertNative(nativeIdentity, {
|
|
143
|
+
nativeIdentity,
|
|
144
|
+
rootRunId,
|
|
145
|
+
parentSpanId,
|
|
146
|
+
depth: Number(parentSpan == null ? void 0 : parentSpan.depth) + 1 || 1,
|
|
147
|
+
source: NATIVE_SOURCE,
|
|
148
|
+
parentSessionId,
|
|
149
|
+
subSessionId,
|
|
150
|
+
toolCallId,
|
|
151
|
+
type: "sub_agent",
|
|
152
|
+
status: status === "error" ? "error" : "unknown",
|
|
153
|
+
leaderUsername: stringValue(readValue(parentConversation, "aiEmployeeUsername")) || void 0,
|
|
154
|
+
employeeUsername,
|
|
155
|
+
toolName: "dispatch-sub-agent-task",
|
|
156
|
+
title: "Native sub-agent dispatch",
|
|
157
|
+
startedAt: new Date(startedAt),
|
|
158
|
+
endedAt,
|
|
159
|
+
nativeActivityAt: endedAt,
|
|
160
|
+
durationMs: Math.max(0, endedAt.getTime() - startedAt),
|
|
161
|
+
metadata: {
|
|
162
|
+
source: NATIVE_SOURCE,
|
|
163
|
+
nativeCoverage: { source: "dispatcher-return", realtime: false },
|
|
164
|
+
capturePolicy: {
|
|
165
|
+
source: "native-persistence-no-invocation-snapshot",
|
|
166
|
+
sharing: "disabled",
|
|
167
|
+
captureInputs: false,
|
|
168
|
+
captureOutputs: false,
|
|
169
|
+
redactSecrets: true
|
|
170
|
+
},
|
|
171
|
+
dispatchToolMessageId: dispatch.id,
|
|
172
|
+
dispatchMessageId: dispatch.messageId,
|
|
173
|
+
harnessTag: settings.harnessTag || "default",
|
|
174
|
+
outcome: status
|
|
175
|
+
},
|
|
176
|
+
userId: (_h = (_g = task.ctx.auth) == null ? void 0 : _g.user) == null ? void 0 : _h.id
|
|
177
|
+
});
|
|
178
|
+
if (!span) this.warn("[AgentOrchestrator] Native dispatch telemetry was not persisted.");
|
|
341
179
|
} catch (error) {
|
|
342
|
-
|
|
343
|
-
return { context: "", appliedScopes: [], chars: 0 };
|
|
180
|
+
this.warn("[AgentOrchestrator] Native dispatch telemetry failed; continuing native execution.", error);
|
|
344
181
|
}
|
|
345
182
|
}
|
|
346
|
-
async
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
source: NATIVE_SOURCE,
|
|
353
|
-
parentSessionId: state.parentSessionId,
|
|
354
|
-
subSessionId: state.subSessionId,
|
|
355
|
-
toolCallId: state.toolCallId,
|
|
356
|
-
type: "sub_agent",
|
|
357
|
-
status: "running",
|
|
358
|
-
leaderUsername: state.leaderUsername,
|
|
359
|
-
employeeUsername: state.employeeUsername,
|
|
360
|
-
toolName: "dispatch-sub-agent-task",
|
|
361
|
-
title: `${state.leaderUsername || "main"} -> ${state.employeeUsername || "sub-agent"}`,
|
|
362
|
-
input: this.spanInput(state, {
|
|
363
|
-
question,
|
|
364
|
-
parentSessionId: state.parentSessionId,
|
|
365
|
-
subSessionId: state.subSessionId
|
|
366
|
-
}),
|
|
367
|
-
metadata: state.rootMetadata,
|
|
368
|
-
userId: state.userId
|
|
369
|
-
});
|
|
370
|
-
state.rootSpanId = span == null ? void 0 : span.id;
|
|
371
|
-
}
|
|
372
|
-
runWithKnowledgeBaseAgentContext(employeeUsername, fn) {
|
|
373
|
-
var _a, _b;
|
|
374
|
-
if (!employeeUsername) return fn();
|
|
375
|
-
const knowledgeBasePlugin = (_b = (_a = this.plugin.app.pm) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "plugin-knowledge-base");
|
|
376
|
-
return (knowledgeBasePlugin == null ? void 0 : knowledgeBasePlugin.runWithAgentContext) ? knowledgeBasePlugin.runWithAgentContext(employeeUsername, fn) : fn();
|
|
377
|
-
}
|
|
378
|
-
async handleWriterChunk(state, chunk) {
|
|
379
|
-
const action = chunk.action;
|
|
380
|
-
if (action === "beforeToolCall") {
|
|
381
|
-
await this.handleBeforeToolCall(state, chunk);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (action === "afterToolCall") {
|
|
385
|
-
await this.handleAfterToolCall(state, chunk, false);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (action === "afterToolCallError") {
|
|
389
|
-
await this.handleAfterToolCall(state, chunk, true);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
if (action === "afterSubAgentInvoke") {
|
|
393
|
-
state.rootMetadata = {
|
|
394
|
-
...state.rootMetadata,
|
|
395
|
-
afterSubAgentInvokeAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
396
|
-
};
|
|
397
|
-
await this.spanService.update(state.rootSpanId, { metadata: state.rootMetadata });
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
async handleBeforeToolCall(state, chunk) {
|
|
401
|
-
if (state.policy.observability.sharing === "disabled") return;
|
|
402
|
-
const body = chunkBody(chunk);
|
|
403
|
-
const toolCall = (0, import_ctx_utils.asObject)(body.toolCall);
|
|
404
|
-
const toolCallId = normalizeString(toolCall.id);
|
|
405
|
-
if (!toolCallId || state.toolSpans.has(toolCallId)) return;
|
|
406
|
-
const conversation = chunkCurrentConversation(chunk);
|
|
407
|
-
const startedAt = Date.now();
|
|
408
|
-
const toolSpan = {
|
|
409
|
-
startedAt,
|
|
410
|
-
ready: Promise.resolve()
|
|
411
|
-
};
|
|
412
|
-
state.toolSpans.set(toolCallId, toolSpan);
|
|
413
|
-
const toolName = normalizeString(toolCall.name);
|
|
414
|
-
toolSpan.ready = this.spanService.create({
|
|
415
|
-
rootRunId: state.rootRunId,
|
|
416
|
-
parentSpanId: state.rootSpanId ? String(state.rootSpanId) : void 0,
|
|
417
|
-
source: NATIVE_SOURCE,
|
|
418
|
-
parentSessionId: state.parentSessionId || void 0,
|
|
419
|
-
subSessionId: normalizeString(conversation.sessionId) || state.subSessionId || void 0,
|
|
420
|
-
toolCallId,
|
|
421
|
-
type: toolName === "dispatch-sub-agent-task" ? "dispatch" : toolName === "skill_hub_execute" || toolName.startsWith("skill_hub_") ? "skill" : "tool",
|
|
422
|
-
status: "running",
|
|
423
|
-
leaderUsername: state.leaderUsername,
|
|
424
|
-
employeeUsername: normalizeString(conversation.username) || state.employeeUsername,
|
|
425
|
-
toolName,
|
|
426
|
-
title: toolName || "tool call",
|
|
427
|
-
input: this.spanInput(state, (0, import_ctx_utils.asObject)(toolCall.args)),
|
|
428
|
-
metadata: {
|
|
429
|
-
source: NATIVE_SOURCE,
|
|
430
|
-
currentConversation: conversation,
|
|
431
|
-
messageId: toolCall.messageId
|
|
432
|
-
},
|
|
433
|
-
userId: state.userId
|
|
434
|
-
}).then((span) => {
|
|
435
|
-
toolSpan.spanId = span == null ? void 0 : span.id;
|
|
183
|
+
async resolveDispatch(parentSessionId, subSessionId, db) {
|
|
184
|
+
if (!parentSessionId || !subSessionId) return null;
|
|
185
|
+
const messages = await this.findMany(db, "aiMessages", {
|
|
186
|
+
filter: { sessionId: parentSessionId },
|
|
187
|
+
sort: ["-messageId"],
|
|
188
|
+
limit: 100
|
|
436
189
|
});
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const status = forceError || result.status === "error" ? "error" : "success";
|
|
449
|
-
const output = result.content ?? result.result ?? result;
|
|
450
|
-
const toolName = normalizeString(toolCall.name);
|
|
451
|
-
const skillExecutionId = toolName === "skill_hub_execute" || toolName.startsWith("skill_hub_") ? readSkillExecutionId(result) : void 0;
|
|
452
|
-
const invokeStart = Number(result.invokeStartTime);
|
|
453
|
-
const invokeEnd = Number(result.invokeEndTime);
|
|
454
|
-
const durationMs = Number.isFinite(invokeStart) && Number.isFinite(invokeEnd) && invokeEnd >= invokeStart ? invokeEnd - invokeStart : Date.now() - existing.startedAt;
|
|
455
|
-
await this.spanService.update(existing.spanId, {
|
|
456
|
-
status,
|
|
457
|
-
endedAt: /* @__PURE__ */ new Date(),
|
|
458
|
-
durationMs,
|
|
459
|
-
output: forceError ? void 0 : this.spanOutput(state, (0, import_ctx_utils.trimText)(output, 2e4)),
|
|
460
|
-
error: forceError ? this.spanOutput(state, (0, import_ctx_utils.trimText)(errorMessage(error), 1e4)) : void 0,
|
|
461
|
-
skillExecutionId,
|
|
462
|
-
metadata: {
|
|
463
|
-
source: NATIVE_SOURCE,
|
|
464
|
-
toolCallResultStatus: result.status,
|
|
465
|
-
invokeStatus: result.invokeStatus,
|
|
466
|
-
messageId: toolCall.messageId
|
|
190
|
+
for (const message of messages) {
|
|
191
|
+
const relations = (0, import_ctx_utils.asObject)(readValue(message, "metadata")).subAgentConversations;
|
|
192
|
+
if (!Array.isArray(relations)) continue;
|
|
193
|
+
const relation = relations.find((value) => stringValue((0, import_ctx_utils.asObject)(value).sessionId) === subSessionId);
|
|
194
|
+
const toolCallId = stringValue((0, import_ctx_utils.asObject)(relation).toolCallId);
|
|
195
|
+
if (toolCallId) {
|
|
196
|
+
return {
|
|
197
|
+
id: void 0,
|
|
198
|
+
messageId: stringValue(readValue(message, "messageId")),
|
|
199
|
+
toolCallId
|
|
200
|
+
};
|
|
467
201
|
}
|
|
468
|
-
});
|
|
469
|
-
if (skillExecutionId && existing.spanId) {
|
|
470
|
-
await this.linkExecutionToSpan(skillExecutionId, existing.spanId);
|
|
471
202
|
}
|
|
472
|
-
await this.
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
);
|
|
203
|
+
const toolMessage = await this.findOne(db, "aiToolMessages", {
|
|
204
|
+
filter: { sessionId: parentSessionId, toolName: "dispatch-sub-agent-task" },
|
|
205
|
+
sort: ["-id"]
|
|
206
|
+
});
|
|
207
|
+
const contentSessionId = stringValue((0, import_ctx_utils.asObject)(readValue(toolMessage, "content")).sessionId);
|
|
208
|
+
return contentSessionId === subSessionId ? {
|
|
209
|
+
id: readValue(toolMessage, "id"),
|
|
210
|
+
messageId: stringValue(readValue(toolMessage, "messageId")),
|
|
211
|
+
toolCallId: stringValue(readValue(toolMessage, "toolCallId"))
|
|
212
|
+
} : null;
|
|
477
213
|
}
|
|
478
|
-
async
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
await repo.update({
|
|
484
|
-
filterByTk: skillExecutionId,
|
|
485
|
-
values: { orchestratorSpanId: spanId }
|
|
214
|
+
async findParentSpan(parentConversation, parentSessionId) {
|
|
215
|
+
const from = stringValue(readValue(parentConversation, "from"));
|
|
216
|
+
if (from === "sub-agent") {
|
|
217
|
+
return this.findOne(this.plugin.db, "agentExecutionSpans", {
|
|
218
|
+
filter: { source: NATIVE_SOURCE, type: "sub_agent", subSessionId: parentSessionId }
|
|
486
219
|
});
|
|
487
|
-
} catch (error) {
|
|
488
|
-
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] Failed to link skill execution to native span", error);
|
|
489
220
|
}
|
|
221
|
+
return this.findOne(this.plugin.db, "agentExecutionSpans", {
|
|
222
|
+
filter: { source: NATIVE_SOURCE, type: "main_agent", parentSessionId }
|
|
223
|
+
});
|
|
490
224
|
}
|
|
491
|
-
|
|
492
|
-
var _a, _b, _c;
|
|
493
|
-
const values = ((_c = (_b = (_a = task.ctx) == null ? void 0 : _a.action) == null ? void 0 : _b.params) == null ? void 0 : _c.values) || {};
|
|
494
|
-
return normalizeString(values.sessionId) || void 0;
|
|
495
|
-
}
|
|
496
|
-
leaderUsernameFor(ctx, parentConversation) {
|
|
497
|
-
var _a, _b;
|
|
498
|
-
const values = ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) || {};
|
|
499
|
-
const direct = normalizeString(values.aiEmployeeUsername) || normalizeString((0, import_ctx_utils.asObject)(values.aiEmployee).username);
|
|
500
|
-
return direct || normalizeString(readValue(parentConversation, "aiEmployeeUsername")) || void 0;
|
|
501
|
-
}
|
|
502
|
-
async safeFindParentConversation(ctx, parentSessionId) {
|
|
225
|
+
async findOne(database, name, options) {
|
|
503
226
|
var _a, _b, _c;
|
|
504
|
-
if (!parentSessionId) return null;
|
|
505
227
|
try {
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
return conversation || null;
|
|
228
|
+
const row = await ((_c = (_b = (_a = database == null ? void 0 : database.getRepository) == null ? void 0 : _a.call(database, name)) == null ? void 0 : _b.findOne) == null ? void 0 : _c.call(_b, options));
|
|
229
|
+
return row ? rowAsObject(row) : null;
|
|
509
230
|
} catch {
|
|
510
231
|
return null;
|
|
511
232
|
}
|
|
512
233
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
return Number.isSafeInteger(runId) && runId > 0 ? runId : void 0;
|
|
516
|
-
}
|
|
517
|
-
async safeResolveParentRunHarness(runId, parentUsername) {
|
|
518
|
-
var _a, _b;
|
|
519
|
-
if (!parentUsername) return null;
|
|
234
|
+
async findMany(database, name, options) {
|
|
235
|
+
var _a, _b, _c;
|
|
520
236
|
try {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
return
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
// The parent's persisted span is the authoritative depth source: it was recorded when the
|
|
528
|
-
// parent itself was dispatched, so a resumed child arrives with its true depth even though its
|
|
529
|
-
// in-process context is fresh. The runtime context can only confirm or deepen the count, never
|
|
530
|
-
// lower it.
|
|
531
|
-
async resolveDelegationContext(parentSessionId) {
|
|
532
|
-
var _a;
|
|
533
|
-
const candidates = [];
|
|
534
|
-
const context = (0, import_AgentExecutionContext.getAgentExecutionContext)();
|
|
535
|
-
if (context == null ? void 0 : context.spanId) {
|
|
536
|
-
const span = await this.safeFindSpan({ filterByTk: context.spanId });
|
|
537
|
-
if (span) candidates.push(span);
|
|
538
|
-
}
|
|
539
|
-
if (parentSessionId) {
|
|
540
|
-
const span = await this.safeFindSpan({
|
|
541
|
-
filter: { subSessionId: parentSessionId, type: "sub_agent" },
|
|
542
|
-
sort: ["-id"]
|
|
543
|
-
});
|
|
544
|
-
if (span) candidates.push(span);
|
|
237
|
+
const rows = await ((_c = (_b = (_a = database == null ? void 0 : database.getRepository) == null ? void 0 : _a.call(database, name)) == null ? void 0 : _b.find) == null ? void 0 : _c.call(_b, options));
|
|
238
|
+
return Array.isArray(rows) ? rows.map(rowAsObject) : [];
|
|
239
|
+
} catch {
|
|
240
|
+
return [];
|
|
545
241
|
}
|
|
546
|
-
const depth = candidates.reduce((deepest, span) => Math.max(deepest, Number(span.depth) || 0), 0);
|
|
547
|
-
const parentSpanId = (_a = candidates.find((span) => span.id !== void 0)) == null ? void 0 : _a.id;
|
|
548
|
-
return { parentSpanId: parentSpanId === void 0 ? void 0 : String(parentSpanId), depth };
|
|
549
242
|
}
|
|
550
|
-
|
|
243
|
+
info(message) {
|
|
551
244
|
var _a, _b;
|
|
552
245
|
try {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return await repo.findOne(options) || null;
|
|
556
|
-
} catch (error) {
|
|
557
|
-
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] Failed to resolve delegation parent span", error);
|
|
558
|
-
return null;
|
|
246
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.info) == null ? void 0 : _b.call(_a, message);
|
|
247
|
+
} catch {
|
|
559
248
|
}
|
|
560
249
|
}
|
|
561
|
-
|
|
562
|
-
var _a, _b
|
|
563
|
-
if (!parentSessionId) return null;
|
|
250
|
+
warn(message, error) {
|
|
251
|
+
var _a, _b;
|
|
564
252
|
try {
|
|
565
|
-
|
|
566
|
-
if (fromMetadata) {
|
|
567
|
-
return fromMetadata;
|
|
568
|
-
}
|
|
569
|
-
const repo = (_b = (_a = ctx.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "aiToolMessages");
|
|
570
|
-
const record = await ((_c = repo == null ? void 0 : repo.findOne) == null ? void 0 : _c.call(repo, {
|
|
571
|
-
filter: {
|
|
572
|
-
sessionId: parentSessionId,
|
|
573
|
-
toolName: "dispatch-sub-agent-task",
|
|
574
|
-
invokeStatus: {
|
|
575
|
-
$ne: "confirmed"
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
sort: ["-id"]
|
|
579
|
-
}));
|
|
580
|
-
return (0, import_ctx_utils.toPlain)(record);
|
|
253
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, message, { error });
|
|
581
254
|
} catch {
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
async resolveDispatchToolMessageFromMetadata(ctx, parentSessionId, subSessionId) {
|
|
586
|
-
var _a, _b, _c, _d, _e, _f;
|
|
587
|
-
if (!parentSessionId || !subSessionId) return null;
|
|
588
|
-
const messageRepo = (_b = (_a = ctx.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "aiMessages");
|
|
589
|
-
const toolRepo = (_d = (_c = ctx.db) == null ? void 0 : _c.getRepository) == null ? void 0 : _d.call(_c, "aiToolMessages");
|
|
590
|
-
const messages = await ((_e = messageRepo == null ? void 0 : messageRepo.find) == null ? void 0 : _e.call(messageRepo, {
|
|
591
|
-
filter: { sessionId: parentSessionId },
|
|
592
|
-
sort: ["-messageId"],
|
|
593
|
-
limit: 20
|
|
594
|
-
}));
|
|
595
|
-
if (!Array.isArray(messages)) return null;
|
|
596
|
-
for (const rawMessage of messages) {
|
|
597
|
-
const message = (0, import_ctx_utils.toPlain)(rawMessage);
|
|
598
|
-
const conversations = (0, import_ctx_utils.asObject)(message == null ? void 0 : message.metadata).subAgentConversations;
|
|
599
|
-
if (!Array.isArray(conversations)) continue;
|
|
600
|
-
const matched = conversations.find((item) => normalizeString(item == null ? void 0 : item.sessionId) === subSessionId);
|
|
601
|
-
const toolCallId = normalizeString(matched == null ? void 0 : matched.toolCallId);
|
|
602
|
-
if (!toolCallId) continue;
|
|
603
|
-
const toolMessage = await ((_f = toolRepo == null ? void 0 : toolRepo.findOne) == null ? void 0 : _f.call(toolRepo, {
|
|
604
|
-
filter: {
|
|
605
|
-
sessionId: parentSessionId,
|
|
606
|
-
toolCallId
|
|
607
|
-
}
|
|
608
|
-
}));
|
|
609
|
-
return {
|
|
610
|
-
...(0, import_ctx_utils.toPlain)(toolMessage) || {},
|
|
611
|
-
toolCallId,
|
|
612
|
-
messageId: readValue(toolMessage, "messageId") || (message == null ? void 0 : message.messageId),
|
|
613
|
-
sessionId: parentSessionId,
|
|
614
|
-
status: matched == null ? void 0 : matched.status
|
|
615
|
-
};
|
|
616
255
|
}
|
|
617
|
-
return null;
|
|
618
|
-
}
|
|
619
|
-
async flushPending(state) {
|
|
620
|
-
const pending = Array.from(state.pending);
|
|
621
|
-
if (!pending.length) return;
|
|
622
|
-
await Promise.allSettled(pending);
|
|
623
256
|
}
|
|
624
257
|
}
|
|
625
258
|
// Annotate the CommonJS export names for ESM import in node:
|