@promptbook/wizard 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 +141 -28
  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 +2 -2
  39. package/umd/index.umd.js +141 -28
  40. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -36,7 +36,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
36
36
  * @generated
37
37
  * @see https://github.com/webgptorg/promptbook
38
38
  */
39
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-10';
39
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-12';
40
40
  /**
41
41
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
42
42
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5656,6 +5656,22 @@ resultContent, rawResponse) {
5656
5656
  * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenAiUsage` and `computeAnthropicClaudeUsage`
5657
5657
  */
5658
5658
 
5659
+ /**
5660
+ * Maps Promptbook tools to OpenAI tools.
5661
+ *
5662
+ * @private
5663
+ */
5664
+ function mapToolsToOpenAi(tools) {
5665
+ return tools.map((tool) => ({
5666
+ type: 'function',
5667
+ function: {
5668
+ name: tool.name,
5669
+ description: tool.description,
5670
+ parameters: tool.parameters,
5671
+ },
5672
+ }));
5673
+ }
5674
+
5659
5675
  /**
5660
5676
  * Parses an OpenAI error message to identify which parameter is unsupported
5661
5677
  *
@@ -5853,6 +5869,9 @@ class OpenAiCompatibleExecutionTools {
5853
5869
  },
5854
5870
  ],
5855
5871
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
5872
+ tools: currentModelRequirements.tools === undefined
5873
+ ? undefined
5874
+ : mapToolsToOpenAi(currentModelRequirements.tools),
5856
5875
  };
5857
5876
  const start = $getCurrentDate();
5858
5877
  if (this.options.isVerbose) {
@@ -5997,6 +6016,7 @@ class OpenAiCompatibleExecutionTools {
5997
6016
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
5998
6017
  const rawRequest = {
5999
6018
  ...modelSettings,
6019
+ model: modelName,
6000
6020
  prompt: rawPromptContent,
6001
6021
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
6002
6022
  };
@@ -6251,8 +6271,8 @@ class OpenAiCompatibleExecutionTools {
6251
6271
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
6252
6272
  const rawRequest = {
6253
6273
  ...modelSettings,
6254
- size: modelSettings.size || '1024x1024',
6255
6274
  prompt: rawPromptContent,
6275
+ size: modelSettings.size || '1024x1024',
6256
6276
  user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
6257
6277
  response_format: 'url', // TODO: [🧠] Maybe allow b64_json
6258
6278
  };
@@ -7150,6 +7170,7 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
7150
7170
  thread: {
7151
7171
  messages: threadMessages,
7152
7172
  },
7173
+ tools: modelRequirements.tools === undefined ? undefined : mapToolsToOpenAi(modelRequirements.tools),
7153
7174
  // <- TODO: Add user identification here> user: this.options.user,
7154
7175
  };
7155
7176
  const start = $getCurrentDate();
@@ -9438,7 +9459,7 @@ function countUsage(llmTools) {
9438
9459
  * TODO: [🧠] Is there some meaningfull way how to test this util
9439
9460
  * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
9440
9461
  * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
9441
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9462
+ * TODO: [👷‍♂️] Write a comprehensive manual explaining the construction and usage of LLM tools in the Promptbook ecosystem
9442
9463
  */
9443
9464
 
9444
9465
  /**
@@ -9678,7 +9699,7 @@ function joinLlmExecutionTools(title, ...llmExecutionTools) {
9678
9699
  }
9679
9700
  /**
9680
9701
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
9681
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9702
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
9682
9703
  */
9683
9704
 
9684
9705
  /**
@@ -9695,7 +9716,7 @@ function getSingleLlmExecutionTools(oneOrMoreLlmExecutionTools) {
9695
9716
  }
9696
9717
  /**
9697
9718
  * TODO: [🙆] `getSingleLlmExecutionTools` vs `joinLlmExecutionTools` - explain difference or pick one
9698
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9719
+ * TODO: [👷‍♂️] Write a comprehensive manual about how to construct and use LLM execution tools in Promptbook
9699
9720
  */
