@promptbook/core 0.103.0-49 → 0.103.0-50
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 +73 -16
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgent.d.ts +20 -0
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +8 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +7 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +5 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +73 -16
- package/umd/index.umd.js.map +1 -1
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-50';
|
|
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
|
|
@@ -10487,23 +10487,21 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
10487
10487
|
const selectResult = await this.supabaseClient
|
|
10488
10488
|
.from(this.getTableName('Agent'))
|
|
10489
10489
|
.select('agentSource')
|
|
10490
|
-
.eq('agentName', agentName)
|
|
10491
|
-
|
|
10492
|
-
/*
|
|
10493
|
-
if (selectResult.data===null) {
|
|
10490
|
+
.eq('agentName', agentName);
|
|
10491
|
+
if (selectResult.data && selectResult.data.length === 0) {
|
|
10494
10492
|
throw new NotFoundError(`Agent "${agentName}" not found`);
|
|
10495
10493
|
}
|
|
10496
|
-
|
|
10497
|
-
|
|
10494
|
+
else if (selectResult.data && selectResult.data.length > 1) {
|
|
10495
|
+
throw new UnexpectedError(`More agents with agentName="${agentName}" found`);
|
|
10496
|
+
}
|
|
10497
|
+
else if (selectResult.error) {
|
|
10498
10498
|
throw new DatabaseError(spaceTrim((block) => `
|
|
10499
|
-
|
|
10500
10499
|
Error fetching agent "${agentName}" from Supabase:
|
|
10501
10500
|
|
|
10502
10501
|
${block(selectResult.error.message)}
|
|
10503
10502
|
`));
|
|
10504
|
-
// <- TODO: [🐱🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`
|
|
10505
10503
|
}
|
|
10506
|
-
return selectResult.data.agentSource;
|
|
10504
|
+
return selectResult.data[0].agentSource;
|
|
10507
10505
|
}
|
|
10508
10506
|
/**
|
|
10509
10507
|
* Creates a new agent in the collection
|
|
@@ -10558,7 +10556,7 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
10558
10556
|
|
|
10559
10557
|
${block(selectPreviousAgentResult.error.message)}
|
|
10560
10558
|
`));
|
|
10561
|
-
// <- TODO: [🐱🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`
|
|
10559
|
+
// <- TODO: [🐱🚀] First check if the error is "not found" and throw `NotFoundError` instead then throw `DatabaseError`, look at `getAgentSource` implementation
|
|
10562
10560
|
}
|
|
10563
10561
|
selectPreviousAgentResult.data.agentName;
|
|
10564
10562
|
const previousAgentHash = selectPreviousAgentResult.data.agentHash;
|
|
@@ -17233,6 +17231,16 @@ class AgentLlmExecutionTools {
|
|
|
17233
17231
|
*/
|
|
17234
17232
|
this._cachedAgentInfo = null;
|
|
17235
17233
|
}
|
|
17234
|
+
/**
|
|
17235
|
+
* Updates the agent source and clears the cache
|
|
17236
|
+
*
|
|
17237
|
+
* @param agentSource The new agent source string
|
|
17238
|
+
*/
|
|
17239
|
+
updateAgentSource(agentSource) {
|
|
17240
|
+
this.options.agentSource = agentSource;
|
|
17241
|
+
this._cachedAgentInfo = null;
|
|
17242
|
+
this._cachedModelRequirements = null;
|
|
17243
|
+
}
|
|
17236
17244
|
/**
|
|
17237
17245
|
* Get cached or parse agent information
|
|
17238
17246
|
*/
|
|
@@ -17479,6 +17487,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
17479
17487
|
// TODO: [🐱🚀] Add `Agent` learning by promptbookAgent
|
|
17480
17488
|
this.agentSource = agentSource;
|
|
17481
17489
|
this.agentSource.subscribe((source) => {
|
|
17490
|
+
this.updateAgentSource(source);
|
|
17482
17491
|
const { agentName, personaDescription, initialMessage, links, meta } = parseAgentSource(source);
|
|
17483
17492
|
this._agentName = agentName;
|
|
17484
17493
|
this.personaDescription = personaDescription;
|
|
@@ -17487,6 +17496,35 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
17487
17496
|
this.meta = { ...this.meta, ...meta };
|
|
17488
17497
|
});
|
|
17489
17498
|
}
|
|
17499
|
+
/**
|
|
17500
|
+
* Calls the chat model with agent-specific system prompt and requirements with streaming
|
|
17501
|
+
*
|
|
17502
|
+
* Note: This method also implements the learning mechanism
|
|
17503
|
+
*/
|
|
17504
|
+
async callChatModelStream(prompt, onProgress) {
|
|
17505
|
+
const result = await super.callChatModelStream(prompt, onProgress);
|
|
17506
|
+
// TODO: !!! Extract learning to separate method
|
|
17507
|
+
// Learning: Append the conversation sample to the agent source
|
|
17508
|
+
const learningExample = spaceTrim$1((block) => `
|
|
17509
|
+
|
|
17510
|
+
---
|
|
17511
|
+
|
|
17512
|
+
SAMPLE
|
|
17513
|
+
|
|
17514
|
+
User:
|
|
17515
|
+
${block(prompt.content)}
|
|
17516
|
+
|
|
17517
|
+
${this.title} (Me, the Agent):
|
|
17518
|
+
${block(result.content)}
|
|
17519
|
+
|
|
17520
|
+
`);
|
|
17521
|
+
// Append to the current source
|
|
17522
|
+
const currentSource = this.agentSource.value;
|
|
17523
|
+
const newSource = padBook(validateBook(spaceTrim$1(currentSource) + '\n\n' + learningExample));
|
|
17524
|
+
// Update the source (which will trigger the subscription and update the underlying tools)
|
|
17525
|
+
this.agentSource.next(newSource);
|
|
17526
|
+
return result;
|
|
17527
|
+
}
|
|
17490
17528
|
}
|
|
17491
17529
|
/**
|
|
17492
17530
|
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
@@ -17566,14 +17604,20 @@ const _AgentRegistration = $llmToolsRegister.register(createAgentLlmExecutionToo
|
|
|
17566
17604
|
*/
|
|
17567
17605
|
class RemoteAgent extends Agent {
|
|
17568
17606
|
static async connect(options) {
|
|
17569
|
-
console.log('[🐱🚀]', `${options.agentUrl}/api/
|
|
17570
|
-
const
|
|
17607
|
+
console.log('[🐱🚀]', `${options.agentUrl}/api/profile`);
|
|
17608
|
+
const profileResponse = await fetch(`${options.agentUrl}/api/profile`);
|
|
17571
17609
|
// <- TODO: [🐱🚀] What about closed-source agents?
|
|
17572
17610
|
// <- TODO: [🐱🚀] Maybe use promptbookFetch
|
|
17573
|
-
const
|
|
17574
|
-
|
|
17611
|
+
const profile = await profileResponse.json();
|
|
17612
|
+
// Note: We are creating dummy agent source because we don't have the source from the remote agent
|
|
17613
|
+
// But we populate the metadata from the profile
|
|
17614
|
+
const agentSource = new BehaviorSubject(`
|
|
17615
|
+
# ${profile.agentName}
|
|
17616
|
+
|
|
17617
|
+
${profile.personaDescription}
|
|
17618
|
+
`);
|
|
17575
17619
|
// <- TODO: [🐱🚀] Support updating and self-updating
|
|
17576
|
-
|
|
17620
|
+
const remoteAgent = new RemoteAgent({
|
|
17577
17621
|
...options,
|
|
17578
17622
|
executionTools: {
|
|
17579
17623
|
/* Note: These tools are not used */
|
|
@@ -17590,11 +17634,24 @@ class RemoteAgent extends Agent {
|
|
|
17590
17634
|
},
|
|
17591
17635
|
agentSource,
|
|
17592
17636
|
});
|
|
17637
|
+
remoteAgent._remoteAgentName = profile.agentName;
|
|
17638
|
+
remoteAgent._remoteAgentHash = profile.agentHash;
|
|
17639
|
+
remoteAgent.personaDescription = profile.personaDescription;
|
|
17640
|
+
remoteAgent.initialMessage = profile.initialMessage;
|
|
17641
|
+
remoteAgent.links = profile.links;
|
|
17642
|
+
remoteAgent.meta = profile.meta;
|
|
17643
|
+
return remoteAgent;
|
|
17593
17644
|
}
|
|
17594
17645
|
constructor(options) {
|
|
17595
17646
|
super(options);
|
|
17596
17647
|
this.agentUrl = options.agentUrl;
|
|
17597
17648
|
}
|
|
17649
|
+
get agentName() {
|
|
17650
|
+
return this._remoteAgentName || super.agentName;
|
|
17651
|
+
}
|
|
17652
|
+
get agentHash() {
|
|
17653
|
+
return this._remoteAgentHash || super.agentHash;
|
|
17654
|
+
}
|
|
17598
17655
|
/**
|
|
17599
17656
|
* Calls the agent on agents remote server
|
|
17600
17657
|
*/
|