@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,252 @@
|
|
|
1
|
+
import {APIError, asyncHandler, authenticateMiddleware, createOpenApiBuilder} from "@terreno/api";
|
|
2
|
+
import type expressTypes from "express";
|
|
3
|
+
import express from "express";
|
|
4
|
+
|
|
5
|
+
import {type LocalDatasetStore, throwOnDatasetImportErrors} from "../local/datasetStore";
|
|
6
|
+
import {
|
|
7
|
+
type ObservabilityRouteAccessOptions,
|
|
8
|
+
observabilityAccessMiddleware,
|
|
9
|
+
observabilityRouteMiddleware,
|
|
10
|
+
} from "./observabilityRouteAccess";
|
|
11
|
+
|
|
12
|
+
const BASE_PATH = "/ai/observability";
|
|
13
|
+
|
|
14
|
+
export interface ObservabilityDatasetRouteOptions extends ObservabilityRouteAccessOptions {
|
|
15
|
+
store: LocalDatasetStore;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const addObservabilityDatasetRoutes = (
|
|
19
|
+
router: expressTypes.Application,
|
|
20
|
+
options: ObservabilityDatasetRouteOptions
|
|
21
|
+
): void => {
|
|
22
|
+
const openApiOptions = options.openApi ? {openApi: options.openApi} : {};
|
|
23
|
+
const builder = (): ReturnType<typeof createOpenApiBuilder> => {
|
|
24
|
+
return createOpenApiBuilder(openApiOptions as Parameters<typeof createOpenApiBuilder>[0]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
router.get(
|
|
28
|
+
`${BASE_PATH}/datasets`,
|
|
29
|
+
observabilityRouteMiddleware(
|
|
30
|
+
options.accessControl,
|
|
31
|
+
{action: "list", resource: "aiDataset"},
|
|
32
|
+
builder()
|
|
33
|
+
.withTags(["observability"])
|
|
34
|
+
.withSummary("List datasets")
|
|
35
|
+
.withResponse(200, {})
|
|
36
|
+
.build()
|
|
37
|
+
),
|
|
38
|
+
asyncHandler(async (_req, res) => {
|
|
39
|
+
return res.json({data: await options.store.list()});
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
router.post(
|
|
44
|
+
`${BASE_PATH}/datasets`,
|
|
45
|
+
observabilityRouteMiddleware(
|
|
46
|
+
options.accessControl,
|
|
47
|
+
{action: "create", resource: "aiDataset"},
|
|
48
|
+
builder()
|
|
49
|
+
.withTags(["observability"])
|
|
50
|
+
.withSummary("Create a dataset")
|
|
51
|
+
.withResponse(201, {})
|
|
52
|
+
.build()
|
|
53
|
+
),
|
|
54
|
+
asyncHandler(async (req, res) => {
|
|
55
|
+
const data = await options.store.create(req.body);
|
|
56
|
+
return res.status(201).json({data});
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
router.get(
|
|
61
|
+
`${BASE_PATH}/datasets/:id`,
|
|
62
|
+
observabilityRouteMiddleware(
|
|
63
|
+
options.accessControl,
|
|
64
|
+
{action: "read", resource: "aiDataset"},
|
|
65
|
+
builder()
|
|
66
|
+
.withTags(["observability"])
|
|
67
|
+
.withSummary("Get a dataset")
|
|
68
|
+
.withPathParameter("id", {type: "string"})
|
|
69
|
+
.withResponse(200, {})
|
|
70
|
+
.build()
|
|
71
|
+
),
|
|
72
|
+
asyncHandler(async (req, res) => {
|
|
73
|
+
return res.json({data: await options.store.get(req.params.id)});
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
router.patch(
|
|
78
|
+
`${BASE_PATH}/datasets/:id`,
|
|
79
|
+
observabilityRouteMiddleware(
|
|
80
|
+
options.accessControl,
|
|
81
|
+
{action: "update", resource: "aiDataset"},
|
|
82
|
+
builder()
|
|
83
|
+
.withTags(["observability"])
|
|
84
|
+
.withSummary("Update a dataset")
|
|
85
|
+
.withPathParameter("id", {type: "string"})
|
|
86
|
+
.withResponse(200, {})
|
|
87
|
+
.build()
|
|
88
|
+
),
|
|
89
|
+
asyncHandler(async (req, res) => {
|
|
90
|
+
return res.json({data: await options.store.update(req.params.id, req.body)});
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
router.delete(
|
|
95
|
+
`${BASE_PATH}/datasets/:id`,
|
|
96
|
+
observabilityRouteMiddleware(
|
|
97
|
+
options.accessControl,
|
|
98
|
+
{action: "delete", resource: "aiDataset"},
|
|
99
|
+
builder()
|
|
100
|
+
.withTags(["observability"])
|
|
101
|
+
.withSummary("Delete a dataset")
|
|
102
|
+
.withPathParameter("id", {type: "string"})
|
|
103
|
+
.withResponse(204, {})
|
|
104
|
+
.build()
|
|
105
|
+
),
|
|
106
|
+
asyncHandler(async (req, res) => {
|
|
107
|
+
await options.store.remove(req.params.id);
|
|
108
|
+
return res.status(204).end();
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
router.get(
|
|
113
|
+
`${BASE_PATH}/datasets/:id/items`,
|
|
114
|
+
observabilityRouteMiddleware(
|
|
115
|
+
options.accessControl,
|
|
116
|
+
{action: "read", resource: "aiDataset"},
|
|
117
|
+
builder()
|
|
118
|
+
.withTags(["observability"])
|
|
119
|
+
.withSummary("List dataset items")
|
|
120
|
+
.withPathParameter("id", {type: "string"})
|
|
121
|
+
.withResponse(200, {})
|
|
122
|
+
.build()
|
|
123
|
+
),
|
|
124
|
+
asyncHandler(async (req, res) => {
|
|
125
|
+
return res.json({data: await options.store.listItems(req.params.id)});
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
router.post(
|
|
130
|
+
`${BASE_PATH}/datasets/:id/items`,
|
|
131
|
+
observabilityRouteMiddleware(
|
|
132
|
+
options.accessControl,
|
|
133
|
+
{action: "update", resource: "aiDataset"},
|
|
134
|
+
builder()
|
|
135
|
+
.withTags(["observability"])
|
|
136
|
+
.withSummary("Create a dataset item")
|
|
137
|
+
.withPathParameter("id", {type: "string"})
|
|
138
|
+
.withResponse(201, {})
|
|
139
|
+
.build()
|
|
140
|
+
),
|
|
141
|
+
asyncHandler(async (req, res) => {
|
|
142
|
+
const data = await options.store.createItem(req.params.id, req.body);
|
|
143
|
+
return res.status(201).json({data});
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
router.patch(
|
|
148
|
+
`${BASE_PATH}/datasets/:id/items/:itemId`,
|
|
149
|
+
observabilityRouteMiddleware(
|
|
150
|
+
options.accessControl,
|
|
151
|
+
{action: "update", resource: "aiDataset"},
|
|
152
|
+
builder()
|
|
153
|
+
.withTags(["observability"])
|
|
154
|
+
.withSummary("Update a dataset item")
|
|
155
|
+
.withPathParameter("id", {type: "string"})
|
|
156
|
+
.withPathParameter("itemId", {type: "string"})
|
|
157
|
+
.withResponse(200, {})
|
|
158
|
+
.build()
|
|
159
|
+
),
|
|
160
|
+
asyncHandler(async (req, res) => {
|
|
161
|
+
const data = await options.store.updateItem(req.params.id, req.params.itemId, req.body);
|
|
162
|
+
return res.json({data});
|
|
163
|
+
})
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
router.delete(
|
|
167
|
+
`${BASE_PATH}/datasets/:id/items/:itemId`,
|
|
168
|
+
observabilityRouteMiddleware(
|
|
169
|
+
options.accessControl,
|
|
170
|
+
{action: "delete", resource: "aiDataset"},
|
|
171
|
+
builder()
|
|
172
|
+
.withTags(["observability"])
|
|
173
|
+
.withSummary("Delete a dataset item")
|
|
174
|
+
.withPathParameter("id", {type: "string"})
|
|
175
|
+
.withPathParameter("itemId", {type: "string"})
|
|
176
|
+
.withResponse(204, {})
|
|
177
|
+
.build()
|
|
178
|
+
),
|
|
179
|
+
asyncHandler(async (req, res) => {
|
|
180
|
+
await options.store.removeItem(req.params.id, req.params.itemId);
|
|
181
|
+
return res.status(204).end();
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
router.post(
|
|
186
|
+
`${BASE_PATH}/datasets/:id/import`,
|
|
187
|
+
[
|
|
188
|
+
express.text({type: ["text/csv", "text/plain"]}),
|
|
189
|
+
authenticateMiddleware(),
|
|
190
|
+
observabilityAccessMiddleware(options.accessControl, {
|
|
191
|
+
action: "update",
|
|
192
|
+
resource: "aiDataset",
|
|
193
|
+
}),
|
|
194
|
+
builder()
|
|
195
|
+
.withTags(["observability"])
|
|
196
|
+
.withSummary("Import dataset items from JSON or CSV")
|
|
197
|
+
.withPathParameter("id", {type: "string"})
|
|
198
|
+
.withResponse(200, {})
|
|
199
|
+
.build(),
|
|
200
|
+
],
|
|
201
|
+
asyncHandler(async (req, res) => {
|
|
202
|
+
const contentType = req.headers["content-type"] ?? "";
|
|
203
|
+
if (contentType.includes("text/csv")) {
|
|
204
|
+
const content = typeof req.body === "string" ? req.body : String(req.body ?? "");
|
|
205
|
+
const data = await options.store.importCsv(req.params.id, content);
|
|
206
|
+
throwOnDatasetImportErrors(data);
|
|
207
|
+
return res.json({data});
|
|
208
|
+
}
|
|
209
|
+
const body = req.body as {content?: string; format?: string; rows?: unknown};
|
|
210
|
+
if (body.format === "csv") {
|
|
211
|
+
if (!body.content) {
|
|
212
|
+
throw new APIError({status: 400, title: "CSV import requires content"});
|
|
213
|
+
}
|
|
214
|
+
const data = await options.store.importCsv(req.params.id, body.content);
|
|
215
|
+
throwOnDatasetImportErrors(data);
|
|
216
|
+
return res.json({data});
|
|
217
|
+
}
|
|
218
|
+
const payload = body.rows ?? body;
|
|
219
|
+
const data = await options.store.importJson(req.params.id, payload);
|
|
220
|
+
throwOnDatasetImportErrors(data);
|
|
221
|
+
return res.json({data});
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
router.post(
|
|
226
|
+
`${BASE_PATH}/traces/add-to-dataset`,
|
|
227
|
+
observabilityRouteMiddleware(
|
|
228
|
+
options.accessControl,
|
|
229
|
+
{action: "update", resource: "aiDataset"},
|
|
230
|
+
builder()
|
|
231
|
+
.withTags(["observability"])
|
|
232
|
+
.withSummary("Copy one or many traces into a dataset")
|
|
233
|
+
.withResponse(201, {})
|
|
234
|
+
.build()
|
|
235
|
+
),
|
|
236
|
+
asyncHandler(async (req, res) => {
|
|
237
|
+
const body = req.body as {datasetId?: string; traceId?: string; traceIds?: string[]};
|
|
238
|
+
if (!body.datasetId) {
|
|
239
|
+
throw new APIError({status: 400, title: "datasetId is required"});
|
|
240
|
+
}
|
|
241
|
+
const traceIds = body.traceIds ?? (body.traceId ? [body.traceId] : []);
|
|
242
|
+
if (traceIds.length === 0) {
|
|
243
|
+
throw new APIError({status: 400, title: "traceId or traceIds is required"});
|
|
244
|
+
}
|
|
245
|
+
const data = await options.store.addTracesToDataset({
|
|
246
|
+
datasetId: body.datasetId,
|
|
247
|
+
traceIds,
|
|
248
|
+
});
|
|
249
|
+
return res.status(201).json({data});
|
|
250
|
+
})
|
|
251
|
+
);
|
|
252
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import {TerrenoApp} from "@terreno/api";
|
|
3
|
+
import type express from "express";
|
|
4
|
+
|
|
5
|
+
import {authAsUser, ensureTestUsers, UserModel} from "../../tests/helpers";
|
|
6
|
+
import {createLocalObservabilityPlugin} from "../local/localPlugin";
|
|
7
|
+
import {registerObsEvaluator} from "../local/models/obsEvaluator";
|
|
8
|
+
import {registerObsPrompt} from "../local/models/obsPrompt";
|
|
9
|
+
import {registerObsPromptLabel} from "../local/models/obsPromptLabel";
|
|
10
|
+
import {registerObsPromptVersion} from "../local/models/obsPromptVersion";
|
|
11
|
+
import {LocalPromptStore} from "../local/promptStore";
|
|
12
|
+
import {ObservabilityApp, resetObservabilityApp} from "../observabilityApp";
|
|
13
|
+
|
|
14
|
+
describe("observability evaluator routes", () => {
|
|
15
|
+
let app: express.Application;
|
|
16
|
+
|
|
17
|
+
beforeAll(async () => {
|
|
18
|
+
await ensureTestUsers();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
resetObservabilityApp();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
await registerObsEvaluator().deleteMany({});
|
|
27
|
+
await registerObsPromptLabel().deleteMany({});
|
|
28
|
+
await registerObsPromptVersion().deleteMany({});
|
|
29
|
+
await registerObsPrompt().deleteMany({});
|
|
30
|
+
const promptStore = new LocalPromptStore();
|
|
31
|
+
await promptStore.create({
|
|
32
|
+
folder: "eval",
|
|
33
|
+
name: "eval-judge-correctness",
|
|
34
|
+
outputSchema: {
|
|
35
|
+
properties: {correct: {type: "boolean"}},
|
|
36
|
+
required: ["correct"],
|
|
37
|
+
type: "object",
|
|
38
|
+
},
|
|
39
|
+
system: "Judge correctness",
|
|
40
|
+
type: "text",
|
|
41
|
+
});
|
|
42
|
+
await promptStore.moveLabel("eval-judge-correctness", {label: "production", version: 1});
|
|
43
|
+
app = new TerrenoApp({skipListen: true, userModel: UserModel})
|
|
44
|
+
.register(new ObservabilityApp({plugins: [createLocalObservabilityPlugin()]}))
|
|
45
|
+
.build();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("installs a template by name and rejects human live sampling", async () => {
|
|
49
|
+
const agent = await authAsUser(app, "admin");
|
|
50
|
+
const templates = await agent.get("/ai/observability/evaluators/templates");
|
|
51
|
+
expect(templates.status).toBe(200);
|
|
52
|
+
expect(templates.body.data.some((row: {name: string}) => row.name === "correctness")).toBe(
|
|
53
|
+
true
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const installed = await agent.post("/ai/observability/evaluators/templates/correctness");
|
|
57
|
+
expect(installed.status).toBe(201);
|
|
58
|
+
expect(installed.body.data.name).toBe("correctness");
|
|
59
|
+
expect(installed.body.data.type).toBe("llm-judge");
|
|
60
|
+
|
|
61
|
+
const humanInstalled = await agent.post(
|
|
62
|
+
"/ai/observability/evaluators/templates/correctness-human"
|
|
63
|
+
);
|
|
64
|
+
expect(humanInstalled.status).toBe(201);
|
|
65
|
+
expect(humanInstalled.body.data.type).toBe("human");
|
|
66
|
+
|
|
67
|
+
const live = await agent.post("/ai/observability/evaluators").send({
|
|
68
|
+
dimensions: [{dataType: "boolean", key: "correct", required: true}],
|
|
69
|
+
name: "live-human",
|
|
70
|
+
runModes: {allowManualRun: true, availableInExperiments: true, liveSampleRate: 10},
|
|
71
|
+
target: "full trace",
|
|
72
|
+
type: "human",
|
|
73
|
+
});
|
|
74
|
+
expect(live.status).toBe(400);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("supports evaluator CRUD routes", async () => {
|
|
78
|
+
const agent = await authAsUser(app, "admin");
|
|
79
|
+
const listed = await agent.get("/ai/observability/evaluators");
|
|
80
|
+
expect(listed.status).toBe(200);
|
|
81
|
+
|
|
82
|
+
const created = await agent.post("/ai/observability/evaluators").send({
|
|
83
|
+
assertion: {constraint: "exists", path: "answer"},
|
|
84
|
+
confidenceAlertBelow: 0.6,
|
|
85
|
+
description: "route evaluator",
|
|
86
|
+
dimensions: [{dataType: "boolean", key: "correct", required: true}],
|
|
87
|
+
instructions: "Check it",
|
|
88
|
+
judgePromptName: "eval-judge-correctness",
|
|
89
|
+
name: "route-evaluator",
|
|
90
|
+
target: "full trace",
|
|
91
|
+
type: "llm-judge",
|
|
92
|
+
});
|
|
93
|
+
expect(created.status).toBe(201);
|
|
94
|
+
expect(created.body.data.target).toBe("full trace");
|
|
95
|
+
|
|
96
|
+
const spanTarget = await agent.post("/ai/observability/evaluators").send({
|
|
97
|
+
dimensions: [{dataType: "boolean", key: "correct", required: true}],
|
|
98
|
+
judgePromptName: "eval-judge-correctness",
|
|
99
|
+
name: "span-evaluator",
|
|
100
|
+
target: "generation span",
|
|
101
|
+
type: "llm-judge",
|
|
102
|
+
});
|
|
103
|
+
expect(spanTarget.status).toBe(400);
|
|
104
|
+
expect(spanTarget.body.title).toBe("Only full trace evaluators are supported");
|
|
105
|
+
const evaluatorId = created.body.data.id as string;
|
|
106
|
+
|
|
107
|
+
const detail = await agent.get(`/ai/observability/evaluators/${evaluatorId}`);
|
|
108
|
+
expect(detail.status).toBe(200);
|
|
109
|
+
|
|
110
|
+
const updated = await agent.patch(`/ai/observability/evaluators/${evaluatorId}`).send({
|
|
111
|
+
description: "updated",
|
|
112
|
+
});
|
|
113
|
+
expect(updated.status).toBe(200);
|
|
114
|
+
expect(updated.body.data.description).toBe("updated");
|
|
115
|
+
|
|
116
|
+
const deleted = await agent.delete(`/ai/observability/evaluators/${evaluatorId}`);
|
|
117
|
+
expect(deleted.status).toBe(204);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {APIError, asyncHandler, createOpenApiBuilder} from "@terreno/api";
|
|
2
|
+
import type express from "express";
|
|
3
|
+
|
|
4
|
+
import {EVALUATOR_TEMPLATES} from "../evaluatorTemplates";
|
|
5
|
+
import type {EvaluatorWriteInput, LocalEvaluatorStore} from "../local/evaluatorStore";
|
|
6
|
+
import {
|
|
7
|
+
type ObservabilityRouteAccessOptions,
|
|
8
|
+
observabilityRouteMiddleware,
|
|
9
|
+
} from "./observabilityRouteAccess";
|
|
10
|
+
|
|
11
|
+
const BASE_PATH = "/ai/observability";
|
|
12
|
+
|
|
13
|
+
export interface ObservabilityEvaluatorRouteOptions extends ObservabilityRouteAccessOptions {
|
|
14
|
+
store: LocalEvaluatorStore;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const writeFromBody = (
|
|
18
|
+
body: Record<string, unknown>,
|
|
19
|
+
mode: "create" | "update"
|
|
20
|
+
): Partial<EvaluatorWriteInput> => {
|
|
21
|
+
const input: Partial<EvaluatorWriteInput> = {};
|
|
22
|
+
if (typeof body.name === "string") {
|
|
23
|
+
input.name = body.name;
|
|
24
|
+
}
|
|
25
|
+
if (body.target) {
|
|
26
|
+
input.target = body.target as EvaluatorWriteInput["target"];
|
|
27
|
+
}
|
|
28
|
+
if (body.type) {
|
|
29
|
+
input.type = body.type as EvaluatorWriteInput["type"];
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(body.dimensions)) {
|
|
32
|
+
input.dimensions = body.dimensions as EvaluatorWriteInput["dimensions"];
|
|
33
|
+
}
|
|
34
|
+
if (body.runModes) {
|
|
35
|
+
input.runModes = body.runModes as EvaluatorWriteInput["runModes"];
|
|
36
|
+
}
|
|
37
|
+
if (typeof body.instructions === "string") {
|
|
38
|
+
input.instructions = body.instructions;
|
|
39
|
+
}
|
|
40
|
+
if (typeof body.description === "string") {
|
|
41
|
+
input.description = body.description;
|
|
42
|
+
}
|
|
43
|
+
if (typeof body.confidenceAlertBelow === "number") {
|
|
44
|
+
input.confidenceAlertBelow = body.confidenceAlertBelow;
|
|
45
|
+
}
|
|
46
|
+
if (typeof body.judgePromptName === "string") {
|
|
47
|
+
input.judgePromptName = body.judgePromptName;
|
|
48
|
+
}
|
|
49
|
+
if (body.assertion && typeof body.assertion === "object") {
|
|
50
|
+
input.assertion = body.assertion as EvaluatorWriteInput["assertion"];
|
|
51
|
+
}
|
|
52
|
+
if (mode === "create") {
|
|
53
|
+
return {
|
|
54
|
+
...input,
|
|
55
|
+
dimensions: input.dimensions ?? [],
|
|
56
|
+
name: input.name ?? "",
|
|
57
|
+
// TODO: enable generation span and dataset item targets.
|
|
58
|
+
target: input.target ?? "full trace",
|
|
59
|
+
type: input.type ?? "human",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return input;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const addObservabilityEvaluatorRoutes = (
|
|
66
|
+
router: express.Application,
|
|
67
|
+
options: ObservabilityEvaluatorRouteOptions
|
|
68
|
+
): void => {
|
|
69
|
+
const openApiOptions = options.openApi ? {openApi: options.openApi} : {};
|
|
70
|
+
const builder = (): ReturnType<typeof createOpenApiBuilder> => {
|
|
71
|
+
return createOpenApiBuilder(openApiOptions as Parameters<typeof createOpenApiBuilder>[0]);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
router.get(
|
|
75
|
+
`${BASE_PATH}/evaluators/templates`,
|
|
76
|
+
observabilityRouteMiddleware(
|
|
77
|
+
options.accessControl,
|
|
78
|
+
{action: "list", resource: "aiEvaluator"},
|
|
79
|
+
builder()
|
|
80
|
+
.withTags(["observability"])
|
|
81
|
+
.withSummary("List seeded evaluator templates")
|
|
82
|
+
.withResponse(200, {data: {type: "array"}})
|
|
83
|
+
.build()
|
|
84
|
+
),
|
|
85
|
+
asyncHandler(async (_req, res) => {
|
|
86
|
+
return res.json({data: EVALUATOR_TEMPLATES});
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
router.post(
|
|
91
|
+
`${BASE_PATH}/evaluators/templates/:name`,
|
|
92
|
+
observabilityRouteMiddleware(
|
|
93
|
+
options.accessControl,
|
|
94
|
+
{action: "create", resource: "aiEvaluator"},
|
|
95
|
+
builder()
|
|
96
|
+
.withTags(["observability"])
|
|
97
|
+
.withSummary("Install a seeded evaluator template")
|
|
98
|
+
.withPathParameter("name", {type: "string"})
|
|
99
|
+
.withResponse(201, {data: {type: "object"}})
|
|
100
|
+
.build()
|
|
101
|
+
),
|
|
102
|
+
asyncHandler(async (req, res) => {
|
|
103
|
+
const data = await options.store.installTemplate(req.params.name);
|
|
104
|
+
return res.status(201).json({data});
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
router.get(
|
|
109
|
+
`${BASE_PATH}/evaluators`,
|
|
110
|
+
observabilityRouteMiddleware(
|
|
111
|
+
options.accessControl,
|
|
112
|
+
{action: "list", resource: "aiEvaluator"},
|
|
113
|
+
builder()
|
|
114
|
+
.withTags(["observability"])
|
|
115
|
+
.withSummary("List evaluators")
|
|
116
|
+
.withResponse(200, {data: {type: "array"}})
|
|
117
|
+
.build()
|
|
118
|
+
),
|
|
119
|
+
asyncHandler(async (_req, res) => {
|
|
120
|
+
return res.json({data: await options.store.list()});
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
router.post(
|
|
125
|
+
`${BASE_PATH}/evaluators`,
|
|
126
|
+
observabilityRouteMiddleware(
|
|
127
|
+
options.accessControl,
|
|
128
|
+
{action: "create", resource: "aiEvaluator"},
|
|
129
|
+
builder()
|
|
130
|
+
.withTags(["observability"])
|
|
131
|
+
.withSummary("Create an evaluator")
|
|
132
|
+
.withResponse(201, {data: {type: "object"}})
|
|
133
|
+
.build()
|
|
134
|
+
),
|
|
135
|
+
asyncHandler(async (req, res) => {
|
|
136
|
+
const input = writeFromBody(
|
|
137
|
+
req.body as Record<string, unknown>,
|
|
138
|
+
"create"
|
|
139
|
+
) as EvaluatorWriteInput;
|
|
140
|
+
// TODO: enable generation span and dataset item targets.
|
|
141
|
+
if (input.target !== "full trace") {
|
|
142
|
+
throw new APIError({
|
|
143
|
+
status: 400,
|
|
144
|
+
title: "Only full trace evaluators are supported",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const data = await options.store.create(input);
|
|
148
|
+
return res.status(201).json({data});
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
router.get(
|
|
153
|
+
`${BASE_PATH}/evaluators/:id`,
|
|
154
|
+
observabilityRouteMiddleware(
|
|
155
|
+
options.accessControl,
|
|
156
|
+
{action: "read", resource: "aiEvaluator"},
|
|
157
|
+
builder()
|
|
158
|
+
.withTags(["observability"])
|
|
159
|
+
.withSummary("Get an evaluator")
|
|
160
|
+
.withPathParameter("id", {type: "string"})
|
|
161
|
+
.withResponse(200, {data: {type: "object"}})
|
|
162
|
+
.build()
|
|
163
|
+
),
|
|
164
|
+
asyncHandler(async (req, res) => {
|
|
165
|
+
return res.json({data: await options.store.get(req.params.id)});
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
router.patch(
|
|
170
|
+
`${BASE_PATH}/evaluators/:id`,
|
|
171
|
+
observabilityRouteMiddleware(
|
|
172
|
+
options.accessControl,
|
|
173
|
+
{action: "update", resource: "aiEvaluator"},
|
|
174
|
+
builder()
|
|
175
|
+
.withTags(["observability"])
|
|
176
|
+
.withSummary("Update an evaluator")
|
|
177
|
+
.withPathParameter("id", {type: "string"})
|
|
178
|
+
.withResponse(200, {data: {type: "object"}})
|
|
179
|
+
.build()
|
|
180
|
+
),
|
|
181
|
+
asyncHandler(async (req, res) => {
|
|
182
|
+
const data = await options.store.update(
|
|
183
|
+
req.params.id,
|
|
184
|
+
writeFromBody(req.body as Record<string, unknown>, "update")
|
|
185
|
+
);
|
|
186
|
+
return res.json({data});
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
router.delete(
|
|
191
|
+
`${BASE_PATH}/evaluators/:id`,
|
|
192
|
+
observabilityRouteMiddleware(
|
|
193
|
+
options.accessControl,
|
|
194
|
+
{action: "delete", resource: "aiEvaluator"},
|
|
195
|
+
builder()
|
|
196
|
+
.withTags(["observability"])
|
|
197
|
+
.withSummary("Delete an evaluator")
|
|
198
|
+
.withPathParameter("id", {type: "string"})
|
|
199
|
+
.withResponse(204, {})
|
|
200
|
+
.build()
|
|
201
|
+
),
|
|
202
|
+
asyncHandler(async (req, res) => {
|
|
203
|
+
await options.store.remove(req.params.id);
|
|
204
|
+
return res.status(204).end();
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
};
|