@promptbook/remote-server 0.112.0-25 → 0.112.0-27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -18,8 +18,8 @@ import { Converter } from 'showdown';
18
18
  import { createElement } from 'react';
19
19
  import { renderToStaticMarkup } from 'react-dom/server';
20
20
  import { Subject, BehaviorSubject } from 'rxjs';
21
- import { lookup, extension } from 'mime-types';
22
21
  import moment from 'moment';
22
+ import { lookup, extension } from 'mime-types';
23
23
  import sha256 from 'crypto-js/sha256';
24
24
  import { parse, unparse } from 'papaparse';
25
25
  import { Agent as Agent$1, setDefaultOpenAIClient, setDefaultOpenAIKey, fileSearchTool, tool, run } from '@openai/agents';
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
40
40
  * @generated
41
41
  * @see https://github.com/webgptorg/promptbook
42
42
  */
43
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-25';
43
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-27';
44
44
  /**
45
45
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
46
46
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -16248,6 +16248,147 @@ class UseCommitmentDefinition extends BaseCommitmentDefinition {
16248
16248
  * Note: [💞] Ignore a discrepancy between file name and entity name
16249
16249
  */
16250
16250
 
16251
+ /**
16252
+ * All `USE` commitment types currently participating in final system-message aggregation.
16253
+ *
16254
+ * @private internal constant for `aggregateUseCommitmentSystemMessages`
16255
+ */
16256
+ const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
16257
+ /**
16258
+ * Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
16259
+ *
16260
+ * @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
16261
+ */
16262
+ const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
16263
+ /**
16264
+ * Type guard for `USE` commitment types that are aggregated in the final system message.
16265
+ *
16266
+ * @param type - Commitment type to check.
16267
+ * @returns `true` when the commitment participates in `USE` system-message aggregation.
16268
+ * @private internal utility of `aggregateUseCommitmentSystemMessages`
16269
+ */
16270
+ function isAggregatedUseCommitmentType(type) {
16271
+ return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
16272
+ }
16273
+ /**
16274
+ * Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
16275
+ *
16276
+ * @param type - Aggregated `USE` commitment type.
16277
+ * @returns Single-line placeholder comment stored in the interim system message.
16278
+ * @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
16279
+ */
16280
+ function getAggregatedUseCommitmentPlaceholder(type) {
16281
+ return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
16282
+ }
16283
+ /**
16284
+ * Combines distinct additional instruction blocks in source order.
16285
+ *
16286
+ * @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
16287
+ * @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
16288
+ * @private internal utility of `createAggregatedUseCommitmentSystemMessage`
16289
+ */
16290
+ function combineAdditionalInstructions(additionalInstructions) {
16291
+ return additionalInstructions.join('\n');
16292
+ }
16293
+ /**
16294
+ * Creates the final aggregated system-message section for a supported `USE` commitment type.
16295
+ *
16296
+ * @param type - Aggregated `USE` commitment type.
16297
+ * @param additionalInstructions - Distinct additional instructions in source order.
16298
+ * @returns Final system-message block for the commitment type.
16299
+ * @private internal utility of `aggregateUseCommitmentSystemMessages`
16300
+ */
16301
+ function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
16302
+ const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
16303
+ switch (type) {
16304
+ case 'USE TIME':
16305
+ return spaceTrim$1((block) => `
16306
+ Time and date context:
16307
+ - It is ${moment().format('MMMM YYYY')} now.
16308
+ - If you need more precise current time information, use the tool "get_current_time".
16309
+ ${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
16310
+ `);
16311
+ case 'USE BROWSER':
16312
+ return spaceTrim$1((block) => `
16313
+ You have access to browser tools to fetch and access content from the internet.
16314
+ - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
16315
+ - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
16316
+ When you need to know information from a specific website or document, use the fetch_url_content tool.
16317
+ ${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
16318
+ `);
16319
+ case 'USE SEARCH ENGINE':
16320
+ return spaceTrim$1((block) => `
16321
+ Tool:
16322
+ - You have access to the web search engine via the tool "web_search".
16323
+ - Use it to find up-to-date information or facts that you don't know.
16324
+ - When you need to know some information from the internet, use the tool provided to you.
16325
+ - Do not make up information when you can search for it.
16326
+ - Do not tell the user you cannot search for information, YOU CAN.
16327
+ ${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
16328
+ `);
16329
+ }
16330
+ }
16331
+ /**
16332
+ * Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
16333
+ *
16334
+ * @param requirements - Current model requirements.
16335
+ * @param type - Aggregated `USE` commitment type being applied.
16336
+ * @returns Requirements with the placeholder inserted when it was not already present.
16337
+ * @private internal utility of `USE` commitments
16338
+ */
16339
+ function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
16340
+ const placeholder = getAggregatedUseCommitmentPlaceholder(type);
16341
+ if (requirements.systemMessage.includes(placeholder)) {
16342
+ return requirements;
16343
+ }
16344
+ const systemMessage = requirements.systemMessage.trim()
16345
+ ? `${requirements.systemMessage}\n\n${placeholder}`
16346
+ : placeholder;
16347
+ return {
16348
+ ...requirements,
16349
+ systemMessage,
16350
+ };
16351
+ }
16352
+ /**
16353
+ * Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
16354
+ *
16355
+ * Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
16356
+ *
16357
+ * @param requirements - Model requirements produced by commitment-by-commitment application.
16358
+ * @param commitments - Filtered commitments in their original source order.
16359
+ * @returns Requirements with aggregated `USE` system-message sections.
16360
+ * @private internal utility of `createAgentModelRequirementsWithCommitments`
16361
+ */
16362
+ function aggregateUseCommitmentSystemMessages(requirements, commitments) {
16363
+ const additionalInstructionsByType = new Map();
16364
+ for (const commitment of commitments) {
16365
+ if (!isAggregatedUseCommitmentType(commitment.type)) {
16366
+ continue;
16367
+ }
16368
+ let additionalInstructions = additionalInstructionsByType.get(commitment.type);
16369
+ if (!additionalInstructions) {
16370
+ additionalInstructions = [];
16371
+ additionalInstructionsByType.set(commitment.type, additionalInstructions);
16372
+ }
16373
+ const normalizedContent = spaceTrim$1(commitment.content);
16374
+ if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
16375
+ additionalInstructions.push(normalizedContent);
16376
+ }
16377
+ }
16378
+ let systemMessage = requirements.systemMessage;
16379
+ for (const [type, additionalInstructions] of additionalInstructionsByType) {
16380
+ const placeholder = getAggregatedUseCommitmentPlaceholder(type);
16381
+ if (!systemMessage.includes(placeholder)) {
16382
+ continue;
16383
+ }
16384
+ systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
16385
+ }
16386
+ return {
16387
+ ...requirements,
16388
+ systemMessage,
16389
+ };
16390
+ }
16391
+
16251
16392
  /**
16252
16393
  * Client-side safe wrapper for fetching URL content
16253
16394
  *
@@ -16298,13 +16439,14 @@ async function fetchUrlContentViaBrowser(url, agentsServerUrl) {
16298
16439
  * 1. One-shot URL fetching: Simple function to fetch and scrape URL content
16299
16440
  * 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
16300
16441
  *
16301
- * The content following `USE BROWSER` is ignored (similar to NOTE).
16442
+ * The content following `USE BROWSER` is an arbitrary text that the agent should know
16443
+ * (e.g. browsing scope or preferred sources).
16302
16444
  *
16303
16445
  * Example usage in agent source:
16304
16446
  *
16305
16447
  * ```book
16306
16448
  * USE BROWSER
16307
- * USE BROWSER This will be ignored
16449
+ * USE BROWSER Prefer official documentation and source websites.
16308
16450
  * ```
16309
16451
  *
16310
16452
  * @private [🪔] Maybe export the commitments through some package
@@ -16342,7 +16484,7 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
16342
16484
 
16343
16485
  ## Key aspects
16344
16486
 
16345
- - The content following \`USE BROWSER\` is ignored (similar to NOTE)
16487
+ - The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
16346
16488
  - Provides two levels of browser access:
16347
16489
  1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
16348
16490
  2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
@@ -16459,20 +16601,14 @@ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
16459
16601
  });
16460
16602
  }
16461
16603
  const updatedTools = [...existingTools, ...toolsToAdd];
16462
- // Return requirements with updated tools and metadata
16463
- return this.appendToSystemMessage({
16604
+ return appendAggregatedUseCommitmentPlaceholder({
16464
16605
  ...requirements,
16465
16606
  tools: updatedTools,
16466
16607
  _metadata: {
16467
16608
  ...requirements._metadata,
16468
16609
  useBrowser: true,
16469
16610
  },
16470
- }, spaceTrim$1(`
16471
- You have access to browser tools to fetch and access content from the internet.
16472
- - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
16473
- - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
16474
- When you need to know information from a specific website or document, use the fetch_url_content tool.
16475
- `));
16611
+ }, this.type);
16476
16612
  }
16477
16613
  /**
16478
16614
  * Gets the browser tool function implementations.
@@ -20259,7 +20395,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
20259
20395
  `);
20260
20396
  }
20261
20397
  applyToAgentModelRequirements(requirements, content) {
20262
- const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
20263
20398
  // Get existing tools array or create new one
20264
20399
  const existingTools = requirements.tools || [];
20265
20400
  // Add 'web_search' to tools if not already present
@@ -20272,7 +20407,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
20272
20407
  description: spaceTrim$1(`
20273
20408
  Search the internet for information.
20274
20409
  Use this tool when you need to find up-to-date information or facts that you don't know.
20275
- ${!content ? '' : `Search scope / instructions: ${content}`}
20276
20410
  `),
20277
20411
  parameters: {
20278
20412
  type: 'object',
@@ -20310,23 +20444,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
20310
20444
  },
20311
20445
  },
20312
20446
  ];
20313
- // Return requirements with updated tools and metadata
20314
- return this.appendToSystemMessage({
20447
+ return appendAggregatedUseCommitmentPlaceholder({
20315
20448
  ...requirements,
20316
20449
  tools: updatedTools,
20317
20450
  _metadata: {
20318
20451
  ...requirements._metadata,
20319
20452
  useSearchEngine: content || true,
20320
20453
  },
20321
- }, spaceTrim$1((block) => `
20322
- Tool:
20323
- - You have access to the web search engine via the tool "web_search".
20324
- - Use it to find up-to-date information or facts that you don't know.
20325
- - When you need to know some information from the internet, use the tool provided to you.
20326
- - Do not make up information when you can search for it.
20327
- - Do not tell the user you cannot search for information, YOU CAN.
20328
- ${block(extraInstructions)}
20329
- `));
20454
+ }, this.type);
20330
20455
  }
20331
20456
  /**
20332
20457
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -21437,7 +21562,6 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
21437
21562
  `);
21438
21563
  }
21439
21564
  applyToAgentModelRequirements(requirements, content) {
21440
- const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
21441
21565
  // Get existing tools array or create new one
21442
21566
  const existingTools = requirements.tools || [];
21443
21567
  // Add 'get_current_time' to tools if not already present
@@ -21461,19 +21585,13 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
21461
21585
  },
21462
21586
  // <- TODO: !!!! define the function in LLM tools
21463
21587
  ];
21464
- // Return requirements with updated tools and metadata
21465
- return this.appendToSystemMessage({
21588
+ return appendAggregatedUseCommitmentPlaceholder({
21466
21589
  ...requirements,
21467
21590
  tools: updatedTools,
21468
21591
  _metadata: {
21469
21592
  ...requirements._metadata,
21470
21593
  },
21471
- }, spaceTrim$1((block) => `
21472
- Time and date context:
21473
- - It is ${moment().format('MMMM YYYY')} now.
21474
- - If you need more precise current time information, use the tool "get_current_time".
21475
- ${block(extraInstructions)}
21476
- `));
21594
+ }, this.type);
21477
21595
  }
21478
21596
  /**
21479
21597
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -25168,6 +25286,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
25168
25286
  }
25169
25287
  }
25170
25288
  }
25289
+ requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
25171
25290
  // Handle IMPORT commitments for generic files
25172
25291
  // Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
25173
25292
  if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {