@promptbook/core 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
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-58';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-60';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7974,36 +7974,38 @@ function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions
7974
7974
  switch (type) {
7975
7975
  case 'USE TIME':
7976
7976
  return spaceTrim$1((block) => `
7977
- Time and date context:
7978
- - It is ${moment().format('MMMM YYYY')} now.
7979
- - If you need more precise current time information, use the tool "get_current_time".
7977
+ ## Time and date context
7978
+
7979
+ - It is ${moment().format('MMMM YYYY')} now.
7980
+ - If you need more precise current time information, use the tool \`get_current_time\`.
7980
7981
  ${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
7981
7982
  `);
7982
7983
  case 'USE BROWSER':
7983
7984
  return spaceTrim$1((block) => `
7984
- You have access to browser tools to fetch and access content from the internet.
7985
- - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
7986
- - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
7987
- When you need to know information from a specific website or document, use the fetch_url_content tool.
7985
+ ## Browser
7986
+
7987
+ - Use \`fetch_url_content\` to retrieve content from specific URLs (webpages or documents) using scrapers.
7988
+ - Use \`run_browser\` for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
7989
+ - When you need to know information from a specific website or document, use the tools provided.
7988
7990
  ${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
7989
7991
  `);
7990
7992
  case 'USE SEARCH ENGINE':
7991
7993
  return spaceTrim$1((block) => `
7992
- Tool:
7993
- - You have access to the web search engine via the tool "web_search".
7994
- - Use it to find up-to-date information or facts that you don't know.
7995
- - When you need to know some information from the internet, use the tool provided to you.
7996
- - Do not make up information when you can search for it.
7997
- - Do not tell the user you cannot search for information, YOU CAN.
7994
+ ## Web Search
7995
+
7996
+ - Use \`web_search\` to find up-to-date information or facts.
7997
+ - When you need to know some information from the internet, use the search tool provided.
7998
+ - Do not make up information when you can search for it.
7999
+ - Do not tell the user you cannot search for information, YOU CAN.
7998
8000
  ${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
7999
8001
  `);
8000
8002
  case 'USE DEEPSEARCH':
8001
8003
  return spaceTrim$1((block) => `
8002
- Tool:
8003
- - You have access to DeepSearch via the tool "deep_search".
8004
- - Use it for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
8005
- - Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
8006
- - Do not pretend you cannot research current information when this tool is available.
8004
+ ## Deep Research
8005
+
8006
+ - Use \`deep_search\` for broader research tasks that need multi-step investigation, comparison, or synthesis across multiple sources.
8007
+ - Prefer it over quick search when the user asks for a well-grounded brief, report, or deeper investigation.
8008
+ - Do not pretend you cannot research current information when this tool is available.
8007
8009
  ${block(formatOptionalInstructionBlock('DeepSearch instructions', combinedAdditionalInstructions))}
8008
8010
  `);
8009
8011
  }
@@ -8245,6 +8247,49 @@ class BaseCommitmentDefinition {
8245
8247
  return this.appendToSystemMessage(requirements, commentSection);
8246
8248
  }
8247
8249
  }
