@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
|
@@ -8,6 +8,8 @@ export interface UploadFileParams {
|
|
|
8
8
|
export interface UploadFileResult {
|
|
9
9
|
filename: string;
|
|
10
10
|
gcsKey: string;
|
|
11
|
+
/** The `FileAttachment` id, sent as `fileId` in an answer to a `files` ask. */
|
|
12
|
+
id: string;
|
|
11
13
|
mimeType: string;
|
|
12
14
|
size: number;
|
|
13
15
|
url: string;
|
|
@@ -21,6 +23,8 @@ export declare class FileStorageService {
|
|
|
21
23
|
});
|
|
22
24
|
private get bucket();
|
|
23
25
|
upload({ buffer, filename, mimeType, userId }: UploadFileParams): Promise<UploadFileResult>;
|
|
26
|
+
/** The bytes of an upload, so a `files` ask answer can reach the model. */
|
|
27
|
+
download(gcsKey: string): Promise<Buffer>;
|
|
24
28
|
getSignedUrl(gcsKey: string): Promise<string>;
|
|
25
29
|
delete(gcsKey: string): Promise<void>;
|
|
26
30
|
}
|
|
@@ -24,7 +24,7 @@ class FileStorageService {
|
|
|
24
24
|
metadata: { userId: userId.toString() },
|
|
25
25
|
});
|
|
26
26
|
const url = `https://storage.googleapis.com/${this.bucketName}/${gcsKey}`;
|
|
27
|
-
await fileAttachment_1.FileAttachment.create({
|
|
27
|
+
const attachment = await fileAttachment_1.FileAttachment.create({
|
|
28
28
|
filename,
|
|
29
29
|
gcsKey,
|
|
30
30
|
mimeType,
|
|
@@ -32,7 +32,12 @@ class FileStorageService {
|
|
|
32
32
|
url,
|
|
33
33
|
userId,
|
|
34
34
|
});
|
|
35
|
-
return { filename, gcsKey, mimeType, size: buffer.length, url };
|
|
35
|
+
return { filename, gcsKey, id: attachment._id.toString(), mimeType, size: buffer.length, url };
|
|
36
|
+
}
|
|
37
|
+
/** The bytes of an upload, so a `files` ask answer can reach the model. */
|
|
38
|
+
async download(gcsKey) {
|
|
39
|
+
const [contents] = await this.bucket.file(gcsKey).download();
|
|
40
|
+
return contents;
|
|
36
41
|
}
|
|
37
42
|
async getSignedUrl(gcsKey) {
|
|
38
43
|
const file = this.bucket.file(gcsKey);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gives each actions block that omitted `id` a unique one.
|
|
3
|
+
* Models often leave it off; the schema requires it, and the chat then shows the raw YAML.
|
|
4
|
+
* Returns the document as JSON, or undefined when nothing was missing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const fillMissingActionIds: (text: string) => string | undefined;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fillMissingActionIds = void 0;
|
|
4
|
+
const blocks_1 = require("@terreno/blocks");
|
|
5
|
+
const ACTION_ID = /^[a-z][a-z0-9_]{0,63}$/;
|
|
6
|
+
const isLooseDocument = (value) => {
|
|
7
|
+
if (typeof value !== "object" || value === null) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const doc = value;
|
|
11
|
+
return doc.v === 1 && Array.isArray(doc.blocks);
|
|
12
|
+
};
|
|
13
|
+
const collectIds = (blocks, ids) => {
|
|
14
|
+
for (const block of blocks) {
|
|
15
|
+
if (typeof block.id === "string" && ACTION_ID.test(block.id)) {
|
|
16
|
+
ids.add(block.id);
|
|
17
|
+
}
|
|
18
|
+
if (block.type === "actions") {
|
|
19
|
+
for (const element of block.elements ?? []) {
|
|
20
|
+
if (typeof element.id === "string" && ACTION_ID.test(element.id)) {
|
|
21
|
+
ids.add(element.id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (block.type === "columns" || block.type === "card") {
|
|
26
|
+
collectIds(block.children ?? [], ids);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const nextActionId = (ids) => {
|
|
31
|
+
if (!ids.has("actions")) {
|
|
32
|
+
return "actions";
|
|
33
|
+
}
|
|
34
|
+
let index = 2;
|
|
35
|
+
while (ids.has(`actions_${index}`)) {
|
|
36
|
+
index += 1;
|
|
37
|
+
}
|
|
38
|
+
return `actions_${index}`;
|
|
39
|
+
};
|
|
40
|
+
const assignIds = (blocks, ids) => {
|
|
41
|
+
let changed = false;
|
|
42
|
+
for (const block of blocks) {
|
|
43
|
+
if (block.type === "actions" && typeof block.id !== "string") {
|
|
44
|
+
const id = nextActionId(ids);
|
|
45
|
+
block.id = id;
|
|
46
|
+
ids.add(id);
|
|
47
|
+
changed = true;
|
|
48
|
+
}
|
|
49
|
+
if (block.type === "columns" || block.type === "card") {
|
|
50
|
+
if (assignIds(block.children ?? [], ids)) {
|
|
51
|
+
changed = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return changed;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Gives each actions block that omitted `id` a unique one.
|
|
59
|
+
* Models often leave it off; the schema requires it, and the chat then shows the raw YAML.
|
|
60
|
+
* Returns the document as JSON, or undefined when nothing was missing.
|
|
61
|
+
*/
|
|
62
|
+
const fillMissingActionIds = (text) => {
|
|
63
|
+
const parsed = (0, blocks_1.parseBlocks)(text);
|
|
64
|
+
if (!parsed.ok || !isLooseDocument(parsed.value)) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const ids = new Set();
|
|
68
|
+
collectIds(parsed.value.blocks, ids);
|
|
69
|
+
if (!assignIds(parsed.value.blocks, ids)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const ordered = {
|
|
73
|
+
v: 1,
|
|
74
|
+
...(parsed.value.datasets !== undefined ? { datasets: parsed.value.datasets } : {}),
|
|
75
|
+
blocks: parsed.value.blocks,
|
|
76
|
+
};
|
|
77
|
+
return JSON.stringify(ordered);
|
|
78
|
+
};
|
|
79
|
+
exports.fillMissingActionIds = fillMissingActionIds;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a language model so non-streaming `doGenerate` text parts are normalized via
|
|
4
|
+
* {@link normalizeLlmJsonTextForStructuredOutput} (fences, preamble, balanced slice, light repairs)
|
|
5
|
+
* before Vercel `Output.*` parsing.
|
|
6
|
+
*/
|
|
7
|
+
export declare const withStrippedJsonFencesModel: (model: LanguageModel) => LanguageModel;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withStrippedJsonFencesModel = void 0;
|
|
4
|
+
const parseAiJson_1 = require("./parseAiJson");
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a language model so non-streaming `doGenerate` text parts are normalized via
|
|
7
|
+
* {@link normalizeLlmJsonTextForStructuredOutput} (fences, preamble, balanced slice, light repairs)
|
|
8
|
+
* before Vercel `Output.*` parsing.
|
|
9
|
+
*/
|
|
10
|
+
const withStrippedJsonFencesModel = (model) => {
|
|
11
|
+
if (typeof model === "string") {
|
|
12
|
+
return model;
|
|
13
|
+
}
|
|
14
|
+
return new Proxy(model, {
|
|
15
|
+
get(target, prop, receiver) {
|
|
16
|
+
if (prop === "doGenerate") {
|
|
17
|
+
const original = Reflect.get(target, prop, receiver);
|
|
18
|
+
if (typeof original !== "function") {
|
|
19
|
+
return original;
|
|
20
|
+
}
|
|
21
|
+
const boundGenerate = original;
|
|
22
|
+
return async (options) => {
|
|
23
|
+
const result = await Promise.resolve(boundGenerate.call(target, options));
|
|
24
|
+
if (!result?.content || !Array.isArray(result.content)) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...result,
|
|
29
|
+
content: result.content.map((part) => {
|
|
30
|
+
if (part.type !== "text" || typeof part.text !== "string") {
|
|
31
|
+
return part;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...part,
|
|
35
|
+
text: (0, parseAiJson_1.normalizeLlmJsonTextForStructuredOutput)(part.text),
|
|
36
|
+
};
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return Reflect.get(target, prop, receiver);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.withStrippedJsonFencesModel = withStrippedJsonFencesModel;
|
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whole-reply document instructions, with no host callbacks registered.
|
|
3
|
+
* `uiBlocksSystemPrompt` rebuilds this when the host lists callback names.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TERRENO_UI_BLOCKS_SYSTEM_PROMPT: string;
|
|
6
|
+
/** Tells the model to return only a corrected document. The failed document and its errors are the user prompt. */
|
|
7
|
+
export declare const UI_BLOCKS_REPAIR_SYSTEM_PROMPT = "The document you wrote failed validation. Reply with only the corrected document. Do not explain the changes.";
|
|
8
|
+
/** The blocks prompt for this host's callback names. */
|
|
9
|
+
export declare const uiBlocksSystemPrompt: (hostActions: readonly string[], allowHtml?: boolean, imageHosts?: readonly string[]) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Appended to the chat system prompt when a route enables asks. The enabled ask tools and their
|
|
12
|
+
* limits follow it at call time (`askPromptSection` from @terreno/blocks), so the numbers stay in
|
|
13
|
+
* one place.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TERRENO_ASKS_SYSTEM_PROMPT: string;
|
|
16
|
+
/**
|
|
17
|
+
* Appended to the chat system prompt when a request sends `surface: "compact"`, because the user
|
|
18
|
+
* reads replies and answers asks on a small screen. With asks on, the asks section before it
|
|
19
|
+
* offers only the compact ask tools.
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMPACT_SURFACE_SYSTEM_PROMPT: string;
|
|
22
|
+
export declare const ASK_CHOICE_TOOL_DESCRIPTION: string;
|
|
23
|
+
/** The compact surface offers only select one, so its tool description does not mention many or Other. */
|
|
24
|
+
export declare const COMPACT_ASK_CHOICE_TOOL_DESCRIPTION: string;
|
|
25
|
+
export declare const ASK_CONFIRM_TOOL_DESCRIPTION: string;
|
|
26
|
+
export declare const COMPACT_ASK_CONFIRM_TOOL_DESCRIPTION: string;
|
|
27
|
+
export declare const ASK_MARKDOWN_TOOL_DESCRIPTION: string;
|
|
28
|
+
export declare const ASK_FORM_TOOL_DESCRIPTION: string;
|
|
29
|
+
export declare const ASK_FILES_TOOL_DESCRIPTION: string;
|
|
30
|
+
/** The line before each file of a `files` answer in the tool result the model sees. */
|
|
31
|
+
export declare const askFileHeading: ({ count, filename, mimeType, position, size, }: {
|
|
32
|
+
count: number;
|
|
33
|
+
filename: string;
|
|
34
|
+
mimeType: string;
|
|
35
|
+
position: number;
|
|
36
|
+
size: number;
|
|
37
|
+
}) => string;
|
|
38
|
+
/** The note after a text file of a `files` answer that was cut to fit. */
|
|
39
|
+
export declare const truncatedAskFileNote: ({ keptBytes, totalBytes, }: {
|
|
40
|
+
keptBytes: number;
|
|
41
|
+
totalBytes: number;
|
|
42
|
+
}) => string;
|
|
43
|
+
/** The note naming the uploads of a `files` answer that a host's own replay could not load. */
|
|
44
|
+
export declare const unloadedAskUploadsNote: (uploads: unknown[]) => string;
|
|
45
|
+
/** Tool result for a call that was left without one when the turn paused for an ask. */
|
|
46
|
+
export declare const UNANSWERED_TOOL_CALL_RESULT = "This tool call did not run, so it has no result.";
|
|
1
47
|
export declare const DEFAULT_GPT_MEMORY: string;
|
|
2
48
|
export declare const REMIX_PROMPT: string;
|
|
3
49
|
export declare const CONTENT_SUMMARY_PROMPT: string;
|
|
@@ -5,3 +51,9 @@ export declare const TRANSLATION_PROMPT: string;
|
|
|
5
51
|
export declare const TITLE_GENERATION_PROMPT: string;
|
|
6
52
|
/** When callers omit systemPrompt for JSON helpers, steer the model away from prose and markdown fences. */
|
|
7
53
|
export declare const JSON_VALUE_SYSTEM_PROMPT: string;
|
|
54
|
+
/** Observability test-multi-stage workflow: first parallel-style LLM pass. */
|
|
55
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_1_SYSTEM: string;
|
|
56
|
+
/** Observability test-multi-stage workflow: second LLM pass over the same input. */
|
|
57
|
+
export declare const OBS_TEST_MULTI_STAGE_CALL_2_SYSTEM: string;
|
|
58
|
+
/** Observability test-multi-stage workflow: final synthesis LLM pass. */
|
|
59
|
+
export declare const OBS_TEST_MULTI_STAGE_FINAL_SYSTEM: string;
|
package/dist/service/prompts.js
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSON_VALUE_SYSTEM_PROMPT = exports.TITLE_GENERATION_PROMPT = exports.TRANSLATION_PROMPT = exports.CONTENT_SUMMARY_PROMPT = exports.REMIX_PROMPT = exports.DEFAULT_GPT_MEMORY = void 0;
|
|
3
|
+
exports.OBS_TEST_MULTI_STAGE_FINAL_SYSTEM = exports.OBS_TEST_MULTI_STAGE_CALL_2_SYSTEM = exports.OBS_TEST_MULTI_STAGE_CALL_1_SYSTEM = exports.JSON_VALUE_SYSTEM_PROMPT = exports.TITLE_GENERATION_PROMPT = exports.TRANSLATION_PROMPT = exports.CONTENT_SUMMARY_PROMPT = exports.REMIX_PROMPT = exports.DEFAULT_GPT_MEMORY = exports.UNANSWERED_TOOL_CALL_RESULT = exports.unloadedAskUploadsNote = exports.truncatedAskFileNote = exports.askFileHeading = exports.ASK_FILES_TOOL_DESCRIPTION = exports.ASK_FORM_TOOL_DESCRIPTION = exports.ASK_MARKDOWN_TOOL_DESCRIPTION = exports.COMPACT_ASK_CONFIRM_TOOL_DESCRIPTION = exports.ASK_CONFIRM_TOOL_DESCRIPTION = exports.COMPACT_ASK_CHOICE_TOOL_DESCRIPTION = exports.ASK_CHOICE_TOOL_DESCRIPTION = exports.COMPACT_SURFACE_SYSTEM_PROMPT = exports.TERRENO_ASKS_SYSTEM_PROMPT = exports.uiBlocksSystemPrompt = exports.UI_BLOCKS_REPAIR_SYSTEM_PROMPT = exports.TERRENO_UI_BLOCKS_SYSTEM_PROMPT = void 0;
|
|
4
|
+
const blocks_1 = require("@terreno/blocks");
|
|
5
|
+
/**
|
|
6
|
+
* Whole-reply document instructions, with no host callbacks registered.
|
|
7
|
+
* `uiBlocksSystemPrompt` rebuilds this when the host lists callback names.
|
|
8
|
+
*/
|
|
9
|
+
exports.TERRENO_UI_BLOCKS_SYSTEM_PROMPT = (0, blocks_1.blocksPromptSection)();
|
|
10
|
+
/** Tells the model to return only a corrected document. The failed document and its errors are the user prompt. */
|
|
11
|
+
exports.UI_BLOCKS_REPAIR_SYSTEM_PROMPT = "The document you wrote failed validation. Reply with only the corrected document. Do not explain the changes.";
|
|
12
|
+
/** The blocks prompt for this host's callback names. */
|
|
13
|
+
const uiBlocksSystemPrompt = (hostActions, allowHtml = false, imageHosts = []) => {
|
|
14
|
+
if (hostActions.length === 0 && !allowHtml && imageHosts.length === 0) {
|
|
15
|
+
return exports.TERRENO_UI_BLOCKS_SYSTEM_PROMPT;
|
|
16
|
+
}
|
|
17
|
+
return (0, blocks_1.blocksPromptSection)({ allowHtml, hostActions, imageHosts });
|
|
18
|
+
};
|
|
19
|
+
exports.uiBlocksSystemPrompt = uiBlocksSystemPrompt;
|
|
20
|
+
/**
|
|
21
|
+
* Appended to the chat system prompt when a route enables asks. The enabled ask tools and their
|
|
22
|
+
* limits follow it at call time (`askPromptSection` from @terreno/blocks), so the numbers stay in
|
|
23
|
+
* one place.
|
|
24
|
+
*/
|
|
25
|
+
exports.TERRENO_ASKS_SYSTEM_PROMPT = "You can ask the user a question inside the chat by calling an ask tool. The chat shows the " +
|
|
26
|
+
"ask as a control, the user answers it, and the answer comes back to you as the tool's result.\n\n" +
|
|
27
|
+
"When to ask:\n" +
|
|
28
|
+
"- When you need an answer that one of the ask tools listed below can collect, call that tool " +
|
|
29
|
+
"instead of asking in plain text.\n" +
|
|
30
|
+
"- Ask only when you cannot continue well without the answer. Do not ask for anything you can " +
|
|
31
|
+
"find out with another tool.\n" +
|
|
32
|
+
"- Call at most one ask tool per step, and do not call other tools in the same step.\n" +
|
|
33
|
+
"- Never ask for passwords, payment card numbers, API keys, or other secrets.\n\n" +
|
|
34
|
+
"How answers come back:\n" +
|
|
35
|
+
'- {"action": "accept", "content": {...}}: the user answered; content holds the answer.\n' +
|
|
36
|
+
'- {"action": "decline"}: the user skipped the question. Continue without the answer, or ' +
|
|
37
|
+
"explain what you need.\n" +
|
|
38
|
+
'- {"action": "cancel", "reason": "..."}: the ask was dropped. "user_sent_message" means the ' +
|
|
39
|
+
'user typed a message instead, so respond to that message. "one_ask_at_a_time" means you ' +
|
|
40
|
+
"asked more than once in one step.\n" +
|
|
41
|
+
"After a decline or a cancel, do not ask the same question again unless the user asks you to.";
|
|
42
|
+
/**
|
|
43
|
+
* Appended to the chat system prompt when a request sends `surface: "compact"`, because the user
|
|
44
|
+
* reads replies and answers asks on a small screen. With asks on, the asks section before it
|
|
45
|
+
* offers only the compact ask tools.
|
|
46
|
+
*/
|
|
47
|
+
exports.COMPACT_SURFACE_SYSTEM_PROMPT = "The user is on a small screen, such as a watch. Keep each reply to at most two short " +
|
|
48
|
+
"sentences, and ask only yes-or-no questions or questions with up to three short options.";
|
|
49
|
+
exports.ASK_CHOICE_TOOL_DESCRIPTION = "Ask the user to pick one or more options from a list you provide, optionally with an Other " +
|
|
50
|
+
"field for an answer of their own. The chat shows the options as a control and returns the " +
|
|
51
|
+
"user's answer as this tool's result. Use it instead of asking in plain text when the user must " +
|
|
52
|
+
"choose from options you can list.";
|
|
53
|
+
/** The compact surface offers only select one, so its tool description does not mention many or Other. */
|
|
54
|
+
exports.COMPACT_ASK_CHOICE_TOOL_DESCRIPTION = "Ask the user to pick one option from a list you provide. The chat shows the options as a " +
|
|
55
|
+
"control and returns the user's answer as this tool's result. Use it instead of asking in plain " +
|
|
56
|
+
"text when the user must choose between options you can list.";
|
|
57
|
+
exports.ASK_CONFIRM_TOOL_DESCRIPTION = "Ask the user to approve or deny one action you describe. The chat shows an approve button and " +
|
|
58
|
+
"a deny button and returns {confirmed: true} or {confirmed: false} as this tool's result. Call " +
|
|
59
|
+
"it before a tool that deletes data, sends something on the user's behalf, spends money, or " +
|
|
60
|
+
"cannot be undone.";
|
|
61
|
+
exports.COMPACT_ASK_CONFIRM_TOOL_DESCRIPTION = "Ask the user to approve or deny one action you describe, with two short buttons. The user's " +
|
|
62
|
+
"answer comes back as {confirmed: true} or {confirmed: false}. Call it before a tool that " +
|
|
63
|
+
"deletes data, sends something, spends money, or cannot be undone.";
|
|
64
|
+
exports.ASK_MARKDOWN_TOOL_DESCRIPTION = "Ask the user to edit a markdown draft you write, or to write one, and send it back. The chat " +
|
|
65
|
+
"shows a markdown editor with a preview and returns {markdown, changed} as this tool's result; " +
|
|
66
|
+
"changed is false when the user approved your draft as is. Use it when the user should review " +
|
|
67
|
+
"or rewrite text before you use it, such as an announcement, an email, or release notes.";
|
|
68
|
+
exports.ASK_FORM_TOOL_DESCRIPTION = "Ask the user to fill in a few typed fields and submit them at once, such as the details for " +
|
|
69
|
+
"an invoice or a booking. The chat shows one input per field and returns {values}, keyed by " +
|
|
70
|
+
"field id, as this tool's result. Use it when you need several values together; for one pick " +
|
|
71
|
+
"from a list, use a choice instead.";
|
|
72
|
+
exports.ASK_FILES_TOOL_DESCRIPTION = "Ask the user to upload one or more files, such as a photo of a receipt, a signed PDF, or a " +
|
|
73
|
+
"CSV export. The chat shows a file picker limited to the types in accept, and this tool's " +
|
|
74
|
+
"result lists each file's filename, mimeType, and size, followed by the files themselves: " +
|
|
75
|
+
"images and PDFs as they are, text, CSV, and JSON as text. Use it when you need the file's " +
|
|
76
|
+
"contents; ask for a typed value with a form instead.";
|
|
77
|
+
/** The line before each file of a `files` answer in the tool result the model sees. */
|
|
78
|
+
const askFileHeading = ({ count, filename, mimeType, position, size, }) => `File ${position} of ${count}: ${filename} (${mimeType}, ${size} bytes)`;
|
|
79
|
+
exports.askFileHeading = askFileHeading;
|
|
80
|
+
/** The note after a text file of a `files` answer that was cut to fit. */
|
|
81
|
+
const truncatedAskFileNote = ({ keptBytes, totalBytes, }) => `[The file is cut to its first ${keptBytes} of ${totalBytes} bytes.]`;
|
|
82
|
+
exports.truncatedAskFileNote = truncatedAskFileNote;
|
|
83
|
+
/** The note naming the uploads of a `files` answer that a host's own replay could not load. */
|
|
84
|
+
const unloadedAskUploadsNote = (uploads) => `Uploads not loaded here: ${JSON.stringify(uploads)}`;
|
|
85
|
+
exports.unloadedAskUploadsNote = unloadedAskUploadsNote;
|
|
86
|
+
/** Tool result for a call that was left without one when the turn paused for an ask. */
|
|
87
|
+
exports.UNANSWERED_TOOL_CALL_RESULT = "This tool call did not run, so it has no result.";
|
|
4
88
|
exports.DEFAULT_GPT_MEMORY = "You are a helpful, friendly AI assistant. Provide clear, accurate, and concise responses. " +
|
|
5
89
|
"When you don't know something, say so honestly rather than guessing.";
|
|
6
90
|
exports.REMIX_PROMPT = "Reword the following text to sound more natural and polished while preserving the original " +
|
|
@@ -17,3 +101,14 @@ exports.TITLE_GENERATION_PROMPT = "Generate a short title (3-6 words) that summa
|
|
|
17
101
|
/** When callers omit systemPrompt for JSON helpers, steer the model away from prose and markdown fences. */
|
|
18
102
|
exports.JSON_VALUE_SYSTEM_PROMPT = "You respond with a single JSON value (object, array, string, number, boolean, or null) only. " +
|
|
19
103
|
"No markdown code fences, no commentary before or after the JSON.";
|
|
104
|
+
/** Observability test-multi-stage workflow: first parallel-style LLM pass. */
|
|
105
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_1_SYSTEM = "Summarize the user input in one short phrase. Return a JSON object that matches the output " +
|
|
106
|
+
'schema {"phrase": string}. No markdown fences and no extra keys.';
|
|
107
|
+
/** Observability test-multi-stage workflow: second LLM pass over the same input. */
|
|
108
|
+
exports.OBS_TEST_MULTI_STAGE_CALL_2_SYSTEM = "Extract exactly two keywords from the user input. Return a JSON object that matches the output " +
|
|
109
|
+
'schema {"keywords": [string, string]}. No markdown fences and no extra keys.';
|
|
110
|
+
/** Observability test-multi-stage workflow: final synthesis LLM pass. */
|
|
111
|
+
exports.OBS_TEST_MULTI_STAGE_FINAL_SYSTEM = "Combine the stage-one phrase, stage-two keywords, and text metrics into one concise sentence. " +
|
|
112
|
+
"Return a JSON object that matches the output schema " +
|
|
113
|
+
'{"sentence": string, "phrase": string, "keywords": string[], "metrics": object}. ' +
|
|
114
|
+
"Echo phrase, keywords, and metrics from the prompt. No markdown fences and no extra keys.";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display-only HTML. Scripts, frames, forms, event handlers, and links are removed.
|
|
3
|
+
* The only URL that remains is an image `data:` URL.
|
|
4
|
+
* @internal Test seam. Callers store the document from `sanitizeBlocksText`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const sanitizeHtmlFragment: (html: string) => string;
|
|
7
|
+
/** Rewrites `html` fields in a block document. A non-document is returned unchanged. */
|
|
8
|
+
export declare const sanitizeBlocksText: (text: string) => {
|
|
9
|
+
changed: boolean;
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sanitizeBlocksText = exports.sanitizeHtmlFragment = void 0;
|
|
7
|
+
const blocks_1 = require("@terreno/blocks");
|
|
8
|
+
const sanitize_html_1 = __importDefault(require("sanitize-html"));
|
|
9
|
+
const DROPPED_TAGS = new Set([
|
|
10
|
+
"base",
|
|
11
|
+
"button",
|
|
12
|
+
"embed",
|
|
13
|
+
"form",
|
|
14
|
+
"frame",
|
|
15
|
+
"iframe",
|
|
16
|
+
"input",
|
|
17
|
+
"link",
|
|
18
|
+
"meta",
|
|
19
|
+
"object",
|
|
20
|
+
"script",
|
|
21
|
+
"select",
|
|
22
|
+
"textarea",
|
|
23
|
+
]);
|
|
24
|
+
const allowedTags = [
|
|
25
|
+
...sanitize_html_1.default.defaults.allowedTags.filter((tag) => !DROPPED_TAGS.has(tag)),
|
|
26
|
+
"img",
|
|
27
|
+
];
|
|
28
|
+
const allowedAttributes = {};
|
|
29
|
+
for (const [tag, attributes] of Object.entries(sanitize_html_1.default.defaults.allowedAttributes)) {
|
|
30
|
+
allowedAttributes[tag] = attributes.filter((attribute) => attribute !== "href" && !attribute.startsWith("on"));
|
|
31
|
+
}
|
|
32
|
+
allowedAttributes.a = (allowedAttributes.a ?? []).filter((attribute) => attribute !== "href");
|
|
33
|
+
allowedAttributes.img = ["alt", "height", "src", "width"];
|
|
34
|
+
/**
|
|
35
|
+
* Display-only HTML. Scripts, frames, forms, event handlers, and links are removed.
|
|
36
|
+
* The only URL that remains is an image `data:` URL.
|
|
37
|
+
* @internal Test seam. Callers store the document from `sanitizeBlocksText`.
|
|
38
|
+
*/
|
|
39
|
+
const sanitizeHtmlFragment = (html) => (0, sanitize_html_1.default)(html, {
|
|
40
|
+
allowedAttributes,
|
|
41
|
+
allowedSchemes: ["data"],
|
|
42
|
+
allowedSchemesByTag: { img: ["data"] },
|
|
43
|
+
allowedTags,
|
|
44
|
+
allowProtocolRelative: false,
|
|
45
|
+
disallowedTagsMode: "discard",
|
|
46
|
+
transformTags: {
|
|
47
|
+
img: (_tagName, attribs) => {
|
|
48
|
+
const src = attribs.src ?? "";
|
|
49
|
+
const next = {};
|
|
50
|
+
if (attribs.alt !== undefined) {
|
|
51
|
+
next.alt = attribs.alt;
|
|
52
|
+
}
|
|
53
|
+
if (/^data:image\//i.test(src)) {
|
|
54
|
+
next.src = src;
|
|
55
|
+
}
|
|
56
|
+
return { attribs: next, tagName: "img" };
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
exports.sanitizeHtmlFragment = sanitizeHtmlFragment;
|
|
61
|
+
const sanitizeBlock = (block) => {
|
|
62
|
+
if (block.type === "html") {
|
|
63
|
+
const html = (0, exports.sanitizeHtmlFragment)(block.html);
|
|
64
|
+
return { block: html === block.html ? block : { ...block, html }, changed: html !== block.html };
|
|
65
|
+
}
|
|
66
|
+
if (block.type === "columns" || block.type === "card") {
|
|
67
|
+
let changed = false;
|
|
68
|
+
const children = block.children.map((child) => {
|
|
69
|
+
const next = sanitizeBlock(child);
|
|
70
|
+
changed = changed || next.changed;
|
|
71
|
+
return next.block;
|
|
72
|
+
});
|
|
73
|
+
return { block: changed ? { ...block, children } : block, changed };
|
|
74
|
+
}
|
|
75
|
+
return { block, changed: false };
|
|
76
|
+
};
|
|
77
|
+
/** Rewrites `html` fields in a block document. A non-document is returned unchanged. */
|
|
78
|
+
const sanitizeBlocksText = (text) => {
|
|
79
|
+
const parsed = (0, blocks_1.parseBlocks)(text);
|
|
80
|
+
if (!parsed.ok) {
|
|
81
|
+
return { changed: false, text };
|
|
82
|
+
}
|
|
83
|
+
const validated = (0, blocks_1.validateBlocks)(parsed.value, { allowHtml: true });
|
|
84
|
+
if (!validated.ok) {
|
|
85
|
+
return { changed: false, text };
|
|
86
|
+
}
|
|
87
|
+
let changed = false;
|
|
88
|
+
const blocks = validated.doc.blocks.map((block) => {
|
|
89
|
+
const next = sanitizeBlock(block);
|
|
90
|
+
changed = changed || next.changed;
|
|
91
|
+
return next.block;
|
|
92
|
+
});
|
|
93
|
+
if (!changed) {
|
|
94
|
+
return { changed: false, text };
|
|
95
|
+
}
|
|
96
|
+
const doc = { blocks, v: 1 };
|
|
97
|
+
if (validated.doc.datasets !== undefined) {
|
|
98
|
+
doc.datasets = validated.doc.datasets;
|
|
99
|
+
}
|
|
100
|
+
const ordered = {};
|
|
101
|
+
ordered.v = doc.v;
|
|
102
|
+
if (doc.datasets !== undefined) {
|
|
103
|
+
ordered.datasets = doc.datasets;
|
|
104
|
+
}
|
|
105
|
+
ordered.blocks = doc.blocks;
|
|
106
|
+
return { changed: true, text: JSON.stringify(ordered) };
|
|
107
|
+
};
|
|
108
|
+
exports.sanitizeBlocksText = sanitizeBlocksText;
|