@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.
@@ -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
@@ -44,7 +44,7 @@ import { NotYetImplementedCommitmentDefinition } from './_base/NotYetImplemented
44
44
  *
45
45
  * @private Use functions to access commitments instead of this array directly
46
46
  */
47
- export declare const COMMITMENT_REGISTRY: readonly [PersonaCommitmentDefinition, PersonaCommitmentDefinition, KnowledgeCommitmentDefinition, MemoryCommitmentDefinition, MemoryCommitmentDefinition, StyleCommitmentDefinition, StyleCommitmentDefinition, RuleCommitmentDefinition, RuleCommitmentDefinition, LanguageCommitmentDefinition, LanguageCommitmentDefinition, SampleCommitmentDefinition, SampleCommitmentDefinition, FormatCommitmentDefinition, FormatCommitmentDefinition, FromCommitmentDefinition, ImportCommitmentDefinition, ImportCommitmentDefinition, ModelCommitmentDefinition, ModelCommitmentDefinition, ActionCommitmentDefinition, ActionCommitmentDefinition, ComponentCommitmentDefinition, MetaImageCommitmentDefinition, MetaColorCommitmentDefinition, MetaFontCommitmentDefinition, MetaLinkCommitmentDefinition, MetaCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, GoalCommitmentDefinition, GoalCommitmentDefinition, InitialMessageCommitmentDefinition, UserMessageCommitmentDefinition, AgentMessageCommitmentDefinition, MessageCommitmentDefinition, MessageCommitmentDefinition, ScenarioCommitmentDefinition, ScenarioCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DictionaryCommitmentDefinition, OpenCommitmentDefinition, ClosedCommitmentDefinition, UseBrowserCommitmentDefinition, UseSearchEngineCommitmentDefinition, UseTimeCommitmentDefinition, UseMcpCommitmentDefinition, UseCommitmentDefinition, NotYetImplementedCommitmentDefinition<"EXPECT">, NotYetImplementedCommitmentDefinition<"BEHAVIOUR">, NotYetImplementedCommitmentDefinition<"BEHAVIOURS">, NotYetImplementedCommitmentDefinition<"AVOID">, NotYetImplementedCommitmentDefinition<"AVOIDANCE">, NotYetImplementedCommitmentDefinition<"CONTEXT">];
47
+ export declare const COMMITMENT_REGISTRY: readonly [PersonaCommitmentDefinition, PersonaCommitmentDefinition, KnowledgeCommitmentDefinition, MemoryCommitmentDefinition, MemoryCommitmentDefinition, StyleCommitmentDefinition, StyleCommitmentDefinition, RuleCommitmentDefinition, RuleCommitmentDefinition, LanguageCommitmentDefinition, LanguageCommitmentDefinition, SampleCommitmentDefinition, SampleCommitmentDefinition, FormatCommitmentDefinition, FormatCommitmentDefinition, FromCommitmentDefinition, ImportCommitmentDefinition, ImportCommitmentDefinition, ModelCommitmentDefinition, ModelCommitmentDefinition, ActionCommitmentDefinition, ActionCommitmentDefinition, ComponentCommitmentDefinition, MetaImageCommitmentDefinition, MetaColorCommitmentDefinition, MetaFontCommitmentDefinition, MetaLinkCommitmentDefinition, MetaCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, NoteCommitmentDefinition, GoalCommitmentDefinition, GoalCommitmentDefinition, InitialMessageCommitmentDefinition, UserMessageCommitmentDefinition, AgentMessageCommitmentDefinition, MessageCommitmentDefinition, MessageCommitmentDefinition, ScenarioCommitmentDefinition, ScenarioCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DeleteCommitmentDefinition, DictionaryCommitmentDefinition, OpenCommitmentDefinition, ClosedCommitmentDefinition, UseBrowserCommitmentDefinition, UseSearchEngineCommitmentDefinition, UseTimeCommitmentDefinition, UseMcpCommitmentDefinition, UseCommitmentDefinition, NotYetImplementedCommitmentDefinition<"EXPECT">, NotYetImplementedCommitmentDefinition<"BEHAVIOUR">, NotYetImplementedCommitmentDefinition<"BEHAVIOURS">, NotYetImplementedCommitmentDefinition<"AVOID">, NotYetImplementedCommitmentDefinition<"AVOIDANCE">, NotYetImplementedCommitmentDefinition<"CONTEXT">];
48
48
  /**
49
49
  * Gets a commitment definition by its type
50
50
  * @param type The commitment type to look up
@@ -72,6 +72,7 @@ export declare class Agent extends AgentLlmExecutionTools implements LlmExecutio
72
72
  */
73
73
  get parameters(): Array<BookParameter>;
74
74
  readonly agentSource: BehaviorSubject<string_book>;
75
+ private readonly teacherAgent;
75
76
  constructor(options: AgentOptions);
