@promptbook/browser 0.112.0-58 → 0.112.0-60

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 CHANGED
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-58';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-60';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1448,6 +1448,49 @@ class BaseCommitmentDefinition {
1448
1448
  return this.appendToSystemMessage(requirements, commentSection);
1449
1449
  }
1450
1450
  }
1451
+ /**
1452
+ * Helper method to append a bullet point to an existing `## SectionTitle` section in the system
1453
+ * message, or to create a new section when it does not yet exist.
1454
+ *
1455
+ * Handles the case where the same commitment type appears multiple times in the book source and
1456
+ * all entries should be grouped under one shared heading rather than emitting a duplicate block.
1457
+ *
1458
+ * @param requirements - Current model requirements.
1459
+ * @param sectionTitle - Section title without the `##` prefix.
1460
+ * @param bulletContent - Bullet content without the leading `- ` prefix.
1461
+ * @returns Requirements with the bullet appended to the section.
1462
+ */
1463
+ appendBulletPointToSection(requirements, sectionTitle, bulletContent) {
1464
+ const sectionHeader = `## ${sectionTitle}`;
1465
+ const bullet = `- ${bulletContent}`;
1466
+ if (requirements.systemMessage.includes(sectionHeader)) {
1467
+ // Append bullet to end of existing section, before the next h2 heading or end of message
1468
+ const newSystemMessage = requirements.systemMessage.replace(new RegExp(`(## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n\\n)([\\s\\S]*?)(?=\\n\\n##|$)`), `$1$2\n${bullet}`);
1469
+ return { ...requirements, systemMessage: newSystemMessage };
1470
+ }
1471
+ return this.appendToSystemMessage(requirements, `${sectionHeader}\n\n${bullet}`, '\n\n');
1472
+ }
1473
+ /**
1474
+ * Helper method to replace an existing `## SectionTitle` section in the system message, or to
1475
+ * append a new one when the section does not yet exist.
1476
+ *
1477
+ * Use this when a commitment type can appear multiple times and each subsequent occurrence should
1478
+ * update the single shared section rather than appending a duplicate block.
1479
+ *
1480
+ * @param requirements - Current model requirements.
1481
+ * @param sectionTitle - Section title without the `##` prefix.
1482
+ * @param sectionContent - Full section content including the `## Title` header line.
1483
+ * @returns Requirements with the section replaced or appended.
1484
+ */
1485
+ replaceOrCreateSection(requirements, sectionTitle, sectionContent) {
1486
+ const sectionHeader = `## ${sectionTitle}`;
1487
+ if (requirements.systemMessage.includes(sectionHeader)) {
1488
+ // Replace all text from the heading until the next h2 heading or end of message
1489
+ const newSystemMessage = requirements.systemMessage.replace(new RegExp(`## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), sectionContent);
1490
+ return { ...requirements, systemMessage: newSystemMessage };
1491
+ }
1492
+ return this.appendToSystemMessage(requirements, sectionContent, '\n\n');
1493
+ }
1451
1494
  /**
1452
1495
  * Gets tool function implementations provided by this commitment
1453
1496
  *
@@ -1927,20 +1970,16 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
1927
1970
  if (!trimmedContent) {
1928
1971
  return requirements;
1929
1972
  }
1930
- // Get existing dictionary entries from metadata
1973
+ // Store the entry in metadata for debugging and inspection
1931
1974
  const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
1932
- // Merge the new dictionary entry with existing entries
1933
1975
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
1934
- // Store the merged dictionary in metadata for debugging and inspection
1935
1976
  const updatedMetadata = {
1936
1977
  ...requirements._metadata,
1937
1978
  DICTIONARY: mergedDictionary,
1938
1979
  };
1939
- // Create the dictionary section for the system message
1940
- // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
1941
- const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
1980
+ // Append each dictionary entry as a bullet point under ## Dictionary
1942
1981
  return {
1943
- ...this.appendToSystemMessage(requirements, dictionarySection),
1982
+ ...this.appendBulletPointToSection(requirements, 'Dictionary', trimmedContent),
1944
1983
  _metadata: updatedMetadata,
1945
1984
  };
1946
1985
  }
@@ -6615,10 +6654,10 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
6615
6654
  if (!trimmedContent) {
6616
6655
  return requirements;
6617
6656
  }
6618
- // Add goal to the system message
6619
- const goalSection = `Goal: ${trimmedContent}`;
6657
+ // Add goal as a proper h2 section to the system message
6658
+ const goalSection = `## Goal\n\n${trimmedContent}`;
6620
6659
  const requirementsWithGoal = this.appendToSystemMessage(requirements, goalSection, '\n\n');
6621
- return this.appendToPromptSuffix(requirementsWithGoal, goalSection);
6660
+ return this.appendToPromptSuffix(requirementsWithGoal, trimmedContent);
6622
6661
  }
6623
6662
  }
6624
6663
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7138,11 +7177,8 @@ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
7138
7177
  if (!trimmedContent) {
7139
7178
  return requirements;
7140
7179
  }
7141
- // Add language rule to the system message
7142
- const languageSection = this.createSystemMessageSection('Language:', spaceTrim$1((block) => `
7143
- ${block(trimmedContent)}
7144
- <- You are speaking these languages in your responses to the user.
7145
- `));
7180
+ // Add language as a bullet under a ## Language section
7181
+ const languageSection = `## Language\n\n- Your language is ${trimmedContent}`;
7146
7182
  return this.appendToSystemMessage(requirements, languageSection, '\n\n');
7147
7183
  }
7148
7184
  }
