@promptbook/node 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.
@@ -26,45 +26,6 @@ export type HoistedMenuItem = {
26
26
  */
27
27
  isActive?: boolean;
28
28
  };
29
- /**
30
- * Shared actions provided to hoisted mobile menu-section renderers.
31
- *
32
- * @private mechanism inside Promptbook
33
- */
34
- export type HoistedMobileMenuSectionRenderOptions = {
35
- /**
36
- * Closes the owning mobile header menu.
37
- */
38
- readonly closeMenu: () => void;
39
- };
40
- /**
41
- * Mobile-only section hoisted into the shared application menu.
42
- *
43
- * @private mechanism inside Promptbook
44
- */
45
- export type HoistedMobileMenuSection = {
46
- /**
47
- * Stable identifier used to preserve section open state.
48
- */
49
- readonly key: string;
50
- /**
51
- * Visible section label rendered by the mobile menu.
52
- */
53
- readonly label: ReactNode;
54
- /**
55
- * Whether the section should start expanded whenever the menu opens.
56
- */
57
- readonly isDefaultOpen?: boolean;
58
- /**
59
- * Lazily renders section content inside the mobile header menu.
60
- */
61
- readonly renderContent: (options: HoistedMobileMenuSectionRenderOptions) => ReactNode;
62
- };
63
- /**
64
- * Value exposed through the shared menu-hoisting context.
65
- *
66
- * @private mechanism inside Promptbook
67
- */
68
29
  type MenuHoistingContextType = {
69
30
  /**
70
31
  * The currently hoisted menu items
@@ -74,14 +35,6 @@ type MenuHoistingContextType = {
74
35
  * Set the hoisted menu items
75
36
  */
76
37
  setMenu: (items: HoistedMenuItem[]) => void;
77
- /**
78
- * Mobile-only sections hoisted into the shared application menu.
79
- */
80
- mobileMenuSections: HoistedMobileMenuSection[];
81
- /**
82
- * Sets the mobile-only hoisted menu sections.
83
- */
84
- setMobileMenuSections: (sections: HoistedMobileMenuSection[]) => void;
85
38
  };
86
39
  /**
87
40
  * Provider for menu hoisting
@@ -0,0 +1,30 @@
1
+ import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements';
2
+ import type { ParsedCommitment } from '../_base/ParsedCommitment';
3
+ /**
4
+ * `USE` commitment types whose system-message sections are aggregated after the
5
+ * commitment-by-commitment application step.
6
+ *
7
+ * @private internal utility of `createAgentModelRequirementsWithCommitments`
8
+ */
9
+ type AggregatedUseCommitmentType = 'USE BROWSER' | 'USE SEARCH ENGINE' | 'USE TIME';
10
+ /**
11
+ * Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
12
+ *
13
+ * @param requirements - Current model requirements.
14
+ * @param type - Aggregated `USE` commitment type being applied.
15
+ * @returns Requirements with the placeholder inserted when it was not already present.
16
+ * @private internal utility of `USE` commitments
17
+ */
18
+ export declare function appendAggregatedUseCommitmentPlaceholder(requirements: AgentModelRequirements, type: AggregatedUseCommitmentType): AgentModelRequirements;
19
+ /**
20
+ * Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
21
+ *
22
+ * Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
23
+ *
24
+ * @param requirements - Model requirements produced by commitment-by-commitment application.
25
+ * @param commitments - Filtered commitments in their original source order.
26
+ * @returns Requirements with aggregated `USE` system-message sections.
27
+ * @private internal utility of `createAgentModelRequirementsWithCommitments`
28
+ */
29
+ export declare function aggregateUseCommitmentSystemMessages(requirements: AgentModelRequirements, commitments: ReadonlyArray<ParsedCommitment>): AgentModelRequirements;
30
+ export {};
@@ -12,13 +12,14 @@ import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
12
12
  * 1. One-shot URL fetching: Simple function to fetch and scrape URL content
13
13
  * 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
14
14
  *
15
- * The content following `USE BROWSER` is ignored (similar to NOTE).
15
+ * The content following `USE BROWSER` is an arbitrary text that the agent should know
16
+ * (e.g. browsing scope or preferred sources).
16
17
  *
17
18
  * Example usage in agent source:
18
19
  *
19
20
  * ```book
20
21
  * USE BROWSER
21
- * USE BROWSER This will be ignored
22
+ * USE BROWSER Prefer official documentation and source websites.
22
23
  * ```
