@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,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addObservabilityPromptRoutes = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
const aiRequest_1 = require("../../models/aiRequest");
|
|
7
|
+
const observabilityRouteAccess_1 = require("./observabilityRouteAccess");
|
|
8
|
+
const requestAiService_1 = require("./requestAiService");
|
|
9
|
+
const BASE_PATH = "/ai/observability";
|
|
10
|
+
const asUserId = (user) => {
|
|
11
|
+
if (!user || typeof user !== "object" || !("_id" in user)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return user._id;
|
|
15
|
+
};
|
|
16
|
+
const parsePromptVersionQuery = (value) => {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const parsed = Number(value);
|
|
21
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
22
|
+
throw new api_1.APIError({ status: 400, title: "promptVersion must be a positive integer" });
|
|
23
|
+
}
|
|
24
|
+
return parsed;
|
|
25
|
+
};
|
|
26
|
+
const versionFieldsFromBody = (body) => {
|
|
27
|
+
return {
|
|
28
|
+
config: body.config,
|
|
29
|
+
inputSchema: body.inputSchema,
|
|
30
|
+
outputFieldNotes: body.outputFieldNotes,
|
|
31
|
+
outputSchema: body.outputSchema,
|
|
32
|
+
sensitive: body.sensitive,
|
|
33
|
+
system: body.system,
|
|
34
|
+
template: body.template,
|
|
35
|
+
type: body.type ?? "text",
|
|
36
|
+
variables: body.variables,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const createPlaygroundGenerator = (aiService) => {
|
|
40
|
+
return {
|
|
41
|
+
generate: async ({ prompt, systemPrompt, userId }) => {
|
|
42
|
+
const started = luxon_1.DateTime.utc();
|
|
43
|
+
const output = await aiService.generateText({
|
|
44
|
+
prompt,
|
|
45
|
+
skipTrace: true,
|
|
46
|
+
systemPrompt,
|
|
47
|
+
userId,
|
|
48
|
+
});
|
|
49
|
+
const filter = {};
|
|
50
|
+
if (userId) {
|
|
51
|
+
filter.userId = userId;
|
|
52
|
+
}
|
|
53
|
+
const recent = await aiRequest_1.AIRequest.find(filter).sort({ created: -1 }).limit(1);
|
|
54
|
+
const last = recent[0];
|
|
55
|
+
const metadata = (last?.metadata ?? {});
|
|
56
|
+
return {
|
|
57
|
+
inputTokens: metadata.inputTokens,
|
|
58
|
+
latencyMs: last?.responseTime ?? luxon_1.DateTime.utc().diff(started, "milliseconds").as("milliseconds"),
|
|
59
|
+
output,
|
|
60
|
+
outputTokens: metadata.outputTokens,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const addObservabilityPromptRoutes = (router, options) => {
|
|
66
|
+
const openApiOptions = options.openApi ? { openApi: options.openApi } : {};
|
|
67
|
+
const builder = () => {
|
|
68
|
+
return (0, api_1.createOpenApiBuilder)(openApiOptions);
|
|
69
|
+
};
|
|
70
|
+
router.get(`${BASE_PATH}/prompts`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "list", resource: "aiPrompt" }, builder()
|
|
71
|
+
.withTags(["observability"])
|
|
72
|
+
.withSummary("List observability prompts")
|
|
73
|
+
.withQueryParameter("folder", { type: "string" }, { required: false })
|
|
74
|
+
.withQueryParameter("search", { type: "string" }, { required: false })
|
|
75
|
+
.withQueryParameter("include", { type: "string" }, { required: false })
|
|
76
|
+
.withResponse(200, { data: { type: "array" } })
|
|
77
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
78
|
+
const include = typeof req.query.include === "string" ? req.query.include : undefined;
|
|
79
|
+
const data = await options.store.list({
|
|
80
|
+
folder: typeof req.query.folder === "string" ? req.query.folder : undefined,
|
|
81
|
+
includeUsage7d: include === "usage7d",
|
|
82
|
+
search: typeof req.query.search === "string" ? req.query.search : undefined,
|
|
83
|
+
});
|
|
84
|
+
return res.json({ data });
|
|
85
|
+
}));
|
|
86
|
+
router.post(`${BASE_PATH}/prompts`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "create", resource: "aiPrompt" }, builder()
|
|
87
|
+
.withTags(["observability"])
|
|
88
|
+
.withSummary("Create an observability prompt")
|
|
89
|
+
.withRequestBody({
|
|
90
|
+
description: { required: false, type: "string" },
|
|
91
|
+
folder: { required: true, type: "string" },
|
|
92
|
+
name: { required: true, type: "string" },
|
|
93
|
+
})
|
|
94
|
+
.withResponse(201, { data: { type: "object" } })
|
|
95
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
96
|
+
const body = req.body;
|
|
97
|
+
const created = await options.store.create({
|
|
98
|
+
...versionFieldsFromBody(body),
|
|
99
|
+
description: typeof body.description === "string" ? body.description : undefined,
|
|
100
|
+
folder: String(body.folder ?? ""),
|
|
101
|
+
name: String(body.name ?? ""),
|
|
102
|
+
tags: body.tags,
|
|
103
|
+
});
|
|
104
|
+
return res.status(201).json({ data: created });
|
|
105
|
+
}));
|
|
106
|
+
router.get(`${BASE_PATH}/prompts/:name`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "read", resource: "aiPrompt" }, builder()
|
|
107
|
+
.withTags(["observability"])
|
|
108
|
+
.withSummary("Get an observability prompt")
|
|
109
|
+
.withPathParameter("name", { type: "string" })
|
|
110
|
+
.withQueryParameter("promptVersion", { type: "number" }, { required: false })
|
|
111
|
+
.withResponse(200, { data: { type: "object" } })
|
|
112
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
113
|
+
const promptVersion = parsePromptVersionQuery(req.query.promptVersion);
|
|
114
|
+
const data = await options.store.getDetail(req.params.name, { promptVersion });
|
|
115
|
+
return res.json({ data });
|
|
116
|
+
}));
|
|
117
|
+
router.post(`${BASE_PATH}/prompts/:name/versions`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "update", resource: "aiPrompt" }, builder()
|
|
118
|
+
.withTags(["observability"])
|
|
119
|
+
.withSummary("Create the next immutable prompt version")
|
|
120
|
+
.withPathParameter("name", { type: "string" })
|
|
121
|
+
.withResponse(201, { data: { type: "object" } })
|
|
122
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
123
|
+
const created = await options.store.createVersion(req.params.name, versionFieldsFromBody(req.body));
|
|
124
|
+
return res.status(201).json({ data: created });
|
|
125
|
+
}));
|
|
126
|
+
router.post(`${BASE_PATH}/prompts/:name/labels`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "promote", resource: "aiPrompt" }, builder()
|
|
127
|
+
.withTags(["observability"])
|
|
128
|
+
.withSummary("Move a prompt label")
|
|
129
|
+
.withPathParameter("name", { type: "string" })
|
|
130
|
+
.withRequestBody({
|
|
131
|
+
label: { required: true, type: "string" },
|
|
132
|
+
version: { required: true, type: "number" },
|
|
133
|
+
})
|
|
134
|
+
.withResponse(200, { data: { type: "object" } })
|
|
135
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
136
|
+
const body = req.body;
|
|
137
|
+
if (!body.label || body.version === undefined) {
|
|
138
|
+
throw new api_1.APIError({ status: 400, title: "label and version are required" });
|
|
139
|
+
}
|
|
140
|
+
const data = await options.store.moveLabel(req.params.name, {
|
|
141
|
+
label: body.label,
|
|
142
|
+
version: body.version,
|
|
143
|
+
});
|
|
144
|
+
return res.json({ data });
|
|
145
|
+
}));
|
|
146
|
+
router.post(`${BASE_PATH}/prompts/:name/playground`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "playground", resource: "aiPrompt" }, builder()
|
|
147
|
+
.withTags(["observability"])
|
|
148
|
+
.withSummary("Compile and run a prompt version once")
|
|
149
|
+
.withPathParameter("name", { type: "string" })
|
|
150
|
+
.withResponse(200, { data: { type: "object" } })
|
|
151
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
152
|
+
const body = req.body;
|
|
153
|
+
const aiService = (0, requestAiService_1.resolveRequestAiService)({
|
|
154
|
+
aiService: options.aiService,
|
|
155
|
+
modelId: body.modelId,
|
|
156
|
+
req,
|
|
157
|
+
requestAiServiceFactory: options.requestAiServiceFactory,
|
|
158
|
+
});
|
|
159
|
+
const data = await options.store.runPlayground({
|
|
160
|
+
generator: createPlaygroundGenerator(aiService),
|
|
161
|
+
modelId: aiService.modelId,
|
|
162
|
+
name: req.params.name,
|
|
163
|
+
priceMap: options.priceMap,
|
|
164
|
+
userId: asUserId(req.user),
|
|
165
|
+
userPrompt: body.userPrompt,
|
|
166
|
+
variables: body.variables,
|
|
167
|
+
version: body.version,
|
|
168
|
+
});
|
|
169
|
+
return res.json({ data });
|
|
170
|
+
}));
|
|
171
|
+
};
|
|
172
|
+
exports.addObservabilityPromptRoutes = addObservabilityPromptRoutes;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { ObservabilityGenerateClient, ObservabilityRequestAiServiceFactory } from "../types";
|
|
3
|
+
export interface ResolveRequestAiServiceOptions {
|
|
4
|
+
aiService?: ObservabilityGenerateClient;
|
|
5
|
+
modelId?: string;
|
|
6
|
+
req: express.Request;
|
|
7
|
+
requestAiServiceFactory?: ObservabilityRequestAiServiceFactory;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Prefer the server-wide client, then let the host build one from the caller's
|
|
11
|
+
* `x-ai-api-key` header so admins can run AI routes with their own provider key.
|
|
12
|
+
*/
|
|
13
|
+
export declare const resolveRequestAiService: ({ aiService, modelId, req, requestAiServiceFactory, }: ResolveRequestAiServiceOptions) => ObservabilityGenerateClient;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRequestAiService = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const MISSING_AI_SERVICE_TITLE = "No AI service is available. Configure ObservabilityApp.aiService or provide an AI API key.";
|
|
6
|
+
/**
|
|
7
|
+
* Prefer the server-wide client, then let the host build one from the caller's
|
|
8
|
+
* `x-ai-api-key` header so admins can run AI routes with their own provider key.
|
|
9
|
+
*/
|
|
10
|
+
const resolveRequestAiService = ({ aiService, modelId, req, requestAiServiceFactory, }) => {
|
|
11
|
+
const resolved = aiService ??
|
|
12
|
+
requestAiServiceFactory?.({
|
|
13
|
+
apiKey: req.header("x-ai-api-key"),
|
|
14
|
+
modelId,
|
|
15
|
+
});
|
|
16
|
+
if (!resolved) {
|
|
17
|
+
throw new api_1.APIError({ status: 503, title: MISSING_AI_SERVICE_TITLE });
|
|
18
|
+
}
|
|
19
|
+
return resolved;
|
|
20
|
+
};
|
|
21
|
+
exports.resolveRequestAiService = resolveRequestAiService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { LocalReviewStore } from "../local/reviewStore";
|
|
3
|
+
import { type ObservabilityRouteAccessOptions } from "./observabilityRouteAccess";
|
|
4
|
+
export interface ObservabilityReviewRouteOptions extends ObservabilityRouteAccessOptions {
|
|
5
|
+
store: LocalReviewStore;
|
|
6
|
+
}
|
|
7
|
+
export declare const addObservabilityReviewRoutes: (router: express.Application, options: ObservabilityReviewRouteOptions) => void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addObservabilityReviewRoutes = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const observabilityAppRegistry_1 = require("../observabilityAppRegistry");
|
|
6
|
+
const observabilityRouteAccess_1 = require("./observabilityRouteAccess");
|
|
7
|
+
const BASE_PATH = "/ai/observability";
|
|
8
|
+
const addObservabilityReviewRoutes = (router, options) => {
|
|
9
|
+
const openApiOptions = options.openApi ? { openApi: options.openApi } : {};
|
|
10
|
+
const builder = () => {
|
|
11
|
+
return (0, api_1.createOpenApiBuilder)(openApiOptions);
|
|
12
|
+
};
|
|
13
|
+
router.post(`${BASE_PATH}/traces/review`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "assign", resource: "aiReview" }, builder()
|
|
14
|
+
.withTags(["observability"])
|
|
15
|
+
.withSummary("Enqueue traces for human review")
|
|
16
|
+
.withResponse(201, { data: { type: "array" } })
|
|
17
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
18
|
+
const body = req.body;
|
|
19
|
+
if (!body.evaluatorId || !body.traceIds) {
|
|
20
|
+
throw new api_1.APIError({ status: 400, title: "evaluatorId and traceIds are required" });
|
|
21
|
+
}
|
|
22
|
+
const data = await options.store.enqueue({
|
|
23
|
+
evaluatorId: body.evaluatorId,
|
|
24
|
+
reason: body.reason ?? "manual",
|
|
25
|
+
traceIds: body.traceIds,
|
|
26
|
+
});
|
|
27
|
+
return res.status(201).json({ data });
|
|
28
|
+
}));
|
|
29
|
+
router.get(`${BASE_PATH}/review`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "list", resource: "aiReview" }, builder()
|
|
30
|
+
.withTags(["observability"])
|
|
31
|
+
.withSummary("List the review queue")
|
|
32
|
+
.withResponse(200, { data: { type: "array" } })
|
|
33
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
34
|
+
const status = req.query.status;
|
|
35
|
+
return res.json({ ...(await options.store.list(status)), more: false });
|
|
36
|
+
}));
|
|
37
|
+
router.get(`${BASE_PATH}/review/:id`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "read", resource: "aiReview" }, builder()
|
|
38
|
+
.withTags(["observability"])
|
|
39
|
+
.withSummary("Get a review item")
|
|
40
|
+
.withPathParameter("id", { type: "string" })
|
|
41
|
+
.withResponse(200, { data: { type: "object" } })
|
|
42
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
43
|
+
return res.json({ data: await options.store.getDetail(req.params.id) });
|
|
44
|
+
}));
|
|
45
|
+
router.post(`${BASE_PATH}/review/:id`, [
|
|
46
|
+
(0, api_1.authenticateMiddleware)(),
|
|
47
|
+
(0, observabilityRouteAccess_1.observabilityReviewMutationMiddleware)(options.accessControl),
|
|
48
|
+
builder()
|
|
49
|
+
.withTags(["observability"])
|
|
50
|
+
.withSummary("Submit, skip, or assign a review item")
|
|
51
|
+
.withPathParameter("id", { type: "string" })
|
|
52
|
+
.withResponse(200, { data: { type: "object" } })
|
|
53
|
+
.build(),
|
|
54
|
+
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
55
|
+
const body = req.body;
|
|
56
|
+
if (body.action === "submit") {
|
|
57
|
+
await options.store.submit({
|
|
58
|
+
comment: body.comment,
|
|
59
|
+
id: req.params.id,
|
|
60
|
+
scores: body.scores ?? {},
|
|
61
|
+
sinks: (0, observabilityAppRegistry_1.getObservabilityApp)()?.scoreSinks ?? [],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else if (body.action === "skip") {
|
|
65
|
+
await options.store.skip(req.params.id);
|
|
66
|
+
}
|
|
67
|
+
else if (body.action === "assign") {
|
|
68
|
+
if (!body.assigneeId) {
|
|
69
|
+
throw new api_1.APIError({ status: 400, title: "assigneeId is required" });
|
|
70
|
+
}
|
|
71
|
+
await options.store.assign(req.params.id, body.assigneeId);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new api_1.APIError({ status: 400, title: "action must be submit, skip, or assign" });
|
|
75
|
+
}
|
|
76
|
+
return res.json({ data: await options.store.getDetail(req.params.id) });
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
exports.addObservabilityReviewRoutes = addObservabilityReviewRoutes;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import { type ObservabilityRouteAccessOptions } from "./observabilityRouteAccess";
|
|
3
|
+
export interface ObservabilityStatusRouteOptions extends ObservabilityRouteAccessOptions {
|
|
4
|
+
}
|
|
5
|
+
export declare const addObservabilityStatusRoutes: (router: express.Application, options?: ObservabilityStatusRouteOptions) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addObservabilityStatusRoutes = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const observabilityAppRegistry_1 = require("../observabilityAppRegistry");
|
|
6
|
+
const permissions_1 = require("../permissions");
|
|
7
|
+
const status_1 = require("../status");
|
|
8
|
+
const observabilityRouteAccess_1 = require("./observabilityRouteAccess");
|
|
9
|
+
const BASE_PATH = "/ai/observability";
|
|
10
|
+
const addObservabilityStatusRoutes = (router, options = {}) => {
|
|
11
|
+
const openApiOptions = options.openApi ? { openApi: options.openApi } : {};
|
|
12
|
+
const builder = () => {
|
|
13
|
+
return (0, api_1.createOpenApiBuilder)(openApiOptions);
|
|
14
|
+
};
|
|
15
|
+
router.get(`${BASE_PATH}/status`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, undefined, builder()
|
|
16
|
+
.withTags(["observability"])
|
|
17
|
+
.withSummary("Observability plugin status for admin chrome")
|
|
18
|
+
.withResponse(200, { data: { type: "object" } })
|
|
19
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
20
|
+
const app = (0, observabilityAppRegistry_1.getObservabilityApp)();
|
|
21
|
+
if (!app) {
|
|
22
|
+
throw new api_1.APIError({ status: 503, title: "ObservabilityApp is not registered" });
|
|
23
|
+
}
|
|
24
|
+
const permissions = await (0, permissions_1.resolveObservabilityPermissions)({
|
|
25
|
+
accessControl: options.accessControl,
|
|
26
|
+
user: req.user,
|
|
27
|
+
});
|
|
28
|
+
return res.json({ data: (0, status_1.buildObservabilityStatus)(app, permissions) });
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
exports.addObservabilityStatusRoutes = addObservabilityStatusRoutes;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { ObservabilityGenerateClient, ObservabilityRequestAiServiceFactory, TraceRecord } from "../types";
|
|
3
|
+
import { type ObservabilityRouteAccessOptions } from "./observabilityRouteAccess";
|
|
4
|
+
export interface ObservabilityTestMultiStageRouteOptions extends ObservabilityRouteAccessOptions {
|
|
5
|
+
aiService?: ObservabilityGenerateClient;
|
|
6
|
+
exportTrace: (trace: TraceRecord) => Promise<string | undefined>;
|
|
7
|
+
requestAiServiceFactory?: ObservabilityRequestAiServiceFactory;
|
|
8
|
+
}
|
|
9
|
+
export declare const addObservabilityTestMultiStageRoutes: (router: express.Application, options: ObservabilityTestMultiStageRouteOptions) => void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addObservabilityTestMultiStageRoutes = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const testMultiStageWorkflow_1 = require("../testMultiStageWorkflow");
|
|
6
|
+
const observabilityRouteAccess_1 = require("./observabilityRouteAccess");
|
|
7
|
+
const requestAiService_1 = require("./requestAiService");
|
|
8
|
+
const BASE_PATH = "/ai/observability";
|
|
9
|
+
const addObservabilityTestMultiStageRoutes = (router, options) => {
|
|
10
|
+
const openApiOptions = options.openApi ? { openApi: options.openApi } : {};
|
|
11
|
+
const builder = () => {
|
|
12
|
+
return (0, api_1.createOpenApiBuilder)(openApiOptions);
|
|
13
|
+
};
|
|
14
|
+
router.post(`${BASE_PATH}/traces/test-multi-stage`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "read", resource: "aiTrace" }, builder()
|
|
15
|
+
.withTags(["observability"])
|
|
16
|
+
.withSummary("Run a multi-stage observability workflow and export one nested trace")
|
|
17
|
+
.withRequestBody({
|
|
18
|
+
input: { type: "string" },
|
|
19
|
+
})
|
|
20
|
+
.withResponse(200, {
|
|
21
|
+
data: {
|
|
22
|
+
properties: {
|
|
23
|
+
output: {
|
|
24
|
+
properties: {
|
|
25
|
+
keywords: { items: { type: "string" }, type: "array" },
|
|
26
|
+
metrics: { type: "object" },
|
|
27
|
+
phrase: { type: "string" },
|
|
28
|
+
sentence: { type: "string" },
|
|
29
|
+
},
|
|
30
|
+
type: "object",
|
|
31
|
+
},
|
|
32
|
+
stages: {
|
|
33
|
+
items: {
|
|
34
|
+
properties: {
|
|
35
|
+
name: { type: "string" },
|
|
36
|
+
status: { type: "string" },
|
|
37
|
+
},
|
|
38
|
+
type: "object",
|
|
39
|
+
},
|
|
40
|
+
type: "array",
|
|
41
|
+
},
|
|
42
|
+
traceId: { type: "string" },
|
|
43
|
+
},
|
|
44
|
+
type: "object",
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
.withResponse(503, { title: { type: "string" } })
|
|
48
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
49
|
+
const aiService = (0, requestAiService_1.resolveRequestAiService)({
|
|
50
|
+
aiService: options.aiService,
|
|
51
|
+
req,
|
|
52
|
+
requestAiServiceFactory: options.requestAiServiceFactory,
|
|
53
|
+
});
|
|
54
|
+
const input = typeof req.body?.input === "string" && req.body.input.length > 0
|
|
55
|
+
? req.body.input
|
|
56
|
+
: "Terreno observability multi-stage smoke test.";
|
|
57
|
+
const userId = req.user?._id;
|
|
58
|
+
const result = await (0, testMultiStageWorkflow_1.runTestMultiStageWorkflow)({
|
|
59
|
+
aiService,
|
|
60
|
+
exportTrace: options.exportTrace,
|
|
61
|
+
input,
|
|
62
|
+
userId,
|
|
63
|
+
});
|
|
64
|
+
return res.json({ data: result });
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
exports.addObservabilityTestMultiStageRoutes = addObservabilityTestMultiStageRoutes;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { LocalTraceStore } from "../local/traceStore";
|
|
3
|
+
import { type ObservabilityRouteAccessOptions } from "./observabilityRouteAccess";
|
|
4
|
+
export interface ObservabilityTraceRouteOptions extends ObservabilityRouteAccessOptions {
|
|
5
|
+
store: LocalTraceStore;
|
|
6
|
+
}
|
|
7
|
+
export declare const addObservabilityTraceRoutes: (router: express.Application, options: ObservabilityTraceRouteOptions) => void;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addObservabilityTraceRoutes = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const observabilityAppRegistry_1 = require("../observabilityAppRegistry");
|
|
6
|
+
const observabilityRouteAccess_1 = require("./observabilityRouteAccess");
|
|
7
|
+
const BASE_PATH = "/ai/observability";
|
|
8
|
+
const parseBoolean = (value) => {
|
|
9
|
+
if (value === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (value === true || value === "true") {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (value === false || value === "false") {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
throw new api_1.APIError({ status: 400, title: "boolean query must be true or false" });
|
|
19
|
+
};
|
|
20
|
+
const parsePromptVersion = (value, prompt) => {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const parsed = Number(value);
|
|
25
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
26
|
+
throw new api_1.APIError({ status: 400, title: "promptVersion must be a positive integer" });
|
|
27
|
+
}
|
|
28
|
+
if (!prompt) {
|
|
29
|
+
throw new api_1.APIError({ status: 400, title: "prompt is required when promptVersion is set" });
|
|
30
|
+
}
|
|
31
|
+
return parsed;
|
|
32
|
+
};
|
|
33
|
+
const parsePositiveInt = (value, fallback) => {
|
|
34
|
+
if (value === undefined) {
|
|
35
|
+
return fallback;
|
|
36
|
+
}
|
|
37
|
+
const parsed = Number(value);
|
|
38
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
39
|
+
throw new api_1.APIError({ status: 400, title: "page and limit must be positive integers" });
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
};
|
|
43
|
+
const addObservabilityTraceRoutes = (router, options) => {
|
|
44
|
+
const openApiOptions = options.openApi ? { openApi: options.openApi } : {};
|
|
45
|
+
const builder = () => {
|
|
46
|
+
return (0, api_1.createOpenApiBuilder)(openApiOptions);
|
|
47
|
+
};
|
|
48
|
+
router.get(`${BASE_PATH}/traces`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "list", resource: "aiTrace" }, builder()
|
|
49
|
+
.withTags(["observability"])
|
|
50
|
+
.withSummary("List observability traces")
|
|
51
|
+
.withQueryParameter("prompt", { type: "string" }, { required: false })
|
|
52
|
+
.withQueryParameter("promptVersion", { type: "number" }, { required: false })
|
|
53
|
+
.withResponse(200, { data: { type: "array" } })
|
|
54
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
55
|
+
const prompt = typeof req.query.prompt === "string" ? req.query.prompt : undefined;
|
|
56
|
+
const listed = await options.store.list({
|
|
57
|
+
flaggedForDataset: parseBoolean(req.query.flaggedForDataset),
|
|
58
|
+
from: typeof req.query.from === "string" ? req.query.from : undefined,
|
|
59
|
+
hasScore: parseBoolean(req.query.hasScore),
|
|
60
|
+
limit: parsePositiveInt(req.query.limit, 20),
|
|
61
|
+
page: parsePositiveInt(req.query.page, 1),
|
|
62
|
+
prompt,
|
|
63
|
+
promptVersion: parsePromptVersion(req.query.promptVersion, prompt),
|
|
64
|
+
sensitive: parseBoolean(req.query.sensitive),
|
|
65
|
+
sessionId: typeof req.query.sessionId === "string" ? req.query.sessionId : undefined,
|
|
66
|
+
status: req.query.status === "ok" || req.query.status === "error" ? req.query.status : undefined,
|
|
67
|
+
to: typeof req.query.to === "string" ? req.query.to : undefined,
|
|
68
|
+
userId: typeof req.query.userId === "string" ? req.query.userId : undefined,
|
|
69
|
+
});
|
|
70
|
+
const { limit, page, total } = listed.meta;
|
|
71
|
+
return res.json({
|
|
72
|
+
data: listed.data,
|
|
73
|
+
limit,
|
|
74
|
+
more: page * limit < total,
|
|
75
|
+
page,
|
|
76
|
+
total,
|
|
77
|
+
});
|
|
78
|
+
}));
|
|
79
|
+
router.get(`${BASE_PATH}/traces/:id`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "read", resource: "aiTrace" }, builder()
|
|
80
|
+
.withTags(["observability"])
|
|
81
|
+
.withSummary("Get an observability trace")
|
|
82
|
+
.withPathParameter("id", { type: "string" })
|
|
83
|
+
.withResponse(200, { data: { type: "object" } })
|
|
84
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
85
|
+
const data = await options.store.getDetail(req.params.id);
|
|
86
|
+
return res.json({ data });
|
|
87
|
+
}));
|
|
88
|
+
router.post(`${BASE_PATH}/traces/:id/scores`, (0, observabilityRouteAccess_1.observabilityRouteMiddleware)(options.accessControl, { action: "score", resource: "aiReview" }, builder()
|
|
89
|
+
.withTags(["observability"])
|
|
90
|
+
.withSummary("Add a score to a trace")
|
|
91
|
+
.withPathParameter("id", { type: "string" })
|
|
92
|
+
.withResponse(201, { data: { type: "object" } })
|
|
93
|
+
.build()), (0, api_1.asyncHandler)(async (req, res) => {
|
|
94
|
+
await options.store.getDetail(req.params.id);
|
|
95
|
+
const body = req.body;
|
|
96
|
+
if (!body.name || body.value === undefined || !body.dataType || !body.source) {
|
|
97
|
+
throw new api_1.APIError({
|
|
98
|
+
status: 400,
|
|
99
|
+
title: "name, value, dataType, and source are required",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const score = {
|
|
103
|
+
comment: body.comment,
|
|
104
|
+
confidence: body.confidence,
|
|
105
|
+
dataType: body.dataType,
|
|
106
|
+
name: body.name,
|
|
107
|
+
source: body.source,
|
|
108
|
+
spanId: body.spanId,
|
|
109
|
+
traceId: req.params.id,
|
|
110
|
+
value: body.value,
|
|
111
|
+
};
|
|
112
|
+
const sinks = (0, observabilityAppRegistry_1.getObservabilityApp)()?.scoreSinks ?? [];
|
|
113
|
+
if (sinks.length === 0) {
|
|
114
|
+
await options.store.exportScore(score);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const results = await Promise.allSettled(sinks.map((sink) => {
|
|
118
|
+
return sink.export(score);
|
|
119
|
+
}));
|
|
120
|
+
for (const result of results) {
|
|
121
|
+
if (result.status === "rejected") {
|
|
122
|
+
throw result.reason;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return res.status(201).json({ data: score });
|
|
127
|
+
}));
|
|
128
|
+
};
|
|
129
|
+
exports.addObservabilityTraceRoutes = addObservabilityTraceRoutes;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateAgainstSchema = void 0;
|
|
7
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
const ajv = new ajv_1.default({ allErrors: true, strict: false });
|
|
9
|
+
const validateAgainstSchema = (schema, value) => {
|
|
10
|
+
if (!schema) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const validate = ajv.compile(schema);
|
|
14
|
+
const valid = validate(value);
|
|
15
|
+
if (valid) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return (validate.errors ?? []).map((error) => {
|
|
19
|
+
const path = error.instancePath.length > 0 ? error.instancePath : "/";
|
|
20
|
+
return {
|
|
21
|
+
message: error.message ?? "schema validation failed",
|
|
22
|
+
path,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.validateAgainstSchema = validateAgainstSchema;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOP_DEFAULT_THRESHOLDS = void 0;
|
|
4
|
+
exports.SOP_DEFAULT_THRESHOLDS = [
|
|
5
|
+
{ aggregate: "trueRate", dimension: "correct", evaluatorName: "correctness", op: "eq", value: 1 },
|
|
6
|
+
{
|
|
7
|
+
aggregate: "trueRate",
|
|
8
|
+
dimension: "hallucinated",
|
|
9
|
+
evaluatorName: "hallucination",
|
|
10
|
+
op: "eq",
|
|
11
|
+
value: 0,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
aggregate: "mean",
|
|
15
|
+
dimension: "helpfulness",
|
|
16
|
+
evaluatorName: "helpfulness",
|
|
17
|
+
op: "gte",
|
|
18
|
+
value: 0.9,
|
|
19
|
+
},
|
|
20
|
+
{ aggregate: "trueRate", dimension: "toxic", evaluatorName: "toxicity", op: "eq", value: 0 },
|
|
21
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RegisteredObservabilityApp } from "./observabilityAppRegistry";
|
|
2
|
+
import type { ObservabilityPermissions } from "./permissions";
|
|
3
|
+
import type { ObservabilityCapability, ObservabilityControlConfig } from "./types";
|
|
4
|
+
export interface ObservabilityPluginStatus {
|
|
5
|
+
capabilities: ObservabilityCapability[];
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export type PlaygroundAiSource = "request-key" | "server" | "unavailable";
|
|
9
|
+
export interface PlaygroundAiStatus {
|
|
10
|
+
source: PlaygroundAiSource;
|
|
11
|
+
}
|
|
12
|
+
export interface ObservabilityStatus {
|
|
13
|
+
localOn: boolean;
|
|
14
|
+
permissions: ObservabilityPermissions;
|
|
15
|
+
playgroundAi: PlaygroundAiStatus;
|
|
16
|
+
plugins: ObservabilityPluginStatus[];
|
|
17
|
+
primaries: ObservabilityControlConfig;
|
|
18
|
+
}
|
|
19
|
+
export declare const buildPlaygroundAiStatus: (app: RegisteredObservabilityApp) => PlaygroundAiStatus;
|
|
20
|
+
export declare const isLocalObservabilityPluginOn: (plugins: ReadonlyArray<{
|
|
21
|
+
id: string;
|
|
22
|
+
}>) => boolean;
|
|
23
|
+
export declare const buildObservabilityStatus: (app: RegisteredObservabilityApp, permissions: ObservabilityPermissions) => ObservabilityStatus;
|