@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,6 @@
|
|
|
1
|
+
TODO: !!!! Tests of this should be in main testing pipeline
|
|
2
|
+
TODO: !!!! Make the agents live here
|
|
3
|
+
TODO: !!!! Publish `agents-server` this as Docker container
|
|
4
|
+
TODO: !!!! Publish `@promptbook/agents-server` to npm
|
|
5
|
+
TODO: !!!! Work `ptbk start-pipelines-server` / `ptbk start-agents-server` CLI command to start this server
|
|
6
|
+
TODO: [🧠][🚙] `AgentXxx` vs `AgentsXxx` naming convention
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// TODO: Use or remove this file:
|
|
2
|
+
|
|
3
|
+
import { CLI_APP_ID } from '@promptbook/core';
|
|
4
|
+
import { string_app_id } from '@promptbook/types';
|
|
5
|
+
import { spaceTrim } from '@promptbook/utils';
|
|
6
|
+
import { ConfigChecker } from 'configchecker';
|
|
7
|
+
import type { DallePrompt } from './src/ai/text-to-image/dalle/interfaces/DallePrompt';
|
|
8
|
+
import { validateAgentSource } from './src/book-2.0/agent-source/string_agent_source';
|
|
9
|
+
import { maxdown } from './src/components/Content/Maxdown/maxdown';
|
|
10
|
+
import type { LightModeDarkMode } from './src/components/LightModeDarkMode/utils/LightModeDarkMode';
|
|
11
|
+
import { DigitalOceanSpaces } from './src/utils/cdn/classes/DigitalOceanSpaces';
|
|
12
|
+
import type { BrjappOptions } from './src/utils/client/BrjappConnector';
|
|
13
|
+
import { validateUserId } from './src/utils/client/validateUserId';
|
|
14
|
+
import { validateDomain } from './src/utils/domains/validateDomain';
|
|
15
|
+
import type { EmailAddress } from './src/utils/emails/Email';
|
|
16
|
+
import { parseEmailAddress } from './src/utils/emails/utils/parseEmailAddress';
|
|
17
|
+
import { isRunningInBrowser } from './src/utils/isRunningInWhatever';
|
|
18
|
+
import type { string_char_emoji } from './src/utils/typeAliasEmoji';
|
|
19
|
+
import type { string_domain, string_maxdown, string_name } from './src/utils/typeAliases';
|
|
20
|
+
import { isUrlOnPrivateNetwork } from './src/utils/validators/isUrlOnPrivateNetwork';
|
|
21
|
+
import { validateUuid } from './src/utils/validators/validateUuid';
|
|
22
|
+
|
|
23
|
+
const config = ConfigChecker.from({
|
|
24
|
+
...process.env,
|
|
25
|
+
|
|
26
|
+
// Note: To expose env variables to the browser, using this seemingly strange syntax:
|
|
27
|
+
// @see https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#exposing-environment-variables-to-the-browser
|
|
28
|
+
NEXT_PUBLIC_URL: process.env.NEXT_PUBLIC_URL,
|
|
29
|
+
NEXT_PUBLIC_VERCEL_BRANCH_URL: process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL,
|
|
30
|
+
NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF,
|
|
31
|
+
NEXT_PUBLIC_PROMPTBOOK_SERVER_URL: process.env.NEXT_PUBLIC_PROMPTBOOK_SERVER_URL,
|
|
32
|
+
NEXT_PUBLIC_IMAGE_SERVER_URL: process.env.NEXT_PUBLIC_IMAGE_SERVER_URL,
|
|
33
|
+
NEXT_PUBLIC_BROWSER_SERVER_URL: process.env.NEXT_PUBLIC_BROWSER_SERVER_URL,
|
|
34
|
+
NEXT_PUBLIC_OUR_DOMAINS: process.env.NEXT_PUBLIC_OUR_DOMAINS,
|
|
35
|
+
NEXT_PUBLIC_SUPABASE_URL: process.env.NEXT_PUBLIC_SUPABASE_URL,
|
|
36
|
+
NEXT_PUBLIC_SUPABASE_ANON_KEY: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
|
37
|
+
|
|
38
|
+
// Auth service environment variables
|
|
39
|
+
NEXT_PUBLIC_FACEBOOK_APP_ID: process.env.NEXT_PUBLIC_FACEBOOK_APP_ID,
|
|
40
|
+
NEXT_PUBLIC_LINKEDIN_CLIENT_ID: process.env.NEXT_PUBLIC_LINKEDIN_CLIENT_ID,
|
|
41
|
+
NEXT_PUBLIC_GITHUB_CLIENT_ID: process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID,
|
|
42
|
+
NEXT_PUBLIC_GOOGLE_CLIENT_ID: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF = config.get('NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF').value;
|
|
46
|
+
|
|
47
|
+
const NEXT_PUBLIC_VERCEL_BRANCH_URL = config.get('NEXT_PUBLIC_VERCEL_BRANCH_URL').value;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* TODO: [🧠] Maybe rename to NEXT_PUBLIC_WEBGPT_URL
|
|
51
|
+
*/
|
|
52
|
+
export const NEXT_PUBLIC_URL = NEXT_PUBLIC_VERCEL_BRANCH_URL
|
|
53
|
+
? NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF === 'main'
|
|
54
|
+
? // Production:
|
|
55
|
+
config.get('NEXT_PUBLIC_URL').url().required().value
|
|
56
|
+
: // Preview branch:
|
|
57
|
+
new URL(`https://${NEXT_PUBLIC_VERCEL_BRANCH_URL}/`)
|
|
58
|
+
: // Local development:
|
|
59
|
+
config.get('NEXT_PUBLIC_URL').url().required().value;
|
|
60
|
+
|
|
61
|
+
export const ADMIN_GITHUB_NAME: string_name = 'hejny';
|
|
62
|
+
export const ADMIN_EMAIL: EmailAddress = parseEmailAddress('pavol@webgpt.cz');
|
|
63
|
+
export const BOT_EMAIL: EmailAddress = parseEmailAddress('bot@bot.webgpt.cz');
|
|
64
|
+
export const RUKA_DOMAIN: string_domain = validateDomain('bot.webgpt.cz');
|
|
65
|
+
export const BOT_SIGNATURE: string_maxdown = maxdown`[✨ ${APP_NAME} Bot](${NEXT_PUBLIC_URL.href})`;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 🌒 Default color mode for Promptbook studio
|
|
69
|
+
*
|
|
70
|
+
* Note: This will be used in rare cases because most of the time system settings will be present
|
|
71
|
+
* Note: Use 🌒 dark mode for promptbook studio and miniapps
|
|
72
|
+
*/
|
|
73
|
+
export const DEFAULT_STUDIO_LIGHT_MODE_DARK_MODE: LightModeDarkMode = 'DARK';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 🌒 Default color mode for miniapps
|
|
77
|
+
*
|
|
78
|
+
* Note: This can be overridden by the miniapp itself
|
|
79
|
+
*/
|
|
80
|
+
export const DEFAULT_MINIAPP_LIGHT_MODE_DARK_MODE: LightModeDarkMode = 'LIGHT';
|
|
81
|
+
|
|
82
|
+
export const USE_DALLE_VERSION: 2 | 3 = 3;
|
|
83
|
+
|
|
84
|
+
export const USE_DALLE_MODEL_SETTINGS: DallePrompt['modelSettings'] = {
|
|
85
|
+
style: 'vivid',
|
|
86
|
+
quality: `standard`,
|
|
87
|
+
// <- TODO: !! Play with theeese to achieve best results
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const NEXT_PUBLIC_PROMPTBOOK_SERVER_URL = config.get('NEXT_PUBLIC_PROMPTBOOK_SERVER_URL').url().required().value;
|
|
91
|
+
export const NEXT_PUBLIC_IMAGE_SERVER_URL = config.get('NEXT_PUBLIC_IMAGE_SERVER_URL').url().required().value;
|
|
92
|
+
export const NEXT_PUBLIC_BROWSER_SERVER_URL = config.get('NEXT_PUBLIC_BROWSER_SERVER_URL').url().required().value;
|
|
93
|
+
|
|
94
|
+
export const IS_DEVELOPMENT =
|
|
95
|
+
isUrlOnPrivateNetwork(
|
|
96
|
+
NEXT_PUBLIC_URL,
|
|
97
|
+
); /* <- TODO: Maybe pass NODE_ENV and not assume that local is automatically dev */
|
|
98
|
+
export const IS_PRODUCTION = !IS_DEVELOPMENT;
|
|
99
|
+
|
|
100
|
+
if (isRunningInBrowser()) {
|
|
101
|
+
const enviromentLogText = IS_DEVELOPMENT ? ' (in development mode)' : '';
|
|
102
|
+
const branchLogText =
|
|
103
|
+
NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF && NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF !== 'main'
|
|
104
|
+
? ` (branch ${NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF})`
|
|
105
|
+
: '';
|
|
106
|
+
|
|
107
|
+
// TODO: Also log " client ${provideClientIdWithoutValidation()}" and avoid error unhandledRejection ReferenceError: window is not defined @see https://vercel.com/hejny/1-2i/E2LhCdVbk9hjEa8dE9ww42vnkcTg
|
|
108
|
+
console.info(
|
|
109
|
+
`%c✨ ${APP_NAME}${enviromentLogText}${branchLogText} version ${APP_VERSION} running on ${NEXT_PUBLIC_URL.href} `,
|
|
110
|
+
spaceTrim(`
|
|
111
|
+
display: block;
|
|
112
|
+
|
|
113
|
+
background-color: rgba(0, 0, 0, 0.13);
|
|
114
|
+
border: 1px solid rgba(255, 255 ,255, 0.53);
|
|
115
|
+
box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
|
|
116
|
+
backdrop-filter: blur(10px);
|
|
117
|
+
border-radius: 60px;
|
|
118
|
+
overflow: clip;
|
|
119
|
+
|
|
120
|
+
padding: 10px;
|
|
121
|
+
padding-left: 15px;
|
|
122
|
+
padding-right: 15px;
|
|
123
|
+
|
|
124
|
+
display: flex;
|
|
125
|
+
justify-content: center /* <-[x] */;
|
|
126
|
+
align-items: center /* <-[y] */;
|
|
127
|
+
`)
|
|
128
|
+
.split('\n')
|
|
129
|
+
.join(''),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const NEXT_PUBLIC_DEBUG = config.get('NEXT_PUBLIC_DEBUG').boolean().value;
|
|
134
|
+
|
|
135
|
+
export const NEXT_PUBLIC_OUR_DOMAINS = config.get('NEXT_PUBLIC_OUR_DOMAINS').list().required().value;
|
|
136
|
+
|
|
137
|
+
// TODO: !!!!!!!!!!! Make this more semantic, use named apps
|
|
138
|
+
export const PROMPTBOOK_STUDIO_APP_ID: string_app_id = '00fe1297-bbbe-4447-a321-cb7a1e010025';
|
|
139
|
+
export const RUKA_APP_ID: string_app_id = validateUserId('ccc3d0d7-2e28-4e12-9244-82440445c1fb');
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* You can login to theese apps with your email and password using BRJAPP
|
|
143
|
+
*/
|
|
144
|
+
export const SUPPORTED_APPS_FOR_USER_LOGIN = [PROMPTBOOK_STUDIO_APP_ID, RUKA_APP_ID, CLI_APP_ID];
|
|
145
|
+
|
|
146
|
+
// TODO: [feature/brj-app] !!! Change to SHA256 hash user ids
|
|
147
|
+
export const SYSTEM_USER_ID = validateUserId('000d2940-4a35-4859-83a8-3c754ea5df51');
|
|
148
|
+
export const ANONYMOUS_USER_ID = validateUserId('6bbb20dc-cb55-4f19-b867-71ad263bb828');
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Salt for hashing emails to derive user IDs
|
|
152
|
+
*/
|
|
153
|
+
export const USER_ID_HASH_SALT = config.get('USER_ID_HASH_SALT').value;
|
|
154
|
+
|
|
155
|
+
export const ZERO_UUID = validateUuid('00000000-0000-0000-0000-000000000000');
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The number of pregenerated photobank images to offer to the user to choose from
|
|
159
|
+
*/
|
|
160
|
+
export const PHOTOBANK_SEARCH_IMAGES_COUNT = 4;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Number of keywords reduction attempts until photobank give up and just pick random images
|
|
164
|
+
*/
|
|
165
|
+
export const OPTIMIZE_PHOTOBANK_MAX_SEARCH_DEPTH = 5;
|
|
166
|
+
|
|
167
|
+
export const NEXT_PUBLIC_SUPABASE_URL = config.get('NEXT_PUBLIC_SUPABASE_URL').url().required().value;
|
|
168
|
+
export const NEXT_PUBLIC_SUPABASE_ANON_KEY = config.get('NEXT_PUBLIC_SUPABASE_ANON_KEY').required().value;
|
|
169
|
+
export const SUPABASE_SERVICE_ROLE_KEY = config.get('SUPABASE_SERVICE_ROLE_KEY').value;
|
|
170
|
+
|
|
171
|
+
export const VERCEL_GIT_COMMIT_MESSAGE = config.get('VERCEL_GIT_COMMIT_MESSAGE').value;
|
|
172
|
+
export const VERCEL_GIT_COMMIT_SHA = config.get('VERCEL_GIT_COMMIT_SHA').value;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @deprecated Use App instead
|
|
176
|
+
*/
|
|
177
|
+
export const OPENAI_API_KEY = config.get('OPENAI_API_KEY').value;
|
|
178
|
+
|
|
179
|
+
export const ELEVENLABS_API_KEY =
|
|
180
|
+
config.get('ELEVENLABS_API_KEY').value || 'sk_895d7dc576352e55f6b81545951c711f0d55f66a3e015db7'; // <- TODO: [🟢] Remove this hardcoded api key
|
|
181
|
+
|
|
182
|
+
export const SENDGRID_API_KEY = config.get('SENDGRID_API_KEY').value;
|
|
183
|
+
export const ZEPTOMAIL_API_KEY = config.get('ZEPTOMAIL_API_KEY').value;
|
|
184
|
+
|
|
185
|
+
export const AZURE_COMPUTER_VISION_ENDPOINT = config.get('AZURE_COMPUTER_VISION_ENDPOINT').url().value;
|
|
186
|
+
export const AZURE_COMPUTER_VISION_KEY = config.get('AZURE_COMPUTER_VISION_KEY').value;
|
|
187
|
+
|
|
188
|
+
// TODO: [🧠] How to do required only on server
|
|
189
|
+
export const CDN_BUCKET = config.get('CDN_BUCKET') /*.required([📐])*/.value;
|
|
190
|
+
export const CDN_PATH_PREFIX = config.get('CDN_PATH_PREFIX') /*.required([📐])*/.value;
|
|
191
|
+
export const CDN_ENDPOINT = config.get('CDN_ENDPOINT') /*.required([📐])*/.value;
|
|
192
|
+
export const CDN_ACCESS_KEY_ID = config.get('CDN_ACCESS_KEY_ID') /*.required([📐])*/.value;
|
|
193
|
+
export const CDN_SECRET_ACCESS_KEY = config.get('CDN_SECRET_ACCESS_KEY') /*.required([📐])*/.value;
|
|
194
|
+
export const CDN_PUBLIC_URL = config.get('CDN_PUBLIC_URL').url() /*.required([📐])*/.value;
|
|
195
|
+
|
|
196
|
+
export const CDN = (CDN_BUCKET &&
|
|
197
|
+
// [📐]
|
|
198
|
+
new DigitalOceanSpaces({
|
|
199
|
+
bucket: CDN_BUCKET!,
|
|
200
|
+
pathPrefix: CDN_PATH_PREFIX!,
|
|
201
|
+
endpoint: CDN_ENDPOINT!,
|
|
202
|
+
accessKeyId: CDN_ACCESS_KEY_ID!,
|
|
203
|
+
secretAccessKey: CDN_SECRET_ACCESS_KEY!,
|
|
204
|
+
cdnPublicUrl: CDN_PUBLIC_URL!,
|
|
205
|
+
gzip: false /* <- TODO: Maybe just remove this functionality from WebGPT repository */,
|
|
206
|
+
})) as DigitalOceanSpaces;
|
|
207
|
+
|
|
208
|
+
export const MIDJOURNEY_WHOLE_GALLERY_PATH = 'X:/Mythings/MidJourney';
|
|
209
|
+
|
|
210
|
+
export const PDFMK_URL = config.get('PDFMK_URL', `@see https://github.com/hejny/pdfmk-server`).url().value;
|
|
211
|
+
export const PDFMK_TOKEN = config.get('PDFMK_TOKEN', `@see https://github.com/hejny/pdfmk-server`).value;
|
|
212
|
+
|
|
213
|
+
export const BRJAPP_API_KEY = config.get('BRJAPP_API_KEY').value;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Options for the BrjappConnector instance
|
|
217
|
+
*/
|
|
218
|
+
export const BRJAPP_OPTIONS: BrjappOptions = {
|
|
219
|
+
userGroups: ['cli'],
|
|
220
|
+
initialCredits: 500000,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const CITATION_COLORS = [
|
|
224
|
+
'#8a3ffc', // <- purple
|
|
225
|
+
'#0f62fe', // <- blue
|
|
226
|
+
'#42be65', // <- green
|
|
227
|
+
'#ff832b', // <- orange
|
|
228
|
+
'#ee5396', // <- pink
|
|
229
|
+
'#f1c21b', // <- yellow
|
|
230
|
+
'#007d79', // <- teal
|
|
231
|
+
'#fa4d56', // <- red
|
|
232
|
+
'#6fdc8c', // <- light green
|
|
233
|
+
'#be95ff', // <- lavender
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Storage key for custom agents in localStorage
|
|
238
|
+
*/
|
|
239
|
+
export const CUSTOM_AGENTS_STORAGE_KEY = 'custom-agents';
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Default agent name for AI avatars
|
|
243
|
+
*/
|
|
244
|
+
export const DEFAULT_AGENT_NAME = 'AI Avatar';
|
|
245
|
+
|
|
246
|
+
export function getTagedDefaultAgentName(tag: `[${string | string_char_emoji}]`): string {
|
|
247
|
+
console.trace(`${tag} getTagedDefaultAgentName called`);
|
|
248
|
+
return `${DEFAULT_AGENT_NAME} ${tag}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Initial agent source for new agents
|
|
253
|
+
*/
|
|
254
|
+
export const INITIAL_AGENT_SOURCE = validateAgentSource(
|
|
255
|
+
spaceTrim(`
|
|
256
|
+
${DEFAULT_AGENT_NAME}
|
|
257
|
+
|
|
258
|
+
PERSONA A friendly AI assistant that helps you with your tasks
|
|
259
|
+
|
|
260
|
+
`),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// Auth services configurations:
|
|
264
|
+
export const NEXT_PUBLIC_FACEBOOK_APP_ID = config.get('NEXT_PUBLIC_FACEBOOK_APP_ID').value;
|
|
265
|
+
export const FACEBOOK_APP_SECRET = config.get('FACEBOOK_APP_SECRET').value;
|
|
266
|
+
export const NEXT_PUBLIC_LINKEDIN_CLIENT_ID = config.get('NEXT_PUBLIC_LINKEDIN_CLIENT_ID').value;
|
|
267
|
+
export const LINKEDIN_CLIENT_SECRET = config.get('LINKEDIN_CLIENT_SECRET').value;
|
|
268
|
+
export const NEXT_PUBLIC_GITHUB_CLIENT_ID = config.get('NEXT_PUBLIC_GITHUB_CLIENT_ID').value;
|
|
269
|
+
export const GITHUB_CLIENT_SECRET = config.get('GITHUB_CLIENT_SECRET').value;
|
|
270
|
+
export const NEXT_PUBLIC_GOOGLE_CLIENT_ID = config.get('NEXT_PUBLIC_GOOGLE_CLIENT_ID').value;
|
|
271
|
+
export const GOOGLE_CLIENT_SECRET = config.get('GOOGLE_CLIENT_SECRET').value;
|
|
272
|
+
|
|
273
|
+
// Apify configuration for social media scraping
|
|
274
|
+
export const APIFY_API_KEY = config.get('APIFY_API_KEY').value;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Boilerplate discussion topics for the Arena
|
|
278
|
+
*/
|
|
279
|
+
export const ARENA_DISCUSSION_TOPICS = [
|
|
280
|
+
'What is the future of AI?',
|
|
281
|
+
'How can AI improve education?',
|
|
282
|
+
'What are the ethical implications of AI?',
|
|
283
|
+
'Will AI replace human jobs or create new ones?',
|
|
284
|
+
'How should AI be regulated?',
|
|
285
|
+
'What role will AI play in healthcare?',
|
|
286
|
+
'Can AI be creative and artistic?',
|
|
287
|
+
'How will AI change the way we work?',
|
|
288
|
+
'What are the risks of artificial general intelligence?',
|
|
289
|
+
'How can we ensure AI remains beneficial to humanity?',
|
|
290
|
+
'Should AI have rights?',
|
|
291
|
+
'How will AI impact privacy and surveillance?',
|
|
292
|
+
'What is the role of AI in scientific discovery?',
|
|
293
|
+
'How can AI help solve climate change?',
|
|
294
|
+
'What are the philosophical implications of conscious AI?',
|
|
295
|
+
|
|
296
|
+
// More conversational and diverse topics
|
|
297
|
+
'Is remote work better than office work?',
|
|
298
|
+
'Should social media be regulated more heavily?',
|
|
299
|
+
'What makes a good leader in 2025?',
|
|
300
|
+
'Is cryptocurrency the future of money?',
|
|
301
|
+
'How important is work-life balance?',
|
|
302
|
+
'Should everyone learn to code?',
|
|
303
|
+
"What's the best way to combat misinformation?",
|
|
304
|
+
'Is space exploration worth the investment?',
|
|
305
|
+
'How do we fix the housing crisis?',
|
|
306
|
+
"What's the ideal length for a work week?",
|
|
307
|
+
'Should university education be free?',
|
|
308
|
+
'How do we address mental health at work?',
|
|
309
|
+
'Is nuclear energy the solution to climate change?',
|
|
310
|
+
'What makes content go viral?',
|
|
311
|
+
'How should we prepare for the next pandemic?',
|
|
312
|
+
];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NextConfig } from 'next';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const nextConfig: NextConfig = {
|
|
5
|
+
experimental: {
|
|
6
|
+
externalDir: true,
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
turbopack: {
|
|
10
|
+
// Note: Set this to your monorepo root (where the shared folder lives)
|
|
11
|
+
root: path.join(__dirname, '..', '..'),
|
|
12
|
+
|
|
13
|
+
resolveAlias: {
|
|
14
|
+
'@': path.resolve(__dirname),
|
|
15
|
+
'@common': path.resolve(__dirname, '../common'),
|
|
16
|
+
'@promptbook-local': path.resolve(__dirname, '../../src/_packages'),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
/*/
|
|
21
|
+
// Note: In case you need to use Webpack instead of Turbopack
|
|
22
|
+
webpack(config) {
|
|
23
|
+
// Use TsconfigPathsPlugin for all path alias resolution
|
|
24
|
+
config.resolve.plugins = config.resolve.plugins || [];
|
|
25
|
+
config.resolve.plugins.push(
|
|
26
|
+
new TsconfigPathsPlugin({
|
|
27
|
+
configFile: path.resolve(__dirname, 'tsconfig.json'),
|
|
28
|
+
extensions: config.resolve.extensions,
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
config.module.rules.push({
|
|
33
|
+
test: /\.txt$/,
|
|
34
|
+
use: 'raw-loader',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return config;
|
|
38
|
+
},
|
|
39
|
+
/**/
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default nextConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptbook-agents-server",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"dev": "(npx kill-port 4440 || true) && next dev -p 4440",
|
|
5
|
+
"test-build": "npm run build",
|
|
6
|
+
"build": "(npx kill-port 4440 || true) && next build",
|
|
7
|
+
"start": "next start -p 4440",
|
|
8
|
+
"lint": "next lint",
|
|
9
|
+
"postinstall": "cd ../../ && npm ci"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { $createAgentAction } from './actions';
|
|
4
|
+
|
|
5
|
+
export function AddAgentButton() {
|
|
6
|
+
const handleAddAgent = async () => {
|
|
7
|
+
await $createAgentAction();
|
|
8
|
+
// TODO: Add proper error handling and UI feedback
|
|
9
|
+
window.location.reload(); // Refresh to show the new agent
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div
|
|
14
|
+
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 cursor-pointer"
|
|
15
|
+
onClick={handleAddAgent}
|
|
16
|
+
>
|
|
17
|
+
+ Add New Agent
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { $generateBookBoilerplate } from '@promptbook-local/core';
|
|
4
|
+
import { $provideAgentCollectionForServer } from '../tools/$provideAgentCollectionForServer';
|
|
5
|
+
|
|
6
|
+
export async function $createAgentAction() {
|
|
7
|
+
const collection = await $provideAgentCollectionForServer();
|
|
8
|
+
await collection.createAgent($generateBookBoilerplate());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* TODO: !!!! Reorganize actions.ts files
|
|
13
|
+
* TODO: !!! [🧠] Study how Next.js actions work
|
|
14
|
+
*/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export function AgentUrlCopy({ url }: { url: string; }) {
|
|
6
|
+
const [copied, setCopied] = useState(false);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const handleCopy = async () => {
|
|
10
|
+
try {
|
|
11
|
+
await navigator.clipboard.writeText(url);
|
|
12
|
+
setCopied(true);
|
|
13
|
+
setTimeout(() => setCopied(false), 2000);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error('Failed to copy:', err);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="w-full">
|
|
21
|
+
<label className="block text-xs text-gray-500 font-semibold mb-1">Agent Page URL</label>
|
|
22
|
+
<div className="flex gap-2 items-center">
|
|
23
|
+
<input
|
|
24
|
+
type="text"
|
|
25
|
+
value={url}
|
|
26
|
+
readOnly
|
|
27
|
+
className="flex-1 px-2 py-1 border rounded text-sm bg-gray-50 text-gray-700"
|
|
28
|
+
onFocus={(e) => e.target.select()}
|
|
29
|
+
/>
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
className="px-2 py-1 text-white rounded text-xs font-semibold transition hover:opacity-90"
|
|
33
|
+
|
|
34
|
+
onClick={handleCopy}
|
|
35
|
+
>
|
|
36
|
+
{copied ? '✓ Copied' : 'Copy'}
|
|
37
|
+
</button>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TODO: [🚗] Components and pages here should be just tiny UI wraper around proper agent logic and conponents
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
|
+
import { padBook, validateBook } from '@promptbook-local/core';
|
|
3
|
+
import { serializeError } from '@promptbook-local/utils';
|
|
4
|
+
import spaceTrim from 'spacetrim';
|
|
5
|
+
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
6
|
+
import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
|
|
7
|
+
|
|
8
|
+
export async function GET(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
9
|
+
keepUnused(request /* <- Note: We dont need `request` parameter */);
|
|
10
|
+
let { agentName } = await params;
|
|
11
|
+
agentName = decodeURIComponent(agentName);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const collection = await $provideAgentCollectionForServer();
|
|
15
|
+
const agentSource = await collection.getAgentSource(agentName);
|
|
16
|
+
|
|
17
|
+
return new Response(agentSource.getValue(), {
|
|
18
|
+
status: 200,
|
|
19
|
+
headers: { 'Content-Type': 'text/plain' /* <- TODO: [🎳] Mime type of book */ },
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
assertsError(error);
|
|
23
|
+
|
|
24
|
+
console.error(error);
|
|
25
|
+
|
|
26
|
+
return new Response(
|
|
27
|
+
JSON.stringify(
|
|
28
|
+
serializeError(error),
|
|
29
|
+
// <- TODO: !!! Rename `serializeError` to `errorToJson`
|
|
30
|
+
null,
|
|
31
|
+
4,
|
|
32
|
+
// <- TODO: !!! Allow to configure pretty print for agent server
|
|
33
|
+
),
|
|
34
|
+
{
|
|
35
|
+
status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
|
|
36
|
+
headers: { 'Content-Type': 'application/json' },
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function PUT(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
43
|
+
let { agentName } = await params;
|
|
44
|
+
agentName = decodeURIComponent(agentName);
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const collection = await $provideAgentCollectionForServer();
|
|
48
|
+
let agentSourceUnchecked = await request.text();
|
|
49
|
+
agentSourceUnchecked = spaceTrim(agentSourceUnchecked);
|
|
50
|
+
let agentSource = validateBook(agentSourceUnchecked);
|
|
51
|
+
agentSource = padBook(agentSource);
|
|
52
|
+
|
|
53
|
+
await collection.updateAgentSource(agentName, agentSource);
|
|
54
|
+
// <- TODO: !!! Properly type as string_book
|
|
55
|
+
|
|
56
|
+
return new Response(
|
|
57
|
+
JSON.stringify({
|
|
58
|
+
isSuccessful: true,
|
|
59
|
+
message: `Agent "${agentName}" updated successfully`,
|
|
60
|
+
agentSource, // <- TODO: !!! Remove from response
|
|
61
|
+
}),
|
|
62
|
+
{
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: { 'Content-Type': 'application/json' },
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
assertsError(error);
|
|
69
|
+
|
|
70
|
+
console.error(error);
|
|
71
|
+
|
|
72
|
+
return new Response(
|
|
73
|
+
JSON.stringify(
|
|
74
|
+
serializeError(error),
|
|
75
|
+
// <- TODO: !!! Rename `serializeError` to `errorToJson`
|
|
76
|
+
null,
|
|
77
|
+
4,
|
|
78
|
+
// <- TODO: !!! Allow to configure pretty print for agent server
|
|
79
|
+
),
|
|
80
|
+
{
|
|
81
|
+
status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
|
|
82
|
+
headers: { 'Content-Type': 'application/json' },
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
### Get the book
|
|
2
|
+
|
|
3
|
+
GET http://localhost:4440/agents/Gabriel%20Gray/api/book
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# _______________________________________
|
|
8
|
+
### Update the book 1
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
PUT http://localhost:4440/agents/Gabriel%20Gray/api/book
|
|
12
|
+
Content-Type: text/plain
|
|
13
|
+
# <- TODO: [🎳] Mime type of book
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Gabriel Gray
|
|
17
|
+
|
|
18
|
+
META COLOR #c9c9c9ff
|
|
19
|
+
PERSONA Friendly and helpful AI agent.
|
|
20
|
+
RULE Be kind and respectful.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# _______________________________________
|
|
26
|
+
### Update the book 2
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
PUT http://localhost:4440/agents/Gabriel%20Gray/api/book
|
|
30
|
+
Content-Type: text/plain
|
|
31
|
+
# <- TODO: [🎳] Mime type of book
|
|
32
|
+
|
|
33
|
+
Gabriel Gray
|
|
34
|
+
|
|
35
|
+
META COLOR #242424ff
|
|
36
|
+
PERSONA Strict and professional AI agent.
|
|
37
|
+
RULE Be strict and professional.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
|
|
2
|
+
import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$provideOpenAiAssistantExecutionToolsForServer';
|
|
3
|
+
import { Agent } from '@promptbook-local/core';
|
|
4
|
+
import { serializeError } from '@promptbook-local/utils';
|
|
5
|
+
import { assertsError } from '../../../../../../../../src/errors/assertsError';
|
|
6
|
+
|
|
7
|
+
export async function GET(request: Request, { params }: { params: Promise<{ agentName: string }> }) {
|
|
8
|
+
const { agentName } = await params;
|
|
9
|
+
const { searchParams } = new URL(request.url);
|
|
10
|
+
const message = searchParams.get('message') || 'Tell me more about yourself.';
|
|
11
|
+
// <- TODO: !!!! To configuration DEFAULT_INITIAL_HIDDEN_MESSAGE
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const collection = await $provideAgentCollectionForServer();
|
|
15
|
+
// [▶️] const executionTools = await $provideExecutionToolsForServer();
|
|
16
|
+
const openAiAssistantExecutionTools = await $provideOpenAiAssistantExecutionToolsForServer();
|
|
17
|
+
const agentSource = await collection.getAgentSource(agentName);
|
|
18
|
+
const agent = new Agent({
|
|
19
|
+
isVerbose: true, // <- TODO: !!! From environment variable
|
|
20
|
+
executionTools: {
|
|
21
|
+
// [▶️] ...executionTools,
|
|
22
|
+
llm: openAiAssistantExecutionTools, // Note: Providing the OpenAI Assistant LLM tools to the Agent to be able to create its own Assistants GPTs
|
|
23
|
+
},
|
|
24
|
+
agentSource,
|
|
25
|
+
});
|
|
26
|
+
const llmTools = agent.getLlmExecutionTools();
|
|
27
|
+
|
|
28
|
+
const response = await llmTools.callChatModel!({
|
|
29
|
+
title: `Chat with agent ${agentName}`,
|
|
30
|
+
parameters: {},
|
|
31
|
+
modelRequirements: {
|
|
32
|
+
modelVariant: 'CHAT',
|
|
33
|
+
},
|
|
34
|
+
content: message,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return new Response(response.content, {
|
|
38
|
+
status: 200,
|
|
39
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
assertsError(error);
|
|
43
|
+
|
|
44
|
+
console.error(error);
|
|
45
|
+
|
|
46
|
+
return new Response(
|
|
47
|
+
JSON.stringify(
|
|
48
|
+
serializeError(error),
|
|
49
|
+
// <- TODO: !!! Rename `serializeError` to `errorToJson`
|
|
50
|
+
null,
|
|
51
|
+
4,
|
|
52
|
+
// <- TODO: !!! Allow to configure pretty print for agent server
|
|
53
|
+
),
|
|
54
|
+
{
|
|
55
|
+
status: 400, // <- TODO: !!! Make `errorToHttpStatusCode`
|
|
56
|
+
headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|