@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,96 @@
|
|
|
1
|
+
import {asyncHandler, createOpenApiBuilder} from "@terreno/api";
|
|
2
|
+
import type express from "express";
|
|
3
|
+
import type mongoose from "mongoose";
|
|
4
|
+
import {runTestMultiStageWorkflow} from "../testMultiStageWorkflow";
|
|
5
|
+
import type {
|
|
6
|
+
ObservabilityGenerateClient,
|
|
7
|
+
ObservabilityRequestAiServiceFactory,
|
|
8
|
+
TraceRecord,
|
|
9
|
+
} from "../types";
|
|
10
|
+
import {
|
|
11
|
+
type ObservabilityRouteAccessOptions,
|
|
12
|
+
observabilityRouteMiddleware,
|
|
13
|
+
} from "./observabilityRouteAccess";
|
|
14
|
+
import {resolveRequestAiService} from "./requestAiService";
|
|
15
|
+
|
|
16
|
+
const BASE_PATH = "/ai/observability";
|
|
17
|
+
|
|
18
|
+
export interface ObservabilityTestMultiStageRouteOptions extends ObservabilityRouteAccessOptions {
|
|
19
|
+
aiService?: ObservabilityGenerateClient;
|
|
20
|
+
exportTrace: (trace: TraceRecord) => Promise<string | undefined>;
|
|
21
|
+
requestAiServiceFactory?: ObservabilityRequestAiServiceFactory;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const addObservabilityTestMultiStageRoutes = (
|
|
25
|
+
router: express.Application,
|
|
26
|
+
options: ObservabilityTestMultiStageRouteOptions
|
|
27
|
+
): void => {
|
|
28
|
+
const openApiOptions = options.openApi ? {openApi: options.openApi} : {};
|
|
29
|
+
const builder = (): ReturnType<typeof createOpenApiBuilder> => {
|
|
30
|
+
return createOpenApiBuilder(openApiOptions as Parameters<typeof createOpenApiBuilder>[0]);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
router.post(
|
|
34
|
+
`${BASE_PATH}/traces/test-multi-stage`,
|
|
35
|
+
observabilityRouteMiddleware(
|
|
36
|
+
options.accessControl,
|
|
37
|
+
{action: "read", resource: "aiTrace"},
|
|
38
|
+
builder()
|
|
39
|
+
.withTags(["observability"])
|
|
40
|
+
.withSummary("Run a multi-stage observability workflow and export one nested trace")
|
|
41
|
+
.withRequestBody({
|
|
42
|
+
input: {type: "string"},
|
|
43
|
+
})
|
|
44
|
+
.withResponse(200, {
|
|
45
|
+
data: {
|
|
46
|
+
properties: {
|
|
47
|
+
output: {
|
|
48
|
+
properties: {
|
|
49
|
+
keywords: {items: {type: "string"}, type: "array"},
|
|
50
|
+
metrics: {type: "object"},
|
|
51
|
+
phrase: {type: "string"},
|
|
52
|
+
sentence: {type: "string"},
|
|
53
|
+
},
|
|
54
|
+
type: "object",
|
|
55
|
+
},
|
|
56
|
+
stages: {
|
|
57
|
+
items: {
|
|
58
|
+
properties: {
|
|
59
|
+
name: {type: "string"},
|
|
60
|
+
status: {type: "string"},
|
|
61
|
+
},
|
|
62
|
+
type: "object",
|
|
63
|
+
},
|
|
64
|
+
type: "array",
|
|
65
|
+
},
|
|
66
|
+
traceId: {type: "string"},
|
|
67
|
+
},
|
|
68
|
+
type: "object",
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
.withResponse(503, {title: {type: "string"}})
|
|
72
|
+
.build()
|
|
73
|
+
),
|
|
74
|
+
asyncHandler(async (req, res) => {
|
|
75
|
+
const aiService = resolveRequestAiService({
|
|
76
|
+
aiService: options.aiService,
|
|
77
|
+
req,
|
|
78
|
+
requestAiServiceFactory: options.requestAiServiceFactory,
|
|
79
|
+
});
|
|
80
|
+
const input =
|
|
81
|
+
typeof req.body?.input === "string" && req.body.input.length > 0
|
|
82
|
+
? req.body.input
|
|
83
|
+
: "Terreno observability multi-stage smoke test.";
|
|
84
|
+
const userId = (req.user as {_id?: mongoose.Types.ObjectId} | undefined)?._id;
|
|
85
|
+
|
|
86
|
+
const result = await runTestMultiStageWorkflow({
|
|
87
|
+
aiService,
|
|
88
|
+
exportTrace: options.exportTrace,
|
|
89
|
+
input,
|
|
90
|
+
userId,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return res.json({data: result});
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import {TerrenoApp} from "@terreno/api";
|
|
3
|
+
import type express from "express";
|
|
4
|
+
import {DateTime} from "luxon";
|
|
5
|
+
|
|
6
|
+
import {authAsUser, ensureTestUsers, UserModel} from "../../tests/helpers";
|
|
7
|
+
import {createLocalObservabilityPlugin} from "../local/localPlugin";
|
|
8
|
+
import {registerObsScore} from "../local/models/obsScore";
|
|
9
|
+
import {registerObsSpan} from "../local/models/obsSpan";
|
|
10
|
+
import {registerObsTrace} from "../local/models/obsTrace";
|
|
11
|
+
import {LocalTraceStore} from "../local/traceStore";
|
|
12
|
+
import {ObservabilityApp, resetObservabilityApp} from "../observabilityApp";
|
|
13
|
+
|
|
14
|
+
describe("observability trace routes", () => {
|
|
15
|
+
let app: express.Application;
|
|
16
|
+
let store: LocalTraceStore;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
await ensureTestUsers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
resetObservabilityApp();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
await registerObsTrace().deleteMany({});
|
|
28
|
+
await registerObsSpan().deleteMany({});
|
|
29
|
+
await registerObsScore().deleteMany({});
|
|
30
|
+
const plugin = createLocalObservabilityPlugin();
|
|
31
|
+
store =
|
|
32
|
+
plugin.traceSink && "store" in plugin.traceSink
|
|
33
|
+
? (plugin.traceSink as {store: LocalTraceStore}).store
|
|
34
|
+
: new LocalTraceStore();
|
|
35
|
+
app = new TerrenoApp({skipListen: true, userModel: UserModel})
|
|
36
|
+
.register(new ObservabilityApp({plugins: [plugin]}))
|
|
37
|
+
.build();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("returns nested spans, both prompts, and posted scores", async () => {
|
|
41
|
+
const startedAt = DateTime.utc().toISO() ?? "";
|
|
42
|
+
const exported = await store.exportTrace({
|
|
43
|
+
id: "t1",
|
|
44
|
+
name: "multi",
|
|
45
|
+
prompts: [
|
|
46
|
+
{name: "summarize", version: 1},
|
|
47
|
+
{name: "title", version: 1},
|
|
48
|
+
],
|
|
49
|
+
sensitive: false,
|
|
50
|
+
spans: [
|
|
51
|
+
{
|
|
52
|
+
durationMs: 20,
|
|
53
|
+
id: "root",
|
|
54
|
+
kind: "CHAIN",
|
|
55
|
+
name: "root",
|
|
56
|
+
startedAt,
|
|
57
|
+
status: "ok",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
durationMs: 5,
|
|
61
|
+
id: "llm",
|
|
62
|
+
kind: "LLM",
|
|
63
|
+
name: "llm",
|
|
64
|
+
parentSpanId: "root",
|
|
65
|
+
startedAt,
|
|
66
|
+
startOffsetMs: 3,
|
|
67
|
+
status: "ok",
|
|
68
|
+
usage: {inputTokens: 2, model: "unpriced", outputTokens: 3},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
startedAt,
|
|
72
|
+
status: "ok",
|
|
73
|
+
});
|
|
74
|
+
const agent = await authAsUser(app, "admin");
|
|
75
|
+
const detail = await agent.get(`/ai/observability/traces/${exported.id}`);
|
|
76
|
+
expect(detail.status).toBe(200);
|
|
77
|
+
expect(detail.body.data.prompts).toHaveLength(2);
|
|
78
|
+
expect(detail.body.data.spans[0].children).toHaveLength(1);
|
|
79
|
+
expect("costUsd" in (detail.body.data.spans[0].children[0].usage ?? {})).toBe(false);
|
|
80
|
+
|
|
81
|
+
const scored = await agent.post(`/ai/observability/traces/${exported.id}/scores`).send({
|
|
82
|
+
dataType: "numeric",
|
|
83
|
+
name: "quality",
|
|
84
|
+
source: "human",
|
|
85
|
+
value: 4,
|
|
86
|
+
});
|
|
87
|
+
expect(scored.status).toBe(201);
|
|
88
|
+
|
|
89
|
+
const listed = await agent.get("/ai/observability/traces?hasScore=true&prompt=summarize");
|
|
90
|
+
expect(listed.status).toBe(200);
|
|
91
|
+
expect(listed.body.data.map((row: {id: string}) => row.id)).toEqual([exported.id]);
|
|
92
|
+
expect(listed.body.more).toBe(false);
|
|
93
|
+
expect(listed.body.page).toBe(1);
|
|
94
|
+
expect(listed.body.total).toBe(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("forbids non-admins from listing traces", async () => {
|
|
98
|
+
const agent = await authAsUser(app, "notAdmin");
|
|
99
|
+
const res = await agent.get("/ai/observability/traces");
|
|
100
|
+
expect(res.status).toBe(403);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("validates trace list query params and score payloads", async () => {
|
|
104
|
+
const startedAt = DateTime.utc().toISO() ?? "";
|
|
105
|
+
const exported = await store.exportTrace({
|
|
106
|
+
id: "trace-query",
|
|
107
|
+
name: "query",
|
|
108
|
+
prompts: [{name: "summarize", version: 1}],
|
|
109
|
+
sensitive: false,
|
|
110
|
+
spans: [],
|
|
111
|
+
startedAt,
|
|
112
|
+
status: "ok",
|
|
113
|
+
});
|
|
114
|
+
const admin = await authAsUser(app, "admin");
|
|
115
|
+
|
|
116
|
+
const badBoolean = await admin.get("/ai/observability/traces?hasScore=maybe");
|
|
117
|
+
expect(badBoolean.status).toBe(400);
|
|
118
|
+
|
|
119
|
+
const badPage = await admin.get("/ai/observability/traces?page=0");
|
|
120
|
+
expect(badPage.status).toBe(400);
|
|
121
|
+
|
|
122
|
+
const filtered = await admin.get(
|
|
123
|
+
"/ai/observability/traces?flaggedForDataset=false&limit=5&page=1&status=ok"
|
|
124
|
+
);
|
|
125
|
+
expect(filtered.status).toBe(200);
|
|
126
|
+
expect(filtered.body.data.map((row: {id: string}) => row.id)).toContain(exported.id);
|
|
127
|
+
|
|
128
|
+
const v2Trace = await store.exportTrace({
|
|
129
|
+
id: "trace-v2",
|
|
130
|
+
name: "summarize-v2",
|
|
131
|
+
prompts: [{name: "summarize", version: 2}],
|
|
132
|
+
sensitive: false,
|
|
133
|
+
spans: [],
|
|
134
|
+
startedAt,
|
|
135
|
+
status: "ok",
|
|
136
|
+
});
|
|
137
|
+
const v2Only = await admin.get("/ai/observability/traces?prompt=summarize&promptVersion=2");
|
|
138
|
+
expect(v2Only.status).toBe(200);
|
|
139
|
+
expect(v2Only.body.data.map((row: {id: string}) => row.id)).toEqual([v2Trace.id]);
|
|
140
|
+
const v1Only = await admin.get("/ai/observability/traces?prompt=summarize&promptVersion=1");
|
|
141
|
+
expect(v1Only.body.data.map((row: {id: string}) => row.id)).toEqual([exported.id]);
|
|
142
|
+
|
|
143
|
+
const missingPrompt = await admin.get("/ai/observability/traces?promptVersion=1");
|
|
144
|
+
expect(missingPrompt.status).toBe(400);
|
|
145
|
+
expect(missingPrompt.body.title).toBe("prompt is required when promptVersion is set");
|
|
146
|
+
|
|
147
|
+
const zeroVersion = await admin.get(
|
|
148
|
+
"/ai/observability/traces?prompt=summarize&promptVersion=0"
|
|
149
|
+
);
|
|
150
|
+
expect(zeroVersion.status).toBe(400);
|
|
151
|
+
|
|
152
|
+
const fractional = await admin.get(
|
|
153
|
+
"/ai/observability/traces?prompt=summarize&promptVersion=1.5"
|
|
154
|
+
);
|
|
155
|
+
expect(fractional.status).toBe(400);
|
|
156
|
+
|
|
157
|
+
const nonInteger = await admin.get(
|
|
158
|
+
"/ai/observability/traces?prompt=summarize&promptVersion=abc"
|
|
159
|
+
);
|
|
160
|
+
expect(nonInteger.status).toBe(400);
|
|
161
|
+
|
|
162
|
+
const missingFields = await admin.post(`/ai/observability/traces/${exported.id}/scores`).send({
|
|
163
|
+
name: "quality",
|
|
164
|
+
});
|
|
165
|
+
expect(missingFields.status).toBe(400);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {APIError, asyncHandler, createOpenApiBuilder} from "@terreno/api";
|
|
2
|
+
import type express from "express";
|
|
3
|
+
import type {LocalTraceStore} from "../local/traceStore";
|
|
4
|
+
import {getObservabilityApp} from "../observabilityAppRegistry";
|
|
5
|
+
import type {ScoreRecord, ScoreSink} from "../types";
|
|
6
|
+
import {
|
|
7
|
+
type ObservabilityRouteAccessOptions,
|
|
8
|
+
observabilityRouteMiddleware,
|
|
9
|
+
} from "./observabilityRouteAccess";
|
|
10
|
+
|
|
11
|
+
const BASE_PATH = "/ai/observability";
|
|
12
|
+
|
|
13
|
+
export interface ObservabilityTraceRouteOptions extends ObservabilityRouteAccessOptions {
|
|
14
|
+
store: LocalTraceStore;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parseBoolean = (value: unknown): boolean | undefined => {
|
|
18
|
+
if (value === undefined) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (value === true || value === "true") {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (value === false || value === "false") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
throw new APIError({status: 400, title: "boolean query must be true or false"});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const parsePromptVersion = (value: unknown, prompt?: string): number | undefined => {
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const parsed = Number(value);
|
|
35
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
36
|
+
throw new APIError({status: 400, title: "promptVersion must be a positive integer"});
|
|
37
|
+
}
|
|
38
|
+
if (!prompt) {
|
|
39
|
+
throw new APIError({status: 400, title: "prompt is required when promptVersion is set"});
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const parsePositiveInt = (value: unknown, fallback: number): number => {
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
const parsed = Number(value);
|
|
49
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
50
|
+
throw new APIError({status: 400, title: "page and limit must be positive integers"});
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const addObservabilityTraceRoutes = (
|
|
56
|
+
router: express.Application,
|
|
57
|
+
options: ObservabilityTraceRouteOptions
|
|
58
|
+
): void => {
|
|
59
|
+
const openApiOptions = options.openApi ? {openApi: options.openApi} : {};
|
|
60
|
+
const builder = (): ReturnType<typeof createOpenApiBuilder> => {
|
|
61
|
+
return createOpenApiBuilder(openApiOptions as Parameters<typeof createOpenApiBuilder>[0]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
router.get(
|
|
65
|
+
`${BASE_PATH}/traces`,
|
|
66
|
+
observabilityRouteMiddleware(
|
|
67
|
+
options.accessControl,
|
|
68
|
+
{action: "list", resource: "aiTrace"},
|
|
69
|
+
builder()
|
|
70
|
+
.withTags(["observability"])
|
|
71
|
+
.withSummary("List observability traces")
|
|
72
|
+
.withQueryParameter("prompt", {type: "string"}, {required: false})
|
|
73
|
+
.withQueryParameter("promptVersion", {type: "number"}, {required: false})
|
|
74
|
+
.withResponse(200, {data: {type: "array"}})
|
|
75
|
+
.build()
|
|
76
|
+
),
|
|
77
|
+
asyncHandler(async (req, res) => {
|
|
78
|
+
const prompt = typeof req.query.prompt === "string" ? req.query.prompt : undefined;
|
|
79
|
+
const listed = await options.store.list({
|
|
80
|
+
flaggedForDataset: parseBoolean(req.query.flaggedForDataset),
|
|
81
|
+
from: typeof req.query.from === "string" ? req.query.from : undefined,
|
|
82
|
+
hasScore: parseBoolean(req.query.hasScore),
|
|
83
|
+
limit: parsePositiveInt(req.query.limit, 20),
|
|
84
|
+
page: parsePositiveInt(req.query.page, 1),
|
|
85
|
+
prompt,
|
|
86
|
+
promptVersion: parsePromptVersion(req.query.promptVersion, prompt),
|
|
87
|
+
sensitive: parseBoolean(req.query.sensitive),
|
|
88
|
+
sessionId: typeof req.query.sessionId === "string" ? req.query.sessionId : undefined,
|
|
89
|
+
status:
|
|
90
|
+
req.query.status === "ok" || req.query.status === "error" ? req.query.status : undefined,
|
|
91
|
+
to: typeof req.query.to === "string" ? req.query.to : undefined,
|
|
92
|
+
userId: typeof req.query.userId === "string" ? req.query.userId : undefined,
|
|
93
|
+
});
|
|
94
|
+
const {limit, page, total} = listed.meta;
|
|
95
|
+
return res.json({
|
|
96
|
+
data: listed.data,
|
|
97
|
+
limit,
|
|
98
|
+
more: page * limit < total,
|
|
99
|
+
page,
|
|
100
|
+
total,
|
|
101
|
+
});
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
router.get(
|
|
106
|
+
`${BASE_PATH}/traces/:id`,
|
|
107
|
+
observabilityRouteMiddleware(
|
|
108
|
+
options.accessControl,
|
|
109
|
+
{action: "read", resource: "aiTrace"},
|
|
110
|
+
builder()
|
|
111
|
+
.withTags(["observability"])
|
|
112
|
+
.withSummary("Get an observability trace")
|
|
113
|
+
.withPathParameter("id", {type: "string"})
|
|
114
|
+
.withResponse(200, {data: {type: "object"}})
|
|
115
|
+
.build()
|
|
116
|
+
),
|
|
117
|
+
asyncHandler(async (req, res) => {
|
|
118
|
+
const data = await options.store.getDetail(req.params.id);
|
|
119
|
+
return res.json({data});
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
router.post(
|
|
124
|
+
`${BASE_PATH}/traces/:id/scores`,
|
|
125
|
+
observabilityRouteMiddleware(
|
|
126
|
+
options.accessControl,
|
|
127
|
+
{action: "score", resource: "aiReview"},
|
|
128
|
+
builder()
|
|
129
|
+
.withTags(["observability"])
|
|
130
|
+
.withSummary("Add a score to a trace")
|
|
131
|
+
.withPathParameter("id", {type: "string"})
|
|
132
|
+
.withResponse(201, {data: {type: "object"}})
|
|
133
|
+
.build()
|
|
134
|
+
),
|
|
135
|
+
asyncHandler(async (req, res) => {
|
|
136
|
+
await options.store.getDetail(req.params.id);
|
|
137
|
+
const body = req.body as Partial<ScoreRecord>;
|
|
138
|
+
if (!body.name || body.value === undefined || !body.dataType || !body.source) {
|
|
139
|
+
throw new APIError({
|
|
140
|
+
status: 400,
|
|
141
|
+
title: "name, value, dataType, and source are required",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const score: ScoreRecord = {
|
|
145
|
+
comment: body.comment,
|
|
146
|
+
confidence: body.confidence,
|
|
147
|
+
dataType: body.dataType,
|
|
148
|
+
name: body.name,
|
|
149
|
+
source: body.source,
|
|
150
|
+
spanId: body.spanId,
|
|
151
|
+
traceId: req.params.id,
|
|
152
|
+
value: body.value,
|
|
153
|
+
};
|
|
154
|
+
const sinks: ScoreSink[] = getObservabilityApp()?.scoreSinks ?? [];
|
|
155
|
+
if (sinks.length === 0) {
|
|
156
|
+
await options.store.exportScore(score);
|
|
157
|
+
} else {
|
|
158
|
+
const results = await Promise.allSettled(
|
|
159
|
+
sinks.map((sink) => {
|
|
160
|
+
return sink.export(score);
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
for (const result of results) {
|
|
164
|
+
if (result.status === "rejected") {
|
|
165
|
+
throw result.reason;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return res.status(201).json({data: score});
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Ajv, {type ErrorObject} from "ajv";
|
|
2
|
+
|
|
3
|
+
const ajv = new Ajv({allErrors: true, strict: false});
|
|
4
|
+
|
|
5
|
+
export interface SchemaValidationError {
|
|
6
|
+
message: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const validateAgainstSchema = (
|
|
11
|
+
schema: Record<string, unknown> | undefined,
|
|
12
|
+
value: unknown
|
|
13
|
+
): SchemaValidationError[] => {
|
|
14
|
+
if (!schema) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const validate = ajv.compile(schema);
|
|
18
|
+
const valid = validate(value);
|
|
19
|
+
if (valid) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return (validate.errors ?? []).map((error: ErrorObject) => {
|
|
23
|
+
const path = error.instancePath.length > 0 ? error.instancePath : "/";
|
|
24
|
+
return {
|
|
25
|
+
message: error.message ?? "schema validation failed",
|
|
26
|
+
path,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type {ScoreThreshold} from "../types/observability";
|
|
2
|
+
|
|
3
|
+
export const SOP_DEFAULT_THRESHOLDS: ScoreThreshold[] = [
|
|
4
|
+
{aggregate: "trueRate", dimension: "correct", evaluatorName: "correctness", op: "eq", value: 1},
|
|
5
|
+
{
|
|
6
|
+
aggregate: "trueRate",
|
|
7
|
+
dimension: "hallucinated",
|
|
8
|
+
evaluatorName: "hallucination",
|
|
9
|
+
op: "eq",
|
|
10
|
+
value: 0,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
aggregate: "mean",
|
|
14
|
+
dimension: "helpfulness",
|
|
15
|
+
evaluatorName: "helpfulness",
|
|
16
|
+
op: "gte",
|
|
17
|
+
value: 0.9,
|
|
18
|
+
},
|
|
19
|
+
{aggregate: "trueRate", dimension: "toxic", evaluatorName: "toxicity", op: "eq", value: 0},
|
|
20
|
+
];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {createLocalObservabilityPlugin} from "./local/localPlugin";
|
|
4
|
+
import {ObservabilityApp, resetObservabilityApp} from "./observabilityApp";
|
|
5
|
+
import {buildPlaygroundAiStatus} from "./status";
|
|
6
|
+
|
|
7
|
+
describe("buildPlaygroundAiStatus", () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
resetObservabilityApp();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("prefers a configured server aiService", () => {
|
|
13
|
+
const app = new ObservabilityApp({
|
|
14
|
+
aiService: {} as never,
|
|
15
|
+
plugins: [createLocalObservabilityPlugin()],
|
|
16
|
+
requestAiServiceFactory: () => undefined,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(buildPlaygroundAiStatus(app)).toEqual({source: "server"});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("reports request-key when only requestAiServiceFactory is configured", () => {
|
|
23
|
+
const app = new ObservabilityApp({
|
|
24
|
+
plugins: [createLocalObservabilityPlugin()],
|
|
25
|
+
requestAiServiceFactory: () => undefined,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(buildPlaygroundAiStatus(app)).toEqual({source: "request-key"});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("reports unavailable when neither AI path is configured", () => {
|
|
32
|
+
const app = new ObservabilityApp({
|
|
33
|
+
plugins: [createLocalObservabilityPlugin()],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(buildPlaygroundAiStatus(app)).toEqual({source: "unavailable"});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {RegisteredObservabilityApp} from "./observabilityAppRegistry";
|
|
2
|
+
import type {ObservabilityPermissions} from "./permissions";
|
|
3
|
+
import type {ObservabilityCapability, ObservabilityControlConfig} from "./types";
|
|
4
|
+
|
|
5
|
+
export interface ObservabilityPluginStatus {
|
|
6
|
+
capabilities: ObservabilityCapability[];
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type PlaygroundAiSource = "request-key" | "server" | "unavailable";
|
|
11
|
+
|
|
12
|
+
export interface PlaygroundAiStatus {
|
|
13
|
+
source: PlaygroundAiSource;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ObservabilityStatus {
|
|
17
|
+
localOn: boolean;
|
|
18
|
+
permissions: ObservabilityPermissions;
|
|
19
|
+
playgroundAi: PlaygroundAiStatus;
|
|
20
|
+
plugins: ObservabilityPluginStatus[];
|
|
21
|
+
primaries: ObservabilityControlConfig;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const buildPlaygroundAiStatus = (app: RegisteredObservabilityApp): PlaygroundAiStatus => {
|
|
25
|
+
if (app.aiService) {
|
|
26
|
+
return {source: "server"};
|
|
27
|
+
}
|
|
28
|
+
if (app.requestAiServiceFactory) {
|
|
29
|
+
return {source: "request-key"};
|
|
30
|
+
}
|
|
31
|
+
return {source: "unavailable"};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const isLocalObservabilityPluginOn = (plugins: ReadonlyArray<{id: string}>): boolean => {
|
|
35
|
+
return plugins.some((plugin) => {
|
|
36
|
+
return plugin.id === "local";
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const buildObservabilityStatus = (
|
|
41
|
+
app: RegisteredObservabilityApp,
|
|
42
|
+
permissions: ObservabilityPermissions
|
|
43
|
+
): ObservabilityStatus => {
|
|
44
|
+
return {
|
|
45
|
+
localOn: isLocalObservabilityPluginOn(app.plugins),
|
|
46
|
+
permissions,
|
|
47
|
+
playgroundAi: buildPlaygroundAiStatus(app),
|
|
48
|
+
plugins: app.plugins.map((plugin) => {
|
|
49
|
+
return {
|
|
50
|
+
capabilities: [...plugin.capabilities].sort() as ObservabilityCapability[],
|
|
51
|
+
id: plugin.id,
|
|
52
|
+
};
|
|
53
|
+
}),
|
|
54
|
+
primaries: app.control,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {jsonSchema} from "ai";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ObsTestMultiStageCall1Output,
|
|
5
|
+
ObsTestMultiStageCall2Output,
|
|
6
|
+
ObsTestMultiStageFinalOutput,
|
|
7
|
+
} from "../types";
|
|
8
|
+
|
|
9
|
+
export const OBS_TEST_MULTI_STAGE_CALL_1_SCHEMA_NAME = "obs-test-multi-stage-call-1";
|
|
10
|
+
export const OBS_TEST_MULTI_STAGE_CALL_2_SCHEMA_NAME = "obs-test-multi-stage-call-2";
|
|
11
|
+
export const OBS_TEST_MULTI_STAGE_FINAL_SCHEMA_NAME = "obs-test-multi-stage-final";
|
|
12
|
+
|
|
13
|
+
export const OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA: Record<string, unknown> = {
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
phrase: {
|
|
17
|
+
description: "One short phrase summarizing the user input",
|
|
18
|
+
type: "string",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
required: ["phrase"],
|
|
22
|
+
type: "object",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA: Record<string, unknown> = {
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
properties: {
|
|
28
|
+
keywords: {
|
|
29
|
+
description: "Exactly two keywords taken from the user input",
|
|
30
|
+
items: {type: "string"},
|
|
31
|
+
maxItems: 2,
|
|
32
|
+
minItems: 2,
|
|
33
|
+
type: "array",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
required: ["keywords"],
|
|
37
|
+
type: "object",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA: Record<string, unknown> = {
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
properties: {
|
|
43
|
+
keywords: {
|
|
44
|
+
description: "The two keywords from stage two",
|
|
45
|
+
items: {type: "string"},
|
|
46
|
+
type: "array",
|
|
47
|
+
},
|
|
48
|
+
metrics: {
|
|
49
|
+
description: "Character and word counts from the text-metrics tool",
|
|
50
|
+
properties: {
|
|
51
|
+
call1: {
|
|
52
|
+
properties: {
|
|
53
|
+
charCount: {type: "number"},
|
|
54
|
+
wordCount: {type: "number"},
|
|
55
|
+
},
|
|
56
|
+
required: ["charCount", "wordCount"],
|
|
57
|
+
type: "object",
|
|
58
|
+
},
|
|
59
|
+
call2: {
|
|
60
|
+
properties: {
|
|
61
|
+
charCount: {type: "number"},
|
|
62
|
+
wordCount: {type: "number"},
|
|
63
|
+
},
|
|
64
|
+
required: ["charCount", "wordCount"],
|
|
65
|
+
type: "object",
|
|
66
|
+
},
|
|
67
|
+
combinedCharCount: {type: "number"},
|
|
68
|
+
},
|
|
69
|
+
required: ["call1", "call2", "combinedCharCount"],
|
|
70
|
+
type: "object",
|
|
71
|
+
},
|
|
72
|
+
phrase: {
|
|
73
|
+
description: "The short phrase from stage one",
|
|
74
|
+
type: "string",
|
|
75
|
+
},
|
|
76
|
+
sentence: {
|
|
77
|
+
description: "One concise sentence combining phrase, keywords, and metrics",
|
|
78
|
+
type: "string",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
required: ["keywords", "metrics", "phrase", "sentence"],
|
|
82
|
+
type: "object",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const obsTestMultiStageCall1Schema = jsonSchema<ObsTestMultiStageCall1Output>(
|
|
86
|
+
OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export const obsTestMultiStageCall2Schema = jsonSchema<ObsTestMultiStageCall2Output>(
|
|
90
|
+
OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
export const obsTestMultiStageFinalSchema = jsonSchema<ObsTestMultiStageFinalOutput>(
|
|
94
|
+
OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA
|
|
95
|
+
);
|