@promptbook/javascript 0.105.0-7 → 0.105.0-8

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.
package/umd/index.umd.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5638,6 +5638,46 @@
5638
5638
  * Note: [💞] Ignore a discrepancy between file name and entity name
5639
5639
  */
5640
5640
 
5641
+ /**
5642
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
5643
+ *
5644
+ * @private <- TODO: !!!! Export via some package
5645
+ */
5646
+ class SerpSearchEngine {
5647
+ get title() {
5648
+ return 'SerpApi Search Engine';
5649
+ }
5650
+ get description() {
5651
+ return 'Search engine that uses SerpApi to fetch Google search results';
5652
+ }
5653
+ checkConfiguration() {
5654
+ if (!process.env.SERP_API_KEY) {
5655
+ throw new Error('SERP_API_KEY is not configured');
5656
+ }
5657
+ }
5658
+ async search(query) {
5659
+ const apiKey = process.env.SERP_API_KEY;
5660
+ if (!apiKey) {
5661
+ throw new Error('SERP_API_KEY is not configured');
5662
+ }
5663
+ const url = new URL('https://serpapi.com/search');
5664
+ url.searchParams.set('q', query);
5665
+ url.searchParams.set('api_key', apiKey);
5666
+ url.searchParams.set('engine', 'google');
5667
+ const response = await fetch(url.toString());
5668
+ if (!response.ok) {
5669
+ const body = await response.text();
5670
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
5671
+ }
5672
+ const data = (await response.json());
5673
+ return (data.organic_results || []).map((item) => ({
5674
+ title: item.title,
5675
+ url: item.link,
5676
+ snippet: item.snippet || '',
5677
+ }));
5678
+ }
5679
+ }
5680
+
5641
5681
  /**
5642
5682
  * USE SEARCH ENGINE commitment definition
5643
5683
  *
@@ -5714,18 +5754,13 @@
5714
5754
  ? existingTools
5715
5755
  : [
5716
5756
  ...existingTools,
5717
- { type: 'web_search' },
5718
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
5719
- // In future we will use proper MCP search tool:
5720
- /*
5721
-
5722
5757
  {
5723
5758
  name: 'web_search',
5724
- description: spaceTrim(`
5725
- Search the internet for information.
5726
- Use this tool when you need to find up-to-date information or facts that you don't know.
5727
- ${!content ? '' : `Search scope / instructions: ${content}`}
5728
- `),
5759
+ description: spaceTrim$1.spaceTrim(`
5760
+ Search the internet for information.
5761
+ Use this tool when you need to find up-to-date information or facts that you don't know.
5762
+ ${!content ? '' : `Search scope / instructions: ${content}`}
5763
+ `),
5729
5764
  parameters: {
5730
5765
  type: 'object',
5731
5766
  properties: {
@@ -5737,7 +5772,6 @@
5737
5772
  required: ['query'],
5738
5773
  },
5739
5774
  },
5740
- */
5741
5775
  ];
5742
5776
  // Return requirements with updated tools and metadata
5743
5777
  return {
@@ -5749,6 +5783,33 @@
5749
5783
  },
5750
5784
  };
5751
5785
  }
5786
+ /**
5787
+ * Gets the `web_search` tool function implementation.
5788
+ */
5789
+ getToolFunctions() {
5790
+ return {
5791
+ async web_search(args) {
5792
+ console.log('!!!! [Tool] web_search called', { args });
5793
+ const { query } = args;
5794
+ if (!query) {
5795
+ throw new Error('Search query is required');
5796
+ }
5797
+ const searchEngine = new SerpSearchEngine();
5798
+ const results = await searchEngine.search(query);
5799
+ return spaceTrim$1.spaceTrim((block) => `
5800
+ Search results for "${query}":
5801
+
5802
+ ${block(results
5803
+ .map((result) => spaceTrim$1.spaceTrim(`
5804
+ - **${result.title}**
5805
+ ${result.url}
5806
+ ${result.snippet}
5807
+ `))
5808
+ .join('\n\n'))}
5809
+ `);
5810
+ },
5811
+ };
5812
+ }
5752
5813
  }
5753
5814
  /**
5754
5815
  * Note: [💞] Ignore a discrepancy between file name and entity name