@promptbook/cli 0.104.0-0 → 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.
Files changed (118) hide show
  1. package/apps/agents-server/next.config.ts +2 -2
  2. package/apps/agents-server/package.json +6 -1
  3. package/apps/agents-server/public/fonts/OpenMoji-color-cbdt.woff2 +0 -0
  4. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +50 -0
  5. package/apps/agents-server/scripts/generate-reserved-paths/tsconfig.json +19 -0
  6. package/apps/agents-server/src/app/AddAgentButton.tsx +4 -3
  7. package/apps/agents-server/src/app/actions.ts +17 -5
  8. package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +15 -11
  9. package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +51 -7
  10. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +32 -2
  11. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +2 -0
  12. package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +18 -0
  13. package/apps/agents-server/src/app/agents/[agentName]/agentLinks.tsx +8 -8
  14. package/apps/agents-server/src/app/agents/[agentName]/api/agents/route.ts +17 -26
  15. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +17 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +1 -1
  17. package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +1 -1
  18. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +20 -16
  19. package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +15 -2
  20. package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +15 -2
  21. package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +12 -0
  22. package/apps/agents-server/src/app/agents/[agentName]/code/api/route.ts +66 -0
  23. package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +211 -0
  24. package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +5 -0
  25. package/apps/agents-server/src/app/agents/[agentName]/history/actions.ts +2 -2
  26. package/apps/agents-server/src/app/agents/[agentName]/integration/WebsiteIntegrationTabs.tsx +26 -0
  27. package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +23 -6
  28. package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +2 -2
  29. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +12 -6
  30. package/apps/agents-server/src/app/agents/[agentName]/system-message/page.tsx +87 -0
  31. package/apps/agents-server/src/app/agents/[agentName]/website-integration/page.tsx +35 -18
  32. package/apps/agents-server/src/app/api/admin-email/route.ts +12 -0
  33. package/apps/agents-server/src/app/api/agents/[agentName]/restore/route.ts +19 -0
  34. package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +42 -0
  35. package/apps/agents-server/src/app/api/agents/route.ts +29 -4
  36. package/apps/agents-server/src/app/api/docs/book.md/route.ts +58 -0
  37. package/apps/agents-server/src/app/api/embed.js/route.ts +87 -67
  38. package/apps/agents-server/src/app/api/federated-agents/route.ts +12 -0
  39. package/apps/agents-server/src/app/api/images/[filename]/route.ts +107 -0
  40. package/apps/agents-server/src/app/api/upload/route.ts +119 -45
  41. package/apps/agents-server/src/app/docs/[docId]/page.tsx +2 -3
  42. package/apps/agents-server/src/app/docs/page.tsx +12 -12
  43. package/apps/agents-server/src/app/embed/layout.tsx +31 -0
  44. package/apps/agents-server/src/app/embed/page.tsx +22 -9
  45. package/apps/agents-server/src/app/globals.css +140 -33
  46. package/apps/agents-server/src/app/layout.tsx +27 -22
  47. package/apps/agents-server/src/app/page.tsx +50 -4
  48. package/apps/agents-server/src/app/recycle-bin/actions.ts +20 -14
  49. package/apps/agents-server/src/app/recycle-bin/page.tsx +25 -41
  50. package/apps/agents-server/src/app/sitemap.xml/route.ts +6 -3
  51. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +6 -97
  52. package/apps/agents-server/src/components/AgentProfile/useAgentBackground.ts +97 -0
  53. package/apps/agents-server/src/components/DeletedAgentBanner.tsx +26 -0
  54. package/apps/agents-server/src/components/DocsToolbar/DocsToolbar.tsx +38 -0
  55. package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +11 -9
  56. package/apps/agents-server/src/components/Footer/Footer.tsx +5 -5
  57. package/apps/agents-server/src/components/ForgottenPasswordDialog/ForgottenPasswordDialog.tsx +61 -0
  58. package/apps/agents-server/src/components/Header/Header.tsx +79 -35
  59. package/apps/agents-server/src/components/Homepage/AgentCard.tsx +85 -20
  60. package/apps/agents-server/src/components/Homepage/AgentsList.tsx +72 -12
  61. package/apps/agents-server/src/components/Homepage/DeletedAgentsList.tsx +50 -0
  62. package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +3 -2
  63. package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +50 -1
  64. package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +7 -2
  65. package/apps/agents-server/src/components/OpenMojiIcon/OpenMojiIcon.tsx +16 -7
  66. package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +4 -4
  67. package/apps/agents-server/src/components/RegisterUserDialog/RegisterUserDialog.tsx +61 -0
  68. package/apps/agents-server/src/database/metadataDefaults.ts +19 -1
  69. package/apps/agents-server/src/database/migrations/2025-12-0240-agent-public-id.sql +3 -0
  70. package/apps/agents-server/src/database/migrations/2025-12-0360-agent-deleted-at.sql +1 -0
  71. package/apps/agents-server/src/database/migrations/2025-12-0370-image-table.sql +19 -0
  72. package/apps/agents-server/src/database/migrations/2025-12-0380-agent-visibility.sql +1 -0
  73. package/apps/agents-server/src/database/migrations/2025-12-0390-upload-tracking.sql +20 -0
  74. package/apps/agents-server/src/database/migrations/2025-12-0401-file-upload-status.sql +13 -0
  75. package/apps/agents-server/src/database/migrations/2025-12-0640-openai-assistant-cache.sql +12 -0
  76. package/apps/agents-server/src/database/schema.ts +109 -0
  77. package/apps/agents-server/src/generated/reservedPaths.ts +27 -0
  78. package/apps/agents-server/src/middleware.ts +7 -20
  79. package/apps/agents-server/src/tools/$provideCdnForServer.ts +6 -1
  80. package/apps/agents-server/src/utils/cdn/classes/TrackedFilesStorage.ts +57 -0
  81. package/apps/agents-server/src/utils/cdn/classes/VercelBlobStorage.ts +4 -0
  82. package/apps/agents-server/src/utils/cdn/interfaces/IFilesStorage.ts +18 -0
  83. package/apps/agents-server/src/utils/getUserIdFromRequest.ts +33 -0
  84. package/apps/agents-server/src/utils/handleChatCompletion.ts +60 -4
  85. package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +21 -0
  86. package/apps/agents-server/src/utils/validateApiKey.ts +2 -1
  87. package/esm/index.es.js +140 -27
  88. package/esm/index.es.js.map +1 -1
  89. package/esm/typings/src/_packages/types.index.d.ts +6 -2
  90. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +6 -1
  91. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +5 -1
  92. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +5 -0
  93. package/esm/typings/src/book-components/Chat/CodeBlock/CodeBlock.d.ts +13 -0
  94. package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +1 -0
  95. package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +2 -2
  96. package/esm/typings/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +56 -0
  97. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +13 -7
  98. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +6 -0
  99. package/esm/typings/src/commitments/DICTIONARY/DICTIONARY.d.ts +46 -0
  100. package/esm/typings/src/commitments/index.d.ts +2 -1
  101. package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +1 -1
  102. package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +1 -1
  103. package/esm/typings/src/types/typeAliases.d.ts +12 -0
  104. package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +4 -4
  105. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +1 -1
  106. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +1 -1
  107. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +1 -1
  108. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  109. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  110. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  111. package/esm/typings/src/utils/random/$randomBase58.d.ts +12 -0
  112. package/esm/typings/src/version.d.ts +1 -1
  113. package/package.json +1 -1
  114. package/umd/index.umd.js +146 -33
  115. package/umd/index.umd.js.map +1 -1
  116. package/apps/agents-server/package-lock.json +0 -27
  117. package/apps/agents-server/public/fonts/download-font.js +0 -22
  118. 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