8250
+ /**
8251
+ * Helper method to append a bullet point to an existing `## SectionTitle` section in the system
8252
+ * message, or to create a new section when it does not yet exist.
8253
+ *
8254
+ * Handles the case where the same commitment type appears multiple times in the book source and
8255
+ * all entries should be grouped under one shared heading rather than emitting a duplicate block.
8256
+ *
8257
+ * @param requirements - Current model requirements.
8258
+ * @param sectionTitle - Section title without the `##` prefix.
8259
+ * @param bulletContent - Bullet content without the leading `- ` prefix.
8260
+ * @returns Requirements with the bullet appended to the section.
8261
+ */
8262
+ appendBulletPointToSection(requirements, sectionTitle, bulletContent) {
8263
+ const sectionHeader = `## ${sectionTitle}`;
8264
+ const bullet = `- ${bulletContent}`;
8265
+ if (requirements.systemMessage.includes(sectionHeader)) {
8266
+ // Append bullet to end of existing section, before the next h2 heading or end of message
8267
+ const newSystemMessage = requirements.systemMessage.replace(new RegExp(`(## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\n\\n)([\\s\\S]*?)(?=\\n\\n##|$)`), `$1$2\n${bullet}`);
8268
+ return { ...requirements, systemMessage: newSystemMessage };
8269
+ }
8270
+ return this.appendToSystemMessage(requirements, `${sectionHeader}\n\n${bullet}`, '\n\n');
8271
+ }
8272
+ /**
8273
+ * Helper method to replace an existing `## SectionTitle` section in the system message, or to
8274
+ * append a new one when the section does not yet exist.
8275
+ *
8276
+ * Use this when a commitment type can appear multiple times and each subsequent occurrence should
8277
+ * update the single shared section rather than appending a duplicate block.
8278
+ *
8279
+ * @param requirements - Current model requirements.
8280
+ * @param sectionTitle - Section title without the `##` prefix.
8281
+ * @param sectionContent - Full section content including the `## Title` header line.
8282
+ * @returns Requirements with the section replaced or appended.
8283
+ */
8284
+ replaceOrCreateSection(requirements, sectionTitle, sectionContent) {
8285
+ const sectionHeader = `## ${sectionTitle}`;
8286
+ if (requirements.systemMessage.includes(sectionHeader)) {
8287
+ // Replace all text from the heading until the next h2 heading or end of message
8288
+ const newSystemMessage = requirements.systemMessage.replace(new RegExp(`## ${sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), sectionContent);
8289
+ return { ...requirements, systemMessage: newSystemMessage };
8290
+ }
8291
+ return this.appendToSystemMessage(requirements, sectionContent, '\n\n');
8292
+ }
8248
8293
  /**
8249
8294
  * Gets tool function implementations provided by this commitment
8250
8295
  *
@@ -8706,20 +8751,16 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
8706
8751
  if (!trimmedContent) {
8707
8752
  return requirements;
8708
8753
  }
8709
- // Get existing dictionary entries from metadata
8754
+ // Store the entry in metadata for debugging and inspection
8710
8755
  const existingDictionary = ((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
8711
- // Merge the new dictionary entry with existing entries
8712
8756
  const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
8713
- // Store the merged dictionary in metadata for debugging and inspection
8714
8757
  const updatedMetadata = {
8715
8758
  ...requirements._metadata,
8716
8759
  DICTIONARY: mergedDictionary,
8717
8760
  };
8718
- // Create the dictionary section for the system message
8719
- // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
8720
- const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
8761
+ // Append each dictionary entry as a bullet point under ## Dictionary
8721
8762
  return {
8722
- ...this.appendToSystemMessage(requirements, dictionarySection),
8763
+ ...this.appendBulletPointToSection(requirements, 'Dictionary', trimmedContent),
8723
8764
  _metadata: updatedMetadata,
8724
8765
  };
8725
8766
  }
@@ -11724,10 +11765,10 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
11724
11765
  if (!trimmedContent) {
11725
11766
  return requirements;
11726
11767
  }
11727
- // Add goal to the system message
11728
- const goalSection = `Goal: ${trimmedContent}`;
11768
+ // Add goal as a proper h2 section to the system message
11769
+ const goalSection = `## Goal\n\n${trimmedContent}`;
11729
11770
  const requirementsWithGoal = this.appendToSystemMessage(requirements, goalSection, '\n\n');
11730
- return this.appendToPromptSuffix(requirementsWithGoal, goalSection);
11771
+ return this.appendToPromptSuffix(requirementsWithGoal, trimmedContent);
11731
11772
  }
11732
11773
  }
11733
11774
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -12247,11 +12288,8 @@ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
12247
12288
  if (!trimmedContent) {
12248
12289
  return requirements;
12249
12290
  }
12250
- // Add language rule to the system message
12251
- const languageSection = this.createSystemMessageSection('Language:', spaceTrim$1((block) => `
12252
- ${block(trimmedContent)}
12253
- <- You are speaking these languages in your responses to the user.
12254
- `));
12291
+ // Add language as a bullet under a ## Language section
12292
+ const languageSection = `## Language\n\n- Your language is ${trimmedContent}`;
12255
12293
  return this.appendToSystemMessage(requirements, languageSection, '\n\n');
12256
12294
  }
12257
12295
  }
@@ -12276,15 +12314,16 @@ const MemoryToolNames = {
12276
12314
  */
12277
12315
  function createMemorySystemMessage(extraInstructions) {
12278
12316
  return spaceTrim$1((block) => `
12279
- Memory:
12280
- - Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
12281
- - You can use persistent user memory tools.
12282
- - Use "${MemoryToolNames.retrieve}" to load relevant memory before answering.
12283
- - Use "${MemoryToolNames.store}" to save stable user-specific facts that improve future help.
12284
- - Use "${MemoryToolNames.update}" to refresh an existing memory when the content changes.
12285
- - Use "${MemoryToolNames.delete}" to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
12286
- - Store concise memory items and avoid duplicates.
12287
- - Never claim memory was saved or loaded unless the tool confirms it.
12317
+ ## Memory
12318
+
12319
+ - Prefer storing agent-scoped memories; only make them global when the fact should apply across all your agents.
12320
+ - You can use persistent user memory tools.
12321
+ - Use \`${MemoryToolNames.retrieve}\` to load relevant memory before answering.
12322
+ - Use \`${MemoryToolNames.store}\` to save stable user-specific facts that improve future help.
12323
+ - Use \`${MemoryToolNames.update}\` to refresh an existing memory when the content changes.
12324
+ - Use \`${MemoryToolNames.delete}\` to delete memories that are no longer accurate (deletions are soft and hidden from future queries).
12325
+ - Store concise memory items and avoid duplicates.
12326
+ - Never claim memory was saved or loaded unless the tool confirms it.
12288
12327
  ${block(extraInstructions)}
12289
12328
  `);
12290
12329
  }
@@ -13206,10 +13245,8 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
13206
13245
  if (!trimmedContent) {
13207
13246
  return requirements;
13208
13247
  }
13209
- // Create message section for system message
13210
- const messageSection = `Previous Message: ${trimmedContent}`;
13211
13248
  // Messages represent conversation history and should be included for context
13212
- return this.appendToSystemMessage(requirements, messageSection, '\n\n');
13249
+ return this.appendBulletPointToSection(requirements, 'Previous messages', trimmedContent);
13213
13250
  }
