@promptbook/cli 0.103.0-48 → 0.103.0-49

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 (110) hide show
  1. package/apps/agents-server/README.md +1 -1
  2. package/apps/agents-server/TODO.txt +6 -5
  3. package/apps/agents-server/config.ts +130 -0
  4. package/apps/agents-server/next.config.ts +1 -1
  5. package/apps/agents-server/public/fonts/OpenMoji-black-glyf.woff2 +0 -0
  6. package/apps/agents-server/public/fonts/download-font.js +22 -0
  7. package/apps/agents-server/src/app/[agentName]/[...rest]/page.tsx +6 -0
  8. package/apps/agents-server/src/app/[agentName]/page.tsx +1 -0
  9. package/apps/agents-server/src/app/actions.ts +37 -2
  10. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +68 -0
  11. package/apps/agents-server/src/app/agents/[agentName]/AgentQrCode.tsx +55 -0
  12. package/apps/agents-server/src/app/agents/[agentName]/AgentUrlCopy.tsx +4 -5
  13. package/apps/agents-server/src/app/agents/[agentName]/CopyField.tsx +44 -0
  14. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +8 -8
  15. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +100 -24
  16. package/apps/agents-server/src/app/agents/[agentName]/api/feedback/route.ts +54 -0
  17. package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/route.ts +6 -6
  18. package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/systemMessage/route.ts +3 -3
  19. package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +6 -7
  20. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +4 -5
  21. package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +9 -2
  22. package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChat.tsx +23 -0
  23. package/apps/agents-server/src/app/agents/[agentName]/book+chat/{AgentBookAndChatComponent.tsx → AgentBookAndChatComponent.tsx.todo} +4 -4
  24. package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +28 -17
  25. package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx.todo +21 -0
  26. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatWrapper.tsx +34 -4
  27. package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +4 -1
  28. package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +42 -0
  29. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +109 -106
  30. package/apps/agents-server/src/app/agents/page.tsx +1 -1
  31. package/apps/agents-server/src/app/api/auth/login/route.ts +65 -0
  32. package/apps/agents-server/src/app/api/auth/logout/route.ts +7 -0
  33. package/apps/agents-server/src/app/api/metadata/route.ts +116 -0
  34. package/apps/agents-server/src/app/api/upload/route.ts +7 -3
  35. package/apps/agents-server/src/app/api/users/[username]/route.ts +75 -0
  36. package/apps/agents-server/src/app/api/users/route.ts +71 -0
  37. package/apps/agents-server/src/app/globals.css +35 -1
  38. package/apps/agents-server/src/app/layout.tsx +43 -23
  39. package/apps/agents-server/src/app/metadata/MetadataClient.tsx +271 -0
  40. package/apps/agents-server/src/app/metadata/page.tsx +13 -0
  41. package/apps/agents-server/src/app/not-found.tsx +5 -0
  42. package/apps/agents-server/src/app/page.tsx +84 -46
  43. package/apps/agents-server/src/components/Auth/AuthControls.tsx +123 -0
  44. package/apps/agents-server/src/components/ErrorPage/ErrorPage.tsx +33 -0
  45. package/apps/agents-server/src/components/ForbiddenPage/ForbiddenPage.tsx +15 -0
  46. package/apps/agents-server/src/components/Header/Header.tsx +146 -0
  47. package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +27 -0
  48. package/apps/agents-server/src/components/LoginDialog/LoginDialog.tsx +40 -0
  49. package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +109 -0
  50. package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +17 -0
  51. package/apps/agents-server/src/components/UsersList/UsersList.tsx +190 -0
  52. package/apps/agents-server/src/components/VercelDeploymentCard/VercelDeploymentCard.tsx +60 -0
  53. package/apps/agents-server/src/database/$getTableName.ts +18 -0
  54. package/apps/agents-server/src/database/$provideSupabase.ts +2 -2
  55. package/apps/agents-server/src/database/$provideSupabaseForServer.ts +3 -3
  56. package/apps/agents-server/src/database/getMetadata.ts +31 -0
  57. package/apps/agents-server/src/database/metadataDefaults.ts +32 -0
  58. package/apps/agents-server/src/database/schema.sql +81 -33
  59. package/apps/agents-server/src/database/schema.ts +35 -1
  60. package/apps/agents-server/src/middleware.ts +162 -0
  61. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +11 -7
  62. package/apps/agents-server/src/tools/$provideCdnForServer.ts +1 -1
  63. package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +11 -13
  64. package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +7 -7
  65. package/apps/agents-server/src/tools/$provideServer.ts +39 -0
  66. package/apps/agents-server/src/utils/auth.ts +33 -0
  67. package/apps/agents-server/src/utils/cdn/utils/nameToSubfolderPath.ts +1 -1
  68. package/apps/agents-server/src/utils/getCurrentUser.ts +32 -0
  69. package/apps/agents-server/src/utils/isIpAllowed.ts +101 -0
  70. package/apps/agents-server/src/utils/isUserAdmin.ts +31 -0
  71. package/apps/agents-server/src/utils/session.ts +50 -0
  72. package/apps/agents-server/tailwind.config.ts +2 -0
  73. package/esm/index.es.js +147 -31
  74. package/esm/index.es.js.map +1 -1
  75. package/esm/typings/servers.d.ts +1 -0
  76. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  77. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  78. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +12 -2
  79. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +14 -8
  80. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
  81. package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +28 -0
  82. package/esm/typings/src/commitments/index.d.ts +2 -1
  83. package/esm/typings/src/config.d.ts +1 -0
  84. package/esm/typings/src/errors/DatabaseError.d.ts +2 -2
  85. package/esm/typings/src/errors/WrappedError.d.ts +2 -2
  86. package/esm/typings/src/execution/ExecutionTask.d.ts +2 -2
  87. package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -1
  88. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
  89. package/esm/typings/src/llm-providers/agent/Agent.d.ts +11 -3
  90. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +6 -1
  91. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +6 -2
  92. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +6 -1
  93. package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
  94. package/esm/typings/src/utils/color/Color.d.ts +7 -0
  95. package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
  96. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
  97. package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
  98. package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
  99. package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
  100. package/esm/typings/src/utils/organization/$side_effect.d.ts +2 -2
  101. package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
  102. package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
  103. package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
  104. package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
  105. package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
  106. package/esm/typings/src/version.d.ts +1 -1
  107. package/package.json +1 -1
  108. package/umd/index.umd.js +147 -31
  109. package/umd/index.umd.js.map +1 -1
  110. package/apps/agents-server/config.ts.todo +0 -38
