@promptbook/node 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
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15254,6 +15254,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15254
15254
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15255
15255
|
*/
|
|
15256
15256
|
|
|
15257
|
+
/**
|
|
15258
|
+
* A search engine implementation that uses the SerpApi to fetch Google search results.
|
|
15259
|
+
*
|
|
15260
|
+
* @private <- TODO: !!!! Export via some package
|
|
15261
|
+
*/
|
|
15262
|
+
class SerpSearchEngine {
|
|
15263
|
+
get title() {
|
|
15264
|
+
return 'SerpApi Search Engine';
|
|
15265
|
+
}
|
|
15266
|
+
get description() {
|
|
15267
|
+
return 'Search engine that uses SerpApi to fetch Google search results';
|
|
15268
|
+
}
|
|
15269
|
+
checkConfiguration() {
|
|
15270
|
+
if (!process.env.SERP_API_KEY) {
|
|
15271
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
15272
|
+
}
|
|
15273
|
+
}
|
|
15274
|
+
async search(query) {
|
|
15275
|
+
const apiKey = process.env.SERP_API_KEY;
|
|
15276
|
+
if (!apiKey) {
|
|
15277
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
15278
|
+
}
|
|
15279
|
+
const url = new URL('https://serpapi.com/search');
|
|
15280
|
+
url.searchParams.set('q', query);
|
|
15281
|
+
url.searchParams.set('api_key', apiKey);
|
|
15282
|
+
url.searchParams.set('engine', 'google');
|
|
15283
|
+
const response = await fetch(url.toString());
|
|
15284
|
+
if (!response.ok) {
|
|
15285
|
+
const body = await response.text();
|
|
15286
|
+
throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
|
|
15287
|
+
}
|
|
15288
|
+
const data = (await response.json());
|
|
15289
|
+
return (data.organic_results || []).map((item) => ({
|
|
15290
|
+
title: item.title,
|
|
15291
|
+
url: item.link,
|
|
15292
|
+
snippet: item.snippet || '',
|
|
15293
|
+
}));
|
|
15294
|
+
}
|
|
15295
|
+
}
|
|
15296
|
+
|
|
15257
15297
|
/**
|
|
15258
15298
|
* USE SEARCH ENGINE commitment definition
|
|
15259
15299
|
*
|
|
@@ -15330,18 +15370,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15330
15370
|
? existingTools
|
|
15331
15371
|
: [
|
|
15332
15372
|
...existingTools,
|
|
15333
|
-
{ type: 'web_search' },
|
|
15334
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
15335
|
-
// In future we will use proper MCP search tool:
|
|
15336
|
-
/*
|
|
15337
|
-
|
|
15338
15373
|
{
|
|
15339
15374
|
name: 'web_search',
|
|
15340
|
-
description: spaceTrim(`
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
15344
|
-
|
|
15375
|
+
description: spaceTrim$1(`
|
|
15376
|
+
Search the internet for information.
|
|
15377
|
+
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
15378
|
+
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
15379
|
+
`),
|
|
15345
15380
|
parameters: {
|
|
15346
15381
|
type: 'object',
|
|
15347
15382
|
properties: {
|
|
@@ -15353,7 +15388,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15353
15388
|
required: ['query'],
|
|
15354
15389
|
},
|
|
15355
15390
|
},
|
|
15356
|
-
*/
|
|
15357
15391
|
];
|
|
15358
15392
|
// Return requirements with updated tools and metadata
|
|
15359
15393
|
return {
|
|
@@ -15365,6 +15399,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15365
15399
|
},
|
|
15366
15400
|
};
|
|
15367
15401
|
}
|
|
15402
|
+
/**
|
|
15403
|
+
* Gets the `web_search` tool function implementation.
|
|
15404
|
+
*/
|
|
15405
|
+
getToolFunctions() {
|
|
15406
|
+
return {
|
|
15407
|
+
async web_search(args) {
|
|
15408
|
+
console.log('!!!! [Tool] web_search called', { args });
|
|
15409
|
+
const { query } = args;
|
|
15410
|
+
if (!query) {
|
|
15411
|
+
throw new Error('Search query is required');
|
|
15412
|
+
}
|
|
15413
|
+
const searchEngine = new SerpSearchEngine();
|
|
15414
|
+
const results = await searchEngine.search(query);
|
|
15415
|
+
return spaceTrim$1((block) => `
|
|
15416
|
+
Search results for "${query}":
|
|
15417
|
+
|
|
15418
|
+
${block(results
|
|
15419
|
+
.map((result) => spaceTrim$1(`
|
|
15420
|
+
- **${result.title}**
|
|
15421
|
+
${result.url}
|
|
15422
|
+
${result.snippet}
|
|
15423
|
+
`))
|
|
15424
|
+
.join('\n\n'))}
|
|
15425
|
+
`);
|
|
15426
|
+
},
|
|
15427
|
+
};
|
|
15428
|
+
}
|
|
15368
15429
|
}
|
|
15369
15430
|
/**
|
|
15370
15431
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|