@promptbook/fake-llm 0.105.0-7 → 0.105.0-9

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-8`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/fake-llm",
3
- "version": "0.105.0-7",
3
+ "version": "0.105.0-9",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -96,7 +96,7 @@
96
96
  "module": "./esm/index.es.js",
97
97
  "typings": "./esm/typings/src/_packages/fake-llm.index.d.ts",
98
98
  "peerDependencies": {
99
- "@promptbook/core": "0.105.0-7"
99
+ "@promptbook/core": "0.105.0-9"
100
100
  },
101
101
  "dependencies": {
102
102
  "crypto": "1.0.1",
package/umd/index.umd.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-9';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6167,6 +6167,46 @@
6167
6167
  * Note: [💞] Ignore a discrepancy between file name and entity name
6168
6168
  */
6169
6169
 
6170
+ /**
6171
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
6172
+ *
6173
+ * @private <- TODO: !!!! Export via some package
6174
+ */
6175
+ class SerpSearchEngine {
6176
+ get title() {
6177
+ return 'SerpApi Search Engine';
6178
+ }
6179
+ get description() {
6180
+ return 'Search engine that uses SerpApi to fetch Google search results';
6181
+ }
6182
+ checkConfiguration() {
6183
+ if (!process.env.SERP_API_KEY) {
6184
+ throw new Error('SERP_API_KEY is not configured');
6185
+ }
6186
+ }
6187
+ async search(query) {
6188
+ const apiKey = process.env.SERP_API_KEY;
6189
+ if (!apiKey) {
6190
+ throw new Error('SERP_API_KEY is not configured');
6191
+ }
6192
+ const url = new URL('https://serpapi.com/search');
6193
+ url.searchParams.set('q', query);
6194
+ url.searchParams.set('api_key', apiKey);
6195
+ url.searchParams.set('engine', 'google');
6196
+ const response = await fetch(url.toString());
6197
+ if (!response.ok) {
6198
+ const body = await response.text();
6199
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
6200
+ }
6201
+ const data = (await response.json());
6202
+ return (data.organic_results || []).map((item) => ({
6203
+ title: item.title,
6204
+ url: item.link,
6205
+ snippet: item.snippet || '',
6206
+ }));
6207
+ }
6208
+ }
6209
+
6170
6210
  /**
6171
6211
  * USE SEARCH ENGINE commitment definition
6172
6212
  *
@@ -6243,18 +6283,13 @@
6243
6283
  ? existingTools
6244
6284
  : [
6245
6285
  ...existingTools,
6246
- { type: 'web_search' },
6247
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
6248
- // In future we will use proper MCP search tool:
6249
- /*
6250
-
6251
6286
  {
6252
6287
  name: 'web_search',
6253
- description: spaceTrim(`
6254
- Search the internet for information.
6255
- Use this tool when you need to find up-to-date information or facts that you don't know.
6256
- ${!content ? '' : `Search scope / instructions: ${content}`}
6257
- `),
6288
+ description: spaceTrim$1.spaceTrim(`
6289
+ Search the internet for information.
6290
+ Use this tool when you need to find up-to-date information or facts that you don't know.
6291
+ ${!content ? '' : `Search scope / instructions: ${content}`}
6292
+ `),
6258
6293
  parameters: {
6259
6294
  type: 'object',
6260
6295
  properties: {
@@ -6266,7 +6301,6 @@
6266
6301
  required: ['query'],
6267
6302
  },
6268
6303
  },
6269
- */
6270
6304
  ];
6271
6305
  // Return requirements with updated tools and metadata
6272
6306
  return {
@@ -6278,6 +6312,33 @@
6278
6312
  },
6279
6313
  };
6280
6314
  }
6315
+ /**
6316
+ * Gets the `web_search` tool function implementation.
6317
+ */
6318
+ getToolFunctions() {
6319
+ return {
6320
+ async web_search(args) {
6321
+ console.log('!!!! [Tool] web_search called', { args });
6322
+ const { query } = args;
6323
+ if (!query) {
6324
+ throw new Error('Search query is required');
6325
+ }
6326
+ const searchEngine = new SerpSearchEngine();
6327
+ const results = await searchEngine.search(query);
6328
+ return spaceTrim$1.spaceTrim((block) => `
6329
+ Search results for "${query}":
6330
+
6331
+ ${block(results
6332
+ .map((result) => spaceTrim$1.spaceTrim(`
6333
+ - **${result.title}**
6334
+ ${result.url}
6335
+ ${result.snippet}
6336
+ `))
6337
+ .join('\n\n'))}
6338
+ `);
6339
+ },
6340
+ };
6341
+ }
6281
6342
  }
6282
6343
  /**
6283
6344
  * Note: [💞] Ignore a discrepancy between file name and entity name