@promptbook/node 0.112.0-57 → 0.112.0-59
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 +273 -244
- package/esm/index.es.js.map +1 -1
- package/esm/src/commitments/_base/BaseCommitmentDefinition.d.ts +26 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +273 -244
- package/umd/index.umd.js.map +1 -1
- package/umd/src/commitments/_base/BaseCommitmentDefinition.d.ts +26 -0
- package/umd/src/version.d.ts +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-59';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -14512,6 +14512,49 @@
|
|
|
14512
14512
|
return this.appendToSystemMessage(requirements, commentSection);
|
|
14513
14513
|
}
|
|
14514
14514
|
}
|
|
14515
|
+
/**
|
|
14516
|
+
* Helper method to append a bullet point to an existing `## SectionTitle` section in the system
|
|
14517
|
+
* message, or to create a new section when it does not yet exist.
|
|
14518
|
+
*
|
|
14519
|
+
* Handles the case where the same commitment type appears multiple times in the book source and
|
|
14520
|
+
* all entries should be grouped under one shared heading rather than emitting a duplicate block.
|
|
14521
|
+
*
|
|
14522
|
+
* @param requirements - Current model requirements.
|
|
14523
|
+
* @param sectionTitle - Section title without the `##` prefix.
|
|
14524
|
+
* @param bulletContent - Bullet content without the leading `- ` prefix.
|
|
14525
|
+
* @returns Requirements with the bullet appended to the section.
|
|
14526
|
+
*/
|
|
14527
|
+
appendBulletPointToSection(requirements, sectionTitle, bulletContent) {
|
|
14528
|
+
const sectionHeader = `## ${sectionTitle}`;
|
|
14529
|
+
const bullet = `- ${bulletContent}`;
|
|
14530
|
+
if (requirements.systemMessage.includes(sectionHeader)) {
|
|
14531
|
+
// Append bullet to end of existing section, before the next h2 heading or end of message
|
|
14532
|
+
const newSystemMessage = requirements.systemMessage.replace(new RegExp(`(## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n\\n)([\\s\\S]*?)(?=\\n\\n##|$)`), `$1$2\n${bullet}`);
|
|
14533
|
+
return { ...requirements, systemMessage: newSystemMessage };
|
|
14534
|
+
}
|
|
14535
|
+
return this.appendToSystemMessage(requirements, `${sectionHeader}\n\n${bullet}`, '\n\n');
|
|
14536
|
+
}
|
|
14537
|
+
/**
|
|
14538
|
+
* Helper method to replace an existing `## SectionTitle` section in the system message, or to
|
|
14539
|
+
* append a new one when the section does not yet exist.
|
|
14540
|
+
*
|
|
14541
|
+
* Use this when a commitment type can appear multiple times and each subsequent occurrence should
|
|
14542
|
+
* update the single shared section rather than appending a duplicate block.
|
|
14543
|
+
*
|
|
14544
|
+
* @param requirements - Current model requirements.
|
|
14545
|
+
* @param sectionTitle - Section title without the `##` prefix.
|
|
14546
|
+
* @param sectionContent - Full section content including the `## Title` header line.
|
|
14547
|
+
* @returns Requirements with the section replaced or appended.
|
|
14548
|
+
*/
|
|
14549
|
+
replaceOrCreateSection(requirements, sectionTitle, sectionContent) {
|
|
14550
|
+
const sectionHeader = `## ${sectionTitle}`;
|
|
14551
|
+
if (requirements.systemMessage.includes(sectionHeader)) {
|
|
14552
|
+
// Replace all text from the heading until the next h2 heading or end of message
|
|
14553
|
+
const newSystemMessage = requirements.systemMessage.replace(new RegExp(`## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), sectionContent);
|
|
14554
|
+
return { ...requirements, systemMessage: newSystemMessage };
|
|
14555
|
+
}
|
|
14556
|
+
return this.appendToSystemMessage(requirements, sectionContent, '\n\n');
|
|
14557
|
+
}
|
|
14515
14558
|
/**
|
|
14516
14559
|
* Gets tool function implementations provided by this commitment
|
|
14517
14560
|
*
|
|
@@ -14973,20 +15016,16 @@
|
|
|
14973
15016
|
if (!trimmedContent) {
|
|
14974
15017
|
return requirements;
|
|
14975
15018
|
}
|
|
14976
|
-
//
|
|
15019
|
+
// Store the entry in metadata for debugging and inspection
|
|
14977
15020
|
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
14978
|
-
// Merge the new dictionary entry with existing entries
|
|
14979
15021
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
14980
|
-
// Store the merged dictionary in metadata for debugging and inspection
|
|
14981
15022
|
const updatedMetadata = {
|
|
14982
15023
|
...requirements._metadata,
|
|
14983
15024
|
DICTIONARY: mergedDictionary,
|
|
14984
15025
|
};
|
|
14985
|
-
//
|
|
14986
|
-
// Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
|
|
14987
|
-
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
15026
|
+
// Append each dictionary entry as a bullet point under ## Dictionary
|
|
14988
15027
|
return {
|
|
14989
|
-
...this.
|
|
15028
|
+
...this.appendBulletPointToSection(requirements, 'Dictionary', trimmedContent),
|
|
14990
15029
|
_metadata: updatedMetadata,
|
|
14991
15030
|
};
|
|
14992
15031
|
}
|
|
@@ -15489,10 +15528,10 @@
|
|
|
15489
15528
|
if (!trimmedContent) {
|
|
15490
15529
|
return requirements;
|
|
15491
15530
|
}
|
|
15492
|
-
// Add goal to the system message
|
|
15493
|
-
const goalSection =
|
|
15531
|
+
// Add goal as a proper h2 section to the system message
|
|
15532
|
+
const goalSection = `## Goal\n\n${trimmedContent}`;
|
|
15494
15533
|
const requirementsWithGoal = this.appendToSystemMessage(requirements, goalSection, '\n\n');
|
|
15495
|
-
return this.appendToPromptSuffix(requirementsWithGoal,
|
|
15534
|
+
return this.appendToPromptSuffix(requirementsWithGoal, trimmedContent);
|
|
15496
15535
|
}
|
|
15497
15536
|
}
|
|
15498
15537
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -16012,11 +16051,8 @@
|
|
|
16012
16051
|
if (!trimmedContent) {
|
|
16013
16052
|
return requirements;
|
|
16014
16053
|
}
|
|
16015
|
-
// Add language
|
|
16016
|
-
const languageSection =
|
|
16017
|
-
${block(trimmedContent)}
|
|
16018
|
-
<- You are speaking these languages in your responses to the user.
|
|
16019
|
-
`));
|
|
16054
|
+
// Add language as a bullet under a ## Language section
|
|
16055
|
+
const languageSection = `## Language\n\n- Your language is ${trimmedContent}`;
|
|
16020
16056
|
return this.appendToSystemMessage(requirements, languageSection, '\n\n');
|
|
16021
16057
|
}
|
|
16022
16058
|
}
|
|
@@ -16060,15 +16096,16 @@
|
|
|
16060
16096
|
*/
|
|
16061
16097
|
function createMemorySystemMessage(extraInstructions) {
|
|
16062
16098
|
return _spaceTrim.spaceTrim((block) => `
|
|
16063
|
-
Memory
|
|
16064
|
-
|
|
16065
|
-
-
|
|
16066
|
-
-
|
|
16067
|
-
-
|
|
16068
|
-
-
|
|
16069
|
-
-
|
|
16070
|
-
-
|
|
16071
|
-
-
|
|
16099
|
+
## Memory
|
|
16100
|
+
|
|
16101
|
+
- Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
|
|
16102
|
+
- You can use persistent user memory tools.
|
|
16103
|
+
- Use \`${MemoryToolNames.retrieve}\` to load relevant memory before answering.
|
|
16104
|
+
- Use \`${MemoryToolNames.store}\` to save stable user-specific facts that improve future help.
|
|
16105
|
+
- Use \`${MemoryToolNames.update}\` to refresh an existing memory when the content changes.
|
|
16106
|
+
- Use \`${MemoryToolNames.delete}\` to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
|
|
16107
|
+
- Store concise memory items and avoid duplicates.
|
|
16108
|
+
- Never claim memory was saved or loaded unless the tool confirms it.
|
|
16072
16109
|
${block(extraInstructions)}
|
|
16073
16110
|
`);
|
|
16074
16111
|
}
|
|
@@ -16990,10 +17027,8 @@
|
|
|
16990
17027
|
if (!trimmedContent) {
|
|
16991
17028
|
return requirements;
|
|
16992
17029
|
}
|
|
16993
|
-
// Create message section for system message
|
|
16994
|
-
const messageSection = `Previous Message: ${trimmedContent}`;
|
|
16995
17030
|
// Messages represent conversation history and should be included for context
|
|
16996
|
-
return this.
|
|
17031
|
+
return this.appendBulletPointToSection(requirements, 'Previous messages', trimmedContent);
|
|
16997
17032
|
}
|
|
16998
17033
|
}
|
|
16999
17034
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -21787,10 +21822,9 @@
|
|
|
21787
21822
|
if (!trimmedContent) {
|
|
21788
21823
|
return requirements;
|
|
21789
21824
|
}
|
|
21790
|
-
//
|
|
21791
|
-
const
|
|
21792
|
-
|
|
21793
|
-
return this.appendToPromptSuffix(requirementsWithRule, ruleSection);
|
|
21825
|
+
// Group all rules under a single ## Rules section as bullet points
|
|
21826
|
+
const requirementsWithRule = this.appendBulletPointToSection(requirements, 'Rules', trimmedContent);
|
|
21827
|
+
return this.appendToPromptSuffix(requirementsWithRule, `- ${trimmedContent}`);
|
|
21794
21828
|
}
|
|
21795
21829
|
}
|
|
21796
21830
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -22026,10 +22060,8 @@
|
|
|
22026
22060
|
if (!trimmedContent) {
|
|
22027
22061
|
return requirements;
|
|
22028
22062
|
}
|
|
22029
|
-
// Create scenario section for system message
|
|
22030
|
-
const scenarioSection = `Scenario: ${trimmedContent}`;
|
|
22031
22063
|
// Scenarios provide important contextual information that affects behavior
|
|
22032
|
-
return this.
|
|
22064
|
+
return this.appendBulletPointToSection(requirements, 'Scenarios', trimmedContent);
|
|
22033
22065
|
}
|
|
22034
22066
|
}
|
|
22035
22067
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -22412,8 +22444,8 @@
|
|
|
22412
22444
|
* @private
|
|
22413
22445
|
*/
|
|
22414
22446
|
const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
|
|
22415
|
-
'-
|
|
22416
|
-
'-
|
|
22447
|
+
'- If a teammate is relevant to the request, consult that teammate using the matching tool.',
|
|
22448
|
+
'- Do not ask the user for information that a listed teammate can provide directly.',
|
|
22417
22449
|
];
|
|
22418
22450
|
/**
|
|
22419
22451
|
* Constant for remote agents by Url.
|
|
@@ -22541,7 +22573,7 @@
|
|
|
22541
22573
|
toolName: entry.toolName,
|
|
22542
22574
|
});
|
|
22543
22575
|
}
|
|
22544
|
-
const teamSystemMessage = this.createSystemMessageSection('Teammates
|
|
22576
|
+
const teamSystemMessage = this.createSystemMessageSection('Teammates', buildTeamSystemMessageBody(teamEntries));
|
|
22545
22577
|
return this.appendToSystemMessage({
|
|
22546
22578
|
...requirements,
|
|
22547
22579
|
tools: updatedTools,
|
|
@@ -23031,36 +23063,38 @@
|
|
|
23031
23063
|
switch (type) {
|
|
23032
23064
|
case 'USE TIME':
|
|
23033
23065
|
return _spaceTrim.spaceTrim((block) => `
|
|
23034
|
-
Time and date context
|
|
23035
|
-
|
|
23036
|
-
-
|
|
23066
|
+
## Time and date context
|
|
23067
|
+
|
|
23068
|
+
- It is ${moment__default["default"]().format('MMMM YYYY')} now.
|
|
23069
|
+
- If you need more precise current time information, use the tool \`get_current_time\`.
|
|
23037
23070
|
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
23038
23071
|
`);
|
|
23039
23072
|
case 'USE BROWSER':
|
|
23040
23073
|
return _spaceTrim.spaceTrim((block) => `
|
|
23041
|
-
|
|
23042
|
-
|
|
23043
|
-
-
|
|
23044
|
-
|
|
23074
|
+
## Browser
|
|
23075
|
+
|
|
23076
|
+
- Use \`fetch_url_content\` to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
23077
|
+
- Use \`run_browser\` for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
23078
|
+
- When you need to know information from a specific website or document, use the tools provided.
|
|
23045
23079
|
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
23046
23080
|
`);
|
|
23047
23081
|
case 'USE SEARCH ENGINE':
|
|
23048
23082
|
return _spaceTrim.spaceTrim((block) => `
|
|
23049
|
-
|
|
23050
|
-
|
|
23051
|
-
-
|
|
23052
|
-
-
|
|
23053
|
-
-
|
|
23054
|
-
-
|
|
23083
|
+
## Web Search
|
|
23084
|
+
|
|
23085
|
+
- Use \`web_search\` to find up-to-date information or facts.
|
|
23086
|
+
- When you need to know some information from the internet, use the search tool provided.
|
|
23087
|
+
- Do not make up information when you can search for it.
|
|
23088
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
23055
23089
|
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
23056
23090
|
`);
|
|
23057
23091
|
case 'USE DEEPSEARCH':
|
|
23058
23092
|
return _spaceTrim.spaceTrim((block) => `
|
|
23059
|
-
|
|
23060
|
-
|
|
23061
|
-
-
|
|
23062
|
-
-
|
|
23063
|
-
-
|
|
23093
|
+
## Deep Research
|
|
23094
|
+
|
|
23095
|
+
- Use \`deep_search\` for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
|
|
23096
|
+
- Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
|
|
23097
|
+
- Do not pretend you cannot research current information when this tool is available.
|
|
23064
23098
|
${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
|
|
23065
23099
|
`);
|
|
23066
23100
|
}
|
|
@@ -23390,96 +23424,6 @@
|
|
|
23390
23424
|
}
|
|
23391
23425
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
23392
23426
|
|
|
23393
|
-
/**
|
|
23394
|
-
* Base Google Calendar API URL.
|
|
23395
|
-
*
|
|
23396
|
-
* @private constant of callGoogleCalendarApi
|
|
23397
|
-
*/
|
|
23398
|
-
const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
|
|
23399
|
-
/**
|
|
23400
|
-
* Runs one Google Calendar API request and parses JSON response payload.
|
|
23401
|
-
*
|
|
23402
|
-
* @private function of UseCalendarCommitmentDefinition
|
|
23403
|
-
*/
|
|
23404
|
-
async function callGoogleCalendarApi(accessToken, options) {
|
|
23405
|
-
const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
|
|
23406
|
-
if (options.query) {
|
|
23407
|
-
for (const [key, value] of Object.entries(options.query)) {
|
|
23408
|
-
if (value && value.trim()) {
|
|
23409
|
-
url.searchParams.set(key, value);
|
|
23410
|
-
}
|
|
23411
|
-
}
|
|
23412
|
-
}
|
|
23413
|
-
const response = await fetch(url.toString(), {
|
|
23414
|
-
method: options.method,
|
|
23415
|
-
headers: {
|
|
23416
|
-
Authorization: `Bearer ${accessToken}`,
|
|
23417
|
-
Accept: 'application/json',
|
|
23418
|
-
'Content-Type': 'application/json',
|
|
23419
|
-
},
|
|
23420
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
23421
|
-
});
|
|
23422
|
-
const textPayload = await response.text();
|
|
23423
|
-
const parsedPayload = tryParseJson$2(textPayload);
|
|
23424
|
-
if (options.allowNotFound && response.status === 404) {
|
|
23425
|
-
return null;
|
|
23426
|
-
}
|
|
23427
|
-
if (!response.ok) {
|
|
23428
|
-
throw new Error(_spaceTrim.spaceTrim(`
|
|
23429
|
-
Google Calendar API request failed (${response.status} ${response.statusText}):
|
|
23430
|
-
${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
|
|
23431
|
-
`));
|
|
23432
|
-
}
|
|
23433
|
-
return parsedPayload;
|
|
23434
|
-
}
|
|
23435
|
-
/**
|
|
23436
|
-
* Parses raw text into JSON when possible.
|
|
23437
|
-
*
|
|
23438
|
-
* @private function of callGoogleCalendarApi
|
|
23439
|
-
*/
|
|
23440
|
-
function tryParseJson$2(rawText) {
|
|
23441
|
-
if (!rawText.trim()) {
|
|
23442
|
-
return {};
|
|
23443
|
-
}
|
|
23444
|
-
try {
|
|
23445
|
-
return JSON.parse(rawText);
|
|
23446
|
-
}
|
|
23447
|
-
catch (_a) {
|
|
23448
|
-
return rawText;
|
|
23449
|
-
}
|
|
23450
|
-
}
|
|
23451
|
-
/**
|
|
23452
|
-
* Extracts a user-friendly Google Calendar API error message.
|
|
23453
|
-
*
|
|
23454
|
-
* @private function of callGoogleCalendarApi
|
|
23455
|
-
*/
|
|
23456
|
-
function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
|
|
23457
|
-
if (parsedPayload && typeof parsedPayload === 'object') {
|
|
23458
|
-
const payload = parsedPayload;
|
|
23459
|
-
const errorPayload = payload.error;
|
|
23460
|
-
if (errorPayload && typeof errorPayload === 'object') {
|
|
23461
|
-
const normalizedErrorPayload = errorPayload;
|
|
23462
|
-
const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
|
|
23463
|
-
const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
|
|
23464
|
-
const flattenedErrors = errors
|
|
23465
|
-
.map((errorEntry) => {
|
|
23466
|
-
if (!errorEntry || typeof errorEntry !== 'object') {
|
|
23467
|
-
return '';
|
|
23468
|
-
}
|
|
23469
|
-
const normalizedErrorEntry = errorEntry;
|
|
23470
|
-
const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
|
|
23471
|
-
const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
|
|
23472
|
-
return [detailMessage, reason].filter(Boolean).join(' | ');
|
|
23473
|
-
})
|
|
23474
|
-
.filter(Boolean);
|
|
23475
|
-
if (message || flattenedErrors.length > 0) {
|
|
23476
|
-
return [message, ...flattenedErrors].filter(Boolean).join(' | ');
|
|
23477
|
-
}
|
|
23478
|
-
}
|
|
23479
|
-
}
|
|
23480
|
-
return fallbackText || 'Unknown Google Calendar API error';
|
|
23481
|
-
}
|
|
23482
|
-
|
|
23483
23427
|
/**
|
|
23484
23428
|
* Hostnames accepted for Google Calendar references.
|
|
23485
23429
|
*
|
|
@@ -23661,6 +23605,96 @@
|
|
|
23661
23605
|
}
|
|
23662
23606
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
23663
23607
|
|
|
23608
|
+
/**
|
|
23609
|
+
* Base Google Calendar API URL.
|
|
23610
|
+
*
|
|
23611
|
+
* @private constant of callGoogleCalendarApi
|
|
23612
|
+
*/
|
|
23613
|
+
const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
|
|
23614
|
+
/**
|
|
23615
|
+
* Runs one Google Calendar API request and parses JSON response payload.
|
|
23616
|
+
*
|
|
23617
|
+
* @private function of UseCalendarCommitmentDefinition
|
|
23618
|
+
*/
|
|
23619
|
+
async function callGoogleCalendarApi(accessToken, options) {
|
|
23620
|
+
const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
|
|
23621
|
+
if (options.query) {
|
|
23622
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
23623
|
+
if (value && value.trim()) {
|
|
23624
|
+
url.searchParams.set(key, value);
|
|
23625
|
+
}
|
|
23626
|
+
}
|
|
23627
|
+
}
|
|
23628
|
+
const response = await fetch(url.toString(), {
|
|
23629
|
+
method: options.method,
|
|
23630
|
+
headers: {
|
|
23631
|
+
Authorization: `Bearer ${accessToken}`,
|
|
23632
|
+
Accept: 'application/json',
|
|
23633
|
+
'Content-Type': 'application/json',
|
|
23634
|
+
},
|
|
23635
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
23636
|
+
});
|
|
23637
|
+
const textPayload = await response.text();
|
|
23638
|
+
const parsedPayload = tryParseJson$2(textPayload);
|
|
23639
|
+
if (options.allowNotFound && response.status === 404) {
|
|
23640
|
+
return null;
|
|
23641
|
+
}
|
|
23642
|
+
if (!response.ok) {
|
|
23643
|
+
throw new Error(_spaceTrim.spaceTrim(`
|
|
23644
|
+
Google Calendar API request failed (${response.status} ${response.statusText}):
|
|
23645
|
+
${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
|
|
23646
|
+
`));
|
|
23647
|
+
}
|
|
23648
|
+
return parsedPayload;
|
|
23649
|
+
}
|
|
23650
|
+
/**
|
|
23651
|
+
* Parses raw text into JSON when possible.
|
|
23652
|
+
*
|
|
23653
|
+
* @private function of callGoogleCalendarApi
|
|
23654
|
+
*/
|
|
23655
|
+
function tryParseJson$2(rawText) {
|
|
23656
|
+
if (!rawText.trim()) {
|
|
23657
|
+
return {};
|
|
23658
|
+
}
|
|
23659
|
+
try {
|
|
23660
|
+
return JSON.parse(rawText);
|
|
23661
|
+
}
|
|
23662
|
+
catch (_a) {
|
|
23663
|
+
return rawText;
|
|
23664
|
+
}
|
|
23665
|
+
}
|
|
23666
|
+
/**
|
|
23667
|
+
* Extracts a user-friendly Google Calendar API error message.
|
|
23668
|
+
*
|
|
23669
|
+
* @private function of callGoogleCalendarApi
|
|
23670
|
+
*/
|
|
23671
|
+
function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
|
|
23672
|
+
if (parsedPayload && typeof parsedPayload === 'object') {
|
|
23673
|
+
const payload = parsedPayload;
|
|
23674
|
+
const errorPayload = payload.error;
|
|
23675
|
+
if (errorPayload && typeof errorPayload === 'object') {
|
|
23676
|
+
const normalizedErrorPayload = errorPayload;
|
|
23677
|
+
const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
|
|
23678
|
+
const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
|
|
23679
|
+
const flattenedErrors = errors
|
|
23680
|
+
.map((errorEntry) => {
|
|
23681
|
+
if (!errorEntry || typeof errorEntry !== 'object') {
|
|
23682
|
+
return '';
|
|
23683
|
+
}
|
|
23684
|
+
const normalizedErrorEntry = errorEntry;
|
|
23685
|
+
const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
|
|
23686
|
+
const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
|
|
23687
|
+
return [detailMessage, reason].filter(Boolean).join(' | ');
|
|
23688
|
+
})
|
|
23689
|
+
.filter(Boolean);
|
|
23690
|
+
if (message || flattenedErrors.length > 0) {
|
|
23691
|
+
return [message, ...flattenedErrors].filter(Boolean).join(' | ');
|
|
23692
|
+
}
|
|
23693
|
+
}
|
|
23694
|
+
}
|
|
23695
|
+
return fallbackText || 'Unknown Google Calendar API error';
|
|
23696
|
+
}
|
|
23697
|
+
|
|
23664
23698
|
/**
|
|
23665
23699
|
* Wallet metadata used by USE CALENDAR when resolving Google Calendar credentials.
|
|
23666
23700
|
*
|
|
@@ -24561,18 +24595,20 @@
|
|
|
24561
24595
|
if (parsedCommitment.calendar) {
|
|
24562
24596
|
addConfiguredCalendarIfMissing(existingConfiguredCalendars, parsedCommitment.calendar);
|
|
24563
24597
|
}
|
|
24564
|
-
const
|
|
24565
|
-
? existingConfiguredCalendars
|
|
24566
|
-
|
|
24567
|
-
`- ${calendar.provider}: ${calendar.url}`,
|
|
24568
|
-
calendar.scopes.length > 0 ? ` scopes: ${calendar.scopes.join(', ')}` : '',
|
|
24569
|
-
]
|
|
24570
|
-
.filter(Boolean)
|
|
24571
|
-
.join('\n'))
|
|
24572
|
-
.join('\n')
|
|
24573
|
-
: '- Calendar is resolved from runtime context';
|
|
24598
|
+
const calendarBullets = existingConfiguredCalendars.length > 0
|
|
24599
|
+
? existingConfiguredCalendars.map((calendar) => `- ${calendar.provider}: ${calendar.url}`).join('\n')
|
|
24600
|
+
: '- Calendar is resolved from runtime context';
|
|
24574
24601
|
const extraInstructions = formatOptionalInstructionBlock('Calendar instructions', parsedCommitment.instructions);
|
|
24575
|
-
|
|
24602
|
+
const calendarSectionContent = _spaceTrim.spaceTrim((block) => `
|
|
24603
|
+
## Calendar
|
|
24604
|
+
|
|
24605
|
+
- Use \`calendar_list_events\`, \`calendar_get_event\`, \`calendar_create_event\`, \`calendar_update_event\`, \`calendar_delete_event\`, and \`calendar_invite_guests\` to manage events in configured calendars.
|
|
24606
|
+
- Supported operations include read, create, update, delete, invite guests, and reminders.
|
|
24607
|
+
- Configured calendars:
|
|
24608
|
+
${block(calendarBullets)}
|
|
24609
|
+
${block(extraInstructions)}
|
|
24610
|
+
`);
|
|
24611
|
+
return this.replaceOrCreateSection({
|
|
24576
24612
|
...requirements,
|
|
24577
24613
|
tools: createUseCalendarTools(requirements.tools || []),
|
|
24578
24614
|
_metadata: {
|
|
@@ -24580,16 +24616,7 @@
|
|
|
24580
24616
|
useCalendar: true,
|
|
24581
24617
|
useCalendars: existingConfiguredCalendars,
|
|
24582
24618
|
},
|
|
24583
|
-
},
|
|
24584
|
-
Calendar tools:
|
|
24585
|
-
- You can inspect and manage events in configured calendars.
|
|
24586
|
-
- Supported operations include read, create, update, delete, invite guests, and reminders.
|
|
24587
|
-
- Configured calendars:
|
|
24588
|
-
${block(calendarsList)}
|
|
24589
|
-
- USE CALENDAR credentials are read from wallet records (ACCESS_TOKEN, service "${UseCalendarWallet.service}", key "${UseCalendarWallet.key}").
|
|
24590
|
-
- If credentials are missing, ask user to connect calendar credentials in host UI and/or add them to wallet.
|
|
24591
|
-
${block(extraInstructions)}
|
|
24592
|
-
`));
|
|
24619
|
+
}, 'Calendar', calendarSectionContent);
|
|
24593
24620
|
}
|
|
24594
24621
|
/**
|
|
24595
24622
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -24926,18 +24953,6 @@
|
|
|
24926
24953
|
* @private internal USE EMAIL constant
|
|
24927
24954
|
*/
|
|
24928
24955
|
const SEND_EMAIL_TOOL_NAME = 'send_email';
|
|
24929
|
-
/**
|
|
24930
|
-
* Wallet service used for SMTP credentials required by USE EMAIL.
|
|
24931
|
-
*
|
|
24932
|
-
* @private internal USE EMAIL constant
|
|
24933
|
-
*/
|
|
24934
|
-
const USE_EMAIL_SMTP_WALLET_SERVICE = 'smtp';
|
|
24935
|
-
/**
|
|
24936
|
-
* Wallet key used for SMTP credentials required by USE EMAIL.
|
|
24937
|
-
*
|
|
24938
|
-
* @private internal USE EMAIL constant
|
|
24939
|
-
*/
|
|
24940
|
-
const USE_EMAIL_SMTP_WALLET_KEY = 'use-email-smtp-credentials';
|
|
24941
24956
|
/**
|
|
24942
24957
|
* USE EMAIL commitment definition.
|
|
24943
24958
|
*
|
|
@@ -24996,31 +25011,41 @@
|
|
|
24996
25011
|
`);
|
|
24997
25012
|
}
|
|
24998
25013
|
applyToAgentModelRequirements(requirements, content) {
|
|
25014
|
+
var _a;
|
|
24999
25015
|
const parsedCommitment = parseUseEmailCommitmentContent(content);
|
|
25000
|
-
const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
|
|
25001
|
-
const senderInstruction = parsedCommitment.senderEmail
|
|
25002
|
-
? `- Default sender address from commitment: "${parsedCommitment.senderEmail}".`
|
|
25003
|
-
: '';
|
|
25004
25016
|
const updatedTools = addUseEmailTools(requirements.tools || []);
|
|
25005
|
-
|
|
25017
|
+
// Collect all configured sender emails across multiple USE EMAIL commitments
|
|
25018
|
+
const existingSenders = Array.isArray((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useEmailSenders)
|
|
25019
|
+
? [...requirements._metadata.useEmailSenders]
|
|
25020
|
+
: [];
|
|
25021
|
+
if (parsedCommitment.senderEmail && !existingSenders.includes(parsedCommitment.senderEmail)) {
|
|
25022
|
+
existingSenders.push(parsedCommitment.senderEmail);
|
|
25023
|
+
}
|
|
25024
|
+
const senderBullets = existingSenders.length > 0
|
|
25025
|
+
? existingSenders
|
|
25026
|
+
.map((email, index) => index === 0
|
|
25027
|
+
? `- Default sender address: "${email}".`
|
|
25028
|
+
: `- Additional sender address: "${email}".`)
|
|
25029
|
+
.join('\n')
|
|
25030
|
+
: '';
|
|
25031
|
+
const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
|
|
25032
|
+
const emailSectionContent = _spaceTrim.spaceTrim((block) => `
|
|
25033
|
+
## Emails
|
|
25034
|
+
|
|
25035
|
+
- Use \`${SEND_EMAIL_TOOL_NAME}\` to send outbound emails.
|
|
25036
|
+
${block(senderBullets)}
|
|
25037
|
+
${block(extraInstructions)}
|
|
25038
|
+
`);
|
|
25039
|
+
return this.replaceOrCreateSection({
|
|
25006
25040
|
...requirements,
|
|
25007
25041
|
tools: updatedTools,
|
|
25008
25042
|
_metadata: {
|
|
25009
25043
|
...requirements._metadata,
|
|
25010
25044
|
useEmail: true,
|
|
25011
25045
|
...(parsedCommitment.senderEmail ? { useEmailSender: parsedCommitment.senderEmail } : {}),
|
|
25046
|
+
useEmailSenders: existingSenders,
|
|
25012
25047
|
},
|
|
25013
|
-
},
|
|
25014
|
-
Email tool:
|
|
25015
|
-
- Use "${SEND_EMAIL_TOOL_NAME}" to send outbound emails.
|
|
25016
|
-
- Prefer \`message\` argument compatible with Promptbook \`Message\` type.
|
|
25017
|
-
- Include subject in \`message.metadata.subject\` (or use legacy \`subject\` argument).
|
|
25018
|
-
- USE EMAIL credentials are read from wallet records (ACCESS_TOKEN, service "${USE_EMAIL_SMTP_WALLET_SERVICE}", key "${USE_EMAIL_SMTP_WALLET_KEY}").
|
|
25019
|
-
- Wallet secret must contain SMTP credentials in JSON format with fields \`host\`, \`port\`, \`secure\`, \`username\`, \`password\`.
|
|
25020
|
-
- If credentials are missing, ask user to add wallet credentials.
|
|
25021
|
-
${block(senderInstruction)}
|
|
25022
|
-
${block(extraInstructions)}
|
|
25023
|
-
`));
|
|
25048
|
+
}, 'Emails', emailSectionContent);
|
|
25024
25049
|
}
|
|
25025
25050
|
/**
|
|
25026
25051
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -25056,13 +25081,13 @@
|
|
|
25056
25081
|
...existingTools,
|
|
25057
25082
|
{
|
|
25058
25083
|
name: SEND_EMAIL_TOOL_NAME,
|
|
25059
|
-
description: 'Send an outbound email
|
|
25084
|
+
description: 'Send an outbound email.',
|
|
25060
25085
|
parameters: {
|
|
25061
25086
|
type: 'object',
|
|
25062
25087
|
properties: {
|
|
25063
25088
|
message: {
|
|
25064
25089
|
type: 'object',
|
|
25065
|
-
description: '
|
|
25090
|
+
description: 'Email payload. Use metadata.subject for the subject line.',
|
|
25066
25091
|
},
|
|
25067
25092
|
to: {
|
|
25068
25093
|
type: 'string',
|
|
@@ -25166,13 +25191,14 @@
|
|
|
25166
25191
|
useImageGenerator: content || true,
|
|
25167
25192
|
},
|
|
25168
25193
|
}, _spaceTrim.spaceTrim((block) => `
|
|
25169
|
-
Image generation
|
|
25170
|
-
|
|
25171
|
-
-
|
|
25172
|
-
|
|
25173
|
-
|
|
25174
|
-
-
|
|
25175
|
-
-
|
|
25194
|
+
## Image generation
|
|
25195
|
+
|
|
25196
|
+
- You do not generate images directly and you do not call any image tool.
|
|
25197
|
+
- When the user asks for an image, include markdown notation in your message:
|
|
25198
|
+
\`\`
|
|
25199
|
+
- Keep \`<alt text>\` short and descriptive.
|
|
25200
|
+
- Keep \`<prompt>\` detailed so the generated image matches the request.
|
|
25201
|
+
- You can include normal explanatory text before and after the notation.
|
|
25176
25202
|
${block(extraInstructions)}
|
|
25177
25203
|
`));
|
|
25178
25204
|
}
|
|
@@ -25352,11 +25378,12 @@
|
|
|
25352
25378
|
usePopup: content || true,
|
|
25353
25379
|
},
|
|
25354
25380
|
}, _spaceTrim.spaceTrim((block) => `
|
|
25355
|
-
|
|
25356
|
-
|
|
25357
|
-
-
|
|
25381
|
+
## Popup
|
|
25382
|
+
|
|
25383
|
+
- You can open a popup window with a specific URL using the tool \`open_popup\`.
|
|
25384
|
+
- Use this when you want the user to see or interact with a specific website.
|
|
25358
25385
|
${block(extraInstructions)}
|
|
25359
|
-
|
|
25386
|
+
`));
|
|
25360
25387
|
}
|
|
25361
25388
|
/**
|
|
25362
25389
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -25530,11 +25557,12 @@
|
|
|
25530
25557
|
usePrivacy: content || true,
|
|
25531
25558
|
},
|
|
25532
25559
|
}, _spaceTrim.spaceTrim((block) => `
|
|
25533
|
-
Privacy
|
|
25534
|
-
|
|
25535
|
-
-
|
|
25536
|
-
-
|
|
25537
|
-
-
|
|
25560
|
+
## Privacy
|
|
25561
|
+
|
|
25562
|
+
- Use \`${TURN_PRIVACY_ON_TOOL_NAME}\` when the user asks for a private/sensitive conversation.
|
|
25563
|
+
- This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
|
|
25564
|
+
- Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
|
|
25565
|
+
- Do not claim that end-to-end encryption is implemented yet.
|
|
25538
25566
|
${block(extraInstructions)}
|
|
25539
25567
|
`));
|
|
25540
25568
|
}
|
|
@@ -27158,9 +27186,16 @@
|
|
|
27158
27186
|
}
|
|
27159
27187
|
const existingConfiguredProjects = normalizeConfiguredProjects((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useProjects);
|
|
27160
27188
|
addConfiguredProjectIfMissing(existingConfiguredProjects, parsedCommitment.repository);
|
|
27161
|
-
const repositoriesList = existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n');
|
|
27162
27189
|
const extraInstructions = formatOptionalInstructionBlock('Project instructions', parsedCommitment.instructions);
|
|
27163
|
-
|
|
27190
|
+
const sectionContent = _spaceTrim.spaceTrim((block) => `
|
|
27191
|
+
- You can inspect and edit configured GitHub repositories using project tools.
|
|
27192
|
+
- Configured repositories:
|
|
27193
|
+
${block(existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n'))}
|
|
27194
|
+
- When a repository is not obvious from context, pass \`repository\` in tool arguments explicitly.
|
|
27195
|
+
- If credentials are missing, ask the user to connect their GitHub account in the host UI.
|
|
27196
|
+
${block(extraInstructions)}
|
|
27197
|
+
`);
|
|
27198
|
+
return this.replaceOrCreateSection({
|
|
27164
27199
|
...requirements,
|
|
27165
27200
|
tools: createUseProjectTools(requirements.tools || []),
|
|
27166
27201
|
_metadata: {
|
|
@@ -27168,16 +27203,7 @@
|
|
|
27168
27203
|
useProject: true,
|
|
27169
27204
|
useProjects: existingConfiguredProjects,
|
|
27170
27205
|
},
|
|
27171
|
-
},
|
|
27172
|
-
Project tools:
|
|
27173
|
-
- You can inspect and edit configured GitHub repositories using project tools.
|
|
27174
|
-
- Configured repositories:
|
|
27175
|
-
${block(repositoriesList)}
|
|
27176
|
-
- When a repository is not obvious from context, pass "repository" in tool arguments explicitly.
|
|
27177
|
-
- USE PROJECT credentials are read from wallet records (ACCESS_TOKEN, service "${UseProjectWallet.service}", key "${UseProjectWallet.key}").
|
|
27178
|
-
- If credentials are missing, ask the user to connect credentials in host UI and/or add them to wallet.
|
|
27179
|
-
${block(extraInstructions)}
|
|
27180
|
-
`));
|
|
27206
|
+
}, 'GitHub repositories', sectionContent);
|
|
27181
27207
|
}
|
|
27182
27208
|
/**
|
|
27183
27209
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -27524,11 +27550,12 @@
|
|
|
27524
27550
|
useSpawn: content || true,
|
|
27525
27551
|
},
|
|
27526
27552
|
}, _spaceTrim.spaceTrim((block) => `
|
|
27527
|
-
Spawning agents
|
|
27528
|
-
|
|
27529
|
-
-
|
|
27530
|
-
-
|
|
27531
|
-
-
|
|
27553
|
+
## Spawning agents
|
|
27554
|
+
|
|
27555
|
+
- Use \`${SPAWN_AGENT_TOOL_NAME}\` only when user asks to create a persistent new agent.
|
|
27556
|
+
- Pass full agent source in \`source\`.
|
|
27557
|
+
- Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
|
|
27558
|
+
- Do not add unknown fields in tool arguments.
|
|
27532
27559
|
${block(extraInstructions)}
|
|
27533
27560
|
`));
|
|
27534
27561
|
}
|
|
@@ -27562,13 +27589,14 @@
|
|
|
27562
27589
|
*/
|
|
27563
27590
|
function createTimeoutSystemMessage(extraInstructions) {
|
|
27564
27591
|
return _spaceTrim.spaceTrim((block) => `
|
|
27565
|
-
Timeout scheduling
|
|
27566
|
-
|
|
27567
|
-
-
|
|
27568
|
-
-
|
|
27569
|
-
-
|
|
27570
|
-
-
|
|
27571
|
-
-
|
|
27592
|
+
## Timeout scheduling
|
|
27593
|
+
|
|
27594
|
+
- Use \`set_timeout\` to wake this same chat thread in the future.
|
|
27595
|
+
- Use \`list_timeouts\` to review timeout ids/details across all chats for the same user+agent scope.
|
|
27596
|
+
- \`cancel_timeout\` accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
|
|
27597
|
+
- Use \`update_timeout\` to pause/resume, edit next run, edit recurrence, or update timeout payload details.
|
|
27598
|
+
- When one timeout elapses, you will receive a new user-like message that explicitly says it is a timeout wake-up and includes the \`timeoutId\`.
|
|
27599
|
+
- Do not claim a timer was set or cancelled unless the tool confirms it.
|
|
27572
27600
|
${block(extraInstructions)}
|
|
27573
27601
|
`);
|
|
27574
27602
|
}
|
|
@@ -28668,10 +28696,11 @@
|
|
|
28668
28696
|
useUserLocation: content || true,
|
|
28669
28697
|
},
|
|
28670
28698
|
}, _spaceTrim.spaceTrim((block) => `
|
|
28671
|
-
User location
|
|
28672
|
-
|
|
28673
|
-
-
|
|
28674
|
-
-
|
|
28699
|
+
## User location
|
|
28700
|
+
|
|
28701
|
+
- Use \`${GET_USER_LOCATION_TOOL_NAME}\` only when location is needed for a better answer.
|
|
28702
|
+
- If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
|
|
28703
|
+
- Do not invent coordinates or local facts when location is unavailable.
|
|
28675
28704
|
${block(extraInstructions)}
|
|
28676
28705
|
`));
|
|
28677
28706
|
}
|
|
@@ -32771,7 +32800,7 @@
|
|
|
32771
32800
|
if (examples.length === 0) {
|
|
32772
32801
|
return null;
|
|
32773
32802
|
}
|
|
32774
|
-
return
|
|
32803
|
+
return `## Sample of communication with the agent:\n\n${examples.join('\n\n')}`;
|
|
32775
32804
|
}
|
|
32776
32805
|
/**
|
|
32777
32806
|
* Collects the individual lines used in the example interaction section.
|
|
@@ -32787,11 +32816,11 @@
|
|
|
32787
32816
|
const examples = [];
|
|
32788
32817
|
const initialMessage = (_a = parseResult.commitments.find((commitment) => commitment.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
|
|
32789
32818
|
if (initialMessage) {
|
|
32790
|
-
examples.push(
|
|
32819
|
+
examples.push(`**Agent:**\n${initialMessage}`);
|
|
32791
32820
|
}
|
|
32792
32821
|
if (samples && samples.length > 0) {
|
|
32793
32822
|
for (const sample of samples) {
|
|
32794
|
-
examples.push(
|
|
32823
|
+
examples.push(`**User:** ${sample.question}\n\n**Agent:**\n${sample.answer}`);
|
|
32795
32824
|
}
|
|
32796
32825
|
}
|
|
32797
32826
|
return examples;
|