@@ -7186,15 +7222,16 @@ const MemoryToolNames = {
7186
7222
  */
7187
7223
  function createMemorySystemMessage(extraInstructions) {
7188
7224
  return spaceTrim$1((block) => `
7189
- Memory:
7190
- - Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
7191
- - You can use persistent user memory tools.
7192
- - Use "${MemoryToolNames.retrieve}" to load relevant memory before answering.
7193
- - Use "${MemoryToolNames.store}" to save stable user-specific facts that improve future help.
7194
- - Use "${MemoryToolNames.update}" to refresh an existing memory when the content changes.
7195
- - Use "${MemoryToolNames.delete}" to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
7196
- - Store concise memory items and avoid duplicates.
7197
- - Never claim memory was saved or loaded unless the tool confirms it.
7225
+ ## Memory
7226
+
7227
+ - Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
7228
+ - You can use persistent user memory tools.
7229
+ - Use \`${MemoryToolNames.retrieve}\` to load relevant memory before answering.
7230
+ - Use \`${MemoryToolNames.store}\` to save stable user-specific facts that improve future help.
7231
+ - Use \`${MemoryToolNames.update}\` to refresh an existing memory when the content changes.
7232
+ - Use \`${MemoryToolNames.delete}\` to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
7233
+ - Store concise memory items and avoid duplicates.
7234
+ - Never claim memory was saved or loaded unless the tool confirms it.
7198
7235
  ${block(extraInstructions)}
7199
7236
  `);
7200
7237
  }
@@ -8116,10 +8153,8 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
8116
8153
  if (!trimmedContent) {
8117
8154
  return requirements;
8118
8155
  }
8119
- // Create message section for system message
8120
- const messageSection = `Previous Message: ${trimmedContent}`;
8121
8156
  // Messages represent conversation history and should be included for context
8122
- return this.appendToSystemMessage(requirements, messageSection, '\n\n');
8157
+ return this.appendBulletPointToSection(requirements, 'Previous messages', trimmedContent);
8123
8158
  }
8124
8159
  }
8125
8160
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -12913,10 +12948,9 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
12913
12948
  if (!trimmedContent) {
12914
12949
  return requirements;
12915
12950
  }
12916
- // Add rule to the system message
12917
- const ruleSection = `Rule: ${trimmedContent}`;
12918
- const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
12919
- return this.appendToPromptSuffix(requirementsWithRule, ruleSection);
12951
+ // Group all rules under a single ## Rules section as bullet points
12952
+ const requirementsWithRule = this.appendBulletPointToSection(requirements, 'Rules', trimmedContent);
12953
+ return this.appendToPromptSuffix(requirementsWithRule, `- ${trimmedContent}`);
12920
12954
  }
12921
12955
  }
12922
12956
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -13152,10 +13186,8 @@ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
13152
13186
  if (!trimmedContent) {
13153
13187
  return requirements;
13154
13188
  }
13155
- // Create scenario section for system message
13156
- const scenarioSection = `Scenario: ${trimmedContent}`;
13157
13189
  // Scenarios provide important contextual information that affects behavior
13158
- return this.appendToSystemMessage(requirements, scenarioSection, '\n\n');
13190
+ return this.appendBulletPointToSection(requirements, 'Scenarios', trimmedContent);
13159
13191
  }
13160
13192
  }
13161
13193
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -13538,8 +13570,8 @@ const teamToolTitles = {};
13538
13570
  * @private
13539
13571
  */
13540
13572
  const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
13541
- '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
13542
- '- Do not ask the user for information that a listed teammate can provide directly.',
13573
+ '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
13574
+ '- Do not ask the user for information that a listed teammate can provide directly.',
13543
13575
  ];
