@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.
Files changed (479) hide show
  1. package/README.md +274 -0
  2. package/dist/module.d.mts +3 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +250 -0
  5. package/dist/runtime/assets/css/code-theme.css +1 -0
  6. package/dist/runtime/assets/css/markstream.css +1 -0
  7. package/dist/runtime/components/AppStatusToast.d.vue.ts +3 -0
  8. package/dist/runtime/components/AppStatusToast.vue +42 -0
  9. package/dist/runtime/components/AppStatusToast.vue.d.ts +3 -0
  10. package/dist/runtime/components/TelaChat.d.vue.ts +19 -0
  11. package/dist/runtime/components/TelaChat.vue +25 -0
  12. package/dist/runtime/components/TelaChat.vue.d.ts +19 -0
  13. package/dist/runtime/components/app-markdown-render.d.vue.ts +15 -0
  14. package/dist/runtime/components/app-markdown-render.vue +45 -0
  15. package/dist/runtime/components/app-markdown-render.vue.d.ts +15 -0
  16. package/dist/runtime/components/application-card.d.vue.ts +9 -0
  17. package/dist/runtime/components/application-card.vue +52 -0
  18. package/dist/runtime/components/application-card.vue.d.ts +9 -0
  19. package/dist/runtime/components/audio-preview.d.vue.ts +14 -0
  20. package/dist/runtime/components/audio-preview.vue +52 -0
  21. package/dist/runtime/components/audio-preview.vue.d.ts +14 -0
  22. package/dist/runtime/components/chat/bash-widget.d.vue.ts +9 -0
  23. package/dist/runtime/components/chat/bash-widget.vue +86 -0
  24. package/dist/runtime/components/chat/bash-widget.vue.d.ts +9 -0
  25. package/dist/runtime/components/chat/canvas-selector-modal.d.vue.ts +14 -0
  26. package/dist/runtime/components/chat/canvas-selector-modal.vue +290 -0
  27. package/dist/runtime/components/chat/canvas-selector-modal.vue.d.ts +14 -0
  28. package/dist/runtime/components/chat/context-config.d.vue.ts +30 -0
  29. package/dist/runtime/components/chat/context-config.vue +423 -0
  30. package/dist/runtime/components/chat/context-config.vue.d.ts +30 -0
  31. package/dist/runtime/components/chat/conversation-item.d.vue.ts +20 -0
  32. package/dist/runtime/components/chat/conversation-item.vue +184 -0
  33. package/dist/runtime/components/chat/conversation-item.vue.d.ts +20 -0
  34. package/dist/runtime/components/chat/conversation-list.d.vue.ts +10 -0
  35. package/dist/runtime/components/chat/conversation-list.vue +78 -0
  36. package/dist/runtime/components/chat/conversation-list.vue.d.ts +10 -0
  37. package/dist/runtime/components/chat/doc-sdk-widget.d.vue.ts +9 -0
  38. package/dist/runtime/components/chat/doc-sdk-widget.vue +74 -0
  39. package/dist/runtime/components/chat/doc-sdk-widget.vue.d.ts +9 -0
  40. package/dist/runtime/components/chat/file-preview.d.vue.ts +7 -0
  41. package/dist/runtime/components/chat/file-preview.vue +313 -0
  42. package/dist/runtime/components/chat/file-preview.vue.d.ts +7 -0
  43. package/dist/runtime/components/chat/files-view.d.vue.ts +6 -0
  44. package/dist/runtime/components/chat/files-view.vue +399 -0
  45. package/dist/runtime/components/chat/files-view.vue.d.ts +6 -0
  46. package/dist/runtime/components/chat/generic-tool-widget.d.vue.ts +9 -0
  47. package/dist/runtime/components/chat/generic-tool-widget.vue +334 -0
  48. package/dist/runtime/components/chat/generic-tool-widget.vue.d.ts +9 -0
  49. package/dist/runtime/components/chat/grep-widget.d.vue.ts +9 -0
  50. package/dist/runtime/components/chat/grep-widget.vue +259 -0
  51. package/dist/runtime/components/chat/grep-widget.vue.d.ts +9 -0
  52. package/dist/runtime/components/chat/mention-dropdown.d.vue.ts +14 -0
  53. package/dist/runtime/components/chat/mention-dropdown.vue +90 -0
  54. package/dist/runtime/components/chat/mention-dropdown.vue.d.ts +14 -0
  55. package/dist/runtime/components/chat/message-bubble.d.vue.ts +11 -0
  56. package/dist/runtime/components/chat/message-bubble.vue +288 -0
  57. package/dist/runtime/components/chat/message-bubble.vue.d.ts +11 -0
  58. package/dist/runtime/components/chat/message-input.d.vue.ts +34 -0
  59. package/dist/runtime/components/chat/message-input.vue +428 -0
  60. package/dist/runtime/components/chat/message-input.vue.d.ts +34 -0
  61. package/dist/runtime/components/chat/message-list.d.vue.ts +11 -0
  62. package/dist/runtime/components/chat/message-list.vue +36 -0
  63. package/dist/runtime/components/chat/message-list.vue.d.ts +11 -0
  64. package/dist/runtime/components/chat/model-selector.d.vue.ts +15 -0
  65. package/dist/runtime/components/chat/model-selector.vue +35 -0
  66. package/dist/runtime/components/chat/model-selector.vue.d.ts +15 -0
  67. package/dist/runtime/components/chat/new-conversation-modal.d.vue.ts +14 -0
  68. package/dist/runtime/components/chat/new-conversation-modal.vue +271 -0
  69. package/dist/runtime/components/chat/new-conversation-modal.vue.d.ts +14 -0
  70. package/dist/runtime/components/chat/read-widget.d.vue.ts +9 -0
  71. package/dist/runtime/components/chat/read-widget.vue +195 -0
  72. package/dist/runtime/components/chat/read-widget.vue.d.ts +9 -0
  73. package/dist/runtime/components/chat/reasoning-message.d.vue.ts +13 -0
  74. package/dist/runtime/components/chat/reasoning-message.vue +341 -0
  75. package/dist/runtime/components/chat/reasoning-message.vue.d.ts +13 -0
  76. package/dist/runtime/components/chat/reasoning-step-item.d.vue.ts +37 -0
  77. package/dist/runtime/components/chat/reasoning-step-item.vue +125 -0
  78. package/dist/runtime/components/chat/reasoning-step-item.vue.d.ts +37 -0
  79. package/dist/runtime/components/chat/reasoning-steps.d.vue.ts +12 -0
  80. package/dist/runtime/components/chat/reasoning-steps.vue +47 -0
  81. package/dist/runtime/components/chat/reasoning-steps.vue.d.ts +12 -0
  82. package/dist/runtime/components/chat/reasoning-thought.d.vue.ts +11 -0
  83. package/dist/runtime/components/chat/reasoning-thought.vue +287 -0
  84. package/dist/runtime/components/chat/reasoning-thought.vue.d.ts +11 -0
  85. package/dist/runtime/components/chat/tela-skill-widget.d.vue.ts +9 -0
  86. package/dist/runtime/components/chat/tela-skill-widget.vue +94 -0
  87. package/dist/runtime/components/chat/tela-skill-widget.vue.d.ts +9 -0
  88. package/dist/runtime/components/chat/thinking-indicator.d.vue.ts +3 -0
  89. package/dist/runtime/components/chat/thinking-indicator.vue +52 -0
  90. package/dist/runtime/components/chat/thinking-indicator.vue.d.ts +3 -0
  91. package/dist/runtime/components/chat/thinking-widget.d.vue.ts +8 -0
  92. package/dist/runtime/components/chat/thinking-widget.vue +53 -0
  93. package/dist/runtime/components/chat/thinking-widget.vue.d.ts +8 -0
  94. package/dist/runtime/components/chat/topbar.d.vue.ts +43 -0
  95. package/dist/runtime/components/chat/topbar.vue +223 -0
  96. package/dist/runtime/components/chat/topbar.vue.d.ts +43 -0
  97. package/dist/runtime/components/chat/usage-view.d.vue.ts +8 -0
  98. package/dist/runtime/components/chat/usage-view.vue +393 -0
  99. package/dist/runtime/components/chat/usage-view.vue.d.ts +8 -0
  100. package/dist/runtime/components/chat/vault-link.d.vue.ts +20 -0
  101. package/dist/runtime/components/chat/vault-link.vue +34 -0
  102. package/dist/runtime/components/chat/vault-link.vue.d.ts +20 -0
  103. package/dist/runtime/components/chat/web-search-widget.d.vue.ts +9 -0
  104. package/dist/runtime/components/chat/web-search-widget.vue +121 -0
  105. package/dist/runtime/components/chat/web-search-widget.vue.d.ts +9 -0
  106. package/dist/runtime/components/chat/workstation-query-widget.d.vue.ts +10 -0
  107. package/dist/runtime/components/chat/workstation-query-widget.vue +552 -0
  108. package/dist/runtime/components/chat/workstation-query-widget.vue.d.ts +10 -0
  109. package/dist/runtime/components/chat/workstation-selector-modal.d.vue.ts +14 -0
  110. package/dist/runtime/components/chat/workstation-selector-modal.vue +272 -0
  111. package/dist/runtime/components/chat/workstation-selector-modal.vue.d.ts +14 -0
  112. package/dist/runtime/components/chat/write-widget.d.vue.ts +9 -0
  113. package/dist/runtime/components/chat/write-widget.vue +165 -0
  114. package/dist/runtime/components/chat/write-widget.vue.d.ts +9 -0
  115. package/dist/runtime/components/conversation-files-panel.d.vue.ts +3 -0
  116. package/dist/runtime/components/conversation-files-panel.vue +252 -0
  117. package/dist/runtime/components/conversation-files-panel.vue.d.ts +3 -0
  118. package/dist/runtime/components/csv-preview.d.vue.ts +20 -0
  119. package/dist/runtime/components/csv-preview.vue +157 -0
  120. package/dist/runtime/components/csv-preview.vue.d.ts +20 -0
  121. package/dist/runtime/components/file-preview-panel.d.vue.ts +3 -0
  122. package/dist/runtime/components/file-preview-panel.vue +185 -0
  123. package/dist/runtime/components/file-preview-panel.vue.d.ts +3 -0
  124. package/dist/runtime/components/file-uploader.d.vue.ts +16 -0
  125. package/dist/runtime/components/file-uploader.vue +136 -0
  126. package/dist/runtime/components/file-uploader.vue.d.ts +16 -0
  127. package/dist/runtime/components/icons/anthropic.d.vue.ts +3 -0
  128. package/dist/runtime/components/icons/anthropic.vue +5 -0
  129. package/dist/runtime/components/icons/anthropic.vue.d.ts +3 -0
  130. package/dist/runtime/components/image-preview.d.vue.ts +14 -0
  131. package/dist/runtime/components/image-preview.vue +54 -0
  132. package/dist/runtime/components/image-preview.vue.d.ts +14 -0
  133. package/dist/runtime/components/json-tree-node.d.vue.ts +9 -0
  134. package/dist/runtime/components/json-tree-node.vue +109 -0
  135. package/dist/runtime/components/json-tree-node.vue.d.ts +9 -0
  136. package/dist/runtime/components/json-viewer.d.vue.ts +6 -0
  137. package/dist/runtime/components/json-viewer.vue +88 -0
  138. package/dist/runtime/components/json-viewer.vue.d.ts +6 -0
  139. package/dist/runtime/components/pdf-preview.d.vue.ts +20 -0
  140. package/dist/runtime/components/pdf-preview.vue +89 -0
  141. package/dist/runtime/components/pdf-preview.vue.d.ts +20 -0
  142. package/dist/runtime/components/pdf-viewer.d.vue.ts +10 -0
  143. package/dist/runtime/components/pdf-viewer.vue +265 -0
  144. package/dist/runtime/components/pdf-viewer.vue.d.ts +10 -0
  145. package/dist/runtime/components/powered-by-tela.d.vue.ts +3 -0
  146. package/dist/runtime/components/powered-by-tela.vue +14 -0
  147. package/dist/runtime/components/powered-by-tela.vue.d.ts +3 -0
  148. package/dist/runtime/components/renderers/artifact-display.d.vue.ts +15 -0
  149. package/dist/runtime/components/renderers/artifact-display.vue +105 -0
  150. package/dist/runtime/components/renderers/artifact-display.vue.d.ts +15 -0
  151. package/dist/runtime/components/renderers/audio-renderer.d.vue.ts +7 -0
  152. package/dist/runtime/components/renderers/audio-renderer.vue +52 -0
  153. package/dist/runtime/components/renderers/audio-renderer.vue.d.ts +7 -0
  154. package/dist/runtime/components/renderers/csv-renderer.d.vue.ts +6 -0
  155. package/dist/runtime/components/renderers/csv-renderer.vue +203 -0
  156. package/dist/runtime/components/renderers/csv-renderer.vue.d.ts +6 -0
  157. package/dist/runtime/components/renderers/image-renderer.d.vue.ts +7 -0
  158. package/dist/runtime/components/renderers/image-renderer.vue +44 -0
  159. package/dist/runtime/components/renderers/image-renderer.vue.d.ts +7 -0
  160. package/dist/runtime/components/renderers/markdown-renderer.d.vue.ts +6 -0
  161. package/dist/runtime/components/renderers/markdown-renderer.vue +66 -0
  162. package/dist/runtime/components/renderers/markdown-renderer.vue.d.ts +6 -0
  163. package/dist/runtime/components/renderers/mermaid-diagram.d.vue.ts +7 -0
  164. package/dist/runtime/components/renderers/mermaid-diagram.vue +165 -0
  165. package/dist/runtime/components/renderers/mermaid-diagram.vue.d.ts +7 -0
  166. package/dist/runtime/components/renderers/text-renderer.d.vue.ts +7 -0
  167. package/dist/runtime/components/renderers/text-renderer.vue +70 -0
  168. package/dist/runtime/components/renderers/text-renderer.vue.d.ts +7 -0
  169. package/dist/runtime/components/renderers/video-renderer.d.vue.ts +6 -0
  170. package/dist/runtime/components/renderers/video-renderer.vue +43 -0
  171. package/dist/runtime/components/renderers/video-renderer.vue.d.ts +6 -0
  172. package/dist/runtime/components/text-preview.d.vue.ts +19 -0
  173. package/dist/runtime/components/text-preview.vue +105 -0
  174. package/dist/runtime/components/text-preview.vue.d.ts +19 -0
  175. package/dist/runtime/components/video-preview.d.vue.ts +14 -0
  176. package/dist/runtime/components/video-preview.vue +55 -0
  177. package/dist/runtime/components/video-preview.vue.d.ts +14 -0
  178. package/dist/runtime/composables/PageNavigation.d.ts +13 -0
  179. package/dist/runtime/composables/PageNavigation.js +18 -0
  180. package/dist/runtime/composables/useChat.d.ts +25 -0
  181. package/dist/runtime/composables/useChat.js +512 -0
  182. package/dist/runtime/composables/useChatApi.d.ts +6 -0
  183. package/dist/runtime/composables/useChatApi.js +28 -0
  184. package/dist/runtime/composables/useConversationFiles.d.ts +13 -0
  185. package/dist/runtime/composables/useConversationFiles.js +98 -0
  186. package/dist/runtime/composables/useConversationFilesPanel.d.ts +11 -0
  187. package/dist/runtime/composables/useConversationFilesPanel.js +35 -0
  188. package/dist/runtime/composables/useConversations.d.ts +15 -0
  189. package/dist/runtime/composables/useConversations.js +191 -0
  190. package/dist/runtime/composables/useDiagramExport.d.ts +11 -0
  191. package/dist/runtime/composables/useDiagramExport.js +186 -0
  192. package/dist/runtime/composables/useEmbedConfig.d.ts +13 -0
  193. package/dist/runtime/composables/useEmbedConfig.js +11 -0
  194. package/dist/runtime/composables/useFeatureFlags.d.ts +19 -0
  195. package/dist/runtime/composables/useFeatureFlags.js +67 -0
  196. package/dist/runtime/composables/useFileDrop.d.ts +17 -0
  197. package/dist/runtime/composables/useFileDrop.js +89 -0
  198. package/dist/runtime/composables/useFilePreviewPanel.d.ts +30 -0
  199. package/dist/runtime/composables/useFilePreviewPanel.js +42 -0
  200. package/dist/runtime/composables/useFileUpload.d.ts +7 -0
  201. package/dist/runtime/composables/useFileUpload.js +39 -0
  202. package/dist/runtime/composables/useGitHubSkills.d.ts +6 -0
  203. package/dist/runtime/composables/useGitHubSkills.js +68 -0
  204. package/dist/runtime/composables/useGitHubSkillsCallback.d.ts +5 -0
  205. package/dist/runtime/composables/useGitHubSkillsCallback.js +42 -0
  206. package/dist/runtime/composables/useIDB.d.ts +11 -0
  207. package/dist/runtime/composables/useIDB.js +57 -0
  208. package/dist/runtime/composables/useInputHistory.d.ts +7 -0
  209. package/dist/runtime/composables/useInputHistory.js +36 -0
  210. package/dist/runtime/composables/useKnowledgeSources.d.ts +6 -0
  211. package/dist/runtime/composables/useKnowledgeSources.js +15 -0
  212. package/dist/runtime/composables/useMediaCache.d.ts +13 -0
  213. package/dist/runtime/composables/useMediaCache.js +92 -0
  214. package/dist/runtime/composables/useMentionAutocomplete.d.ts +10 -0
  215. package/dist/runtime/composables/useMentionAutocomplete.js +272 -0
  216. package/dist/runtime/composables/useMermaidRenderer.d.ts +5 -0
  217. package/dist/runtime/composables/useMermaidRenderer.js +121 -0
  218. package/dist/runtime/composables/usePdf.d.ts +21 -0
  219. package/dist/runtime/composables/usePdf.js +138 -0
  220. package/dist/runtime/composables/usePolling.d.ts +12 -0
  221. package/dist/runtime/composables/usePolling.js +55 -0
  222. package/dist/runtime/composables/useSelectedModel.d.ts +4 -0
  223. package/dist/runtime/composables/useSelectedModel.js +46 -0
  224. package/dist/runtime/composables/useSplashScreen.d.ts +3 -0
  225. package/dist/runtime/composables/useSplashScreen.js +4 -0
  226. package/dist/runtime/composables/useStatusToast.d.ts +22 -0
  227. package/dist/runtime/composables/useStatusToast.js +40 -0
  228. package/dist/runtime/composables/useTela.d.ts +12 -0
  229. package/dist/runtime/composables/useTela.js +47 -0
  230. package/dist/runtime/composables/useToolFormatting.d.ts +5 -0
  231. package/dist/runtime/composables/useToolFormatting.js +61 -0
  232. package/dist/runtime/composables/useVault.d.ts +13 -0
  233. package/dist/runtime/composables/useVault.js +35 -0
  234. package/dist/runtime/composables/useVerbConjugation.d.ts +6 -0
  235. package/dist/runtime/composables/useVerbConjugation.js +256 -0
  236. package/dist/runtime/composables/useWorkspaceContextFiles.d.ts +19 -0
  237. package/dist/runtime/composables/useWorkspaceContextFiles.js +74 -0
  238. package/dist/runtime/composables/useWorkspaceCredentials.d.ts +34 -0
  239. package/dist/runtime/composables/useWorkspaceCredentials.js +175 -0
  240. package/dist/runtime/composables/useWorkspaceExternalSkills.d.ts +22 -0
  241. package/dist/runtime/composables/useWorkspaceExternalSkills.js +135 -0
  242. package/dist/runtime/composables/useWorkspaceKnowledgeSources.d.ts +11 -0
  243. package/dist/runtime/composables/useWorkspaceKnowledgeSources.js +88 -0
  244. package/dist/runtime/composables/useWorkspaceMembers.d.ts +13 -0
  245. package/dist/runtime/composables/useWorkspaceMembers.js +37 -0
  246. package/dist/runtime/composables/useWorkspacePersonalization.d.ts +6 -0
  247. package/dist/runtime/composables/useWorkspacePersonalization.js +19 -0
  248. package/dist/runtime/composables/useWorkspaceSettings.d.ts +30 -0
  249. package/dist/runtime/composables/useWorkspaceSettings.js +135 -0
  250. package/dist/runtime/composables/useWorkspaceTelaTools.d.ts +13 -0
  251. package/dist/runtime/composables/useWorkspaceTelaTools.js +91 -0
  252. package/dist/runtime/composables/useWorkspaces.d.ts +5 -0
  253. package/dist/runtime/composables/useWorkspaces.js +14 -0
  254. package/dist/runtime/composables/useZoomPan.d.ts +18 -0
  255. package/dist/runtime/composables/useZoomPan.js +130 -0
  256. package/dist/runtime/embed/components/ChatEmbed.d.vue.ts +23 -0
  257. package/dist/runtime/embed/components/ChatEmbed.vue +27 -0
  258. package/dist/runtime/embed/components/ChatEmbed.vue.d.ts +23 -0
  259. package/dist/runtime/embed/components/ChatEmbedInner.d.vue.ts +19 -0
  260. package/dist/runtime/embed/components/ChatEmbedInner.vue +604 -0
  261. package/dist/runtime/embed/components/ChatEmbedInner.vue.d.ts +19 -0
  262. package/dist/runtime/public/favicon.svg +4 -0
  263. package/dist/runtime/public/files/archive.svg +9 -0
  264. package/dist/runtime/public/files/audio.svg +4 -0
  265. package/dist/runtime/public/files/c.svg +4 -0
  266. package/dist/runtime/public/files/cpp.svg +6 -0
  267. package/dist/runtime/public/files/css.svg +4 -0
  268. package/dist/runtime/public/files/doc.svg +5 -0
  269. package/dist/runtime/public/files/generic.svg +7 -0
  270. package/dist/runtime/public/files/go.svg +6 -0
  271. package/dist/runtime/public/files/html.svg +4 -0
  272. package/dist/runtime/public/files/image.svg +3 -0
  273. package/dist/runtime/public/files/java.svg +7 -0
  274. package/dist/runtime/public/files/javascript.svg +4 -0
  275. package/dist/runtime/public/files/json.svg +5 -0
  276. package/dist/runtime/public/files/markdown.svg +5 -0
  277. package/dist/runtime/public/files/pdf.svg +5 -0
  278. package/dist/runtime/public/files/presentation.svg +5 -0
  279. package/dist/runtime/public/files/python.svg +5 -0
  280. package/dist/runtime/public/files/ruby.svg +5 -0
  281. package/dist/runtime/public/files/rust.svg +13 -0
  282. package/dist/runtime/public/files/sheet.svg +9 -0
  283. package/dist/runtime/public/files/shell.svg +5 -0
  284. package/dist/runtime/public/files/sql.svg +6 -0
  285. package/dist/runtime/public/files/typescript.svg +5 -0
  286. package/dist/runtime/public/files/video.svg +5 -0
  287. package/dist/runtime/public/files/yaml.svg +7 -0
  288. package/dist/runtime/public/github.svg +3 -0
  289. package/dist/runtime/public/robots.txt +1 -0
  290. package/dist/runtime/server/api/admin/trigger-usage-report.post.d.ts +2 -0
  291. package/dist/runtime/server/api/admin/trigger-usage-report.post.js +15 -0
  292. package/dist/runtime/server/api/chat/conversations/[id]/cancel.post.d.ts +1 -0
  293. package/dist/runtime/server/api/chat/conversations/[id]/cancel.post.js +1 -0
  294. package/dist/runtime/server/api/chat/conversations/[id]/clear.post.d.ts +1 -0
  295. package/dist/runtime/server/api/chat/conversations/[id]/clear.post.js +1 -0
  296. package/dist/runtime/server/api/chat/conversations/[id]/duplicate.post.d.ts +1 -0
  297. package/dist/runtime/server/api/chat/conversations/[id]/duplicate.post.js +1 -0
  298. package/dist/runtime/server/api/chat/conversations/[id]/files.get.d.ts +1 -0
  299. package/dist/runtime/server/api/chat/conversations/[id]/files.get.js +1 -0
  300. package/dist/runtime/server/api/chat/conversations/[id]/index.delete.d.ts +1 -0
  301. package/dist/runtime/server/api/chat/conversations/[id]/index.delete.js +1 -0
  302. package/dist/runtime/server/api/chat/conversations/[id]/index.get.d.ts +1 -0
  303. package/dist/runtime/server/api/chat/conversations/[id]/index.get.js +1 -0
  304. package/dist/runtime/server/api/chat/conversations/[id]/index.patch.d.ts +1 -0
  305. package/dist/runtime/server/api/chat/conversations/[id]/index.patch.js +1 -0
  306. package/dist/runtime/server/api/chat/conversations/[id]/messages/[messageId]/retry.post.d.ts +1 -0
  307. package/dist/runtime/server/api/chat/conversations/[id]/messages/[messageId]/retry.post.js +1 -0
  308. package/dist/runtime/server/api/chat/conversations/[id]/messages/index.get.d.ts +1 -0
  309. package/dist/runtime/server/api/chat/conversations/[id]/messages/index.get.js +1 -0
  310. package/dist/runtime/server/api/chat/conversations/[id]/messages/index.post.d.ts +1 -0
  311. package/dist/runtime/server/api/chat/conversations/[id]/messages/index.post.js +1 -0
  312. package/dist/runtime/server/api/chat/conversations/[id]/usage.get.d.ts +1 -0
  313. package/dist/runtime/server/api/chat/conversations/[id]/usage.get.js +1 -0
  314. package/dist/runtime/server/api/chat/conversations/generate-title.post.d.ts +1 -0
  315. package/dist/runtime/server/api/chat/conversations/generate-title.post.js +1 -0
  316. package/dist/runtime/server/api/chat/conversations/index.get.d.ts +1 -0
  317. package/dist/runtime/server/api/chat/conversations/index.get.js +1 -0
  318. package/dist/runtime/server/api/chat/conversations/index.post.d.ts +1 -0
  319. package/dist/runtime/server/api/chat/conversations/index.post.js +1 -0
  320. package/dist/runtime/server/api/chat/workspace/settings.get.d.ts +2 -0
  321. package/dist/runtime/server/api/chat/workspace/settings.get.js +14 -0
  322. package/dist/runtime/server/api/conversations/[id]/cancel.post.d.ts +2 -0
  323. package/dist/runtime/server/api/conversations/[id]/cancel.post.js +58 -0
  324. package/dist/runtime/server/api/conversations/[id]/clear.post.d.ts +2 -0
  325. package/dist/runtime/server/api/conversations/[id]/clear.post.js +38 -0
  326. package/dist/runtime/server/api/conversations/[id]/duplicate.post.d.ts +2 -0
  327. package/dist/runtime/server/api/conversations/[id]/duplicate.post.js +41 -0
  328. package/dist/runtime/server/api/conversations/[id]/files.get.d.ts +2 -0
  329. package/dist/runtime/server/api/conversations/[id]/files.get.js +131 -0
  330. package/dist/runtime/server/api/conversations/[id]/index.delete.d.ts +2 -0
  331. package/dist/runtime/server/api/conversations/[id]/index.delete.js +35 -0
  332. package/dist/runtime/server/api/conversations/[id]/index.get.d.ts +2 -0
  333. package/dist/runtime/server/api/conversations/[id]/index.get.js +34 -0
  334. package/dist/runtime/server/api/conversations/[id]/index.patch.d.ts +2 -0
  335. package/dist/runtime/server/api/conversations/[id]/index.patch.js +54 -0
  336. package/dist/runtime/server/api/conversations/[id]/messages/[messageId]/retry.post.d.ts +2 -0
  337. package/dist/runtime/server/api/conversations/[id]/messages/[messageId]/retry.post.js +168 -0
  338. package/dist/runtime/server/api/conversations/[id]/messages/index.get.d.ts +2 -0
  339. package/dist/runtime/server/api/conversations/[id]/messages/index.get.js +220 -0
  340. package/dist/runtime/server/api/conversations/[id]/messages/index.post.d.ts +2 -0
  341. package/dist/runtime/server/api/conversations/[id]/messages/index.post.js +181 -0
  342. package/dist/runtime/server/api/conversations/[id]/usage.get.d.ts +8 -0
  343. package/dist/runtime/server/api/conversations/[id]/usage.get.js +96 -0
  344. package/dist/runtime/server/api/conversations/generate-title.post.d.ts +2 -0
  345. package/dist/runtime/server/api/conversations/generate-title.post.js +49 -0
  346. package/dist/runtime/server/api/conversations/index.get.d.ts +2 -0
  347. package/dist/runtime/server/api/conversations/index.get.js +11 -0
  348. package/dist/runtime/server/api/conversations/index.post.d.ts +2 -0
  349. package/dist/runtime/server/api/conversations/index.post.js +41 -0
  350. package/dist/runtime/server/api/external-skills/discover.post.d.ts +2 -0
  351. package/dist/runtime/server/api/external-skills/discover.post.js +65 -0
  352. package/dist/runtime/server/api/github/disconnect.post.d.ts +2 -0
  353. package/dist/runtime/server/api/github/disconnect.post.js +21 -0
  354. package/dist/runtime/server/api/github/status.get.d.ts +2 -0
  355. package/dist/runtime/server/api/github/status.get.js +23 -0
  356. package/dist/runtime/server/api/tela/canvas.get.d.ts +2 -0
  357. package/dist/runtime/server/api/tela/canvas.get.js +18 -0
  358. package/dist/runtime/server/api/tela/projects.get.d.ts +2 -0
  359. package/dist/runtime/server/api/tela/projects.get.js +9 -0
  360. package/dist/runtime/server/api/tela/workspaces.get.d.ts +2 -0
  361. package/dist/runtime/server/api/tela/workspaces.get.js +9 -0
  362. package/dist/runtime/server/api/tela/workstations.get.d.ts +2 -0
  363. package/dist/runtime/server/api/tela/workstations.get.js +24 -0
  364. package/dist/runtime/server/api/vault/permalink-metadata.post.d.ts +2 -0
  365. package/dist/runtime/server/api/vault/permalink-metadata.post.js +77 -0
  366. package/dist/runtime/server/api/vault/resolve.post.d.ts +2 -0
  367. package/dist/runtime/server/api/vault/resolve.post.js +82 -0
  368. package/dist/runtime/server/api/vault/upload.post.d.ts +2 -0
  369. package/dist/runtime/server/api/vault/upload.post.js +55 -0
  370. package/dist/runtime/server/api/workspace/credentials/[id].delete.d.ts +2 -0
  371. package/dist/runtime/server/api/workspace/credentials/[id].delete.js +18 -0
  372. package/dist/runtime/server/api/workspace/credentials/[id].put.d.ts +2 -0
  373. package/dist/runtime/server/api/workspace/credentials/[id].put.js +28 -0
  374. package/dist/runtime/server/api/workspace/credentials/index.get.d.ts +2 -0
  375. package/dist/runtime/server/api/workspace/credentials/index.get.js +10 -0
  376. package/dist/runtime/server/api/workspace/credentials/index.post.d.ts +2 -0
  377. package/dist/runtime/server/api/workspace/credentials/index.post.js +33 -0
  378. package/dist/runtime/server/api/workspace/settings.get.d.ts +2 -0
  379. package/dist/runtime/server/api/workspace/settings.get.js +27 -0
  380. package/dist/runtime/server/api/workspace/settings.patch.d.ts +2 -0
  381. package/dist/runtime/server/api/workspace/settings.patch.js +86 -0
  382. package/dist/runtime/server/api/workspace/usage.get.d.ts +48 -0
  383. package/dist/runtime/server/api/workspace/usage.get.js +186 -0
  384. package/dist/runtime/server/db/index.d.ts +6 -0
  385. package/dist/runtime/server/db/index.js +19 -0
  386. package/dist/runtime/server/db/schema/conversation-usage.d.ts +438 -0
  387. package/dist/runtime/server/db/schema/conversation-usage.js +34 -0
  388. package/dist/runtime/server/db/schema/conversations.d.ts +197 -0
  389. package/dist/runtime/server/db/schema/conversations.js +18 -0
  390. package/dist/runtime/server/db/schema/external-skills.d.ts +235 -0
  391. package/dist/runtime/server/db/schema/external-skills.js +26 -0
  392. package/dist/runtime/server/db/schema/index.d.ts +5 -0
  393. package/dist/runtime/server/db/schema/index.js +5 -0
  394. package/dist/runtime/server/db/schema/messages.d.ts +221 -0
  395. package/dist/runtime/server/db/schema/messages.js +19 -0
  396. package/dist/runtime/server/db/schema/workspace-settings.d.ts +164 -0
  397. package/dist/runtime/server/db/schema/workspace-settings.js +15 -0
  398. package/dist/runtime/server/db/schema.d.ts +1 -0
  399. package/dist/runtime/server/db/schema.js +1 -0
  400. package/dist/runtime/server/middleware/domain-validation.d.ts +2 -0
  401. package/dist/runtime/server/middleware/domain-validation.js +22 -0
  402. package/dist/runtime/server/middleware/request-logger.d.ts +2 -0
  403. package/dist/runtime/server/middleware/request-logger.js +15 -0
  404. package/dist/runtime/server/prompts/base-system.d.ts +2 -0
  405. package/dist/runtime/server/prompts/base-system.js +100 -0
  406. package/dist/runtime/server/prompts/base-system.md +99 -0
  407. package/dist/runtime/server/prompts/knowledge-sources.d.ts +2 -0
  408. package/dist/runtime/server/prompts/knowledge-sources.js +37 -0
  409. package/dist/runtime/server/prompts/knowledge-sources.md +36 -0
  410. package/dist/runtime/server/tasks/send-daily-usage-report.d.ts +2 -0
  411. package/dist/runtime/server/tasks/send-daily-usage-report.js +73 -0
  412. package/dist/runtime/server/tsconfig.json +21 -0
  413. package/dist/runtime/server/utils/agent-api.d.ts +39 -0
  414. package/dist/runtime/server/utils/agent-api.js +169 -0
  415. package/dist/runtime/server/utils/auth-api.d.ts +1 -0
  416. package/dist/runtime/server/utils/auth-api.js +25 -0
  417. package/dist/runtime/server/utils/auth.d.ts +17 -0
  418. package/dist/runtime/server/utils/auth.js +28 -0
  419. package/dist/runtime/server/utils/billing.d.ts +37 -0
  420. package/dist/runtime/server/utils/billing.js +68 -0
  421. package/dist/runtime/server/utils/chat-context.d.ts +9 -0
  422. package/dist/runtime/server/utils/chat-context.js +24 -0
  423. package/dist/runtime/server/utils/chat-message-builder.d.ts +4 -0
  424. package/dist/runtime/server/utils/chat-message-builder.js +39 -0
  425. package/dist/runtime/server/utils/chat-prompts.d.ts +7 -0
  426. package/dist/runtime/server/utils/chat-prompts.js +9 -0
  427. package/dist/runtime/server/utils/chat-workspace-settings.d.ts +16 -0
  428. package/dist/runtime/server/utils/chat-workspace-settings.js +115 -0
  429. package/dist/runtime/server/utils/external-skills.d.ts +2 -0
  430. package/dist/runtime/server/utils/external-skills.js +15 -0
  431. package/dist/runtime/server/utils/logger.d.ts +2 -0
  432. package/dist/runtime/server/utils/logger.js +12 -0
  433. package/dist/runtime/server/utils/slack.d.ts +32 -0
  434. package/dist/runtime/server/utils/slack.js +102 -0
  435. package/dist/runtime/server/utils/tela-api.d.ts +2 -0
  436. package/dist/runtime/server/utils/tela-api.js +29 -0
  437. package/dist/runtime/server/utils/vault.d.ts +3 -0
  438. package/dist/runtime/server/utils/vault.js +52 -0
  439. package/dist/runtime/server/utils/workspace-settings-resolver.stub.d.ts +2 -0
  440. package/dist/runtime/server/utils/workspace-settings-resolver.stub.js +1 -0
  441. package/dist/runtime/server/utils/workspace.d.ts +4 -0
  442. package/dist/runtime/server/utils/workspace.js +21 -0
  443. package/dist/runtime/types/agent.d.ts +168 -0
  444. package/dist/runtime/types/agent.js +95 -0
  445. package/dist/runtime/types/chat-workspace-settings-resolver.d.ts +4 -0
  446. package/dist/runtime/types/chat.d.ts +81 -0
  447. package/dist/runtime/types/chat.js +12 -0
  448. package/dist/runtime/types/credential.d.ts +8 -0
  449. package/dist/runtime/types/credential.js +0 -0
  450. package/dist/runtime/types/csv.d.ts +4 -0
  451. package/dist/runtime/types/csv.js +0 -0
  452. package/dist/runtime/types/external-skills.d.ts +8 -0
  453. package/dist/runtime/types/external-skills.js +0 -0
  454. package/dist/runtime/types/feature-flags.d.ts +7 -0
  455. package/dist/runtime/types/feature-flags.js +6 -0
  456. package/dist/runtime/types/reasoning.d.ts +17 -0
  457. package/dist/runtime/types/reasoning.js +0 -0
  458. package/dist/runtime/types/tela.d.ts +46 -0
  459. package/dist/runtime/types/tela.js +0 -0
  460. package/dist/runtime/types/workspace.d.ts +20 -0
  461. package/dist/runtime/types/workspace.js +0 -0
  462. package/dist/runtime/utils/calculate-usage.d.ts +48 -0
  463. package/dist/runtime/utils/calculate-usage.js +63 -0
  464. package/dist/runtime/utils/code-detection.d.ts +1 -0
  465. package/dist/runtime/utils/code-detection.js +24 -0
  466. package/dist/runtime/utils/export-conversation.d.ts +2 -0
  467. package/dist/runtime/utils/export-conversation.js +43 -0
  468. package/dist/runtime/utils/file.d.ts +46 -0
  469. package/dist/runtime/utils/file.js +500 -0
  470. package/dist/runtime/utils/format-time.d.ts +22 -0
  471. package/dist/runtime/utils/format-time.js +96 -0
  472. package/dist/runtime/utils/markdown-nodes.d.ts +22 -0
  473. package/dist/runtime/utils/markdown-nodes.js +40 -0
  474. package/dist/runtime/utils/string.d.ts +4 -0
  475. package/dist/runtime/utils/string.js +5 -0
  476. package/dist/runtime/utils/tela-chat.d.ts +19 -0
  477. package/dist/runtime/utils/tela-chat.js +20 -0
  478. package/dist/types.d.mts +7 -0
  479. package/package.json +72 -0