23
24
  *
24
25
  * @private [🪔] Maybe export the commitments through some package
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.112.0-24`).
18
+ * It follows semantic versioning (e.g., `0.112.0-26`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.112.0-25",
3
+ "version": "0.112.0-27",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -96,7 +96,7 @@
96
96
  "module": "./esm/index.es.js",
97
97
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
98
98
  "peerDependencies": {
99
- "@promptbook/core": "0.112.0-25"
99
+ "@promptbook/core": "0.112.0-27"
100
100
  },
101
101
  "dependencies": {
102
102
  "@mozilla/readability": "0.6.0",
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('jszip'), require('crypto'), require('crypto-js'), require('crypto-js/enc-hex'), require('@mozilla/readability'), require('jsdom'), require('showdown'), require('child_process'), require('waitasecond'), require('dotenv'), require('crypto-js/sha256'), require('rxjs'), require('mime-types'), require('moment'), require('papaparse'), require('@openai/agents'), require('bottleneck'), require('openai')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'jszip', 'crypto', 'crypto-js', 'crypto-js/enc-hex', '@mozilla/readability', 'jsdom', 'showdown', 'child_process', 'waitasecond', 'dotenv', 'crypto-js/sha256', 'rxjs', 'mime-types', 'moment', 'papaparse', '@openai/agents', 'bottleneck', 'openai'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global._spaceTrim, global.JSZip, global.crypto, global.cryptoJs, global.hexEncoder, global.readability, global.jsdom, global.showdown, global.child_process, global.waitasecond, global.dotenv, global.sha256, global.rxjs, global.mimeTypes, global.moment, global.papaparse, global.agents, global.Bottleneck, global.OpenAI));
5
- })(this, (function (exports, colors, promises, path, _spaceTrim, JSZip, crypto, cryptoJs, hexEncoder, readability, jsdom, showdown, child_process, waitasecond, dotenv, sha256, rxjs, mimeTypes, moment, papaparse, agents, Bottleneck, OpenAI) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('jszip'), require('crypto'), require('crypto-js'), require('crypto-js/enc-hex'), require('@mozilla/readability'), require('jsdom'), require('showdown'), require('child_process'), require('waitasecond'), require('dotenv'), require('crypto-js/sha256'), require('rxjs'), require('moment'), require('mime-types'), require('papaparse'), require('@openai/agents'), require('bottleneck'), require('openai')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'jszip', 'crypto', 'crypto-js', 'crypto-js/enc-hex', '@mozilla/readability', 'jsdom', 'showdown', 'child_process', 'waitasecond', 'dotenv', 'crypto-js/sha256', 'rxjs', 'moment', 'mime-types', 'papaparse', '@openai/agents', 'bottleneck', 'openai'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global._spaceTrim, global.JSZip, global.crypto, global.cryptoJs, global.hexEncoder, global.readability, global.jsdom, global.showdown, global.child_process, global.waitasecond, global.dotenv, global.sha256, global.rxjs, global.moment, global.mimeTypes, global.papaparse, global.agents, global.Bottleneck, global.OpenAI));
5
+ })(this, (function (exports, colors, promises, path, _spaceTrim, JSZip, crypto, cryptoJs, hexEncoder, readability, jsdom, showdown, child_process, waitasecond, dotenv, sha256, rxjs, moment, mimeTypes, papaparse, agents, Bottleneck, OpenAI) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-25';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-27';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -19196,6 +19196,147 @@
19196
19196
  * Note: [💞] Ignore a discrepancy between file name and entity name
19197
19197
  */
19198
19198
 
19199
+ /**
19200
+ * All `USE` commitment types currently participating in final system-message aggregation.
19201
+ *
19202
+ * @private internal constant for `aggregateUseCommitmentSystemMessages`
19203
+ */
19204
+ const AGGREGATED_USE_COMMITMENT_TYPES = ['USE BROWSER', 'USE SEARCH ENGINE', 'USE TIME'];
19205
+ /**
19206
+ * Prefix used for temporary in-system-message placeholders that preserve the first-occurrence position of aggregated `USE` sections.
19207
+ *
19208
+ * @private internal constant for `appendAggregatedUseCommitmentPlaceholder`
19209
+ */
19210
+ const AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX = '# AGGREGATED USE COMMITMENT: ';
19211
+ /**
19212
+ * Type guard for `USE` commitment types that are aggregated in the final system message.
19213
+ *
19214
+ * @param type - Commitment type to check.
19215
+ * @returns `true` when the commitment participates in `USE` system-message aggregation.
19216
+ * @private internal utility of `aggregateUseCommitmentSystemMessages`
19217
+ */
19218
+ function isAggregatedUseCommitmentType(type) {
19219
+ return AGGREGATED_USE_COMMITMENT_TYPES.includes(type);
19220
+ }
19221
+ /**
19222
+ * Creates the placeholder token used to reserve the first-occurrence position of an aggregated `USE` system-message section.
19223
+ *
19224
+ * @param type - Aggregated `USE` commitment type.
19225
+ * @returns Single-line placeholder comment stored in the interim system message.
19226
+ * @private internal utility of `appendAggregatedUseCommitmentPlaceholder`
19227
+ */
19228
+ function getAggregatedUseCommitmentPlaceholder(type) {
19229
+ return `${AGGREGATED_USE_COMMITMENT_PLACEHOLDER_PREFIX}${type}`;
19230
+ }
19231
+ /**
19232
+ * Combines distinct additional instruction blocks in source order.
19233
+ *
19234
+ * @param additionalInstructions - Deduplicated instruction blocks collected from the agent source.
19235
+ * @returns Combined instruction text ready for `formatOptionalInstructionBlock`.
19236
+ * @private internal utility of `createAggregatedUseCommitmentSystemMessage`
19237
+ */
19238
+ function combineAdditionalInstructions(additionalInstructions) {
19239
+ return additionalInstructions.join('\n');
19240
+ }
19241
+ /**
19242
+ * Creates the final aggregated system-message section for a supported `USE` commitment type.
19243
+ *
19244
+ * @param type - Aggregated `USE` commitment type.
19245
+ * @param additionalInstructions - Distinct additional instructions in source order.
19246
+ * @returns Final system-message block for the commitment type.
19247
+ * @private internal utility of `aggregateUseCommitmentSystemMessages`
19248
+ */
19249
+ function createAggregatedUseCommitmentSystemMessage(type, additionalInstructions) {
19250
+ const combinedAdditionalInstructions = combineAdditionalInstructions(additionalInstructions);
19251
+ switch (type) {
19252
+ case 'USE TIME':
19253
+ return _spaceTrim.spaceTrim((block) => `
19254
+ Time and date context:
19255
+ - It is ${moment__default["default"]().format('MMMM YYYY')} now.
19256
+ - If you need more precise current time information, use the tool "get_current_time".
19257
+ ${block(formatOptionalInstructionBlock('Time instructions', combinedAdditionalInstructions))}
19258
+ `);
19259
+ case 'USE BROWSER':
19260
+ return _spaceTrim.spaceTrim((block) => `
19261
+ You have access to browser tools to fetch and access content from the internet.
19262
+ - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
19263
+ - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
19264
+ When you need to know information from a specific website or document, use the fetch_url_content tool.
19265
+ ${block(formatOptionalInstructionBlock('Browser instructions', combinedAdditionalInstructions))}
19266
+ `);
19267
+ case 'USE SEARCH ENGINE':
19268
+ return _spaceTrim.spaceTrim((block) => `
19269
+ Tool:
19270
+ - You have access to the web search engine via the tool "web_search".
19271
+ - Use it to find up-to-date information or facts that you don't know.
19272
+ - When you need to know some information from the internet, use the tool provided to you.
19273
+ - Do not make up information when you can search for it.
19274
+ - Do not tell the user you cannot search for information, YOU CAN.
19275
+ ${block(formatOptionalInstructionBlock('Search instructions', combinedAdditionalInstructions))}
19276
+ `);
19277
+ }
19278
+ }
19279
+ /**
19280
+ * Adds the placeholder for an aggregated `USE` system-message section only once, preserving the section position from the first occurrence.
19281
+ *
19282
+ * @param requirements - Current model requirements.
19283
+ * @param type - Aggregated `USE` commitment type being applied.
19284
+ * @returns Requirements with the placeholder inserted when it was not already present.
19285
+ * @private internal utility of `USE` commitments
19286
+ */
19287
+ function appendAggregatedUseCommitmentPlaceholder(requirements, type) {
19288
+ const placeholder = getAggregatedUseCommitmentPlaceholder(type);
19289
+ if (requirements.systemMessage.includes(placeholder)) {
19290
+ return requirements;
19291
+ }
19292
+ const systemMessage = requirements.systemMessage.trim()
19293
+ ? `${requirements.systemMessage}\n\n${placeholder}`
19294
+ : placeholder;
19295
+ return {
19296
+ ...requirements,
19297
+ systemMessage,
19298
+ };
19299
+ }
19300
+ /**
19301
+ * Replaces temporary `USE` placeholders with one aggregated system-message block per commitment type.
19302
+ *
19303
+ * Distinct additional-instruction blocks are merged in stable source order while the hard-coded section is emitted only once.
19304
+ *
19305
+ * @param requirements - Model requirements produced by commitment-by-commitment application.
19306
+ * @param commitments - Filtered commitments in their original source order.
19307
+ * @returns Requirements with aggregated `USE` system-message sections.
19308
+ * @private internal utility of `createAgentModelRequirementsWithCommitments`
19309
+ */
19310
+ function aggregateUseCommitmentSystemMessages(requirements, commitments) {
19311
+ const additionalInstructionsByType = new Map();
19312
+ for (const commitment of commitments) {
19313
+ if (!isAggregatedUseCommitmentType(commitment.type)) {
19314
+ continue;
19315
+ }
19316
+ let additionalInstructions = additionalInstructionsByType.get(commitment.type);
19317
+ if (!additionalInstructions) {
19318
+ additionalInstructions = [];
19319
+ additionalInstructionsByType.set(commitment.type, additionalInstructions);
19320
+ }
19321
+ const normalizedContent = _spaceTrim.spaceTrim(commitment.content);
19322
+ if (normalizedContent && !additionalInstructions.includes(normalizedContent)) {
19323
+ additionalInstructions.push(normalizedContent);
19324
+ }
19325
+ }
19326
+ let systemMessage = requirements.systemMessage;
19327
+ for (const [type, additionalInstructions] of additionalInstructionsByType) {
19328
+ const placeholder = getAggregatedUseCommitmentPlaceholder(type);
19329
+ if (!systemMessage.includes(placeholder)) {
19330
+ continue;
19331
+ }
19332
+ systemMessage = systemMessage.replace(placeholder, createAggregatedUseCommitmentSystemMessage(type, additionalInstructions));
19333
+ }
19334
+ return {
19335
+ ...requirements,
19336
+ systemMessage,
19337
+ };
19338
+ }
19339
+
19199
19340
  /**
19200
19341
  * Client-side safe wrapper for fetching URL content
19201
19342
  *
@@ -19246,13 +19387,14 @@
19246
19387
  * 1. One-shot URL fetching: Simple function to fetch and scrape URL content
19247
19388
  * 2. Running browser: For complex tasks like scrolling, clicking, form filling, etc.
19248
19389
  *
19249
- * The content following `USE BROWSER` is ignored (similar to NOTE).
19390
+ * The content following `USE BROWSER` is an arbitrary text that the agent should know
19391
+ * (e.g. browsing scope or preferred sources).
19250
19392
  *
19251
19393
  * Example usage in agent source:
19252
19394
  *
19253
19395
  * ```book