13544
13576
  /**
13545
13577
  * Constant for remote agents by Url.
@@ -13667,7 +13699,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
13667
13699
  toolName: entry.toolName,
13668
13700
  });
13669
13701
  }
13670
- const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamEntries));
13702
+ const teamSystemMessage = this.createSystemMessageSection('Teammates', buildTeamSystemMessageBody(teamEntries));
13671
13703
  return this.appendToSystemMessage({
13672
13704
  ...requirements,
13673
13705
  tools: updatedTools,
@@ -14157,36 +14189,38 @@ function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions
14157
14189
  switch (type) {
14158
14190
  case 'USE TIME':
14159
14191
  return spaceTrim$1((block) => `
14160
- Time and date context:
14161
- - It is ${moment().format('MMMM YYYY')} now.
14162
- - If you need more precise current time information, use the tool "get_current_time".
14192
+ ## Time and date context
14193
+
14194
+ - It is ${moment().format('MMMM YYYY')} now.
14195
+ - If you need more precise current time information, use the tool \`get_current_time\`.
14163
14196
  ${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
14164
14197
  `);
14165
14198
  case 'USE BROWSER':
14166
14199
  return spaceTrim$1((block) => `
14167
- You have access to browser tools to fetch and access content from the internet.
14168
- - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
14169
- - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
14170
- When you need to know information from a specific website or document, use the fetch_url_content tool.
14200
+ ## Browser
14201
+
14202
+ - Use \`fetch_url_content\` to retrieve content from specific URLs (webpages or documents) using scrapers.
14203
+ - Use \`run_browser\` for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
14204
+ - When you need to know information from a specific website or document, use the tools provided.
14171
14205
  ${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
14172
14206
  `);
14173
14207
  case 'USE SEARCH ENGINE':
14174
14208
  return spaceTrim$1((block) => `
14175
- Tool:
14176
- - You have access to the web search engine via the tool "web_search".
14177
- - Use it to find up-to-date information or facts that you don't know.
14178
- - When you need to know some information from the internet, use the tool provided to you.
14179
- - Do not make up information when you can search for it.
14180
- - Do not tell the user you cannot search for information, YOU CAN.
14209
+ ## Web Search
14210
+
14211
+ - Use \`web_search\` to find up-to-date information or facts.
14212
+ - When you need to know some information from the internet, use the search tool provided.
14213
+ - Do not make up information when you can search for it.
14214
+ - Do not tell the user you cannot search for information, YOU CAN.
14181
14215
  ${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
14182
14216
  `);
14183
14217
  case 'USE DEEPSEARCH':
14184
14218
  return spaceTrim$1((block) => `
14185
- Tool:
14186
- - You have access to DeepSearch via the tool "deep_search".
14187
- - Use it for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
14188
- - Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
14189
- - Do not pretend you cannot research current information when this tool is available.
14219
+ ## Deep Research
14220
+
14221
+ - Use \`deep_search\` for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
14222
+ - Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
14223
+ - Do not pretend you cannot research current information when this tool is available.
14190
14224
  ${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
14191
14225
  `);
14192
14226
  }
@@ -14516,96 +14550,6 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
14516
14550
  }
14517
14551
  // Note: [💞] Ignore a discrepancy between file name and entity name
14518
14552
 
14519
- /**
14520
- * Base Google Calendar API URL.
14521
- *
14522
- * @private constant of callGoogleCalendarApi
14523
- */
14524
- const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
14525
- /**
14526
- * Runs one Google Calendar API request and parses JSON response payload.
14527
- *
14528
- * @private function of UseCalendarCommitmentDefinition
14529
- */
14530
- async function callGoogleCalendarApi(accessToken, options) {
14531
- const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
14532
- if (options.query) {
14533
- for (const [key, value] of Object.entries(options.query)) {
14534
- if (value && value.trim()) {
14535
- url.searchParams.set(key, value);
14536
- }
14537
- }
14538
- }
14539
- const response = await fetch(url.toString(), {
14540
- method: options.method,
14541
- headers: {
14542
- Authorization: `Bearer ${accessToken}`,
14543
- Accept: 'application/json',
14544
- 'Content-Type': 'application/json',
14545
- },
14546
- body: options.body ? JSON.stringify(options.body) : undefined,
14547
- });
14548
- const textPayload = await response.text();
14549
- const parsedPayload = tryParseJson$2(textPayload);
14550
- if (options.allowNotFound && response.status === 404) {
14551
- return null;
14552
- }
14553
- if (!response.ok) {
14554
- throw new Error(spaceTrim$1(`
14555
- Google Calendar API request failed (${response.status} ${response.statusText}):
14556
- ${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
14557
- `));
14558
- }
14559
- return parsedPayload;
14560
- }
14561
- /**
14562
- * Parses raw text into JSON when possible.
14563
- *
14564
- * @private function of callGoogleCalendarApi
14565
- */
14566
- function tryParseJson$2(rawText) {
14567
- if (!rawText.trim()) {
14568
- return {};
14569
- }
14570
- try {
14571
- return JSON.parse(rawText);
14572
- }
14573
- catch (_a) {
14574
- return rawText;
14575
- }
14576
- }
14577
- /**
14578
- * Extracts a user-friendly Google Calendar API error message.
14579
- *
14580
- * @private function of callGoogleCalendarApi
14581
- */
14582
- function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
14583
- if (parsedPayload && typeof parsedPayload === 'object') {
14584
- const payload = parsedPayload;
14585
- const errorPayload = payload.error;
14586
- if (errorPayload && typeof errorPayload === 'object') {
14587
- const normalizedErrorPayload = errorPayload;
14588
- const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
14589
- const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
14590
- const flattenedErrors = errors
14591
- .map((errorEntry) => {
14592
- if (!errorEntry || typeof errorEntry !== 'object') {
14593
- return '';
14594
- }
14595
- const normalizedErrorEntry = errorEntry;
14596
- const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
14597
- const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
14598
- return [detailMessage, reason].filter(Boolean).join(' | ');
14599
- })
14600
- .filter(Boolean);
14601
- if (message || flattenedErrors.length > 0) {
14602
- return [message, ...flattenedErrors].filter(Boolean).join(' | ');
14603
- }
14604
- }
14605
- }
14606
- return fallbackText || 'Unknown Google Calendar API error';
14607
- }
14608
-
14609
14553
  /**
14610
14554
  * Hostnames accepted for Google Calendar references.
14611
14555
  *
@@ -14787,6 +14731,96 @@ function removeTokenFromLine(line, token) {
14787
14731
  }
14788
14732
  // Note: [💞] Ignore a discrepancy between file name and entity name
14789
14733
 
14734
+ /**
14735
+ * Base Google Calendar API URL.
14736
+ *
14737
+ * @private constant of callGoogleCalendarApi
14738
+ */
14739
+ const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
14740
+ /**
14741
+ * Runs one Google Calendar API request and parses JSON response payload.
14742
+ *
14743
+ * @private function of UseCalendarCommitmentDefinition
14744
+ */
14745
+ async function callGoogleCalendarApi(accessToken, options) {
14746
+ const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
14747
+ if (options.query) {
14748
+ for (const [key, value] of Object.entries(options.query)) {
14749
+ if (value && value.trim()) {
14750
+ url.searchParams.set(key, value);
14751
+ }
14752
+ }
14753
+ }
14754
+ const response = await fetch(url.toString(), {
14755
+ method: options.method,
14756
+ headers: {
14757
+ Authorization: `Bearer ${accessToken}`,
14758
+ Accept: 'application/json',
14759
+ 'Content-Type': 'application/json',
14760
+ },
14761
+ body: options.body ? JSON.stringify(options.body) : undefined,
14762
+ });
14763
+ const textPayload = await response.text();
14764
+ const parsedPayload = tryParseJson$2(textPayload);
14765
+ if (options.allowNotFound && response.status === 404) {
14766
+ return null;
14767
+ }
14768
+ if (!response.ok) {
14769
+ throw new Error(spaceTrim$1(`
14770
+ Google Calendar API request failed (${response.status} ${response.statusText}):
14771
+ ${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
14772
+ `));
14773
+ }
14774
+ return parsedPayload;
14775
+ }
14776
+ /**
14777
+ * Parses raw text into JSON when possible.
14778
+ *
14779
+ * @private function of callGoogleCalendarApi
14780
+ */
14781
+ function tryParseJson$2(rawText) {
14782
+ if (!rawText.trim()) {
14783
+ return {};
14784
+ }
14785
+ try {
14786
+ return JSON.parse(rawText);
14787
+ }
14788
+ catch (_a) {
14789
+ return rawText;
14790
+ }
14791
+ }
14792
+ /**
14793
+ * Extracts a user-friendly Google Calendar API error message.
14794
+ *
14795
+ * @private function of callGoogleCalendarApi
14796
+ */
14797
+ function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
14798
+ if (parsedPayload && typeof parsedPayload === 'object') {
14799
+ const payload = parsedPayload;
14800
+ const errorPayload = payload.error;
14801
+ if (errorPayload && typeof errorPayload === 'object') {
14802
+ const normalizedErrorPayload = errorPayload;
14803
+ const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
14804
+ const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
14805
+ const flattenedErrors = errors
14806
+ .map((errorEntry) => {
14807
+ if (!errorEntry || typeof errorEntry !== 'object') {
14808
+ return '';
14809
+ }
14810
+ const normalizedErrorEntry = errorEntry;
14811
+ const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
14812
+ const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
14813
+ return [detailMessage, reason].filter(Boolean).join(' | ');
14814
+ })
14815
+ .filter(Boolean);
14816
+ if (message || flattenedErrors.length > 0) {
14817
+ return [message, ...flattenedErrors].filter(Boolean).join(' | ');
14818
+ }
14819
+ }
14820
+ }
14821
+ return fallbackText || 'Unknown Google Calendar API error';
14822
+ }
14823
+
14790
14824
  /**
14791
14825
  * Wallet metadata used by USE CALENDAR when resolving Google Calendar credentials.
14792
14826
  *
@@ -15687,18 +15721,20 @@ class UseCalendarCommitmentDefinition extends BaseCommitmentDefinition {
15687
15721
  if (parsedCommitment.calendar) {
15688
15722
  addConfiguredCalendarIfMissing(existingConfiguredCalendars, parsedCommitment.calendar);
15689
15723
  }
15690
- const calendarsList = existingConfiguredCalendars.length > 0
15691
- ? existingConfiguredCalendars
15692
- .map((calendar) => [
15693
- `- ${calendar.provider}: ${calendar.url}`,
15694
- calendar.scopes.length > 0 ? ` scopes: ${calendar.scopes.join(', ')}` : '',
15695
- ]
15696
- .filter(Boolean)
15697
- .join('\n'))
15698
- .join('\n')
15699
- : '- Calendar is resolved from runtime context';
15724
+ const calendarBullets = existingConfiguredCalendars.length > 0
15725
+ ? existingConfiguredCalendars.map((calendar) => `- ${calendar.provider}: ${calendar.url}`).join('\n')
15726
+ : '- Calendar is resolved from runtime context';
15700
15727
  const extraInstructions = formatOptionalInstructionBlock('Calendar instructions', parsedCommitment.instructions);
15701
- return this.appendToSystemMessage({
15728
+ const calendarSectionContent = spaceTrim$1((block) => `
15729
+ ## Calendar
15730
+
15731
+ - 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.
15732
+ - Supported operations include read, create, update, delete, invite guests, and reminders.
15733
+ - Configured calendars:
15734
+ ${block(calendarBullets)}
15735
+ ${block(extraInstructions)}
15736
+ `);
15737
+ return this.replaceOrCreateSection({
15702
15738
  ...requirements,
15703
15739
  tools: createUseCalendarTools(requirements.tools || []),
15704
15740
  _metadata: {
@@ -15706,16 +15742,7 @@ class UseCalendarCommitmentDefinition extends BaseCommitmentDefinition {
15706
15742
  useCalendar: true,
15707
15743
  useCalendars: existingConfiguredCalendars,
15708
15744
  },
15709
- }, spaceTrim$1((block) => `
15710
- Calendar tools:
15711
- - You can inspect and manage events in configured calendars.
15712
- - Supported operations include read, create, update, delete, invite guests, and reminders.
15713
- - Configured calendars:
15714
- ${block(calendarsList)}
15715
- - USE CALENDAR credentials are read from wallet records (ACCESS_TOKEN, service "${UseCalendarWallet.service}", key "${UseCalendarWallet.key}").
15716
- - If credentials are missing, ask user to connect calendar credentials in host UI and/or add them to wallet.
15717
- ${block(extraInstructions)}
15718
- `));
15745
+ }, 'Calendar', calendarSectionContent);
15719
15746
  }
15720
15747
  /**
15721
15748
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -16052,18 +16079,6 @@ async function sendEmailViaBrowser(args, agentsServerUrl) {
16052
16079
  * @private internal USE EMAIL constant
16053
16080
  */
