@promptbook/cli 0.104.0-0 → 0.104.0-10
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/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/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/WebsiteIntegrationTabs.tsx +26 -0
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +32 -8
- 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/agents/[agentName]/website-integration/page.tsx +35 -18
- 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/embed.js/route.ts +87 -67
- package/apps/agents-server/src/app/api/federated-agents/route.ts +12 -0
- package/apps/agents-server/src/app/api/images/[filename]/route.ts +107 -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/embed/layout.tsx +31 -0
- package/apps/agents-server/src/app/embed/page.tsx +22 -9
- 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/AgentProfile.tsx +41 -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 +114 -40
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +145 -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/$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/schema.ts +231 -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 +2890 -2737
- 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 +10 -2
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -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 +7 -11
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +2 -2
- package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +21 -11
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +80 -14
- 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/_multiple/MultipleLlmExecutionTools.d.ts +6 -2
- 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/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/$randomBase58.d.ts +12 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +4018 -3865
- 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
|
@@ -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
|
|
|
@@ -27,7 +27,11 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
|
|
|
27
27
|
const agentSource = await collection.getAgentSource(agentName);
|
|
28
28
|
const agentProfile = parseAgentSource(agentSource);
|
|
29
29
|
const agentHash = computeAgentHash(agentSource);
|
|
30
|
-
const isVoiceCallingEnabled = (await getMetadata('
|
|
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
|
+
}
|
|
31
35
|
|
|
32
36
|
return new Response(
|
|
33
37
|
JSON.stringify(
|
|
@@ -6,10 +6,13 @@ import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$pro
|
|
|
6
6
|
import { Agent, computeAgentHash, PROMPTBOOK_ENGINE_VERSION } from '@promptbook-local/core';
|
|
7
7
|
import { computeHash, serializeError } from '@promptbook-local/utils';
|
|
8
8
|
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
9
|
+
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
9
10
|
|
|
10
11
|
export const maxDuration = 300;
|
|
11
12
|
|
|
12
13
|
export async function OPTIONS(request: Request) {
|
|
14
|
+
keepUnused(request);
|
|
15
|
+
|
|
13
16
|
return new Response(null, {
|
|
14
17
|
status: 200,
|
|
15
18
|
headers: {
|
|
@@ -22,7 +25,7 @@ export async function OPTIONS(request: Request) {
|
|
|
22
25
|
|
|
23
26
|
export async function POST(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
24
27
|
// Check if voice calling is enabled
|
|
25
|
-
const isVoiceCallingEnabled = (await getMetadata('
|
|
28
|
+
const isVoiceCallingEnabled = (await getMetadata('IS_EXPERIMENTAL_VOICE_CALLING_ENABLED')) === 'true';
|
|
26
29
|
if (!isVoiceCallingEnabled) {
|
|
27
30
|
return new Response(JSON.stringify({ error: 'Voice calling is disabled on this server' }), {
|
|
28
31
|
status: 403,
|
|
@@ -38,7 +41,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ age
|
|
|
38
41
|
const audioFile = formData.get('audio') as File | null;
|
|
39
42
|
const threadString = formData.get('thread') as string | null;
|
|
40
43
|
const thread = threadString ? JSON.parse(threadString) : undefined;
|
|
41
|
-
const messageContext = formData.get('message') as string | null; // Optional text context or previous message?
|
|
44
|
+
// const messageContext = formData.get('message') as string | null; // Optional text context or previous message?
|
|
42
45
|
|
|
43
46
|
if (!audioFile) {
|
|
44
47
|
return new Response(JSON.stringify({ error: 'No audio file provided' }), {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { BookEditor } from '@promptbook-local/components';
|
|
4
4
|
import { string_book } from '@promptbook-local/types';
|
|
5
|
+
import { upload } from '@vercel/blob/client';
|
|
5
6
|
import { useEffect, useRef, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
type BookEditorWrapperProps = {
|
|
@@ -93,35 +94,38 @@ export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorW
|
|
|
93
94
|
value={agentSource}
|
|
94
95
|
onChange={handleChange}
|
|
95
96
|
onFileUpload={async (file) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
}),
|
|
102
111
|
});
|
|
103
112
|
|
|
104
|
-
|
|
105
|
-
throw new Error(`Failed to upload file: ${response.statusText}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const { fileUrl: longFileUrl } = await response.json();
|
|
113
|
+
const fileUrl = blob.url;
|
|
109
114
|
|
|
110
115
|
const LONG_URL = `${process.env.NEXT_PUBLIC_CDN_PUBLIC_URL!}/${process.env
|
|
111
116
|
.NEXT_PUBLIC_CDN_PATH_PREFIX!}/user/files/`;
|
|
112
117
|
const SHORT_URL = `https://ptbk.io/k/`;
|
|
113
118
|
// <- TODO: [🌍] Unite this logic in one place
|
|
114
119
|
|
|
115
|
-
const shortFileUrl =
|
|
120
|
+
const shortFileUrl = fileUrl.split(LONG_URL).join(SHORT_URL);
|
|
116
121
|
|
|
117
|
-
console.log(
|
|
122
|
+
console.log(`🔼 File uploaded:`, {
|
|
118
123
|
LONG_URL,
|
|
119
124
|
SHORT_URL,
|
|
120
|
-
|
|
125
|
+
fileUrl,
|
|
121
126
|
shortFileUrl,
|
|
122
127
|
file,
|
|
123
|
-
|
|
124
|
-
response,
|
|
128
|
+
blob,
|
|
125
129
|
});
|
|
126
130
|
|
|
127
131
|
return shortFileUrl;
|
|
@@ -5,21 +5,34 @@ import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentColle
|
|
|
5
5
|
import { isUserAdmin } from '@/src/utils/isUserAdmin';
|
|
6
6
|
import { headers } from 'next/headers';
|
|
7
7
|
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
8
|
+
import { isAgentDeleted } from '../_utils';
|
|
8
9
|
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
9
10
|
import { BookEditorWrapper } from './BookEditorWrapper';
|
|
11
|
+
import { DeletedAgentBanner } from '../../../../components/DeletedAgentBanner';
|
|
10
12
|
|
|
11
13
|
export const generateMetadata = generateAgentMetadata;
|
|
12
14
|
|
|
13
15
|
export default async function AgentBookPage({ params }: { params: Promise<{ agentName: string }> }) {
|
|
14
16
|
$sideEffect(headers());
|
|
15
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
|
+
|
|
16
31
|
if (!(await isUserAdmin())) {
|
|
17
32
|
/* <- TODO: [👹] Here should be user permissions */
|
|
18
33
|
return <ForbiddenPage />;
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
let { agentName } = await params;
|
|
22
|
-
agentName = decodeURIComponent(agentName);
|
|
23
36
|
const collection = await $provideAgentCollectionForServer();
|
|
24
37
|
const agentSource = await collection.getAgentSource(decodeURIComponent(agentName));
|
|
25
38
|
|
|
@@ -5,21 +5,34 @@ import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentColle
|
|
|
5
5
|
import { isUserAdmin } from '@/src/utils/isUserAdmin';
|
|
6
6
|
import { headers } from 'next/headers';
|
|
7
7
|
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
8
|
+
import { isAgentDeleted } from '../_utils';
|
|
8
9
|
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
9
10
|
import { AgentBookAndChat } from './AgentBookAndChat';
|
|
11
|
+
import { DeletedAgentBanner } from '../../../../components/DeletedAgentBanner';
|
|
10
12
|
|
|
11
13
|
export const generateMetadata = generateAgentMetadata;
|
|
12
14
|
|
|
13
15
|
export default async function AgentBookAndChatPage({ params }: { params: Promise<{ agentName: string }> }) {
|
|
14
16
|
$sideEffect(headers());
|
|
15
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
|
+
|
|
16
31
|
if (!(await isUserAdmin())) {
|
|
17
32
|
/* <- TODO: [👹] Here should be user permissions */
|
|
18
33
|
return <ForbiddenPage />;
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
let { agentName } = await params;
|
|
22
|
-
agentName = decodeURIComponent(agentName);
|
|
23
36
|
const collection = await $provideAgentCollectionForServer();
|
|
24
37
|
const agentSource = await collection.getAgentSource(agentName);
|
|
25
38
|
const agentUrl = `/agents/${agentName}`;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { headers } from 'next/headers';
|
|
4
4
|
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
5
|
+
import { isAgentDeleted } from '../_utils';
|
|
5
6
|
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
6
7
|
import { AgentChatWrapper } from '../AgentChatWrapper';
|
|
8
|
+
import { DeletedAgentBanner } from '../../../../components/DeletedAgentBanner';
|
|
7
9
|
|
|
8
10
|
export const generateMetadata = generateAgentMetadata;
|
|
9
11
|
|
|
@@ -19,6 +21,16 @@ export default async function AgentChatPage({
|
|
|
19
21
|
agentName = decodeURIComponent(agentName);
|
|
20
22
|
const { message } = await searchParams;
|
|
21
23
|
|
|
24
|
+
const isDeleted = await isAgentDeleted(agentName);
|
|
25
|
+
|
|
26
|
+
if (isDeleted) {
|
|
27
|
+
return (
|
|
28
|
+
<main className="w-screen h-screen flex items-center justify-center p-8">
|
|
29
|
+
<DeletedAgentBanner message="This agent has been deleted. You can restore it from the Recycle Bin." />
|
|
30
|
+
</main>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
const agentUrl = `/agents/${agentName}`;
|
|
23
35
|
|
|
24
36
|
return (
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
|
+
import { $provideExecutionToolsForServer } from '@/src/tools/$provideExecutionToolsForServer';
|
|
3
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
4
|
+
import { $bookTranspilersRegister } from '../../../../../../../../src/transpilers/_common/register/$bookTranspilersRegister';
|
|
5
|
+
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
6
|
+
|
|
7
|
+
export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
8
|
+
keepUnused(request);
|
|
9
|
+
keepUnused(params);
|
|
10
|
+
// const agentName = (await params).agentName;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
// Get available transpilers
|
|
14
|
+
const transpilers = $bookTranspilersRegister.list().map((transpiler) => ({
|
|
15
|
+
name: transpiler.name,
|
|
16
|
+
title: transpiler.title,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
return NextResponse.json({ transpilers });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Error getting transpilers:', error);
|
|
22
|
+
return NextResponse.json({ error: 'Failed to get transpilers' }, { status: 500 });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function POST(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
27
|
+
const agentName = (await params).agentName;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const { transpilerName } = await request.json();
|
|
31
|
+
|
|
32
|
+
if (!transpilerName) {
|
|
33
|
+
return NextResponse.json({ error: 'Transpiler name is required' }, { status: 400 });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Get the transpiler
|
|
37
|
+
const allTranspilers = $bookTranspilersRegister.list();
|
|
38
|
+
const transpiler = allTranspilers.find((t) => t.name === transpilerName);
|
|
39
|
+
if (!transpiler) {
|
|
40
|
+
return NextResponse.json({ error: 'Transpiler not found' }, { status: 404 });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get agent source
|
|
44
|
+
const collection = await $provideAgentCollectionForServer();
|
|
45
|
+
const agentSource = await collection.getAgentSource(agentName);
|
|
46
|
+
|
|
47
|
+
if (!agentSource) {
|
|
48
|
+
return NextResponse.json({ error: 'Agent source not found' }, { status: 404 });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get execution tools
|
|
52
|
+
const tools = await $provideExecutionToolsForServer();
|
|
53
|
+
|
|
54
|
+
// Transpile the code
|
|
55
|
+
const transpiledCode = await transpiler.transpileBook(agentSource, tools);
|
|
56
|
+
|
|
57
|
+
return NextResponse.json({
|
|
58
|
+
code: transpiledCode,
|
|
59
|
+
transpiler: {
|
|
60
|
+
name: transpiler.name,
|
|
61
|
+
title: transpiler.title,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error('Error transpiling code:', error);
|
|
66
|
+
return NextResponse.json({ error: 'Failed to transpile code' }, { status: 500 });
|
|
67
|
+
}
|
|
68
|
+
}
|