@promptbook/browser 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
|
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
19
19
|
* @generated
|
|
20
20
|
* @see https://github.com/webgptorg/promptbook
|
|
21
21
|
*/
|
|
22
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
|
|
23
23
|
/**
|
|
24
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
25
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -6063,6 +6063,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6063
6063
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6064
6064
|
*/
|
|
6065
6065
|
|
|
6066
|
+
/**
|
|
6067
|
+
* A search engine implementation that uses the SerpApi to fetch Google search results.
|
|
6068
|
+
*
|
|
6069
|
+
* @private <- TODO: !!!! Export via some package
|
|
6070
|
+
*/
|
|
6071
|
+
class SerpSearchEngine {
|
|
6072
|
+
get title() {
|
|
6073
|
+
return 'SerpApi Search Engine';
|
|
6074
|
+
}
|
|
6075
|
+
get description() {
|
|
6076
|
+
return 'Search engine that uses SerpApi to fetch Google search results';
|
|
6077
|
+
}
|
|
6078
|
+
checkConfiguration() {
|
|
6079
|
+
if (!process.env.SERP_API_KEY) {
|
|
6080
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
async search(query) {
|
|
6084
|
+
const apiKey = process.env.SERP_API_KEY;
|
|
6085
|
+
if (!apiKey) {
|
|
6086
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
6087
|
+
}
|
|
6088
|
+
const url = new URL('https://serpapi.com/search');
|
|
6089
|
+
url.searchParams.set('q', query);
|
|
6090
|
+
url.searchParams.set('api_key', apiKey);
|
|
6091
|
+
url.searchParams.set('engine', 'google');
|
|
6092
|
+
const response = await fetch(url.toString());
|
|
6093
|
+
if (!response.ok) {
|
|
6094
|
+
const body = await response.text();
|
|
6095
|
+
throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
|
|
6096
|
+
}
|
|
6097
|
+
const data = (await response.json());
|
|
6098
|
+
return (data.organic_results || []).map((item) => ({
|
|
6099
|
+
title: item.title,
|
|
6100
|
+
url: item.link,
|
|
6101
|
+
snippet: item.snippet || '',
|
|
6102
|
+
}));
|
|
6103
|
+
}
|
|
6104
|
+
}
|
|
6105
|
+
|
|
6066
6106
|
/**
|
|
6067
6107
|
* USE SEARCH ENGINE commitment definition
|
|
6068
6108
|
*
|
|
@@ -6139,18 +6179,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6139
6179
|
? existingTools
|
|
6140
6180
|
: [
|
|
6141
6181
|
...existingTools,
|
|
6142
|
-
{ type: 'web_search' },
|
|
6143
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
6144
|
-
// In future we will use proper MCP search tool:
|
|
6145
|
-
/*
|
|
6146
|
-
|
|
6147
6182
|
{
|
|
6148
6183
|
name: 'web_search',
|
|
6149
|
-
description: spaceTrim(`
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6184
|
+
description: spaceTrim$1(`
|
|
6185
|
+
Search the internet for information.
|
|
6186
|
+
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
6187
|
+
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
6188
|
+
`),
|
|
6154
6189
|
parameters: {
|
|
6155
6190
|
type: 'object',
|
|
6156
6191
|
properties: {
|
|
@@ -6162,7 +6197,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6162
6197
|
required: ['query'],
|
|
6163
6198
|
},
|
|
6164
6199
|
},
|
|
6165
|
-
*/
|
|
6166
6200
|
];
|
|
6167
6201
|
// Return requirements with updated tools and metadata
|
|
6168
6202
|
return {
|
|
@@ -6174,6 +6208,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6174
6208
|
},
|
|
6175
6209
|
};
|
|
6176
6210
|
}
|
|
6211
|
+
/**
|
|
6212
|
+
* Gets the `web_search` tool function implementation.
|
|
6213
|
+
*/
|
|
6214
|
+
getToolFunctions() {
|
|
6215
|
+
return {
|
|
6216
|
+
async web_search(args) {
|
|
6217
|
+
console.log('!!!! [Tool] web_search called', { args });
|
|
6218
|
+
const { query } = args;
|
|
6219
|
+
if (!query) {
|
|
6220
|
+
throw new Error('Search query is required');
|
|
6221
|
+
}
|
|
6222
|
+
const searchEngine = new SerpSearchEngine();
|
|
6223
|
+
const results = await searchEngine.search(query);
|
|
6224
|
+
return spaceTrim$1((block) => `
|
|
6225
|
+
Search results for "${query}":
|
|
6226
|
+
|
|
6227
|
+
${block(results
|
|
6228
|
+
.map((result) => spaceTrim$1(`
|
|
6229
|
+
- **${result.title}**
|
|
6230
|
+
${result.url}
|
|
6231
|
+
${result.snippet}
|
|
6232
|
+
`))
|
|
6233
|
+
.join('\n\n'))}
|
|
6234
|
+
`);
|
|
6235
|
+
},
|
|
6236
|
+
};
|
|
6237
|
+
}
|
|
6177
6238
|
}
|
|
6178
6239
|
/**
|
|
6179
6240
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|