@promptbook/cli 0.103.0-9 → 0.104.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 +59 -35
- package/apps/agents-server/README.md +3 -0
- package/apps/agents-server/TODO.txt +7 -0
- package/apps/agents-server/config.ts +130 -0
- package/apps/agents-server/next.config.ts +45 -0
- package/apps/agents-server/package-lock.json +27 -0
- package/apps/agents-server/package.json +12 -0
- package/apps/agents-server/postcss.config.mjs +8 -0
- package/apps/agents-server/public/.gitkeep +0 -0
- package/apps/agents-server/public/favicon.ico +0 -0
- package/apps/agents-server/public/fonts/OpenMoji-black-glyf.woff2 +0 -0
- package/apps/agents-server/public/fonts/download-font.js +22 -0
- package/apps/agents-server/public/logo-blue-white-256.png +0 -0
- package/apps/agents-server/public/sw.js +16 -0
- package/apps/agents-server/src/app/AddAgentButton.tsx +41 -0
- package/apps/agents-server/src/app/[agentName]/[...rest]/page.tsx +11 -0
- package/apps/agents-server/src/app/[agentName]/page.tsx +1 -0
- package/apps/agents-server/src/app/actions.ts +53 -0
- package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +186 -0
- package/apps/agents-server/src/app/admin/api-tokens/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +614 -0
- package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +22 -0
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +634 -0
- package/apps/agents-server/src/app/admin/chat-history/page.tsx +21 -0
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +477 -0
- package/apps/agents-server/src/app/admin/metadata/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/models/page.tsx +22 -0
- package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +131 -0
- package/apps/agents-server/src/app/admin/users/[userId]/page.tsx +21 -0
- package/apps/agents-server/src/app/admin/users/page.tsx +18 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +78 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +314 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +91 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +48 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentUrlCopy.tsx +40 -0
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatFeedbackButton.tsx +63 -0
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatHistoryButton.tsx +63 -0
- package/apps/agents-server/src/app/agents/[agentName]/CloneAgentButton.tsx +41 -0
- package/apps/agents-server/src/app/agents/[agentName]/CopyField.tsx +44 -0
- package/apps/agents-server/src/app/agents/[agentName]/InstallPwaButton.tsx +74 -0
- package/apps/agents-server/src/app/agents/[agentName]/ServiceWorkerRegister.tsx +24 -0
- package/apps/agents-server/src/app/agents/[agentName]/TODO.txt +1 -0
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +19 -0
- package/apps/agents-server/src/app/agents/[agentName]/agentLinks.tsx +80 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/agents/route.ts +67 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +88 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/test.http +37 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +174 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/feedback/route.ts +54 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +203 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/TODO.txt +1 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/route.ts +55 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/systemMessage/route.ts +47 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/chat/completions/route.ts +10 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/models/route.ts +93 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/chat/completions/route.ts +10 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/models/route.ts +93 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openrouter/chat/completions/route.ts +10 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +76 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +181 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +139 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +35 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChat.tsx +75 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChatComponent.tsx.todo +160 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +32 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx.todo +21 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatWrapper.tsx +68 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +33 -0
- package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +46 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/RestoreVersionButton.tsx +46 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/actions.ts +12 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +62 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/icon-256.png/route.tsx +80 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-fullhd.png/route.tsx +92 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-phone.png/route.tsx +92 -0
- package/apps/agents-server/src/app/agents/[agentName]/integration/SdkCodeTabs.tsx +31 -0
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +302 -0
- package/apps/agents-server/src/app/agents/[agentName]/layout.tsx +41 -0
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +182 -0
- package/apps/agents-server/src/app/agents/[agentName]/opengraph-image.tsx +102 -0
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +106 -0
- package/apps/agents-server/src/app/agents/[agentName]/website-integration/page.tsx +72 -0
- package/apps/agents-server/src/app/agents/page.tsx +11 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +47 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +19 -0
- package/apps/agents-server/src/app/api/agents/route.ts +43 -0
- package/apps/agents-server/src/app/api/api-tokens/route.ts +76 -0
- package/apps/agents-server/src/app/api/auth/change-password/route.ts +75 -0
- package/apps/agents-server/src/app/api/auth/login/route.ts +27 -0
- package/apps/agents-server/src/app/api/auth/logout/route.ts +7 -0
- package/apps/agents-server/src/app/api/chat/route.ts +32 -0
- package/apps/agents-server/src/app/api/chat-feedback/[id]/route.ts +38 -0
- package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +55 -0
- package/apps/agents-server/src/app/api/chat-feedback/route.ts +157 -0
- package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +37 -0
- package/apps/agents-server/src/app/api/chat-history/export/route.ts +55 -0
- package/apps/agents-server/src/app/api/chat-history/route.ts +147 -0
- package/apps/agents-server/src/app/api/chat-streaming/route.ts +48 -0
- package/apps/agents-server/src/app/api/embed.js/route.ts +93 -0
- package/apps/agents-server/src/app/api/federated-agents/route.ts +17 -0
- package/apps/agents-server/src/app/api/long-running-task/route.ts +7 -0
- package/apps/agents-server/src/app/api/long-streaming/route.ts +20 -0
- package/apps/agents-server/src/app/api/metadata/route.ts +116 -0
- package/apps/agents-server/src/app/api/openai/v1/chat/completions/route.ts +6 -0
- package/apps/agents-server/src/app/api/openai/v1/models/route.ts +65 -0
- package/apps/agents-server/src/app/api/upload/route.ts +83 -0
- package/apps/agents-server/src/app/api/users/[username]/route.ts +75 -0
- package/apps/agents-server/src/app/api/users/route.ts +71 -0
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +43 -0
- package/apps/agents-server/src/app/docs/page.tsx +59 -0
- package/apps/agents-server/src/app/embed/page.tsx +24 -0
- package/apps/agents-server/src/app/globals.css +276 -0
- package/apps/agents-server/src/app/humans.txt/route.ts +15 -0
- package/apps/agents-server/src/app/layout.tsx +139 -0
- package/apps/agents-server/src/app/manifest.ts +114 -0
- package/apps/agents-server/src/app/not-found.tsx +5 -0
- package/apps/agents-server/src/app/page.tsx +96 -0
- package/apps/agents-server/src/app/recycle-bin/RestoreAgentButton.tsx +40 -0
- package/apps/agents-server/src/app/recycle-bin/actions.ts +27 -0
- package/apps/agents-server/src/app/recycle-bin/page.tsx +58 -0
- package/apps/agents-server/src/app/restricted/page.tsx +33 -0
- package/apps/agents-server/src/app/robots.txt/route.ts +15 -0
- package/apps/agents-server/src/app/security.txt/route.ts +15 -0
- package/apps/agents-server/src/app/sitemap.xml/route.ts +37 -0
- package/apps/agents-server/src/app/test/og-image/README.md +1 -0
- package/apps/agents-server/src/app/test/og-image/opengraph-image.tsx +37 -0
- package/apps/agents-server/src/app/test/og-image/page.tsx +22 -0
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +339 -0
- package/apps/agents-server/src/components/AgentProfile/AgentProfileFromSource.tsx +23 -0
- package/apps/agents-server/src/components/AgentProfile/AgentQrCode.tsx +62 -0
- package/apps/agents-server/src/components/AgentProfile/QrCodeModal.tsx +90 -0
- package/apps/agents-server/src/components/Auth/AuthControls.tsx +123 -0
- package/apps/agents-server/src/components/ChangePasswordDialog/ChangePasswordDialog.tsx +41 -0
- package/apps/agents-server/src/components/ChangePasswordForm/ChangePasswordForm.tsx +159 -0
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +88 -0
- package/apps/agents-server/src/components/ErrorPage/ErrorPage.tsx +33 -0
- package/apps/agents-server/src/components/Footer/Footer.tsx +175 -0
- package/apps/agents-server/src/components/ForbiddenPage/ForbiddenPage.tsx +15 -0
- package/apps/agents-server/src/components/Header/Header.tsx +668 -0
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +60 -0
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +58 -0
- package/apps/agents-server/src/components/Homepage/Card.tsx +18 -0
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSection.tsx +21 -0
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSectionClient.tsx +183 -0
- package/apps/agents-server/src/components/Homepage/ModelCard.tsx +29 -0
- package/apps/agents-server/src/components/Homepage/ModelsSection.tsx +75 -0
- package/apps/agents-server/src/components/Homepage/Section.tsx +17 -0
- package/apps/agents-server/src/components/Homepage/TechInfoCard.tsx +20 -0
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +57 -0
- package/apps/agents-server/src/components/LoginDialog/LoginDialog.tsx +41 -0
- package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +109 -0
- package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +17 -0
- package/apps/agents-server/src/components/OpenMojiIcon/OpenMojiIcon.tsx +20 -0
- package/apps/agents-server/src/components/Portal/Portal.tsx +38 -0
- package/apps/agents-server/src/components/PrintButton/PrintButton.tsx +18 -0
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +18 -0
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +141 -0
- package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +139 -0
- package/apps/agents-server/src/components/VercelDeploymentCard/VercelDeploymentCard.tsx +55 -0
- package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +28 -0
- package/apps/agents-server/src/components/_utils/headlessParam.tsx +36 -0
- package/apps/agents-server/src/database/$getTableName.ts +18 -0
- package/apps/agents-server/src/database/$provideSupabase.ts +29 -0
- package/apps/agents-server/src/database/$provideSupabaseForBrowser.ts +41 -0
- package/apps/agents-server/src/database/$provideSupabaseForServer.ts +48 -0
- package/apps/agents-server/src/database/$provideSupabaseForWorker.ts +43 -0
- package/apps/agents-server/src/database/getMetadata.ts +31 -0
- package/apps/agents-server/src/database/metadataDefaults.ts +75 -0
- package/apps/agents-server/src/database/migrate.ts +131 -0
- package/apps/agents-server/src/database/migrations/2025-11-0001-initial-schema.sql +163 -0
- package/apps/agents-server/src/database/migrations/2025-11-0002-metadata-table.sql +16 -0
- package/apps/agents-server/src/database/migrations/2025-12-0010-llm-cache.sql +12 -0
- package/apps/agents-server/src/database/migrations/2025-12-0060-api-tokens.sql +13 -0
- package/apps/agents-server/src/database/migrations/2025-12-0070-chat-history-source.sql +2 -0
- package/apps/agents-server/src/database/schema.ts +308 -0
- package/apps/agents-server/src/deamons/longRunningTask.ts +37 -0
- package/apps/agents-server/src/middleware.ts +305 -0
- package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +54 -0
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +36 -0
- package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +117 -0
- package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +35 -0
- package/apps/agents-server/src/tools/$provideServer.ts +39 -0
- package/apps/agents-server/src/utils/auth.ts +33 -0
- package/apps/agents-server/src/utils/authenticateUser.ts +42 -0
- package/apps/agents-server/src/utils/cache/SupabaseCacheStorage.ts +55 -0
- package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +119 -0
- package/apps/agents-server/src/utils/cdn/classes/VercelBlobStorage.ts +64 -0
- package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +32 -0
- package/apps/agents-server/src/utils/cdn/interfaces/IStorage.ts +14 -0
- package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +28 -0
- package/apps/agents-server/src/utils/cdn/utils/nameToSubfolderPath.ts +9 -0
- package/apps/agents-server/src/utils/cdn/utils/nextRequestToNodeRequest.ts +27 -0
- package/apps/agents-server/src/utils/chatFeedbackAdmin.ts +96 -0
- package/apps/agents-server/src/utils/chatHistoryAdmin.ts +96 -0
- package/apps/agents-server/src/utils/convertToCsv.ts +31 -0
- package/apps/agents-server/src/utils/getCurrentUser.ts +32 -0
- package/apps/agents-server/src/utils/getEffectiveFederatedServers.ts +22 -0
- package/apps/agents-server/src/utils/getFederatedAgents.ts +89 -0
- package/apps/agents-server/src/utils/getFederatedServersFromMetadata.ts +10 -0
- package/apps/agents-server/src/utils/getVisibleCommitmentDefinitions.ts +12 -0
- package/apps/agents-server/src/utils/handleChatCompletion.ts +355 -0
- package/apps/agents-server/src/utils/isIpAllowed.ts +101 -0
- package/apps/agents-server/src/utils/isUserAdmin.ts +31 -0
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +100 -0
- package/apps/agents-server/src/utils/session.ts +50 -0
- package/apps/agents-server/src/utils/validateApiKey.ts +128 -0
- package/apps/agents-server/src/utils/validators/validateMimeType.ts +24 -0
- package/apps/agents-server/tailwind.config.ts +26 -0
- package/apps/agents-server/tsconfig.json +29 -0
- package/apps/agents-server/vercel.json +7 -0
- package/esm/index.es.js +5406 -443
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +0 -81
- package/esm/typings/servers.d.ts +9 -7
- package/esm/typings/src/_packages/browser.index.d.ts +6 -0
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/components.index.d.ts +22 -8
- package/esm/typings/src/_packages/core.index.d.ts +58 -18
- package/esm/typings/src/_packages/node.index.d.ts +2 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +70 -8
- package/esm/typings/src/_packages/utils.index.d.ts +6 -0
- package/esm/typings/src/_packages/wizard.index.d.ts +4 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +20 -5
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +17 -1
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +3 -2
- package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +3 -3
- package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +18 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +3 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +6 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +85 -14
- package/esm/typings/src/book-components/BookEditor/BookEditorActionbar.d.ts +18 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorMonaco.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +17 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +16 -0
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +15 -0
- package/esm/typings/src/book-components/Chat/MockedChat/MockedChat.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +4 -0
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentIntegration.d.ts +67 -0
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentSeamlessIntegration.d.ts +23 -0
- package/esm/typings/src/book-components/Qr/BrandedQrCode.d.ts +18 -0
- package/esm/typings/src/book-components/Qr/GenericQrCode.d.ts +10 -0
- package/esm/typings/src/book-components/Qr/PromptbookQrCode.d.ts +18 -0
- package/esm/typings/src/book-components/Qr/useQrCode.d.ts +15 -0
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +15 -0
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +12 -0
- package/esm/typings/src/book-components/_common/Modal/Modal.d.ts +2 -2
- package/esm/typings/src/book-components/_common/Tooltip/Tooltip.d.ts +47 -0
- package/esm/typings/src/book-components/icons/AboutIcon.d.ts +9 -0
- package/esm/typings/src/book-components/icons/CameraIcon.d.ts +11 -0
- package/esm/typings/src/book-components/icons/CloseIcon.d.ts +4 -8
- package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +9 -0
- package/esm/typings/src/book-components/icons/ExitFullscreenIcon.d.ts +7 -0
- package/esm/typings/src/book-components/icons/FullscreenIcon.d.ts +7 -0
- package/esm/typings/src/book-components/icons/MenuIcon.d.ts +12 -0
- package/esm/typings/src/book-components/icons/MicIcon.d.ts +8 -0
- package/esm/typings/src/book-components/icons/SendIcon.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/about.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/login.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/make.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/{start-server.d.ts → start-agents-server.d.ts} +3 -2
- package/esm/typings/src/cli/cli-commands/start-pipelines-server.d.ts +15 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +2 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +2 -1
- package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +12 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +75 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +154 -0
- package/esm/typings/src/collection/{PipelineCollection.d.ts → pipeline-collection/PipelineCollection.d.ts} +7 -3
- package/esm/typings/src/collection/{SimplePipelineCollection.d.ts → pipeline-collection/SimplePipelineCollection.d.ts} +5 -5
- package/esm/typings/src/collection/{constructors/createCollectionFromDirectory.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.d.ts} +8 -11
- package/esm/typings/src/collection/pipeline-collection/constructors/createPipelineCollectionFromJson.d.ts +13 -0
- package/esm/typings/src/collection/{constructors/createCollectionFromPromise.d.ts → pipeline-collection/constructors/createPipelineCollectionFromPromise.d.ts} +6 -5
- package/esm/typings/src/collection/pipeline-collection/constructors/createPipelineCollectionFromPromise.test.d.ts +1 -0
- package/esm/typings/src/collection/{constructors/createCollectionFromUrl.d.ts → pipeline-collection/constructors/createPipelineCollectionFromUrl.d.ts} +3 -3
- package/esm/typings/src/collection/{constructors/createSubcollection.d.ts → pipeline-collection/constructors/createPipelineSubcollection.d.ts} +3 -3
- package/esm/typings/src/collection/pipeline-collection/pipelineCollectionToJson.d.ts +13 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -5
- package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +5 -1
- package/esm/typings/src/commitments/CLOSED/CLOSED.d.ts +39 -0
- package/esm/typings/src/commitments/CLOSED/CLOSED.test.d.ts +4 -0
- package/esm/typings/src/commitments/COMPONENT/COMPONENT.d.ts +28 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +5 -1
- package/esm/typings/src/commitments/FROM/FROM.d.ts +34 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +5 -5
- package/esm/typings/src/commitments/LANGUAGE/LANGUAGE.d.ts +35 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +5 -1
- package/esm/typings/src/commitments/MESSAGE/AgentMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +5 -1
- package/esm/typings/src/commitments/MESSAGE/UserMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +5 -1
- package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +48 -0
- package/esm/typings/src/commitments/META_FONT/META_FONT.d.ts +42 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +5 -1
- package/esm/typings/src/commitments/OPEN/OPEN.d.ts +35 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +5 -1
- package/esm/typings/src/commitments/USE/USE.d.ts +53 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +42 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.test.d.ts +1 -0
- package/esm/typings/src/commitments/USE_MCP/USE_MCP.d.ts +37 -0
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +38 -0
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +14 -2
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +6 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +5 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/commitments/index.d.ts +93 -0
- package/esm/typings/src/config.d.ts +24 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -0
- package/esm/typings/src/errors/0-index.d.ts +6 -0
- package/esm/typings/src/errors/DatabaseError.d.ts +12 -0
- package/esm/typings/src/errors/NotAllowed.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +2 -2
- package/esm/typings/src/execution/AvailableModel.d.ts +1 -0
- package/esm/typings/src/execution/Executables.d.ts +3 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +12 -3
- package/esm/typings/src/execution/ExecutionTools.d.ts +5 -0
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +26 -2
- package/esm/typings/src/execution/PromptResult.d.ts +7 -1
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +5 -0
- package/esm/typings/src/execution/utils/usage-constants.d.ts +4 -124
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +2 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +2 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +2 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
- package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +72 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +26 -4
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +19 -0
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +17 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +50 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -19
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/google-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +60 -2
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +7 -1
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +13 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +6 -6
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +1 -1
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +2 -0
- package/esm/typings/src/playground/permanent/_boilerplate.d.ts +5 -0
- package/esm/typings/src/playground/permanent/agent-with-browser-playground.d.ts +5 -0
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +1 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +26 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +4 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +3 -8
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -9
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +2 -1
- package/esm/typings/src/transpilers/_common/BookTranspiler.d.ts +33 -0
- package/esm/typings/src/transpilers/_common/BookTranspilerOptions.d.ts +18 -0
- package/esm/typings/src/transpilers/_common/register/$bookTranspilersRegister.d.ts +15 -0
- package/esm/typings/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.d.ts +16 -0
- package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +15 -0
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.d.ts +16 -0
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.test.d.ts +1 -0
- package/esm/typings/src/transpilers/openai-sdk/playground/playground.d.ts +5 -0
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +15 -0
- package/esm/typings/src/types/LlmCall.d.ts +20 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +13 -1
- package/esm/typings/src/types/ModelVariant.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +13 -1
- package/esm/typings/src/types/Updatable.d.ts +19 -0
- package/esm/typings/src/types/typeAliases.d.ts +38 -2
- package/esm/typings/src/utils/color/$randomColor.d.ts +1 -0
- package/esm/typings/src/utils/color/Color.d.ts +16 -1
- package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
- package/esm/typings/src/utils/color/css-colors.d.ts +1 -0
- package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
- package/esm/typings/src/utils/color/operators/darken.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/grayscale.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/lighten.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/saturate.d.ts +1 -1
- package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +16 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +2 -1
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +2 -1
- package/esm/typings/src/utils/files/$induceBookDownload.d.ts +13 -0
- package/esm/typings/src/utils/files/$induceFileDownload.d.ts +13 -0
- package/esm/typings/src/utils/files/ObjectUrl.d.ts +46 -0
- package/esm/typings/src/utils/files/listAllFiles.d.ts +2 -3
- package/esm/typings/src/utils/misc/aboutPromptbookInformation.d.ts +27 -0
- package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
- package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
- package/esm/typings/src/utils/misc/injectCssModuleIntoShadowRoot.d.ts +1 -0
- package/esm/typings/src/utils/misc/xAboutPromptbookInformation.d.ts +13 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
- package/esm/typings/src/utils/normalization/normalizeMessageText.d.ts +9 -0
- package/esm/typings/src/utils/normalization/normalizeMessageText.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
- package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
- package/esm/typings/src/utils/organization/$side_effect.d.ts +7 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
- package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
- package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
- package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +31 -0
- package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +9 -0
- package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +13 -0
- package/esm/typings/src/utils/random/$randomItem.d.ts +9 -0
- package/esm/typings/src/utils/random/$randomSeed.d.ts +3 -0
- package/esm/typings/src/utils/random/$randomToken.d.ts +2 -0
- package/esm/typings/src/utils/random/CzechNamePool.d.ts +7 -0
- package/esm/typings/src/utils/random/EnglishNamePool.d.ts +7 -0
- package/esm/typings/src/utils/random/NamePool.d.ts +17 -0
- package/esm/typings/src/utils/random/getNamePool.d.ts +10 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +2 -1
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
- package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -2
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +2 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/esm/typings/src/wizard/$getCompiledBook.d.ts +1 -2
- package/package.json +16 -16
- package/umd/index.umd.js +5382 -417
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-2.0/commitments/index.d.ts +0 -60
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +0 -5
- package/esm/typings/src/book-components/BookEditor/BookEditorWrapper.d.ts +0 -9
- package/esm/typings/src/book-components/BookEditor/config.d.ts +0 -10
- package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +0 -21
- package/esm/typings/src/collection/collectionToJson.d.ts +0 -13
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +0 -13
- /package/esm/typings/src/{book-components/Chat/utils/renderMarkdown.test.d.ts → book-2.0/agent-source/computeAgentHash.test.d.ts} +0 -0
- /package/esm/typings/src/{collection/constructors/createCollectionFromDirectory.test.d.ts → book-2.0/agent-source/normalizeAgentName.test.d.ts} +0 -0
- /package/esm/typings/src/{collection/constructors/createCollectionFromJson.test.d.ts → book-components/Chat/AgentChat/AgentChat.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{constructors/createCollectionFromPromise.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.test.d.ts} +0 -0
- /package/esm/typings/src/{commands/_common/parseCommand.test.d.ts → collection/pipeline-collection/constructors/createPipelineCollectionFromJson.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{collectionToJson.test.d.ts → pipeline-collection/pipelineCollectionToJson.test.d.ts} +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { FileText, Hash, Image, Shield, ToggleLeft, Type, Upload } from 'lucide-react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { metadataDefaults, MetadataType } from '../../../database/metadataDefaults';
|
|
6
|
+
|
|
7
|
+
type MetadataEntry = {
|
|
8
|
+
id: number;
|
|
9
|
+
key: string;
|
|
10
|
+
value: string;
|
|
11
|
+
note: string | null;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
isDefault?: boolean;
|
|
15
|
+
type?: MetadataType;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function mergeMetadataWithDefaults(data: MetadataEntry[]): MetadataEntry[] {
|
|
19
|
+
const byKey = new Map<string, MetadataEntry>();
|
|
20
|
+
|
|
21
|
+
// First prefer existing (non-default) metadata coming from the database
|
|
22
|
+
for (const entry of data) {
|
|
23
|
+
const existing = byKey.get(entry.key);
|
|
24
|
+
if (!existing || existing.isDefault) {
|
|
25
|
+
// Find type from defaults
|
|
26
|
+
const def = metadataDefaults.find((d) => d.key === entry.key);
|
|
27
|
+
byKey.set(entry.key, { ...entry, type: def?.type });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Then add defaults only for keys that are missing
|
|
32
|
+
for (const def of metadataDefaults) {
|
|
33
|
+
if (!byKey.has(def.key)) {
|
|
34
|
+
byKey.set(def.key, {
|
|
35
|
+
id: -1,
|
|
36
|
+
key: def.key,
|
|
37
|
+
value: def.value,
|
|
38
|
+
note: def.note,
|
|
39
|
+
createdAt: new Date().toISOString(),
|
|
40
|
+
updatedAt: new Date().toISOString(),
|
|
41
|
+
isDefault: true,
|
|
42
|
+
type: def.type,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return Array.from(byKey.values()).sort((a, b) => a.key.localeCompare(b.key));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function MetadataClient() {
|
|
51
|
+
const [metadata, setMetadata] = useState<MetadataEntry[]>([]);
|
|
52
|
+
const [loading, setLoading] = useState(true);
|
|
53
|
+
const [error, setError] = useState<string | null>(null);
|
|
54
|
+
const [editingId, setEditingId] = useState<number | null>(null);
|
|
55
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
56
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
57
|
+
const [formState, setFormState] = useState<{
|
|
58
|
+
key: string;
|
|
59
|
+
value: string;
|
|
60
|
+
note: string;
|
|
61
|
+
type?: MetadataType;
|
|
62
|
+
}>({ key: '', value: '', note: '' });
|
|
63
|
+
|
|
64
|
+
const fetchMetadata = async () => {
|
|
65
|
+
try {
|
|
66
|
+
setLoading(true);
|
|
67
|
+
const response = await fetch('/api/metadata');
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error('Failed to fetch metadata');
|
|
70
|
+
}
|
|
71
|
+
const data: MetadataEntry[] = await response.json();
|
|
72
|
+
|
|
73
|
+
const mergedData = mergeMetadataWithDefaults(data);
|
|
74
|
+
|
|
75
|
+
setMetadata(mergedData);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
78
|
+
} finally {
|
|
79
|
+
setLoading(false);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
fetchMetadata();
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
setError(null);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// If editingId is -1 (default value) or null (new value), use POST to create
|
|
93
|
+
// If editingId is > 0 (existing value), use PUT to update
|
|
94
|
+
const method = editingId && editingId !== -1 ? 'PUT' : 'POST';
|
|
95
|
+
const response = await fetch('/api/metadata', {
|
|
96
|
+
method,
|
|
97
|
+
headers: { 'Content-Type': 'application/json' },
|
|
98
|
+
body: JSON.stringify(formState),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
const data = await response.json();
|
|
103
|
+
throw new Error(data.error || 'Failed to save metadata');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setFormState({ key: '', value: '', note: '' });
|
|
107
|
+
setEditingId(null);
|
|
108
|
+
fetchMetadata();
|
|
109
|
+
} catch (err) {
|
|
110
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleEdit = (entry: MetadataEntry) => {
|
|
115
|
+
setEditingId(entry.id);
|
|
116
|
+
setFormState({
|
|
117
|
+
key: entry.key,
|
|
118
|
+
value: entry.value,
|
|
119
|
+
note: entry.note || '',
|
|
120
|
+
type: entry.type,
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleDelete = async (key: string) => {
|
|
125
|
+
if (!confirm('Are you sure you want to delete this metadata?')) return;
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const response = await fetch(`/api/metadata?key=${encodeURIComponent(key)}`, {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
const data = await response.json();
|
|
134
|
+
throw new Error(data.error || 'Failed to delete metadata');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fetchMetadata();
|
|
138
|
+
} catch (err) {
|
|
139
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const handleCancel = () => {
|
|
144
|
+
setEditingId(null);
|
|
145
|
+
setFormState({ key: '', value: '', note: '' });
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const getTypeIcon = (type?: MetadataType) => {
|
|
149
|
+
switch (type) {
|
|
150
|
+
case 'TEXT_SINGLE_LINE':
|
|
151
|
+
return <Type className="w-4 h-4" />;
|
|
152
|
+
case 'TEXT':
|
|
153
|
+
return <FileText className="w-4 h-4" />;
|
|
154
|
+
case 'NUMBER':
|
|
155
|
+
return <Hash className="w-4 h-4" />;
|
|
156
|
+
case 'BOOLEAN':
|
|
157
|
+
return <ToggleLeft className="w-4 h-4" />;
|
|
158
|
+
case 'IMAGE_URL':
|
|
159
|
+
return <Image className="w-4 h-4" />;
|
|
160
|
+
case 'IP_RANGE':
|
|
161
|
+
return <Shield className="w-4 h-4" />;
|
|
162
|
+
default:
|
|
163
|
+
return <Type className="w-4 h-4" />;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const validateIpOrCidr = (ip: string) => {
|
|
168
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
169
|
+
const cidrV4Regex =
|
|
170
|
+
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/;
|
|
171
|
+
// Simple IPv6 check (allows :: abbreviation)
|
|
172
|
+
const ipv6Regex =
|
|
173
|
+
/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
174
|
+
const cidrV6Regex = /^([0-9a-fA-F:.]{2,})\/(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9])$/;
|
|
175
|
+
|
|
176
|
+
if (ip.includes('/')) {
|
|
177
|
+
return cidrV4Regex.test(ip) || cidrV6Regex.test(ip);
|
|
178
|
+
}
|
|
179
|
+
return ipv4Regex.test(ip) || ipv6Regex.test(ip);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
183
|
+
const file = e.target.files?.[0];
|
|
184
|
+
if (!file) return;
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
setIsUploading(true);
|
|
188
|
+
const formData = new FormData();
|
|
189
|
+
formData.append('file', file);
|
|
190
|
+
|
|
191
|
+
const response = await fetch('/api/upload', {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
body: formData,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
throw new Error(`Failed to upload file: ${response.statusText}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const { fileUrl: longFileUrl } = await response.json();
|
|
201
|
+
|
|
202
|
+
const LONG_URL = `${process.env.NEXT_PUBLIC_CDN_PUBLIC_URL!}/${process.env
|
|
203
|
+
.NEXT_PUBLIC_CDN_PATH_PREFIX!}/user/files/`;
|
|
204
|
+
const SHORT_URL = `https://ptbk.io/k/`;
|
|
205
|
+
// <- TODO: [🌍] Unite this logic in one place
|
|
206
|
+
|
|
207
|
+
const shortFileUrl = longFileUrl.split(LONG_URL).join(SHORT_URL);
|
|
208
|
+
setFormState((prev) => ({ ...prev, value: shortFileUrl }));
|
|
209
|
+
} catch (err) {
|
|
210
|
+
setError(err instanceof Error ? err.message : 'Failed to upload image');
|
|
211
|
+
} finally {
|
|
212
|
+
setIsUploading(false);
|
|
213
|
+
if (fileInputRef.current) {
|
|
214
|
+
fileInputRef.current.value = '';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
if (loading && metadata.length === 0) {
|
|
220
|
+
return <div className="p-8 text-center">Loading metadata...</div>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<div className="container mx-auto p-8 max-w-4xl">
|
|
225
|
+
<h1 className="text-3xl font-bold mb-8">Metadata Management</h1>
|
|
226
|
+
|
|
227
|
+
{error && (
|
|
228
|
+
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6">{error}</div>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
<div className="bg-white shadow rounded-lg p-6 mb-8">
|
|
232
|
+
<h2 className="text-xl font-semibold mb-4">{editingId ? 'Edit Metadata' : 'Add New Metadata'}</h2>
|
|
233
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
234
|
+
<div>
|
|
235
|
+
<label htmlFor="key" className="block text-sm font-medium text-gray-700 mb-1">
|
|
236
|
+
Key
|
|
237
|
+
</label>
|
|
238
|
+
<input
|
|
239
|
+
type="text"
|
|
240
|
+
id="key"
|
|
241
|
+
value={formState.key}
|
|
242
|
+
onChange={(e) => setFormState({ ...formState, key: e.target.value })}
|
|
243
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
244
|
+
required
|
|
245
|
+
disabled={!!editingId} // Key cannot be changed during edit
|
|
246
|
+
placeholder="e.g., SERVER_NAME"
|
|
247
|
+
/>
|
|
248
|
+
{editingId && <p className="text-xs text-gray-500 mt-1">Key cannot be changed.</p>}
|
|
249
|
+
</div>
|
|
250
|
+
<div>
|
|
251
|
+
<label htmlFor="value" className="block text-sm font-medium text-gray-700 mb-1">
|
|
252
|
+
Value
|
|
253
|
+
</label>
|
|
254
|
+
{formState.type === 'TEXT_SINGLE_LINE' ? (
|
|
255
|
+
<input
|
|
256
|
+
type="text"
|
|
257
|
+
id="value"
|
|
258
|
+
value={formState.value}
|
|
259
|
+
onChange={(e) => setFormState({ ...formState, value: e.target.value })}
|
|
260
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
261
|
+
required
|
|
262
|
+
placeholder="Metadata value..."
|
|
263
|
+
/>
|
|
264
|
+
) : formState.type === 'IMAGE_URL' ? (
|
|
265
|
+
<div className="space-y-2">
|
|
266
|
+
<div className="flex space-x-2">
|
|
267
|
+
<input
|
|
268
|
+
type="text"
|
|
269
|
+
id="value"
|
|
270
|
+
value={formState.value}
|
|
271
|
+
onChange={(e) => setFormState({ ...formState, value: e.target.value })}
|
|
272
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
273
|
+
placeholder="Image URL..."
|
|
274
|
+
/>
|
|
275
|
+
<input
|
|
276
|
+
type="file"
|
|
277
|
+
accept="image/*"
|
|
278
|
+
className="hidden"
|
|
279
|
+
ref={fileInputRef}
|
|
280
|
+
onChange={handleFileUpload}
|
|
281
|
+
/>
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
onClick={() => fileInputRef.current?.click()}
|
|
285
|
+
disabled={isUploading}
|
|
286
|
+
className="bg-gray-100 text-gray-700 px-3 py-2 rounded-md border border-gray-300 hover:bg-gray-200 flex items-center space-x-2 min-w-max"
|
|
287
|
+
>
|
|
288
|
+
<Upload className="w-4 h-4" />
|
|
289
|
+
<span>{isUploading ? 'Uploading...' : 'Upload Image'}</span>
|
|
290
|
+
</button>
|
|
291
|
+
</div>
|
|
292
|
+
{formState.value && (
|
|
293
|
+
<div className="mt-2 p-2 border border-gray-200 rounded-md bg-gray-50 inline-block">
|
|
294
|
+
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
295
|
+
<img
|
|
296
|
+
src={formState.value}
|
|
297
|
+
alt="Preview"
|
|
298
|
+
className="max-w-full h-auto max-h-[200px] object-contain"
|
|
299
|
+
onError={(e) => {
|
|
300
|
+
(e.target as HTMLImageElement).style.display = 'none';
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
)}
|
|
305
|
+
</div>
|
|
306
|
+
) : formState.type === 'BOOLEAN' ? (
|
|
307
|
+
<select
|
|
308
|
+
id="value"
|
|
309
|
+
value={formState.value}
|
|
310
|
+
onChange={(e) => setFormState({ ...formState, value: e.target.value })}
|
|
311
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
312
|
+
>
|
|
313
|
+
<option value="true">True</option>
|
|
314
|
+
<option value="false">False</option>
|
|
315
|
+
</select>
|
|
316
|
+
) : formState.type === 'NUMBER' ? (
|
|
317
|
+
<input
|
|
318
|
+
type="number"
|
|
319
|
+
id="value"
|
|
320
|
+
value={formState.value}
|
|
321
|
+
onChange={(e) => setFormState({ ...formState, value: e.target.value })}
|
|
322
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
323
|
+
required
|
|
324
|
+
placeholder="Metadata value..."
|
|
325
|
+
/>
|
|
326
|
+
) : formState.type === 'IP_RANGE' ? (
|
|
327
|
+
<div className="space-y-2">
|
|
328
|
+
<textarea
|
|
329
|
+
id="value"
|
|
330
|
+
value={formState.value.split(',').join('\n')}
|
|
331
|
+
onChange={(e) => {
|
|
332
|
+
const newValue = e.target.value
|
|
333
|
+
.split('\n')
|
|
334
|
+
.map((line) => line.trim())
|
|
335
|
+
.filter((line) => line !== '')
|
|
336
|
+
.join(',');
|
|
337
|
+
setFormState({ ...formState, value: newValue });
|
|
338
|
+
}}
|
|
339
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 min-h-[100px] font-mono"
|
|
340
|
+
placeholder="e.g. 192.168.1.1 10.0.0.0/24"
|
|
341
|
+
/>
|
|
342
|
+
<div className="flex flex-wrap gap-2">
|
|
343
|
+
{formState.value
|
|
344
|
+
.split(',')
|
|
345
|
+
.filter((ip) => ip.trim() !== '')
|
|
346
|
+
.map((ip, i) => {
|
|
347
|
+
const isValid = validateIpOrCidr(ip.trim());
|
|
348
|
+
return (
|
|
349
|
+
<span
|
|
350
|
+
key={i}
|
|
351
|
+
className={`px-2 py-1 rounded text-xs font-mono border ${
|
|
352
|
+
isValid
|
|
353
|
+
? 'bg-green-100 text-green-800 border-green-200'
|
|
354
|
+
: 'bg-red-100 text-red-800 border-red-200'
|
|
355
|
+
}`}
|
|
356
|
+
>
|
|
357
|
+
{ip}
|
|
358
|
+
{!isValid && ' (Invalid)'}
|
|
359
|
+
</span>
|
|
360
|
+
);
|
|
361
|
+
})}
|
|
362
|
+
</div>
|
|
363
|
+
<p className="text-xs text-gray-500">Enter each IP or CIDR range on a new line.</p>
|
|
364
|
+
</div>
|
|
365
|
+
) : (
|
|
366
|
+
<textarea
|
|
367
|
+
id="value"
|
|
368
|
+
value={formState.value}
|
|
369
|
+
onChange={(e) => setFormState({ ...formState, value: e.target.value })}
|
|
370
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 min-h-[100px]"
|
|
371
|
+
required
|
|
372
|
+
placeholder="Metadata value..."
|
|
373
|
+
/>
|
|
374
|
+
)}
|
|
375
|
+
</div>
|
|
376
|
+
<div>
|
|
377
|
+
<label htmlFor="note" className="block text-sm font-medium text-gray-700 mb-1">
|
|
378
|
+
Note (Optional)
|
|
379
|
+
</label>
|
|
380
|
+
<input
|
|
381
|
+
type="text"
|
|
382
|
+
id="note"
|
|
383
|
+
value={formState.note}
|
|
384
|
+
onChange={(e) => setFormState({ ...formState, note: e.target.value })}
|
|
385
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
386
|
+
placeholder="Description of this metadata"
|
|
387
|
+
/>
|
|
388
|
+
</div>
|
|
389
|
+
<div className="flex space-x-3">
|
|
390
|
+
<button
|
|
391
|
+
type="submit"
|
|
392
|
+
className="bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition-colors"
|
|
393
|
+
>
|
|
394
|
+
{editingId ? 'Update Metadata' : 'Add Metadata'}
|
|
395
|
+
</button>
|
|
396
|
+
{editingId && (
|
|
397
|
+
<button
|
|
398
|
+
type="button"
|
|
399
|
+
onClick={handleCancel}
|
|
400
|
+
className="bg-gray-200 text-gray-800 py-2 px-4 rounded-md hover:bg-gray-300 transition-colors"
|
|
401
|
+
>
|
|
402
|
+
Cancel
|
|
403
|
+
</button>
|
|
404
|
+
)}
|
|
405
|
+
</div>
|
|
406
|
+
</form>
|
|
407
|
+
</div>
|
|
408
|
+
|
|
409
|
+
<div className="bg-white shadow rounded-lg overflow-hidden">
|
|
410
|
+
<table className="min-w-full divide-y divide-gray-200">
|
|
411
|
+
<thead className="bg-gray-50">
|
|
412
|
+
<tr>
|
|
413
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
414
|
+
Type
|
|
415
|
+
</th>
|
|
416
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
417
|
+
Key
|
|
418
|
+
</th>
|
|
419
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
420
|
+
Value
|
|
421
|
+
</th>
|
|
422
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
423
|
+
Note
|
|
424
|
+
</th>
|
|
425
|
+
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
426
|
+
Actions
|
|
427
|
+
</th>
|
|
428
|
+
</tr>
|
|
429
|
+
</thead>
|
|
430
|
+
<tbody className="bg-white divide-y divide-gray-200">
|
|
431
|
+
{metadata.length === 0 ? (
|
|
432
|
+
<tr>
|
|
433
|
+
<td colSpan={4} className="px-6 py-4 text-center text-gray-500">
|
|
434
|
+
No metadata found.
|
|
435
|
+
</td>
|
|
436
|
+
</tr>
|
|
437
|
+
) : (
|
|
438
|
+
metadata.map((entry) => (
|
|
439
|
+
<tr key={entry.id}>
|
|
440
|
+
<td className="px-6 py-4 whitespace-nowrap text-gray-500">
|
|
441
|
+
<div className="flex items-center" title={entry.type || 'Unknown'}>
|
|
442
|
+
{getTypeIcon(entry.type)}
|
|
443
|
+
</div>
|
|
444
|
+
</td>
|
|
445
|
+
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
|
446
|
+
{entry.key}
|
|
447
|
+
</td>
|
|
448
|
+
<td className="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">{entry.value}</td>
|
|
449
|
+
<td className="px-6 py-4 text-sm text-gray-500">{entry.note || '-'}</td>
|
|
450
|
+
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
451
|
+
<button
|
|
452
|
+
onClick={() => handleEdit(entry)}
|
|
453
|
+
className="text-blue-600 hover:text-blue-900 mr-4"
|
|
454
|
+
>
|
|
455
|
+
Edit
|
|
456
|
+
</button>
|
|
457
|
+
{!entry.isDefault && (
|
|
458
|
+
<button
|
|
459
|
+
onClick={() => handleDelete(entry.key)}
|
|
460
|
+
className="text-red-600 hover:text-red-900"
|
|
461
|
+
>
|
|
462
|
+
Delete
|
|
463
|
+
</button>
|
|
464
|
+
)}
|
|
465
|
+
{entry.isDefault && (
|
|
466
|
+
<span className="text-gray-400 text-xs italic ml-2">Default</span>
|
|
467
|
+
)}
|
|
468
|
+
</td>
|
|
469
|
+
</tr>
|
|
470
|
+
))
|
|
471
|
+
)}
|
|
472
|
+
</tbody>
|
|
473
|
+
</table>
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
);
|
|
477
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ForbiddenPage } from '../../../components/ForbiddenPage/ForbiddenPage';
|
|
2
|
+
import { isUserAdmin } from '../../../utils/isUserAdmin';
|
|
3
|
+
import { MetadataClient } from './MetadataClient';
|
|
4
|
+
|
|
5
|
+
export default async function MetadataPage() {
|
|
6
|
+
const isAdmin = await isUserAdmin();
|
|
7
|
+
|
|
8
|
+
if (!isAdmin) {
|
|
9
|
+
return <ForbiddenPage />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return <MetadataClient />;
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getSingleLlmExecutionTools } from '@promptbook-local/core';
|
|
2
|
+
import { ForbiddenPage } from '../../../components/ForbiddenPage/ForbiddenPage';
|
|
3
|
+
import { ModelsSection } from '../../../components/Homepage/ModelsSection';
|
|
4
|
+
import { $provideExecutionToolsForServer } from '../../../tools/$provideExecutionToolsForServer';
|
|
5
|
+
import { isUserAdmin } from '../../../utils/isUserAdmin';
|
|
6
|
+
|
|
7
|
+
export default async function AdminModelsPage() {
|
|
8
|
+
const isAdmin = await isUserAdmin();
|
|
9
|
+
|
|
10
|
+
if (!isAdmin) {
|
|
11
|
+
return <ForbiddenPage />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const executionTools = await $provideExecutionToolsForServer();
|
|
15
|
+
const models = await getSingleLlmExecutionTools(executionTools.llm).listModels();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className="container mx-auto px-4 py-8">
|
|
19
|
+
<ModelsSection models={models} />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { useRouter } from 'next/navigation';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { Card } from '../../../../components/Homepage/Card';
|
|
7
|
+
import { Section } from '../../../../components/Homepage/Section';
|
|
8
|
+
import { useUsersAdmin } from '../../../../components/UsersList/useUsersAdmin';
|
|
9
|
+
|
|
10
|
+
type UserDetailClientProps = {
|
|
11
|
+
/**
|
|
12
|
+
* User identifier from the URL.
|
|
13
|
+
*
|
|
14
|
+
* In practice this is the username (see Header links), but we also
|
|
15
|
+
* gracefully handle the case where a numeric ID is used.
|
|
16
|
+
*/
|
|
17
|
+
userId: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function UserDetailClient({ userId }: UserDetailClientProps) {
|
|
21
|
+
const router = useRouter();
|
|
22
|
+
const { users, loading, error, deleteUser, toggleAdmin } = useUsersAdmin();
|
|
23
|
+
|
|
24
|
+
const user = useMemo(
|
|
25
|
+
() => users.find((u) => u.username === userId || String(u.id) === userId) ?? null,
|
|
26
|
+
[users, userId],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const handleDelete = async () => {
|
|
30
|
+
if (!user) return;
|
|
31
|
+
|
|
32
|
+
await deleteUser(user.username);
|
|
33
|
+
router.push('/admin/users');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleToggleAdmin = async () => {
|
|
37
|
+
if (!user) return;
|
|
38
|
+
|
|
39
|
+
await toggleAdmin(user.username, user.isAdmin);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (loading && !user) {
|
|
43
|
+
return <div className="container mx-auto px-4 py-8">Loading user...</div>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (error && !user) {
|
|
47
|
+
return (
|
|
48
|
+
<div className="container mx-auto px-4 py-8">
|
|
49
|
+
<div className="bg-red-100 text-red-700 p-3 rounded">{error}</div>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!user) {
|
|
55
|
+
return (
|
|
56
|
+
<div className="container mx-auto px-4 py-8">
|
|
57
|
+
<p className="text-gray-600">User not found.</p>
|
|
58
|
+
<Link href="/admin/users" className="mt-4 inline-block text-blue-600 hover:text-blue-800 text-sm">
|
|
59
|
+
← Back to users
|
|
60
|
+
</Link>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className="container mx-auto px-4 py-8 space-y-6">
|
|
67
|
+
<Link href="/admin/users" className="text-sm text-blue-600 hover:text-blue-800">
|
|
68
|
+
← Back to users
|
|
69
|
+
</Link>
|
|
70
|
+
|
|
71
|
+
<Section title={`User profile: ${user.username}`}>
|
|
72
|
+
<Card>
|
|
73
|
+
<div className="flex justify-between items-start">
|
|
74
|
+
<div>
|
|
75
|
+
<h2 className="text-2xl font-semibold text-gray-900">{user.username}</h2>
|
|
76
|
+
{user.isAdmin && (
|
|
77
|
+
<span className="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mt-1">
|
|
78
|
+
Admin
|
|
79
|
+
</span>
|
|
80
|
+
)}
|
|
81
|
+
<p className="text-gray-500 text-sm mt-2">ID: {user.id}</p>
|
|
82
|
+
<p className="text-gray-500 text-sm mt-1">
|
|
83
|
+
Created:{' '}
|
|
84
|
+
{user.createdAt
|
|
85
|
+
? new Date(user.createdAt).toLocaleString()
|
|
86
|
+
: 'Unknown'}
|
|
87
|
+
</p>
|
|
88
|
+
<p className="text-gray-500 text-sm mt-1">
|
|
89
|
+
Last updated:{' '}
|
|
90
|
+
{user.updatedAt
|
|
91
|
+
? new Date(user.updatedAt).toLocaleString()
|
|
92
|
+
: 'Unknown'}
|
|
93
|
+
</p>
|
|
94
|
+
</div>
|
|
95
|
+
<div className="space-x-2">
|
|
96
|
+
<button
|
|
97
|
+
onClick={handleToggleAdmin}
|
|
98
|
+
className="text-sm text-blue-600 hover:text-blue-800"
|
|
99
|
+
>
|
|
100
|
+
{user.isAdmin ? 'Remove admin' : 'Make admin'}
|
|
101
|
+
</button>
|
|
102
|
+
<button
|
|
103
|
+
onClick={handleDelete}
|
|
104
|
+
className="text-sm text-red-600 hover:text-red-800"
|
|
105
|
+
>
|
|
106
|
+
Delete user
|
|
107
|
+
</button>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</Card>
|
|
111
|
+
|
|
112
|
+
<Card>
|
|
113
|
+
<h3 className="text-lg font-semibold text-gray-900 mb-2">Created agents</h3>
|
|
114
|
+
<p className="text-gray-600 text-sm">
|
|
115
|
+
Listing agents created by users is not wired to the data model yet.
|
|
116
|
+
{/* TODO: [🧠] Once agents are linked to users, show their agents here. */}
|
|
117
|
+
</p>
|
|
118
|
+
</Card>
|
|
119
|
+
|
|
120
|
+
<Card>
|
|
121
|
+
<h3 className="text-lg font-semibold text-gray-900 mb-2">Activity</h3>
|
|
122
|
+
<p className="text-gray-600 text-sm">
|
|
123
|
+
Detailed activity tracking is not implemented yet. For now, you can use the
|
|
124
|
+
created/updated timestamps above as a basic signal of recent changes.
|
|
125
|
+
{/* TODO: [🧠] Implement user activity timeline once events are stored. */}
|
|
126
|
+
</p>
|
|
127
|
+
</Card>
|
|
128
|
+
</Section>
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { ForbiddenPage } from '../../../../components/ForbiddenPage/ForbiddenPage';
|
|
4
|
+
import { isUserAdmin } from '../../../../utils/isUserAdmin';
|
|
5
|
+
import { UserDetailClient } from './UserDetailClient';
|
|
6
|
+
|
|
7
|
+
export default async function UserDetailPage({
|
|
8
|
+
params,
|
|
9
|
+
}: {
|
|
10
|
+
params: Promise<{ userId: string }>;
|
|
11
|
+
}) {
|
|
12
|
+
const isAdmin = await isUserAdmin();
|
|
13
|
+
|
|
14
|
+
if (!isAdmin) {
|
|
15
|
+
return <ForbiddenPage />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { userId } = await params;
|
|
19
|
+
|
|
20
|
+
return <UserDetailClient userId={decodeURIComponent(userId)} />;
|
|
21
|
+
}
|