@promptbook/browser 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 +154 -35
- 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 +2 -2
- package/umd/index.umd.js +157 -38
- 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
|
@@ -5,8 +5,8 @@ import { randomBytes } from 'crypto';
|
|
|
5
5
|
import { SHA256 } from 'crypto-js';
|
|
6
6
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
7
7
|
import { basename, join, dirname, isAbsolute } from 'path';
|
|
8
|
-
import { lookup, extension } from 'mime-types';
|
|
9
8
|
import moment from 'moment';
|
|
9
|
+
import { lookup, extension } from 'mime-types';
|
|
10
10
|
import { forTime } from 'waitasecond';
|
|
11
11
|
import sha256 from 'crypto-js/sha256';
|
|
12
12
|
import { parse, unparse } from 'papaparse';
|
|
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
29
29
|
* @generated
|
|
30
30
|
* @see https://github.com/webgptorg/promptbook
|
|
31
31
|
*/
|
|
32
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-28';
|
|
33
33
|
/**
|
|
34
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
35
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -10686,6 +10686,147 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
10686
10686
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10687
10687
|
*/
|
|
10688
10688
|
|
|
10689
|
+
/**
|
|
10690
|
+
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
10691
|
+
*
|
|
10692
|
+
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
10693
|
+
*/
|
|
10694
|
+
const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
|
|
10695
|
+
/**
|
|
10696
|
+
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
10697
|
+
*
|
|
10698
|
+
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
10699
|
+
*/
|
|
10700
|
+
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
10701
|
+
/**
|
|
10702
|
+
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
10703
|
+
*
|
|
10704
|
+
* @param type - Commitment type to check.
|
|
10705
|
+
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
10706
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
10707
|
+
*/
|
|
10708
|
+
function isAggregatedUseCommitmentType(type) {
|
|
10709
|
+
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
10710
|
+
}
|
|
10711
|
+
/**
|
|
10712
|
+
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
10713
|
+
*
|
|
10714
|
+
* @param type - Aggregated `USE` commitment type.
|
|
10715
|
+
* @returns Single-line placeholder comment stored in the interim system message.
|
|
10716
|
+
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
10717
|
+
*/
|
|
10718
|
+
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
10719
|
+
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
10720
|
+
}
|
|
10721
|
+
/**
|
|
10722
|
+
* Combines distinct additional instruction blocks in source order.
|
|
10723
|
+
*
|
|
10724
|
+
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
10725
|
+
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
10726
|
+
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
10727
|
+
*/
|
|
10728
|
+
function combineAdditionalInstructions(additionalInstructions) {
|
|
10729
|
+
return additionalInstructions.join('\n');
|
|
10730
|
+
}
|
|
10731
|
+
/**
|
|
10732
|
+
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
10733
|
+
*
|
|
10734
|
+
* @param type - Aggregated `USE` commitment type.
|
|
10735
|
+
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
10736
|
+
* @returns Final system-message block for the commitment type.
|
|
10737
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
10738
|
+
*/
|
|
10739
|
+
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
10740
|
+
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
10741
|
+
switch (type) {
|
|
10742
|
+
case 'USE TIME':
|
|
10743
|
+
return spaceTrim$1((block) => `
|
|
10744
|
+
Time and date context:
|
|
10745
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
10746
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
10747
|
+
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
10748
|
+
`);
|
|
10749
|
+
case 'USE BROWSER':
|
|
10750
|
+
return spaceTrim$1((block) => `
|
|
10751
|
+
You have access to browser tools to fetch and access content from the internet.
|
|
10752
|
+
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
10753
|
+
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
10754
|
+
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
10755
|
+
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
10756
|
+
`);
|
|
10757
|
+
case 'USE SEARCH ENGINE':
|
|
10758
|
+
return spaceTrim$1((block) => `
|
|
10759
|
+
Tool:
|
|
10760
|
+
- You have access to the web search engine via the tool "web_search".
|
|
10761
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
10762
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
10763
|
+
- Do not make up information when you can search for it.
|
|
10764
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
10765
|
+
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
10766
|
+
`);
|
|
10767
|
+
}
|
|
10768
|
+
}
|
|
10769
|
+
/**
|
|
10770
|
+
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
10771
|
+
*
|
|
10772
|
+
* @param requirements - Current model requirements.
|
|
10773
|
+
* @param type - Aggregated `USE` commitment type being applied.
|
|
10774
|
+
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
10775
|
+
* @private internal utility of `USE` commitments
|
|
10776
|
+
*/
|
|
10777
|
+
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
10778
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
10779
|
+
if (requirements.systemMessage.includes(placeholder)) {
|
|
10780
|
+
return requirements;
|
|
10781
|
+
}
|
|
10782
|
+
const systemMessage = requirements.systemMessage.trim()
|
|
10783
|
+
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
10784
|
+
: placeholder;
|
|
10785
|
+
return {
|
|
10786
|
+
...requirements,
|
|
10787
|
+
systemMessage,
|
|
10788
|
+
};
|
|
10789
|
+
}
|
|
10790
|
+
/**
|
|
10791
|
+
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
10792
|
+
*
|
|
10793
|
+
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
10794
|
+
*
|
|
10795
|
+
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
10796
|
+
* @param commitments - Filtered commitments in their original source order.
|
|
10797
|
+
* @returns Requirements with aggregated `USE` system-message sections.
|
|
10798
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
10799
|
+
*/
|
|
10800
|
+
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
10801
|
+
const additionalInstructionsByType = new Map();
|
|
10802
|
+
for (const commitment of commitments) {
|
|
10803
|
+
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
10804
|
+
continue;
|
|
10805
|
+
}
|
|
10806
|
+
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
10807
|
+
if (!additionalInstructions) {
|
|
10808
|
+
additionalInstructions = [];
|
|
10809
|
+
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
10810
|
+
}
|
|
10811
|
+
const normalizedContent = spaceTrim$1(commitment.content);
|
|
10812
|
+
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
10813
|
+
additionalInstructions.push(normalizedContent);
|
|
10814
|
+
}
|
|
10815
|
+
}
|
|
10816
|
+
let systemMessage = requirements.systemMessage;
|
|
10817
|
+
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
10818
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
10819
|
+
if (!systemMessage.includes(placeholder)) {
|
|
10820
|
+
continue;
|
|
10821
|
+
}
|
|
10822
|
+
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
10823
|
+
}
|
|
10824
|
+
return {
|
|
10825
|
+
...requirements,
|
|
10826
|
+
systemMessage,
|
|
10827
|
+
};
|
|
10828
|
+
}
|
|
10829
|
+
|
|
10689
10830
|
/**
|
|
10690
10831
|
* Client-side safe wrapper for fetching URL content
|
|
10691
10832
|
*
|
|
@@ -10736,13 +10877,14 @@ async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
|
10736
10877
|
* 1. One-shot URL fetching: Simple function to fetch and scrape URL content
|
|
10737
10878
|
* 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
|
|
10738
10879
|
*
|
|
10739
|
-
* The content following `USE BROWSER` is
|
|
10880
|
+
* The content following `USE BROWSER` is an arbitrary text that the agent should know
|
|
10881
|
+
* (e.g. browsing scope or preferred sources).
|
|
10740
10882
|
*
|
|
10741
10883
|
* Example usage in agent source:
|
|
10742
10884
|
*
|
|
10743
10885
|
* ```book
|
|
10744
10886
|
* USE BROWSER
|
|
10745
|
-
* USE BROWSER
|
|
10887
|
+
* USE BROWSER Prefer official documentation and source websites.
|
|
10746
10888
|
* ```
|
|
10747
10889
|
*
|
|
10748
10890
|
* @private [🪔] Maybe export the commitments through some package
|
|
@@ -10780,7 +10922,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
10780
10922
|
|
|
10781
10923
|
## Key aspects
|
|
10782
10924
|
|
|
10783
|
-
- The content following \`USE BROWSER\` is
|
|
10925
|
+
- The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
|
|
10784
10926
|
- Provides two levels of browser access:
|
|
10785
10927
|
1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
|
|
10786
10928
|
2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
|
|
@@ -10897,20 +11039,14 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
10897
11039
|
});
|
|
10898
11040
|
}
|
|
10899
11041
|
const updatedTools = [...existingTools, ...toolsToAdd];
|
|
10900
|
-
|
|
10901
|
-
return this.appendToSystemMessage({
|
|
11042
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
10902
11043
|
...requirements,
|
|
10903
11044
|
tools: updatedTools,
|
|
10904
11045
|
_metadata: {
|
|
10905
11046
|
...requirements._metadata,
|
|
10906
11047
|
useBrowser: true,
|
|
10907
11048
|
},
|
|
10908
|
-
},
|
|
10909
|
-
You have access to browser tools to fetch and access content from the internet.
|
|
10910
|
-
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
10911
|
-
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
10912
|
-
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
10913
|
-
`));
|
|
11049
|
+
}, this.type);
|
|
10914
11050
|
}
|
|
10915
11051
|
/**
|
|
10916
11052
|
* Gets the browser tool function implementations.
|
|
@@ -14716,7 +14852,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14716
14852
|
`);
|
|
14717
14853
|
}
|
|
14718
14854
|
applyToAgentModelRequirements(requirements, content) {
|
|
14719
|
-
const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
|
|
14720
14855
|
// Get existing tools array or create new one
|
|
14721
14856
|
const existingTools = requirements.tools || [];
|
|
14722
14857
|
// Add 'web_search' to tools if not already present
|
|
@@ -14729,7 +14864,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14729
14864
|
description: spaceTrim$1(`
|
|
14730
14865
|
Search the internet for information.
|
|
14731
14866
|
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
14732
|
-
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
14733
14867
|
`),
|
|
14734
14868
|
parameters: {
|
|
14735
14869
|
type: 'object',
|
|
@@ -14767,23 +14901,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
14767
14901
|
},
|
|
14768
14902
|
},
|
|
14769
14903
|
];
|
|
14770
|
-
|
|
14771
|
-
return this.appendToSystemMessage({
|
|
14904
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
14772
14905
|
...requirements,
|
|
14773
14906
|
tools: updatedTools,
|
|
14774
14907
|
_metadata: {
|
|
14775
14908
|
...requirements._metadata,
|
|
14776
14909
|
useSearchEngine: content || true,
|
|
14777
14910
|
},
|
|
14778
|
-
},
|
|
14779
|
-
Tool:
|
|
14780
|
-
- You have access to the web search engine via the tool "web_search".
|
|
14781
|
-
- Use it to find up-to-date information or facts that you don't know.
|
|
14782
|
-
- When you need to know some information from the internet, use the tool provided to you.
|
|
14783
|
-
- Do not make up information when you can search for it.
|
|
14784
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
14785
|
-
${block(extraInstructions)}
|
|
14786
|
-
`));
|
|
14911
|
+
}, this.type);
|
|
14787
14912
|
}
|
|
14788
14913
|
/**
|
|
14789
14914
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -15894,7 +16019,6 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15894
16019
|
`);
|
|
15895
16020
|
}
|
|
15896
16021
|
applyToAgentModelRequirements(requirements, content) {
|
|
15897
|
-
const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
|
|
15898
16022
|
// Get existing tools array or create new one
|
|
15899
16023
|
const existingTools = requirements.tools || [];
|
|
15900
16024
|
// Add 'get_current_time' to tools if not already present
|
|
@@ -15918,19 +16042,13 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15918
16042
|
},
|
|
15919
16043
|
// <- TODO: !!!! define the function in LLM tools
|
|
15920
16044
|
];
|
|
15921
|
-
|
|
15922
|
-
return this.appendToSystemMessage({
|
|
16045
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
15923
16046
|
...requirements,
|
|
15924
16047
|
tools: updatedTools,
|
|
15925
16048
|
_metadata: {
|
|
15926
16049
|
...requirements._metadata,
|
|
15927
16050
|
},
|
|
15928
|
-
},
|
|
15929
|
-
Time and date context:
|
|
15930
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
15931
|
-
- If you need more precise current time information, use the tool "get_current_time".
|
|
15932
|
-
${block(extraInstructions)}
|
|
15933
|
-
`));
|
|
16051
|
+
}, this.type);
|
|
15934
16052
|
}
|
|
15935
16053
|
/**
|
|
15936
16054
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -22612,6 +22730,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
22612
22730
|
}
|
|
22613
22731
|
}
|
|
22614
22732
|
}
|
|
22733
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
22615
22734
|
// Handle IMPORT commitments for generic files
|
|
22616
22735
|
// Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
|
|
22617
22736
|
if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {
|