- const formData = new FormData();
97
- formData.append('file', file);
98
-
99
- const response = await fetch('/api/upload', {
100
- method: 'POST',
101
- body: formData,
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
- if (!response.ok) {
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 = longFileUrl.split(LONG_URL).join(SHORT_URL);
120
+ const shortFileUrl = fileUrl.split(LONG_URL).join(SHORT_URL);
116
121
 
117
- console.log(`File uploaded:`, {
122
+ console.log(`🔼 File uploaded:`, {
118
123
  LONG_URL,
119
124
  SHORT_URL,
120
- longFileUrl,
125
+ fileUrl,
121
126
  shortFileUrl,
122
127
  file,
123
- formData,
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.restoreAgent(historyId);
9
-
8
+ await collection.restoreAgentFromHistory(historyId);
9
+
10
10
  revalidatePath(`/agents/${agentName}`);
11
11
  revalidatePath(`/agents/${agentName}/history`);
12
12
  }
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import { CodePreview } from '../../../../../../_common/components/CodePreview/CodePreview';
4
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from '../../../../../../_common/components/Tabs/Tabs';
5
+
6
+ type WebsiteIntegrationTabsProps = {
7
+ reactCode: string;
8
+ htmlCode: string;
9
+ };
10
+
11
+ export function WebsiteIntegrationTabs({ reactCode, htmlCode }: WebsiteIntegrationTabsProps) {
12
+ return (
13
+ <Tabs defaultValue="react" className="w-full">
14
+ <TabsList>
15
+ <TabsTrigger value="react">React</TabsTrigger>
16
+ <TabsTrigger value="html">HTML</TabsTrigger>
17
+ </TabsList>
18
+ <TabsContent value="react">
19
+ <CodePreview code={reactCode} language="typescript" />
20
+ </TabsContent>
21
+ <TabsContent value="html">
22
+ <CodePreview code={htmlCode} language="xml" />
23
+ </TabsContent>
24
+ </Tabs>
25
+ );
26
+ }
@@ -14,11 +14,12 @@ import { Color } from '../../../../../../../src/utils/color/Color';
14
14
  import { withAlpha } from '../../../../../../../src/utils/color/operators/withAlpha';
15
15
  import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
16
16
  import { CodePreview } from '../../../../../../_common/components/CodePreview/CodePreview';
17
+ import { getAgentName, getAgentProfile } from '../_utils';
17
18
  import { getAgentLinks } from '../agentLinks';
18
19
  import { CopyField } from '../CopyField';
19
- import { getAgentName, getAgentProfile } from '../_utils';
20
20
  import { generateAgentMetadata } from '../generateAgentMetadata';
21
21
  import { SdkCodeTabs } from './SdkCodeTabs';
22
+ import { WebsiteIntegrationTabs } from './WebsiteIntegrationTabs';
22
23
 
23
24
  export const generateMetadata = generateAgentMetadata;
24
25
 
@@ -71,13 +72,13 @@ export default async function AgentIntegrationPage({ params }: { params: Promise
71
72
 
72
73
  // Website Integration Code
73
74
  const { fullname, color, image, ...restMeta } = agentProfile.meta;
74
- const websiteIntegrationCode = spaceTrim(
75
+ const websiteIntegrationReactCode = spaceTrim(
75
76
  (block) => `
76
- import { PromptbookAgent } from '@promptbook/components';
77
+ import { PromptbookAgentIntegration } from '@promptbook/components';
77
78
 
78
79
  export function YourComponent() {
79
80
  return(
80
- <PromptbookAgent
81
+ <PromptbookAgentIntegration
81
82
  agentUrl="${baseUrl}"
82
83
  meta={${block(JSON.stringify({ fullname, color, image, ...restMeta }, null, 4))}}
83
84
  />
@@ -86,6 +87,19 @@ export default async function AgentIntegrationPage({ params }: { params: Promise
86
87
  `,
87
88
  );
88
89
 
90
+ // HTML Integration Code - use single quotes for meta attribute to allow JSON with double quotes inside
91
+ const metaJsonString = JSON.stringify({ fullname, color, image, ...restMeta }, null, 4);
92
+ const websiteIntegrationHtmlCode = spaceTrim(
93
+ (block) => `
94
+ <script src="${publicUrl.href}api/embed.js" async defer></script>
95
+
96
+ <promptbook-agent-integration
97
+ agent-url="${baseUrl}"
98
+ meta='${block(metaJsonString)}'
99
+ />
100
+ `,
101
+ );
102
+
89
103
  // OpenAI Compatible Curl
90
104
  const curlCode = spaceTrim(`
91
105
  curl ${agentApiBase}/api/openai/v1/chat/completions \\
@@ -156,7 +170,7 @@ export default async function AgentIntegrationPage({ params }: { params: Promise
156
170
  }
157
171
  `);
158
172
 
159
- const agentLinks = getAgentLinks(agentName);
173
+ const agentLinks = getAgentLinks(agentProfile.permanentId || agentName);
160
174
  const chatLink = agentLinks.find((l) => l.title === 'Chat with Agent')!;
161
175
  const websiteIntegrationLink = agentLinks.find((l) => l.title === 'Website Integration')!;
162
176
 
@@ -214,7 +228,10 @@ export default async function AgentIntegrationPage({ params }: { params: Promise
214
228
  </p>
215
229
  </div>
216
230
  </div>
217
- <CodePreview code={websiteIntegrationCode} language="typescript" />
231
+ <WebsiteIntegrationTabs
232
+ reactCode={websiteIntegrationReactCode}
233
+ htmlCode={websiteIntegrationHtmlCode}
234
+ />
218
235
  </div>
219
236
 
220
237
  {/* OpenAI API Compatible Endpoint */}
@@ -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 Error &&
36
- // Note: This is a bit hacky, but valid way to check for specific error message
37
- (error.message.includes('Cannot coerce the result to a single JSON object') ||
38
- error.message.includes('JSON object requested, multiple (or no) results returned'))
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
  </>