13214
13251
  }
13215
13252
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -18003,10 +18040,9 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
18003
18040
  if (!trimmedContent) {
18004
18041
  return requirements;
18005
18042
  }
18006
- // Add rule to the system message
18007
- const ruleSection = `Rule: ${trimmedContent}`;
18008
- const requirementsWithRule = this.appendToSystemMessage(requirements, ruleSection, '\n\n');
18009
- return this.appendToPromptSuffix(requirementsWithRule, ruleSection);
18043
+ // Group all rules under a single ## Rules section as bullet points
18044
+ const requirementsWithRule = this.appendBulletPointToSection(requirements, 'Rules', trimmedContent);
18045
+ return this.appendToPromptSuffix(requirementsWithRule, `- ${trimmedContent}`);
18010
18046
  }
18011
18047
  }
18012
18048
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -18242,10 +18278,8 @@ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
18242
18278
  if (!trimmedContent) {
18243
18279
  return requirements;
18244
18280
  }
18245
- // Create scenario section for system message
18246
- const scenarioSection = `Scenario: ${trimmedContent}`;
18247
18281
  // Scenarios provide important contextual information that affects behavior
18248
- return this.appendToSystemMessage(requirements, scenarioSection, '\n\n');
18282
+ return this.appendBulletPointToSection(requirements, 'Scenarios', trimmedContent);
18249
18283
  }
18250
18284
  }
18251
18285
  // Note: [💞] Ignore a discrepancy between file name and entity name
@@ -18628,8 +18662,8 @@ const teamToolTitles = {};
18628
18662
  * @private
18629
18663
  */
18630
18664
  const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
18631
- '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
18632
- '- Do not ask the user for information that a listed teammate can provide directly.',
18665
+ '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
18666
+ '- Do not ask the user for information that a listed teammate can provide directly.',
18633
18667
  ];
