@promptbook/core 0.104.0-11 → 0.104.0-13

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 (30) hide show
  1. package/esm/index.es.js +98 -31
  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/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
  8. package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
  9. package/esm/typings/src/commitments/META/META_DESCRIPTION.d.ts +41 -0
  10. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
  11. package/esm/typings/src/commitments/_base/BookCommitment.d.ts +1 -1
  12. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  14. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
  18. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +1 -1
  19. package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
  20. package/esm/typings/src/search-engines/SearchResult.d.ts +4 -4
  21. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +1 -1
  22. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +1 -1
  23. package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
  24. package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
  25. package/esm/typings/src/utils/random/$randomItem.d.ts +1 -1
  26. package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
  27. package/esm/typings/src/version.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/umd/index.umd.js +98 -31
  30. 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-13';
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
  /**
@@ -8074,9 +8074,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
8074
8074
  // Get existing dictionary entries from metadata
8075
8075
  const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
8076
8076
  // Merge the new dictionary entry with existing entries
8077
- const mergedDictionary = existingDictionary
8078
- ? `${existingDictionary}\n${trimmedContent}`
8079
- : trimmedContent;
8077
+ const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
8080
8078
  // Store the merged dictionary in metadata for debugging and inspection
8081
8079
  const updatedMetadata = {
8082
8080
  ...requirements.metadata,
@@ -10605,19 +10603,37 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
10605
10603
  `);
10606
10604
  }
10607
10605
  applyToAgentModelRequirements(requirements, content) {
10608
- // We simply mark that browser capability is enabled in metadata
10609
- // Get existing metadata
10610
- const existingMetadata = requirements.metadata || {};
10611
10606
  // 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
10607
+ const existingTools = requirements.tools || [];
10608
+ // Add 'web_browser' to tools if not already present
10609
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
10610
+ ? existingTools
10611
+ : [
10612
+ ...existingTools,
10613
+ {
10614
+ name: 'web_browser',
10615
+ description: spaceTrim$1(`
10616
+ A tool that can browse the web.
10617
+ Use this tool when you need to access specific websites or browse the internet.
10618
+ `),
10619
+ parameters: {
10620
+ type: 'object',
10621
+ properties: {
10622
+ url: {
10623
+ type: 'string',
10624
+ description: 'The URL to browse',
10625
+ },
10626
+ },
10627
+ required: ['url'],
10628
+ },
10629
+ },
10630
+ ];
10631
+ // Return requirements with updated tools and metadata
10616
10632
  return {
10617
10633
  ...requirements,
10634
+ tools: updatedTools,
10618
10635
  metadata: {
10619
- ...existingMetadata,
10620
- tools: updatedTools,
10636
+ ...requirements.metadata,
10621
10637
  useBrowser: true,
10622
10638
  },
10623
10639
  };
@@ -10710,13 +10726,13 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
10710
10726
  * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
10711
10727
  * to access and retrieve up-to-date information from the internet when necessary.
10712
10728
  *
10713
- * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
10729
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
10714
10730
  *
10715
10731
  * Example usage in agent source:
10716
10732
  *
10717
10733
  * ```book
10718
10734
  * USE SEARCH ENGINE
10719
- * USE SEARCH ENGINE This will be ignored
10735
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
10720
10736
  * ```
10721
10737
  *
10722
10738
  * @private [🪔] Maybe export the commitments through some package
@@ -10748,7 +10764,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10748
10764
 
10749
10765
  ## Key aspects
10750
10766
 
10751
- - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
10767
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
10752
10768
  - The actual search engine tool usage is handled by the agent runtime
10753
10769
  - Allows the agent to search for current information from the web
10754
10770
  - Useful for research tasks, finding facts, and accessing dynamic content
@@ -10773,20 +10789,39 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10773
10789
  `);
10774
10790
  }
10775
10791
  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
10792
  // 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
10793
+ const existingTools = requirements.tools || [];
10794
+ // Add 'web_search' to tools if not already present
10795
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
10796
+ ? existingTools
10797
+ : [
10798
+ ...existingTools,
10799
+ {
10800
+ name: 'web_search',
10801
+ description: spaceTrim$1(`
10802
+ Search the internet for information.
10803
+ Use this tool when you need to find up-to-date information or facts that you don't know.
10804
+ ${!content ? '' : `Search scope / instructions: ${content}`}
10805
+ `),
10806
+ parameters: {
10807
+ type: 'object',
10808
+ properties: {
10809
+ query: {
10810
+ type: 'string',
10811
+ description: 'The search query',
10812
+ },
10813
+ },
10814
+ required: ['query'],
10815
+ },
10816
+ },
10817
+ ];
10818
+ // Return requirements with updated tools and metadata
10784
10819
  return {
10785
10820
  ...requirements,
10821
+ tools: updatedTools,
10786
10822
  metadata: {
10787
- ...existingMetadata,
10788
- tools: updatedTools,
10789
- useSearchEngine: true,
10823
+ ...requirements.metadata,
10824
+ useSearchEngine: content || true,
10790
10825
  },
10791
10826
  };
10792
10827
  }
@@ -11956,6 +11991,10 @@ function parseAgentSource(agentSource) {
11956
11991
  meta.image = spaceTrim$2(commitment.content);
11957
11992
  continue;
11958
11993
  }
11994
+ if (commitment.type === 'META DESCRIPTION') {
11995
+ meta.description = spaceTrim$2(commitment.content);
11996
+ continue;
11997
+ }
11959
11998
  if (commitment.type === 'META COLOR') {
11960
11999
  meta.color = normalizeSeparator(commitment.content);
11961
12000
  continue;
@@ -14134,7 +14173,12 @@ const jokerCommandParser = {
14134
14173
  * @see {@link ModelVariant}
14135
14174
  * @public exported from `@promptbook/core`
14136
14175
  */
