@promptbook/components 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
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
35
35
  * @generated
36
36
  * @see https://github.com/webgptorg/promptbook
37
37
  */
38
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
38
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-9';
39
39
  /**
40
40
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
41
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7686,6 +7686,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
7686
7686
  * Note: [💞] Ignore a discrepancy between file name and entity name
7687
7687
  */
7688
7688
 
7689
+ /**
7690
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
7691
+ *
7692
+ * @private <- TODO: !!!! Export via some package
7693
+ */
7694
+ class SerpSearchEngine {
7695
+ get title() {
7696
+ return 'SerpApi Search Engine';
7697
+ }
7698
+ get description() {
7699
+ return 'Search engine that uses SerpApi to fetch Google search results';
7700
+ }
7701
+ checkConfiguration() {
7702
+ if (!process.env.SERP_API_KEY) {
7703
+ throw new Error('SERP_API_KEY is not configured');
7704
+ }
7705
+ }
7706
+ async search(query) {
7707
+ const apiKey = process.env.SERP_API_KEY;
7708
+ if (!apiKey) {
7709
+ throw new Error('SERP_API_KEY is not configured');
7710
+ }
7711
+ const url = new URL('https://serpapi.com/search');
7712
+ url.searchParams.set('q', query);
7713
+ url.searchParams.set('api_key', apiKey);
7714
+ url.searchParams.set('engine', 'google');
7715
+ const response = await fetch(url.toString());
7716
+ if (!response.ok) {
7717
+ const body = await response.text();
7718
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
7719
+ }
7720
+ const data = (await response.json());
7721
+ return (data.organic_results || []).map((item) => ({
7722
+ title: item.title,
7723
+ url: item.link,
7724
+ snippet: item.snippet || '',
7725
+ }));
7726
+ }
7727
+ }
7728
+
7689
7729
  /**
7690
7730
  * USE SEARCH ENGINE commitment definition
7691
7731
  *
@@ -7762,18 +7802,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
7762
7802
  ? existingTools
7763
7803
  : [
7764
7804
  ...existingTools,
7765
- { type: 'web_search' },
7766
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
7767
- // In future we will use proper MCP search tool:
7768
- /*
7769
-
7770
7805
  {
7771
7806
  name: 'web_search',
7772
- description: spaceTrim(`
7773
- Search the internet for information.
7774
- Use this tool when you need to find up-to-date information or facts that you don't know.
7775
- ${!content ? '' : `Search scope / instructions: ${content}`}
7776
- `),
7807
+ description: spaceTrim$1(`
7808
+ Search the internet for information.
7809
+ Use this tool when you need to find up-to-date information or facts that you don't know.
7810
+ ${!content ? '' : `Search scope / instructions: ${content}`}
7811
+ `),
7777
7812
  parameters: {
7778
7813
  type: 'object',
7779
7814
  properties: {
@@ -7785,7 +7820,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
7785
7820
  required: ['query'],
7786
7821
  },
7787
7822
  },
7788
- */
7789
7823
  ];
7790
7824
  // Return requirements with updated tools and metadata
7791
7825
  return {
@@ -7797,6 +7831,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
7797
7831
  },
7798
7832
  };
7799
7833
  }
7834
+ /**
7835
+ * Gets the `web_search` tool function implementation.
7836
+ */
7837
+ getToolFunctions() {
7838
+ return {
7839
+ async web_search(args) {
7840
+ console.log('!!!! [Tool] web_search called', { args });
7841
+ const { query } = args;
7842
+ if (!query) {
7843
+ throw new Error('Search query is required');
7844
+ }
7845
+ const searchEngine = new SerpSearchEngine();
7846
+ const results = await searchEngine.search(query);
7847
+ return spaceTrim$1((block) => `
7848
+ Search results for "${query}":
7849
+
7850
+ ${block(results
7851
+ .map((result) => spaceTrim$1(`
7852
+ - **${result.title}**
7853
+ ${result.url}
7854
+ ${result.snippet}
7855
+ `))
7856
+ .join('\n\n'))}
7857
+ `);
7858
+ },
7859
+ };
7860
+ }
7800
7861
  }
7801
7862
  /**
7802
7863
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -11958,7 +12019,7 @@ function LlmChat(props) {
11958
12019
  */
11959
12020
  function AgentChat(props) {
11960
12021
  const { agent, title, persistenceKey, onChange, sendMessage, ...restProps } = props;
11961
- const brandColor = Color.fromSafe(agent.meta.color || PROMPTBOOK_COLOR).then(saturate(-0.5));
12022
+ const brandColor = Color.fromSafe(agent.meta.color || PROMPTBOOK_COLOR).then(saturate(-0.2));
11962
12023
  return (jsx(Fragment, { children: jsx(LlmChat, { title: title || `Chat with ${agent.meta.fullname || agent.agentName || 'Agent'}`, persistenceKey: persistenceKey || `agent-chat-${agent.agentName}`, userParticipantName: "USER", llmParticipantName: "AGENT" // <- TODO: [🧠] Maybe dynamic agent id
11963
12024
  , initialMessages: [
11964
12025
  {
@@ -19755,6 +19816,7 @@ _Agent_instances = new WeakSet(), _Agent_selfLearnNonce =
19755
19816
  */
19756
19817
  async function _Agent_selfLearnNonce() {
19757
19818
  await forTime(Math.random() * 5000);
19819
+ // <- TODO: [🕓] `await forRandom(...)`
19758
19820
  console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Nonce'));
19759
19821
  const nonce = `NONCE ${await linguisticHash(Math.random().toString())}`;
19760
19822
  // Append to the current source