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