@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,78 @@
|
|
|
1
|
+
import {createdUpdatedPlugin, findExactlyOne, findOneOrNone, isDeletedPlugin} from "@terreno/api";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
|
|
4
|
+
import type {AIDatasetDocument, AIDatasetModel, AIDatasetSchema} from "../types";
|
|
5
|
+
|
|
6
|
+
const columnSchema = new mongoose.Schema(
|
|
7
|
+
{
|
|
8
|
+
name: {
|
|
9
|
+
description: "Column name used by chart and table blocks",
|
|
10
|
+
required: true,
|
|
11
|
+
type: String,
|
|
12
|
+
},
|
|
13
|
+
type: {
|
|
14
|
+
description: "Cell type: string, number, or date",
|
|
15
|
+
enum: ["string", "number", "date"],
|
|
16
|
+
required: true,
|
|
17
|
+
type: String,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{_id: false}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const aiDatasetSchema: AIDatasetSchema = new mongoose.Schema(
|
|
24
|
+
{
|
|
25
|
+
columns: {
|
|
26
|
+
description: "Named columns and their cell types, at most 12",
|
|
27
|
+
required: true,
|
|
28
|
+
type: [columnSchema],
|
|
29
|
+
},
|
|
30
|
+
expiresAt: {
|
|
31
|
+
description: "When this dataset expires. Absent datasets are kept.",
|
|
32
|
+
type: Date,
|
|
33
|
+
},
|
|
34
|
+
historyId: {
|
|
35
|
+
description: "The conversation whose tool stored these rows",
|
|
36
|
+
index: true,
|
|
37
|
+
ref: "GptHistory",
|
|
38
|
+
required: true,
|
|
39
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
+
},
|
|
41
|
+
rowCount: {
|
|
42
|
+
description: "How many rows were stored",
|
|
43
|
+
required: true,
|
|
44
|
+
type: Number,
|
|
45
|
+
},
|
|
46
|
+
rows: {
|
|
47
|
+
description: "Table cells, one array per row, aligned with columns",
|
|
48
|
+
required: true,
|
|
49
|
+
type: mongoose.Schema.Types.Mixed,
|
|
50
|
+
},
|
|
51
|
+
userId: {
|
|
52
|
+
description: "The user who ran the tool that stored these rows",
|
|
53
|
+
index: true,
|
|
54
|
+
ref: "User",
|
|
55
|
+
required: true,
|
|
56
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{strict: "throw", toJSON: {virtuals: true}, toObject: {virtuals: true}}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
aiDatasetSchema.plugin(createdUpdatedPlugin);
|
|
63
|
+
aiDatasetSchema.plugin(isDeletedPlugin);
|
|
64
|
+
aiDatasetSchema.plugin(findOneOrNone);
|
|
65
|
+
aiDatasetSchema.plugin(findExactlyOne);
|
|
66
|
+
|
|
67
|
+
// Documents with no expiresAt are kept. expireAfterSeconds 0 deletes at the stored instant.
|
|
68
|
+
aiDatasetSchema.index({expiresAt: 1}, {expireAfterSeconds: 0});
|
|
69
|
+
|
|
70
|
+
// Virtual ownerId alias so Permissions.IsOwner works with userId field
|
|
71
|
+
aiDatasetSchema.virtual("ownerId").get(function (this: AIDatasetDocument) {
|
|
72
|
+
return this.userId;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const AIDataset = mongoose.model<AIDatasetDocument, AIDatasetModel>(
|
|
76
|
+
"AIDataset",
|
|
77
|
+
aiDatasetSchema
|
|
78
|
+
);
|
|
@@ -31,7 +31,7 @@ describe("AIRequest Model", () => {
|
|
|
31
31
|
it("should create a request with all fields", async () => {
|
|
32
32
|
const userId = new mongoose.Types.ObjectId();
|
|
33
33
|
const request = await AIRequest.create({
|
|
34
|
-
aiModel: "gemini-
|
|
34
|
+
aiModel: "gemini-3.8-flash",
|
|
35
35
|
error: undefined,
|
|
36
36
|
metadata: {key: "value"},
|
|
37
37
|
prompt: "Translate this",
|
|
@@ -42,7 +42,7 @@ describe("AIRequest Model", () => {
|
|
|
42
42
|
userId,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
expect(request.aiModel).toBe("gemini-
|
|
45
|
+
expect(request.aiModel).toBe("gemini-3.8-flash");
|
|
46
46
|
expect(request.requestType).toBe("translation");
|
|
47
47
|
expect(request.response).toBe("Translated text");
|
|
48
48
|
expect(request.responseTime).toBe(1500);
|
package/src/models/aiRequest.ts
CHANGED
|
@@ -27,7 +27,8 @@ const aiRequestSchema = new mongoose.Schema<AIRequestDocument, AIRequestModel>(
|
|
|
27
27
|
},
|
|
28
28
|
prompt: {description: "The input prompt sent to the AI model", required: true, type: String},
|
|
29
29
|
requestType: {
|
|
30
|
-
description:
|
|
30
|
+
description:
|
|
31
|
+
"The type of AI request (general, translation, summarization, ui_action, and the other default types)",
|
|
31
32
|
required: true,
|
|
32
33
|
type: String,
|
|
33
34
|
},
|
|
@@ -210,6 +210,162 @@ describe("GptHistory Model", () => {
|
|
|
210
210
|
});
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
+
describe("asks", () => {
|
|
214
|
+
const planAsk = {
|
|
215
|
+
options: [
|
|
216
|
+
{id: "starter", label: "Starter"},
|
|
217
|
+
{id: "team", label: "Team"},
|
|
218
|
+
],
|
|
219
|
+
prompt: "Which plan should I set up?",
|
|
220
|
+
select: "one",
|
|
221
|
+
};
|
|
222
|
+
const pendingAsk = {
|
|
223
|
+
created: new Date("2026-09-27T12:00:00.000Z"),
|
|
224
|
+
input: planAsk,
|
|
225
|
+
kind: "choice",
|
|
226
|
+
promptIndex: 1,
|
|
227
|
+
responseMessages: [
|
|
228
|
+
{
|
|
229
|
+
content: [
|
|
230
|
+
{input: {}, toolCallId: "call_lookup", toolName: "lookupPlans", type: "tool-call"},
|
|
231
|
+
{input: planAsk, toolCallId: "call_plan", toolName: "ask_choice", type: "tool-call"},
|
|
232
|
+
],
|
|
233
|
+
role: "assistant",
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
simple: {
|
|
237
|
+
buttons: [
|
|
238
|
+
{
|
|
239
|
+
id: "option:starter",
|
|
240
|
+
label: "Starter",
|
|
241
|
+
response: {action: "accept", content: {selected: ["starter"]}},
|
|
242
|
+
style: "default",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: "option:team",
|
|
246
|
+
label: "Team",
|
|
247
|
+
response: {action: "accept", content: {selected: ["team"]}},
|
|
248
|
+
style: "default",
|
|
249
|
+
},
|
|
250
|
+
{id: "skip", label: "Skip", response: {action: "decline"}, style: "cancel"},
|
|
251
|
+
],
|
|
252
|
+
handoff: false,
|
|
253
|
+
kind: "choice",
|
|
254
|
+
text: "Which plan should I set up?",
|
|
255
|
+
toolCallId: "call_plan",
|
|
256
|
+
},
|
|
257
|
+
toolCallId: "call_plan",
|
|
258
|
+
};
|
|
259
|
+
const askRow = {
|
|
260
|
+
args: planAsk,
|
|
261
|
+
ask: {kind: "choice", status: "pending"},
|
|
262
|
+
text: "Tool call: ask_choice",
|
|
263
|
+
toolCallId: "call_plan",
|
|
264
|
+
toolName: "ask_choice",
|
|
265
|
+
type: "tool-call",
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
it("loads a history saved before asks existed", async () => {
|
|
269
|
+
const userId = new mongoose.Types.ObjectId();
|
|
270
|
+
const {insertedId} = await GptHistory.collection.insertOne({
|
|
271
|
+
created: new Date("2026-01-05T09:00:00.000Z"),
|
|
272
|
+
deleted: false,
|
|
273
|
+
prompts: [
|
|
274
|
+
{text: "What time is it?", type: "user"},
|
|
275
|
+
{
|
|
276
|
+
args: {},
|
|
277
|
+
text: "Tool call: get_time",
|
|
278
|
+
toolCallId: "c1",
|
|
279
|
+
toolName: "get_time",
|
|
280
|
+
type: "tool-call",
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
updated: new Date("2026-01-05T09:00:00.000Z"),
|
|
284
|
+
userId,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const history = await GptHistory.findById(insertedId);
|
|
288
|
+
|
|
289
|
+
expect(history?.pendingAsk).toBeUndefined();
|
|
290
|
+
expect(history?.prompts[1].ask).toBeUndefined();
|
|
291
|
+
expect(history?.prompts[1].toolName).toBe("get_time");
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("stores a pending ask and its row, keeping empty objects in responseMessages", async () => {
|
|
295
|
+
const userId = new mongoose.Types.ObjectId();
|
|
296
|
+
const history = await GptHistory.create({
|
|
297
|
+
pendingAsk,
|
|
298
|
+
prompts: [{text: "Set up my workspace", type: "user"}, askRow],
|
|
299
|
+
userId,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const stored = await GptHistory.collection.findOne({_id: history._id});
|
|
303
|
+
|
|
304
|
+
expect(stored?.pendingAsk).toEqual(pendingAsk);
|
|
305
|
+
expect(stored?.prompts[1].ask).toEqual({kind: "choice", status: "pending"});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("keeps empty objects in responseMessages when a pending ask replaces another", async () => {
|
|
309
|
+
const userId = new mongoose.Types.ObjectId();
|
|
310
|
+
const history = await GptHistory.create({prompts: [], userId});
|
|
311
|
+
|
|
312
|
+
history.pendingAsk = pendingAsk as unknown as NonNullable<typeof history.pendingAsk>;
|
|
313
|
+
await history.save();
|
|
314
|
+
|
|
315
|
+
const stored = await GptHistory.collection.findOne({_id: history._id});
|
|
316
|
+
expect(stored?.pendingAsk.responseMessages[0].content[0]).toEqual({
|
|
317
|
+
input: {},
|
|
318
|
+
toolCallId: "call_lookup",
|
|
319
|
+
toolName: "lookupPlans",
|
|
320
|
+
type: "tool-call",
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it.each([
|
|
325
|
+
{
|
|
326
|
+
expected: 'at path "pendingAsk" because of "StrictModeError"',
|
|
327
|
+
field: "pendingAsk",
|
|
328
|
+
history: {pendingAsk: {...pendingAsk, note: "extra"}},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
expected: 'at path "ask" because of "StrictModeError"',
|
|
332
|
+
field: "prompts.ask",
|
|
333
|
+
history: {prompts: [{...askRow, ask: {kind: "choice", note: "extra", status: "pending"}}]},
|
|
334
|
+
},
|
|
335
|
+
])("rejects an unknown key in $field", async ({expected, history}) => {
|
|
336
|
+
await expect(
|
|
337
|
+
GptHistory.create({...history, userId: new mongoose.Types.ObjectId()})
|
|
338
|
+
).rejects.toThrow(expected);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it.each([
|
|
342
|
+
{
|
|
343
|
+
expected: "`bogus` is not a valid enum value for path `kind`",
|
|
344
|
+
history: {pendingAsk: {...pendingAsk, kind: "bogus"}},
|
|
345
|
+
label: "an unknown pending ask kind",
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
expected: "`bogus` is not a valid enum value for path `kind`",
|
|
349
|
+
history: {prompts: [{...askRow, ask: {kind: "bogus", status: "pending"}}]},
|
|
350
|
+
label: "an unknown row ask kind",
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
expected: "`done` is not a valid enum value for path `status`",
|
|
354
|
+
history: {prompts: [{...askRow, ask: {kind: "choice", status: "done"}}]},
|
|
355
|
+
label: "an unknown row ask status",
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
expected: "Path `toolCallId` is required.",
|
|
359
|
+
history: {pendingAsk: {...pendingAsk, toolCallId: undefined}},
|
|
360
|
+
label: "a pending ask without a toolCallId",
|
|
361
|
+
},
|
|
362
|
+
])("rejects $label", async ({expected, history}) => {
|
|
363
|
+
await expect(
|
|
364
|
+
GptHistory.create({...history, userId: new mongoose.Types.ObjectId()})
|
|
365
|
+
).rejects.toThrow(expected);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
213
369
|
describe("soft delete", () => {
|
|
214
370
|
it("should filter out deleted records by default", async () => {
|
|
215
371
|
const userId = new mongoose.Types.ObjectId();
|
package/src/models/gptHistory.ts
CHANGED
|
@@ -1,11 +1,94 @@
|
|
|
1
1
|
import {createdUpdatedPlugin, findExactlyOne, findOneOrNone, isDeletedPlugin} from "@terreno/api";
|
|
2
|
+
import {ASK_KINDS} from "@terreno/blocks";
|
|
2
3
|
import mongoose from "mongoose";
|
|
3
4
|
|
|
4
|
-
import type {GptHistoryDocument, GptHistoryModel} from "../types";
|
|
5
|
+
import type {AskOrigin, GptHistoryAskStatus, GptHistoryDocument, GptHistoryModel} from "../types";
|
|
6
|
+
|
|
7
|
+
const ASK_STATUSES: GptHistoryAskStatus[] = ["pending", "answered", "cancelled"];
|
|
8
|
+
const ASK_ORIGINS: AskOrigin[] = ["approval"];
|
|
9
|
+
|
|
10
|
+
const askOriginField = {
|
|
11
|
+
description:
|
|
12
|
+
"approval when the server asked before running a host tool that needs approval; unset when the model asked",
|
|
13
|
+
enum: ASK_ORIGINS,
|
|
14
|
+
type: String,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const promptAskSchema = new mongoose.Schema(
|
|
18
|
+
{
|
|
19
|
+
kind: {
|
|
20
|
+
description: "Ask kind; the model asked with the tool ask_<kind>",
|
|
21
|
+
enum: ASK_KINDS,
|
|
22
|
+
required: true,
|
|
23
|
+
type: String,
|
|
24
|
+
},
|
|
25
|
+
origin: askOriginField,
|
|
26
|
+
status: {
|
|
27
|
+
description:
|
|
28
|
+
"pending while the user can answer; answered or cancelled once the ask is resolved",
|
|
29
|
+
enum: ASK_STATUSES,
|
|
30
|
+
required: true,
|
|
31
|
+
type: String,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{_id: false, strict: "throw"}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const pendingAskSchema = new mongoose.Schema(
|
|
38
|
+
{
|
|
39
|
+
approvalId: {
|
|
40
|
+
description: "AI SDK approval request an approval ask answers; the same as toolCallId",
|
|
41
|
+
type: String,
|
|
42
|
+
},
|
|
43
|
+
created: {description: "When the model asked", required: true, type: Date},
|
|
44
|
+
input: {
|
|
45
|
+
description: "The validated ask input the model sent",
|
|
46
|
+
required: true,
|
|
47
|
+
type: mongoose.Schema.Types.Mixed,
|
|
48
|
+
},
|
|
49
|
+
kind: {
|
|
50
|
+
description: "Ask kind; the model asked with the tool ask_<kind>",
|
|
51
|
+
enum: ASK_KINDS,
|
|
52
|
+
required: true,
|
|
53
|
+
type: String,
|
|
54
|
+
},
|
|
55
|
+
origin: askOriginField,
|
|
56
|
+
promptIndex: {
|
|
57
|
+
description:
|
|
58
|
+
"Number of leading prompts that form the paused turn's history, replayed before responseMessages on resume",
|
|
59
|
+
required: true,
|
|
60
|
+
type: Number,
|
|
61
|
+
},
|
|
62
|
+
responseMessages: {
|
|
63
|
+
description:
|
|
64
|
+
"AI SDK response messages of the paused turn, replayed verbatim with the answer on resume",
|
|
65
|
+
required: true,
|
|
66
|
+
type: mongoose.Schema.Types.Mixed,
|
|
67
|
+
},
|
|
68
|
+
simple: {
|
|
69
|
+
description:
|
|
70
|
+
"Simple card (short text and up to three answer buttons) made when the ask was made",
|
|
71
|
+
required: true,
|
|
72
|
+
type: mongoose.Schema.Types.Mixed,
|
|
73
|
+
},
|
|
74
|
+
toolCallId: {
|
|
75
|
+
description: "Tool call id of the ask; an answer must name it",
|
|
76
|
+
required: true,
|
|
77
|
+
type: String,
|
|
78
|
+
},
|
|
79
|
+
toolName: {description: "Host tool an approval ask asks to run", type: String},
|
|
80
|
+
},
|
|
81
|
+
// `minimize` would drop empty objects the AI SDK requires on replay, such as a tool call's `input: {}`.
|
|
82
|
+
{_id: false, minimize: false, strict: "throw"}
|
|
83
|
+
);
|
|
5
84
|
|
|
6
85
|
const contentPartSchema = new mongoose.Schema(
|
|
7
86
|
{
|
|
8
87
|
filename: {description: "Original filename of the attached file", type: String},
|
|
88
|
+
gcsKey: {
|
|
89
|
+
description: "Durable storage key for an attachment uploaded through FileStorageService",
|
|
90
|
+
type: String,
|
|
91
|
+
},
|
|
9
92
|
mimeType: {description: "MIME type of the content part", type: String},
|
|
10
93
|
text: {description: "Text content of this part", type: String},
|
|
11
94
|
type: {
|
|
@@ -22,6 +105,10 @@ const contentPartSchema = new mongoose.Schema(
|
|
|
22
105
|
const gptHistoryPromptSchema = new mongoose.Schema(
|
|
23
106
|
{
|
|
24
107
|
args: {description: "Arguments passed to a tool call", type: mongoose.Schema.Types.Mixed},
|
|
108
|
+
ask: {
|
|
109
|
+
description: "Set on tool-call rows where the model asked the user a question",
|
|
110
|
+
type: promptAskSchema,
|
|
111
|
+
},
|
|
25
112
|
content: {description: "Multipart content attached to this prompt", type: [contentPartSchema]},
|
|
26
113
|
model: {description: "AI model identifier used for this prompt", type: String},
|
|
27
114
|
rating: {
|
|
@@ -30,12 +117,22 @@ const gptHistoryPromptSchema = new mongoose.Schema(
|
|
|
30
117
|
type: String,
|
|
31
118
|
},
|
|
32
119
|
result: {description: "Result returned from a tool call", type: mongoose.Schema.Types.Mixed},
|
|
120
|
+
status: {
|
|
121
|
+
description:
|
|
122
|
+
"Lifecycle of an assistant reply: streaming while partial text is persisted, then complete or error",
|
|
123
|
+
enum: ["streaming", "complete", "error"],
|
|
124
|
+
type: String,
|
|
125
|
+
},
|
|
126
|
+
streamId: {
|
|
127
|
+
description: "Identifier of the /gpt/prompt reply, used to resume an in-flight stream",
|
|
128
|
+
type: String,
|
|
129
|
+
},
|
|
33
130
|
text: {
|
|
34
131
|
default: "",
|
|
35
132
|
description: "Text content of the prompt or response",
|
|
36
|
-
// Image-only responses carry their payload in content,
|
|
37
|
-
required: function (this: {content?: unknown[]}): boolean {
|
|
38
|
-
return !this.content?.length;
|
|
133
|
+
// Image-only responses carry their payload in content, and streaming replies start empty
|
|
134
|
+
required: function (this: {content?: unknown[]; status?: string}): boolean {
|
|
135
|
+
return !this.content?.length && !this.status;
|
|
39
136
|
},
|
|
40
137
|
type: String,
|
|
41
138
|
},
|
|
@@ -56,6 +153,11 @@ const gptHistoryPromptSchema = new mongoose.Schema(
|
|
|
56
153
|
|
|
57
154
|
const gptHistorySchema = new mongoose.Schema<GptHistoryDocument, GptHistoryModel>(
|
|
58
155
|
{
|
|
156
|
+
pendingAsk: {
|
|
157
|
+
description:
|
|
158
|
+
"The ask this conversation is waiting on; cleared when the user answers or the ask is cancelled",
|
|
159
|
+
type: pendingAskSchema,
|
|
160
|
+
},
|
|
59
161
|
projectId: {
|
|
60
162
|
description: "Project this conversation belongs to",
|
|
61
163
|
index: true,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {AI_OBSERVABILITY_GROUP, observabilityAdminScreens} from "./adminScreens";
|
|
4
|
+
|
|
5
|
+
describe("observabilityAdminScreens", () => {
|
|
6
|
+
it("omits the review queue when the local plugin is off", () => {
|
|
7
|
+
const screens = observabilityAdminScreens({localOn: false});
|
|
8
|
+
expect(screens.map((screen) => screen.name)).toEqual([
|
|
9
|
+
"ai-prompts",
|
|
10
|
+
"ai-traces",
|
|
11
|
+
"ai-evaluators",
|
|
12
|
+
"ai-datasets",
|
|
13
|
+
"ai-experiments",
|
|
14
|
+
]);
|
|
15
|
+
expect(screens.every((screen) => screen.group === AI_OBSERVABILITY_GROUP)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("includes the review queue when the local plugin is on", () => {
|
|
19
|
+
const screens = observabilityAdminScreens({localOn: true});
|
|
20
|
+
expect(screens.map((screen) => screen.name)).toEqual([
|
|
21
|
+
"ai-prompts",
|
|
22
|
+
"ai-traces",
|
|
23
|
+
"ai-evaluators",
|
|
24
|
+
"ai-datasets",
|
|
25
|
+
"ai-experiments",
|
|
26
|
+
"ai-review",
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("declares list permissions per observability resource", () => {
|
|
31
|
+
const screens = observabilityAdminScreens({localOn: true});
|
|
32
|
+
expect(screens).toEqual([
|
|
33
|
+
{
|
|
34
|
+
adminAccess: {action: "list", resource: "aiPrompt"},
|
|
35
|
+
displayName: "Prompts",
|
|
36
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
37
|
+
name: "ai-prompts",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
adminAccess: {action: "list", resource: "aiTrace"},
|
|
41
|
+
displayName: "Traces",
|
|
42
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
43
|
+
name: "ai-traces",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
adminAccess: {action: "list", resource: "aiEvaluator"},
|
|
47
|
+
displayName: "Evaluators",
|
|
48
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
49
|
+
name: "ai-evaluators",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
adminAccess: {action: "list", resource: "aiDataset"},
|
|
53
|
+
displayName: "Datasets",
|
|
54
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
55
|
+
name: "ai-datasets",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
adminAccess: {action: "list", resource: "aiExperiment"},
|
|
59
|
+
displayName: "Experiments",
|
|
60
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
61
|
+
name: "ai-experiments",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
adminAccess: {action: "list", resource: "aiReview"},
|
|
65
|
+
displayName: "Review queue",
|
|
66
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
67
|
+
name: "ai-review",
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {AdminCustomScreen} from "@terreno/api";
|
|
2
|
+
|
|
3
|
+
export const AI_OBSERVABILITY_GROUP = "AI Observability";
|
|
4
|
+
|
|
5
|
+
const observabilityScreen = ({
|
|
6
|
+
displayName,
|
|
7
|
+
name,
|
|
8
|
+
resource,
|
|
9
|
+
}: {
|
|
10
|
+
displayName: string;
|
|
11
|
+
name: string;
|
|
12
|
+
resource: string;
|
|
13
|
+
}): AdminCustomScreen => ({
|
|
14
|
+
adminAccess: {action: "list", resource},
|
|
15
|
+
displayName,
|
|
16
|
+
group: AI_OBSERVABILITY_GROUP,
|
|
17
|
+
name,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const observabilityAdminScreens = ({localOn}: {localOn: boolean}): AdminCustomScreen[] => {
|
|
21
|
+
const screens: AdminCustomScreen[] = [
|
|
22
|
+
observabilityScreen({displayName: "Prompts", name: "ai-prompts", resource: "aiPrompt"}),
|
|
23
|
+
observabilityScreen({displayName: "Traces", name: "ai-traces", resource: "aiTrace"}),
|
|
24
|
+
observabilityScreen({
|
|
25
|
+
displayName: "Evaluators",
|
|
26
|
+
name: "ai-evaluators",
|
|
27
|
+
resource: "aiEvaluator",
|
|
28
|
+
}),
|
|
29
|
+
observabilityScreen({displayName: "Datasets", name: "ai-datasets", resource: "aiDataset"}),
|
|
30
|
+
observabilityScreen({
|
|
31
|
+
displayName: "Experiments",
|
|
32
|
+
name: "ai-experiments",
|
|
33
|
+
resource: "aiExperiment",
|
|
34
|
+
}),
|
|
35
|
+
];
|
|
36
|
+
if (localOn) {
|
|
37
|
+
screens.push(
|
|
38
|
+
observabilityScreen({displayName: "Review queue", name: "ai-review", resource: "aiReview"})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return screens;
|
|
42
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {describe, it} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
|
|
4
|
+
import {compileTemplate} from "./compileTemplate";
|
|
5
|
+
|
|
6
|
+
describe("compileTemplate", () => {
|
|
7
|
+
it("replaces {{var}} placeholders from the variable map", () => {
|
|
8
|
+
assert.equal(compileTemplate("Hello {{name}}", {name: "Ada"}), "Hello Ada");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("leaves unknown placeholders empty", () => {
|
|
12
|
+
assert.equal(compileTemplate("Hello {{name}}", {}), "Hello ");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const PLACEHOLDER = /\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}/g;
|
|
2
|
+
|
|
3
|
+
export const compileTemplate = (template: string, variables: Record<string, string>): string => {
|
|
4
|
+
return template.replace(PLACEHOLDER, (_match, key: string) => {
|
|
5
|
+
if (Object.hasOwn(variables, key)) {
|
|
6
|
+
return variables[key];
|
|
7
|
+
}
|
|
8
|
+
return "";
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {describe, it} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
flattenValidationPath,
|
|
6
|
+
parseDatasetCsvImport,
|
|
7
|
+
parseDatasetJsonImport,
|
|
8
|
+
} from "./datasetImport";
|
|
9
|
+
|
|
10
|
+
describe("datasetImport", () => {
|
|
11
|
+
it("rejects malformed JSON payloads and rows", () => {
|
|
12
|
+
assert.throws(() => parseDatasetJsonImport({rows: []}), /array/);
|
|
13
|
+
assert.throws(() => parseDatasetJsonImport([null]), /row 1/);
|
|
14
|
+
assert.throws(
|
|
15
|
+
() => parseDatasetJsonImport([{input: undefined}]),
|
|
16
|
+
/structured import row requires input/
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("parses structured JSON rows and bare objects with reserved fields", () => {
|
|
21
|
+
const structured = parseDatasetJsonImport([
|
|
22
|
+
{
|
|
23
|
+
expectedOutput: {answer: 4},
|
|
24
|
+
input: {text: "hello"},
|
|
25
|
+
metadata: {source: "seed"},
|
|
26
|
+
outcomeClass: "tp",
|
|
27
|
+
proofread: true,
|
|
28
|
+
tags: ["gold"],
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
31
|
+
assert.deepEqual(structured[0], {
|
|
32
|
+
expectedOutput: {answer: 4},
|
|
33
|
+
input: {text: "hello"},
|
|
34
|
+
metadata: {source: "seed"},
|
|
35
|
+
outcomeClass: "tp",
|
|
36
|
+
proofread: true,
|
|
37
|
+
tags: ["gold"],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const bare = parseDatasetJsonImport([
|
|
41
|
+
{
|
|
42
|
+
expectedOutput: "yes",
|
|
43
|
+
metadata: ["bad"],
|
|
44
|
+
outcomeClass: "bad",
|
|
45
|
+
proofread: "true",
|
|
46
|
+
tags: [1, "gold"],
|
|
47
|
+
text: "hello",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
assert.deepEqual(bare[0]?.input, {text: "hello"});
|
|
51
|
+
assert.equal(bare[0]?.expectedOutput, "yes");
|
|
52
|
+
assert.isUndefined(bare[0]?.metadata);
|
|
53
|
+
assert.isUndefined(bare[0]?.outcomeClass);
|
|
54
|
+
assert.isUndefined(bare[0]?.proofread);
|
|
55
|
+
assert.deepEqual(bare[0]?.tags, ["gold"]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("coerces CSV cells, nested columns, and reserved fields", () => {
|
|
59
|
+
const csv = [
|
|
60
|
+
"input.text,input.count,expectedOutput.answer,proofread,tags,outcomeClass,plain",
|
|
61
|
+
'"hello",42,"{""ok"":true}",yes,"gold|edge",tp,ignored',
|
|
62
|
+
].join("\n");
|
|
63
|
+
const rows = parseDatasetCsvImport(csv);
|
|
64
|
+
assert.deepEqual(rows[0]?.input, {count: 42, plain: "ignored", text: "hello"});
|
|
65
|
+
assert.deepEqual(rows[0]?.expectedOutput, {answer: {ok: true}});
|
|
66
|
+
assert.equal(rows[0]?.proofread, true);
|
|
67
|
+
assert.deepEqual(rows[0]?.tags, ["gold", "edge"]);
|
|
68
|
+
assert.equal(rows[0]?.outcomeClass, "tp");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("handles boolean, numeric, and invalid JSON CSV cells", () => {
|
|
72
|
+
const rows = parseDatasetCsvImport(
|
|
73
|
+
["input.flag,input.badJson,input.empty", "false,{not-json:},"].join("\n")
|
|
74
|
+
);
|
|
75
|
+
assert.deepEqual(rows[0]?.input, {
|
|
76
|
+
badJson: "{not-json:}",
|
|
77
|
+
empty: "",
|
|
78
|
+
flag: false,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("parses JSON values from plain input and expectedOutput CSV columns", () => {
|
|
83
|
+
const rows = parseDatasetCsvImport(
|
|
84
|
+
["input,expectedOutput", '"{""text"":""hello""}","{""summary"":""short""}"'].join("\n")
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
assert.deepEqual(rows[0]?.input, {text: "hello"});
|
|
88
|
+
assert.deepEqual(rows[0]?.expectedOutput, {summary: "short"});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("normalizes validation paths", () => {
|
|
92
|
+
assert.equal(flattenValidationPath(""), "/");
|
|
93
|
+
assert.equal(flattenValidationPath("text"), "/text");
|
|
94
|
+
});
|
|
95
|
+
});
|