@@ -0,0 +1,131 @@
1
+ import { and, asc, eq } from "drizzle-orm";
2
+ import { useDb, schema } from "#chat-runtime/server/db";
3
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
4
+ import { APIKeyAuthStrategy, extractVaultReferences, VaultFile } from "@meistrari/vault-sdk";
5
+ import { getAgentDataToken } from "#chat-runtime/server/utils/agent-api";
6
+ import { generateFileId } from "#chat-runtime/utils/file";
7
+ import { logger } from "#chat-runtime/server/utils/logger";
8
+ export default defineEventHandler(async (event) => {
9
+ const context = resolveChatContext(event);
10
+ const db = useDb();
11
+ const conversationId = getRouterParam(event, "id");
12
+ const authToken = getAgentDataToken(event);
13
+ const { vaultUrl } = useRuntimeConfig();
14
+ if (!conversationId || !/^[0-9a-f-]{36}$/i.test(conversationId)) {
15
+ throw createError({
16
+ statusCode: 400,
17
+ statusMessage: "Invalid conversation ID format"
18
+ });
19
+ }
20
+ const [conversation] = await db.select().from(schema.conversations).where(and(
21
+ eq(schema.conversations.id, conversationId),
22
+ eq(schema.conversations.workspaceId, context.workspaceId)
23
+ ));
24
+ if (!conversation) {
25
+ throw createError({
26
+ statusCode: 404,
27
+ statusMessage: "Conversation not found"
28
+ });
29
+ }
30
+ const conversationMessages = await db.select({
31
+ id: schema.messages.id,
32
+ role: schema.messages.role,
33
+ createdAt: schema.messages.createdAt,
34
+ files: schema.messages.files,
35
+ content: schema.messages.content
36
+ }).from(schema.messages).where(eq(schema.messages.conversationId, conversationId)).orderBy(asc(schema.messages.createdAt));
37
+ const messagesWithFiles = conversationMessages.filter((msg) => Array.isArray(msg.files) && msg.files.length > 0);
38
+ const files = [];
39
+ const resolvedVaultRefs = /* @__PURE__ */ new Set();
40
+ const vaultRefEntries = [];
41
+ const seenInContent = /* @__PURE__ */ new Set();
42
+ for (const msg of conversationMessages) {
43
+ if (msg.content.trim() === "")
44
+ continue;
45
+ const vaultRefs = [...new Set(extractVaultReferences(msg.content))];
46
+ for (const reference of vaultRefs) {
47
+ if (!seenInContent.has(reference)) {
48
+ seenInContent.add(reference);
49
+ vaultRefEntries.push({ reference, msg });
50
+ }
51
+ }
52
+ }
53
+ if (vaultUrl && vaultRefEntries.length > 0) {
54
+ const resolved = await Promise.all(
55
+ vaultRefEntries.map(async ({ reference, msg }) => {
56
+ try {
57
+ const vaultFile = await VaultFile.fromVaultReference({
58
+ reference,
59
+ config: {
60
+ authStrategy: new APIKeyAuthStrategy(authToken),
61
+ vaultUrl
62
+ }
63
+ });
64
+ await vaultFile.populateMetadata();
65
+ const permalinks = await vaultFile.getPermalinks();
66
+ let permalink = permalinks.find((p) => !p.expiresAt);
67
+ if (!permalink) {
68
+ permalink = await vaultFile.createPermalink();
69
+ }
70
+ return {
71
+ id: generateFileId(reference),
72
+ url: permalink.url.toString(),
73
+ vaultReference: reference,
74
+ name: vaultFile.metadata?.originalFileName ?? "unknown",
75
+ mimeType: vaultFile.metadata?.mimeType ?? "application/octet-stream",
76
+ source: "message",
77
+ messageId: msg.id,
78
+ messageRole: msg.role === "user" || msg.role === "assistant" ? msg.role : void 0,
79
+ createdAt: msg.createdAt,
80
+ size: vaultFile.metadata?.size ?? 0
81
+ };
82
+ } catch (error) {
83
+ logger.error({ reference, error }, "Failed to resolve vault reference");
84
+ return null;
85
+ }
86
+ })
87
+ );
88
+ for (const file of resolved) {
89
+ if (file) {
90
+ files.push(file);
91
+ resolvedVaultRefs.add(file.vaultReference);
92
+ }
93
+ }
94
+ }
95
+ for (const message of messagesWithFiles) {
96
+ if (!Array.isArray(message.files))
97
+ continue;
98
+ for (const file of message.files) {
99
+ if (!file || typeof file !== "object" || !file.url || !file.name) {
100
+ continue;
101
+ }
102
+ const ref = file.vaultReference ?? file.url;
103
+ if (resolvedVaultRefs.has(ref))
104
+ continue;
105
+ resolvedVaultRefs.add(ref);
106
+ files.push({
107
+ id: generateFileId(file.url),
108
+ url: file.url,
109
+ name: file.name,
110
+ vaultReference: file.vaultReference ?? file.url,
111
+ mimeType: file.mimeType ?? "application/octet-stream",
112
+ source: "message",
113
+ messageId: message.id,
114
+ messageRole: message.role === "user" || message.role === "assistant" ? message.role : void 0,
115
+ createdAt: message.createdAt,
116
+ size: file.size
117
+ });
118
+ }
119
+ }
120
+ files.sort((a, b) => {
121
+ const dateA = a.createdAt?.getTime() ?? 0;
122
+ const dateB = b.createdAt?.getTime() ?? 0;
123
+ return dateB - dateA;
124
+ });
125
+ return {
126
+ files,
127
+ summary: {
128
+ total: files.length
129
+ }
130
+ };
131
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,35 @@
1
+ import { eq, and } from "drizzle-orm";
2
+ import { useDb, schema } from "#chat-runtime/server/db";
3
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
4
+ import { getAgentDataToken, deleteSession } from "#chat-runtime/server/utils/agent-api";
5
+ import { logger } from "#chat-runtime/server/utils/logger";
6
+ export default defineEventHandler(async (event) => {
7
+ const context = resolveChatContext(event);
8
+ const token = getAgentDataToken(event);
9
+ const db = useDb();
10
+ const id = getRouterParam(event, "id");
11
+ if (!id) {
12
+ throw createError({
13
+ statusCode: 400,
14
+ statusMessage: "Conversation ID is required"
15
+ });
16
+ }
17
+ const [deleted] = await db.delete(schema.conversations).where(
18
+ and(
19
+ eq(schema.conversations.id, id),
20
+ eq(schema.conversations.workspaceId, context.workspaceId)
21
+ )
22
+ ).returning();
23
+ if (!deleted) {
24
+ throw createError({
25
+ statusCode: 404,
26
+ statusMessage: "Conversation not found"
27
+ });
28
+ }
29
+ logger.info({ conversationId: id, workspaceId: context.workspaceId }, "Conversation deleted");
30
+ if (deleted.threadSessionId) {
31
+ deleteSession(token, deleted.threadSessionId).catch(() => {
32
+ });
33
+ }
34
+ return { success: true };
35
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,34 @@
1
+ import { eq, and, asc } from "drizzle-orm";
2
+ import { useDb, schema } from "#chat-runtime/server/db";
3
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
4
+ export default defineEventHandler(async (event) => {
5
+ const context = resolveChatContext(event);
6
+ const db = useDb();
7
+ const id = getRouterParam(event, "id");
8
+ if (!id) {
9
+ throw createError({
10
+ statusCode: 400,
11
+ statusMessage: "Conversation ID is required"
12
+ });
13
+ }
14
+ const [conversationResult, messages] = await Promise.all([
15
+ db.select().from(schema.conversations).where(
16
+ and(
17
+ eq(schema.conversations.id, id),
18
+ eq(schema.conversations.workspaceId, context.workspaceId)
19
+ )
20
+ ),
21
+ db.select().from(schema.messages).where(eq(schema.messages.conversationId, id)).orderBy(asc(schema.messages.createdAt))
22
+ ]);
23
+ const [conversation] = conversationResult;
24
+ if (!conversation) {
25
+ throw createError({
26
+ statusCode: 404,
27
+ statusMessage: "Conversation not found"
28
+ });
29
+ }
30
+ return {
31
+ ...conversation,
32
+ messages
33
+ };
34
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,54 @@
1
+ import { eq, and } from "drizzle-orm";
2
+ import { useDb, schema } from "#chat-runtime/server/db";
3
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
4
+ import { logger } from "#chat-runtime/server/utils/logger";
5
+ import { isValidModel } from "#chat-runtime/types/chat";
6
+ export default defineEventHandler(async (event) => {
7
+ const context = resolveChatContext(event);
8
+ const db = useDb();
9
+ const id = getRouterParam(event, "id");
10
+ if (!id) {
11
+ throw createError({
12
+ statusCode: 400,
13
+ statusMessage: "Conversation ID is required"
14
+ });
15
+ }
16
+ const body = await readBody(event);
17
+ if (body.title === void 0 && body.model === void 0) {
18
+ throw createError({
19
+ statusCode: 400,
20
+ statusMessage: "At least one field is required to update"
21
+ });
22
+ }
23
+ if (body.title !== void 0 && !body.title?.trim()) {
24
+ throw createError({
25
+ statusCode: 400,
26
+ statusMessage: "Title cannot be empty"
27
+ });
28
+ }
29
+ if (body.model !== void 0 && body.model !== null && !isValidModel(body.model)) {
30
+ throw createError({
31
+ statusCode: 400,
32
+ statusMessage: "Invalid model"
33
+ });
34
+ }
35
+ const updateData = { updatedAt: /* @__PURE__ */ new Date() };
36
+ if (body.title !== void 0)
37
+ updateData.title = body.title.trim();
38
+ if (body.model !== void 0)
39
+ updateData.model = body.model;
40
+ const [updated] = await db.update(schema.conversations).set(updateData).where(
41
+ and(
42
+ eq(schema.conversations.id, id),
43
+ eq(schema.conversations.workspaceId, context.workspaceId)
44
+ )
45
+ ).returning();
46
+ if (!updated) {
47
+ throw createError({
48
+ statusCode: 404,
49
+ statusMessage: "Conversation not found"
50
+ });
51
+ }
52
+ logger.debug({ conversationId: id }, "Conversation title updated");
53
+ return updated;
54
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,168 @@
1
+ import { eq, and, lt, desc, isNull } from "drizzle-orm";
2
+ import { logger } from "#chat-runtime/server/utils/logger";
3
+ import { useDb, schema } from "#chat-runtime/server/db";
4
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
5
+ import { buildMessageWithContext, renderSystemPrompt, truncateTitle } from "#chat-runtime/server/utils/chat-message-builder";
6
+ import { getAgentDataToken, createChatAgentSession, continueSession } from "#chat-runtime/server/utils/agent-api";
7
+ import {
8
+ getConversationAppliedSettings,
9
+ getWorkspaceSettingsUpdatedAt,
10
+ resolveWorkspaceSettings,
11
+ serializeResolvedWorkspaceSettings
12
+ } from "#chat-runtime/server/utils/chat-workspace-settings";
13
+ import { resolveWorkspaceCredentials } from "#chat-runtime/server/utils/workspace";
14
+ import { mergeFileUrls } from "#chat-runtime/utils/file";
15
+ import { isValidModel } from "#chat-runtime/types/chat";
16
+ export default defineEventHandler(async (event) => {
17
+ const context = resolveChatContext(event);
18
+ const token = getAgentDataToken(event);
19
+ const db = useDb();
20
+ const conversationId = getRouterParam(event, "id");
21
+ const messageId = getRouterParam(event, "messageId");
22
+ if (!conversationId || !messageId) {
23
+ throw createError({
24
+ statusCode: 400,
25
+ statusMessage: "Conversation ID and Message ID are required"
26
+ });
27
+ }
28
+ const [conversation] = await db.select().from(schema.conversations).where(
29
+ and(
30
+ eq(schema.conversations.id, conversationId),
31
+ eq(schema.conversations.workspaceId, context.workspaceId)
32
+ )
33
+ );
34
+ if (!conversation) {
35
+ throw createError({
36
+ statusCode: 404,
37
+ statusMessage: "Conversation not found"
38
+ });
39
+ }
40
+ const [failedMessage] = await db.select().from(schema.messages).where(
41
+ and(
42
+ eq(schema.messages.id, messageId),
43
+ eq(schema.messages.conversationId, conversationId),
44
+ eq(schema.messages.role, "assistant"),
45
+ eq(schema.messages.status, "failed")
46
+ )
47
+ );
48
+ if (!failedMessage) {
49
+ throw createError({
50
+ statusCode: 404,
51
+ statusMessage: "Failed message not found"
52
+ });
53
+ }
54
+ const [userMessage] = await db.select().from(schema.messages).where(
55
+ and(
56
+ eq(schema.messages.conversationId, conversationId),
57
+ eq(schema.messages.role, "user"),
58
+ lt(schema.messages.createdAt, failedMessage.createdAt)
59
+ )
60
+ ).orderBy(desc(schema.messages.createdAt)).limit(1);
61
+ if (!userMessage) {
62
+ throw createError({
63
+ statusCode: 404,
64
+ statusMessage: "User message not found"
65
+ });
66
+ }
67
+ await db.update(schema.messages).set({
68
+ content: "",
69
+ status: "pending",
70
+ reasoningData: null,
71
+ files: null
72
+ }).where(eq(schema.messages.id, messageId));
73
+ logger.info({ conversationId, messageId }, "Message retry initiated");
74
+ const trustedSettings = conversation.appliedSettingsSnapshot ? null : await resolveWorkspaceSettings(event, context, db);
75
+ const appliedSettings = getConversationAppliedSettings(conversation, trustedSettings);
76
+ const needsNewThread = conversation.threadSessionId === null;
77
+ const fileUrls = mergeFileUrls(appliedSettings.contextFiles, userMessage.files);
78
+ const knowledgeSources = appliedSettings.knowledgeSources ?? null;
79
+ const hasKnowledgeSources = knowledgeSources !== null && knowledgeSources.length > 0;
80
+ const { vaultUrl } = useRuntimeConfig();
81
+ const messageWithContext = buildMessageWithContext(
82
+ userMessage.content.trim(),
83
+ appliedSettings.systemMessage ?? null,
84
+ knowledgeSources,
85
+ needsNewThread,
86
+ needsNewThread ? renderSystemPrompt(vaultUrl) : ""
87
+ );
88
+ const canvasTools = appliedSettings.canvasTools;
89
+ const externalSkillRefs = appliedSettings.externalSkills?.map((skill) => skill.ref) ?? [];
90
+ const skills = externalSkillRefs.length > 0 ? externalSkillRefs : void 0;
91
+ const effectiveModel = isValidModel(conversation.model) ? conversation.model : void 0;
92
+ const messageTitle = truncateTitle(userMessage.content);
93
+ const settingsTimestamp = getWorkspaceSettingsUpdatedAt(appliedSettings);
94
+ if (!conversation.appliedSettingsSnapshot && trustedSettings) {
95
+ await db.update(schema.conversations).set({
96
+ appliedSettingsAt: settingsTimestamp,
97
+ appliedSettingsSnapshot: serializeResolvedWorkspaceSettings(trustedSettings),
98
+ updatedAt: /* @__PURE__ */ new Date()
99
+ }).where(and(
100
+ eq(schema.conversations.id, conversationId),
101
+ isNull(schema.conversations.appliedSettingsSnapshot)
102
+ ));
103
+ }
104
+ const processAgent = async () => {
105
+ try {
106
+ if (needsNewThread) {
107
+ let environmentVariables = {};
108
+ try {
109
+ environmentVariables = await resolveWorkspaceCredentials(event, context.workspaceId);
110
+ } catch (error) {
111
+ logger.warn({ conversationId, messageId, error }, "Failed to resolve workspace credentials on retry, proceeding without env vars");
112
+ }
113
+ const hasEnvironmentVariables = Object.keys(environmentVariables).length > 0;
114
+ const result = await createChatAgentSession(token, {
115
+ message: messageWithContext,
116
+ fileUrls,
117
+ model: effectiveModel,
118
+ customTools: canvasTools?.length ? { canvas: canvasTools } : void 0,
119
+ tools: hasKnowledgeSources ? { workstationQueryTool: true } : void 0,
120
+ environmentVariables: hasEnvironmentVariables ? environmentVariables : void 0,
121
+ skills
122
+ });
123
+ if (result.success) {
124
+ logger.info({ conversationId, messageId, sessionId: result.sessionId }, "New agent thread created on retry");
125
+ await db.update(schema.conversations).set({
126
+ threadSessionId: result.sessionId,
127
+ title: messageTitle,
128
+ appliedSettingsAt: settingsTimestamp,
129
+ model: effectiveModel ?? null,
130
+ updatedAt: /* @__PURE__ */ new Date()
131
+ }).where(eq(schema.conversations.id, conversationId));
132
+ } else {
133
+ logger.warn({ conversationId, messageId, error: result.error }, "Agent thread creation failed on retry");
134
+ await db.update(schema.messages).set({
135
+ content: `Erro: ${result.error}`,
136
+ status: "failed"
137
+ }).where(eq(schema.messages.id, messageId));
138
+ }
139
+ } else {
140
+ const result = await continueSession(token, conversation.threadSessionId, {
141
+ content: userMessage.content.trim(),
142
+ fileUrls,
143
+ model: effectiveModel
144
+ });
145
+ if (!result.success) {
146
+ logger.warn({ conversationId, messageId, error: result.error }, "Agent session continue failed on retry");
147
+ await db.update(schema.messages).set({
148
+ content: `Erro: ${result.error}`,
149
+ status: "failed"
150
+ }).where(eq(schema.messages.id, messageId));
151
+ }
152
+ await db.update(schema.conversations).set({
153
+ ...effectiveModel ? { model: effectiveModel } : {},
154
+ updatedAt: /* @__PURE__ */ new Date()
155
+ }).where(eq(schema.conversations.id, conversationId));
156
+ }
157
+ } catch (error) {
158
+ logger.error({ error }, "Failed to process agent retry");
159
+ await db.update(schema.messages).set({
160
+ content: `Erro: ${needsNewThread ? "Falha ao conectar ao agente" : "Falha ao continuar a sess\xE3o"}`,
161
+ status: "failed"
162
+ }).where(eq(schema.messages.id, messageId));
163
+ }
164
+ };
165
+ void processAgent();
166
+ const [updatedMessage] = await db.select().from(schema.messages).where(eq(schema.messages.id, messageId));
167
+ return updatedMessage;
168
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,220 @@
1
+ import { and, asc, eq, gt, isNotNull } from "drizzle-orm";
2
+ import { APIKeyAuthStrategy, VaultFile } from "@meistrari/vault-sdk";
3
+ import { schema, useDb } from "#chat-runtime/server/db";
4
+ import { extractContentFromSession, getAgentDataToken, getSessionStatus } from "#chat-runtime/server/utils/agent-api";
5
+ import { resolveChatContext } from "#chat-runtime/server/utils/chat-context";
6
+ import { detectFilesInText } from "#chat-runtime/utils/file";
7
+ import { logger } from "#chat-runtime/server/utils/logger";
8
+ async function getExistingFileUrls(db, conversationId) {
9
+ const messagesWithFiles = await db.select({ files: schema.messages.files }).from(schema.messages).where(and(
10
+ eq(schema.messages.conversationId, conversationId),
11
+ isNotNull(schema.messages.files)
12
+ ));
13
+ const urls = /* @__PURE__ */ new Set();
14
+ for (const message of messagesWithFiles) {
15
+ if (Array.isArray(message.files)) {
16
+ for (const file of message.files) {
17
+ if (file?.url) {
18
+ urls.add(file.url);
19
+ }
20
+ }
21
+ }
22
+ }
23
+ return urls;
24
+ }
25
+ async function extractAssistantFiles(content, authToken) {
26
+ const detected = detectFilesInText(content);
27
+ const vaultFiles = detected.filter((f) => f.type === "vault");
28
+ if (vaultFiles.length === 0)
29
+ return [];
30
+ const { vaultUrl } = useRuntimeConfig();
31
+ const filesWithMetadata = await Promise.all(
32
+ vaultFiles.map(async (file) => {
33
+ let name = file.name;
34
+ let mimeType = file.mimeType !== "unknown" ? file.mimeType : void 0;
35
+ let size;
36
+ if (vaultUrl) {
37
+ try {
38
+ const authStrategy = new APIKeyAuthStrategy(authToken);
39
+ const vaultFile = await VaultFile.fromVaultReference({
40
+ reference: file.reference,
41
+ config: { authStrategy, vaultUrl }
42
+ });
43
+ await vaultFile.populateMetadata();
44
+ if (vaultFile.metadata?.originalFileName) {
45
+ name = vaultFile.metadata.originalFileName;
46
+ }
47
+ if (vaultFile.metadata?.mimeType) {
48
+ mimeType = vaultFile.metadata.mimeType;
49
+ }
50
+ if (vaultFile.metadata?.size) {
51
+ size = vaultFile.metadata.size;
52
+ }
53
+ } catch {
54
+ logger.debug({ reference: file.reference }, "Vault metadata fetch failed for assistant file");
55
+ }
56
+ }
57
+ return {
58
+ url: file.reference,
59
+ name,
60
+ mimeType,
61
+ source: "assistant",
62
+ size
63
+ };
64
+ })
65
+ );
66
+ return filesWithMetadata;
67
+ }
68
+ export default defineEventHandler(async (event) => {
69
+ const context = resolveChatContext(event);
70
+ const token = getAgentDataToken(event);
71
+ const db = useDb();
72
+ const conversationId = getRouterParam(event, "id");
73
+ const query = getQuery(event);
74
+ const after = query.after;
75
+ if (!conversationId) {
76
+ throw createError({
77
+ statusCode: 400,
78
+ statusMessage: "Conversation ID is required"
79
+ });
80
+ }
81
+ const conditions = [eq(schema.messages.conversationId, conversationId)];
82
+ if (after) {
83
+ const afterDate = new Date(after);
84
+ if (!Number.isNaN(afterDate.getTime())) {
85
+ conditions.push(gt(schema.messages.createdAt, afterDate));
86
+ }
87
+ }
88
+ const [conversationResult, messages] = await Promise.all([
89
+ db.select().from(schema.conversations).where(
90
+ and(
91
+ eq(schema.conversations.id, conversationId),
92
+ eq(schema.conversations.workspaceId, context.workspaceId)
93
+ )
94
+ ),
95
+ db.select().from(schema.messages).where(and(...conditions)).orderBy(asc(schema.messages.createdAt))
96
+ ]);
97
+ const [conversation] = conversationResult;
98
+ if (!conversation) {
99
+ throw createError({
100
+ statusCode: 404,
101
+ statusMessage: "Conversation not found"
102
+ });
103
+ }
104
+ const pendingMessage = messages.find((m) => m.status === "pending");
105
+ const lastAssistantMessage = messages.findLast((m) => m.role === "assistant" && m.status === "completed");
106
+ if (pendingMessage && conversation.threadSessionId) {
107
+ logger.debug({ conversationId, messageId: pendingMessage.id, sessionId: conversation.threadSessionId }, "Polling pending message");
108
+ const sessionResult = await getSessionStatus(token, conversation.threadSessionId);
109
+ if (sessionResult.success) {
110
+ const agentSession = sessionResult.data;
111
+ const updateData = {};
112
+ const lastSyncedUuid = lastAssistantMessage?.externalUuid;
113
+ const lastSyncedIndex = lastSyncedUuid ? agentSession.reasoning?.findIndex((r) => r.uuid === lastSyncedUuid) ?? -1 : -1;
114
+ const newReasoning = agentSession.reasoning?.slice(lastSyncedIndex + 1);
115
+ const hasNewReasoning = newReasoning && newReasoning.length > 0;
116
+ if (hasNewReasoning) {
117
+ updateData.reasoningData = newReasoning;
118
+ const lastReasoningItem = newReasoning.at(-1);
119
+ if (lastReasoningItem?.uuid) {
120
+ updateData.externalUuid = lastReasoningItem.uuid;
121
+ }
122
+ if (!pendingMessage.ttft) {
123
+ const userMessage = messages.findLast((m) => m.role === "user");
124
+ if (userMessage) {
125
+ const ttft = Date.now() - userMessage.createdAt.getTime();
126
+ updateData.ttft = String(ttft);
127
+ }
128
+ }
129
+ }
130
+ if (agentSession.status === "completed" || agentSession.status === "waiting_messages") {
131
+ if (hasNewReasoning) {
132
+ const content = extractContentFromSession(agentSession, newReasoning);
133
+ updateData.content = content;
134
+ updateData.status = "completed";
135
+ updateData.updatedAt = /* @__PURE__ */ new Date();
136
+ logger.info({ conversationId, messageId: pendingMessage.id, status: "completed" }, "Message completed");
137
+ const assistantFiles = await extractAssistantFiles(content, token);
138
+ if (assistantFiles.length > 0) {
139
+ const existingUrls = await getExistingFileUrls(db, conversationId);
140
+ const newFiles = assistantFiles.filter((f) => !existingUrls.has(f.url));
141
+ if (newFiles.length > 0) {
142
+ updateData.files = newFiles;
143
+ }
144
+ }
145
+ }
146
+ } else if (agentSession.status === "failed") {
147
+ const errorContent = agentSession.error || "Agent execution failed";
148
+ updateData.content = `Error: ${errorContent}`;
149
+ updateData.status = agentSession.status;
150
+ updateData.updatedAt = /* @__PURE__ */ new Date();
151
+ logger.warn({ conversationId, messageId: pendingMessage.id, status: "failed" }, "Message failed");
152
+ }
153
+ if (Object.keys(updateData).length > 0) {
154
+ await db.update(schema.messages).set(updateData).where(eq(schema.messages.id, pendingMessage.id));
155
+ if ((updateData.status === "completed" || updateData.status === "failed") && agentSession.result?.usage) {
156
+ const usage = agentSession.result.usage;
157
+ const breakdown = agentSession.result?.usageBreakdown;
158
+ const serverToolUse = breakdown?.serverToolUse;
159
+ const webSearchRequests = typeof serverToolUse?.web_search_requests === "number" ? serverToolUse.web_search_requests : null;
160
+ const webFetchRequests = typeof serverToolUse?.web_fetch_requests === "number" ? serverToolUse.web_fetch_requests : null;
161
+ void db.insert(schema.conversationUsage).values({
162
+ workspaceId: context.workspaceId,
163
+ conversationId,
164
+ promptTokens: usage.promptTokens ?? 0,
165
+ completionTokens: usage.completionTokens ?? 0,
166
+ totalTokens: usage.totalTokens ?? 0,
167
+ promptCost: String(usage.promptCost ?? 0),
168
+ completionCost: String(usage.completionCost ?? 0),
169
+ totalCost: String(usage.totalCost ?? 0),
170
+ durationMs: usage.duration ?? null,
171
+ turns: usage.turns ?? null,
172
+ userId: context.user.id,
173
+ userEmail: context.user.email ?? null,
174
+ model: agentSession.model ?? null,
175
+ sessionId: conversation.threadSessionId,
176
+ cacheReadInputTokens: breakdown?.cacheReadInputTokens ?? null,
177
+ cacheCreationInputTokens: breakdown?.cacheCreationInputTokens ?? null,
178
+ modelUsage: breakdown?.modelUsage ?? null,
179
+ durationApiMs: breakdown?.durationApiMs ?? null,
180
+ webSearchRequests,
181
+ webFetchRequests
182
+ }).onConflictDoUpdate({
183
+ target: schema.conversationUsage.conversationId,
184
+ set: {
185
+ promptTokens: usage.promptTokens ?? 0,
186
+ completionTokens: usage.completionTokens ?? 0,
187
+ totalTokens: usage.totalTokens ?? 0,
188
+ promptCost: String(usage.promptCost ?? 0),
189
+ completionCost: String(usage.completionCost ?? 0),
190
+ totalCost: String(usage.totalCost ?? 0),
191
+ durationMs: usage.duration ?? null,
192
+ turns: usage.turns ?? null,
193
+ model: agentSession.model ?? null,
194
+ cacheReadInputTokens: breakdown?.cacheReadInputTokens ?? null,
195
+ cacheCreationInputTokens: breakdown?.cacheCreationInputTokens ?? null,
196
+ modelUsage: breakdown?.modelUsage ?? null,
197
+ durationApiMs: breakdown?.durationApiMs ?? null,
198
+ webSearchRequests,
199
+ webFetchRequests,
200
+ updatedAt: /* @__PURE__ */ new Date()
201
+ }
202
+ }).catch((error) => {
203
+ console.warn("Failed to track conversation usage:", error);
204
+ });
205
+ }
206
+ const updatedMessages = messages.map(
207
+ (m) => m.id === pendingMessage.id ? { ...m, ...updateData } : m
208
+ );
209
+ if (updateData.files && updateData.files.length > 0) {
210
+ return {
211
+ messages: updatedMessages,
212
+ newFiles: updateData.files
213
+ };
214
+ }
215
+ return { messages: updatedMessages };
216
+ }
217
+ }
218
+ }
219
+ return { messages };
220
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;