@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.
- package/apps/agents-server/README.md +1 -1
- package/apps/agents-server/TODO.txt +6 -5
- package/apps/agents-server/config.ts +130 -0
- package/apps/agents-server/next.config.ts +1 -1
- package/apps/agents-server/public/fonts/OpenMoji-black-glyf.woff2 +0 -0
- package/apps/agents-server/public/fonts/download-font.js +22 -0
- package/apps/agents-server/src/app/[agentName]/[...rest]/page.tsx +6 -0
- package/apps/agents-server/src/app/[agentName]/page.tsx +1 -0
- package/apps/agents-server/src/app/actions.ts +37 -2
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +68 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentQrCode.tsx +55 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentUrlCopy.tsx +4 -5
- package/apps/agents-server/src/app/agents/[agentName]/CopyField.tsx +44 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +8 -8
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +100 -18
- package/apps/agents-server/src/app/agents/[agentName]/api/feedback/route.ts +54 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/route.ts +6 -6
- package/apps/agents-server/src/app/agents/[agentName]/api/modelRequirements/systemMessage/route.ts +3 -3
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +6 -7
- package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +6 -7
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +9 -2
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChat.tsx +23 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/{AgentBookAndChatComponent.tsx → AgentBookAndChatComponent.tsx.todo} +6 -8
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx +28 -17
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/page.tsx.todo +21 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/AgentChatWrapper.tsx +34 -4
- package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +4 -1
- package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +42 -0
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +111 -108
- package/apps/agents-server/src/app/agents/page.tsx +1 -1
- package/apps/agents-server/src/app/api/auth/login/route.ts +65 -0
- package/apps/agents-server/src/app/api/auth/logout/route.ts +7 -0
- package/apps/agents-server/src/app/api/metadata/route.ts +116 -0
- package/apps/agents-server/src/app/api/upload/route.ts +7 -7
- package/apps/agents-server/src/app/api/users/[username]/route.ts +75 -0
- package/apps/agents-server/src/app/api/users/route.ts +71 -0
- package/apps/agents-server/src/app/globals.css +35 -1
- package/apps/agents-server/src/app/layout.tsx +43 -23
- package/apps/agents-server/src/app/metadata/MetadataClient.tsx +271 -0
- package/apps/agents-server/src/app/metadata/page.tsx +13 -0
- package/apps/agents-server/src/app/not-found.tsx +5 -0
- package/apps/agents-server/src/app/page.tsx +84 -46
- package/apps/agents-server/src/components/Auth/AuthControls.tsx +123 -0
- package/apps/agents-server/src/components/ErrorPage/ErrorPage.tsx +33 -0
- package/apps/agents-server/src/components/ForbiddenPage/ForbiddenPage.tsx +15 -0
- package/apps/agents-server/src/components/Header/Header.tsx +146 -0
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +27 -0
- package/apps/agents-server/src/components/LoginDialog/LoginDialog.tsx +40 -0
- package/apps/agents-server/src/components/LoginForm/LoginForm.tsx +109 -0
- package/apps/agents-server/src/components/NotFoundPage/NotFoundPage.tsx +17 -0
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +190 -0
- package/apps/agents-server/src/components/VercelDeploymentCard/VercelDeploymentCard.tsx +60 -0
- package/apps/agents-server/src/database/$getTableName.ts +18 -0
- package/apps/agents-server/src/database/$provideSupabase.ts +29 -0
- package/apps/agents-server/src/{supabase/getSupabaseForBrowser.ts → database/$provideSupabaseForBrowser.ts} +9 -5
- package/apps/agents-server/src/{supabase/getSupabaseForServer.ts → database/$provideSupabaseForServer.ts} +7 -7
- package/apps/agents-server/src/{supabase/getSupabaseForWorker.ts → database/$provideSupabaseForWorker.ts} +5 -4
- package/apps/agents-server/src/database/getMetadata.ts +31 -0
- package/apps/agents-server/src/database/metadataDefaults.ts +32 -0
- package/apps/agents-server/src/database/schema.sql +179 -0
- package/apps/agents-server/src/database/schema.ts +251 -0
- package/apps/agents-server/src/middleware.ts +162 -0
- package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +14 -10
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +1 -1
- package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +11 -13
- package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +7 -7
- package/apps/agents-server/src/tools/$provideServer.ts +39 -0
- package/apps/agents-server/src/utils/auth.ts +33 -0
- package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +2 -1
- package/apps/agents-server/src/utils/cdn/utils/nameToSubfolderPath.ts +1 -1
- package/apps/agents-server/src/utils/getCurrentUser.ts +32 -0
- package/apps/agents-server/src/utils/isIpAllowed.ts +101 -0
- package/apps/agents-server/src/utils/isUserAdmin.ts +31 -0
- package/apps/agents-server/src/utils/session.ts +50 -0
- package/apps/agents-server/tailwind.config.ts +2 -0
- package/esm/index.es.js +310 -49
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +1 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +17 -3
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
- package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
- package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
- package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +14 -8
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabaseOptions.d.ts +10 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
- package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +28 -0
- package/esm/typings/src/commitments/index.d.ts +2 -1
- package/esm/typings/src/config.d.ts +1 -0
- package/esm/typings/src/errors/DatabaseError.d.ts +2 -2
- package/esm/typings/src/errors/WrappedError.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTask.d.ts +2 -2
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +6 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +17 -4
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +10 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +6 -2
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +30 -4
- package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/color/Color.d.ts +7 -0
- package/esm/typings/src/utils/color/Color.test.d.ts +1 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -2
- package/esm/typings/src/utils/misc/computeHash.d.ts +11 -0
- package/esm/typings/src/utils/misc/computeHash.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
- package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +2 -2
- package/esm/typings/src/utils/organization/$side_effect.d.ts +2 -2
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +2 -2
- package/esm/typings/src/utils/organization/keepUnused.d.ts +2 -2
- package/esm/typings/src/utils/organization/preserve.d.ts +3 -3
- package/esm/typings/src/utils/organization/really_any.d.ts +7 -0
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +2 -2
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +311 -50
- package/umd/index.umd.js.map +1 -1
- package/apps/agents-server/config.ts.todo +0 -312
- package/apps/agents-server/src/supabase/TODO.txt +0 -1
- package/apps/agents-server/src/supabase/getSupabase.ts +0 -25
package/umd/index.umd.js
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
* @generated
|
|
57
57
|
* @see https://github.com/webgptorg/promptbook
|
|
58
58
|
*/
|
|
59
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
59
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-49';
|
|
60
60
|
/**
|
|
61
61
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
62
62
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
*/
|
|
96
96
|
];
|
|
97
97
|
/**
|
|
98
|
+
* TODO: [🐱🚀] Auto-federated server from url in here
|
|
98
99
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
99
100
|
*/
|
|
100
101
|
|
|
@@ -441,6 +442,9 @@
|
|
|
441
442
|
if (hex.length === 3) {
|
|
442
443
|
return Color.fromHex3(hex);
|
|
443
444
|
}
|
|
445
|
+
if (hex.length === 4) {
|
|
446
|
+
return Color.fromHex4(hex);
|
|
447
|
+
}
|
|
444
448
|
if (hex.length === 6) {
|
|
445
449
|
return Color.fromHex6(hex);
|
|
446
450
|
}
|
|
@@ -461,6 +465,19 @@
|
|
|
461
465
|
const b = parseInt(hex.substr(2, 1), 16) * 16;
|
|
462
466
|
return take(new Color(r, g, b));
|
|
463
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Creates a new Color instance from color in hex format with 4 digits (with alpha channel)
|
|
470
|
+
*
|
|
471
|
+
* @param color in hex for example `09df`
|
|
472
|
+
* @returns Color object
|
|
473
|
+
*/
|
|
474
|
+
static fromHex4(hex) {
|
|
475
|
+
const r = parseInt(hex.substr(0, 1), 16) * 16;
|
|
476
|
+
const g = parseInt(hex.substr(1, 1), 16) * 16;
|
|
477
|
+
const b = parseInt(hex.substr(2, 1), 16) * 16;
|
|
478
|
+
const a = parseInt(hex.substr(3, 1), 16) * 16;
|
|
479
|
+
return take(new Color(r, g, b, a));
|
|
480
|
+
}
|
|
464
481
|
/**
|
|
465
482
|
* Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
|
|
466
483
|
*
|
|
@@ -651,7 +668,8 @@
|
|
|
651
668
|
* @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
|
|
652
669
|
*/
|
|
653
670
|
static isHexColorString(value) {
|
|
654
|
-
return typeof value === 'string' &&
|
|
671
|
+
return (typeof value === 'string' &&
|
|
672
|
+
/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
|
|
655
673
|
}
|
|
656
674
|
/**
|
|
657
675
|
* Creates new Color object
|
|
@@ -992,6 +1010,7 @@
|
|
|
992
1010
|
({
|
|
993
1011
|
TITLE: Color.fromHex('#244EA8'),
|
|
994
1012
|
LINE: Color.fromHex('#eeeeee'),
|
|
1013
|
+
SEPARATOR: Color.fromHex('#cccccc'),
|
|
995
1014
|
COMMITMENT: Color.fromHex('#DA0F78'),
|
|
996
1015
|
PARAMETER: Color.fromHex('#8e44ad'),
|
|
997
1016
|
});
|
|
@@ -2394,7 +2413,7 @@
|
|
|
2394
2413
|
TODO: [🧠] Is there a better implementation?
|
|
2395
2414
|
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2396
2415
|
> for (const propertyName of propertyNames) {
|
|
2397
|
-
> const value = (objectValue as
|
|
2416
|
+
> const value = (objectValue as chococake)[propertyName];
|
|
2398
2417
|
> if (value && typeof value === 'object') {
|
|
2399
2418
|
> deepClone(value);
|
|
2400
2419
|
> }
|
|
@@ -2947,6 +2966,8 @@
|
|
|
2947
2966
|
/**
|
|
2948
2967
|
* Converts a given text to kebab-case format.
|
|
2949
2968
|
*
|
|
2969
|
+
* Note: [🔂] This function is idempotent.
|
|
2970
|
+
*
|
|
2950
2971
|
* @param text The text to be converted.
|
|
2951
2972
|
* @returns The kebab-case formatted string.
|
|
2952
2973
|
* @example 'hello-world'
|
|
@@ -3016,6 +3037,8 @@
|
|
|
3016
3037
|
/**
|
|
3017
3038
|
* Converts a title string into a normalized name.
|
|
3018
3039
|
*
|
|
3040
|
+
* Note: [🔂] This function is idempotent.
|
|
3041
|
+
*
|
|
3019
3042
|
* @param value The title string to be converted to a name.
|
|
3020
3043
|
* @returns A normalized name derived from the input title.
|
|
3021
3044
|
* @example 'Hello World!' -> 'hello-world'
|
|
@@ -3209,7 +3232,7 @@
|
|
|
3209
3232
|
}
|
|
3210
3233
|
}
|
|
3211
3234
|
/**
|
|
3212
|
-
* TODO:
|
|
3235
|
+
* TODO: [🐱🚀] Explain that NotFoundError ([🐱🚀] and other specific errors) has priority over DatabaseError in some contexts
|
|
3213
3236
|
*/
|
|
3214
3237
|
|
|
3215
3238
|
/**
|
|
@@ -10026,6 +10049,8 @@
|
|
|
10026
10049
|
/**
|
|
10027
10050
|
* Normalizes a given text to camelCase format.
|
|
10028
10051
|
*
|
|
10052
|
+
* Note: [🔂] This function is idempotent.
|
|
10053
|
+
*
|
|
10029
10054
|
* @param text The text to be normalized.
|
|
10030
10055
|
* @param _isFirstLetterCapital Whether the first letter should be capitalized.
|
|
10031
10056
|
* @returns The camelCase formatted string.
|
|
@@ -12975,6 +13000,18 @@
|
|
|
12975
13000
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
12976
13001
|
*/
|
|
12977
13002
|
|
|
13003
|
+
/**
|
|
13004
|
+
* Computes SHA-256 hash of the given object
|
|
13005
|
+
*
|
|
13006
|
+
* @public exported from `@promptbook/utils`
|
|
13007
|
+
*/
|
|
13008
|
+
function computeHash(value) {
|
|
13009
|
+
return cryptoJs.SHA256(hexEncoder__default["default"].parse(spaceTrim__default["default"](valueToString(value)))).toString( /* hex */);
|
|
13010
|
+
}
|
|
13011
|
+
/**
|
|
13012
|
+
* TODO: [🥬][🥬] Use this ACRY
|
|
13013
|
+
*/
|
|
13014
|
+
|
|
12978
13015
|
/**
|
|
12979
13016
|
* Makes first letter of a string lowercase
|
|
12980
13017
|
*
|
|
@@ -13034,6 +13071,9 @@
|
|
|
13034
13071
|
}
|
|
13035
13072
|
|
|
13036
13073
|
/**
|
|
13074
|
+
* Normalizes a given text to PascalCase format.
|
|
13075
|
+
*
|
|
13076
|
+
* Note: [🔂] This function is idempotent.
|
|
13037
13077
|
*
|
|
13038
13078
|
* @param text @public exported from `@promptbook/utils`
|
|
13039
13079
|
* @returns
|
|
@@ -15083,7 +15123,7 @@
|
|
|
15083
15123
|
*/
|
|
15084
15124
|
|
|
15085
15125
|
/**
|
|
15086
|
-
*
|
|
15126
|
+
* [🐱🚀]
|
|
15087
15127
|
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
15088
15128
|
*
|
|
15089
15129
|
* You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
|
|
@@ -15091,11 +15131,11 @@
|
|
|
15091
15131
|
*
|
|
15092
15132
|
* @see https://github.com/webgptorg/promptbook#remote-server
|
|
15093
15133
|
* @public exported from `@promptbook/remote-server`
|
|
15094
|
-
* <- TODO:
|
|
15134
|
+
* <- TODO: [🐱🚀] Change to `@promptbook/agent-server`
|
|
15095
15135
|
*/
|
|
15096
15136
|
async function startAgentServer(options) {
|
|
15097
15137
|
const { port = 4440 } = options;
|
|
15098
|
-
// TODO:
|
|
15138
|
+
// TODO: [🐱🚀] [🌕]
|
|
15099
15139
|
const agentsServerRoot = path.join(__dirname, '../apps/agents-server');
|
|
15100
15140
|
console.trace(`!!! Starting agents server on port ${port}...`);
|
|
15101
15141
|
console.log(`!!! cwd`, process.cwd());
|
|
@@ -15131,7 +15171,7 @@
|
|
|
15131
15171
|
startServerCommand.alias('start');
|
|
15132
15172
|
startServerCommand.action(handleActionErrors(async (path, cliOptions) => {
|
|
15133
15173
|
const { port: portRaw, reload: isCacheReloaded, verbose: isVerbose } = cliOptions;
|
|
15134
|
-
// TODO:
|
|
15174
|
+
// TODO: [🐱🚀] [🌕] DRY
|
|
15135
15175
|
const port = parseInt(portRaw, 10);
|
|
15136
15176
|
if (isNaN(port) || port <= 0 || port > 65535) {
|
|
15137
15177
|
console.error(colors__default["default"].red(`Invalid port number: ${portRaw}`));
|
|
@@ -15173,11 +15213,11 @@
|
|
|
15173
15213
|
TODO_USE(tools);
|
|
15174
15214
|
TODO_USE(collection);
|
|
15175
15215
|
*/
|
|
15176
|
-
// TODO:
|
|
15177
|
-
// TODO:
|
|
15178
|
-
// TODO:
|
|
15216
|
+
// TODO: [🐱🚀] Use
|
|
15217
|
+
// TODO: [🐱🚀] Pass collection and tools to the server starter
|
|
15218
|
+
// TODO: [🐱🚀] The Next app should be build during the package build step not here
|
|
15179
15219
|
/*
|
|
15180
|
-
// TODO:
|
|
15220
|
+
// TODO: [🐱🚀] Run this conditionally only in production mode in dev mode use `next dev`
|
|
15181
15221
|
await $execCommand({
|
|
15182
15222
|
cwd: './apps/agents-server',
|
|
15183
15223
|
command: `next build`,
|
|
@@ -16403,8 +16443,7 @@
|
|
|
16403
16443
|
};
|
|
16404
16444
|
}
|
|
16405
16445
|
/**
|
|
16406
|
-
|
|
16407
|
-
* TODO: !!!! Allow to chat with agents directly via remote server
|
|
16446
|
+
|
|
16408
16447
|
* TODO: [🕋] Use here `aboutPromptbookInformation`
|
|
16409
16448
|
* TODO: [🌡] Add CORS and security - probably via `helmet`
|
|
16410
16449
|
* TODO: Split this file into multiple functions - handler for each request
|
|
@@ -17525,17 +17564,17 @@
|
|
|
17525
17564
|
},
|
|
17526
17565
|
/**/
|
|
17527
17566
|
/*/
|
|
17528
|
-
|
|
17529
|
-
|
|
17530
|
-
|
|
17531
|
-
|
|
17532
|
-
|
|
17567
|
+
{
|
|
17568
|
+
modelTitle: 'tts-1-hd-1106',
|
|
17569
|
+
modelName: 'tts-1-hd-1106',
|
|
17570
|
+
},
|
|
17571
|
+
/**/
|
|
17533
17572
|
/*/
|
|
17534
|
-
|
|
17535
|
-
|
|
17536
|
-
|
|
17537
|
-
|
|
17538
|
-
|
|
17573
|
+
{
|
|
17574
|
+
modelTitle: 'tts-1-hd',
|
|
17575
|
+
modelName: 'tts-1-hd',
|
|
17576
|
+
},
|
|
17577
|
+
/**/
|
|
17539
17578
|
/**/
|
|
17540
17579
|
{
|
|
17541
17580
|
modelVariant: 'CHAT',
|
|
@@ -20391,11 +20430,12 @@
|
|
|
20391
20430
|
*
|
|
20392
20431
|
* This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
20393
20432
|
*
|
|
20394
|
-
*
|
|
20433
|
+
* Note: [🦖] There are several different things in Promptbook:
|
|
20395
20434
|
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
20396
20435
|
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
20397
20436
|
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
20398
20437
|
* - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
|
|
20438
|
+
* - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
|
|
20399
20439
|
*
|
|
20400
20440
|
* @public exported from `@promptbook/openai`
|
|
20401
20441
|
*/
|
|
@@ -20430,6 +20470,12 @@
|
|
|
20430
20470
|
* Calls OpenAI API to use a chat model.
|
|
20431
20471
|
*/
|
|
20432
20472
|
async callChatModel(prompt) {
|
|
20473
|
+
return this.callChatModelStream(prompt, () => { });
|
|
20474
|
+
}
|
|
20475
|
+
/**
|
|
20476
|
+
* Calls OpenAI API to use a chat model with streaming.
|
|
20477
|
+
*/
|
|
20478
|
+
async callChatModelStream(prompt, onProgress) {
|
|
20433
20479
|
var _a, _b, _c;
|
|
20434
20480
|
if (this.options.isVerbose) {
|
|
20435
20481
|
console.info('💬 OpenAI callChatModel call', { prompt });
|
|
@@ -20497,21 +20543,24 @@
|
|
|
20497
20543
|
console.info('connect', stream.currentEvent);
|
|
20498
20544
|
}
|
|
20499
20545
|
});
|
|
20500
|
-
|
|
20501
|
-
|
|
20502
|
-
|
|
20503
|
-
this.options.isVerbose &&
|
|
20504
|
-
messageDelta &&
|
|
20505
|
-
messageDelta.content &&
|
|
20506
|
-
messageDelta.content[0] &&
|
|
20507
|
-
messageDelta.content[0].type === 'text'
|
|
20508
|
-
) {
|
|
20509
|
-
console.info('messageDelta', messageDelta.content[0].text?.value);
|
|
20546
|
+
stream.on('textDelta', (textDelta, snapshot) => {
|
|
20547
|
+
if (this.options.isVerbose && textDelta.value) {
|
|
20548
|
+
console.info('textDelta', textDelta.value);
|
|
20510
20549
|
}
|
|
20511
|
-
|
|
20512
|
-
|
|
20550
|
+
const chunk = {
|
|
20551
|
+
content: textDelta.value || '',
|
|
20552
|
+
modelName: 'assistant',
|
|
20553
|
+
timing: {
|
|
20554
|
+
start,
|
|
20555
|
+
complete: $getCurrentDate(),
|
|
20556
|
+
},
|
|
20557
|
+
usage: UNCERTAIN_USAGE,
|
|
20558
|
+
rawPromptContent,
|
|
20559
|
+
rawRequest,
|
|
20560
|
+
rawResponse: snapshot,
|
|
20561
|
+
};
|
|
20562
|
+
onProgress(chunk);
|
|
20513
20563
|
});
|
|
20514
|
-
*/
|
|
20515
20564
|
stream.on('messageCreated', (message) => {
|
|
20516
20565
|
if (this.options.isVerbose) {
|
|
20517
20566
|
console.info('messageCreated', message);
|
|
@@ -20547,7 +20596,7 @@
|
|
|
20547
20596
|
}
|
|
20548
20597
|
return exportJson({
|
|
20549
20598
|
name: 'promptResult',
|
|
20550
|
-
message: `Result of \`OpenAiAssistantExecutionTools.
|
|
20599
|
+
message: `Result of \`OpenAiAssistantExecutionTools.callChatModelStream\``,
|
|
20551
20600
|
order: [],
|
|
20552
20601
|
value: {
|
|
20553
20602
|
content: resultContent,
|
|
@@ -20566,15 +20615,19 @@
|
|
|
20566
20615
|
},
|
|
20567
20616
|
});
|
|
20568
20617
|
}
|
|
20569
|
-
|
|
20618
|
+
/*
|
|
20619
|
+
public async playground() {
|
|
20570
20620
|
const client = await this.getClient();
|
|
20621
|
+
|
|
20571
20622
|
// List all assistants
|
|
20572
20623
|
const assistants = await client.beta.assistants.list();
|
|
20573
20624
|
console.log('!!! Assistants:', assistants);
|
|
20625
|
+
|
|
20574
20626
|
// Get details of a specific assistant
|
|
20575
20627
|
const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
|
|
20576
20628
|
const assistant = await client.beta.assistants.retrieve(assistantId);
|
|
20577
20629
|
console.log('!!! Assistant Details:', assistant);
|
|
20630
|
+
|
|
20578
20631
|
// Update an assistant
|
|
20579
20632
|
const updatedAssistant = await client.beta.assistants.update(assistantId, {
|
|
20580
20633
|
name: assistant.name + '(M)',
|
|
@@ -20584,7 +20637,18 @@
|
|
|
20584
20637
|
},
|
|
20585
20638
|
});
|
|
20586
20639
|
console.log('!!! Updated Assistant:', updatedAssistant);
|
|
20587
|
-
|
|
20640
|
+
|
|
20641
|
+
await forEver();
|
|
20642
|
+
}
|
|
20643
|
+
*/
|
|
20644
|
+
/**
|
|
20645
|
+
* Get an existing assistant tool wrapper
|
|
20646
|
+
*/
|
|
20647
|
+
getAssistant(assistantId) {
|
|
20648
|
+
return new OpenAiAssistantExecutionTools({
|
|
20649
|
+
...this.options,
|
|
20650
|
+
assistantId,
|
|
20651
|
+
});
|
|
20588
20652
|
}
|
|
20589
20653
|
async createNewAssistant(options) {
|
|
20590
20654
|
if (!this.isCreatingNewAssistantsAllowed) {
|
|
@@ -20671,9 +20735,98 @@
|
|
|
20671
20735
|
}
|
|
20672
20736
|
const assistant = await client.beta.assistants.create(assistantConfig);
|
|
20673
20737
|
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
20674
|
-
// TODO:
|
|
20675
|
-
// TODO:
|
|
20676
|
-
// TODO:
|
|
20738
|
+
// TODO: [🐱🚀] Try listing existing assistants
|
|
20739
|
+
// TODO: [🐱🚀] Try marking existing assistants by DISCRIMINANT
|
|
20740
|
+
// TODO: [🐱🚀] Allow to update and reconnect to existing assistants
|
|
20741
|
+
return new OpenAiAssistantExecutionTools({
|
|
20742
|
+
...this.options,
|
|
20743
|
+
isCreatingNewAssistantsAllowed: false,
|
|
20744
|
+
assistantId: assistant.id,
|
|
20745
|
+
});
|
|
20746
|
+
}
|
|
20747
|
+
async updateAssistant(options) {
|
|
20748
|
+
if (!this.isCreatingNewAssistantsAllowed) {
|
|
20749
|
+
throw new NotAllowed(`Updating assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
20750
|
+
}
|
|
20751
|
+
const { assistantId, name, instructions, knowledgeSources } = options;
|
|
20752
|
+
const client = await this.getClient();
|
|
20753
|
+
let vectorStoreId;
|
|
20754
|
+
// If knowledge sources are provided, create a vector store with them
|
|
20755
|
+
// TODO: [🧠] Reuse vector store creation logic from createNewAssistant
|
|
20756
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
20757
|
+
if (this.options.isVerbose) {
|
|
20758
|
+
console.info(`📚 Creating vector store for update with ${knowledgeSources.length} knowledge sources...`);
|
|
20759
|
+
}
|
|
20760
|
+
// Create a vector store
|
|
20761
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
20762
|
+
name: `${name} Knowledge Base`,
|
|
20763
|
+
});
|
|
20764
|
+
vectorStoreId = vectorStore.id;
|
|
20765
|
+
if (this.options.isVerbose) {
|
|
20766
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
20767
|
+
}
|
|
20768
|
+
// Upload files from knowledge sources to the vector store
|
|
20769
|
+
const fileStreams = [];
|
|
20770
|
+
for (const source of knowledgeSources) {
|
|
20771
|
+
try {
|
|
20772
|
+
// Check if it's a URL
|
|
20773
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
20774
|
+
// Download the file
|
|
20775
|
+
const response = await fetch(source);
|
|
20776
|
+
if (!response.ok) {
|
|
20777
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
20778
|
+
continue;
|
|
20779
|
+
}
|
|
20780
|
+
const buffer = await response.arrayBuffer();
|
|
20781
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
20782
|
+
const blob = new Blob([buffer]);
|
|
20783
|
+
const file = new File([blob], filename);
|
|
20784
|
+
fileStreams.push(file);
|
|
20785
|
+
}
|
|
20786
|
+
else {
|
|
20787
|
+
// Assume it's a local file path
|
|
20788
|
+
// Note: This will work in Node.js environment
|
|
20789
|
+
// For browser environments, this would need different handling
|
|
20790
|
+
const fs = await import('fs');
|
|
20791
|
+
const fileStream = fs.createReadStream(source);
|
|
20792
|
+
fileStreams.push(fileStream);
|
|
20793
|
+
}
|
|
20794
|
+
}
|
|
20795
|
+
catch (error) {
|
|
20796
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
20797
|
+
}
|
|
20798
|
+
}
|
|
20799
|
+
// Batch upload files to the vector store
|
|
20800
|
+
if (fileStreams.length > 0) {
|
|
20801
|
+
try {
|
|
20802
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
20803
|
+
files: fileStreams,
|
|
20804
|
+
});
|
|
20805
|
+
if (this.options.isVerbose) {
|
|
20806
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
20807
|
+
}
|
|
20808
|
+
}
|
|
20809
|
+
catch (error) {
|
|
20810
|
+
console.error('Error uploading files to vector store:', error);
|
|
20811
|
+
}
|
|
20812
|
+
}
|
|
20813
|
+
}
|
|
20814
|
+
const assistantUpdate = {
|
|
20815
|
+
name,
|
|
20816
|
+
instructions,
|
|
20817
|
+
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
20818
|
+
};
|
|
20819
|
+
if (vectorStoreId) {
|
|
20820
|
+
assistantUpdate.tool_resources = {
|
|
20821
|
+
file_search: {
|
|
20822
|
+
vector_store_ids: [vectorStoreId],
|
|
20823
|
+
},
|
|
20824
|
+
};
|
|
20825
|
+
}
|
|
20826
|
+
const assistant = await client.beta.assistants.update(assistantId, assistantUpdate);
|
|
20827
|
+
if (this.options.isVerbose) {
|
|
20828
|
+
console.log(`✅ Assistant updated: ${assistant.id}`);
|
|
20829
|
+
}
|
|
20677
20830
|
return new OpenAiAssistantExecutionTools({
|
|
20678
20831
|
...this.options,
|
|
20679
20832
|
isCreatingNewAssistantsAllowed: false,
|
|
@@ -22906,6 +23059,60 @@
|
|
|
22906
23059
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
22907
23060
|
*/
|
|
22908
23061
|
|
|
23062
|
+
/**
|
|
23063
|
+
* INITIAL MESSAGE commitment definition
|
|
23064
|
+
*
|
|
23065
|
+
* The INITIAL MESSAGE commitment defines the first message that the user sees when opening the chat.
|
|
23066
|
+
* It is used to greet the user and set the tone of the conversation.
|
|
23067
|
+
*
|
|
23068
|
+
* Example usage in agent source:
|
|
23069
|
+
*
|
|
23070
|
+
* ```book
|
|
23071
|
+
* INITIAL MESSAGE Hello! I am ready to help you with your tasks.
|
|
23072
|
+
* ```
|
|
23073
|
+
*
|
|
23074
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
23075
|
+
*/
|
|
23076
|
+
class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
23077
|
+
constructor() {
|
|
23078
|
+
super('INITIAL MESSAGE');
|
|
23079
|
+
}
|
|
23080
|
+
/**
|
|
23081
|
+
* Short one-line description of INITIAL MESSAGE.
|
|
23082
|
+
*/
|
|
23083
|
+
get description() {
|
|
23084
|
+
return 'Defines the **initial message** shown to the user when the chat starts.';
|
|
23085
|
+
}
|
|
23086
|
+
/**
|
|
23087
|
+
* Markdown documentation for INITIAL MESSAGE commitment.
|
|
23088
|
+
*/
|
|
23089
|
+
get documentation() {
|
|
23090
|
+
return spaceTrim.spaceTrim(`
|
|
23091
|
+
# ${this.type}
|
|
23092
|
+
|
|
23093
|
+
Defines the first message that the user sees when opening the chat. This message is purely for display purposes in the UI and does not inherently become part of the LLM's system prompt context (unless also included via other means).
|
|
23094
|
+
|
|
23095
|
+
## Key aspects
|
|
23096
|
+
|
|
23097
|
+
- Used to greet the user.
|
|
23098
|
+
- Sets the tone of the conversation.
|
|
23099
|
+
- Displayed immediately when the chat interface loads.
|
|
23100
|
+
|
|
23101
|
+
## Examples
|
|
23102
|
+
|
|
23103
|
+
\`\`\`book
|
|
23104
|
+
Support Agent
|
|
23105
|
+
|
|
23106
|
+
PERSONA You are a helpful support agent.
|
|
23107
|
+
INITIAL MESSAGE Hi there! How can I assist you today?
|
|
23108
|
+
\`\`\`
|
|
23109
|
+
`);
|
|
23110
|
+
}
|
|
23111
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
23112
|
+
return requirements;
|
|
23113
|
+
}
|
|
23114
|
+
}
|
|
23115
|
+
|
|
22909
23116
|
/**
|
|
22910
23117
|
* MESSAGE commitment definition
|
|
22911
23118
|
*
|
|
@@ -23610,6 +23817,7 @@
|
|
|
23610
23817
|
// Keep everything after the PERSONA section
|
|
23611
23818
|
cleanedMessage = lines.slice(personaEndIndex).join('\n').trim();
|
|
23612
23819
|
}
|
|
23820
|
+
// TODO: [🕛] There should be `agentFullname` not `agentName`
|
|
23613
23821
|
// Create new system message with persona at the beginning
|
|
23614
23822
|
// Format: "You are {agentName}\n{personaContent}"
|
|
23615
23823
|
// The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
|
|
@@ -24066,6 +24274,7 @@
|
|
|
24066
24274
|
new NoteCommitmentDefinition('NONCE'),
|
|
24067
24275
|
new GoalCommitmentDefinition('GOAL'),
|
|
24068
24276
|
new GoalCommitmentDefinition('GOALS'),
|
|
24277
|
+
new InitialMessageCommitmentDefinition(),
|
|
24069
24278
|
new MessageCommitmentDefinition('MESSAGE'),
|
|
24070
24279
|
new MessageCommitmentDefinition('MESSAGES'),
|
|
24071
24280
|
new ScenarioCommitmentDefinition('SCENARIO'),
|
|
@@ -24438,6 +24647,36 @@
|
|
|
24438
24647
|
* TODO: [🤹] Figure out best placeholder image generator https://i.pravatar.cc/1000?u=568
|
|
24439
24648
|
*/
|
|
24440
24649
|
|
|
24650
|
+
/**
|
|
24651
|
+
* Computes SHA-256 hash of the agent source
|
|
24652
|
+
*
|
|
24653
|
+
* @public exported from `@promptbook/core`
|
|
24654
|
+
*/
|
|
24655
|
+
function computeAgentHash(agentSource) {
|
|
24656
|
+
return computeHash(agentSource);
|
|
24657
|
+
}
|
|
24658
|
+
|
|
24659
|
+
/**
|
|
24660
|
+
* Normalizes agent name from arbitrary string to valid agent name
|
|
24661
|
+
*
|
|
24662
|
+
* Note: [🔂] This function is idempotent.
|
|
24663
|
+
*
|
|
24664
|
+
* @public exported from `@promptbook/core`
|
|
24665
|
+
*/
|
|
24666
|
+
function normalizeAgentName(rawAgentName) {
|
|
24667
|
+
return titleToName(spaceTrim__default["default"](rawAgentName));
|
|
24668
|
+
}
|
|
24669
|
+
|
|
24670
|
+
/**
|
|
24671
|
+
* Creates temporary default agent name based on agent source hash
|
|
24672
|
+
*
|
|
24673
|
+
* @public exported from `@promptbook/core`
|
|
24674
|
+
*/
|
|
24675
|
+
function createDefaultAgentName(agentSource) {
|
|
24676
|
+
const agentHash = computeAgentHash(agentSource);
|
|
24677
|
+
return normalizeAgentName(`Agent ${agentHash.substring(0, 6)}`);
|
|
24678
|
+
}
|
|
24679
|
+
|
|
24441
24680
|
/**
|
|
24442
24681
|
* Parses basic information from agent source
|
|
24443
24682
|
*
|
|
@@ -24463,13 +24702,31 @@
|
|
|
24463
24702
|
}
|
|
24464
24703
|
personaDescription += commitment.content;
|
|
24465
24704
|
}
|
|
24705
|
+
let initialMessage = null;
|
|
24706
|
+
for (const commitment of parseResult.commitments) {
|
|
24707
|
+
if (commitment.type !== 'INITIAL MESSAGE') {
|
|
24708
|
+
continue;
|
|
24709
|
+
}
|
|
24710
|
+
// Note: Initial message override logic - later overrides earlier
|
|
24711
|
+
// Or should it append? Usually initial message is just one block.
|
|
24712
|
+
// Let's stick to "later overrides earlier" for simplicity, or just take the last one.
|
|
24713
|
+
initialMessage = commitment.content;
|
|
24714
|
+
}
|
|
24466
24715
|
const meta = {};
|
|
24716
|
+
const links = [];
|
|
24467
24717
|
for (const commitment of parseResult.commitments) {
|
|
24718
|
+
if (commitment.type === 'META LINK') {
|
|
24719
|
+
links.push(spaceTrim__default["default"](commitment.content));
|
|
24720
|
+
continue;
|
|
24721
|
+
}
|
|
24468
24722
|
if (commitment.type !== 'META') {
|
|
24469
24723
|
continue;
|
|
24470
24724
|
}
|
|
24471
24725
|
// Parse META commitments - format is "META TYPE content"
|
|
24472
24726
|
const metaTypeRaw = commitment.content.split(' ')[0] || 'NONE';
|
|
24727
|
+
if (metaTypeRaw === 'LINK') {
|
|
24728
|
+
links.push(spaceTrim__default["default"](commitment.content.substring(metaTypeRaw.length)));
|
|
24729
|
+
}
|
|
24473
24730
|
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
24474
24731
|
meta[metaType] = spaceTrim__default["default"](commitment.content.substring(metaTypeRaw.length));
|
|
24475
24732
|
}
|
|
@@ -24480,10 +24737,14 @@
|
|
|
24480
24737
|
// Parse parameters using unified approach - both @Parameter and {parameter} notations
|
|
24481
24738
|
// are treated as the same syntax feature with unified representation
|
|
24482
24739
|
const parameters = parseParameters(agentSource);
|
|
24740
|
+
const agentHash = computeAgentHash(agentSource);
|
|
24483
24741
|
return {
|
|
24484
|
-
agentName: parseResult.agentName,
|
|
24742
|
+
agentName: normalizeAgentName(parseResult.agentName || createDefaultAgentName(agentSource)),
|
|
24743
|
+
agentHash,
|
|
24485
24744
|
personaDescription,
|
|
24745
|
+
initialMessage,
|
|
24486
24746
|
meta,
|
|
24747
|
+
links,
|
|
24487
24748
|
parameters,
|
|
24488
24749
|
};
|
|
24489
24750
|
}
|
|
@@ -24701,7 +24962,7 @@
|
|
|
24701
24962
|
});
|
|
24702
24963
|
|
|
24703
24964
|
const answer = response.choices[0].message.content;
|
|
24704
|
-
console.log('\\n🧠 ${agentName}:', answer, '\\n');
|
|
24965
|
+
console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
|
|
24705
24966
|
|
|
24706
24967
|
chatHistory.push({ role: 'assistant', content: answer });
|
|
24707
24968
|
promptUser();
|
|
@@ -24720,7 +24981,7 @@
|
|
|
24720
24981
|
|
|
24721
24982
|
(async () => {
|
|
24722
24983
|
await setupKnowledge();
|
|
24723
|
-
console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
|
|
24984
|
+
console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
|
|
24724
24985
|
promptUser();
|
|
24725
24986
|
})();
|
|
24726
24987
|
`);
|
|
@@ -24767,7 +25028,7 @@
|
|
|
24767
25028
|
});
|
|
24768
25029
|
|
|
24769
25030
|
const answer = response.choices[0].message.content;
|
|
24770
|
-
console.log('\\n🧠 ${agentName}:', answer, '\\n');
|
|
25031
|
+
console.log('\\n🧠 ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */}:', answer, '\\n');
|
|
24771
25032
|
|
|
24772
25033
|
chatHistory.push({ role: 'assistant', content: answer });
|
|
24773
25034
|
promptUser();
|
|
@@ -24784,7 +25045,7 @@
|
|
|
24784
25045
|
});
|
|
24785
25046
|
}
|
|
24786
25047
|
|
|
24787
|
-
console.log("🤖 Chat with ${agentName} (type 'exit' to quit)\\n");
|
|
25048
|
+
console.log("🤖 Chat with ${agentName /* <- TODO: [🕛] There should be `agentFullname` not `agentName` */} (type 'exit' to quit)\\n");
|
|
24788
25049
|
promptUser();
|
|
24789
25050
|
|
|
24790
25051
|
`);
|
|
@@ -24800,7 +25061,7 @@
|
|
|
24800
25061
|
* @public exported from `@promptbook/wizard`
|
|
24801
25062
|
* @public exported from `@promptbook/cli`
|
|
24802
25063
|
*
|
|
24803
|
-
* TODO:
|
|
25064
|
+
* TODO: [🧠] Which package should export this?
|
|
24804
25065
|
*/
|
|
24805
25066
|
const _OpenAiSdkTranspilerRegistration = $bookTranspilersRegister.register(OpenAiSdkTranspiler);
|
|
24806
25067
|
/**
|