9700
9721
 
9701
9722
  /**
@@ -16767,19 +16788,37 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
16767
16788
  `);
16768
16789
  }
16769
16790
  applyToAgentModelRequirements(requirements, content) {
16770
- // We simply mark that browser capability is enabled in metadata
16771
- // Get existing metadata
16772
- const existingMetadata = requirements.metadata || {};
16773
16791
  // Get existing tools array or create new one
16774
- const existingTools = existingMetadata.tools || [];
16775
- // Add 'browser' to tools if not already present
16776
- const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
16777
- // Return requirements with updated metadata
16792
+ const existingTools = requirements.tools || [];
16793
+ // Add 'web_browser' to tools if not already present
16794
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
16795
+ ? existingTools
16796
+ : [
16797
+ ...existingTools,
16798
+ {
16799
+ name: 'web_browser',
16800
+ description: spaceTrim$1(`
16801
+ A tool that can browse the web.
16802
+ Use this tool when you need to access specific websites or browse the internet.
16803
+ `),
16804
+ parameters: {
16805
+ type: 'object',
16806
+ properties: {
16807
+ url: {
16808
+ type: 'string',
16809
+ description: 'The URL to browse',
16810
+ },
16811
+ },
16812
+ required: ['url'],
16813
+ },
16814
+ },
16815
+ ];
16816
+ // Return requirements with updated tools and metadata
16778
16817
  return {
16779
16818
  ...requirements,
16819
+ tools: updatedTools,
16780
16820
  metadata: {
16781
- ...existingMetadata,
16782
- tools: updatedTools,
16821
+ ...requirements.metadata,
16783
16822
  useBrowser: true,
16784
16823
  },
16785
16824
  };
@@ -16872,13 +16911,13 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
16872
16911
  * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
16873
16912
  * to access and retrieve up-to-date information from the internet when necessary.
16874
16913
  *
16875
- * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
16914
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
16876
16915
  *
16877
16916
  * Example usage in agent source:
16878
16917
  *
16879
16918
  * ```book
16880
16919
  * USE SEARCH ENGINE
16881
- * USE SEARCH ENGINE This will be ignored
16920
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
16882
16921
  * ```
16883
16922
  *
16884
16923
  * @private [🪔] Maybe export the commitments through some package
@@ -16910,7 +16949,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16910
16949
 
16911
16950
  ## Key aspects
16912
16951
 
16913
- - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
16952
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
16914
16953
  - The actual search engine tool usage is handled by the agent runtime
16915
16954
  - Allows the agent to search for current information from the web
16916
16955
  - Useful for research tasks, finding facts, and accessing dynamic content
@@ -16935,20 +16974,39 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16935
16974
  `);
16936
16975
  }
16937
16976
  applyToAgentModelRequirements(requirements, content) {
16938
- // We simply mark that search engine capability is enabled in metadata
16939
- // Get existing metadata
16940
- const existingMetadata = requirements.metadata || {};
16941
16977
  // Get existing tools array or create new one
16942
- const existingTools = existingMetadata.tools || [];
16943
- // Add 'search-engine' to tools if not already present
16944
- const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
16945
- // Return requirements with updated metadata
16978
+ const existingTools = requirements.tools || [];
16979
+ // Add 'web_search' to tools if not already present
16980
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
16981
+ ? existingTools
16982
+ : [
16983
+ ...existingTools,
16984
+ {
16985
+ name: 'web_search',
16986
+ description: spaceTrim$1(`
16987
+ Search the internet for information.
16988
+ Use this tool when you need to find up-to-date information or facts that you don't know.
16989
+ ${!content ? '' : `Search scope / instructions: ${content}`}
16990
+ `),
16991
+ parameters: {
16992
+ type: 'object',
16993
+ properties: {
16994
+ query: {
16995
+ type: 'string',
16996
+ description: 'The search query',
16997
+ },
16998
+ },
16999
+ required: ['query'],
17000
+ },
17001
+ },
17002
+ ];
17003
+ // Return requirements with updated tools and metadata
16946
17004
  return {
16947
17005
  ...requirements,
17006
+ tools: updatedTools,
16948
17007
  metadata: {
16949
- ...existingMetadata,
16950
- tools: updatedTools,
16951
- useSearchEngine: true,
17008
+ ...requirements.metadata,
17009
+ useSearchEngine: content || true,
16952
17010
  },
16953
17011
  };
16954
17012
  }
@@ -17933,7 +17991,57 @@ function parseAgentSource(agentSource) {
17933
17991
  }
17934
17992
  const meta = {};
17935
17993
  const links = [];
17994
+ const capabilities = [];
17936
17995
  for (const commitment of parseResult.commitments) {
17996
+ if (commitment.type === 'USE BROWSER') {
17997
+ capabilities.push({
17998
+ type: 'browser',
17999
+ label: 'Browser',
18000
+ iconName: 'Globe',
18001
+ });
18002
+ continue;
18003
+ }
18004
+ if (commitment.type === 'USE SEARCH ENGINE') {
18005
+ capabilities.push({
18006
+ type: 'search-engine',
18007
+ label: 'Search Internet',
18008
+ iconName: 'Search',
18009
+ });
18010
+ continue;
18011
+ }
18012
+ if (commitment.type === 'KNOWLEDGE') {
18013
+ const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
18014
+ let label = content;
18015
+ let iconName = 'Book';
18016
+ if (content.startsWith('http://') || content.startsWith('https://')) {
18017
+ try {
18018
+ const url = new URL(content);
18019
+ if (url.pathname.endsWith('.pdf')) {
18020
+ label = url.pathname.split('/').pop() || 'Document.pdf';
18021
+ iconName = 'FileText';
18022
+ }
18023
+ else {
18024
+ label = url.hostname.replace(/^www\./, '');
18025
+ }
18026
+ }
18027
+ catch (e) {
18028
+ // Invalid URL, treat as text
18029
+ }
18030
+ }
18031
+ else {
18032
+ // Text content - take first few words
18033
+ const words = content.split(/\s+/);
18034
+ if (words.length > 4) {
18035
+ label = words.slice(0, 4).join(' ') + '...';
18036
+ }
18037
+ }
18038
+ capabilities.push({
18039
+ type: 'knowledge',
18040
+ label,
18041
+ iconName,
18042
+ });
18043
+ continue;
18044
+ }
17937
18045
  if (commitment.type === 'META LINK') {
17938
18046
  const linkValue = spaceTrim$2(commitment.content);
17939
18047
  links.push(linkValue);
@@ -17944,6 +18052,10 @@ function parseAgentSource(agentSource) {
17944
18052
  meta.image = spaceTrim$2(commitment.content);
17945
18053
  continue;
17946
18054
  }
18055
+ if (commitment.type === 'META DESCRIPTION') {
18056
+ meta.description = spaceTrim$2(commitment.content);
18057
+ continue;
18058
+ }
17947
18059
  if (commitment.type === 'META COLOR') {
17948
18060
  meta.color = normalizeSeparator(commitment.content);
17949
18061
  continue;
@@ -17980,6 +18092,7 @@ function parseAgentSource(agentSource) {
17980
18092
  meta,
17981
18093
  links,
17982
18094
  parameters,
18095
+ capabilities,
17983
18096
  };
17984
18097
  }
17985
18098
  /**
@@ -19418,7 +19531,7 @@ async function $provideLlmToolsForWizardOrCli(options) {
19418
19531
  }
19419
19532
  /**
19420
19533
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
19421
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
19534
+ * TODO: [👷‍♂️] Write a comprehensive manual about the construction of LLM tools
19422
19535
  * TODO: [🥃] Allow `ptbk make` without llm tools
19423
19536
  * TODO: This should be maybe not under `_common` but under `utils-internal` / `utils/internal`
19424
19537
  * TODO: [®] DRY Register logic