@promptbook/components 0.112.0-25 → 0.112.0-27
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 +1 -1
- 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 { SHA256 } from 'crypto-js';
|
|
|
5
5
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
6
6
|
import { basename, join, dirname, isAbsolute } from 'path';
|
|
7
7
|
import { randomBytes } from 'crypto';
|
|
8
|
-
import { lookup, extension } from 'mime-types';
|
|
9
8
|
import moment from 'moment';
|
|
9
|
+
import { lookup, extension } from 'mime-types';
|
|
10
10
|
import { createPortal } from 'react-dom';
|
|
11
11
|
import MonacoEditor, { useMonaco } from '@monaco-editor/react';
|
|
12
12
|
import { Registration } from 'destroyable';
|
|
@@ -39,7 +39,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
39
39
|
* @generated
|
|
40
40
|
* @see https://github.com/webgptorg/promptbook
|
|
41
41
|
*/
|
|
42
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
42
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-27';
|
|
43
43
|
/**
|
|
44
44
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
45
45
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -11364,6 +11364,147 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11364
11364
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11365
11365
|
*/
|
|
11366
11366
|
|
|
11367
|
+
/**
|
|
11368
|
+
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
11369
|
+
*
|
|
11370
|
+
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
11371
|
+
*/
|
|
11372
|
+
const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
|
|
11373
|
+
/**
|
|
11374
|
+
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
11375
|
+
*
|
|
11376
|
+
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
11377
|
+
*/
|
|
11378
|
+
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
11379
|
+
/**
|
|
11380
|
+
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
11381
|
+
*
|
|
11382
|
+
* @param type - Commitment type to check.
|
|
11383
|
+
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
11384
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
11385
|
+
*/
|
|
11386
|
+
function isAggregatedUseCommitmentType(type) {
|
|
11387
|
+
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
11388
|
+
}
|
|
11389
|
+
/**
|
|
11390
|
+
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
11391
|
+
*
|
|
11392
|
+
* @param type - Aggregated `USE` commitment type.
|
|
11393
|
+
* @returns Single-line placeholder comment stored in the interim system message.
|
|
11394
|
+
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
11395
|
+
*/
|
|
11396
|
+
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
11397
|
+
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
11398
|
+
}
|
|
11399
|
+
/**
|
|
11400
|
+
* Combines distinct additional instruction blocks in source order.
|
|
11401
|
+
*
|
|
11402
|
+
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
11403
|
+
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
11404
|
+
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
11405
|
+
*/
|
|
11406
|
+
function combineAdditionalInstructions(additionalInstructions) {
|
|
11407
|
+
return additionalInstructions.join('\n');
|
|
11408
|
+
}
|
|
11409
|
+
/**
|
|
11410
|
+
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
11411
|
+
*
|
|
11412
|
+
* @param type - Aggregated `USE` commitment type.
|
|
11413
|
+
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
11414
|
+
* @returns Final system-message block for the commitment type.
|
|
11415
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
11416
|
+
*/
|
|
11417
|
+
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
11418
|
+
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
11419
|
+
switch (type) {
|
|
11420
|
+
case 'USE TIME':
|
|
11421
|
+
return spaceTrim$1((block) => `
|
|
11422
|
+
Time and date context:
|
|
11423
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
11424
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
11425
|
+
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
11426
|
+
`);
|
|
11427
|
+
case 'USE BROWSER':
|
|
11428
|
+
return spaceTrim$1((block) => `
|
|
11429
|
+
You have access to browser tools to fetch and access content from the internet.
|
|
11430
|
+
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
11431
|
+
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
11432
|
+
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
11433
|
+
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
11434
|
+
`);
|
|
11435
|
+
case 'USE SEARCH ENGINE':
|
|
11436
|
+
return spaceTrim$1((block) => `
|
|
11437
|
+
Tool:
|
|
11438
|
+
- You have access to the web search engine via the tool "web_search".
|
|
11439
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
11440
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
11441
|
+
- Do not make up information when you can search for it.
|
|
11442
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
11443
|
+
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
11444
|
+
`);
|
|
11445
|
+
}
|
|
11446
|
+
}
|
|
11447
|
+
/**
|
|
11448
|
+
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
11449
|
+
*
|
|
11450
|
+
* @param requirements - Current model requirements.
|
|
11451
|
+
* @param type - Aggregated `USE` commitment type being applied.
|
|
11452
|
+
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
11453
|
+
* @private internal utility of `USE` commitments
|
|
11454
|
+
*/
|
|
11455
|
+
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
11456
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
11457
|
+
if (requirements.systemMessage.includes(placeholder)) {
|
|
11458
|
+
return requirements;
|
|
11459
|
+
}
|
|
11460
|
+
const systemMessage = requirements.systemMessage.trim()
|
|
11461
|
+
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
11462
|
+
: placeholder;
|
|
11463
|
+
return {
|
|
11464
|
+
...requirements,
|
|
11465
|
+
systemMessage,
|
|
11466
|
+
};
|
|
11467
|
+
}
|
|
11468
|
+
/**
|
|
11469
|
+
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
11470
|
+
*
|
|
11471
|
+
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
11472
|
+
*
|
|
11473
|
+
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
11474
|
+
* @param commitments - Filtered commitments in their original source order.
|
|
11475
|
+
* @returns Requirements with aggregated `USE` system-message sections.
|
|
11476
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
11477
|
+
*/
|
|
11478
|
+
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
11479
|
+
const additionalInstructionsByType = new Map();
|
|
11480
|
+
for (const commitment of commitments) {
|
|
11481
|
+
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
11482
|
+
continue;
|
|
11483
|
+
}
|
|
11484
|
+
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
11485
|
+
if (!additionalInstructions) {
|
|
11486
|
+
additionalInstructions = [];
|
|
11487
|
+
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
11488
|
+
}
|
|
11489
|
+
const normalizedContent = spaceTrim$1(commitment.content);
|
|
11490
|
+
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
11491
|
+
additionalInstructions.push(normalizedContent);
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
11494
|
+
let systemMessage = requirements.systemMessage;
|
|
11495
|
+
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
11496
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
11497
|
+
if (!systemMessage.includes(placeholder)) {
|
|
11498
|
+
continue;
|
|
11499
|
+
}
|
|
11500
|
+
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
11501
|
+
}
|
|
11502
|
+
return {
|
|
11503
|
+
...requirements,
|
|
11504
|
+
systemMessage,
|
|
11505
|
+
};
|
|
11506
|
+
}
|
|
11507
|
+
|
|
11367
11508
|
/**
|
|
11368
11509
|
* Client-side safe wrapper for fetching URL content
|
|
11369
11510
|
*
|
|
@@ -11414,13 +11555,14 @@ async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
|
11414
11555
|
* 1. One-shot URL fetching: Simple function to fetch and scrape URL content
|
|
11415
11556
|
* 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
|
|
11416
11557
|
*
|
|
11417
|
-
* The content following `USE BROWSER` is
|
|
11558
|
+
* The content following `USE BROWSER` is an arbitrary text that the agent should know
|
|
11559
|
+
* (e.g. browsing scope or preferred sources).
|
|
11418
11560
|
*
|
|
11419
11561
|
* Example usage in agent source:
|
|
11420
11562
|
*
|
|
11421
11563
|
* ```book
|
|
11422
11564
|
* USE BROWSER
|
|
11423
|
-
* USE BROWSER
|
|
11565
|
+
* USE BROWSER Prefer official documentation and source websites.
|
|
11424
11566
|
* ```
|
|
11425
11567
|
*
|
|
11426
11568
|
* @private [🪔] Maybe export the commitments through some package
|
|
@@ -11458,7 +11600,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11458
11600
|
|
|
11459
11601
|
## Key aspects
|
|
11460
11602
|
|
|
11461
|
-
- The content following \`USE BROWSER\` is
|
|
11603
|
+
- The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
|
|
11462
11604
|
- Provides two levels of browser access:
|
|
11463
11605
|
1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
|
|
11464
11606
|
2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
|
|
@@ -11575,20 +11717,14 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11575
11717
|
});
|
|
11576
11718
|
}
|
|
11577
11719
|
const updatedTools = [...existingTools, ...toolsToAdd];
|
|
11578
|
-
|
|
11579
|
-
return this.appendToSystemMessage({
|
|
11720
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
11580
11721
|
...requirements,
|
|
11581
11722
|
tools: updatedTools,
|
|
11582
11723
|
_metadata: {
|
|
11583
11724
|
...requirements._metadata,
|
|
11584
11725
|
useBrowser: true,
|
|
11585
11726
|
},
|
|
11586
|
-
},
|
|
11587
|
-
You have access to browser tools to fetch and access content from the internet.
|
|
11588
|
-
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
11589
|
-
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
11590
|
-
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
11591
|
-
`));
|
|
11727
|
+
}, this.type);
|
|
11592
11728
|
}
|
|
11593
11729
|
/**
|
|
11594
11730
|
* Gets the browser tool function implementations.
|
|
@@ -15217,7 +15353,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15217
15353
|
`);
|
|
15218
15354
|
}
|
|
15219
15355
|
applyToAgentModelRequirements(requirements, content) {
|
|
15220
|
-
const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
|
|
15221
15356
|
// Get existing tools array or create new one
|
|
15222
15357
|
const existingTools = requirements.tools || [];
|
|
15223
15358
|
// Add 'web_search' to tools if not already present
|
|
@@ -15230,7 +15365,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15230
15365
|
description: spaceTrim$1(`
|
|
15231
15366
|
Search the internet for information.
|
|
15232
15367
|
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
15233
|
-
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
15234
15368
|
`),
|
|
15235
15369
|
parameters: {
|
|
15236
15370
|
type: 'object',
|
|
@@ -15268,23 +15402,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
15268
15402
|
},
|
|
15269
15403
|
},
|
|
15270
15404
|
];
|
|
15271
|
-
|
|
15272
|
-
return this.appendToSystemMessage({
|
|
15405
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
15273
15406
|
...requirements,
|
|
15274
15407
|
tools: updatedTools,
|
|
15275
15408
|
_metadata: {
|
|
15276
15409
|
...requirements._metadata,
|
|
15277
15410
|
useSearchEngine: content || true,
|
|
15278
15411
|
},
|
|
15279
|
-
},
|
|
15280
|
-
Tool:
|
|
15281
|
-
- You have access to the web search engine via the tool "web_search".
|
|
15282
|
-
- Use it to find up-to-date information or facts that you don't know.
|
|
15283
|
-
- When you need to know some information from the internet, use the tool provided to you.
|
|
15284
|
-
- Do not make up information when you can search for it.
|
|
15285
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
15286
|
-
${block(extraInstructions)}
|
|
15287
|
-
`));
|
|
15412
|
+
}, this.type);
|
|
15288
15413
|
}
|
|
15289
15414
|
/**
|
|
15290
15415
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -16395,7 +16520,6 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16395
16520
|
`);
|
|
16396
16521
|
}
|
|
16397
16522
|
applyToAgentModelRequirements(requirements, content) {
|
|
16398
|
-
const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
|
|
16399
16523
|
// Get existing tools array or create new one
|
|
16400
16524
|
const existingTools = requirements.tools || [];
|
|
16401
16525
|
// Add 'get_current_time' to tools if not already present
|
|
@@ -16419,19 +16543,13 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
16419
16543
|
},
|
|
16420
16544
|
// <- TODO: !!!! define the function in LLM tools
|
|
16421
16545
|
];
|
|
16422
|
-
|
|
16423
|
-
return this.appendToSystemMessage({
|
|
16546
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
16424
16547
|
...requirements,
|
|
16425
16548
|
tools: updatedTools,
|
|
16426
16549
|
_metadata: {
|
|
16427
16550
|
...requirements._metadata,
|
|
16428
16551
|
},
|
|
16429
|
-
},
|
|
16430
|
-
Time and date context:
|
|
16431
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
16432
|
-
- If you need more precise current time information, use the tool "get_current_time".
|
|
16433
|
-
${block(extraInstructions)}
|
|
16434
|
-
`));
|
|
16552
|
+
}, this.type);
|
|
16435
16553
|
}
|
|
16436
16554
|
/**
|
|
16437
16555
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -28852,6 +28970,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
28852
28970
|
}
|
|
28853
28971
|
}
|
|
28854
28972
|
}
|
|
28973
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
28855
28974
|
// Handle IMPORT commitments for generic files
|
|
28856
28975
|
// Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
|
|
28857
28976
|
if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {
|