18634
18668
  /**
18635
18669
  * Constant for remote agents by Url.
@@ -18757,7 +18791,7 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
18757
18791
  toolName: entry.toolName,
18758
18792
  });
18759
18793
  }
18760
- const teamSystemMessage = this.createSystemMessageSection('Teammates:', buildTeamSystemMessageBody(teamEntries));
18794
+ const teamSystemMessage = this.createSystemMessageSection('Teammates', buildTeamSystemMessageBody(teamEntries));
18761
18795
  return this.appendToSystemMessage({
18762
18796
  ...requirements,
18763
18797
  tools: updatedTools,
@@ -19445,96 +19479,6 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
19445
19479
  }
19446
19480
  // Note: [💞] Ignore a discrepancy between file name and entity name
19447
19481
 
19448
- /**
19449
- * Base Google Calendar API URL.
19450
- *
19451
- * @private constant of callGoogleCalendarApi
19452
- */
19453
- const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
19454
- /**
19455
- * Runs one Google Calendar API request and parses JSON response payload.
19456
- *
19457
- * @private function of UseCalendarCommitmentDefinition
19458
- */
19459
- async function callGoogleCalendarApi(accessToken, options) {
19460
- const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
19461
- if (options.query) {
19462
- for (const [key, value] of Object.entries(options.query)) {
19463
- if (value && value.trim()) {
19464
- url.searchParams.set(key, value);
19465
- }
19466
- }
19467
- }
19468
- const response = await fetch(url.toString(), {
19469
- method: options.method,
19470
- headers: {
19471
- Authorization: `Bearer ${accessToken}`,
19472
- Accept: 'application/json',
19473
- 'Content-Type': 'application/json',
19474
- },
19475
- body: options.body ? JSON.stringify(options.body) : undefined,
19476
- });
19477
- const textPayload = await response.text();
19478
- const parsedPayload = tryParseJson$2(textPayload);
19479
- if (options.allowNotFound && response.status === 404) {
19480
- return null;
19481
- }
19482
- if (!response.ok) {
19483
- throw new Error(spaceTrim$1(`
19484
- Google Calendar API request failed (${response.status} ${response.statusText}):
19485
- ${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
19486
- `));
19487
- }
19488
- return parsedPayload;
19489
- }
19490
- /**
19491
- * Parses raw text into JSON when possible.
19492
- *
19493
- * @private function of callGoogleCalendarApi
19494
- */
19495
- function tryParseJson$2(rawText) {
19496
- if (!rawText.trim()) {
19497
- return {};
19498
- }
19499
- try {
19500
- return JSON.parse(rawText);
19501
- }
19502
- catch (_a) {
19503
- return rawText;
19504
- }
19505
- }
19506
- /**
19507
- * Extracts a user-friendly Google Calendar API error message.
19508
- *
19509
- * @private function of callGoogleCalendarApi
19510
- */
19511
- function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
19512
- if (parsedPayload && typeof parsedPayload === 'object') {
19513
- const payload = parsedPayload;
19514
- const errorPayload = payload.error;
19515
- if (errorPayload && typeof errorPayload === 'object') {
19516
- const normalizedErrorPayload = errorPayload;
19517
- const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
19518
- const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
19519
- const flattenedErrors = errors
19520
- .map((errorEntry) => {
19521
- if (!errorEntry || typeof errorEntry !== 'object') {
19522
- return '';
19523
- }
19524
- const normalizedErrorEntry = errorEntry;
19525
- const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
19526
- const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
19527
- return [detailMessage, reason].filter(Boolean).join(' | ');
19528
- })
19529
- .filter(Boolean);
19530
- if (message || flattenedErrors.length > 0) {
19531
- return [message, ...flattenedErrors].filter(Boolean).join(' | ');
19532
- }
19533
- }
19534
- }
19535
- return fallbackText || 'Unknown Google Calendar API error';
19536
- }
19537
-
19538
19482
  /**
19539
19483
  * Hostnames accepted for Google Calendar references.
19540
19484
  *
@@ -19716,6 +19660,96 @@ function removeTokenFromLine(line, token) {
19716
19660
  }
19717
19661
  // Note: [💞] Ignore a discrepancy between file name and entity name
19718
19662
 
19663
+ /**
19664
+ * Base Google Calendar API URL.
19665
+ *
19666
+ * @private constant of callGoogleCalendarApi
19667
+ */
19668
+ const GOOGLE_CALENDAR_API_BASE_URL = 'https://www.googleapis.com/calendar/v3';
19669
+ /**
19670
+ * Runs one Google Calendar API request and parses JSON response payload.
19671
+ *
19672
+ * @private function of UseCalendarCommitmentDefinition
19673
+ */
19674
+ async function callGoogleCalendarApi(accessToken, options) {
19675
+ const url = new URL(options.path, GOOGLE_CALENDAR_API_BASE_URL);
19676
+ if (options.query) {
19677
+ for (const [key, value] of Object.entries(options.query)) {
19678
+ if (value && value.trim()) {
19679
+ url.searchParams.set(key, value);
19680
+ }
19681
+ }
19682
+ }
19683
+ const response = await fetch(url.toString(), {
19684
+ method: options.method,
19685
+ headers: {
19686
+ Authorization: `Bearer ${accessToken}`,
19687
+ Accept: 'application/json',
19688
+ 'Content-Type': 'application/json',
19689
+ },
19690
+ body: options.body ? JSON.stringify(options.body) : undefined,
19691
+ });
19692
+ const textPayload = await response.text();
19693
+ const parsedPayload = tryParseJson$2(textPayload);
19694
+ if (options.allowNotFound && response.status === 404) {
19695
+ return null;
19696
+ }
19697
+ if (!response.ok) {
19698
+ throw new Error(spaceTrim$1(`
19699
+ Google Calendar API request failed (${response.status} ${response.statusText}):
19700
+ ${extractGoogleCalendarApiErrorMessage(parsedPayload, textPayload)}
19701
+ `));
19702
+ }
19703
+ return parsedPayload;
19704
+ }
19705
+ /**
19706
+ * Parses raw text into JSON when possible.
19707
+ *
19708
+ * @private function of callGoogleCalendarApi
19709
+ */
19710
+ function tryParseJson$2(rawText) {
19711
+ if (!rawText.trim()) {
19712
+ return {};
19713
+ }
19714
+ try {
19715
+ return JSON.parse(rawText);
19716
+ }
19717
+ catch (_a) {
19718
+ return rawText;
19719
+ }
19720
+ }
19721
+ /**
19722
+ * Extracts a user-friendly Google Calendar API error message.
19723
+ *
19724
+ * @private function of callGoogleCalendarApi
19725
+ */
19726
+ function extractGoogleCalendarApiErrorMessage(parsedPayload, fallbackText) {
19727
+ if (parsedPayload && typeof parsedPayload === 'object') {
19728
+ const payload = parsedPayload;
19729
+ const errorPayload = payload.error;
19730
+ if (errorPayload && typeof errorPayload === 'object') {
19731
+ const normalizedErrorPayload = errorPayload;
19732
+ const message = typeof normalizedErrorPayload.message === 'string' ? normalizedErrorPayload.message : '';
19733
+ const errors = Array.isArray(normalizedErrorPayload.errors) ? normalizedErrorPayload.errors : [];
19734
+ const flattenedErrors = errors
19735
+ .map((errorEntry) => {
19736
+ if (!errorEntry || typeof errorEntry !== 'object') {
19737
+ return '';
19738
+ }
19739
+ const normalizedErrorEntry = errorEntry;
19740
+ const detailMessage = typeof normalizedErrorEntry.message === 'string' ? normalizedErrorEntry.message : '';
19741
+ const reason = typeof normalizedErrorEntry.reason === 'string' ? normalizedErrorEntry.reason : '';
19742
+ return [detailMessage, reason].filter(Boolean).join(' | ');
19743
+ })
19744
+ .filter(Boolean);
19745
+ if (message || flattenedErrors.length > 0) {
19746
+ return [message, ...flattenedErrors].filter(Boolean).join(' | ');
19747
+ }
19748
+ }
19749
+ }
19750
+ return fallbackText || 'Unknown Google Calendar API error';
19751
+ }
19752
+
19719
19753
  /**
19720
19754
  * Wallet metadata used by USE CALENDAR when resolving Google Calendar credentials.
19721
19755
  *
@@ -20616,18 +20650,20 @@ class UseCalendarCommitmentDefinition extends BaseCommitmentDefinition {
20616
20650
  if (parsedCommitment.calendar) {
20617
20651
  addConfiguredCalendarIfMissing(existingConfiguredCalendars, parsedCommitment.calendar);
20618
20652
  }
20619
- const calendarsList = existingConfiguredCalendars.length > 0
20620
- ? existingConfiguredCalendars
20621
- .map((calendar) => [
20622
- `- ${calendar.provider}: ${calendar.url}`,
20623
- calendar.scopes.length > 0 ? ` scopes: ${calendar.scopes.join(', ')}` : '',
20624
- ]
20625
- .filter(Boolean)
20626
- .join('\n'))
20627
- .join('\n')
20628
- : '- Calendar is resolved from runtime context';
20653
+ const calendarBullets = existingConfiguredCalendars.length > 0
20654
+ ? existingConfiguredCalendars.map((calendar) => `- ${calendar.provider}: ${calendar.url}`).join('\n')
20655
+ : '- Calendar is resolved from runtime context';
20629
20656
  const extraInstructions = formatOptionalInstructionBlock('Calendar instructions', parsedCommitment.instructions);
20630
- return this.appendToSystemMessage({
20657
+ const calendarSectionContent = spaceTrim$1((block) => `
20658
+ ## Calendar
20659
+
20660
+ - 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.
20661
+ - Supported operations include read, create, update, delete, invite guests, and reminders.
20662
+ - Configured calendars:
20663
+ ${block(calendarBullets)}
20664
+ ${block(extraInstructions)}
20665
+ `);
20666
+ return this.replaceOrCreateSection({
20631
20667
  ...requirements,
20632
20668
  tools: createUseCalendarTools(requirements.tools || []),
20633
20669
  _metadata: {
@@ -20635,16 +20671,7 @@ class UseCalendarCommitmentDefinition extends BaseCommitmentDefinition {
20635
20671
  useCalendar: true,
20636
20672
  useCalendars: existingConfiguredCalendars,
20637
20673
  },
20638
- }, spaceTrim$1((block) => `
20639
- Calendar tools:
20640
- - You can inspect and manage events in configured calendars.
20641
- - Supported operations include read, create, update, delete, invite guests, and reminders.
20642
- - Configured calendars:
20643
- ${block(calendarsList)}
20644
- - USE CALENDAR credentials are read from wallet records (ACCESS_TOKEN, service "${UseCalendarWallet.service}", key "${UseCalendarWallet.key}").
20645
- - If credentials are missing, ask user to connect calendar credentials in host UI and/or add them to wallet.
20646
- ${block(extraInstructions)}
20647
- `));
20674
+ }, 'Calendar', calendarSectionContent);
20648
20675
  }
20649
20676
  /**
20650
20677
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -20981,18 +21008,6 @@ async function sendEmailViaBrowser(args, agentsServerUrl) {
20981
21008
  * @private internal USE EMAIL constant
20982
21009
  */
