@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.
@@ -1,4 +1,6 @@
1
+ import { string_javascript_name } from '../../_packages/types.index';
1
2
  import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
3
+ import { ToolFunction } from '../../scripting/javascript/JavascriptExecutionToolsOptions';
2
4
  import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
3
5
  /**
4
6
  * USE SEARCH ENGINE commitment definition
@@ -32,6 +34,10 @@ export declare class UseSearchEngineCommitmentDefinition extends BaseCommitmentD
32
34
  */
33
35
  get documentation(): string;
34
36
  applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
37
+ /**
38
+ * Gets the `web_search` tool function implementation.
39
+ */
40
+ getToolFunctions(): Record<string_javascript_name, ToolFunction>;
35
41
  }
36
42
  /**
37
43
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.105.0-6`).
18
+ * It follows semantic versioning (e.g., `0.105.0-7`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.105.0-7",
3
+ "version": "0.105.0-8",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -93,7 +93,7 @@
93
93
  "module": "./esm/index.es.js",
94
94
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
95
95
  "peerDependencies": {
96
- "@promptbook/core": "0.105.0-7"
96
+ "@promptbook/core": "0.105.0-8"
97
97
  },
98
98
  "dependencies": {
99
99
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -45,7 +45,7 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
48
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
49
49
  /**
50
50
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
51
51
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -15271,6 +15271,46 @@
15271
15271
  * Note: [💞] Ignore a discrepancy between file name and entity name
15272
15272
  */
15273
15273
 
15274
+ /**
15275
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
15276
+ *
15277
+ * @private <- TODO: !!!! Export via some package
15278
+ */
15279
+ class SerpSearchEngine {
15280
+ get title() {
15281
+ return 'SerpApi Search Engine';
15282
+ }
15283
+ get description() {
15284
+ return 'Search engine that uses SerpApi to fetch Google search results';
15285
+ }
15286
+ checkConfiguration() {
15287
+ if (!process.env.SERP_API_KEY) {
15288
+ throw new Error('SERP_API_KEY is not configured');
15289
+ }
15290
+ }
15291
+ async search(query) {
15292
+ const apiKey = process.env.SERP_API_KEY;
15293
+ if (!apiKey) {
15294
+ throw new Error('SERP_API_KEY is not configured');
15295
+ }
15296
+ const url = new URL('https://serpapi.com/search');
15297
+ url.searchParams.set('q', query);
15298
+ url.searchParams.set('api_key', apiKey);
15299
+ url.searchParams.set('engine', 'google');
15300
+ const response = await fetch(url.toString());
15301
+ if (!response.ok) {
15302
+ const body = await response.text();
15303
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
15304
+ }
15305
+ const data = (await response.json());
15306
+ return (data.organic_results || []).map((item) => ({
15307
+ title: item.title,
15308
+ url: item.link,
15309
+ snippet: item.snippet || '',
15310
+ }));
15311
+ }
15312
+ }
15313
+
15274
15314
  /**
15275
15315
  * USE SEARCH ENGINE commitment definition
15276
15316
  *
@@ -15347,18 +15387,13 @@
15347
15387
  ? existingTools
15348
15388
  : [
15349
15389
  ...existingTools,
15350
- { type: 'web_search' },
15351
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
15352
- // In future we will use proper MCP search tool:
15353
- /*
15354
-
15355
15390
  {
15356
15391
  name: 'web_search',
15357
- description: spaceTrim(`
15358
- Search the internet for information.
15359
- Use this tool when you need to find up-to-date information or facts that you don't know.
15360
- ${!content ? '' : `Search scope / instructions: ${content}`}
15361
- `),
15392
+ description: spaceTrim$1.spaceTrim(`
15393
+ Search the internet for information.
15394
+ Use this tool when you need to find up-to-date information or facts that you don't know.
15395
+ ${!content ? '' : `Search scope / instructions: ${content}`}
15396
+ `),
15362
15397
  parameters: {
15363
15398
  type: 'object',
15364
15399
  properties: {
@@ -15370,7 +15405,6 @@
15370
15405
  required: ['query'],
15371
15406
  },
15372
15407
  },
15373
- */
15374
15408
  ];
15375
15409
  // Return requirements with updated tools and metadata
15376
15410
  return {
@@ -15382,6 +15416,33 @@
15382
15416
  },
15383
15417
  };
15384
15418
  }
15419
+ /**
15420
+ * Gets the `web_search` tool function implementation.
15421
+ */
15422
+ getToolFunctions() {
15423
+ return {
15424
+ async web_search(args) {
15425
+ console.log('!!!! [Tool] web_search called', { args });
15426
+ const { query } = args;
15427
+ if (!query) {
15428
+ throw new Error('Search query is required');
15429
+ }
15430
+ const searchEngine = new SerpSearchEngine();
15431
+ const results = await searchEngine.search(query);
15432
+ return spaceTrim$1.spaceTrim((block) => `
15433
+ Search results for "${query}":
15434
+
15435
+ ${block(results
15436
+ .map((result) => spaceTrim$1.spaceTrim(`
15437
+ - **${result.title}**
15438
+ ${result.url}
15439
+ ${result.snippet}
15440
+ `))
15441
+ .join('\n\n'))}
15442
+ `);
15443
+ },
15444
+ };
15445
+ }
15385
15446
  }
15386
15447
  /**
15387
15448
  * Note: [💞] Ignore a discrepancy between file name and entity name