16054
16081
  const SEND_EMAIL_TOOL_NAME = 'send_email';
16055
- /**
16056
- * Wallet service used for SMTP credentials required by USE EMAIL.
16057
- *
16058
- * @private internal USE EMAIL constant
16059
- */
16060
- const USE_EMAIL_SMTP_WALLET_SERVICE = 'smtp';
16061
- /**
16062
- * Wallet key used for SMTP credentials required by USE EMAIL.
16063
- *
16064
- * @private internal USE EMAIL constant
16065
- */
16066
- const USE_EMAIL_SMTP_WALLET_KEY = 'use-email-smtp-credentials';
16067
16082
  /**
16068
16083
  * USE EMAIL commitment definition.
16069
16084
  *
@@ -16122,31 +16137,41 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
16122
16137
  `);
16123
16138
  }
16124
16139
  applyToAgentModelRequirements(requirements, content) {
16140
+ var _a;
16125
16141
  const parsedCommitment = parseUseEmailCommitmentContent(content);
16126
- const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
16127
- const senderInstruction = parsedCommitment.senderEmail
16128
- ? `- Default sender address from commitment: "${parsedCommitment.senderEmail}".`
16129
- : '';
16130
16142
  const updatedTools = addUseEmailTools(requirements.tools || []);
16131
- return this.appendToSystemMessage({
16143
+ // Collect all configured sender emails across multiple USE EMAIL commitments
16144
+ const existingSenders = Array.isArray((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useEmailSenders)
16145
+ ? [...requirements._metadata.useEmailSenders]
16146
+ : [];
16147
+ if (parsedCommitment.senderEmail && !existingSenders.includes(parsedCommitment.senderEmail)) {
16148
+ existingSenders.push(parsedCommitment.senderEmail);
16149
+ }
16150
+ const senderBullets = existingSenders.length > 0
16151
+ ? existingSenders
16152
+ .map((email, index) => index === 0
16153
+ ? `- Default sender address: "${email}".`
16154
+ : `- Additional sender address: "${email}".`)
16155
+ .join('\n')
16156
+ : '';
16157
+ const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
16158
+ const emailSectionContent = spaceTrim$1((block) => `
16159
+ ## Emails
16160
+
16161
+ - Use \`${SEND_EMAIL_TOOL_NAME}\` to send outbound emails.
16162
+ ${block(senderBullets)}
16163
+ ${block(extraInstructions)}
16164
+ `);
16165
+ return this.replaceOrCreateSection({
16132
16166
  ...requirements,
16133
16167
  tools: updatedTools,
16134
16168
  _metadata: {
16135
16169
  ...requirements._metadata,
16136
16170
  useEmail: true,
16137
16171
  ...(parsedCommitment.senderEmail ? { useEmailSender: parsedCommitment.senderEmail } : {}),
16172
+ useEmailSenders: existingSenders,
16138
16173
  },
16139
- }, spaceTrim$1((block) => `
16140
- Email tool:
16141
- - Use "${SEND_EMAIL_TOOL_NAME}" to send outbound emails.
16142
- - Prefer \`message\` argument compatible with Promptbook \`Message\` type.
16143
- - Include subject in \`message.metadata.subject\` (or use legacy \`subject\` argument).
16144
- - USE EMAIL credentials are read from wallet records (ACCESS_TOKEN, service "${USE_EMAIL_SMTP_WALLET_SERVICE}", key "${USE_EMAIL_SMTP_WALLET_KEY}").
16145
- - Wallet secret must contain SMTP credentials in JSON format with fields \`host\`, \`port\`, \`secure\`, \`username\`, \`password\`.
16146
- - If credentials are missing, ask user to add wallet credentials.
16147
- ${block(senderInstruction)}
16148
- ${block(extraInstructions)}
16149
- `));
16174
+ }, 'Emails', emailSectionContent);
16150
16175
  }
16151
16176
  /**
16152
16177
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -16182,13 +16207,13 @@ function addUseEmailTools(existingTools) {
16182
16207
  ...existingTools,
16183
16208
  {
16184
16209
  name: SEND_EMAIL_TOOL_NAME,
16185
- description: 'Send an outbound email through configured SMTP credentials. Prefer providing Message-like payload in `message`.',
16210
+ description: 'Send an outbound email.',
16186
16211
  parameters: {
16187
16212
  type: 'object',
16188
16213
  properties: {
16189
16214
  message: {
16190
16215
  type: 'object',
16191
- description: 'Preferred input payload compatible with Promptbook Message type. Use metadata.subject for subject line.',
16216
+ description: 'Email payload. Use metadata.subject for the subject line.',
16192
16217
  },
16193
16218
  to: {
16194
16219
  type: 'string',
@@ -16292,13 +16317,14 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
16292
16317
  useImageGenerator: content || true,
16293
16318
  },
16294
16319
  }, spaceTrim$1((block) => `
16295
- Image generation:
16296
- - You do not generate images directly and you do not call any image tool.
16297
- - When the user asks for an image, include markdown notation in your message:
16298
- \`![<alt text>](?image-prompt=<prompt>)\`
16299
- - Keep \`<alt text>\` short and descriptive.
16300
- - Keep \`<prompt>\` detailed so the generated image matches the request.
16301
- - You can include normal explanatory text before and after the notation.
16320
+ ## Image generation
16321
+
16322
+ - You do not generate images directly and you do not call any image tool.
16323
+ - When the user asks for an image, include markdown notation in your message:
16324
+ \`![<alt text>](?image-prompt=<prompt>)\`
16325
+ - Keep \`<alt text>\` short and descriptive.
16326
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
16327
+ - You can include normal explanatory text before and after the notation.
16302
16328
  ${block(extraInstructions)}
16303
16329
  `));
16304
16330
  }
@@ -16478,11 +16504,12 @@ class UsePopupCommitmentDefinition extends BaseCommitmentDefinition {
16478
16504
  usePopup: content || true,
16479
16505
  },
16480
16506
  }, spaceTrim$1((block) => `
16481
- Tool:
16482
- - You can open a popup window with a specific URL using the tool "open_popup".
16483
- - Use this when you want the user to see or interact with a specific website.
16507
+ ## Popup
16508
+
16509
+ - You can open a popup window with a specific URL using the tool \`open_popup\`.
16510
+ - Use this when you want the user to see or interact with a specific website.
16484
16511
  ${block(extraInstructions)}
16485
- `));
16512
+ `));
16486
16513
  }
16487
16514
  /**
16488
16515
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -16656,11 +16683,12 @@ class UsePrivacyCommitmentDefinition extends BaseCommitmentDefinition {
16656
16683
  usePrivacy: content || true,
16657
16684
  },
16658
16685
  }, spaceTrim$1((block) => `
16659
- Privacy mode:
16660
- - Use "${TURN_PRIVACY_ON_TOOL_NAME}" when the user asks for a private/sensitive conversation.
16661
- - This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
16662
- - Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
16663
- - Do not claim that end-to-end encryption is implemented yet.
16686
+ ## Privacy
16687
+
16688
+ - Use \`${TURN_PRIVACY_ON_TOOL_NAME}\` when the user asks for a private/sensitive conversation.
16689
+ - This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
16690
+ - Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
16691
+ - Do not claim that end-to-end encryption is implemented yet.
16664
16692
  ${block(extraInstructions)}
16665
16693
  `));
16666
16694
  }
@@ -18303,9 +18331,16 @@ class UseProjectCommitmentDefinition extends BaseCommitmentDefinition {
18303
18331
  }
18304
18332
  const existingConfiguredProjects = normalizeConfiguredProjects((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useProjects);
18305
18333
  addConfiguredProjectIfMissing(existingConfiguredProjects, parsedCommitment.repository);
18306
- const repositoriesList = existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n');
18307
18334
  const extraInstructions = formatOptionalInstructionBlock('Project instructions', parsedCommitment.instructions);
18308
- return this.appendToSystemMessage({
18335
+ const sectionContent = spaceTrim$1((block) => `
18336
+ - You can inspect and edit configured GitHub repositories using project tools.
18337
+ - Configured repositories:
18338
+ ${block(existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n'))}
18339
+ - When a repository is not obvious from context, pass \`repository\` in tool arguments explicitly.
18340
+ - If credentials are missing, ask the user to connect their GitHub account in the host UI.
18341
+ ${block(extraInstructions)}
18342
+ `);
18343
+ return this.replaceOrCreateSection({
18309
18344
  ...requirements,
18310
18345
  tools: createUseProjectTools(requirements.tools || []),
18311
18346
  _metadata: {
@@ -18313,16 +18348,7 @@ class UseProjectCommitmentDefinition extends BaseCommitmentDefinition {
18313
18348
  useProject: true,
18314
18349
  useProjects: existingConfiguredProjects,
18315
18350
  },
18316
- }, spaceTrim$1((block) => `
18317
- Project tools:
18318
- - You can inspect and edit configured GitHub repositories using project tools.
18319
- - Configured repositories:
18320
- ${block(repositoriesList)}
18321
- - When a repository is not obvious from context, pass "repository" in tool arguments explicitly.
18322
- - USE PROJECT credentials are read from wallet records (ACCESS_TOKEN, service "${UseProjectWallet.service}", key "${UseProjectWallet.key}").
18323
- - If credentials are missing, ask the user to connect credentials in host UI and/or add them to wallet.
18324
- ${block(extraInstructions)}
18325
- `));
18351
+ }, 'GitHub repositories', sectionContent);
18326
18352
  }
18327
18353
  /**
18328
18354
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -18669,11 +18695,12 @@ class UseSpawnCommitmentDefinition extends BaseCommitmentDefinition {
18669
18695
  useSpawn: content || true,
18670
18696
  },
18671
18697
  }, spaceTrim$1((block) => `
18672
- Spawning agents:
18673
- - Use "${SPAWN_AGENT_TOOL_NAME}" only when user asks to create a persistent new agent.
18674
- - Pass full agent source in \`source\`.
18675
- - Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
18676
- - Do not add unknown fields in tool arguments.
18698
+ ## Spawning agents
18699
+
18700
+ - Use \`${SPAWN_AGENT_TOOL_NAME}\` only when user asks to create a persistent new agent.
18701
+ - Pass full agent source in \`source\`.
18702
+ - Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
18703
+ - Do not add unknown fields in tool arguments.
18677
18704
  ${block(extraInstructions)}
18678
18705
  `));
18679
18706
  }
@@ -18707,13 +18734,14 @@ class UseSpawnCommitmentDefinition extends BaseCommitmentDefinition {
18707
18734
  */
