@promptbook/core 0.112.0-26 → 0.112.0-28
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 +153 -34
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-2.0/agent-source/createAgentModelRequirements.useCommitmentAggregation.test.d.ts +1 -0
- package/esm/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +0 -47
- package/esm/src/commitments/USE/aggregateUseCommitmentSystemMessages.d.ts +30 -0
- package/esm/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +3 -2
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +153 -34
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-2.0/agent-source/createAgentModelRequirements.useCommitmentAggregation.test.d.ts +1 -0
- package/umd/src/book-components/_common/MenuHoisting/MenuHoistingContext.d.ts +0 -47
- package/umd/src/commitments/USE/aggregateUseCommitmentSystemMessages.d.ts +30 -0
- package/umd/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +3 -2
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-28';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -15459,6 +15459,147 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15459
15459
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
15460
15460
|
*/
|
|
15461
15461
|
|
|
15462
|
+
/**
|
|
15463
|
+
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
15464
|
+
*
|
|
15465
|
+
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
15466
|
+
*/
|
|
15467
|
+
const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
|
|
15468
|
+
/**
|
|
15469
|
+
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
15470
|
+
*
|
|
15471
|
+
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
15472
|
+
*/
|
|
15473
|
+
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
15474
|
+
/**
|
|
15475
|
+
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
15476
|
+
*
|
|
15477
|
+
* @param type - Commitment type to check.
|
|
15478
|
+
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
15479
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
15480
|
+
*/
|
|
15481
|
+
function isAggregatedUseCommitmentType(type) {
|
|
15482
|
+
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
15483
|
+
}
|
|
15484
|
+
/**
|
|
15485
|
+
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
15486
|
+
*
|
|
15487
|
+
* @param type - Aggregated `USE` commitment type.
|
|
15488
|
+
* @returns Single-line placeholder comment stored in the interim system message.
|
|
15489
|
+
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
15490
|
+
*/
|
|
15491
|
+
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
15492
|
+
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
15493
|
+
}
|
|
15494
|
+
/**
|
|
15495
|
+
* Combines distinct additional instruction blocks in source order.
|
|
15496
|
+
*
|
|
15497
|
+
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
15498
|
+
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
15499
|
+
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
15500
|
+
*/
|
|
15501
|
+
function combineAdditionalInstructions(additionalInstructions) {
|
|
15502
|
+
return additionalInstructions.join('\n');
|
|
15503
|
+
}
|
|
15504
|
+
/**
|
|
15505
|
+
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
15506
|
+
*
|
|
15507
|
+
* @param type - Aggregated `USE` commitment type.
|
|
15508
|
+
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
15509
|
+
* @returns Final system-message block for the commitment type.
|
|
15510
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
15511
|
+
*/
|
|
15512
|
+
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
15513
|
+
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
15514
|
+
switch (type) {
|
|
15515
|
+
case 'USE TIME':
|
|
15516
|
+
return spaceTrim$1((block) => `
|
|
15517
|
+
Time and date context:
|
|
15518
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
15519
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
15520
|
+
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
15521
|
+
`);
|
|
15522
|
+
case 'USE BROWSER':
|
|
15523
|
+
return spaceTrim$1((block) => `
|
|
15524
|
+
You have access to browser tools to fetch and access content from the internet.
|
|
15525
|
+
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
15526
|
+
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
15527
|
+
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
15528
|
+
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
15529
|
+
`);
|
|
15530
|
+
case 'USE SEARCH ENGINE':
|
|
15531
|
+
return spaceTrim$1((block) => `
|
|
15532
|
+
Tool:
|
|
15533
|
+
- You have access to the web search engine via the tool "web_search".
|
|
15534
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
15535
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
15536
|
+
- Do not make up information when you can search for it.
|
|
15537
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
15538
|
+
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
15539
|
+
`);
|
|
15540
|
+
}
|
|
15541
|
+
}
|
|
15542
|
+
/**
|
|
15543
|
+
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
15544
|
+
*
|
|
15545
|
+
* @param requirements - Current model requirements.
|
|
15546
|
+
* @param type - Aggregated `USE` commitment type being applied.
|
|
15547
|
+
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
15548
|
+
* @private internal utility of `USE` commitments
|
|
15549
|
+
*/
|
|
15550
|
+
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
15551
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
15552
|
+
if (requirements.systemMessage.includes(placeholder)) {
|
|
15553
|
+
return requirements;
|
|
15554
|
+
}
|
|
15555
|
+
const systemMessage = requirements.systemMessage.trim()
|
|
15556
|
+
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
15557
|
+
: placeholder;
|
|
15558
|
+
return {
|
|
15559
|
+
...requirements,
|
|
15560
|
+
systemMessage,
|
|
15561
|
+
};
|
|
15562
|
+
}
|
|
15563
|
+
/**
|
|
15564
|
+
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
15565
|
+
*
|
|
15566
|
+
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
15567
|
+
*
|
|
15568
|
+
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
15569
|
+
* @param commitments - Filtered commitments in their original source order.
|
|
15570
|
+
* @returns Requirements with aggregated `USE` system-message sections.
|
|
15571
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
15572
|
+
*/
|
|
15573
|
+
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
15574
|
+
const additionalInstructionsByType = new Map();
|
|
15575
|
+
for (const commitment of commitments) {
|
|
15576
|
+
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
15577
|
+
continue;
|
|
15578
|
+
}
|
|
15579
|
+
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
15580
|
+
if (!additionalInstructions) {
|
|
15581
|
+
additionalInstructions = [];
|
|
15582
|
+
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
15583
|
+
}
|
|
15584
|
+
const normalizedContent = spaceTrim$1(commitment.content);
|
|
15585
|
+
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
15586
|
+
additionalInstructions.push(normalizedContent);
|
|
15587
|
+
}
|
|
15588
|
+
}
|
|
15589
|
+
let systemMessage = requirements.systemMessage;
|
|
15590
|
+
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
15591
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
15592
|
+
if (!systemMessage.includes(placeholder)) {
|
|
15593
|
+
continue;
|
|
15594
|
+
}
|
|
15595
|
+
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
15596
|
+
}
|
|
15597
|
+
return {
|
|
15598
|
+
...requirements,
|
|
15599
|
+
systemMessage,
|
|
15600
|
+
};
|
|
15601
|
+
}
|
|
15602
|
+
|
|
15462
15603
|
/**
|
|
15463
15604
|
* Client-side safe wrapper for fetching URL content
|
|
15464
15605
|
*
|
|
@@ -15509,13 +15650,14 @@ async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
|
15509
15650
|
* 1. One-shot URL fetching: Simple function to fetch and scrape URL content
|
|
15510
15651
|
* 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
|
|
15511
15652
|
*
|
|
15512
|
-
* The content following `USE BROWSER` is
|
|
15653
|
+
* The content following `USE BROWSER` is an arbitrary text that the agent should know
|
|
15654
|
+
* (e.g. browsing scope or preferred sources).
|
|
15513
15655
|
*
|
|
15514
15656
|
* Example usage in agent source:
|
|
15515
15657
|
*
|
|
15516
15658
|
* ```book
|
|
15517
15659
|
* USE BROWSER
|
|
15518
|
-
* USE BROWSER
|
|
15660
|
+
* USE BROWSER Prefer official documentation and source websites.
|
|
15519
15661
|
* ```
|
|
15520
15662
|
*
|
|
15521
15663
|
* @private [🪔] Maybe export the commitments through some package
|
|
@@ -15553,7 +15695,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15553
15695
|
|
|
15554
15696
|
## Key aspects
|
|
15555
15697
|
|
|
15556
|
-
- The content following \`USE BROWSER\` is
|
|
15698
|
+
- The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
|
|
15557
15699
|
- Provides two levels of browser access:
|
|
15558
15700
|
1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
|
|
15559
15701
|
2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
|
|
@@ -15670,20 +15812,14 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15670
15812
|
});
|
|
15671
15813
|
}
|
|
15672
15814
|
const updatedTools = [...existingTools, ...toolsToAdd];
|
|
15673
|
-
|
|
15674
|
-
return this.appendToSystemMessage({
|
|
15815
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
15675
15816
|
...requirements,
|
|
15676
15817
|
tools: updatedTools,
|
|
15677
15818
|
_metadata: {
|
|
15678
15819
|
...requirements._metadata,
|
|
15679
15820
|
useBrowser: true,
|
|
15680
15821
|
},
|
|
15681
|
-
},
|
|
15682
|
-
You have access to browser tools to fetch and access content from the internet.
|
|
15683
|
-
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
15684
|
-
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
15685
|
-
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
15686
|
-
`));
|
|
15822
|
+
}, this.type);
|
|
15687
15823
|
}
|
|
15688
15824
|
/**
|
|
15689
15825
|
* Gets the browser tool function implementations.
|
|
@@ -19470,7 +19606,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19470
19606
|
`);
|
|
19471
19607
|
}
|
|
19472
19608
|
applyToAgentModelRequirements(requirements, content) {
|
|
19473
|
-
const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
|
|
19474
19609
|
// Get existing tools array or create new one
|
|
19475
19610
|
const existingTools = requirements.tools || [];
|
|
19476
19611
|
// Add 'web_search' to tools if not already present
|
|
@@ -19483,7 +19618,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19483
19618
|
description: spaceTrim$1(`
|
|
19484
19619
|
Search the internet for information.
|
|
19485
19620
|
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
19486
|
-
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
19487
19621
|
`),
|
|
19488
19622
|
parameters: {
|
|
19489
19623
|
type: 'object',
|
|
@@ -19521,23 +19655,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
19521
19655
|
},
|
|
19522
19656
|
},
|
|
19523
19657
|
];
|
|
19524
|
-
|
|
19525
|
-
return this.appendToSystemMessage({
|
|
19658
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
19526
19659
|
...requirements,
|
|
19527
19660
|
tools: updatedTools,
|
|
19528
19661
|
_metadata: {
|
|
19529
19662
|
...requirements._metadata,
|
|
19530
19663
|
useSearchEngine: content || true,
|
|
19531
19664
|
},
|
|
19532
|
-
},
|
|
19533
|
-
Tool:
|
|
19534
|
-
- You have access to the web search engine via the tool "web_search".
|
|
19535
|
-
- Use it to find up-to-date information or facts that you don't know.
|
|
19536
|
-
- When you need to know some information from the internet, use the tool provided to you.
|
|
19537
|
-
- Do not make up information when you can search for it.
|
|
19538
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
19539
|
-
${block(extraInstructions)}
|
|
19540
|
-
`));
|
|
19665
|
+
}, this.type);
|
|
19541
19666
|
}
|
|
19542
19667
|
/**
|
|
19543
19668
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -20648,7 +20773,6 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20648
20773
|
`);
|
|
20649
20774
|
}
|
|
20650
20775
|
applyToAgentModelRequirements(requirements, content) {
|
|
20651
|
-
const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
|
|
20652
20776
|
// Get existing tools array or create new one
|
|
20653
20777
|
const existingTools = requirements.tools || [];
|
|
20654
20778
|
// Add 'get_current_time' to tools if not already present
|
|
@@ -20672,19 +20796,13 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
20672
20796
|
},
|
|
20673
20797
|
// <- TODO: !!!! define the function in LLM tools
|
|
20674
20798
|
];
|
|
20675
|
-
|
|
20676
|
-
return this.appendToSystemMessage({
|
|
20799
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
20677
20800
|
...requirements,
|
|
20678
20801
|
tools: updatedTools,
|
|
20679
20802
|
_metadata: {
|
|
20680
20803
|
...requirements._metadata,
|
|
20681
20804
|
},
|
|
20682
|
-
},
|
|
20683
|
-
Time and date context:
|
|
20684
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
20685
|
-
- If you need more precise current time information, use the tool "get_current_time".
|
|
20686
|
-
${block(extraInstructions)}
|
|
20687
|
-
`));
|
|
20805
|
+
}, this.type);
|
|
20688
20806
|
}
|
|
20689
20807
|
/**
|
|
20690
20808
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -21739,6 +21857,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
21739
21857
|
}
|
|
21740
21858
|
}
|
|
21741
21859
|
}
|
|
21860
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
21742
21861
|
// Handle IMPORT commitments for generic files
|
|
21743
21862
|
// Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
|
|
21744
21863
|
if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {
|