@terreno/ai 57.9.0 → 57.11.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 +1 -0
- package/bunfig.toml +1 -1
- package/dist/aiApp.d.ts +8 -2
- package/dist/aiApp.js +12 -6
- package/dist/harness/adminScreens.d.ts +6 -0
- package/dist/harness/adminScreens.js +11 -0
- package/dist/harness/agentLoop.d.ts +61 -0
- package/dist/harness/agentLoop.js +798 -0
- package/dist/harness/agentTaskNames.d.ts +4 -0
- package/dist/harness/agentTaskNames.js +7 -0
- package/dist/harness/approvalPolicy.d.ts +3 -0
- package/dist/harness/approvalPolicy.js +23 -0
- package/dist/harness/approvals.d.ts +101 -0
- package/dist/harness/approvals.js +468 -0
- package/dist/harness/commit.d.ts +238 -0
- package/dist/harness/commit.js +678 -0
- package/dist/harness/conversation.d.ts +75 -0
- package/dist/harness/conversation.js +397 -0
- package/dist/harness/defineAgent.d.ts +9 -0
- package/dist/harness/defineAgent.js +65 -0
- package/dist/harness/defineTask.d.ts +11 -0
- package/dist/harness/defineTask.js +59 -0
- package/dist/harness/defineTool.d.ts +7 -0
- package/dist/harness/defineTool.js +36 -0
- package/dist/harness/definitionError.d.ts +8 -0
- package/dist/harness/definitionError.js +15 -0
- package/dist/harness/errors.d.ts +133 -0
- package/dist/harness/errors.js +107 -0
- package/dist/harness/eventHub.d.ts +45 -0
- package/dist/harness/eventHub.js +135 -0
- package/dist/harness/events.d.ts +95 -0
- package/dist/harness/events.js +267 -0
- package/dist/harness/executionEnv.d.ts +31 -0
- package/dist/harness/executionEnv.js +2 -0
- package/dist/harness/extensions.d.ts +82 -0
- package/dist/harness/extensions.js +274 -0
- package/dist/harness/harness.d.ts +163 -0
- package/dist/harness/harness.js +522 -0
- package/dist/harness/harnessApp.d.ts +44 -0
- package/dist/harness/harnessApp.js +62 -0
- package/dist/harness/internalRuntime.d.ts +16 -0
- package/dist/harness/internalRuntime.js +18 -0
- package/dist/harness/leases.d.ts +35 -0
- package/dist/harness/leases.js +86 -0
- package/dist/harness/memo.d.ts +24 -0
- package/dist/harness/memo.js +78 -0
- package/dist/harness/modelCall.d.ts +45 -0
- package/dist/harness/modelCall.js +147 -0
- package/dist/harness/models/harnessApproval.d.ts +2 -0
- package/dist/harness/models/harnessApproval.js +100 -0
- package/dist/harness/models/harnessConversation.d.ts +2 -0
- package/dist/harness/models/harnessConversation.js +117 -0
- package/dist/harness/models/harnessEvent.d.ts +3 -0
- package/dist/harness/models/harnessEvent.js +73 -0
- package/dist/harness/models/harnessInboxEvent.d.ts +2 -0
- package/dist/harness/models/harnessInboxEvent.js +58 -0
- package/dist/harness/models/harnessMemo.d.ts +2 -0
- package/dist/harness/models/harnessMemo.js +42 -0
- package/dist/harness/models/harnessMessage.d.ts +2 -0
- package/dist/harness/models/harnessMessage.js +73 -0
- package/dist/harness/models/harnessOwner.d.ts +2 -0
- package/dist/harness/models/harnessOwner.js +36 -0
- package/dist/harness/models/harnessTask.d.ts +2 -0
- package/dist/harness/models/harnessTask.js +191 -0
- package/dist/harness/ownership.d.ts +89 -0
- package/dist/harness/ownership.js +438 -0
- package/dist/harness/registry.d.ts +29 -0
- package/dist/harness/registry.js +93 -0
- package/dist/harness/retryBackoff.d.ts +31 -0
- package/dist/harness/retryBackoff.js +50 -0
- package/dist/harness/routes/approvals.d.ts +13 -0
- package/dist/harness/routes/approvals.js +93 -0
- package/dist/harness/routes/conversations.d.ts +11 -0
- package/dist/harness/routes/conversations.js +66 -0
- package/dist/harness/routes/events.d.ts +19 -0
- package/dist/harness/routes/events.js +215 -0
- package/dist/harness/routes/tasks.d.ts +11 -0
- package/dist/harness/routes/tasks.js +108 -0
- package/dist/harness/runners/inProcessRunner.d.ts +64 -0
- package/dist/harness/runners/inProcessRunner.js +227 -0
- package/dist/harness/runners/jobsRunner.d.ts +62 -0
- package/dist/harness/runners/jobsRunner.js +212 -0
- package/dist/harness/runtime.d.ts +52 -0
- package/dist/harness/runtime.js +604 -0
- package/dist/harness/subagent.d.ts +53 -0
- package/dist/harness/subagent.js +134 -0
- package/dist/harness/suspend.d.ts +8 -0
- package/dist/harness/suspend.js +16 -0
- package/dist/harness/transaction.d.ts +3 -0
- package/dist/harness/transaction.js +22 -0
- package/dist/harness/waits.d.ts +100 -0
- package/dist/harness/waits.js +214 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +45 -2
- package/dist/models/aiDataset.d.ts +2 -0
- package/dist/models/aiDataset.js +67 -0
- package/dist/models/aiRequest.js +1 -1
- package/dist/models/gptHistory.js +73 -0
- package/dist/observability/adminScreens.d.ts +5 -0
- package/dist/observability/adminScreens.js +32 -0
- package/dist/observability/compileTemplate.d.ts +1 -0
- package/dist/observability/compileTemplate.js +13 -0
- package/dist/observability/datasetImport.d.ts +11 -0
- package/dist/observability/datasetImport.js +185 -0
- package/dist/observability/evaluate.d.ts +31 -0
- package/dist/observability/evaluate.js +200 -0
- package/dist/observability/evaluatorTemplates.d.ts +17 -0
- package/dist/observability/evaluatorTemplates.js +111 -0
- package/dist/observability/jsonPath.d.ts +2 -0
- package/dist/observability/jsonPath.js +57 -0
- package/dist/observability/local/datasetStore.d.ts +87 -0
- package/dist/observability/local/datasetStore.js +326 -0
- package/dist/observability/local/evaluatorStore.d.ts +44 -0
- package/dist/observability/local/evaluatorStore.js +182 -0
- package/dist/observability/local/experimentRunner.d.ts +96 -0
- package/dist/observability/local/experimentRunner.js +419 -0
- package/dist/observability/local/localPlugin.d.ts +22 -0
- package/dist/observability/local/localPlugin.js +76 -0
- package/dist/observability/local/models/obsDataset.d.ts +2 -0
- package/dist/observability/local/models/obsDataset.js +37 -0
- package/dist/observability/local/models/obsDatasetItem.d.ts +2 -0
- package/dist/observability/local/models/obsDatasetItem.js +76 -0
- package/dist/observability/local/models/obsEvaluator.d.ts +2 -0
- package/dist/observability/local/models/obsEvaluator.js +98 -0
- package/dist/observability/local/models/obsExperiment.d.ts +2 -0
- package/dist/observability/local/models/obsExperiment.js +87 -0
- package/dist/observability/local/models/obsExperimentItem.d.ts +2 -0
- package/dist/observability/local/models/obsExperimentItem.js +45 -0
- package/dist/observability/local/models/obsPrompt.d.ts +2 -0
- package/dist/observability/local/models/obsPrompt.js +42 -0
- package/dist/observability/local/models/obsPromptLabel.d.ts +2 -0
- package/dist/observability/local/models/obsPromptLabel.js +39 -0
- package/dist/observability/local/models/obsPromptVersion.d.ts +2 -0
- package/dist/observability/local/models/obsPromptVersion.js +96 -0
- package/dist/observability/local/models/obsReviewItem.d.ts +2 -0
- package/dist/observability/local/models/obsReviewItem.js +75 -0
- package/dist/observability/local/models/obsScore.d.ts +2 -0
- package/dist/observability/local/models/obsScore.js +58 -0
- package/dist/observability/local/models/obsSpan.d.ts +2 -0
- package/dist/observability/local/models/obsSpan.js +64 -0
- package/dist/observability/local/models/obsTrace.d.ts +2 -0
- package/dist/observability/local/models/obsTrace.js +93 -0
- package/dist/observability/local/promptStore.d.ts +180 -0
- package/dist/observability/local/promptStore.js +444 -0
- package/dist/observability/local/reviewStore.d.ts +50 -0
- package/dist/observability/local/reviewStore.js +203 -0
- package/dist/observability/local/traceStore.d.ts +103 -0
- package/dist/observability/local/traceStore.js +325 -0
- package/dist/observability/observabilityApp.d.ts +24 -0
- package/dist/observability/observabilityApp.js +157 -0
- package/dist/observability/observabilityAppRegistry.d.ts +14 -0
- package/dist/observability/observabilityAppRegistry.js +16 -0
- package/dist/observability/permissions.d.ts +7 -0
- package/dist/observability/permissions.js +60 -0
- package/dist/observability/reviewPanels.d.ts +18 -0
- package/dist/observability/reviewPanels.js +46 -0
- package/dist/observability/routes/datasets.d.ts +7 -0
- package/dist/observability/routes/datasets.js +149 -0
- package/dist/observability/routes/evaluators.d.ts +7 -0
- package/dist/observability/routes/evaluators.js +123 -0
- package/dist/observability/routes/experiments.d.ts +7 -0
- package/dist/observability/routes/experiments.js +95 -0
- package/dist/observability/routes/observabilityRouteAccess.d.ts +13 -0
- package/dist/observability/routes/observabilityRouteAccess.js +67 -0
- package/dist/observability/routes/prompts.d.ts +12 -0
- package/dist/observability/routes/prompts.js +172 -0
- package/dist/observability/routes/requestAiService.d.ts +13 -0
- package/dist/observability/routes/requestAiService.js +21 -0
- package/dist/observability/routes/review.d.ts +7 -0
- package/dist/observability/routes/review.js +79 -0
- package/dist/observability/routes/status.d.ts +5 -0
- package/dist/observability/routes/status.js +31 -0
- package/dist/observability/routes/testMultiStage.d.ts +9 -0
- package/dist/observability/routes/testMultiStage.js +67 -0
- package/dist/observability/routes/traces.d.ts +7 -0
- package/dist/observability/routes/traces.js +129 -0
- package/dist/observability/schemaValidation.d.ts +5 -0
- package/dist/observability/schemaValidation.js +26 -0
- package/dist/observability/sopThresholds.d.ts +2 -0
- package/dist/observability/sopThresholds.js +21 -0
- package/dist/observability/status.d.ts +23 -0
- package/dist/observability/status.js +34 -0
- package/dist/observability/testMultiStageSchemas.d.ts +10 -0
- package/dist/observability/testMultiStageSchemas.js +79 -0
- package/dist/observability/testMultiStageWorkflow.d.ts +20 -0
- package/dist/observability/testMultiStageWorkflow.js +218 -0
- package/dist/observability/types.d.ts +159 -0
- package/dist/observability/types.js +67 -0
- package/dist/routes/files.js +18 -7
- package/dist/routes/gpt.js +79 -689
- package/dist/routes/gptActions.d.ts +9 -0
- package/dist/routes/gptActions.js +212 -0
- package/dist/routes/gptDatasets.d.ts +5 -0
- package/dist/routes/gptDatasets.js +94 -0
- package/dist/routes/gptHistories.d.ts +3 -1
- package/dist/routes/gptHistories.js +188 -2
- package/dist/service/aiDatasets.d.ts +57 -0
- package/dist/service/aiDatasets.js +253 -0
- package/dist/service/aiService.d.ts +50 -1
- package/dist/service/aiService.js +426 -77
- package/dist/service/askFiles.d.ts +49 -0
- package/dist/service/askFiles.js +162 -0
- package/dist/service/asks.d.ts +76 -0
- package/dist/service/asks.js +284 -0
- package/dist/service/chatTurn.d.ts +128 -0
- package/dist/service/chatTurn.js +1674 -0
- package/dist/service/fileStorage.d.ts +4 -0
- package/dist/service/fileStorage.js +7 -2
- package/dist/service/fillActionIds.d.ts +6 -0
- package/dist/service/fillActionIds.js +79 -0
- package/dist/service/jsonFenceModel.d.ts +7 -0
- package/dist/service/jsonFenceModel.js +45 -0
- package/dist/service/prompts.d.ts +52 -0
- package/dist/service/prompts.js +96 -1
- package/dist/service/sanitizeHtml.d.ts +11 -0
- package/dist/service/sanitizeHtml.js +108 -0
- package/dist/types/harness.d.ts +952 -0
- package/dist/types/harness.js +133 -0
- package/dist/types/index.d.ts +192 -14
- package/dist/types/index.js +2 -0
- package/dist/types/observability.d.ts +288 -0
- package/dist/types/observability.js +2 -0
- package/package.json +28 -5
- package/src/aiApp.test.ts +207 -1
- package/src/aiApp.ts +19 -6
- package/src/harness/adminScreens.test.ts +34 -0
- package/src/harness/adminScreens.ts +11 -0
- package/src/harness/agentLoop.test.ts +1034 -0
- package/src/harness/agentLoop.ts +1082 -0
- package/src/harness/agentRecovery.test.ts +380 -0
- package/src/harness/agentTaskNames.ts +4 -0
- package/src/harness/approvalPolicy.ts +28 -0
- package/src/harness/approvals.test.ts +1094 -0
- package/src/harness/approvals.ts +644 -0
- package/src/harness/commit.ts +1049 -0
- package/src/harness/concurrency.test.ts +155 -0
- package/src/harness/conversation.ts +503 -0
- package/src/harness/defineAgent.test.ts +92 -0
- package/src/harness/defineAgent.ts +82 -0
- package/src/harness/defineTask.test.ts +59 -0
- package/src/harness/defineTask.ts +76 -0
- package/src/harness/defineTool.ts +45 -0
- package/src/harness/definitionError.ts +13 -0
- package/src/harness/errors.test.ts +90 -0
- package/src/harness/errors.ts +125 -0
- package/src/harness/eventHub.test.ts +124 -0
- package/src/harness/eventHub.ts +159 -0
- package/src/harness/events.test.ts +769 -0
- package/src/harness/events.ts +384 -0
- package/src/harness/executionEnv.ts +34 -0
- package/src/harness/extensions.test.ts +1218 -0
- package/src/harness/extensions.ts +382 -0
- package/src/harness/harness.test.ts +693 -0
- package/src/harness/harness.ts +778 -0
- package/src/harness/harnessApp.ts +76 -0
- package/src/harness/internalRuntime.ts +44 -0
- package/src/harness/leases.ts +132 -0
- package/src/harness/memo.ts +107 -0
- package/src/harness/modelCall.test.ts +134 -0
- package/src/harness/modelCall.ts +200 -0
- package/src/harness/models/harnessApproval.ts +109 -0
- package/src/harness/models/harnessConversation.ts +142 -0
- package/src/harness/models/harnessEvent.ts +92 -0
- package/src/harness/models/harnessInboxEvent.ts +73 -0
- package/src/harness/models/harnessMemo.ts +43 -0
- package/src/harness/models/harnessMessage.ts +85 -0
- package/src/harness/models/harnessModels.test.ts +60 -0
- package/src/harness/models/harnessOwner.ts +40 -0
- package/src/harness/models/harnessTask.ts +206 -0
- package/src/harness/ownership.test.ts +1087 -0
- package/src/harness/ownership.ts +618 -0
- package/src/harness/recovery.test.ts +907 -0
- package/src/harness/registry.ts +124 -0
- package/src/harness/retries.test.ts +292 -0
- package/src/harness/retryBackoff.test.ts +100 -0
- package/src/harness/retryBackoff.ts +77 -0
- package/src/harness/routes/approvals.ts +123 -0
- package/src/harness/routes/conversations.test.ts +518 -0
- package/src/harness/routes/conversations.ts +102 -0
- package/src/harness/routes/events.ts +280 -0
- package/src/harness/routes/tasks.test.ts +198 -0
- package/src/harness/routes/tasks.ts +146 -0
- package/src/harness/runners/inProcessRunner.test.ts +530 -0
- package/src/harness/runners/inProcessRunner.ts +260 -0
- package/src/harness/runners/jobsRunner.test.ts +709 -0
- package/src/harness/runners/jobsRunner.ts +252 -0
- package/src/harness/runtime.ts +802 -0
- package/src/harness/subagent.test.ts +696 -0
- package/src/harness/subagent.ts +192 -0
- package/src/harness/suspend.ts +13 -0
- package/src/harness/transaction.ts +17 -0
- package/src/harness/versioning.test.ts +288 -0
- package/src/harness/waits.test.ts +693 -0
- package/src/harness/waits.ts +356 -0
- package/src/index.test.ts +13 -0
- package/src/index.ts +70 -0
- package/src/isolated/adminScreensConfig.isolated.ts +143 -0
- package/src/models/aiDataset.test.ts +34 -0
- package/src/models/aiDataset.ts +78 -0
- package/src/models/aiRequest.ts +2 -1
- package/src/models/gptHistory.test.ts +156 -0
- package/src/models/gptHistory.ts +89 -1
- package/src/observability/adminScreens.test.ts +71 -0
- package/src/observability/adminScreens.ts +42 -0
- package/src/observability/compileTemplate.test.ts +14 -0
- package/src/observability/compileTemplate.ts +10 -0
- package/src/observability/datasetImport.test.ts +95 -0
- package/src/observability/datasetImport.ts +220 -0
- package/src/observability/evaluate.test.ts +549 -0
- package/src/observability/evaluate.ts +254 -0
- package/src/observability/evaluatorTemplates.ts +124 -0
- package/src/observability/jsonPath.test.ts +52 -0
- package/src/observability/jsonPath.ts +60 -0
- package/src/observability/local/datasetStore.test.ts +230 -0
- package/src/observability/local/datasetStore.ts +452 -0
- package/src/observability/local/evaluatorStore.test.ts +138 -0
- package/src/observability/local/evaluatorStore.ts +224 -0
- package/src/observability/local/experimentRunner.test.ts +489 -0
- package/src/observability/local/experimentRunner.ts +548 -0
- package/src/observability/local/localPlugin.ts +88 -0
- package/src/observability/local/models/obsDataset.ts +38 -0
- package/src/observability/local/models/obsDatasetItem.ts +80 -0
- package/src/observability/local/models/obsEvaluator.ts +102 -0
- package/src/observability/local/models/obsExperiment.ts +91 -0
- package/src/observability/local/models/obsExperimentItem.ts +52 -0
- package/src/observability/local/models/obsPrompt.ts +43 -0
- package/src/observability/local/models/obsPromptLabel.ts +43 -0
- package/src/observability/local/models/obsPromptVersion.ts +107 -0
- package/src/observability/local/models/obsReviewItem.ts +79 -0
- package/src/observability/local/models/obsScore.ts +59 -0
- package/src/observability/local/models/obsSpan.ts +65 -0
- package/src/observability/local/models/obsTrace.ts +94 -0
- package/src/observability/local/obsModels.test.ts +119 -0
- package/src/observability/local/promptStore.test.ts +351 -0
- package/src/observability/local/promptStore.ts +665 -0
- package/src/observability/local/reviewStore.test.ts +164 -0
- package/src/observability/local/reviewStore.ts +264 -0
- package/src/observability/local/traceStore.test.ts +264 -0
- package/src/observability/local/traceStore.ts +440 -0
- package/src/observability/observabilityApp.test.ts +92 -0
- package/src/observability/observabilityApp.ts +185 -0
- package/src/observability/observabilityAppRegistry.test.ts +30 -0
- package/src/observability/observabilityAppRegistry.ts +35 -0
- package/src/observability/permissions.test.ts +96 -0
- package/src/observability/permissions.ts +78 -0
- package/src/observability/reviewPanels.test.ts +35 -0
- package/src/observability/reviewPanels.ts +64 -0
- package/src/observability/routes/datasets.test.ts +176 -0
- package/src/observability/routes/datasets.ts +252 -0
- package/src/observability/routes/evaluators.test.ts +119 -0
- package/src/observability/routes/evaluators.ts +207 -0
- package/src/observability/routes/experiments.test.ts +282 -0
- package/src/observability/routes/experiments.ts +152 -0
- package/src/observability/routes/observabilityRbac.test.ts +767 -0
- package/src/observability/routes/observabilityRouteAccess.ts +106 -0
- package/src/observability/routes/prompts.test.ts +320 -0
- package/src/observability/routes/prompts.ts +263 -0
- package/src/observability/routes/requestAiService.ts +36 -0
- package/src/observability/routes/review.test.ts +120 -0
- package/src/observability/routes/review.ts +125 -0
- package/src/observability/routes/status.test.ts +116 -0
- package/src/observability/routes/status.ts +47 -0
- package/src/observability/routes/testMultiStage.test.ts +214 -0
- package/src/observability/routes/testMultiStage.ts +96 -0
- package/src/observability/routes/traces.test.ts +167 -0
- package/src/observability/routes/traces.ts +172 -0
- package/src/observability/schemaValidation.ts +29 -0
- package/src/observability/sopThresholds.ts +20 -0
- package/src/observability/status.test.ts +38 -0
- package/src/observability/status.ts +56 -0
- package/src/observability/testMultiStageSchemas.ts +95 -0
- package/src/observability/testMultiStageWorkflow.test.ts +114 -0
- package/src/observability/testMultiStageWorkflow.ts +307 -0
- package/src/observability/types.ts +262 -0
- package/src/routes/files.test.ts +63 -9
- package/src/routes/files.ts +21 -7
- package/src/routes/gpt.test.ts +3279 -0
- package/src/routes/gpt.ts +91 -816
- package/src/routes/gptActions.test.ts +241 -0
- package/src/routes/gptActions.ts +255 -0
- package/src/routes/gptApprovals.test.ts +762 -0
- package/src/routes/gptDatasets.test.ts +86 -0
- package/src/routes/gptDatasets.ts +104 -0
- package/src/routes/gptFiles.test.ts +589 -0
- package/src/routes/gptHistories.test.ts +933 -0
- package/src/routes/gptHistories.ts +266 -5
- package/src/routes/routes.test.ts +222 -2
- package/src/service/aiDatasets.test.ts +123 -0
- package/src/service/aiDatasets.ts +316 -0
- package/src/service/aiService.test.ts +593 -0
- package/src/service/aiService.ts +568 -111
- package/src/service/askFiles.test.ts +96 -0
- package/src/service/askFiles.ts +222 -0
- package/src/service/asks.test.ts +946 -0
- package/src/service/asks.ts +423 -0
- package/src/service/chatTurn.ts +2287 -0
- package/src/service/fileStorage.test.ts +11 -0
- package/src/service/fileStorage.ts +10 -2
- package/src/service/fillActionIds.test.ts +65 -0
- package/src/service/fillActionIds.ts +98 -0
- package/src/service/jsonFenceModel.test.ts +47 -0
- package/src/service/jsonFenceModel.ts +53 -0
- package/src/service/prompts.test.ts +21 -0
- package/src/service/prompts.ts +147 -0
- package/src/service/sanitizeHtml.test.ts +61 -0
- package/src/service/sanitizeHtml.ts +109 -0
- package/src/tests/bunSetup.test.ts +7 -4
- package/src/tests/bunSetup.ts +7 -7
- package/src/tests/chatHarness.ts +478 -0
- package/src/tests/generateStream.ts +49 -0
- package/src/tests/harnessErrors.ts +22 -0
- package/src/tests/harnessStreaming.ts +227 -0
- package/src/tests/helpers.ts +9 -2
- package/src/types/harness.ts +1119 -0
- package/src/types/index.ts +209 -13
- package/src/types/observability.ts +344 -0
- package/src/types/sanitize-html.d.ts +25 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessEventStream = exports.registerHarnessEvent = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const harness_1 = require("../../types/harness");
|
|
9
|
+
const harnessEventSchema = new mongoose_1.default.Schema({
|
|
10
|
+
created: { description: "When the event was written", required: true, type: Date },
|
|
11
|
+
expiresAt: {
|
|
12
|
+
description: "When Mongo deletes the row; set on delta events only",
|
|
13
|
+
type: Date,
|
|
14
|
+
},
|
|
15
|
+
payload: { description: "Event body (JSON)", type: mongoose_1.default.Schema.Types.Mixed },
|
|
16
|
+
seq: {
|
|
17
|
+
description: "Position in the stream; strictly increasing from 1, unique per stream",
|
|
18
|
+
required: true,
|
|
19
|
+
type: Number,
|
|
20
|
+
},
|
|
21
|
+
streamId: {
|
|
22
|
+
description: "Conversation id, or root task id for a task tree's events",
|
|
23
|
+
required: true,
|
|
24
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
25
|
+
},
|
|
26
|
+
taskId: {
|
|
27
|
+
description: "Task the event is about, when there is one",
|
|
28
|
+
ref: "HarnessTask",
|
|
29
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
30
|
+
},
|
|
31
|
+
taskPath: {
|
|
32
|
+
default: () => [],
|
|
33
|
+
description: "On task-stream events: the task and every task that owns it",
|
|
34
|
+
type: [mongoose_1.default.Schema.Types.ObjectId],
|
|
35
|
+
},
|
|
36
|
+
type: {
|
|
37
|
+
description: "Event type, for example message.created, delta, or task.status",
|
|
38
|
+
enum: Object.values(harness_1.HARNESS_EVENT_TYPES),
|
|
39
|
+
required: true,
|
|
40
|
+
type: String,
|
|
41
|
+
},
|
|
42
|
+
}, { minimize: false, strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
43
|
+
// biome-ignore assist/source/useSortedKeys: streamId must lead; replays read one stream in seq order
|
|
44
|
+
harnessEventSchema.index({ streamId: 1, seq: 1 }, { unique: true });
|
|
45
|
+
// biome-ignore assist/source/useSortedKeys: task-subtree replays filter one stream by taskPath, in seq order
|
|
46
|
+
harnessEventSchema.index({ streamId: 1, taskPath: 1, seq: 1 });
|
|
47
|
+
// Only delta rows carry expiresAt, so committed events are kept.
|
|
48
|
+
harnessEventSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
49
|
+
const harnessEventStreamSchema = new mongoose_1.default.Schema({
|
|
50
|
+
_id: {
|
|
51
|
+
description: "The stream: a conversation id, or a root task id",
|
|
52
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
53
|
+
},
|
|
54
|
+
seq: {
|
|
55
|
+
default: 0,
|
|
56
|
+
description: "Highest event seq handed out on the stream",
|
|
57
|
+
type: Number,
|
|
58
|
+
},
|
|
59
|
+
}, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
60
|
+
const registerHarnessEvent = () => {
|
|
61
|
+
if (mongoose_1.default.models.HarnessEvent) {
|
|
62
|
+
return mongoose_1.default.models.HarnessEvent;
|
|
63
|
+
}
|
|
64
|
+
return mongoose_1.default.model("HarnessEvent", harnessEventSchema);
|
|
65
|
+
};
|
|
66
|
+
exports.registerHarnessEvent = registerHarnessEvent;
|
|
67
|
+
const registerHarnessEventStream = () => {
|
|
68
|
+
if (mongoose_1.default.models.HarnessEventStream) {
|
|
69
|
+
return mongoose_1.default.models.HarnessEventStream;
|
|
70
|
+
}
|
|
71
|
+
return mongoose_1.default.model("HarnessEventStream", harnessEventStreamSchema);
|
|
72
|
+
};
|
|
73
|
+
exports.registerHarnessEventStream = registerHarnessEventStream;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessInboxEvent = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const harnessInboxEventSchema = new mongoose_1.default.Schema({
|
|
10
|
+
consumedAt: { description: "When a rt.waitFor call received the event", type: Date },
|
|
11
|
+
consumedKey: {
|
|
12
|
+
description: "`<step>:<call index>` of the rt.waitFor call that received the event",
|
|
13
|
+
type: String,
|
|
14
|
+
},
|
|
15
|
+
name: { description: "Event name rt.waitFor waits on", required: true, type: String },
|
|
16
|
+
payload: { description: "Value rt.waitFor returns (JSON)", type: mongoose_1.default.Schema.Types.Mixed },
|
|
17
|
+
requestId: {
|
|
18
|
+
description: "Sender idempotency key, unique per task; a repeated send is a no-op",
|
|
19
|
+
type: String,
|
|
20
|
+
},
|
|
21
|
+
seq: {
|
|
22
|
+
description: "Position in the task's inbox; delivery is FIFO per event name",
|
|
23
|
+
required: true,
|
|
24
|
+
type: Number,
|
|
25
|
+
},
|
|
26
|
+
taskId: {
|
|
27
|
+
description: "Task the event was sent to",
|
|
28
|
+
ref: "HarnessTask",
|
|
29
|
+
required: true,
|
|
30
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
31
|
+
},
|
|
32
|
+
}, {
|
|
33
|
+
// Keep empty objects: `{}` is a meaningful payload.
|
|
34
|
+
minimize: false,
|
|
35
|
+
strict: "throw",
|
|
36
|
+
toJSON: { virtuals: true },
|
|
37
|
+
toObject: { virtuals: true },
|
|
38
|
+
});
|
|
39
|
+
harnessInboxEventSchema.plugin(api_1.createdUpdatedPlugin);
|
|
40
|
+
harnessInboxEventSchema.plugin(api_1.findOneOrNone);
|
|
41
|
+
harnessInboxEventSchema.plugin(api_1.findExactlyOne);
|
|
42
|
+
// Oldest undelivered event of one name; compound index field order is query-significant.
|
|
43
|
+
harnessInboxEventSchema.index(Object.fromEntries([
|
|
44
|
+
["taskId", 1],
|
|
45
|
+
["name", 1],
|
|
46
|
+
["consumedKey", 1],
|
|
47
|
+
["seq", 1],
|
|
48
|
+
]));
|
|
49
|
+
harnessInboxEventSchema.index({ requestId: 1, taskId: 1 }, { partialFilterExpression: { requestId: { $exists: true } }, unique: true });
|
|
50
|
+
// One event per wait call, so a call can never receive two.
|
|
51
|
+
harnessInboxEventSchema.index({ consumedKey: 1, taskId: 1 }, { partialFilterExpression: { consumedKey: { $exists: true } }, unique: true });
|
|
52
|
+
const registerHarnessInboxEvent = () => {
|
|
53
|
+
if (mongoose_1.default.models.HarnessInboxEvent) {
|
|
54
|
+
return mongoose_1.default.models.HarnessInboxEvent;
|
|
55
|
+
}
|
|
56
|
+
return mongoose_1.default.model("HarnessInboxEvent", harnessInboxEventSchema);
|
|
57
|
+
};
|
|
58
|
+
exports.registerHarnessInboxEvent = registerHarnessInboxEvent;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessMemo = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const harnessMemoSchema = new mongoose_1.default.Schema({
|
|
10
|
+
key: {
|
|
11
|
+
description: "Memo key, unique within its task",
|
|
12
|
+
required: true,
|
|
13
|
+
type: String,
|
|
14
|
+
},
|
|
15
|
+
taskId: {
|
|
16
|
+
description: "Task the memo is scoped to (the turn task for extension hooks)",
|
|
17
|
+
ref: "HarnessTask",
|
|
18
|
+
required: true,
|
|
19
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
20
|
+
},
|
|
21
|
+
value: {
|
|
22
|
+
description: "First value written for the key (JSON); later writes keep it",
|
|
23
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
24
|
+
},
|
|
25
|
+
}, {
|
|
26
|
+
// Keep empty objects: `{}` is a meaningful memo value.
|
|
27
|
+
minimize: false,
|
|
28
|
+
strict: "throw",
|
|
29
|
+
toJSON: { virtuals: true },
|
|
30
|
+
toObject: { virtuals: true },
|
|
31
|
+
});
|
|
32
|
+
harnessMemoSchema.plugin(api_1.createdUpdatedPlugin);
|
|
33
|
+
harnessMemoSchema.plugin(api_1.findOneOrNone);
|
|
34
|
+
harnessMemoSchema.plugin(api_1.findExactlyOne);
|
|
35
|
+
harnessMemoSchema.index({ key: 1, taskId: 1 }, { unique: true });
|
|
36
|
+
const registerHarnessMemo = () => {
|
|
37
|
+
if (mongoose_1.default.models.HarnessMemo) {
|
|
38
|
+
return mongoose_1.default.models.HarnessMemo;
|
|
39
|
+
}
|
|
40
|
+
return mongoose_1.default.model("HarnessMemo", harnessMemoSchema);
|
|
41
|
+
};
|
|
42
|
+
exports.registerHarnessMemo = registerHarnessMemo;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessMessage = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const harness_1 = require("../../types/harness");
|
|
10
|
+
const harnessMessageSchema = new mongoose_1.default.Schema({
|
|
11
|
+
aborted: {
|
|
12
|
+
default: false,
|
|
13
|
+
description: "True when the next prompt must skip this message: a partial stream, or an assistant message aborted before its tool calls had results",
|
|
14
|
+
type: Boolean,
|
|
15
|
+
},
|
|
16
|
+
conversationId: {
|
|
17
|
+
description: "Conversation this message belongs to",
|
|
18
|
+
ref: "HarnessConversation",
|
|
19
|
+
required: true,
|
|
20
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
21
|
+
},
|
|
22
|
+
parts: {
|
|
23
|
+
default: () => [],
|
|
24
|
+
description: "Content parts: an array of text, tool-call, or tool-result objects",
|
|
25
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
26
|
+
},
|
|
27
|
+
requestId: {
|
|
28
|
+
description: "Submitter's idempotency key on user messages from submit or send; unique per conversation",
|
|
29
|
+
type: String,
|
|
30
|
+
},
|
|
31
|
+
role: {
|
|
32
|
+
description: "Who produced the message: system, user, assistant, or tool",
|
|
33
|
+
enum: Object.values(harness_1.HARNESS_MESSAGE_ROLES),
|
|
34
|
+
required: true,
|
|
35
|
+
type: String,
|
|
36
|
+
},
|
|
37
|
+
seq: {
|
|
38
|
+
description: "Position in the conversation; strictly increasing from 1",
|
|
39
|
+
required: true,
|
|
40
|
+
type: Number,
|
|
41
|
+
},
|
|
42
|
+
status: {
|
|
43
|
+
description: "For tool messages: ok, or error when the call failed or was interrupted",
|
|
44
|
+
enum: ["error", "ok"],
|
|
45
|
+
type: String,
|
|
46
|
+
},
|
|
47
|
+
toolCallId: { description: "Tool call this tool message answers", type: String },
|
|
48
|
+
toolName: { description: "Tool that produced this tool message", type: String },
|
|
49
|
+
turnTaskId: {
|
|
50
|
+
description: "Turn task that wrote this message",
|
|
51
|
+
ref: "HarnessTask",
|
|
52
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
53
|
+
},
|
|
54
|
+
}, {
|
|
55
|
+
// Keep empty objects: `{}` tool arguments and states are meaningful values.
|
|
56
|
+
minimize: false,
|
|
57
|
+
strict: "throw",
|
|
58
|
+
toJSON: { virtuals: true },
|
|
59
|
+
toObject: { virtuals: true },
|
|
60
|
+
});
|
|
61
|
+
harnessMessageSchema.plugin(api_1.createdUpdatedPlugin);
|
|
62
|
+
harnessMessageSchema.plugin(api_1.isDeletedPlugin);
|
|
63
|
+
harnessMessageSchema.plugin(api_1.findOneOrNone);
|
|
64
|
+
harnessMessageSchema.plugin(api_1.findExactlyOne);
|
|
65
|
+
harnessMessageSchema.index({ conversationId: 1, seq: 1 }, { unique: true });
|
|
66
|
+
harnessMessageSchema.index({ conversationId: 1, requestId: 1 }, { partialFilterExpression: { requestId: { $type: "string" } }, unique: true });
|
|
67
|
+
const registerHarnessMessage = () => {
|
|
68
|
+
if (mongoose_1.default.models.HarnessMessage) {
|
|
69
|
+
return mongoose_1.default.models.HarnessMessage;
|
|
70
|
+
}
|
|
71
|
+
return mongoose_1.default.model("HarnessMessage", harnessMessageSchema);
|
|
72
|
+
};
|
|
73
|
+
exports.registerHarnessMessage = registerHarnessMessage;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessOwner = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const harnessOwnerSchema = new mongoose_1.default.Schema({
|
|
10
|
+
expiresAt: {
|
|
11
|
+
description: "When the owner lease lapses unless the holder renews it",
|
|
12
|
+
required: true,
|
|
13
|
+
type: Date,
|
|
14
|
+
},
|
|
15
|
+
key: {
|
|
16
|
+
description: "Lease name; one row per singleton lease (the in-process runner uses default)",
|
|
17
|
+
required: true,
|
|
18
|
+
type: String,
|
|
19
|
+
},
|
|
20
|
+
owner: {
|
|
21
|
+
description: "Runner instance id that holds the lease",
|
|
22
|
+
required: true,
|
|
23
|
+
type: String,
|
|
24
|
+
},
|
|
25
|
+
}, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
26
|
+
harnessOwnerSchema.plugin(api_1.createdUpdatedPlugin);
|
|
27
|
+
harnessOwnerSchema.plugin(api_1.findOneOrNone);
|
|
28
|
+
harnessOwnerSchema.plugin(api_1.findExactlyOne);
|
|
29
|
+
harnessOwnerSchema.index({ key: 1 }, { unique: true });
|
|
30
|
+
const registerHarnessOwner = () => {
|
|
31
|
+
if (mongoose_1.default.models.HarnessOwner) {
|
|
32
|
+
return mongoose_1.default.models.HarnessOwner;
|
|
33
|
+
}
|
|
34
|
+
return mongoose_1.default.model("HarnessOwner", harnessOwnerSchema);
|
|
35
|
+
};
|
|
36
|
+
exports.registerHarnessOwner = registerHarnessOwner;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerHarnessTask = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const harness_1 = require("../../types/harness");
|
|
10
|
+
const harnessTaskSchema = new mongoose_1.default.Schema({
|
|
11
|
+
abortRequested: {
|
|
12
|
+
at: { description: "When an abort of this task was requested", type: Date },
|
|
13
|
+
handlerClaimExpiresAt: {
|
|
14
|
+
description: "Until when one aborter holds the right to run the abort handler",
|
|
15
|
+
type: Date,
|
|
16
|
+
},
|
|
17
|
+
reason: { description: "Why the abort was requested", type: String },
|
|
18
|
+
userId: {
|
|
19
|
+
description: "Who requested the abort",
|
|
20
|
+
ref: "User",
|
|
21
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
ancestorIds: {
|
|
25
|
+
default: () => [],
|
|
26
|
+
description: "Owning tasks from the root down to the parent (empty for a root task); scopes task event streams to a subtree",
|
|
27
|
+
ref: "HarnessTask",
|
|
28
|
+
type: [mongoose_1.default.Schema.Types.ObjectId],
|
|
29
|
+
},
|
|
30
|
+
attempt: {
|
|
31
|
+
default: 0,
|
|
32
|
+
description: "Failed attempts consumed by the current phase",
|
|
33
|
+
type: Number,
|
|
34
|
+
},
|
|
35
|
+
background: {
|
|
36
|
+
default: false,
|
|
37
|
+
description: "When true, the task outlives its owning conversation turn",
|
|
38
|
+
type: Boolean,
|
|
39
|
+
},
|
|
40
|
+
claims: {
|
|
41
|
+
default: 0,
|
|
42
|
+
description: "Times a runner claimed the task; numbers each runnable visit for job dispatch",
|
|
43
|
+
type: Number,
|
|
44
|
+
},
|
|
45
|
+
eventSeq: {
|
|
46
|
+
default: 0,
|
|
47
|
+
description: "Events received by harness.sendEvent; numbers the task's inbox",
|
|
48
|
+
type: Number,
|
|
49
|
+
},
|
|
50
|
+
input: { description: "Immutable task input", type: mongoose_1.default.Schema.Types.Mixed },
|
|
51
|
+
lease: {
|
|
52
|
+
acquiredAt: {
|
|
53
|
+
description: "When the current phase started under this lease",
|
|
54
|
+
type: Date,
|
|
55
|
+
},
|
|
56
|
+
expiresAt: { description: "When the current execution lease lapses", type: Date },
|
|
57
|
+
owner: { description: "Runner instance that holds the execution lease", type: String },
|
|
58
|
+
token: { description: "Fencing token every commit must match", type: String },
|
|
59
|
+
},
|
|
60
|
+
name: { description: "Registered task definition name", required: true, type: String },
|
|
61
|
+
outcome: {
|
|
62
|
+
error: { description: "Failure cause for a failed task", type: String },
|
|
63
|
+
result: { description: "Result value for a completed task", type: mongoose_1.default.Schema.Types.Mixed },
|
|
64
|
+
status: {
|
|
65
|
+
description: "Terminal status recorded with the outcome",
|
|
66
|
+
enum: ["aborted", "completed", "failed"],
|
|
67
|
+
type: String,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
ownership: {
|
|
71
|
+
id: {
|
|
72
|
+
description: "Owning conversation or task id; empty for root tasks",
|
|
73
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
74
|
+
},
|
|
75
|
+
kind: {
|
|
76
|
+
default: "root",
|
|
77
|
+
description: "What owns this task: a conversation, another task, or nothing (root)",
|
|
78
|
+
enum: ["conversation", "root", "task"],
|
|
79
|
+
type: String,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
phase: { description: "Current checkpointed phase name", required: true, type: String },
|
|
83
|
+
requestId: {
|
|
84
|
+
description: "Caller idempotency key; a repeated create returns the existing task",
|
|
85
|
+
type: String,
|
|
86
|
+
},
|
|
87
|
+
retry: {
|
|
88
|
+
backoffMs: { description: "Base retry backoff in milliseconds", type: Number },
|
|
89
|
+
maxAttempts: { description: "Attempts allowed per phase before the task fails", type: Number },
|
|
90
|
+
maxBackoffMs: { description: "Upper bound for retry backoff in milliseconds", type: Number },
|
|
91
|
+
},
|
|
92
|
+
rootSpanId: {
|
|
93
|
+
description: "Root CHAIN span that parents every phase span",
|
|
94
|
+
ref: "ObsSpan",
|
|
95
|
+
required: true,
|
|
96
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
97
|
+
},
|
|
98
|
+
rootTaskId: {
|
|
99
|
+
description: "Top of the ownership tree; equals _id for root tasks",
|
|
100
|
+
ref: "HarnessTask",
|
|
101
|
+
required: true,
|
|
102
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
103
|
+
},
|
|
104
|
+
runAt: { description: "Earliest time a runner may execute the task", type: Date },
|
|
105
|
+
state: { description: "Checkpointed task state", type: mongoose_1.default.Schema.Types.Mixed },
|
|
106
|
+
status: {
|
|
107
|
+
default: harness_1.HARNESS_TASK_STATUSES.pending,
|
|
108
|
+
description: "Lifecycle status of the task",
|
|
109
|
+
enum: Object.values(harness_1.HARNESS_TASK_STATUSES),
|
|
110
|
+
required: true,
|
|
111
|
+
type: String,
|
|
112
|
+
},
|
|
113
|
+
step: {
|
|
114
|
+
default: 0,
|
|
115
|
+
description: "Phase commits so far; names the current phase visit for idempotent child creation",
|
|
116
|
+
type: Number,
|
|
117
|
+
},
|
|
118
|
+
traceId: {
|
|
119
|
+
description: "ObsTrace that audits this task tree",
|
|
120
|
+
ref: "ObsTrace",
|
|
121
|
+
required: true,
|
|
122
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
123
|
+
},
|
|
124
|
+
userId: {
|
|
125
|
+
description: "User on whose behalf the task runs",
|
|
126
|
+
ref: "User",
|
|
127
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
128
|
+
},
|
|
129
|
+
version: { description: "Pinned task definition version", required: true, type: Number },
|
|
130
|
+
waiting: {
|
|
131
|
+
key: { description: "Event key or sleep reason the task waits on", type: String },
|
|
132
|
+
kind: {
|
|
133
|
+
description: "What the task waits for",
|
|
134
|
+
enum: ["event", "sleep", "tasks"],
|
|
135
|
+
type: String,
|
|
136
|
+
},
|
|
137
|
+
policy: {
|
|
138
|
+
description: "How child-task waits resolve",
|
|
139
|
+
enum: ["all", "failFast"],
|
|
140
|
+
type: String,
|
|
141
|
+
},
|
|
142
|
+
taskIds: {
|
|
143
|
+
description: "Child tasks the task waits on",
|
|
144
|
+
type: [mongoose_1.default.Schema.Types.ObjectId],
|
|
145
|
+
},
|
|
146
|
+
timeoutAt: { description: "When the wait times out", type: Date },
|
|
147
|
+
},
|
|
148
|
+
waits: {
|
|
149
|
+
description: "rt.waitFor / rt.sleep calls of the current phase visit by `<step>:<call index>`, so a re-run returns the same result",
|
|
150
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
151
|
+
},
|
|
152
|
+
}, {
|
|
153
|
+
// Keep empty objects: `{}` tool arguments and states are meaningful values.
|
|
154
|
+
minimize: false,
|
|
155
|
+
strict: "throw",
|
|
156
|
+
toJSON: { virtuals: true },
|
|
157
|
+
toObject: { virtuals: true },
|
|
158
|
+
});
|
|
159
|
+
harnessTaskSchema.plugin(api_1.createdUpdatedPlugin);
|
|
160
|
+
harnessTaskSchema.plugin(api_1.isDeletedPlugin);
|
|
161
|
+
harnessTaskSchema.plugin(api_1.findOneOrNone);
|
|
162
|
+
harnessTaskSchema.plugin(api_1.findExactlyOne);
|
|
163
|
+
harnessTaskSchema.index({ requestId: 1 }, { sparse: true, unique: true });
|
|
164
|
+
// Runner claim scan; compound index field order is query-significant.
|
|
165
|
+
harnessTaskSchema.index(Object.fromEntries([
|
|
166
|
+
["status", 1],
|
|
167
|
+
["runAt", 1],
|
|
168
|
+
]));
|
|
169
|
+
// Claim scan for event and sleep waits whose timeout passed.
|
|
170
|
+
harnessTaskSchema.index(Object.fromEntries([
|
|
171
|
+
["status", 1],
|
|
172
|
+
["waiting.timeoutAt", 1],
|
|
173
|
+
]));
|
|
174
|
+
harnessTaskSchema.index({ rootTaskId: 1 });
|
|
175
|
+
// Owned-task lookups for abort and child waits.
|
|
176
|
+
harnessTaskSchema.index(Object.fromEntries([
|
|
177
|
+
["ownership.id", 1],
|
|
178
|
+
["ownership.kind", 1],
|
|
179
|
+
]));
|
|
180
|
+
// Expired-lease recovery scan.
|
|
181
|
+
harnessTaskSchema.index(Object.fromEntries([
|
|
182
|
+
["status", 1],
|
|
183
|
+
["lease.expiresAt", 1],
|
|
184
|
+
]));
|
|
185
|
+
const registerHarnessTask = () => {
|
|
186
|
+
if (mongoose_1.default.models.HarnessTask) {
|
|
187
|
+
return mongoose_1.default.models.HarnessTask;
|
|
188
|
+
}
|
|
189
|
+
return mongoose_1.default.model("HarnessTask", harnessTaskSchema);
|
|
190
|
+
};
|
|
191
|
+
exports.registerHarnessTask = registerHarnessTask;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type mongoose from "mongoose";
|
|
2
|
+
import type { HarnessAgentDefinition, HarnessChildOutcome, HarnessExtensionDefinition, HarnessTaskDefinition, HarnessTaskDocument, HarnessTaskView, HarnessTestHooks, HarnessWaitPolicy } from "../types/harness";
|
|
3
|
+
import { type HarnessModels } from "./commit";
|
|
4
|
+
import type { ExecutionEnv } from "./executionEnv";
|
|
5
|
+
/** Everything the engine's task, ownership, and wait logic shares within one harness. */
|
|
6
|
+
export interface HarnessEngine {
|
|
7
|
+
/** Registered agents, by name; `rt.runAgent` only runs these. */
|
|
8
|
+
agents: Map<string, HarnessAgentDefinition>;
|
|
9
|
+
/** Abort controllers of tasks running in this process, by task id. */
|
|
10
|
+
controllers: Map<string, AbortController>;
|
|
11
|
+
definitions: Map<string, HarnessTaskDefinition>;
|
|
12
|
+
/** Handed to phases as `rt.env` and to tools as `api.env`. */
|
|
13
|
+
env?: ExecutionEnv;
|
|
14
|
+
/** Registered extensions, by name. */
|
|
15
|
+
extensions: Map<string, HarnessExtensionDefinition>;
|
|
16
|
+
models: HarnessModels;
|
|
17
|
+
testHooks?: HarnessTestHooks;
|
|
18
|
+
/** Tell the runner new work may be runnable. */
|
|
19
|
+
wake: () => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const toTaskView: (task: HarnessTaskDocument) => HarnessTaskView<unknown, unknown>;
|
|
22
|
+
/** How the top task of an abort is fenced and audited, when not a plain `abort`. */
|
|
23
|
+
export interface AbortTopOverride {
|
|
24
|
+
error: string;
|
|
25
|
+
filter: Record<string, unknown>;
|
|
26
|
+
output: Record<string, unknown>;
|
|
27
|
+
spanName: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Abort `top` and every non-terminal task it owns. First, top-down, each task is fenced
|
|
31
|
+
* (no new claims; a running phase loses its lease token) and its in-process run is
|
|
32
|
+
* signalled. Then, bottom-up, each task's `abort` handler runs and the task is committed
|
|
33
|
+
* `aborted` with an audit span. A descendant that settled on its own before its fence is
|
|
34
|
+
* skipped. Afterwards `top`'s owner is re-checked, since an aborted child can settle a
|
|
35
|
+
* parent's wait. Throws `HarnessCommitConflictError` when `top` is already terminal.
|
|
36
|
+
*/
|
|
37
|
+
export declare const abortTaskTree: ({ engine, override, reason, settleOwner, top, userId, }: {
|
|
38
|
+
engine: HarnessEngine;
|
|
39
|
+
override?: AbortTopOverride;
|
|
40
|
+
reason: string;
|
|
41
|
+
/** False when the caller already handles the owner (a failFast sibling abort). */
|
|
42
|
+
settleOwner?: boolean;
|
|
43
|
+
top: HarnessTaskDocument;
|
|
44
|
+
userId?: string;
|
|
45
|
+
}) => Promise<HarnessTaskDocument>;
|
|
46
|
+
/** Settled children of a `waitForTasks` call, in the order their ids were passed. */
|
|
47
|
+
export declare const childOutcomes: (ids: ReadonlyArray<string>, children: ReadonlyArray<HarnessTaskDocument>) => HarnessChildOutcome[];
|
|
48
|
+
/**
|
|
49
|
+
* Settle a child wait under `policy`. Under `failFast`, the first failed or aborted child
|
|
50
|
+
* aborts every sibling still in flight (with the sibling's subtree) before the wait
|
|
51
|
+
* resolves. Returns the children as they now stand and whether the wait is satisfied.
|
|
52
|
+
*/
|
|
53
|
+
export declare const settleChildren: ({ engine, ids, ownerId, policy, }: {
|
|
54
|
+
engine: HarnessEngine;
|
|
55
|
+
ids: ReadonlyArray<mongoose.Types.ObjectId>;
|
|
56
|
+
ownerId: mongoose.Types.ObjectId;
|
|
57
|
+
policy: HarnessWaitPolicy;
|
|
58
|
+
}) => Promise<{
|
|
59
|
+
children: HarnessTaskDocument[];
|
|
60
|
+
isSettled: boolean;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Wake `taskId` when it is `waiting` on child tasks that have now settled. Safe to call
|
|
64
|
+
* any number of times from anywhere: the wake itself is fenced on the wait.
|
|
65
|
+
*/
|
|
66
|
+
export declare const checkTaskWait: ({ engine, taskId, }: {
|
|
67
|
+
engine: HarnessEngine;
|
|
68
|
+
taskId: mongoose.Types.ObjectId;
|
|
69
|
+
}) => Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Start the next queued submission of every conversation that still has one, after
|
|
72
|
+
* freeing conversations stuck `busy` on a finished turn. A turn frees its conversation in
|
|
73
|
+
* its terminal commit and starts the next queued turn right after; this covers a process
|
|
74
|
+
* that died between the two. Returns how many turns started.
|
|
75
|
+
*/
|
|
76
|
+
export declare const sweepQueuedConversations: (engine: HarnessEngine) => Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Wake whatever owns a task that just settled: a waiting parent task re-checks its wait;
|
|
79
|
+
* a conversation whose turn ended goes back to `idle` and starts its next queued submission.
|
|
80
|
+
*/
|
|
81
|
+
export declare const settleTaskOwner: ({ engine, task, }: {
|
|
82
|
+
engine: HarnessEngine;
|
|
83
|
+
task: HarnessTaskDocument;
|
|
84
|
+
}) => Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Re-check tasks waiting on children. Covers wakes lost to a crash between a child's
|
|
87
|
+
* terminal commit and its owner check. Returns how many tasks were woken.
|
|
88
|
+
*/
|
|
89
|
+
export declare const sweepWaitingTasks: (engine: HarnessEngine) => Promise<number>;
|