14137
- const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'IMAGE_GENERATION', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
14176
+ const MODEL_VARIANTS = [
14177
+ 'COMPLETION',
14178
+ 'CHAT',
14179
+ 'IMAGE_GENERATION',
14180
+ 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */,
14181
+ ];
14138
14182
 
14139
14183
  /**
14140
14184
  * Parses the model command
@@ -17141,7 +17185,7 @@ function limitTotalUsage(llmTools, options = {}) {
17141
17185
  * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
17142
17186
  * TODO: [🧠] Is there some meaningfull way how to test this util
17143
17187
  * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
17144
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
17188
+ * TODO: [👷‍♂️] Write a comprehensive manual about the construction of LLM tools
17145
17189
  */
17146
17190
 
17147
17191
  /**
@@ -18029,6 +18073,22 @@ resultContent, rawResponse) {
18029
18073
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
18030
18074
  */
18031
18075
 
18076
+ /**
18077
+ * Maps Promptbook tools to OpenAI tools.
18078
+ *
18079
+ * @private
18080
+ */
18081
+ function mapToolsToOpenAi(tools) {
18082
+ return tools.map((tool) => ({
18083
+ type: 'function',
18084
+ function: {
18085
+ name: tool.name,
18086
+ description: tool.description,
18087
+ parameters: tool.parameters,
18088
+ },
18089
+ }));
18090
+ }
18091
+
18032
18092
  /**
18033
18093
  * Parses an OpenAI error message to identify which parameter is unsupported
18034
18094
  *
@@ -18226,6 +18286,9 @@ class OpenAiCompatibleExecutionTools {
18226
18286
  },
18227
18287
  ],
18228
18288
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18289
+ tools: currentModelRequirements.tools === undefined
18290
+ ? undefined
18291
+ : mapToolsToOpenAi(currentModelRequirements.tools),
18229
18292
  };
18230
18293
  const start = $getCurrentDate();
18231
18294
  if (this.options.isVerbose) {
@@ -18370,6 +18433,7 @@ class OpenAiCompatibleExecutionTools {
18370
18433
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18371
18434
  const rawRequest = {
18372
18435
  ...modelSettings,
18436
+ model: modelName,
18373
18437
  prompt: rawPromptContent,
18374
18438
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18375
18439
  };
@@ -18624,8 +18688,8 @@ class OpenAiCompatibleExecutionTools {
18624
18688
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
18625
18689
  const rawRequest = {
18626
18690
  ...modelSettings,
18627
- size: modelSettings.size || '1024x1024',
18628
18691
  prompt: rawPromptContent,
18692
+ size: modelSettings.size || '1024x1024',
18629
18693
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
18630
18694
  response_format: 'url', // TODO: [🧠] Maybe allow b64_json
18631
18695
  };
@@ -19027,6 +19091,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
19027
19091
  thread: {
19028
19092
  messages: threadMessages,
19029
19093
  },
19094
+ tools: modelRequirements.tools === undefined ? undefined : mapToolsToOpenAi(modelRequirements.tools),
19030
19095
  // <- TODO: Add user identification here> user: this.options.user,
19031
19096
  };
19032
19097
  const start = $getCurrentDate();
@@ -19550,6 +19615,8 @@ class AgentLlmExecutionTools {
19550
19615
  modelRequirements: {
19551
19616
  ...chatPrompt.modelRequirements,
19552
19617
  ...modelRequirements,
19618
+ // Spread tools to convert readonly array to mutable
19619
+ tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
19553
19620
  // Prepend agent system message to existing system message
19554
19621
  systemMessage: modelRequirements.systemMessage +
19555
19622
  (chatPrompt.modelRequirements.systemMessage