@promptbook/core 0.104.0-15 → 0.104.0-17

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 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.104.0-15';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-17';
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
@@ -10617,6 +10617,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
10617
10617
  const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
10618
10618
  ? existingTools
10619
10619
  : [
10620
+ // TODO: [🔰] Use through proper MCP server
10620
10621
  ...existingTools,
10621
10622
  {
10622
10623
  name: 'web_browser',
@@ -10804,13 +10805,18 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10804
10805
  ? existingTools
10805
10806
  : [
10806
10807
  ...existingTools,
10808
+ { type: 'web_search' },
10809
+ // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
10810
+ // In future we will use proper MCP search tool:
10811
+ /*
10812
+
10807
10813
  {
10808
10814
  name: 'web_search',
10809
- description: spaceTrim$1(`
10810
- Search the internet for information.
10811
- Use this tool when you need to find up-to-date information or facts that you don't know.
10812
- ${!content ? '' : `Search scope / instructions: ${content}`}
10813
- `),
10815
+ description: spaceTrim(`
10816
+ Search the internet for information.
10817
+ Use this tool when you need to find up-to-date information or facts that you don't know.
10818
+ ${!content ? '' : `Search scope / instructions: ${content}`}
10819
+ `),
10814
10820
  parameters: {
10815
10821
  type: 'object',
10816
10822
  properties: {
@@ -10822,6 +10828,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10822
10828
  required: ['query'],
10823
10829
  },
10824
10830
  },
10831
+ */
10825
10832
  ];
10826
10833
  // Return requirements with updated tools and metadata
10827
10834
  return {
@@ -12292,7 +12299,7 @@ function $randomBase58(length) {
12292
12299
  * @public exported from `@promptbook/core`
12293
12300
  * <- TODO: [🐱‍🚀] Move to `@promptbook/supabase` package
12294
12301
  */
12295
- class AgentCollectionInSupabase /* TODO: [🐱‍🚀] implements Agent */ {
12302
+ class AgentCollectionInSupabase /* TODO: [🌈][🐱‍🚀] implements AgentCollection */ {
12296
12303
  /**
12297
12304
  * @param supabaseClient - The initialized Supabase client
12298
12305
  * @param options - Configuration options for the collection (e.g., table prefix, verbosity)
@@ -17198,6 +17205,27 @@ function limitTotalUsage(llmTools, options = {}) {
17198
17205
  * TODO: [👷‍♂️] Write a comprehensive manual about the construction of LLM tools
17199
17206
  */
17200
17207
 
17208
+ /*! *****************************************************************************
17209
+ Copyright (c) Microsoft Corporation.
17210
+
17211
+ Permission to use, copy, modify, and/or distribute this software for any
17212
+ purpose with or without fee is hereby granted.
17213
+
17214
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17215
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17216
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17217
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17218
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17219
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17220
+ PERFORMANCE OF THIS SOFTWARE.
17221
+ ***************************************************************************** */
17222
+
17223
+ function __classPrivateFieldGet(receiver, state, kind, f) {
17224
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
17225
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
17226
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17227
+ }
17228
+
17201
17229
  /**
17202
17230
  * Restricts an Updatable to a (2) BehaviorSubject variant
17203
17231
  *
@@ -19667,6 +19695,7 @@ AgentLlmExecutionTools.assistantCache = new Map();
19667
19695
  * TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
19668
19696
  */
19669
19697
 
19698
+ var _Agent_instances, _Agent_selfLearn;
19670
19699
  /**
19671
19700
  * Represents one AI Agent
19672
19701
  *
@@ -19707,6 +19736,7 @@ class Agent extends AgentLlmExecutionTools {
19707
19736
  llmTools: getSingleLlmExecutionTools(options.executionTools.llm),
19708
19737
  agentSource: agentSource.value, // <- TODO: [🐱‍🚀] Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
19709
19738
  });
19739
+ _Agent_instances.add(this);
19710
19740
  this._agentName = undefined;
19711
19741
  /**
19712
19742
  * Description of the agent
@@ -19800,9 +19830,18 @@ class Agent extends AgentLlmExecutionTools {
19800
19830
  if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
19801
19831
  return result;
19802
19832
  }
19803
- // TODO: !!! Extract learning to separate method
19804
- // Learning: Append the conversation sample to the agent source
19805
- const learningExample = spaceTrim$2((block) => `
19833
+ await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearn).call(this, prompt, result);
19834
+ // <- TODO: !!!! Do not await self-learn, run in background with error handling
19835
+ return result;
19836
+ }
19837
+ }
19838
+ _Agent_instances = new WeakSet(), _Agent_selfLearn =
19839
+ /**
19840
+ * Self-learning: Appends the conversation and extracted knowledge to the agent source
19841
+ */
19842
+ async function _Agent_selfLearn(prompt, result) {
19843
+ // Learning: Append the conversation sample to the agent source
19844
+ const learningExample = spaceTrim$2((block) => `
19806
19845
 
19807
19846
  ---
19808
19847
 
@@ -19813,15 +19852,15 @@ class Agent extends AgentLlmExecutionTools {
19813
19852
  ${block(result.content)}
19814
19853
 
19815
19854
  `);
19816
- // Extract knowledge
19817
- let knowledgeBlock = '';
19818
- try {
19819
- const extractionPrompt = {
19820
- title: 'Knowledge Extraction',
19821
- modelRequirements: {
19822
- modelVariant: 'CHAT',
19823
- },
19824
- content: spaceTrim$2((block) => `
19855
+ // Extract knowledge
19856
+ let knowledgeBlock = '';
19857
+ try {
19858
+ const extractionPrompt = {
19859
+ title: 'Knowledge Extraction',
19860
+ modelRequirements: {
19861
+ modelVariant: 'CHAT',
19862
+ },
19863
+ content: spaceTrim$2((block) => `
19825
19864
  You are an AI agent that is learning from a conversation.
19826
19865
 
19827
19866
  Here is the conversation so far:
@@ -19837,33 +19876,31 @@ class Agent extends AgentLlmExecutionTools {
19837
19876
  KNOWLEDGE The user's name is Alice.
19838
19877
  KNOWLEDGE The project deadline is next Friday.
19839
19878
  `),
19840
- pipelineUrl: 'https://github.com/webgptorg/promptbook/blob/main/prompts/knowledge-extraction.ptbk.md',
19841
- parameters: {},
19842
- };
19843
- if (this.options.llmTools.callChatModel) {
19844
- const extractionResult = await this.options.llmTools.callChatModel(extractionPrompt);
19845
- const extractedContent = extractionResult.content;
19846
- if (extractedContent.includes('KNOWLEDGE')) {
19847
- knowledgeBlock = '\n\n' + spaceTrim$2(extractedContent);
19848
- }
19849
- }
19850
- else {
19851
- // TODO: [🧠] Fallback to callChatModelStream if callChatModel is not available
19879
+ pipelineUrl: 'https://github.com/webgptorg/promptbook/blob/main/prompts/knowledge-extraction.ptbk.md',
19880
+ parameters: {},
19881
+ };
19882
+ if (this.options.llmTools.callChatModel) {
19883
+ const extractionResult = await this.options.llmTools.callChatModel(extractionPrompt);
19884
+ const extractedContent = extractionResult.content;
19885
+ if (extractedContent.includes('KNOWLEDGE')) {
19886
+ knowledgeBlock = '\n\n' + spaceTrim$2(extractedContent);
19852
19887
  }
19853
19888
  }
19854
- catch (error) {
19855
- if (this.options.isVerbose) {
19856
- console.warn('Failed to extract knowledge', error);
19857
- }
19889
+ else {
19890
+ // TODO: [🧠] Fallback to callChatModelStream if callChatModel is not available
19858
19891
  }
19859
- // Append to the current source
19860
- const currentSource = this.agentSource.value;
19861
- const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + learningExample + knowledgeBlock));
19862
- // Update the source (which will trigger the subscription and update the underlying tools)
19863
- this.agentSource.next(newSource);
19864
- return result;
19865
19892
  }
19866
- }
19893
+ catch (error) {
19894
+ if (this.options.isVerbose) {
19895
+ console.warn('Failed to extract knowledge', error);
19896
+ }
19897
+ }
19898
+ // Append to the current source
19899
+ const currentSource = this.agentSource.value;
19900
+ const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + learningExample + knowledgeBlock));
19901
+ // Update the source (which will trigger the subscription and update the underlying tools)
19902
+ this.agentSource.next(newSource);
19903
+ };
19867
19904
  /**
19868
19905
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
19869
19906
  */