@promptbook/browser 0.104.0-9 → 0.104.0

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 (60) hide show
  1. package/README.md +0 -4
  2. package/esm/index.es.js +192 -47
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +0 -6
  5. package/esm/typings/src/_packages/core.index.d.ts +8 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +8 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  8. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +24 -0
  9. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +12 -2
  10. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirements.tools.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/utils/generatePlaceholderAgentProfileImageUrl.d.ts +1 -1
  12. package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
  13. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +6 -3
  14. package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +5 -1
  15. package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +5 -1
  16. package/esm/typings/src/book-components/icons/AboutIcon.d.ts +5 -1
  17. package/esm/typings/src/book-components/icons/AttachmentIcon.d.ts +6 -2
  18. package/esm/typings/src/book-components/icons/CameraIcon.d.ts +6 -2
  19. package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +5 -1
  20. package/esm/typings/src/book-components/icons/MenuIcon.d.ts +5 -1
  21. package/esm/typings/src/book-components/icons/SaveIcon.d.ts +6 -2
  22. package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +1 -1
  23. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +9 -7
  24. package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
  25. package/esm/typings/src/commitments/META/META_DESCRIPTION.d.ts +41 -0
  26. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +2 -2
  27. package/esm/typings/src/commitments/_base/BookCommitment.d.ts +1 -1
  28. package/esm/typings/src/config.d.ts +8 -1
  29. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +1 -1
  30. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizardOrCli.d.ts +1 -1
  32. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +8 -4
  34. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +1 -1
  35. package/esm/typings/src/llm-providers/_multiple/getSingleLlmExecutionTools.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +12 -8
  37. package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -1
  38. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
  39. package/esm/typings/src/llm-providers/openai/utils/mapToolsToOpenAi.d.ts +8 -0
  40. package/esm/typings/src/remote-server/ui/ServerApp.d.ts +5 -1
  41. package/esm/typings/src/scrapers/_common/utils/promptbookFetch.test.d.ts +1 -0
  42. package/esm/typings/src/search-engines/SearchEngine.d.ts +9 -0
  43. package/esm/typings/src/search-engines/SearchResult.d.ts +18 -0
  44. package/esm/typings/src/search-engines/bing/BingSearchEngine.d.ts +15 -0
  45. package/esm/typings/src/search-engines/dummy/DummySearchEngine.d.ts +15 -0
  46. package/esm/typings/src/types/LlmToolDefinition.d.ts +20 -0
  47. package/esm/typings/src/types/ModelRequirements.d.ts +13 -0
  48. package/esm/typings/src/types/typeAliasEmoji.d.ts +2 -2
  49. package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +7 -2
  50. package/esm/typings/src/utils/random/$randomItem.d.ts +1 -1
  51. package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
  52. package/esm/typings/src/utils/validators/url/isValidAgentUrl.d.ts +16 -0
  53. package/esm/typings/src/utils/validators/url/isValidAgentUrl.test.d.ts +1 -0
  54. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
  55. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +4 -3
  56. package/esm/typings/src/version.d.ts +1 -1
  57. package/package.json +2 -2
  58. package/umd/index.umd.js +192 -47
  59. package/umd/index.umd.js.map +1 -1
  60. package/esm/typings/servers.d.ts +0 -50
package/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-9';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2212,9 +2212,10 @@
2212
2212
  *
2213
2213
  * Note: [🔂] This function is idempotent.
2214
2214
  * Note: Dataurl are considered perfectly valid.
2215
- * Note: There are two similar functions:
2216
- * - `isValidUrl` which tests any URL
2217
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
2215
+ * Note: There are few similar functions:
2216
+ * - `isValidUrl` *(this one)* which tests any URL
2217
+ * - `isValidAgentUrl` which tests just agent URL
2218
+ * - `isValidPipelineUrl` which tests just pipeline URL
2218
2219
  *
2219
2220
  * @public exported from `@promptbook/utils`
2220
2221
  */
@@ -2492,8 +2493,8 @@
2492
2493
  */
