@promptbook/cli 0.104.0-1 → 0.104.0-11
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/apps/agents-server/config.ts +1 -3
- package/apps/agents-server/next.config.ts +2 -2
- package/apps/agents-server/package.json +7 -3
- package/apps/agents-server/public/fonts/OpenMoji-color-cbdt.woff2 +0 -0
- package/apps/agents-server/public/swagger.json +115 -0
- package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +54 -0
- package/apps/agents-server/scripts/generate-reserved-paths/tsconfig.json +19 -0
- package/apps/agents-server/src/app/AddAgentButton.tsx +47 -21
- package/apps/agents-server/src/app/actions.ts +22 -5
- package/apps/agents-server/src/app/admin/browser-test/BrowserTestClient.tsx +211 -0
- package/apps/agents-server/src/app/admin/browser-test/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +221 -274
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +94 -137
- package/apps/agents-server/src/app/admin/files/FilesGalleryClient.tsx +263 -0
- package/apps/agents-server/src/app/admin/files/actions.ts +61 -0
- package/apps/agents-server/src/app/admin/files/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/image-generator-test/ImageGeneratorTestClient.tsx +169 -0
- package/apps/agents-server/src/app/admin/image-generator-test/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/images/ImagesGalleryClient.tsx +256 -0
- package/apps/agents-server/src/app/admin/images/actions.ts +60 -0
- package/apps/agents-server/src/app/admin/images/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +294 -0
- package/apps/agents-server/src/app/admin/messages/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/messages/send-email/SendEmailClient.tsx +104 -0
- package/apps/agents-server/src/app/admin/messages/send-email/actions.ts +35 -0
- package/apps/agents-server/src/app/admin/messages/send-email/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +23 -19
- package/apps/agents-server/src/app/admin/search-engine-test/SearchEngineTestClient.tsx +109 -0
- package/apps/agents-server/src/app/admin/search-engine-test/actions.ts +17 -0
- package/apps/agents-server/src/app/admin/search-engine-test/page.tsx +13 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +15 -1
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +51 -9
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +47 -4
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +53 -11
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +23 -3
- package/apps/agents-server/src/app/agents/[agentName]/agentLinks.tsx +8 -8
- package/apps/agents-server/src/app/agents/[agentName]/api/agents/route.ts +17 -26
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +4 -2
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +20 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +6 -11
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +5 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +5 -2
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +20 -16
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +15 -2
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +15 -2
- package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +12 -0
- package/apps/agents-server/src/app/agents/[agentName]/code/api/route.ts +68 -0
- package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +223 -0
- package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +5 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/actions.ts +2 -2
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +10 -3
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/getAgentDefaultAvatarPrompt.ts +31 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/default-avatar.png/route.ts +194 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/icon-256.png/route.tsx +14 -2
- package/apps/agents-server/src/app/agents/[agentName]/images/page.tsx +200 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-fullhd.png/route.tsx +4 -3
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-phone.png/route.tsx +4 -3
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +10 -3
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +11 -4
- package/apps/agents-server/src/app/agents/[agentName]/opengraph-image.tsx +11 -2
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +18 -10
- package/apps/agents-server/src/app/agents/[agentName]/system-message/page.tsx +100 -0
- package/apps/agents-server/src/app/api/admin-email/route.ts +12 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +13 -14
- package/apps/agents-server/src/app/api/agents/[agentName]/restore/route.ts +20 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +43 -1
- package/apps/agents-server/src/app/api/agents/route.ts +28 -3
- package/apps/agents-server/src/app/api/api-tokens/route.ts +6 -7
- package/apps/agents-server/src/app/api/browser-test/act/route.ts +141 -0
- package/apps/agents-server/src/app/api/browser-test/screenshot/route.ts +30 -0
- package/apps/agents-server/src/app/api/browser-test/scroll-facebook/route.ts +62 -0
- package/apps/agents-server/src/app/api/docs/book.md/route.ts +61 -0
- package/apps/agents-server/src/app/api/emails/incoming/sendgrid/route.ts +48 -0
- package/apps/agents-server/src/app/api/federated-agents/route.ts +12 -0
- package/apps/agents-server/src/app/api/images/[filename]/route.ts +128 -0
- package/apps/agents-server/src/app/api/messages/route.ts +102 -0
- package/apps/agents-server/src/app/api/metadata/route.ts +5 -6
- package/apps/agents-server/src/app/api/upload/route.ts +128 -45
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +2 -3
- package/apps/agents-server/src/app/docs/page.tsx +12 -12
- package/apps/agents-server/src/app/globals.css +140 -33
- package/apps/agents-server/src/app/humans.txt/route.ts +1 -1
- package/apps/agents-server/src/app/layout.tsx +27 -22
- package/apps/agents-server/src/app/page.tsx +54 -6
- package/apps/agents-server/src/app/recycle-bin/actions.ts +20 -14
- package/apps/agents-server/src/app/recycle-bin/page.tsx +27 -41
- package/apps/agents-server/src/app/robots.txt/route.ts +1 -1
- package/apps/agents-server/src/app/security.txt/route.ts +1 -1
- package/apps/agents-server/src/app/sitemap.xml/route.ts +9 -7
- package/apps/agents-server/src/app/swagger/page.tsx +14 -0
- package/apps/agents-server/src/components/AgentProfile/AgentCapabilityChips.tsx +38 -0
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +44 -116
- package/apps/agents-server/src/components/AgentProfile/AgentProfileImage.tsx +92 -0
- package/apps/agents-server/src/components/AgentProfile/QrCodeModal.tsx +0 -1
- package/apps/agents-server/src/components/AgentProfile/useAgentBackground.ts +97 -0
- package/apps/agents-server/src/components/Auth/AuthControls.tsx +5 -4
- package/apps/agents-server/src/components/DeletedAgentBanner.tsx +26 -0
- package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +38 -0
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +11 -9
- package/apps/agents-server/src/components/Footer/Footer.tsx +5 -5
- package/apps/agents-server/src/components/ForgottenPasswordDialog/ForgottenPasswordDialog.tsx +61 -0
- package/apps/agents-server/src/components/Header/Header.tsx +130 -40
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +150 -23
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +93 -15
- package/apps/agents-server/src/components/Homepage/DeletedAgentsList.tsx +66 -0
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSection.tsx +12 -3
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSectionClient.tsx +19 -10
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +3 -2
- package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +50 -1
- package/apps/agents-server/src/components/NewAgentDialog/NewAgentDialog.tsx +88 -0
- package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +7 -2
- package/apps/agents-server/src/components/OpenMojiIcon/OpenMojiIcon.tsx +16 -7
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -4
- package/apps/agents-server/src/components/RegisterUserDialog/RegisterUserDialog.tsx +61 -0
- package/apps/agents-server/src/components/VercelDeploymentCard/VercelDeploymentCard.tsx +2 -0
- package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +12 -10
- package/apps/agents-server/src/components/_utils/headlessParam.tsx +7 -3
- package/apps/agents-server/src/database/$getTableName.ts +1 -0
- package/apps/agents-server/src/database/$provideSupabaseForBrowser.ts +3 -3
- package/apps/agents-server/src/database/$provideSupabaseForServer.ts +1 -1
- package/apps/agents-server/src/database/$provideSupabaseForWorker.ts +3 -3
- package/apps/agents-server/src/database/metadataDefaults.ts +19 -1
- package/apps/agents-server/src/database/migrate.ts +34 -1
- package/apps/agents-server/src/database/migrations/2025-11-0001-initial-schema.sql +1 -3
- package/apps/agents-server/src/database/migrations/2025-11-0002-metadata-table.sql +1 -3
- package/apps/agents-server/src/database/migrations/2025-12-0240-agent-public-id.sql +3 -0
- package/apps/agents-server/src/database/migrations/2025-12-0360-agent-deleted-at.sql +1 -0
- package/apps/agents-server/src/database/migrations/2025-12-0370-image-table.sql +19 -0
- package/apps/agents-server/src/database/migrations/2025-12-0380-agent-visibility.sql +1 -0
- package/apps/agents-server/src/database/migrations/2025-12-0390-upload-tracking.sql +20 -0
- package/apps/agents-server/src/database/migrations/2025-12-0401-file-upload-status.sql +13 -0
- package/apps/agents-server/src/database/migrations/2025-12-0402-message-table.sql +42 -0
- package/apps/agents-server/src/database/migrations/2025-12-0403-generation-lock-table.sql +15 -0
- package/apps/agents-server/src/database/migrations/2025-12-0640-openai-assistant-cache.sql +12 -0
- package/apps/agents-server/src/database/migrations/2025-12-0820-agent-history-permanent-id.sql +29 -0
- package/apps/agents-server/src/database/migrations/2025-12-0830-image-purpose.sql +5 -0
- package/apps/agents-server/src/database/migrations/2025-12-0890-file-agent-id.sql +5 -0
- package/apps/agents-server/src/database/schema.ts +244 -4
- package/apps/agents-server/src/generated/reservedPaths.ts +32 -0
- package/apps/agents-server/src/message-providers/email/_common/Email.ts +73 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/TODO.txt +1 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +108 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.ts +62 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +117 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.ts +19 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +119 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.ts +19 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +74 -0
- package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.ts +14 -0
- package/apps/agents-server/src/message-providers/email/sendgrid/SendgridMessageProvider.ts +44 -0
- package/apps/agents-server/src/message-providers/email/sendgrid/parseInboundSendgridEmail.ts +49 -0
- package/apps/agents-server/src/message-providers/email/zeptomail/ZeptomailMessageProvider.ts +51 -0
- package/apps/agents-server/src/message-providers/index.ts +13 -0
- package/apps/agents-server/src/message-providers/interfaces/MessageProvider.ts +11 -0
- package/apps/agents-server/src/middleware.ts +19 -23
- package/apps/agents-server/src/tools/$provideBrowserForServer.ts +32 -0
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +7 -2
- package/apps/agents-server/src/utils/auth.ts +117 -17
- package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +57 -0
- package/apps/agents-server/src/utils/cdn/classes/VercelBlobStorage.ts +4 -0
- package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +18 -0
- package/apps/agents-server/src/utils/content/extractBodyContentFromHtml.ts +19 -0
- package/apps/agents-server/src/utils/getUserIdFromRequest.ts +35 -0
- package/apps/agents-server/src/utils/handleChatCompletion.ts +65 -5
- package/apps/agents-server/src/utils/messages/sendMessage.ts +91 -0
- package/apps/agents-server/src/utils/messagesAdmin.ts +72 -0
- package/apps/agents-server/src/utils/normalization/filenameToPrompt.test.ts +36 -0
- package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +25 -0
- package/apps/agents-server/src/utils/validateApiKey.ts +7 -11
- package/esm/index.es.js +1534 -1330
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +8 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +16 -2
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +29 -1
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.d.ts +6 -6
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.closed.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +3 -3
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/CodeBlock/CodeBlock.d.ts +13 -0
- package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +9 -13
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +3 -3
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +1 -1
- package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
- package/esm/typings/src/book-components/icons/AboutIcon.d.ts +1 -1
- package/esm/typings/src/book-components/icons/AttachmentIcon.d.ts +1 -1
- package/esm/typings/src/book-components/icons/CameraIcon.d.ts +1 -1
- package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +1 -1
- package/esm/typings/src/book-components/icons/MenuIcon.d.ts +1 -1
- package/esm/typings/src/book-components/icons/SaveIcon.d.ts +1 -1
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +22 -12
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +27 -15
- package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
- package/esm/typings/src/commitments/index.d.ts +2 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +6 -2
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +6 -1
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/remote-server/ui/ServerApp.d.ts +1 -1
- 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/Message.d.ts +49 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +38 -14
- package/esm/typings/src/types/typeAliases.d.ts +23 -1
- package/esm/typings/src/utils/color/utils/colorToDataUrl.d.ts +2 -1
- package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +3 -2
- package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +1542 -1338
- package/umd/index.umd.js.map +1 -1
- package/apps/agents-server/package-lock.json +0 -27
- package/apps/agents-server/public/fonts/download-font.js +0 -22
- package/apps/agents-server/src/components/PrintButton/PrintButton.tsx +0 -18
- package/esm/typings/src/book-2.0/utils/generateGravatarUrl.d.ts +0 -10
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { BingSearchEngine } from '../../../../../../src/search-engines/bing/BingSearchEngine';
|
|
4
|
+
import { DummySearchEngine } from '../../../../../../src/search-engines/dummy/DummySearchEngine';
|
|
5
|
+
import { SearchResult } from '../../../../../../src/search-engines/SearchResult';
|
|
6
|
+
|
|
7
|
+
export async function search(query: string, provider: string): Promise<SearchResult[]> {
|
|
8
|
+
if (provider === 'dummy') {
|
|
9
|
+
const searchEngine = new DummySearchEngine();
|
|
10
|
+
return searchEngine.search(query);
|
|
11
|
+
} else if (provider === 'bing') {
|
|
12
|
+
const searchEngine = new BingSearchEngine();
|
|
13
|
+
await searchEngine.checkConfiguration();
|
|
14
|
+
return searchEngine.search(query);
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ForbiddenPage } from '../../../components/ForbiddenPage/ForbiddenPage';
|
|
2
|
+
import { isUserAdmin } from '../../../utils/isUserAdmin';
|
|
3
|
+
import { SearchEngineTestClient } from './SearchEngineTestClient';
|
|
4
|
+
|
|
5
|
+
export default async function SearchEngineTestPage() {
|
|
6
|
+
const isAdmin = await isUserAdmin();
|
|
7
|
+
|
|
8
|
+
if (!isAdmin) {
|
|
9
|
+
return <ForbiddenPage />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return <SearchEngineTestClient />;
|
|
13
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { usePromise } from '@common/hooks/usePromise';
|
|
4
4
|
import { AgentChat } from '@promptbook-local/components';
|
|
5
5
|
import { RemoteAgent } from '@promptbook-local/core';
|
|
6
|
-
import { useCallback, useMemo } from 'react';
|
|
6
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
7
7
|
import { string_agent_url } from '../../../../../../src/types/typeAliases';
|
|
8
8
|
|
|
9
9
|
type AgentChatWrapperProps = {
|
|
@@ -58,6 +58,20 @@ export function AgentChatWrapper(props: AgentChatWrapperProps) {
|
|
|
58
58
|
[agent, agentUrl],
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
+
// Remove the 'message' query parameter from URL after auto-executing a message
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (autoExecuteMessage && typeof window !== 'undefined') {
|
|
64
|
+
// Wait for the message to be processed, then remove the query parameter
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
const url = new URL(window.location.href);
|
|
67
|
+
url.searchParams.delete('message');
|
|
68
|
+
window.history.replaceState({}, '', url.toString());
|
|
69
|
+
}, 1000); // 1 second delay to ensure message processing is complete
|
|
70
|
+
|
|
71
|
+
return () => clearTimeout(timer);
|
|
72
|
+
}
|
|
73
|
+
}, [autoExecuteMessage]);
|
|
74
|
+
|
|
61
75
|
if (!agent) {
|
|
62
76
|
return <>{/* <- TODO: [🐱🚀] <PromptbookLoading /> */}</>;
|
|
63
77
|
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { TODO_any } from '@promptbook-local/types';
|
|
4
4
|
import {
|
|
5
|
+
CodeIcon,
|
|
5
6
|
CopyIcon,
|
|
6
7
|
CopyPlusIcon,
|
|
7
8
|
DownloadIcon,
|
|
9
|
+
FileTextIcon,
|
|
8
10
|
MailIcon,
|
|
9
11
|
MessageCircleQuestionIcon,
|
|
10
12
|
MessageSquareIcon,
|
|
@@ -13,10 +15,12 @@ import {
|
|
|
13
15
|
QrCodeIcon,
|
|
14
16
|
SmartphoneIcon,
|
|
15
17
|
SquareSplitHorizontalIcon,
|
|
18
|
+
TrashIcon,
|
|
16
19
|
} from 'lucide-react';
|
|
17
20
|
import { Barlow_Condensed } from 'next/font/google';
|
|
18
21
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
19
|
-
import { string_data_url, string_url_image } from '../../../../../../src/types/typeAliases';
|
|
22
|
+
import { string_agent_permanent_id, string_data_url, string_url_image } from '../../../../../../src/types/typeAliases';
|
|
23
|
+
import { deleteAgent } from '../../recycle-bin/actions';
|
|
20
24
|
import { getAgentLinks } from './agentLinks';
|
|
21
25
|
|
|
22
26
|
type BeforeInstallPromptEvent = Event & {
|
|
@@ -33,6 +37,7 @@ const barlowCondensed = Barlow_Condensed({
|
|
|
33
37
|
type AgentOptionsMenuProps = {
|
|
34
38
|
agentName: string;
|
|
35
39
|
derivedAgentName: string;
|
|
40
|
+
permanentId?: string_agent_permanent_id;
|
|
36
41
|
agentUrl: string;
|
|
37
42
|
agentEmail: string;
|
|
38
43
|
brandColorHex: string;
|
|
@@ -44,11 +49,10 @@ type AgentOptionsMenuProps = {
|
|
|
44
49
|
export function AgentOptionsMenu({
|
|
45
50
|
agentName,
|
|
46
51
|
derivedAgentName,
|
|
52
|
+
permanentId,
|
|
47
53
|
agentUrl,
|
|
48
54
|
agentEmail,
|
|
49
|
-
brandColorHex,
|
|
50
55
|
isAdmin = false,
|
|
51
|
-
backgroundImage,
|
|
52
56
|
onShowQrCode,
|
|
53
57
|
}: AgentOptionsMenuProps) {
|
|
54
58
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -115,7 +119,7 @@ export function AgentOptionsMenu({
|
|
|
115
119
|
}
|
|
116
120
|
};
|
|
117
121
|
|
|
118
|
-
const links = getAgentLinks(agentName);
|
|
122
|
+
const links = getAgentLinks(permanentId || agentName);
|
|
119
123
|
const editBookLink = links.find((l) => l.title === 'Edit Book')!;
|
|
120
124
|
const integrationLink = links.find((l) => l.title === 'Integration')!;
|
|
121
125
|
const historyLink = links.find((l) => l.title === 'History & Feedback')!;
|
|
@@ -128,13 +132,29 @@ export function AgentOptionsMenu({
|
|
|
128
132
|
const handleUpdateUrl = () => {
|
|
129
133
|
if (
|
|
130
134
|
window.confirm(
|
|
131
|
-
`Are you sure you want to change the agent URL from "/agents/${agentName}" to "/agents/${derivedAgentName}"
|
|
135
|
+
`Are you sure you want to change the agent URL from "/agents/${agentName}" to "/agents/${derivedAgentName}"?`,
|
|
132
136
|
)
|
|
133
137
|
) {
|
|
134
138
|
window.location.href = updateUrlHref;
|
|
135
139
|
}
|
|
136
140
|
};
|
|
137
141
|
|
|
142
|
+
const handleDeleteAgent = async () => {
|
|
143
|
+
if (
|
|
144
|
+
window.confirm(
|
|
145
|
+
`Are you sure you want to delete the agent "${agentName}"? This action can be undone by restoring it from the recycle bin.`,
|
|
146
|
+
)
|
|
147
|
+
) {
|
|
148
|
+
try {
|
|
149
|
+
await deleteAgent(agentName);
|
|
150
|
+
window.location.href = '/';
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error('Failed to delete agent:', error);
|
|
153
|
+
alert('Failed to delete agent. Please try again.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
138
158
|
const menuItems = [
|
|
139
159
|
...(showUpdateUrl
|
|
140
160
|
? [
|
|
@@ -166,6 +186,18 @@ export function AgentOptionsMenu({
|
|
|
166
186
|
icon: editBookLink.icon,
|
|
167
187
|
label: editBookLink.title,
|
|
168
188
|
},
|
|
189
|
+
{
|
|
190
|
+
type: 'link' as const,
|
|
191
|
+
href: `/agents/${encodeURIComponent(agentName)}/system-message`,
|
|
192
|
+
icon: FileTextIcon,
|
|
193
|
+
label: 'System Message',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: 'link' as const,
|
|
197
|
+
href: `/agents/${encodeURIComponent(agentName)}/code`,
|
|
198
|
+
icon: CodeIcon,
|
|
199
|
+
label: 'View Code',
|
|
200
|
+
},
|
|
169
201
|
{ type: 'divider' as const },
|
|
170
202
|
{
|
|
171
203
|
type: 'link' as const,
|
|
@@ -243,6 +275,12 @@ export function AgentOptionsMenu({
|
|
|
243
275
|
icon: DownloadIcon,
|
|
244
276
|
label: 'Export Agent',
|
|
245
277
|
},
|
|
278
|
+
{
|
|
279
|
+
type: 'action' as const,
|
|
280
|
+
icon: TrashIcon,
|
|
281
|
+
label: 'Delete Agent',
|
|
282
|
+
onClick: handleDeleteAgent,
|
|
283
|
+
},
|
|
246
284
|
// {
|
|
247
285
|
// type: 'link' as const,
|
|
248
286
|
// href: backgroundImage,
|
|
@@ -297,12 +335,16 @@ export function AgentOptionsMenu({
|
|
|
297
335
|
}
|
|
298
336
|
}}
|
|
299
337
|
className={`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors
|
|
300
|
-
${
|
|
301
|
-
|
|
302
|
-
|
|
338
|
+
${
|
|
339
|
+
item.highlight
|
|
340
|
+
? 'bg-yellow-100 text-yellow-900 font-bold hover:bg-yellow-200'
|
|
341
|
+
: 'text-gray-700 hover:bg-gray-50'
|
|
342
|
+
}
|
|
303
343
|
`}
|
|
304
344
|
>
|
|
305
|
-
<item.icon
|
|
345
|
+
<item.icon
|
|
346
|
+
className={`w-4 h-4 ${item.highlight ? 'text-yellow-700' : 'text-gray-500'}`}
|
|
347
|
+
/>
|
|
306
348
|
<span className="text-sm font-medium">{item.label}</span>
|
|
307
349
|
</button>
|
|
308
350
|
);
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
import { usePromise } from '@common/hooks/usePromise';
|
|
4
4
|
import { Chat } from '@promptbook-local/components';
|
|
5
5
|
import { RemoteAgent } from '@promptbook-local/core';
|
|
6
|
+
import { string_book } from '@promptbook-local/types';
|
|
6
7
|
import { useRouter } from 'next/navigation';
|
|
7
|
-
import { useCallback, useMemo } from 'react';
|
|
8
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
8
9
|
import spaceTrim from 'spacetrim';
|
|
9
10
|
import { string_agent_url, string_color } from '../../../../../../src/types/typeAliases';
|
|
11
|
+
import { keepUnused } from '../../../../../../src/utils/organization/keepUnused';
|
|
12
|
+
import { $createAgentFromBookAction } from '../../../app/actions';
|
|
13
|
+
import { DeletedAgentBanner } from '../../../components/DeletedAgentBanner';
|
|
10
14
|
|
|
11
15
|
type AgentProfileChatProps = {
|
|
12
16
|
agentUrl: string_agent_url;
|
|
@@ -14,10 +18,21 @@ type AgentProfileChatProps = {
|
|
|
14
18
|
fullname: string;
|
|
15
19
|
brandColorHex: string_color;
|
|
16
20
|
avatarSrc: string;
|
|
21
|
+
isDeleted?: boolean;
|
|
17
22
|
};
|
|
18
23
|
|
|
19
|
-
export function AgentProfileChat({
|
|
24
|
+
export function AgentProfileChat({
|
|
25
|
+
agentUrl,
|
|
26
|
+
agentName,
|
|
27
|
+
fullname,
|
|
28
|
+
brandColorHex,
|
|
29
|
+
avatarSrc,
|
|
30
|
+
isDeleted = false,
|
|
31
|
+
}: AgentProfileChatProps) {
|
|
20
32
|
const router = useRouter();
|
|
33
|
+
const [isCreatingAgent, setIsCreatingAgent] = useState(false);
|
|
34
|
+
|
|
35
|
+
keepUnused(isCreatingAgent);
|
|
21
36
|
|
|
22
37
|
const agentPromise = useMemo(
|
|
23
38
|
() =>
|
|
@@ -38,6 +53,24 @@ export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex,
|
|
|
38
53
|
[agentName, router],
|
|
39
54
|
);
|
|
40
55
|
|
|
56
|
+
const handleCreateAgent = useCallback(
|
|
57
|
+
async (bookContent: string) => {
|
|
58
|
+
setIsCreatingAgent(true);
|
|
59
|
+
try {
|
|
60
|
+
const { permanentId } = await $createAgentFromBookAction(bookContent as string_book);
|
|
61
|
+
if (permanentId) {
|
|
62
|
+
router.push(`/agents/${permanentId}`);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error('Failed to create agent:', error);
|
|
66
|
+
alert('Failed to create agent. Please try again.');
|
|
67
|
+
} finally {
|
|
68
|
+
setIsCreatingAgent(false);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
[router],
|
|
72
|
+
);
|
|
73
|
+
|
|
41
74
|
const initialMessage = useMemo(() => {
|
|
42
75
|
if (!agent) {
|
|
43
76
|
return 'Loading...';
|
|
@@ -52,6 +85,15 @@ export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex,
|
|
|
52
85
|
);
|
|
53
86
|
}, [agent, fullname, agentName]);
|
|
54
87
|
|
|
88
|
+
// If agent is deleted, show banner instead of chat
|
|
89
|
+
if (isDeleted) {
|
|
90
|
+
return (
|
|
91
|
+
<div className="w-full min-h-[350px] md:min-h-[500px] flex items-center justify-center">
|
|
92
|
+
<DeletedAgentBanner message="This agent has been deleted. You can restore it from the Recycle Bin." />
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
55
97
|
// If agent is not loaded yet, we can show a skeleton or just the default Chat structure
|
|
56
98
|
// But to match "same initial message", we need the agent loaded or at least the default fallback.
|
|
57
99
|
// The fallback above matches AgentChat.tsx default.
|
|
@@ -72,14 +114,15 @@ export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex,
|
|
|
72
114
|
]}
|
|
73
115
|
messages={[
|
|
74
116
|
{
|
|
75
|
-
|
|
117
|
+
sender: 'AGENT',
|
|
76
118
|
content: initialMessage,
|
|
77
|
-
|
|
119
|
+
createdAt: new Date(),
|
|
78
120
|
id: 'initial-message',
|
|
79
121
|
isComplete: true,
|
|
80
122
|
},
|
|
81
123
|
]}
|
|
82
124
|
onMessage={handleMessage}
|
|
125
|
+
onCreateAgent={handleCreateAgent}
|
|
83
126
|
isSaveButtonEnabled={false}
|
|
84
127
|
isCopyButtonEnabled={false}
|
|
85
128
|
className="bg-transparent"
|
|
@@ -1,37 +1,79 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { AgentBasicInformation } from '@promptbook-local/types';
|
|
3
|
+
import { AgentBasicInformation, string_agent_name } from '@promptbook-local/types';
|
|
4
4
|
import { AgentProfile } from '../../../components/AgentProfile/AgentProfile';
|
|
5
5
|
import { AgentOptionsMenu } from './AgentOptionsMenu';
|
|
6
6
|
|
|
7
7
|
type AgentProfileWrapperProps = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
/***
|
|
9
|
+
* @@@
|
|
10
|
+
*/
|
|
11
|
+
readonly agent: AgentBasicInformation;
|
|
12
|
+
|
|
13
|
+
/***
|
|
14
|
+
* @@@
|
|
15
|
+
*/
|
|
16
|
+
readonly agentUrl: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base URL of the agents server
|
|
20
|
+
*/
|
|
21
|
+
readonly publicUrl: URL;
|
|
22
|
+
|
|
23
|
+
/***
|
|
24
|
+
* @@@
|
|
25
|
+
*/
|
|
26
|
+
readonly agentEmail: string;
|
|
27
|
+
|
|
28
|
+
/***
|
|
29
|
+
* @@@
|
|
30
|
+
*/
|
|
31
|
+
readonly agentName: string_agent_name;
|
|
32
|
+
|
|
33
|
+
/***
|
|
34
|
+
* @@@
|
|
35
|
+
*/
|
|
36
|
+
readonly brandColorHex: string;
|
|
37
|
+
|
|
38
|
+
/***
|
|
39
|
+
* @@@
|
|
40
|
+
*/
|
|
41
|
+
readonly isAdmin: boolean;
|
|
42
|
+
|
|
43
|
+
/***
|
|
44
|
+
* @@@
|
|
45
|
+
*/
|
|
46
|
+
readonly isHeadless: boolean;
|
|
47
|
+
|
|
48
|
+
readonly actions: React.ReactNode;
|
|
49
|
+
|
|
50
|
+
/***
|
|
51
|
+
* @@@
|
|
52
|
+
*/
|
|
53
|
+
readonly children: React.ReactNode;
|
|
17
54
|
};
|
|
18
55
|
|
|
19
56
|
export function AgentProfileWrapper(props: AgentProfileWrapperProps) {
|
|
20
|
-
const { agent, agentUrl, agentEmail, agentName, brandColorHex, isAdmin, isHeadless, actions, children } =
|
|
57
|
+
const { agent, agentUrl, publicUrl, agentEmail, agentName, brandColorHex, isAdmin, isHeadless, actions, children } =
|
|
58
|
+
props;
|
|
21
59
|
|
|
22
60
|
// Derived agentName from agent data
|
|
23
61
|
const derivedAgentName = agent.agentName;
|
|
62
|
+
const permanentId = agent.permanentId;
|
|
24
63
|
|
|
25
64
|
return (
|
|
26
65
|
<AgentProfile
|
|
27
66
|
agent={agent}
|
|
28
67
|
agentUrl={agentUrl}
|
|
68
|
+
publicUrl={publicUrl}
|
|
69
|
+
permanentId={permanentId || agentName}
|
|
29
70
|
agentEmail={agentEmail}
|
|
30
71
|
isHeadless={isHeadless}
|
|
31
72
|
renderMenu={({ onShowQrCode }) => (
|
|
32
73
|
<AgentOptionsMenu
|
|
33
74
|
agentName={agentName}
|
|
34
75
|
derivedAgentName={derivedAgentName}
|
|
76
|
+
permanentId={permanentId}
|
|
35
77
|
agentUrl={agentUrl}
|
|
36
78
|
agentEmail={agentEmail}
|
|
37
79
|
brandColorHex={brandColorHex}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { $getTableName } from '@/src/database/$getTableName';
|
|
1
2
|
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
3
|
import { parseAgentSource } from '@promptbook-local/core';
|
|
4
|
+
import { $provideSupabaseForServer } from '../../../database/$provideSupabaseForServer';
|
|
3
5
|
|
|
4
6
|
export const AGENT_ACTIONS = ['Emails', 'Web chat', 'Read documents', 'Browser', 'WhatsApp', '<Coding/>'];
|
|
5
7
|
|
|
@@ -10,10 +12,28 @@ export async function getAgentName(params: Promise<{ agentName: string }>) {
|
|
|
10
12
|
|
|
11
13
|
export async function getAgentProfile(agentName: string) {
|
|
12
14
|
const collection = await $provideAgentCollectionForServer();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
+
const agentId = await collection.getAgentPermanentId(agentName);
|
|
16
|
+
const agentSource = await collection.getAgentSource(agentId);
|
|
17
|
+
const agentProfile = parseAgentSource(agentSource);
|
|
18
|
+
return agentProfile;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function isAgentDeleted(agentName: string): Promise<boolean> {
|
|
22
|
+
const supabase = $provideSupabaseForServer();
|
|
23
|
+
|
|
24
|
+
const result = await supabase
|
|
25
|
+
.from(await $getTableName(`Agent`))
|
|
26
|
+
.select('deletedAt')
|
|
27
|
+
.eq('agentName', agentName)
|
|
28
|
+
.single();
|
|
29
|
+
|
|
30
|
+
if (result.error || !result.data) {
|
|
31
|
+
return false; // If agent doesn't exist or error, consider not deleted
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result.data.deletedAt !== null;
|
|
15
35
|
}
|
|
16
36
|
|
|
17
37
|
/**
|
|
18
|
-
* TODO: Split to multiple files
|
|
38
|
+
* TODO: Split to multiple files, refactor
|
|
19
39
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { string_agent_name, string_agent_permanent_id } from '@promptbook-local/types';
|
|
1
2
|
import {
|
|
2
3
|
BookOpenIcon,
|
|
3
4
|
CodeIcon,
|
|
@@ -18,42 +19,41 @@ type AgentLink = {
|
|
|
18
19
|
rel?: string;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
export const getAgentLinks = (
|
|
22
|
-
const encodedName = encodeURIComponent(agentName);
|
|
22
|
+
export const getAgentLinks = (permanentId: string_agent_permanent_id | string_agent_name): AgentLink[] => {
|
|
23
23
|
return [
|
|
24
24
|
{
|
|
25
25
|
title: 'Chat with Agent',
|
|
26
|
-
href: `/agents/${
|
|
26
|
+
href: `/agents/${permanentId}`,
|
|
27
27
|
icon: MessageSquareIcon,
|
|
28
28
|
description: 'Direct interface to converse with the agent.',
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
title: 'Edit Book',
|
|
32
|
-
href: `/agents/${
|
|
32
|
+
href: `/agents/${permanentId}/book`,
|
|
33
33
|
icon: NotebookPenIcon,
|
|
34
34
|
description: "Edit the agent's knowledge book.",
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
title: 'Integration',
|
|
38
|
-
href: `/agents/${
|
|
38
|
+
href: `/agents/${permanentId}/integration`,
|
|
39
39
|
icon: CodeIcon,
|
|
40
40
|
description: 'Learn how to integrate this agent into your applications.',
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
title: 'History & Feedback',
|
|
44
|
-
href: `/agents/${
|
|
44
|
+
href: `/agents/${permanentId}/history`,
|
|
45
45
|
icon: HistoryIcon,
|
|
46
46
|
description: 'View past conversations and provide feedback.',
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
title: 'All Links',
|
|
50
|
-
href: `/agents/${
|
|
50
|
+
href: `/agents/${permanentId}/links`,
|
|
51
51
|
icon: LinkIcon,
|
|
52
52
|
description: 'Signpost & Links',
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
title: 'Website Integration',
|
|
56
|
-
href: `/agents/${
|
|
56
|
+
href: `/agents/${permanentId}/website-integration`,
|
|
57
57
|
icon: GlobeIcon,
|
|
58
58
|
description: 'Embed the agent chat widget directly into your React application.',
|
|
59
59
|
},
|
|
@@ -2,15 +2,12 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
2
2
|
|
|
3
3
|
export const dynamic = 'force-dynamic';
|
|
4
4
|
|
|
5
|
-
export async function GET(
|
|
6
|
-
request: NextRequest,
|
|
7
|
-
{ params }: { params: Promise<{ agentName: string }> }
|
|
8
|
-
) {
|
|
5
|
+
export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
9
6
|
try {
|
|
10
7
|
const { agentName } = await params;
|
|
11
8
|
// agentName is likely the federated server URL (e.g., "https://s6.ptbk.io")
|
|
12
9
|
// It comes decoded from the URL params if it was encoded in the request path
|
|
13
|
-
|
|
10
|
+
|
|
14
11
|
let serverUrl = agentName;
|
|
15
12
|
|
|
16
13
|
// If the serverUrl doesn't look like a URL, it might be just a hostname or something else
|
|
@@ -18,20 +15,17 @@ export async function GET(
|
|
|
18
15
|
// The client will likely pass the full URL or hostname.
|
|
19
16
|
// We'll assume if it doesn't start with http, we might need to prepend it, or it's invalid.
|
|
20
17
|
// However, the current federated servers list contains full URLs.
|
|
21
|
-
|
|
18
|
+
|
|
22
19
|
// If it was somehow double encoded or something, we might need to handle it, but standard Next.js behavior is single decode.
|
|
23
|
-
|
|
20
|
+
|
|
24
21
|
if (!serverUrl.startsWith('http')) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ status: 400 }
|
|
33
|
-
);
|
|
34
|
-
}
|
|
22
|
+
// Maybe it is just a hostname?
|
|
23
|
+
// Let's try to assume https if missing
|
|
24
|
+
if (serverUrl.includes('.')) {
|
|
25
|
+
serverUrl = `https://${serverUrl}`;
|
|
26
|
+
} else {
|
|
27
|
+
return NextResponse.json({ error: 'Invalid federated server URL' }, { status: 400 });
|
|
28
|
+
}
|
|
35
29
|
}
|
|
36
30
|
|
|
37
31
|
// Normalize URL (remove trailing slash)
|
|
@@ -48,20 +42,17 @@ export async function GET(
|
|
|
48
42
|
|
|
49
43
|
if (!response.ok) {
|
|
50
44
|
console.warn(`Proxy failed to fetch agents from ${serverUrl}: ${response.status} ${response.statusText}`);
|
|
51
|
-
return NextResponse.json(
|
|
52
|
-
{ error: `Failed to fetch from ${serverUrl}` },
|
|
53
|
-
{ status: response.status }
|
|
54
|
-
);
|
|
45
|
+
return NextResponse.json({ error: `Failed to fetch from ${serverUrl}` }, { status: response.status });
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
const data = await response.json();
|
|
58
49
|
return NextResponse.json(data);
|
|
59
|
-
|
|
60
50
|
} catch (error) {
|
|
61
51
|
console.error('Proxy error fetching federated agents:', error);
|
|
62
|
-
return NextResponse.json(
|
|
63
|
-
{ error: 'Internal Server Error' },
|
|
64
|
-
{ status: 500 }
|
|
65
|
-
);
|
|
52
|
+
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
|
66
53
|
}
|
|
67
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* TODO: !!!! Probbably remove this route
|
|
58
|
+
*/
|
|
@@ -13,7 +13,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
|
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
15
|
const collection = await $provideAgentCollectionForServer();
|
|
16
|
-
const
|
|
16
|
+
const agentId = await collection.getAgentPermanentId(agentName);
|
|
17
|
+
const agentSource = await collection.getAgentSource(agentId);
|
|
17
18
|
const effectiveAgentSource = await resolveInheritedAgentSource(agentSource, collection);
|
|
18
19
|
|
|
19
20
|
return new Response(effectiveAgentSource, {
|
|
@@ -52,7 +53,8 @@ export async function PUT(request: Request, { params }: { params: Promise<{ agen
|
|
|
52
53
|
let agentSource = validateBook(agentSourceUnchecked);
|
|
53
54
|
agentSource = padBook(agentSource);
|
|
54
55
|
|
|
55
|
-
await collection.
|
|
56
|
+
const agentId = await collection.getAgentPermanentId(agentName);
|
|
57
|
+
await collection.updateAgentSource(agentId, agentSource);
|
|
56
58
|
// <- TODO: [🐱🚀] Properly type as string_book
|
|
57
59
|
|
|
58
60
|
return new Response(
|
|
@@ -5,6 +5,8 @@ import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$pro
|
|
|
5
5
|
import { Agent, computeAgentHash, PROMPTBOOK_ENGINE_VERSION } from '@promptbook-local/core';
|
|
6
6
|
import { computeHash, serializeError } from '@promptbook-local/utils';
|
|
7
7
|
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
8
|
+
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
9
|
+
import { isAgentDeleted } from '../../_utils';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Allow long-running streams: set to platform maximum (seconds)
|
|
@@ -12,6 +14,8 @@ import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
|
12
14
|
export const maxDuration = 300;
|
|
13
15
|
|
|
14
16
|
export async function OPTIONS(request: Request) {
|
|
17
|
+
keepUnused(request);
|
|
18
|
+
|
|
15
19
|
return new Response(null, {
|
|
16
20
|
status: 200,
|
|
17
21
|
headers: {
|
|
@@ -26,6 +30,22 @@ export async function POST(request: Request, { params }: { params: Promise<{ age
|
|
|
26
30
|
let { agentName } = await params;
|
|
27
31
|
agentName = decodeURIComponent(agentName);
|
|
28
32
|
|
|
33
|
+
// Check if agent is deleted
|
|
34
|
+
if (await isAgentDeleted(agentName)) {
|
|
35
|
+
return new Response(
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
error: {
|
|
38
|
+
message: 'This agent has been deleted. You can restore it from the Recycle Bin.',
|
|
39
|
+
type: 'agent_deleted',
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
{
|
|
43
|
+
status: 410, // Gone - indicates the resource is no longer available
|
|
44
|
+
headers: { 'Content-Type': 'application/json' },
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
const body = await request.json();
|
|
30
50
|
const { message = 'Tell me more about yourself.', thread } = body;
|
|
31
51
|
// <- TODO: [🐱🚀] To configuration DEFAULT_INITIAL_HIDDEN_MESSAGE
|
|
@@ -4,7 +4,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
4
4
|
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
5
|
import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
import { Agent } from '@promptbook-local/core';
|
|
7
|
-
import { ChatMessage,
|
|
7
|
+
import { ChatMessage, Prompt, TODO_any } from '@promptbook-local/types';
|
|
8
8
|
import { NextRequest, NextResponse } from 'next/server';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
|
|
@@ -51,10 +51,7 @@ class SSENextJsTransport implements Transport {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export async function GET(
|
|
55
|
-
request: NextRequest,
|
|
56
|
-
{ params }: { params: Promise<{ agentName: string }> },
|
|
57
|
-
) {
|
|
54
|
+
export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
58
55
|
const { agentName } = await params;
|
|
59
56
|
|
|
60
57
|
// Check if agent exists
|
|
@@ -98,7 +95,7 @@ export async function GET(
|
|
|
98
95
|
),
|
|
99
96
|
model: z.string().optional(),
|
|
100
97
|
},
|
|
101
|
-
async ({ messages
|
|
98
|
+
async ({ messages }) => {
|
|
102
99
|
try {
|
|
103
100
|
const collection = await $provideAgentCollectionForServer();
|
|
104
101
|
const agentSource = await collection.getAgentSource(agentName);
|
|
@@ -115,8 +112,9 @@ export async function GET(
|
|
|
115
112
|
const previousMessages = messages.slice(0, -1);
|
|
116
113
|
|
|
117
114
|
const thread: ChatMessage[] = previousMessages.map((msg: TODO_any, index: number) => ({
|
|
115
|
+
// channel: 'PROMPTBOOK_CHAT',
|
|
118
116
|
id: `msg-${index}`,
|
|
119
|
-
|
|
117
|
+
sender: msg.role === 'assistant' ? 'agent' : 'user', // Mapping standard roles
|
|
120
118
|
content: msg.content,
|
|
121
119
|
isComplete: true,
|
|
122
120
|
date: new Date(),
|
|
@@ -177,10 +175,7 @@ export async function GET(
|
|
|
177
175
|
});
|
|
178
176
|
}
|
|
179
177
|
|
|
180
|
-
export async function POST(
|
|
181
|
-
request: NextRequest,
|
|
182
|
-
{ params }: { params: Promise<{ agentName: string }> },
|
|
183
|
-
) {
|
|
178
|
+
export async function POST(request: NextRequest /*, { params }: { params: Promise<{ agentName: string }> }*/) {
|
|
184
179
|
const { searchParams } = new URL(request.url);
|
|
185
180
|
const sessionId = searchParams.get('sessionId');
|
|
186
181
|
|