19254
19396
  * USE BROWSER
19255
- * USE BROWSER This will be ignored
19397
+ * USE BROWSER Prefer official documentation and source websites.
19256
19398
  * ```
19257
19399
  *
19258
19400
  * @private [🪔] Maybe export the commitments through some package
@@ -19290,7 +19432,7 @@
19290
19432
 
19291
19433
  ## Key aspects
19292
19434
 
19293
- - The content following \`USE BROWSER\` is ignored (similar to NOTE)
19435
+ - The content following \`USE BROWSER\` is an arbitrary text that the agent should know (e.g. browsing scope or preferred sources).
19294
19436
  - Provides two levels of browser access:
19295
19437
  1. **One-shot URL fetching**: Simple function to fetch and scrape URL content (active)
19296
19438
  2. **Running browser**: For complex tasks like scrolling, clicking, form filling, etc. (runtime-dependent)
@@ -19407,20 +19549,14 @@
19407
19549
  });
19408
19550
  }
19409
19551
  const updatedTools = [...existingTools, ...toolsToAdd];
19410
- // Return requirements with updated tools and metadata
19411
- return this.appendToSystemMessage({
19552
+ return appendAggregatedUseCommitmentPlaceholder({
19412
19553
  ...requirements,
19413
19554
  tools: updatedTools,
19414
19555
  _metadata: {
19415
19556
  ...requirements._metadata,
19416
19557
  useBrowser: true,
19417
19558
  },
19418
- }, _spaceTrim.spaceTrim(`
19419
- You have access to browser tools to fetch and access content from the internet.
19420
- - Use "fetch_url_content" to retrieve content from specific URLs (webpages or documents) using scrapers.
19421
- - Use "run_browser" for real interactive browser automation (navigation, clicks, typing, waiting, scrolling).
19422
- When you need to know information from a specific website or document, use the fetch_url_content tool.
19423
- `));
19559
+ }, this.type);
19424
19560
  }
19425
19561
  /**
19426
19562
  * Gets the browser tool function implementations.
@@ -23207,7 +23343,6 @@
23207
23343
  `);