20983
21010
  const SEND_EMAIL_TOOL_NAME = 'send_email';
20984
- /**
20985
- * Wallet service used for SMTP credentials required by USE EMAIL.
20986
- *
20987
- * @private internal USE EMAIL constant
20988
- */
20989
- const USE_EMAIL_SMTP_WALLET_SERVICE = 'smtp';
20990
- /**
20991
- * Wallet key used for SMTP credentials required by USE EMAIL.
20992
- *
20993
- * @private internal USE EMAIL constant
20994
- */
20995
- const USE_EMAIL_SMTP_WALLET_KEY = 'use-email-smtp-credentials';
20996
21011
  /**
20997
21012
  * USE EMAIL commitment definition.
20998
21013
  *
@@ -21051,31 +21066,41 @@ class UseEmailCommitmentDefinition extends BaseCommitmentDefinition {
21051
21066
  `);
21052
21067
  }
21053
21068
  applyToAgentModelRequirements(requirements, content) {
21069
+ var _a;
21054
21070
  const parsedCommitment = parseUseEmailCommitmentContent(content);
21055
- const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
21056
- const senderInstruction = parsedCommitment.senderEmail
21057
- ? `- Default sender address from commitment: "${parsedCommitment.senderEmail}".`
21058
- : '';
21059
21071
  const updatedTools = addUseEmailTools(requirements.tools || []);
21060
- return this.appendToSystemMessage({
21072
+ // Collect all configured sender emails across multiple USE EMAIL commitments
21073
+ const existingSenders = Array.isArray((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useEmailSenders)
21074
+ ? [...requirements._metadata.useEmailSenders]
21075
+ : [];
21076
+ if (parsedCommitment.senderEmail && !existingSenders.includes(parsedCommitment.senderEmail)) {
21077
+ existingSenders.push(parsedCommitment.senderEmail);
21078
+ }
21079
+ const senderBullets = existingSenders.length > 0
21080
+ ? existingSenders
21081
+ .map((email, index) => index === 0
21082
+ ? `- Default sender address: "${email}".`
21083
+ : `- Additional sender address: "${email}".`)
21084
+ .join('\n')
21085
+ : '';
21086
+ const extraInstructions = formatOptionalInstructionBlock('Email instructions', parsedCommitment.instructions);
21087
+ const emailSectionContent = spaceTrim$1((block) => `
21088
+ ## Emails
21089
+
21090
+ - Use \`${SEND_EMAIL_TOOL_NAME}\` to send outbound emails.
21091
+ ${block(senderBullets)}
21092
+ ${block(extraInstructions)}
21093
+ `);
21094
+ return this.replaceOrCreateSection({
21061
21095
  ...requirements,
21062
21096
  tools: updatedTools,
21063
21097
  _metadata: {
21064
21098
  ...requirements._metadata,
21065
21099
  useEmail: true,
21066
21100
  ...(parsedCommitment.senderEmail ? { useEmailSender: parsedCommitment.senderEmail } : {}),
21101
+ useEmailSenders: existingSenders,
21067
21102
  },
21068
- }, spaceTrim$1((block) => `
21069
- Email tool:
21070
- - Use "${SEND_EMAIL_TOOL_NAME}" to send outbound emails.
21071
- - Prefer \`message\` argument compatible with Promptbook \`Message\` type.
21072
- - Include subject in \`message.metadata.subject\` (or use legacy \`subject\` argument).
21073
- - USE EMAIL credentials are read from wallet records (ACCESS_TOKEN, service "${USE_EMAIL_SMTP_WALLET_SERVICE}", key "${USE_EMAIL_SMTP_WALLET_KEY}").
21074
- - Wallet secret must contain SMTP credentials in JSON format with fields \`host\`, \`port\`, \`secure\`, \`username\`, \`password\`.
21075
- - If credentials are missing, ask user to add wallet credentials.
21076
- ${block(senderInstruction)}
21077
- ${block(extraInstructions)}
21078
- `));
21103
+ }, 'Emails', emailSectionContent);
21079
21104
  }
21080
21105
  /**
21081
21106
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -21111,13 +21136,13 @@ function addUseEmailTools(existingTools) {
21111
21136
  ...existingTools,
21112
21137
  {
21113
21138
  name: SEND_EMAIL_TOOL_NAME,
21114
- description: 'Send an outbound email through configured SMTP credentials. Prefer providing Message-like payload in `message`.',
21139
+ description: 'Send an outbound email.',
21115
21140
  parameters: {
21116
21141
  type: 'object',
21117
21142
  properties: {
21118
21143
  message: {
21119
21144
  type: 'object',
21120
- description: 'Preferred input payload compatible with Promptbook Message type. Use metadata.subject for subject line.',
21145
+ description: 'Email payload. Use metadata.subject for the subject line.',
21121
21146
  },
21122
21147
  to: {
21123
21148
  type: 'string',
@@ -21221,13 +21246,14 @@ class UseImageGeneratorCommitmentDefinition extends BaseCommitmentDefinition {
21221
21246
  useImageGenerator: content || true,
21222
21247
  },
21223
21248
  }, spaceTrim$1((block) => `
21224
- Image generation:
21225
- - You do not generate images directly and you do not call any image tool.
21226
- - When the user asks for an image, include markdown notation in your message:
21227
- \`![<alt text>](?image-prompt=<prompt>)\`
21228
- - Keep \`<alt text>\` short and descriptive.
21229
- - Keep \`<prompt>\` detailed so the generated image matches the request.
21230
- - You can include normal explanatory text before and after the notation.
21249
+ ## Image generation
21250
+
21251
+ - You do not generate images directly and you do not call any image tool.
21252
+ - When the user asks for an image, include markdown notation in your message:
21253
+ \`![<alt text>](?image-prompt=<prompt>)\`
21254
+ - Keep \`<alt text>\` short and descriptive.
21255
+ - Keep \`<prompt>\` detailed so the generated image matches the request.
21256
+ - You can include normal explanatory text before and after the notation.
21231
21257
  ${block(extraInstructions)}
21232
21258
  `));
21233
21259
  }
@@ -21407,11 +21433,12 @@ class UsePopupCommitmentDefinition extends BaseCommitmentDefinition {
21407
21433
  usePopup: content || true,
21408
21434
  },
21409
21435
  }, spaceTrim$1((block) => `
21410
- Tool:
21411
- - You can open a popup window with a specific URL using the tool "open_popup".
21412
- - Use this when you want the user to see or interact with a specific website.
21436
+ ## Popup
21437
+
21438
+ - You can open a popup window with a specific URL using the tool \`open_popup\`.
21439
+ - Use this when you want the user to see or interact with a specific website.
21413
21440
  ${block(extraInstructions)}
21414
- `));
21441
+ `));
21415
21442
  }
21416
21443
  /**
21417
21444
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -21585,11 +21612,12 @@ class UsePrivacyCommitmentDefinition extends BaseCommitmentDefinition {
21585
21612
  usePrivacy: content || true,
21586
21613
  },
21587
21614
  }, spaceTrim$1((block) => `
21588
- Privacy mode:
21589
- - Use "${TURN_PRIVACY_ON_TOOL_NAME}" when the user asks for a private/sensitive conversation.
21590
- - This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
21591
- - Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
21592
- - Do not claim that end-to-end encryption is implemented yet.
21615
+ ## Privacy
21616
+
21617
+ - Use \`${TURN_PRIVACY_ON_TOOL_NAME}\` when the user asks for a private/sensitive conversation.
21618
+ - This tool requests a UI confirmation dialog. Private mode is enabled only after user confirms.
21619
+ - Current implementation uses the existing chat private mode (no chat persistence, memory persistence, or self-learning while active).
21620
+ - Do not claim that end-to-end encryption is implemented yet.
21593
21621
  ${block(extraInstructions)}
21594
21622
  `));
21595
21623
  }
@@ -23213,9 +23241,16 @@ class UseProjectCommitmentDefinition extends BaseCommitmentDefinition {
23213
23241
  }
23214
23242
  const existingConfiguredProjects = normalizeConfiguredProjects((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.useProjects);
23215
23243
  addConfiguredProjectIfMissing(existingConfiguredProjects, parsedCommitment.repository);
23216
- const repositoriesList = existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n');
23217
23244
  const extraInstructions = formatOptionalInstructionBlock('Project instructions', parsedCommitment.instructions);
23218
- return this.appendToSystemMessage({
23245
+ const sectionContent = spaceTrim$1((block) => `
23246
+ - You can inspect and edit configured GitHub repositories using project tools.
23247
+ - Configured repositories:
23248
+ ${block(existingConfiguredProjects.map((project) => `- ${project.url}`).join('\n'))}
23249
+ - When a repository is not obvious from context, pass \`repository\` in tool arguments explicitly.
23250
+ - If credentials are missing, ask the user to connect their GitHub account in the host UI.
23251
+ ${block(extraInstructions)}
23252
+ `);
23253
+ return this.replaceOrCreateSection({
23219
23254
  ...requirements,
23220
23255
  tools: createUseProjectTools(requirements.tools || []),
23221
23256
  _metadata: {
@@ -23223,16 +23258,7 @@ class UseProjectCommitmentDefinition extends BaseCommitmentDefinition {
23223
23258
  useProject: true,
23224
23259
  useProjects: existingConfiguredProjects,
23225
23260
  },
23226
- }, spaceTrim$1((block) => `
23227
- Project tools:
23228
- - You can inspect and edit configured GitHub repositories using project tools.
23229
- - Configured repositories:
23230
- ${block(repositoriesList)}
23231
- - When a repository is not obvious from context, pass "repository" in tool arguments explicitly.
23232
- - USE PROJECT credentials are read from wallet records (ACCESS_TOKEN, service "${UseProjectWallet.service}", key "${UseProjectWallet.key}").
23233
- - If credentials are missing, ask the user to connect credentials in host UI and/or add them to wallet.
23234
- ${block(extraInstructions)}
23235
- `));
23261
+ }, 'GitHub repositories', sectionContent);
23236
23262
  }
23237
23263
  /**
23238
23264
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -23579,11 +23605,12 @@ class UseSpawnCommitmentDefinition extends BaseCommitmentDefinition {
23579
23605
  useSpawn: content || true,
23580
23606
  },
23581
23607
  }, spaceTrim$1((block) => `
23582
- Spawning agents:
23583
- - Use "${SPAWN_AGENT_TOOL_NAME}" only when user asks to create a persistent new agent.
23584
- - Pass full agent source in \`source\`.
23585
- - Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
23586
- - Do not add unknown fields in tool arguments.
23608
+ ## Spawning agents
23609
+
23610
+ - Use \`${SPAWN_AGENT_TOOL_NAME}\` only when user asks to create a persistent new agent.
23611
+ - Pass full agent source in \`source\`.
23612
+ - Keep \`source\` concise; the maximum accepted length is ${CREATE_AGENT_INPUT_SOURCE_MAX_LENGTH} characters.
23613
+ - Do not add unknown fields in tool arguments.
23587
23614
  ${block(extraInstructions)}
23588
23615
  `));
23589
23616
  }
@@ -23617,13 +23644,14 @@ class UseSpawnCommitmentDefinition extends BaseCommitmentDefinition {
23617
23644
  */
