@promptbook/core 0.104.0-10 → 0.104.0-12

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.
Files changed (40) hide show
  1. package/esm/index.es.js +154 -32
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/types.index.d.ts +8 -0
  4. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +24 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +5 -0
  6. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.tools.test.d.ts +1 -0
  7. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +2 -2
  8. package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +1 -1
  9. package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +1 -1
  10. package/esm/typings/src/book-components/icons/AboutIcon.d.ts +1 -1
  11. package/esm/typings/src/book-components/icons/AttachmentIcon.d.ts +1 -1
  12. package/esm/typings/src/book-components/icons/CameraIcon.d.ts +1 -1
  13. package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +1 -1
  14. package/esm/typings/src/book-components/icons/MenuIcon.d.ts +1 -1
  15. package/esm/typings/src/book-components/icons/SaveIcon.d.ts +1 -1
  16. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +2 -2
  17. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +0 -54
  18. package/esm/typings/src/commitments/META/META_DESCRIPTION.d.ts +41 -0
  19. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
  20. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  21. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
  22. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +1 -1
  24. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/agent/Agent.d.ts +6 -1
  28. package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
  29. package/esm/typings/src/remote-server/ui/ServerApp.d.ts +1 -1
  30. package/esm/typings/src/search-engines/SearchEngine.d.ts +9 -0
  31. package/esm/typings/src/search-engines/SearchResult.d.ts +18 -0
  32. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +15 -0
  33. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +15 -0
  34. package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
  35. package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
  36. package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +3 -2
  37. package/esm/typings/src/version.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/umd/index.umd.js +154 -32
  40. 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.104.0-10';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-12';
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
@@ -3763,7 +3763,7 @@ function countUsage(llmTools) {
3763
3763
  * TODO: [🧠] Is there some meaningfull way how to test this util
3764
3764
  * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
3765
3765
  * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
3766
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
3766
+ * TODO: [👷‍♂️] Write a comprehensive manual explaining the construction and usage of LLM tools in the Promptbook ecosystem
3767
3767
  */
3768
3768
 
3769
3769
  /**
@@ -4003,7 +4003,7 @@ function joinLlmExecutionTools(title, ...llmExecutionTools) {
4003
4003
  }
4004
4004
  /**
4005
4005
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
4006
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
4006
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
4007
4007
  */
4008
4008
 
4009
4009
  /**
@@ -4020,7 +4020,7 @@ function getSingleLlmExecutionTools(oneOrMoreLlmExecutionTools) {
4020
4020
  }
4021
4021
  /**
4022
4022
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
4023
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
4023
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
4024
4024
  */
4025
4025
 
4026
4026
  /**
@@ -10605,19 +10605,37 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
10605
10605
  `);
10606
10606
  }
10607
10607
  applyToAgentModelRequirements(requirements, content) {
10608
- // We simply mark that browser capability is enabled in metadata
10609
- // Get existing metadata
10610
- const existingMetadata = requirements.metadata || {};
10611
10608
  // Get existing tools array or create new one
10612
- const existingTools = existingMetadata.tools || [];
10613
- // Add 'browser' to tools if not already present
10614
- const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
10615
- // Return requirements with updated metadata
10609
+ const existingTools = requirements.tools || [];
10610
+ // Add 'web_browser' to tools if not already present
10611
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
10612
+ ? existingTools
10613
+ : [
10614
+ ...existingTools,
10615
+ {
10616
+ name: 'web_browser',
10617
+ description: spaceTrim$1(`
10618
+ A tool that can browse the web.
10619
+ Use this tool when you need to access specific websites or browse the internet.
10620
+ `),
10621
+ parameters: {
10622
+ type: 'object',
10623
+ properties: {
10624
+ url: {
10625
+ type: 'string',
10626
+ description: 'The URL to browse',
10627
+ },
10628
+ },
10629
+ required: ['url'],
10630
+ },
10631
+ },
10632
+ ];
10633
+ // Return requirements with updated tools and metadata
10616
10634
  return {
10617
10635
  ...requirements,
10636
+ tools: updatedTools,
10618
10637
  metadata: {
10619
- ...existingMetadata,
10620
- tools: updatedTools,
10638
+ ...requirements.metadata,
10621
10639
  useBrowser: true,
10622
10640
  },
10623
10641
  };
@@ -10710,13 +10728,13 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
10710
10728
  * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
10711
10729
  * to access and retrieve up-to-date information from the internet when necessary.
10712
10730
  *
10713
- * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
10731
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
10714
10732
  *
10715
10733
  * Example usage in agent source:
10716
10734
  *
10717
10735
  * ```book
10718
10736
  * USE SEARCH ENGINE
10719
- * USE SEARCH ENGINE This will be ignored
10737
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
10720
10738
  * ```
10721
10739
  *
10722
10740
  * @private [🪔] Maybe export the commitments through some package
@@ -10748,7 +10766,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10748
10766
 
10749
10767
  ## Key aspects
10750
10768
 
10751
- - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
10769
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
10752
10770
  - The actual search engine tool usage is handled by the agent runtime
10753
10771
  - Allows the agent to search for current information from the web
10754
10772
  - Useful for research tasks, finding facts, and accessing dynamic content
@@ -10773,20 +10791,39 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10773
10791
  `);
10774
10792
  }
10775
10793
  applyToAgentModelRequirements(requirements, content) {
10776
- // We simply mark that search engine capability is enabled in metadata
10777
- // Get existing metadata
10778
- const existingMetadata = requirements.metadata || {};
10779
10794
  // Get existing tools array or create new one
10780
- const existingTools = existingMetadata.tools || [];
10781
- // Add 'search-engine' to tools if not already present
10782
- const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
10783
- // Return requirements with updated metadata
10795
+ const existingTools = requirements.tools || [];
10796
+ // Add 'web_search' to tools if not already present
10797
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
10798
+ ? existingTools
10799
+ : [
10800
+ ...existingTools,
10801
+ {
10802
+ name: 'web_search',
10803
+ description: spaceTrim$1(`
10804
+ Search the internet for information.
10805
+ Use this tool when you need to find up-to-date information or facts that you don't know.
10806
+ ${!content ? '' : `Search scope / instructions: ${content}`}
10807
+ `),
10808
+ parameters: {
10809
+ type: 'object',
10810
+ properties: {
10811
+ query: {
10812
+ type: 'string',
10813
+ description: 'The search query',
10814
+ },
10815
+ },
10816
+ required: ['query'],
10817
+ },
10818
+ },
10819
+ ];
10820
+ // Return requirements with updated tools and metadata
10784
10821
  return {
10785
10822
  ...requirements,
10823
+ tools: updatedTools,
10786
10824
  metadata: {
10787
- ...existingMetadata,
10788
- tools: updatedTools,
10789
- useSearchEngine: true,
10825
+ ...requirements.metadata,
10826
+ useSearchEngine: content || true,
10790
10827
  },
10791
10828
  };
10792
10829
  }
@@ -11895,7 +11932,57 @@ function parseAgentSource(agentSource) {
11895
11932
  }
11896
11933
  const meta = {};
11897
11934
  const links = [];
11935
+ const capabilities = [];
11898
11936
  for (const commitment of parseResult.commitments) {
11937
+ if (commitment.type === 'USE BROWSER') {
11938
+ capabilities.push({
11939
+ type: 'browser',
11940
+ label: 'Browser',
11941
+ iconName: 'Globe',
11942
+ });
11943
+ continue;
11944
+ }
11945
+ if (commitment.type === 'USE SEARCH ENGINE') {
11946
+ capabilities.push({
11947
+ type: 'search-engine',
11948
+ label: 'Search Internet',
11949
+ iconName: 'Search',
11950
+ });
11951
+ continue;
11952
+ }
11953
+ if (commitment.type === 'KNOWLEDGE') {
11954
+ const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
11955
+ let label = content;
11956
+ let iconName = 'Book';
11957
+ if (content.startsWith('http://') || content.startsWith('https://')) {
11958
+ try {
11959
+ const url = new URL(content);
11960
+ if (url.pathname.endsWith('.pdf')) {
11961
+ label = url.pathname.split('/').pop() || 'Document.pdf';
11962
+ iconName = 'FileText';
11963
+ }
11964
+ else {
11965
+ label = url.hostname.replace(/^www\./, '');
11966
+ }
11967
+ }
11968
+ catch (e) {
11969
+ // Invalid URL, treat as text
11970
+ }
11971
+ }
11972
+ else {
11973
+ // Text content - take first few words
11974
+ const words = content.split(/\s+/);
11975
+ if (words.length > 4) {
11976
+ label = words.slice(0, 4).join(' ') + '...';
11977
+ }
11978
+ }
11979
+ capabilities.push({
11980
+ type: 'knowledge',
11981
+ label,
11982
+ iconName,
11983
+ });
11984
+ continue;
11985
+ }
11899
11986
  if (commitment.type === 'META LINK') {
11900
11987
  const linkValue = spaceTrim$2(commitment.content);
11901
11988
  links.push(linkValue);
@@ -11906,6 +11993,10 @@ function parseAgentSource(agentSource) {
11906
11993
  meta.image = spaceTrim$2(commitment.content);
11907
11994
  continue;
11908
11995
  }
11996
+ if (commitment.type === 'META DESCRIPTION') {
11997
+ meta.description = spaceTrim$2(commitment.content);
11998
+ continue;
11999
+ }
11909
12000
  if (commitment.type === 'META COLOR') {
11910
12001
  meta.color = normalizeSeparator(commitment.content);
11911
12002
  continue;
@@ -11942,6 +12033,7 @@ function parseAgentSource(agentSource) {
11942
12033
  meta,
11943
12034
  links,
11944
12035
  parameters,
12036
+ capabilities,
11945
12037
  };
11946
12038
  }
11947
12039
  /**
@@ -12244,7 +12336,7 @@ class AgentCollectionInSupabase /* TODO: [🐱‍🚀] implements Agent */ {
12244
12336
  });
