@promptbook/wizard 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 +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
|
@@ -18,8 +18,8 @@ import * as dotenv from 'dotenv';
|
|
|
18
18
|
import sha256 from 'crypto-js/sha256';
|
|
19
19
|
import JSZip from 'jszip';
|
|
20
20
|
import { Subject, BehaviorSubject } from 'rxjs';
|
|
21
|
-
import { lookup, extension } from 'mime-types';
|
|
22
21
|
import moment from 'moment';
|
|
22
|
+
import { lookup, extension } from 'mime-types';
|
|
23
23
|
import { parse, unparse } from 'papaparse';
|
|
24
24
|
import { Agent as Agent$1, setDefaultOpenAIClient, setDefaultOpenAIKey, fileSearchTool, tool, run } from '@openai/agents';
|
|
25
25
|
import OpenAI from 'openai';
|
|
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
38
38
|
* @generated
|
|
39
39
|
* @see https://github.com/webgptorg/promptbook
|
|
40
40
|
*/
|
|
41
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
41
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-27';
|
|
42
42
|
/**
|
|
43
43
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
44
44
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -23138,6 +23138,147 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
23138
23138
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
23139
23139
|
*/
|
|
23140
23140
|
|
|
23141
|
+
/**
|
|
23142
|
+
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
23143
|
+
*
|
|
23144
|
+
* @private internal constant for `aggregateUseCommitmentSystemMessages`
|
|
23145
|
+
*/
|
|
23146
|
+
const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
|
|
23147
|
+
/**
|
|
23148
|
+
* Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
|
|
23149
|
+
*
|
|
23150
|
+
* @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
|
|
23151
|
+
*/
|
|
23152
|
+
const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
|
|
23153
|
+
/**
|
|
23154
|
+
* Type guard for `USE` commitment types that are aggregated in the final system message.
|
|
23155
|
+
*
|
|
23156
|
+
* @param type - Commitment type to check.
|
|
23157
|
+
* @returns `true` when the commitment participates in `USE` system-message aggregation.
|
|
23158
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
23159
|
+
*/
|
|
23160
|
+
function isAggregatedUseCommitmentType(type) {
|
|
23161
|
+
return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
|
|
23162
|
+
}
|
|
23163
|
+
/**
|
|
23164
|
+
* Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
|
|
23165
|
+
*
|
|
23166
|
+
* @param type - Aggregated `USE` commitment type.
|
|
23167
|
+
* @returns Single-line placeholder comment stored in the interim system message.
|
|
23168
|
+
* @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
|
|
23169
|
+
*/
|
|
23170
|
+
function getAggregatedUseCommitmentPlaceholder(type) {
|
|
23171
|
+
return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
|
|
23172
|
+
}
|
|
23173
|
+
/**
|
|
23174
|
+
* Combines distinct additional instruction blocks in source order.
|
|
23175
|
+
*
|
|
23176
|
+
* @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
|
|
23177
|
+
* @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
|
|
23178
|
+
* @private internal utility of `createAggregatedUseCommitmentSystemMessage`
|
|
23179
|
+
*/
|
|
23180
|
+
function combineAdditionalInstructions(additionalInstructions) {
|
|
23181
|
+
return additionalInstructions.join('\n');
|
|
23182
|
+
}
|
|
23183
|
+
/**
|
|
23184
|
+
* Creates the final aggregated system-message section for a supported `USE` commitment type.
|
|
23185
|
+
*
|
|
23186
|
+
* @param type - Aggregated `USE` commitment type.
|
|
23187
|
+
* @param additionalInstructions - Distinct additional instructions in source order.
|
|
23188
|
+
* @returns Final system-message block for the commitment type.
|
|
23189
|
+
* @private internal utility of `aggregateUseCommitmentSystemMessages`
|
|
23190
|
+
*/
|
|
23191
|
+
function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
|
|
23192
|
+
const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
|
|
23193
|
+
switch (type) {
|
|
23194
|
+
case 'USE TIME':
|
|
23195
|
+
return spaceTrim$1((block) => `
|
|
23196
|
+
Time and date context:
|
|
23197
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
23198
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
23199
|
+
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
23200
|
+
`);
|
|
23201
|
+
case 'USE BROWSER':
|
|
23202
|
+
return spaceTrim$1((block) => `
|
|
23203
|
+
You have access to browser tools to fetch and access content from the internet.
|
|
23204
|
+
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
23205
|
+
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
23206
|
+
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
23207
|
+
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
23208
|
+
`);
|
|
23209
|
+
case 'USE SEARCH ENGINE':
|
|
23210
|
+
return spaceTrim$1((block) => `
|
|
23211
|
+
Tool:
|
|
23212
|
+
- You have access to the web search engine via the tool "web_search".
|
|
23213
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
23214
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
23215
|
+
- Do not make up information when you can search for it.
|
|
23216
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
23217
|
+
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
23218
|
+
`);
|
|
23219
|
+
}
|
|
23220
|
+
}
|
|
23221
|
+
/**
|
|
23222
|
+
* Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
|
|
23223
|
+
*
|
|
23224
|
+
* @param requirements - Current model requirements.
|
|
23225
|
+
* @param type - Aggregated `USE` commitment type being applied.
|
|
23226
|
+
* @returns Requirements with the placeholder inserted when it was not already present.
|
|
23227
|
+
* @private internal utility of `USE` commitments
|
|
23228
|
+
*/
|
|
23229
|
+
function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
|
|
23230
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
23231
|
+
if (requirements.systemMessage.includes(placeholder)) {
|
|
23232
|
+
return requirements;
|
|
23233
|
+
}
|
|
23234
|
+
const systemMessage = requirements.systemMessage.trim()
|
|
23235
|
+
? `${requirements.systemMessage}\n\n${placeholder}`
|
|
23236
|
+
: placeholder;
|
|
23237
|
+
return {
|
|
23238
|
+
...requirements,
|
|
23239
|
+
systemMessage,
|
|
23240
|
+
};
|
|
23241
|
+
}
|
|
23242
|
+
/**
|
|
23243
|
+
* Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
|
|
23244
|
+
*
|
|
23245
|
+
* Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
|
|
23246
|
+
*
|
|
23247
|
+
* @param requirements - Model requirements produced by commitment-by-commitment application.
|
|
23248
|
+
* @param commitments - Filtered commitments in their original source order.
|
|
23249
|
+
* @returns Requirements with aggregated `USE` system-message sections.
|
|
23250
|
+
* @private internal utility of `createAgentModelRequirementsWithCommitments`
|
|
23251
|
+
*/
|
|
23252
|
+
function aggregateUseCommitmentSystemMessages(requirements, commitments) {
|
|
23253
|
+
const additionalInstructionsByType = new Map();
|
|
23254
|
+
for (const commitment of commitments) {
|
|
23255
|
+
if (!isAggregatedUseCommitmentType(commitment.type)) {
|
|
23256
|
+
continue;
|
|
23257
|
+
}
|
|
23258
|
+
let additionalInstructions = additionalInstructionsByType.get(commitment.type);
|
|
23259
|
+
if (!additionalInstructions) {
|
|
23260
|
+
additionalInstructions = [];
|
|
23261
|
+
additionalInstructionsByType.set(commitment.type, additionalInstructions);
|
|
23262
|
+
}
|
|
23263
|
+
const normalizedContent = spaceTrim$1(commitment.content);
|
|
23264
|
+
if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
|
|
23265
|
+
additionalInstructions.push(normalizedContent);
|
|
23266
|
+
}
|
|
23267
|
+
}
|
|
23268
|
+
let systemMessage = requirements.systemMessage;
|
|
23269
|
+
for (const [type, additionalInstructions] of additionalInstructionsByType) {
|
|
23270
|
+
const placeholder = getAggregatedUseCommitmentPlaceholder(type);
|
|
23271
|
+
if (!systemMessage.includes(placeholder)) {
|
|
23272
|
+
continue;
|
|
23273
|
+
}
|
|
23274
|
+
systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
|
|
23275
|
+
}
|
|
23276
|
+
return {
|
|
23277
|
+
...requirements,
|
|
23278
|
+
systemMessage,
|
|
23279
|
+
};
|
|
23280
|
+
}
|
|
23281
|
+
|
|
23141
23282
|
/**
|
|
23142
23283
|
* Client-side safe wrapper for fetching URL content
|
|
23143
23284
|
*
|
|
@@ -23188,13 +23329,14 @@ async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
|
|
|
23188
23329
|
* 1. One-shot URL fetching: Simple function to fetch and scrape URL content
|
|
23189
23330
|
* 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
|
|
23190
23331
|
*
|
|
23191
|
-
* The content following `USE BROWSER` is
|
|
23332
|
+
* The content following `USE BROWSER` is an arbitrary text that the agent should know
|
|
23333
|
+
* (e.g. browsing scope or preferred sources).
|
|
23192
23334
|
*
|
|
23193
23335
|
* Example usage in agent source:
|
|
23194
23336
|
*
|
|
23195
23337
|
* ```book
|
|
23196
23338
|
* USE BROWSER
|
|
23197
|
-
* USE BROWSER
|
|
23339
|
+
* USE BROWSER Prefer official documentation and source websites.
|
|
23198
23340
|
* ```
|
|
23199
23341
|
*
|
|
23200
23342
|
* @private [🪔] Maybe export the commitments through some package
|
|
@@ -23232,7 +23374,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
23232
23374
|
|
|
23233
23375
|
## Key aspects
|
|
23234
23376
|
|
|
23235
|
-
- The content following \`USE BROWSER\` is
|
|
23377
|
+
- The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
|
|
23236
23378
|
- Provides two levels of browser access:
|
|
23237
23379
|
1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
|
|
23238
23380
|
2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
|
|
@@ -23349,20 +23491,14 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
23349
23491
|
});
|
|
23350
23492
|
}
|
|
23351
23493
|
const updatedTools = [...existingTools, ...toolsToAdd];
|
|
23352
|
-
|
|
23353
|
-
return this.appendToSystemMessage({
|
|
23494
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
23354
23495
|
...requirements,
|
|
23355
23496
|
tools: updatedTools,
|
|
23356
23497
|
_metadata: {
|
|
23357
23498
|
...requirements._metadata,
|
|
23358
23499
|
useBrowser: true,
|
|
23359
23500
|
},
|
|
23360
|
-
},
|
|
23361
|
-
You have access to browser tools to fetch and access content from the internet.
|
|
23362
|
-
- Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
23363
|
-
- Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
23364
|
-
When you need to know information from a specific website or document, use the fetch_url_content tool.
|
|
23365
|
-
`));
|
|
23501
|
+
}, this.type);
|
|
23366
23502
|
}
|
|
23367
23503
|
/**
|
|
23368
23504
|
* Gets the browser tool function implementations.
|
|
@@ -27149,7 +27285,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
27149
27285
|
`);
|
|
27150
27286
|
}
|
|
27151
27287
|
applyToAgentModelRequirements(requirements, content) {
|
|
27152
|
-
const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
|
|
27153
27288
|
// Get existing tools array or create new one
|
|
27154
27289
|
const existingTools = requirements.tools || [];
|
|
27155
27290
|
// Add 'web_search' to tools if not already present
|
|
@@ -27162,7 +27297,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
27162
27297
|
description: spaceTrim$1(`
|
|
27163
27298
|
Search the internet for information.
|
|
27164
27299
|
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
27165
|
-
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
27166
27300
|
`),
|
|
27167
27301
|
parameters: {
|
|
27168
27302
|
type: 'object',
|
|
@@ -27200,23 +27334,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
27200
27334
|
},
|
|
27201
27335
|
},
|
|
27202
27336
|
];
|
|
27203
|
-
|
|
27204
|
-
return this.appendToSystemMessage({
|
|
27337
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
27205
27338
|
...requirements,
|
|
27206
27339
|
tools: updatedTools,
|
|
27207
27340
|
_metadata: {
|
|
27208
27341
|
...requirements._metadata,
|
|
27209
27342
|
useSearchEngine: content || true,
|
|
27210
27343
|
},
|
|
27211
|
-
},
|
|
27212
|
-
Tool:
|
|
27213
|
-
- You have access to the web search engine via the tool "web_search".
|
|
27214
|
-
- Use it to find up-to-date information or facts that you don't know.
|
|
27215
|
-
- When you need to know some information from the internet, use the tool provided to you.
|
|
27216
|
-
- Do not make up information when you can search for it.
|
|
27217
|
-
- Do not tell the user you cannot search for information, YOU CAN.
|
|
27218
|
-
${block(extraInstructions)}
|
|
27219
|
-
`));
|
|
27344
|
+
}, this.type);
|
|
27220
27345
|
}
|
|
27221
27346
|
/**
|
|
27222
27347
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -28278,7 +28403,6 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
28278
28403
|
`);
|
|
28279
28404
|
}
|
|
28280
28405
|
applyToAgentModelRequirements(requirements, content) {
|
|
28281
|
-
const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
|
|
28282
28406
|
// Get existing tools array or create new one
|
|
28283
28407
|
const existingTools = requirements.tools || [];
|
|
28284
28408
|
// Add 'get_current_time' to tools if not already present
|
|
@@ -28302,19 +28426,13 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
28302
28426
|
},
|
|
28303
28427
|
// <- TODO: !!!! define the function in LLM tools
|
|
28304
28428
|
];
|
|
28305
|
-
|
|
28306
|
-
return this.appendToSystemMessage({
|
|
28429
|
+
return appendAggregatedUseCommitmentPlaceholder({
|
|
28307
28430
|
...requirements,
|
|
28308
28431
|
tools: updatedTools,
|
|
28309
28432
|
_metadata: {
|
|
28310
28433
|
...requirements._metadata,
|
|
28311
28434
|
},
|
|
28312
|
-
},
|
|
28313
|
-
Time and date context:
|
|
28314
|
-
- It is ${moment().format('MMMM YYYY')} now.
|
|
28315
|
-
- If you need more precise current time information, use the tool "get_current_time".
|
|
28316
|
-
${block(extraInstructions)}
|
|
28317
|
-
`));
|
|
28435
|
+
}, this.type);
|
|
28318
28436
|
}
|
|
28319
28437
|
/**
|
|
28320
28438
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -29369,6 +29487,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
29369
29487
|
}
|
|
29370
29488
|
}
|
|
29371
29489
|
}
|
|
29490
|
+
requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
|
|
29372
29491
|
// Handle IMPORT commitments for generic files
|
|
29373
29492
|
// Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
|
|
29374
29493
|
if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {
|