23208
23344
  }
23209
23345
  applyToAgentModelRequirements(requirements, content) {
23210
- const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
23211
23346
  // Get existing tools array or create new one
23212
23347
  const existingTools = requirements.tools || [];
23213
23348
  // Add 'web_search' to tools if not already present
@@ -23220,7 +23355,6 @@
23220
23355
  description: _spaceTrim.spaceTrim(`
23221
23356
  Search the internet for information.
23222
23357
  Use this tool when you need to find up-to-date information or facts that you don't know.
23223
- ${!content ? '' : `Search scope / instructions: ${content}`}
23224
23358
  `),
23225
23359
  parameters: {
23226
23360
  type: 'object',
@@ -23258,23 +23392,14 @@
23258
23392
  },
23259
23393
  },
23260
23394
  ];
23261
- // Return requirements with updated tools and metadata
23262
- return this.appendToSystemMessage({
23395
+ return appendAggregatedUseCommitmentPlaceholder({
23263
23396
  ...requirements,
23264
23397
  tools: updatedTools,
23265
23398
  _metadata: {
23266
23399
  ...requirements._metadata,
23267
23400
  useSearchEngine: content || true,
23268
23401
  },
23269
- }, _spaceTrim.spaceTrim((block) => `
23270
- Tool:
23271
- - You have access to the web search engine via the tool "web_search".
23272
- - Use it to find up-to-date information or facts that you don't know.
23273
- - When you need to know some information from the internet, use the tool provided to you.
23274
- - Do not make up information when you can search for it.
23275
- - Do not tell the user you cannot search for information, YOU CAN.
23276
- ${block(extraInstructions)}
23277
- `));
23402
+ }, this.type);
23278
23403
  }
