@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,99 @@
|
|
|
1
|
+
# Instruções do Assistente
|
|
2
|
+
|
|
3
|
+
Você é um assistente especializado em análise de documentos e dados. Seu objetivo é ajudar o usuário de forma clara, precisa e objetiva.
|
|
4
|
+
|
|
5
|
+
## Regras Absolutas (NEVER/ALWAYS)
|
|
6
|
+
|
|
7
|
+
Estas regras não têm exceções:
|
|
8
|
+
|
|
9
|
+
- NEVER mencione detalhes técnicos internos (tasks, workstations, skills, queries, IDs de sistema)
|
|
10
|
+
- NEVER exponha estruturas de dados internas ao usuário
|
|
11
|
+
- ALWAYS fale em termos de "documentos", "informações", "dados extraídos"
|
|
12
|
+
- ALWAYS referencie o documento original ao citar informações
|
|
13
|
+
- ALWAYS seja conciso e direto nas respostas
|
|
14
|
+
|
|
15
|
+
## Referências de Arquivos do Vault (STRICTLY ENFORCED)
|
|
16
|
+
|
|
17
|
+
CRITICAL: Ao referenciar arquivos do Vault, você DEVE incluir metadados na URL usando fragmentos (#).
|
|
18
|
+
|
|
19
|
+
<format_rules>
|
|
20
|
+
Formato obrigatório: `https://{{VAULT_HOST}}/permalinks/<id>#param1=value1¶m2=value2`
|
|
21
|
+
|
|
22
|
+
Parâmetros disponíveis:
|
|
23
|
+
- `filename=<nome>` - Nome do arquivo (SEMPRE inclua para clareza do usuário)
|
|
24
|
+
- `page_number=<N>` - Número da página ao citar informações específicas
|
|
25
|
+
</format_rules>
|
|
26
|
+
|
|
27
|
+
<examples>
|
|
28
|
+
CORRETO:
|
|
29
|
+
- `[Contrato ABC](https://{{VAULT_HOST}}/permalinks/abc123#filename=contrato-abc.pdf&page_number=5)`
|
|
30
|
+
- `[Relatório Financeiro](https://{{VAULT_HOST}}/permalinks/xyz789#filename=relatorio-2024.pdf)`
|
|
31
|
+
- `[Ver página 12](https://{{VAULT_HOST}}/permalinks/def456#filename=manual.pdf&page_number=12)`
|
|
32
|
+
|
|
33
|
+
INCORRETO:
|
|
34
|
+
- `[Ver documento](https://{{VAULT_HOST}}/permalinks/abc123)` (falta filename)
|
|
35
|
+
- `[Link](https://{{VAULT_HOST}}/permalinks/abc123#page=5)` (parâmetro errado, falta filename)
|
|
36
|
+
- `abc123` (apenas ID, sem URL completa)
|
|
37
|
+
</examples>
|
|
38
|
+
|
|
39
|
+
## Prioridade de Fontes de Dados
|
|
40
|
+
|
|
41
|
+
IMPORTANT: Siga esta ordem de prioridade ao buscar informações:
|
|
42
|
+
|
|
43
|
+
1. **Dados já extraídos** (fontes de conhecimento) - Use primeiro quando disponíveis
|
|
44
|
+
2. **Arquivos originais** - Use apenas quando:
|
|
45
|
+
- A informação não está nos dados extraídos
|
|
46
|
+
- O usuário solicita explicitamente ver o documento original
|
|
47
|
+
- Precisa de contexto visual (imagens, gráficos, layouts)
|
|
48
|
+
|
|
49
|
+
## Comportamentos Padrão (WHEN IN DOUBT)
|
|
50
|
+
|
|
51
|
+
- WHEN IN DOUBT sobre formato: Seja conciso, use listas e formatação clara
|
|
52
|
+
- WHEN IN DOUBT sobre fonte: Prefira dados extraídos sobre arquivos brutos
|
|
53
|
+
- WHEN IN DOUBT sobre referência: Sempre inclua link com filename e page_number
|
|
54
|
+
- WHEN IN DOUBT sobre linguagem: Responda no mesmo idioma do usuário
|
|
55
|
+
|
|
56
|
+
## Menções de Arquivos e Skills
|
|
57
|
+
|
|
58
|
+
Quando o usuário menciona arquivos com `@` ou skills com `/`, eles aparecem na mensagem como tags estruturadas. Estas tags têm prioridade sobre instruções genéricas.
|
|
59
|
+
|
|
60
|
+
### `<file_mention>`
|
|
61
|
+
|
|
62
|
+
```xml
|
|
63
|
+
<file_mention name="relatorio.pdf" url="https://{{VAULT_HOST}}/permalinks/abc123">...</file_mention>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- ALWAYS acesse o arquivo usando o atributo `url`
|
|
67
|
+
- ALWAYS foque a sua resposta no conteúdo deste arquivo específico
|
|
68
|
+
- Se múltiplos `<file_mention>` estiverem presentes, use todos os arquivos listados
|
|
69
|
+
|
|
70
|
+
### `<canvas_mention>`
|
|
71
|
+
|
|
72
|
+
```xml
|
|
73
|
+
<canvas_mention name="meu_canvas" canvas-id="uuid-do-canvas" description="Descrição do canvas">
|
|
74
|
+
O usuário quer usar este canvas do Tela.
|
|
75
|
+
Variáveis obrigatórias (use EXATAMENTE estes nomes no JSON):
|
|
76
|
+
- nome_variavel (text): Descrição da variável
|
|
77
|
+
Invoque via Bash: bun run .claude/skills/tela/run.ts "uuid-do-canvas" com as variáveis em JSON.
|
|
78
|
+
</canvas_mention>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- Este é um Canvas do Tela. Para invocá-lo, use a tool Bash com o comando:
|
|
82
|
+
`bun run .claude/skills/tela/run.ts "<canvas-id>" '<variables-json>'`
|
|
83
|
+
- O atributo `canvas-id` contém o ID do canvas — passe como primeiro argumento
|
|
84
|
+
- O conteúdo da tag lista as **variáveis obrigatórias** com seus nomes e tipos exatos
|
|
85
|
+
- CRITICAL: Use EXATAMENTE os nomes de variáveis listados na tag. Nomes incorretos causam erro 400
|
|
86
|
+
- Passe variáveis como JSON no segundo argumento usando os nomes exatos (ex: `'{"nome_variavel": "valor"}'`)
|
|
87
|
+
- Variáveis do tipo `text` recebem texto. Variáveis do tipo `file` recebem URL do arquivo
|
|
88
|
+
- O atributo `description` descreve o que o canvas faz — use como contexto
|
|
89
|
+
- Se o canvas precisar de variáveis e o usuário não forneceu os valores, solicite-os antes de invocar
|
|
90
|
+
|
|
91
|
+
### `<skill_mention>`
|
|
92
|
+
|
|
93
|
+
```xml
|
|
94
|
+
<skill_mention name="MinhaSkill" ref="skill-ref-id" description="Descrição da skill">...</skill_mention>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- ALWAYS invoque a skill usando o atributo `ref`
|
|
98
|
+
- O atributo `description` descreve o que a skill faz — use como contexto
|
|
99
|
+
- Se o usuário não forneceu parâmetros adicionais e a skill precisar deles, solicite-os antes de invocar
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "## RULE 1: Fontes de Conhecimento (Skill Priority)\n\nIMPORTANT: Antes de buscar em arquivos, verifique se a informa\u00E7\u00E3o est\u00E1 dispon\u00EDvel nas fontes de conhecimento abaixo.\n\n<available_knowledge_sources>\n{{SOURCES}}\n</available_knowledge_sources>\n\n### Como Usar\n\nPara buscar informa\u00E7\u00F5es, use a skill `workstation-query` com o ID da fonte:\n\n<query_guide>\nFiltros suportados:\n- Igualdade: `{ \"campo\": \"valor\" }`\n- Compara\u00E7\u00F5es: `$gt`, `$gte`, `$lt`, `$lte`\n- Texto parcial: `$contains`\n- Lista de valores: `$in`\n- Arrays aninhados: `$elemMatch`\n\nExemplo de busca:\n```json\n{\n \"workstationId\": \"<ID_DA_FONTE>\",\n \"filters\": { \"status\": \"aprovado\" },\n \"select\": [\"nome\", \"valor\", \"data\"],\n \"limit\": 10\n}\n```\n</query_guide>\n\n### Regras de Uso\n\n- ALWAYS use os dados das fontes de conhecimento quando dispon\u00EDveis\n- ALWAYS cite a fonte original do documento ao apresentar informa\u00E7\u00F5es\n- NEVER mencione \"workstation\", \"task\" ou \"query\" para o usu\u00E1rio - fale em \"documentos\" e \"informa\u00E7\u00F5es extra\u00EDdas\"\n";
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default `## RULE 1: Fontes de Conhecimento (Skill Priority)
|
|
2
|
+
|
|
3
|
+
IMPORTANT: Antes de buscar em arquivos, verifique se a informa\xE7\xE3o est\xE1 dispon\xEDvel nas fontes de conhecimento abaixo.
|
|
4
|
+
|
|
5
|
+
<available_knowledge_sources>
|
|
6
|
+
{{SOURCES}}
|
|
7
|
+
</available_knowledge_sources>
|
|
8
|
+
|
|
9
|
+
### Como Usar
|
|
10
|
+
|
|
11
|
+
Para buscar informa\xE7\xF5es, use a skill \`workstation-query\` com o ID da fonte:
|
|
12
|
+
|
|
13
|
+
<query_guide>
|
|
14
|
+
Filtros suportados:
|
|
15
|
+
- Igualdade: \`{ "campo": "valor" }\`
|
|
16
|
+
- Compara\xE7\xF5es: \`$gt\`, \`$gte\`, \`$lt\`, \`$lte\`
|
|
17
|
+
- Texto parcial: \`$contains\`
|
|
18
|
+
- Lista de valores: \`$in\`
|
|
19
|
+
- Arrays aninhados: \`$elemMatch\`
|
|
20
|
+
|
|
21
|
+
Exemplo de busca:
|
|
22
|
+
\`\`\`json
|
|
23
|
+
{
|
|
24
|
+
"workstationId": "<ID_DA_FONTE>",
|
|
25
|
+
"filters": { "status": "aprovado" },
|
|
26
|
+
"select": ["nome", "valor", "data"],
|
|
27
|
+
"limit": 10
|
|
28
|
+
}
|
|
29
|
+
\`\`\`
|
|
30
|
+
</query_guide>
|
|
31
|
+
|
|
32
|
+
### Regras de Uso
|
|
33
|
+
|
|
34
|
+
- ALWAYS use os dados das fontes de conhecimento quando dispon\xEDveis
|
|
35
|
+
- ALWAYS cite a fonte original do documento ao apresentar informa\xE7\xF5es
|
|
36
|
+
- NEVER mencione "workstation", "task" ou "query" para o usu\xE1rio - fale em "documentos" e "informa\xE7\xF5es extra\xEDdas"
|
|
37
|
+
`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
## RULE 1: Fontes de Conhecimento (Skill Priority)
|
|
2
|
+
|
|
3
|
+
IMPORTANT: Antes de buscar em arquivos, verifique se a informação está disponível nas fontes de conhecimento abaixo.
|
|
4
|
+
|
|
5
|
+
<available_knowledge_sources>
|
|
6
|
+
{{SOURCES}}
|
|
7
|
+
</available_knowledge_sources>
|
|
8
|
+
|
|
9
|
+
### Como Usar
|
|
10
|
+
|
|
11
|
+
Para buscar informações, use a skill `workstation-query` com o ID da fonte:
|
|
12
|
+
|
|
13
|
+
<query_guide>
|
|
14
|
+
Filtros suportados:
|
|
15
|
+
- Igualdade: `{ "campo": "valor" }`
|
|
16
|
+
- Comparações: `$gt`, `$gte`, `$lt`, `$lte`
|
|
17
|
+
- Texto parcial: `$contains`
|
|
18
|
+
- Lista de valores: `$in`
|
|
19
|
+
- Arrays aninhados: `$elemMatch`
|
|
20
|
+
|
|
21
|
+
Exemplo de busca:
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"workstationId": "<ID_DA_FONTE>",
|
|
25
|
+
"filters": { "status": "aprovado" },
|
|
26
|
+
"select": ["nome", "valor", "data"],
|
|
27
|
+
"limit": 10
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
</query_guide>
|
|
31
|
+
|
|
32
|
+
### Regras de Uso
|
|
33
|
+
|
|
34
|
+
- ALWAYS use os dados das fontes de conhecimento quando disponíveis
|
|
35
|
+
- ALWAYS cite a fonte original do documento ao apresentar informações
|
|
36
|
+
- NEVER mencione "workstation", "task" ou "query" para o usuário - fale em "documentos" e "informações extraídas"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { and, gte, lte, sql } from "drizzle-orm";
|
|
2
|
+
import { useDb, schema } from "../db/index.js";
|
|
3
|
+
import { sendSlackMessage, formatUsageReport } from "../utils/slack.js";
|
|
4
|
+
import { getWorkspaceInfo, transformCostForBilling } from "../utils/billing.js";
|
|
5
|
+
export default defineTask({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "send-daily-usage-report",
|
|
8
|
+
description: "Sends daily usage report to Slack"
|
|
9
|
+
},
|
|
10
|
+
async run() {
|
|
11
|
+
const config = useRuntimeConfig();
|
|
12
|
+
const slackWebhookUrl = config.slackWebhookUrl;
|
|
13
|
+
if (!slackWebhookUrl) {
|
|
14
|
+
return { result: "No webhook configured" };
|
|
15
|
+
}
|
|
16
|
+
const db = useDb();
|
|
17
|
+
const now = /* @__PURE__ */ new Date();
|
|
18
|
+
const startOfToday = new Date(now);
|
|
19
|
+
startOfToday.setUTCHours(3, 0, 0, 0);
|
|
20
|
+
const endOfReport = new Date(now);
|
|
21
|
+
endOfReport.setUTCHours(23, 0, 0, 0);
|
|
22
|
+
const rawWorkspaceUsage = await db.select({
|
|
23
|
+
workspaceId: schema.conversationUsage.workspaceId,
|
|
24
|
+
totalTokens: sql`SUM(${schema.conversationUsage.totalTokens})::int`,
|
|
25
|
+
totalCost: sql`SUM(${schema.conversationUsage.totalCost}::numeric)::float`,
|
|
26
|
+
promptTokens: sql`SUM(${schema.conversationUsage.promptTokens})::int`,
|
|
27
|
+
completionTokens: sql`SUM(${schema.conversationUsage.completionTokens})::int`,
|
|
28
|
+
promptCost: sql`SUM(${schema.conversationUsage.promptCost}::numeric)::float`,
|
|
29
|
+
completionCost: sql`SUM(${schema.conversationUsage.completionCost}::numeric)::float`,
|
|
30
|
+
conversationCount: sql`COUNT(DISTINCT ${schema.conversationUsage.conversationId})::int`,
|
|
31
|
+
userCount: sql`COUNT(DISTINCT ${schema.conversationUsage.userId})::int`
|
|
32
|
+
}).from(schema.conversationUsage).where(
|
|
33
|
+
and(
|
|
34
|
+
gte(schema.conversationUsage.createdAt, startOfToday),
|
|
35
|
+
lte(schema.conversationUsage.createdAt, endOfReport)
|
|
36
|
+
)
|
|
37
|
+
).groupBy(schema.conversationUsage.workspaceId).orderBy(sql`SUM(${schema.conversationUsage.totalCost}::numeric) DESC`);
|
|
38
|
+
if (rawWorkspaceUsage.length === 0) {
|
|
39
|
+
return { result: "No usage data" };
|
|
40
|
+
}
|
|
41
|
+
const workspaceUsage = await Promise.all(
|
|
42
|
+
rawWorkspaceUsage.map(async (usage) => {
|
|
43
|
+
const { billing, name } = await getWorkspaceInfo(usage.workspaceId);
|
|
44
|
+
const transformedCosts = transformCostForBilling({
|
|
45
|
+
promptCost: usage.promptCost,
|
|
46
|
+
completionCost: usage.completionCost,
|
|
47
|
+
totalCost: usage.totalCost,
|
|
48
|
+
promptTokens: usage.promptTokens,
|
|
49
|
+
completionTokens: usage.completionTokens
|
|
50
|
+
}, billing);
|
|
51
|
+
return {
|
|
52
|
+
workspaceId: usage.workspaceId,
|
|
53
|
+
workspaceName: name,
|
|
54
|
+
totalTokens: usage.totalTokens,
|
|
55
|
+
totalCost: transformedCosts.totalCost,
|
|
56
|
+
rawCost: usage.totalCost,
|
|
57
|
+
promptTokens: usage.promptTokens,
|
|
58
|
+
completionTokens: usage.completionTokens,
|
|
59
|
+
conversationCount: usage.conversationCount,
|
|
60
|
+
userCount: usage.userCount,
|
|
61
|
+
billingMode: billing.mode
|
|
62
|
+
};
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
const message = formatUsageReport(workspaceUsage, startOfToday);
|
|
66
|
+
const sent = await sendSlackMessage(slackWebhookUrl, message);
|
|
67
|
+
if (sent) {
|
|
68
|
+
return { result: `Sent report for ${workspaceUsage.length} workspaces` };
|
|
69
|
+
} else {
|
|
70
|
+
return { result: "Failed to send report" };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../.nuxt/tsconfig.server.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"strict": true,
|
|
5
|
+
"allowUnreachableCode": false,
|
|
6
|
+
"allowUnusedLabels": false,
|
|
7
|
+
"exactOptionalPropertyTypes": false,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"skipLibCheck": true
|
|
16
|
+
},
|
|
17
|
+
"exclude": [
|
|
18
|
+
"../../../../../node_modules/*",
|
|
19
|
+
"**/node_modules/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { AgentApiChatPayload, AgentApiSession, ContinueSessionPayload, ReasoningItem } from '#chat-runtime/types/agent';
|
|
3
|
+
export declare function getAgentDataToken(event: H3Event): string;
|
|
4
|
+
export declare function createChatAgentSession(token: string, payload: AgentApiChatPayload): Promise<{
|
|
5
|
+
success: true;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
} | {
|
|
8
|
+
success: false;
|
|
9
|
+
error: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function continueSession(token: string, sessionId: string, payload: ContinueSessionPayload): Promise<{
|
|
12
|
+
success: true;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
} | {
|
|
15
|
+
success: false;
|
|
16
|
+
error: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function getSessionStatus(token: string, sessionId: string): Promise<{
|
|
19
|
+
success: true;
|
|
20
|
+
data: AgentApiSession;
|
|
21
|
+
} | {
|
|
22
|
+
success: false;
|
|
23
|
+
error: string;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function deleteSession(token: string, sessionId: string): Promise<{
|
|
26
|
+
success: true;
|
|
27
|
+
} | {
|
|
28
|
+
success: false;
|
|
29
|
+
error: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function cancelSession(token: string, sessionId: string): Promise<{
|
|
32
|
+
success: true;
|
|
33
|
+
previousStatus: string;
|
|
34
|
+
} | {
|
|
35
|
+
success: false;
|
|
36
|
+
error: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function extractContentFromReasoning(reasoning: ReasoningItem[]): string;
|
|
39
|
+
export declare function extractContentFromSession(session: AgentApiSession, turnReasoning?: ReasoningItem[]): string;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { agentApiQueryResponseSchema, agentApiSessionSchema } from "#chat-runtime/types/agent";
|
|
2
|
+
import { logger } from "#chat-runtime/server/utils/logger";
|
|
3
|
+
const getConfig = () => useRuntimeConfig();
|
|
4
|
+
export function getAgentDataToken(event) {
|
|
5
|
+
const cookieToken = event.context.auth?.token;
|
|
6
|
+
if (cookieToken) {
|
|
7
|
+
return cookieToken;
|
|
8
|
+
}
|
|
9
|
+
throw createError({
|
|
10
|
+
statusCode: 401,
|
|
11
|
+
statusMessage: "Authentication token not found"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function createChatAgentSession(token, payload) {
|
|
15
|
+
const { agentApiUrl } = getConfig();
|
|
16
|
+
const url = `${agentApiUrl}/v2/chat`;
|
|
17
|
+
logger.debug({ url, method: "POST" }, "Agent API createChatAgentSession request");
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
"Authorization": token
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify(payload)
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
logger.warn({ status: response.status, statusText: response.statusText }, "Agent API createChatAgentSession failed");
|
|
28
|
+
return { success: false, error: `Agent API error: ${response.status} - ${response.statusText}` };
|
|
29
|
+
}
|
|
30
|
+
const json = await response.json();
|
|
31
|
+
logger.debug({ status: response.status }, "Agent API createChatAgentSession response received");
|
|
32
|
+
const parsed = agentApiQueryResponseSchema.safeParse(json);
|
|
33
|
+
if (!parsed.success) {
|
|
34
|
+
logger.warn({ issues: parsed.error.issues }, "Agent API createChatAgentSession parse error");
|
|
35
|
+
return { success: false, error: "Invalid response from Agent API" };
|
|
36
|
+
}
|
|
37
|
+
return parsed.data;
|
|
38
|
+
}
|
|
39
|
+
export async function continueSession(token, sessionId, payload) {
|
|
40
|
+
const { agentApiUrl } = getConfig();
|
|
41
|
+
const url = `${agentApiUrl}/v2/sessions/${sessionId}/continue`;
|
|
42
|
+
logger.debug({ url, sessionId }, "Agent API continueSession request");
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"Authorization": token
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({ ...payload, isChat: true })
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
logger.warn({ status: response.status, statusText: response.statusText, sessionId }, "Agent API continueSession failed");
|
|
53
|
+
return { success: false, error: `Agent API error: ${response.status} - ${response.statusText}` };
|
|
54
|
+
}
|
|
55
|
+
const json = await response.json();
|
|
56
|
+
const parsed = agentApiQueryResponseSchema.safeParse(json);
|
|
57
|
+
if (!parsed.success) {
|
|
58
|
+
logger.warn({ sessionId }, "Agent API continueSession invalid response format");
|
|
59
|
+
return { success: false, error: "Invalid response from Agent API" };
|
|
60
|
+
}
|
|
61
|
+
logger.debug({ sessionId }, "Agent API continueSession response received");
|
|
62
|
+
return parsed.data;
|
|
63
|
+
}
|
|
64
|
+
export async function getSessionStatus(token, sessionId) {
|
|
65
|
+
const { agentApiUrl } = getConfig();
|
|
66
|
+
const url = `${agentApiUrl}/v2/sessions/${sessionId}`;
|
|
67
|
+
logger.debug({ url, sessionId }, "Agent API getSessionStatus request");
|
|
68
|
+
const response = await fetch(url, {
|
|
69
|
+
method: "GET",
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": "application/json",
|
|
72
|
+
"Authorization": token
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
logger.warn({ status: response.status, statusText: response.statusText, sessionId }, "Agent API getSessionStatus failed");
|
|
77
|
+
return { success: false, error: `Agent API error: ${response.status} - ${response.statusText}` };
|
|
78
|
+
}
|
|
79
|
+
const json = await response.json();
|
|
80
|
+
const parsed = agentApiSessionSchema.safeParse(json);
|
|
81
|
+
if (!parsed.success) {
|
|
82
|
+
logger.warn({ sessionId }, "Agent API getSessionStatus parse error");
|
|
83
|
+
return { success: false, error: "Invalid session response from Agent API" };
|
|
84
|
+
}
|
|
85
|
+
logger.debug({ sessionId, status: parsed.data.status }, "Agent API getSessionStatus response received");
|
|
86
|
+
return { success: true, data: parsed.data };
|
|
87
|
+
}
|
|
88
|
+
export async function deleteSession(token, sessionId) {
|
|
89
|
+
const { agentApiUrl } = getConfig();
|
|
90
|
+
const url = `${agentApiUrl}/v2/sessions/${sessionId}`;
|
|
91
|
+
logger.debug({ url, sessionId }, "Agent API deleteSession request");
|
|
92
|
+
const response = await fetch(url, {
|
|
93
|
+
method: "DELETE",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
"Authorization": token
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
logger.warn({ status: response.status, statusText: response.statusText, sessionId }, "Agent API deleteSession failed");
|
|
101
|
+
return { success: false, error: `Agent API error: ${response.status} - ${response.statusText}` };
|
|
102
|
+
}
|
|
103
|
+
logger.debug({ sessionId }, "Agent API deleteSession succeeded");
|
|
104
|
+
return { success: true };
|
|
105
|
+
}
|
|
106
|
+
export async function cancelSession(token, sessionId) {
|
|
107
|
+
const { agentApiUrl } = getConfig();
|
|
108
|
+
const url = `${agentApiUrl}/v2/sessions/${sessionId}/cancel`;
|
|
109
|
+
logger.debug({ url, sessionId }, "Agent API cancelSession request");
|
|
110
|
+
const response = await fetch(url, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
"Authorization": token
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
logger.warn({ status: response.status, statusText: response.statusText, sessionId }, "Agent API cancelSession failed");
|
|
119
|
+
return { success: false, error: `Agent API error: ${response.status} - ${response.statusText}` };
|
|
120
|
+
}
|
|
121
|
+
const json = await response.json();
|
|
122
|
+
if (!json.success) {
|
|
123
|
+
logger.warn({ sessionId }, "Agent API cancelSession returned failure");
|
|
124
|
+
return { success: false, error: json.error ?? "Failed to cancel session" };
|
|
125
|
+
}
|
|
126
|
+
logger.debug({ sessionId, previousStatus: json.previousStatus }, "Agent API cancelSession succeeded");
|
|
127
|
+
return { success: true, previousStatus: json.previousStatus ?? "unknown" };
|
|
128
|
+
}
|
|
129
|
+
export function extractContentFromReasoning(reasoning) {
|
|
130
|
+
for (let i = reasoning.length - 1; i >= 0; i--) {
|
|
131
|
+
const item = reasoning[i];
|
|
132
|
+
if (item && typeof item === "object") {
|
|
133
|
+
const itemObj = item;
|
|
134
|
+
if (itemObj.type === "assistant" && itemObj.message) {
|
|
135
|
+
const message = itemObj.message;
|
|
136
|
+
if (Array.isArray(message.content)) {
|
|
137
|
+
for (const part of message.content) {
|
|
138
|
+
if (part && typeof part === "object") {
|
|
139
|
+
const partObj = part;
|
|
140
|
+
if (partObj.type === "text" && typeof partObj.text === "string") {
|
|
141
|
+
return partObj.text;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return "";
|
|
150
|
+
}
|
|
151
|
+
export function extractContentFromSession(session, turnReasoning) {
|
|
152
|
+
if (turnReasoning !== void 0) {
|
|
153
|
+
return extractContentFromReasoning(turnReasoning);
|
|
154
|
+
}
|
|
155
|
+
if (session.result?.content) {
|
|
156
|
+
return session.result.content;
|
|
157
|
+
}
|
|
158
|
+
if (session.result?.structuredContent) {
|
|
159
|
+
const content = session.result.structuredContent.content;
|
|
160
|
+
if (typeof content === "string") {
|
|
161
|
+
return content;
|
|
162
|
+
}
|
|
163
|
+
return JSON.stringify(session.result.structuredContent);
|
|
164
|
+
}
|
|
165
|
+
if (session.reasoning && Array.isArray(session.reasoning)) {
|
|
166
|
+
return extractContentFromReasoning(session.reasoning);
|
|
167
|
+
}
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function authApiFetch<T>(path: string, options?: RequestInit): Promise<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { logger } from "#chat-runtime/server/utils/logger";
|
|
2
|
+
export async function authApiFetch(path, options) {
|
|
3
|
+
const config = useRuntimeConfig();
|
|
4
|
+
if (!config.authApiSecret) {
|
|
5
|
+
throw createError({ statusCode: 500, statusMessage: "AUTH_API_SECRET not configured" });
|
|
6
|
+
}
|
|
7
|
+
const start = performance.now();
|
|
8
|
+
const response = await fetch(`${config.authApiUrl}${path}`, {
|
|
9
|
+
...options,
|
|
10
|
+
headers: {
|
|
11
|
+
"Authorization": `Bearer ${config.authApiSecret}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
...options?.headers
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
logger.error({ status: response.status, statusText: response.statusText, path }, "Auth API request failed");
|
|
18
|
+
throw createError({
|
|
19
|
+
statusCode: response.status,
|
|
20
|
+
statusMessage: `Auth API error: ${response.statusText}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
logger.debug({ path, durationMs: Math.round(performance.now() - start) }, "Auth API request succeeded");
|
|
24
|
+
return response.json();
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
export type SessionUser = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
|
+
image: string;
|
|
7
|
+
role: string;
|
|
8
|
+
};
|
|
9
|
+
export type SessionWorkspace = {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
};
|
|
13
|
+
export type AppSession = {
|
|
14
|
+
user: SessionUser;
|
|
15
|
+
workspace: SessionWorkspace;
|
|
16
|
+
};
|
|
17
|
+
export declare function requireUser(event: H3Event): AppSession;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { logger } from "#chat-runtime/server/utils/logger";
|
|
2
|
+
export function requireUser(event) {
|
|
3
|
+
const { user, workspace } = event.context.auth ?? {};
|
|
4
|
+
if (!user?.id) {
|
|
5
|
+
logger.warn("Auth required but no user in context");
|
|
6
|
+
throw createError({
|
|
7
|
+
statusCode: 401,
|
|
8
|
+
statusMessage: "Unauthorized"
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (!workspace?.id) {
|
|
12
|
+
logger.warn("Auth required but no workspace in context");
|
|
13
|
+
throw createError({
|
|
14
|
+
statusCode: 401,
|
|
15
|
+
statusMessage: "Unauthorized"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
user: {
|
|
20
|
+
id: user.id,
|
|
21
|
+
name: user.name ?? "",
|
|
22
|
+
email: user.email ?? "",
|
|
23
|
+
image: user.image ?? "",
|
|
24
|
+
role: user.role ?? "member"
|
|
25
|
+
},
|
|
26
|
+
workspace
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type BillingConfig = {
|
|
2
|
+
mode: 'plan';
|
|
3
|
+
cvp: number;
|
|
4
|
+
} | {
|
|
5
|
+
mode: 'credits';
|
|
6
|
+
};
|
|
7
|
+
export type WorkspaceInfo = {
|
|
8
|
+
billing: BillingConfig;
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Fetch workspace info including billing settings from the auth API
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWorkspaceInfo(workspaceId: string): Promise<WorkspaceInfo>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetch workspace billing settings from the auth API
|
|
17
|
+
*/
|
|
18
|
+
export declare function getWorkspaceBilling(workspaceId: string): Promise<BillingConfig>;
|
|
19
|
+
export type UsageData = {
|
|
20
|
+
promptCost: number;
|
|
21
|
+
completionCost: number;
|
|
22
|
+
totalCost: number;
|
|
23
|
+
promptTokens: number;
|
|
24
|
+
completionTokens: number;
|
|
25
|
+
};
|
|
26
|
+
export type TransformedCosts = {
|
|
27
|
+
promptCost: number;
|
|
28
|
+
completionCost: number;
|
|
29
|
+
totalCost: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Transform raw costs based on workspace billing mode
|
|
33
|
+
*
|
|
34
|
+
* For 'plan' mode: costs are multiplied by cvp
|
|
35
|
+
* For 'credits' mode: calculates credits based on costs and token amounts
|
|
36
|
+
*/
|
|
37
|
+
export declare function transformCostForBilling(usage: UsageData, billing: BillingConfig): TransformedCosts;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { authApiFetch } from "#chat-runtime/server/utils/auth-api";
|
|
2
|
+
import { logger } from "#chat-runtime/server/utils/logger";
|
|
3
|
+
const DEFAULT_CVP = 1.5;
|
|
4
|
+
function calculateCreditsUsed(inputCost, outputCost, inputAmount, outputAmount) {
|
|
5
|
+
const baseCost = inputCost + inputAmount * 306e-8 + outputCost + outputAmount * 378e-6 + 0.036;
|
|
6
|
+
const costCap = 10 * (inputCost + outputCost);
|
|
7
|
+
const alternativeCost = (inputAmount * (302e-8 + 306e-8) + outputAmount * (1514e-8 + 378e-6) + 0.036) / 2;
|
|
8
|
+
const credits = Math.ceil(
|
|
9
|
+
Math.max(
|
|
10
|
+
Math.min(baseCost, costCap),
|
|
11
|
+
alternativeCost
|
|
12
|
+
) / 0.01
|
|
13
|
+
);
|
|
14
|
+
return credits;
|
|
15
|
+
}
|
|
16
|
+
export async function getWorkspaceInfo(workspaceId) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await authApiFetch(`/organizations/${workspaceId}`);
|
|
19
|
+
const workspace = response.data;
|
|
20
|
+
const settings = workspace?.settings;
|
|
21
|
+
const billingSettings = settings?.billing;
|
|
22
|
+
const billing = billingSettings?.mode === "credits" ? { mode: "credits" } : { mode: "plan", cvp: billingSettings?.cvp ?? DEFAULT_CVP };
|
|
23
|
+
return {
|
|
24
|
+
billing,
|
|
25
|
+
name: workspace?.title ?? workspaceId
|
|
26
|
+
};
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logger.error(error, "Failed to fetch workspace info");
|
|
29
|
+
return {
|
|
30
|
+
billing: { mode: "plan", cvp: DEFAULT_CVP },
|
|
31
|
+
name: workspaceId
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function getWorkspaceBilling(workspaceId) {
|
|
36
|
+
const info = await getWorkspaceInfo(workspaceId);
|
|
37
|
+
return info.billing;
|
|
38
|
+
}
|
|
39
|
+
export function transformCostForBilling(usage, billing) {
|
|
40
|
+
if (billing.mode === "plan") {
|
|
41
|
+
return {
|
|
42
|
+
promptCost: usage.promptCost * billing.cvp,
|
|
43
|
+
completionCost: usage.completionCost * billing.cvp,
|
|
44
|
+
totalCost: usage.totalCost * billing.cvp
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const totalCredits = calculateCreditsUsed(
|
|
48
|
+
usage.promptCost,
|
|
49
|
+
usage.completionCost,
|
|
50
|
+
usage.promptTokens,
|
|
51
|
+
usage.completionTokens
|
|
52
|
+
);
|
|
53
|
+
const totalRawCost = usage.promptCost + usage.completionCost;
|
|
54
|
+
if (totalRawCost === 0) {
|
|
55
|
+
return {
|
|
56
|
+
promptCost: 0,
|
|
57
|
+
completionCost: 0,
|
|
58
|
+
totalCost: totalCredits
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const promptRatio = usage.promptCost / totalRawCost;
|
|
62
|
+
const completionRatio = usage.completionCost / totalRawCost;
|
|
63
|
+
return {
|
|
64
|
+
promptCost: totalCredits * promptRatio,
|
|
65
|
+
completionCost: totalCredits * completionRatio,
|
|
66
|
+
totalCost: totalCredits
|
|
67
|
+
};
|
|
68
|
+
}
|