@promptbook/node 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 +92 -12
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/commitments/NOTE/NOTE.d.ts +2 -2
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +6 -0
- package/esm/typings/src/commitments/index.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +1 -0
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +7 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +92 -12
- package/umd/index.umd.js.map +1 -1
|
@@ -26,8 +26,8 @@ import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
|
|
|
26
26
|
*
|
|
27
27
|
* @private [🪔] Maybe export the commitments through some package
|
|
28
28
|
*/
|
|
29
|
-
export declare class NoteCommitmentDefinition extends BaseCommitmentDefinition<'NOTE' | 'NOTES' | 'COMMENT' | 'NONCE'> {
|
|
30
|
-
constructor(type?: 'NOTE' | 'NOTES' | 'COMMENT' | 'NONCE');
|
|
29
|
+
export declare class NoteCommitmentDefinition extends BaseCommitmentDefinition<'NOTE' | 'NOTES' | 'COMMENT' | 'NONCE' | 'TODO'> {
|
|
30
|
+
constructor(type?: 'NOTE' | 'NOTES' | 'COMMENT' | 'NONCE' | 'TODO');
|
|
31
31
|
/**
|
|
32
32
|
* Short one-line description of NOTE.
|
|
33
33
|
*/
|
|
@@ -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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
|
@@ -11847,6 +11847,16 @@
|
|
|
11847
11847
|
trimmedText = spaceTrim$1.spaceTrim(trimmedText);
|
|
11848
11848
|
}
|
|
11849
11849
|
let processedText = trimmedText;
|
|
11850
|
+
// Check for markdown code block
|
|
11851
|
+
const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
|
|
11852
|
+
const codeBlockMatch = processedText.match(codeBlockRegex);
|
|
11853
|
+
if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
|
|
11854
|
+
// Check if there's only one code block
|
|
11855
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
11856
|
+
if (codeBlockCount === 1) {
|
|
11857
|
+
return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
11858
|
+
}
|
|
11859
|
+
}
|
|
11850
11860
|
if (isIntroduceSentenceRemoved) {
|
|
11851
11861
|
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
11852
11862
|
if (introduceSentenceRegex.test(text)) {
|
|
@@ -11854,6 +11864,14 @@
|
|
|
11854
11864
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
11855
11865
|
}
|
|
11856
11866
|
processedText = spaceTrim$1.spaceTrim(processedText);
|
|
11867
|
+
// Check again for code block after removing introduce sentence
|
|
11868
|
+
const codeBlockMatch2 = processedText.match(codeBlockRegex);
|
|
11869
|
+
if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
|
|
11870
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
11871
|
+
if (codeBlockCount === 1) {
|
|
11872
|
+
return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
11873
|
+
}
|
|
11874
|
+
}
|
|
11857
11875
|
}
|
|
11858
11876
|
if (processedText.length < 3) {
|
|
11859
11877
|
return trimmedText;
|
|
@@ -15253,6 +15271,46 @@
|
|
|
15253
15271
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15254
15272
|
*/
|
|
15255
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
|
+
|
|
15256
15314
|
/**
|
|
15257
15315
|
* USE SEARCH ENGINE commitment definition
|
|
15258
15316
|
*
|
|
@@ -15329,18 +15387,13 @@
|
|
|
15329
15387
|
? existingTools
|
|
15330
15388
|
: [
|
|
15331
15389
|
...existingTools,
|
|
15332
|
-
{ type: 'web_search' },
|
|
15333
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
15334
|
-
// In future we will use proper MCP search tool:
|
|
15335
|
-
/*
|
|
15336
|
-
|
|
15337
15390
|
{
|
|
15338
15391
|
name: 'web_search',
|
|
15339
|
-
description: spaceTrim(`
|
|
15340
|
-
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
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
|
+
`),
|
|
15344
15397
|
parameters: {
|
|
15345
15398
|
type: 'object',
|
|
15346
15399
|
properties: {
|
|
@@ -15352,7 +15405,6 @@
|
|
|
15352
15405
|
required: ['query'],
|
|
15353
15406
|
},
|
|
15354
15407
|
},
|
|
15355
|
-
*/
|
|
15356
15408
|
];
|
|
15357
15409
|
// Return requirements with updated tools and metadata
|
|
15358
15410
|
return {
|
|
@@ -15364,6 +15416,33 @@
|
|
|
15364
15416
|
},
|
|
15365
15417
|
};
|
|
15366
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
|
+
}
|
|
15367
15446
|
}
|
|
15368
15447
|
/**
|
|
15369
15448
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15607,6 +15686,7 @@
|
|
|
15607
15686
|
new NoteCommitmentDefinition('NOTES'),
|
|
15608
15687
|
new NoteCommitmentDefinition('COMMENT'),
|
|
15609
15688
|
new NoteCommitmentDefinition('NONCE'),
|
|
15689
|
+
new NoteCommitmentDefinition('TODO'),
|
|
15610
15690
|
new GoalCommitmentDefinition('GOAL'),
|
|
15611
15691
|
new GoalCommitmentDefinition('GOALS'),
|
|
15612
15692
|
new InitialMessageCommitmentDefinition(),
|