18708
18735
  function createTimeoutSystemMessage(extraInstructions) {
18709
18736
  return spaceTrim$1((block) => `
18710
- Timeout scheduling:
18711
- - Use "set_timeout" to wake this same chat thread in the future.
18712
- - Use "list_timeouts" to review timeout ids/details across all chats for the same user+agent scope.
18713
- - "cancel_timeout" accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
18714
- - Use "update_timeout" to pause/resume, edit next run, edit recurrence, or update timeout payload details.
18715
- - 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\`.
18716
- - Do not claim a timer was set or cancelled unless the tool confirms it.
18737
+ ## Timeout scheduling
18738
+
18739
+ - Use \`set_timeout\` to wake this same chat thread in the future.
18740
+ - Use \`list_timeouts\` to review timeout ids/details across all chats for the same user+agent scope.
18741
+ - \`cancel_timeout\` accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
18742
+ - Use \`update_timeout\` to pause/resume, edit next run, edit recurrence, or update timeout payload details.
18743
+ - 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\`.
18744
+ - Do not claim a timer was set or cancelled unless the tool confirms it.
18717
18745
  ${block(extraInstructions)}
18718
18746
  `);
18719
18747
  }
@@ -19813,10 +19841,11 @@ class UseUserLocationCommitmentDefinition extends BaseCommitmentDefinition {
19813
19841
  useUserLocation: content || true,
19814
19842
  },
