@promptbook/core 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
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -12098,6 +12098,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12098
12098
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12099
12099
|
*/
|
|
12100
12100
|
|
|
12101
|
+
/**
|
|
12102
|
+
* A search engine implementation that uses the SerpApi to fetch Google search results.
|
|
12103
|
+
*
|
|
12104
|
+
* @private <- TODO: !!!! Export via some package
|
|
12105
|
+
*/
|
|
12106
|
+
class SerpSearchEngine {
|
|
12107
|
+
get title() {
|
|
12108
|
+
return 'SerpApi Search Engine';
|
|
12109
|
+
}
|
|
12110
|
+
get description() {
|
|
12111
|
+
return 'Search engine that uses SerpApi to fetch Google search results';
|
|
12112
|
+
}
|
|
12113
|
+
checkConfiguration() {
|
|
12114
|
+
if (!process.env.SERP_API_KEY) {
|
|
12115
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
12116
|
+
}
|
|
12117
|
+
}
|
|
12118
|
+
async search(query) {
|
|
12119
|
+
const apiKey = process.env.SERP_API_KEY;
|
|
12120
|
+
if (!apiKey) {
|
|
12121
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
12122
|
+
}
|
|
12123
|
+
const url = new URL('https://serpapi.com/search');
|
|
12124
|
+
url.searchParams.set('q', query);
|
|
12125
|
+
url.searchParams.set('api_key', apiKey);
|
|
12126
|
+
url.searchParams.set('engine', 'google');
|
|
12127
|
+
const response = await fetch(url.toString());
|
|
12128
|
+
if (!response.ok) {
|
|
12129
|
+
const body = await response.text();
|
|
12130
|
+
throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
|
|
12131
|
+
}
|
|
12132
|
+
const data = (await response.json());
|
|
12133
|
+
return (data.organic_results || []).map((item) => ({
|
|
12134
|
+
title: item.title,
|
|
12135
|
+
url: item.link,
|
|
12136
|
+
snippet: item.snippet || '',
|
|
12137
|
+
}));
|
|
12138
|
+
}
|
|
12139
|
+
}
|
|
12140
|
+
|
|
12101
12141
|
/**
|
|
12102
12142
|
* USE SEARCH ENGINE commitment definition
|
|
12103
12143
|
*
|
|
@@ -12174,18 +12214,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12174
12214
|
? existingTools
|
|
12175
12215
|
: [
|
|
12176
12216
|
...existingTools,
|
|
12177
|
-
{ type: 'web_search' },
|
|
12178
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
12179
|
-
// In future we will use proper MCP search tool:
|
|
12180
|
-
/*
|
|
12181
|
-
|
|
12182
12217
|
{
|
|
12183
12218
|
name: 'web_search',
|
|
12184
|
-
description: spaceTrim(`
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12219
|
+
description: spaceTrim$1(`
|
|
12220
|
+
Search the internet for information.
|
|
12221
|
+
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
12222
|
+
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
12223
|
+
`),
|
|
12189
12224
|
parameters: {
|
|
12190
12225
|
type: 'object',
|
|
12191
12226
|
properties: {
|
|
@@ -12197,7 +12232,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12197
12232
|
required: ['query'],
|
|
12198
12233
|
},
|
|
12199
12234
|
},
|
|
12200
|
-
*/
|
|
12201
12235
|
];
|
|
12202
12236
|
// Return requirements with updated tools and metadata
|
|
12203
12237
|
return {
|
|
@@ -12209,6 +12243,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
12209
12243
|
},
|
|
12210
12244
|
};
|
|
12211
12245
|
}
|
|
12246
|
+
/**
|
|
12247
|
+
* Gets the `web_search` tool function implementation.
|
|
12248
|
+
*/
|
|
12249
|
+
getToolFunctions() {
|
|
12250
|
+
return {
|
|
12251
|
+
async web_search(args) {
|
|
12252
|
+
console.log('!!!! [Tool] web_search called', { args });
|
|
12253
|
+
const { query } = args;
|
|
12254
|
+
if (!query) {
|
|
12255
|
+
throw new Error('Search query is required');
|
|
12256
|
+
}
|
|
12257
|
+
const searchEngine = new SerpSearchEngine();
|
|
12258
|
+
const results = await searchEngine.search(query);
|
|
12259
|
+
return spaceTrim$1((block) => `
|
|
12260
|
+
Search results for "${query}":
|
|
12261
|
+
|
|
12262
|
+
${block(results
|
|
12263
|
+
.map((result) => spaceTrim$1(`
|
|
12264
|
+
- **${result.title}**
|
|
12265
|
+
${result.url}
|
|
12266
|
+
${result.snippet}
|
|
12267
|
+
`))
|
|
12268
|
+
.join('\n\n'))}
|
|
12269
|
+
`);
|
|
12270
|
+
},
|
|
12271
|
+
};
|
|
12272
|
+
}
|
|
12212
12273
|
}
|
|
12213
12274
|
/**
|
|
12214
12275
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -18429,6 +18490,16 @@ function cacheLlmTools(llmTools, options = {}) {
|
|
|
18429
18490
|
}
|
|
18430
18491
|
}
|
|
18431
18492
|
}
|
|
18493
|
+
if (shouldCache && promptResult.toolCalls !== undefined) {
|
|
18494
|
+
// Note: Do not cache results that contain tool calls because they are dynamic and should be always fresh
|
|
18495
|
+
// 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.
|
|
18496
|
+
shouldCache = false;
|
|
18497
|
+
if (isVerbose) {
|
|
18498
|
+
console.info('Not caching result that contains tool calls for key:', key, {
|
|
18499
|
+
toolCalls: promptResult.toolCalls,
|
|
18500
|
+
});
|
|
18501
|
+
}
|
|
18502
|
+
}
|
|
18432
18503
|
if (shouldCache) {
|
|
18433
18504
|
await storage.setItem(key, {
|
|
18434
18505
|
date: $getCurrentDate(),
|
|
@@ -21487,6 +21558,7 @@ _Agent_instances = new WeakSet(), _Agent_selfLearnNonce =
|
|
|
21487
21558
|
*/
|
|
21488
21559
|
async function _Agent_selfLearnNonce() {
|
|
21489
21560
|
await forTime(Math.random() * 5000);
|
|
21561
|
+
// <- TODO: [🕓] `await forRandom(...)`
|
|
21490
21562
|
console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Nonce'));
|
|
21491
21563
|
const nonce = `NONCE ${await linguisticHash(Math.random().toString())}`;
|
|
21492
21564
|
// Append to the current source
|