@promptbook/remote-server 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 CHANGED
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-6';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8161,6 +8161,16 @@ function unwrapResult(text, options) {
8161
8161
  trimmedText = spaceTrim$1(trimmedText);
8162
8162
  }
8163
8163
  let processedText = trimmedText;
8164
+ // Check for markdown code block
8165
+ const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
8166
+ const codeBlockMatch = processedText.match(codeBlockRegex);
8167
+ if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
8168
+ // Check if there's only one code block
8169
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
8170
+ if (codeBlockCount === 1) {
8171
+ return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
8172
+ }
8173
+ }
8164
8174
  if (isIntroduceSentenceRemoved) {
8165
8175
  const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
8166
8176
  if (introduceSentenceRegex.test(text)) {
@@ -8168,6 +8178,14 @@ function unwrapResult(text, options) {
8168
8178
  processedText = processedText.replace(introduceSentenceRegex, '');
8169
8179
  }
8170
8180
  processedText = spaceTrim$1(processedText);
8181
+ // Check again for code block after removing introduce sentence
8182
+ const codeBlockMatch2 = processedText.match(codeBlockRegex);
8183
+ if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
8184
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
8185
+ if (codeBlockCount === 1) {
8186
+ return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
8187
+ }
8188
+ }
8171
8189
  }
8172
8190
  if (processedText.length < 3) {
8173
8191
  return trimmedText;
@@ -11533,6 +11551,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
11533
11551
  * Note: [💞] Ignore a discrepancy between file name and entity name
11534
11552
  */
11535
11553
 
11554
+ /**
11555
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
11556
+ *
11557
+ * @private <- TODO: !!!! Export via some package
11558
+ */
11559
+ class SerpSearchEngine {
11560
+ get title() {
11561
+ return 'SerpApi Search Engine';
11562
+ }
11563
+ get description() {
11564
+ return 'Search engine that uses SerpApi to fetch Google search results';
11565
+ }
11566
+ checkConfiguration() {
11567
+ if (!process.env.SERP_API_KEY) {
11568
+ throw new Error('SERP_API_KEY is not configured');
11569
+ }
11570
+ }
11571
+ async search(query) {
11572
+ const apiKey = process.env.SERP_API_KEY;
11573
+ if (!apiKey) {
11574
+ throw new Error('SERP_API_KEY is not configured');
11575
+ }
11576
+ const url = new URL('https://serpapi.com/search');
11577
+ url.searchParams.set('q', query);
11578
+ url.searchParams.set('api_key', apiKey);
11579
+ url.searchParams.set('engine', 'google');
11580
+ const response = await fetch(url.toString());
11581
+ if (!response.ok) {
11582
+ const body = await response.text();
11583
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
11584
+ }
11585
+ const data = (await response.json());
11586
+ return (data.organic_results || []).map((item) => ({
11587
+ title: item.title,
11588
+ url: item.link,
11589
+ snippet: item.snippet || '',
11590
+ }));
11591
+ }
11592
+ }
11593
+
11536
11594
  /**
11537
11595
  * USE SEARCH ENGINE commitment definition
11538
11596
  *
@@ -11609,18 +11667,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
11609
11667
  ? existingTools
11610
11668
  : [
11611
11669
  ...existingTools,
11612
- { type: 'web_search' },
11613
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
11614
- // In future we will use proper MCP search tool:
11615
- /*
11616
-
11617
11670
  {
11618
11671
  name: 'web_search',
11619
- description: spaceTrim(`
11620
- Search the internet for information.
11621
- Use this tool when you need to find up-to-date information or facts that you don't know.
11622
- ${!content ? '' : `Search scope / instructions: ${content}`}
11623
- `),
11672
+ description: spaceTrim$1(`
11673
+ Search the internet for information.
11674
+ Use this tool when you need to find up-to-date information or facts that you don't know.
11675
+ ${!content ? '' : `Search scope / instructions: ${content}`}
11676
+ `),
11624
11677
  parameters: {
11625
11678
  type: 'object',
11626
11679
  properties: {
@@ -11632,7 +11685,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
11632
11685
  required: ['query'],
11633
11686
  },
11634
11687
  },
11635
- */
11636
11688
  ];
11637
11689
  // Return requirements with updated tools and metadata
11638
11690
  return {
@@ -11644,6 +11696,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
11644
11696
  },
11645
11697
  };
11646
11698
  }
11699
+ /**
11700
+ * Gets the `web_search` tool function implementation.
11701
+ */
11702
+ getToolFunctions() {
11703
+ return {
11704
+ async web_search(args) {
11705
+ console.log('!!!! [Tool] web_search called', { args });
11706
+ const { query } = args;
11707
+ if (!query) {
11708
+ throw new Error('Search query is required');
11709
+ }
11710
+ const searchEngine = new SerpSearchEngine();
11711
+ const results = await searchEngine.search(query);
11712
+ return spaceTrim$1((block) => `
11713
+ Search results for "${query}":
11714
+
11715
+ ${block(results
11716
+ .map((result) => spaceTrim$1(`
11717
+ - **${result.title}**
11718
+ ${result.url}
11719
+ ${result.snippet}
11720
+ `))
11721
+ .join('\n\n'))}
11722
+ `);
11723
+ },
11724
+ };
11725
+ }
11647
11726
  }
11648
11727
  /**
11649
11728
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -11887,6 +11966,7 @@ const COMMITMENT_REGISTRY = [
11887
11966
  new NoteCommitmentDefinition('NOTES'),
11888
11967
  new NoteCommitmentDefinition('COMMENT'),
11889
11968
  new NoteCommitmentDefinition('NONCE'),
11969
+ new NoteCommitmentDefinition('TODO'),
11890
11970
  new GoalCommitmentDefinition('GOAL'),
11891
11971
  new GoalCommitmentDefinition('GOALS'),
11892
11972
  new InitialMessageCommitmentDefinition(),