@@ -0,0 +1,54 @@
1
+ import { $provideSupabaseForServer } from '@/src/database/$provideSupabaseForServer';
2
+ import { NextRequest, NextResponse } from 'next/server';
3
+ import { PROMPTBOOK_ENGINE_VERSION } from '../../../../../../../../src/version';
4
+ import { $getTableName } from '../../../../../database/$getTableName';
5
+
6
+ type FeedbackRequest = {
7
+ agentHash: string;
8
+ rating?: string;
9
+ textRating?: string;
10
+ chatThread?: string;
11
+ userNote?: string;
12
+ expectedAnswer?: string;
13
+ };
14
+
15
+ export async function POST(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
16
+ try {
17
+ const { agentName } = await params;
18
+ const body = (await request.json()) as FeedbackRequest;
19
+ const { agentHash, rating, textRating, chatThread, userNote, expectedAnswer } = body;
20
+
21
+ if (!agentHash) {
22
+ return NextResponse.json({ message: 'Missing agentHash' }, { status: 400 });
23
+ }
24
+
25
+ const supabase = $provideSupabaseForServer();
26
+
27
+ const { error } = await supabase.from(await $getTableName('ChatFeedback')).insert({
28
+ createdAt: new Date().toISOString(),
29
+ agentName,
30
+ agentHash,
31
+ rating,
32
+ textRating,
33
+ chatThread,
34
+ userNote,
35
+ expectedAnswer,
36
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
37
+ // Telemetry fields can be populated here if available in headers
38
+ // For now we leave them null or let Supabase handle default if any (though schema has them nullable)
39
+ url: request.headers.get('referer') || undefined,
40
+ userAgent: request.headers.get('user-agent') || undefined,
41
+ ip: request.headers.get('x-forwarded-for') || undefined,
42
+ });
43
+
44
+ if (error) {
45
+ console.error('Error inserting feedback:', error);
46
+ return NextResponse.json({ message: 'Failed to save feedback' }, { status: 500 });
47
+ }
48
+
49
+ return NextResponse.json({ message: 'Feedback saved' }, { status: 201 });
50
+ } catch (error) {
51
+ console.error('Unexpected error in feedback route:', error);
52
+ return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
53
+ }
54
+ }
@@ -17,10 +17,10 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
17
17
  return new Response(
18
18
  JSON.stringify(
19
19
  modelRequirements,
20
- // <- TODO: !!! Rename `serializeError` to `errorToJson`
20
+ // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
21
21
  null,
22
22
  4,
23
- // <- TODO: !!! Allow to configure pretty print for agent server
23
+ // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
24
24
  ),
25
25
  {
26
26
  status: 200,
@@ -35,13 +35,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
35
35
  return new Response(
36
36
  JSON.stringify(
37
37
  serializeError(error),
38
- // <- TODO: !!! Rename `serializeError` to `errorToJson`
38
+ // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
39
39
  null,
40
40
  4,
41
- // <- TODO: !!! Allow to configure pretty print for agent server
41
+ // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
42
42
  ),
43
43
  {
44
- status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
44
+ status: 400, // <- TODO: [🐱‍🚀] Make `errorToHttpStatusCode`
45
45
  headers: { 'Content-Type': 'application/json' },
46
46
  },
47
47
  );
@@ -50,4 +50,4 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
50
50
 
51
51
  /**
52
52
  * TODO: [🍞] DRY - Make some common utility for API on one agent
53
- */
53
+ */
@@ -27,13 +27,13 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
27
27
  return new Response(
28
28
  JSON.stringify(
29
29
  serializeError(error),
30
- // <- TODO: !!! Rename `serializeError` to `errorToJson`
30
+ // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
31
31
  null,
32
32
  4,
33
- // <- TODO: !!! Allow to configure pretty print for agent server
33
+ // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
34
34
  ),
35
35
  {
36
- status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
36
+ status: 400, // <- TODO: [🐱‍🚀] Make `errorToHttpStatusCode`
37
37
  headers: { 'Content-Type': 'application/json' },
38
38
  },
39
39
  );
@@ -17,10 +17,10 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
17
17
  return new Response(
18
18
  JSON.stringify(
19
19
  agentProfile,
20
- // <- TODO: !!! Rename `serializeError` to `errorToJson`
20
+ // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
21
21
  null,
22
22
  4,
23
- // <- TODO: !!! Allow to configure pretty print for agent server
23
+ // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
24
24
  ),
25
25
  {
26
26
  status: 200,
@@ -35,20 +35,19 @@ export async function GET(request: Request, { params }: { params: Promise<{ agen
35
35
  return new Response(
36
36
  JSON.stringify(
37
37
  serializeError(error),
38
- // <- TODO: !!! Rename `serializeError` to `errorToJson`
38
+ // <- TODO: [🐱‍🚀] Rename `serializeError` to `errorToJson`
39
39
  null,
40
40
  4,
41
- // <- TODO: !!! Allow to configure pretty print for agent server
41
+ // <- TODO: [🐱‍🚀] Allow to configure pretty print for agent server
42
42
  ),
43
43
  {
44
- status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
44
+ status: 400, // <- TODO: [🐱‍🚀] Make `errorToHttpStatusCode`
45
45
  headers: { 'Content-Type': 'application/json' },
46
46
  },
47
47
  );
48
48
  }
49
49
  }
50
50
 
51
-
52
51
  /**
53
52
  * TODO: [🍞] DRY - Make some common utility for API on one agent
54
- */
53
+ */
@@ -9,7 +9,7 @@ type BookEditorWrapperProps = {
9
9
  initialAgentSource: string_book;
10
10
  };
11
11
 
12
- // TODO: !!!! Rename to BookEditorSavingWrapper
12
+ // TODO: [🐱‍🚀] Rename to BookEditorSavingWrapper
13
13
 
14
14
  export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorWrapperProps) {
15
15
  const [agentSource, setAgentSource] = useState<string_book>(initialAgentSource);
@@ -126,15 +126,14 @@ export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorW
126
126
 
127
127
  return shortFileUrl;
128
128
  }}
129
- // <- TODO: !!!! Create two-state solution for `<BookEditor onFileUpload={...} />`
130
129
  />
131
130
  </div>
132
131
  );
133
132
  }
134
133
 
135
134
  /**
135
+ * TODO: Prompt: Use `import { debounce } from '@promptbook-local/utils';` instead of custom debounce implementation
136
136
  * TODO: [🚗] Transfer the saving logic to `<BookEditor/>` be aware of CRDT / yjs approach to be implementable in future
137
- * DONE: Implement debouncing for auto-save (600ms delay)
138
- * TODO: !!! Add error handling and retry logic
139
- * TODO: !!! Show save status indicator
137
+ * TODO: [🐱‍🚀] Add error handling and retry logic
138
+ * TODO: [🐱‍🚀] Show save status indicator
140
139
  */
@@ -1,6 +1,8 @@
1
1
  'use server';
2
2
 
3
+ import { ForbiddenPage } from '@/src/components/ForbiddenPage/ForbiddenPage';
3
4
  import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
5
+ import { isUserAdmin } from '@/src/utils/isUserAdmin';
4
6
  import { headers } from 'next/headers';
5
7
  import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
6
8
  import { BookEditorWrapper } from './BookEditorWrapper';
@@ -8,15 +10,20 @@ import { BookEditorWrapper } from './BookEditorWrapper';
8
10
  export default async function AgentBookPage({ params }: { params: Promise<{ agentName: string }> }) {
9
11
  $sideEffect(headers());
10
12
 
13
+ if (!(await isUserAdmin())) {
14
+ /* <- TODO: [👹] Here should be user permissions */
15
+ return <ForbiddenPage />;
16
+ }
17
+
11
18
  let { agentName } = await params;
12
19
  agentName = decodeURIComponent(agentName);
13
20
  const collection = await $provideAgentCollectionForServer();
14
21
  const agentSource = await collection.getAgentSource(decodeURIComponent(agentName));
15
22
 
16
23
  return (
17
- <main className={`w-screen h-screen`}>
24
+ <div className={`w-screen h-[calc(100vh-60px)]`}>
18
25
  <BookEditorWrapper agentName={agentName} initialAgentSource={agentSource} />
19
- </main>
26
+ </div>
20
27
  );
21
28
  }
22
29
 
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+
3
+ import { ResizablePanelsAuto } from '@common/components/ResizablePanelsAuto/ResizablePanelsAuto';
4
+ import { string_agent_url, string_book } from '@promptbook-local/types';
5
+ import { BookEditorWrapper } from '../book/BookEditorWrapper';
6
+ import { AgentChatWrapper } from '../AgentChatWrapper';
7
+
8
+ type AgentBookAndChatProps = {
9
+ agentName: string;
10
+ initialAgentSource: string_book;
11
+ agentUrl: string_agent_url;
12
+ };
13
+
14
+ export function AgentBookAndChat(props: AgentBookAndChatProps) {
15
+ const { agentName, initialAgentSource, agentUrl } = props;
16
+
17
+ return (
18
+ <ResizablePanelsAuto name={`agent-book-and-chat-${agentName}`} className="w-full h-full">
19
+ <BookEditorWrapper agentName={agentName} initialAgentSource={initialAgentSource} />
20
+ <AgentChatWrapper agentUrl={agentUrl} />
21
+ </ResizablePanelsAuto>
22
+ );
23
+ }
@@ -16,7 +16,7 @@ export function AgentBookAndChatComponent() {
16
16
 
17
17
  const [agentSource, setAgentSource] = useStateInLocalStorage<string_book>(
18
18
  'marigold-agentSource-1',
19
- // TODO: !!! Uplad image to ptbk.io CDN
19
+ // TODO: [🐱‍🚀] Uplad image to ptbk.io CDN
20
20
  () => book`
21
21
  Marigold
22
22
 
@@ -53,7 +53,7 @@ export function AgentBookAndChatComponent() {
53
53
 
54
54
  const agent = useMemo(() => {
55
55
  /*/
56
- // TODO: !!! Try working with `RemoteLlmExecutionTools`
56
+ // TODO: [🐱‍🚀] Try working with `RemoteLlmExecutionTools`
57
57
  const llm = new RemoteLlmExecutionTools({
58
58
  remoteServerUrl: 'https://promptbook.s5.ptbk.io/',
59
59
  identification: {
@@ -66,7 +66,7 @@ export function AgentBookAndChatComponent() {
66
66
  /**/
67
67
  const llm = new OpenAiAssistantExecutionTools({
68
68
  dangerouslyAllowBrowser: true,
69
- isCreatingNewAssistantsAllowed: true, // <- TODO: !!! Test without whether warning is shown
69
+ isCreatingNewAssistantsAllowed: true, // <- TODO: [🐱‍🚀] Test without whether warning is shown
70
70
  apiKey,
71
71
  assistantId: 'asst_xI94Elk27nssnwAUkG2Cmok8', // <- TODO: [🧠] Make dynamic
72
72
  isVerbose: true,
@@ -155,6 +155,6 @@ export function AgentBookAndChatComponent() {
155
155
  }
156
156
 
157
157
  /**
158
- * TODO: !!!! Make self-learning book createAgentLlmExecutionTools, use bidirectional agentSource
158
+ * TODO: [🐱‍🚀] Make self-learning book createAgentLlmExecutionTools, use bidirectional agentSource
159
159
  * TODO: [🚗] Components and pages here should be just tiny UI wraper around proper agent logic and conponents
160
160
  */
@@ -1,21 +1,32 @@
1
- 'use client';
1
+ 'use server';
2
2
 
3
- import dynamic from 'next/dynamic';
3
+ import { ForbiddenPage } from '@/src/components/ForbiddenPage/ForbiddenPage';
4
+ import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
5
+ import { isUserAdmin } from '@/src/utils/isUserAdmin';
6
+ import { headers } from 'next/headers';
7
+ import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
8
+ import { generateAgentMetadata } from '../generateAgentMetadata';
9
+ import { AgentBookAndChat } from './AgentBookAndChat';
4
10
 
5
- const SelfLearningBook = dynamic(
6
- () => import('./AgentBookAndChatComponent').then((module) => module.AgentBookAndChatComponent),
7
- {
8
- ssr: false,
9
- },
10
- );
11
+ export const generateMetadata = generateAgentMetadata;
11
12
 
12
- export default function AgentBookAndChatPage() {
13
- return <SelfLearningBook />;
14
- }
13
+ export default async function AgentBookAndChatPage({ params }: { params: Promise<{ agentName: string }> }) {
14
+ $sideEffect(headers());
15
+
16
+ if (!(await isUserAdmin())) {
17
+ /* <- TODO: [👹] Here should be user permissions */
18
+ return <ForbiddenPage />;
19
+ }
15
20
 
16
- /**
17
- * TODO: !!! Private / public / open agents
18
- * TODO: !!! Allow http://localhost:4440/agents/agent-123.book to download the agent book file
19
- * TODO: !!! BOOK_MIME_TYPE in config
20
- * TODO: [🚗] Components and pages here should be just tiny UI wraper around proper agent logic and conponents
21
- */
21
+ let { agentName } = await params;
22
+ agentName = decodeURIComponent(agentName);
23
+ const collection = await $provideAgentCollectionForServer();
24
+ const agentSource = await collection.getAgentSource(agentName);
25
+ const agentUrl = `/agents/${agentName}`;
26
+
27
+ return (
28
+ <div className={`w-screen h-[calc(100vh-60px)]`}>
29
+ <AgentBookAndChat agentName={agentName} initialAgentSource={agentSource} agentUrl={agentUrl} />
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+
3
+ import dynamic from 'next/dynamic';
4
+
5
+ const SelfLearningBook = dynamic(
6
+ () => import('./AgentBookAndChatComponent').then((module) => module.AgentBookAndChatComponent),
7
+ {
8
+ ssr: false,
9
+ },
10
+ );
11
+
12
+ export default function AgentBookAndChatPage() {
13
+ return <SelfLearningBook />;
14
+ }
15
+
16
+ /**
17
+ * TODO: [🐱‍🚀] Private / public / open agents
18
+ * TODO: [🐱‍🚀] Allow http://localhost:4440/agents/agent-123.book to download the agent book file
19
+ * TODO: [🐱‍🚀] BOOK_MIME_TYPE in config
20
+ * TODO: [🚗] Components and pages here should be just tiny UI wraper around proper agent logic and conponents
21
+ */
@@ -3,14 +3,14 @@
3
3
  import { usePromise } from '@common/hooks/usePromise';
4
4
  import { AgentChat } from '@promptbook-local/components';
5
5
  import { RemoteAgent } from '@promptbook-local/core';
6
- import { useMemo } from 'react';
6
+ import { useCallback, useMemo } from 'react';
7
7
  import { string_agent_url } from '../../../../../../../src/types/typeAliases';
8
8
 
9
9
  type AgentChatWrapperProps = {
10
10
  agentUrl: string_agent_url;
11
11
  };
12
12
 
13
- // TODO: !!!! Rename to AgentChatSomethingWrapper
13
+ // TODO: [🐱‍🚀] Rename to AgentChatSomethingWrapper
14
14
 
15
15
  export function AgentChatWrapper(props: AgentChatWrapperProps) {
16
16
  const { agentUrl } = props;
@@ -26,11 +26,41 @@ export function AgentChatWrapper(props: AgentChatWrapperProps) {
26
26
 
27
27
  const { value: agent } = usePromise(agentPromise, [agentPromise]);
28
28
 
29
+ const handleFeedback = useCallback(
30
+ async (feedback: {
31
+ rating: number;
32
+ textRating?: string;
33
+ chatThread?: string;
34
+ userNote?: string;
35
+ expectedAnswer?: string | null;
36
+ }) => {
37
+ if (!agent) {
38
+ return;
39
+ }
40
+
41
+ await fetch(`${agentUrl}/api/feedback`, {
42
+ method: 'POST',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ },
46
+ body: JSON.stringify({
47
+ rating: feedback.rating.toString(),
48
+ textRating: feedback.textRating,
49
+ chatThread: feedback.chatThread,
50
+ userNote: feedback.textRating, // Mapping textRating to userNote as well if needed, or just textRating
51
+ expectedAnswer: feedback.expectedAnswer,
52
+ agentHash: agent.agentHash,
53
+ }),
54
+ });
55
+ },
56
+ [agent, agentUrl],
57
+ );
58
+
29
59
  if (!agent) {
30
- return <>{/* <- TODO: !!! <PromptbookLoading /> */}</>;
60
+ return <>{/* <- TODO: [🐱‍🚀] <PromptbookLoading /> */}</>;
31
61
  }
32
62
 
33
- return <AgentChat className={`w-full h-full`} agent={agent} />;
63
+ return <AgentChat className={`w-full h-full`} agent={agent} onFeedback={handleFeedback} />;
34
64
  }
35
65
 
36
66
  /**
@@ -2,7 +2,10 @@
2
2
 
3
3
  import { headers } from 'next/headers';
4
4
  import { $sideEffect } from '../../../../../../../src/utils/organization/$sideEffect';
5
- import { AgentChatWrapper } from './AgentChatWrapper';
5
+ import { generateAgentMetadata } from '../generateAgentMetadata';
6
+ import { AgentChatWrapper } from '../AgentChatWrapper';
7
+
8
+ export const generateMetadata = generateAgentMetadata;
6
9
 
7
10
  export default async function AgentChatPage({ params }: { params: Promise<{ agentName: string }> }) {
8
11
  $sideEffect(headers());
@@ -0,0 +1,42 @@
1
+ import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
2
+ import { parseAgentSource } from '@promptbook-local/core';
3
+ import { Metadata } from 'next';
4
+
5
+ export async function generateAgentMetadata({ params }: { params: Promise<{ agentName: string }> }): Promise<Metadata> {
6
+ let { agentName } = await params;
7
+ agentName = decodeURIComponent(agentName);
8
+
9
+ try {
10
+ const collection = await $provideAgentCollectionForServer();
11
+ const agentSource = await collection.getAgentSource(agentName);
12
+ const agentProfile = parseAgentSource(agentSource);
13
+
14
+ const title = agentProfile.meta.title || agentProfile.agentName;
15
+ const description = agentProfile.meta.description || agentProfile.personaDescription || undefined;
16
+
17
+ // Extract image from meta
18
+ const image = agentProfile.meta.image;
19
+
20
+ return {
21
+ title,
22
+ description,
23
+ openGraph: {
24
+ title,
25
+ description,
26
+ type: 'website',
27
+ images: image ? [{ url: image }] : undefined,
28
+ },
29
+ twitter: {
30
+ card: 'summary_large_image',
31
+ title,
32
+ description,
33
+ images: image ? [image] : undefined,
34
+ },
35
+ };
36
+ } catch (error) {
37
+ console.warn(`Failed to generate metadata for agent ${agentName}`, error);
38
+ return {
39
+ title: agentName,
40
+ };
41
+ }
42
+ }