@promptbook/cli 0.103.0-47 → 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 (133) 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 -18
  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 +6 -7
  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} +6 -8
  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 +111 -108
  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 -7
  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 +29 -0
  55. package/apps/agents-server/src/{supabase/getSupabaseForBrowser.ts → database/$provideSupabaseForBrowser.ts} +9 -5
  56. package/apps/agents-server/src/{supabase/getSupabaseForServer.ts → database/$provideSupabaseForServer.ts} +7 -7
  57. package/apps/agents-server/src/{supabase/getSupabaseForWorker.ts → database/$provideSupabaseForWorker.ts} +5 -4
  58. package/apps/agents-server/src/database/getMetadata.ts +31 -0
  59. package/apps/agents-server/src/database/metadataDefaults.ts +32 -0
  60. package/apps/agents-server/src/database/schema.sql +179 -0
  61. package/apps/agents-server/src/database/schema.ts +251 -0
  62. package/apps/agents-server/src/middleware.ts +162 -0
  63. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +14 -10
  64. package/apps/agents-server/src/tools/$provideCdnForServer.ts +1 -1
  65. package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +11 -13
  66. package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +7 -7
  67. package/apps/agents-server/src/tools/$provideServer.ts +39 -0
  68. package/apps/agents-server/src/utils/auth.ts +33 -0
  69. package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +2 -1
  70. package/apps/agents-server/src/utils/cdn/utils/nameToSubfolderPath.ts +1 -1
  71. package/apps/agents-server/src/utils/getCurrentUser.ts +32 -0
  72. package/apps/agents-server/src/utils/isIpAllowed.ts +101 -0
  73. package/apps/agents-server/src/utils/isUserAdmin.ts +31 -0
  74. package/apps/agents-server/src/utils/session.ts +50 -0
  75. package/apps/agents-server/tailwind.config.ts +2 -0
  76. package/esm/index.es.js +310 -49
  77. package/esm/index.es.js.map +1 -1
  78. package/esm/typings/servers.d.ts +1 -0
  79. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  80. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  81. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  82. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +17 -3
  83. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
  84. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
  85. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
  86. package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
  87. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
  88. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
  89. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
  90. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +14 -8
  91. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
  92. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
  93. package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +28 -0
  94. package/esm/typings/src/commitments/index.d.ts +2 -1
  95. package/esm/typings/src/config.d.ts +1 -0
  96. package/esm/typings/src/errors/DatabaseError.d.ts +2 -2
  97. package/esm/typings/src/errors/WrappedError.d.ts +2 -2
  98. package/esm/typings/src/execution/ExecutionTask.d.ts +2 -2
  99. package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -1
  100. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
  101. package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
  102. package/esm/typings/src/llm-providers/agent/Agent.d.ts +17 -4
  103. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +10 -1
  104. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +6 -2
  105. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +30 -4
  106. package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
  107. package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
  108. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  109. package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
  110. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  111. package/esm/typings/src/utils/color/Color.d.ts +7 -0
  112. package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
  113. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
  114. package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
  115. package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
  116. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
  117. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
  118. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
  119. package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
  120. package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
  121. package/esm/typings/src/utils/organization/$side_effect.d.ts +2 -2
  122. package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
  123. package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
  124. package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
  125. package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
  126. package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
  127. package/esm/typings/src/version.d.ts +1 -1
  128. package/package.json +1 -1
  129. package/umd/index.umd.js +311 -50
  130. package/umd/index.umd.js.map +1 -1
  131. package/apps/agents-server/config.ts.todo +0 -312
  132. package/apps/agents-server/src/supabase/TODO.txt +0 -1
  133. package/apps/agents-server/src/supabase/getSupabase.ts +0 -25
@@ -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);
@@ -18,7 +18,7 @@ export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorW
18
18
  // Debounce timer ref so we can clear previous pending save
19
19
  const debounceTimerRef = useRef<number | null>(null);
20
20
  // Configurable debounce delay (ms) - tweak if needed
21
- const DEBOUNCE_DELAY = 600;
21
+ const DEBOUNCE_DELAY = 1000;
22
22
 
23
23
  const performSave = async (sourceToSave: string_book) => {
24
24
  setSaveStatus('saving');
@@ -88,6 +88,7 @@ export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorW
88
88
 
89
89
  <BookEditor
90
90
  className="w-full h-full"
91
+ isBorderRadiusDisabled
91
92
  height={null}
92
93
  value={agentSource}
93
94
  onChange={handleChange}
@@ -125,16 +126,14 @@ export function BookEditorWrapper({ agentName, initialAgentSource }: BookEditorW
125
126
 
126
127
  return shortFileUrl;
127
128
  }}
128
- // <- TODO: !!!! Create two-state solution for `<BookEditor onFileUpload={...} />`
129
129
  />
130
130
  </div>
131
131
  );
132
132
  }
133
133
 
134
134
  /**
135
+ * TODO: Prompt: Use `import { debounce } from '@promptbook-local/utils';` instead of custom debounce implementation
135
136
  * TODO: [🚗] Transfer the saving logic to `<BookEditor/>` be aware of CRDT / yjs approach to be implementable in future
136
- * DONE: Implement debouncing for auto-save (600ms delay)
137
- * TODO: !!! Add error handling and retry logic
138
- * TODO: !!! Show save status indicator
139
- * TODO: !!!!! Add file upload capability
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,
@@ -84,8 +84,6 @@ export function AgentBookAndChatComponent() {
84
84
  return agent;
85
85
  }, [agentSource, setAgentSource, apiKey]);
86
86
 
87
-
88
-
89
87
  return (
90
88
  <div className="min-h-screen relative">
91
89
  {/* Floating API Key Configuration */}
@@ -139,17 +137,17 @@ export function AgentBookAndChatComponent() {
139
137
  <ResizablePanelsAuto name="two-editors">
140
138
  <BookEditor
141
139
  className="w-full h-full"
140
+ isBorderRadiusDisabled
142
141
  height={null}
143
142
  value={agentSource}
144
143
  onChange={setAgentSource}
145
144
  // className={styles.BookEditor}
146
145
  isVerbose={false}
147
- isBorderRadiusDisabled
148
146
  onFileUpload={(file) => {
149
147
  return file.name;
150
148
  }}
151
149
  />
152
-
150
+
153
151
  <AgentChat className={`h-full flex flex-col`} {...{ agent }} />
154
152
  </ResizablePanelsAuto>
155
153
  </div>
@@ -157,6 +155,6 @@ export function AgentBookAndChatComponent() {
157
155
  }
158
156
 
159
157
  /**
160
- * TODO: !!!! Make self-learning book createAgentLlmExecutionTools, use bidirectional agentSource
158
+ * TODO: [🐱‍🚀] Make self-learning book createAgentLlmExecutionTools, use bidirectional agentSource
161
159
  * TODO: [🚗] Components and pages here should be just tiny UI wraper around proper agent logic and conponents
162
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
+ }