@promptbook/cli 0.103.0-44 → 0.103.0-46
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/README.md +3 -0
- package/apps/agents-server/TODO.txt +6 -0
- package/apps/agents-server/config.ts.todo +312 -0
- package/apps/agents-server/next.config.ts +42 -0
- package/apps/agents-server/package.json +11 -0
- package/apps/agents-server/postcss.config.mjs +8 -0
- package/apps/agents-server/public/.gitkeep +0 -0
- package/apps/agents-server/public/favicon.ico +0 -0
- package/apps/agents-server/public/logo-blue-white-256.png +0 -0
- package/apps/agents-server/src/app/AddAgentButton.tsx +20 -0
- package/apps/agents-server/src/app/actions.ts +14 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentUrlCopy.tsx +41 -0
- package/apps/agents-server/src/app/agents/[agentName]/TODO.txt +1 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +86 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/test.http +37 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +60 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +74 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +21 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/SelfLearningBook.tsx +203 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +18 -0
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +160 -0
- package/apps/agents-server/src/app/api/chat/route.ts +32 -0
- package/apps/agents-server/src/app/api/chat-streaming/route.ts +44 -0
- package/apps/agents-server/src/app/api/long-running-task/route.ts +7 -0
- package/apps/agents-server/src/app/api/long-streaming/route.ts +20 -0
- package/apps/agents-server/src/app/globals.css +113 -0
- package/apps/agents-server/src/app/layout.tsx +72 -0
- package/apps/agents-server/src/app/page.tsx +115 -0
- package/apps/agents-server/src/deamons/longRunningTask.ts +37 -0
- package/apps/agents-server/src/supabase/TODO.txt +1 -0
- package/apps/agents-server/src/supabase/getSupabase.ts +25 -0
- package/apps/agents-server/src/supabase/getSupabaseForBrowser.ts +37 -0
- package/apps/agents-server/src/supabase/getSupabaseForServer.ts +48 -0
- package/apps/agents-server/src/supabase/getSupabaseForWorker.ts +42 -0
- package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +49 -0
- package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +110 -0
- package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +35 -0
- package/apps/agents-server/tailwind.config.ts +24 -0
- package/apps/agents-server/tsconfig.json +29 -0
- package/esm/index.es.js +40 -6
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +2 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +4 -0
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +2 -0
- package/esm/typings/src/execution/utils/validatePromptResult.d.ts +2 -0
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +2 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +3 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +2 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +40 -6
- package/umd/index.umd.js.map +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
@import 'tailwindcss/base';
|
|
2
|
+
@import 'tailwindcss/components';
|
|
3
|
+
@import 'tailwindcss/utilities';
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
--background: #ffffff;
|
|
7
|
+
--foreground: #171717;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root {
|
|
12
|
+
--background: #0a0a0a;
|
|
13
|
+
--foreground: #ededed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
body {
|
|
18
|
+
background: var(--background);
|
|
19
|
+
color: var(--foreground);
|
|
20
|
+
font-family: 'Barlow Condensed', Arial, Helvetica, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* Custom utilities */
|
|
24
|
+
.line-clamp-2 {
|
|
25
|
+
display: -webkit-box;
|
|
26
|
+
-webkit-line-clamp: 2;
|
|
27
|
+
line-clamp: 2;
|
|
28
|
+
-webkit-box-orient: vertical;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.line-clamp-3 {
|
|
33
|
+
display: -webkit-box;
|
|
34
|
+
-webkit-line-clamp: 3;
|
|
35
|
+
line-clamp: 3;
|
|
36
|
+
-webkit-box-orient: vertical;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Mermaid diagram styling */
|
|
41
|
+
.mermaid-container {
|
|
42
|
+
display: flex;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.mermaid-container svg {
|
|
48
|
+
max-width: 100%;
|
|
49
|
+
height: auto;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Code block styling */
|
|
53
|
+
pre code {
|
|
54
|
+
font-family: var(--font-mono), 'Courier New', monospace;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Smooth transitions */
|
|
58
|
+
* {
|
|
59
|
+
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow,
|
|
60
|
+
transform, filter, backdrop-filter;
|
|
61
|
+
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
62
|
+
transition-duration: 150ms;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Focus styles */
|
|
66
|
+
button:focus-visible,
|
|
67
|
+
a:focus-visible,
|
|
68
|
+
input:focus-visible,
|
|
69
|
+
textarea:focus-visible {
|
|
70
|
+
outline: 2px solid #3b82f6;
|
|
71
|
+
outline-offset: 2px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Custom scrollbar */
|
|
75
|
+
::-webkit-scrollbar {
|
|
76
|
+
width: 8px;
|
|
77
|
+
height: 8px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
::-webkit-scrollbar-track {
|
|
81
|
+
background: #f1f5f9;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
::-webkit-scrollbar-thumb {
|
|
85
|
+
background: #cbd5e1;
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
::-webkit-scrollbar-thumb:hover {
|
|
90
|
+
background: #94a3b8;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Loading animation */
|
|
94
|
+
@keyframes spin {
|
|
95
|
+
to {
|
|
96
|
+
transform: rotate(360deg);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.animate-spin {
|
|
101
|
+
animation: spin 1s linear infinite;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Gradient backgrounds */
|
|
105
|
+
.bg-gradient-to-br {
|
|
106
|
+
background-image: linear-gradient(to bottom right, var(--tw-gradient-stops));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Component preview container */
|
|
110
|
+
.component-preview {
|
|
111
|
+
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
|
|
112
|
+
border: 1px solid #e2e8f0;
|
|
113
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import faviconLogoImage from '@/public/favicon.ico';
|
|
2
|
+
import type { Metadata } from 'next';
|
|
3
|
+
import { Barlow_Condensed } from 'next/font/google';
|
|
4
|
+
import './globals.css';
|
|
5
|
+
|
|
6
|
+
const barlowCondensed = Barlow_Condensed({
|
|
7
|
+
subsets: ['latin'],
|
|
8
|
+
weight: ['300', '400', '500', '600', '700'],
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const metadata: Metadata = {
|
|
12
|
+
title: 'Promptbook agents server',
|
|
13
|
+
description: '@@@',
|
|
14
|
+
keywords: ['@@@'],
|
|
15
|
+
authors: [{ name: 'Promptbook Team' }],
|
|
16
|
+
openGraph: {
|
|
17
|
+
title: 'Promptbook agents server',
|
|
18
|
+
description: '@@@',
|
|
19
|
+
type: 'website',
|
|
20
|
+
images: [
|
|
21
|
+
/*
|
|
22
|
+
TODO:
|
|
23
|
+
{
|
|
24
|
+
url: 'https://www.ptbk.io/design',
|
|
25
|
+
width: 1200,
|
|
26
|
+
height: 630,
|
|
27
|
+
alt: 'Promptbook agents server',
|
|
28
|
+
},
|
|
29
|
+
*/
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
twitter: {
|
|
33
|
+
card: 'summary_large_image',
|
|
34
|
+
title: 'Promptbook agents server',
|
|
35
|
+
description: '@@@',
|
|
36
|
+
// TODO: images: ['https://www.ptbk.io/design'],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default function RootLayout({
|
|
41
|
+
children,
|
|
42
|
+
}: Readonly<{
|
|
43
|
+
children: React.ReactNode;
|
|
44
|
+
}>) {
|
|
45
|
+
return (
|
|
46
|
+
<html lang="en">
|
|
47
|
+
<head>
|
|
48
|
+
{/* Favicon for light mode */}
|
|
49
|
+
{/*
|
|
50
|
+
<link
|
|
51
|
+
rel="icon"
|
|
52
|
+
href="https://www.ptbk.io/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Flogo-blue-transparent-256.493b7e49.png&w=64&q=75"
|
|
53
|
+
media="(prefers-color-scheme: light)"
|
|
54
|
+
type="image/svg+xml"
|
|
55
|
+
/>
|
|
56
|
+
*/}
|
|
57
|
+
{/* Favicon for dark mode */}
|
|
58
|
+
{/*
|
|
59
|
+
<link
|
|
60
|
+
rel="icon"
|
|
61
|
+
href="https://www.ptbk.io/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Flogo-blue-transparent-256.493b7e49.png&w=64&q=75"
|
|
62
|
+
media="(prefers-color-scheme: dark)"
|
|
63
|
+
type="image/svg+xml"
|
|
64
|
+
/>
|
|
65
|
+
*/}
|
|
66
|
+
{/* Default favicon as a fallback */}
|
|
67
|
+
<link rel="icon" href={faviconLogoImage.src} type="image/x-icon" />
|
|
68
|
+
</head>
|
|
69
|
+
<body className={`${barlowCondensed.className} antialiased bg-white text-gray-900`}>{children}</body>
|
|
70
|
+
</html>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import logoImage from '@/public/logo-blue-white-256.png';
|
|
4
|
+
import { getSingleLlmExecutionTools } from '@promptbook-local/core';
|
|
5
|
+
import moment from 'moment';
|
|
6
|
+
import { headers } from 'next/headers';
|
|
7
|
+
import Image from 'next/image';
|
|
8
|
+
import Link from 'next/link';
|
|
9
|
+
import { AvatarProfile } from '../../../../src/book-components/AvatarProfile/AvatarProfile/AvatarProfile';
|
|
10
|
+
import { AboutPromptbookInformation } from '../../../../src/utils/misc/xAboutPromptbookInformation';
|
|
11
|
+
import { $sideEffect } from '../../../../src/utils/organization/$sideEffect';
|
|
12
|
+
import { getLongRunningTask } from '../deamons/longRunningTask';
|
|
13
|
+
import { $provideAgentCollectionForServer } from '../tools/$provideAgentCollectionForServer';
|
|
14
|
+
import { $provideExecutionToolsForServer } from '../tools/$provideExecutionToolsForServer';
|
|
15
|
+
import { AddAgentButton } from './AddAgentButton';
|
|
16
|
+
|
|
17
|
+
// Add calendar formats that include seconds
|
|
18
|
+
const calendarWithSeconds = {
|
|
19
|
+
sameDay: '[Today at] LTS',
|
|
20
|
+
nextDay: '[Tomorrow at] LTS',
|
|
21
|
+
nextWeek: 'dddd [at] LTS',
|
|
22
|
+
lastDay: '[Yesterday at] LTS',
|
|
23
|
+
lastWeek: '[Last] dddd [at] LTS',
|
|
24
|
+
sameElse: 'L [at] LTS',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default async function HomePage() {
|
|
28
|
+
$sideEffect(/* Note: [🐶] This will ensure dynamic rendering of page and avoid Next.js pre-render */ headers());
|
|
29
|
+
|
|
30
|
+
const collection = await $provideAgentCollectionForServer();
|
|
31
|
+
const agents = await collection.listAgents();
|
|
32
|
+
|
|
33
|
+
const longRunningTask = getLongRunningTask();
|
|
34
|
+
|
|
35
|
+
const executionTools = await $provideExecutionToolsForServer();
|
|
36
|
+
const models = await getSingleLlmExecutionTools(executionTools.llm).listModels();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
|
40
|
+
<div className="container mx-auto px-4 py-16">
|
|
41
|
+
<h1 className="text-4xl font-bold text-gray-900 mb-4">
|
|
42
|
+
<Image src={logoImage} alt="Promptbook Logo" height={50} className="inline-block mr-4" />
|
|
43
|
+
Promptbook Agents Server
|
|
44
|
+
</h1>
|
|
45
|
+
|
|
46
|
+
<>
|
|
47
|
+
<h2 className="text-3xl text-gray-900 mt-16 mb-4">Agents ({agents.length})</h2>
|
|
48
|
+
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
49
|
+
{agents.map((agent) => (
|
|
50
|
+
<Link key={agent.agentName} href={`/agents/${agent.agentName}`}>
|
|
51
|
+
<AvatarProfile
|
|
52
|
+
{...{ agent }}
|
|
53
|
+
style={
|
|
54
|
+
!agent.meta.color
|
|
55
|
+
? {}
|
|
56
|
+
: {
|
|
57
|
+
backgroundColor: `${agent.meta.color}22`, // <- TODO: Use Color object here
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
className="block p-6 bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 border border-gray-200 hover:border-blue-400"
|
|
61
|
+
/>
|
|
62
|
+
</Link>
|
|
63
|
+
))}
|
|
64
|
+
<AddAgentButton />
|
|
65
|
+
</div>
|
|
66
|
+
</>
|
|
67
|
+
|
|
68
|
+
<>
|
|
69
|
+
<h2 className="text-3xl text-gray-900 mt-16 mb-4">Models ({models.length})</h2>
|
|
70
|
+
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
71
|
+
{models.map(({ modelName, modelTitle, modelDescription }) => (
|
|
72
|
+
<Link key={modelName} href={`#!!!`}>
|
|
73
|
+
<div className="block p-6 bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 border border-gray-200 hover:border-blue-400">
|
|
74
|
+
<h2 className="text-2xl font-semibold text-gray-900 mb-2">{modelTitle}</h2>
|
|
75
|
+
<code>{modelName}</code>
|
|
76
|
+
<p className="text-gray-600">{modelDescription}</p>
|
|
77
|
+
</div>
|
|
78
|
+
</Link>
|
|
79
|
+
))}
|
|
80
|
+
</div>
|
|
81
|
+
</>
|
|
82
|
+
|
|
83
|
+
<>
|
|
84
|
+
<h2 className="text-3xl text-gray-900 mt-16 mb-4">About</h2>
|
|
85
|
+
<AboutPromptbookInformation />
|
|
86
|
+
</>
|
|
87
|
+
|
|
88
|
+
<>
|
|
89
|
+
<h2 className="text-3xl text-gray-900 mt-16 mb-4">Technical Information</h2>
|
|
90
|
+
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
91
|
+
<Link
|
|
92
|
+
href={'#'}
|
|
93
|
+
className="block p-6 bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 border border-gray-200 hover:border-blue-400"
|
|
94
|
+
>
|
|
95
|
+
<h2 className="text-2xl font-semibold text-gray-900 mb-2">
|
|
96
|
+
Long running task {longRunningTask.taskId}
|
|
97
|
+
</h2>
|
|
98
|
+
<p className="text-gray-600">Tick: {longRunningTask.tick}</p>
|
|
99
|
+
<p className="text-gray-600">
|
|
100
|
+
Created At: {moment(longRunningTask.createdAt).calendar(undefined, calendarWithSeconds)}
|
|
101
|
+
</p>
|
|
102
|
+
<p className="text-gray-600">
|
|
103
|
+
Updated At: {moment(longRunningTask.updatedAt).calendar(undefined, calendarWithSeconds)}
|
|
104
|
+
</p>
|
|
105
|
+
</Link>
|
|
106
|
+
</div>
|
|
107
|
+
</>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* TODO: [🕋] Use here `AboutPromptbookInformation`
|
|
115
|
+
*/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { forTime } from 'waitasecond';
|
|
2
|
+
import { just } from '../../../../src/utils/organization/just';
|
|
3
|
+
import { $randomToken } from '../../../../src/utils/random/$randomToken';
|
|
4
|
+
|
|
5
|
+
let longRunningTask: {
|
|
6
|
+
taskId: string;
|
|
7
|
+
tick: number;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
} | null = null;
|
|
11
|
+
|
|
12
|
+
export function getLongRunningTask() {
|
|
13
|
+
if (longRunningTask !== null) {
|
|
14
|
+
return longRunningTask;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const taskId = $randomToken(8);
|
|
18
|
+
let tick = 0;
|
|
19
|
+
|
|
20
|
+
longRunningTask = {
|
|
21
|
+
taskId,
|
|
22
|
+
tick,
|
|
23
|
+
createdAt: new Date(),
|
|
24
|
+
updatedAt: new Date(),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
(async () => {
|
|
28
|
+
while (just(true)) {
|
|
29
|
+
await forTime(1000);
|
|
30
|
+
// console.log(`Long running task ${taskId} tick ${tick}`);
|
|
31
|
+
longRunningTask.updatedAt = new Date();
|
|
32
|
+
longRunningTask.tick = ++tick;
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
return longRunningTask;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TODO: !!!! Rename all to $provide...
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentsDatabaseSchema } from '@promptbook-local/types';
|
|
2
|
+
import { $isRunningInBrowser, $isRunningInNode, $isRunningInWebWorker } from '@promptbook-local/utils';
|
|
3
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
+
import { getSupabaseForBrowser } from './getSupabaseForBrowser';
|
|
5
|
+
import { getSupabaseForServer } from './getSupabaseForServer';
|
|
6
|
+
import { getSupabaseForWorker } from './getSupabaseForWorker';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get supabase client in any environment
|
|
10
|
+
*
|
|
11
|
+
* Note: The client is cached, so it's safe to call this function multiple times
|
|
12
|
+
*
|
|
13
|
+
* @returns instance of supabase client
|
|
14
|
+
*/
|
|
15
|
+
export function getSupabase(): SupabaseClient<AgentsDatabaseSchema> {
|
|
16
|
+
if ($isRunningInNode()) {
|
|
17
|
+
return getSupabaseForServer();
|
|
18
|
+
} else if ($isRunningInBrowser()) {
|
|
19
|
+
return getSupabaseForBrowser();
|
|
20
|
+
} else if ($isRunningInWebWorker()) {
|
|
21
|
+
return getSupabaseForWorker();
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error('Unknown environment, cannot determine how to get Supabase client');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
+
import { AgentsDatabaseSchema } from '@promptbook-local/types';
|
|
3
|
+
import { $isRunningInBrowser } from '@promptbook-local/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal cache for `getSupabaseForBrowser`
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
* @singleton
|
|
10
|
+
*/
|
|
11
|
+
let supabase: SupabaseClient<AgentsDatabaseSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get supabase client
|
|
15
|
+
*
|
|
16
|
+
* Note: The client is cached, so it's safe to call this function multiple times
|
|
17
|
+
* Note: This function is available ONLY in browser, use getSupabaseForServer in node
|
|
18
|
+
*
|
|
19
|
+
* @returns instance of supabase client
|
|
20
|
+
*/
|
|
21
|
+
export function getSupabaseForBrowser(): typeof supabase {
|
|
22
|
+
if (!$isRunningInBrowser()) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Function `getSupabaseForBrowser` can not be used on server or worker, use `getSupabaseForServer` or `getSupabaseForWorker` instead.',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!supabase) {
|
|
29
|
+
// Create a single supabase client for interacting with your database
|
|
30
|
+
supabase = createClient<AgentsDatabaseSchema>(
|
|
31
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
32
|
+
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return supabase;
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AgentsDatabaseSchema } from '@promptbook-local/types';
|
|
2
|
+
import { $isRunningInNode } from '@promptbook-local/utils';
|
|
3
|
+
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal cache for `getSupabaseForServer`
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
* @singleton
|
|
10
|
+
*/
|
|
11
|
+
let supabase: SupabaseClient<AgentsDatabaseSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get supabase client
|
|
15
|
+
*
|
|
16
|
+
* Note: The client is cached, so it's safe to call this function multiple times
|
|
17
|
+
* Note: This function is available ONLY on server/node, use getSupabaseForClient in browser
|
|
18
|
+
*
|
|
19
|
+
* @returns instance of supabase client
|
|
20
|
+
*/
|
|
21
|
+
export function getSupabaseForServer(): typeof supabase {
|
|
22
|
+
if (!$isRunningInNode()) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Function `getSupabaseForServer` can not be used in browser, use `getSupabaseForBrowser` instead.',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!supabase) {
|
|
29
|
+
// Create a single supabase client for interacting with your database
|
|
30
|
+
supabase = createClient<AgentsDatabaseSchema>(
|
|
31
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
32
|
+
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
|
33
|
+
{
|
|
34
|
+
auth: {
|
|
35
|
+
autoRefreshToken: false,
|
|
36
|
+
persistSession: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
// Access auth admin api
|
|
44
|
+
const adminAuthClient = supabase.auth.admin;
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
return supabase;
|
|
48
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AgentsDatabaseSchema } from '@promptbook-local/types';
|
|
2
|
+
import { $isRunningInWebWorker } from '@promptbook-local/utils';
|
|
3
|
+
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal cache for `getSupabaseForWorker`
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
* @singleton
|
|
10
|
+
*/
|
|
11
|
+
let supabase: SupabaseClient<AgentsDatabaseSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get supabase client
|
|
15
|
+
*
|
|
16
|
+
* Note: The client is cached, so it's safe to call this function multiple times
|
|
17
|
+
* Note: This function is available ONLY in worker, use getSupabaseForBrowser for main thread
|
|
18
|
+
*
|
|
19
|
+
* @returns instance of supabase client
|
|
20
|
+
*/
|
|
21
|
+
export function getSupabaseForWorker(): typeof supabase {
|
|
22
|
+
if (!$isRunningInWebWorker) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'Function `getSupabaseForWorker` can not be used in browser, use `getSupabaseForBrowser` instead.',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!supabase) {
|
|
29
|
+
// Create a single supabase client for interacting with your database
|
|
30
|
+
supabase = createClient<AgentsDatabaseSchema>(
|
|
31
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
32
|
+
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return supabase;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* TODO: Fix> No storage option exists to persist the session, which may result in unexpected behavior when using auth.
|
|
41
|
+
If you want to set persistSession to true, please provide a storage option or you may set persistSession to false to disable this warning.
|
|
42
|
+
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { AgentCollectionInSupabase } from '@promptbook-local/core';
|
|
4
|
+
import { AgentCollection } from '@promptbook-local/types';
|
|
5
|
+
import { getSupabaseForServer } from '../supabase/getSupabaseForServer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache of provided agent collection
|
|
9
|
+
* @private internal cache for `$provideAgentCollectionForServer`
|
|
10
|
+
*/
|
|
11
|
+
let agentCollection: null | AgentCollection = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* !!!!
|
|
15
|
+
*/
|
|
16
|
+
export async function $provideAgentCollectionForServer(): Promise<AgentCollection> {
|
|
17
|
+
// <- Note: This function is potentially async
|
|
18
|
+
|
|
19
|
+
// TODO: !!!! [🌕] DRY
|
|
20
|
+
|
|
21
|
+
const isVerbose = true; // <- TODO: !!!! Pass
|
|
22
|
+
|
|
23
|
+
if (agentCollection !== null) {
|
|
24
|
+
console.log('!!! Returning cached agent collection');
|
|
25
|
+
return agentCollection;
|
|
26
|
+
// TODO: !!!! Be aware of options changes
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log('!!! Creating NEW agent collection');
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
// TODO: [🧟♂️][◽] DRY:
|
|
33
|
+
const collection = new AgentCollectionInDirectory(path, tools, {
|
|
34
|
+
isVerbose,
|
|
35
|
+
isRecursive: true,
|
|
36
|
+
isLazyLoaded: false,
|
|
37
|
+
isCrashedOnError: true,
|
|
38
|
+
// <- TODO: [🍖] Add `intermediateFilesStrategy`
|
|
39
|
+
});
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
const supabase = getSupabaseForServer();
|
|
43
|
+
|
|
44
|
+
agentCollection = new AgentCollectionInSupabase(supabase, {
|
|
45
|
+
isVerbose,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return agentCollection;
|
|
49
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
_AnthropicClaudeMetadataRegistration,
|
|
5
|
+
_AzureOpenAiMetadataRegistration,
|
|
6
|
+
_BoilerplateScraperMetadataRegistration,
|
|
7
|
+
_DeepseekMetadataRegistration,
|
|
8
|
+
_DocumentScraperMetadataRegistration,
|
|
9
|
+
_GoogleMetadataRegistration,
|
|
10
|
+
_LegacyDocumentScraperMetadataRegistration,
|
|
11
|
+
_MarkdownScraperMetadataRegistration,
|
|
12
|
+
_MarkitdownScraperMetadataRegistration,
|
|
13
|
+
_OllamaMetadataRegistration,
|
|
14
|
+
_OpenAiAssistantMetadataRegistration,
|
|
15
|
+
_OpenAiCompatibleMetadataRegistration,
|
|
16
|
+
_OpenAiMetadataRegistration,
|
|
17
|
+
_PdfScraperMetadataRegistration,
|
|
18
|
+
_WebsiteScraperMetadataRegistration,
|
|
19
|
+
} from '@promptbook-local/core';
|
|
20
|
+
import { _GoogleRegistration } from '@promptbook-local/google';
|
|
21
|
+
import { _OpenAiRegistration } from '@promptbook-local/openai';
|
|
22
|
+
import { ExecutionTools, TODO_any } from '@promptbook-local/types';
|
|
23
|
+
import { $provideLlmToolsForCli } from '../../../../src/cli/common/$provideLlmToolsForCli';
|
|
24
|
+
import { $provideExecutablesForNode } from '../../../../src/executables/$provideExecutablesForNode';
|
|
25
|
+
import { $provideFilesystemForNode } from '../../../../src/scrapers/_common/register/$provideFilesystemForNode';
|
|
26
|
+
import { $provideScrapersForNode } from '../../../../src/scrapers/_common/register/$provideScrapersForNode';
|
|
27
|
+
import { $provideScriptingForNode } from '../../../../src/scrapers/_common/register/$provideScriptingForNode';
|
|
28
|
+
import { $sideEffect } from '../../../../src/utils/organization/$sideEffect';
|
|
29
|
+
|
|
30
|
+
$sideEffect(
|
|
31
|
+
_AnthropicClaudeMetadataRegistration,
|
|
32
|
+
_AzureOpenAiMetadataRegistration,
|
|
33
|
+
_DeepseekMetadataRegistration,
|
|
34
|
+
_GoogleMetadataRegistration,
|
|
35
|
+
_OllamaMetadataRegistration,
|
|
36
|
+
_OpenAiMetadataRegistration,
|
|
37
|
+
_OpenAiAssistantMetadataRegistration,
|
|
38
|
+
_OpenAiCompatibleMetadataRegistration,
|
|
39
|
+
_BoilerplateScraperMetadataRegistration,
|
|
40
|
+
_LegacyDocumentScraperMetadataRegistration,
|
|
41
|
+
_DocumentScraperMetadataRegistration,
|
|
42
|
+
_MarkdownScraperMetadataRegistration,
|
|
43
|
+
_MarkitdownScraperMetadataRegistration,
|
|
44
|
+
_PdfScraperMetadataRegistration,
|
|
45
|
+
_WebsiteScraperMetadataRegistration,
|
|
46
|
+
// <- TODO: !!! Export all registrations from one variabile in `@promptbook/core`
|
|
47
|
+
);
|
|
48
|
+
$sideEffect(/* [㊗] */ _OpenAiRegistration);
|
|
49
|
+
$sideEffect(/* [㊗] */ _GoogleRegistration);
|
|
50
|
+
// <- TODO: !!!! Allow to dynamically install required metadata
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Cache of provided execution tools
|
|
54
|
+
*
|
|
55
|
+
* @private internal cache for `$provideExecutionToolsForServer`
|
|
56
|
+
*/
|
|
57
|
+
let executionTools: null | ExecutionTools = null;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
TODO: [▶️]
|
|
63
|
+
type ProvideExecutionToolsForServerOptions = {
|
|
64
|
+
isLlmProvided
|
|
65
|
+
}
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* !!!!
|
|
70
|
+
*/
|
|
71
|
+
export async function $provideExecutionToolsForServer(): Promise<ExecutionTools> {
|
|
72
|
+
// TODO: !!!! [🌕] DRY
|
|
73
|
+
|
|
74
|
+
// const path = '../../agents'; // <- TODO: !!!! Pass
|
|
75
|
+
const isVerbose = true; // <- TODO: !!!! Pass
|
|
76
|
+
const isCacheReloaded = false; // <- TODO: !!!! Pass
|
|
77
|
+
const cliOptions = {
|
|
78
|
+
provider: 'BRING_YOUR_OWN_KEYS',
|
|
79
|
+
} as TODO_any; // <- TODO: !!!! Pass
|
|
80
|
+
|
|
81
|
+
if (executionTools !== null) {
|
|
82
|
+
console.log('!!! Returning cached execution tools');
|
|
83
|
+
return executionTools;
|
|
84
|
+
// TODO: !!!! Be aware of options changes
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log('!!! Creating NEW execution tools');
|
|
88
|
+
|
|
89
|
+
// TODO: DRY [◽]
|
|
90
|
+
const prepareAndScrapeOptions = {
|
|
91
|
+
isVerbose,
|
|
92
|
+
isCacheReloaded,
|
|
93
|
+
}; /* <- TODO: ` satisfies PrepareAndScrapeOptions` */
|
|
94
|
+
const fs = await $provideFilesystemForNode(prepareAndScrapeOptions);
|
|
95
|
+
const { /* [0] strategy,*/ llm } = await $provideLlmToolsForCli({
|
|
96
|
+
cliOptions,
|
|
97
|
+
...prepareAndScrapeOptions,
|
|
98
|
+
});
|
|
99
|
+
const executables = await $provideExecutablesForNode(prepareAndScrapeOptions);
|
|
100
|
+
|
|
101
|
+
executionTools = {
|
|
102
|
+
llm,
|
|
103
|
+
fs,
|
|
104
|
+
executables,
|
|
105
|
+
scrapers: await $provideScrapersForNode({ fs, llm, executables }, prepareAndScrapeOptions),
|
|
106
|
+
script: await $provideScriptingForNode(prepareAndScrapeOptions),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return executionTools;
|
|
110
|
+
}
|