@terreno/ai 57.9.0 → 57.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bunfig.toml +1 -1
- package/dist/aiApp.d.ts +8 -2
- package/dist/aiApp.js +12 -6
- package/dist/harness/adminScreens.d.ts +6 -0
- package/dist/harness/adminScreens.js +11 -0
- package/dist/harness/agentLoop.d.ts +61 -0
- package/dist/harness/agentLoop.js +798 -0
- package/dist/harness/agentTaskNames.d.ts +4 -0
- package/dist/harness/agentTaskNames.js +7 -0
- package/dist/harness/approvalPolicy.d.ts +3 -0
- package/dist/harness/approvalPolicy.js +23 -0
- package/dist/harness/approvals.d.ts +101 -0
- package/dist/harness/approvals.js +468 -0
- package/dist/harness/commit.d.ts +238 -0
- package/dist/harness/commit.js +678 -0
- package/dist/harness/conversation.d.ts +75 -0
- package/dist/harness/conversation.js +397 -0
- package/dist/harness/defineAgent.d.ts +9 -0
- package/dist/harness/defineAgent.js +65 -0
- package/dist/harness/defineTask.d.ts +11 -0
- package/dist/harness/defineTask.js +59 -0
- package/dist/harness/defineTool.d.ts +7 -0
- package/dist/harness/defineTool.js +36 -0
- package/dist/harness/definitionError.d.ts +8 -0
- package/dist/harness/definitionError.js +15 -0
- package/dist/harness/errors.d.ts +133 -0
- package/dist/harness/errors.js +107 -0
- package/dist/harness/eventHub.d.ts +45 -0
- package/dist/harness/eventHub.js +135 -0
- package/dist/harness/events.d.ts +95 -0
- package/dist/harness/events.js +267 -0
- package/dist/harness/executionEnv.d.ts +31 -0
- package/dist/harness/executionEnv.js +2 -0
- package/dist/harness/extensions.d.ts +82 -0
- package/dist/harness/extensions.js +274 -0
- package/dist/harness/harness.d.ts +163 -0
- package/dist/harness/harness.js +522 -0
- package/dist/harness/harnessApp.d.ts +44 -0
- package/dist/harness/harnessApp.js +62 -0
- package/dist/harness/internalRuntime.d.ts +16 -0
- package/dist/harness/internalRuntime.js +18 -0
- package/dist/harness/leases.d.ts +35 -0
- package/dist/harness/leases.js +86 -0
- package/dist/harness/memo.d.ts +24 -0
- package/dist/harness/memo.js +78 -0
- package/dist/harness/modelCall.d.ts +45 -0
- package/dist/harness/modelCall.js +147 -0
- package/dist/harness/models/harnessApproval.d.ts +2 -0
- package/dist/harness/models/harnessApproval.js +100 -0
- package/dist/harness/models/harnessConversation.d.ts +2 -0
- package/dist/harness/models/harnessConversation.js +117 -0
- package/dist/harness/models/harnessEvent.d.ts +3 -0
- package/dist/harness/models/harnessEvent.js +73 -0
- package/dist/harness/models/harnessInboxEvent.d.ts +2 -0
- package/dist/harness/models/harnessInboxEvent.js +58 -0
- package/dist/harness/models/harnessMemo.d.ts +2 -0
- package/dist/harness/models/harnessMemo.js +42 -0
- package/dist/harness/models/harnessMessage.d.ts +2 -0
- package/dist/harness/models/harnessMessage.js +73 -0
- package/dist/harness/models/harnessOwner.d.ts +2 -0
- package/dist/harness/models/harnessOwner.js +36 -0
- package/dist/harness/models/harnessTask.d.ts +2 -0
- package/dist/harness/models/harnessTask.js +191 -0
- package/dist/harness/ownership.d.ts +89 -0
- package/dist/harness/ownership.js +438 -0
- package/dist/harness/registry.d.ts +29 -0
- package/dist/harness/registry.js +93 -0
- package/dist/harness/retryBackoff.d.ts +31 -0
- package/dist/harness/retryBackoff.js +50 -0
- package/dist/harness/routes/approvals.d.ts +13 -0
- package/dist/harness/routes/approvals.js +93 -0
- package/dist/harness/routes/conversations.d.ts +11 -0
- package/dist/harness/routes/conversations.js +66 -0
- package/dist/harness/routes/events.d.ts +19 -0
- package/dist/harness/routes/events.js +215 -0
- package/dist/harness/routes/tasks.d.ts +11 -0
- package/dist/harness/routes/tasks.js +108 -0
- package/dist/harness/runners/inProcessRunner.d.ts +64 -0
- package/dist/harness/runners/inProcessRunner.js +227 -0
- package/dist/harness/runners/jobsRunner.d.ts +62 -0
- package/dist/harness/runners/jobsRunner.js +212 -0
- package/dist/harness/runtime.d.ts +52 -0
- package/dist/harness/runtime.js +604 -0
- package/dist/harness/subagent.d.ts +53 -0
- package/dist/harness/subagent.js +134 -0
- package/dist/harness/suspend.d.ts +8 -0
- package/dist/harness/suspend.js +16 -0
- package/dist/harness/transaction.d.ts +3 -0
- package/dist/harness/transaction.js +22 -0
- package/dist/harness/waits.d.ts +100 -0
- package/dist/harness/waits.js +214 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +45 -2
- package/dist/models/aiDataset.d.ts +2 -0
- package/dist/models/aiDataset.js +67 -0
- package/dist/models/aiRequest.js +1 -1
- package/dist/models/gptHistory.js +73 -0
- package/dist/observability/adminScreens.d.ts +5 -0
- package/dist/observability/adminScreens.js +32 -0
- package/dist/observability/compileTemplate.d.ts +1 -0
- package/dist/observability/compileTemplate.js +13 -0
- package/dist/observability/datasetImport.d.ts +11 -0
- package/dist/observability/datasetImport.js +185 -0
- package/dist/observability/evaluate.d.ts +31 -0
- package/dist/observability/evaluate.js +200 -0
- package/dist/observability/evaluatorTemplates.d.ts +17 -0
- package/dist/observability/evaluatorTemplates.js +111 -0
- package/dist/observability/jsonPath.d.ts +2 -0
- package/dist/observability/jsonPath.js +57 -0
- package/dist/observability/local/datasetStore.d.ts +87 -0
- package/dist/observability/local/datasetStore.js +326 -0
- package/dist/observability/local/evaluatorStore.d.ts +44 -0
- package/dist/observability/local/evaluatorStore.js +182 -0
- package/dist/observability/local/experimentRunner.d.ts +96 -0
- package/dist/observability/local/experimentRunner.js +419 -0
- package/dist/observability/local/localPlugin.d.ts +22 -0
- package/dist/observability/local/localPlugin.js +76 -0
- package/dist/observability/local/models/obsDataset.d.ts +2 -0
- package/dist/observability/local/models/obsDataset.js +37 -0
- package/dist/observability/local/models/obsDatasetItem.d.ts +2 -0
- package/dist/observability/local/models/obsDatasetItem.js +76 -0
- package/dist/observability/local/models/obsEvaluator.d.ts +2 -0
- package/dist/observability/local/models/obsEvaluator.js +98 -0
- package/dist/observability/local/models/obsExperiment.d.ts +2 -0
- package/dist/observability/local/models/obsExperiment.js +87 -0
- package/dist/observability/local/models/obsExperimentItem.d.ts +2 -0
- package/dist/observability/local/models/obsExperimentItem.js +45 -0
- package/dist/observability/local/models/obsPrompt.d.ts +2 -0
- package/dist/observability/local/models/obsPrompt.js +42 -0
- package/dist/observability/local/models/obsPromptLabel.d.ts +2 -0
- package/dist/observability/local/models/obsPromptLabel.js +39 -0
- package/dist/observability/local/models/obsPromptVersion.d.ts +2 -0
- package/dist/observability/local/models/obsPromptVersion.js +96 -0
- package/dist/observability/local/models/obsReviewItem.d.ts +2 -0
- package/dist/observability/local/models/obsReviewItem.js +75 -0
- package/dist/observability/local/models/obsScore.d.ts +2 -0
- package/dist/observability/local/models/obsScore.js +58 -0
- package/dist/observability/local/models/obsSpan.d.ts +2 -0
- package/dist/observability/local/models/obsSpan.js +64 -0
- package/dist/observability/local/models/obsTrace.d.ts +2 -0
- package/dist/observability/local/models/obsTrace.js +93 -0
- package/dist/observability/local/promptStore.d.ts +180 -0
- package/dist/observability/local/promptStore.js +444 -0
- package/dist/observability/local/reviewStore.d.ts +50 -0
- package/dist/observability/local/reviewStore.js +203 -0
- package/dist/observability/local/traceStore.d.ts +103 -0
- package/dist/observability/local/traceStore.js +325 -0
- package/dist/observability/observabilityApp.d.ts +24 -0
- package/dist/observability/observabilityApp.js +157 -0
- package/dist/observability/observabilityAppRegistry.d.ts +14 -0
- package/dist/observability/observabilityAppRegistry.js +16 -0
- package/dist/observability/permissions.d.ts +7 -0
- package/dist/observability/permissions.js +60 -0
- package/dist/observability/reviewPanels.d.ts +18 -0
- package/dist/observability/reviewPanels.js +46 -0
- package/dist/observability/routes/datasets.d.ts +7 -0
- package/dist/observability/routes/datasets.js +149 -0
- package/dist/observability/routes/evaluators.d.ts +7 -0
- package/dist/observability/routes/evaluators.js +123 -0
- package/dist/observability/routes/experiments.d.ts +7 -0
- package/dist/observability/routes/experiments.js +95 -0
- package/dist/observability/routes/observabilityRouteAccess.d.ts +13 -0
- package/dist/observability/routes/observabilityRouteAccess.js +67 -0
- package/dist/observability/routes/prompts.d.ts +12 -0
- package/dist/observability/routes/prompts.js +172 -0
- package/dist/observability/routes/requestAiService.d.ts +13 -0
- package/dist/observability/routes/requestAiService.js +21 -0
- package/dist/observability/routes/review.d.ts +7 -0
- package/dist/observability/routes/review.js +79 -0
- package/dist/observability/routes/status.d.ts +5 -0
- package/dist/observability/routes/status.js +31 -0
- package/dist/observability/routes/testMultiStage.d.ts +9 -0
- package/dist/observability/routes/testMultiStage.js +67 -0
- package/dist/observability/routes/traces.d.ts +7 -0
- package/dist/observability/routes/traces.js +129 -0
- package/dist/observability/schemaValidation.d.ts +5 -0
- package/dist/observability/schemaValidation.js +26 -0
- package/dist/observability/sopThresholds.d.ts +2 -0
- package/dist/observability/sopThresholds.js +21 -0
- package/dist/observability/status.d.ts +23 -0
- package/dist/observability/status.js +34 -0
- package/dist/observability/testMultiStageSchemas.d.ts +10 -0
- package/dist/observability/testMultiStageSchemas.js +79 -0
- package/dist/observability/testMultiStageWorkflow.d.ts +20 -0
- package/dist/observability/testMultiStageWorkflow.js +218 -0
- package/dist/observability/types.d.ts +159 -0
- package/dist/observability/types.js +67 -0
- package/dist/routes/files.js +18 -7
- package/dist/routes/gpt.js +79 -689
- package/dist/routes/gptActions.d.ts +9 -0
- package/dist/routes/gptActions.js +212 -0
- package/dist/routes/gptDatasets.d.ts +5 -0
- package/dist/routes/gptDatasets.js +94 -0
- package/dist/routes/gptHistories.d.ts +3 -1
- package/dist/routes/gptHistories.js +188 -2
- package/dist/service/aiDatasets.d.ts +57 -0
- package/dist/service/aiDatasets.js +253 -0
- package/dist/service/aiService.d.ts +50 -1
- package/dist/service/aiService.js +426 -77
- package/dist/service/askFiles.d.ts +49 -0
- package/dist/service/askFiles.js +162 -0
- package/dist/service/asks.d.ts +76 -0
- package/dist/service/asks.js +284 -0
- package/dist/service/chatTurn.d.ts +128 -0
- package/dist/service/chatTurn.js +1674 -0
- package/dist/service/fileStorage.d.ts +4 -0
- package/dist/service/fileStorage.js +7 -2
- package/dist/service/fillActionIds.d.ts +6 -0
- package/dist/service/fillActionIds.js +79 -0
- package/dist/service/jsonFenceModel.d.ts +7 -0
- package/dist/service/jsonFenceModel.js +45 -0
- package/dist/service/prompts.d.ts +52 -0
- package/dist/service/prompts.js +96 -1
- package/dist/service/sanitizeHtml.d.ts +11 -0
- package/dist/service/sanitizeHtml.js +108 -0
- package/dist/types/harness.d.ts +952 -0
- package/dist/types/harness.js +133 -0
- package/dist/types/index.d.ts +192 -14
- package/dist/types/index.js +2 -0
- package/dist/types/observability.d.ts +288 -0
- package/dist/types/observability.js +2 -0
- package/package.json +28 -5
- package/src/aiApp.test.ts +207 -1
- package/src/aiApp.ts +19 -6
- package/src/harness/adminScreens.test.ts +34 -0
- package/src/harness/adminScreens.ts +11 -0
- package/src/harness/agentLoop.test.ts +1034 -0
- package/src/harness/agentLoop.ts +1082 -0
- package/src/harness/agentRecovery.test.ts +380 -0
- package/src/harness/agentTaskNames.ts +4 -0
- package/src/harness/approvalPolicy.ts +28 -0
- package/src/harness/approvals.test.ts +1094 -0
- package/src/harness/approvals.ts +644 -0
- package/src/harness/commit.ts +1049 -0
- package/src/harness/concurrency.test.ts +155 -0
- package/src/harness/conversation.ts +503 -0
- package/src/harness/defineAgent.test.ts +92 -0
- package/src/harness/defineAgent.ts +82 -0
- package/src/harness/defineTask.test.ts +59 -0
- package/src/harness/defineTask.ts +76 -0
- package/src/harness/defineTool.ts +45 -0
- package/src/harness/definitionError.ts +13 -0
- package/src/harness/errors.test.ts +90 -0
- package/src/harness/errors.ts +125 -0
- package/src/harness/eventHub.test.ts +124 -0
- package/src/harness/eventHub.ts +159 -0
- package/src/harness/events.test.ts +769 -0
- package/src/harness/events.ts +384 -0
- package/src/harness/executionEnv.ts +34 -0
- package/src/harness/extensions.test.ts +1218 -0
- package/src/harness/extensions.ts +382 -0
- package/src/harness/harness.test.ts +693 -0
- package/src/harness/harness.ts +778 -0
- package/src/harness/harnessApp.ts +76 -0
- package/src/harness/internalRuntime.ts +44 -0
- package/src/harness/leases.ts +132 -0
- package/src/harness/memo.ts +107 -0
- package/src/harness/modelCall.test.ts +134 -0
- package/src/harness/modelCall.ts +200 -0
- package/src/harness/models/harnessApproval.ts +109 -0
- package/src/harness/models/harnessConversation.ts +142 -0
- package/src/harness/models/harnessEvent.ts +92 -0
- package/src/harness/models/harnessInboxEvent.ts +73 -0
- package/src/harness/models/harnessMemo.ts +43 -0
- package/src/harness/models/harnessMessage.ts +85 -0
- package/src/harness/models/harnessModels.test.ts +60 -0
- package/src/harness/models/harnessOwner.ts +40 -0
- package/src/harness/models/harnessTask.ts +206 -0
- package/src/harness/ownership.test.ts +1087 -0
- package/src/harness/ownership.ts +618 -0
- package/src/harness/recovery.test.ts +907 -0
- package/src/harness/registry.ts +124 -0
- package/src/harness/retries.test.ts +292 -0
- package/src/harness/retryBackoff.test.ts +100 -0
- package/src/harness/retryBackoff.ts +77 -0
- package/src/harness/routes/approvals.ts +123 -0
- package/src/harness/routes/conversations.test.ts +518 -0
- package/src/harness/routes/conversations.ts +102 -0
- package/src/harness/routes/events.ts +280 -0
- package/src/harness/routes/tasks.test.ts +198 -0
- package/src/harness/routes/tasks.ts +146 -0
- package/src/harness/runners/inProcessRunner.test.ts +530 -0
- package/src/harness/runners/inProcessRunner.ts +260 -0
- package/src/harness/runners/jobsRunner.test.ts +709 -0
- package/src/harness/runners/jobsRunner.ts +252 -0
- package/src/harness/runtime.ts +802 -0
- package/src/harness/subagent.test.ts +696 -0
- package/src/harness/subagent.ts +192 -0
- package/src/harness/suspend.ts +13 -0
- package/src/harness/transaction.ts +17 -0
- package/src/harness/versioning.test.ts +288 -0
- package/src/harness/waits.test.ts +693 -0
- package/src/harness/waits.ts +356 -0
- package/src/index.test.ts +13 -0
- package/src/index.ts +70 -0
- package/src/isolated/adminScreensConfig.isolated.ts +143 -0
- package/src/models/aiDataset.test.ts +34 -0
- package/src/models/aiDataset.ts +78 -0
- package/src/models/aiRequest.ts +2 -1
- package/src/models/gptHistory.test.ts +156 -0
- package/src/models/gptHistory.ts +89 -1
- package/src/observability/adminScreens.test.ts +71 -0
- package/src/observability/adminScreens.ts +42 -0
- package/src/observability/compileTemplate.test.ts +14 -0
- package/src/observability/compileTemplate.ts +10 -0
- package/src/observability/datasetImport.test.ts +95 -0
- package/src/observability/datasetImport.ts +220 -0
- package/src/observability/evaluate.test.ts +549 -0
- package/src/observability/evaluate.ts +254 -0
- package/src/observability/evaluatorTemplates.ts +124 -0
- package/src/observability/jsonPath.test.ts +52 -0
- package/src/observability/jsonPath.ts +60 -0
- package/src/observability/local/datasetStore.test.ts +230 -0
- package/src/observability/local/datasetStore.ts +452 -0
- package/src/observability/local/evaluatorStore.test.ts +138 -0
- package/src/observability/local/evaluatorStore.ts +224 -0
- package/src/observability/local/experimentRunner.test.ts +489 -0
- package/src/observability/local/experimentRunner.ts +548 -0
- package/src/observability/local/localPlugin.ts +88 -0
- package/src/observability/local/models/obsDataset.ts +38 -0
- package/src/observability/local/models/obsDatasetItem.ts +80 -0
- package/src/observability/local/models/obsEvaluator.ts +102 -0
- package/src/observability/local/models/obsExperiment.ts +91 -0
- package/src/observability/local/models/obsExperimentItem.ts +52 -0
- package/src/observability/local/models/obsPrompt.ts +43 -0
- package/src/observability/local/models/obsPromptLabel.ts +43 -0
- package/src/observability/local/models/obsPromptVersion.ts +107 -0
- package/src/observability/local/models/obsReviewItem.ts +79 -0
- package/src/observability/local/models/obsScore.ts +59 -0
- package/src/observability/local/models/obsSpan.ts +65 -0
- package/src/observability/local/models/obsTrace.ts +94 -0
- package/src/observability/local/obsModels.test.ts +119 -0
- package/src/observability/local/promptStore.test.ts +351 -0
- package/src/observability/local/promptStore.ts +665 -0
- package/src/observability/local/reviewStore.test.ts +164 -0
- package/src/observability/local/reviewStore.ts +264 -0
- package/src/observability/local/traceStore.test.ts +264 -0
- package/src/observability/local/traceStore.ts +440 -0
- package/src/observability/observabilityApp.test.ts +92 -0
- package/src/observability/observabilityApp.ts +185 -0
- package/src/observability/observabilityAppRegistry.test.ts +30 -0
- package/src/observability/observabilityAppRegistry.ts +35 -0
- package/src/observability/permissions.test.ts +96 -0
- package/src/observability/permissions.ts +78 -0
- package/src/observability/reviewPanels.test.ts +35 -0
- package/src/observability/reviewPanels.ts +64 -0
- package/src/observability/routes/datasets.test.ts +176 -0
- package/src/observability/routes/datasets.ts +252 -0
- package/src/observability/routes/evaluators.test.ts +119 -0
- package/src/observability/routes/evaluators.ts +207 -0
- package/src/observability/routes/experiments.test.ts +282 -0
- package/src/observability/routes/experiments.ts +152 -0
- package/src/observability/routes/observabilityRbac.test.ts +767 -0
- package/src/observability/routes/observabilityRouteAccess.ts +106 -0
- package/src/observability/routes/prompts.test.ts +320 -0
- package/src/observability/routes/prompts.ts +263 -0
- package/src/observability/routes/requestAiService.ts +36 -0
- package/src/observability/routes/review.test.ts +120 -0
- package/src/observability/routes/review.ts +125 -0
- package/src/observability/routes/status.test.ts +116 -0
- package/src/observability/routes/status.ts +47 -0
- package/src/observability/routes/testMultiStage.test.ts +214 -0
- package/src/observability/routes/testMultiStage.ts +96 -0
- package/src/observability/routes/traces.test.ts +167 -0
- package/src/observability/routes/traces.ts +172 -0
- package/src/observability/schemaValidation.ts +29 -0
- package/src/observability/sopThresholds.ts +20 -0
- package/src/observability/status.test.ts +38 -0
- package/src/observability/status.ts +56 -0
- package/src/observability/testMultiStageSchemas.ts +95 -0
- package/src/observability/testMultiStageWorkflow.test.ts +114 -0
- package/src/observability/testMultiStageWorkflow.ts +307 -0
- package/src/observability/types.ts +262 -0
- package/src/routes/files.test.ts +63 -9
- package/src/routes/files.ts +21 -7
- package/src/routes/gpt.test.ts +3279 -0
- package/src/routes/gpt.ts +91 -816
- package/src/routes/gptActions.test.ts +241 -0
- package/src/routes/gptActions.ts +255 -0
- package/src/routes/gptApprovals.test.ts +762 -0
- package/src/routes/gptDatasets.test.ts +86 -0
- package/src/routes/gptDatasets.ts +104 -0
- package/src/routes/gptFiles.test.ts +589 -0
- package/src/routes/gptHistories.test.ts +933 -0
- package/src/routes/gptHistories.ts +266 -5
- package/src/routes/routes.test.ts +222 -2
- package/src/service/aiDatasets.test.ts +123 -0
- package/src/service/aiDatasets.ts +316 -0
- package/src/service/aiService.test.ts +593 -0
- package/src/service/aiService.ts +568 -111
- package/src/service/askFiles.test.ts +96 -0
- package/src/service/askFiles.ts +222 -0
- package/src/service/asks.test.ts +946 -0
- package/src/service/asks.ts +423 -0
- package/src/service/chatTurn.ts +2287 -0
- package/src/service/fileStorage.test.ts +11 -0
- package/src/service/fileStorage.ts +10 -2
- package/src/service/fillActionIds.test.ts +65 -0
- package/src/service/fillActionIds.ts +98 -0
- package/src/service/jsonFenceModel.test.ts +47 -0
- package/src/service/jsonFenceModel.ts +53 -0
- package/src/service/prompts.test.ts +21 -0
- package/src/service/prompts.ts +147 -0
- package/src/service/sanitizeHtml.test.ts +61 -0
- package/src/service/sanitizeHtml.ts +109 -0
- package/src/tests/bunSetup.test.ts +7 -4
- package/src/tests/bunSetup.ts +7 -7
- package/src/tests/chatHarness.ts +478 -0
- package/src/tests/generateStream.ts +49 -0
- package/src/tests/harnessErrors.ts +22 -0
- package/src/tests/harnessStreaming.ts +227 -0
- package/src/tests/helpers.ts +9 -2
- package/src/types/harness.ts +1119 -0
- package/src/types/index.ts +209 -13
- package/src/types/observability.ts +344 -0
- package/src/types/sanitize-html.d.ts +25 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildObservabilityStatus = exports.isLocalObservabilityPluginOn = exports.buildPlaygroundAiStatus = void 0;
|
|
4
|
+
const buildPlaygroundAiStatus = (app) => {
|
|
5
|
+
if (app.aiService) {
|
|
6
|
+
return { source: "server" };
|
|
7
|
+
}
|
|
8
|
+
if (app.requestAiServiceFactory) {
|
|
9
|
+
return { source: "request-key" };
|
|
10
|
+
}
|
|
11
|
+
return { source: "unavailable" };
|
|
12
|
+
};
|
|
13
|
+
exports.buildPlaygroundAiStatus = buildPlaygroundAiStatus;
|
|
14
|
+
const isLocalObservabilityPluginOn = (plugins) => {
|
|
15
|
+
return plugins.some((plugin) => {
|
|
16
|
+
return plugin.id === "local";
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.isLocalObservabilityPluginOn = isLocalObservabilityPluginOn;
|
|
20
|
+
const buildObservabilityStatus = (app, permissions) => {
|
|
21
|
+
return {
|
|
22
|
+
localOn: (0, exports.isLocalObservabilityPluginOn)(app.plugins),
|
|
23
|
+
permissions,
|
|
24
|
+
playgroundAi: (0, exports.buildPlaygroundAiStatus)(app),
|
|
25
|
+
plugins: app.plugins.map((plugin) => {
|
|
26
|
+
return {
|
|
27
|
+
capabilities: [...plugin.capabilities].sort(),
|
|
28
|
+
id: plugin.id,
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
primaries: app.control,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.buildObservabilityStatus = buildObservabilityStatus;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ObsTestMultiStageCall1Output, ObsTestMultiStageCall2Output, ObsTestMultiStageFinalOutput } from "../types";
|
|
2
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_1_SCHEMA_NAME = "obs-test-multi-stage-call-1";
|
|
3
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_2_SCHEMA_NAME = "obs-test-multi-stage-call-2";
|
|
4
|
+
export declare const OBS_TEST_MULTI_STAGE_FINAL_SCHEMA_NAME = "obs-test-multi-stage-final";
|
|
5
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA: Record<string, unknown>;
|
|
6
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA: Record<string, unknown>;
|
|
7
|
+
export declare const OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA: Record<string, unknown>;
|
|
8
|
+
export declare const obsTestMultiStageCall1Schema: import("ai").Schema<ObsTestMultiStageCall1Output>;
|
|
9
|
+
export declare const obsTestMultiStageCall2Schema: import("ai").Schema<ObsTestMultiStageCall2Output>;
|
|
10
|
+
export declare const obsTestMultiStageFinalSchema: import("ai").Schema<ObsTestMultiStageFinalOutput>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.obsTestMultiStageFinalSchema = exports.obsTestMultiStageCall2Schema = exports.obsTestMultiStageCall1Schema = exports.OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA = exports.OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA = exports.OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA = exports.OBS_TEST_MULTI_STAGE_FINAL_SCHEMA_NAME = exports.OBS_TEST_MULTI_STAGE_CALL_2_SCHEMA_NAME = exports.OBS_TEST_MULTI_STAGE_CALL_1_SCHEMA_NAME = void 0;
|
|
4
|
+
const ai_1 = require("ai");
|
|
5
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_1_SCHEMA_NAME = "obs-test-multi-stage-call-1";
|
|
6
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_2_SCHEMA_NAME = "obs-test-multi-stage-call-2";
|
|
7
|
+
exports.OBS_TEST_MULTI_STAGE_FINAL_SCHEMA_NAME = "obs-test-multi-stage-final";
|
|
8
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA = {
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
properties: {
|
|
11
|
+
phrase: {
|
|
12
|
+
description: "One short phrase summarizing the user input",
|
|
13
|
+
type: "string",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
required: ["phrase"],
|
|
17
|
+
type: "object",
|
|
18
|
+
};
|
|
19
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA = {
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
properties: {
|
|
22
|
+
keywords: {
|
|
23
|
+
description: "Exactly two keywords taken from the user input",
|
|
24
|
+
items: { type: "string" },
|
|
25
|
+
maxItems: 2,
|
|
26
|
+
minItems: 2,
|
|
27
|
+
type: "array",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["keywords"],
|
|
31
|
+
type: "object",
|
|
32
|
+
};
|
|
33
|
+
exports.OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA = {
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
properties: {
|
|
36
|
+
keywords: {
|
|
37
|
+
description: "The two keywords from stage two",
|
|
38
|
+
items: { type: "string" },
|
|
39
|
+
type: "array",
|
|
40
|
+
},
|
|
41
|
+
metrics: {
|
|
42
|
+
description: "Character and word counts from the text-metrics tool",
|
|
43
|
+
properties: {
|
|
44
|
+
call1: {
|
|
45
|
+
properties: {
|
|
46
|
+
charCount: { type: "number" },
|
|
47
|
+
wordCount: { type: "number" },
|
|
48
|
+
},
|
|
49
|
+
required: ["charCount", "wordCount"],
|
|
50
|
+
type: "object",
|
|
51
|
+
},
|
|
52
|
+
call2: {
|
|
53
|
+
properties: {
|
|
54
|
+
charCount: { type: "number" },
|
|
55
|
+
wordCount: { type: "number" },
|
|
56
|
+
},
|
|
57
|
+
required: ["charCount", "wordCount"],
|
|
58
|
+
type: "object",
|
|
59
|
+
},
|
|
60
|
+
combinedCharCount: { type: "number" },
|
|
61
|
+
},
|
|
62
|
+
required: ["call1", "call2", "combinedCharCount"],
|
|
63
|
+
type: "object",
|
|
64
|
+
},
|
|
65
|
+
phrase: {
|
|
66
|
+
description: "The short phrase from stage one",
|
|
67
|
+
type: "string",
|
|
68
|
+
},
|
|
69
|
+
sentence: {
|
|
70
|
+
description: "One concise sentence combining phrase, keywords, and metrics",
|
|
71
|
+
type: "string",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
required: ["keywords", "metrics", "phrase", "sentence"],
|
|
75
|
+
type: "object",
|
|
76
|
+
};
|
|
77
|
+
exports.obsTestMultiStageCall1Schema = (0, ai_1.jsonSchema)(exports.OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA);
|
|
78
|
+
exports.obsTestMultiStageCall2Schema = (0, ai_1.jsonSchema)(exports.OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA);
|
|
79
|
+
exports.obsTestMultiStageFinalSchema = (0, ai_1.jsonSchema)(exports.OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type mongoose from "mongoose";
|
|
2
|
+
import type { ObsTestMultiStageFinalOutput } from "../types";
|
|
3
|
+
import type { ObservabilityGenerateClient, TraceRecord } from "./types";
|
|
4
|
+
export interface TestMultiStageStageSummary {
|
|
5
|
+
name: string;
|
|
6
|
+
output?: unknown;
|
|
7
|
+
status: "error" | "ok";
|
|
8
|
+
}
|
|
9
|
+
export interface TestMultiStageWorkflowResult {
|
|
10
|
+
output: ObsTestMultiStageFinalOutput;
|
|
11
|
+
stages: TestMultiStageStageSummary[];
|
|
12
|
+
traceId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TestMultiStageWorkflowParams {
|
|
15
|
+
aiService: ObservabilityGenerateClient;
|
|
16
|
+
exportTrace: (trace: TraceRecord) => Promise<string | undefined>;
|
|
17
|
+
input: string;
|
|
18
|
+
userId?: mongoose.Types.ObjectId;
|
|
19
|
+
}
|
|
20
|
+
export declare const runTestMultiStageWorkflow: (params: TestMultiStageWorkflowParams) => Promise<TestMultiStageWorkflowResult>;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTestMultiStageWorkflow = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
const prompts_1 = require("../service/prompts");
|
|
7
|
+
const testMultiStageSchemas_1 = require("./testMultiStageSchemas");
|
|
8
|
+
const toIsoUtc = (millis) => {
|
|
9
|
+
return luxon_1.DateTime.fromMillis(millis, { zone: "utc" }).toISO() ?? "";
|
|
10
|
+
};
|
|
11
|
+
const computeTextMetrics = (text) => {
|
|
12
|
+
return {
|
|
13
|
+
charCount: text.length,
|
|
14
|
+
wordCount: text.split(/\s+/).filter((word) => word.length > 0).length,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const buildChildSpan = (params) => {
|
|
18
|
+
return {
|
|
19
|
+
durationMs: params.endedAt - params.startedAt,
|
|
20
|
+
endedAt: toIsoUtc(params.endedAt),
|
|
21
|
+
id: (0, node_crypto_1.randomUUID)(),
|
|
22
|
+
input: params.input,
|
|
23
|
+
kind: params.kind,
|
|
24
|
+
name: params.name,
|
|
25
|
+
output: params.output,
|
|
26
|
+
startedAt: toIsoUtc(params.startedAt),
|
|
27
|
+
startOffsetMs: params.startedAt - params.traceStart,
|
|
28
|
+
status: params.status,
|
|
29
|
+
...(params.error ? { error: params.error } : {}),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const buildTrace = (params) => {
|
|
33
|
+
const endedAt = luxon_1.DateTime.now().toMillis();
|
|
34
|
+
const rootId = (0, node_crypto_1.randomUUID)();
|
|
35
|
+
const rootSpan = {
|
|
36
|
+
durationMs: endedAt - params.traceStart,
|
|
37
|
+
endedAt: toIsoUtc(endedAt),
|
|
38
|
+
id: rootId,
|
|
39
|
+
input: params.input,
|
|
40
|
+
kind: "CHAIN",
|
|
41
|
+
name: "test-multi-stage",
|
|
42
|
+
output: params.output,
|
|
43
|
+
startedAt: toIsoUtc(params.traceStart),
|
|
44
|
+
status: params.status,
|
|
45
|
+
...(params.errorSummary ? { error: params.errorSummary } : {}),
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
endedAt: toIsoUtc(endedAt),
|
|
49
|
+
id: (0, node_crypto_1.randomUUID)(),
|
|
50
|
+
input: params.input,
|
|
51
|
+
name: "test-multi-stage",
|
|
52
|
+
output: params.output,
|
|
53
|
+
prompts: [],
|
|
54
|
+
sensitive: false,
|
|
55
|
+
spans: [
|
|
56
|
+
rootSpan,
|
|
57
|
+
...params.childSpans.map((child) => {
|
|
58
|
+
return {
|
|
59
|
+
...child,
|
|
60
|
+
parentSpanId: rootId,
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
startedAt: toIsoUtc(params.traceStart),
|
|
65
|
+
status: params.status,
|
|
66
|
+
userId: params.userId?.toString(),
|
|
67
|
+
...(params.errorSummary ? { error: params.errorSummary } : {}),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const runLlmObjectStage = async (params) => {
|
|
71
|
+
const startedAt = luxon_1.DateTime.now().toMillis();
|
|
72
|
+
const spanInput = {
|
|
73
|
+
outputSchema: params.outputSchema,
|
|
74
|
+
prompt: params.prompt,
|
|
75
|
+
schemaName: params.schemaName,
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
const output = await params.aiService.generateJsonObject({
|
|
79
|
+
prompt: params.prompt,
|
|
80
|
+
schema: params.schema,
|
|
81
|
+
schemaDescription: params.schemaDescription,
|
|
82
|
+
schemaName: params.schemaName,
|
|
83
|
+
skipTrace: true,
|
|
84
|
+
systemPrompt: params.systemPrompt,
|
|
85
|
+
userId: params.userId,
|
|
86
|
+
});
|
|
87
|
+
const endedAt = luxon_1.DateTime.now().toMillis();
|
|
88
|
+
params.childSpans.push(buildChildSpan({
|
|
89
|
+
endedAt,
|
|
90
|
+
input: spanInput,
|
|
91
|
+
kind: "LLM",
|
|
92
|
+
name: params.name,
|
|
93
|
+
output,
|
|
94
|
+
startedAt,
|
|
95
|
+
status: "ok",
|
|
96
|
+
traceStart: params.traceStart,
|
|
97
|
+
}));
|
|
98
|
+
params.stages.push({ name: params.name, output, status: "ok" });
|
|
99
|
+
return output;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const endedAt = luxon_1.DateTime.now().toMillis();
|
|
103
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
+
params.childSpans.push(buildChildSpan({
|
|
105
|
+
endedAt,
|
|
106
|
+
error: message,
|
|
107
|
+
input: spanInput,
|
|
108
|
+
kind: "LLM",
|
|
109
|
+
name: params.name,
|
|
110
|
+
output: undefined,
|
|
111
|
+
startedAt,
|
|
112
|
+
status: "error",
|
|
113
|
+
traceStart: params.traceStart,
|
|
114
|
+
}));
|
|
115
|
+
params.stages.push({ name: params.name, status: "error" });
|
|
116
|
+
const trace = buildTrace({
|
|
117
|
+
childSpans: params.childSpans,
|
|
118
|
+
errorSummary: message,
|
|
119
|
+
input: params.workflowInput,
|
|
120
|
+
status: "error",
|
|
121
|
+
traceStart: params.traceStart,
|
|
122
|
+
userId: params.userId,
|
|
123
|
+
});
|
|
124
|
+
await params.exportTrace(trace);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const runTestMultiStageWorkflow = async (params) => {
|
|
129
|
+
const traceStart = luxon_1.DateTime.now().toMillis();
|
|
130
|
+
const childSpans = [];
|
|
131
|
+
const stages = [];
|
|
132
|
+
const call1Output = await runLlmObjectStage({
|
|
133
|
+
aiService: params.aiService,
|
|
134
|
+
childSpans,
|
|
135
|
+
exportTrace: params.exportTrace,
|
|
136
|
+
name: "call-1",
|
|
137
|
+
outputSchema: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_CALL_1_OUTPUT_SCHEMA,
|
|
138
|
+
prompt: params.input,
|
|
139
|
+
schema: testMultiStageSchemas_1.obsTestMultiStageCall1Schema,
|
|
140
|
+
schemaDescription: "Short phrase summary of the user input",
|
|
141
|
+
schemaName: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_CALL_1_SCHEMA_NAME,
|
|
142
|
+
stages,
|
|
143
|
+
systemPrompt: prompts_1.OBS_TEST_MULTI_STAGE_CALL_1_SYSTEM,
|
|
144
|
+
traceStart,
|
|
145
|
+
userId: params.userId,
|
|
146
|
+
workflowInput: params.input,
|
|
147
|
+
});
|
|
148
|
+
const call2Output = await runLlmObjectStage({
|
|
149
|
+
aiService: params.aiService,
|
|
150
|
+
childSpans,
|
|
151
|
+
exportTrace: params.exportTrace,
|
|
152
|
+
name: "call-2",
|
|
153
|
+
outputSchema: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_CALL_2_OUTPUT_SCHEMA,
|
|
154
|
+
prompt: params.input,
|
|
155
|
+
schema: testMultiStageSchemas_1.obsTestMultiStageCall2Schema,
|
|
156
|
+
schemaDescription: "Exactly two keywords from the user input",
|
|
157
|
+
schemaName: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_CALL_2_SCHEMA_NAME,
|
|
158
|
+
stages,
|
|
159
|
+
systemPrompt: prompts_1.OBS_TEST_MULTI_STAGE_CALL_2_SYSTEM,
|
|
160
|
+
traceStart,
|
|
161
|
+
userId: params.userId,
|
|
162
|
+
workflowInput: params.input,
|
|
163
|
+
});
|
|
164
|
+
const call1Text = call1Output.phrase;
|
|
165
|
+
const call2Text = call2Output.keywords.join(", ");
|
|
166
|
+
const toolStartedAt = luxon_1.DateTime.now().toMillis();
|
|
167
|
+
const toolOutput = {
|
|
168
|
+
call1: computeTextMetrics(call1Text),
|
|
169
|
+
call2: computeTextMetrics(call2Text),
|
|
170
|
+
combinedCharCount: call1Text.length + call2Text.length,
|
|
171
|
+
};
|
|
172
|
+
const toolEndedAt = luxon_1.DateTime.now().toMillis();
|
|
173
|
+
childSpans.push(buildChildSpan({
|
|
174
|
+
endedAt: toolEndedAt,
|
|
175
|
+
input: { call1: call1Output, call2: call2Output },
|
|
176
|
+
kind: "TOOL",
|
|
177
|
+
name: "text-metrics",
|
|
178
|
+
output: toolOutput,
|
|
179
|
+
startedAt: toolStartedAt,
|
|
180
|
+
status: "ok",
|
|
181
|
+
traceStart,
|
|
182
|
+
}));
|
|
183
|
+
stages.push({ name: "text-metrics", output: toolOutput, status: "ok" });
|
|
184
|
+
const finalPrompt = `Stage one phrase: ${call1Output.phrase}\n` +
|
|
185
|
+
`Stage two keywords: ${JSON.stringify(call2Output.keywords)}\n` +
|
|
186
|
+
`Text metrics: ${JSON.stringify(toolOutput)}`;
|
|
187
|
+
const finalOutput = await runLlmObjectStage({
|
|
188
|
+
aiService: params.aiService,
|
|
189
|
+
childSpans,
|
|
190
|
+
exportTrace: params.exportTrace,
|
|
191
|
+
name: "final",
|
|
192
|
+
outputSchema: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_FINAL_OUTPUT_SCHEMA,
|
|
193
|
+
prompt: finalPrompt,
|
|
194
|
+
schema: testMultiStageSchemas_1.obsTestMultiStageFinalSchema,
|
|
195
|
+
schemaDescription: "Combined sentence plus echoed phrase, keywords, and metrics",
|
|
196
|
+
schemaName: testMultiStageSchemas_1.OBS_TEST_MULTI_STAGE_FINAL_SCHEMA_NAME,
|
|
197
|
+
stages,
|
|
198
|
+
systemPrompt: prompts_1.OBS_TEST_MULTI_STAGE_FINAL_SYSTEM,
|
|
199
|
+
traceStart,
|
|
200
|
+
userId: params.userId,
|
|
201
|
+
workflowInput: params.input,
|
|
202
|
+
});
|
|
203
|
+
const trace = buildTrace({
|
|
204
|
+
childSpans,
|
|
205
|
+
input: params.input,
|
|
206
|
+
output: finalOutput,
|
|
207
|
+
status: "ok",
|
|
208
|
+
traceStart,
|
|
209
|
+
userId: params.userId,
|
|
210
|
+
});
|
|
211
|
+
const traceId = await params.exportTrace(trace);
|
|
212
|
+
return {
|
|
213
|
+
output: finalOutput,
|
|
214
|
+
stages,
|
|
215
|
+
traceId,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
exports.runTestMultiStageWorkflow = runTestMultiStageWorkflow;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type AnyTerrenoAccess } from "@terreno/api";
|
|
2
|
+
export type ObservabilityCapability = "datasets" | "experiments" | "prompts" | "reviewQueue" | "scores" | "traces";
|
|
3
|
+
export type ControlPrimary = "langfuse" | "local";
|
|
4
|
+
export interface ObservabilityControlConfig {
|
|
5
|
+
datasets: ControlPrimary;
|
|
6
|
+
experiments: ControlPrimary;
|
|
7
|
+
prompts: ControlPrimary;
|
|
8
|
+
reviewQueue: "local";
|
|
9
|
+
}
|
|
10
|
+
export type SpanKind = "AGENT" | "CHAIN" | "EVALUATOR" | "LLM" | "RETRIEVER" | "TOOL";
|
|
11
|
+
export interface SpanRecord {
|
|
12
|
+
durationMs?: number;
|
|
13
|
+
endedAt?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
id: string;
|
|
16
|
+
input?: unknown;
|
|
17
|
+
kind: SpanKind;
|
|
18
|
+
name: string;
|
|
19
|
+
output?: unknown;
|
|
20
|
+
parentSpanId?: string;
|
|
21
|
+
sensitive?: boolean;
|
|
22
|
+
startOffsetMs?: number;
|
|
23
|
+
startedAt: string;
|
|
24
|
+
status: "error" | "ok";
|
|
25
|
+
usage?: {
|
|
26
|
+
costUsd?: number;
|
|
27
|
+
inputTokens?: number;
|
|
28
|
+
model?: string;
|
|
29
|
+
outputTokens?: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface TraceRecord {
|
|
33
|
+
endedAt?: string;
|
|
34
|
+
errorSummary?: string;
|
|
35
|
+
flaggedForDataset?: boolean;
|
|
36
|
+
id: string;
|
|
37
|
+
input?: unknown;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
name: string;
|
|
40
|
+
output?: unknown;
|
|
41
|
+
prompts: {
|
|
42
|
+
label?: string;
|
|
43
|
+
name: string;
|
|
44
|
+
version: number;
|
|
45
|
+
}[];
|
|
46
|
+
sensitive: boolean;
|
|
47
|
+
sessionId?: string;
|
|
48
|
+
spans: SpanRecord[];
|
|
49
|
+
startedAt: string;
|
|
50
|
+
status: "error" | "ok";
|
|
51
|
+
usage?: {
|
|
52
|
+
costUsd?: number;
|
|
53
|
+
inputTokens?: number;
|
|
54
|
+
model?: string;
|
|
55
|
+
outputTokens?: number;
|
|
56
|
+
};
|
|
57
|
+
userId?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ScoreRecord {
|
|
60
|
+
comment?: string;
|
|
61
|
+
confidence?: number;
|
|
62
|
+
dataType: "boolean" | "categorical" | "numeric";
|
|
63
|
+
evaluatorId?: string;
|
|
64
|
+
name: string;
|
|
65
|
+
source: "code" | "human" | "llm-judge" | "user-feedback";
|
|
66
|
+
spanId?: string;
|
|
67
|
+
traceId: string;
|
|
68
|
+
value: boolean | number | string;
|
|
69
|
+
}
|
|
70
|
+
export interface PromptVersionRef {
|
|
71
|
+
body: string;
|
|
72
|
+
label?: string;
|
|
73
|
+
name: string;
|
|
74
|
+
sensitive?: boolean;
|
|
75
|
+
version: number;
|
|
76
|
+
}
|
|
77
|
+
export interface PromptRegistry {
|
|
78
|
+
get: (args: {
|
|
79
|
+
label?: string;
|
|
80
|
+
name: string;
|
|
81
|
+
}) => Promise<PromptVersionRef | undefined>;
|
|
82
|
+
}
|
|
83
|
+
export interface TraceExportResult {
|
|
84
|
+
id?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface TraceSink {
|
|
87
|
+
export: (trace: TraceRecord) => Promise<TraceExportResult | undefined>;
|
|
88
|
+
}
|
|
89
|
+
export interface ScoreSink {
|
|
90
|
+
export: (score: ScoreRecord) => Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
export interface DatasetStore {
|
|
93
|
+
id?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface ExperimentRunner {
|
|
96
|
+
id?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface ReviewQueue {
|
|
99
|
+
id?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ObservabilityPlugin {
|
|
102
|
+
readonly capabilities: ReadonlySet<ObservabilityCapability>;
|
|
103
|
+
readonly id: string;
|
|
104
|
+
datasetStore?: DatasetStore | import("./local/datasetStore").LocalDatasetStore;
|
|
105
|
+
experimentRunner?: ExperimentRunner | import("./local/experimentRunner").LocalExperimentRunner;
|
|
106
|
+
promptRegistry?: PromptRegistry;
|
|
107
|
+
reviewQueue?: ReviewQueue;
|
|
108
|
+
scoreSink?: ScoreSink;
|
|
109
|
+
traceSink?: TraceSink;
|
|
110
|
+
}
|
|
111
|
+
export interface ModelPrice {
|
|
112
|
+
inputPerMTok: number;
|
|
113
|
+
outputPerMTok: number;
|
|
114
|
+
}
|
|
115
|
+
export interface ObservabilityGenerateClient {
|
|
116
|
+
readonly modelId: string;
|
|
117
|
+
generateJsonObject: <OBJECT>(options: {
|
|
118
|
+
prompt: string;
|
|
119
|
+
promptName?: string;
|
|
120
|
+
schema: import("ai").FlexibleSchema<OBJECT>;
|
|
121
|
+
schemaDescription?: string;
|
|
122
|
+
schemaName?: string;
|
|
123
|
+
skipTrace?: boolean;
|
|
124
|
+
systemPrompt?: string;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
userId?: import("mongoose").Types.ObjectId;
|
|
127
|
+
}) => Promise<OBJECT>;
|
|
128
|
+
generateText: (options: {
|
|
129
|
+
prompt: string;
|
|
130
|
+
skipTrace?: boolean;
|
|
131
|
+
systemPrompt?: string;
|
|
132
|
+
temperature?: number;
|
|
133
|
+
userId?: import("mongoose").Types.ObjectId;
|
|
134
|
+
}) => Promise<string>;
|
|
135
|
+
}
|
|
136
|
+
/** Selects an AI client for a specific model id (used by experiment `modelOverride`). */
|
|
137
|
+
export type ObservabilityAiServiceFactory = (modelId: string) => ObservabilityGenerateClient | undefined;
|
|
138
|
+
export type ObservabilityRequestAiServiceFactory = (params: {
|
|
139
|
+
apiKey?: string;
|
|
140
|
+
modelId?: string;
|
|
141
|
+
}) => ObservabilityGenerateClient | undefined;
|
|
142
|
+
export interface ObservabilityAppOptions {
|
|
143
|
+
accessControl?: AnyTerrenoAccess;
|
|
144
|
+
aiService?: ObservabilityGenerateClient;
|
|
145
|
+
aiServiceFactory?: ObservabilityAiServiceFactory;
|
|
146
|
+
control?: {
|
|
147
|
+
datasets?: ControlPrimary;
|
|
148
|
+
experiments?: ControlPrimary;
|
|
149
|
+
prompts?: ControlPrimary;
|
|
150
|
+
reviewQueue?: ControlPrimary;
|
|
151
|
+
};
|
|
152
|
+
plugins: ObservabilityPlugin[];
|
|
153
|
+
priceMap?: Record<string, ModelPrice>;
|
|
154
|
+
requestAiServiceFactory?: ObservabilityRequestAiServiceFactory;
|
|
155
|
+
sampleRate?: number;
|
|
156
|
+
}
|
|
157
|
+
export declare const DEFAULT_OBSERVABILITY_CONTROL: ObservabilityControlConfig;
|
|
158
|
+
export declare const resolveObservabilityControl: (options: ObservabilityAppOptions) => ObservabilityControlConfig;
|
|
159
|
+
export declare const validateObservabilityConfig: (options: ObservabilityAppOptions) => ObservabilityControlConfig;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateObservabilityConfig = exports.resolveObservabilityControl = exports.DEFAULT_OBSERVABILITY_CONTROL = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const CONTROL_CAPABILITY = {
|
|
6
|
+
datasets: "datasets",
|
|
7
|
+
experiments: "experiments",
|
|
8
|
+
prompts: "prompts",
|
|
9
|
+
reviewQueue: "reviewQueue",
|
|
10
|
+
};
|
|
11
|
+
const CONTROL_STORE = {
|
|
12
|
+
datasets: "datasetStore",
|
|
13
|
+
experiments: "experimentRunner",
|
|
14
|
+
prompts: "promptRegistry",
|
|
15
|
+
reviewQueue: "reviewQueue",
|
|
16
|
+
};
|
|
17
|
+
exports.DEFAULT_OBSERVABILITY_CONTROL = {
|
|
18
|
+
datasets: "local",
|
|
19
|
+
experiments: "local",
|
|
20
|
+
prompts: "local",
|
|
21
|
+
reviewQueue: "local",
|
|
22
|
+
};
|
|
23
|
+
const resolveObservabilityControl = (options) => {
|
|
24
|
+
return {
|
|
25
|
+
datasets: options.control?.datasets ?? exports.DEFAULT_OBSERVABILITY_CONTROL.datasets,
|
|
26
|
+
experiments: options.control?.experiments ?? exports.DEFAULT_OBSERVABILITY_CONTROL.experiments,
|
|
27
|
+
prompts: options.control?.prompts ?? exports.DEFAULT_OBSERVABILITY_CONTROL.prompts,
|
|
28
|
+
reviewQueue: "local",
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.resolveObservabilityControl = resolveObservabilityControl;
|
|
32
|
+
const validateObservabilityConfig = (options) => {
|
|
33
|
+
const fail = (message) => {
|
|
34
|
+
api_1.logger.error(message);
|
|
35
|
+
throw new api_1.APIError({ status: 500, title: message });
|
|
36
|
+
};
|
|
37
|
+
if (options.control?.reviewQueue && options.control.reviewQueue !== "local") {
|
|
38
|
+
return fail("Observability reviewQueue.primary must be local");
|
|
39
|
+
}
|
|
40
|
+
const datasetsPrimary = options.control?.datasets ?? exports.DEFAULT_OBSERVABILITY_CONTROL.datasets;
|
|
41
|
+
const experimentsPrimary = options.control?.experiments ?? exports.DEFAULT_OBSERVABILITY_CONTROL.experiments;
|
|
42
|
+
if (experimentsPrimary !== datasetsPrimary) {
|
|
43
|
+
return fail("Observability experiments.primary must equal datasets.primary");
|
|
44
|
+
}
|
|
45
|
+
const control = (0, exports.resolveObservabilityControl)(options);
|
|
46
|
+
const primaries = [
|
|
47
|
+
"prompts",
|
|
48
|
+
"datasets",
|
|
49
|
+
"experiments",
|
|
50
|
+
"reviewQueue",
|
|
51
|
+
];
|
|
52
|
+
for (const key of primaries) {
|
|
53
|
+
const primaryId = control[key];
|
|
54
|
+
const capability = CONTROL_CAPABILITY[key];
|
|
55
|
+
const storeKey = CONTROL_STORE[key];
|
|
56
|
+
const plugin = options.plugins.find((candidate) => {
|
|
57
|
+
return (candidate.id === primaryId &&
|
|
58
|
+
candidate.capabilities.has(capability) &&
|
|
59
|
+
candidate[storeKey] !== undefined);
|
|
60
|
+
});
|
|
61
|
+
if (!plugin) {
|
|
62
|
+
return fail(`Observability ${key} primary "${primaryId}" has no plugin`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return control;
|
|
66
|
+
};
|
|
67
|
+
exports.validateObservabilityConfig = validateObservabilityConfig;
|
package/dist/routes/files.js
CHANGED
|
@@ -19,6 +19,12 @@ const ALLOWED_MIME_TYPES = new Set([
|
|
|
19
19
|
"application/json",
|
|
20
20
|
]);
|
|
21
21
|
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
|
22
|
+
/** The `*gcsKey` wildcard as a key: Express 5 passes it as its path segments. */
|
|
23
|
+
const gcsKeyParam = (req) => {
|
|
24
|
+
const param = req.params.gcsKey ?? "";
|
|
25
|
+
return Array.isArray(param) ? param.join("/") : param;
|
|
26
|
+
};
|
|
27
|
+
const requestUserId = (req) => req.user?._id;
|
|
22
28
|
const addFileRoutes = (router, options) => {
|
|
23
29
|
const { fileStorageService, maxFileSize = DEFAULT_MAX_FILE_SIZE } = options;
|
|
24
30
|
const upload = (0, multer_1.default)({
|
|
@@ -42,6 +48,7 @@ const addFileRoutes = (router, options) => {
|
|
|
42
48
|
.withResponse(200, {
|
|
43
49
|
filename: { type: "string" },
|
|
44
50
|
gcsKey: { type: "string" },
|
|
51
|
+
id: { type: "string" },
|
|
45
52
|
mimeType: { type: "string" },
|
|
46
53
|
size: { type: "number" },
|
|
47
54
|
url: { type: "string" },
|
|
@@ -50,8 +57,7 @@ const addFileRoutes = (router, options) => {
|
|
|
50
57
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
51
58
|
await (0, fileUploadsGate_1.assertFileUploadsEnabled)(req, options.fileUploadsEnabled);
|
|
52
59
|
const file = req.file;
|
|
53
|
-
const userId = req
|
|
54
|
-
?._id;
|
|
60
|
+
const userId = requestUserId(req);
|
|
55
61
|
if (!file) {
|
|
56
62
|
throw new api_1.APIError({ status: 400, title: "No file provided" });
|
|
57
63
|
}
|
|
@@ -64,6 +70,7 @@ const addFileRoutes = (router, options) => {
|
|
|
64
70
|
return res.json({ data: result });
|
|
65
71
|
}));
|
|
66
72
|
router.get("/files/*gcsKey", [
|
|
73
|
+
(0, api_1.authenticateMiddleware)(),
|
|
67
74
|
(0, api_1.createOpenApiBuilder)(options.openApiOptions ?? {})
|
|
68
75
|
.withTags(["files"])
|
|
69
76
|
.withSummary("Get file URL")
|
|
@@ -71,8 +78,13 @@ const addFileRoutes = (router, options) => {
|
|
|
71
78
|
.withResponse(200, { url: { type: "string" } })
|
|
72
79
|
.build(),
|
|
73
80
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
74
|
-
const gcsKey = req
|
|
75
|
-
|
|
81
|
+
const gcsKey = gcsKeyParam(req);
|
|
82
|
+
// Another user's file is "not found", so keys cannot be probed.
|
|
83
|
+
const attachment = await fileAttachment_1.FileAttachment.findOneOrNone({
|
|
84
|
+
deleted: false,
|
|
85
|
+
gcsKey,
|
|
86
|
+
userId: requestUserId(req),
|
|
87
|
+
});
|
|
76
88
|
if (!attachment) {
|
|
77
89
|
throw new api_1.APIError({ status: 404, title: "File not found" });
|
|
78
90
|
}
|
|
@@ -88,9 +100,8 @@ const addFileRoutes = (router, options) => {
|
|
|
88
100
|
.withResponse(200, { success: { type: "boolean" } })
|
|
89
101
|
.build(),
|
|
90
102
|
], (0, api_1.asyncHandler)(async (req, res) => {
|
|
91
|
-
const gcsKey = req
|
|
92
|
-
const userId = req
|
|
93
|
-
?._id;
|
|
103
|
+
const gcsKey = gcsKeyParam(req);
|
|
104
|
+
const userId = requestUserId(req);
|
|
94
105
|
const attachment = await fileAttachment_1.FileAttachment.findOneOrNone({ deleted: false, gcsKey });
|
|
95
106
|
if (!attachment) {
|
|
96
107
|
throw new api_1.APIError({ status: 404, title: "File not found" });
|