@promptbook/cli 0.112.0-99 → 0.113.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 (850) hide show
  1. package/README.md +76 -44
  2. package/agents/default/developer.book +24 -0
  3. package/apps/agents-server/README.md +19 -2
  4. package/apps/agents-server/env-manual/GITHUB_APP.md +1 -1
  5. package/apps/agents-server/next.config.ts +41 -1
  6. package/apps/agents-server/package.json +1 -1
  7. package/apps/agents-server/playwright.config.ts +3 -0
  8. package/apps/agents-server/public/promptbook-logo-blue.png +0 -0
  9. package/apps/agents-server/public/promptbook-logo-white.png +0 -0
  10. package/apps/agents-server/scripts/prerender-homepage.js +76 -1
  11. package/apps/agents-server/src/app/AddAgentButton.tsx +0 -5
  12. package/apps/agents-server/src/app/[agentName]/layout.tsx +1 -0
  13. package/apps/agents-server/src/app/actions.ts +70 -9
  14. package/apps/agents-server/src/app/admin/about/page.tsx +1 -1
  15. package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +4 -1
  16. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +3 -0
  17. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackTable.tsx +13 -8
  18. package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +2 -4
  19. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +3 -0
  20. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryTable.tsx +13 -8
  21. package/apps/agents-server/src/app/admin/chat-history/page.tsx +2 -4
  22. package/apps/agents-server/src/app/admin/cli-access/CliAccessClient.tsx +1 -3
  23. package/apps/agents-server/src/app/admin/code-runners/CodeRunnersClient.tsx +19 -11
  24. package/apps/agents-server/src/app/admin/custom-css/CustomCssClient.tsx +4 -0
  25. package/apps/agents-server/src/app/admin/custom-css/CustomCssEditorPanel.tsx +7 -1
  26. package/apps/agents-server/src/app/admin/custom-css/CustomCssFilesPanel.tsx +7 -1
  27. package/apps/agents-server/src/app/admin/custom-js/CustomJsClient.tsx +11 -0
  28. package/apps/agents-server/src/app/admin/custom-js/CustomJsEditorPanel.tsx +7 -1
  29. package/apps/agents-server/src/app/admin/custom-js/CustomJsFilesPanel.tsx +7 -1
  30. package/apps/agents-server/src/app/admin/files/FilesGalleryClient.tsx +4 -0
  31. package/apps/agents-server/src/app/admin/files/FilesGalleryGrid.tsx +9 -11
  32. package/apps/agents-server/src/app/admin/files/FilesGalleryTable.tsx +9 -8
  33. package/apps/agents-server/src/app/admin/image-generator-test/ImageAttachmentsEditor.tsx +30 -9
  34. package/apps/agents-server/src/app/admin/images/ImagesGalleryClient.tsx +4 -0
  35. package/apps/agents-server/src/app/admin/images/ImagesGalleryGrid.tsx +16 -11
  36. package/apps/agents-server/src/app/admin/images/ImagesGalleryTable.tsx +18 -9
  37. package/apps/agents-server/src/app/admin/limits/LimitsClient.tsx +11 -12
  38. package/apps/agents-server/src/app/admin/login-methods/shibboleth/page.tsx +355 -0
  39. package/apps/agents-server/src/app/admin/logs/LogsClient.tsx +9 -3
  40. package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +7 -6
  41. package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +671 -45
  42. package/apps/agents-server/src/app/admin/servers/CreateServerDialog.tsx +22 -1
  43. package/apps/agents-server/src/app/admin/servers/ServersRegistryTable.tsx +14 -13
  44. package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +57 -20
  45. package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +4 -2
  46. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +14 -15
  47. package/apps/agents-server/src/app/admin/task-manager/TaskManagerTasksCard.tsx +4 -1
  48. package/apps/agents-server/src/app/admin/task-manager/useTaskManagerState.ts +6 -9
  49. package/apps/agents-server/src/app/admin/update/CustomCommitPicker.tsx +258 -0
  50. package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +627 -137
  51. package/apps/agents-server/src/app/admin/usage/UsageClient.tsx +4 -2
  52. package/apps/agents-server/src/app/admin/usage/UsageClientAnalyticsPanels.tsx +6 -4
  53. package/apps/agents-server/src/app/admin/usage/UsageClientFormatting.ts +6 -12
  54. package/apps/agents-server/src/app/admin/usage/UsageClientTimelineChart.tsx +7 -4
  55. package/apps/agents-server/src/app/admin/usage/useUsageClientState.ts +12 -4
  56. package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +27 -15
  57. package/apps/agents-server/src/app/agents/[agentName]/ActiveAgentBreadcrumbBinder.tsx +30 -0
  58. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +13 -2
  59. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +20 -25
  60. package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +7 -5
  61. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +2 -0
  62. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/messages/route.ts +4 -11
  63. package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
  64. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +7 -1
  65. package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorHistory.ts +9 -2
  66. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryPayloadState.ts +38 -4
  67. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistorySyncOperations.ts +4 -1
  68. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatPageLayout.tsx +2 -2
  69. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +19 -13
  70. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +30 -16
  71. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistoryClientState.ts +2 -15
  72. package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
  73. package/apps/agents-server/src/app/agents/[agentName]/chat/useCanonicalAgentChatPanelState.ts +58 -7
  74. package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +6 -1
  75. package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +6 -2
  76. package/apps/agents-server/src/app/agents/[agentName]/integration/CalendarIntegrationSection.tsx +23 -5
  77. package/apps/agents-server/src/app/agents/[agentName]/layout.tsx +47 -1
  78. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +4 -2
  79. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +9 -4
  80. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +4 -1
  81. package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +10 -3
  82. package/apps/agents-server/src/app/api/admin/cli-access/route.ts +27 -123
  83. package/apps/agents-server/src/app/api/admin/code-runners/authentication/route.ts +33 -125
  84. package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
  85. package/apps/agents-server/src/app/api/admin/servers/route.ts +5 -0
  86. package/apps/agents-server/src/app/api/admin/update/commits/route.ts +35 -0
  87. package/apps/agents-server/src/app/api/admin/update/log/route.ts +42 -0
  88. package/apps/agents-server/src/app/api/admin/update/route.ts +10 -2
  89. package/apps/agents-server/src/app/api/agent-folders/[folderId]/visibility/route.ts +19 -7
  90. package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +39 -25
  91. package/apps/agents-server/src/app/api/agents/export/route.ts +67 -0
  92. package/apps/agents-server/src/app/api/agents/import/route.ts +168 -0
  93. package/apps/agents-server/src/app/api/auth/change-password/route.ts +53 -6
  94. package/apps/agents-server/src/app/api/auth/login/route.ts +17 -16
  95. package/apps/agents-server/src/app/api/auth/logout/route.ts +2 -10
  96. package/apps/agents-server/src/app/api/auth/shibboleth/acs/route.ts +112 -0
  97. package/apps/agents-server/src/app/api/auth/shibboleth/login/route.ts +70 -0
  98. package/apps/agents-server/src/app/api/auth/shibboleth/metadata/route.ts +15 -0
  99. package/apps/agents-server/src/app/api/auth/shibboleth/status/route.ts +17 -0
  100. package/apps/agents-server/src/app/api/chat/citation-label/route.ts +133 -0
  101. package/apps/agents-server/src/app/api/chat/export/pdf/route.ts +167 -2
  102. package/apps/agents-server/src/app/api/chat/route.ts +29 -7
  103. package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +2 -2
  104. package/apps/agents-server/src/app/api/chat-feedback/route.ts +3 -3
  105. package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +2 -2
  106. package/apps/agents-server/src/app/api/chat-history/export/route.ts +2 -2
  107. package/apps/agents-server/src/app/api/chat-history/route.ts +3 -3
  108. package/apps/agents-server/src/app/api/chat-streaming/route.ts +29 -0
  109. package/apps/agents-server/src/app/api/elevenlabs/tts/route.ts +60 -2
  110. package/apps/agents-server/src/app/api/emails/incoming/sendgrid/route.ts +24 -2
  111. package/apps/agents-server/src/app/api/federated-agents/route.ts +1 -1
  112. package/apps/agents-server/src/app/api/health/route.ts +18 -0
  113. package/apps/agents-server/src/app/api/images/[filename]/route.ts +108 -2
  114. package/apps/agents-server/src/app/api/internal/agent-runner-limits/route.ts +52 -0
  115. package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +17 -4
  116. package/apps/agents-server/src/app/api/metadata/export/route.ts +34 -0
  117. package/apps/agents-server/src/app/api/metadata/import/route.ts +47 -0
  118. package/apps/agents-server/src/app/api/metadata/route.ts +4 -0
  119. package/apps/agents-server/src/app/api/openai/v1/audio/transcriptions/route.ts +111 -2
  120. package/apps/agents-server/src/app/api/page-preview/check/route.ts +49 -0
  121. package/apps/agents-server/src/app/api/page-preview/screenshot/route.ts +64 -0
  122. package/apps/agents-server/src/app/api/scrape/route.ts +18 -0
  123. package/apps/agents-server/src/app/api/team-agent-profile/route.ts +20 -0
  124. package/apps/agents-server/src/app/api/upload/route.ts +204 -220
  125. package/apps/agents-server/src/app/api/users/[username]/route.ts +3 -2
  126. package/apps/agents-server/src/app/api/users/route.ts +8 -7
  127. package/apps/agents-server/src/app/api/v1/agents/[agentId]/route.ts +17 -8
  128. package/apps/agents-server/src/app/api/v1/agents/route.ts +2 -0
  129. package/apps/agents-server/src/app/dashboard/page.tsx +12 -17
  130. package/apps/agents-server/src/app/docs/[docId]/page.tsx +1 -1
  131. package/apps/agents-server/src/app/docs/page.tsx +1 -1
  132. package/apps/agents-server/src/app/globals.css +179 -0
  133. package/apps/agents-server/src/app/layout.tsx +33 -4
  134. package/apps/agents-server/src/app/recycle-bin/actions.ts +3 -0
  135. package/apps/agents-server/src/app/recycle-bin/page.tsx +1 -1
  136. package/apps/agents-server/src/app/s3/[first]/[second]/[hash]/[filename]/route.ts +52 -0
  137. package/apps/agents-server/src/app/swagger/SwaggerApiKeysPanel.tsx +4 -1
  138. package/apps/agents-server/src/app/system/settings/KeybindingsSettingsClient.tsx +13 -7
  139. package/apps/agents-server/src/app/system/user-memory/UserMemoryClient.tsx +4 -2
  140. package/apps/agents-server/src/app/system/user-wallet/UserWalletClient.tsx +3 -0
  141. package/apps/agents-server/src/app/system/user-wallet/UserWalletRecordsTable.tsx +5 -1
  142. package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorClient.tsx +3 -0
  143. package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorSidebar.tsx +7 -8
  144. package/apps/agents-server/src/components/AdminTerminal/AdminTerminalCard.tsx +13 -70
  145. package/apps/agents-server/src/components/AdminTerminal/AdminXtermTerminal.tsx +330 -0
  146. package/apps/agents-server/src/components/AdminTerminal/useAdminTerminalSession.ts +45 -5
  147. package/apps/agents-server/src/components/AgentContextMenu/useAgentContextMenuItems.ts +27 -19
  148. package/apps/agents-server/src/components/AgentProfile/AgentCapabilityChips.tsx +39 -5
  149. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +4 -7
  150. package/apps/agents-server/src/components/AgentProfile/AgentProfileImage.tsx +8 -2
  151. package/apps/agents-server/src/components/ApplicationErrorPage/ApplicationErrorPage.tsx +118 -12
  152. package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +4 -4
  153. package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +9 -9
  154. package/apps/agents-server/src/components/FileUploadAvailability/FileUploadAvailabilityContext.tsx +50 -0
  155. package/apps/agents-server/src/components/FileUploadAvailability/FileUploadUnavailableNotice.tsx +45 -0
  156. package/apps/agents-server/src/components/Footer/Footer.tsx +10 -9
  157. package/apps/agents-server/src/components/Footer/getCommitFooterEmoji.ts +112 -0
  158. package/apps/agents-server/src/components/Header/ActiveAgentBreadcrumbContext.tsx +82 -0
  159. package/apps/agents-server/src/components/Header/Header.tsx +24 -15
  160. package/apps/agents-server/src/components/Header/HeaderTypes.ts +6 -0
  161. package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +51 -1
  162. package/apps/agents-server/src/components/Header/useHeaderActiveAgent.ts +26 -7
  163. package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +0 -5
  164. package/apps/agents-server/src/components/Homepage/AgentCard.tsx +7 -1
  165. package/apps/agents-server/src/components/Homepage/AgentsList.tsx +22 -1
  166. package/apps/agents-server/src/components/Homepage/AgentsListHeader.tsx +85 -1
  167. package/apps/agents-server/src/components/Homepage/AgentsListListView.tsx +6 -0
  168. package/apps/agents-server/src/components/Homepage/AgentsListViewContent.tsx +6 -0
  169. package/apps/agents-server/src/components/Homepage/Card.tsx +1 -1
  170. package/apps/agents-server/src/components/Homepage/Section.tsx +3 -1
  171. package/apps/agents-server/src/components/Homepage/SortableFolderCard.tsx +7 -1
  172. package/apps/agents-server/src/components/Homepage/hiddenFolders.ts +104 -0
  173. package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +525 -0
  174. package/apps/agents-server/src/components/Homepage/useAgentsListQueryState.ts +35 -0
  175. package/apps/agents-server/src/components/Homepage/useAgentsListState.ts +38 -4
  176. package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +93 -70
  177. package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +52 -12
  178. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoNewAgentWizard.tsx +151 -0
  179. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoOnboardingNavigation.tsx +50 -0
  180. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/BookLanguagePanel.tsx +125 -0
  181. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/DropZone.tsx +83 -0
  182. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/EmailTestRun.tsx +216 -0
  183. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/KnowledgeList.tsx +79 -0
  184. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/Logo.tsx +20 -0
  185. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownBookEditor.tsx +154 -0
  186. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownPreview.tsx +188 -0
  187. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/RailStepper.tsx +115 -0
  188. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/StepFrame.tsx +47 -0
  189. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/TestChat.tsx +159 -0
  190. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/WizardShell.tsx +114 -0
  191. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/brand/RailArtwork.tsx +60 -0
  192. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/BookStep.tsx +135 -0
  193. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/DoneStep.tsx +215 -0
  194. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/KnowledgeStep.tsx +152 -0
  195. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/TestStep.tsx +262 -0
  196. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/ZadaniStep.tsx +64 -0
  197. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Badge.tsx +41 -0
  198. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Banner.tsx +69 -0
  199. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Button.tsx +77 -0
  200. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Card.tsx +33 -0
  201. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Field.tsx +103 -0
  202. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/IconButton.tsx +40 -0
  203. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Spinner.tsx +14 -0
  204. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/tokens.ts +37 -0
  205. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/bookSections.ts +62 -0
  206. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/emailScenarios.ts +22 -0
  207. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/steps.ts +46 -0
  208. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/index.ts +11 -0
  209. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/cn.ts +4 -0
  210. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/format.ts +9 -0
  211. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/id.ts +11 -0
  212. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentEvalService.ts +30 -0
  213. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentTestService.ts +69 -0
  214. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/bookService.ts +21 -0
  215. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/createManGoAgentSource.ts +107 -0
  216. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/draftService.ts +45 -0
  217. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/uploadService.ts +27 -0
  218. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/OnboardingProvider.tsx +121 -0
  219. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/types.ts +52 -0
  220. package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +7 -3
  221. package/apps/agents-server/src/components/NewAgentDialog/NewAgentWizardKnowledgeStep.tsx +6 -0
  222. package/apps/agents-server/src/components/NewAgentDialog/createNewAgentWizardSource.ts +1 -1
  223. package/apps/agents-server/src/components/NewAgentDialog/trackNewAgentCreationEvent.ts +1 -1
  224. package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +113 -14
  225. package/apps/agents-server/src/components/NewAgentDialog/useNewAgentWizardKnowledgeState.ts +8 -1
  226. package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -2
  227. package/apps/agents-server/src/components/Skeleton/ConsolePageLoadingSkeleton.tsx +1 -1
  228. package/apps/agents-server/src/components/Skeleton/DocumentationRouteLoadingSkeleton.tsx +1 -1
  229. package/apps/agents-server/src/components/Skeleton/HomepageLoadingSkeleton.tsx +1 -1
  230. package/apps/agents-server/src/components/UsersList/UsersList.tsx +24 -6
  231. package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +2 -7
  232. package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +1 -1
  233. package/apps/agents-server/src/constants/newAgentWizard.ts +17 -8
  234. package/apps/agents-server/src/constants/serverLimits.ts +41 -2
  235. package/apps/agents-server/src/constants/shibbolethAuth.ts +139 -0
  236. package/apps/agents-server/src/database/$provideClientSql.ts +37 -0
  237. package/apps/agents-server/src/database/$provideSupabaseForServer.ts +41 -0
  238. package/apps/agents-server/src/database/customJavascript.ts +62 -1
  239. package/apps/agents-server/src/database/customStylesheet.ts +60 -1
  240. package/apps/agents-server/src/database/getMetadata.ts +121 -4
  241. package/apps/agents-server/src/database/loadAgentsServerEnvFile.ts +29 -0
  242. package/apps/agents-server/src/database/metadataDefaults.ts +85 -31
  243. package/apps/agents-server/src/database/migrate.ts +8 -2
  244. package/apps/agents-server/src/database/migrations/2026-06-0100-shibboleth-auth.sql +136 -0
  245. package/apps/agents-server/src/database/migrations/2026-06-0200-default-agent-avatar-visual-octopus3d3.sql +16 -0
  246. package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
  247. package/apps/agents-server/src/database/migrations/2026-06-2200-new-agent-wizard-metadata-key.sql +27 -0
  248. package/apps/agents-server/src/database/migrations/2026-06-2201-new-agent-wizard-mango-default.sql +11 -0
  249. package/apps/agents-server/src/database/migrations/2026-06-2600-agent-directory-performance-indexes.sql +14 -0
  250. package/apps/agents-server/src/database/migrations/2026-06-2700-default-agent-avatar-visual-octopus3d4.sql +16 -0
  251. package/apps/agents-server/src/database/seedCoreAgents.ts +234 -0
  252. package/apps/agents-server/src/database/seedDefaultAgents.ts +223 -0
  253. package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +234 -41
  254. package/apps/agents-server/src/generated/reservedPaths.ts +3 -0
  255. package/apps/agents-server/src/instrumentation-client.ts +28 -0
  256. package/apps/agents-server/src/instrumentation.ts +19 -0
  257. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +4 -0
  258. package/apps/agents-server/src/languages/translations/czech.yaml +5 -1
  259. package/apps/agents-server/src/languages/translations/english.yaml +5 -1
  260. package/apps/agents-server/src/message-providers/email/sendgrid/verifySendgridInboundParseWebhook.ts +345 -0
  261. package/apps/agents-server/src/middleware/applyEmbeddingHeader.ts +4 -2
  262. package/apps/agents-server/src/middleware/contentSecurityPolicy.ts +97 -0
  263. package/apps/agents-server/src/middleware/resolveAccessControlResponse.ts +3 -2
  264. package/apps/agents-server/src/middleware/resolveMiddlewareResponse.ts +8 -3
  265. package/apps/agents-server/src/middleware.ts +15 -32
  266. package/apps/agents-server/src/search/createDefaultServerSearchProviders/createFederatedAgentsSearchProvider.ts +1 -1
  267. package/apps/agents-server/src/sentry.edge.config.ts +18 -0
  268. package/apps/agents-server/src/sentry.server.config.ts +19 -0
  269. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +2 -9
  270. package/apps/agents-server/src/tools/$provideCdnForServer.ts +187 -15
  271. package/apps/agents-server/src/tools/BrowserConnectionProvider.ts +2 -19
  272. package/apps/agents-server/src/tools/agent_progress.ts +4 -10
  273. package/apps/agents-server/src/tools/createAgentProgressTools.ts +8 -4
  274. package/apps/agents-server/src/tools/createChatAttachmentToolFunctions.ts +8 -4
  275. package/apps/agents-server/src/tools/createServerChromiumLaunchOptions.ts +44 -0
  276. package/apps/agents-server/src/utils/agentOwnership.ts +54 -5
  277. package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +101 -19
  278. package/apps/agents-server/src/utils/agentVisibility.ts +25 -62
  279. package/apps/agents-server/src/utils/agentsTransfer/createAgentsExportZipStream.ts +81 -0
  280. package/apps/agents-server/src/utils/agentsTransfer/importAgentsFromFiles.ts +852 -0
  281. package/apps/agents-server/src/utils/assertSafeUrl.ts +136 -0
  282. package/apps/agents-server/src/utils/authenticateUser.ts +112 -4
  283. package/apps/agents-server/src/utils/authenticationAttemptRateLimit.ts +504 -0
  284. package/apps/agents-server/src/utils/backup/createBooksBackupZipStream.ts +91 -7
  285. package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +48 -4
  286. package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +6 -5
  287. package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +5 -0
  288. package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +10 -3
  289. package/apps/agents-server/src/utils/chat/resolveAgentsServerCitationLabel.ts +130 -0
  290. package/apps/agents-server/src/utils/chat/resolveCitationSourceLabel.ts +436 -0
  291. package/apps/agents-server/src/utils/chatExport/renderHtmlToPdfOnServer.ts +66 -17
  292. package/apps/agents-server/src/utils/chatExport/sanitizeChatPdfExportHtml.ts +193 -0
  293. package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
  294. package/apps/agents-server/src/utils/createAdminTerminalRouteHandlers.ts +264 -0
  295. package/apps/agents-server/src/utils/createAgentWithDefaultVisibility.ts +3 -1
  296. package/apps/agents-server/src/utils/currentUserIdentity.ts +22 -9
  297. package/apps/agents-server/src/utils/defaultAgents/loadDefaultAgentBooks.ts +145 -0
  298. package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
  299. package/apps/agents-server/src/utils/errorReporting/applicationErrorHandling.ts +45 -0
  300. package/apps/agents-server/src/utils/errorReporting/refreshApplicationDocument.ts +10 -0
  301. package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +381 -0
  302. package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +43 -152
  303. package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
  304. package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +187 -0
  305. package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
  306. package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +15 -8
  307. package/apps/agents-server/src/utils/findAgentForCallerWriteAccess.ts +36 -0
  308. package/apps/agents-server/src/utils/getCurrentUser.ts +2 -1
  309. package/apps/agents-server/src/utils/getFederatedServers.ts +3 -74
  310. package/apps/agents-server/src/utils/getUserById.ts +19 -5
  311. package/apps/agents-server/src/utils/getWellKnownAgentUrl.ts +10 -4
  312. package/apps/agents-server/src/utils/iframe/checkIfUrlCanBeEmbedded.ts +68 -0
  313. package/apps/agents-server/src/utils/interactiveTerminalSession.ts +9 -4
  314. package/apps/agents-server/src/utils/isAdminPasswordEqual.ts +28 -0
  315. package/apps/agents-server/src/utils/isUserGlobalAdmin.ts +3 -1
  316. package/apps/agents-server/src/utils/knowledge/createInlineKnowledgeSourceUploader.ts +24 -5
  317. package/apps/agents-server/src/utils/knowledge/resolveWebsiteKnowledgeSourcesForServer.ts +10 -1
  318. package/apps/agents-server/src/utils/localChatRunner/LocalUserChatJobMetadata.ts +15 -5
  319. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +24 -18
  320. package/apps/agents-server/src/utils/localization/formatServerLanguageHumanReadableDate.ts +70 -0
  321. package/apps/agents-server/src/utils/localization/getRequestServerLanguage.ts +32 -0
  322. package/apps/agents-server/src/utils/metadataConfigurationTransfer.ts +442 -0
  323. package/apps/agents-server/src/utils/paidApiRequestGuard.ts +241 -0
  324. package/apps/agents-server/src/utils/publicUser.ts +59 -0
  325. package/apps/agents-server/src/utils/serverLimits.ts +28 -1
  326. package/apps/agents-server/src/utils/serverManagement/createManagedServer/bootstrapManagedServer.ts +5 -6
  327. package/apps/agents-server/src/utils/serverManagement/createManagedServer/normalizeCreateServerInput.ts +6 -0
  328. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +162 -0
  329. package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +7 -87
  330. package/apps/agents-server/src/utils/serverManagement/createManagedServer.ts +5 -0
  331. package/apps/agents-server/src/utils/session.ts +72 -30
  332. package/apps/agents-server/src/utils/shareTargetPayloads.ts +37 -66
  333. package/apps/agents-server/src/utils/shibbolethAuthentication.ts +957 -0
  334. package/apps/agents-server/src/utils/transpilers/resolveTranspiledTeamExport.ts +10 -10
  335. package/apps/agents-server/src/utils/upload/createBookEditorUploadHandler.ts +19 -28
  336. package/apps/agents-server/src/utils/upload/fileUploadAvailability.ts +91 -0
  337. package/apps/agents-server/src/utils/upload/uploadFileToServer.ts +157 -0
  338. package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +26 -12
  339. package/apps/agents-server/src/utils/userChat/createRunUserChatJobExecutionContext.ts +45 -0
  340. package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +17 -11
  341. package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
  342. package/apps/agents-server/src/utils/userChat/createUserChatHarnessProgressCard.ts +93 -0
  343. package/apps/agents-server/src/utils/userChat/createUserChatRunnerProgressCard.ts +57 -0
  344. package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
  345. package/apps/agents-server/src/utils/userChat/listUserChats.ts +117 -6
  346. package/apps/agents-server/src/utils/userChat/persistUserChatJobProgressCard.ts +40 -0
  347. package/apps/agents-server/src/utils/userChat/resolveUserChatProgressToolHighlights.ts +100 -0
  348. package/apps/agents-server/src/utils/userChat/resolveUserChatWorkerInternalToken.ts +63 -9
  349. package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
  350. package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +30 -0
  351. package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
  352. package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +69 -1
  353. package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +360 -0
  354. package/apps/agents-server/src/utils/validateApiKey.ts +7 -3
  355. package/apps/agents-server/src/utils/vpsConfiguration.ts +8 -1
  356. package/apps/agents-server/src/utils/vpsSelfUpdate.ts +935 -64
  357. package/esm/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
  358. package/esm/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
  359. package/esm/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
  360. package/esm/index.es.js +24308 -18655
  361. package/esm/index.es.js.map +1 -1
  362. package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  363. package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  364. package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  365. package/esm/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
  366. package/esm/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
  367. package/esm/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
  368. package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
  369. package/esm/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
  370. package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  371. package/esm/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
  372. package/esm/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
  373. package/esm/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
  374. package/esm/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
  375. package/esm/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
  376. package/esm/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
  377. package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  378. package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  379. package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  380. package/esm/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
  381. package/esm/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
  382. package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
  383. package/esm/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  384. package/esm/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  385. package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
  386. package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
  387. package/esm/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
  388. package/esm/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
  389. package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  390. package/esm/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
  391. package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  392. package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
  393. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
  394. package/esm/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
  395. package/esm/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
  396. package/esm/src/_packages/components.index.d.ts +4 -0
  397. package/esm/src/_packages/core.index.d.ts +22 -2
  398. package/esm/src/_packages/node.index.d.ts +40 -0
  399. package/esm/src/_packages/types.index.d.ts +20 -0
  400. package/esm/src/avatars/avatarAnimationScheduler.d.ts +4 -0
  401. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  402. package/esm/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
  403. package/esm/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
  404. package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  405. package/esm/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
  406. package/esm/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
  407. package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  408. package/esm/src/book-3.0/CliAgent.d.ts +66 -0
  409. package/esm/src/book-3.0/CliAgent.test.d.ts +1 -0
  410. package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
  411. package/esm/src/book-3.0/LiteAgent.test.d.ts +1 -0
  412. package/esm/src/book-3.0/agentFolderPaths.d.ts +30 -0
  413. package/esm/src/book-3.0/cliAgentEnv.d.ts +33 -0
  414. package/esm/src/book-components/BookEditor/BookEditor.d.ts +6 -5
  415. package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  416. package/esm/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
  417. package/esm/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
  418. package/esm/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
  419. package/esm/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
  420. package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
  421. package/esm/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
  422. package/esm/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
  423. package/esm/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
  424. package/esm/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
  425. package/esm/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  426. package/esm/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
  427. package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  428. package/esm/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
  429. package/esm/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
  430. package/esm/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
  431. package/esm/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
  432. package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  433. package/esm/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
  434. package/esm/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
  435. package/esm/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
  436. package/esm/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  437. package/esm/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
  438. package/esm/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
  439. package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
  440. package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
  441. package/esm/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
  442. package/esm/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
  443. package/esm/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
  444. package/esm/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
  445. package/esm/src/book-components/_common/Modal/Modal.d.ts +1 -1
  446. package/esm/src/book-components/icons/AboutIcon.d.ts +1 -1
  447. package/esm/src/book-components/icons/DownloadIcon.d.ts +1 -1
  448. package/esm/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
  449. package/esm/src/book-components/icons/FullscreenIcon.d.ts +1 -1
  450. package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  451. package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
  452. package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
  453. package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  454. package/esm/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
  455. package/esm/src/cli/cli-commands/agent.d.ts +14 -0
  456. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
  457. package/esm/src/cli/cli-commands/agents-server/run.d.ts +6 -0
  458. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
  459. package/esm/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
  460. package/esm/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  461. package/esm/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  462. package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  463. package/esm/src/cli/cli-commands/coder/server.d.ts +13 -0
  464. package/esm/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
  465. package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
  466. package/esm/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
  467. package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  468. package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
  469. package/esm/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
  470. package/esm/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
  471. package/esm/src/commitments/index.d.ts +2 -1
  472. package/esm/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  473. package/esm/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  474. package/esm/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
  475. package/esm/src/utils/isTimingSafeEqualString.d.ts +25 -0
  476. package/esm/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
  477. package/esm/src/version.d.ts +1 -1
  478. package/package.json +6 -1
  479. package/servers.ts +1 -16
  480. package/src/_packages/components.index.ts +4 -0
  481. package/src/_packages/core.index.ts +22 -2
  482. package/src/_packages/node.index.ts +40 -0
  483. package/src/_packages/types.index.ts +20 -0
  484. package/src/avatars/avatarAnimationScheduler.ts +76 -4
  485. package/src/avatars/types/AvatarVisualDefinition.ts +2 -0
  486. package/src/avatars/visuals/avatarVisualRegistry.ts +4 -0
  487. package/src/avatars/visuals/fractalAvatarVisual.ts +5 -4
  488. package/src/avatars/visuals/minecraft2AvatarVisual.ts +16 -11
  489. package/src/avatars/visuals/minecraftAvatarVisual.ts +21 -7
  490. package/src/avatars/visuals/octopus3d2AvatarVisual.ts +175 -38
  491. package/src/avatars/visuals/octopus3d3AvatarVisual.ts +1068 -0
  492. package/src/avatars/visuals/octopus3d4AvatarVisual.ts +1295 -0
  493. package/src/avatars/visuals/octopus3dAvatarVisual.ts +69 -17
  494. package/src/book-2.0/agent-source/AgentBasicInformation.ts +2 -0
  495. package/src/book-2.0/agent-source/agentSourceVisibility.ts +214 -0
  496. package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.ts +18 -2
  497. package/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.ts +17 -0
  498. package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
  499. package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +7 -1
  500. package/src/book-3.0/Book.ts +3 -1
  501. package/src/book-3.0/BookNodeAgentSource.ts +135 -0
  502. package/src/book-3.0/CliAgent.ts +252 -0
  503. package/src/book-3.0/LiteAgent.ts +468 -0
  504. package/src/book-3.0/agentFolderPaths.ts +38 -0
  505. package/src/book-3.0/cliAgentEnv.ts +46 -0
  506. package/src/book-components/BookEditor/BookEditor.module.css +61 -0
  507. package/src/book-components/BookEditor/BookEditor.tsx +16 -13
  508. package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +72 -0
  509. package/src/book-components/BookEditor/BookEditorActionbar.tsx +35 -5
  510. package/src/book-components/BookEditor/BookEditorBrowserConfig.ts +11 -0
  511. package/src/book-components/BookEditor/BookEditorForClient.tsx +33 -0
  512. package/src/book-components/BookEditor/BookEditorMonaco.tsx +4 -2
  513. package/src/book-components/BookEditor/BookEditorMonacoTokenization.ts +89 -27
  514. package/src/book-components/BookEditor/BookEditorTheme.ts +32 -0
  515. package/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.ts +11 -0
  516. package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +62 -92
  517. package/src/book-components/BookEditor/useBookEditorMonacoLifecycle.ts +1 -5
  518. package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +3 -2
  519. package/src/book-components/BookEditor/useBookEditorMonacoUploads.ts +1 -1
  520. package/src/book-components/Chat/Chat/Chat.module.css +50 -0
  521. package/src/book-components/Chat/Chat/Chat.tsx +4 -0
  522. package/src/book-components/Chat/Chat/ChatCitationModal.tsx +19 -5
  523. package/src/book-components/Chat/Chat/ChatMessageItem.tsx +22 -2
  524. package/src/book-components/Chat/Chat/ChatMessageList.tsx +6 -0
  525. package/src/book-components/Chat/Chat/ChatProps.tsx +6 -0
  526. package/src/book-components/Chat/Chat/ChatToolCallModal.tsx +4 -0
  527. package/src/book-components/Chat/Chat/ChatToolCallModalContent.tsx +4 -0
  528. package/src/book-components/Chat/Chat/CitationIframePreview.tsx +78 -0
  529. package/src/book-components/Chat/Chat/TeamToolCallModalContent.tsx +16 -3
  530. package/src/book-components/Chat/Chat/createChatMessageToolCallRenderModel.ts +2 -9
  531. package/src/book-components/Chat/Chat/useChatPostprocessedMessages.ts +13 -2
  532. package/src/book-components/Chat/MarkdownContent/MarkdownContent.tsx +63 -4
  533. package/src/book-components/Chat/SourceChip/SourceChip.module.css +8 -0
  534. package/src/book-components/Chat/SourceChip/SourceChip.tsx +19 -5
  535. package/src/book-components/Chat/hooks/useResolvedCitationLabel.ts +65 -0
  536. package/src/book-components/Chat/save/html/htmlSaveFormatDefinition.ts +315 -88
  537. package/src/book-components/Chat/save/react/reactSaveFormatDefinition.ts +7 -1
  538. package/src/book-components/Chat/types/ChatMessage.ts +5 -0
  539. package/src/book-components/Chat/types/ChatParticipant.ts +1 -1
  540. package/src/book-components/Chat/types/CitationLabelResolver.ts +9 -0
  541. package/src/book-components/Chat/utils/citationHelpers.ts +90 -2
  542. package/src/book-components/Chat/utils/createCitationFootnoteRenderModel.ts +3 -0
  543. package/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.ts +178 -0
  544. package/src/book-components/Chat/utils/isVisibleChatToolCall.ts +23 -0
  545. package/src/book-components/Chat/utils/parseCitationsFromContent.ts +6 -0
  546. package/src/book-components/Chat/utils/renderMarkdown.ts +3 -2
  547. package/src/book-components/_common/Dropdown/Dropdown.tsx +1 -1
  548. package/src/book-components/_common/MenuHoisting/MenuHoistingContext.tsx +1 -1
  549. package/src/book-components/_common/Modal/Modal.tsx +1 -1
  550. package/src/book-components/icons/AboutIcon.tsx +1 -1
  551. package/src/book-components/icons/DownloadIcon.tsx +1 -1
  552. package/src/book-components/icons/ExitFullscreenIcon.tsx +1 -1
  553. package/src/book-components/icons/FullscreenIcon.tsx +1 -1
  554. package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
  555. package/src/cli/cli-commands/agent/chat.ts +54 -0
  556. package/src/cli/cli-commands/agent/exec.ts +60 -0
  557. package/src/cli/cli-commands/agent-folder/agentProjectPaths.ts +15 -28
  558. package/src/cli/cli-commands/agent.ts +44 -0
  559. package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +325 -33
  560. package/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.ts +15 -2
  561. package/src/cli/cli-commands/agents-server/run.ts +103 -31
  562. package/src/cli/cli-commands/agents-server/startAgentsServer.ts +270 -41
  563. package/src/cli/cli-commands/agents-server.ts +7 -1
  564. package/src/cli/cli-commands/coder/ThinkingLevel.ts +3 -1
  565. package/src/cli/cli-commands/coder/agentCodingFile.ts +1 -1
  566. package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +79 -0
  567. package/src/cli/cli-commands/coder/find-unwritten.ts +58 -0
  568. package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +2 -2
  569. package/src/cli/cli-commands/coder/init.ts +6 -1
  570. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +10 -0
  571. package/src/cli/cli-commands/coder/printInitializationSummary.ts +3 -0
  572. package/src/cli/cli-commands/coder/run.ts +108 -13
  573. package/src/cli/cli-commands/coder/server.ts +259 -0
  574. package/src/cli/cli-commands/coder/waitOptions.ts +24 -0
  575. package/src/cli/cli-commands/coder.ts +6 -0
  576. package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +33 -49
  577. package/src/cli/common/$deprecateCliCommand.ts +10 -1
  578. package/src/cli/promptbookCli.ts +2 -0
  579. package/src/collection/agent-collection/CreateAgentInput.ts +10 -5
  580. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +98 -17
  581. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords.ts +7 -4
  582. package/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.ts +44 -8
  583. package/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.ts +2 -2
  584. package/src/commitments/GOAL/GOAL.ts +7 -2
  585. package/src/commitments/LANGUAGE/LANGUAGE.ts +7 -2
  586. package/src/commitments/META_VISIBILITY/META_VISIBILITY.ts +78 -0
  587. package/src/commitments/TEAM/TEAM.ts +12 -1
  588. package/src/commitments/USE_PROJECT/createUseProjectToolFunctions.ts +8 -1
  589. package/src/commitments/_common/teamInternalAgentAccess.ts +14 -8
  590. package/src/commitments/index.ts +2 -0
  591. package/src/execution/createPipelineExecutor/getKnowledgeForTask.ts +1 -1
  592. package/src/formats/csv/CsvFormatParser.ts +4 -4
  593. package/src/formats/csv/utils/csvParse.ts +2 -2
  594. package/src/import-plugins/JsonFileImportPlugin.ts +15 -2
  595. package/src/import-plugins/TextFileImportPlugin.ts +8 -1
  596. package/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.ts +1 -1
  597. package/src/llm-providers/_common/register/$provideLlmToolsFromEnv.ts +1 -1
  598. package/src/llm-providers/_common/register/$registeredLlmToolsMessage.ts +6 -1
  599. package/src/llm-providers/agent/AgentLlmExecutionTools.ts +2 -2
  600. package/src/llm-providers/agent/AgentLlmExecutionToolsAgentKitRunner.ts +2 -2
  601. package/src/llm-providers/agent/AgentLlmExecutionToolsOpenAiAssistantRunner.ts +2 -2
  602. package/src/llm-providers/anthropic-claude/register-configuration.ts +6 -3
  603. package/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.ts +3 -1
  604. package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
  605. package/src/llm-providers/openai/OpenAiVectorStoreKnowledgeSourcePreparer.ts +1 -1
  606. package/src/other/templates/getTemplatesPipelineCollection.ts +817 -702
  607. package/src/scrapers/_common/utils/getScraperIntermediateSource.ts +2 -2
  608. package/src/scrapers/website/WebsiteScraper.ts +1 -1
  609. package/src/scrapers/website/utils/createShowdownConverter.ts +2 -2
  610. package/src/scripting/javascript/JavascriptEvalExecutionTools.ts +1 -1
  611. package/src/utils/agents/resolveAgentAvatarImageUrl.ts +1 -1
  612. package/src/utils/chat/chatAttachments/resolveChatAttachmentContent.ts +8 -1
  613. package/src/utils/isTimingSafeEqualString.ts +43 -0
  614. package/src/utils/misc/computeHash.ts +2 -2
  615. package/src/utils/random/$randomToken.ts +2 -2
  616. package/src/utils/validators/url/isValidAgentUrl.ts +5 -7
  617. package/src/version.ts +2 -2
  618. package/src/versions.txt +33 -0
  619. package/umd/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
  620. package/umd/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
  621. package/umd/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
  622. package/umd/index.umd.js +24336 -18681
  623. package/umd/index.umd.js.map +1 -1
  624. package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
  625. package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
  626. package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
  627. package/umd/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
  628. package/umd/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
  629. package/umd/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
  630. package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
  631. package/umd/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
  632. package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
  633. package/umd/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
  634. package/umd/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
  635. package/umd/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
  636. package/umd/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
  637. package/umd/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
  638. package/umd/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
  639. package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
  640. package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
  641. package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
  642. package/umd/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
  643. package/umd/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
  644. package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
  645. package/umd/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
  646. package/umd/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
  647. package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
  648. package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
  649. package/umd/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
  650. package/umd/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
  651. package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
  652. package/umd/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
  653. package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
  654. package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
  655. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
  656. package/umd/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
  657. package/umd/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
  658. package/umd/src/_packages/components.index.d.ts +4 -0
  659. package/umd/src/_packages/core.index.d.ts +22 -2
  660. package/umd/src/_packages/node.index.d.ts +40 -0
  661. package/umd/src/_packages/types.index.d.ts +20 -0
  662. package/umd/src/avatars/avatarAnimationScheduler.d.ts +4 -0
  663. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  664. package/umd/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
  665. package/umd/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
  666. package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  667. package/umd/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
  668. package/umd/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
  669. package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
  670. package/umd/src/book-3.0/CliAgent.d.ts +66 -0
  671. package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
  672. package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
  673. package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
  674. package/umd/src/book-3.0/agentFolderPaths.d.ts +30 -0
  675. package/umd/src/book-3.0/cliAgentEnv.d.ts +33 -0
  676. package/umd/src/book-components/BookEditor/BookEditor.d.ts +6 -5
  677. package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
  678. package/umd/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
  679. package/umd/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
  680. package/umd/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
  681. package/umd/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
  682. package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
  683. package/umd/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
  684. package/umd/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
  685. package/umd/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
  686. package/umd/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
  687. package/umd/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
  688. package/umd/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
  689. package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  690. package/umd/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
  691. package/umd/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
  692. package/umd/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
  693. package/umd/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
  694. package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  695. package/umd/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
  696. package/umd/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
  697. package/umd/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
  698. package/umd/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  699. package/umd/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
  700. package/umd/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
  701. package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
  702. package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
  703. package/umd/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
  704. package/umd/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
  705. package/umd/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
  706. package/umd/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
  707. package/umd/src/book-components/_common/Modal/Modal.d.ts +1 -1
  708. package/umd/src/book-components/icons/AboutIcon.d.ts +1 -1
  709. package/umd/src/book-components/icons/DownloadIcon.d.ts +1 -1
  710. package/umd/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
  711. package/umd/src/book-components/icons/FullscreenIcon.d.ts +1 -1
  712. package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
  713. package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
  714. package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
  715. package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
  716. package/umd/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
  717. package/umd/src/cli/cli-commands/agent.d.ts +14 -0
  718. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
  719. package/umd/src/cli/cli-commands/agents-server/run.d.ts +6 -0
  720. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
  721. package/umd/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
  722. package/umd/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
  723. package/umd/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
  724. package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
  725. package/umd/src/cli/cli-commands/coder/server.d.ts +13 -0
  726. package/umd/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
  727. package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
  728. package/umd/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
  729. package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
  730. package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
  731. package/umd/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
  732. package/umd/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
  733. package/umd/src/commitments/index.d.ts +2 -1
  734. package/umd/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  735. package/umd/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  736. package/umd/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
  737. package/umd/src/utils/isTimingSafeEqualString.d.ts +25 -0
  738. package/umd/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
  739. package/umd/src/version.d.ts +1 -1
  740. package/apps/agents-server/src/app/api/long-streaming/route.ts +0 -23
  741. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +0 -108
  742. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +0 -117
  743. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +0 -119
  744. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +0 -74
  745. package/apps/agents-server/src/utils/defaultFederatedAgents/DefaultFederatedAgentsSyncOptions.ts +0 -9
  746. package/apps/agents-server/src/utils/defaultFederatedAgents/ensureDefaultFederatedAgentExists.ts +0 -277
  747. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchCoreOrganizationPayload.ts +0 -39
  748. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchFederatedAgentBook.ts +0 -43
  749. package/apps/agents-server/src/utils/defaultFederatedAgents/fetchWithDefaultFederatedAgentTimeout.ts +0 -28
  750. package/apps/agents-server/src/utils/defaultFederatedAgents/getDefaultFederatedAgentSyncPool.ts +0 -38
  751. package/apps/agents-server/src/utils/defaultFederatedAgents/loadActiveLocalAgentIdsByNormalizedName.ts +0 -41
  752. package/apps/agents-server/src/utils/defaultFederatedAgents/loadDefaultFederatedAgentSyncMetadata.ts +0 -76
  753. package/apps/agents-server/src/utils/defaultFederatedAgents/quoteIdentifier.ts +0 -11
  754. package/apps/agents-server/src/utils/defaultFederatedAgents/scheduleDefaultFederatedAgentsSync.ts +0 -88
  755. package/apps/agents-server/src/utils/defaultFederatedAgents/selectDefaultFederatedAgentsFromOrganizationPayload.ts +0 -181
  756. package/apps/agents-server/src/utils/defaultFederatedAgents/synchronizeDefaultFederatedAgents.ts +0 -77
  757. package/apps/agents-server/src/utils/shibboleth/createShibbolethAuthenticationLogPayload.ts +0 -173
  758. package/apps/agents-server/src/utils/shibboleth/writeShibbolethAuthenticationLog.ts +0 -27
  759. package/apps/agents-server/tests/e2e/authentication-and-navigation.spec.ts.todo +0 -178
  760. package/src/_packages/browser.index.ts +0 -31
  761. package/src/_packages/browser.readme.md +0 -43
  762. package/src/book-2.0/agent-source/parseAgentSourceWithCommitments.test.ts.todo +0 -265
  763. package/src/book-components/BookEditor/BookEditorMonaco.test.tsx.todo +0 -115
  764. package/src/book-components/Chat/utils/renderMarkdown.test.ts.tmp +0 -199
  765. package/src/collection/agent-collection/constructors/agent-collection-in-directory/AgentCollectionInDirectory.test.ts.todo +0 -131
  766. package/src/commands/_common/parseCommand.test.ts.todo +0 -48
  767. package/src/commitments/META_LINK/META_LINK.test.ts.todo +0 -75
  768. package/src/conversion/validation/pipelineStringToJson-errors.test.ts.todo +0 -33
  769. package/src/dialogs/simple-prompt/SimplePromptInterfaceTools.ts +0 -51
  770. package/src/executables/browsers/locateSafari.test.ts.tmp +0 -15
  771. package/src/execution/PromptbookFetch.test-type.ts +0 -14
  772. package/src/execution/createPipelineExecutor/00-createPipelineExecutor.test.ts.todo +0 -0
  773. package/src/execution/execution-report/executionReportJsonToString.test.ts.todo +0 -83
  774. package/src/execution/utils/usageToHuman.test.ts.todo +0 -80
  775. package/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.ts +0 -76
  776. package/src/llm-providers/_common/utils/assertUniqueModels.ts +0 -27
  777. package/src/llm-providers/_multiple/playground/playground.ts +0 -141
  778. package/src/llm-providers/_multiple/playground/tsconfig.json +0 -19
  779. package/src/llm-providers/agent/playground/playground.ts +0 -190
  780. package/src/llm-providers/agent/playground/tsconfig.json +0 -19
  781. package/src/llm-providers/anthropic-claude/playground/playground.ts +0 -99
  782. package/src/llm-providers/anthropic-claude/playground/tsconfig.json +0 -19
  783. package/src/llm-providers/azure-openai/playground/playground.ts +0 -101
  784. package/src/llm-providers/azure-openai/playground/tsconfig.json +0 -19
  785. package/src/llm-providers/ollama/playground/playground.ts +0 -120
  786. package/src/llm-providers/ollama/playground/tsconfig.json +0 -19
  787. package/src/llm-providers/openai/playground/playground.ts +0 -406
  788. package/src/llm-providers/openai/playground/tsconfig.json +0 -19
  789. package/src/llm-providers/remote/playground/playground.ts +0 -144
  790. package/src/llm-providers/remote/playground/tsconfig.json +0 -19
  791. package/src/llm-providers/vercel/playground/playground.ts +0 -133
  792. package/src/llm-providers/vercel/playground/tsconfig.json +0 -19
  793. package/src/personas/preparePersona.test.ts.todo +0 -126
  794. package/src/playground/backup/_playground-boilerplate.ts.txt +0 -37
  795. package/src/playground/backup/playground-agent-os.txt +0 -62
  796. package/src/playground/backup/playground-brj-app.ts.txt +0 -302
  797. package/src/playground/backup/playground-browser-playwright.txt +0 -110
  798. package/src/playground/backup/playground-claude-mcp.txt +0 -43
  799. package/src/playground/backup/playground-document-conversion.txt +0 -84
  800. package/src/playground/backup/playground-glob.ts.txt +0 -42
  801. package/src/playground/backup/playground-mcp-server.txt +0 -1
  802. package/src/playground/backup/playground-openai-agent-kit.txt +0 -73
  803. package/src/playground/backup/playground-openai-function-calling.txt +0 -131
  804. package/src/playground/backup/playground-openai-streaming.ts.txt +0 -68
  805. package/src/playground/backup/playground-scrape-knowledge.txt +0 -65
  806. package/src/playground/backup/playground-scraperFetch.ts.txt +0 -44
  807. package/src/playground/backup/playground-using-openai-compatible-route-on-agents-server.ts.txt +0 -49
  808. package/src/playground/backup/playground-write-pavolhejny-bio.txt +0 -120
  809. package/src/playground/permanent/_boilerplate.ts +0 -54
  810. package/src/playground/permanent/agent-with-browser-playground.ts +0 -92
  811. package/src/playground/permanent/error-handling-playground.ts +0 -103
  812. package/src/playground/playground.ts +0 -36
  813. package/src/playground/tsconfig.json +0 -19
  814. package/src/scrapers/_boilerplate/BoilerplateScraper.test.ts.todo +0 -73
  815. package/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.ts +0 -79
  816. package/src/scrapers/_boilerplate/playground/tsconfig.json +0 -19
  817. package/src/scrapers/_common/utils/files/blobToDataurl.test.ts.todo +0 -17
  818. package/src/scrapers/_common/utils/files/dataurlToBlob.test.ts.todo +0 -52
  819. package/src/scrapers/_common/utils/files/isValidDataurl.test.ts.todo +0 -42
  820. package/src/scrapers/_common/utils/files/shorten.test.ts.todo +0 -13
  821. package/src/scrapers/document/playground/document-scraper-playground.ts +0 -80
  822. package/src/scrapers/document/playground/tsconfig.json +0 -19
  823. package/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.ts +0 -80
  824. package/src/scrapers/document-legacy/playground/tsconfig.json +0 -19
  825. package/src/scrapers/markdown/playground/markdown-scraper-playground.ts +0 -74
  826. package/src/scrapers/markdown/playground/tsconfig.json +0 -19
  827. package/src/scrapers/markitdown/MarkitdownScraper.test.ts.todo +0 -132
  828. package/src/scrapers/markitdown/playground/markitdown-scraper-playground.ts +0 -91
  829. package/src/scrapers/markitdown/playground/tsconfig.json +0 -19
  830. package/src/scrapers/pdf/PdfScraper.test.ts.todo +0 -52
  831. package/src/scrapers/pdf/playground/pdf-scraper-playground.ts +0 -75
  832. package/src/scrapers/pdf/playground/tsconfig.json +0 -19
  833. package/src/scrapers/website/playground/tsconfig.json +0 -19
  834. package/src/scrapers/website/playground/website-scraper-playground.ts +0 -82
  835. package/src/storage/_common/PromptbookStorage.test-type.ts +0 -14
  836. package/src/storage/local-storage/getIndexedDbStorage.ts +0 -36
  837. package/src/storage/local-storage/getLocalStorage.ts +0 -33
  838. package/src/storage/local-storage/getSessionStorage.ts +0 -33
  839. package/src/storage/local-storage/utils/IndexedDbStorageOptions.ts +0 -16
  840. package/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.ts +0 -58
  841. package/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.ts +0 -45
  842. package/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.test.ts.todo +0 -35
  843. package/src/transpilers/openai-sdk/playground/playground.ts +0 -85
  844. package/src/transpilers/openai-sdk/playground/tmp/chatbot-openaisdk-1.js +0 -194
  845. package/src/transpilers/openai-sdk/playground/tmp/package.json +0 -3
  846. package/src/transpilers/openai-sdk/playground/tsconfig.json +0 -18
  847. package/src/utils/editable/utils/findUsableParameters.test.ts.todo +0 -43
  848. package/src/utils/editable/utils/stringifyPipelineJson.test.ts.todo +0 -38
  849. package/src/utils/markdown/prettifyMarkdown.test.ts.tmp +0 -42
  850. package/src/utils/serialization/serializeToPromptbookJavascript.test.ts.todo +0 -116