23279
23404
  /**
23280
23405
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -24385,7 +24510,6 @@
24385
24510
  `);
24386
24511
  }
24387
24512
  applyToAgentModelRequirements(requirements, content) {
24388
- const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
24389
24513
  // Get existing tools array or create new one
24390
24514
  const existingTools = requirements.tools || [];
24391
24515
  // Add 'get_current_time' to tools if not already present
@@ -24409,19 +24533,13 @@
24409
24533
  },
24410
24534
  // <- TODO: !!!! define the function in LLM tools
24411
24535
  ];
24412
- // Return requirements with updated tools and metadata
24413
- return this.appendToSystemMessage({
24536
+ return appendAggregatedUseCommitmentPlaceholder({
24414
24537
  ...requirements,
24415
24538
  tools: updatedTools,
24416
24539
  _metadata: {
24417
24540
  ...requirements._metadata,
24418
24541
  },
24419
- }, _spaceTrim.spaceTrim((block) => `
24420
- Time and date context:
24421
- - It is ${moment__default["default"]().format('MMMM YYYY')} now.
24422
- - If you need more precise current time information, use the tool "get_current_time".
24423
- ${block(extraInstructions)}
24424
- `));
24542
+ }, this.type);
24425
24543
  }
24426
24544
  /**
24427
24545
  * Gets human-readable titles for tool functions provided by this commitment.
@@ -28077,6 +28195,7 @@
28077
28195
  }
28078
28196
  }
28079
28197
  }
28198
+ requirements = aggregateUseCommitmentSystemMessages(requirements, filteredCommitments);
28080
28199
  // Handle IMPORT commitments for generic files
28081
28200
  // Note: This logic could be moved to ImportCommitmentDefinition, but it needs to be asynchronous
28082
28201
  if (requirements.importedFileUrls && requirements.importedFileUrls.length > 0) {