19815
19843
  }, spaceTrim$1((block) => `
19816
- User location:
19817
- - Use "${GET_USER_LOCATION_TOOL_NAME}" only when location is needed for a better answer.
19818
- - If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
19819
- - Do not invent coordinates or local facts when location is unavailable.
19844
+ ## User location
19845
+
19846
+ - Use \`${GET_USER_LOCATION_TOOL_NAME}\` only when location is needed for a better answer.
19847
+ - If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
19848
+ - Do not invent coordinates or local facts when location is unavailable.
19820
19849
  ${block(extraInstructions)}
19821
19850
  `));
19822
19851
  }
@@ -26979,7 +27008,7 @@ function createExampleInteractionsContent(parseResult, samples) {
26979
27008
  if (examples.length === 0) {
26980
27009
  return null;
26981
27010
  }
26982
- return `Example interaction:\n\n${examples.join('\n\n')}`;
27011
+ return `## Sample of communication with the agent:\n\n${examples.join('\n\n')}`;
26983
27012
  }
26984
27013
  /**
26985
27014
  * Collects the individual lines used in the example interaction section.
@@ -26995,11 +27024,11 @@ function collectExampleInteractionLines(parseResult, samples) {
26995
27024
  const examples = [];
26996
27025
  const initialMessage = (_a = parseResult.commitments.find((commitment) => commitment.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
26997
27026
  if (initialMessage) {
26998
- examples.push(`Agent: ${initialMessage}`);
27027
+ examples.push(`**Agent:**\n${initialMessage}`);
26999
27028
  }
27000
27029
  if (samples && samples.length > 0) {
27001
27030
  for (const sample of samples) {
27002
- examples.push(`User: ${sample.question}\nAgent: ${sample.answer}`);
27031
+ examples.push(`**User:** ${sample.question}\n\n**Agent:**\n${sample.answer}`);
27003
27032
  }
27004
27033
  }
27005
27034
  return examples;
@@ -31547,8 +31576,8 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
31547
31576
  * Prepares an AgentKit agent with optional knowledge sources and tool definitions.
31548
31577
  */