23618
23645
  function createTimeoutSystemMessage(extraInstructions) {
23619
23646
  return spaceTrim$1((block) => `
23620
- Timeout scheduling:
23621
- - Use "set_timeout" to wake this same chat thread in the future.
23622
- - Use "list_timeouts" to review timeout ids/details across all chats for the same user+agent scope.
23623
- - "cancel_timeout" accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
23624
- - Use "update_timeout" to pause/resume, edit next run, edit recurrence, or update timeout payload details.
23625
- - 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\`.
23626
- - Do not claim a timer was set or cancelled unless the tool confirms it.
23647
+ ## Timeout scheduling
23648
+
23649
+ - Use \`set_timeout\` to wake this same chat thread in the future.
23650
+ - Use \`list_timeouts\` to review timeout ids/details across all chats for the same user+agent scope.
23651
+ - \`cancel_timeout\` accepts either one timeout id or \`allActive: true\` to cancel all active timeouts in this same user+agent scope.
23652
+ - Use \`update_timeout\` to pause/resume, edit next run, edit recurrence, or update timeout payload details.
23653
+ - 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\`.
23654
+ - Do not claim a timer was set or cancelled unless the tool confirms it.
23627
23655
  ${block(extraInstructions)}
23628
23656
  `);
23629
23657
  }
