@promptbook/cli 0.105.0-7 → 0.105.0-9

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/esm/index.es.js CHANGED
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-9';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5150,6 +5150,16 @@ function cacheLlmTools(llmTools, options = {}) {
5150
5150
  }
5151
5151
  }
5152
5152
  }
5153
+ if (shouldCache && promptResult.toolCalls !== undefined) {
5154
+ // Note: Do not cache results that contain tool calls because they are dynamic and should be always fresh
5155
+ // For example, it doesn't make sense to cache the message 'What time is it? 3:30 pm' because when the question is asked another time, it can be a different time.
5156
+ shouldCache = false;
5157
+ if (isVerbose) {
5158
+ console.info('Not caching result that contains tool calls for key:', key, {
5159
+ toolCalls: promptResult.toolCalls,
5160
+ });
5161
+ }
5162
+ }
5153
5163
  if (shouldCache) {
5154
5164
  await storage.setItem(key, {
5155
5165
  date: $getCurrentDate(),
@@ -16608,6 +16618,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
16608
16618
  * Note: [💞] Ignore a discrepancy between file name and entity name
16609
16619
  */
16610
16620
 
16621
+ /**
16622
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
16623
+ *
16624
+ * @private <- TODO: !!!! Export via some package
16625
+ */
16626
+ class SerpSearchEngine {
16627
+ get title() {
16628
+ return 'SerpApi Search Engine';
16629
+ }
16630
+ get description() {
16631
+ return 'Search engine that uses SerpApi to fetch Google search results';
16632
+ }
16633
+ checkConfiguration() {
16634
+ if (!process.env.SERP_API_KEY) {
16635
+ throw new Error('SERP_API_KEY is not configured');
16636
+ }
16637
+ }
16638
+ async search(query) {
16639
+ const apiKey = process.env.SERP_API_KEY;
16640
+ if (!apiKey) {
16641
+ throw new Error('SERP_API_KEY is not configured');
16642
+ }
16643
+ const url = new URL('https://serpapi.com/search');
16644
+ url.searchParams.set('q', query);
16645
+ url.searchParams.set('api_key', apiKey);
16646
+ url.searchParams.set('engine', 'google');
16647
+ const response = await fetch(url.toString());
16648
+ if (!response.ok) {
16649
+ const body = await response.text();
16650
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
16651
+ }
16652
+ const data = (await response.json());
16653
+ return (data.organic_results || []).map((item) => ({
16654
+ title: item.title,
16655
+ url: item.link,
16656
+ snippet: item.snippet || '',
16657
+ }));
16658
+ }
16659
+ }
16660
+
16611
16661
  /**
16612
16662
  * USE SEARCH ENGINE commitment definition
16613
16663
  *
@@ -16684,18 +16734,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16684
16734
  ? existingTools
16685
16735
  : [
16686
16736
  ...existingTools,
16687
- { type: 'web_search' },
16688
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
16689
- // In future we will use proper MCP search tool:
16690
- /*
16691
-
16692
16737
  {
16693
16738
  name: 'web_search',
16694
- description: spaceTrim(`
16695
- Search the internet for information.
16696
- Use this tool when you need to find up-to-date information or facts that you don't know.
16697
- ${!content ? '' : `Search scope / instructions: ${content}`}
16698
- `),
16739
+ description: spaceTrim$1(`
16740
+ Search the internet for information.
16741
+ Use this tool when you need to find up-to-date information or facts that you don't know.
16742
+ ${!content ? '' : `Search scope / instructions: ${content}`}
16743
+ `),
16699
16744
  parameters: {
16700
16745
  type: 'object',
16701
16746
  properties: {
@@ -16707,7 +16752,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16707
16752
  required: ['query'],
16708
16753
  },
16709
16754
  },
16710
- */
16711
16755
  ];
16712
16756
  // Return requirements with updated tools and metadata
16713
16757
  return {
@@ -16719,6 +16763,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
16719
16763
  },
16720
16764
  };
16721
16765
  }
16766
+ /**
16767
+ * Gets the `web_search` tool function implementation.
16768
+ */
16769
+ getToolFunctions() {
16770
+ return {
16771
+ async web_search(args) {
16772
+ console.log('!!!! [Tool] web_search called', { args });
16773
+ const { query } = args;
16774
+ if (!query) {
16775
+ throw new Error('Search query is required');
16776
+ }
16777
+ const searchEngine = new SerpSearchEngine();
16778
+ const results = await searchEngine.search(query);
16779
+ return spaceTrim$1((block) => `
16780
+ Search results for "${query}":
16781
+
16782
+ ${block(results
16783
+ .map((result) => spaceTrim$1(`
16784
+ - **${result.title}**
16785
+ ${result.url}
16786
+ ${result.snippet}
16787
+ `))
16788
+ .join('\n\n'))}
16789
+ `);
16790
+ },
16791
+ };
16792
+ }
16722
16793
  }
16723
16794
  /**
16724
16795
  * Note: [💞] Ignore a discrepancy between file name and entity name