@promptbook/cli 0.104.0-9 → 0.104.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 +0 -4
- package/esm/index.es.js +255 -130
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +0 -6
- package/esm/typings/src/_packages/core.index.d.ts +8 -6
- package/esm/typings/src/_packages/types.index.d.ts +8 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +24 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +12 -2
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.tools.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +6 -3
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +5 -1
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +5 -1
- package/esm/typings/src/book-components/icons/AboutIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/AttachmentIcon.d.ts +6 -2
- package/esm/typings/src/book-components/icons/CameraIcon.d.ts +6 -2
- package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/MenuIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/SaveIcon.d.ts +6 -2
- package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +1 -1
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +9 -7
- package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
- package/esm/typings/src/commitments/META/META_DESCRIPTION.d.ts +41 -0
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
- package/esm/typings/src/commitments/_base/BookCommitment.d.ts +1 -1
- package/esm/typings/src/config.d.ts +8 -1
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +8 -4
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +12 -8
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -1
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
- package/esm/typings/src/remote-server/ui/ServerApp.d.ts +5 -1
- package/esm/typings/src/scrapers/_common/utils/promptbookFetch.test.d.ts +1 -0
- package/esm/typings/src/search-engines/SearchEngine.d.ts +9 -0
- package/esm/typings/src/search-engines/SearchResult.d.ts +18 -0
- package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +15 -0
- package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +15 -0
- package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
- package/esm/typings/src/types/typeAliasEmoji.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +7 -2
- package/esm/typings/src/utils/random/$randomItem.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
- package/esm/typings/src/utils/validators/url/isValidAgentUrl.d.ts +16 -0
- package/esm/typings/src/utils/validators/url/isValidAgentUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +4 -3
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +255 -130
- package/umd/index.umd.js.map +1 -1
- package/apps/agents-server/README.md +0 -3
- package/apps/agents-server/TODO.txt +0 -7
- package/apps/agents-server/config.ts +0 -128
- package/apps/agents-server/next.config.ts +0 -45
- package/apps/agents-server/package.json +0 -16
- package/apps/agents-server/postcss.config.mjs +0 -8
- 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/OpenMoji-color-cbdt.woff2 +0 -0
- package/apps/agents-server/public/logo-blue-white-256.png +0 -0
- package/apps/agents-server/public/sw.js +0 -16
- package/apps/agents-server/public/swagger.json +0 -115
- package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +0 -54
- package/apps/agents-server/scripts/generate-reserved-paths/tsconfig.json +0 -19
- package/apps/agents-server/src/app/AddAgentButton.tsx +0 -67
- package/apps/agents-server/src/app/[agentName]/[...rest]/page.tsx +0 -11
- package/apps/agents-server/src/app/[agentName]/page.tsx +0 -1
- package/apps/agents-server/src/app/actions.ts +0 -70
- package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +0 -186
- package/apps/agents-server/src/app/admin/api-tokens/page.tsx +0 -13
- package/apps/agents-server/src/app/admin/browser-test/BrowserTestClient.tsx +0 -108
- package/apps/agents-server/src/app/admin/browser-test/page.tsx +0 -13
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +0 -561
- package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +0 -22
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +0 -591
- package/apps/agents-server/src/app/admin/chat-history/page.tsx +0 -21
- package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +0 -294
- package/apps/agents-server/src/app/admin/messages/page.tsx +0 -13
- package/apps/agents-server/src/app/admin/messages/send-email/SendEmailClient.tsx +0 -104
- package/apps/agents-server/src/app/admin/messages/send-email/actions.ts +0 -35
- package/apps/agents-server/src/app/admin/messages/send-email/page.tsx +0 -13
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +0 -481
- package/apps/agents-server/src/app/admin/metadata/page.tsx +0 -13
- package/apps/agents-server/src/app/admin/models/page.tsx +0 -22
- package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +0 -131
- package/apps/agents-server/src/app/admin/users/[userId]/page.tsx +0 -21
- package/apps/agents-server/src/app/admin/users/page.tsx +0 -18
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +0 -92
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +0 -356
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +0 -134
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +0 -90
- package/apps/agents-server/src/app/agents/[agentName]/AgentUrlCopy.tsx +0 -40
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatFeedbackButton.tsx +0 -63
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatHistoryButton.tsx +0 -63
- package/apps/agents-server/src/app/agents/[agentName]/CloneAgentButton.tsx +0 -41
- package/apps/agents-server/src/app/agents/[agentName]/CopyField.tsx +0 -44
- package/apps/agents-server/src/app/agents/[agentName]/InstallPwaButton.tsx +0 -74
- package/apps/agents-server/src/app/agents/[agentName]/ServiceWorkerRegister.tsx +0 -24
- package/apps/agents-server/src/app/agents/[agentName]/TODO.txt +0 -1
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +0 -39
- package/apps/agents-server/src/app/agents/[agentName]/agentLinks.tsx +0 -80
- package/apps/agents-server/src/app/agents/[agentName]/api/agents/route.ts +0 -58
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +0 -90
- package/apps/agents-server/src/app/agents/[agentName]/api/book/test.http +0 -37
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +0 -194
- package/apps/agents-server/src/app/agents/[agentName]/api/feedback/route.ts +0 -54
- package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +0 -198
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/TODO.txt +0 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/route.ts +0 -55
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/systemMessage/route.ts +0 -47
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/chat/completions/route.ts +0 -10
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/models/route.ts +0 -93
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/chat/completions/route.ts +0 -10
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/models/route.ts +0 -93
- package/apps/agents-server/src/app/agents/[agentName]/api/openrouter/chat/completions/route.ts +0 -10
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +0 -80
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +0 -184
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +0 -143
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +0 -48
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChat.tsx +0 -75
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChatComponent.tsx.todo +0 -160
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +0 -45
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx.todo +0 -21
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatWrapper.tsx +0 -68
- package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +0 -45
- package/apps/agents-server/src/app/agents/[agentName]/code/api/route.ts +0 -68
- package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +0 -223
- package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +0 -51
- package/apps/agents-server/src/app/agents/[agentName]/history/RestoreVersionButton.tsx +0 -46
- package/apps/agents-server/src/app/agents/[agentName]/history/actions.ts +0 -12
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +0 -69
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/getAgentDefaultAvatarPrompt.ts +0 -31
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +0 -161
- package/apps/agents-server/src/app/agents/[agentName]/images/icon-256.png/route.tsx +0 -92
- package/apps/agents-server/src/app/agents/[agentName]/images/page.tsx +0 -200
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-fullhd.png/route.tsx +0 -93
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-phone.png/route.tsx +0 -93
- package/apps/agents-server/src/app/agents/[agentName]/integration/SdkCodeTabs.tsx +0 -31
- package/apps/agents-server/src/app/agents/[agentName]/integration/WebsiteIntegrationTabs.tsx +0 -26
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +0 -326
- package/apps/agents-server/src/app/agents/[agentName]/layout.tsx +0 -41
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +0 -189
- package/apps/agents-server/src/app/agents/[agentName]/opengraph-image.tsx +0 -111
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +0 -114
- package/apps/agents-server/src/app/agents/[agentName]/system-message/page.tsx +0 -100
- package/apps/agents-server/src/app/agents/[agentName]/website-integration/page.tsx +0 -89
- package/apps/agents-server/src/app/agents/page.tsx +0 -11
- package/apps/agents-server/src/app/api/admin-email/route.ts +0 -12
- package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +0 -46
- package/apps/agents-server/src/app/api/agents/[agentName]/restore/route.ts +0 -20
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +0 -61
- package/apps/agents-server/src/app/api/agents/route.ts +0 -68
- package/apps/agents-server/src/app/api/api-tokens/route.ts +0 -75
- package/apps/agents-server/src/app/api/auth/change-password/route.ts +0 -75
- package/apps/agents-server/src/app/api/auth/login/route.ts +0 -27
- package/apps/agents-server/src/app/api/auth/logout/route.ts +0 -7
- package/apps/agents-server/src/app/api/browser-test/screenshot/route.ts +0 -30
- package/apps/agents-server/src/app/api/browser-test/scroll-facebook/route.ts +0 -62
- package/apps/agents-server/src/app/api/chat/route.ts +0 -32
- package/apps/agents-server/src/app/api/chat-feedback/[id]/route.ts +0 -38
- package/apps/agents-server/src/app/api/chat-feedback/export/route.ts +0 -55
- package/apps/agents-server/src/app/api/chat-feedback/route.ts +0 -157
- package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +0 -37
- package/apps/agents-server/src/app/api/chat-history/export/route.ts +0 -55
- package/apps/agents-server/src/app/api/chat-history/route.ts +0 -147
- package/apps/agents-server/src/app/api/chat-streaming/route.ts +0 -48
- package/apps/agents-server/src/app/api/docs/book.md/route.ts +0 -61
- package/apps/agents-server/src/app/api/emails/incoming/sendgrid/route.ts +0 -48
- package/apps/agents-server/src/app/api/embed.js/route.ts +0 -113
- package/apps/agents-server/src/app/api/federated-agents/route.ts +0 -29
- package/apps/agents-server/src/app/api/images/[filename]/route.ts +0 -107
- package/apps/agents-server/src/app/api/long-running-task/route.ts +0 -7
- package/apps/agents-server/src/app/api/long-streaming/route.ts +0 -20
- package/apps/agents-server/src/app/api/messages/route.ts +0 -102
- package/apps/agents-server/src/app/api/metadata/route.ts +0 -115
- package/apps/agents-server/src/app/api/openai/v1/chat/completions/route.ts +0 -6
- package/apps/agents-server/src/app/api/openai/v1/models/route.ts +0 -65
- package/apps/agents-server/src/app/api/upload/route.ts +0 -166
- package/apps/agents-server/src/app/api/users/[username]/route.ts +0 -75
- package/apps/agents-server/src/app/api/users/route.ts +0 -71
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +0 -42
- package/apps/agents-server/src/app/docs/page.tsx +0 -59
- package/apps/agents-server/src/app/embed/layout.tsx +0 -31
- package/apps/agents-server/src/app/embed/page.tsx +0 -37
- package/apps/agents-server/src/app/globals.css +0 -383
- package/apps/agents-server/src/app/humans.txt/route.ts +0 -15
- package/apps/agents-server/src/app/layout.tsx +0 -144
- package/apps/agents-server/src/app/manifest.ts +0 -114
- package/apps/agents-server/src/app/not-found.tsx +0 -5
- package/apps/agents-server/src/app/page.tsx +0 -144
- package/apps/agents-server/src/app/recycle-bin/RestoreAgentButton.tsx +0 -40
- package/apps/agents-server/src/app/recycle-bin/actions.ts +0 -33
- package/apps/agents-server/src/app/recycle-bin/page.tsx +0 -44
- package/apps/agents-server/src/app/restricted/page.tsx +0 -33
- package/apps/agents-server/src/app/robots.txt/route.ts +0 -15
- package/apps/agents-server/src/app/security.txt/route.ts +0 -15
- package/apps/agents-server/src/app/sitemap.xml/route.ts +0 -39
- package/apps/agents-server/src/app/swagger/page.tsx +0 -14
- package/apps/agents-server/src/app/test/og-image/README.md +0 -1
- package/apps/agents-server/src/app/test/og-image/opengraph-image.tsx +0 -37
- package/apps/agents-server/src/app/test/og-image/page.tsx +0 -22
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +0 -264
- package/apps/agents-server/src/components/AgentProfile/AgentProfileFromSource.tsx +0 -23
- package/apps/agents-server/src/components/AgentProfile/AgentProfileImage.tsx +0 -79
- package/apps/agents-server/src/components/AgentProfile/AgentQrCode.tsx +0 -62
- package/apps/agents-server/src/components/AgentProfile/QrCodeModal.tsx +0 -89
- package/apps/agents-server/src/components/AgentProfile/useAgentBackground.ts +0 -97
- package/apps/agents-server/src/components/Auth/AuthControls.tsx +0 -124
- package/apps/agents-server/src/components/ChangePasswordDialog/ChangePasswordDialog.tsx +0 -41
- package/apps/agents-server/src/components/ChangePasswordForm/ChangePasswordForm.tsx +0 -159
- package/apps/agents-server/src/components/DeletedAgentBanner.tsx +0 -26
- package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +0 -38
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +0 -90
- package/apps/agents-server/src/components/ErrorPage/ErrorPage.tsx +0 -33
- package/apps/agents-server/src/components/Footer/Footer.tsx +0 -175
- package/apps/agents-server/src/components/ForbiddenPage/ForbiddenPage.tsx +0 -15
- package/apps/agents-server/src/components/ForgottenPasswordDialog/ForgottenPasswordDialog.tsx +0 -61
- package/apps/agents-server/src/components/Header/Header.tsx +0 -742
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +0 -182
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +0 -136
- package/apps/agents-server/src/components/Homepage/Card.tsx +0 -18
- package/apps/agents-server/src/components/Homepage/DeletedAgentsList.tsx +0 -66
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSection.tsx +0 -30
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSectionClient.tsx +0 -192
- package/apps/agents-server/src/components/Homepage/ModelCard.tsx +0 -29
- package/apps/agents-server/src/components/Homepage/ModelsSection.tsx +0 -75
- package/apps/agents-server/src/components/Homepage/Section.tsx +0 -17
- package/apps/agents-server/src/components/Homepage/TechInfoCard.tsx +0 -20
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +0 -58
- package/apps/agents-server/src/components/LoginDialog/LoginDialog.tsx +0 -41
- package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +0 -158
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +0 -88
- package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +0 -22
- package/apps/agents-server/src/components/OpenMojiIcon/OpenMojiIcon.tsx +0 -29
- package/apps/agents-server/src/components/Portal/Portal.tsx +0 -38
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +0 -18
- package/apps/agents-server/src/components/RegisterUserDialog/RegisterUserDialog.tsx +0 -61
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +0 -141
- package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +0 -139
- package/apps/agents-server/src/components/VercelDeploymentCard/VercelDeploymentCard.tsx +0 -57
- package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +0 -30
- package/apps/agents-server/src/components/_utils/headlessParam.tsx +0 -40
- package/apps/agents-server/src/database/$getTableName.ts +0 -18
- package/apps/agents-server/src/database/$provideSupabase.ts +0 -29
- package/apps/agents-server/src/database/$provideSupabaseForBrowser.ts +0 -41
- package/apps/agents-server/src/database/$provideSupabaseForServer.ts +0 -48
- package/apps/agents-server/src/database/$provideSupabaseForWorker.ts +0 -43
- package/apps/agents-server/src/database/getMetadata.ts +0 -31
- package/apps/agents-server/src/database/metadataDefaults.ts +0 -93
- package/apps/agents-server/src/database/migrate.ts +0 -164
- package/apps/agents-server/src/database/migrations/2025-11-0001-initial-schema.sql +0 -161
- package/apps/agents-server/src/database/migrations/2025-11-0002-metadata-table.sql +0 -14
- package/apps/agents-server/src/database/migrations/2025-12-0010-llm-cache.sql +0 -12
- package/apps/agents-server/src/database/migrations/2025-12-0060-api-tokens.sql +0 -13
- package/apps/agents-server/src/database/migrations/2025-12-0070-chat-history-source.sql +0 -2
- package/apps/agents-server/src/database/migrations/2025-12-0240-agent-public-id.sql +0 -3
- package/apps/agents-server/src/database/migrations/2025-12-0360-agent-deleted-at.sql +0 -1
- package/apps/agents-server/src/database/migrations/2025-12-0370-image-table.sql +0 -19
- package/apps/agents-server/src/database/migrations/2025-12-0380-agent-visibility.sql +0 -1
- package/apps/agents-server/src/database/migrations/2025-12-0390-upload-tracking.sql +0 -20
- package/apps/agents-server/src/database/migrations/2025-12-0401-file-upload-status.sql +0 -13
- package/apps/agents-server/src/database/migrations/2025-12-0402-message-table.sql +0 -42
- package/apps/agents-server/src/database/migrations/2025-12-0640-openai-assistant-cache.sql +0 -12
- package/apps/agents-server/src/database/migrations/2025-12-0820-agent-history-permanent-id.sql +0 -29
- package/apps/agents-server/src/database/schema.ts +0 -511
- package/apps/agents-server/src/deamons/longRunningTask.ts +0 -37
- package/apps/agents-server/src/generated/reservedPaths.ts +0 -32
- package/apps/agents-server/src/message-providers/email/_common/Email.ts +0 -73
- package/apps/agents-server/src/message-providers/email/_common/utils/TODO.txt +0 -1
- 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/parseEmailAddress.ts +0 -62
- 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/parseEmailAddresses.ts +0 -19
- 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/stringifyEmailAddress.ts +0 -19
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +0 -74
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.ts +0 -14
- package/apps/agents-server/src/message-providers/email/sendgrid/SendgridMessageProvider.ts +0 -44
- package/apps/agents-server/src/message-providers/email/sendgrid/parseInboundSendgridEmail.ts +0 -49
- package/apps/agents-server/src/message-providers/email/zeptomail/ZeptomailMessageProvider.ts +0 -51
- package/apps/agents-server/src/message-providers/index.ts +0 -13
- package/apps/agents-server/src/message-providers/interfaces/MessageProvider.ts +0 -11
- package/apps/agents-server/src/middleware.ts +0 -301
- package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +0 -54
- package/apps/agents-server/src/tools/$provideBrowserForServer.ts +0 -29
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +0 -41
- package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +0 -117
- package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +0 -35
- package/apps/agents-server/src/tools/$provideServer.ts +0 -39
- package/apps/agents-server/src/utils/auth.ts +0 -133
- package/apps/agents-server/src/utils/authenticateUser.ts +0 -42
- package/apps/agents-server/src/utils/cache/SupabaseCacheStorage.ts +0 -55
- package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +0 -119
- package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +0 -57
- package/apps/agents-server/src/utils/cdn/classes/VercelBlobStorage.ts +0 -68
- package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +0 -50
- package/apps/agents-server/src/utils/cdn/interfaces/IStorage.ts +0 -14
- package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +0 -28
- package/apps/agents-server/src/utils/cdn/utils/nameToSubfolderPath.ts +0 -9
- package/apps/agents-server/src/utils/cdn/utils/nextRequestToNodeRequest.ts +0 -27
- package/apps/agents-server/src/utils/chatFeedbackAdmin.ts +0 -96
- package/apps/agents-server/src/utils/chatHistoryAdmin.ts +0 -96
- package/apps/agents-server/src/utils/content/extractBodyContentFromHtml.ts +0 -19
- package/apps/agents-server/src/utils/convertToCsv.ts +0 -31
- package/apps/agents-server/src/utils/getCurrentUser.ts +0 -32
- package/apps/agents-server/src/utils/getEffectiveFederatedServers.ts +0 -22
- package/apps/agents-server/src/utils/getFederatedAgents.ts +0 -89
- package/apps/agents-server/src/utils/getFederatedServersFromMetadata.ts +0 -10
- package/apps/agents-server/src/utils/getUserIdFromRequest.ts +0 -35
- package/apps/agents-server/src/utils/getVisibleCommitmentDefinitions.ts +0 -12
- package/apps/agents-server/src/utils/handleChatCompletion.ts +0 -415
- package/apps/agents-server/src/utils/isIpAllowed.ts +0 -101
- package/apps/agents-server/src/utils/isUserAdmin.ts +0 -31
- package/apps/agents-server/src/utils/messages/sendMessage.ts +0 -91
- package/apps/agents-server/src/utils/messagesAdmin.ts +0 -72
- package/apps/agents-server/src/utils/normalization/filenameToPrompt.test.ts +0 -36
- package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +0 -25
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +0 -100
- package/apps/agents-server/src/utils/session.ts +0 -50
- package/apps/agents-server/src/utils/validateApiKey.ts +0 -124
- package/apps/agents-server/src/utils/validators/validateMimeType.ts +0 -24
- package/apps/agents-server/tailwind.config.ts +0 -26
- package/apps/agents-server/tsconfig.json +0 -29
- package/apps/agents-server/vercel.json +0 -7
- package/esm/typings/servers.d.ts +0 -50
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
|
-
import { validateApiKey } from '@/src/utils/validateApiKey';
|
|
3
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* GET /agents/[agentName]/api/openai/v1/models
|
|
7
|
-
*
|
|
8
|
-
* Lists available models for the OpenAI-compatible API.
|
|
9
|
-
* This endpoint is required for OpenAI-compatible clients (like Jan, LM Studio, etc.)
|
|
10
|
-
* to discover available models.
|
|
11
|
-
*/
|
|
12
|
-
export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
13
|
-
const { agentName } = await params;
|
|
14
|
-
|
|
15
|
-
// Validate API key explicitly (in addition to middleware)
|
|
16
|
-
const apiKeyValidation = await validateApiKey(request);
|
|
17
|
-
if (!apiKeyValidation.isValid) {
|
|
18
|
-
return NextResponse.json(
|
|
19
|
-
{
|
|
20
|
-
error: {
|
|
21
|
-
message: apiKeyValidation.error || 'Invalid API key',
|
|
22
|
-
type: 'authentication_error',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
{ status: 401 },
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const collection = await $provideAgentCollectionForServer();
|
|
31
|
-
|
|
32
|
-
let agentSource;
|
|
33
|
-
try {
|
|
34
|
-
agentSource = await collection.getAgentSource(agentName);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
return NextResponse.json(
|
|
37
|
-
{ error: { message: `Agent '${agentName}' not found.`, type: 'invalid_request_error' } },
|
|
38
|
-
{ status: 404 },
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!agentSource) {
|
|
43
|
-
return NextResponse.json(
|
|
44
|
-
{ error: { message: `Agent '${agentName}' not found.`, type: 'invalid_request_error' } },
|
|
45
|
-
{ status: 404 },
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Return the agent as a single model in OpenAI format
|
|
50
|
-
// The model ID is the agent name, which clients will use when making chat completion requests
|
|
51
|
-
const models = [
|
|
52
|
-
{
|
|
53
|
-
id: agentName,
|
|
54
|
-
object: 'model',
|
|
55
|
-
created: Math.floor(Date.now() / 1000),
|
|
56
|
-
owned_by: 'promptbook',
|
|
57
|
-
permission: [
|
|
58
|
-
{
|
|
59
|
-
id: `modelperm-${agentName}`,
|
|
60
|
-
object: 'model_permission',
|
|
61
|
-
created: Math.floor(Date.now() / 1000),
|
|
62
|
-
allow_create_engine: false,
|
|
63
|
-
allow_sampling: true,
|
|
64
|
-
allow_logprobs: false,
|
|
65
|
-
allow_search_indices: false,
|
|
66
|
-
allow_view: true,
|
|
67
|
-
allow_fine_tuning: false,
|
|
68
|
-
organization: '*',
|
|
69
|
-
group: null,
|
|
70
|
-
is_blocking: false,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
root: agentName,
|
|
74
|
-
parent: null,
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
return NextResponse.json({
|
|
79
|
-
object: 'list',
|
|
80
|
-
data: models,
|
|
81
|
-
});
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error in models listing handler:', error);
|
|
84
|
-
return NextResponse.json(
|
|
85
|
-
{ error: { message: (error as Error).message || 'Internal Server Error', type: 'server_error' } },
|
|
86
|
-
{ status: 500 },
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* TODO: [🧠] Consider listing all available agents as models when agentName is a wildcard or special value
|
|
93
|
-
*/
|
package/apps/agents-server/src/app/agents/[agentName]/api/openrouter/chat/completions/route.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { handleChatCompletion } from '@/src/utils/handleChatCompletion';
|
|
2
|
-
import { NextRequest } from 'next/server';
|
|
3
|
-
|
|
4
|
-
export async function POST(
|
|
5
|
-
request: NextRequest,
|
|
6
|
-
{ params }: { params: Promise<{ agentName: string }> },
|
|
7
|
-
) {
|
|
8
|
-
const { agentName } = await params;
|
|
9
|
-
return handleChatCompletion(request, { agentName }, 'OpenRouter API Chat Completion');
|
|
10
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { getMetadata } from '@/src/database/getMetadata';
|
|
2
|
-
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
3
|
-
import { computeAgentHash, parseAgentSource } from '@promptbook-local/core';
|
|
4
|
-
import { serializeError } from '@promptbook-local/utils';
|
|
5
|
-
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
6
|
-
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
7
|
-
|
|
8
|
-
export async function OPTIONS(request: Request) {
|
|
9
|
-
keepUnused(request);
|
|
10
|
-
return new Response(null, {
|
|
11
|
-
status: 200,
|
|
12
|
-
headers: {
|
|
13
|
-
'Access-Control-Allow-Origin': '*',
|
|
14
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
15
|
-
'Access-Control-Allow-Headers': 'Content-Type',
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function GET(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
21
|
-
keepUnused(request /* <- Note: We dont need `request` parameter */);
|
|
22
|
-
let { agentName } = await params;
|
|
23
|
-
agentName = decodeURIComponent(agentName);
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const collection = await $provideAgentCollectionForServer();
|
|
27
|
-
const agentSource = await collection.getAgentSource(agentName);
|
|
28
|
-
const agentProfile = parseAgentSource(agentSource);
|
|
29
|
-
const agentHash = computeAgentHash(agentSource);
|
|
30
|
-
const isVoiceCallingEnabled = (await getMetadata('IS_EXPERIMENTAL_VOICE_CALLING_ENABLED')) === 'true';
|
|
31
|
-
|
|
32
|
-
if (!agentProfile.meta.image) {
|
|
33
|
-
agentProfile.meta.image = `/agents/${encodeURIComponent(agentName)}/images/default-avatar.png`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return new Response(
|
|
37
|
-
JSON.stringify(
|
|
38
|
-
{
|
|
39
|
-
...agentProfile,
|
|
40
|
-
agentHash,
|
|
41
|
-
parameters: [], // <- TODO: [😰] Implement parameters
|
|
42
|
-
isVoiceCallingEnabled, // [✨✷] Add voice calling status
|
|
43
|
-
},
|
|
44
|
-
// <- TODO: [🐱🚀] Rename `serializeError` to `errorToJson`
|
|
45
|
-
null,
|
|
46
|
-
4,
|
|
47
|
-
// <- TODO: [🐱🚀] Allow to configure pretty print for agent server
|
|
48
|
-
),
|
|
49
|
-
{
|
|
50
|
-
status: 200,
|
|
51
|
-
headers: {
|
|
52
|
-
'Content-Type': 'application/json',
|
|
53
|
-
'Access-Control-Allow-Origin': '*', // <- Note: Allow embedding on other websites
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
assertsError(error);
|
|
59
|
-
|
|
60
|
-
console.error(error);
|
|
61
|
-
|
|
62
|
-
return new Response(
|
|
63
|
-
JSON.stringify(
|
|
64
|
-
serializeError(error),
|
|
65
|
-
// <- TODO: [🐱🚀] Rename `serializeError` to `errorToJson`
|
|
66
|
-
null,
|
|
67
|
-
4,
|
|
68
|
-
// <- TODO: [🐱🚀] Allow to configure pretty print for agent server
|
|
69
|
-
),
|
|
70
|
-
{
|
|
71
|
-
status: 400, // <- TODO: [🐱🚀] Make `errorToHttpStatusCode`
|
|
72
|
-
headers: { 'Content-Type': 'application/json' },
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* TODO: [🍞] DRY - Make some common utility for API on one agent
|
|
80
|
-
*/
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { $getTableName } from '@/src/database/$getTableName';
|
|
2
|
-
import { $provideSupabaseForServer } from '@/src/database/$provideSupabaseForServer';
|
|
3
|
-
import { getMetadata } from '@/src/database/getMetadata';
|
|
4
|
-
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
5
|
-
import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$provideOpenAiAssistantExecutionToolsForServer';
|
|
6
|
-
import { Agent, computeAgentHash, PROMPTBOOK_ENGINE_VERSION } from '@promptbook-local/core';
|
|
7
|
-
import { computeHash, serializeError } from '@promptbook-local/utils';
|
|
8
|
-
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
9
|
-
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
10
|
-
|
|
11
|
-
export const maxDuration = 300;
|
|
12
|
-
|
|
13
|
-
export async function OPTIONS(request: Request) {
|
|
14
|
-
keepUnused(request);
|
|
15
|
-
|
|
16
|
-
return new Response(null, {
|
|
17
|
-
status: 200,
|
|
18
|
-
headers: {
|
|
19
|
-
'Access-Control-Allow-Origin': '*',
|
|
20
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
21
|
-
'Access-Control-Allow-Headers': 'Content-Type',
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function POST(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
27
|
-
// Check if voice calling is enabled
|
|
28
|
-
const isVoiceCallingEnabled = (await getMetadata('IS_EXPERIMENTAL_VOICE_CALLING_ENABLED')) === 'true';
|
|
29
|
-
if (!isVoiceCallingEnabled) {
|
|
30
|
-
return new Response(JSON.stringify({ error: 'Voice calling is disabled on this server' }), {
|
|
31
|
-
status: 403,
|
|
32
|
-
headers: { 'Content-Type': 'application/json' },
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let { agentName } = await params;
|
|
37
|
-
agentName = decodeURIComponent(agentName);
|
|
38
|
-
|
|
39
|
-
// Note: Parse FormData for audio file
|
|
40
|
-
const formData = await request.formData();
|
|
41
|
-
const audioFile = formData.get('audio') as File | null;
|
|
42
|
-
const threadString = formData.get('thread') as string | null;
|
|
43
|
-
const thread = threadString ? JSON.parse(threadString) : undefined;
|
|
44
|
-
// const messageContext = formData.get('message') as string | null; // Optional text context or previous message?
|
|
45
|
-
|
|
46
|
-
if (!audioFile) {
|
|
47
|
-
return new Response(JSON.stringify({ error: 'No audio file provided' }), {
|
|
48
|
-
status: 400,
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const collection = await $provideAgentCollectionForServer();
|
|
55
|
-
const openAiAssistantExecutionTools = await $provideOpenAiAssistantExecutionToolsForServer();
|
|
56
|
-
const agentSource = await collection.getAgentSource(agentName);
|
|
57
|
-
const agent = new Agent({
|
|
58
|
-
isVerbose: true,
|
|
59
|
-
executionTools: {
|
|
60
|
-
llm: openAiAssistantExecutionTools,
|
|
61
|
-
},
|
|
62
|
-
agentSource,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// 1. Transcribe Audio (STT)
|
|
66
|
-
const client = await openAiAssistantExecutionTools.getClient();
|
|
67
|
-
const transcription = await client.audio.transcriptions.create({
|
|
68
|
-
file: audioFile,
|
|
69
|
-
model: 'whisper-1',
|
|
70
|
-
});
|
|
71
|
-
const message = transcription.text;
|
|
72
|
-
|
|
73
|
-
// --- Common Chat Logic Start (TODO: Extract) ---
|
|
74
|
-
|
|
75
|
-
const agentHash = computeAgentHash(agentSource);
|
|
76
|
-
const userAgent = request.headers.get('user-agent');
|
|
77
|
-
const ip =
|
|
78
|
-
request.headers.get('x-forwarded-for') ||
|
|
79
|
-
request.headers.get('x-real-ip') ||
|
|
80
|
-
request.headers.get('x-client-ip');
|
|
81
|
-
const language = request.headers.get('accept-language');
|
|
82
|
-
const platform = userAgent ? userAgent.match(/\(([^)]+)\)/)?.[1] : undefined;
|
|
83
|
-
|
|
84
|
-
// Identify and Record User Message
|
|
85
|
-
const userMessageContent = {
|
|
86
|
-
role: 'USER',
|
|
87
|
-
content: message,
|
|
88
|
-
isVoiceCall: true, // Mark as voice call
|
|
89
|
-
};
|
|
90
|
-
const supabase = $provideSupabaseForServer();
|
|
91
|
-
await supabase.from(await $getTableName('ChatHistory')).insert({
|
|
92
|
-
createdAt: new Date().toISOString(),
|
|
93
|
-
messageHash: computeHash(userMessageContent),
|
|
94
|
-
previousMessageHash: null,
|
|
95
|
-
agentName,
|
|
96
|
-
agentHash,
|
|
97
|
-
message: userMessageContent,
|
|
98
|
-
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
99
|
-
url: request.url,
|
|
100
|
-
ip,
|
|
101
|
-
userAgent,
|
|
102
|
-
language,
|
|
103
|
-
platform,
|
|
104
|
-
source: 'AGENT_PAGE_CHAT',
|
|
105
|
-
apiKey: null,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Call Agent
|
|
109
|
-
const response = await agent.callChatModel({
|
|
110
|
-
title: `Voice Chat with agent ${agentName}`,
|
|
111
|
-
parameters: {},
|
|
112
|
-
modelRequirements: {
|
|
113
|
-
modelVariant: 'CHAT',
|
|
114
|
-
},
|
|
115
|
-
content: message,
|
|
116
|
-
thread,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const agentMessageContent = {
|
|
120
|
-
role: 'MODEL',
|
|
121
|
-
content: response.content,
|
|
122
|
-
isVoiceCall: true,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// Record Agent Message
|
|
126
|
-
await supabase.from(await $getTableName('ChatHistory')).insert({
|
|
127
|
-
createdAt: new Date().toISOString(),
|
|
128
|
-
messageHash: computeHash(agentMessageContent),
|
|
129
|
-
previousMessageHash: computeHash(userMessageContent),
|
|
130
|
-
agentName,
|
|
131
|
-
agentHash,
|
|
132
|
-
message: agentMessageContent,
|
|
133
|
-
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
134
|
-
url: request.url,
|
|
135
|
-
ip,
|
|
136
|
-
userAgent,
|
|
137
|
-
language,
|
|
138
|
-
platform,
|
|
139
|
-
source: 'AGENT_PAGE_CHAT',
|
|
140
|
-
apiKey: null,
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Learning
|
|
144
|
-
const newAgentSource = agent.agentSource.value;
|
|
145
|
-
if (newAgentSource !== agentSource) {
|
|
146
|
-
await collection.updateAgentSource(agentName, newAgentSource);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// --- Common Chat Logic End ---
|
|
150
|
-
|
|
151
|
-
// 2. Synthesize Audio (TTS)
|
|
152
|
-
const mp3 = await client.audio.speech.create({
|
|
153
|
-
model: 'tts-1',
|
|
154
|
-
voice: 'alloy',
|
|
155
|
-
input: response.content,
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
const buffer = Buffer.from(await mp3.arrayBuffer());
|
|
159
|
-
const base64Audio = buffer.toString('base64');
|
|
160
|
-
|
|
161
|
-
return new Response(
|
|
162
|
-
JSON.stringify({
|
|
163
|
-
userMessage: message,
|
|
164
|
-
agentMessage: response.content,
|
|
165
|
-
audio: base64Audio,
|
|
166
|
-
audioFormat: 'mp3',
|
|
167
|
-
}),
|
|
168
|
-
{
|
|
169
|
-
status: 200,
|
|
170
|
-
headers: {
|
|
171
|
-
'Content-Type': 'application/json',
|
|
172
|
-
'Access-Control-Allow-Origin': '*',
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
} catch (error) {
|
|
177
|
-
assertsError(error);
|
|
178
|
-
console.error(error);
|
|
179
|
-
return new Response(JSON.stringify(serializeError(error), null, 4), {
|
|
180
|
-
status: 400,
|
|
181
|
-
headers: { 'Content-Type': 'application/json' },
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { BookEditor } from '@promptbook-local/components';
|
|
4
|
-
import { string_book } from '@promptbook-local/types';
|
|
5
|
-
import { upload } from '@vercel/blob/client';
|
|
6
|
-
import { useEffect, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
type BookEditorWrapperProps = {
|
|
9
|
-
agentName: string;
|
|
10
|
-
initialAgentSource: string_book;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// TODO: [🐱🚀] Rename to BookEditorSavingWrapper
|
|
14
|
-
|
|
15
|
-
export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorWrapperProps) {
|
|
16
|
-
const [agentSource, setAgentSource] = useState<string_book>(initialAgentSource);
|
|
17
|
-
const [saveStatus, setSaveStatus] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle');
|
|
18
|
-
|
|
19
|
-
// Debounce timer ref so we can clear previous pending save
|
|
20
|
-
const debounceTimerRef = useRef<number | null>(null);
|
|
21
|
-
// Configurable debounce delay (ms) - tweak if needed
|
|
22
|
-
const DEBOUNCE_DELAY = 1000;
|
|
23
|
-
|
|
24
|
-
const performSave = async (sourceToSave: string_book) => {
|
|
25
|
-
setSaveStatus('saving');
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetch(`/agents/${encodeURIComponent(agentName)}/api/book`, {
|
|
28
|
-
method: 'PUT',
|
|
29
|
-
headers: { 'Content-Type': 'text/plain' },
|
|
30
|
-
body: sourceToSave,
|
|
31
|
-
});
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
throw new Error(`Failed to save: ${response.statusText}`);
|
|
34
|
-
}
|
|
35
|
-
setSaveStatus('saved');
|
|
36
|
-
setTimeout(() => setSaveStatus('idle'), 2000); // Reset status after 2 seconds
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error('Error saving agent source:', error);
|
|
39
|
-
setSaveStatus('error');
|
|
40
|
-
setTimeout(() => setSaveStatus('idle'), 3000);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const scheduleSave = (nextSource: string_book) => {
|
|
45
|
-
// Clear existing pending save
|
|
46
|
-
if (debounceTimerRef.current) {
|
|
47
|
-
clearTimeout(debounceTimerRef.current);
|
|
48
|
-
}
|
|
49
|
-
// We stay 'idle' while typing; could add a 'pending' status in future if desired
|
|
50
|
-
// Schedule new save
|
|
51
|
-
debounceTimerRef.current = window.setTimeout(() => {
|
|
52
|
-
performSave(nextSource);
|
|
53
|
-
}, DEBOUNCE_DELAY);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const handleChange = (newSource: string_book) => {
|
|
57
|
-
setAgentSource(newSource);
|
|
58
|
-
scheduleSave(newSource);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Cleanup on unmount to avoid lingering timeouts
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
return () => {
|
|
64
|
-
if (debounceTimerRef.current) {
|
|
65
|
-
clearTimeout(debounceTimerRef.current);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<div className="w-full h-full">
|
|
72
|
-
{saveStatus !== 'idle' && (
|
|
73
|
-
<div
|
|
74
|
-
role="status"
|
|
75
|
-
aria-live="polite"
|
|
76
|
-
className={`fixed top-5 right-28 z-50 px-4 py-2 text-sm rounded shadow-md ${
|
|
77
|
-
saveStatus === 'saving'
|
|
78
|
-
? 'bg-blue-100 text-blue-800'
|
|
79
|
-
: saveStatus === 'saved'
|
|
80
|
-
? 'bg-green-100 text-green-800'
|
|
81
|
-
: 'bg-red-100 text-red-800'
|
|
82
|
-
}`}
|
|
83
|
-
>
|
|
84
|
-
{saveStatus === 'saving' && '💾 Saving...'}
|
|
85
|
-
{saveStatus === 'saved' && '✅ Saved'}
|
|
86
|
-
{saveStatus === 'error' && '❌ Failed to save'}
|
|
87
|
-
</div>
|
|
88
|
-
)}
|
|
89
|
-
|
|
90
|
-
<BookEditor
|
|
91
|
-
className="w-full h-full"
|
|
92
|
-
isBorderRadiusDisabled
|
|
93
|
-
height={null}
|
|
94
|
-
value={agentSource}
|
|
95
|
-
onChange={handleChange}
|
|
96
|
-
onFileUpload={async (file) => {
|
|
97
|
-
console.info('🔼 Uploading file', file);
|
|
98
|
-
|
|
99
|
-
// Build the full path including prefix and user/files directory
|
|
100
|
-
const pathPrefix = process.env.NEXT_PUBLIC_CDN_PATH_PREFIX || '';
|
|
101
|
-
const uploadPath = pathPrefix ? `${pathPrefix}/user/files/${file.name}` : `user/files/${file.name}`;
|
|
102
|
-
|
|
103
|
-
// Upload directly to Vercel Blob using client upload
|
|
104
|
-
const blob = await upload(uploadPath, file, {
|
|
105
|
-
access: 'public',
|
|
106
|
-
handleUploadUrl: '/api/upload',
|
|
107
|
-
clientPayload: JSON.stringify({
|
|
108
|
-
purpose: 'KNOWLEDGE',
|
|
109
|
-
contentType: file.type,
|
|
110
|
-
}),
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const fileUrl = blob.url;
|
|
114
|
-
|
|
115
|
-
const LONG_URL = `${process.env.NEXT_PUBLIC_CDN_PUBLIC_URL!}/${process.env
|
|
116
|
-
.NEXT_PUBLIC_CDN_PATH_PREFIX!}/user/files/`;
|
|
117
|
-
const SHORT_URL = `https://ptbk.io/k/`;
|
|
118
|
-
// <- TODO: [🌍] Unite this logic in one place
|
|
119
|
-
|
|
120
|
-
const shortFileUrl = fileUrl.split(LONG_URL).join(SHORT_URL);
|
|
121
|
-
|
|
122
|
-
console.log(`🔼 File uploaded:`, {
|
|
123
|
-
LONG_URL,
|
|
124
|
-
SHORT_URL,
|
|
125
|
-
fileUrl,
|
|
126
|
-
shortFileUrl,
|
|
127
|
-
file,
|
|
128
|
-
blob,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return shortFileUrl;
|
|
132
|
-
}}
|
|
133
|
-
/>
|
|
134
|
-
</div>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* TODO: Prompt: Use `import { debounce } from '@promptbook-local/utils';` instead of custom debounce implementation
|
|
140
|
-
* TODO: [🚗] Transfer the saving logic to `<BookEditor/>` be aware of CRDT / yjs approach to be implementable in future
|
|
141
|
-
* TODO: [🐱🚀] Add error handling and retry logic
|
|
142
|
-
* TODO: [🐱🚀] Show save status indicator
|
|
143
|
-
*/
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { ForbiddenPage } from '@/src/components/ForbiddenPage/ForbiddenPage';
|
|
4
|
-
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
5
|
-
import { isUserAdmin } from '@/src/utils/isUserAdmin';
|
|
6
|
-
import { headers } from 'next/headers';
|
|
7
|
-
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
8
|
-
import { isAgentDeleted } from '../_utils';
|
|
9
|
-
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
10
|
-
import { BookEditorWrapper } from './BookEditorWrapper';
|
|
11
|
-
import { DeletedAgentBanner } from '../../../../components/DeletedAgentBanner';
|
|
12
|
-
|
|
13
|
-
export const generateMetadata = generateAgentMetadata;
|
|
14
|
-
|
|
15
|
-
export default async function AgentBookPage({ params }: { params: Promise<{ agentName: string }> }) {
|
|
16
|
-
$sideEffect(headers());
|
|
17
|
-
|
|
18
|
-
let { agentName } = await params;
|
|
19
|
-
agentName = decodeURIComponent(agentName);
|
|
20
|
-
|
|
21
|
-
const isDeleted = await isAgentDeleted(agentName);
|
|
22
|
-
|
|
23
|
-
if (isDeleted) {
|
|
24
|
-
return (
|
|
25
|
-
<div className="w-screen h-[calc(100vh-60px)] flex items-center justify-center p-8">
|
|
26
|
-
<DeletedAgentBanner />
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!(await isUserAdmin())) {
|
|
32
|
-
/* <- TODO: [👹] Here should be user permissions */
|
|
33
|
-
return <ForbiddenPage />;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const collection = await $provideAgentCollectionForServer();
|
|
37
|
-
const agentSource = await collection.getAgentSource(decodeURIComponent(agentName));
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div className={`w-screen h-[calc(100vh-60px)]`}>
|
|
41
|
-
<BookEditorWrapper agentName={agentName} initialAgentSource={agentSource} />
|
|
42
|
-
</div>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* TODO: [🚗] Components and pages here should be just tiny UI wrapper around proper agent logic and components
|
|
48
|
-
*/
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { ResizablePanelsAuto } from '@common/components/ResizablePanelsAuto/ResizablePanelsAuto';
|
|
4
|
-
import { string_agent_url, string_book } from '@promptbook-local/types';
|
|
5
|
-
import { Book, MessageSquare } from 'lucide-react';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
7
|
-
import { AgentChatWrapper } from '../AgentChatWrapper';
|
|
8
|
-
import { BookEditorWrapper } from '../book/BookEditorWrapper';
|
|
9
|
-
|
|
10
|
-
type AgentBookAndChatProps = {
|
|
11
|
-
agentName: string;
|
|
12
|
-
initialAgentSource: string_book;
|
|
13
|
-
agentUrl: string_agent_url;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function AgentBookAndChat(props: AgentBookAndChatProps) {
|
|
17
|
-
const { agentName, initialAgentSource, agentUrl } = props;
|
|
18
|
-
const [isMobile, setIsMobile] = useState(false);
|
|
19
|
-
const [activeTab, setActiveTab] = useState<'book' | 'chat'>('chat');
|
|
20
|
-
const [isMounted, setIsMounted] = useState(false);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
setIsMounted(true);
|
|
24
|
-
const checkMobile = () => setIsMobile(window.innerWidth < 1024);
|
|
25
|
-
checkMobile();
|
|
26
|
-
window.addEventListener('resize', checkMobile);
|
|
27
|
-
return () => window.removeEventListener('resize', checkMobile);
|
|
28
|
-
}, []);
|
|
29
|
-
|
|
30
|
-
if (!isMounted) {
|
|
31
|
-
return <div className="w-full h-full bg-white" />;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (isMobile) {
|
|
35
|
-
return (
|
|
36
|
-
<div className="flex flex-col h-full w-full bg-white">
|
|
37
|
-
<div className="flex-grow overflow-hidden relative">
|
|
38
|
-
<div className={`w-full h-full ${activeTab === 'book' ? 'block' : 'hidden'}`}>
|
|
39
|
-
<BookEditorWrapper agentName={agentName} initialAgentSource={initialAgentSource} />
|
|
40
|
-
</div>
|
|
41
|
-
<div className={`w-full h-full ${activeTab === 'chat' ? 'block' : 'hidden'}`}>
|
|
42
|
-
<AgentChatWrapper agentUrl={agentUrl} />
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
<div className="flex-shrink-0 h-16 bg-white border-t border-gray-200 flex shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.05)] z-10">
|
|
46
|
-
<button
|
|
47
|
-
onClick={() => setActiveTab('book')}
|
|
48
|
-
className={`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${
|
|
49
|
-
activeTab === 'book' ? 'text-blue-600 bg-blue-50/50' : 'text-gray-500 hover:bg-gray-50'
|
|
50
|
-
}`}
|
|
51
|
-
>
|
|
52
|
-
<Book className="w-5 h-5" />
|
|
53
|
-
<span className="text-xs font-medium">Info</span>
|
|
54
|
-
</button>
|
|
55
|
-
<button
|
|
56
|
-
onClick={() => setActiveTab('chat')}
|
|
57
|
-
className={`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${
|
|
58
|
-
activeTab === 'chat' ? 'text-blue-600 bg-blue-50/50' : 'text-gray-500 hover:bg-gray-50'
|
|
59
|
-
}`}
|
|
60
|
-
>
|
|
61
|
-
<MessageSquare className="w-5 h-5" />
|
|
62
|
-
<span className="text-xs font-medium">Chat</span>
|
|
63
|
-
</button>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<ResizablePanelsAuto name={`agent-book-and-chat-${agentName}`} className="w-full h-full">
|
|
71
|
-
<BookEditorWrapper agentName={agentName} initialAgentSource={initialAgentSource} />
|
|
72
|
-
<AgentChatWrapper agentUrl={agentUrl} />
|
|
73
|
-
</ResizablePanelsAuto>
|
|
74
|
-
);
|
|
75
|
-
}
|