@@ -24723,10 +24751,11 @@ class UseUserLocationCommitmentDefinition extends BaseCommitmentDefinition {
24723
24751
  useUserLocation: content || true,
24724
24752
  },
24725
24753
  }, spaceTrim$1((block) => `
24726
- User location:
24727
- - Use "${GET_USER_LOCATION_TOOL_NAME}" only when location is needed for a better answer.
24728
- - If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
24729
- - Do not invent coordinates or local facts when location is unavailable.
24754
+ ## User location
24755
+
24756
+ - Use \`${GET_USER_LOCATION_TOOL_NAME}\` only when location is needed for a better answer.
24757
+ - If the tool returns "unavailable" or "permission-denied", ask user to share location or provide city manually.
24758
+ - Do not invent coordinates or local facts when location is unavailable.
24730
24759
  ${block(extraInstructions)}
24731
24760
  `));
24732
24761
  }
@@ -25740,7 +25769,7 @@ function createExampleInteractionsContent(parseResult, samples) {
25740
25769
  if (examples.length === 0) {
25741
25770
  return null;
25742
25771
  }
25743
- return `Example interaction:\n\n${examples.join('\n\n')}`;
25772
+ return `## Sample of communication with the agent:\n\n${examples.join('\n\n')}`;
25744
25773
  }