76
77
  /**
77
78
  * Calls the chat model with agent-specific system prompt and requirements with streaming
@@ -2,6 +2,7 @@ import type { string_book } from '../../book-2.0/agent-source/string_book';
2
2
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
3
3
  import type { ExecutionTools } from '../../execution/ExecutionTools';
4
4
  import type { Updatable } from '../../types/Updatable';
5
+ import { Agent } from './Agent';
5
6
  /**
6
7
  * Options for creating an Agent
7
8
  */
@@ -16,4 +17,10 @@ export type AgentOptions = CommonToolsOptions & {
16
17
  * The source of the agent
17
18
  */
18
19
  agentSource: Updatable<string_book>;
20
+ /**
21
+ * Teacher agent for self-learning
22
+ *
23
+ * Note: If provided, the agent can do full self-learning from the teacher agent during its operation.
24
+ */
25
+ teacherAgent: Agent | null;
19
26
  };
@@ -3,7 +3,7 @@ import type { string_agent_url } from '../../types/typeAliases';
3
3
  /**
4
4
  * Options for creating a Remote Agent
5
5
  */
6
- export type RemoteAgentOptions = CommonToolsOptions & {
6
+ export type RemoteAgentOptions = Omit<CommonToolsOptions, 'teacherAgent'> & {
7
7
  /**
8
8
  * Url of the remote agent
9
9
  */
@@ -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-5`).
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/fake-llm",
3
- "version": "0.105.0-6",
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,
@@ -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-6"
99
+ "@promptbook/core": "0.105.0-8"
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-6';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
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
@@ -2777,6 +2777,16 @@
2777
2777
  trimmedText = spaceTrim$1.spaceTrim(trimmedText);
2778
2778
  }
2779
2779
  let processedText = trimmedText;
2780
+ // Check for markdown code block
2781
+ const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
2782
+ const codeBlockMatch = processedText.match(codeBlockRegex);
2783
+ if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
2784
+ // Check if there's only one code block
2785
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
2786
+ if (codeBlockCount === 1) {
2787
+ return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
2788
+ }
2789
+ }
2780
2790
  if (isIntroduceSentenceRemoved) {
2781
2791
  const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2782
2792
  if (introduceSentenceRegex.test(text)) {
@@ -2784,6 +2794,14 @@
2784
2794
  processedText = processedText.replace(introduceSentenceRegex, '');
2785
2795
  }
2786
2796
  processedText = spaceTrim$1.spaceTrim(processedText);
2797
+ // Check again for code block after removing introduce sentence
2798
+ const codeBlockMatch2 = processedText.match(codeBlockRegex);
2799
+ if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
2800
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
2801
+ if (codeBlockCount === 1) {
2802
+ return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
2803
+ }
2804
+ }
2787
2805
  }
2788
2806
  if (processedText.length < 3) {
2789
2807
  return trimmedText;
@@ -6149,6 +6167,46 @@
6149
6167
  * Note: [💞] Ignore a discrepancy between file name and entity name
6150
6168
  */
6151
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
+
6152
6210
  /**
6153
6211
  * USE SEARCH ENGINE commitment definition
6154
6212
  *
@@ -6225,18 +6283,13 @@
6225
6283
  ? existingTools
6226
6284
  : [
6227
6285
  ...existingTools,
6228
- { type: 'web_search' },
6229
- // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
6230
- // In future we will use proper MCP search tool:
6231
- /*
6232
-
6233
6286
  {
6234
6287
  name: 'web_search',
6235
- description: spaceTrim(`
6236
- Search the internet for information.
6237
- Use this tool when you need to find up-to-date information or facts that you don't know.
6238
- ${!content ? '' : `Search scope / instructions: ${content}`}
6239
- `),
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
+ `),
6240
6293
  parameters: {
6241
6294
  type: 'object',
6242
6295
  properties: {
@@ -6248,7 +6301,6 @@
6248
6301
  required: ['query'],
6249
6302
  },
6250
6303
  },
6251
- */
6252
6304
  ];
6253
6305
  // Return requirements with updated tools and metadata
6254
6306
  return {
@@ -6260,6 +6312,33 @@
6260
6312
  },
6261
6313
  };
6262
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
+ }
6263
6342
  }
6264
6343
  /**
6265
6344
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6503,6 +6582,7 @@
6503
6582
  new NoteCommitmentDefinition('NOTES'),
6504
6583
  new NoteCommitmentDefinition('COMMENT'),
6505
6584
  new NoteCommitmentDefinition('NONCE'),
6585
+ new NoteCommitmentDefinition('TODO'),
6506
6586
  new GoalCommitmentDefinition('GOAL'),
6507
6587
  new GoalCommitmentDefinition('GOALS'),
6508
6588
  new InitialMessageCommitmentDefinition(),