@promptbook/remote-server 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
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
* @generated
|
|
51
51
|
* @see https://github.com/webgptorg/promptbook
|
|
52
52
|
*/
|
|
53
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
53
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-59';
|
|
54
54
|
/**
|
|
55
55
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
56
56
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -11350,6 +11350,49 @@
|
|
|
11350
11350
|
return this.appendToSystemMessage(requirements, commentSection);
|
|
11351
11351
|
}
|
|
11352
11352
|
}
|
|
11353
|
+
/**
|
|
11354
|
+
* Helper method to append a bullet point to an existing `## SectionTitle` section in the system
|
|
11355
|
+
* message, or to create a new section when it does not yet exist.
|
|
11356
|
+
*
|
|
11357
|
+
* Handles the case where the same commitment type appears multiple times in the book source and
|
|
11358
|
+
* all entries should be grouped under one shared heading rather than emitting a duplicate block.
|
|
11359
|
+
*
|
|
11360
|
+
* @param requirements - Current model requirements.
|
|
11361
|
+
* @param sectionTitle - Section title without the `##` prefix.
|
|
11362
|
+
* @param bulletContent - Bullet content without the leading `- ` prefix.
|
|
11363
|
+
* @returns Requirements with the bullet appended to the section.
|
|
11364
|
+
*/
|
|
11365
|
+
appendBulletPointToSection(requirements, sectionTitle, bulletContent) {
|
|
11366
|
+
const sectionHeader = `## ${sectionTitle}`;
|
|
11367
|
+
const bullet = `- ${bulletContent}`;
|
|
11368
|
+
if (requirements.systemMessage.includes(sectionHeader)) {
|
|
11369
|
+
// Append bullet to end of existing section, before the next h2 heading or end of message
|
|
11370
|
+
const newSystemMessage = requirements.systemMessage.replace(new RegExp(`(## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n\\n)([\\s\\S]*?)(?=\\n\\n##|$)`), `$1$2\n${bullet}`);
|
|
11371
|
+
return { ...requirements, systemMessage: newSystemMessage };
|
|
11372
|
+
}
|
|
11373
|
+
return this.appendToSystemMessage(requirements, `${sectionHeader}\n\n${bullet}`, '\n\n');
|
|
11374
|
+
}
|
|
11375
|
+
/**
|
|
11376
|
+
* Helper method to replace an existing `## SectionTitle` section in the system message, or to
|
|
11377
|
+
* append a new one when the section does not yet exist.
|
|
11378
|
+
*
|
|
11379
|
+
* Use this when a commitment type can appear multiple times and each subsequent occurrence should
|
|
11380
|
+
* update the single shared section rather than appending a duplicate block.
|
|
11381
|
+
*
|
|
11382
|
+
* @param requirements - Current model requirements.
|
|
11383
|
+
* @param sectionTitle - Section title without the `##` prefix.
|
|
11384
|
+
* @param sectionContent - Full section content including the `## Title` header line.
|
|
11385
|
+
* @returns Requirements with the section replaced or appended.
|
|
11386
|
+
*/
|
|
11387
|
+
replaceOrCreateSection(requirements, sectionTitle, sectionContent) {
|
|
11388
|
+
const sectionHeader = `## ${sectionTitle}`;
|
|
11389
|
+
if (requirements.systemMessage.includes(sectionHeader)) {
|
|
11390
|
+
// Replace all text from the heading until the next h2 heading or end of message
|
|
11391
|
+
const newSystemMessage = requirements.systemMessage.replace(new RegExp(`## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), sectionContent);
|
|
11392
|
+
return { ...requirements, systemMessage: newSystemMessage };
|
|
11393
|
+
}
|
|
11394
|
+
return this.appendToSystemMessage(requirements, sectionContent, '\n\n');
|
|
11395
|
+
}
|
|
11353
11396
|
/**
|
|
11354
11397
|
* Gets tool function implementations provided by this commitment
|
|
11355
11398
|
*
|
|
@@ -11811,20 +11854,16 @@
|
|
|
11811
11854
|
if (!trimmedContent) {
|
|
11812
11855
|
return requirements;
|
|
11813
11856
|
}
|
|
11814
|
-
//
|
|
11857
|
+
// Store the entry in metadata for debugging and inspection
|
|
11815
11858
|
const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
11816
|
-
// Merge the new dictionary entry with existing entries
|
|
11817
11859
|
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
11818
|
-
// Store the merged dictionary in metadata for debugging and inspection
|
|
11819
11860
|
const updatedMetadata = {
|
|
11820
11861
|
...requirements._metadata,
|
|
11821
11862
|
DICTIONARY: mergedDictionary,
|
|
11822
11863
|
};
|
|
11823
|
-
//
|
|
11824
|
-
// Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
|
|
11825
|
-
const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
|
|
11864
|
+
// Append each dictionary entry as a bullet point under ## Dictionary
|
|
11826
11865
|
return {
|
|
11827
|
-
...this.
|
|
11866
|
+
...this.appendBulletPointToSection(requirements, 'Dictionary', trimmedContent),
|
|
11828
11867
|
_metadata: updatedMetadata,
|
|
11829
11868
|
};
|
|
11830
11869
|
}
|
|
@@ -12327,10 +12366,10 @@
|
|
|
12327
12366
|
if (!trimmedContent) {
|
|
12328
12367
|
return requirements;
|
|
12329
12368
|
}
|
|
12330
|
-
// Add goal to the system message
|
|
12331
|
-
const goalSection =
|
|
12369
|
+
// Add goal as a proper h2 section to the system message
|
|
12370
|
+
const goalSection = `## Goal\n\n${trimmedContent}`;
|
|
12332
12371
|
const requirementsWithGoal = this.appendToSystemMessage(requirements, goalSection, '\n\n');
|
|
12333
|
-
return this.appendToPromptSuffix(requirementsWithGoal,
|
|
12372
|
+
return this.appendToPromptSuffix(requirementsWithGoal, trimmedContent);
|
|
12334
12373
|
}
|
|
12335
12374
|
}
|
|
12336
12375
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -12850,11 +12889,8 @@
|
|
|
12850
12889
|
if (!trimmedContent) {
|
|
12851
12890
|
return requirements;
|
|
12852
12891
|
}
|
|
12853
|
-
// Add language
|
|
12854
|
-
const languageSection =
|
|
12855
|
-
${block(trimmedContent)}
|
|
12856
|
-
<- You are speaking these languages in your responses to the user.
|
|
12857
|
-
`));
|
|
12892
|
+
// Add language as a bullet under a ## Language section
|
|
12893
|
+
const languageSection = `## Language\n\n- Your language is ${trimmedContent}`;
|
|
12858
12894
|
return this.appendToSystemMessage(requirements, languageSection, '\n\n');
|
|
12859
12895
|
}
|
|
12860
12896
|
}
|
|
@@ -12898,15 +12934,16 @@
|
|
|
12898
12934
|
*/
|
|
12899
12935
|
function createMemorySystemMessage(extraInstructions) {
|
|
12900
12936
|
return _spaceTrim.spaceTrim((block) => `
|
|
12901
|
-
Memory
|
|
12902
|
-
|
|
12903
|
-
-
|
|
12904
|
-
-
|
|
12905
|
-
-
|
|
12906
|
-
-
|
|
12907
|
-
-
|
|
12908
|
-
-
|
|
12909
|
-
-
|
|
12937
|
+
## Memory
|
|
12938
|
+
|
|
12939
|
+
- Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
|
|
12940
|
+
- You can use persistent user memory tools.
|
|
12941
|
+
- Use \`${MemoryToolNames.retrieve}\` to load relevant memory before answering.
|
|
12942
|
+
- Use \`${MemoryToolNames.store}\` to save stable user-specific facts that improve future help.
|
|
12943
|
+
- Use \`${MemoryToolNames.update}\` to refresh an existing memory when the content changes.
|
|
12944
|
+
- Use \`${MemoryToolNames.delete}\` to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
|
|
12945
|
+
- Store concise memory items and avoid duplicates.
|
|
12946
|
+
- Never claim memory was saved or loaded unless the tool confirms it.
|
|
12910
12947
|
${block(extraInstructions)}
|
|
12911
12948
|
`);
|
|
12912
12949
|
}
|
|
@@ -13828,10 +13865,8 @@
|
|
|
13828
13865
|
if (!trimmedContent) {
|
|
13829
13866
|
return requirements;
|
|
13830
13867
|
}
|
|
13831
|
-
// Create message section for system message
|
|
13832
|
-
const messageSection = `Previous Message: ${trimmedContent}`;
|
|
13833
13868
|
// Messages represent conversation history and should be included for context
|
|
13834
|
-
return this.
|
|
13869
|
+
return this.appendBulletPointToSection(requirements, 'Previous messages', trimmedContent);
|
|
13835
13870
|
}
|
|
13836
13871
|
}
|
|
13837
13872
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -18625,10 +18660,9 @@
|
|
|
18625
18660
|
if (!trimmedContent) {
|
|
18626
18661
|
return requirements;
|
|
18627
18662
|
}
|
|
18628
|
-
//
|
|
18629
|
-
const
|
|
18630
|
-
|
|
18631
|
-
return this.appendToPromptSuffix(requirementsWithRule, ruleSection);
|
|
18663
|
+
// Group all rules under a single ## Rules section as bullet points
|
|
18664
|
+
const requirementsWithRule = this.appendBulletPointToSection(requirements, 'Rules', trimmedContent);
|
|
18665
|
+
return this.appendToPromptSuffix(requirementsWithRule, `- ${trimmedContent}`);
|
|
18632
18666
|
}
|
|
18633
18667
|
}
|
|
18634
18668
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -18864,10 +18898,8 @@
|
|
|
18864
18898
|
if (!trimmedContent) {
|
|
18865
18899
|
return requirements;
|
|
18866
18900
|
}
|
|
18867
|
-
// Create scenario section for system message
|
|
18868
|
-
const scenarioSection = `Scenario: ${trimmedContent}`;
|
|
18869
18901
|
// Scenarios provide important contextual information that affects behavior
|
|
18870
|
-
return this.
|
|
18902
|
+
return this.appendBulletPointToSection(requirements, 'Scenarios', trimmedContent);
|
|
18871
18903
|
}
|
|
18872
18904
|
}
|
|
18873
18905
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -19250,8 +19282,8 @@
|
|
|
19250
19282
|
* @private
|
|
19251
19283
|
*/
|
|
19252
19284
|
const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
|
|
19253
|
-
'-
|
|
19254
|
-
'-
|
|
19285
|
+
'- If a teammate is relevant to the request, consult that teammate using the matching tool.',
|
|
19286
|
+
'- Do not ask the user for information that a listed teammate can provide directly.',
|
|
19255
19287
|
];
|
|
19256
19288
|
/**
|
|
19257
19289
|
* Constant for remote agents by Url.
|
|
@@ -19379,7 +19411,7 @@
|
|
|
19379
19411
|
toolName: entry.toolName,
|
|
19380
19412
|
});
|
|
19381
19413
|
}
|
|
19382
|
-
const teamSystemMessage = this.createSystemMessageSection('Teammates
|
|
19414
|
+
const teamSystemMessage = this.createSystemMessageSection('Teammates', buildTeamSystemMessageBody(teamEntries));
|
|
19383
19415
|
return this.appendToSystemMessage({
|
|
19384
19416
|
...requirements,
|
|
19385
19417
|
tools: updatedTools,
|
|
@@ -19869,36 +19901,38 @@
|
|
|
19869
19901
|
switch (type) {
|
|
19870
19902
|
case 'USE TIME':
|
|
19871
19903
|
return _spaceTrim.spaceTrim((block) => `
|
|
19872
|
-
Time and date context
|
|
19873
|
-
|
|
19874
|
-
-
|
|
19904
|
+
## Time and date context
|
|
19905
|
+
|
|
19906
|
+
- It is ${moment__default["default"]().format('MMMM YYYY')} now.
|
|
19907
|
+
- If you need more precise current time information, use the tool \`get_current_time\`.
|
|
19875
19908
|
${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
|
|
19876
19909
|
`);
|
|
19877
19910
|
case 'USE BROWSER':
|
|
19878
19911
|
return _spaceTrim.spaceTrim((block) => `
|
|
19879
|
-
|
|
19880
|
-
|
|
19881
|
-
-
|
|
19882
|
-
|
|
19912
|
+
## Browser
|
|
19913
|
+
|
|
19914
|
+
- Use \`fetch_url_content\` to retrieve content from specific URLs (webpages or documents) using scrapers.
|
|
19915
|
+
- Use \`run_browser\` for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
|
|
19916
|
+
- When you need to know information from a specific website or document, use the tools provided.
|
|
19883
19917
|
${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
|
|
19884
19918
|
`);
|
|
19885
19919
|
case 'USE SEARCH ENGINE':
|
|
19886
19920
|
return _spaceTrim.spaceTrim((block) => `
|
|
19887
|
-
|
|
19888
|
-
|
|
19889
|
-
-
|
|
19890
|
-
-
|
|
19891
|
-
-
|
|
19892
|
-
-
|
|
19921
|
+
## Web Search
|
|
19922
|
+
|
|
19923
|
+
- Use \`web_search\` to find up-to-date information or facts.
|
|
19924
|
+
- When you need to know some information from the internet, use the search tool provided.
|
|
19925
|
+
- Do not make up information when you can search for it.
|
|
19926
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
19893
19927
|
${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
|
|
19894
19928
|
`);
|
|
19895
19929
|
case 'USE DEEPSEARCH':
|
|
19896
19930
|
return _spaceTrim.spaceTrim((block) => `
|
|
19897
|
-
|
|
19898
|
-
|
|
19899
|
-
-
|
|
19900
|
-
-
|
|
19901
|
-
-
|
|
19931
|
+
## Deep Research
|
|
19932
|
+
|
|
19933
|
+
- Use \`deep_search\` for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
|
|
19934
|
+
- Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
|
|
19935
|
+
- Do not pretend you cannot research current information when this tool is available.
|
|
19902
19936
|
${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
|
|
19903
19937
|
`);
|
|
19904
19938
|
}
|
|
@@ -20228,96 +20262,6 @@
|
|
|
20228
20262
|
}
|
|
20229
20263
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
20230
20264
|
|
|
20231
|
-
/**
|
|
20232
|
-
* Base Google Calendar API URL.
|
|
20233
|
-
*
|
|
20234
|
-
* @private constant of callGoogleCalendarApi
|
|
20235
|
-
*/
|
|
20236
|
-
const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
|
|
20237
|
-
/**
|
|
20238
|
-
* Runs one Google Calendar API request and parses JSON response payload.
|
|
20239
|
-
*
|
|
20240
|
-
* @private function of UseCalendarCommitmentDefinition
|
|
20241
|
-
*/
|
|
20242
|
-
async function callGoogleCalendarApi(accessToken, options) {
|
|
20243
|
-
const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
|
|
20244
|
-
if (options.query) {
|
|
20245
|
-
for (const [key, value] of Object.entries(options.query)) {
|
|
20246
|
-
if (value && value.trim()) {
|
|
20247
|
-
url.searchParams.set(key, value);
|
|
20248
|
-
}
|
|
20249
|
-
}
|
|
20250
|
-
}
|
|
20251
|
-
const response = await fetch(url.toString(), {
|
|
20252
|
-
method: options.method,
|
|
20253
|
-
headers: {
|
|
20254
|
-
Authorization: `Bearer ${accessToken}`,
|
|
20255
|
-
Accept: 'application/json',
|
|
20256
|
-
'Content-Type': 'application/json',
|
|
20257
|
-
},
|
|
20258
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
20259
|
-
});
|
|
20260
|
-
const textPayload = await response.text();
|
|
20261
|
-
const parsedPayload = tryParseJson$2(textPayload);
|
|
20262
|
-
if (options.allowNotFound && response.status === 404) {
|
|
20263
|
-
return null;
|
|
20264
|
-
}
|
|
20265
|
-
if (!response.ok) {
|
|
20266
|
-
throw new Error(_spaceTrim.spaceTrim(`
|
|
20267
|
-
Google Calendar API request failed (${response.status} ${response.statusText}):
|
|
20268
|
-
${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
|
|
20269
|
-
`));
|
|
20270
|
-
}
|
|
20271
|
-
return parsedPayload;
|
|
20272
|
-
}
|
|
20273
|
-
/**
|
|
20274
|
-
* Parses raw text into JSON when possible.
|
|
20275
|
-
*
|
|
20276
|
-
* @private function of callGoogleCalendarApi
|
|
20277
|
-
*/
|
|
20278
|
-
function tryParseJson$2(rawText) {
|
|
20279
|
-
if (!rawText.trim()) {
|
|
20280
|
-
return {};
|
|
20281
|
-
}
|
|
20282
|
-
try {
|
|
20283
|
-
return JSON.parse(rawText);
|
|
20284
|
-
}
|
|
20285
|
-
catch (_a) {
|
|
20286
|
-
return rawText;
|
|
20287
|
-
}
|
|
20288
|
-
}
|
|
20289
|
-
/**
|
|
20290
|
-
* Extracts a user-friendly Google Calendar API error message.
|
|
20291
|
-
*
|
|
20292
|
-
* @private function of callGoogleCalendarApi
|
|
20293
|
-
*/
|
|
20294
|
-
function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
|
|
20295
|
-
if (parsedPayload && typeof parsedPayload === 'object') {
|
|
20296
|
-
const payload = parsedPayload;
|
|
20297
|
-
const errorPayload = payload.error;
|
|
20298
|
-
if (errorPayload && typeof errorPayload === 'object') {
|
|
20299
|
-
const normalizedErrorPayload = errorPayload;
|
|
20300
|
-
const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
|
|
20301
|
-
const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
|
|
20302
|
-
const flattenedErrors = errors
|
|
20303
|
-
.map((errorEntry) => {
|
|
20304
|
-
if (!errorEntry || typeof errorEntry !== 'object') {
|
|
20305
|
-
return '';
|
|
20306
|
-
}
|
|
20307
|
-
const normalizedErrorEntry = errorEntry;
|
|
20308
|
-
const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
|
|
20309
|
-
const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
|
|
20310
|
-
return [detailMessage, reason].filter(Boolean).join(' | ');
|
|
20311
|
-
})
|
|
20312
|
-
.filter(Boolean);
|
|
20313
|
-
if (message || flattenedErrors.length > 0) {
|
|
20314
|
-
return [message, ...flattenedErrors].filter(Boolean).join(' | ');
|
|
20315
|
-
}
|
|
20316
|
-
}
|
|
20317
|
-
}
|
|
20318
|
-
return fallbackText || 'Unknown Google Calendar API error';
|
|
20319
|
-
}
|
|
20320
|
-
|
|
20321
20265
|
/**
|
|
20322
20266
|
* Hostnames accepted for Google Calendar references.
|
|
20323
20267
|
*
|
|
@@ -20499,6 +20443,96 @@
|
|
|
20499
20443
|
}
|
|
20500
20444
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
20501
20445
|
|
|
20446
|
+
/**
|
|
20447
|
+
* Base Google Calendar API URL.
|
|
20448
|
+
*
|
|
20449
|
+
* @private constant of callGoogleCalendarApi
|
|
20450
|
+
*/
|
|
20451
|
+
const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
|
|
20452
|
+
/**
|
|
20453
|
+
* Runs one Google Calendar API request and parses JSON response payload.
|
|
20454
|
+
*
|
|
20455
|
+
* @private function of UseCalendarCommitmentDefinition
|
|
20456
|
+
*/
|
|
20457
|
+
async function callGoogleCalendarApi(accessToken, options) {
|
|
20458
|
+
const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
|
|
20459
|
+
if (options.query) {
|
|
20460
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
20461
|
+
if (value && value.trim()) {
|
|
20462
|
+
url.searchParams.set(key, value);
|
|
20463
|
+
}
|
|
20464
|
+
}
|
|
20465
|
+
}
|
|
20466
|
+
const response = await fetch(url.toString(), {
|
|
20467
|
+
method: options.method,
|
|
20468
|
+
headers: {
|
|
20469
|
+
Authorization: `Bearer ${accessToken}`,
|
|
20470
|
+
Accept: 'application/json',
|
|
20471
|
+
'Content-Type': 'application/json',
|
|
20472
|
+
},
|
|
20473
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
20474
|
+
});
|
|
20475
|
+
const textPayload = await response.text();
|
|
20476
|
+
const parsedPayload = tryParseJson$2(textPayload);
|
|
20477
|
+
if (options.allowNotFound && response.status === 404) {
|
|
20478
|
+
return null;
|
|
20479
|
+
}
|
|
20480
|
+
if (!response.ok) {
|
|
20481
|
+
throw new Error(_spaceTrim.spaceTrim(`
|
|
20482
|
+
Google Calendar API request failed (${response.status} ${response.statusText}):
|
|
20483
|
+
${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
|
|
20484
|
+
`));
|
|
20485
|
+
}
|
|
20486
|
+
return parsedPayload;
|
|
20487
|
+
}
|
|
20488
|
+
/**
|
|
20489
|
+
* Parses raw text into JSON when possible.
|
|
20490
|
+
*
|
|
20491
|
+
* @private function of callGoogleCalendarApi
|
|
20492
|
+
*/
|
|
20493
|
+
function tryParseJson$2(rawText) {
|
|
20494
|
+
if (!rawText.trim()) {
|
|
20495
|
+
return {};
|
|
20496
|
+
}
|
|
20497
|
+
try {
|
|
20498
|
+
return JSON.parse(rawText);
|
|
20499
|
+
}
|
|
20500
|
+
catch (_a) {
|
|
20501
|
+
return rawText;
|
|
20502
|
+
}
|
|
20503
|
+
}
|
|
20504
|
+
/**
|
|
20505
|
+
* Extracts a user-friendly Google Calendar API error message.
|
|
20506
|
+
*
|
|
20507
|
+
* @private function of callGoogleCalendarApi
|
|
20508
|
+
*/
|
|
20509
|
+
function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
|
|
20510
|
+
if (parsedPayload && typeof parsedPayload === 'object') {
|
|
20511
|
+
const payload = parsedPayload;
|
|
20512
|
+
const errorPayload = payload.error;
|
|
20513
|
+
if (errorPayload && typeof errorPayload === 'object') {
|
|
20514
|
+
const normalizedErrorPayload = errorPayload;
|
|
20515
|
+
const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
|
|
20516
|
+
const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
|
|
20517
|
+
const flattenedErrors = errors
|
|
20518
|
+
.map((errorEntry) => {
|
|
20519
|
+
if (!errorEntry || typeof errorEntry !== 'object') {
|
|
20520
|
+
return '';
|
|
20521
|
+
}
|
|
20522
|
+
const normalizedErrorEntry = errorEntry;
|
|
20523
|
+
const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
|
|
20524
|
+
const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
|
|
20525
|
+
return [detailMessage, reason].filter(Boolean).join(' | ');
|
|
20526
|
+
})
|
|
20527
|
+
.filter(Boolean);
|
|
20528
|
+
if (message || flattenedErrors.length > 0) {
|
|
20529
|
+
return [message, ...flattenedErrors].filter(Boolean).join(' | ');
|
|
20530
|
+
}
|
|
20531
|
+
}
|
|
20532
|
+
}
|
|
20533
|
+
return fallbackText || 'Unknown Google Calendar API error';
|
|
20534
|
+
}
|
|
20535
|
+
|
|
20502
20536
|
/**
|
|
20503
20537
|
* Wallet metadata used by USE CALENDAR when resolving Google Calendar credentials.
|
|
20504
20538
|
*
|
|
@@ -21399,18 +21433,20 @@
|
|
|
21399
21433
|
if (parsedCommitment.calendar) {
|
|
21400
21434
|
addConfiguredCalendarIfMissing(existingConfiguredCalendars, parsedCommitment.calendar);
|
|
21401
21435
|
}
|
|
21402
|
-
const
|
|
21403
|
-
? existingConfiguredCalendars
|
|
21404
|
-
|
|
21405
|
-
`- ${calendar.provider}: ${calendar.url}`,
|
|
21406
|
-
calendar.scopes.length > 0 ? ` scopes: ${calendar.scopes.join(', ')}` : '',
|
|
21407
|
-
]
|
|
21408
|
-
.filter(Boolean)
|
|
21409
|
-
.join('\n'))
|
|
21410
|
-
.join('\n')
|
|
21411
|
-
: '- Calendar is resolved from runtime context';
|
|
21436
|
+
const calendarBullets = existingConfiguredCalendars.length > 0
|
|
21437
|
+
? existingConfiguredCalendars.map((calendar) => `- ${calendar.provider}: ${calendar.url}`).join('\n')
|
|
21438
|
+
: '- Calendar is resolved from runtime context';
|
|
21412
21439
|
const extraInstructions = formatOptionalInstructionBlock('Calendar instructions', parsedCommitment.instructions);
|
|
21413
|
-
|
|
21440
|
+
const calendarSectionContent = _spaceTrim.spaceTrim((block) => `
|
|
21441
|
+
## Calendar
|
|
21442
|
+
|
|
21443
|
+
- 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.
|
|
21444
|
+
- Supported operations include read, create, update, delete, invite guests, and reminders.
|
|
21445
|
+
- Configured calendars:
|
|
21446
|
+
${block(calendarBullets)}
|
|
21447
|
+
${block(extraInstructions)}
|
|
21448
|
+
`);
|
|
21449
|
+
return this.replaceOrCreateSection({
|
|
21414
21450
|
...requirements,
|
|
21415
21451
|
tools: createUseCalendarTools(requirements.tools || []),
|
|
21416
21452
|
_metadata: {
|
|
@@ -21418,16 +21454,7 @@
|
|
|
21418
21454
|
useCalendar: true,
|
|
21419
21455
|
useCalendars: existingConfiguredCalendars,
|
|
21420
21456
|
},
|
|
21421
|
-
},
|
|
21422
|
-
Calendar tools:
|
|
21423
|
-
- You can inspect and manage events in configured calendars.
|
|
21424
|
-
- Supported operations include read, create, update, delete, invite guests, and reminders.
|
|
21425
|
-
- Configured calendars:
|
|
21426
|
-
${block(calendarsList)}
|
|
21427
|
-
- USE CALENDAR credentials are read from wallet records (ACCESS_TOKEN, service "${UseCalendarWallet.service}", key "${UseCalendarWallet.key}").
|
|
21428
|
-
- If credentials are missing, ask user to connect calendar credentials in host UI and/or add them to wallet.
|
|
21429
|
-
${block(extraInstructions)}
|
|
21430
|
-
`));
|
|
21457
|
+
}, 'Calendar', calendarSectionContent);
|
|
21431
21458
|
}
|
|
21432
21459
|
/**
|
|
21433
21460
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -21764,18 +21791,6 @@
|
|
|
21764
21791
|
* @private internal USE EMAIL constant
|
|
21765
21792
|
*/
|
|
21766
21793
|
const SEND_EMAIL_TOOL_NAME = 'send_email';
|
|
21767
|
-
/**
|
|
21768
|
-
* Wallet service used for SMTP credentials required by USE EMAIL.
|
|
21769
|
-
*
|
|
21770
|
-
* @private internal USE EMAIL constant
|
|
21771
|
-
*/
|
|
21772
|
-
const USE_EMAIL_SMTP_WALLET_SERVICE = 'smtp';
|
|
21773
|
-
/**
|
|
21774
|
-
* Wallet key used for SMTP credentials required by USE EMAIL.
|
|
21775
|
-
*
|
|
21776
|
-
* @private internal USE EMAIL constant
|
|
21777
|
-
*/
|
|
21778
|
-
const USE_EMAIL_SMTP_WALLET_KEY = 'use-email-smtp-credentials';
|
|
21779
21794
|
/**
|
|
21780
21795
|
* USE EMAIL commitment definition.
|
|
21781
21796
|
*
|
|
@@ -21834,31 +21849,41 @@
|
|
|
21834
21849
|
`);
|
|
21835
21850
|
}
|
|
21836
21851
|
applyToAgentModelRequirements(requirements, content) {
|
|
21852
|
+
var _a;
|
|
21837
21853
|
const parsedCommitment = parseUseEmailCommitmentContent(content);
|
|
21838
|
-
const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
|
|
21839
|
-
const senderInstruction = parsedCommitment.senderEmail
|
|
21840
|
-
? `- Default sender address from commitment: "${parsedCommitment.senderEmail}".`
|
|
21841
|
-
: '';
|
|
21842
21854
|
const updatedTools = addUseEmailTools(requirements.tools || []);
|
|
21843
|
-
|
|
21855
|
+
// Collect all configured sender emails across multiple USE EMAIL commitments
|
|
21856
|
+
const existingSenders = Array.isArray((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useEmailSenders)
|
|
21857
|
+
? [...requirements._metadata.useEmailSenders]
|
|
21858
|
+
: [];
|
|
21859
|
+
if (parsedCommitment.senderEmail && !existingSenders.includes(parsedCommitment.senderEmail)) {
|
|
21860
|
+
existingSenders.push(parsedCommitment.senderEmail);
|
|
21861
|
+
}
|
|
21862
|
+
const senderBullets = existingSenders.length > 0
|
|
21863
|
+
? existingSenders
|
|
21864
|
+
.map((email, index) => index === 0
|
|
21865
|
+
? `- Default sender address: "${email}".`
|
|
21866
|
+
: `- Additional sender address: "${email}".`)
|
|
21867
|
+
.join('\n')
|
|
21868
|
+
: '';
|
|
21869
|
+
const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
|
|
21870
|
+
const emailSectionContent = _spaceTrim.spaceTrim((block) => `
|
|
21871
|
+
## Emails
|
|
21872
|
+
|
|
21873
|
+
- Use \`${SEND_EMAIL_TOOL_NAME}\` to send outbound emails.
|
|
21874
|
+
${block(senderBullets)}
|
|
21875
|
+
${block(extraInstructions)}
|
|
21876
|
+
`);
|
|
21877
|
+
return this.replaceOrCreateSection({
|
|
21844
21878
|
...requirements,
|
|
21845
21879
|
tools: updatedTools,
|
|
21846
21880
|
_metadata: {
|
|
21847
21881
|
...requirements._metadata,
|
|
21848
21882
|
useEmail: true,
|
|
21849
21883
|
...(parsedCommitment.senderEmail ? { useEmailSender: parsedCommitment.senderEmail } : {}),
|
|
21884
|
+
useEmailSenders: existingSenders,
|
|
21850
21885
|
},
|
|
21851
|
-
},
|
|
21852
|
-
Email tool:
|
|
21853
|
-
- Use "${SEND_EMAIL_TOOL_NAME}" to send outbound emails.
|
|
21854
|
-
- Prefer \`message\` argument compatible with Promptbook \`Message\` type.
|
|
21855
|
-
- Include subject in \`message.metadata.subject\` (or use legacy \`subject\` argument).
|
|
21856
|
-
- USE EMAIL credentials are read from wallet records (ACCESS_TOKEN, service "${USE_EMAIL_SMTP_WALLET_SERVICE}", key "${USE_EMAIL_SMTP_WALLET_KEY}").
|
|
21857
|
-
- Wallet secret must contain SMTP credentials in JSON format with fields \`host\`, \`port\`, \`secure\`, \`username\`, \`password\`.
|
|
21858
|
-
- If credentials are missing, ask user to add wallet credentials.
|
|
21859
|
-
${block(senderInstruction)}
|
|
21860
|
-
${block(extraInstructions)}
|
|
21861
|
-
`));
|
|
21886
|
+
}, 'Emails', emailSectionContent);
|
|
21862
21887
|
}
|
|
21863
21888
|
/**
|
|
21864
21889
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -21894,13 +21919,13 @@
|
|
|
21894
21919
|
...existingTools,
|
|
21895
21920
|
{
|
|
21896
21921
|
name: SEND_EMAIL_TOOL_NAME,
|
|
21897
|
-
description: 'Send an outbound email
|
|
21922
|
+
description: 'Send an outbound email.',
|
|
21898
21923
|
parameters: {
|
|
21899
21924
|
type: 'object',
|
|
21900
21925
|
properties: {
|
|
21901
21926
|
message: {
|
|
21902
21927
|
type: 'object',
|
|
21903
|
-
description: '
|
|
21928
|
+
description: 'Email payload. Use metadata.subject for the subject line.',
|
|
21904
21929
|
},
|
|
21905
21930
|
to: {
|
|
21906
21931
|
type: 'string',
|
|
@@ -22004,13 +22029,14 @@
|
|
|
22004
22029
|
useImageGenerator: content || true,
|
|
22005
22030
|
},
|
|
22006
22031
|
}, _spaceTrim.spaceTrim((block) => `
|
|
22007
|
-
Image generation
|
|
22008
|
-
|
|
22009
|
-
-
|
|
22010
|
-
|
|
22011
|
-
|
|
22012
|
-
-
|
|
22013
|
-
-
|
|
22032
|
+
## Image generation
|
|
22033
|
+
|
|
22034
|
+
- You do not generate images directly and you do not call any image tool.
|
|
22035
|
+
- When the user asks for an image, include markdown notation in your message:
|
|
22036
|
+
\`\`
|
|
22037
|
+
- Keep \`<alt text>\` short and descriptive.
|
|
22038
|
+
- Keep \`<prompt>\` detailed so the generated image matches the request.
|
|
22039
|
+
- You can include normal explanatory text before and after the notation.
|
|
22014
22040
|
${block(extraInstructions)}
|
|
22015
22041
|
`));
|
|
22016
22042
|
}
|
|
@@ -22190,11 +22216,12 @@
|
|
|
22190
22216
|
usePopup: content || true,
|
|
22191
22217
|
},
|
|
22192
22218
|
}, _spaceTrim.spaceTrim((block) => `
|
|
22193
|
-
|
|
22194
|
-
|
|
22195
|
-
-
|
|
22219
|
+
## Popup
|
|
22220
|
+
|
|
22221
|
+
- You can open a popup window with a specific URL using the tool \`open_popup\`.
|
|
22222
|
+
- Use this when you want the user to see or interact with a specific website.
|
|
22196
22223
|
${block(extraInstructions)}
|
|
22197
|
-
|
|
22224
|
+
`));
|
|
22198
22225
|
}
|
|
22199
22226
|
/**
|
|
22200
22227
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -22368,11 +22395,12 @@
|
|
|
22368
22395
|
usePrivacy: content || true,
|
|
22369
22396
|
},
|
|
22370
22397
|
}, _spaceTrim.spaceTrim((block) => `
|
|
22371
|
-
Privacy
|
|
22372
|
-
|
|
22373
|
-
-
|
|
22374
|
-
-
|
|
22375
|
-
-
|
|
22398
|
+
## Privacy
|
|
22399
|
+
|
|
22400
|
+
- Use \`${TURN_PRIVACY_ON_TOOL_NAME}\` when the user asks for a private/sensitive conversation.
|
|
22401
|
+
- This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
|
|
22402
|
+
- Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
|
|
22403
|
+
- Do not claim that end-to-end encryption is implemented yet.
|
|
22376
22404
|
${block(extraInstructions)}
|
|
22377
22405
|
`));
|
|
22378
22406
|
}
|
|
@@ -23996,9 +24024,16 @@
|
|
|
23996
24024
|
}
|
|
23997
24025
|
const existingConfiguredProjects = normalizeConfiguredProjects((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useProjects);
|
|
23998
24026
|
addConfiguredProjectIfMissing(existingConfiguredProjects, parsedCommitment.repository);
|
|
23999
|
-
const repositoriesList = existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n');
|
|
24000
24027
|
const extraInstructions = formatOptionalInstructionBlock('Project instructions', parsedCommitment.instructions);
|
|
24001
|
-
|
|
24028
|
+
const sectionContent = _spaceTrim.spaceTrim((block) => `
|
|
24029
|
+
- You can inspect and edit configured GitHub repositories using project tools.
|
|
24030
|
+
- Configured repositories:
|
|
24031
|
+
${block(existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n'))}
|
|
24032
|
+
- When a repository is not obvious from context, pass \`repository\` in tool arguments explicitly.
|
|
24033
|
+
- If credentials are missing, ask the user to connect their GitHub account in the host UI.
|
|
24034
|
+
${block(extraInstructions)}
|
|
24035
|
+
`);
|
|
24036
|
+
return this.replaceOrCreateSection({
|
|
24002
24037
|
...requirements,
|
|
24003
24038
|
tools: createUseProjectTools(requirements.tools || []),
|
|
24004
24039
|
_metadata: {
|
|
@@ -24006,16 +24041,7 @@
|
|
|
24006
24041
|
useProject: true,
|
|
24007
24042
|
useProjects: existingConfiguredProjects,
|
|
24008
24043
|
},
|
|
24009
|
-
},
|
|
24010
|
-
Project tools:
|
|
24011
|
-
- You can inspect and edit configured GitHub repositories using project tools.
|
|
24012
|
-
- Configured repositories:
|
|
24013
|
-
${block(repositoriesList)}
|
|
24014
|
-
- When a repository is not obvious from context, pass "repository" in tool arguments explicitly.
|
|
24015
|
-
- USE PROJECT credentials are read from wallet records (ACCESS_TOKEN, service "${UseProjectWallet.service}", key "${UseProjectWallet.key}").
|
|
24016
|
-
- If credentials are missing, ask the user to connect credentials in host UI and/or add them to wallet.
|
|
24017
|
-
${block(extraInstructions)}
|
|
24018
|
-
`));
|
|
24044
|
+
}, 'GitHub repositories', sectionContent);
|
|
24019
24045
|
}
|
|
24020
24046
|
/**
|
|
24021
24047
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -24362,11 +24388,12 @@
|
|
|
24362
24388
|
useSpawn: content || true,
|
|
24363
24389
|
},
|
|
24364
24390
|
}, _spaceTrim.spaceTrim((block) => `
|
|
24365
|
-
Spawning agents
|
|
24366
|
-
|
|
24367
|
-
-
|
|
24368
|
-
-
|
|
24369
|
-
-
|
|
24391
|
+
## Spawning agents
|
|
24392
|
+
|
|
24393
|
+
- Use \`${SPAWN_AGENT_TOOL_NAME}\` only when user asks to create a persistent new agent.
|
|
24394
|
+
- Pass full agent source in \`source\`.
|
|
24395
|
+
- Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
|
|
24396
|
+
- Do not add unknown fields in tool arguments.
|
|
24370
24397
|
${block(extraInstructions)}
|
|
24371
24398
|
`));
|
|
24372
24399
|
}
|
|
@@ -24400,13 +24427,14 @@
|
|
|
24400
24427
|
*/
|
|
24401
24428
|
function createTimeoutSystemMessage(extraInstructions) {
|
|
24402
24429
|
return _spaceTrim.spaceTrim((block) => `
|
|
24403
|
-
Timeout scheduling
|
|
24404
|
-
|
|
24405
|
-
-
|
|
24406
|
-
-
|
|
24407
|
-
-
|
|
24408
|
-
-
|
|
24409
|
-
-
|
|
24430
|
+
## Timeout scheduling
|
|
24431
|
+
|
|
24432
|
+
- Use \`set_timeout\` to wake this same chat thread in the future.
|
|
24433
|
+
- Use \`list_timeouts\` to review timeout ids/details across all chats for the same user+agent scope.
|
|
24434
|
+
- \`cancel_timeout\` accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
|
|
24435
|
+
- Use \`update_timeout\` to pause/resume, edit next run, edit recurrence, or update timeout payload details.
|
|
24436
|
+
- 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\`.
|
|
24437
|
+
- Do not claim a timer was set or cancelled unless the tool confirms it.
|
|
24410
24438
|
${block(extraInstructions)}
|
|
24411
24439
|
`);
|
|
24412
24440
|
}
|
|
@@ -25506,10 +25534,11 @@
|
|
|
25506
25534
|
useUserLocation: content || true,
|
|
25507
25535
|
},
|
|
25508
25536
|
}, _spaceTrim.spaceTrim((block) => `
|
|
25509
|
-
User location
|
|
25510
|
-
|
|
25511
|
-
-
|
|
25512
|
-
-
|
|
25537
|
+
## User location
|
|
25538
|
+
|
|
25539
|
+
- Use \`${GET_USER_LOCATION_TOOL_NAME}\` only when location is needed for a better answer.
|
|
25540
|
+
- If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
|
|
25541
|
+
- Do not invent coordinates or local facts when location is unavailable.
|
|
25513
25542
|
${block(extraInstructions)}
|
|
25514
25543
|
`));
|
|
25515
25544
|
}
|
|
@@ -29750,7 +29779,7 @@
|
|
|
29750
29779
|
if (examples.length === 0) {
|
|
29751
29780
|
return null;
|
|
29752
29781
|
}
|
|
29753
|
-
return
|
|
29782
|
+
return `## Sample of communication with the agent:\n\n${examples.join('\n\n')}`;
|
|
29754
29783
|
}
|
|
29755
29784
|
/**
|
|
29756
29785
|
* Collects the individual lines used in the example interaction section.
|
|
@@ -29766,11 +29795,11 @@
|
|
|
29766
29795
|
const examples = [];
|
|
29767
29796
|
const initialMessage = (_a = parseResult.commitments.find((commitment) => commitment.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
|
|
29768
29797
|
if (initialMessage) {
|
|
29769
|
-
examples.push(
|
|
29798
|
+
examples.push(`**Agent:**\n${initialMessage}`);
|
|
29770
29799
|
}
|
|
29771
29800
|
if (samples && samples.length > 0) {
|
|
29772
29801
|
for (const sample of samples) {
|
|
29773
|
-
examples.push(
|
|
29802
|
+
examples.push(`**User:** ${sample.question}\n\n**Agent:**\n${sample.answer}`);
|
|
29774
29803
|
}
|
|
29775
29804
|
}
|
|
29776
29805
|
return examples;
|