25745
25774
  /**
25746
25775
  * Collects the individual lines used in the example interaction section.
@@ -25756,11 +25785,11 @@ function collectExampleInteractionLines(parseResult, samples) {
25756
25785
  const examples = [];
25757
25786
  const initialMessage = (_a = parseResult.commitments.find((commitment) => commitment.type === 'INITIAL MESSAGE')) === null || _a === void 0 ? void 0 : _a.content;
25758
25787
  if (initialMessage) {
25759
- examples.push(`Agent: ${initialMessage}`);
25788
+ examples.push(`**Agent:**\n${initialMessage}`);
25760
25789
  }
25761
25790
  if (samples && samples.length > 0) {
25762
25791
  for (const sample of samples) {
25763
- examples.push(`User: ${sample.question}\nAgent: ${sample.answer}`);
25792
+ examples.push(`**User:** ${sample.question}\n\n**Agent:**\n${sample.answer}`);
25764
25793
  }
25765
25794
  }
25766
25795
  return examples;
@@ -36783,8 +36812,8 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
36783
36812
  * Prepares an AgentKit agent with optional knowledge sources and tool definitions.
36784
36813
  */
36785
36814
  async prepareAgentKitAgent(options) {
36786
- var _a, _b;
36787
- const { name, instructions, knowledgeSources, tools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
36815
+ var _a, _b, _c;
36816
+ const { name, instructions, knowledgeSources, tools, nativeAgentKitTools, vectorStoreId: cachedVectorStoreId, storeAsPrepared, } = options;
36788
36817
  await this.ensureAgentKitDefaults();
36789
36818
  if (this.options.isVerbose) {
36790
36819
  console.info('[🤰]', 'Preparing OpenAI AgentKit agent', {
@@ -36792,6 +36821,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
36792
36821
  instructionsLength: instructions.length,
36793
36822
  knowledgeSourcesCount: (_a = knowledgeSources === null || knowledgeSources === void 0 ? void 0 : knowledgeSources.length) !== null && _a !== void 0 ? _a : 0,
36794
36823
  toolsCount: (_b = tools === null || tools === void 0 ? void 0 : tools.length) !== null && _b !== void 0 ? _b : 0,
36824
+ nativeAgentKitToolsCount: (_c = nativeAgentKitTools === null || nativeAgentKitTools === void 0 ? void 0 : nativeAgentKitTools.length) !== null && _c !== void 0 ? _c : 0,
36795
36825
  });
36796
36826
  }
36797
36827
  let vectorStoreId = cachedVectorStoreId;
@@ -36810,7 +36840,7 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
36810
36840
  vectorStoreId,
36811
36841
  });
36812
36842
  }
36813
- const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
36843
+ const agentKitTools = this.buildAgentKitTools({ tools, nativeAgentKitTools, vectorStoreId });
36814
36844
  const openAiAgentKitAgent = new Agent$1({
36815
36845
  name,
36816
36846
  model: this.agentKitModelName,
@@ -36849,11 +36879,14 @@ class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler {
36849
36879
  * Builds the tool list for AgentKit, including hosted file search when applicable.
36850
36880
  */
36851
36881
  buildAgentKitTools(options) {
36852
- const { tools, vectorStoreId } = options;
36882
+ const { tools, nativeAgentKitTools, vectorStoreId } = options;
36853
36883
  const agentKitTools = [];
36854
36884
  if (vectorStoreId) {
36855
36885
  agentKitTools.push(fileSearchTool(vectorStoreId));
36856
36886
  }
36887
+ if (nativeAgentKitTools && nativeAgentKitTools.length > 0) {
36888
+ agentKitTools.push(...nativeAgentKitTools);
36889
+ }
36857
36890
  if (tools && tools.length > 0) {
36858
36891
  let scriptTools = null;
36859
36892
  for (const toolDefinition of tools) {