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
|
@@ -0,0 +1,691 @@
|
|
|
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
|
+
import { ExecutionSpanService } from './ExecutionSpanService';
|
|
11
|
+
import { makeNativeRunId, NATIVE_SOURCE } from './NativeSubAgentObserver';
|
|
12
|
+
import { TokenTracker, usageFromAIUsageEvent } from './TokenTracker';
|
|
13
|
+
import { resolveTracingRetentionDays } from './TracingRetentionPolicy';
|
|
14
|
+
import { asObject, toPlain } from '../utils/ctx-utils';
|
|
15
|
+
|
|
16
|
+
type NativeRecord = Record<string, unknown> & { get?: (key: string) => unknown };
|
|
17
|
+
|
|
18
|
+
type NativeRepository = {
|
|
19
|
+
create: (options: Record<string, unknown>) => Promise<unknown>;
|
|
20
|
+
update: (options: Record<string, unknown>) => Promise<unknown>;
|
|
21
|
+
find?: (options?: Record<string, unknown>) => Promise<unknown[]>;
|
|
22
|
+
findOne?: (options?: Record<string, unknown>) => Promise<unknown>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type NativePlugin = {
|
|
26
|
+
app: {
|
|
27
|
+
logger?: {
|
|
28
|
+
warn?: (
|
|
29
|
+
message: string,
|
|
30
|
+
meta?: { module?: string; submodule?: string; method?: string; [key: string]: unknown },
|
|
31
|
+
) => void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
db: { getRepository: (name: string) => NativeRepository | undefined };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type PageCursor = { after?: string; done?: boolean };
|
|
38
|
+
type NativeCursor = {
|
|
39
|
+
version: 2;
|
|
40
|
+
conversations: PageCursor;
|
|
41
|
+
messages: PageCursor;
|
|
42
|
+
toolMessages: PageCursor;
|
|
43
|
+
usageEvents: PageCursor;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type SyncPage = { rows: NativeRecord[]; hasMore: boolean };
|
|
47
|
+
|
|
48
|
+
type SyncCounts = {
|
|
49
|
+
conversations: number;
|
|
50
|
+
messages: number;
|
|
51
|
+
linkedSubAgents: number;
|
|
52
|
+
toolMessages: number;
|
|
53
|
+
modelCalls: number;
|
|
54
|
+
skipped: number;
|
|
55
|
+
correlationIncomplete: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const MAX_PAGE_SIZE = 1000;
|
|
59
|
+
const MAX_RELATIONS_PER_MESSAGE = 100;
|
|
60
|
+
const DISABLED_NATIVE_CAPTURE = {
|
|
61
|
+
source: 'native-persistence-no-invocation-snapshot',
|
|
62
|
+
sharing: 'disabled',
|
|
63
|
+
captureInputs: false,
|
|
64
|
+
captureOutputs: false,
|
|
65
|
+
redactSecrets: true,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function recordOf(value: unknown): NativeRecord {
|
|
69
|
+
const plain = toPlain(value);
|
|
70
|
+
return plain && typeof plain === 'object' && !Array.isArray(plain) ? (plain as NativeRecord) : {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function stringValue(value: unknown) {
|
|
74
|
+
if (typeof value === 'string') return value.trim();
|
|
75
|
+
if (typeof value === 'number' || typeof value === 'bigint') return String(value);
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function nativeRootIdentity(sessionId: string) {
|
|
80
|
+
return 'native:conversation:' + sessionId;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function nativeToolIdentity(toolCallId: string) {
|
|
84
|
+
return 'native:tool-call:' + toolCallId;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function sessionRootRunId(sessionId: string) {
|
|
88
|
+
return makeNativeRunId(['main', sessionId]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function parseDate(value: unknown) {
|
|
92
|
+
if (value instanceof Date) return Number.isFinite(value.getTime()) ? value : undefined;
|
|
93
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
94
|
+
const date = new Date(typeof value === 'string' && /^\d{12,}$/.test(value) ? Number(value) : value);
|
|
95
|
+
return Number.isFinite(date.getTime()) ? date : undefined;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function latestDate(...values: unknown[]) {
|
|
101
|
+
const dates = values.map(parseDate).filter((date): date is Date => Boolean(date));
|
|
102
|
+
return dates.reduce<Date | undefined>((latest, date) => (!latest || date > latest ? date : latest), undefined);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function numberValue(value: unknown) {
|
|
106
|
+
if (value === null || value === undefined || value === '') return undefined;
|
|
107
|
+
const result = Number(value);
|
|
108
|
+
return Number.isFinite(result) ? result : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function isSubAgentConversation(conversation: NativeRecord) {
|
|
112
|
+
return stringValue(conversation.from) === 'sub-agent';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function statusForConversation(conversation: NativeRecord) {
|
|
116
|
+
const state = stringValue(conversation.llmActiveState).toLowerCase();
|
|
117
|
+
if (state === 'streaming' || state === 'invoking') return 'running';
|
|
118
|
+
// plugin-ai persists conversation sessions, not per-request completion records. An idle
|
|
119
|
+
// session cannot prove that its most recent invocation completed successfully or failed.
|
|
120
|
+
return 'unknown';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function statusForTool(toolMessage: NativeRecord) {
|
|
124
|
+
const invokeStatus = stringValue(toolMessage.invokeStatus).toLowerCase();
|
|
125
|
+
const resultStatus = stringValue(toolMessage.status).toLowerCase();
|
|
126
|
+
if (resultStatus === 'error' || invokeStatus === 'error' || invokeStatus === 'failed') return 'error';
|
|
127
|
+
if (invokeStatus === 'interrupted' || invokeStatus === 'waiting') return 'waiting_approval';
|
|
128
|
+
if (invokeStatus === 'done' || invokeStatus === 'confirmed') return resultStatus === 'error' ? 'error' : 'success';
|
|
129
|
+
if (invokeStatus === 'init' || invokeStatus === 'pending') return 'running';
|
|
130
|
+
return 'unknown';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function metadataForNativeProjection(extra: Record<string, unknown> = {}) {
|
|
134
|
+
return {
|
|
135
|
+
source: NATIVE_SOURCE,
|
|
136
|
+
nativeCoverage: {
|
|
137
|
+
source: 'persisted-native-records',
|
|
138
|
+
realtime: false,
|
|
139
|
+
contentCapture: 'unsupported-without-invocation-snapshot',
|
|
140
|
+
},
|
|
141
|
+
capturePolicy: DISABLED_NATIVE_CAPTURE,
|
|
142
|
+
...extra,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function parseNativeMonitorCursor(value: unknown): NativeCursor {
|
|
147
|
+
if (value == null) return { version: 2, conversations: {}, messages: {}, toolMessages: {}, usageEvents: {} };
|
|
148
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid native monitor cursor.');
|
|
149
|
+
const cursor = value as Partial<NativeCursor>;
|
|
150
|
+
if (cursor.version !== 2) throw new Error('Unsupported native monitor cursor version.');
|
|
151
|
+
const parsePage = (entry: unknown): PageCursor => {
|
|
152
|
+
const page = asObject(entry);
|
|
153
|
+
if (page.after !== undefined && (typeof page.after !== 'string' || !page.after)) {
|
|
154
|
+
throw new Error('Invalid native monitor cursor position.');
|
|
155
|
+
}
|
|
156
|
+
if (page.done !== undefined && typeof page.done !== 'boolean')
|
|
157
|
+
throw new Error('Invalid native monitor cursor state.');
|
|
158
|
+
return { ...(page.after ? { after: page.after as string } : {}), ...(page.done ? { done: true } : {}) };
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
version: 2,
|
|
162
|
+
conversations: parsePage(cursor.conversations),
|
|
163
|
+
messages: parsePage(cursor.messages),
|
|
164
|
+
toolMessages: parsePage(cursor.toolMessages),
|
|
165
|
+
usageEvents: parsePage(cursor.usageEvents),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export class NativeAgentMonitorSyncService {
|
|
170
|
+
private readonly spans: ExecutionSpanService;
|
|
171
|
+
private readonly usageTracker: TokenTracker;
|
|
172
|
+
|
|
173
|
+
constructor(private readonly plugin: NativePlugin) {
|
|
174
|
+
this.spans = new ExecutionSpanService(plugin);
|
|
175
|
+
this.usageTracker = new TokenTracker(plugin);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async sync(options: { limit?: number; cursor?: unknown; sessionId?: string } = {}) {
|
|
179
|
+
const limit = Math.min(Math.max(Math.trunc(Number(options.limit) || 200), 1), MAX_PAGE_SIZE);
|
|
180
|
+
const retentionDays = await resolveTracingRetentionDays(this.plugin);
|
|
181
|
+
const cutoff = new Date(Date.now() - retentionDays * 86400000);
|
|
182
|
+
const cursor = parseNativeMonitorCursor(options.cursor);
|
|
183
|
+
const counts: SyncCounts = {
|
|
184
|
+
conversations: 0,
|
|
185
|
+
messages: 0,
|
|
186
|
+
linkedSubAgents: 0,
|
|
187
|
+
toolMessages: 0,
|
|
188
|
+
modelCalls: 0,
|
|
189
|
+
skipped: 0,
|
|
190
|
+
correlationIncomplete: 0,
|
|
191
|
+
};
|
|
192
|
+
const pages: Record<string, { processed: number; hasMore: boolean }> = {};
|
|
193
|
+
const sessionFilter = options.sessionId ? { sessionId: options.sessionId } : {};
|
|
194
|
+
const page = async (
|
|
195
|
+
name: keyof Omit<NativeCursor, 'version'>,
|
|
196
|
+
repositoryName: string,
|
|
197
|
+
key: string,
|
|
198
|
+
filter: Record<string, unknown>,
|
|
199
|
+
project: (record: NativeRecord) => Promise<void>,
|
|
200
|
+
) => {
|
|
201
|
+
const position = cursor[name];
|
|
202
|
+
if (position.done) {
|
|
203
|
+
pages[name] = { processed: 0, hasMore: false };
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const rows = await this.fetchPage(repositoryName, {
|
|
207
|
+
filter: position.after ? { $and: [filter, { [key]: { $gt: position.after } }] } : filter,
|
|
208
|
+
sort: [key],
|
|
209
|
+
limit,
|
|
210
|
+
});
|
|
211
|
+
for (const row of rows.rows) await project(row);
|
|
212
|
+
const last = rows.rows[rows.rows.length - 1];
|
|
213
|
+
const after = last ? stringValue(last[key]) : position.after;
|
|
214
|
+
if (last && !after) throw new Error(`Native monitor source ${repositoryName} has no ${key}.`);
|
|
215
|
+
cursor[name] = { ...(after ? { after } : {}), ...(!rows.hasMore ? { done: true } : {}) };
|
|
216
|
+
pages[name] = { processed: rows.rows.length, hasMore: rows.hasMore };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
await page(
|
|
220
|
+
'conversations',
|
|
221
|
+
'aiConversations',
|
|
222
|
+
'sessionId',
|
|
223
|
+
{ ...sessionFilter, from: { $ne: 'sub-agent' } },
|
|
224
|
+
async (conversation) => {
|
|
225
|
+
const sessionId = stringValue(conversation.sessionId);
|
|
226
|
+
if (!sessionId) {
|
|
227
|
+
counts.skipped += 1;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (await this.upsertMainConversation(conversation, cutoff, counts)) counts.conversations += 1;
|
|
231
|
+
},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
await page('messages', 'aiMessages', 'messageId', sessionFilter, async (message) => {
|
|
235
|
+
counts.messages += 1;
|
|
236
|
+
counts.linkedSubAgents += await this.projectSubAgentRelations(message, counts, cutoff);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
await page('toolMessages', 'aiToolMessages', 'id', sessionFilter, async (toolMessage) => {
|
|
240
|
+
if (await this.projectToolMessage(toolMessage, counts, cutoff)) counts.toolMessages += 1;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
await page('usageEvents', 'aiUsageEvents', 'id', { ...sessionFilter, eventType: 'llm_message' }, async (event) => {
|
|
244
|
+
if (await this.projectUsageEvent(event, counts, cutoff)) counts.modelCalls += 1;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const complete =
|
|
248
|
+
cursor.conversations.done && cursor.messages.done && cursor.toolMessages.done && cursor.usageEvents.done;
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
data: {
|
|
252
|
+
coverage: {
|
|
253
|
+
source: 'persisted-native-records',
|
|
254
|
+
realtime: false,
|
|
255
|
+
granularity: 'conversation-session-and-persisted-calls',
|
|
256
|
+
note: 'Main-agent records are session-level. This is a bounded full-pass reconciliation, not a realtime or per-request trace; repeat complete passes to capture source updates and late records.',
|
|
257
|
+
contentCapture: 'omitted-without-invocation-policy-snapshot',
|
|
258
|
+
maxRelationsPerMessage: MAX_RELATIONS_PER_MESSAGE,
|
|
259
|
+
traceRetentionDays: retentionDays,
|
|
260
|
+
},
|
|
261
|
+
counts,
|
|
262
|
+
pages,
|
|
263
|
+
complete: Boolean(complete),
|
|
264
|
+
cursor: complete ? null : cursor,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async syncSession(sessionId: string) {
|
|
270
|
+
if (!sessionId) throw new Error('A native session id is required.');
|
|
271
|
+
// A single bounded page avoids unbounded work in the API lifecycle. Durable usage
|
|
272
|
+
// events and any remaining pages are recovered by a subsequent explicit full pass.
|
|
273
|
+
return this.sync({ sessionId, limit: 200 });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private async fetchPage(name: string, options: Record<string, unknown>): Promise<SyncPage> {
|
|
277
|
+
try {
|
|
278
|
+
const repository = this.plugin.db.getRepository(name);
|
|
279
|
+
if (!repository?.find) throw new Error(`Native monitor source ${name} is unavailable.`);
|
|
280
|
+
const rows = await repository.find(options);
|
|
281
|
+
const limit = Number(options.limit) || 0;
|
|
282
|
+
const values = Array.isArray(rows) ? rows.map(recordOf) : [];
|
|
283
|
+
return { rows: values, hasMore: values.length === limit };
|
|
284
|
+
} catch (error) {
|
|
285
|
+
this.warn('[AgentOrchestrator] Failed to sync native ' + name, error);
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private async resolveRunAssociation(rawRunId: unknown) {
|
|
291
|
+
const runId = numberValue(rawRunId);
|
|
292
|
+
if (!Number.isSafeInteger(runId) || !runId || runId < 0) {
|
|
293
|
+
return {
|
|
294
|
+
runId: rawRunId == null || rawRunId === '' ? undefined : null,
|
|
295
|
+
missing: rawRunId != null && rawRunId !== '',
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const run = await this.findOne('agentLoopRuns', { filterByTk: runId });
|
|
299
|
+
return run
|
|
300
|
+
? { runId, rootRunId: stringValue(run.rootRunId) || undefined, missing: false }
|
|
301
|
+
: { runId: null, missing: true };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private withinRetention(activity: Date | undefined, cutoff: Date, counts: SyncCounts) {
|
|
305
|
+
if (!activity) {
|
|
306
|
+
counts.skipped += 1;
|
|
307
|
+
counts.correlationIncomplete += 1;
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
if (activity < cutoff) {
|
|
311
|
+
counts.skipped += 1;
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private async upsertMainConversation(
|
|
318
|
+
conversation: NativeRecord,
|
|
319
|
+
cutoff: Date,
|
|
320
|
+
counts: SyncCounts,
|
|
321
|
+
minimumActivity?: Date,
|
|
322
|
+
) {
|
|
323
|
+
const sessionId = stringValue(conversation.sessionId);
|
|
324
|
+
const employeeUsername = stringValue(conversation.aiEmployeeUsername) || undefined;
|
|
325
|
+
const createdAt = parseDate(conversation.createdAt);
|
|
326
|
+
const updatedAt = parseDate(conversation.updatedAt);
|
|
327
|
+
const latestUsage = await this.findOne('aiUsageEvents', {
|
|
328
|
+
filter: { sessionId, eventType: 'llm_message' },
|
|
329
|
+
sort: ['-occurredAt'],
|
|
330
|
+
});
|
|
331
|
+
const activity = latestDate(createdAt, updatedAt, latestUsage?.occurredAt, minimumActivity);
|
|
332
|
+
if (!this.withinRetention(activity, cutoff, counts)) return null;
|
|
333
|
+
const association = await this.resolveRunAssociation(asObject(conversation.options).controlPlaneRunId);
|
|
334
|
+
if (association.missing && counts) counts.correlationIncomplete += 1;
|
|
335
|
+
const previous = await this.findOne('agentExecutionSpans', {
|
|
336
|
+
filter: { nativeIdentity: nativeRootIdentity(sessionId) },
|
|
337
|
+
});
|
|
338
|
+
const saved = await this.spans.upsertNative(nativeRootIdentity(sessionId), {
|
|
339
|
+
nativeIdentity: nativeRootIdentity(sessionId),
|
|
340
|
+
rootRunId: association.rootRunId || stringValue(previous?.rootRunId) || sessionRootRunId(sessionId),
|
|
341
|
+
agentLoopRunId: association.runId,
|
|
342
|
+
source: NATIVE_SOURCE,
|
|
343
|
+
parentSessionId: sessionId,
|
|
344
|
+
subSessionId: sessionId,
|
|
345
|
+
type: 'main_agent',
|
|
346
|
+
status: statusForConversation(conversation),
|
|
347
|
+
leaderUsername: employeeUsername,
|
|
348
|
+
employeeUsername,
|
|
349
|
+
toolName: 'native-agent-session',
|
|
350
|
+
title: 'Native agent session',
|
|
351
|
+
startedAt: createdAt || activity,
|
|
352
|
+
nativeActivityAt: activity,
|
|
353
|
+
// Idle is not proof that a session-level root completed. Keep it open-ended.
|
|
354
|
+
...(stringValue(conversation.llmActiveState) === 'completed' && updatedAt ? { endedAt: updatedAt } : {}),
|
|
355
|
+
metadata: metadataForNativeProjection({
|
|
356
|
+
nativeSessionId: sessionId,
|
|
357
|
+
nativeStatus: stringValue(conversation.llmActiveState) || 'idle',
|
|
358
|
+
category: stringValue(conversation.category) || 'chat',
|
|
359
|
+
from: stringValue(conversation.from) || 'main-agent',
|
|
360
|
+
scope: stringValue(conversation.scope) || undefined,
|
|
361
|
+
sessionGranularity: true,
|
|
362
|
+
correlationIncomplete: Boolean(conversation.orphanedUsage) || association.missing,
|
|
363
|
+
}),
|
|
364
|
+
userId: stringValue(conversation.userId) || undefined,
|
|
365
|
+
});
|
|
366
|
+
if (!saved) throw new Error('Could not persist native session projection.');
|
|
367
|
+
return saved;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private async projectSubAgentRelations(message: NativeRecord, counts: SyncCounts, cutoff: Date) {
|
|
371
|
+
const parentSessionId = stringValue(message.sessionId);
|
|
372
|
+
const relations = asObject(message.metadata).subAgentConversations;
|
|
373
|
+
if (!parentSessionId || !Array.isArray(relations)) return 0;
|
|
374
|
+
const parentConversation = await this.findOne('aiConversations', { filter: { sessionId: parentSessionId } });
|
|
375
|
+
if (!parentConversation) {
|
|
376
|
+
counts.correlationIncomplete += relations.length;
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
let projected = 0;
|
|
380
|
+
if (relations.length > MAX_RELATIONS_PER_MESSAGE) {
|
|
381
|
+
counts.correlationIncomplete += relations.length - MAX_RELATIONS_PER_MESSAGE;
|
|
382
|
+
}
|
|
383
|
+
for (const relationValue of relations.slice(0, MAX_RELATIONS_PER_MESSAGE)) {
|
|
384
|
+
const relation = asObject(relationValue);
|
|
385
|
+
const childSessionId = stringValue(relation.sessionId);
|
|
386
|
+
const toolCallId = stringValue(relation.toolCallId);
|
|
387
|
+
if (!childSessionId || !toolCallId) {
|
|
388
|
+
counts.skipped += 1;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const childConversation = await this.findOne('aiConversations', { filter: { sessionId: childSessionId } });
|
|
392
|
+
const toolMessage = await this.findOne('aiToolMessages', { filter: { toolCallId } });
|
|
393
|
+
const activity = latestDate(
|
|
394
|
+
toolMessage?.invokeEndTime,
|
|
395
|
+
toolMessage?.invokeStartTime,
|
|
396
|
+
toolMessage?.updatedAt,
|
|
397
|
+
toolMessage?.createdAt,
|
|
398
|
+
message.updatedAt,
|
|
399
|
+
message.createdAt,
|
|
400
|
+
);
|
|
401
|
+
if (!this.withinRetention(activity, cutoff, counts)) continue;
|
|
402
|
+
const parent = await this.resolveParentSpan(parentConversation, cutoff, counts, activity);
|
|
403
|
+
if (!parent) {
|
|
404
|
+
counts.correlationIncomplete += 1;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const saved = await this.spans.upsertNative(
|
|
408
|
+
nativeToolIdentity(toolCallId),
|
|
409
|
+
this.subAgentSpanValues({
|
|
410
|
+
parent,
|
|
411
|
+
parentConversation,
|
|
412
|
+
childConversation,
|
|
413
|
+
childSessionId,
|
|
414
|
+
toolCallId,
|
|
415
|
+
messageId: stringValue(message.messageId),
|
|
416
|
+
nativeStatus: stringValue(relation.status),
|
|
417
|
+
toolStatus: toolMessage ? statusForTool(toolMessage) : undefined,
|
|
418
|
+
nativeActivityAt: activity,
|
|
419
|
+
}),
|
|
420
|
+
);
|
|
421
|
+
if (!saved) throw new Error('Could not persist native sub-agent projection.');
|
|
422
|
+
projected += 1;
|
|
423
|
+
}
|
|
424
|
+
return projected;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private async projectToolMessage(toolMessage: NativeRecord, counts: SyncCounts, cutoff: Date) {
|
|
428
|
+
const toolCallId = stringValue(toolMessage.toolCallId);
|
|
429
|
+
const sessionId = stringValue(toolMessage.sessionId);
|
|
430
|
+
if (!toolCallId || !sessionId) {
|
|
431
|
+
counts.skipped += 1;
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
const activity = latestDate(
|
|
435
|
+
toolMessage.invokeEndTime,
|
|
436
|
+
toolMessage.invokeStartTime,
|
|
437
|
+
toolMessage.updatedAt,
|
|
438
|
+
toolMessage.createdAt,
|
|
439
|
+
);
|
|
440
|
+
if (!this.withinRetention(activity, cutoff, counts)) return false;
|
|
441
|
+
const parentConversation = await this.findOne('aiConversations', { filter: { sessionId } });
|
|
442
|
+
if (!parentConversation) {
|
|
443
|
+
counts.correlationIncomplete += 1;
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
const parent = await this.resolveParentSpan(parentConversation, cutoff, counts, activity);
|
|
447
|
+
if (!parent) {
|
|
448
|
+
counts.correlationIncomplete += 1;
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const message = await this.findOne('aiMessages', {
|
|
453
|
+
filter: { sessionId, messageId: stringValue(toolMessage.messageId) },
|
|
454
|
+
});
|
|
455
|
+
const child = this.findSubAgentRelation(message, toolCallId);
|
|
456
|
+
const childSessionId = stringValue(child?.sessionId || asObject(toolMessage.content).sessionId);
|
|
457
|
+
const childConversation = childSessionId
|
|
458
|
+
? await this.findOne('aiConversations', { filter: { sessionId: childSessionId } })
|
|
459
|
+
: null;
|
|
460
|
+
const toolName = stringValue(toolMessage.toolName);
|
|
461
|
+
const isDispatch = toolName === 'dispatch-sub-agent-task';
|
|
462
|
+
const isSubAgent = isDispatch && Boolean(childSessionId);
|
|
463
|
+
const invokeStart = parseDate(toolMessage.invokeStartTime);
|
|
464
|
+
const invokeEnd = parseDate(toolMessage.invokeEndTime);
|
|
465
|
+
const durationMs =
|
|
466
|
+
invokeStart && invokeEnd && invokeEnd >= invokeStart ? invokeEnd.getTime() - invokeStart.getTime() : undefined;
|
|
467
|
+
const identity = nativeToolIdentity(toolCallId);
|
|
468
|
+
const values = isSubAgent
|
|
469
|
+
? this.subAgentSpanValues({
|
|
470
|
+
parent,
|
|
471
|
+
parentConversation,
|
|
472
|
+
childConversation,
|
|
473
|
+
childSessionId,
|
|
474
|
+
toolCallId,
|
|
475
|
+
messageId: stringValue(toolMessage.messageId),
|
|
476
|
+
nativeStatus: stringValue(child?.status || toolMessage.invokeStatus),
|
|
477
|
+
toolStatus: statusForTool(toolMessage),
|
|
478
|
+
startedAt: invokeStart || parseDate(toolMessage.createdAt) || activity,
|
|
479
|
+
endedAt: invokeEnd,
|
|
480
|
+
durationMs,
|
|
481
|
+
nativeActivityAt: activity,
|
|
482
|
+
})
|
|
483
|
+
: {
|
|
484
|
+
rootRunId: stringValue(parent.rootRunId) || sessionRootRunId(sessionId),
|
|
485
|
+
agentLoopRunId: parent.agentLoopRunId == null ? null : String(parent.agentLoopRunId),
|
|
486
|
+
parentSpanId: parent.id === undefined ? undefined : String(parent.id),
|
|
487
|
+
source: NATIVE_SOURCE,
|
|
488
|
+
parentSessionId: sessionId,
|
|
489
|
+
toolCallId,
|
|
490
|
+
type: isDispatch ? 'dispatch' : 'tool',
|
|
491
|
+
status: statusForTool(toolMessage),
|
|
492
|
+
leaderUsername: stringValue(parentConversation.aiEmployeeUsername) || undefined,
|
|
493
|
+
employeeUsername: stringValue(parentConversation.aiEmployeeUsername) || undefined,
|
|
494
|
+
toolName,
|
|
495
|
+
title: toolName || 'Native tool call',
|
|
496
|
+
startedAt: invokeStart || parseDate(toolMessage.createdAt) || activity,
|
|
497
|
+
nativeActivityAt: activity,
|
|
498
|
+
endedAt: invokeEnd,
|
|
499
|
+
durationMs,
|
|
500
|
+
metadata: metadataForNativeProjection({
|
|
501
|
+
nativeIdentity: identity,
|
|
502
|
+
nativeStatus: stringValue(toolMessage.status),
|
|
503
|
+
invokeStatus: stringValue(toolMessage.invokeStatus),
|
|
504
|
+
messageId: stringValue(toolMessage.messageId),
|
|
505
|
+
toolMessageId: stringValue(toolMessage.id),
|
|
506
|
+
}),
|
|
507
|
+
userId: stringValue(parentConversation.userId) || undefined,
|
|
508
|
+
};
|
|
509
|
+
if (!(await this.spans.upsertNative(identity, values)))
|
|
510
|
+
throw new Error('Could not persist native tool projection.');
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
private async projectUsageEvent(event: NativeRecord, counts: SyncCounts, cutoff: Date) {
|
|
515
|
+
const sessionId = stringValue(event.sessionId);
|
|
516
|
+
const messageId = stringValue(event.messageId);
|
|
517
|
+
if (!sessionId || !messageId) {
|
|
518
|
+
counts.skipped += 1;
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
const conversation = await this.findOne('aiConversations', { filter: { sessionId } });
|
|
522
|
+
const eventActivity = parseDate(event.occurredAt);
|
|
523
|
+
let parent = conversation ? await this.resolveParentSpan(conversation, cutoff, counts, eventActivity) : null;
|
|
524
|
+
if (!conversation && stringValue(event.from) !== 'sub-agent') {
|
|
525
|
+
// API gateway conversations are temporary, while usage events retain user and employee identity.
|
|
526
|
+
// Recreate only a session-level projection, without inventing request or message content.
|
|
527
|
+
const synthetic = {
|
|
528
|
+
sessionId,
|
|
529
|
+
userId: event.userId,
|
|
530
|
+
aiEmployeeUsername: event.aiEmployeeUsername,
|
|
531
|
+
from: event.from || 'main-agent',
|
|
532
|
+
category: event.category,
|
|
533
|
+
createdAt: event.occurredAt,
|
|
534
|
+
orphanedUsage: true,
|
|
535
|
+
};
|
|
536
|
+
const root = await this.upsertMainConversation(synthetic, cutoff, counts);
|
|
537
|
+
parent = root ? recordOf(root) : null;
|
|
538
|
+
}
|
|
539
|
+
if (!parent) counts.correlationIncomplete += 1;
|
|
540
|
+
|
|
541
|
+
const usageIdentity = 'ai-usage-event:' + sessionId + ':' + messageId;
|
|
542
|
+
const rawRunId = asObject(conversation?.options).controlPlaneRunId ?? parent?.agentLoopRunId;
|
|
543
|
+
const association = await this.resolveRunAssociation(rawRunId);
|
|
544
|
+
if (association.missing) counts.correlationIncomplete += 1;
|
|
545
|
+
const saved = await this.usageTracker.recordModelCallUsage({
|
|
546
|
+
usageIdentity,
|
|
547
|
+
nativeIdentity: usageIdentity,
|
|
548
|
+
sessionId,
|
|
549
|
+
messageId,
|
|
550
|
+
usage: usageFromAIUsageEvent(event),
|
|
551
|
+
model: stringValue(event.model) || undefined,
|
|
552
|
+
provider: stringValue(event.provider) || undefined,
|
|
553
|
+
llmService: stringValue(event.llmService) || undefined,
|
|
554
|
+
runId: association.runId,
|
|
555
|
+
rootRunId: association.rootRunId || stringValue(parent?.rootRunId) || sessionRootRunId(sessionId),
|
|
556
|
+
parentSpanId: parent?.id === undefined ? undefined : String(parent.id),
|
|
557
|
+
role: stringValue(event.role) || undefined,
|
|
558
|
+
employeeUsername: stringValue(event.aiEmployeeUsername || conversation?.aiEmployeeUsername) || undefined,
|
|
559
|
+
userId: stringValue(event.userId || conversation?.userId) || undefined,
|
|
560
|
+
source: 'ai_usage_event',
|
|
561
|
+
occurredAt: parseDate(event.occurredAt),
|
|
562
|
+
});
|
|
563
|
+
if (saved === undefined) throw new Error('Could not persist native model usage projection.');
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
private subAgentSpanValues(options: {
|
|
568
|
+
parent: NativeRecord;
|
|
569
|
+
parentConversation: NativeRecord;
|
|
570
|
+
childConversation: NativeRecord | null;
|
|
571
|
+
childSessionId: string;
|
|
572
|
+
toolCallId: string;
|
|
573
|
+
messageId?: string;
|
|
574
|
+
nativeStatus?: string;
|
|
575
|
+
toolStatus?: string;
|
|
576
|
+
startedAt?: Date;
|
|
577
|
+
endedAt?: Date;
|
|
578
|
+
durationMs?: number;
|
|
579
|
+
nativeActivityAt?: Date;
|
|
580
|
+
}) {
|
|
581
|
+
const { parent, parentConversation, childConversation, childSessionId, toolCallId } = options;
|
|
582
|
+
const startedAt = options.startedAt || parseDate(childConversation?.createdAt) || options.nativeActivityAt;
|
|
583
|
+
return {
|
|
584
|
+
rootRunId: stringValue(parent.rootRunId) || sessionRootRunId(stringValue(parentConversation.sessionId)),
|
|
585
|
+
agentLoopRunId: parent.agentLoopRunId == null ? null : String(parent.agentLoopRunId),
|
|
586
|
+
parentSpanId: parent.id === undefined ? undefined : String(parent.id),
|
|
587
|
+
source: NATIVE_SOURCE,
|
|
588
|
+
parentSessionId: stringValue(parentConversation.sessionId),
|
|
589
|
+
subSessionId: childSessionId,
|
|
590
|
+
toolCallId,
|
|
591
|
+
type: 'sub_agent',
|
|
592
|
+
status:
|
|
593
|
+
options.toolStatus && options.toolStatus !== 'unknown'
|
|
594
|
+
? options.toolStatus
|
|
595
|
+
: this.statusForNativeRelation(options.nativeStatus) !== 'unknown'
|
|
596
|
+
? this.statusForNativeRelation(options.nativeStatus)
|
|
597
|
+
: childConversation
|
|
598
|
+
? statusForConversation(childConversation)
|
|
599
|
+
: 'unknown',
|
|
600
|
+
depth: (numberValue(parent.depth) || 0) + 1,
|
|
601
|
+
leaderUsername: stringValue(parentConversation.aiEmployeeUsername) || undefined,
|
|
602
|
+
employeeUsername: stringValue(childConversation?.aiEmployeeUsername) || undefined,
|
|
603
|
+
toolName: 'dispatch-sub-agent-task',
|
|
604
|
+
title: 'Native sub-agent dispatch',
|
|
605
|
+
startedAt,
|
|
606
|
+
nativeActivityAt: options.nativeActivityAt,
|
|
607
|
+
endedAt: options.endedAt,
|
|
608
|
+
durationMs: options.durationMs,
|
|
609
|
+
metadata: metadataForNativeProjection({
|
|
610
|
+
nativeIdentity: nativeToolIdentity(toolCallId),
|
|
611
|
+
nativeStatus: options.nativeStatus || undefined,
|
|
612
|
+
messageId: options.messageId || undefined,
|
|
613
|
+
childSessionId,
|
|
614
|
+
}),
|
|
615
|
+
userId: stringValue(childConversation?.userId || parentConversation.userId) || undefined,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
private statusForNativeRelation(status: string | undefined) {
|
|
620
|
+
if (status === 'success' || status === 'completed' || status === 'done') return 'success';
|
|
621
|
+
if (status === 'error' || status === 'failed') return 'error';
|
|
622
|
+
if (status === 'interrupted' || status === 'waiting') return 'waiting_approval';
|
|
623
|
+
if (status === 'pending' || status === 'running') return 'running';
|
|
624
|
+
return 'unknown';
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
private findSubAgentRelation(message: NativeRecord | null, toolCallId: string) {
|
|
628
|
+
const relations = asObject(message?.metadata).subAgentConversations;
|
|
629
|
+
if (!Array.isArray(relations)) return null;
|
|
630
|
+
const matched = relations
|
|
631
|
+
.slice(0, MAX_RELATIONS_PER_MESSAGE)
|
|
632
|
+
.find((value) => stringValue(asObject(value).toolCallId) === toolCallId);
|
|
633
|
+
return matched ? asObject(matched) : null;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private async resolveParentSpan(
|
|
637
|
+
conversation: NativeRecord,
|
|
638
|
+
cutoff: Date,
|
|
639
|
+
counts: SyncCounts,
|
|
640
|
+
activity?: Date,
|
|
641
|
+
): Promise<NativeRecord | null> {
|
|
642
|
+
const sessionId = stringValue(conversation.sessionId);
|
|
643
|
+
if (!sessionId) return null;
|
|
644
|
+
if (isSubAgentConversation(conversation)) {
|
|
645
|
+
const canonical = await this.findOne('agentExecutionSpans', {
|
|
646
|
+
filter: { source: NATIVE_SOURCE, type: 'sub_agent', subSessionId: sessionId, nativeIdentity: { $ne: null } },
|
|
647
|
+
});
|
|
648
|
+
const parent =
|
|
649
|
+
canonical ||
|
|
650
|
+
(await this.findOne('agentExecutionSpans', {
|
|
651
|
+
filter: { source: NATIVE_SOURCE, type: 'sub_agent', subSessionId: sessionId },
|
|
652
|
+
}));
|
|
653
|
+
if (!parent) return null;
|
|
654
|
+
const parentActivity = latestDate(parent.nativeActivityAt, parent.startedAt, parent.createdAt, activity);
|
|
655
|
+
if (!this.withinRetention(parentActivity, cutoff, counts)) return null;
|
|
656
|
+
if (activity && activity >= cutoff) await this.advanceAncestorActivity(parent, activity, counts);
|
|
657
|
+
return parent;
|
|
658
|
+
}
|
|
659
|
+
const root = await this.upsertMainConversation(conversation, cutoff, counts, activity);
|
|
660
|
+
return root ? recordOf(root) : null;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private async advanceAncestorActivity(start: NativeRecord, activity: Date, counts: SyncCounts) {
|
|
664
|
+
let node: NativeRecord | null = start;
|
|
665
|
+
const visited = new Set<string>();
|
|
666
|
+
while (node && node.id !== undefined && visited.size < 32) {
|
|
667
|
+
const id = stringValue(node.id);
|
|
668
|
+
if (!id || visited.has(id)) break;
|
|
669
|
+
visited.add(id);
|
|
670
|
+
await this.spans.advanceNativeActivity(id, activity);
|
|
671
|
+
const parentId = stringValue(node.parentSpanId);
|
|
672
|
+
node = parentId ? await this.findOne('agentExecutionSpans', { filterByTk: parentId }) : null;
|
|
673
|
+
}
|
|
674
|
+
if (node && visited.size >= 32) counts.correlationIncomplete += 1;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
private async findOne(name: string, options: Record<string, unknown>): Promise<NativeRecord | null> {
|
|
678
|
+
const repository = this.plugin.db.getRepository(name);
|
|
679
|
+
if (!repository?.findOne) throw new Error(`Native monitor source ${name} is unavailable.`);
|
|
680
|
+
const row = await repository.findOne(options);
|
|
681
|
+
return row ? recordOf(row) : null;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private warn(message: string, error: unknown) {
|
|
685
|
+
try {
|
|
686
|
+
this.plugin.app.logger?.warn?.(message, { error });
|
|
687
|
+
} catch {
|
|
688
|
+
// Telemetry logging is best effort.
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|