12245
12337
  }
12246
12338
  /**
12247
- * [🐱‍🚀]@@@
12339
+ * Retrieves the permanent ID of an agent by its name or permanent ID.
12248
12340
  */
12249
12341
  async getAgentPermanentId(agentNameOrPermanentId) {
12250
12342
  const selectResult = await this.supabaseClient
@@ -12258,7 +12350,7 @@ class AgentCollectionInSupabase /* TODO: [🐱‍🚀] implements Agent */ {
12258
12350
  return selectResult.data.permanentId;
12259
12351
  }
12260
12352
  /**
12261
- * [🐱‍🚀]@@@
12353
+ * Retrieves the source code of an agent by its name or permanent ID.
12262
12354
  */
12263
12355
  async getAgentSource(agentNameOrPermanentId) {
12264
12356
  const selectResult = await this.supabaseClient
@@ -12535,6 +12627,7 @@ class AgentCollectionInSupabase /* TODO: [🐱‍🚀] implements Agent */ {
12535
12627
  getTableName(tableName) {
12536
12628
  const { tablePrefix = '' } = this.options || {};
12537
12629
  return `${tablePrefix}${tableName}`;
12630
+ // <- TODO: [🏧] DRY
12538
12631
  }
12539
12632
  }
12540
12633
  /**
@@ -17089,7 +17182,7 @@ function limitTotalUsage(llmTools, options = {}) {
17089
17182
  * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
17090
17183
  * TODO: [🧠] Is there some meaningfull way how to test this util
17091
17184
  * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
17092
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
17185
+ * TODO: [👷‍♂️] Write a comprehensive manual about the construction of LLM tools
17093
17186
  */
17094
17187
 
17095
17188
  /**
@@ -17977,6 +18070,22 @@ resultContent, rawResponse) {
17977
18070
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
17978
18071
  */
17979
18072
 
18073
+ /**
18074
+ * Maps Promptbook tools to OpenAI tools.
18075
+ *
18076
+ * @private
18077
+ */
18078
+ function mapToolsToOpenAi(tools) {
18079
+ return tools.map((tool) => ({
18080
+ type: 'function',
18081
+ function: {
18082
+ name: tool.name,
18083
+ description: tool.description,
18084
+ parameters: tool.parameters,
18085
+ },
18086
+ }));
18087
+ }
18088
+
17980
18089
  /**
17981
18090
  * Parses an OpenAI error message to identify which parameter is unsupported
17982
18091
  *
@@ -18174,6 +18283,9 @@ class OpenAiCompatibleExecutionTools {
18174
18283
  },
18175
18284
  ],
18176
18285
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18286
+ tools: currentModelRequirements.tools === undefined
18287
+ ? undefined
18288
+ : mapToolsToOpenAi(currentModelRequirements.tools),
18177
18289
  };
18178
18290
  const start = $getCurrentDate();
18179
18291
  if (this.options.isVerbose) {
@@ -18318,6 +18430,7 @@ class OpenAiCompatibleExecutionTools {
18318
18430
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18319
18431
  const rawRequest = {
18320
18432
  ...modelSettings,
18433
+ model: modelName,
18321
18434
  prompt: rawPromptContent,
18322
18435
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18323
18436
  };
@@ -18572,8 +18685,8 @@ class OpenAiCompatibleExecutionTools {
18572
18685
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18573
18686
  const rawRequest = {
18574
18687
  ...modelSettings,
18575
- size: modelSettings.size || '1024x1024',
18576
18688
  prompt: rawPromptContent,
18689
+ size: modelSettings.size || '1024x1024',
18577
18690
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18578
18691
  response_format: 'url', // TODO: [🧠] Maybe allow b64_json
18579
18692
  };
@@ -18975,6 +19088,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
18975
19088
  thread: {
18976
19089
  messages: threadMessages,
18977
19090
  },
19091
+ tools: modelRequirements.tools === undefined ? undefined : mapToolsToOpenAi(modelRequirements.tools),
18978
19092
  // <- TODO: Add user identification here> user: this.options.user,
18979
19093
  };
18980
19094
  const start = $getCurrentDate();
@@ -19498,6 +19612,8 @@ class AgentLlmExecutionTools {
19498
19612
  modelRequirements: {
19499
19613
  ...chatPrompt.modelRequirements,
19500
19614
  ...modelRequirements,
19615
+ // Spread tools to convert readonly array to mutable
19616
+ tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
19501
19617
  // Prepend agent system message to existing system message
19502
19618
  systemMessage: modelRequirements.systemMessage +
19503
19619
  (chatPrompt.modelRequirements.systemMessage
@@ -19591,6 +19707,11 @@ class Agent extends AgentLlmExecutionTools {
19591
19707
  * Links found in the agent source
19592
19708
  */
19593
19709
  this.links = [];
19710
+ /**
19711
+ * Capabilities of the agent
19712
+ * This is parsed from commitments like USE BROWSER, USE SEARCH ENGINE, KNOWLEDGE, etc.
19713
+ */
19714
+ this.capabilities = [];
19594
19715
  /**
19595
19716
  * Metadata like image or color
19596
19717
  */
@@ -19600,11 +19721,12 @@ class Agent extends AgentLlmExecutionTools {
19600
19721
  this.agentSource = agentSource;
19601
19722
  this.agentSource.subscribe((source) => {
19602
19723
  this.updateAgentSource(source);
19603
- const { agentName, personaDescription, initialMessage, links, meta } = parseAgentSource(source);
19724
+ const { agentName, personaDescription, initialMessage, links, meta, capabilities } = parseAgentSource(source);
19604
19725
  this._agentName = agentName;
19605
19726
  this.personaDescription = personaDescription;
19606
19727
  this.initialMessage = initialMessage;
19607
19728
  this.links = links;
19729
+ this.capabilities = capabilities;
19608
19730
  this.meta = { ...this.meta, ...meta };
19609
19731
  });
19610
19732
  }
@@ -21175,7 +21297,7 @@ const PERSONALITIES = [
21175
21297
  'Serious and focused AI consultant.',
21176
21298
  ];
21177
21299
  /**
21178
- * @@@@
21300
+ * Generates a random agent persona description.
21179
21301
  *
21180
21302
  * @private internal helper function
21181
21303
  */