@meistrari/chat-nuxt 1.0.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 +274 -0
- package/dist/module.d.mts +3 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +250 -0
- package/dist/runtime/assets/css/code-theme.css +1 -0
- package/dist/runtime/assets/css/markstream.css +1 -0
- package/dist/runtime/components/AppStatusToast.d.vue.ts +3 -0
- package/dist/runtime/components/AppStatusToast.vue +42 -0
- package/dist/runtime/components/AppStatusToast.vue.d.ts +3 -0
- package/dist/runtime/components/TelaChat.d.vue.ts +19 -0
- package/dist/runtime/components/TelaChat.vue +25 -0
- package/dist/runtime/components/TelaChat.vue.d.ts +19 -0
- package/dist/runtime/components/app-markdown-render.d.vue.ts +15 -0
- package/dist/runtime/components/app-markdown-render.vue +45 -0
- package/dist/runtime/components/app-markdown-render.vue.d.ts +15 -0
- package/dist/runtime/components/application-card.d.vue.ts +9 -0
- package/dist/runtime/components/application-card.vue +52 -0
- package/dist/runtime/components/application-card.vue.d.ts +9 -0
- package/dist/runtime/components/audio-preview.d.vue.ts +14 -0
- package/dist/runtime/components/audio-preview.vue +52 -0
- package/dist/runtime/components/audio-preview.vue.d.ts +14 -0
- package/dist/runtime/components/chat/bash-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/bash-widget.vue +86 -0
- package/dist/runtime/components/chat/bash-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/canvas-selector-modal.d.vue.ts +14 -0
- package/dist/runtime/components/chat/canvas-selector-modal.vue +290 -0
- package/dist/runtime/components/chat/canvas-selector-modal.vue.d.ts +14 -0
- package/dist/runtime/components/chat/context-config.d.vue.ts +30 -0
- package/dist/runtime/components/chat/context-config.vue +423 -0
- package/dist/runtime/components/chat/context-config.vue.d.ts +30 -0
- package/dist/runtime/components/chat/conversation-item.d.vue.ts +20 -0
- package/dist/runtime/components/chat/conversation-item.vue +184 -0
- package/dist/runtime/components/chat/conversation-item.vue.d.ts +20 -0
- package/dist/runtime/components/chat/conversation-list.d.vue.ts +10 -0
- package/dist/runtime/components/chat/conversation-list.vue +78 -0
- package/dist/runtime/components/chat/conversation-list.vue.d.ts +10 -0
- package/dist/runtime/components/chat/doc-sdk-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/doc-sdk-widget.vue +74 -0
- package/dist/runtime/components/chat/doc-sdk-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/file-preview.d.vue.ts +7 -0
- package/dist/runtime/components/chat/file-preview.vue +313 -0
- package/dist/runtime/components/chat/file-preview.vue.d.ts +7 -0
- package/dist/runtime/components/chat/files-view.d.vue.ts +6 -0
- package/dist/runtime/components/chat/files-view.vue +399 -0
- package/dist/runtime/components/chat/files-view.vue.d.ts +6 -0
- package/dist/runtime/components/chat/generic-tool-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/generic-tool-widget.vue +334 -0
- package/dist/runtime/components/chat/generic-tool-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/grep-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/grep-widget.vue +259 -0
- package/dist/runtime/components/chat/grep-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/mention-dropdown.d.vue.ts +14 -0
- package/dist/runtime/components/chat/mention-dropdown.vue +90 -0
- package/dist/runtime/components/chat/mention-dropdown.vue.d.ts +14 -0
- package/dist/runtime/components/chat/message-bubble.d.vue.ts +11 -0
- package/dist/runtime/components/chat/message-bubble.vue +288 -0
- package/dist/runtime/components/chat/message-bubble.vue.d.ts +11 -0
- package/dist/runtime/components/chat/message-input.d.vue.ts +34 -0
- package/dist/runtime/components/chat/message-input.vue +428 -0
- package/dist/runtime/components/chat/message-input.vue.d.ts +34 -0
- package/dist/runtime/components/chat/message-list.d.vue.ts +11 -0
- package/dist/runtime/components/chat/message-list.vue +36 -0
- package/dist/runtime/components/chat/message-list.vue.d.ts +11 -0
- package/dist/runtime/components/chat/model-selector.d.vue.ts +15 -0
- package/dist/runtime/components/chat/model-selector.vue +35 -0
- package/dist/runtime/components/chat/model-selector.vue.d.ts +15 -0
- package/dist/runtime/components/chat/new-conversation-modal.d.vue.ts +14 -0
- package/dist/runtime/components/chat/new-conversation-modal.vue +271 -0
- package/dist/runtime/components/chat/new-conversation-modal.vue.d.ts +14 -0
- package/dist/runtime/components/chat/read-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/read-widget.vue +195 -0
- package/dist/runtime/components/chat/read-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/reasoning-message.d.vue.ts +13 -0
- package/dist/runtime/components/chat/reasoning-message.vue +341 -0
- package/dist/runtime/components/chat/reasoning-message.vue.d.ts +13 -0
- package/dist/runtime/components/chat/reasoning-step-item.d.vue.ts +37 -0
- package/dist/runtime/components/chat/reasoning-step-item.vue +125 -0
- package/dist/runtime/components/chat/reasoning-step-item.vue.d.ts +37 -0
- package/dist/runtime/components/chat/reasoning-steps.d.vue.ts +12 -0
- package/dist/runtime/components/chat/reasoning-steps.vue +47 -0
- package/dist/runtime/components/chat/reasoning-steps.vue.d.ts +12 -0
- package/dist/runtime/components/chat/reasoning-thought.d.vue.ts +11 -0
- package/dist/runtime/components/chat/reasoning-thought.vue +287 -0
- package/dist/runtime/components/chat/reasoning-thought.vue.d.ts +11 -0
- package/dist/runtime/components/chat/tela-skill-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/tela-skill-widget.vue +94 -0
- package/dist/runtime/components/chat/tela-skill-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/thinking-indicator.d.vue.ts +3 -0
- package/dist/runtime/components/chat/thinking-indicator.vue +52 -0
- package/dist/runtime/components/chat/thinking-indicator.vue.d.ts +3 -0
- package/dist/runtime/components/chat/thinking-widget.d.vue.ts +8 -0
- package/dist/runtime/components/chat/thinking-widget.vue +53 -0
- package/dist/runtime/components/chat/thinking-widget.vue.d.ts +8 -0
- package/dist/runtime/components/chat/topbar.d.vue.ts +43 -0
- package/dist/runtime/components/chat/topbar.vue +223 -0
- package/dist/runtime/components/chat/topbar.vue.d.ts +43 -0
- package/dist/runtime/components/chat/usage-view.d.vue.ts +8 -0
- package/dist/runtime/components/chat/usage-view.vue +393 -0
- package/dist/runtime/components/chat/usage-view.vue.d.ts +8 -0
- package/dist/runtime/components/chat/vault-link.d.vue.ts +20 -0
- package/dist/runtime/components/chat/vault-link.vue +34 -0
- package/dist/runtime/components/chat/vault-link.vue.d.ts +20 -0
- package/dist/runtime/components/chat/web-search-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/web-search-widget.vue +121 -0
- package/dist/runtime/components/chat/web-search-widget.vue.d.ts +9 -0
- package/dist/runtime/components/chat/workstation-query-widget.d.vue.ts +10 -0
- package/dist/runtime/components/chat/workstation-query-widget.vue +552 -0
- package/dist/runtime/components/chat/workstation-query-widget.vue.d.ts +10 -0
- package/dist/runtime/components/chat/workstation-selector-modal.d.vue.ts +14 -0
- package/dist/runtime/components/chat/workstation-selector-modal.vue +272 -0
- package/dist/runtime/components/chat/workstation-selector-modal.vue.d.ts +14 -0
- package/dist/runtime/components/chat/write-widget.d.vue.ts +9 -0
- package/dist/runtime/components/chat/write-widget.vue +165 -0
- package/dist/runtime/components/chat/write-widget.vue.d.ts +9 -0
- package/dist/runtime/components/conversation-files-panel.d.vue.ts +3 -0
- package/dist/runtime/components/conversation-files-panel.vue +252 -0
- package/dist/runtime/components/conversation-files-panel.vue.d.ts +3 -0
- package/dist/runtime/components/csv-preview.d.vue.ts +20 -0
- package/dist/runtime/components/csv-preview.vue +157 -0
- package/dist/runtime/components/csv-preview.vue.d.ts +20 -0
- package/dist/runtime/components/file-preview-panel.d.vue.ts +3 -0
- package/dist/runtime/components/file-preview-panel.vue +185 -0
- package/dist/runtime/components/file-preview-panel.vue.d.ts +3 -0
- package/dist/runtime/components/file-uploader.d.vue.ts +16 -0
- package/dist/runtime/components/file-uploader.vue +136 -0
- package/dist/runtime/components/file-uploader.vue.d.ts +16 -0
- package/dist/runtime/components/icons/anthropic.d.vue.ts +3 -0
- package/dist/runtime/components/icons/anthropic.vue +5 -0
- package/dist/runtime/components/icons/anthropic.vue.d.ts +3 -0
- package/dist/runtime/components/image-preview.d.vue.ts +14 -0
- package/dist/runtime/components/image-preview.vue +54 -0
- package/dist/runtime/components/image-preview.vue.d.ts +14 -0
- package/dist/runtime/components/json-tree-node.d.vue.ts +9 -0
- package/dist/runtime/components/json-tree-node.vue +109 -0
- package/dist/runtime/components/json-tree-node.vue.d.ts +9 -0
- package/dist/runtime/components/json-viewer.d.vue.ts +6 -0
- package/dist/runtime/components/json-viewer.vue +88 -0
- package/dist/runtime/components/json-viewer.vue.d.ts +6 -0
- package/dist/runtime/components/pdf-preview.d.vue.ts +20 -0
- package/dist/runtime/components/pdf-preview.vue +89 -0
- package/dist/runtime/components/pdf-preview.vue.d.ts +20 -0
- package/dist/runtime/components/pdf-viewer.d.vue.ts +10 -0
- package/dist/runtime/components/pdf-viewer.vue +265 -0
- package/dist/runtime/components/pdf-viewer.vue.d.ts +10 -0
- package/dist/runtime/components/powered-by-tela.d.vue.ts +3 -0
- package/dist/runtime/components/powered-by-tela.vue +14 -0
- package/dist/runtime/components/powered-by-tela.vue.d.ts +3 -0
- package/dist/runtime/components/renderers/artifact-display.d.vue.ts +15 -0
- package/dist/runtime/components/renderers/artifact-display.vue +105 -0
- package/dist/runtime/components/renderers/artifact-display.vue.d.ts +15 -0
- package/dist/runtime/components/renderers/audio-renderer.d.vue.ts +7 -0
- package/dist/runtime/components/renderers/audio-renderer.vue +52 -0
- package/dist/runtime/components/renderers/audio-renderer.vue.d.ts +7 -0
- package/dist/runtime/components/renderers/csv-renderer.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/csv-renderer.vue +203 -0
- package/dist/runtime/components/renderers/csv-renderer.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/image-renderer.d.vue.ts +7 -0
- package/dist/runtime/components/renderers/image-renderer.vue +44 -0
- package/dist/runtime/components/renderers/image-renderer.vue.d.ts +7 -0
- package/dist/runtime/components/renderers/markdown-renderer.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/markdown-renderer.vue +66 -0
- package/dist/runtime/components/renderers/markdown-renderer.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/mermaid-diagram.d.vue.ts +7 -0
- package/dist/runtime/components/renderers/mermaid-diagram.vue +165 -0
- package/dist/runtime/components/renderers/mermaid-diagram.vue.d.ts +7 -0
- package/dist/runtime/components/renderers/text-renderer.d.vue.ts +7 -0
- package/dist/runtime/components/renderers/text-renderer.vue +70 -0
- package/dist/runtime/components/renderers/text-renderer.vue.d.ts +7 -0
- package/dist/runtime/components/renderers/video-renderer.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/video-renderer.vue +43 -0
- package/dist/runtime/components/renderers/video-renderer.vue.d.ts +6 -0
- package/dist/runtime/components/text-preview.d.vue.ts +19 -0
- package/dist/runtime/components/text-preview.vue +105 -0
- package/dist/runtime/components/text-preview.vue.d.ts +19 -0
- package/dist/runtime/components/video-preview.d.vue.ts +14 -0
- package/dist/runtime/components/video-preview.vue +55 -0
- package/dist/runtime/components/video-preview.vue.d.ts +14 -0
- package/dist/runtime/composables/PageNavigation.d.ts +13 -0
- package/dist/runtime/composables/PageNavigation.js +18 -0
- package/dist/runtime/composables/useChat.d.ts +25 -0
- package/dist/runtime/composables/useChat.js +512 -0
- package/dist/runtime/composables/useChatApi.d.ts +6 -0
- package/dist/runtime/composables/useChatApi.js +28 -0
- package/dist/runtime/composables/useConversationFiles.d.ts +13 -0
- package/dist/runtime/composables/useConversationFiles.js +98 -0
- package/dist/runtime/composables/useConversationFilesPanel.d.ts +11 -0
- package/dist/runtime/composables/useConversationFilesPanel.js +35 -0
- package/dist/runtime/composables/useConversations.d.ts +15 -0
- package/dist/runtime/composables/useConversations.js +191 -0
- package/dist/runtime/composables/useDiagramExport.d.ts +11 -0
- package/dist/runtime/composables/useDiagramExport.js +186 -0
- package/dist/runtime/composables/useEmbedConfig.d.ts +13 -0
- package/dist/runtime/composables/useEmbedConfig.js +11 -0
- package/dist/runtime/composables/useFeatureFlags.d.ts +19 -0
- package/dist/runtime/composables/useFeatureFlags.js +67 -0
- package/dist/runtime/composables/useFileDrop.d.ts +17 -0
- package/dist/runtime/composables/useFileDrop.js +89 -0
- package/dist/runtime/composables/useFilePreviewPanel.d.ts +30 -0
- package/dist/runtime/composables/useFilePreviewPanel.js +42 -0
- package/dist/runtime/composables/useFileUpload.d.ts +7 -0
- package/dist/runtime/composables/useFileUpload.js +39 -0
- package/dist/runtime/composables/useGitHubSkills.d.ts +6 -0
- package/dist/runtime/composables/useGitHubSkills.js +68 -0
- package/dist/runtime/composables/useGitHubSkillsCallback.d.ts +5 -0
- package/dist/runtime/composables/useGitHubSkillsCallback.js +42 -0
- package/dist/runtime/composables/useIDB.d.ts +11 -0
- package/dist/runtime/composables/useIDB.js +57 -0
- package/dist/runtime/composables/useInputHistory.d.ts +7 -0
- package/dist/runtime/composables/useInputHistory.js +36 -0
- package/dist/runtime/composables/useKnowledgeSources.d.ts +6 -0
- package/dist/runtime/composables/useKnowledgeSources.js +15 -0
- package/dist/runtime/composables/useMediaCache.d.ts +13 -0
- package/dist/runtime/composables/useMediaCache.js +92 -0
- package/dist/runtime/composables/useMentionAutocomplete.d.ts +10 -0
- package/dist/runtime/composables/useMentionAutocomplete.js +272 -0
- package/dist/runtime/composables/useMermaidRenderer.d.ts +5 -0
- package/dist/runtime/composables/useMermaidRenderer.js +121 -0
- package/dist/runtime/composables/usePdf.d.ts +21 -0
- package/dist/runtime/composables/usePdf.js +138 -0
- package/dist/runtime/composables/usePolling.d.ts +12 -0
- package/dist/runtime/composables/usePolling.js +55 -0
- package/dist/runtime/composables/useSelectedModel.d.ts +4 -0
- package/dist/runtime/composables/useSelectedModel.js +46 -0
- package/dist/runtime/composables/useSplashScreen.d.ts +3 -0
- package/dist/runtime/composables/useSplashScreen.js +4 -0
- package/dist/runtime/composables/useStatusToast.d.ts +22 -0
- package/dist/runtime/composables/useStatusToast.js +40 -0
- package/dist/runtime/composables/useTela.d.ts +12 -0
- package/dist/runtime/composables/useTela.js +47 -0
- package/dist/runtime/composables/useToolFormatting.d.ts +5 -0
- package/dist/runtime/composables/useToolFormatting.js +61 -0
- package/dist/runtime/composables/useVault.d.ts +13 -0
- package/dist/runtime/composables/useVault.js +35 -0
- package/dist/runtime/composables/useVerbConjugation.d.ts +6 -0
- package/dist/runtime/composables/useVerbConjugation.js +256 -0
- package/dist/runtime/composables/useWorkspaceContextFiles.d.ts +19 -0
- package/dist/runtime/composables/useWorkspaceContextFiles.js +74 -0
- package/dist/runtime/composables/useWorkspaceCredentials.d.ts +34 -0
- package/dist/runtime/composables/useWorkspaceCredentials.js +175 -0
- package/dist/runtime/composables/useWorkspaceExternalSkills.d.ts +22 -0
- package/dist/runtime/composables/useWorkspaceExternalSkills.js +135 -0
- package/dist/runtime/composables/useWorkspaceKnowledgeSources.d.ts +11 -0
- package/dist/runtime/composables/useWorkspaceKnowledgeSources.js +88 -0
- package/dist/runtime/composables/useWorkspaceMembers.d.ts +13 -0
- package/dist/runtime/composables/useWorkspaceMembers.js +37 -0
- package/dist/runtime/composables/useWorkspacePersonalization.d.ts +6 -0
- package/dist/runtime/composables/useWorkspacePersonalization.js +19 -0
- package/dist/runtime/composables/useWorkspaceSettings.d.ts +30 -0
- package/dist/runtime/composables/useWorkspaceSettings.js +135 -0
- package/dist/runtime/composables/useWorkspaceTelaTools.d.ts +13 -0
- package/dist/runtime/composables/useWorkspaceTelaTools.js +91 -0
- package/dist/runtime/composables/useWorkspaces.d.ts +5 -0
- package/dist/runtime/composables/useWorkspaces.js +14 -0
- package/dist/runtime/composables/useZoomPan.d.ts +18 -0
- package/dist/runtime/composables/useZoomPan.js +130 -0
- package/dist/runtime/embed/components/ChatEmbed.d.vue.ts +23 -0
- package/dist/runtime/embed/components/ChatEmbed.vue +27 -0
- package/dist/runtime/embed/components/ChatEmbed.vue.d.ts +23 -0
- package/dist/runtime/embed/components/ChatEmbedInner.d.vue.ts +19 -0
- package/dist/runtime/embed/components/ChatEmbedInner.vue +604 -0
- package/dist/runtime/embed/components/ChatEmbedInner.vue.d.ts +19 -0
- package/dist/runtime/public/favicon.svg +4 -0
- package/dist/runtime/public/files/archive.svg +9 -0
- package/dist/runtime/public/files/audio.svg +4 -0
- package/dist/runtime/public/files/c.svg +4 -0
- package/dist/runtime/public/files/cpp.svg +6 -0
- package/dist/runtime/public/files/css.svg +4 -0
- package/dist/runtime/public/files/doc.svg +5 -0
- package/dist/runtime/public/files/generic.svg +7 -0
- package/dist/runtime/public/files/go.svg +6 -0
- package/dist/runtime/public/files/html.svg +4 -0
- package/dist/runtime/public/files/image.svg +3 -0
- package/dist/runtime/public/files/java.svg +7 -0
- package/dist/runtime/public/files/javascript.svg +4 -0
- package/dist/runtime/public/files/json.svg +5 -0
- package/dist/runtime/public/files/markdown.svg +5 -0
- package/dist/runtime/public/files/pdf.svg +5 -0
- package/dist/runtime/public/files/presentation.svg +5 -0
- package/dist/runtime/public/files/python.svg +5 -0
- package/dist/runtime/public/files/ruby.svg +5 -0
- package/dist/runtime/public/files/rust.svg +13 -0
- package/dist/runtime/public/files/sheet.svg +9 -0
- package/dist/runtime/public/files/shell.svg +5 -0
- package/dist/runtime/public/files/sql.svg +6 -0
- package/dist/runtime/public/files/typescript.svg +5 -0
- package/dist/runtime/public/files/video.svg +5 -0
- package/dist/runtime/public/files/yaml.svg +7 -0
- package/dist/runtime/public/github.svg +3 -0
- package/dist/runtime/public/robots.txt +1 -0
- package/dist/runtime/server/api/admin/trigger-usage-report.post.d.ts +2 -0
- package/dist/runtime/server/api/admin/trigger-usage-report.post.js +15 -0
- package/dist/runtime/server/api/chat/conversations/[id]/cancel.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/cancel.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/clear.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/clear.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/duplicate.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/duplicate.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/files.get.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/files.get.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.delete.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.delete.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.get.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.get.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.patch.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/index.patch.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/[messageId]/retry.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/[messageId]/retry.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/index.get.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/index.get.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/index.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/messages/index.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/usage.get.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/[id]/usage.get.js +1 -0
- package/dist/runtime/server/api/chat/conversations/generate-title.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/generate-title.post.js +1 -0
- package/dist/runtime/server/api/chat/conversations/index.get.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/index.get.js +1 -0
- package/dist/runtime/server/api/chat/conversations/index.post.d.ts +1 -0
- package/dist/runtime/server/api/chat/conversations/index.post.js +1 -0
- package/dist/runtime/server/api/chat/workspace/settings.get.d.ts +2 -0
- package/dist/runtime/server/api/chat/workspace/settings.get.js +14 -0
- package/dist/runtime/server/api/conversations/[id]/cancel.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/cancel.post.js +58 -0
- package/dist/runtime/server/api/conversations/[id]/clear.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/clear.post.js +38 -0
- package/dist/runtime/server/api/conversations/[id]/duplicate.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/duplicate.post.js +41 -0
- package/dist/runtime/server/api/conversations/[id]/files.get.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/files.get.js +131 -0
- package/dist/runtime/server/api/conversations/[id]/index.delete.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/index.delete.js +35 -0
- package/dist/runtime/server/api/conversations/[id]/index.get.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/index.get.js +34 -0
- package/dist/runtime/server/api/conversations/[id]/index.patch.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/index.patch.js +54 -0
- package/dist/runtime/server/api/conversations/[id]/messages/[messageId]/retry.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/messages/[messageId]/retry.post.js +168 -0
- package/dist/runtime/server/api/conversations/[id]/messages/index.get.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/messages/index.get.js +220 -0
- package/dist/runtime/server/api/conversations/[id]/messages/index.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/messages/index.post.js +181 -0
- package/dist/runtime/server/api/conversations/[id]/usage.get.d.ts +8 -0
- package/dist/runtime/server/api/conversations/[id]/usage.get.js +96 -0
- package/dist/runtime/server/api/conversations/generate-title.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/generate-title.post.js +49 -0
- package/dist/runtime/server/api/conversations/index.get.d.ts +2 -0
- package/dist/runtime/server/api/conversations/index.get.js +11 -0
- package/dist/runtime/server/api/conversations/index.post.d.ts +2 -0
- package/dist/runtime/server/api/conversations/index.post.js +41 -0
- package/dist/runtime/server/api/external-skills/discover.post.d.ts +2 -0
- package/dist/runtime/server/api/external-skills/discover.post.js +65 -0
- package/dist/runtime/server/api/github/disconnect.post.d.ts +2 -0
- package/dist/runtime/server/api/github/disconnect.post.js +21 -0
- package/dist/runtime/server/api/github/status.get.d.ts +2 -0
- package/dist/runtime/server/api/github/status.get.js +23 -0
- package/dist/runtime/server/api/tela/canvas.get.d.ts +2 -0
- package/dist/runtime/server/api/tela/canvas.get.js +18 -0
- package/dist/runtime/server/api/tela/projects.get.d.ts +2 -0
- package/dist/runtime/server/api/tela/projects.get.js +9 -0
- package/dist/runtime/server/api/tela/workspaces.get.d.ts +2 -0
- package/dist/runtime/server/api/tela/workspaces.get.js +9 -0
- package/dist/runtime/server/api/tela/workstations.get.d.ts +2 -0
- package/dist/runtime/server/api/tela/workstations.get.js +24 -0
- package/dist/runtime/server/api/vault/permalink-metadata.post.d.ts +2 -0
- package/dist/runtime/server/api/vault/permalink-metadata.post.js +77 -0
- package/dist/runtime/server/api/vault/resolve.post.d.ts +2 -0
- package/dist/runtime/server/api/vault/resolve.post.js +82 -0
- package/dist/runtime/server/api/vault/upload.post.d.ts +2 -0
- package/dist/runtime/server/api/vault/upload.post.js +55 -0
- package/dist/runtime/server/api/workspace/credentials/[id].delete.d.ts +2 -0
- package/dist/runtime/server/api/workspace/credentials/[id].delete.js +18 -0
- package/dist/runtime/server/api/workspace/credentials/[id].put.d.ts +2 -0
- package/dist/runtime/server/api/workspace/credentials/[id].put.js +28 -0
- package/dist/runtime/server/api/workspace/credentials/index.get.d.ts +2 -0
- package/dist/runtime/server/api/workspace/credentials/index.get.js +10 -0
- package/dist/runtime/server/api/workspace/credentials/index.post.d.ts +2 -0
- package/dist/runtime/server/api/workspace/credentials/index.post.js +33 -0
- package/dist/runtime/server/api/workspace/settings.get.d.ts +2 -0
- package/dist/runtime/server/api/workspace/settings.get.js +27 -0
- package/dist/runtime/server/api/workspace/settings.patch.d.ts +2 -0
- package/dist/runtime/server/api/workspace/settings.patch.js +86 -0
- package/dist/runtime/server/api/workspace/usage.get.d.ts +48 -0
- package/dist/runtime/server/api/workspace/usage.get.js +186 -0
- package/dist/runtime/server/db/index.d.ts +6 -0
- package/dist/runtime/server/db/index.js +19 -0
- package/dist/runtime/server/db/schema/conversation-usage.d.ts +438 -0
- package/dist/runtime/server/db/schema/conversation-usage.js +34 -0
- package/dist/runtime/server/db/schema/conversations.d.ts +197 -0
- package/dist/runtime/server/db/schema/conversations.js +18 -0
- package/dist/runtime/server/db/schema/external-skills.d.ts +235 -0
- package/dist/runtime/server/db/schema/external-skills.js +26 -0
- package/dist/runtime/server/db/schema/index.d.ts +5 -0
- package/dist/runtime/server/db/schema/index.js +5 -0
- package/dist/runtime/server/db/schema/messages.d.ts +221 -0
- package/dist/runtime/server/db/schema/messages.js +19 -0
- package/dist/runtime/server/db/schema/workspace-settings.d.ts +164 -0
- package/dist/runtime/server/db/schema/workspace-settings.js +15 -0
- package/dist/runtime/server/db/schema.d.ts +1 -0
- package/dist/runtime/server/db/schema.js +1 -0
- package/dist/runtime/server/middleware/domain-validation.d.ts +2 -0
- package/dist/runtime/server/middleware/domain-validation.js +22 -0
- package/dist/runtime/server/middleware/request-logger.d.ts +2 -0
- package/dist/runtime/server/middleware/request-logger.js +15 -0
- package/dist/runtime/server/prompts/base-system.d.ts +2 -0
- package/dist/runtime/server/prompts/base-system.js +100 -0
- package/dist/runtime/server/prompts/base-system.md +99 -0
- package/dist/runtime/server/prompts/knowledge-sources.d.ts +2 -0
- package/dist/runtime/server/prompts/knowledge-sources.js +37 -0
- package/dist/runtime/server/prompts/knowledge-sources.md +36 -0
- package/dist/runtime/server/tasks/send-daily-usage-report.d.ts +2 -0
- package/dist/runtime/server/tasks/send-daily-usage-report.js +73 -0
- package/dist/runtime/server/tsconfig.json +21 -0
- package/dist/runtime/server/utils/agent-api.d.ts +39 -0
- package/dist/runtime/server/utils/agent-api.js +169 -0
- package/dist/runtime/server/utils/auth-api.d.ts +1 -0
- package/dist/runtime/server/utils/auth-api.js +25 -0
- package/dist/runtime/server/utils/auth.d.ts +17 -0
- package/dist/runtime/server/utils/auth.js +28 -0
- package/dist/runtime/server/utils/billing.d.ts +37 -0
- package/dist/runtime/server/utils/billing.js +68 -0
- package/dist/runtime/server/utils/chat-context.d.ts +9 -0
- package/dist/runtime/server/utils/chat-context.js +24 -0
- package/dist/runtime/server/utils/chat-message-builder.d.ts +4 -0
- package/dist/runtime/server/utils/chat-message-builder.js +39 -0
- package/dist/runtime/server/utils/chat-prompts.d.ts +7 -0
- package/dist/runtime/server/utils/chat-prompts.js +9 -0
- package/dist/runtime/server/utils/chat-workspace-settings.d.ts +16 -0
- package/dist/runtime/server/utils/chat-workspace-settings.js +115 -0
- package/dist/runtime/server/utils/external-skills.d.ts +2 -0
- package/dist/runtime/server/utils/external-skills.js +15 -0
- package/dist/runtime/server/utils/logger.d.ts +2 -0
- package/dist/runtime/server/utils/logger.js +12 -0
- package/dist/runtime/server/utils/slack.d.ts +32 -0
- package/dist/runtime/server/utils/slack.js +102 -0
- package/dist/runtime/server/utils/tela-api.d.ts +2 -0
- package/dist/runtime/server/utils/tela-api.js +29 -0
- package/dist/runtime/server/utils/vault.d.ts +3 -0
- package/dist/runtime/server/utils/vault.js +52 -0
- package/dist/runtime/server/utils/workspace-settings-resolver.stub.d.ts +2 -0
- package/dist/runtime/server/utils/workspace-settings-resolver.stub.js +1 -0
- package/dist/runtime/server/utils/workspace.d.ts +4 -0
- package/dist/runtime/server/utils/workspace.js +21 -0
- package/dist/runtime/types/agent.d.ts +168 -0
- package/dist/runtime/types/agent.js +95 -0
- package/dist/runtime/types/chat-workspace-settings-resolver.d.ts +4 -0
- package/dist/runtime/types/chat.d.ts +81 -0
- package/dist/runtime/types/chat.js +12 -0
- package/dist/runtime/types/credential.d.ts +8 -0
- package/dist/runtime/types/credential.js +0 -0
- package/dist/runtime/types/csv.d.ts +4 -0
- package/dist/runtime/types/csv.js +0 -0
- package/dist/runtime/types/external-skills.d.ts +8 -0
- package/dist/runtime/types/external-skills.js +0 -0
- package/dist/runtime/types/feature-flags.d.ts +7 -0
- package/dist/runtime/types/feature-flags.js +6 -0
- package/dist/runtime/types/reasoning.d.ts +17 -0
- package/dist/runtime/types/reasoning.js +0 -0
- package/dist/runtime/types/tela.d.ts +46 -0
- package/dist/runtime/types/tela.js +0 -0
- package/dist/runtime/types/workspace.d.ts +20 -0
- package/dist/runtime/types/workspace.js +0 -0
- package/dist/runtime/utils/calculate-usage.d.ts +48 -0
- package/dist/runtime/utils/calculate-usage.js +63 -0
- package/dist/runtime/utils/code-detection.d.ts +1 -0
- package/dist/runtime/utils/code-detection.js +24 -0
- package/dist/runtime/utils/export-conversation.d.ts +2 -0
- package/dist/runtime/utils/export-conversation.js +43 -0
- package/dist/runtime/utils/file.d.ts +46 -0
- package/dist/runtime/utils/file.js +500 -0
- package/dist/runtime/utils/format-time.d.ts +22 -0
- package/dist/runtime/utils/format-time.js +96 -0
- package/dist/runtime/utils/markdown-nodes.d.ts +22 -0
- package/dist/runtime/utils/markdown-nodes.js +40 -0
- package/dist/runtime/utils/string.d.ts +4 -0
- package/dist/runtime/utils/string.js +5 -0
- package/dist/runtime/utils/tela-chat.d.ts +19 -0
- package/dist/runtime/utils/tela-chat.js +20 -0
- package/dist/types.d.mts +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { and, eq, gte, lte, sql, desc } from "drizzle-orm";
|
|
2
|
+
import { useDb, schema } from "#chat-runtime/server/db";
|
|
3
|
+
import { requireUser } from "#chat-runtime/server/utils/auth";
|
|
4
|
+
import { getWorkspaceBilling, transformCostForBilling } from "#chat-runtime/server/utils/billing";
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const session = requireUser(event);
|
|
7
|
+
const db = useDb();
|
|
8
|
+
const query = getQuery(event);
|
|
9
|
+
const startDate = query.startDate ? new Date(query.startDate) : void 0;
|
|
10
|
+
const endDate = query.endDate ? new Date(query.endDate) : void 0;
|
|
11
|
+
const groupBy = query.groupBy;
|
|
12
|
+
const cursor = query.cursor;
|
|
13
|
+
const limit = Math.min(Number(query.limit) || 100, 250);
|
|
14
|
+
const conditions = [eq(schema.conversationUsage.workspaceId, session.workspace.id)];
|
|
15
|
+
if (startDate && !Number.isNaN(startDate.getTime())) {
|
|
16
|
+
conditions.push(gte(schema.conversationUsage.createdAt, startDate));
|
|
17
|
+
}
|
|
18
|
+
if (endDate && !Number.isNaN(endDate.getTime())) {
|
|
19
|
+
conditions.push(lte(schema.conversationUsage.createdAt, endDate));
|
|
20
|
+
}
|
|
21
|
+
if (cursor) {
|
|
22
|
+
const [cursorDate, cursorId] = cursor.split("_");
|
|
23
|
+
const parsedDate = new Date(cursorDate);
|
|
24
|
+
if (!Number.isNaN(parsedDate.getTime()) && cursorId) {
|
|
25
|
+
conditions.push(
|
|
26
|
+
sql`(${schema.conversationUsage.createdAt}, ${schema.conversationUsage.id}) < (${parsedDate}, ${cursorId})`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const [totals] = await db.select({
|
|
31
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
32
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
33
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
34
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
35
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
36
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`
|
|
37
|
+
}).from(schema.conversationUsage).where(and(...conditions));
|
|
38
|
+
const records = await db.select({
|
|
39
|
+
id: schema.conversationUsage.id,
|
|
40
|
+
conversationId: schema.conversationUsage.conversationId,
|
|
41
|
+
promptTokens: schema.conversationUsage.promptTokens,
|
|
42
|
+
completionTokens: schema.conversationUsage.completionTokens,
|
|
43
|
+
totalTokens: schema.conversationUsage.totalTokens,
|
|
44
|
+
promptCost: schema.conversationUsage.promptCost,
|
|
45
|
+
completionCost: schema.conversationUsage.completionCost,
|
|
46
|
+
totalCost: schema.conversationUsage.totalCost,
|
|
47
|
+
durationMs: schema.conversationUsage.durationMs,
|
|
48
|
+
turns: schema.conversationUsage.turns,
|
|
49
|
+
userId: schema.conversationUsage.userId,
|
|
50
|
+
userEmail: schema.conversationUsage.userEmail,
|
|
51
|
+
model: schema.conversationUsage.model,
|
|
52
|
+
createdAt: schema.conversationUsage.createdAt
|
|
53
|
+
}).from(schema.conversationUsage).where(and(...conditions)).orderBy(desc(schema.conversationUsage.createdAt)).limit(limit + 1);
|
|
54
|
+
const hasMore = records.length > limit;
|
|
55
|
+
const paginatedRecords = records.slice(0, limit);
|
|
56
|
+
const billing = await getWorkspaceBilling(session.workspace.id);
|
|
57
|
+
const formattedRecords = paginatedRecords.map((r) => {
|
|
58
|
+
const transformedCosts = transformCostForBilling({
|
|
59
|
+
promptCost: Number(r.promptCost),
|
|
60
|
+
completionCost: Number(r.completionCost),
|
|
61
|
+
totalCost: Number(r.totalCost),
|
|
62
|
+
promptTokens: r.promptTokens,
|
|
63
|
+
completionTokens: r.completionTokens
|
|
64
|
+
}, billing);
|
|
65
|
+
return {
|
|
66
|
+
...r,
|
|
67
|
+
...transformedCosts
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const totalsCosts = transformCostForBilling({
|
|
71
|
+
promptCost: totals?.promptCost ?? 0,
|
|
72
|
+
completionCost: totals?.completionCost ?? 0,
|
|
73
|
+
totalCost: totals?.totalCost ?? 0,
|
|
74
|
+
promptTokens: totals?.promptTokens ?? 0,
|
|
75
|
+
completionTokens: totals?.completionTokens ?? 0
|
|
76
|
+
}, billing);
|
|
77
|
+
const response = {
|
|
78
|
+
usage: {
|
|
79
|
+
totalTokens: totals?.totalTokens ?? 0,
|
|
80
|
+
totalCost: totalsCosts.totalCost,
|
|
81
|
+
breakdown: {
|
|
82
|
+
promptTokens: totals?.promptTokens ?? 0,
|
|
83
|
+
completionTokens: totals?.completionTokens ?? 0,
|
|
84
|
+
promptCost: totalsCosts.promptCost,
|
|
85
|
+
completionCost: totalsCosts.completionCost
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
records: formattedRecords,
|
|
89
|
+
hasMore,
|
|
90
|
+
billing
|
|
91
|
+
};
|
|
92
|
+
if (hasMore && paginatedRecords.length > 0) {
|
|
93
|
+
const lastRecord = paginatedRecords[paginatedRecords.length - 1];
|
|
94
|
+
response.cursor = `${lastRecord?.createdAt.toISOString()}_${lastRecord?.id}`;
|
|
95
|
+
}
|
|
96
|
+
if (groupBy) {
|
|
97
|
+
let groupedQuery;
|
|
98
|
+
switch (groupBy) {
|
|
99
|
+
case "day":
|
|
100
|
+
groupedQuery = db.select({
|
|
101
|
+
key: sql`DATE_TRUNC('day', ${schema.conversationUsage.createdAt})::text`,
|
|
102
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
103
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
104
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
105
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
106
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
107
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`,
|
|
108
|
+
count: sql`COUNT(*)::int`
|
|
109
|
+
}).from(schema.conversationUsage).where(and(...conditions)).groupBy(sql`DATE_TRUNC('day', ${schema.conversationUsage.createdAt})`).orderBy(sql`DATE_TRUNC('day', ${schema.conversationUsage.createdAt}) DESC`);
|
|
110
|
+
break;
|
|
111
|
+
case "week":
|
|
112
|
+
groupedQuery = db.select({
|
|
113
|
+
key: sql`DATE_TRUNC('week', ${schema.conversationUsage.createdAt})::text`,
|
|
114
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
115
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
116
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
117
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
118
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
119
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`,
|
|
120
|
+
count: sql`COUNT(*)::int`
|
|
121
|
+
}).from(schema.conversationUsage).where(and(...conditions)).groupBy(sql`DATE_TRUNC('week', ${schema.conversationUsage.createdAt})`).orderBy(sql`DATE_TRUNC('week', ${schema.conversationUsage.createdAt}) DESC`);
|
|
122
|
+
break;
|
|
123
|
+
case "month":
|
|
124
|
+
groupedQuery = db.select({
|
|
125
|
+
key: sql`DATE_TRUNC('month', ${schema.conversationUsage.createdAt})::text`,
|
|
126
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
127
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
128
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
129
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
130
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
131
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`,
|
|
132
|
+
count: sql`COUNT(*)::int`
|
|
133
|
+
}).from(schema.conversationUsage).where(and(...conditions)).groupBy(sql`DATE_TRUNC('month', ${schema.conversationUsage.createdAt})`).orderBy(sql`DATE_TRUNC('month', ${schema.conversationUsage.createdAt}) DESC`);
|
|
134
|
+
break;
|
|
135
|
+
case "user":
|
|
136
|
+
groupedQuery = db.select({
|
|
137
|
+
key: schema.conversationUsage.userId,
|
|
138
|
+
label: schema.conversationUsage.userEmail,
|
|
139
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
140
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
141
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
142
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
143
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
144
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`,
|
|
145
|
+
count: sql`COUNT(*)::int`
|
|
146
|
+
}).from(schema.conversationUsage).where(and(...conditions)).groupBy(schema.conversationUsage.userId, schema.conversationUsage.userEmail).orderBy(sql`SUM(${schema.conversationUsage.totalCost}::numeric) DESC`);
|
|
147
|
+
break;
|
|
148
|
+
case "conversation":
|
|
149
|
+
groupedQuery = db.select({
|
|
150
|
+
key: schema.conversationUsage.conversationId,
|
|
151
|
+
totalTokens: sql`COALESCE(SUM(${schema.conversationUsage.totalTokens}), 0)::int`,
|
|
152
|
+
promptTokens: sql`COALESCE(SUM(${schema.conversationUsage.promptTokens}), 0)::int`,
|
|
153
|
+
completionTokens: sql`COALESCE(SUM(${schema.conversationUsage.completionTokens}), 0)::int`,
|
|
154
|
+
totalCost: sql`COALESCE(SUM(${schema.conversationUsage.totalCost}::numeric), 0)::float`,
|
|
155
|
+
promptCost: sql`COALESCE(SUM(${schema.conversationUsage.promptCost}::numeric), 0)::float`,
|
|
156
|
+
completionCost: sql`COALESCE(SUM(${schema.conversationUsage.completionCost}::numeric), 0)::float`,
|
|
157
|
+
count: sql`COUNT(*)::int`
|
|
158
|
+
}).from(schema.conversationUsage).where(and(...conditions)).groupBy(schema.conversationUsage.conversationId).orderBy(sql`SUM(${schema.conversationUsage.totalCost}::numeric) DESC`);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (groupedQuery) {
|
|
162
|
+
const groupedResults = await groupedQuery;
|
|
163
|
+
response.grouped = groupedResults.map((r) => {
|
|
164
|
+
const transformedCosts = transformCostForBilling({
|
|
165
|
+
promptCost: r.promptCost,
|
|
166
|
+
completionCost: r.completionCost,
|
|
167
|
+
totalCost: r.totalCost,
|
|
168
|
+
promptTokens: r.promptTokens,
|
|
169
|
+
completionTokens: r.completionTokens
|
|
170
|
+
}, billing);
|
|
171
|
+
return {
|
|
172
|
+
key: r.key,
|
|
173
|
+
label: "label" in r ? r.label ?? r.key : r.key,
|
|
174
|
+
totalTokens: r.totalTokens,
|
|
175
|
+
promptTokens: r.promptTokens,
|
|
176
|
+
completionTokens: r.completionTokens,
|
|
177
|
+
totalCost: transformedCosts.totalCost,
|
|
178
|
+
promptCost: transformedCosts.promptCost,
|
|
179
|
+
completionCost: transformedCosts.completionCost,
|
|
180
|
+
count: r.count
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return response;
|
|
186
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as schema from './schema.js';
|
|
2
|
+
export type { ContextFile, ExternalSkill } from './schema.js';
|
|
3
|
+
export declare function useDb(): import("drizzle-orm/postgres-js").PostgresJsDatabase<Record<string, unknown>> & {
|
|
4
|
+
$client: import("postgres").Sql<{}>;
|
|
5
|
+
};
|
|
6
|
+
export { schema };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import postgres from "postgres";
|
|
2
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
3
|
+
import * as schema from "./schema/index.js";
|
|
4
|
+
import { logger } from "#chat-runtime/server/utils/logger";
|
|
5
|
+
let dbInstance = null;
|
|
6
|
+
export function useDb() {
|
|
7
|
+
if (dbInstance) {
|
|
8
|
+
return dbInstance;
|
|
9
|
+
}
|
|
10
|
+
const config = useRuntimeConfig();
|
|
11
|
+
if (!config.databaseUrl) {
|
|
12
|
+
throw new Error("DATABASE_URL is not configured");
|
|
13
|
+
}
|
|
14
|
+
const client = postgres(config.databaseUrl, { max: 10 });
|
|
15
|
+
dbInstance = drizzle(client, { schema });
|
|
16
|
+
logger.info("Database connection pool initialized");
|
|
17
|
+
return dbInstance;
|
|
18
|
+
}
|
|
19
|
+
export { schema };
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
export type ConversationUsageMetadata = {
|
|
2
|
+
filesUsed?: {
|
|
3
|
+
name: string;
|
|
4
|
+
mimeType?: string;
|
|
5
|
+
source: 'user' | 'context';
|
|
6
|
+
}[];
|
|
7
|
+
toolsInvoked?: string[];
|
|
8
|
+
knowledgeSourcesUsed?: string[];
|
|
9
|
+
hasCanvasTools?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ModelUsageEntry = {
|
|
12
|
+
inputTokens?: number | null;
|
|
13
|
+
outputTokens?: number | null;
|
|
14
|
+
cacheReadInputTokens?: number | null;
|
|
15
|
+
cacheCreationInputTokens?: number | null;
|
|
16
|
+
webSearchRequests?: number | null;
|
|
17
|
+
costUSD?: number | null;
|
|
18
|
+
contextWindow?: number | null;
|
|
19
|
+
};
|
|
20
|
+
export declare const conversationUsage: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
21
|
+
name: "conversation_usage";
|
|
22
|
+
schema: undefined;
|
|
23
|
+
columns: {
|
|
24
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
25
|
+
name: "id";
|
|
26
|
+
tableName: "conversation_usage";
|
|
27
|
+
dataType: "string";
|
|
28
|
+
columnType: "PgUUID";
|
|
29
|
+
data: string;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
notNull: true;
|
|
32
|
+
hasDefault: true;
|
|
33
|
+
isPrimaryKey: true;
|
|
34
|
+
isAutoincrement: false;
|
|
35
|
+
hasRuntimeDefault: false;
|
|
36
|
+
enumValues: undefined;
|
|
37
|
+
baseColumn: never;
|
|
38
|
+
identity: undefined;
|
|
39
|
+
generated: undefined;
|
|
40
|
+
}, {}, {}>;
|
|
41
|
+
workspaceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
42
|
+
name: "workspace_id";
|
|
43
|
+
tableName: "conversation_usage";
|
|
44
|
+
dataType: "string";
|
|
45
|
+
columnType: "PgText";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
notNull: true;
|
|
49
|
+
hasDefault: false;
|
|
50
|
+
isPrimaryKey: false;
|
|
51
|
+
isAutoincrement: false;
|
|
52
|
+
hasRuntimeDefault: false;
|
|
53
|
+
enumValues: [string, ...string[]];
|
|
54
|
+
baseColumn: never;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}, {}, {}>;
|
|
58
|
+
conversationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
59
|
+
name: "conversation_id";
|
|
60
|
+
tableName: "conversation_usage";
|
|
61
|
+
dataType: "string";
|
|
62
|
+
columnType: "PgUUID";
|
|
63
|
+
data: string;
|
|
64
|
+
driverParam: string;
|
|
65
|
+
notNull: true;
|
|
66
|
+
hasDefault: false;
|
|
67
|
+
isPrimaryKey: false;
|
|
68
|
+
isAutoincrement: false;
|
|
69
|
+
hasRuntimeDefault: false;
|
|
70
|
+
enumValues: undefined;
|
|
71
|
+
baseColumn: never;
|
|
72
|
+
identity: undefined;
|
|
73
|
+
generated: undefined;
|
|
74
|
+
}, {}, {}>;
|
|
75
|
+
promptTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
76
|
+
name: "prompt_tokens";
|
|
77
|
+
tableName: "conversation_usage";
|
|
78
|
+
dataType: "number";
|
|
79
|
+
columnType: "PgInteger";
|
|
80
|
+
data: number;
|
|
81
|
+
driverParam: string | number;
|
|
82
|
+
notNull: true;
|
|
83
|
+
hasDefault: false;
|
|
84
|
+
isPrimaryKey: false;
|
|
85
|
+
isAutoincrement: false;
|
|
86
|
+
hasRuntimeDefault: false;
|
|
87
|
+
enumValues: undefined;
|
|
88
|
+
baseColumn: never;
|
|
89
|
+
identity: undefined;
|
|
90
|
+
generated: undefined;
|
|
91
|
+
}, {}, {}>;
|
|
92
|
+
completionTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
93
|
+
name: "completion_tokens";
|
|
94
|
+
tableName: "conversation_usage";
|
|
95
|
+
dataType: "number";
|
|
96
|
+
columnType: "PgInteger";
|
|
97
|
+
data: number;
|
|
98
|
+
driverParam: string | number;
|
|
99
|
+
notNull: true;
|
|
100
|
+
hasDefault: false;
|
|
101
|
+
isPrimaryKey: false;
|
|
102
|
+
isAutoincrement: false;
|
|
103
|
+
hasRuntimeDefault: false;
|
|
104
|
+
enumValues: undefined;
|
|
105
|
+
baseColumn: never;
|
|
106
|
+
identity: undefined;
|
|
107
|
+
generated: undefined;
|
|
108
|
+
}, {}, {}>;
|
|
109
|
+
totalTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
110
|
+
name: "total_tokens";
|
|
111
|
+
tableName: "conversation_usage";
|
|
112
|
+
dataType: "number";
|
|
113
|
+
columnType: "PgInteger";
|
|
114
|
+
data: number;
|
|
115
|
+
driverParam: string | number;
|
|
116
|
+
notNull: true;
|
|
117
|
+
hasDefault: false;
|
|
118
|
+
isPrimaryKey: false;
|
|
119
|
+
isAutoincrement: false;
|
|
120
|
+
hasRuntimeDefault: false;
|
|
121
|
+
enumValues: undefined;
|
|
122
|
+
baseColumn: never;
|
|
123
|
+
identity: undefined;
|
|
124
|
+
generated: undefined;
|
|
125
|
+
}, {}, {}>;
|
|
126
|
+
promptCost: import("drizzle-orm/pg-core").PgColumn<{
|
|
127
|
+
name: "prompt_cost";
|
|
128
|
+
tableName: "conversation_usage";
|
|
129
|
+
dataType: "string";
|
|
130
|
+
columnType: "PgNumeric";
|
|
131
|
+
data: string;
|
|
132
|
+
driverParam: string;
|
|
133
|
+
notNull: true;
|
|
134
|
+
hasDefault: false;
|
|
135
|
+
isPrimaryKey: false;
|
|
136
|
+
isAutoincrement: false;
|
|
137
|
+
hasRuntimeDefault: false;
|
|
138
|
+
enumValues: undefined;
|
|
139
|
+
baseColumn: never;
|
|
140
|
+
identity: undefined;
|
|
141
|
+
generated: undefined;
|
|
142
|
+
}, {}, {}>;
|
|
143
|
+
completionCost: import("drizzle-orm/pg-core").PgColumn<{
|
|
144
|
+
name: "completion_cost";
|
|
145
|
+
tableName: "conversation_usage";
|
|
146
|
+
dataType: "string";
|
|
147
|
+
columnType: "PgNumeric";
|
|
148
|
+
data: string;
|
|
149
|
+
driverParam: string;
|
|
150
|
+
notNull: true;
|
|
151
|
+
hasDefault: false;
|
|
152
|
+
isPrimaryKey: false;
|
|
153
|
+
isAutoincrement: false;
|
|
154
|
+
hasRuntimeDefault: false;
|
|
155
|
+
enumValues: undefined;
|
|
156
|
+
baseColumn: never;
|
|
157
|
+
identity: undefined;
|
|
158
|
+
generated: undefined;
|
|
159
|
+
}, {}, {}>;
|
|
160
|
+
totalCost: import("drizzle-orm/pg-core").PgColumn<{
|
|
161
|
+
name: "total_cost";
|
|
162
|
+
tableName: "conversation_usage";
|
|
163
|
+
dataType: "string";
|
|
164
|
+
columnType: "PgNumeric";
|
|
165
|
+
data: string;
|
|
166
|
+
driverParam: string;
|
|
167
|
+
notNull: true;
|
|
168
|
+
hasDefault: false;
|
|
169
|
+
isPrimaryKey: false;
|
|
170
|
+
isAutoincrement: false;
|
|
171
|
+
hasRuntimeDefault: false;
|
|
172
|
+
enumValues: undefined;
|
|
173
|
+
baseColumn: never;
|
|
174
|
+
identity: undefined;
|
|
175
|
+
generated: undefined;
|
|
176
|
+
}, {}, {}>;
|
|
177
|
+
durationMs: import("drizzle-orm/pg-core").PgColumn<{
|
|
178
|
+
name: "duration_ms";
|
|
179
|
+
tableName: "conversation_usage";
|
|
180
|
+
dataType: "number";
|
|
181
|
+
columnType: "PgInteger";
|
|
182
|
+
data: number;
|
|
183
|
+
driverParam: string | number;
|
|
184
|
+
notNull: false;
|
|
185
|
+
hasDefault: false;
|
|
186
|
+
isPrimaryKey: false;
|
|
187
|
+
isAutoincrement: false;
|
|
188
|
+
hasRuntimeDefault: false;
|
|
189
|
+
enumValues: undefined;
|
|
190
|
+
baseColumn: never;
|
|
191
|
+
identity: undefined;
|
|
192
|
+
generated: undefined;
|
|
193
|
+
}, {}, {}>;
|
|
194
|
+
turns: import("drizzle-orm/pg-core").PgColumn<{
|
|
195
|
+
name: "turns";
|
|
196
|
+
tableName: "conversation_usage";
|
|
197
|
+
dataType: "number";
|
|
198
|
+
columnType: "PgInteger";
|
|
199
|
+
data: number;
|
|
200
|
+
driverParam: string | number;
|
|
201
|
+
notNull: false;
|
|
202
|
+
hasDefault: false;
|
|
203
|
+
isPrimaryKey: false;
|
|
204
|
+
isAutoincrement: false;
|
|
205
|
+
hasRuntimeDefault: false;
|
|
206
|
+
enumValues: undefined;
|
|
207
|
+
baseColumn: never;
|
|
208
|
+
identity: undefined;
|
|
209
|
+
generated: undefined;
|
|
210
|
+
}, {}, {}>;
|
|
211
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
212
|
+
name: "user_id";
|
|
213
|
+
tableName: "conversation_usage";
|
|
214
|
+
dataType: "string";
|
|
215
|
+
columnType: "PgText";
|
|
216
|
+
data: string;
|
|
217
|
+
driverParam: string;
|
|
218
|
+
notNull: true;
|
|
219
|
+
hasDefault: false;
|
|
220
|
+
isPrimaryKey: false;
|
|
221
|
+
isAutoincrement: false;
|
|
222
|
+
hasRuntimeDefault: false;
|
|
223
|
+
enumValues: [string, ...string[]];
|
|
224
|
+
baseColumn: never;
|
|
225
|
+
identity: undefined;
|
|
226
|
+
generated: undefined;
|
|
227
|
+
}, {}, {}>;
|
|
228
|
+
userEmail: import("drizzle-orm/pg-core").PgColumn<{
|
|
229
|
+
name: "user_email";
|
|
230
|
+
tableName: "conversation_usage";
|
|
231
|
+
dataType: "string";
|
|
232
|
+
columnType: "PgText";
|
|
233
|
+
data: string;
|
|
234
|
+
driverParam: string;
|
|
235
|
+
notNull: false;
|
|
236
|
+
hasDefault: false;
|
|
237
|
+
isPrimaryKey: false;
|
|
238
|
+
isAutoincrement: false;
|
|
239
|
+
hasRuntimeDefault: false;
|
|
240
|
+
enumValues: [string, ...string[]];
|
|
241
|
+
baseColumn: never;
|
|
242
|
+
identity: undefined;
|
|
243
|
+
generated: undefined;
|
|
244
|
+
}, {}, {}>;
|
|
245
|
+
model: import("drizzle-orm/pg-core").PgColumn<{
|
|
246
|
+
name: "model";
|
|
247
|
+
tableName: "conversation_usage";
|
|
248
|
+
dataType: "string";
|
|
249
|
+
columnType: "PgText";
|
|
250
|
+
data: string;
|
|
251
|
+
driverParam: string;
|
|
252
|
+
notNull: false;
|
|
253
|
+
hasDefault: false;
|
|
254
|
+
isPrimaryKey: false;
|
|
255
|
+
isAutoincrement: false;
|
|
256
|
+
hasRuntimeDefault: false;
|
|
257
|
+
enumValues: [string, ...string[]];
|
|
258
|
+
baseColumn: never;
|
|
259
|
+
identity: undefined;
|
|
260
|
+
generated: undefined;
|
|
261
|
+
}, {}, {}>;
|
|
262
|
+
sessionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
263
|
+
name: "session_id";
|
|
264
|
+
tableName: "conversation_usage";
|
|
265
|
+
dataType: "string";
|
|
266
|
+
columnType: "PgText";
|
|
267
|
+
data: string;
|
|
268
|
+
driverParam: string;
|
|
269
|
+
notNull: false;
|
|
270
|
+
hasDefault: false;
|
|
271
|
+
isPrimaryKey: false;
|
|
272
|
+
isAutoincrement: false;
|
|
273
|
+
hasRuntimeDefault: false;
|
|
274
|
+
enumValues: [string, ...string[]];
|
|
275
|
+
baseColumn: never;
|
|
276
|
+
identity: undefined;
|
|
277
|
+
generated: undefined;
|
|
278
|
+
}, {}, {}>;
|
|
279
|
+
cacheReadInputTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
280
|
+
name: "cache_read_input_tokens";
|
|
281
|
+
tableName: "conversation_usage";
|
|
282
|
+
dataType: "number";
|
|
283
|
+
columnType: "PgInteger";
|
|
284
|
+
data: number;
|
|
285
|
+
driverParam: string | number;
|
|
286
|
+
notNull: false;
|
|
287
|
+
hasDefault: false;
|
|
288
|
+
isPrimaryKey: false;
|
|
289
|
+
isAutoincrement: false;
|
|
290
|
+
hasRuntimeDefault: false;
|
|
291
|
+
enumValues: undefined;
|
|
292
|
+
baseColumn: never;
|
|
293
|
+
identity: undefined;
|
|
294
|
+
generated: undefined;
|
|
295
|
+
}, {}, {}>;
|
|
296
|
+
cacheCreationInputTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
297
|
+
name: "cache_creation_input_tokens";
|
|
298
|
+
tableName: "conversation_usage";
|
|
299
|
+
dataType: "number";
|
|
300
|
+
columnType: "PgInteger";
|
|
301
|
+
data: number;
|
|
302
|
+
driverParam: string | number;
|
|
303
|
+
notNull: false;
|
|
304
|
+
hasDefault: false;
|
|
305
|
+
isPrimaryKey: false;
|
|
306
|
+
isAutoincrement: false;
|
|
307
|
+
hasRuntimeDefault: false;
|
|
308
|
+
enumValues: undefined;
|
|
309
|
+
baseColumn: never;
|
|
310
|
+
identity: undefined;
|
|
311
|
+
generated: undefined;
|
|
312
|
+
}, {}, {}>;
|
|
313
|
+
modelUsage: import("drizzle-orm/pg-core").PgColumn<{
|
|
314
|
+
name: "model_usage";
|
|
315
|
+
tableName: "conversation_usage";
|
|
316
|
+
dataType: "json";
|
|
317
|
+
columnType: "PgJsonb";
|
|
318
|
+
data: Record<string, ModelUsageEntry>;
|
|
319
|
+
driverParam: unknown;
|
|
320
|
+
notNull: false;
|
|
321
|
+
hasDefault: false;
|
|
322
|
+
isPrimaryKey: false;
|
|
323
|
+
isAutoincrement: false;
|
|
324
|
+
hasRuntimeDefault: false;
|
|
325
|
+
enumValues: undefined;
|
|
326
|
+
baseColumn: never;
|
|
327
|
+
identity: undefined;
|
|
328
|
+
generated: undefined;
|
|
329
|
+
}, {}, {
|
|
330
|
+
$type: Record<string, ModelUsageEntry>;
|
|
331
|
+
}>;
|
|
332
|
+
durationApiMs: import("drizzle-orm/pg-core").PgColumn<{
|
|
333
|
+
name: "duration_api_ms";
|
|
334
|
+
tableName: "conversation_usage";
|
|
335
|
+
dataType: "number";
|
|
336
|
+
columnType: "PgInteger";
|
|
337
|
+
data: number;
|
|
338
|
+
driverParam: string | number;
|
|
339
|
+
notNull: false;
|
|
340
|
+
hasDefault: false;
|
|
341
|
+
isPrimaryKey: false;
|
|
342
|
+
isAutoincrement: false;
|
|
343
|
+
hasRuntimeDefault: false;
|
|
344
|
+
enumValues: undefined;
|
|
345
|
+
baseColumn: never;
|
|
346
|
+
identity: undefined;
|
|
347
|
+
generated: undefined;
|
|
348
|
+
}, {}, {}>;
|
|
349
|
+
webSearchRequests: import("drizzle-orm/pg-core").PgColumn<{
|
|
350
|
+
name: "web_search_requests";
|
|
351
|
+
tableName: "conversation_usage";
|
|
352
|
+
dataType: "number";
|
|
353
|
+
columnType: "PgInteger";
|
|
354
|
+
data: number;
|
|
355
|
+
driverParam: string | number;
|
|
356
|
+
notNull: false;
|
|
357
|
+
hasDefault: false;
|
|
358
|
+
isPrimaryKey: false;
|
|
359
|
+
isAutoincrement: false;
|
|
360
|
+
hasRuntimeDefault: false;
|
|
361
|
+
enumValues: undefined;
|
|
362
|
+
baseColumn: never;
|
|
363
|
+
identity: undefined;
|
|
364
|
+
generated: undefined;
|
|
365
|
+
}, {}, {}>;
|
|
366
|
+
webFetchRequests: import("drizzle-orm/pg-core").PgColumn<{
|
|
367
|
+
name: "web_fetch_requests";
|
|
368
|
+
tableName: "conversation_usage";
|
|
369
|
+
dataType: "number";
|
|
370
|
+
columnType: "PgInteger";
|
|
371
|
+
data: number;
|
|
372
|
+
driverParam: string | number;
|
|
373
|
+
notNull: false;
|
|
374
|
+
hasDefault: false;
|
|
375
|
+
isPrimaryKey: false;
|
|
376
|
+
isAutoincrement: false;
|
|
377
|
+
hasRuntimeDefault: false;
|
|
378
|
+
enumValues: undefined;
|
|
379
|
+
baseColumn: never;
|
|
380
|
+
identity: undefined;
|
|
381
|
+
generated: undefined;
|
|
382
|
+
}, {}, {}>;
|
|
383
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
384
|
+
name: "metadata";
|
|
385
|
+
tableName: "conversation_usage";
|
|
386
|
+
dataType: "json";
|
|
387
|
+
columnType: "PgJsonb";
|
|
388
|
+
data: ConversationUsageMetadata;
|
|
389
|
+
driverParam: unknown;
|
|
390
|
+
notNull: false;
|
|
391
|
+
hasDefault: false;
|
|
392
|
+
isPrimaryKey: false;
|
|
393
|
+
isAutoincrement: false;
|
|
394
|
+
hasRuntimeDefault: false;
|
|
395
|
+
enumValues: undefined;
|
|
396
|
+
baseColumn: never;
|
|
397
|
+
identity: undefined;
|
|
398
|
+
generated: undefined;
|
|
399
|
+
}, {}, {
|
|
400
|
+
$type: ConversationUsageMetadata;
|
|
401
|
+
}>;
|
|
402
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
403
|
+
name: "created_at";
|
|
404
|
+
tableName: "conversation_usage";
|
|
405
|
+
dataType: "date";
|
|
406
|
+
columnType: "PgTimestamp";
|
|
407
|
+
data: Date;
|
|
408
|
+
driverParam: string;
|
|
409
|
+
notNull: true;
|
|
410
|
+
hasDefault: true;
|
|
411
|
+
isPrimaryKey: false;
|
|
412
|
+
isAutoincrement: false;
|
|
413
|
+
hasRuntimeDefault: false;
|
|
414
|
+
enumValues: undefined;
|
|
415
|
+
baseColumn: never;
|
|
416
|
+
identity: undefined;
|
|
417
|
+
generated: undefined;
|
|
418
|
+
}, {}, {}>;
|
|
419
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
420
|
+
name: "updated_at";
|
|
421
|
+
tableName: "conversation_usage";
|
|
422
|
+
dataType: "date";
|
|
423
|
+
columnType: "PgTimestamp";
|
|
424
|
+
data: Date;
|
|
425
|
+
driverParam: string;
|
|
426
|
+
notNull: true;
|
|
427
|
+
hasDefault: true;
|
|
428
|
+
isPrimaryKey: false;
|
|
429
|
+
isAutoincrement: false;
|
|
430
|
+
hasRuntimeDefault: false;
|
|
431
|
+
enumValues: undefined;
|
|
432
|
+
baseColumn: never;
|
|
433
|
+
identity: undefined;
|
|
434
|
+
generated: undefined;
|
|
435
|
+
}, {}, {}>;
|
|
436
|
+
};
|
|
437
|
+
dialect: "pg";
|
|
438
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { pgTable, uuid, text, timestamp, index, jsonb, integer, numeric, unique } from "drizzle-orm/pg-core";
|
|
2
|
+
import { conversations } from "./conversations.js";
|
|
3
|
+
export const conversationUsage = pgTable("conversation_usage", {
|
|
4
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
5
|
+
workspaceId: text("workspace_id").notNull(),
|
|
6
|
+
conversationId: uuid("conversation_id").notNull().references(() => conversations.id, { onDelete: "cascade" }),
|
|
7
|
+
promptTokens: integer("prompt_tokens").notNull(),
|
|
8
|
+
completionTokens: integer("completion_tokens").notNull(),
|
|
9
|
+
totalTokens: integer("total_tokens").notNull(),
|
|
10
|
+
promptCost: numeric("prompt_cost", { precision: 12, scale: 8 }).notNull(),
|
|
11
|
+
completionCost: numeric("completion_cost", { precision: 12, scale: 8 }).notNull(),
|
|
12
|
+
totalCost: numeric("total_cost", { precision: 12, scale: 8 }).notNull(),
|
|
13
|
+
durationMs: integer("duration_ms"),
|
|
14
|
+
turns: integer("turns"),
|
|
15
|
+
userId: text("user_id").notNull(),
|
|
16
|
+
userEmail: text("user_email"),
|
|
17
|
+
model: text("model"),
|
|
18
|
+
sessionId: text("session_id"),
|
|
19
|
+
cacheReadInputTokens: integer("cache_read_input_tokens"),
|
|
20
|
+
cacheCreationInputTokens: integer("cache_creation_input_tokens"),
|
|
21
|
+
modelUsage: jsonb("model_usage").$type(),
|
|
22
|
+
durationApiMs: integer("duration_api_ms"),
|
|
23
|
+
webSearchRequests: integer("web_search_requests"),
|
|
24
|
+
webFetchRequests: integer("web_fetch_requests"),
|
|
25
|
+
metadata: jsonb("metadata").$type(),
|
|
26
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
27
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull()
|
|
28
|
+
}, (table) => [
|
|
29
|
+
unique("conversation_usage_conversation_id_unique").on(table.conversationId),
|
|
30
|
+
index("idx_usage_workspace").on(table.workspaceId),
|
|
31
|
+
index("idx_usage_workspace_created").on(table.workspaceId, table.createdAt),
|
|
32
|
+
index("idx_usage_conversation").on(table.conversationId),
|
|
33
|
+
index("idx_usage_user").on(table.userId)
|
|
34
|
+
]);
|