@promptbook/core 0.104.0-11 β†’ 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 (24) hide show
  1. package/esm/index.es.js +91 -27
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  4. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -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/commitments/META/META_DESCRIPTION.d.ts +41 -0
  8. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
  9. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  10. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
  11. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
  12. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
  14. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
  16. package/esm/typings/src/search-engines/SearchResult.d.ts +4 -4
  17. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +1 -1
  18. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +1 -1
  19. package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
  20. package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
  21. package/esm/typings/src/version.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/umd/index.umd.js +91 -27
  24. 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-11';
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
@@ -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
  }
@@ -11956,6 +11993,10 @@ function parseAgentSource(agentSource) {
11956
11993
  meta.image = spaceTrim$2(commitment.content);
11957
11994
  continue;
11958
11995
  }
11996
+ if (commitment.type === 'META DESCRIPTION') {
11997
+ meta.description = spaceTrim$2(commitment.content);
11998
+ continue;
11999
+ }
11959
12000
  if (commitment.type === 'META COLOR') {
11960
12001
  meta.color = normalizeSeparator(commitment.content);
11961
12002
  continue;
@@ -17141,7 +17182,7 @@ function limitTotalUsage(llmTools, options = {}) {
17141
17182
  * TODO: [🧠][πŸ’Έ] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
17142
17183
  * TODO: [🧠] Is there some meaningfull way how to test this util
17143
17184
  * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
17144
- * TODO: [πŸ‘·β€β™‚οΈ] @@@ Manual about construction of llmTools
17185
+ * TODO: [πŸ‘·β€β™‚οΈ] Write a comprehensive manual about the construction of LLM tools
17145
17186
  */
17146
17187
 
17147
17188
  /**
@@ -18029,6 +18070,22 @@ resultContent, rawResponse) {
18029
18070
  * TODO: [🀝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
18030
18071
  */
18031
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
+
18032
18089
  /**
18033
18090
  * Parses an OpenAI error message to identify which parameter is unsupported
18034
18091
  *
@@ -18226,6 +18283,9 @@ class OpenAiCompatibleExecutionTools {
18226
18283
  },
18227
18284
  ],
18228
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),
18229
18289
  };
18230
18290
  const start = $getCurrentDate();
18231
18291
  if (this.options.isVerbose) {
@@ -18370,6 +18430,7 @@ class OpenAiCompatibleExecutionTools {
18370
18430
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18371
18431
  const rawRequest = {
18372
18432
  ...modelSettings,
18433
+ model: modelName,
18373
18434
  prompt: rawPromptContent,
18374
18435
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18375
18436
  };
@@ -18624,8 +18685,8 @@ class OpenAiCompatibleExecutionTools {
18624
18685
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18625
18686
  const rawRequest = {
18626
18687
  ...modelSettings,
18627
- size: modelSettings.size || '1024x1024',
18628
18688
  prompt: rawPromptContent,
18689
+ size: modelSettings.size || '1024x1024',
18629
18690
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18630
18691
  response_format: 'url', // TODO: [🧠] Maybe allow b64_json
18631
18692
  };
@@ -19027,6 +19088,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
19027
19088
  thread: {
19028
19089
  messages: threadMessages,
19029
19090
  },
19091
+ tools: modelRequirements.tools === undefined ? undefined : mapToolsToOpenAi(modelRequirements.tools),
19030
19092
  // <- TODO: Add user identification here> user: this.options.user,
19031
19093
  };
19032
19094
  const start = $getCurrentDate();
@@ -19550,6 +19612,8 @@ class AgentLlmExecutionTools {
19550
19612
  modelRequirements: {
19551
19613
  ...chatPrompt.modelRequirements,
19552
19614
  ...modelRequirements,
19615
+ // Spread tools to convert readonly array to mutable
19616
+ tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
19553
19617
  // Prepend agent system message to existing system message
19554
19618
  systemMessage: modelRequirements.systemMessage +
19555
19619
  (chatPrompt.modelRequirements.systemMessage