@promptbook/fake-llm 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
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
20
20
  * @generated
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-6';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2775,6 +2775,16 @@ function unwrapResult(text, options) {
2775
2775
  trimmedText = spaceTrim$1(trimmedText);
2776
2776
  }
2777
2777
  let processedText = trimmedText;
2778
+ // Check for markdown code block
2779
+ const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
2780
+ const codeBlockMatch = processedText.match(codeBlockRegex);
2781
+ if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
2782
+ // Check if there's only one code block
2783
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
2784
+ if (codeBlockCount === 1) {
2785
+ return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
2786
+ }
2787
+ }
2778
2788
  if (isIntroduceSentenceRemoved) {
2779
2789
  const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2780
2790
  if (introduceSentenceRegex.test(text)) {
@@ -2782,6 +2792,14 @@ function unwrapResult(text, options) {
2782
2792
  processedText = processedText.replace(introduceSentenceRegex, '');
2783
2793
  }
2784
2794
  processedText = spaceTrim$1(processedText);
2795
+ // Check again for code block after removing introduce sentence
2796
+ const codeBlockMatch2 = processedText.match(codeBlockRegex);
2797
+ if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
2798
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
2799
+ if (codeBlockCount === 1) {
2800
+ return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
2801
+ }
2802
+ }
2785
2803
  }
2786
2804
  if (processedText.length < 3) {
2787
2805
  return trimmedText;
@@ -6147,6 +6165,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
6147
6165
  * Note: [💞] Ignore a discrepancy between file name and entity name
6148
6166
  */
6149
6167
 
6168
+ /**
6169
+ * A search engine implementation that uses the SerpApi to fetch Google search results.
6170
+ *
6171
+ * @private <- TODO: !!!! Export via some package
6172
+ */
6173
+ class SerpSearchEngine {
6174
+ get title() {
6175
+ return 'SerpApi Search Engine';
6176
+ }
6177
+ get description() {
6178
+ return 'Search engine that uses SerpApi to fetch Google search results';
6179
+ }
6180
+ checkConfiguration() {
6181
+ if (!process.env.SERP_API_KEY) {
6182
+ throw new Error('SERP_API_KEY is not configured');
6183
+ }
6184
+ }
6185
+ async search(query) {
6186
+ const apiKey = process.env.SERP_API_KEY;
6187
+ if (!apiKey) {
6188
+ throw new Error('SERP_API_KEY is not configured');
6189
+ }
6190
+ const url = new URL('https://serpapi.com/search');
6191
+ url.searchParams.set('q', query);
6192
+ url.searchParams.set('api_key', apiKey);
6193
+ url.searchParams.set('engine', 'google');
6194
+ const response = await fetch(url.toString());
6195
+ if (!response.ok) {
6196
+ const body = await response.text();
6197
+ throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
6198
+ }
6199
+ const data = (await response.json());
6200
+ return (data.organic_results || []).map((item) => ({
6201
+ title: item.title,
6202
+ url: item.link,
6203
+ snippet: item.snippet || '',
6204
+ }));
6205
+ }
6206
+ }
6207
+
6150
6208
  /**
6151
6209
  * USE SEARCH ENGINE commitment definition
6152
6210
  *
@@ -6223,18 +6281,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
6223
6281
  ? existingTools
6224
6282
  : [
6225
6283
  ...existingTools,
6226
- { type: 'web_search' },
6227
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
6228
- // In future we will use proper MCP search tool:
6229
- /*
6230
-
6231
6284
  {
6232
6285
  name: 'web_search',
6233
- description: spaceTrim(`
6234
- Search the internet for information.
6235
- Use this tool when you need to find up-to-date information or facts that you don't know.
6236
- ${!content ? '' : `Search scope / instructions: ${content}`}
6237
- `),
6286
+ description: spaceTrim$1(`
6287
+ Search the internet for information.
6288
+ Use this tool when you need to find up-to-date information or facts that you don't know.
6289
+ ${!content ? '' : `Search scope / instructions: ${content}`}
6290
+ `),
6238
6291
  parameters: {
6239
6292
  type: 'object',
6240
6293
  properties: {
@@ -6246,7 +6299,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
6246
6299
  required: ['query'],
6247
6300
  },
6248
6301
  },
6249
- */
6250
6302
  ];
6251
6303
  // Return requirements with updated tools and metadata
6252
6304
  return {
@@ -6258,6 +6310,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
6258
6310
  },
6259
6311
  };
6260
6312
  }
6313
+ /**
6314
+ * Gets the `web_search` tool function implementation.
6315
+ */
6316
+ getToolFunctions() {
6317
+ return {
6318
+ async web_search(args) {
6319
+ console.log('!!!! [Tool] web_search called', { args });
6320
+ const { query } = args;
6321
+ if (!query) {
6322
+ throw new Error('Search query is required');
6323
+ }
6324
+ const searchEngine = new SerpSearchEngine();
6325
+ const results = await searchEngine.search(query);
6326
+ return spaceTrim$1((block) => `
6327
+ Search results for "${query}":
6328
+
6329
+ ${block(results
6330
+ .map((result) => spaceTrim$1(`
6331
+ - **${result.title}**
6332
+ ${result.url}
6333
+ ${result.snippet}
6334
+ `))
6335
+ .join('\n\n'))}
6336
+ `);
6337
+ },
6338
+ };
6339
+ }
6261
6340
  }
6262
6341
  /**
6263
6342
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6501,6 +6580,7 @@ const COMMITMENT_REGISTRY = [
6501
6580
  new NoteCommitmentDefinition('NOTES'),
6502
6581
  new NoteCommitmentDefinition('COMMENT'),
6503
6582
  new NoteCommitmentDefinition('NONCE'),
6583
+ new NoteCommitmentDefinition('TODO'),
6504
6584
  new GoalCommitmentDefinition('GOAL'),
6505
6585
  new GoalCommitmentDefinition('GOALS'),
6506
6586
  new InitialMessageCommitmentDefinition(),