@promptbook/cli 0.104.0-1 → 0.104.0-2
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/next.config.ts +2 -2
- package/apps/agents-server/package.json +6 -1
- package/apps/agents-server/public/fonts/OpenMoji-color-cbdt.woff2 +0 -0
- package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +50 -0
- package/apps/agents-server/scripts/generate-reserved-paths/tsconfig.json +19 -0
- package/apps/agents-server/src/app/AddAgentButton.tsx +4 -3
- package/apps/agents-server/src/app/actions.ts +17 -5
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +15 -11
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +51 -7
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +32 -2
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +2 -0
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +18 -0
- 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/chat/route.ts +17 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +1 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +1 -1
- 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 +66 -0
- package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +211 -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]/integration/page.tsx +1 -1
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +2 -2
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +12 -6
- package/apps/agents-server/src/app/agents/[agentName]/system-message/page.tsx +87 -0
- package/apps/agents-server/src/app/api/admin-email/route.ts +12 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/restore/route.ts +19 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +42 -0
- package/apps/agents-server/src/app/api/agents/route.ts +29 -4
- package/apps/agents-server/src/app/api/docs/book.md/route.ts +58 -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 +107 -0
- package/apps/agents-server/src/app/api/upload/route.ts +119 -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/layout.tsx +27 -22
- package/apps/agents-server/src/app/page.tsx +50 -4
- package/apps/agents-server/src/app/recycle-bin/actions.ts +20 -14
- package/apps/agents-server/src/app/recycle-bin/page.tsx +25 -41
- package/apps/agents-server/src/app/sitemap.xml/route.ts +6 -3
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +6 -97
- package/apps/agents-server/src/components/AgentProfile/useAgentBackground.ts +97 -0
- 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 +79 -35
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +85 -20
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +72 -12
- package/apps/agents-server/src/components/Homepage/DeletedAgentsList.tsx +50 -0
- 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/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/database/metadataDefaults.ts +19 -1
- 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-0640-openai-assistant-cache.sql +12 -0
- package/apps/agents-server/src/database/schema.ts +109 -0
- package/apps/agents-server/src/generated/reservedPaths.ts +27 -0
- package/apps/agents-server/src/middleware.ts +7 -20
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +6 -1
- 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/getUserIdFromRequest.ts +33 -0
- package/apps/agents-server/src/utils/handleChatCompletion.ts +60 -4
- package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +21 -0
- package/apps/agents-server/src/utils/validateApiKey.ts +2 -1
- package/esm/index.es.js +140 -27
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +6 -2
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
- 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/_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 +13 -7
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -0
- 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/ollama/OllamaExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +12 -0
- 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 +146 -33
- 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
|
@@ -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,66 @@
|
|
|
1
|
+
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
|
+
import { $provideExecutionToolsForServer } from '@/src/tools/$provideExecutionToolsForServer';
|
|
3
|
+
import { $bookTranspilersRegister } from '../../../../../../../../src/transpilers/_common/register/$bookTranspilersRegister';
|
|
4
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
5
|
+
|
|
6
|
+
export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
7
|
+
const agentName = (await params).agentName;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
// Get available transpilers
|
|
11
|
+
const transpilers = $bookTranspilersRegister.list().map(transpiler => ({
|
|
12
|
+
name: transpiler.name,
|
|
13
|
+
title: transpiler.title,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
return NextResponse.json({ transpilers });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('Error getting transpilers:', error);
|
|
19
|
+
return NextResponse.json({ error: 'Failed to get transpilers' }, { status: 500 });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function POST(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
|
|
24
|
+
const agentName = (await params).agentName;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const { transpilerName } = await request.json();
|
|
28
|
+
|
|
29
|
+
if (!transpilerName) {
|
|
30
|
+
return NextResponse.json({ error: 'Transpiler name is required' }, { status: 400 });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Get the transpiler
|
|
34
|
+
const allTranspilers = $bookTranspilersRegister.list();
|
|
35
|
+
const transpiler = allTranspilers.find(t => t.name === transpilerName);
|
|
36
|
+
if (!transpiler) {
|
|
37
|
+
return NextResponse.json({ error: 'Transpiler not found' }, { status: 404 });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Get agent source
|
|
41
|
+
const collection = await $provideAgentCollectionForServer();
|
|
42
|
+
const agentSource = await collection.getAgentSource(agentName);
|
|
43
|
+
|
|
44
|
+
if (!agentSource) {
|
|
45
|
+
return NextResponse.json({ error: 'Agent source not found' }, { status: 404 });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Get execution tools
|
|
49
|
+
const tools = await $provideExecutionToolsForServer();
|
|
50
|
+
|
|
51
|
+
// Transpile the code
|
|
52
|
+
const transpiledCode = await transpiler.transpileBook(agentSource, tools);
|
|
53
|
+
|
|
54
|
+
return NextResponse.json({
|
|
55
|
+
code: transpiledCode,
|
|
56
|
+
transpiler: {
|
|
57
|
+
name: transpiler.name,
|
|
58
|
+
title: transpiler.title,
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error('Error transpiling code:', error);
|
|
64
|
+
return NextResponse.json({ error: 'Failed to transpile code' }, { status: 500 });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import Editor from '@monaco-editor/react';
|
|
4
|
+
import { ArrowLeftIcon, ChevronDownIcon, CodeIcon } from 'lucide-react';
|
|
5
|
+
import Link from 'next/link';
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
type Transpiler = {
|
|
9
|
+
name: string;
|
|
10
|
+
title: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type TranspilationResult = {
|
|
14
|
+
code: string;
|
|
15
|
+
transpiler: Transpiler;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function getLanguageFromTranspiler(transpilerName?: string): string {
|
|
19
|
+
if (!transpilerName) return 'plaintext';
|
|
20
|
+
|
|
21
|
+
// Map transpiler names to Monaco language identifiers
|
|
22
|
+
if (transpilerName.includes('openai-sdk')) return 'javascript';
|
|
23
|
+
if (transpilerName.includes('langchain') || transpilerName.includes('python')) return 'python';
|
|
24
|
+
if (transpilerName.includes('markdown')) return 'markdown';
|
|
25
|
+
|
|
26
|
+
// Default to plaintext for unknown transpilers
|
|
27
|
+
return 'plaintext';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function AgentCodePage({ params }: { params: Promise<{ agentName: string }> }) {
|
|
31
|
+
const [agentName, setAgentName] = useState<string>('');
|
|
32
|
+
const [agentProfile, setAgentProfile] = useState<unknown>(null);
|
|
33
|
+
const [transpilers, setTranspilers] = useState<Transpiler[]>([]);
|
|
34
|
+
const [selectedTranspiler, setSelectedTranspiler] = useState<Transpiler | null>(null);
|
|
35
|
+
const [transpiledCode, setTranspiledCode] = useState<string>('');
|
|
36
|
+
const [loading, setLoading] = useState(false);
|
|
37
|
+
const [error, setError] = useState<string>('');
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
params.then((p) => setAgentName(p.agentName));
|
|
41
|
+
}, [params]);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!agentName) return;
|
|
45
|
+
|
|
46
|
+
// Fetch agent profile
|
|
47
|
+
fetch(`/api/agents/${encodeURIComponent(agentName)}`)
|
|
48
|
+
.then((res) => res.json())
|
|
49
|
+
.then((data) => setAgentProfile(data))
|
|
50
|
+
.catch((err) => console.error('Error fetching agent profile:', err));
|
|
51
|
+
|
|
52
|
+
// Fetch available transpilers
|
|
53
|
+
fetch(`/agents/${encodeURIComponent(agentName)}/code/api`)
|
|
54
|
+
.then((res) => res.json())
|
|
55
|
+
.then((data) => {
|
|
56
|
+
setTranspilers(data.transpilers || []);
|
|
57
|
+
if (data.transpilers && data.transpilers.length > 0) {
|
|
58
|
+
setSelectedTranspiler(data.transpilers[0]);
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.catch((err) => console.error('Error fetching transpilers:', err));
|
|
62
|
+
}, [agentName]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (selectedTranspiler && agentName) {
|
|
66
|
+
transpileCode(selectedTranspiler.name);
|
|
67
|
+
}
|
|
68
|
+
}, [selectedTranspiler, agentName]);
|
|
69
|
+
|
|
70
|
+
const transpileCode = async (transpilerName: string) => {
|
|
71
|
+
setLoading(true);
|
|
72
|
+
setError('');
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(`/agents/${encodeURIComponent(agentName)}/code/api`, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: {
|
|
78
|
+
'Content-Type': 'application/json',
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify({ transpilerName }),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
const errorData = await response.json();
|
|
85
|
+
throw new Error(errorData.error || 'Failed to transpile code');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const result: TranspilationResult = await response.json();
|
|
89
|
+
setTranspiledCode(result.code);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
setError(err instanceof Error ? err.message : 'Failed to transpile code');
|
|
92
|
+
setTranspiledCode('');
|
|
93
|
+
} finally {
|
|
94
|
+
setLoading(false);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (!agentProfile) {
|
|
99
|
+
return (
|
|
100
|
+
<div className="min-h-screen p-6 md:p-12 flex flex-col items-center bg-gray-50">
|
|
101
|
+
<div className="w-full max-w-4xl bg-white rounded-xl shadow-sm border border-gray-200 p-12">
|
|
102
|
+
<div className="text-center">Loading...</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div className="min-h-screen p-6 md:p-12 flex flex-col items-center bg-gray-50">
|
|
110
|
+
<div className="w-full max-w-4xl bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
|
111
|
+
{/* Header */}
|
|
112
|
+
<div className="p-6 border-b border-gray-200 flex items-center gap-4">
|
|
113
|
+
{/* eslint-disable @typescript-eslint/no-explicit-any, @next/next/no-img-element */}
|
|
114
|
+
{(agentProfile as any)?.meta?.image && (
|
|
115
|
+
<img
|
|
116
|
+
src={(agentProfile as any).meta.image as string}
|
|
117
|
+
alt={(agentProfile as any).meta.fullname || agentName}
|
|
118
|
+
className="w-16 h-16 rounded-full object-cover border-2 border-gray-200"
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
<div className="flex-1">
|
|
122
|
+
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
|
123
|
+
<h1 className="text-2xl font-bold text-gray-900">
|
|
124
|
+
{(agentProfile as any)?.meta?.fullname || agentName}
|
|
125
|
+
</h1>
|
|
126
|
+
<p className="text-gray-500 flex items-center gap-2">
|
|
127
|
+
<CodeIcon className="w-4 h-4" />
|
|
128
|
+
Generated Code
|
|
129
|
+
</p>
|
|
130
|
+
</div>
|
|
131
|
+
<Link
|
|
132
|
+
href={`/agents/${encodeURIComponent(agentName)}`}
|
|
133
|
+
className="p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-full transition-colors"
|
|
134
|
+
title="Back to Agent"
|
|
135
|
+
>
|
|
136
|
+
<ArrowLeftIcon className="w-6 h-6" />
|
|
137
|
+
</Link>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div className="p-6">
|
|
141
|
+
{/* Transpiler Selector */}
|
|
142
|
+
<div className="mb-6">
|
|
143
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">Select Transpiler</label>
|
|
144
|
+
<div className="relative">
|
|
145
|
+
<select
|
|
146
|
+
value={selectedTranspiler?.name || ''}
|
|
147
|
+
onChange={(e) => {
|
|
148
|
+
const transpiler = transpilers.find((t) => t.name === e.target.value);
|
|
149
|
+
if (transpiler) setSelectedTranspiler(transpiler);
|
|
150
|
+
}}
|
|
151
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
|
152
|
+
>
|
|
153
|
+
{transpilers.map((transpiler) => (
|
|
154
|
+
<option key={transpiler.name} value={transpiler.name}>
|
|
155
|
+
{transpiler.title}
|
|
156
|
+
</option>
|
|
157
|
+
))}
|
|
158
|
+
</select>
|
|
159
|
+
<ChevronDownIcon className="absolute right-3 top-3 w-4 h-4 text-gray-400 pointer-events-none" />
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
{/* Code Display */}
|
|
164
|
+
<div className="bg-gray-50 rounded-lg border border-gray-200 overflow-hidden">
|
|
165
|
+
<div className="p-4 border-b border-gray-200 flex items-center justify-between">
|
|
166
|
+
<h2 className="text-lg font-semibold text-gray-900">
|
|
167
|
+
{selectedTranspiler?.title || 'Generated Code'}
|
|
168
|
+
</h2>
|
|
169
|
+
{loading && <div className="text-sm text-gray-500">Generating...</div>}
|
|
170
|
+
</div>
|
|
171
|
+
<div className="p-4">
|
|
172
|
+
{error && (
|
|
173
|
+
<div className="text-red-600 text-sm mb-4 p-3 bg-red-50 rounded border border-red-200">
|
|
174
|
+
{error}
|
|
175
|
+
</div>
|
|
176
|
+
)}
|
|
177
|
+
{transpiledCode ? (
|
|
178
|
+
<div className="h-96 border border-gray-200 rounded">
|
|
179
|
+
<Editor
|
|
180
|
+
value={transpiledCode}
|
|
181
|
+
language={getLanguageFromTranspiler(selectedTranspiler?.name)}
|
|
182
|
+
options={{
|
|
183
|
+
readOnly: true,
|
|
184
|
+
minimap: { enabled: false },
|
|
185
|
+
fontSize: 14,
|
|
186
|
+
lineNumbers: 'on',
|
|
187
|
+
scrollBeyondLastLine: false,
|
|
188
|
+
automaticLayout: true,
|
|
189
|
+
wordWrap: 'on',
|
|
190
|
+
}}
|
|
191
|
+
loading={
|
|
192
|
+
<div className="flex items-center justify-center h-full text-gray-500">
|
|
193
|
+
Loading editor...
|
|
194
|
+
</div>
|
|
195
|
+
}
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
198
|
+
) : loading ? (
|
|
199
|
+
<div className="text-gray-500 text-center py-8">Generating code...</div>
|
|
200
|
+
) : (
|
|
201
|
+
<div className="text-gray-500 text-center py-8">
|
|
202
|
+
Select a transpiler to generate code
|
|
203
|
+
</div>
|
|
204
|
+
)}
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
@@ -15,6 +15,8 @@ export async function generateAgentMetadata({ params }: { params: Promise<{ agen
|
|
|
15
15
|
// Use the agent's icon-256.png as the favicon
|
|
16
16
|
const iconUrl = `/agents/${encodeURIComponent(agentName)}/images/icon-256.png`;
|
|
17
17
|
|
|
18
|
+
const canonicalUrl = `/agents/${encodeURIComponent(agentProfile.permanentId || agentName)}`;
|
|
19
|
+
|
|
18
20
|
const metadata = {
|
|
19
21
|
metadataBase: publicUrl,
|
|
20
22
|
title,
|
|
@@ -24,6 +26,9 @@ export async function generateAgentMetadata({ params }: { params: Promise<{ agen
|
|
|
24
26
|
shortcut: iconUrl,
|
|
25
27
|
apple: iconUrl,
|
|
26
28
|
},
|
|
29
|
+
alternates: {
|
|
30
|
+
canonical: canonicalUrl,
|
|
31
|
+
},
|
|
27
32
|
openGraph: {
|
|
28
33
|
title,
|
|
29
34
|
description,
|
|
@@ -5,8 +5,8 @@ import { revalidatePath } from 'next/cache';
|
|
|
5
5
|
|
|
6
6
|
export async function restoreAgentVersion(agentName: string, historyId: number) {
|
|
7
7
|
const collection = await $provideAgentCollectionForServer();
|
|
8
|
-
await collection.
|
|
9
|
-
|
|
8
|
+
await collection.restoreAgentFromHistory(historyId);
|
|
9
|
+
|
|
10
10
|
revalidatePath(`/agents/${agentName}`);
|
|
11
11
|
revalidatePath(`/agents/${agentName}/history`);
|
|
12
12
|
}
|
|
@@ -170,7 +170,7 @@ export default async function AgentIntegrationPage({ params }: { params: Promise
|
|
|
170
170
|
}
|
|
171
171
|
`);
|
|
172
172
|
|
|
173
|
-
const agentLinks = getAgentLinks(agentName);
|
|
173
|
+
const agentLinks = getAgentLinks(agentProfile.permanentId || agentName);
|
|
174
174
|
const chatLink = agentLinks.find((l) => l.title === 'Chat with Agent')!;
|
|
175
175
|
const websiteIntegrationLink = agentLinks.find((l) => l.title === 'Website Integration')!;
|
|
176
176
|
|
|
@@ -9,9 +9,9 @@ import { notFound } from 'next/navigation';
|
|
|
9
9
|
import { Color } from '../../../../../../../src/utils/color/Color';
|
|
10
10
|
import { withAlpha } from '../../../../../../../src/utils/color/operators/withAlpha';
|
|
11
11
|
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
12
|
+
import { getAgentName, getAgentProfile } from '../_utils';
|
|
12
13
|
import { getAgentExternalLinks, getAgentLinks } from '../agentLinks';
|
|
13
14
|
import { CopyField } from '../CopyField';
|
|
14
|
-
import { getAgentName, getAgentProfile } from '../_utils';
|
|
15
15
|
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
16
16
|
|
|
17
17
|
export const generateMetadata = generateAgentMetadata;
|
|
@@ -129,7 +129,7 @@ export default async function AgentLinksPage({ params }: { params: Promise<{ age
|
|
|
129
129
|
Agent Resources
|
|
130
130
|
</h2>
|
|
131
131
|
<div className="grid md:grid-cols-2 gap-4">
|
|
132
|
-
{getAgentLinks(agentName)
|
|
132
|
+
{getAgentLinks(agentProfile.permanentId || agentName)
|
|
133
133
|
.filter((link) =>
|
|
134
134
|
['Chat with Agent', 'History & Feedback', 'Integration'].includes(link.title),
|
|
135
135
|
)
|
|
@@ -4,14 +4,16 @@ import { $provideServer } from '@/src/tools/$provideServer';
|
|
|
4
4
|
import { isUserAdmin } from '@/src/utils/isUserAdmin';
|
|
5
5
|
import { saturate } from '@promptbook-local/color';
|
|
6
6
|
import { PROMPTBOOK_COLOR } from '@promptbook-local/core';
|
|
7
|
+
import { NotFoundError } from '@promptbook-local/core';
|
|
7
8
|
import { notFound } from 'next/navigation';
|
|
8
9
|
import { Color } from '../../../../../../src/utils/color/Color';
|
|
9
|
-
import { getAgentName, getAgentProfile } from './_utils';
|
|
10
|
+
import { getAgentName, getAgentProfile, isAgentDeleted } from './_utils';
|
|
10
11
|
import { getAgentLinks } from './agentLinks';
|
|
11
12
|
import { AgentProfileChat } from './AgentProfileChat';
|
|
12
13
|
import { AgentProfileWrapper } from './AgentProfileWrapper';
|
|
13
14
|
import { generateAgentMetadata } from './generateAgentMetadata';
|
|
14
15
|
import { ServiceWorkerRegister } from './ServiceWorkerRegister';
|
|
16
|
+
import { DeletedAgentBanner } from '../../../components/DeletedAgentBanner';
|
|
15
17
|
|
|
16
18
|
export const generateMetadata = generateAgentMetadata;
|
|
17
19
|
|
|
@@ -32,10 +34,11 @@ export default async function AgentPage({
|
|
|
32
34
|
agentProfile = await getAgentProfile(agentName);
|
|
33
35
|
} catch (error) {
|
|
34
36
|
if (
|
|
35
|
-
error instanceof
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
error.message.includes('
|
|
37
|
+
error instanceof NotFoundError ||
|
|
38
|
+
(error instanceof Error &&
|
|
39
|
+
// Note: This is a bit hacky, but valid way to check for specific error message
|
|
40
|
+
(error.message.includes('Cannot coerce the result to a single JSON object') ||
|
|
41
|
+
error.message.includes('JSON object requested, multiple (or no) results returned')))
|
|
39
42
|
) {
|
|
40
43
|
notFound();
|
|
41
44
|
}
|
|
@@ -54,6 +57,7 @@ export default async function AgentPage({
|
|
|
54
57
|
const brandColorHex = brandColor.then(saturate(-0.5)).toHex();
|
|
55
58
|
|
|
56
59
|
const fullname = (agentProfile.meta.fullname || agentProfile.agentName || 'Agent') as string;
|
|
60
|
+
const isDeleted = await isAgentDeleted(agentName);
|
|
57
61
|
|
|
58
62
|
return (
|
|
59
63
|
<>
|
|
@@ -68,7 +72,7 @@ export default async function AgentPage({
|
|
|
68
72
|
isHeadless={isHeadless}
|
|
69
73
|
actions={
|
|
70
74
|
<>
|
|
71
|
-
{getAgentLinks(agentName)
|
|
75
|
+
{getAgentLinks(agentProfile.permanentId || agentName)
|
|
72
76
|
.filter((link) => ['Edit Book', 'Integration', 'All Links'].includes(link.title))
|
|
73
77
|
.map((link) => (
|
|
74
78
|
<a
|
|
@@ -86,12 +90,14 @@ export default async function AgentPage({
|
|
|
86
90
|
</>
|
|
87
91
|
}
|
|
88
92
|
>
|
|
93
|
+
{isDeleted && <DeletedAgentBanner />}
|
|
89
94
|
<AgentProfileChat
|
|
90
95
|
agentUrl={agentUrl}
|
|
91
96
|
agentName={agentName}
|
|
92
97
|
fullname={fullname}
|
|
93
98
|
brandColorHex={brandColorHex}
|
|
94
99
|
avatarSrc={agentProfile.meta.image!}
|
|
100
|
+
isDeleted={isDeleted}
|
|
95
101
|
/>
|
|
96
102
|
</AgentProfileWrapper>
|
|
97
103
|
</>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
4
|
+
import { ArrowLeftIcon, FileTextIcon } from 'lucide-react';
|
|
5
|
+
import { headers } from 'next/headers';
|
|
6
|
+
import Link from 'next/link';
|
|
7
|
+
import { notFound } from 'next/navigation';
|
|
8
|
+
import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
|
|
9
|
+
import { getAgentName, getAgentProfile } from '../_utils';
|
|
10
|
+
import { generateAgentMetadata } from '../generateAgentMetadata';
|
|
11
|
+
|
|
12
|
+
export const generateMetadata = generateAgentMetadata;
|
|
13
|
+
|
|
14
|
+
export default async function AgentSystemMessagePage({ params }: { params: Promise<{ agentName: string }> }) {
|
|
15
|
+
$sideEffect(headers());
|
|
16
|
+
const agentName = await getAgentName(params);
|
|
17
|
+
|
|
18
|
+
let agentProfile;
|
|
19
|
+
let agentSource;
|
|
20
|
+
try {
|
|
21
|
+
agentProfile = await getAgentProfile(agentName);
|
|
22
|
+
const collection = await $provideAgentCollectionForServer();
|
|
23
|
+
agentSource = await collection.getAgentSource(agentName);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (
|
|
26
|
+
error instanceof Error &&
|
|
27
|
+
(error.message.includes('Cannot coerce the result to a single JSON object') ||
|
|
28
|
+
error.message.includes('JSON object requested, multiple (or no) results returned'))
|
|
29
|
+
) {
|
|
30
|
+
notFound();
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// For now, we'll display the agent source as the system message
|
|
36
|
+
// TODO: [🧠] This might need to be the actual generated system message from the Agent class
|
|
37
|
+
const systemMessage = agentSource || 'No system message available';
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className="min-h-screen p-6 md:p-12 flex flex-col items-center bg-gray-50">
|
|
41
|
+
<div className="w-full max-w-4xl bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
|
42
|
+
{/* Header */}
|
|
43
|
+
<div className="p-6 border-b border-gray-200 flex items-center gap-4">
|
|
44
|
+
{agentProfile.meta.image && (
|
|
45
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
46
|
+
<img
|
|
47
|
+
src={agentProfile.meta.image as string}
|
|
48
|
+
alt={agentProfile.meta.fullname || agentName}
|
|
49
|
+
className="w-16 h-16 rounded-full object-cover border-2 border-gray-200"
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
<div className="flex-1">
|
|
53
|
+
<h1 className="text-2xl font-bold text-gray-900">{agentProfile.meta.fullname || agentName}</h1>
|
|
54
|
+
<p className="text-gray-500 flex items-center gap-2">
|
|
55
|
+
<FileTextIcon className="w-4 h-4" />
|
|
56
|
+
System Message
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
|
+
<Link
|
|
60
|
+
href={`/agents/${encodeURIComponent(agentName)}`}
|
|
61
|
+
className="p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-full transition-colors"
|
|
62
|
+
title="Back to Agent"
|
|
63
|
+
>
|
|
64
|
+
<ArrowLeftIcon className="w-6 h-6" />
|
|
65
|
+
</Link>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div className="p-6">
|
|
69
|
+
<div className="bg-gray-50 rounded-lg p-4 border border-gray-200">
|
|
70
|
+
<h2 className="text-lg font-semibold text-gray-900 mb-3">Generated System Message</h2>
|
|
71
|
+
<pre className="text-sm text-gray-700 whitespace-pre-wrap font-mono bg-white p-4 rounded border border-gray-200 overflow-x-auto">
|
|
72
|
+
{systemMessage}
|
|
73
|
+
</pre>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div className="mt-6 bg-blue-50 rounded-lg p-4 border border-blue-200">
|
|
77
|
+
<h3 className="text-md font-semibold text-blue-900 mb-2">Model Requirements</h3>
|
|
78
|
+
<div className="text-sm text-blue-800">
|
|
79
|
+
<p><strong>Model Variant:</strong> CHAT</p>
|
|
80
|
+
{/* TODO: [🧠] Add more model requirements if available */}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|