@terreno/ai 57.8.0 → 57.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursorrules +2 -2
- package/README.md +2 -1
- package/bunfig.toml +1 -1
- package/dist/aiApp.d.ts +16 -5
- package/dist/aiApp.js +17 -7
- 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 +127 -0
- package/dist/harness/errors.js +101 -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 +520 -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 +186 -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 +57 -0
- package/dist/harness/runners/inProcessRunner.js +196 -0
- package/dist/harness/runtime.d.ts +34 -0
- package/dist/harness/runtime.js +551 -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 +88 -2
- 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 +20 -7
- package/dist/routes/gpt.js +179 -488
- 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 +431 -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/fileUploadsGate.d.ts +8 -0
- package/dist/service/fileUploadsGate.js +18 -0
- package/dist/service/fillActionIds.d.ts +6 -0
- package/dist/service/fillActionIds.js +79 -0
- package/dist/service/gemini.d.ts +3 -3
- package/dist/service/gemini.js +3 -3
- 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/service/vertex.d.ts +6 -6
- package/dist/service/vertex.js +5 -5
- package/dist/types/harness.d.ts +934 -0
- package/dist/types/harness.js +133 -0
- package/dist/types/index.d.ts +219 -13
- 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 +17 -5
- package/src/aiApp.test.ts +207 -1
- package/src/aiApp.ts +31 -8
- 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/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 +119 -0
- package/src/harness/eventHub.test.ts +124 -0
- package/src/harness/eventHub.ts +159 -0
- package/src/harness/events.test.ts +757 -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 +767 -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 +201 -0
- package/src/harness/ownership.test.ts +1087 -0
- package/src/harness/ownership.ts +618 -0
- package/src/harness/recovery.test.ts +912 -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 +402 -0
- package/src/harness/runners/inProcessRunner.ts +220 -0
- package/src/harness/runtime.ts +714 -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.test.ts +2 -2
- package/src/models/aiRequest.ts +2 -1
- package/src/models/gptHistory.test.ts +156 -0
- package/src/models/gptHistory.ts +106 -4
- 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 +84 -9
- package/src/routes/files.ts +23 -7
- package/src/routes/gpt.test.ts +3279 -0
- package/src/routes/gpt.ts +214 -552
- 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 +676 -5
- package/src/service/aiDatasets.test.ts +123 -0
- package/src/service/aiDatasets.ts +316 -0
- package/src/service/aiService.test.ts +614 -0
- package/src/service/aiService.ts +575 -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/fileUploadsGate.ts +23 -0
- package/src/service/fillActionIds.test.ts +65 -0
- package/src/service/fillActionIds.ts +98 -0
- package/src/service/gemini.test.ts +16 -10
- package/src/service/gemini.ts +3 -3
- 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/service/vertex.test.ts +49 -49
- package/src/service/vertex.ts +7 -8
- 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 +1095 -0
- package/src/types/index.ts +237 -12
- package/src/types/observability.ts +344 -0
- package/src/types/sanitize-html.d.ts +25 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { APIError } from "@terreno/api";
|
|
2
|
+
/**
|
|
3
|
+
* A misuse of the task API; retrying the phase cannot fix it, so the task fails at once.
|
|
4
|
+
* An `APIError` (500, `harness-definition-invalid`); the specific problem is in `detail`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HarnessDefinitionError extends APIError {
|
|
7
|
+
constructor(detail: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HarnessDefinitionError = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
/**
|
|
7
|
+
* A misuse of the task API; retrying the phase cannot fix it, so the task fails at once.
|
|
8
|
+
* An `APIError` (500, `harness-definition-invalid`); the specific problem is in `detail`.
|
|
9
|
+
*/
|
|
10
|
+
class HarnessDefinitionError extends api_1.APIError {
|
|
11
|
+
constructor(detail) {
|
|
12
|
+
super({ ...errors_1.HARNESS_ERRORS.definitionInvalid, detail });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.HarnessDefinitionError = HarnessDefinitionError;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { APIError } from "@terreno/api";
|
|
2
|
+
/**
|
|
3
|
+
* Harness error vocabulary. Each kind is one stable problem type: `code` and `title` never
|
|
4
|
+
* change between occurrences; the per-occurrence sentence goes in `detail`.
|
|
5
|
+
*/
|
|
6
|
+
export interface HarnessErrorKind {
|
|
7
|
+
code: string;
|
|
8
|
+
status: number;
|
|
9
|
+
title: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const HARNESS_ERRORS: {
|
|
12
|
+
/** `start` called twice on a harness or runner. */
|
|
13
|
+
readonly alreadyStarted: {
|
|
14
|
+
readonly code: "harness-already-started";
|
|
15
|
+
readonly status: 409;
|
|
16
|
+
readonly title: "Already started";
|
|
17
|
+
};
|
|
18
|
+
/** Two writers raced on an approval; the loser can no longer decide it. */
|
|
19
|
+
readonly approvalNotPending: {
|
|
20
|
+
readonly code: "harness-approval-not-pending";
|
|
21
|
+
readonly status: 409;
|
|
22
|
+
readonly title: "Approval can no longer be decided";
|
|
23
|
+
};
|
|
24
|
+
/** A commit lost its checkpoint fence (lease taken over, task aborted, or phase moved). */
|
|
25
|
+
readonly commitConflict: {
|
|
26
|
+
readonly code: "harness-commit-conflict";
|
|
27
|
+
readonly status: 409;
|
|
28
|
+
readonly title: "Harness commit lost its checkpoint fence";
|
|
29
|
+
};
|
|
30
|
+
/** Invalid `Harness.open`, `HarnessApp`, runner, or model-resolver configuration. */
|
|
31
|
+
readonly configInvalid: {
|
|
32
|
+
readonly code: "harness-config-invalid";
|
|
33
|
+
readonly status: 500;
|
|
34
|
+
readonly title: "Invalid harness configuration";
|
|
35
|
+
};
|
|
36
|
+
/** A conversation is running a turn and `submit` cannot start another. */
|
|
37
|
+
readonly conversationBusy: {
|
|
38
|
+
readonly code: "harness-conversation-busy";
|
|
39
|
+
readonly status: 409;
|
|
40
|
+
readonly title: "Conversation is busy";
|
|
41
|
+
};
|
|
42
|
+
/** A subagent conversation: only its owning task's `rt.runAgent` runs turns. */
|
|
43
|
+
readonly conversationOwned: {
|
|
44
|
+
readonly code: "harness-conversation-owned";
|
|
45
|
+
readonly status: 409;
|
|
46
|
+
readonly title: "Conversation is run by its owning task";
|
|
47
|
+
};
|
|
48
|
+
/** Misuse of a definition API (`defineTask`, `rt.*`, ...); retrying cannot fix it. */
|
|
49
|
+
readonly definitionInvalid: {
|
|
50
|
+
readonly code: "harness-definition-invalid";
|
|
51
|
+
readonly status: 500;
|
|
52
|
+
readonly title: "Invalid harness definition";
|
|
53
|
+
};
|
|
54
|
+
/** An internal invariant broke; the work is retried or logged. */
|
|
55
|
+
readonly internal: {
|
|
56
|
+
readonly code: "harness-internal";
|
|
57
|
+
readonly status: 500;
|
|
58
|
+
readonly title: "Harness invariant violated";
|
|
59
|
+
};
|
|
60
|
+
/** A caller passed an invalid argument to a harness method. */
|
|
61
|
+
readonly invalidRequest: {
|
|
62
|
+
readonly code: "harness-invalid-request";
|
|
63
|
+
readonly status: 400;
|
|
64
|
+
readonly title: "Invalid harness request";
|
|
65
|
+
};
|
|
66
|
+
/** A harness row the call depends on no longer exists. */
|
|
67
|
+
readonly notFound: {
|
|
68
|
+
readonly code: "harness-not-found";
|
|
69
|
+
readonly status: 404;
|
|
70
|
+
readonly title: "Harness record not found";
|
|
71
|
+
};
|
|
72
|
+
/** A task definition, agent, or extension is not in this harness registry. */
|
|
73
|
+
readonly notRegistered: {
|
|
74
|
+
readonly code: "harness-not-registered";
|
|
75
|
+
readonly status: 404;
|
|
76
|
+
readonly title: "Not registered in this harness";
|
|
77
|
+
};
|
|
78
|
+
/** `Harness.open` on a MongoDB deployment without transactions (not a replica set or mongos). */
|
|
79
|
+
readonly replicaSetRequired: {
|
|
80
|
+
readonly code: "harness-replica-set-required";
|
|
81
|
+
readonly status: 500;
|
|
82
|
+
readonly title: "MongoDB replica set required";
|
|
83
|
+
};
|
|
84
|
+
/** A `requestId` (task or event) is already used for something else. */
|
|
85
|
+
readonly requestIdConflict: {
|
|
86
|
+
readonly code: "harness-request-id-conflict";
|
|
87
|
+
readonly status: 409;
|
|
88
|
+
readonly title: "requestId is already in use";
|
|
89
|
+
};
|
|
90
|
+
/** `retry` on a task whose abort is still running. */
|
|
91
|
+
readonly taskAborting: {
|
|
92
|
+
readonly code: "harness-task-aborting";
|
|
93
|
+
readonly status: 409;
|
|
94
|
+
readonly title: "Task is being aborted";
|
|
95
|
+
};
|
|
96
|
+
/** `resolveInterrupted` on a task that is not interrupted. */
|
|
97
|
+
readonly taskNotInterrupted: {
|
|
98
|
+
readonly code: "harness-task-not-interrupted";
|
|
99
|
+
readonly status: 409;
|
|
100
|
+
readonly title: "Task is not interrupted";
|
|
101
|
+
};
|
|
102
|
+
/** The task already ended, so it cannot be aborted or receive events. */
|
|
103
|
+
readonly taskTerminal: {
|
|
104
|
+
readonly code: "harness-task-terminal";
|
|
105
|
+
readonly status: 409;
|
|
106
|
+
readonly title: "Task already ended";
|
|
107
|
+
};
|
|
108
|
+
/** `Harness.waitFor` gave up before the task reached the status it waited for. */
|
|
109
|
+
readonly waitTimedOut: {
|
|
110
|
+
readonly code: "harness-wait-timed-out";
|
|
111
|
+
readonly status: 504;
|
|
112
|
+
readonly title: "Timed out waiting for task";
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export type HarnessErrorKindName = keyof typeof HARNESS_ERRORS;
|
|
116
|
+
/** Build an `APIError` of one harness kind; `detail` is a self-contained sentence. */
|
|
117
|
+
export declare const harnessError: ({ cause, detail, kind, }: {
|
|
118
|
+
cause?: unknown;
|
|
119
|
+
detail: string;
|
|
120
|
+
kind: HarnessErrorKindName;
|
|
121
|
+
}) => APIError;
|
|
122
|
+
/**
|
|
123
|
+
* The text recorded for a failure (task `error`, tool results the model sees, logs). Harness
|
|
124
|
+
* details are self-contained sentences, so they stand alone; other `APIError`s keep their
|
|
125
|
+
* title too, and plain errors use their message.
|
|
126
|
+
*/
|
|
127
|
+
export declare const errorMessage: (error: unknown) => string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorMessage = exports.harnessError = exports.HARNESS_ERRORS = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
exports.HARNESS_ERRORS = {
|
|
6
|
+
/** `start` called twice on a harness or runner. */
|
|
7
|
+
alreadyStarted: { code: "harness-already-started", status: 409, title: "Already started" },
|
|
8
|
+
/** Two writers raced on an approval; the loser can no longer decide it. */
|
|
9
|
+
approvalNotPending: {
|
|
10
|
+
code: "harness-approval-not-pending",
|
|
11
|
+
status: 409,
|
|
12
|
+
title: "Approval can no longer be decided",
|
|
13
|
+
},
|
|
14
|
+
/** A commit lost its checkpoint fence (lease taken over, task aborted, or phase moved). */
|
|
15
|
+
commitConflict: {
|
|
16
|
+
code: "harness-commit-conflict",
|
|
17
|
+
status: 409,
|
|
18
|
+
title: "Harness commit lost its checkpoint fence",
|
|
19
|
+
},
|
|
20
|
+
/** Invalid `Harness.open`, `HarnessApp`, runner, or model-resolver configuration. */
|
|
21
|
+
configInvalid: {
|
|
22
|
+
code: "harness-config-invalid",
|
|
23
|
+
status: 500,
|
|
24
|
+
title: "Invalid harness configuration",
|
|
25
|
+
},
|
|
26
|
+
/** A conversation is running a turn and `submit` cannot start another. */
|
|
27
|
+
conversationBusy: {
|
|
28
|
+
code: "harness-conversation-busy",
|
|
29
|
+
status: 409,
|
|
30
|
+
title: "Conversation is busy",
|
|
31
|
+
},
|
|
32
|
+
/** A subagent conversation: only its owning task's `rt.runAgent` runs turns. */
|
|
33
|
+
conversationOwned: {
|
|
34
|
+
code: "harness-conversation-owned",
|
|
35
|
+
status: 409,
|
|
36
|
+
title: "Conversation is run by its owning task",
|
|
37
|
+
},
|
|
38
|
+
/** Misuse of a definition API (`defineTask`, `rt.*`, ...); retrying cannot fix it. */
|
|
39
|
+
definitionInvalid: {
|
|
40
|
+
code: "harness-definition-invalid",
|
|
41
|
+
status: 500,
|
|
42
|
+
title: "Invalid harness definition",
|
|
43
|
+
},
|
|
44
|
+
/** An internal invariant broke; the work is retried or logged. */
|
|
45
|
+
internal: { code: "harness-internal", status: 500, title: "Harness invariant violated" },
|
|
46
|
+
/** A caller passed an invalid argument to a harness method. */
|
|
47
|
+
invalidRequest: { code: "harness-invalid-request", status: 400, title: "Invalid harness request" },
|
|
48
|
+
/** A harness row the call depends on no longer exists. */
|
|
49
|
+
notFound: { code: "harness-not-found", status: 404, title: "Harness record not found" },
|
|
50
|
+
/** A task definition, agent, or extension is not in this harness registry. */
|
|
51
|
+
notRegistered: {
|
|
52
|
+
code: "harness-not-registered",
|
|
53
|
+
status: 404,
|
|
54
|
+
title: "Not registered in this harness",
|
|
55
|
+
},
|
|
56
|
+
/** `Harness.open` on a MongoDB deployment without transactions (not a replica set or mongos). */
|
|
57
|
+
replicaSetRequired: {
|
|
58
|
+
code: "harness-replica-set-required",
|
|
59
|
+
status: 500,
|
|
60
|
+
title: "MongoDB replica set required",
|
|
61
|
+
},
|
|
62
|
+
/** A `requestId` (task or event) is already used for something else. */
|
|
63
|
+
requestIdConflict: {
|
|
64
|
+
code: "harness-request-id-conflict",
|
|
65
|
+
status: 409,
|
|
66
|
+
title: "requestId is already in use",
|
|
67
|
+
},
|
|
68
|
+
/** `retry` on a task whose abort is still running. */
|
|
69
|
+
taskAborting: { code: "harness-task-aborting", status: 409, title: "Task is being aborted" },
|
|
70
|
+
/** `resolveInterrupted` on a task that is not interrupted. */
|
|
71
|
+
taskNotInterrupted: {
|
|
72
|
+
code: "harness-task-not-interrupted",
|
|
73
|
+
status: 409,
|
|
74
|
+
title: "Task is not interrupted",
|
|
75
|
+
},
|
|
76
|
+
/** The task already ended, so it cannot be aborted or receive events. */
|
|
77
|
+
taskTerminal: { code: "harness-task-terminal", status: 409, title: "Task already ended" },
|
|
78
|
+
/** `Harness.waitFor` gave up before the task reached the status it waited for. */
|
|
79
|
+
waitTimedOut: {
|
|
80
|
+
code: "harness-wait-timed-out",
|
|
81
|
+
status: 504,
|
|
82
|
+
title: "Timed out waiting for task",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
/** Build an `APIError` of one harness kind; `detail` is a self-contained sentence. */
|
|
86
|
+
const harnessError = ({ cause, detail, kind, }) => {
|
|
87
|
+
return new api_1.APIError({ ...exports.HARNESS_ERRORS[kind], cause, detail });
|
|
88
|
+
};
|
|
89
|
+
exports.harnessError = harnessError;
|
|
90
|
+
/**
|
|
91
|
+
* The text recorded for a failure (task `error`, tool results the model sees, logs). Harness
|
|
92
|
+
* details are self-contained sentences, so they stand alone; other `APIError`s keep their
|
|
93
|
+
* title too, and plain errors use their message.
|
|
94
|
+
*/
|
|
95
|
+
const errorMessage = (error) => {
|
|
96
|
+
if ((0, api_1.isAPIError)(error) && error.code?.startsWith("harness-") && error.detail) {
|
|
97
|
+
return error.detail;
|
|
98
|
+
}
|
|
99
|
+
return (0, api_1.errorDetail)(error);
|
|
100
|
+
};
|
|
101
|
+
exports.errorMessage = errorMessage;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { HarnessEventDocument } from "../types/harness";
|
|
2
|
+
/** An event as a change stream delivers it (a raw document, not a mongoose model). */
|
|
3
|
+
export type HubEvent = Pick<HarnessEventDocument, "created" | "payload" | "seq" | "streamId" | "taskId" | "taskPath" | "type">;
|
|
4
|
+
/** One SSE connection's interest in the log. */
|
|
5
|
+
export interface HubSubscriber {
|
|
6
|
+
deliver: (event: HubEvent) => void;
|
|
7
|
+
/** The shared tail failed; the subscriber is already removed. */
|
|
8
|
+
fail: (error: unknown) => void;
|
|
9
|
+
streamId: string;
|
|
10
|
+
/** Task streams: only events whose `taskPath` includes this task. */
|
|
11
|
+
taskId?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One change stream on `HarnessEvent` per `HarnessApp`, shared by every SSE connection
|
|
15
|
+
* and fanned out in memory by stream (and task path). It opens with the first subscriber,
|
|
16
|
+
* at a cluster time read after that subscriber registered, and closes with the last. A
|
|
17
|
+
* subscriber registers before it queries its replay, and the tail delivers every insert
|
|
18
|
+
* committed after it opened, so each event committed after a subscriber's replay query
|
|
19
|
+
* reaches it through the tail: replay plus tail, deduplicated by `seq`, is exactly once.
|
|
20
|
+
* One stream holds one pooled connection however many clients watch.
|
|
21
|
+
*/
|
|
22
|
+
export declare class HarnessEventHub {
|
|
23
|
+
private changes;
|
|
24
|
+
private starting;
|
|
25
|
+
private readonly subscribers;
|
|
26
|
+
/** Number of open tails (0 or 1); for tests and diagnostics. */
|
|
27
|
+
get openStreams(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Register `subscriber` and make sure the tail is open. Returns the unsubscribe
|
|
30
|
+
* function. Throws (503) when no cluster time is available to start the tail.
|
|
31
|
+
*/
|
|
32
|
+
subscribe(subscriber: HubSubscriber): Promise<() => void>;
|
|
33
|
+
private unsubscribe;
|
|
34
|
+
private ensureStarted;
|
|
35
|
+
private start;
|
|
36
|
+
/**
|
|
37
|
+
* Read the tail until it is stopped or replaced (`this.changes` no longer points at it),
|
|
38
|
+
* then close it. The first read always finishes: `close()` before the server has assigned
|
|
39
|
+
* a cursor id skips `killCursors`, and the opening aggregate can still leave that cursor
|
|
40
|
+
* open on the server.
|
|
41
|
+
*/
|
|
42
|
+
private pump;
|
|
43
|
+
/** The tail failed: drop every subscriber (each closes its stream); the next one restarts it. */
|
|
44
|
+
private fail;
|
|
45
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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.HarnessEventHub = void 0;
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const harnessEvent_1 = require("./models/harnessEvent");
|
|
11
|
+
/** How long one wait on the tail may block; also how soon a stop takes effect. */
|
|
12
|
+
const TAIL_AWAIT_MS = 1000;
|
|
13
|
+
const matches = (subscriber, event) => String(event.streamId) === subscriber.streamId &&
|
|
14
|
+
(subscriber.taskId === undefined ||
|
|
15
|
+
(event.taskPath ?? []).some((id) => String(id) === subscriber.taskId));
|
|
16
|
+
/**
|
|
17
|
+
* One change stream on `HarnessEvent` per `HarnessApp`, shared by every SSE connection
|
|
18
|
+
* and fanned out in memory by stream (and task path). It opens with the first subscriber,
|
|
19
|
+
* at a cluster time read after that subscriber registered, and closes with the last. A
|
|
20
|
+
* subscriber registers before it queries its replay, and the tail delivers every insert
|
|
21
|
+
* committed after it opened, so each event committed after a subscriber's replay query
|
|
22
|
+
* reaches it through the tail: replay plus tail, deduplicated by `seq`, is exactly once.
|
|
23
|
+
* One stream holds one pooled connection however many clients watch.
|
|
24
|
+
*/
|
|
25
|
+
class HarnessEventHub {
|
|
26
|
+
changes;
|
|
27
|
+
starting;
|
|
28
|
+
subscribers = new Set();
|
|
29
|
+
/** Number of open tails (0 or 1); for tests and diagnostics. */
|
|
30
|
+
get openStreams() {
|
|
31
|
+
return this.changes ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Register `subscriber` and make sure the tail is open. Returns the unsubscribe
|
|
35
|
+
* function. Throws (503) when no cluster time is available to start the tail.
|
|
36
|
+
*/
|
|
37
|
+
async subscribe(subscriber) {
|
|
38
|
+
this.subscribers.add(subscriber);
|
|
39
|
+
const unsubscribe = () => this.unsubscribe(subscriber);
|
|
40
|
+
try {
|
|
41
|
+
await this.ensureStarted();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
unsubscribe();
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return unsubscribe;
|
|
48
|
+
}
|
|
49
|
+
unsubscribe(subscriber) {
|
|
50
|
+
this.subscribers.delete(subscriber);
|
|
51
|
+
if (this.subscribers.size === 0) {
|
|
52
|
+
// The pump finishes its current read (so the server cursor has an id) and closes the tail.
|
|
53
|
+
this.changes = undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async ensureStarted() {
|
|
57
|
+
if (this.changes) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.starting ??= this.start().finally(() => {
|
|
61
|
+
this.starting = undefined;
|
|
62
|
+
});
|
|
63
|
+
await this.starting;
|
|
64
|
+
}
|
|
65
|
+
async start() {
|
|
66
|
+
const ping = await mongoose_1.default.connection.db?.command({ ping: 1 });
|
|
67
|
+
const startAtOperationTime = ping?.operationTime;
|
|
68
|
+
// Without a start time the tail could miss events committed during a replay.
|
|
69
|
+
if (!startAtOperationTime) {
|
|
70
|
+
throw new api_1.APIError({ status: 503, title: "Event stream unavailable: no cluster time" });
|
|
71
|
+
}
|
|
72
|
+
// Every subscriber left while the cluster time was read.
|
|
73
|
+
if (this.subscribers.size === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const changes = (0, harnessEvent_1.registerHarnessEvent)().collection.watch([{ $match: { operationType: "insert" } }], { maxAwaitTimeMS: TAIL_AWAIT_MS, startAtOperationTime });
|
|
77
|
+
this.changes = changes;
|
|
78
|
+
void this.pump(changes);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Read the tail until it is stopped or replaced (`this.changes` no longer points at it),
|
|
82
|
+
* then close it. The first read always finishes: `close()` before the server has assigned
|
|
83
|
+
* a cursor id skips `killCursors`, and the opening aggregate can still leave that cursor
|
|
84
|
+
* open on the server.
|
|
85
|
+
*/
|
|
86
|
+
async pump(changes) {
|
|
87
|
+
let initialized = false;
|
|
88
|
+
try {
|
|
89
|
+
while (this.changes === changes || !initialized) {
|
|
90
|
+
// An invalidated (collection dropped) or externally closed tail is a failure
|
|
91
|
+
// only while this pump still owns it.
|
|
92
|
+
if (changes.closed) {
|
|
93
|
+
if (this.changes !== changes) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
throw (0, errors_1.harnessError)({ detail: "The HarnessEvent change stream closed", kind: "internal" });
|
|
97
|
+
}
|
|
98
|
+
const change = (await changes.tryNext());
|
|
99
|
+
initialized = true;
|
|
100
|
+
if (this.changes !== changes) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const event = change?.fullDocument;
|
|
104
|
+
if (!event) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
for (const subscriber of [...this.subscribers]) {
|
|
108
|
+
if (matches(subscriber, event)) {
|
|
109
|
+
subscriber.deliver(event);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (this.changes === changes) {
|
|
116
|
+
this.fail(error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
// A failed close only means the cursor is already gone.
|
|
121
|
+
await changes.close().catch(() => undefined);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** The tail failed: drop every subscriber (each closes its stream); the next one restarts it. */
|
|
125
|
+
fail(error) {
|
|
126
|
+
api_1.logger.warn(`Harness event tail failed; closing its SSE streams: ${(0, errors_1.errorMessage)(error)}`);
|
|
127
|
+
const subscribers = [...this.subscribers];
|
|
128
|
+
this.subscribers.clear();
|
|
129
|
+
this.changes = undefined;
|
|
130
|
+
for (const subscriber of subscribers) {
|
|
131
|
+
subscriber.fail(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.HarnessEventHub = HarnessEventHub;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Duration } from "luxon";
|
|
2
|
+
import type mongoose from "mongoose";
|
|
3
|
+
import type { ClientSession } from "mongoose";
|
|
4
|
+
import type { HarnessEventDocument, HarnessEventType, HarnessMessageDocument, HarnessStreamingOptions, HarnessTaskDocument } from "../types/harness";
|
|
5
|
+
import type { HarnessModels } from "./commit";
|
|
6
|
+
/** One event to append; `seq` and `created` are assigned on write. */
|
|
7
|
+
export interface HarnessEventInput {
|
|
8
|
+
expiresAt?: Date;
|
|
9
|
+
payload?: unknown;
|
|
10
|
+
taskId?: mongoose.Types.ObjectId;
|
|
11
|
+
taskPath?: mongoose.Types.ObjectId[];
|
|
12
|
+
type: HarnessEventType;
|
|
13
|
+
}
|
|
14
|
+
/** Streaming settings with every default applied. */
|
|
15
|
+
export interface ResolvedStreamingOptions {
|
|
16
|
+
deltaFlushChars: number;
|
|
17
|
+
deltaFlushInterval: Duration;
|
|
18
|
+
deltaTtl: Duration;
|
|
19
|
+
}
|
|
20
|
+
export declare const resolveStreamingOptions: (options?: HarnessStreamingOptions) => ResolvedStreamingOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Append `events` to `streamId` in order. The stream's counter hands out consecutive
|
|
23
|
+
* `seq`s in the same transaction, so concurrent writers to one stream serialize on it and
|
|
24
|
+
* a stream's events commit in `seq` order: a reader that has seen `seq` n has seen every
|
|
25
|
+
* earlier event. Without `session` the write runs in its own transaction.
|
|
26
|
+
*/
|
|
27
|
+
export declare const appendEvents: ({ events, models, session, streamId, }: {
|
|
28
|
+
events: ReadonlyArray<HarnessEventInput>;
|
|
29
|
+
models: HarnessModels;
|
|
30
|
+
session?: ClientSession;
|
|
31
|
+
streamId: mongoose.Types.ObjectId | string;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
/** The stream a task's events go to (its tree's root task) and its path within the tree. */
|
|
34
|
+
export declare const taskStreamOf: (task: Pick<HarnessTaskDocument, "_id" | "ancestorIds" | "rootTaskId">) => {
|
|
35
|
+
streamId: mongoose.Types.ObjectId;
|
|
36
|
+
taskPath: mongoose.Types.ObjectId[];
|
|
37
|
+
};
|
|
38
|
+
/** Append task-stream events about `task` (its tree's stream, scoped to its path). */
|
|
39
|
+
export declare const appendTaskEvents: ({ events, models, session, task, }: {
|
|
40
|
+
events: ReadonlyArray<Omit<HarnessEventInput, "taskId" | "taskPath">>;
|
|
41
|
+
models: HarnessModels;
|
|
42
|
+
session?: ClientSession;
|
|
43
|
+
task: Pick<HarnessTaskDocument, "_id" | "ancestorIds" | "rootTaskId">;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Events for a committed task write, in the write's transaction: `task.status` when the
|
|
47
|
+
* task was created or its status or phase changed, plus `turn.*` / `tool.*` on the
|
|
48
|
+
* conversation stream when a built-in agent task starts or ends.
|
|
49
|
+
*/
|
|
50
|
+
export declare const appendTaskTransitionEvents: ({ after, before, models, session, }: {
|
|
51
|
+
after: HarnessTaskDocument;
|
|
52
|
+
/** The task before the write; omitted for a newly created task. */
|
|
53
|
+
before?: Pick<HarnessTaskDocument, "phase" | "status">;
|
|
54
|
+
models: HarnessModels;
|
|
55
|
+
session: ClientSession;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
/** A transcript message as handed to `insertMessages`. */
|
|
58
|
+
export type HarnessMessageInput = Pick<HarnessMessageDocument, "conversationId" | "parts" | "role" | "seq"> & Partial<Pick<HarnessMessageDocument, "requestId" | "status" | "toolCallId" | "toolName" | "turnTaskId">>;
|
|
59
|
+
/** Insert transcript messages of one conversation and their `message.created` events. */
|
|
60
|
+
export declare const insertMessages: ({ messages, models, session, }: {
|
|
61
|
+
messages: ReadonlyArray<HarnessMessageInput>;
|
|
62
|
+
models: HarnessModels;
|
|
63
|
+
session: ClientSession;
|
|
64
|
+
}) => Promise<HarnessMessageDocument[]>;
|
|
65
|
+
/** Identifies the model request a `delta` belongs to. */
|
|
66
|
+
export interface HarnessDeltaSource {
|
|
67
|
+
conversationId: string;
|
|
68
|
+
/** Fresh per model-request attempt: a retry or re-run streams under a new key. */
|
|
69
|
+
requestKey: string;
|
|
70
|
+
step: number;
|
|
71
|
+
turnTaskId: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Coalesces streamed model text into `delta` events: buffered text is written once
|
|
75
|
+
* `deltaFlushChars` characters accumulate or `deltaFlushInterval` passes. Writes run in
|
|
76
|
+
* order, outside any commit, and are best-effort: a failed write is logged and dropped,
|
|
77
|
+
* since the committed message is authoritative.
|
|
78
|
+
*/
|
|
79
|
+
export declare class HarnessDeltaWriter {
|
|
80
|
+
private readonly context;
|
|
81
|
+
private buffer;
|
|
82
|
+
private pending;
|
|
83
|
+
private timer;
|
|
84
|
+
constructor(context: {
|
|
85
|
+
models: HarnessModels;
|
|
86
|
+
options: ResolvedStreamingOptions;
|
|
87
|
+
source: HarnessDeltaSource;
|
|
88
|
+
});
|
|
89
|
+
push(text: string): void;
|
|
90
|
+
/** Write what is buffered and wait for every write so far. */
|
|
91
|
+
close(): Promise<void>;
|
|
92
|
+
private flush;
|
|
93
|
+
}
|
|
94
|
+
/** The JSON body of an event as sent over SSE (`data:`). */
|
|
95
|
+
export declare const eventBody: (event: Pick<HarnessEventDocument, "created" | "payload" | "seq" | "taskId" | "type">) => Record<string, unknown>;
|