2493
2494
  function removeDiacritics(input) {
2494
2495
  /*eslint no-control-regex: "off"*/
2495
- return input.replace(/[^\u0000-\u007E]/g, (a) => {
2496
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
2496
+ return input.replace(/[^\u0000-\u007E]/g, (character) => {
2497
+ return DIACRITIC_VARIANTS_LETTERS[character] || character;
2497
2498
  });
2498
2499
  }
2499
2500
  /**
@@ -2624,6 +2625,39 @@
2624
2625
  * Note: [💞] Ignore a discrepancy between file name and entity name
2625
2626
  */
2626
2627
 
2628
+ /**
2629
+ * Tests if given string is valid agent URL
2630
+ *
2631
+ * Note: There are few similar functions:
2632
+ * - `isValidUrl` which tests any URL
2633
+ * - `isValidAgentUrl` *(this one)* which tests just agent URL
2634
+ * - `isValidPipelineUrl` which tests just pipeline URL
2635
+ *
2636
+ * @public exported from `@promptbook/utils`
2637
+ */
2638
+ function isValidAgentUrl(url) {
2639
+ if (!isValidUrl(url)) {
2640
+ return false;
2641
+ }
2642
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
2643
+ return false;
2644
+ }
2645
+ if (url.includes('#')) {
2646
+ // TODO: [🐠]
2647
+ return false;
2648
+ }
2649
+ /*
2650
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
2651
+ if (isUrlOnPrivateNetwork(url)) {
2652
+ return false;
2653
+ }
2654
+ */
2655
+ return true;
2656
+ }
2657
+ /**
2658
+ * TODO: [🐠] Maybe more info why the URL is invalid
2659
+ */
2660
+
2627
2661
  /**
2628
2662
  * Normalizes agent name from arbitrary string to valid agent name
2629
2663
  *
@@ -2655,8 +2689,8 @@
2655
2689
  */
2656
2690
  function createCommitmentRegex(commitment, aliases = [], requiresContent = true) {
2657
2691
  const allCommitments = [commitment, ...aliases];
2658
- const patterns = allCommitments.map((c) => {
2659
- const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2692
+ const patterns = allCommitments.map((commitment) => {
2693
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2660
2694
  return escapedCommitment.split(/\s+/).join('\\s+');
2661
2695
  });
2662
2696
  const keywordPattern = patterns.join('|');
@@ -2678,8 +2712,8 @@
2678
2712
  */
2679
2713
  function createCommitmentTypeRegex(commitment, aliases = []) {
2680
2714
  const allCommitments = [commitment, ...aliases];
2681
- const patterns = allCommitments.map((c) => {
2682
- const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2715
+ const patterns = allCommitments.map((commitment) => {
2716
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2683
2717
  return escapedCommitment.split(/\s+/).join('\\s+');
2684
2718
  });
2685
2719
  const keywordPattern = patterns.join('|');
@@ -3189,9 +3223,7 @@
3189
3223
  // Get existing dictionary entries from metadata
3190
3224
  const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3191
3225
  // Merge the new dictionary entry with existing entries
3192
- const mergedDictionary = existingDictionary
3193
- ? `${existingDictionary}\n${trimmedContent}`
3194
- : trimmedContent;
3226
+ const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
3195
3227
  // Store the merged dictionary in metadata for debugging and inspection
3196
3228
  const updatedMetadata = {
3197
3229
  ...requirements.metadata,
@@ -3342,21 +3374,35 @@
3342
3374
  applyToAgentModelRequirements(requirements, content) {
3343
3375
  const trimmedContent = content.trim();
3344
3376
  if (!trimmedContent) {
3345
- return requirements;
3377
+ return {
3378
+ ...requirements,
3379
+ parentAgentUrl: undefined,
3380
+ };
3346
3381
  }
3347
- // Validate URL
3348
- try {
3349
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
3350
- const url = new URL(trimmedContent);
3351
- // TODO: Add more validation if needed (e.g. check for valid protocol)
3382
+ if (trimmedContent.toUpperCase() === 'VOID' ||
3383
+ trimmedContent.toUpperCase() === 'NULL' ||
3384
+ trimmedContent.toUpperCase() === 'NONE' ||
3385
+ trimmedContent.toUpperCase() === 'NIL') {
3386
+ return {
3387
+ ...requirements,
3388
+ parentAgentUrl: null,
3389
+ };
3352
3390
  }
3353
- catch (error) {
3354
- console.warn(`Invalid URL in FROM commitment: ${trimmedContent}`);
3355
- return requirements;
3391
+ if (!isValidAgentUrl(trimmedContent)) {
3392
+ throw new Error(spaceTrim$1.spaceTrim((block) => `
3393
+ Invalid agent URL in FROM commitment: "${trimmedContent}"
3394
+
3395
+ \`\`\`book
3396
+ ${block(content)}
3397
+ \`\`\`
3398
+
3399
+
3400
+ `));
3356
3401
  }
3402
+ const parentAgentUrl = trimmedContent;
3357
3403
  return {
3358
3404
  ...requirements,
3359
- parentAgentUrl: trimmedContent,
3405
+ parentAgentUrl,
3360
3406
  };
3361
3407
  }
3362
3408
  }
@@ -5720,19 +5766,38 @@
5720
5766
  `);
5721
5767
  }
5722
5768
  applyToAgentModelRequirements(requirements, content) {
5723
- // We simply mark that browser capability is enabled in metadata
5724
- // Get existing metadata
5725
- const existingMetadata = requirements.metadata || {};
5726
5769
  // Get existing tools array or create new one
5727
- const existingTools = existingMetadata.tools || [];
5728
- // Add 'browser' to tools if not already present
5729
- const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
5730
- // Return requirements with updated metadata
5770
+ const existingTools = requirements.tools || [];
5771
+ // Add 'web_browser' to tools if not already present
5772
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
5773
+ ? existingTools
5774
+ : [
5775
+ // TODO: [🔰] Use through proper MCP server
5776
+ ...existingTools,
5777
+ {
5778
+ name: 'web_browser',
5779
+ description: spaceTrim$1.spaceTrim(`
5780
+ A tool that can browse the web.
5781
+ Use this tool when you need to access specific websites or browse the internet.
5782
+ `),
5783
+ parameters: {
5784
+ type: 'object',
5785
+ properties: {
5786
+ url: {
5787
+ type: 'string',
5788
+ description: 'The URL to browse',
5789
+ },
5790
+ },
5791
+ required: ['url'],
5792
+ },
5793
+ },
5794
+ ];
5795
+ // Return requirements with updated tools and metadata
5731
5796
  return {
5732
5797
  ...requirements,
5798
+ tools: updatedTools,
5733
5799
  metadata: {
5734
- ...existingMetadata,
5735
- tools: updatedTools,
5800
+ ...requirements.metadata,
5736
5801
  useBrowser: true,
5737
5802
  },
5738
5803
  };
@@ -5825,13 +5890,13 @@
5825
5890
  * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
5826
5891
  * to access and retrieve up-to-date information from the internet when necessary.
5827
5892
  *
5828
- * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
5893
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
5829
5894
  *
5830
5895
  * Example usage in agent source:
5831
5896
  *
5832
5897
  * ```book
5833
5898
  * USE SEARCH ENGINE
5834
- * USE SEARCH ENGINE This will be ignored
5899
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
5835
5900
  * ```
5836
5901
  *
5837
5902
  * @private [🪔] Maybe export the commitments through some package
@@ -5863,7 +5928,7 @@
5863
5928
 
5864
5929
  ## Key aspects
5865
5930
 
5866
- - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
5931
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
5867
5932
  - The actual search engine tool usage is handled by the agent runtime
5868
5933
  - Allows the agent to search for current information from the web
5869
5934
  - Useful for research tasks, finding facts, and accessing dynamic content
@@ -5888,20 +5953,45 @@
5888
5953
  `);
5889
5954
  }
5890
5955
  applyToAgentModelRequirements(requirements, content) {
5891
- // We simply mark that search engine capability is enabled in metadata
5892
- // Get existing metadata
5893
- const existingMetadata = requirements.metadata || {};
5894
5956
  // Get existing tools array or create new one
5895
- const existingTools = existingMetadata.tools || [];
5896
- // Add 'search-engine' to tools if not already present
5897
- const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
5898
- // Return requirements with updated metadata
5957
+ const existingTools = requirements.tools || [];
5958
+ // Add 'web_search' to tools if not already present
5959
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
5960
+ ? existingTools
5961
+ : [
5962
+ ...existingTools,
5963
+ { type: 'web_search' },
5964
+ // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
5965
+ // In future we will use proper MCP search tool:
5966
+ /*
5967
+
5968
+ {
5969
+ name: 'web_search',
5970
+ description: spaceTrim(`
5971
+ Search the internet for information.
5972
+ Use this tool when you need to find up-to-date information or facts that you don't know.
5973
+ ${!content ? '' : `Search scope / instructions: ${content}`}
5974
+ `),
5975
+ parameters: {
5976
+ type: 'object',
5977
+ properties: {
5978
+ query: {
5979
+ type: 'string',
5980
+ description: 'The search query',
5981
+ },
5982
+ },
5983
+ required: ['query'],
5984
+ },
5985
+ },
5986
+ */
5987
+ ];
5988
+ // Return requirements with updated tools and metadata
5899
5989
  return {
5900
5990
  ...requirements,
5991
+ tools: updatedTools,
5901
5992
  metadata: {
5902
- ...existingMetadata,
5903
- tools: updatedTools,
5904
- useSearchEngine: true,
5993
+ ...requirements.metadata,
5994
+ useSearchEngine: content || true,
5905
5995
  },
5906
5996
  };
5907
5997
  }
@@ -6262,8 +6352,8 @@
6262
6352
  return match;
6263
6353
  });
6264
6354
  // Remove duplicates based on name (keep the first occurrence)
6265
- const uniqueParameters = parameters.filter((param, index, array) => {
6266
- return array.findIndex((p) => p.name === param.name) === index;
6355
+ const uniqueParameters = parameters.filter((parameter, index, array) => {
6356
+ return array.findIndex((parameterItem) => parameterItem.name === parameter.name) === index;
6267
6357
  });
6268
6358
  return uniqueParameters;
6269
6359
  }
@@ -6305,7 +6395,57 @@
6305
6395
  }
6306
6396
  const meta = {};
6307
6397
  const links = [];
6398
+ const capabilities = [];
6308
6399
  for (const commitment of parseResult.commitments) {
6400
+ if (commitment.type === 'USE BROWSER') {
6401
+ capabilities.push({
6402
+ type: 'browser',
6403
+ label: 'Browser',
6404
+ iconName: 'Globe',
6405
+ });
6406
+ continue;
6407
+ }
6408
+ if (commitment.type === 'USE SEARCH ENGINE') {
6409
+ capabilities.push({
6410
+ type: 'search-engine',
6411
+ label: 'Search Internet',
6412
+ iconName: 'Search',
6413
+ });
6414
+ continue;
6415
+ }
6416
+ if (commitment.type === 'KNOWLEDGE') {
6417
+ const content = spaceTrim__default["default"](commitment.content).split('\n')[0] || '';
6418
+ let label = content;
6419
+ let iconName = 'Book';
6420
+ if (content.startsWith('http://') || content.startsWith('https://')) {
6421
+ try {
6422
+ const url = new URL(content);
6423
+ if (url.pathname.endsWith('.pdf')) {
6424
+ label = url.pathname.split('/').pop() || 'Document.pdf';
6425
+ iconName = 'FileText';
6426
+ }
6427
+ else {
6428
+ label = url.hostname.replace(/^www\./, '');
6429
+ }
6430
+ }
6431
+ catch (e) {
6432
+ // Invalid URL, treat as text
6433
+ }
6434
+ }
6435
+ else {
6436
+ // Text content - take first few words
6437
+ const words = content.split(/\s+/);
6438
+ if (words.length > 4) {
6439
+ label = words.slice(0, 4).join(' ') + '...';
6440
+ }
6441
+ }
6442
+ capabilities.push({
6443
+ type: 'knowledge',
6444
+ label,
6445
+ iconName,
6446
+ });
6447
+ continue;
6448
+ }
6309
6449
  if (commitment.type === 'META LINK') {
6310
6450
  const linkValue = spaceTrim__default["default"](commitment.content);
6311
6451
  links.push(linkValue);
@@ -6316,6 +6456,10 @@
6316
6456
  meta.image = spaceTrim__default["default"](commitment.content);
6317
6457
  continue;
6318
6458
  }
6459
+ if (commitment.type === 'META DESCRIPTION') {
6460
+ meta.description = spaceTrim__default["default"](commitment.content);
6461
+ continue;
6462
+ }
6319
6463
  if (commitment.type === 'META COLOR') {
6320
6464
  meta.color = normalizeSeparator(commitment.content);
6321
6465
  continue;
@@ -6352,6 +6496,7 @@
6352
6496
  meta,
6353
6497
  links,
6354
6498
  parameters,
6499
+ capabilities,
6355
6500
  };
6356
6501
  }
6357
6502
  /**