@promptbook/javascript 0.105.0-6 → 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 +92 -12
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/commitments/NOTE/NOTE.d.ts +2 -2
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +6 -0
- package/esm/typings/src/commitments/index.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +1 -0
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +7 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +92 -12
- package/umd/index.umd.js.map +1 -1
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
|
|
@@ -2244,6 +2244,16 @@ function unwrapResult(text, options) {
|
|
|
2244
2244
|
trimmedText = spaceTrim$1(trimmedText);
|
|
2245
2245
|
}
|
|
2246
2246
|
let processedText = trimmedText;
|
|
2247
|
+
// Check for markdown code block
|
|
2248
|
+
const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
|
|
2249
|
+
const codeBlockMatch = processedText.match(codeBlockRegex);
|
|
2250
|
+
if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
|
|
2251
|
+
// Check if there's only one code block
|
|
2252
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
2253
|
+
if (codeBlockCount === 1) {
|
|
2254
|
+
return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2247
2257
|
if (isIntroduceSentenceRemoved) {
|
|
2248
2258
|
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
2249
2259
|
if (introduceSentenceRegex.test(text)) {
|
|
@@ -2251,6 +2261,14 @@ function unwrapResult(text, options) {
|
|
|
2251
2261
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
2252
2262
|
}
|
|
2253
2263
|
processedText = spaceTrim$1(processedText);
|
|
2264
|
+
// Check again for code block after removing introduce sentence
|
|
2265
|
+
const codeBlockMatch2 = processedText.match(codeBlockRegex);
|
|
2266
|
+
if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
|
|
2267
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
2268
|
+
if (codeBlockCount === 1) {
|
|
2269
|
+
return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2254
2272
|
}
|
|
2255
2273
|
if (processedText.length < 3) {
|
|
2256
2274
|
return trimmedText;
|
|
@@ -5616,6 +5634,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5616
5634
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5617
5635
|
*/
|
|
5618
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
|
+
|
|
5619
5677
|
/**
|
|
5620
5678
|
* USE SEARCH ENGINE commitment definition
|
|
5621
5679
|
*
|
|
@@ -5692,18 +5750,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5692
5750
|
? existingTools
|
|
5693
5751
|
: [
|
|
5694
5752
|
...existingTools,
|
|
5695
|
-
{ type: 'web_search' },
|
|
5696
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
5697
|
-
// In future we will use proper MCP search tool:
|
|
5698
|
-
/*
|
|
5699
|
-
|
|
5700
5753
|
{
|
|
5701
5754
|
name: 'web_search',
|
|
5702
|
-
description: spaceTrim(`
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
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
|
+
`),
|
|
5707
5760
|
parameters: {
|
|
5708
5761
|
type: 'object',
|
|
5709
5762
|
properties: {
|
|
@@ -5715,7 +5768,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5715
5768
|
required: ['query'],
|
|
5716
5769
|
},
|
|
5717
5770
|
},
|
|
5718
|
-
*/
|
|
5719
5771
|
];
|
|
5720
5772
|
// Return requirements with updated tools and metadata
|
|
5721
5773
|
return {
|
|
@@ -5727,6 +5779,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5727
5779
|
},
|
|
5728
5780
|
};
|
|
5729
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
|
+
}
|
|
5730
5809
|
}
|
|
5731
5810
|
/**
|
|
5732
5811
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -5970,6 +6049,7 @@ const COMMITMENT_REGISTRY = [
|
|
|
5970
6049
|
new NoteCommitmentDefinition('NOTES'),
|
|
5971
6050
|
new NoteCommitmentDefinition('COMMENT'),
|
|
5972
6051
|
new NoteCommitmentDefinition('NONCE'),
|
|
6052
|
+
new NoteCommitmentDefinition('TODO'),
|
|
5973
6053
|
new GoalCommitmentDefinition('GOAL'),
|
|
5974
6054
|
new GoalCommitmentDefinition('GOALS'),
|
|
5975
6055
|
new InitialMessageCommitmentDefinition(),
|