@promptbook/core 0.103.0-46 → 0.103.0-47
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/esm/index.es.js +326 -283
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +1 -7
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +16 -14
- package/esm/typings/src/_packages/types.index.d.ts +12 -6
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +6 -1
- package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +14 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.test.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/AgentChat/AgentChatProps.d.ts +13 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +1 -60
- package/esm/typings/src/{book-2.0/commitments → commitments}/ACTION/ACTION.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/DELETE/DELETE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/FORMAT/FORMAT.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/GOAL/GOAL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/KNOWLEDGE/KNOWLEDGE.d.ts +1 -5
- package/esm/typings/src/{book-2.0/commitments → commitments}/MEMORY/MEMORY.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MESSAGE/MESSAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META/META.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_IMAGE/META_IMAGE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/META_LINK/META_LINK.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/MODEL/MODEL.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/NOTE/NOTE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/PERSONA/PERSONA.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/RULE/RULE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SAMPLE/SAMPLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/SCENARIO/SCENARIO.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/STYLE/STYLE.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BaseCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/CommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/NotYetImplementedCommitmentDefinition.d.ts +1 -1
- package/esm/typings/src/{book-2.0/commitments → commitments}/_base/createEmptyAgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -7
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +32 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +11 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +5 -1
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/color/internal-utils/checkChannelValue.d.ts +0 -3
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomFullnameWithColor.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +326 -282
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/BookCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/_base/ParsedCommitment.d.ts +0 -0
- /package/esm/typings/src/{book-2.0/commitments → commitments}/index.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-47';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -159,15 +159,20 @@ class ParseError extends Error {
|
|
|
159
159
|
*/
|
|
160
160
|
const REMOTE_SERVER_URLS = [
|
|
161
161
|
{
|
|
162
|
-
title: 'Promptbook',
|
|
163
|
-
description: `
|
|
162
|
+
title: 'Promptbook.Studio',
|
|
163
|
+
description: `Server of Promptbook.studio`,
|
|
164
164
|
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
165
|
-
isAnonymousModeAllowed: true,
|
|
166
165
|
urls: [
|
|
167
166
|
'https://promptbook.s5.ptbk.io/',
|
|
168
167
|
// Note: Servers 1-4 are not running
|
|
169
168
|
],
|
|
170
169
|
},
|
|
170
|
+
{
|
|
171
|
+
title: 'Testing Agents',
|
|
172
|
+
description: `Testing Agents server on Vercel`,
|
|
173
|
+
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
174
|
+
urls: ['https://s6.ptbk.io/'],
|
|
175
|
+
},
|
|
171
176
|
/*
|
|
172
177
|
Note: Working on older version of Promptbook and not supported anymore
|
|
173
178
|
{
|
|
@@ -412,9 +417,6 @@ function checkChannelValue(channelName, value) {
|
|
|
412
417
|
throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
|
|
413
418
|
}
|
|
414
419
|
}
|
|
415
|
-
/**
|
|
416
|
-
* TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
|
|
417
|
-
*/
|
|
418
420
|
|
|
419
421
|
/**
|
|
420
422
|
* Color object represents an RGB color with alpha channel
|
|
@@ -7390,40 +7392,6 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
7390
7392
|
* TODO: [🏢] Check validity of `temperature` in pipeline
|
|
7391
7393
|
*/
|
|
7392
7394
|
|
|
7393
|
-
/**
|
|
7394
|
-
* Creates an empty/basic agent model requirements object
|
|
7395
|
-
* This serves as the starting point for the reduce-like pattern
|
|
7396
|
-
* where each commitment applies its changes to build the final requirements
|
|
7397
|
-
*
|
|
7398
|
-
* @public exported from `@promptbook/core`
|
|
7399
|
-
*/
|
|
7400
|
-
function createEmptyAgentModelRequirements() {
|
|
7401
|
-
return {
|
|
7402
|
-
systemMessage: '',
|
|
7403
|
-
// modelName: 'gpt-5',
|
|
7404
|
-
modelName: 'gemini-2.5-flash-lite',
|
|
7405
|
-
temperature: 0.7,
|
|
7406
|
-
topP: 0.9,
|
|
7407
|
-
topK: 50,
|
|
7408
|
-
};
|
|
7409
|
-
}
|
|
7410
|
-
/**
|
|
7411
|
-
* Creates a basic agent model requirements with just the agent name
|
|
7412
|
-
* This is used when we have an agent name but no commitments
|
|
7413
|
-
*
|
|
7414
|
-
* @public exported from `@promptbook/core`
|
|
7415
|
-
*/
|
|
7416
|
-
function createBasicAgentModelRequirements(agentName) {
|
|
7417
|
-
const empty = createEmptyAgentModelRequirements();
|
|
7418
|
-
return {
|
|
7419
|
-
...empty,
|
|
7420
|
-
systemMessage: `You are ${agentName || 'AI Agent'}`,
|
|
7421
|
-
};
|
|
7422
|
-
}
|
|
7423
|
-
/**
|
|
7424
|
-
* TODO: [🐤] Deduplicate `AgentModelRequirements` and `ModelRequirements` model requirements
|
|
7425
|
-
*/
|
|
7426
|
-
|
|
7427
7395
|
/**
|
|
7428
7396
|
* Generates a regex pattern to match a specific commitment
|
|
7429
7397
|
*
|
|
@@ -7957,23 +7925,19 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7957
7925
|
`);
|
|
7958
7926
|
}
|
|
7959
7927
|
applyToAgentModelRequirements(requirements, content) {
|
|
7960
|
-
var _a;
|
|
7961
7928
|
const trimmedContent = content.trim();
|
|
7962
7929
|
if (!trimmedContent) {
|
|
7963
7930
|
return requirements;
|
|
7964
7931
|
}
|
|
7965
7932
|
// Check if content is a URL (external knowledge source)
|
|
7966
|
-
if (
|
|
7933
|
+
if (isValidUrl(trimmedContent)) {
|
|
7967
7934
|
// Store the URL for later async processing
|
|
7968
7935
|
const updatedRequirements = {
|
|
7969
7936
|
...requirements,
|
|
7970
|
-
|
|
7971
|
-
...requirements.
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
trimmedContent,
|
|
7975
|
-
],
|
|
7976
|
-
},
|
|
7937
|
+
knowledgeSources: [
|
|
7938
|
+
...(requirements.knowledgeSources || []),
|
|
7939
|
+
trimmedContent,
|
|
7940
|
+
],
|
|
7977
7941
|
};
|
|
7978
7942
|
// Add placeholder information about knowledge sources to system message
|
|
7979
7943
|
const knowledgeInfo = `Knowledge Source URL: ${trimmedContent} (will be processed for retrieval during chat)`;
|
|
@@ -7985,18 +7949,6 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7985
7949
|
return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
|
|
7986
7950
|
}
|
|
7987
7951
|
}
|
|
7988
|
-
/**
|
|
7989
|
-
* Check if content is a URL
|
|
7990
|
-
*/
|
|
7991
|
-
isUrl(content) {
|
|
7992
|
-
try {
|
|
7993
|
-
new URL(content);
|
|
7994
|
-
return true;
|
|
7995
|
-
}
|
|
7996
|
-
catch (_a) {
|
|
7997
|
-
return false;
|
|
7998
|
-
}
|
|
7999
|
-
}
|
|
8000
7952
|
}
|
|
8001
7953
|
/**
|
|
8002
7954
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -9322,6 +9274,40 @@ function isCommitmentSupported(type) {
|
|
|
9322
9274
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
9323
9275
|
*/
|
|
9324
9276
|
|
|
9277
|
+
/**
|
|
9278
|
+
* Creates an empty/basic agent model requirements object
|
|
9279
|
+
* This serves as the starting point for the reduce-like pattern
|
|
9280
|
+
* where each commitment applies its changes to build the final requirements
|
|
9281
|
+
*
|
|
9282
|
+
* @public exported from `@promptbook/core`
|
|
9283
|
+
*/
|
|
9284
|
+
function createEmptyAgentModelRequirements() {
|
|
9285
|
+
return {
|
|
9286
|
+
systemMessage: '',
|
|
9287
|
+
// modelName: 'gpt-5',
|
|
9288
|
+
modelName: 'gemini-2.5-flash-lite',
|
|
9289
|
+
temperature: 0.7,
|
|
9290
|
+
topP: 0.9,
|
|
9291
|
+
topK: 50,
|
|
9292
|
+
};
|
|
9293
|
+
}
|
|
9294
|
+
/**
|
|
9295
|
+
* Creates a basic agent model requirements with just the agent name
|
|
9296
|
+
* This is used when we have an agent name but no commitments
|
|
9297
|
+
*
|
|
9298
|
+
* @public exported from `@promptbook/core`
|
|
9299
|
+
*/
|
|
9300
|
+
function createBasicAgentModelRequirements(agentName) {
|
|
9301
|
+
const empty = createEmptyAgentModelRequirements();
|
|
9302
|
+
return {
|
|
9303
|
+
...empty,
|
|
9304
|
+
systemMessage: `You are ${agentName || 'AI Agent'}`,
|
|
9305
|
+
};
|
|
9306
|
+
}
|
|
9307
|
+
/**
|
|
9308
|
+
* TODO: [🐤] Deduplicate `AgentModelRequirements` and `ModelRequirements` model requirements
|
|
9309
|
+
*/
|
|
9310
|
+
|
|
9325
9311
|
/**
|
|
9326
9312
|
* Parses agent source using the new commitment system with multiline support
|
|
9327
9313
|
* This function replaces the hardcoded commitment parsing in the original parseAgentSource
|
|
@@ -9412,29 +9398,6 @@ function parseAgentSourceWithCommitments(agentSource) {
|
|
|
9412
9398
|
};
|
|
9413
9399
|
}
|
|
9414
9400
|
|
|
9415
|
-
/**
|
|
9416
|
-
* Removes comment lines (lines starting with #) from a system message
|
|
9417
|
-
* This is used to clean up the final system message before sending it to the AI model
|
|
9418
|
-
* while preserving the original content with comments in metadata
|
|
9419
|
-
*
|
|
9420
|
-
* @param systemMessage The system message that may contain comment lines
|
|
9421
|
-
* @returns The system message with comment lines removed
|
|
9422
|
-
*
|
|
9423
|
-
* @private - TODO: [🧠] Maybe should be public?
|
|
9424
|
-
*/
|
|
9425
|
-
function removeCommentsFromSystemMessage(systemMessage) {
|
|
9426
|
-
if (!systemMessage) {
|
|
9427
|
-
return systemMessage;
|
|
9428
|
-
}
|
|
9429
|
-
const lines = systemMessage.split('\n');
|
|
9430
|
-
const filteredLines = lines.filter((line) => {
|
|
9431
|
-
const trimmedLine = line.trim();
|
|
9432
|
-
// Remove lines that start with # (comments)
|
|
9433
|
-
return !trimmedLine.startsWith('#');
|
|
9434
|
-
});
|
|
9435
|
-
return filteredLines.join('\n').trim();
|
|
9436
|
-
}
|
|
9437
|
-
|
|
9438
9401
|
/**
|
|
9439
9402
|
* Parses parameters from text using both supported notations:
|
|
9440
9403
|
* 1. @Parameter - single word parameter starting with @
|
|
@@ -9493,6 +9456,29 @@ function parseParameters(text) {
|
|
|
9493
9456
|
return uniqueParameters;
|
|
9494
9457
|
}
|
|
9495
9458
|
|
|
9459
|
+
/**
|
|
9460
|
+
* Removes comment lines (lines starting with #) from a system message
|
|
9461
|
+
* This is used to clean up the final system message before sending it to the AI model
|
|
9462
|
+
* while preserving the original content with comments in metadata
|
|
9463
|
+
*
|
|
9464
|
+
* @param systemMessage The system message that may contain comment lines
|
|
9465
|
+
* @returns The system message with comment lines removed
|
|
9466
|
+
*
|
|
9467
|
+
* @private - TODO: [🧠] Maybe should be public?
|
|
9468
|
+
*/
|
|
9469
|
+
function removeCommentsFromSystemMessage(systemMessage) {
|
|
9470
|
+
if (!systemMessage) {
|
|
9471
|
+
return systemMessage;
|
|
9472
|
+
}
|
|
9473
|
+
const lines = systemMessage.split('\n');
|
|
9474
|
+
const filteredLines = lines.filter((line) => {
|
|
9475
|
+
const trimmedLine = line.trim();
|
|
9476
|
+
// Remove lines that start with # (comments)
|
|
9477
|
+
return !trimmedLine.startsWith('#');
|
|
9478
|
+
});
|
|
9479
|
+
return filteredLines.join('\n').trim();
|
|
9480
|
+
}
|
|
9481
|
+
|
|
9496
9482
|
/**
|
|
9497
9483
|
* Creates agent model requirements using the new commitment system
|
|
9498
9484
|
* This function uses a reduce-like pattern where each commitment applies its changes
|
|
@@ -9936,125 +9922,51 @@ class AgentCollectionInSupabase /* TODO: !!!! implements AgentCollection */ {
|
|
|
9936
9922
|
console.info(`Creating pipeline collection from supabase...`);
|
|
9937
9923
|
}
|
|
9938
9924
|
}
|
|
9939
|
-
/**
|
|
9940
|
-
* Cached defined execution tools
|
|
9941
|
-
*/
|
|
9942
|
-
// !!! private _definedTools: ExecutionTools | null = null;
|
|
9943
|
-
/*
|
|
9944
|
-
TODO: !!! Use or remove
|
|
9945
|
-
/**
|
|
9946
|
-
* Gets or creates execution tools for the collection
|
|
9947
|
-
* /
|
|
9948
|
-
private async getTools(): Promise<ExecutionTools> {
|
|
9949
|
-
if (this._definedTools !== null) {
|
|
9950
|
-
return this._definedTools;
|
|
9951
|
-
}
|
|
9952
|
-
|
|
9953
|
-
this._definedTools = {
|
|
9954
|
-
...(this.tools === undefined || this.tools.fs === undefined ? await $provideExecutionToolsForNode() : {}),
|
|
9955
|
-
...this.tools,
|
|
9956
|
-
};
|
|
9957
|
-
return this._definedTools;
|
|
9958
|
-
}
|
|
9959
|
-
// <- TODO: [👪] Maybe create some common abstraction *(or parent abstract class)*
|
|
9960
|
-
*/
|
|
9961
9925
|
/**
|
|
9962
9926
|
* Gets all agents in the collection
|
|
9963
9927
|
*/
|
|
9964
9928
|
async listAgents( /* TODO: [🧠] Allow to pass some condition here */) {
|
|
9965
9929
|
const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
|
|
9966
|
-
const
|
|
9930
|
+
const selectResult = await this.supabaseClient
|
|
9967
9931
|
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
9968
9932
|
.select('agentProfile');
|
|
9969
|
-
if (
|
|
9933
|
+
if (selectResult.error) {
|
|
9970
9934
|
throw new DatabaseError(spaceTrim((block) => `
|
|
9971
9935
|
|
|
9972
9936
|
Error fetching agents from Supabase:
|
|
9973
9937
|
|
|
9974
|
-
${block(
|
|
9938
|
+
${block(selectResult.error.message)}
|
|
9975
9939
|
`));
|
|
9976
9940
|
}
|
|
9977
9941
|
if (isVerbose) {
|
|
9978
|
-
console.info(`Found ${
|
|
9979
|
-
}
|
|
9980
|
-
return result.data.map((row) => row.agentProfile);
|
|
9981
|
-
}
|
|
9982
|
-
/**
|
|
9983
|
-
* !!!
|
|
9984
|
-
* /
|
|
9985
|
-
public async spawnAgent(agentName: string_agent_name): Promise<Agent> {
|
|
9986
|
-
|
|
9987
|
-
// <- TODO: !!! ENOENT: no such file or directory, open 'C:\Users\me\work\ai\promptbook\agents\examples\Asistent pro LŠVP.book
|
|
9988
|
-
const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
|
|
9989
|
-
const tools = await this.getTools();
|
|
9990
|
-
|
|
9991
|
-
const agentSourceValue = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
|
|
9992
|
-
const agentSource = new BehaviorSubject(agentSourceValue);
|
|
9993
|
-
|
|
9994
|
-
// Note: Write file whenever agent source changes
|
|
9995
|
-
agentSource.subscribe(async (newSource) => {
|
|
9996
|
-
if (isVerbose) {
|
|
9997
|
-
console.info(colors.cyan(`Writing agent source to file ${agentSourcePath}`));
|
|
9998
|
-
}
|
|
9999
|
-
await forTime(500); // <- TODO: [🙌] !!! Remove
|
|
10000
|
-
await tools.fs!.writeFile(agentSourcePath, newSource, 'utf-8');
|
|
10001
|
-
});
|
|
10002
|
-
|
|
10003
|
-
// Note: Watch file for external changes
|
|
10004
|
-
for await (const event of tools.fs!.watch(agentSourcePath)) {
|
|
10005
|
-
// <- TODO: !!!! Solve the memory freeing when the watching is no longer needed
|
|
10006
|
-
|
|
10007
|
-
if (event.eventType !== 'change') {
|
|
10008
|
-
continue;
|
|
10009
|
-
}
|
|
10010
|
-
|
|
10011
|
-
if (isVerbose) {
|
|
10012
|
-
console.info(
|
|
10013
|
-
colors.cyan(`Detected external change in agent source file ${agentSourcePath}, reloading`),
|
|
10014
|
-
);
|
|
10015
|
-
}
|
|
10016
|
-
await forTime(500); // <- TODO: [🙌] !!! Remove
|
|
10017
|
-
const newSource = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
|
|
10018
|
-
agentSource.next(newSource);
|
|
10019
|
-
}
|
|
10020
|
-
|
|
10021
|
-
// TODO: [🙌] !!!! Debug the infinite loop when file is changed externally and agent source is updated which causes file to be written again
|
|
10022
|
-
|
|
10023
|
-
const agent = new Agent({
|
|
10024
|
-
...this.options,
|
|
10025
|
-
agentSource,
|
|
10026
|
-
executionTools: this.tools || {},
|
|
10027
|
-
});
|
|
10028
|
-
|
|
10029
|
-
if (isVerbose) {
|
|
10030
|
-
console.info(colors.cyan(`Created agent "${agent.agentName}" from source file ${agentSourcePath}`));
|
|
9942
|
+
console.info(`Found ${selectResult.data.length} agents in directory`);
|
|
10031
9943
|
}
|
|
10032
|
-
|
|
10033
|
-
return agent;
|
|
10034
|
-
* /
|
|
9944
|
+
return selectResult.data.map((row) => row.agentProfile);
|
|
10035
9945
|
}
|
|
10036
|
-
*/
|
|
10037
9946
|
/**
|
|
10038
9947
|
* !!!@@@
|
|
10039
9948
|
*/
|
|
10040
9949
|
async getAgentSource(agentName) {
|
|
10041
|
-
const
|
|
9950
|
+
const selectResult = await this.supabaseClient
|
|
10042
9951
|
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
10043
9952
|
.select('agentSource')
|
|
10044
9953
|
.eq('agentName', agentName)
|
|
10045
9954
|
.single();
|
|
10046
|
-
|
|
9955
|
+
/*
|
|
9956
|
+
if (selectResult.data===null) {
|
|
9957
|
+
throw new NotFoundError(`Agent "${agentName}" not found`);
|
|
9958
|
+
}
|
|
9959
|
+
*/
|
|
9960
|
+
if (selectResult.error) {
|
|
10047
9961
|
throw new DatabaseError(spaceTrim((block) => `
|
|
10048
9962
|
|
|
10049
9963
|
Error fetching agent "${agentName}" from Supabase:
|
|
10050
9964
|
|
|
10051
|
-
${block(
|
|
9965
|
+
${block(selectResult.error.message)}
|
|
10052
9966
|
`));
|
|
10053
9967
|
// <- TODO: !!! First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`
|
|
10054
9968
|
}
|
|
10055
|
-
|
|
10056
|
-
// <- TODO: !!!! Dynamic updates
|
|
10057
|
-
return agentSource;
|
|
9969
|
+
return selectResult.data.agentSource;
|
|
10058
9970
|
}
|
|
10059
9971
|
/**
|
|
10060
9972
|
* Creates a new agent in the collection
|
|
@@ -10064,7 +9976,9 @@ class AgentCollectionInSupabase /* TODO: !!!! implements AgentCollection */ {
|
|
|
10064
9976
|
async createAgent(agentSource) {
|
|
10065
9977
|
const agentProfile = parseAgentSource(agentSource);
|
|
10066
9978
|
// <- TODO: [🕛]
|
|
10067
|
-
const
|
|
9979
|
+
const selectResult = await this.supabaseClient
|
|
9980
|
+
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
9981
|
+
.insert({
|
|
10068
9982
|
agentName: agentProfile.agentName || '!!!!!' /* <- TODO: !!!! Remove */,
|
|
10069
9983
|
agentProfile,
|
|
10070
9984
|
createdAt: new Date().toISOString(),
|
|
@@ -10074,11 +9988,11 @@ class AgentCollectionInSupabase /* TODO: !!!! implements AgentCollection */ {
|
|
|
10074
9988
|
usage: ZERO_USAGE,
|
|
10075
9989
|
agentSource: agentSource,
|
|
10076
9990
|
});
|
|
10077
|
-
if (
|
|
9991
|
+
if (selectResult.error) {
|
|
10078
9992
|
throw new DatabaseError(spaceTrim((block) => `
|
|
10079
9993
|
Error creating agent "${agentProfile.agentName}" in Supabase:
|
|
10080
9994
|
|
|
10081
|
-
${block(
|
|
9995
|
+
${block(selectResult.error.message)}
|
|
10082
9996
|
`));
|
|
10083
9997
|
}
|
|
10084
9998
|
return agentProfile;
|
|
@@ -10087,33 +10001,43 @@ class AgentCollectionInSupabase /* TODO: !!!! implements AgentCollection */ {
|
|
|
10087
10001
|
* Updates an existing agent in the collection
|
|
10088
10002
|
*/
|
|
10089
10003
|
async updateAgentSource(agentName, agentSource) {
|
|
10004
|
+
const selectResult = await this.supabaseClient
|
|
10005
|
+
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
10006
|
+
.select('agentVersion')
|
|
10007
|
+
.eq('agentName', agentName)
|
|
10008
|
+
.single();
|
|
10009
|
+
if (!selectResult.data) {
|
|
10010
|
+
throw new NotFoundError(`Agent "${agentName}" not found`);
|
|
10011
|
+
}
|
|
10090
10012
|
const agentProfile = parseAgentSource(agentSource);
|
|
10091
10013
|
// TODO: !!!!!! What about agentName change
|
|
10092
10014
|
console.log('!!! agentName', agentName);
|
|
10093
10015
|
const oldAgentSource = await this.getAgentSource(agentName);
|
|
10094
|
-
const
|
|
10016
|
+
const updateResult = await this.supabaseClient
|
|
10095
10017
|
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
10096
10018
|
.update({
|
|
10097
10019
|
// TODO: !!!! Compare not update> agentName: agentProfile.agentName || '!!!!!' /* <- TODO: !!!! Remove */,
|
|
10098
10020
|
agentProfile,
|
|
10099
10021
|
updatedAt: new Date().toISOString(),
|
|
10100
|
-
agentVersion:
|
|
10101
|
-
agentSource
|
|
10022
|
+
agentVersion: selectResult.data.agentVersion + 1,
|
|
10023
|
+
agentSource,
|
|
10024
|
+
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
10102
10025
|
})
|
|
10103
10026
|
.eq('agentName', agentName);
|
|
10104
10027
|
const newAgentSource = await this.getAgentSource(agentName);
|
|
10105
|
-
console.log('!!! updateAgent',
|
|
10028
|
+
console.log('!!! updateAgent', updateResult);
|
|
10106
10029
|
console.log('!!! old', oldAgentSource);
|
|
10107
10030
|
console.log('!!! new', newAgentSource);
|
|
10108
|
-
if (
|
|
10031
|
+
if (updateResult.error) {
|
|
10109
10032
|
throw new DatabaseError(spaceTrim((block) => `
|
|
10110
10033
|
Error updating agent "${agentName}" in Supabase:
|
|
10111
10034
|
|
|
10112
|
-
${block(
|
|
10035
|
+
${block(updateResult.error.message)}
|
|
10113
10036
|
`));
|
|
10114
10037
|
}
|
|
10115
10038
|
}
|
|
10116
|
-
// TODO: !!!! getAgentSourceSubject
|
|
10039
|
+
// TODO: !!!! public async getAgentSourceSubject(agentName: string_agent_name): Promise<BehaviorSubject<string_book>>
|
|
10040
|
+
// Use Supabase realtime logic
|
|
10117
10041
|
/**
|
|
10118
10042
|
* Deletes an agent from the collection
|
|
10119
10043
|
*/
|
|
@@ -16562,7 +16486,7 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
|
16562
16486
|
*
|
|
16563
16487
|
* This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
16564
16488
|
*
|
|
16565
|
-
* Note: [🦖] There are several different things in Promptbook:
|
|
16489
|
+
* !!! Note: [🦖] There are several different things in Promptbook:
|
|
16566
16490
|
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
16567
16491
|
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
16568
16492
|
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
@@ -16668,17 +16592,21 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
16668
16592
|
console.info('connect', stream.currentEvent);
|
|
16669
16593
|
}
|
|
16670
16594
|
});
|
|
16595
|
+
/*
|
|
16671
16596
|
stream.on('messageDelta', (messageDelta) => {
|
|
16672
|
-
|
|
16673
|
-
|
|
16597
|
+
if (
|
|
16598
|
+
this.options.isVerbose &&
|
|
16674
16599
|
messageDelta &&
|
|
16675
16600
|
messageDelta.content &&
|
|
16676
16601
|
messageDelta.content[0] &&
|
|
16677
|
-
messageDelta.content[0].type === 'text'
|
|
16678
|
-
|
|
16602
|
+
messageDelta.content[0].type === 'text'
|
|
16603
|
+
) {
|
|
16604
|
+
console.info('messageDelta', messageDelta.content[0].text?.value);
|
|
16679
16605
|
}
|
|
16606
|
+
|
|
16680
16607
|
// <- TODO: [🐚] Make streaming and running tasks working
|
|
16681
16608
|
});
|
|
16609
|
+
*/
|
|
16682
16610
|
stream.on('messageCreated', (message) => {
|
|
16683
16611
|
if (this.options.isVerbose) {
|
|
16684
16612
|
console.info('messageCreated', message);
|
|
@@ -16758,64 +16686,85 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
16758
16686
|
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
16759
16687
|
}
|
|
16760
16688
|
// await this.playground();
|
|
16761
|
-
const { name, instructions } = options;
|
|
16689
|
+
const { name, instructions, knowledgeSources } = options;
|
|
16762
16690
|
const client = await this.getClient();
|
|
16763
|
-
|
|
16764
|
-
//
|
|
16765
|
-
|
|
16766
|
-
|
|
16767
|
-
|
|
16768
|
-
|
|
16769
|
-
|
|
16770
|
-
|
|
16771
|
-
|
|
16772
|
-
if (!res.ok) throw new Error(`Download error: ${url}`);
|
|
16773
|
-
const buffer = await res.arrayBuffer();
|
|
16774
|
-
fs.writeFileSync(filepath, Buffer.from(buffer));
|
|
16775
|
-
console.log(`📥 File downloaded: ${filename}`);
|
|
16776
|
-
|
|
16777
|
-
return filepath;
|
|
16778
|
-
}
|
|
16779
|
-
|
|
16780
|
-
async function uploadFileToOpenAI(filepath: string) {
|
|
16781
|
-
const file = await client.files.create({
|
|
16782
|
-
file: fs.createReadStream(filepath),
|
|
16783
|
-
purpose: 'assistants',
|
|
16691
|
+
let vectorStoreId;
|
|
16692
|
+
// If knowledge sources are provided, create a vector store with them
|
|
16693
|
+
if (knowledgeSources && knowledgeSources.length > 0) {
|
|
16694
|
+
if (this.options.isVerbose) {
|
|
16695
|
+
console.info(`📚 Creating vector store with ${knowledgeSources.length} knowledge sources...`);
|
|
16696
|
+
}
|
|
16697
|
+
// Create a vector store
|
|
16698
|
+
const vectorStore = await client.beta.vectorStores.create({
|
|
16699
|
+
name: `${name} Knowledge Base`,
|
|
16784
16700
|
});
|
|
16785
|
-
|
|
16786
|
-
|
|
16787
|
-
|
|
16788
|
-
|
|
16789
|
-
|
|
16790
|
-
|
|
16791
|
-
|
|
16792
|
-
|
|
16793
|
-
|
|
16794
|
-
|
|
16795
|
-
|
|
16796
|
-
|
|
16797
|
-
|
|
16798
|
-
|
|
16799
|
-
|
|
16800
|
-
|
|
16801
|
-
|
|
16802
|
-
|
|
16803
|
-
|
|
16804
|
-
|
|
16805
|
-
|
|
16806
|
-
|
|
16701
|
+
vectorStoreId = vectorStore.id;
|
|
16702
|
+
if (this.options.isVerbose) {
|
|
16703
|
+
console.info(`✅ Vector store created: ${vectorStoreId}`);
|
|
16704
|
+
}
|
|
16705
|
+
// Upload files from knowledge sources to the vector store
|
|
16706
|
+
const fileStreams = [];
|
|
16707
|
+
for (const source of knowledgeSources) {
|
|
16708
|
+
try {
|
|
16709
|
+
// Check if it's a URL
|
|
16710
|
+
if (source.startsWith('http://') || source.startsWith('https://')) {
|
|
16711
|
+
// Download the file
|
|
16712
|
+
const response = await fetch(source);
|
|
16713
|
+
if (!response.ok) {
|
|
16714
|
+
console.error(`Failed to download ${source}: ${response.statusText}`);
|
|
16715
|
+
continue;
|
|
16716
|
+
}
|
|
16717
|
+
const buffer = await response.arrayBuffer();
|
|
16718
|
+
const filename = source.split('/').pop() || 'downloaded-file';
|
|
16719
|
+
const blob = new Blob([buffer]);
|
|
16720
|
+
const file = new File([blob], filename);
|
|
16721
|
+
fileStreams.push(file);
|
|
16722
|
+
}
|
|
16723
|
+
else {
|
|
16724
|
+
// Assume it's a local file path
|
|
16725
|
+
// Note: This will work in Node.js environment
|
|
16726
|
+
// For browser environments, this would need different handling
|
|
16727
|
+
const fs = await import('fs');
|
|
16728
|
+
const fileStream = fs.createReadStream(source);
|
|
16729
|
+
fileStreams.push(fileStream);
|
|
16730
|
+
}
|
|
16731
|
+
}
|
|
16732
|
+
catch (error) {
|
|
16733
|
+
console.error(`Error processing knowledge source ${source}:`, error);
|
|
16734
|
+
}
|
|
16735
|
+
}
|
|
16736
|
+
// Batch upload files to the vector store
|
|
16737
|
+
if (fileStreams.length > 0) {
|
|
16738
|
+
try {
|
|
16739
|
+
await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
|
|
16740
|
+
files: fileStreams,
|
|
16741
|
+
});
|
|
16742
|
+
if (this.options.isVerbose) {
|
|
16743
|
+
console.info(`✅ Uploaded ${fileStreams.length} files to vector store`);
|
|
16744
|
+
}
|
|
16745
|
+
}
|
|
16746
|
+
catch (error) {
|
|
16747
|
+
console.error('Error uploading files to vector store:', error);
|
|
16748
|
+
}
|
|
16749
|
+
}
|
|
16807
16750
|
}
|
|
16808
|
-
|
|
16809
|
-
|
|
16810
|
-
// 3️⃣ Create assistant with uploaded files
|
|
16811
|
-
const assistant = await client.beta.assistants.create({
|
|
16751
|
+
// Create assistant with vector store attached
|
|
16752
|
+
const assistantConfig = {
|
|
16812
16753
|
name,
|
|
16813
16754
|
description: 'Assistant created via Promptbook',
|
|
16814
16755
|
model: 'gpt-4o',
|
|
16815
16756
|
instructions,
|
|
16816
16757
|
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
16817
|
-
|
|
16818
|
-
|
|
16758
|
+
};
|
|
16759
|
+
// Attach vector store if created
|
|
16760
|
+
if (vectorStoreId) {
|
|
16761
|
+
assistantConfig.tool_resources = {
|
|
16762
|
+
file_search: {
|
|
16763
|
+
vector_store_ids: [vectorStoreId],
|
|
16764
|
+
},
|
|
16765
|
+
};
|
|
16766
|
+
}
|
|
16767
|
+
const assistant = await client.beta.assistants.create(assistantConfig);
|
|
16819
16768
|
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
16820
16769
|
// TODO: !!!! Try listing existing assistants
|
|
16821
16770
|
// TODO: !!!! Try marking existing assistants by DISCRIMINANT
|
|
@@ -16858,7 +16807,7 @@ const DISCRIMINANT = 'OPEN_AI_ASSISTANT_V1';
|
|
|
16858
16807
|
* Execution Tools for calling LLM models with a predefined agent "soul"
|
|
16859
16808
|
* This wraps underlying LLM execution tools and applies agent-specific system prompts and requirements
|
|
16860
16809
|
*
|
|
16861
|
-
* Note: [🦖] There are several different things in Promptbook:
|
|
16810
|
+
* !!! Note: [🦖] There are several different things in Promptbook:
|
|
16862
16811
|
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
16863
16812
|
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
16864
16813
|
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
@@ -16974,6 +16923,7 @@ class AgentLlmExecutionTools {
|
|
|
16974
16923
|
const assistant = await this.options.llmTools.createNewAssistant({
|
|
16975
16924
|
name: this.title,
|
|
16976
16925
|
instructions: modelRequirements.systemMessage,
|
|
16926
|
+
knowledgeSources: modelRequirements.knowledgeSources,
|
|
16977
16927
|
/*
|
|
16978
16928
|
!!!
|
|
16979
16929
|
metadata: {
|
|
@@ -17024,7 +16974,7 @@ class AgentLlmExecutionTools {
|
|
|
17024
16974
|
/**
|
|
17025
16975
|
* Represents one AI Agent
|
|
17026
16976
|
*
|
|
17027
|
-
* Note: [🦖] There are several different things in Promptbook:
|
|
16977
|
+
* !!! Note: [🦖] There are several different things in Promptbook:
|
|
17028
16978
|
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
17029
16979
|
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
17030
16980
|
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
@@ -17032,7 +16982,7 @@ class AgentLlmExecutionTools {
|
|
|
17032
16982
|
*
|
|
17033
16983
|
* @public exported from `@promptbook/core`
|
|
17034
16984
|
*/
|
|
17035
|
-
class Agent {
|
|
16985
|
+
class Agent extends AgentLlmExecutionTools {
|
|
17036
16986
|
/**
|
|
17037
16987
|
* Not used in Agent, always returns empty array
|
|
17038
16988
|
*/
|
|
@@ -17042,7 +16992,12 @@ class Agent {
|
|
|
17042
16992
|
];
|
|
17043
16993
|
}
|
|
17044
16994
|
constructor(options) {
|
|
17045
|
-
|
|
16995
|
+
const agentSource = asUpdatableSubject(options.agentSource);
|
|
16996
|
+
super({
|
|
16997
|
+
isVerbose: options.isVerbose,
|
|
16998
|
+
llmTools: getSingleLlmExecutionTools(options.executionTools.llm),
|
|
16999
|
+
agentSource: agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
|
|
17000
|
+
});
|
|
17046
17001
|
/**
|
|
17047
17002
|
* Name of the agent
|
|
17048
17003
|
*/
|
|
@@ -17055,7 +17010,9 @@ class Agent {
|
|
|
17055
17010
|
* Metadata like image or color
|
|
17056
17011
|
*/
|
|
17057
17012
|
this.meta = {};
|
|
17058
|
-
|
|
17013
|
+
// TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
|
|
17014
|
+
// TODO: !!!! Add `Agent` learning by promptbookAgent
|
|
17015
|
+
this.agentSource = agentSource;
|
|
17059
17016
|
this.agentSource.subscribe((source) => {
|
|
17060
17017
|
const { agentName, personaDescription, meta } = parseAgentSource(source);
|
|
17061
17018
|
this.agentName = agentName;
|
|
@@ -17063,19 +17020,6 @@ class Agent {
|
|
|
17063
17020
|
this.meta = { ...this.meta, ...meta };
|
|
17064
17021
|
});
|
|
17065
17022
|
}
|
|
17066
|
-
/**
|
|
17067
|
-
* Creates LlmExecutionTools which exposes the agent as a model
|
|
17068
|
-
*/
|
|
17069
|
-
getLlmExecutionTools() {
|
|
17070
|
-
const llmTools = new AgentLlmExecutionTools({
|
|
17071
|
-
isVerbose: this.options.isVerbose,
|
|
17072
|
-
llmTools: getSingleLlmExecutionTools(this.options.executionTools.llm),
|
|
17073
|
-
agentSource: this.agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
|
|
17074
|
-
});
|
|
17075
|
-
// TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
|
|
17076
|
-
// TODO: !!!! Add `Agent` learning by promptbookAgent
|
|
17077
|
-
return llmTools;
|
|
17078
|
-
}
|
|
17079
17023
|
}
|
|
17080
17024
|
/**
|
|
17081
17025
|
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
@@ -17142,6 +17086,106 @@ const _AgentRegistration = $llmToolsRegister.register(createAgentLlmExecutionToo
|
|
|
17142
17086
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
17143
17087
|
*/
|
|
17144
17088
|
|
|
17089
|
+
/**
|
|
17090
|
+
* Represents one AI Agent
|
|
17091
|
+
*
|
|
17092
|
+
* !!! Note: [🦖] There are several different things in Promptbook:
|
|
17093
|
+
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
17094
|
+
* !!!! `RemoteAgent`
|
|
17095
|
+
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
17096
|
+
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
17097
|
+
* - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
|
|
17098
|
+
*
|
|
17099
|
+
* @public exported from `@promptbook/core`
|
|
17100
|
+
*/
|
|
17101
|
+
class RemoteAgent extends Agent {
|
|
17102
|
+
static async connect(options) {
|
|
17103
|
+
console.log('!!!!!', `${options.agentUrl}/api/book`);
|
|
17104
|
+
const bookResponse = await fetch(`${options.agentUrl}/api/book`);
|
|
17105
|
+
// <- TODO: !!!! What about closed-source agents?
|
|
17106
|
+
// <- TODO: !!!! Maybe use promptbookFetch
|
|
17107
|
+
const agentSourceValue = (await bookResponse.text());
|
|
17108
|
+
const agentSource = new BehaviorSubject(agentSourceValue);
|
|
17109
|
+
// <- TODO: !!!!!! Support updating
|
|
17110
|
+
return new RemoteAgent({
|
|
17111
|
+
...options,
|
|
17112
|
+
executionTools: {
|
|
17113
|
+
/* Note: These tools are not used */
|
|
17114
|
+
// ---------------------------------------
|
|
17115
|
+
/*
|
|
17116
|
+
TODO: !!! Get rid of
|
|
17117
|
+
|
|
17118
|
+
> You have not provided any `LlmExecutionTools`
|
|
17119
|
+
> This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.
|
|
17120
|
+
>
|
|
17121
|
+
> Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.
|
|
17122
|
+
|
|
17123
|
+
*/
|
|
17124
|
+
},
|
|
17125
|
+
agentSource,
|
|
17126
|
+
});
|
|
17127
|
+
}
|
|
17128
|
+
constructor(options) {
|
|
17129
|
+
super(options);
|
|
17130
|
+
this.agentUrl = options.agentUrl;
|
|
17131
|
+
}
|
|
17132
|
+
/**
|
|
17133
|
+
* Calls the agent on agents remote server
|
|
17134
|
+
*/
|
|
17135
|
+
async callChatModel(prompt) {
|
|
17136
|
+
// Ensure we're working with a chat prompt
|
|
17137
|
+
if (prompt.modelRequirements.modelVariant !== 'CHAT') {
|
|
17138
|
+
throw new Error('Agents only supports chat prompts');
|
|
17139
|
+
}
|
|
17140
|
+
const bookResponse = await fetch(`${this.agentUrl}/api/chat?message=${encodeURIComponent(prompt.content)}`);
|
|
17141
|
+
// <- TODO: !!!! What about closed-source agents?
|
|
17142
|
+
// <- TODO: !!!! Maybe use promptbookFetch
|
|
17143
|
+
let content = '';
|
|
17144
|
+
if (!bookResponse.body) {
|
|
17145
|
+
content = await bookResponse.text();
|
|
17146
|
+
}
|
|
17147
|
+
else {
|
|
17148
|
+
// Note: [🐚] Problem with streaming is not here but it is not implemented on server
|
|
17149
|
+
const decoder = new TextDecoder();
|
|
17150
|
+
// Web ReadableStream is not async-iterable in many runtimes; use a reader.
|
|
17151
|
+
const reader = bookResponse.body.getReader();
|
|
17152
|
+
try {
|
|
17153
|
+
let doneReading = false;
|
|
17154
|
+
while (!doneReading) {
|
|
17155
|
+
const { done, value } = await reader.read();
|
|
17156
|
+
doneReading = !!done;
|
|
17157
|
+
if (value) {
|
|
17158
|
+
const textChunk = decoder.decode(value, { stream: true });
|
|
17159
|
+
// console.debug('RemoteAgent chunk:', textChunk);
|
|
17160
|
+
content += textChunk;
|
|
17161
|
+
}
|
|
17162
|
+
}
|
|
17163
|
+
// Flush any remaining decoder internal state
|
|
17164
|
+
content += decoder.decode();
|
|
17165
|
+
}
|
|
17166
|
+
finally {
|
|
17167
|
+
reader.releaseLock();
|
|
17168
|
+
}
|
|
17169
|
+
}
|
|
17170
|
+
// <- TODO: !!!!!!!! Transfer metadata
|
|
17171
|
+
const agentResult = {
|
|
17172
|
+
content,
|
|
17173
|
+
modelName: this.modelName,
|
|
17174
|
+
timing: {},
|
|
17175
|
+
usage: {},
|
|
17176
|
+
rawPromptContent: {},
|
|
17177
|
+
rawRequest: {},
|
|
17178
|
+
rawResponse: {},
|
|
17179
|
+
// <- TODO: !!!!!!!! Transfer and proxy the metadata
|
|
17180
|
+
};
|
|
17181
|
+
return agentResult;
|
|
17182
|
+
}
|
|
17183
|
+
}
|
|
17184
|
+
/**
|
|
17185
|
+
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
17186
|
+
* TODO: !!! Agent on remote server
|
|
17187
|
+
*/
|
|
17188
|
+
|
|
17145
17189
|
/**
|
|
17146
17190
|
* Registration of LLM provider metadata
|
|
17147
17191
|
*
|
|
@@ -18360,8 +18404,7 @@ function aboutPromptbookInformation(options) {
|
|
|
18360
18404
|
|
|
18361
18405
|
## Servers
|
|
18362
18406
|
|
|
18363
|
-
${block(REMOTE_SERVER_URLS.map(({ title, urls,
|
|
18364
|
-
${isAnonymousModeAllowed ? '🐱💻 ' : ''} ${urls.join(', ')}
|
|
18407
|
+
${block(REMOTE_SERVER_URLS.map(({ title, urls, description }, index) => `${index + 1}. ${title} ${description} ${urls.join(', ')}
|
|
18365
18408
|
`).join('\n'))}
|
|
18366
18409
|
`);
|
|
18367
18410
|
fullInfoPieces.push(serversInfo);
|
|
@@ -18404,6 +18447,30 @@ function $randomItem(...items) {
|
|
|
18404
18447
|
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18405
18448
|
*/
|
|
18406
18449
|
|
|
18450
|
+
const PERSONALITIES = [
|
|
18451
|
+
'Friendly and helpful AI agent.',
|
|
18452
|
+
'Professional and efficient virtual assistant.',
|
|
18453
|
+
'Creative and imaginative digital companion.',
|
|
18454
|
+
'Knowledgeable and informative AI guide.',
|
|
18455
|
+
'Empathetic and understanding support bot.',
|
|
18456
|
+
'Energetic and enthusiastic conversational partner.',
|
|
18457
|
+
'Calm and patient virtual helper.',
|
|
18458
|
+
'Curious and inquisitive AI explorer.',
|
|
18459
|
+
'Witty and humorous digital friend.',
|
|
18460
|
+
'Serious and focused AI consultant.',
|
|
18461
|
+
];
|
|
18462
|
+
/**
|
|
18463
|
+
* @@@@
|
|
18464
|
+
*
|
|
18465
|
+
* @private internal helper function
|
|
18466
|
+
*/
|
|
18467
|
+
function $randomAgentPersona() {
|
|
18468
|
+
return $randomItem(...PERSONALITIES);
|
|
18469
|
+
}
|
|
18470
|
+
/**
|
|
18471
|
+
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18472
|
+
*/
|
|
18473
|
+
|
|
18407
18474
|
const FIRSTNAMES = [
|
|
18408
18475
|
'Paul',
|
|
18409
18476
|
'George',
|
|
@@ -18464,30 +18531,6 @@ function $randomFullnameWithColor() {
|
|
|
18464
18531
|
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18465
18532
|
*/
|
|
18466
18533
|
|
|
18467
|
-
const PERSONALITIES = [
|
|
18468
|
-
'Friendly and helpful AI agent.',
|
|
18469
|
-
'Professional and efficient virtual assistant.',
|
|
18470
|
-
'Creative and imaginative digital companion.',
|
|
18471
|
-
'Knowledgeable and informative AI guide.',
|
|
18472
|
-
'Empathetic and understanding support bot.',
|
|
18473
|
-
'Energetic and enthusiastic conversational partner.',
|
|
18474
|
-
'Calm and patient virtual helper.',
|
|
18475
|
-
'Curious and inquisitive AI explorer.',
|
|
18476
|
-
'Witty and humorous digital friend.',
|
|
18477
|
-
'Serious and focused AI consultant.',
|
|
18478
|
-
];
|
|
18479
|
-
/**
|
|
18480
|
-
* @@@@
|
|
18481
|
-
*
|
|
18482
|
-
* @private internal helper function
|
|
18483
|
-
*/
|
|
18484
|
-
function $randomAgentPersona() {
|
|
18485
|
-
return $randomItem(...PERSONALITIES);
|
|
18486
|
-
}
|
|
18487
|
-
/**
|
|
18488
|
-
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18489
|
-
*/
|
|
18490
|
-
|
|
18491
18534
|
/**
|
|
18492
18535
|
* Generates boilerplate for a new agent book
|
|
18493
18536
|
*
|
|
@@ -18521,5 +18564,5 @@ function $generateBookBoilerplate(options) {
|
|
|
18521
18564
|
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
18522
18565
|
*/
|
|
18523
18566
|
|
|
18524
|
-
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
18567
|
+
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, RemoteAgent, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
18525
18568
|
//# sourceMappingURL=index.es.js.map
|