31549
31578
  async prepareAgentKitAgent(options) {
31550
- var _a, _b;
31551
- const { name, instructions, knowledgeSources, tools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
31579
+ var _a, _b, _c;
31580
+ const { name, instructions, knowledgeSources, tools, nativeAgentKitTools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
31552
31581
  await this.ensureAgentKitDefaults();
31553
31582
  if (this.options.isVerbose) {
31554
31583
  console.info('[🤰]', 'Preparing OpenAI AgentKit agent', {
@@ -31556,6 +31585,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
31556
31585
  instructionsLength: instructions.length,
31557
31586
  knowledgeSourcesCount: (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0,
31558
31587
  toolsCount: (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0,
31588
+ nativeAgentKitToolsCount: (_c = nativeAgentKitTools === null || nativeAgentKitTools === void 0 ? void 0 : nativeAgentKitTools.length) !== null && _c !== void 0 ? _c : 0,
31559
31589
  });
31560
31590
  }
31561
31591
  let vectorStoreId = cachedVectorStoreId;
@@ -31574,7 +31604,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
31574
31604
  vectorStoreId,
31575
31605
  });
31576
31606
  }
31577
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
31607
+ const agentKitTools = this.buildAgentKitTools({ tools, nativeAgentKitTools, vectorStoreId });
31578
31608
  const openAiAgentKitAgent = new Agent$1({
31579
31609
  name,
31580
31610
  model: this.agentKitModelName,
@@ -31613,11 +31643,14 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
31613
31643
  * Builds the tool list for AgentKit, including hosted file search when applicable.
31614
31644
  */
31615
31645
  buildAgentKitTools(options) {
31616
- const { tools, vectorStoreId } = options;
31646
+ const { tools, nativeAgentKitTools, vectorStoreId } = options;
31617
31647
  const agentKitTools = [];
31618
31648
  if (vectorStoreId) {
31619
31649
  agentKitTools.push(fileSearchTool(vectorStoreId));
31620
31650
  }
31651
+ if (nativeAgentKitTools && nativeAgentKitTools.length > 0) {
31652
+ agentKitTools.push(...nativeAgentKitTools);
31653
+ }
31621
31654
  if (tools && tools.length > 0) {
31622
31655
  let scriptTools = null;
31623
31656
  for (const toolDefinition of tools) {