@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.
- package/README.md +76 -44
- package/agents/default/developer.book +24 -0
- package/apps/agents-server/README.md +19 -2
- package/apps/agents-server/env-manual/GITHUB_APP.md +1 -1
- package/apps/agents-server/next.config.ts +41 -1
- package/apps/agents-server/package.json +1 -1
- package/apps/agents-server/playwright.config.ts +3 -0
- package/apps/agents-server/public/promptbook-logo-blue.png +0 -0
- package/apps/agents-server/public/promptbook-logo-white.png +0 -0
- package/apps/agents-server/scripts/prerender-homepage.js +76 -1
- package/apps/agents-server/src/app/AddAgentButton.tsx +0 -5
- package/apps/agents-server/src/app/[agentName]/layout.tsx +1 -0
- package/apps/agents-server/src/app/actions.ts +70 -9
- package/apps/agents-server/src/app/admin/about/page.tsx +1 -1
- package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +4 -1
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +3 -0
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackTable.tsx +13 -8
- package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +2 -4
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +3 -0
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryTable.tsx +13 -8
- package/apps/agents-server/src/app/admin/chat-history/page.tsx +2 -4
- package/apps/agents-server/src/app/admin/cli-access/CliAccessClient.tsx +1 -3
- package/apps/agents-server/src/app/admin/code-runners/CodeRunnersClient.tsx +19 -11
- package/apps/agents-server/src/app/admin/custom-css/CustomCssClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/custom-css/CustomCssEditorPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-css/CustomCssFilesPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-js/CustomJsClient.tsx +11 -0
- package/apps/agents-server/src/app/admin/custom-js/CustomJsEditorPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/custom-js/CustomJsFilesPanel.tsx +7 -1
- package/apps/agents-server/src/app/admin/files/FilesGalleryClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/files/FilesGalleryGrid.tsx +9 -11
- package/apps/agents-server/src/app/admin/files/FilesGalleryTable.tsx +9 -8
- package/apps/agents-server/src/app/admin/image-generator-test/ImageAttachmentsEditor.tsx +30 -9
- package/apps/agents-server/src/app/admin/images/ImagesGalleryClient.tsx +4 -0
- package/apps/agents-server/src/app/admin/images/ImagesGalleryGrid.tsx +16 -11
- package/apps/agents-server/src/app/admin/images/ImagesGalleryTable.tsx +18 -9
- package/apps/agents-server/src/app/admin/limits/LimitsClient.tsx +11 -12
- package/apps/agents-server/src/app/admin/login-methods/shibboleth/page.tsx +355 -0
- package/apps/agents-server/src/app/admin/logs/LogsClient.tsx +9 -3
- package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +7 -6
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +671 -45
- package/apps/agents-server/src/app/admin/servers/CreateServerDialog.tsx +22 -1
- package/apps/agents-server/src/app/admin/servers/ServersRegistryTable.tsx +14 -13
- package/apps/agents-server/src/app/admin/servers/useCreateServerWizard.ts +57 -20
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerClient.tsx +4 -2
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTaskRow.tsx +14 -15
- package/apps/agents-server/src/app/admin/task-manager/TaskManagerTasksCard.tsx +4 -1
- package/apps/agents-server/src/app/admin/task-manager/useTaskManagerState.ts +6 -9
- package/apps/agents-server/src/app/admin/update/CustomCommitPicker.tsx +258 -0
- package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +627 -137
- package/apps/agents-server/src/app/admin/usage/UsageClient.tsx +4 -2
- package/apps/agents-server/src/app/admin/usage/UsageClientAnalyticsPanels.tsx +6 -4
- package/apps/agents-server/src/app/admin/usage/UsageClientFormatting.ts +6 -12
- package/apps/agents-server/src/app/admin/usage/UsageClientTimelineChart.tsx +7 -4
- package/apps/agents-server/src/app/admin/usage/useUsageClientState.ts +12 -4
- package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +27 -15
- package/apps/agents-server/src/app/agents/[agentName]/ActiveAgentBreadcrumbBinder.tsx +30 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +13 -2
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +20 -25
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +7 -5
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/messages/route.ts +4 -11
- package/apps/agents-server/src/app/agents/[agentName]/api/user-chats/[chatId]/stream/route.ts +85 -56
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +7 -1
- package/apps/agents-server/src/app/agents/[agentName]/book/useBookEditorHistory.ts +9 -2
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistoryPayloadState.ts +38 -4
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatHistorySyncOperations.ts +4 -1
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatPageLayout.tsx +2 -2
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatSidebarDefault.tsx +19 -13
- package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +30 -16
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistoryClientState.ts +2 -15
- package/apps/agents-server/src/app/agents/[agentName]/chat/useAgentChatHistorySyncEffects.ts +7 -13
- package/apps/agents-server/src/app/agents/[agentName]/chat/useCanonicalAgentChatPanelState.ts +58 -7
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +6 -1
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +6 -2
- package/apps/agents-server/src/app/agents/[agentName]/integration/CalendarIntegrationSection.tsx +23 -5
- package/apps/agents-server/src/app/agents/[agentName]/layout.tsx +47 -1
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsClient.tsx +4 -2
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsFiltersCard.tsx +9 -4
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableCard.tsx +4 -1
- package/apps/agents-server/src/app/agents/[agentName]/timeouts/AgentTimeoutsTableRow.tsx +10 -3
- package/apps/agents-server/src/app/api/admin/cli-access/route.ts +27 -123
- package/apps/agents-server/src/app/api/admin/code-runners/authentication/route.ts +33 -125
- package/apps/agents-server/src/app/api/admin/code-runners/route.ts +1 -1
- package/apps/agents-server/src/app/api/admin/servers/route.ts +5 -0
- package/apps/agents-server/src/app/api/admin/update/commits/route.ts +35 -0
- package/apps/agents-server/src/app/api/admin/update/log/route.ts +42 -0
- package/apps/agents-server/src/app/api/admin/update/route.ts +10 -2
- package/apps/agents-server/src/app/api/agent-folders/[folderId]/visibility/route.ts +19 -7
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +39 -25
- package/apps/agents-server/src/app/api/agents/export/route.ts +67 -0
- package/apps/agents-server/src/app/api/agents/import/route.ts +168 -0
- package/apps/agents-server/src/app/api/auth/change-password/route.ts +53 -6
- package/apps/agents-server/src/app/api/auth/login/route.ts +17 -16
- package/apps/agents-server/src/app/api/auth/logout/route.ts +2 -10
- package/apps/agents-server/src/app/api/auth/shibboleth/acs/route.ts +112 -0
- package/apps/agents-server/src/app/api/auth/shibboleth/login/route.ts +70 -0
- package/apps/agents-server/src/app/api/auth/shibboleth/metadata/route.ts +15 -0
- package/apps/agents-server/src/app/api/auth/shibboleth/status/route.ts +17 -0
- package/apps/agents-server/src/app/api/chat/citation-label/route.ts +133 -0
- package/apps/agents-server/src/app/api/chat/export/pdf/route.ts +167 -2
- package/apps/agents-server/src/app/api/chat/route.ts +29 -7
- package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +2 -2
- package/apps/agents-server/src/app/api/chat-feedback/route.ts +3 -3
- package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +2 -2
- package/apps/agents-server/src/app/api/chat-history/export/route.ts +2 -2
- package/apps/agents-server/src/app/api/chat-history/route.ts +3 -3
- package/apps/agents-server/src/app/api/chat-streaming/route.ts +29 -0
- package/apps/agents-server/src/app/api/elevenlabs/tts/route.ts +60 -2
- package/apps/agents-server/src/app/api/emails/incoming/sendgrid/route.ts +24 -2
- package/apps/agents-server/src/app/api/federated-agents/route.ts +1 -1
- package/apps/agents-server/src/app/api/health/route.ts +18 -0
- package/apps/agents-server/src/app/api/images/[filename]/route.ts +108 -2
- package/apps/agents-server/src/app/api/internal/agent-runner-limits/route.ts +52 -0
- package/apps/agents-server/src/app/api/internal/user-chat-jobs/run/route.ts +17 -4
- package/apps/agents-server/src/app/api/metadata/export/route.ts +34 -0
- package/apps/agents-server/src/app/api/metadata/import/route.ts +47 -0
- package/apps/agents-server/src/app/api/metadata/route.ts +4 -0
- package/apps/agents-server/src/app/api/openai/v1/audio/transcriptions/route.ts +111 -2
- package/apps/agents-server/src/app/api/page-preview/check/route.ts +49 -0
- package/apps/agents-server/src/app/api/page-preview/screenshot/route.ts +64 -0
- package/apps/agents-server/src/app/api/scrape/route.ts +18 -0
- package/apps/agents-server/src/app/api/team-agent-profile/route.ts +20 -0
- package/apps/agents-server/src/app/api/upload/route.ts +204 -220
- package/apps/agents-server/src/app/api/users/[username]/route.ts +3 -2
- package/apps/agents-server/src/app/api/users/route.ts +8 -7
- package/apps/agents-server/src/app/api/v1/agents/[agentId]/route.ts +17 -8
- package/apps/agents-server/src/app/api/v1/agents/route.ts +2 -0
- package/apps/agents-server/src/app/dashboard/page.tsx +12 -17
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +1 -1
- package/apps/agents-server/src/app/docs/page.tsx +1 -1
- package/apps/agents-server/src/app/globals.css +179 -0
- package/apps/agents-server/src/app/layout.tsx +33 -4
- package/apps/agents-server/src/app/recycle-bin/actions.ts +3 -0
- package/apps/agents-server/src/app/recycle-bin/page.tsx +1 -1
- package/apps/agents-server/src/app/s3/[first]/[second]/[hash]/[filename]/route.ts +52 -0
- package/apps/agents-server/src/app/swagger/SwaggerApiKeysPanel.tsx +4 -1
- package/apps/agents-server/src/app/system/settings/KeybindingsSettingsClient.tsx +13 -7
- package/apps/agents-server/src/app/system/user-memory/UserMemoryClient.tsx +4 -2
- package/apps/agents-server/src/app/system/user-wallet/UserWalletClient.tsx +3 -0
- package/apps/agents-server/src/app/system/user-wallet/UserWalletRecordsTable.tsx +5 -1
- package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorClient.tsx +3 -0
- package/apps/agents-server/src/app/system/utilities/mocked-chats/MockedChatsEditorSidebar.tsx +7 -8
- package/apps/agents-server/src/components/AdminTerminal/AdminTerminalCard.tsx +13 -70
- package/apps/agents-server/src/components/AdminTerminal/AdminXtermTerminal.tsx +330 -0
- package/apps/agents-server/src/components/AdminTerminal/useAdminTerminalSession.ts +45 -5
- package/apps/agents-server/src/components/AgentContextMenu/useAgentContextMenuItems.ts +27 -19
- package/apps/agents-server/src/components/AgentProfile/AgentCapabilityChips.tsx +39 -5
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +4 -7
- package/apps/agents-server/src/components/AgentProfile/AgentProfileImage.tsx +8 -2
- package/apps/agents-server/src/components/ApplicationErrorPage/ApplicationErrorPage.tsx +118 -12
- package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +4 -4
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +9 -9
- package/apps/agents-server/src/components/FileUploadAvailability/FileUploadAvailabilityContext.tsx +50 -0
- package/apps/agents-server/src/components/FileUploadAvailability/FileUploadUnavailableNotice.tsx +45 -0
- package/apps/agents-server/src/components/Footer/Footer.tsx +10 -9
- package/apps/agents-server/src/components/Footer/getCommitFooterEmoji.ts +112 -0
- package/apps/agents-server/src/components/Header/ActiveAgentBreadcrumbContext.tsx +82 -0
- package/apps/agents-server/src/components/Header/Header.tsx +24 -15
- package/apps/agents-server/src/components/Header/HeaderTypes.ts +6 -0
- package/apps/agents-server/src/components/Header/buildHeaderSystemMenuItems.ts +51 -1
- package/apps/agents-server/src/components/Header/useHeaderActiveAgent.ts +26 -7
- package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +0 -5
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +7 -1
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +22 -1
- package/apps/agents-server/src/components/Homepage/AgentsListHeader.tsx +85 -1
- package/apps/agents-server/src/components/Homepage/AgentsListListView.tsx +6 -0
- package/apps/agents-server/src/components/Homepage/AgentsListViewContent.tsx +6 -0
- package/apps/agents-server/src/components/Homepage/Card.tsx +1 -1
- package/apps/agents-server/src/components/Homepage/Section.tsx +3 -1
- package/apps/agents-server/src/components/Homepage/SortableFolderCard.tsx +7 -1
- package/apps/agents-server/src/components/Homepage/hiddenFolders.ts +104 -0
- package/apps/agents-server/src/components/Homepage/useAgentsListImportExportState.ts +525 -0
- package/apps/agents-server/src/components/Homepage/useAgentsListQueryState.ts +35 -0
- package/apps/agents-server/src/components/Homepage/useAgentsListState.ts +38 -4
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +93 -70
- package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +52 -12
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoNewAgentWizard.tsx +151 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoOnboardingNavigation.tsx +50 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/BookLanguagePanel.tsx +125 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/DropZone.tsx +83 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/EmailTestRun.tsx +216 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/KnowledgeList.tsx +79 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/Logo.tsx +20 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownBookEditor.tsx +154 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/MarkdownPreview.tsx +188 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/RailStepper.tsx +115 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/StepFrame.tsx +47 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/TestChat.tsx +159 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/WizardShell.tsx +114 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/brand/RailArtwork.tsx +60 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/BookStep.tsx +135 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/DoneStep.tsx +215 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/KnowledgeStep.tsx +152 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/TestStep.tsx +262 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/ZadaniStep.tsx +64 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Badge.tsx +41 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Banner.tsx +69 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Button.tsx +77 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Card.tsx +33 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Field.tsx +103 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/IconButton.tsx +40 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/Spinner.tsx +14 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/ui/tokens.ts +37 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/bookSections.ts +62 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/emailScenarios.ts +22 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/config/steps.ts +46 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/index.ts +11 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/cn.ts +4 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/format.ts +9 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/lib/id.ts +11 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentEvalService.ts +30 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentTestService.ts +69 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/bookService.ts +21 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/createManGoAgentSource.ts +107 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/draftService.ts +45 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/uploadService.ts +27 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/OnboardingProvider.tsx +121 -0
- package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/types.ts +52 -0
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +7 -3
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentWizardKnowledgeStep.tsx +6 -0
- package/apps/agents-server/src/components/NewAgentDialog/createNewAgentWizardSource.ts +1 -1
- package/apps/agents-server/src/components/NewAgentDialog/trackNewAgentCreationEvent.ts +1 -1
- package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +113 -14
- package/apps/agents-server/src/components/NewAgentDialog/useNewAgentWizardKnowledgeState.ts +8 -1
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -2
- package/apps/agents-server/src/components/Skeleton/ConsolePageLoadingSkeleton.tsx +1 -1
- package/apps/agents-server/src/components/Skeleton/DocumentationRouteLoadingSkeleton.tsx +1 -1
- package/apps/agents-server/src/components/Skeleton/HomepageLoadingSkeleton.tsx +1 -1
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +24 -6
- package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +2 -7
- package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +1 -1
- package/apps/agents-server/src/constants/newAgentWizard.ts +17 -8
- package/apps/agents-server/src/constants/serverLimits.ts +41 -2
- package/apps/agents-server/src/constants/shibbolethAuth.ts +139 -0
- package/apps/agents-server/src/database/$provideClientSql.ts +37 -0
- package/apps/agents-server/src/database/$provideSupabaseForServer.ts +41 -0
- package/apps/agents-server/src/database/customJavascript.ts +62 -1
- package/apps/agents-server/src/database/customStylesheet.ts +60 -1
- package/apps/agents-server/src/database/getMetadata.ts +121 -4
- package/apps/agents-server/src/database/loadAgentsServerEnvFile.ts +29 -0
- package/apps/agents-server/src/database/metadataDefaults.ts +85 -31
- package/apps/agents-server/src/database/migrate.ts +8 -2
- package/apps/agents-server/src/database/migrations/2026-06-0100-shibboleth-auth.sql +136 -0
- package/apps/agents-server/src/database/migrations/2026-06-0200-default-agent-avatar-visual-octopus3d3.sql +16 -0
- package/apps/agents-server/src/database/migrations/2026-06-1300-user-chat-active-read-indexes.sql +7 -0
- package/apps/agents-server/src/database/migrations/2026-06-2200-new-agent-wizard-metadata-key.sql +27 -0
- package/apps/agents-server/src/database/migrations/2026-06-2201-new-agent-wizard-mango-default.sql +11 -0
- package/apps/agents-server/src/database/migrations/2026-06-2600-agent-directory-performance-indexes.sql +14 -0
- package/apps/agents-server/src/database/migrations/2026-06-2700-default-agent-avatar-visual-octopus3d4.sql +16 -0
- package/apps/agents-server/src/database/seedCoreAgents.ts +234 -0
- package/apps/agents-server/src/database/seedDefaultAgents.ts +223 -0
- package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +234 -41
- package/apps/agents-server/src/generated/reservedPaths.ts +3 -0
- package/apps/agents-server/src/instrumentation-client.ts +28 -0
- package/apps/agents-server/src/instrumentation.ts +19 -0
- package/apps/agents-server/src/languages/ServerTranslationKeys.ts +4 -0
- package/apps/agents-server/src/languages/translations/czech.yaml +5 -1
- package/apps/agents-server/src/languages/translations/english.yaml +5 -1
- package/apps/agents-server/src/message-providers/email/sendgrid/verifySendgridInboundParseWebhook.ts +345 -0
- package/apps/agents-server/src/middleware/applyEmbeddingHeader.ts +4 -2
- package/apps/agents-server/src/middleware/contentSecurityPolicy.ts +97 -0
- package/apps/agents-server/src/middleware/resolveAccessControlResponse.ts +3 -2
- package/apps/agents-server/src/middleware/resolveMiddlewareResponse.ts +8 -3
- package/apps/agents-server/src/middleware.ts +15 -32
- package/apps/agents-server/src/search/createDefaultServerSearchProviders/createFederatedAgentsSearchProvider.ts +1 -1
- package/apps/agents-server/src/sentry.edge.config.ts +18 -0
- package/apps/agents-server/src/sentry.server.config.ts +19 -0
- package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +2 -9
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +187 -15
- package/apps/agents-server/src/tools/BrowserConnectionProvider.ts +2 -19
- package/apps/agents-server/src/tools/agent_progress.ts +4 -10
- package/apps/agents-server/src/tools/createAgentProgressTools.ts +8 -4
- package/apps/agents-server/src/tools/createChatAttachmentToolFunctions.ts +8 -4
- package/apps/agents-server/src/tools/createServerChromiumLaunchOptions.ts +44 -0
- package/apps/agents-server/src/utils/agentOwnership.ts +54 -5
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +101 -19
- package/apps/agents-server/src/utils/agentVisibility.ts +25 -62
- package/apps/agents-server/src/utils/agentsTransfer/createAgentsExportZipStream.ts +81 -0
- package/apps/agents-server/src/utils/agentsTransfer/importAgentsFromFiles.ts +852 -0
- package/apps/agents-server/src/utils/assertSafeUrl.ts +136 -0
- package/apps/agents-server/src/utils/authenticateUser.ts +112 -4
- package/apps/agents-server/src/utils/authenticationAttemptRateLimit.ts +504 -0
- package/apps/agents-server/src/utils/backup/createBooksBackupZipStream.ts +91 -7
- package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +48 -4
- package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +6 -5
- package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +5 -0
- package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +10 -3
- package/apps/agents-server/src/utils/chat/resolveAgentsServerCitationLabel.ts +130 -0
- package/apps/agents-server/src/utils/chat/resolveCitationSourceLabel.ts +436 -0
- package/apps/agents-server/src/utils/chatExport/renderHtmlToPdfOnServer.ts +66 -17
- package/apps/agents-server/src/utils/chatExport/sanitizeChatPdfExportHtml.ts +193 -0
- package/apps/agents-server/src/utils/codeRunnerConfiguration.ts +1 -1
- package/apps/agents-server/src/utils/createAdminTerminalRouteHandlers.ts +264 -0
- package/apps/agents-server/src/utils/createAgentWithDefaultVisibility.ts +3 -1
- package/apps/agents-server/src/utils/currentUserIdentity.ts +22 -9
- package/apps/agents-server/src/utils/defaultAgents/loadDefaultAgentBooks.ts +145 -0
- package/apps/agents-server/src/utils/errorReporting/agentsServerSentryContext.ts +203 -0
- package/apps/agents-server/src/utils/errorReporting/applicationErrorHandling.ts +45 -0
- package/apps/agents-server/src/utils/errorReporting/refreshApplicationDocument.ts +10 -0
- package/apps/agents-server/src/utils/errorReporting/registerServerErrorSentryLogging.ts +381 -0
- package/apps/agents-server/src/utils/errorReporting/sendApplicationErrorReportToSentry.ts +43 -152
- package/apps/agents-server/src/utils/errorReporting/sentrySdkConfig.ts +237 -0
- package/apps/agents-server/src/utils/errorReporting/sentryStore.ts +187 -0
- package/apps/agents-server/src/utils/externalChatRunner/createExternalAgentRepositoryFiles.ts +2 -2
- package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +15 -8
- package/apps/agents-server/src/utils/findAgentForCallerWriteAccess.ts +36 -0
- package/apps/agents-server/src/utils/getCurrentUser.ts +2 -1
- package/apps/agents-server/src/utils/getFederatedServers.ts +3 -74
- package/apps/agents-server/src/utils/getUserById.ts +19 -5
- package/apps/agents-server/src/utils/getWellKnownAgentUrl.ts +10 -4
- package/apps/agents-server/src/utils/iframe/checkIfUrlCanBeEmbedded.ts +68 -0
- package/apps/agents-server/src/utils/interactiveTerminalSession.ts +9 -4
- package/apps/agents-server/src/utils/isAdminPasswordEqual.ts +28 -0
- package/apps/agents-server/src/utils/isUserGlobalAdmin.ts +3 -1
- package/apps/agents-server/src/utils/knowledge/createInlineKnowledgeSourceUploader.ts +24 -5
- package/apps/agents-server/src/utils/knowledge/resolveWebsiteKnowledgeSourcesForServer.ts +10 -1
- package/apps/agents-server/src/utils/localChatRunner/LocalUserChatJobMetadata.ts +15 -5
- package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +24 -18
- package/apps/agents-server/src/utils/localization/formatServerLanguageHumanReadableDate.ts +70 -0
- package/apps/agents-server/src/utils/localization/getRequestServerLanguage.ts +32 -0
- package/apps/agents-server/src/utils/metadataConfigurationTransfer.ts +442 -0
- package/apps/agents-server/src/utils/paidApiRequestGuard.ts +241 -0
- package/apps/agents-server/src/utils/publicUser.ts +59 -0
- package/apps/agents-server/src/utils/serverLimits.ts +28 -1
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/bootstrapManagedServer.ts +5 -6
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/normalizeCreateServerInput.ts +6 -0
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerCoreAgents.ts +162 -0
- package/apps/agents-server/src/utils/serverManagement/createManagedServer/seedServerDefaultAgents.ts +7 -87
- package/apps/agents-server/src/utils/serverManagement/createManagedServer.ts +5 -0
- package/apps/agents-server/src/utils/session.ts +72 -30
- package/apps/agents-server/src/utils/shareTargetPayloads.ts +37 -66
- package/apps/agents-server/src/utils/shibbolethAuthentication.ts +957 -0
- package/apps/agents-server/src/utils/transpilers/resolveTranspiledTeamExport.ts +10 -10
- package/apps/agents-server/src/utils/upload/createBookEditorUploadHandler.ts +19 -28
- package/apps/agents-server/src/utils/upload/fileUploadAvailability.ts +91 -0
- package/apps/agents-server/src/utils/upload/uploadFileToServer.ts +157 -0
- package/apps/agents-server/src/utils/userChat/createImmediateUserChatAnswerModelRequirements.ts +26 -12
- package/apps/agents-server/src/utils/userChat/createRunUserChatJobExecutionContext.ts +45 -0
- package/apps/agents-server/src/utils/userChat/createRunUserChatJobPersistenceController.ts +17 -11
- package/apps/agents-server/src/utils/userChat/createUserChatDetailPayload.ts +33 -18
- package/apps/agents-server/src/utils/userChat/createUserChatHarnessProgressCard.ts +93 -0
- package/apps/agents-server/src/utils/userChat/createUserChatRunnerProgressCard.ts +57 -0
- package/apps/agents-server/src/utils/userChat/hasPotentiallyPendingAssistantMessages.ts +26 -0
- package/apps/agents-server/src/utils/userChat/listUserChats.ts +117 -6
- package/apps/agents-server/src/utils/userChat/persistUserChatJobProgressCard.ts +40 -0
- package/apps/agents-server/src/utils/userChat/resolveUserChatProgressToolHighlights.ts +100 -0
- package/apps/agents-server/src/utils/userChat/resolveUserChatWorkerInternalToken.ts +63 -9
- package/apps/agents-server/src/utils/userChat/runImmediateUserChatAnswer.ts +1 -1
- package/apps/agents-server/src/utils/userChat/runUserChatJob.ts +30 -0
- package/apps/agents-server/src/utils/userChat/triggerUserChatJobWorker.ts +54 -19
- package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +69 -1
- package/apps/agents-server/src/utils/userChat/userChatProgressCard.ts +360 -0
- package/apps/agents-server/src/utils/validateApiKey.ts +7 -3
- package/apps/agents-server/src/utils/vpsConfiguration.ts +8 -1
- package/apps/agents-server/src/utils/vpsSelfUpdate.ts +935 -64
- package/esm/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
- package/esm/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
- package/esm/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
- package/esm/index.es.js +24308 -18655
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/esm/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/esm/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/esm/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
- package/esm/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
- package/esm/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
- package/esm/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
- package/esm/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
- package/esm/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/esm/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
- package/esm/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
- package/esm/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
- package/esm/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
- package/esm/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
- package/esm/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
- package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
- package/esm/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/esm/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/esm/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
- package/esm/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
- package/esm/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
- package/esm/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
- package/esm/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
- package/esm/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
- package/esm/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
- package/esm/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
- package/esm/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
- package/esm/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
- package/esm/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
- package/esm/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
- package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
- package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
- package/esm/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
- package/esm/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
- package/esm/src/_packages/components.index.d.ts +4 -0
- package/esm/src/_packages/core.index.d.ts +22 -2
- package/esm/src/_packages/node.index.d.ts +40 -0
- package/esm/src/_packages/types.index.d.ts +20 -0
- package/esm/src/avatars/avatarAnimationScheduler.d.ts +4 -0
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
- package/esm/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
- package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/esm/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
- package/esm/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
- package/esm/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/esm/src/book-3.0/CliAgent.d.ts +66 -0
- package/esm/src/book-3.0/CliAgent.test.d.ts +1 -0
- package/esm/src/book-3.0/LiteAgent.d.ts +68 -0
- package/esm/src/book-3.0/LiteAgent.test.d.ts +1 -0
- package/esm/src/book-3.0/agentFolderPaths.d.ts +30 -0
- package/esm/src/book-3.0/cliAgentEnv.d.ts +33 -0
- package/esm/src/book-components/BookEditor/BookEditor.d.ts +6 -5
- package/esm/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/esm/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
- package/esm/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
- package/esm/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
- package/esm/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
- package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
- package/esm/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
- package/esm/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
- package/esm/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
- package/esm/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
- package/esm/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
- package/esm/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
- package/esm/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
- package/esm/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
- package/esm/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
- package/esm/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
- package/esm/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
- package/esm/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/esm/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
- package/esm/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
- package/esm/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
- package/esm/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- package/esm/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
- package/esm/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
- package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
- package/esm/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
- package/esm/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
- package/esm/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
- package/esm/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
- package/esm/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
- package/esm/src/book-components/_common/Modal/Modal.d.ts +1 -1
- package/esm/src/book-components/icons/AboutIcon.d.ts +1 -1
- package/esm/src/book-components/icons/DownloadIcon.d.ts +1 -1
- package/esm/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
- package/esm/src/book-components/icons/FullscreenIcon.d.ts +1 -1
- package/esm/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/esm/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/esm/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
- package/esm/src/cli/cli-commands/agent.d.ts +14 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
- package/esm/src/cli/cli-commands/agents-server/run.d.ts +6 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
- package/esm/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
- package/esm/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
- package/esm/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
- package/esm/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
- package/esm/src/cli/cli-commands/coder/server.d.ts +13 -0
- package/esm/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
- package/esm/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
- package/esm/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
- package/esm/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
- package/esm/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
- package/esm/src/commitments/index.d.ts +2 -1
- package/esm/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
- package/esm/src/utils/isTimingSafeEqualString.d.ts +25 -0
- package/esm/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +6 -1
- package/servers.ts +1 -16
- package/src/_packages/components.index.ts +4 -0
- package/src/_packages/core.index.ts +22 -2
- package/src/_packages/node.index.ts +40 -0
- package/src/_packages/types.index.ts +20 -0
- package/src/avatars/avatarAnimationScheduler.ts +76 -4
- package/src/avatars/types/AvatarVisualDefinition.ts +2 -0
- package/src/avatars/visuals/avatarVisualRegistry.ts +4 -0
- package/src/avatars/visuals/fractalAvatarVisual.ts +5 -4
- package/src/avatars/visuals/minecraft2AvatarVisual.ts +16 -11
- package/src/avatars/visuals/minecraftAvatarVisual.ts +21 -7
- package/src/avatars/visuals/octopus3d2AvatarVisual.ts +175 -38
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +1068 -0
- package/src/avatars/visuals/octopus3d4AvatarVisual.ts +1295 -0
- package/src/avatars/visuals/octopus3dAvatarVisual.ts +69 -17
- package/src/book-2.0/agent-source/AgentBasicInformation.ts +2 -0
- package/src/book-2.0/agent-source/agentSourceVisibility.ts +214 -0
- package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.ts +18 -2
- package/src/book-2.0/agent-source/parseAgentSource/applyMetaCommitment.ts +17 -0
- package/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.ts +1 -0
- package/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.ts +7 -1
- package/src/book-3.0/Book.ts +3 -1
- package/src/book-3.0/BookNodeAgentSource.ts +135 -0
- package/src/book-3.0/CliAgent.ts +252 -0
- package/src/book-3.0/LiteAgent.ts +468 -0
- package/src/book-3.0/agentFolderPaths.ts +38 -0
- package/src/book-3.0/cliAgentEnv.ts +46 -0
- package/src/book-components/BookEditor/BookEditor.module.css +61 -0
- package/src/book-components/BookEditor/BookEditor.tsx +16 -13
- package/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.tsx +72 -0
- package/src/book-components/BookEditor/BookEditorActionbar.tsx +35 -5
- package/src/book-components/BookEditor/BookEditorBrowserConfig.ts +11 -0
- package/src/book-components/BookEditor/BookEditorForClient.tsx +33 -0
- package/src/book-components/BookEditor/BookEditorMonaco.tsx +4 -2
- package/src/book-components/BookEditor/BookEditorMonacoTokenization.ts +89 -27
- package/src/book-components/BookEditor/BookEditorTheme.ts +32 -0
- package/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.ts +11 -0
- package/src/book-components/BookEditor/useBookEditorMonacoLanguage.ts +62 -92
- package/src/book-components/BookEditor/useBookEditorMonacoLifecycle.ts +1 -5
- package/src/book-components/BookEditor/useBookEditorMonacoStyles.ts +3 -2
- package/src/book-components/BookEditor/useBookEditorMonacoUploads.ts +1 -1
- package/src/book-components/Chat/Chat/Chat.module.css +50 -0
- package/src/book-components/Chat/Chat/Chat.tsx +4 -0
- package/src/book-components/Chat/Chat/ChatCitationModal.tsx +19 -5
- package/src/book-components/Chat/Chat/ChatMessageItem.tsx +22 -2
- package/src/book-components/Chat/Chat/ChatMessageList.tsx +6 -0
- package/src/book-components/Chat/Chat/ChatProps.tsx +6 -0
- package/src/book-components/Chat/Chat/ChatToolCallModal.tsx +4 -0
- package/src/book-components/Chat/Chat/ChatToolCallModalContent.tsx +4 -0
- package/src/book-components/Chat/Chat/CitationIframePreview.tsx +78 -0
- package/src/book-components/Chat/Chat/TeamToolCallModalContent.tsx +16 -3
- package/src/book-components/Chat/Chat/createChatMessageToolCallRenderModel.ts +2 -9
- package/src/book-components/Chat/Chat/useChatPostprocessedMessages.ts +13 -2
- package/src/book-components/Chat/MarkdownContent/MarkdownContent.tsx +63 -4
- package/src/book-components/Chat/SourceChip/SourceChip.module.css +8 -0
- package/src/book-components/Chat/SourceChip/SourceChip.tsx +19 -5
- package/src/book-components/Chat/hooks/useResolvedCitationLabel.ts +65 -0
- package/src/book-components/Chat/save/html/htmlSaveFormatDefinition.ts +315 -88
- package/src/book-components/Chat/save/react/reactSaveFormatDefinition.ts +7 -1
- package/src/book-components/Chat/types/ChatMessage.ts +5 -0
- package/src/book-components/Chat/types/ChatParticipant.ts +1 -1
- package/src/book-components/Chat/types/CitationLabelResolver.ts +9 -0
- package/src/book-components/Chat/utils/citationHelpers.ts +90 -2
- package/src/book-components/Chat/utils/createCitationFootnoteRenderModel.ts +3 -0
- package/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.ts +178 -0
- package/src/book-components/Chat/utils/isVisibleChatToolCall.ts +23 -0
- package/src/book-components/Chat/utils/parseCitationsFromContent.ts +6 -0
- package/src/book-components/Chat/utils/renderMarkdown.ts +3 -2
- package/src/book-components/_common/Dropdown/Dropdown.tsx +1 -1
- package/src/book-components/_common/MenuHoisting/MenuHoistingContext.tsx +1 -1
- package/src/book-components/_common/Modal/Modal.tsx +1 -1
- package/src/book-components/icons/AboutIcon.tsx +1 -1
- package/src/book-components/icons/DownloadIcon.tsx +1 -1
- package/src/book-components/icons/ExitFullscreenIcon.tsx +1 -1
- package/src/book-components/icons/FullscreenIcon.tsx +1 -1
- package/src/cli/cli-commands/agent/agentCliOptions.ts +92 -0
- package/src/cli/cli-commands/agent/chat.ts +54 -0
- package/src/cli/cli-commands/agent/exec.ts +60 -0
- package/src/cli/cli-commands/agent-folder/agentProjectPaths.ts +15 -28
- package/src/cli/cli-commands/agent.ts +44 -0
- package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +325 -33
- package/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.ts +15 -2
- package/src/cli/cli-commands/agents-server/run.ts +103 -31
- package/src/cli/cli-commands/agents-server/startAgentsServer.ts +270 -41
- package/src/cli/cli-commands/agents-server.ts +7 -1
- package/src/cli/cli-commands/coder/ThinkingLevel.ts +3 -1
- package/src/cli/cli-commands/coder/agentCodingFile.ts +1 -1
- package/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.ts +79 -0
- package/src/cli/cli-commands/coder/find-unwritten.ts +58 -0
- package/src/cli/cli-commands/coder/getDefaultCoderPackageJsonScripts.ts +2 -2
- package/src/cli/cli-commands/coder/init.ts +6 -1
- package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +10 -0
- package/src/cli/cli-commands/coder/printInitializationSummary.ts +3 -0
- package/src/cli/cli-commands/coder/run.ts +108 -13
- package/src/cli/cli-commands/coder/server.ts +259 -0
- package/src/cli/cli-commands/coder/waitOptions.ts +24 -0
- package/src/cli/cli-commands/coder.ts +6 -0
- package/src/cli/cli-commands/common/promptRunnerCliOptions.ts +33 -49
- package/src/cli/common/$deprecateCliCommand.ts +10 -1
- package/src/cli/promptbookCli.ts +2 -0
- package/src/collection/agent-collection/CreateAgentInput.ts +10 -5
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.ts +98 -17
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/createAgentPersistenceRecords.ts +7 -4
- package/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.ts +44 -8
- package/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.ts +2 -2
- package/src/commitments/GOAL/GOAL.ts +7 -2
- package/src/commitments/LANGUAGE/LANGUAGE.ts +7 -2
- package/src/commitments/META_VISIBILITY/META_VISIBILITY.ts +78 -0
- package/src/commitments/TEAM/TEAM.ts +12 -1
- package/src/commitments/USE_PROJECT/createUseProjectToolFunctions.ts +8 -1
- package/src/commitments/_common/teamInternalAgentAccess.ts +14 -8
- package/src/commitments/index.ts +2 -0
- package/src/execution/createPipelineExecutor/getKnowledgeForTask.ts +1 -1
- package/src/formats/csv/CsvFormatParser.ts +4 -4
- package/src/formats/csv/utils/csvParse.ts +2 -2
- package/src/import-plugins/JsonFileImportPlugin.ts +15 -2
- package/src/import-plugins/TextFileImportPlugin.ts +8 -1
- package/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.ts +1 -1
- package/src/llm-providers/_common/register/$provideLlmToolsFromEnv.ts +1 -1
- package/src/llm-providers/_common/register/$registeredLlmToolsMessage.ts +6 -1
- package/src/llm-providers/agent/AgentLlmExecutionTools.ts +2 -2
- package/src/llm-providers/agent/AgentLlmExecutionToolsAgentKitRunner.ts +2 -2
- package/src/llm-providers/agent/AgentLlmExecutionToolsOpenAiAssistantRunner.ts +2 -2
- package/src/llm-providers/anthropic-claude/register-configuration.ts +6 -3
- package/src/llm-providers/openai/OpenAiAgentKitExecutionToolsToolBuilder.ts +3 -1
- package/src/llm-providers/openai/OpenAiAssistantExecutionToolsToolRunner.ts +1 -1
- package/src/llm-providers/openai/OpenAiVectorStoreKnowledgeSourcePreparer.ts +1 -1
- package/src/other/templates/getTemplatesPipelineCollection.ts +817 -702
- package/src/scrapers/_common/utils/getScraperIntermediateSource.ts +2 -2
- package/src/scrapers/website/WebsiteScraper.ts +1 -1
- package/src/scrapers/website/utils/createShowdownConverter.ts +2 -2
- package/src/scripting/javascript/JavascriptEvalExecutionTools.ts +1 -1
- package/src/utils/agents/resolveAgentAvatarImageUrl.ts +1 -1
- package/src/utils/chat/chatAttachments/resolveChatAttachmentContent.ts +8 -1
- package/src/utils/isTimingSafeEqualString.ts +43 -0
- package/src/utils/misc/computeHash.ts +2 -2
- package/src/utils/random/$randomToken.ts +2 -2
- package/src/utils/validators/url/isValidAgentUrl.ts +5 -7
- package/src/version.ts +2 -2
- package/src/versions.txt +33 -0
- package/umd/apps/agents-server/src/constants/federatedAgentImport.d.ts +42 -0
- package/umd/apps/agents-server/src/constants/serverLimits.d.ts +224 -0
- package/umd/apps/agents-server/src/constants/toolUsageLimits.d.ts +55 -0
- package/umd/index.umd.js +24336 -18681
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-agent-chat/executeAgentChatTurn.d.ts +28 -0
- package/umd/scripts/run-agent-chat/runAgentChat.d.ts +5 -0
- package/umd/scripts/run-agent-chat/runAgentExec.d.ts +11 -0
- package/umd/scripts/run-agent-messages/main/AgentMessageFailureTracker.d.ts +27 -0
- package/umd/scripts/run-agent-messages/main/handleAgentWatchError.d.ts +4 -0
- package/umd/scripts/run-agent-messages/main/runAgentMessages.d.ts +1 -0
- package/umd/scripts/run-agent-messages/main/runMultipleAgentMessages.d.ts +1 -0
- package/umd/scripts/run-agent-messages/main/tickAgentMessages.d.ts +1 -0
- package/umd/scripts/run-agent-messages/messages/createAgentRunnerSystemMessage.d.ts +10 -0
- package/umd/scripts/run-agent-messages/messages/moveAgentMessageToFailed.d.ts +17 -0
- package/umd/scripts/run-codex-prompts/common/buildCoderRunProgressSnapshot.d.ts +5 -1
- package/umd/scripts/run-codex-prompts/common/cliProgressDisplay.d.ts +7 -0
- package/umd/scripts/run-codex-prompts/common/coderRunEstimateCache.d.ts +31 -0
- package/umd/scripts/run-codex-prompts/common/parseDuration.d.ts +19 -0
- package/umd/scripts/run-codex-prompts/common/progressFormatting.d.ts +2 -0
- package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +6 -0
- package/umd/scripts/run-codex-prompts/common/resolveInlineOrFileText.d.ts +14 -0
- package/umd/scripts/run-codex-prompts/common/runGoScript/printLiveScriptChunk.d.ts +4 -0
- package/umd/scripts/run-codex-prompts/common/sleepWithCountdown.d.ts +27 -0
- package/umd/scripts/run-codex-prompts/common/waitForPause.d.ts +12 -0
- package/umd/scripts/run-codex-prompts/git/commitChanges.d.ts +3 -1
- package/umd/scripts/run-codex-prompts/main/findUnwrittenPrompts.d.ts +19 -0
- package/umd/scripts/run-codex-prompts/main/runCodexPromptsServer.d.ts +27 -0
- package/umd/scripts/run-codex-prompts/main/runPromptRound.d.ts +5 -3
- package/umd/scripts/run-codex-prompts/runners/claude-code/ClaudeCodeRunner.d.ts +3 -1
- package/umd/scripts/run-codex-prompts/server/buildCoderServerPromptResponse.d.ts +50 -0
- package/umd/scripts/run-codex-prompts/server/buildCoderServerRunState.d.ts +23 -0
- package/umd/scripts/run-codex-prompts/server/coderServerHtml.d.ts +9 -0
- package/umd/scripts/run-codex-prompts/server/runCoderHttpServer.d.ts +35 -0
- package/umd/scripts/run-codex-prompts/server/updatePromptSection.d.ts +9 -0
- package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +8 -0
- package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +1 -0
- package/umd/scripts/run-codex-prompts/ui/buildRunUiFrameShared.d.ts +5 -1
- package/umd/scripts/run-codex-prompts/ui/renderCoderRunUi.d.ts +1 -0
- package/umd/src/_packages/components.index.d.ts +4 -0
- package/umd/src/_packages/core.index.d.ts +22 -2
- package/umd/src/_packages/node.index.d.ts +40 -0
- package/umd/src/_packages/types.index.d.ts +20 -0
- package/umd/src/avatars/avatarAnimationScheduler.d.ts +4 -0
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
- package/umd/src/avatars/visuals/octopus3d4AvatarVisual.d.ts +7 -0
- package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/umd/src/book-2.0/agent-source/agentSourceVisibility.d.ts +97 -0
- package/umd/src/book-2.0/agent-source/agentSourceVisibility.test.d.ts +1 -0
- package/umd/src/book-3.0/BookNodeAgentSource.d.ts +38 -0
- package/umd/src/book-3.0/CliAgent.d.ts +66 -0
- package/umd/src/book-3.0/CliAgent.test.d.ts +1 -0
- package/umd/src/book-3.0/LiteAgent.d.ts +68 -0
- package/umd/src/book-3.0/LiteAgent.test.d.ts +1 -0
- package/umd/src/book-3.0/agentFolderPaths.d.ts +30 -0
- package/umd/src/book-3.0/cliAgentEnv.d.ts +33 -0
- package/umd/src/book-components/BookEditor/BookEditor.d.ts +6 -5
- package/umd/src/book-components/BookEditor/BookEditorAboutPromptbookInformation.d.ts +12 -0
- package/umd/src/book-components/BookEditor/BookEditorBrowserConfig.d.ts +2 -0
- package/umd/src/book-components/BookEditor/BookEditorForClient.d.ts +7 -0
- package/umd/src/book-components/BookEditor/BookEditorMonacoTokenization.d.ts +2 -0
- package/umd/src/book-components/BookEditor/BookEditorTheme.d.ts +24 -0
- package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.browser.d.ts +9 -0
- package/umd/src/book-components/BookEditor/useBookEditorMonacoLanguage.d.ts +1 -6
- package/umd/src/book-components/BookEditor/useBookEditorMonacoLifecycle.d.ts +1 -4
- package/umd/src/book-components/BookEditor/useBookEditorMonacoStyles.d.ts +2 -1
- package/umd/src/book-components/Chat/Chat/ChatCitationModal.d.ts +2 -0
- package/umd/src/book-components/Chat/Chat/ChatMessageItem.d.ts +4 -0
- package/umd/src/book-components/Chat/Chat/ChatMessageList.d.ts +4 -0
- package/umd/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
- package/umd/src/book-components/Chat/Chat/ChatToolCallModal.d.ts +2 -0
- package/umd/src/book-components/Chat/Chat/ChatToolCallModalContent.d.ts +3 -1
- package/umd/src/book-components/Chat/Chat/CitationIframePreview.d.ts +20 -0
- package/umd/src/book-components/Chat/Chat/TeamToolCallModalContent.d.ts +2 -0
- package/umd/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/umd/src/book-components/Chat/SourceChip/SourceChip.d.ts +6 -1
- package/umd/src/book-components/Chat/hooks/useResolvedCitationLabel.d.ts +12 -0
- package/umd/src/book-components/Chat/types/ChatMessage.d.ts +4 -0
- package/umd/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- package/umd/src/book-components/Chat/types/CitationLabelResolver.d.ts +8 -0
- package/umd/src/book-components/Chat/utils/citationHelpers.d.ts +9 -0
- package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.d.ts +14 -0
- package/umd/src/book-components/Chat/utils/decodeJsonUnicodeEscapesInMarkdownText.test.d.ts +1 -0
- package/umd/src/book-components/Chat/utils/isVisibleChatToolCall.d.ts +10 -0
- package/umd/src/book-components/Chat/utils/parseCitationsFromContent.d.ts +4 -0
- package/umd/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
- package/umd/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +1 -1
- package/umd/src/book-components/_common/Modal/Modal.d.ts +1 -1
- package/umd/src/book-components/icons/AboutIcon.d.ts +1 -1
- package/umd/src/book-components/icons/DownloadIcon.d.ts +1 -1
- package/umd/src/book-components/icons/ExitFullscreenIcon.d.ts +1 -1
- package/umd/src/book-components/icons/FullscreenIcon.d.ts +1 -1
- package/umd/src/cli/cli-commands/agent/agentCliOptions.d.ts +38 -0
- package/umd/src/cli/cli-commands/agent/chat.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/exec.d.ts +10 -0
- package/umd/src/cli/cli-commands/agent/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent-folder/agentProjectPaths.d.ts +2 -24
- package/umd/src/cli/cli-commands/agent.d.ts +14 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +23 -1
- package/umd/src/cli/cli-commands/agents-server/run.d.ts +6 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +9 -2
- package/umd/src/cli/cli-commands/coder/ThinkingLevel.d.ts +1 -1
- package/umd/src/cli/cli-commands/coder/ensureCoderDeveloperAgentFile.d.ts +25 -0
- package/umd/src/cli/cli-commands/coder/find-unwritten.d.ts +10 -0
- package/umd/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.d.ts +2 -0
- package/umd/src/cli/cli-commands/coder/server.d.ts +13 -0
- package/umd/src/cli/cli-commands/coder/waitOptions.d.ts +14 -0
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +9 -25
- package/umd/src/collection/agent-collection/CreateAgentInput.d.ts +2 -1
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -0
- package/umd/src/collection/agent-collection/constructors/agent-collection-in-supabase/prepareAgentSourceForPersistence.d.ts +21 -1
- package/umd/src/commitments/META_VISIBILITY/META_VISIBILITY.d.ts +27 -0
- package/umd/src/commitments/_common/teamInternalAgentAccess.d.ts +9 -1
- package/umd/src/commitments/index.d.ts +2 -1
- package/umd/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/umd/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/umd/src/scrapers/website/utils/createShowdownConverter.d.ts +2 -2
- package/umd/src/utils/isTimingSafeEqualString.d.ts +25 -0
- package/umd/src/utils/validators/url/isValidAgentUrl.d.ts +5 -0
- package/umd/src/version.d.ts +1 -1
- package/apps/agents-server/src/app/api/long-streaming/route.ts +0 -23
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +0 -108
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +0 -117
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +0 -119
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +0 -74
- package/apps/agents-server/src/utils/defaultFederatedAgents/DefaultFederatedAgentsSyncOptions.ts +0 -9
- package/apps/agents-server/src/utils/defaultFederatedAgents/ensureDefaultFederatedAgentExists.ts +0 -277
- package/apps/agents-server/src/utils/defaultFederatedAgents/fetchCoreOrganizationPayload.ts +0 -39
- package/apps/agents-server/src/utils/defaultFederatedAgents/fetchFederatedAgentBook.ts +0 -43
- package/apps/agents-server/src/utils/defaultFederatedAgents/fetchWithDefaultFederatedAgentTimeout.ts +0 -28
- package/apps/agents-server/src/utils/defaultFederatedAgents/getDefaultFederatedAgentSyncPool.ts +0 -38
- package/apps/agents-server/src/utils/defaultFederatedAgents/loadActiveLocalAgentIdsByNormalizedName.ts +0 -41
- package/apps/agents-server/src/utils/defaultFederatedAgents/loadDefaultFederatedAgentSyncMetadata.ts +0 -76
- package/apps/agents-server/src/utils/defaultFederatedAgents/quoteIdentifier.ts +0 -11
- package/apps/agents-server/src/utils/defaultFederatedAgents/scheduleDefaultFederatedAgentsSync.ts +0 -88
- package/apps/agents-server/src/utils/defaultFederatedAgents/selectDefaultFederatedAgentsFromOrganizationPayload.ts +0 -181
- package/apps/agents-server/src/utils/defaultFederatedAgents/synchronizeDefaultFederatedAgents.ts +0 -77
- package/apps/agents-server/src/utils/shibboleth/createShibbolethAuthenticationLogPayload.ts +0 -173
- package/apps/agents-server/src/utils/shibboleth/writeShibbolethAuthenticationLog.ts +0 -27
- package/apps/agents-server/tests/e2e/authentication-and-navigation.spec.ts.todo +0 -178
- package/src/_packages/browser.index.ts +0 -31
- package/src/_packages/browser.readme.md +0 -43
- package/src/book-2.0/agent-source/parseAgentSourceWithCommitments.test.ts.todo +0 -265
- package/src/book-components/BookEditor/BookEditorMonaco.test.tsx.todo +0 -115
- package/src/book-components/Chat/utils/renderMarkdown.test.ts.tmp +0 -199
- package/src/collection/agent-collection/constructors/agent-collection-in-directory/AgentCollectionInDirectory.test.ts.todo +0 -131
- package/src/commands/_common/parseCommand.test.ts.todo +0 -48
- package/src/commitments/META_LINK/META_LINK.test.ts.todo +0 -75
- package/src/conversion/validation/pipelineStringToJson-errors.test.ts.todo +0 -33
- package/src/dialogs/simple-prompt/SimplePromptInterfaceTools.ts +0 -51
- package/src/executables/browsers/locateSafari.test.ts.tmp +0 -15
- package/src/execution/PromptbookFetch.test-type.ts +0 -14
- package/src/execution/createPipelineExecutor/00-createPipelineExecutor.test.ts.todo +0 -0
- package/src/execution/execution-report/executionReportJsonToString.test.ts.todo +0 -83
- package/src/execution/utils/usageToHuman.test.ts.todo +0 -80
- package/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.ts +0 -76
- package/src/llm-providers/_common/utils/assertUniqueModels.ts +0 -27
- package/src/llm-providers/_multiple/playground/playground.ts +0 -141
- package/src/llm-providers/_multiple/playground/tsconfig.json +0 -19
- package/src/llm-providers/agent/playground/playground.ts +0 -190
- package/src/llm-providers/agent/playground/tsconfig.json +0 -19
- package/src/llm-providers/anthropic-claude/playground/playground.ts +0 -99
- package/src/llm-providers/anthropic-claude/playground/tsconfig.json +0 -19
- package/src/llm-providers/azure-openai/playground/playground.ts +0 -101
- package/src/llm-providers/azure-openai/playground/tsconfig.json +0 -19
- package/src/llm-providers/ollama/playground/playground.ts +0 -120
- package/src/llm-providers/ollama/playground/tsconfig.json +0 -19
- package/src/llm-providers/openai/playground/playground.ts +0 -406
- package/src/llm-providers/openai/playground/tsconfig.json +0 -19
- package/src/llm-providers/remote/playground/playground.ts +0 -144
- package/src/llm-providers/remote/playground/tsconfig.json +0 -19
- package/src/llm-providers/vercel/playground/playground.ts +0 -133
- package/src/llm-providers/vercel/playground/tsconfig.json +0 -19
- package/src/personas/preparePersona.test.ts.todo +0 -126
- package/src/playground/backup/_playground-boilerplate.ts.txt +0 -37
- package/src/playground/backup/playground-agent-os.txt +0 -62
- package/src/playground/backup/playground-brj-app.ts.txt +0 -302
- package/src/playground/backup/playground-browser-playwright.txt +0 -110
- package/src/playground/backup/playground-claude-mcp.txt +0 -43
- package/src/playground/backup/playground-document-conversion.txt +0 -84
- package/src/playground/backup/playground-glob.ts.txt +0 -42
- package/src/playground/backup/playground-mcp-server.txt +0 -1
- package/src/playground/backup/playground-openai-agent-kit.txt +0 -73
- package/src/playground/backup/playground-openai-function-calling.txt +0 -131
- package/src/playground/backup/playground-openai-streaming.ts.txt +0 -68
- package/src/playground/backup/playground-scrape-knowledge.txt +0 -65
- package/src/playground/backup/playground-scraperFetch.ts.txt +0 -44
- package/src/playground/backup/playground-using-openai-compatible-route-on-agents-server.ts.txt +0 -49
- package/src/playground/backup/playground-write-pavolhejny-bio.txt +0 -120
- package/src/playground/permanent/_boilerplate.ts +0 -54
- package/src/playground/permanent/agent-with-browser-playground.ts +0 -92
- package/src/playground/permanent/error-handling-playground.ts +0 -103
- package/src/playground/playground.ts +0 -36
- package/src/playground/tsconfig.json +0 -19
- package/src/scrapers/_boilerplate/BoilerplateScraper.test.ts.todo +0 -73
- package/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.ts +0 -79
- package/src/scrapers/_boilerplate/playground/tsconfig.json +0 -19
- package/src/scrapers/_common/utils/files/blobToDataurl.test.ts.todo +0 -17
- package/src/scrapers/_common/utils/files/dataurlToBlob.test.ts.todo +0 -52
- package/src/scrapers/_common/utils/files/isValidDataurl.test.ts.todo +0 -42
- package/src/scrapers/_common/utils/files/shorten.test.ts.todo +0 -13
- package/src/scrapers/document/playground/document-scraper-playground.ts +0 -80
- package/src/scrapers/document/playground/tsconfig.json +0 -19
- package/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.ts +0 -80
- package/src/scrapers/document-legacy/playground/tsconfig.json +0 -19
- package/src/scrapers/markdown/playground/markdown-scraper-playground.ts +0 -74
- package/src/scrapers/markdown/playground/tsconfig.json +0 -19
- package/src/scrapers/markitdown/MarkitdownScraper.test.ts.todo +0 -132
- package/src/scrapers/markitdown/playground/markitdown-scraper-playground.ts +0 -91
- package/src/scrapers/markitdown/playground/tsconfig.json +0 -19
- package/src/scrapers/pdf/PdfScraper.test.ts.todo +0 -52
- package/src/scrapers/pdf/playground/pdf-scraper-playground.ts +0 -75
- package/src/scrapers/pdf/playground/tsconfig.json +0 -19
- package/src/scrapers/website/playground/tsconfig.json +0 -19
- package/src/scrapers/website/playground/website-scraper-playground.ts +0 -82
- package/src/storage/_common/PromptbookStorage.test-type.ts +0 -14
- package/src/storage/local-storage/getIndexedDbStorage.ts +0 -36
- package/src/storage/local-storage/getLocalStorage.ts +0 -33
- package/src/storage/local-storage/getSessionStorage.ts +0 -33
- package/src/storage/local-storage/utils/IndexedDbStorageOptions.ts +0 -16
- package/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.ts +0 -58
- package/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.ts +0 -45
- package/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.test.ts.todo +0 -35
- package/src/transpilers/openai-sdk/playground/playground.ts +0 -85
- package/src/transpilers/openai-sdk/playground/tmp/chatbot-openaisdk-1.js +0 -194
- package/src/transpilers/openai-sdk/playground/tmp/package.json +0 -3
- package/src/transpilers/openai-sdk/playground/tsconfig.json +0 -18
- package/src/utils/editable/utils/findUsableParameters.test.ts.todo +0 -43
- package/src/utils/editable/utils/stringifyPipelineJson.test.ts.todo +0 -38
- package/src/utils/markdown/prettifyMarkdown.test.ts.tmp +0 -42
- package/src/utils/serialization/serializeToPromptbookJavascript.test.ts.todo +0 -116
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
import { SAML, ValidateInResponseTo, generateServiceProviderMetadata, type Profile } from '@node-saml/node-saml';
|
|
2
|
+
import { DOMParser } from '@xmldom/xmldom';
|
|
3
|
+
import { $getTableName } from '../database/$getTableName';
|
|
4
|
+
import { $provideSupabaseForServer } from '../database/$provideSupabaseForServer';
|
|
5
|
+
import type { AgentsServerDatabase, Json } from '../database/schema';
|
|
6
|
+
import { getMetadataMap } from '../database/getMetadata';
|
|
7
|
+
import { $provideServer } from '../tools/$provideServer';
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_SHIBBOLETH_DISPLAY_NAME_ATTRIBUTE_NAMES,
|
|
10
|
+
DEFAULT_SHIBBOLETH_EMAIL_ATTRIBUTE_NAMES,
|
|
11
|
+
DEFAULT_SHIBBOLETH_UNSTRUCTURED_NAME_ATTRIBUTE_NAMES,
|
|
12
|
+
IS_SHIBBOLETH_AUTH_ACTIVE_METADATA_KEY,
|
|
13
|
+
SHIBBOLETH_AUTHENTICATION_METADATA_KEYS,
|
|
14
|
+
SHIBBOLETH_DISPLAY_NAME_ATTRIBUTE_NAMES_METADATA_KEY,
|
|
15
|
+
SHIBBOLETH_EMAIL_ATTRIBUTE_NAMES_METADATA_KEY,
|
|
16
|
+
SHIBBOLETH_IDENTITY_PROVIDER_METADATA_URL_METADATA_KEY,
|
|
17
|
+
SHIBBOLETH_IDENTITY_PROVIDER_METADATA_XML_METADATA_KEY,
|
|
18
|
+
SHIBBOLETH_SERVICE_PROVIDER_ENTITY_ID_METADATA_KEY,
|
|
19
|
+
SHIBBOLETH_UNSTRUCTURED_NAME_ATTRIBUTE_NAMES_METADATA_KEY,
|
|
20
|
+
parseShibbolethBooleanMetadata,
|
|
21
|
+
} from '../constants/shibbolethAuth';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Persistent NameID format recommended for Shibboleth integrations.
|
|
25
|
+
*/
|
|
26
|
+
const SHIBBOLETH_PERSISTENT_NAME_ID_FORMAT = 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* SAML HTTP Redirect binding URL.
|
|
30
|
+
*/
|
|
31
|
+
const SAML_HTTP_REDIRECT_BINDING = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Timeout for loading remote Identity Provider metadata.
|
|
35
|
+
*/
|
|
36
|
+
const SHIBBOLETH_IDENTITY_PROVIDER_METADATA_TIMEOUT_MS = 10_000;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Clock skew accepted when validating SAML assertion timestamps.
|
|
40
|
+
*/
|
|
41
|
+
const SHIBBOLETH_ACCEPTED_CLOCK_SKEW_MS = 120_000;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Placeholder password hash for database users that can only sign in via Shibboleth.
|
|
45
|
+
*/
|
|
46
|
+
const SHIBBOLETH_PASSWORDLESS_USER_PASSWORD_HASH = 'shibboleth-passwordless-user';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Marker stored on database users that authenticate with username/password only.
|
|
50
|
+
*/
|
|
51
|
+
const LOCAL_AUTHENTICATION_PROVIDER = 'LOCAL';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Marker stored on database users that authenticate with Shibboleth only.
|
|
55
|
+
*/
|
|
56
|
+
const SHIBBOLETH_AUTHENTICATION_PROVIDER = 'SHIBBOLETH';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Marker stored on database users that authenticate with username/password and Shibboleth.
|
|
60
|
+
*/
|
|
61
|
+
const LOCAL_AND_SHIBBOLETH_AUTHENTICATION_PROVIDER = 'LOCAL_AND_SHIBBOLETH';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* User table row fields needed while linking Shibboleth identities.
|
|
65
|
+
*/
|
|
66
|
+
type UserRowWithShibbolethColumns = Pick<
|
|
67
|
+
AgentsServerDatabase['public']['Tables']['User']['Row'],
|
|
68
|
+
'id' | 'username' | 'isAdmin'
|
|
69
|
+
> & {
|
|
70
|
+
readonly email?: string | null;
|
|
71
|
+
readonly displayName?: string | null;
|
|
72
|
+
readonly authenticationProvider?: string | null;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* User insert shape with Shibboleth profile columns added by migration.
|
|
77
|
+
*/
|
|
78
|
+
type UserInsertWithShibbolethColumns = AgentsServerDatabase['public']['Tables']['User']['Insert'] & {
|
|
79
|
+
readonly email?: string | null;
|
|
80
|
+
readonly displayName?: string | null;
|
|
81
|
+
readonly authenticationProvider?: string | null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* User update shape with Shibboleth profile columns added by migration.
|
|
86
|
+
*/
|
|
87
|
+
type UserUpdateWithShibbolethColumns = AgentsServerDatabase['public']['Tables']['User']['Update'] & {
|
|
88
|
+
readonly email?: string | null;
|
|
89
|
+
readonly displayName?: string | null;
|
|
90
|
+
readonly authenticationProvider?: string | null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Supabase projection for user fields needed while linking Shibboleth identities.
|
|
95
|
+
*/
|
|
96
|
+
const SHIBBOLETH_USER_SELECT_COLUMNS: string = 'id, username, isAdmin, email, displayName, authenticationProvider';
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Prefixed Shibboleth identity row.
|
|
100
|
+
*
|
|
101
|
+
* @private internal Shibboleth authentication record
|
|
102
|
+
*/
|
|
103
|
+
export type ShibbolethUserIdentityRow = {
|
|
104
|
+
readonly id: number;
|
|
105
|
+
readonly createdAt: string;
|
|
106
|
+
readonly updatedAt: string;
|
|
107
|
+
readonly userId: number;
|
|
108
|
+
readonly email: string;
|
|
109
|
+
readonly displayName: string | null;
|
|
110
|
+
readonly nameId: string | null;
|
|
111
|
+
readonly nameIdFormat: string | null;
|
|
112
|
+
readonly unstructuredName: string | null;
|
|
113
|
+
readonly eduPersonPrincipalName: string | null;
|
|
114
|
+
readonly rawAttributes: Json | null;
|
|
115
|
+
readonly lastLoggedInAt: string | null;
|
|
116
|
+
readonly loginCount: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Prefixed Shibboleth authentication attempt row.
|
|
121
|
+
*
|
|
122
|
+
* @private internal Shibboleth authentication record
|
|
123
|
+
*/
|
|
124
|
+
export type ShibbolethAuthenticationAttemptRow = {
|
|
125
|
+
readonly id: number;
|
|
126
|
+
readonly createdAt: string;
|
|
127
|
+
readonly stage: string;
|
|
128
|
+
readonly status: string;
|
|
129
|
+
readonly userId: number | null;
|
|
130
|
+
readonly email: string | null;
|
|
131
|
+
readonly displayName: string | null;
|
|
132
|
+
readonly nameId: string | null;
|
|
133
|
+
readonly relayState: string | null;
|
|
134
|
+
readonly ip: string | null;
|
|
135
|
+
readonly userAgent: string | null;
|
|
136
|
+
readonly errorMessage: string | null;
|
|
137
|
+
readonly rawAttributes: Json | null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Request metadata recorded with Shibboleth authentication attempts.
|
|
142
|
+
*
|
|
143
|
+
* @private internal Shibboleth authentication record
|
|
144
|
+
*/
|
|
145
|
+
export type ShibbolethRequestDetails = {
|
|
146
|
+
readonly ip: string | null;
|
|
147
|
+
readonly userAgent: string | null;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Parsed Shibboleth user attributes extracted from SAML profile data.
|
|
152
|
+
*
|
|
153
|
+
* @private internal Shibboleth authentication record
|
|
154
|
+
*/
|
|
155
|
+
export type ShibbolethProfileAttributes = {
|
|
156
|
+
readonly email: string;
|
|
157
|
+
readonly displayName: string | null;
|
|
158
|
+
readonly nameId: string | null;
|
|
159
|
+
readonly nameIdFormat: string | null;
|
|
160
|
+
readonly unstructuredName: string | null;
|
|
161
|
+
readonly eduPersonPrincipalName: string | null;
|
|
162
|
+
readonly rawAttributes: Json;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Service Provider URLs derived for the current request.
|
|
167
|
+
*
|
|
168
|
+
* @private internal Shibboleth authentication configuration
|
|
169
|
+
*/
|
|
170
|
+
export type ShibbolethServiceProviderUrls = {
|
|
171
|
+
readonly origin: string;
|
|
172
|
+
readonly entityId: string;
|
|
173
|
+
readonly assertionConsumerServiceUrl: string;
|
|
174
|
+
readonly metadataUrl: string;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parsed Identity Provider metadata needed by Node-SAML.
|
|
179
|
+
*
|
|
180
|
+
* @private internal Shibboleth authentication configuration
|
|
181
|
+
*/
|
|
182
|
+
export type ShibbolethIdentityProviderMetadata = {
|
|
183
|
+
readonly singleSignOnServiceUrl: string;
|
|
184
|
+
readonly signingCertificates: ReadonlyArray<string>;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Resolved Shibboleth authentication configuration status.
|
|
189
|
+
*
|
|
190
|
+
* @private internal Shibboleth authentication configuration
|
|
191
|
+
*/
|
|
192
|
+
export type ShibbolethAuthenticationConfiguration = {
|
|
193
|
+
readonly isActive: boolean;
|
|
194
|
+
readonly isConfigured: boolean;
|
|
195
|
+
readonly errors: ReadonlyArray<string>;
|
|
196
|
+
readonly identityProviderMetadataUrl: string | null;
|
|
197
|
+
readonly isIdentityProviderMetadataXmlConfigured: boolean;
|
|
198
|
+
readonly serviceProviderUrls: ShibbolethServiceProviderUrls;
|
|
199
|
+
readonly identityProviderMetadata: ShibbolethIdentityProviderMetadata | null;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Options for resolving Shibboleth authentication configuration.
|
|
204
|
+
*/
|
|
205
|
+
type ResolveShibbolethAuthenticationConfigurationOptions = {
|
|
206
|
+
readonly requestUrl: string;
|
|
207
|
+
readonly isIdentityProviderMetadataValidationEnabled?: boolean;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Options for recording a Shibboleth authentication attempt.
|
|
212
|
+
*/
|
|
213
|
+
type RecordShibbolethAuthenticationAttemptOptions = {
|
|
214
|
+
readonly stage: string;
|
|
215
|
+
readonly status: string;
|
|
216
|
+
readonly requestDetails?: ShibbolethRequestDetails;
|
|
217
|
+
readonly userId?: number | null;
|
|
218
|
+
readonly email?: string | null;
|
|
219
|
+
readonly displayName?: string | null;
|
|
220
|
+
readonly nameId?: string | null;
|
|
221
|
+
readonly relayState?: string | null;
|
|
222
|
+
readonly errorMessage?: string | null;
|
|
223
|
+
readonly rawAttributes?: Json | null;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Result of linking a SAML profile to an Agents Server user.
|
|
228
|
+
*/
|
|
229
|
+
type LinkedShibbolethUser = {
|
|
230
|
+
readonly user: UserRowWithShibbolethColumns;
|
|
231
|
+
readonly profileAttributes: ShibbolethProfileAttributes;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Minimal XML node shape used to avoid mixing browser DOM and xmldom typings.
|
|
236
|
+
*/
|
|
237
|
+
type XmlNodeWithElements = {
|
|
238
|
+
readonly getElementsByTagName: (tagName: string) => ArrayLike<XmlElementWithAttributes>;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Minimal XML element shape used by the Shibboleth metadata parser.
|
|
243
|
+
*/
|
|
244
|
+
type XmlElementWithAttributes = XmlNodeWithElements & {
|
|
245
|
+
readonly localName?: string | null;
|
|
246
|
+
readonly nodeName: string;
|
|
247
|
+
readonly textContent?: string | null;
|
|
248
|
+
readonly getAttribute: (attributeName: string) => string | null;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns a safe relative URL to redirect to after Shibboleth finishes.
|
|
253
|
+
*
|
|
254
|
+
* @param relayState - Raw RelayState value from the request or SAML response.
|
|
255
|
+
* @returns Safe relative URL.
|
|
256
|
+
*
|
|
257
|
+
* @private internal Shibboleth authentication helper
|
|
258
|
+
*/
|
|
259
|
+
export function sanitizeShibbolethRelayState(relayState: string | null | undefined): string {
|
|
260
|
+
const trimmedRelayState = (relayState || '').trim();
|
|
261
|
+
|
|
262
|
+
if (!trimmedRelayState || !trimmedRelayState.startsWith('/') || trimmedRelayState.startsWith('//')) {
|
|
263
|
+
return '/';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return trimmedRelayState;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Extracts audit metadata from an incoming request.
|
|
271
|
+
*
|
|
272
|
+
* @param request - Incoming route-handler request.
|
|
273
|
+
* @returns Request details safe to store in the Shibboleth audit log.
|
|
274
|
+
*
|
|
275
|
+
* @private internal Shibboleth authentication helper
|
|
276
|
+
*/
|
|
277
|
+
export function getShibbolethRequestDetails(request: Request): ShibbolethRequestDetails {
|
|
278
|
+
const forwardedFor = request.headers.get('x-forwarded-for');
|
|
279
|
+
const ip = forwardedFor?.split(',')[0]?.trim() || request.headers.get('x-real-ip') || null;
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
ip,
|
|
283
|
+
userAgent: request.headers.get('user-agent'),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Resolves Shibboleth configuration from metadata for a route-handler request.
|
|
289
|
+
*
|
|
290
|
+
* @param options - Request URL and validation options.
|
|
291
|
+
* @returns Shibboleth configuration status and parsed IdP metadata when validation is enabled.
|
|
292
|
+
*
|
|
293
|
+
* @private internal Shibboleth authentication helper
|
|
294
|
+
*/
|
|
295
|
+
export async function resolveShibbolethAuthenticationConfiguration(
|
|
296
|
+
options: ResolveShibbolethAuthenticationConfigurationOptions,
|
|
297
|
+
): Promise<ShibbolethAuthenticationConfiguration> {
|
|
298
|
+
const metadata = await getMetadataMap(SHIBBOLETH_AUTHENTICATION_METADATA_KEYS);
|
|
299
|
+
const isActive = parseShibbolethBooleanMetadata(metadata[IS_SHIBBOLETH_AUTH_ACTIVE_METADATA_KEY]);
|
|
300
|
+
const identityProviderMetadataUrl =
|
|
301
|
+
(metadata[SHIBBOLETH_IDENTITY_PROVIDER_METADATA_URL_METADATA_KEY] || '').trim() || null;
|
|
302
|
+
const identityProviderMetadataXml =
|
|
303
|
+
(metadata[SHIBBOLETH_IDENTITY_PROVIDER_METADATA_XML_METADATA_KEY] || '').trim() || null;
|
|
304
|
+
const serviceProviderUrls = resolveShibbolethServiceProviderUrls(options.requestUrl, metadata);
|
|
305
|
+
const errors: string[] = [];
|
|
306
|
+
let identityProviderMetadata: ShibbolethIdentityProviderMetadata | null = null;
|
|
307
|
+
|
|
308
|
+
if (!identityProviderMetadataUrl && !identityProviderMetadataXml) {
|
|
309
|
+
errors.push(
|
|
310
|
+
`Set ${SHIBBOLETH_IDENTITY_PROVIDER_METADATA_URL_METADATA_KEY} or ${SHIBBOLETH_IDENTITY_PROVIDER_METADATA_XML_METADATA_KEY}.`,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (
|
|
315
|
+
options.isIdentityProviderMetadataValidationEnabled === true &&
|
|
316
|
+
(identityProviderMetadataUrl || identityProviderMetadataXml)
|
|
317
|
+
) {
|
|
318
|
+
try {
|
|
319
|
+
const metadataXml =
|
|
320
|
+
identityProviderMetadataXml || (await fetchIdentityProviderMetadataXml(identityProviderMetadataUrl!));
|
|
321
|
+
identityProviderMetadata = parseIdentityProviderMetadataXml(metadataXml);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
errors.push(
|
|
324
|
+
error instanceof Error ? error.message : 'Failed to load Shibboleth Identity Provider metadata.',
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
isActive,
|
|
331
|
+
isConfigured: errors.length === 0,
|
|
332
|
+
errors,
|
|
333
|
+
identityProviderMetadataUrl,
|
|
334
|
+
isIdentityProviderMetadataXmlConfigured: Boolean(identityProviderMetadataXml),
|
|
335
|
+
serviceProviderUrls,
|
|
336
|
+
identityProviderMetadata,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Creates a Node-SAML client for the resolved Shibboleth configuration.
|
|
342
|
+
*
|
|
343
|
+
* @param configuration - Resolved Shibboleth configuration with parsed IdP metadata.
|
|
344
|
+
* @returns Configured Node-SAML client.
|
|
345
|
+
*
|
|
346
|
+
* @private internal Shibboleth authentication helper
|
|
347
|
+
*/
|
|
348
|
+
export function createShibbolethSamlClient(configuration: ShibbolethAuthenticationConfiguration): SAML {
|
|
349
|
+
if (!configuration.identityProviderMetadata) {
|
|
350
|
+
throw new Error('Shibboleth Identity Provider metadata is not loaded.');
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return new SAML({
|
|
354
|
+
callbackUrl: configuration.serviceProviderUrls.assertionConsumerServiceUrl,
|
|
355
|
+
entryPoint: configuration.identityProviderMetadata.singleSignOnServiceUrl,
|
|
356
|
+
issuer: configuration.serviceProviderUrls.entityId,
|
|
357
|
+
audience: configuration.serviceProviderUrls.entityId,
|
|
358
|
+
idpCert: [...configuration.identityProviderMetadata.signingCertificates],
|
|
359
|
+
identifierFormat: SHIBBOLETH_PERSISTENT_NAME_ID_FORMAT,
|
|
360
|
+
wantAssertionsSigned: true,
|
|
361
|
+
wantAuthnResponseSigned: false,
|
|
362
|
+
acceptedClockSkewMs: SHIBBOLETH_ACCEPTED_CLOCK_SKEW_MS,
|
|
363
|
+
validateInResponseTo: ValidateInResponseTo.never,
|
|
364
|
+
disableRequestedAuthnContext: true,
|
|
365
|
+
signatureAlgorithm: 'sha256',
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Creates Service Provider metadata XML for the current Agents Server deployment.
|
|
371
|
+
*
|
|
372
|
+
* @param requestUrl - URL of the current metadata route request.
|
|
373
|
+
* @returns Service Provider metadata XML suitable for the Shibboleth IdP admin.
|
|
374
|
+
*
|
|
375
|
+
* @private internal Shibboleth authentication helper
|
|
376
|
+
*/
|
|
377
|
+
export async function createShibbolethServiceProviderMetadataXml(requestUrl: string): Promise<string> {
|
|
378
|
+
const metadata = await getMetadataMap(SHIBBOLETH_AUTHENTICATION_METADATA_KEYS);
|
|
379
|
+
const serviceProviderUrls = resolveShibbolethServiceProviderUrls(requestUrl, metadata);
|
|
380
|
+
|
|
381
|
+
return generateServiceProviderMetadata({
|
|
382
|
+
issuer: serviceProviderUrls.entityId,
|
|
383
|
+
callbackUrl: serviceProviderUrls.assertionConsumerServiceUrl,
|
|
384
|
+
identifierFormat: SHIBBOLETH_PERSISTENT_NAME_ID_FORMAT,
|
|
385
|
+
wantAssertionsSigned: true,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Records one Shibboleth authentication attempt.
|
|
391
|
+
*
|
|
392
|
+
* @param options - Attempt details.
|
|
393
|
+
*
|
|
394
|
+
* @private internal Shibboleth authentication audit helper
|
|
395
|
+
*/
|
|
396
|
+
export async function recordShibbolethAuthenticationAttempt(
|
|
397
|
+
options: RecordShibbolethAuthenticationAttemptOptions,
|
|
398
|
+
): Promise<void> {
|
|
399
|
+
try {
|
|
400
|
+
const supabase = $provideSupabaseForServer();
|
|
401
|
+
const tableName = await getShibbolethAuthenticationAttemptTableName();
|
|
402
|
+
const { error } = await supabase.from(tableName).insert({
|
|
403
|
+
stage: options.stage,
|
|
404
|
+
status: options.status,
|
|
405
|
+
userId: options.userId ?? null,
|
|
406
|
+
email: options.email ?? null,
|
|
407
|
+
displayName: options.displayName ?? null,
|
|
408
|
+
nameId: options.nameId ?? null,
|
|
409
|
+
relayState: options.relayState ?? null,
|
|
410
|
+
ip: options.requestDetails?.ip ?? null,
|
|
411
|
+
userAgent: options.requestDetails?.userAgent ?? null,
|
|
412
|
+
errorMessage: options.errorMessage ?? null,
|
|
413
|
+
rawAttributes: options.rawAttributes ?? null,
|
|
414
|
+
} as never);
|
|
415
|
+
|
|
416
|
+
if (error) {
|
|
417
|
+
console.error('Failed to record Shibboleth authentication attempt:', error);
|
|
418
|
+
}
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error('Failed to record Shibboleth authentication attempt:', error);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Links a validated SAML profile to an Agents Server user, creating a passwordless user when needed.
|
|
426
|
+
*
|
|
427
|
+
* @param profile - Validated SAML profile from Node-SAML.
|
|
428
|
+
* @returns Linked database user and extracted Shibboleth attributes.
|
|
429
|
+
*
|
|
430
|
+
* @private internal Shibboleth authentication user helper
|
|
431
|
+
*/
|
|
432
|
+
export async function findOrCreateShibbolethUser(profile: Profile): Promise<LinkedShibbolethUser> {
|
|
433
|
+
const metadata = await getMetadataMap(SHIBBOLETH_AUTHENTICATION_METADATA_KEYS);
|
|
434
|
+
const profileAttributes = extractShibbolethProfileAttributes(profile, metadata);
|
|
435
|
+
const now = new Date().toISOString();
|
|
436
|
+
const existingIdentity =
|
|
437
|
+
(await findShibbolethIdentityByNameId(profileAttributes.nameId)) ||
|
|
438
|
+
(await findShibbolethIdentityByEmail(profileAttributes.email));
|
|
439
|
+
let user = existingIdentity ? await findUserRowById(existingIdentity.userId) : null;
|
|
440
|
+
|
|
441
|
+
if (!user) {
|
|
442
|
+
user = await findUserRowByEmail(profileAttributes.email);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (!user) {
|
|
446
|
+
user = await findUserRowByUsername(profileAttributes.email);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (!user) {
|
|
450
|
+
user = await insertShibbolethUser(profileAttributes, now);
|
|
451
|
+
} else {
|
|
452
|
+
user = await updateLinkedShibbolethUser(user, profileAttributes, now);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
await upsertShibbolethIdentity(user, profileAttributes, existingIdentity, now);
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
user,
|
|
459
|
+
profileAttributes,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Resolves the prefixed Shibboleth identity table name without relying on generated schema typings.
|
|
465
|
+
*
|
|
466
|
+
* @returns Prefixed table name.
|
|
467
|
+
*
|
|
468
|
+
* @private internal Shibboleth authentication table helper
|
|
469
|
+
*/
|
|
470
|
+
export async function getShibbolethUserIdentityTableName(): Promise<string> {
|
|
471
|
+
const { tablePrefix } = await $provideServer();
|
|
472
|
+
return `${tablePrefix}ShibbolethUserIdentity`;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Resolves the prefixed Shibboleth authentication attempt table name without relying on generated schema typings.
|
|
477
|
+
*
|
|
478
|
+
* @returns Prefixed table name.
|
|
479
|
+
*
|
|
480
|
+
* @private internal Shibboleth authentication table helper
|
|
481
|
+
*/
|
|
482
|
+
export async function getShibbolethAuthenticationAttemptTableName(): Promise<string> {
|
|
483
|
+
const { tablePrefix } = await $provideServer();
|
|
484
|
+
return `${tablePrefix}ShibbolethAuthenticationAttempt`;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Extracts required Shibboleth profile attributes from a validated SAML profile.
|
|
489
|
+
*/
|
|
490
|
+
function extractShibbolethProfileAttributes(
|
|
491
|
+
profile: Profile,
|
|
492
|
+
metadata: Readonly<Record<string, string | null>>,
|
|
493
|
+
): ShibbolethProfileAttributes {
|
|
494
|
+
const rawAttributes = sanitizeShibbolethRawAttributes(profile);
|
|
495
|
+
const email = getFirstProfileAttribute(
|
|
496
|
+
profile,
|
|
497
|
+
parseAttributeNames(
|
|
498
|
+
metadata[SHIBBOLETH_EMAIL_ATTRIBUTE_NAMES_METADATA_KEY],
|
|
499
|
+
DEFAULT_SHIBBOLETH_EMAIL_ATTRIBUTE_NAMES,
|
|
500
|
+
),
|
|
501
|
+
)?.toLowerCase();
|
|
502
|
+
|
|
503
|
+
if (!email) {
|
|
504
|
+
throw new Error('Shibboleth login did not provide an email attribute.');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const displayName =
|
|
508
|
+
getFirstProfileAttribute(
|
|
509
|
+
profile,
|
|
510
|
+
parseAttributeNames(
|
|
511
|
+
metadata[SHIBBOLETH_DISPLAY_NAME_ATTRIBUTE_NAMES_METADATA_KEY],
|
|
512
|
+
DEFAULT_SHIBBOLETH_DISPLAY_NAME_ATTRIBUTE_NAMES,
|
|
513
|
+
),
|
|
514
|
+
) || null;
|
|
515
|
+
const unstructuredName =
|
|
516
|
+
getFirstProfileAttribute(
|
|
517
|
+
profile,
|
|
518
|
+
parseAttributeNames(
|
|
519
|
+
metadata[SHIBBOLETH_UNSTRUCTURED_NAME_ATTRIBUTE_NAMES_METADATA_KEY],
|
|
520
|
+
DEFAULT_SHIBBOLETH_UNSTRUCTURED_NAME_ATTRIBUTE_NAMES,
|
|
521
|
+
),
|
|
522
|
+
) || null;
|
|
523
|
+
const eduPersonPrincipalName =
|
|
524
|
+
getFirstProfileAttribute(profile, ['eduPersonPrincipalName', 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6']) || null;
|
|
525
|
+
|
|
526
|
+
return {
|
|
527
|
+
email,
|
|
528
|
+
displayName,
|
|
529
|
+
nameId: getStringOrNull(profile.nameID),
|
|
530
|
+
nameIdFormat: getStringOrNull(profile.nameIDFormat),
|
|
531
|
+
unstructuredName,
|
|
532
|
+
eduPersonPrincipalName,
|
|
533
|
+
rawAttributes,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Resolves SP URLs from request URL, environment, and metadata.
|
|
539
|
+
*/
|
|
540
|
+
function resolveShibbolethServiceProviderUrls(
|
|
541
|
+
requestUrl: string,
|
|
542
|
+
metadata: Readonly<Record<string, string | null>>,
|
|
543
|
+
): ShibbolethServiceProviderUrls {
|
|
544
|
+
const requestOrigin = new URL(requestUrl).origin;
|
|
545
|
+
const configuredSiteUrl = (process.env.NEXT_PUBLIC_SITE_URL || '').trim();
|
|
546
|
+
const origin = configuredSiteUrl ? new URL(configuredSiteUrl).origin : requestOrigin;
|
|
547
|
+
const assertionConsumerServiceUrl = new URL('/api/auth/shibboleth/acs', origin).toString();
|
|
548
|
+
const metadataUrl = new URL('/api/auth/shibboleth/metadata', origin).toString();
|
|
549
|
+
const configuredEntityId = (metadata[SHIBBOLETH_SERVICE_PROVIDER_ENTITY_ID_METADATA_KEY] || '').trim();
|
|
550
|
+
|
|
551
|
+
return {
|
|
552
|
+
origin,
|
|
553
|
+
entityId: configuredEntityId || metadataUrl,
|
|
554
|
+
assertionConsumerServiceUrl,
|
|
555
|
+
metadataUrl,
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Loads remote IdP metadata XML.
|
|
561
|
+
*/
|
|
562
|
+
async function fetchIdentityProviderMetadataXml(identityProviderMetadataUrl: string): Promise<string> {
|
|
563
|
+
const response = await fetch(identityProviderMetadataUrl, {
|
|
564
|
+
cache: 'no-store',
|
|
565
|
+
signal: AbortSignal.timeout(SHIBBOLETH_IDENTITY_PROVIDER_METADATA_TIMEOUT_MS),
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
if (!response.ok) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`Failed to load Shibboleth Identity Provider metadata: ${response.status} ${response.statusText}.`,
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return response.text();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Parses IdP metadata XML into the fields needed for SAML login.
|
|
579
|
+
*/
|
|
580
|
+
function parseIdentityProviderMetadataXml(metadataXml: string): ShibbolethIdentityProviderMetadata {
|
|
581
|
+
const document = new DOMParser().parseFromString(metadataXml, 'application/xml') as unknown as XmlNodeWithElements;
|
|
582
|
+
const singleSignOnServices = getElementsByLocalName(document, 'SingleSignOnService');
|
|
583
|
+
const redirectSingleSignOnService =
|
|
584
|
+
singleSignOnServices.find((element) => element.getAttribute('Binding') === SAML_HTTP_REDIRECT_BINDING) ||
|
|
585
|
+
singleSignOnServices[0];
|
|
586
|
+
const singleSignOnServiceUrl = redirectSingleSignOnService?.getAttribute('Location') || '';
|
|
587
|
+
const signingCertificates = getSigningCertificates(document);
|
|
588
|
+
|
|
589
|
+
if (!singleSignOnServiceUrl) {
|
|
590
|
+
throw new Error('Shibboleth Identity Provider metadata is missing SingleSignOnService Location.');
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (signingCertificates.length === 0) {
|
|
594
|
+
throw new Error('Shibboleth Identity Provider metadata is missing a signing certificate.');
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return {
|
|
598
|
+
singleSignOnServiceUrl,
|
|
599
|
+
signingCertificates,
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Finds all XML elements with the given local name.
|
|
605
|
+
*/
|
|
606
|
+
function getElementsByLocalName(root: XmlNodeWithElements, localName: string): Array<XmlElementWithAttributes> {
|
|
607
|
+
return Array.from(root.getElementsByTagName('*')).filter(
|
|
608
|
+
(element) =>
|
|
609
|
+
element.localName === localName ||
|
|
610
|
+
element.nodeName === localName ||
|
|
611
|
+
element.nodeName.endsWith(`:${localName}`),
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Extracts signing certificates from IdP metadata XML.
|
|
617
|
+
*/
|
|
618
|
+
function getSigningCertificates(document: XmlNodeWithElements): string[] {
|
|
619
|
+
const signingKeyDescriptors = getElementsByLocalName(document, 'KeyDescriptor').filter((element) => {
|
|
620
|
+
const use = element.getAttribute('use');
|
|
621
|
+
return !use || use === 'signing';
|
|
622
|
+
});
|
|
623
|
+
const certificateElements = signingKeyDescriptors.flatMap((element) =>
|
|
624
|
+
getElementsByLocalName(element, 'X509Certificate'),
|
|
625
|
+
);
|
|
626
|
+
const fallbackCertificateElements =
|
|
627
|
+
certificateElements.length > 0 ? certificateElements : getElementsByLocalName(document, 'X509Certificate');
|
|
628
|
+
|
|
629
|
+
return Array.from(
|
|
630
|
+
new Set(
|
|
631
|
+
fallbackCertificateElements
|
|
632
|
+
.map((element) => formatPemCertificate(element.textContent || ''))
|
|
633
|
+
.filter(Boolean),
|
|
634
|
+
),
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Formats an XML X.509 certificate value as PEM.
|
|
640
|
+
*/
|
|
641
|
+
function formatPemCertificate(certificate: string): string {
|
|
642
|
+
const base64Certificate = certificate
|
|
643
|
+
.replace(/-----BEGIN CERTIFICATE-----/gu, '')
|
|
644
|
+
.replace(/-----END CERTIFICATE-----/gu, '')
|
|
645
|
+
.replace(/\s+/gu, '');
|
|
646
|
+
|
|
647
|
+
if (!base64Certificate) {
|
|
648
|
+
return '';
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const wrappedCertificate = base64Certificate.match(/.{1,64}/gu)?.join('\n') || base64Certificate;
|
|
652
|
+
return `-----BEGIN CERTIFICATE-----\n${wrappedCertificate}\n-----END CERTIFICATE-----`;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Finds the first non-empty profile attribute from a list of accepted names.
|
|
657
|
+
*/
|
|
658
|
+
function getFirstProfileAttribute(profile: Profile, attributeNames: ReadonlyArray<string>): string | null {
|
|
659
|
+
for (const attributeName of attributeNames) {
|
|
660
|
+
const value = profile[attributeName];
|
|
661
|
+
const stringValue = getFirstStringValue(value);
|
|
662
|
+
if (stringValue) {
|
|
663
|
+
return stringValue;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Parses metadata-defined attribute names.
|
|
672
|
+
*/
|
|
673
|
+
function parseAttributeNames(value: string | null | undefined, fallback: string): string[] {
|
|
674
|
+
return (value || fallback)
|
|
675
|
+
.split(/[\s,]+/u)
|
|
676
|
+
.map((attributeName) => attributeName.trim())
|
|
677
|
+
.filter(Boolean);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Converts a profile value into one string.
|
|
682
|
+
*/
|
|
683
|
+
function getFirstStringValue(value: unknown): string | null {
|
|
684
|
+
if (typeof value === 'string') {
|
|
685
|
+
return value.trim() || null;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if (Array.isArray(value)) {
|
|
689
|
+
for (const item of value) {
|
|
690
|
+
const stringValue = getFirstStringValue(item);
|
|
691
|
+
if (stringValue) {
|
|
692
|
+
return stringValue;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Converts an unknown value into a string or null.
|
|
702
|
+
*/
|
|
703
|
+
function getStringOrNull(value: unknown): string | null {
|
|
704
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Builds a JSON-safe SAML profile snapshot for audit records.
|
|
709
|
+
*/
|
|
710
|
+
function sanitizeShibbolethRawAttributes(profile: Profile): Json {
|
|
711
|
+
const sanitizedAttributes: Record<string, Json> = {};
|
|
712
|
+
|
|
713
|
+
for (const [key, value] of Object.entries(profile)) {
|
|
714
|
+
if (typeof value === 'function') {
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const sanitizedValue = sanitizeJsonValue(value);
|
|
719
|
+
if (sanitizedValue !== undefined) {
|
|
720
|
+
sanitizedAttributes[key] = sanitizedValue;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return sanitizedAttributes;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Converts unknown profile values into JSON-safe values.
|
|
729
|
+
*/
|
|
730
|
+
function sanitizeJsonValue(value: unknown): Json | undefined {
|
|
731
|
+
if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
732
|
+
return value;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
if (Array.isArray(value)) {
|
|
736
|
+
return value.map((item) => sanitizeJsonValue(item)).filter((item): item is Json => item !== undefined);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (typeof value === 'object') {
|
|
740
|
+
const result: Record<string, Json> = {};
|
|
741
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
742
|
+
const sanitizedValue = sanitizeJsonValue(nestedValue);
|
|
743
|
+
if (sanitizedValue !== undefined) {
|
|
744
|
+
result[key] = sanitizedValue;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return result;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Finds one Shibboleth identity by persistent NameID.
|
|
755
|
+
*/
|
|
756
|
+
async function findShibbolethIdentityByNameId(nameId: string | null): Promise<ShibbolethUserIdentityRow | null> {
|
|
757
|
+
if (!nameId) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const supabase = $provideSupabaseForServer();
|
|
762
|
+
const tableName = await getShibbolethUserIdentityTableName();
|
|
763
|
+
const { data, error } = await supabase
|
|
764
|
+
.from(tableName)
|
|
765
|
+
.select('*')
|
|
766
|
+
.eq('nameId' as never, nameId as never)
|
|
767
|
+
.maybeSingle();
|
|
768
|
+
|
|
769
|
+
if (error) {
|
|
770
|
+
throw new Error(`Failed to resolve Shibboleth identity by NameID: ${error.message}`);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return (data as ShibbolethUserIdentityRow | null) || null;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Finds one Shibboleth identity by email.
|
|
778
|
+
*/
|
|
779
|
+
async function findShibbolethIdentityByEmail(email: string): Promise<ShibbolethUserIdentityRow | null> {
|
|
780
|
+
const supabase = $provideSupabaseForServer();
|
|
781
|
+
const tableName = await getShibbolethUserIdentityTableName();
|
|
782
|
+
const { data, error } = await supabase
|
|
783
|
+
.from(tableName)
|
|
784
|
+
.select('*')
|
|
785
|
+
.eq('email' as never, email as never)
|
|
786
|
+
.maybeSingle();
|
|
787
|
+
|
|
788
|
+
if (error) {
|
|
789
|
+
throw new Error(`Failed to resolve Shibboleth identity by email: ${error.message}`);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
return (data as ShibbolethUserIdentityRow | null) || null;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Finds one user row by database id.
|
|
797
|
+
*/
|
|
798
|
+
async function findUserRowById(userId: number): Promise<UserRowWithShibbolethColumns | null> {
|
|
799
|
+
const supabase = $provideSupabaseForServer();
|
|
800
|
+
const { data, error } = await supabase
|
|
801
|
+
.from(await $getTableName('User'))
|
|
802
|
+
.select(SHIBBOLETH_USER_SELECT_COLUMNS)
|
|
803
|
+
.eq('id', userId)
|
|
804
|
+
.maybeSingle();
|
|
805
|
+
|
|
806
|
+
if (error) {
|
|
807
|
+
throw new Error(`Failed to resolve Shibboleth user by id: ${error.message}`);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
return (data as UserRowWithShibbolethColumns | null) || null;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Finds one user row by email.
|
|
815
|
+
*/
|
|
816
|
+
async function findUserRowByEmail(email: string): Promise<UserRowWithShibbolethColumns | null> {
|
|
817
|
+
const supabase = $provideSupabaseForServer();
|
|
818
|
+
const { data, error } = await supabase
|
|
819
|
+
.from(await $getTableName('User'))
|
|
820
|
+
.select(SHIBBOLETH_USER_SELECT_COLUMNS)
|
|
821
|
+
.eq('email' as never, email as never)
|
|
822
|
+
.maybeSingle();
|
|
823
|
+
|
|
824
|
+
if (error) {
|
|
825
|
+
throw new Error(`Failed to resolve Shibboleth user by email: ${error.message}`);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return (data as UserRowWithShibbolethColumns | null) || null;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Finds one user row by username.
|
|
833
|
+
*/
|
|
834
|
+
async function findUserRowByUsername(username: string): Promise<UserRowWithShibbolethColumns | null> {
|
|
835
|
+
const supabase = $provideSupabaseForServer();
|
|
836
|
+
const { data, error } = await supabase
|
|
837
|
+
.from(await $getTableName('User'))
|
|
838
|
+
.select(SHIBBOLETH_USER_SELECT_COLUMNS)
|
|
839
|
+
.eq('username', username)
|
|
840
|
+
.maybeSingle();
|
|
841
|
+
|
|
842
|
+
if (error) {
|
|
843
|
+
throw new Error(`Failed to resolve Shibboleth user by username: ${error.message}`);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
return (data as UserRowWithShibbolethColumns | null) || null;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Inserts a new passwordless Shibboleth user.
|
|
851
|
+
*/
|
|
852
|
+
async function insertShibbolethUser(
|
|
853
|
+
profileAttributes: ShibbolethProfileAttributes,
|
|
854
|
+
now: string,
|
|
855
|
+
): Promise<UserRowWithShibbolethColumns> {
|
|
856
|
+
const supabase = $provideSupabaseForServer();
|
|
857
|
+
const userInsert: UserInsertWithShibbolethColumns = {
|
|
858
|
+
username: profileAttributes.email,
|
|
859
|
+
passwordHash: SHIBBOLETH_PASSWORDLESS_USER_PASSWORD_HASH,
|
|
860
|
+
isAdmin: false,
|
|
861
|
+
email: profileAttributes.email,
|
|
862
|
+
displayName: profileAttributes.displayName,
|
|
863
|
+
authenticationProvider: SHIBBOLETH_AUTHENTICATION_PROVIDER,
|
|
864
|
+
createdAt: now,
|
|
865
|
+
updatedAt: now,
|
|
866
|
+
};
|
|
867
|
+
const { data, error } = await supabase
|
|
868
|
+
.from(await $getTableName('User'))
|
|
869
|
+
.insert(userInsert)
|
|
870
|
+
.select(SHIBBOLETH_USER_SELECT_COLUMNS)
|
|
871
|
+
.single();
|
|
872
|
+
|
|
873
|
+
if (error) {
|
|
874
|
+
throw new Error(`Failed to create Shibboleth user: ${error.message}`);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
return data as unknown as UserRowWithShibbolethColumns;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Updates Shibboleth profile columns on an existing user row.
|
|
882
|
+
*/
|
|
883
|
+
async function updateLinkedShibbolethUser(
|
|
884
|
+
user: UserRowWithShibbolethColumns,
|
|
885
|
+
profileAttributes: ShibbolethProfileAttributes,
|
|
886
|
+
now: string,
|
|
887
|
+
): Promise<UserRowWithShibbolethColumns> {
|
|
888
|
+
const supabase = $provideSupabaseForServer();
|
|
889
|
+
const nextAuthenticationProvider =
|
|
890
|
+
user.authenticationProvider === LOCAL_AUTHENTICATION_PROVIDER || !user.authenticationProvider
|
|
891
|
+
? LOCAL_AND_SHIBBOLETH_AUTHENTICATION_PROVIDER
|
|
892
|
+
: user.authenticationProvider;
|
|
893
|
+
const userUpdate: UserUpdateWithShibbolethColumns = {
|
|
894
|
+
email: profileAttributes.email,
|
|
895
|
+
displayName: profileAttributes.displayName,
|
|
896
|
+
authenticationProvider: nextAuthenticationProvider,
|
|
897
|
+
updatedAt: now,
|
|
898
|
+
};
|
|
899
|
+
const { data, error } = await supabase
|
|
900
|
+
.from(await $getTableName('User'))
|
|
901
|
+
.update(userUpdate)
|
|
902
|
+
.eq('id', user.id)
|
|
903
|
+
.select(SHIBBOLETH_USER_SELECT_COLUMNS)
|
|
904
|
+
.single();
|
|
905
|
+
|
|
906
|
+
if (error) {
|
|
907
|
+
throw new Error(`Failed to update Shibboleth user: ${error.message}`);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
return data as unknown as UserRowWithShibbolethColumns;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Creates or updates the Shibboleth identity link.
|
|
915
|
+
*/
|
|
916
|
+
async function upsertShibbolethIdentity(
|
|
917
|
+
user: UserRowWithShibbolethColumns,
|
|
918
|
+
profileAttributes: ShibbolethProfileAttributes,
|
|
919
|
+
existingIdentity: ShibbolethUserIdentityRow | null,
|
|
920
|
+
now: string,
|
|
921
|
+
): Promise<void> {
|
|
922
|
+
const supabase = $provideSupabaseForServer();
|
|
923
|
+
const tableName = await getShibbolethUserIdentityTableName();
|
|
924
|
+
const identityPayload = {
|
|
925
|
+
userId: user.id,
|
|
926
|
+
email: profileAttributes.email,
|
|
927
|
+
displayName: profileAttributes.displayName,
|
|
928
|
+
nameId: profileAttributes.nameId,
|
|
929
|
+
nameIdFormat: profileAttributes.nameIdFormat,
|
|
930
|
+
unstructuredName: profileAttributes.unstructuredName,
|
|
931
|
+
eduPersonPrincipalName: profileAttributes.eduPersonPrincipalName,
|
|
932
|
+
rawAttributes: profileAttributes.rawAttributes,
|
|
933
|
+
lastLoggedInAt: now,
|
|
934
|
+
loginCount: Number(existingIdentity?.loginCount || 0) + 1,
|
|
935
|
+
updatedAt: now,
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
if (existingIdentity) {
|
|
939
|
+
const { error } = await supabase
|
|
940
|
+
.from(tableName)
|
|
941
|
+
.update(identityPayload as never)
|
|
942
|
+
.eq('id' as never, existingIdentity.id as never);
|
|
943
|
+
if (error) {
|
|
944
|
+
throw new Error(`Failed to update Shibboleth identity: ${error.message}`);
|
|
945
|
+
}
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const { error } = await supabase.from(tableName).insert({
|
|
950
|
+
...identityPayload,
|
|
951
|
+
createdAt: now,
|
|
952
|
+
} as never);
|
|
953
|
+
|
|
954
|
+
if (error) {
|
|
955
|
+
throw new Error(`Failed to create Shibboleth identity: ${error.message}`);
|
|
956
|
+
}
|
|
957
|
+
}
|