@@ -2,6 +2,8 @@ import { serializeError } from '@promptbook-local/utils';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
  import { fetchUrlContent } from '../../../../../../src/commitments/USE_BROWSER/fetchUrlContent';
4
4
  import { assertsError } from '../../../../../../src/errors/assertsError';
5
+ import { getCurrentUser } from '../../../utils/getCurrentUser';
6
+ import { assertSafeUrl } from '../../../utils/assertSafeUrl';
5
7
 
6
8
  /**
7
9
  * API endpoint for scraping URL content
@@ -9,9 +11,17 @@ import { assertsError } from '../../../../../../src/errors/assertsError';
9
11
  * This endpoint proxies the server-side scraping functionality to be accessible from the browser.
10
12
  * It uses the fetchUrlContent utility to fetch and convert web content to markdown.
11
13
  *
14
+ * Requires authentication to prevent unauthenticated SSRF abuse.
15
+ * The destination URL is validated against private/internal IP ranges before fetching.
16
+ *
12
17
  * @route GET /api/scrape?url=<url>
13
18
  */
14
19
  export async function GET(request: NextRequest) {
20
+ const currentUser = await getCurrentUser();
21
+ if (!currentUser) {
22
+ return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
23
+ }
24
+
15
25
  try {
16
26
  // Get the URL parameter from the query string
17
27
  const searchParams = request.nextUrl.searchParams;
@@ -22,6 +32,14 @@ export async function GET(request: NextRequest) {
22
32
  return NextResponse.json({ error: 'URL parameter is required' }, { status: 400 });
23
33
  }
24
34
 
35
+ // Guard against SSRF: reject private/internal IPs and non-HTTP(S) schemes
36
+ try {
37
+ assertSafeUrl(url);
38
+ } catch (error) {
39
+ assertsError(error);
40
+ return NextResponse.json({ error: error.message, success: false }, { status: 400 });
41
+ }
42
+
25
43
  // Use the server-side fetchUrlContent utility
26
44
  const content = await fetchUrlContent(url);
27
45
 
@@ -8,7 +8,10 @@ import {
8
8
  resolvePlaceholderImageUrl,
9
9
  resolveProfileImageUrl,
10
10
  } from '../../../../../../src/book-components/Chat/utils/loadAgentProfile';
11
+ import { assertsError } from '../../../../../../src/errors/assertsError';
11
12
  import { isValidAgentUrl } from '../../../../../../src/utils/validators/url/isValidAgentUrl';
13
+ import { assertSafeUrl } from '../../../utils/assertSafeUrl';
14
+ import { getCurrentUser } from '../../../utils/getCurrentUser';
12
15
 
13
16
  /**
14
17
  * Response for team agent profile.
@@ -88,8 +91,17 @@ async function fetchAgentProfile(agentUrl: string, localServerUrl: string): Prom
88
91
  *
89
92
  * The client uses this to render tool call chips without relying on direct cross-origin requests
90
93
  * to the teammate agent.
94
+ *
95
+ * Requires authentication to prevent unauthenticated SSRF abuse and exfiltration of the
96
+ * internal team access token. The destination URL is validated against private/internal
97
+ * IP ranges before any outbound request is made.
91
98
  */
92
99
  export async function GET(request: Request) {
100
+ const currentUser = await getCurrentUser();
101
+ if (!currentUser) {
102
+ return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
103
+ }
104
+
93
105
  const requestUrl = new URL(request.url);
94
106
  const agentUrl = requestUrl.searchParams.get('url');
95
107
 
@@ -97,6 +109,14 @@ export async function GET(request: Request) {
97
109
  return NextResponse.json({ error: 'Invalid agent URL' }, { status: 400 });
98
110
  }
99
111
 
112
+ // Guard against SSRF: reject private/internal IPs and non-HTTP(S) schemes
113
+ try {
114
+ assertSafeUrl(agentUrl);
115
+ } catch (error) {
116
+ assertsError(error);
117
+ return NextResponse.json({ error: error.message }, { status: 400 });
118
+ }
119
+
100
120
  const normalizedUrl = agentUrl.replace(/\/$/, '');
101
121
  const profile = await fetchAgentProfile(normalizedUrl, requestUrl.origin);
102
122
 
@@ -1,305 +1,289 @@
1
- import { $getTableName } from '@/src/database/$getTableName';
2
- import { $provideSupabase } from '@/src/database/$provideSupabase';
3
1
  import { serializeError } from '@promptbook-local/utils';
4
- import type { PostgrestSingleResponse, SupabaseClient } from '@supabase/supabase-js';
5
- import { handleUpload, type HandleUploadBody } from '@vercel/blob/client';
6
2
  import { NextRequest, NextResponse } from 'next/server';
3
+ import { spaceTrim } from 'spacetrim';
7
4
  import { assertsError } from '../../../../../../src/errors/assertsError';
8
- import { getUserIdFromRequest } from '../../../../src/utils/getUserIdFromRequest';
5
+ import { LimitReachedError } from '../../../../../../src/errors/LimitReachedError';
6
+ import { NotAllowed } from '../../../../../../src/errors/NotAllowed';
7
+ import { UnexpectedError } from '../../../../../../src/errors/UnexpectedError';
8
+ import { $getTableName } from '../../../database/$getTableName';
9
+ import { $provideSupabase } from '../../../database/$provideSupabase';
9
10
  import type { AgentsServerDatabase } from '../../../database/schema';
11
+ import {
12
+ $provideCdnForServer,
13
+ isSelfContainedS3StorageSelected,
14
+ resolveCdnPublicUrlForServer,
15
+ } from '../../../tools/$provideCdnForServer';
16
+ import { $provideServer } from '../../../tools/$provideServer';
17
+ import { getSafeCdnPath } from '../../../utils/cdn/utils/getSafeCdnPath';
18
+ import { getUserFileCdnKey } from '../../../utils/cdn/utils/getUserFileCdnKey';
10
19
  import { FILE_SECURITY_CHECKERS } from '../../../file-security-checkers';
20
+ import { getUserIdFromRequest } from '../../../utils/getUserIdFromRequest';
11
21
  import { getMaxFileUploadSizeBytes } from '../../../utils/serverLimits';
22
+ import { resolveFileUploadAvailability } from '../../../utils/upload/fileUploadAvailability';
23
+ import { validateMimeType } from '../../../utils/validators/validateMimeType';
12
24
 
13
25
  /**
14
- * Additional metadata accepted from the client-side upload helper.
26
+ * Default purpose used for uploads when the client does not provide one.
15
27
  *
16
28
  * @private
17
29
  */
18
- type UploadClientPayload = {
19
- purpose?: unknown;
20
- contentType?: unknown;
21
- };
30
+ const DEFAULT_UPLOAD_PURPOSE = 'GENERIC_UPLOAD';
22
31
 
23
32
  /**
24
- * Generic object used for safe JSON parsing in upload payloads.
33
+ * Default MIME type used for unknown uploads.
25
34
  *
26
35
  * @private
27
36
  */
28
- type JsonRecord = Record<string, unknown>;
37
+ const DEFAULT_UPLOAD_CONTENT_TYPE = 'application/octet-stream';
29
38
 
30
39
  /**
31
- * Default purpose used for uploads when the client does not provide one.
40
+ * Regular expression for path segments that are safe to keep as public object keys.
32
41
  *
33
42
  * @private
34
43
  */
35
- const DEFAULT_UPLOAD_PURPOSE = 'GENERIC_UPLOAD';
44
+ const SAFE_UPLOAD_PATH_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._~!$&'()*+,;=:@/-]*$/;
36
45
 
37
46
  /**
38
- * Default MIME type used for unknown uploads.
47
+ * Parsed upload request.
39
48
  *
40
49
  * @private
41
50
  */
42
- const DEFAULT_UPLOAD_CONTENT_TYPE = 'application/octet-stream';
51
+ type ParsedUploadRequest = {
52
+ file: File;
53
+ pathname: string;
54
+ purpose: string;
55
+ contentType: string;
56
+ };
43
57
 
44
58
  /**
45
- * Minimal MIME type validation for values provided by client payload.
59
+ * Server context returned by `$provideServer`.
46
60
  *
47
61
  * @private
48
62
  */
49
- const MIME_TYPE_PATTERN = /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i;
63
+ type ProvidedServer = Awaited<ReturnType<typeof $provideServer>>;
50
64
 
51
65
  /**
52
- * Safely parses a JSON string into an object; returns empty object on invalid payload.
66
+ * Normalizes upload purpose to a non-empty string.
53
67
  *
54
68
  * @private
55
69
  */
56
- function parseJsonRecord(rawJson: string | null | undefined): JsonRecord {
57
- if (!rawJson) {
58
- return {};
70
+ function normalizeUploadPurpose(value: FormDataEntryValue | null): string {
71
+ if (typeof value !== 'string') {
72
+ return DEFAULT_UPLOAD_PURPOSE;
59
73
  }
60
74
 
61
- try {
62
- const parsed = JSON.parse(rawJson);
63
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
64
- return {};
65
- }
75
+ const normalizedPurpose = value.trim();
76
+ return normalizedPurpose === '' ? DEFAULT_UPLOAD_PURPOSE : normalizedPurpose;
77
+ }
66
78
 
67
- return parsed as JsonRecord;
79
+ /**
80
+ * Normalizes a MIME type string while keeping a safe fallback for unknown values.
81
+ *
82
+ * @private
83
+ */
84
+ function normalizeUploadContentType(value: FormDataEntryValue | null, fallbackContentType: string): string {
85
+ const candidate = typeof value === 'string' && value.trim() ? value.trim() : fallbackContentType;
86
+
87
+ try {
88
+ return validateMimeType(candidate || DEFAULT_UPLOAD_CONTENT_TYPE);
68
89
  } catch {
69
- return {};
90
+ return DEFAULT_UPLOAD_CONTENT_TYPE;
70
91
  }
71
92
  }
72
93
 
73
94
  /**
74
- * Normalizes upload purpose to a non-empty string.
95
+ * Resolves and validates the storage key requested by the browser.
75
96
  *
76
97
  * @private
77
98
  */
78
- function normalizeUploadPurpose(value: unknown): string {
99
+ function resolveUploadPathname(value: FormDataEntryValue | null): string {
79
100
  if (typeof value !== 'string') {
80
- return DEFAULT_UPLOAD_PURPOSE;
101
+ throw new UnexpectedError('Upload request is missing `pathname`.');
81
102
  }
82
103
 
83
- const normalizedPurpose = value.trim();
84
- return normalizedPurpose === '' ? DEFAULT_UPLOAD_PURPOSE : normalizedPurpose;
104
+ const pathname = value.trim().replace(/\\/g, '/').replace(/^\/+/, '');
105
+
106
+ if (
107
+ pathname === '' ||
108
+ pathname.includes('/../') ||
109
+ pathname.startsWith('../') ||
110
+ pathname.endsWith('/..') ||
111
+ !SAFE_UPLOAD_PATH_PATTERN.test(pathname)
112
+ ) {
113
+ throw new UnexpectedError(
114
+ spaceTrim(`
115
+ Upload request contains an invalid \`pathname\`.
116
+
117
+ The upload key must be a relative CDN path without parent-directory segments.
118
+ `),
119
+ );
120
+ }
121
+
122
+ return getSafeCdnPath({
123
+ pathname,
124
+ pathPrefix: process.env.NEXT_PUBLIC_CDN_PATH_PREFIX,
125
+ });
85
126
  }
86
127
 
87
128
  /**
88
- * Normalizes a MIME type string while keeping a safe fallback for unknown values.
129
+ * Parses the multipart request accepted by `/api/upload`.
89
130
  *
90
131
  * @private
91
132
  */
92
- function normalizeUploadContentType(value: unknown): string {
93
- if (typeof value !== 'string') {
94
- return DEFAULT_UPLOAD_CONTENT_TYPE;
133
+ async function parseUploadRequest(request: NextRequest): Promise<ParsedUploadRequest> {
134
+ const formData = await request.formData();
135
+ const file = formData.get('file');
136
+
137
+ if (!(file instanceof File)) {
138
+ throw new UnexpectedError('Upload request is missing `file`.');
95
139
  }
96
140
 
97
- const normalizedContentType = value.trim().toLowerCase();
98
- if (!MIME_TYPE_PATTERN.test(normalizedContentType)) {
99
- return DEFAULT_UPLOAD_CONTENT_TYPE;
141
+ return {
142
+ file,
143
+ pathname: resolveUploadPathname(formData.get('pathname')),
144
+ purpose: normalizeUploadPurpose(formData.get('purpose')),
145
+ contentType: normalizeUploadContentType(formData.get('contentType'), file.type),
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Runs all configured file-security checkers against the uploaded public URL.
151
+ *
152
+ * @private
153
+ */
154
+ async function checkUploadedFileSecurity(storageUrl: string): Promise<Record<string, unknown>> {
155
+ const securityResults: Record<string, unknown> = {};
156
+
157
+ for (const checkerId of Object.keys(FILE_SECURITY_CHECKERS)) {
158
+ try {
159
+ const checker = FILE_SECURITY_CHECKERS[checkerId]!;
160
+ securityResults[checkerId] = await checker.checkFile(storageUrl);
161
+ } catch (error) {
162
+ securityResults[checkerId] = {
163
+ isSafe: false,
164
+ status: 'ERROR',
165
+ confidence: 0,
166
+ message: error instanceof Error ? error.message : String(error),
167
+ };
168
+ }
100
169
  }
101
170
 
102
- return normalizedContentType;
171
+ return securityResults;
103
172
  }
104
173
 
105
174
  /**
106
- * Extracts normalized upload metadata from client payload.
175
+ * Stores security results for the file row created by `TrackedFilesStorage`.
107
176
  *
108
177
  * @private
109
178
  */
110
- function resolveUploadClientPayload(clientPayload: string | null | undefined): {
111
- purpose: string;
112
- contentType: string;
113
- } {
114
- const payload = parseJsonRecord(clientPayload) as UploadClientPayload;
179
+ async function updateUploadedFileSecurityResult(
180
+ storageUrl: string,
181
+ securityResult: Record<string, unknown>,
182
+ ): Promise<void> {
183
+ if (Object.keys(securityResult).length === 0) {
184
+ return;
185
+ }
115
186
 
116
- return {
117
- purpose: normalizeUploadPurpose(payload.purpose),
118
- contentType: normalizeUploadContentType(payload.contentType),
119
- };
187
+ const supabase = $provideSupabase();
188
+ const securityResultForDatabase =
189
+ securityResult as AgentsServerDatabase['public']['Tables']['File']['Update']['securityResult'];
190
+ const { error } = await supabase
191
+ .from(await $getTableName('File'))
192
+ .update({ securityResult: securityResultForDatabase })
193
+ .eq('storageUrl', storageUrl);
194
+
195
+ if (error) {
196
+ console.error('Failed to update uploaded file security result:', error);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Ensures the current server/domain can accept file uploads.
202
+ *
203
+ * @param providedServer - Current server routing context.
204
+ * @throws `NotAllowed` when uploads would be published without a server domain.
205
+ * @private
206
+ */
207
+ function assertFileUploadAvailable(providedServer: ProvidedServer): void {
208
+ const fileUploadAvailability = resolveFileUploadAvailability({
209
+ serverId: providedServer.id,
210
+ serverPublicUrl: providedServer.publicUrl,
211
+ isSelfContainedS3StorageSelected: isSelfContainedS3StorageSelected(),
212
+ });
213
+
214
+ if (!fileUploadAvailability.isUploadAvailable) {
215
+ throw new NotAllowed(fileUploadAvailability.message || 'File uploads are not available for this server.');
216
+ }
120
217
  }
121
218
 
122
219
  /**
123
- * Handles post.
220
+ * Handles file upload requests.
124
221
  */
125
222
  export async function POST(request: NextRequest) {
126
223
  try {
127
- const body = (await request.json()) as HandleUploadBody;
224
+ const providedServer = await $provideServer();
225
+ assertFileUploadAvailable(providedServer);
226
+
227
+ const { file, purpose, contentType } = await parseUploadRequest(request);
228
+ const fileBuffer = Buffer.from(await file.arrayBuffer());
229
+ const maxFileSize = await getMaxFileUploadSizeBytes();
230
+
231
+ if (fileBuffer.byteLength > maxFileSize) {
232
+ throw new LimitReachedError(
233
+ spaceTrim(`
234
+ Uploaded file \`${file.name}\` exceeds the configured upload limit.
235
+
236
+ Maximum supported size: **${maxFileSize} bytes**
237
+ `),
238
+ );
239
+ }
240
+
241
+ // [✨🏣] Compute a content-addressed CDN key so the public URL contains
242
+ // the file hash and does not expose the internal S3 bucket or path prefix.
243
+ const rawKey = getUserFileCdnKey(fileBuffer, file.name);
244
+ const pathname = getSafeCdnPath({
245
+ pathname: rawKey,
246
+ pathPrefix: process.env.NEXT_PUBLIC_CDN_PATH_PREFIX,
247
+ });
248
+
249
+ const cdn = $provideCdnForServer({
250
+ cdnPublicUrl: resolveCdnPublicUrlForServer(providedServer.publicUrl),
251
+ });
252
+ const storageUrl = cdn.getItemUrl(pathname).href;
128
253
  const userId = await getUserIdFromRequest(request);
129
- const supabase: SupabaseClient<AgentsServerDatabase> = $provideSupabase();
130
-
131
- // Handle Vercel Blob client upload protocol
132
- const jsonResponse = await handleUpload({
133
- body,
134
- request,
135
- token: process.env.VERCEL_BLOB_READ_WRITE_TOKEN!,
136
- onBeforeGenerateToken: async (pathname, clientPayload) => {
137
- // Authenticate user and validate upload
138
-
139
- // Parse client payload for additional metadata
140
- const { purpose, contentType } = resolveUploadClientPayload(clientPayload);
141
-
142
- const maxFileSize = await getMaxFileUploadSizeBytes();
143
-
144
- // Generate the proper path with prefix
145
- // Note: With client uploads, we use the original filename provided by the client
146
- // The file will be stored at: {pathPrefix}/user/files/{filename}
147
- const pathPrefix = process.env.NEXT_PUBLIC_CDN_PATH_PREFIX || '';
148
-
149
- // Create a DB record at the start of the upload to track it
150
- const uploadPurpose = purpose;
151
- const {
152
- data: insertedFile,
153
- error: insertError,
154
- }: PostgrestSingleResponse<Pick<AgentsServerDatabase['public']['Tables']['File']['Row'], 'id'>> =
155
- await supabase
156
- .from(await $getTableName('File'))
157
- .insert({
158
- userId: userId || null,
159
- fileName: pathname,
160
- fileSize: 0, // <- Will be updated when upload completes
161
- fileType: contentType,
162
- storageUrl: null, // <- To be updated on completion
163
- shortUrl: null, // <- To be updated on completion
164
- purpose: uploadPurpose,
165
- status: 'UPLOADING',
166
- })
167
- .select('id')
168
- .single();
169
-
170
- if (insertError) {
171
- console.error('🔼 Failed to create file record:', insertError);
172
- }
173
-
174
- console.info('🔼 Upload started, tracking file:', {
175
- pathname,
176
- fileId: insertedFile?.id,
177
- purpose: uploadPurpose,
178
- });
179
-
180
- return {
181
- maximumSizeInBytes: maxFileSize,
182
- addRandomSuffix: true, // Add random suffix to avoid filename collisions since we can't hash content
183
- tokenPayload: JSON.stringify({
184
- userId: userId || null,
185
- purpose: uploadPurpose,
186
- fileId: insertedFile?.id || null,
187
- uploadPath: pathname,
188
- pathPrefix,
189
- }),
190
- };
191
- },
192
- onUploadCompleted: async ({ blob, tokenPayload }) => {
193
- // !!!!
194
- // ⚠️ IMPORTANT: This callback is a WEBHOOK called by Vercel's servers AFTER the upload completes
195
- // - It runs in a DIFFERENT request context (not the original user request)
196
- // - It WON'T work in local development (Vercel can't reach localhost)
197
- // - All data must come from tokenPayload (userId, fileId, etc.)
198
- // - Need to create a fresh supabase client here
199
- console.info('🔼 Upload completed (webhook callback):', { blob, tokenPayload });
200
-
201
- try {
202
- const payload = parseJsonRecord(tokenPayload);
203
- const fileId = typeof payload.fileId === 'number' ? payload.fileId : null;
204
- const tokenUserId = typeof payload.userId === 'number' ? payload.userId : null;
205
- const tokenPurpose = normalizeUploadPurpose(payload.purpose);
206
- const uploadPath = typeof payload.uploadPath === 'string' ? payload.uploadPath : null;
207
-
208
- // Create fresh supabase client for this webhook context
209
- const supabase = $provideSupabase();
210
-
211
- // Security checks
212
- const securityResults: Record<string, unknown> = {};
213
- const securityResultForDatabase =
214
- securityResults as AgentsServerDatabase['public']['Tables']['File']['Update']['securityResult'];
215
- for (const checkerId in FILE_SECURITY_CHECKERS) {
216
- try {
217
- const checker = FILE_SECURITY_CHECKERS[checkerId]!;
218
- console.info(`🛡️ Checking file security with ${checker.title} (${blob.url})...`);
219
- const result = await checker.checkFile(blob.url);
220
- securityResults[checkerId] = result;
221
- console.info(`🛡️ Security check result from ${checker.title}:`, result.status);
222
- } catch (error) {
223
- console.error(`🛡️ Security check failed for ${checkerId}:`, error);
224
- securityResults[checkerId] = {
225
- isSafe: false,
226
- status: 'ERROR',
227
- confidence: 0,
228
- message: error instanceof Error ? error.message : String(error),
229
- };
230
- }
231
- }
232
-
233
- if (fileId) {
234
- // Update the existing record by ID
235
- const { error: updateError } = await supabase
236
- .from(await $getTableName('File'))
237
- .update({
238
- userId: tokenUserId || null,
239
- fileSize: 0, // <- !!!!
240
- fileType: blob.contentType,
241
- storageUrl: blob.url,
242
- // <- TODO: !!!! Split between storageUrl and shortUrl
243
- purpose: tokenPurpose,
244
- status: 'COMPLETED',
245
- securityResult: securityResultForDatabase,
246
- })
247
- .eq('id', fileId);
248
-
249
- if (updateError) {
250
- console.error('🔼 Failed to update file record:', updateError);
251
- } else {
252
- console.info('🔼 File record updated successfully:', { fileId, shortUrl: blob.url });
253
- }
254
- } else if (uploadPath) {
255
- // Fallback: Update by uploadPath if fileId is not available
256
- const { error: updateError } = await supabase
257
- .from(await $getTableName('File'))
258
- .update({
259
- fileSize: 0, // <- !!!!
260
- fileType: blob.contentType,
261
- storageUrl: blob.url,
262
- status: 'COMPLETED',
263
- securityResult: securityResultForDatabase,
264
- })
265
- .eq('fileName', uploadPath)
266
- .eq('status', 'UPLOADING');
267
-
268
- if (updateError) {
269
- console.error('🔼 Failed to update file record by uploadPath:', updateError);
270
- }
271
- }
272
- } catch (error) {
273
- console.error('🔼 Error in onUploadCompleted:', error);
274
- }
275
- },
254
+
255
+ await cdn.setItem(pathname, {
256
+ type: contentType,
257
+ data: fileBuffer,
258
+ purpose,
259
+ userId: userId || undefined,
260
+ fileSize: fileBuffer.byteLength,
276
261
  });
277
262
 
278
- return NextResponse.json(jsonResponse);
263
+ const securityResult = await checkUploadedFileSecurity(storageUrl);
264
+ await updateUploadedFileSecurityResult(storageUrl, securityResult);
265
+
266
+ return NextResponse.json({
267
+ url: storageUrl,
268
+ pathname,
269
+ contentType,
270
+ size: fileBuffer.byteLength,
271
+ });
279
272
  } catch (error) {
280
273
  assertsError(error);
281
274
 
282
- console.error('🔼', error);
275
+ console.error('Upload failed:', error);
276
+
277
+ const serializedError = serializeError(error);
283
278
 
284
- return new Response(
285
- JSON.stringify(
286
- serializeError(error),
287
- // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
288
- null,
289
- 4,
290
- // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
291
- ),
279
+ return NextResponse.json(
292
280
  {
293
- status: 400, // <- TODO: [🐱‍🚀] Make `errorToHttpStatusCode`
294
- headers: { 'Content-Type': 'application/json' },
281
+ ...serializedError,
282
+ error: serializedError.message,
283
+ },
284
+ {
285
+ status: error instanceof NotAllowed ? 403 : 400, // <- TODO: [🐱‍🚀] Make `errorToHttpStatusCode`
295
286
  },
296
287
  );
297
288
  }
298
289
  }
299
-
300
- // TODO: !!!! Change uploaded URLs from `storageUrl` to `shortUrl`
301
- // TODO: !!!! Record both `storageUrl` (actual storage location) and `shortUrl` in `File` table
302
- // TODO: !!!! Record `purpose` in `File` table
303
- // TODO: !!!! Record `userId` in `File` table
304
- // TODO: !!!! Record all things into `File` table
305
- // TODO: !!!! File type (mime type) of `.book` files should be `application/book` <- [🧠] !!!! Best mime type?!
@@ -3,6 +3,7 @@ import { NextResponse } from 'next/server';
3
3
  import { $provideSupabaseForServer } from '../../../../database/$provideSupabaseForServer';
4
4
  import { getPasswordValidationMessage, hashPassword } from '../../../../utils/auth';
5
5
  import { isUserAdmin } from '../../../../utils/isUserAdmin';
6
+ import { PUBLIC_USER_SELECT_COLUMNS, toPublicUser, type PublicUser } from '../../../../utils/publicUser';
6
7
 
7
8
  /**
8
9
  * Handles patch.
@@ -34,7 +35,7 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ us
34
35
  .from(await $getTableName('User'))
35
36
  .update(updates)
36
37
  .eq('username', usernameParam)
37
- .select('id, username, createdAt, updatedAt, isAdmin')
38
+ .select(PUBLIC_USER_SELECT_COLUMNS)
38
39
  .single();
39
40
 
40
41
  if (error) {
@@ -45,7 +46,7 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ us
45
46
  return NextResponse.json({ error: 'User not found' }, { status: 404 });
46
47
  }
47
48
 
48
- return NextResponse.json(updatedUser);
49
+ return NextResponse.json(toPublicUser(updatedUser as unknown as PublicUser));
49
50
  } catch (error) {
50
51
  console.error('Update user error:', error);
51
52
  const passwordValidationMessage = getPasswordValidationMessage(error);
@@ -2,6 +2,7 @@ import { $getTableName } from '@/src/database/$getTableName';
2
2
  import { $provideSupabaseForServer } from '../../../database/$provideSupabaseForServer';
3
3
  import { getPasswordValidationMessage, hashPassword } from '../../../utils/auth';
4
4
  import { isUserAdmin } from '../../../utils/isUserAdmin';
5
+ import { PUBLIC_USER_SELECT_COLUMNS, toPublicUser, type PublicUser } from '../../../utils/publicUser';
5
6
  import { NextResponse } from 'next/server';
6
7
 
7
8
  /**
@@ -16,14 +17,14 @@ export async function GET() {
16
17
  const supabase = $provideSupabaseForServer();
17
18
  const { data: users, error } = await supabase
18
19
  .from(await $getTableName('User'))
19
- .select('id, username, createdAt, updatedAt, isAdmin')
20
+ .select(PUBLIC_USER_SELECT_COLUMNS)
20
21
  .order('username');
21
22
 
22
23
  if (error) {
23
24
  throw error;
24
25
  }
25
26
 
26
- return NextResponse.json(users);
27
+ return NextResponse.json(((users || []) as unknown as PublicUser[]).map(toPublicUser));
27
28
  } catch (error) {
28
29
  console.error('List users error:', error);
29
30
  return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
@@ -58,18 +59,18 @@ export async function POST(request: Request) {
58
59
  createdAt: new Date().toISOString(),
59
60
  updatedAt: new Date().toISOString(),
60
61
  })
61
- .select('id, username, createdAt, updatedAt, isAdmin')
62
+ .select(PUBLIC_USER_SELECT_COLUMNS)
62
63
  .single();
63
64
 
64
65
  if (error) {
65
- if (error.code === '23505') { // unique_violation
66
- return NextResponse.json({ error: 'Username already exists' }, { status: 409 });
66
+ if (error.code === '23505') {
67
+ // unique_violation
68
+ return NextResponse.json({ error: 'Username already exists' }, { status: 409 });
67
69
  }
68
70
  throw error;
69
71
  }
70
72
 
71
- return NextResponse.json(newUser);
72
-
73
+ return NextResponse.json(toPublicUser(newUser as unknown as PublicUser));
73
74
  } catch (error) {
74
75
  console.error('Create user error:', error);
75
76
  const passwordValidationMessage = getPasswordValidationMessage(error);