@promptbook/browser 0.105.0-1 → 0.105.0-3

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.
Files changed (38) hide show
  1. package/esm/index.es.js +278 -93
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +10 -3
  6. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
  7. package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
  10. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
  12. package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +40 -0
  13. package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
  14. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +8 -0
  15. package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +8 -0
  16. package/esm/typings/src/commitments/index.d.ts +11 -2
  17. package/esm/typings/src/config.d.ts +1 -0
  18. package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
  19. package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
  20. package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
  21. package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
  22. package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
  23. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
  24. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
  25. package/esm/typings/src/llm-providers/agent/Agent.d.ts +9 -2
  26. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
  27. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
  28. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  29. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
  30. package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
  31. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
  32. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
  33. package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
  34. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
  35. package/esm/typings/src/version.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/umd/index.umd.js +278 -93
  38. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-1';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-3';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1071,6 +1071,7 @@ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
1071
1071
  SEPARATOR: Color.fromHex('#cccccc'),
1072
1072
  COMMITMENT: Color.fromHex('#DA0F78'),
1073
1073
  PARAMETER: Color.fromHex('#8e44ad'),
1074
+ CODE_BLOCK: Color.fromHex('#7700ffff'),
1074
1075
  });
1075
1076
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
1076
1077
  /**
@@ -2791,6 +2792,14 @@ class BaseCommitmentDefinition {
2791
2792
  return this.appendToSystemMessage(requirements, commentSection);
2792
2793
  }
2793
2794
  }
2795
+ /**
2796
+ * Gets tool function implementations provided by this commitment
2797
+ *
2798
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
2799
+ */
2800
+ getToolFunctions() {
2801
+ return {};
2802
+ }
2794
2803
  }
2795
2804
 
2796
2805
  /**
@@ -3406,79 +3415,6 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
3406
3415
  * Note: [💞] Ignore a discrepancy between file name and entity name
3407
3416
  */
3408
3417
 
3409
- /**
3410
- * IMPORT commitment definition
3411
- *
3412
- * The IMPORT commitment tells the agent to import content from another agent at the current location.
3413
- *
3414
- * Example usage in agent source:
3415
- *
3416
- * ```book
3417
- * IMPORT https://s6.ptbk.io/benjamin-white
3418
- * ```
3419
- *
3420
- * @private [🪔] Maybe export the commitments through some package
3421
- */
3422
- class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3423
- constructor(type = 'IMPORT') {
3424
- super(type);
3425
- }
3426
- /**
3427
- * Short one-line description of IMPORT.
3428
- */
3429
- get description() {
3430
- return 'Import content from another agent.';
3431
- }
3432
- /**
3433
- * Icon for this commitment.
3434
- */
3435
- get icon() {
3436
- return '📥';
3437
- }
3438
- /**
3439
- * Markdown documentation for IMPORT commitment.
3440
- */
3441
- get documentation() {
3442
- return spaceTrim$1(`
3443
- # ${this.type}
3444
-
3445
- Imports content from another agent at the location of the commitment.
3446
-
3447
- ## Examples
3448
-
3449
- \`\`\`book
3450
- My AI Agent
3451
-
3452
- IMPORT https://s6.ptbk.io/benjamin-white
3453
- RULE Speak only in English.
3454
- \`\`\`
3455
- `);
3456
- }
3457
- applyToAgentModelRequirements(requirements, content) {
3458
- const trimmedContent = content.trim();
3459
- if (!trimmedContent) {
3460
- return requirements;
3461
- }
3462
- if (!isValidAgentUrl(trimmedContent)) {
3463
- throw new Error(spaceTrim$1((block) => `
3464
- Invalid agent URL in IMPORT commitment: "${trimmedContent}"
3465
-
3466
- \`\`\`book
3467
- ${block(content)}
3468
- \`\`\`
3469
- `));
3470
- }
3471
- const importedAgentUrl = trimmedContent;
3472
- return {
3473
- ...requirements,
3474
- importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3475
- };
3476
- }
3477
- }
3478
- /**
3479
- * Note: [💞] Ignore a discrepancy between file name and entity name
3480
- */
3481
-
3482
3418
  /**
3483
3419
  * GOAL commitment definition
3484
3420
  *
@@ -3579,6 +3515,87 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
3579
3515
  * Note: [💞] Ignore a discrepancy between file name and entity name
3580
3516
  */
3581
3517
 
3518
+ /**
3519
+ * IMPORT commitment definition
3520
+ *
3521
+ * The IMPORT commitment tells the agent to import content from another agent at the current location.
3522
+ *
3523
+ * Example usage in agent source:
3524
+ *
3525
+ * ```book
3526
+ * IMPORT https://s6.ptbk.io/benjamin-white
3527
+ * ```
3528
+ *
3529
+ * @private [🪔] Maybe export the commitments through some package
3530
+ */
3531
+ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3532
+ constructor(type = 'IMPORT') {
3533
+ super(type);
3534
+ }
3535
+ /**
3536
+ * Short one-line description of IMPORT.
3537
+ */
3538
+ get description() {
3539
+ return 'Import content from another agent or a generic text file.';
3540
+ }
3541
+ /**
3542
+ * Icon for this commitment.
3543
+ */
3544
+ get icon() {
3545
+ return '📥';
3546
+ }
3547
+ /**
3548
+ * Markdown documentation for IMPORT commitment.
3549
+ */
3550
+ get documentation() {
3551
+ return spaceTrim$1(`
3552
+ # ${this.type}
3553
+
3554
+ Imports content from another agent or a generic text file at the location of the commitment.
3555
+
3556
+ ## Examples
3557
+
3558
+ \`\`\`book
3559
+ My AI Agent
3560
+
3561
+ IMPORT https://s6.ptbk.io/benjamin-white
3562
+ IMPORT https://example.com/some-text-file.txt
3563
+ IMPORT ./path/to/local-file.json
3564
+ RULE Speak only in English.
3565
+ \`\`\`
3566
+ `);
3567
+ }
3568
+ applyToAgentModelRequirements(requirements, content) {
3569
+ const trimmedContent = content.trim();
3570
+ if (!trimmedContent) {
3571
+ return requirements;
3572
+ }
3573
+ if (isValidAgentUrl(trimmedContent)) {
3574
+ const importedAgentUrl = trimmedContent;
3575
+ return {
3576
+ ...requirements,
3577
+ importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3578
+ };
3579
+ }
3580
+ if (isValidUrl(trimmedContent) || isValidFilePath(trimmedContent)) {
3581
+ return {
3582
+ ...requirements,
3583
+ importedFileUrls: [...(requirements.importedFileUrls || []), trimmedContent],
3584
+ };
3585
+ }
3586
+ throw new Error(spaceTrim$1((block) => `
3587
+ Invalid agent URL or file path in IMPORT commitment: "${trimmedContent}"
3588
+
3589
+ \`\`\`book
3590
+ ${block(content)}
3591
+ \`\`\`
3592
+ `));
3593
+ }
3594
+ }
3595
+ /**
3596
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3597
+ */
3598
+
3582
3599
  /**
3583
3600
  * KNOWLEDGE commitment definition
3584
3601
  *
@@ -3998,7 +4015,13 @@ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
3998
4015
  `);
3999
4016
  }
4000
4017
  applyToAgentModelRequirements(requirements, content) {
4001
- return requirements;
4018
+ // INITIAL MESSAGE is for UI display purposes and for conversation history construction.
4019
+ const newSample = { question: null, answer: content };
4020
+ const newSamples = [...(requirements.samples || []), newSample];
4021
+ return {
4022
+ ...requirements,
4023
+ samples: newSamples,
4024
+ };
4002
4025
  }
4003
4026
  }
4004
4027
 
@@ -5030,27 +5053,16 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
5030
5053
  `);
5031
5054
  }
5032
5055
  applyToAgentModelRequirements(requirements, content) {
5033
- var _a;
5034
5056
  // The NOTE commitment makes no changes to the system message or model requirements
5035
5057
  // It only stores the note content in metadata for documentation purposes
5036
- const trimmedContent = content.trim();
5037
- if (!trimmedContent) {
5058
+ const trimmedContent = spaceTrim$1(content);
5059
+ if (trimmedContent === '') {
5038
5060
  return requirements;
5039
5061
  }
5040
- // Get existing note content from metadata
5041
- const existingNoteContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.NOTE) || '';
5042
- // Merge the new content with existing note content
5043
- // When multiple NOTE commitments exist, they are aggregated together
5044
- const mergedNoteContent = existingNoteContent ? `${existingNoteContent}\n${trimmedContent}` : trimmedContent;
5045
- // Store the merged note content in metadata for debugging and inspection
5046
- const updatedMetadata = {
5047
- ...requirements.metadata,
5048
- NOTE: mergedNoteContent,
5049
- };
5050
- // Return requirements with updated metadata but no changes to system message
5062
+ // Return requirements with updated notes but no changes to system message
5051
5063
  return {
5052
5064
  ...requirements,
5053
- metadata: updatedMetadata,
5065
+ notes: [...(requirements.notes || []), trimmedContent],
5054
5066
  };
5055
5067
  }
5056
5068
  }
@@ -6069,6 +6081,104 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
6069
6081
  * Note: [💞] Ignore a discrepancy between file name and entity name
6070
6082
  */
6071
6083
 
6084
+ /**
6085
+ * USE TIME commitment definition
6086
+ *
6087
+ * The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
6088
+ *
6089
+ * Example usage in agent source:
6090
+ *
6091
+ * ```book
6092
+ * USE TIME
6093
+ * ```
6094
+ *
6095
+ * @private [🪔] Maybe export the commitments through some package
6096
+ */
6097
+ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
6098
+ constructor() {
6099
+ super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
6100
+ }
6101
+ /**
6102
+ * Short one-line description of USE TIME.
6103
+ */
6104
+ get description() {
6105
+ return 'Enable the agent to determine the current date and time.';
6106
+ }
6107
+ /**
6108
+ * Icon for this commitment.
6109
+ */
6110
+ get icon() {
6111
+ return '🕒';
6112
+ }
6113
+ /**
6114
+ * Markdown documentation for USE TIME commitment.
6115
+ */
6116
+ get documentation() {
6117
+ return spaceTrim$1(`
6118
+ # USE TIME
6119
+
6120
+ Enables the agent to determine the current date and time.
6121
+
6122
+ ## Key aspects
6123
+
6124
+ - This tool won't receive any input.
6125
+ - It outputs the current date and time as an ISO 8601 string.
6126
+ - Allows the agent to answer questions about the current time or date.
6127
+
6128
+ ## Examples
6129
+
6130
+ \`\`\`book
6131
+ Time-aware Assistant
6132
+
6133
+ PERSONA You are a helpful assistant who knows the current time.
6134
+ USE TIME
6135
+ \`\`\`
6136
+ `);
6137
+ }
6138
+ applyToAgentModelRequirements(requirements, content) {
6139
+ // Get existing tools array or create new one
6140
+ const existingTools = requirements.tools || [];
6141
+ // Add 'get_current_time' to tools if not already present
6142
+ const updatedTools = existingTools.some((tool) => tool.name === 'get_current_time')
6143
+ ? existingTools
6144
+ : [
6145
+ ...existingTools,
6146
+ {
6147
+ name: 'get_current_time',
6148
+ description: 'Get the current date and time in ISO 8601 format.',
6149
+ parameters: {
6150
+ type: 'object',
6151
+ properties: {},
6152
+ required: [],
6153
+ },
6154
+ },
6155
+ // <- TODO: !!!! define the function in LLM tools
6156
+ ];
6157
+ // Return requirements with updated tools and metadata
6158
+ return {
6159
+ ...requirements,
6160
+ tools: updatedTools,
6161
+ metadata: {
6162
+ ...requirements.metadata,
6163
+ },
6164
+ };
6165
+ }
6166
+ /**
6167
+ * Gets the `get_current_time` tool function implementation.
6168
+ */
6169
+ getToolFunctions() {
6170
+ return {
6171
+ async get_current_time() {
6172
+ console.log('!!!! [Tool] get_current_time called');
6173
+ return new Date().toISOString();
6174
+ },
6175
+ };
6176
+ }
6177
+ }
6178
+ /**
6179
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6180
+ */
6181
+
6072
6182
  /**
6073
6183
  * Placeholder commitment definition for commitments that are not yet implemented
6074
6184
  *
@@ -6136,7 +6246,6 @@ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
6136
6246
  }
6137
6247
  }
6138
6248
 
6139
- // Import all commitment definition classes
6140
6249
  /**
6141
6250
  * Registry of all available commitment definitions
6142
6251
  * This array contains instances of all commitment definitions
@@ -6153,10 +6262,10 @@ const COMMITMENT_REGISTRY = [
6153
6262
  new MemoryCommitmentDefinition('MEMORIES'),
6154
6263
  new StyleCommitmentDefinition('STYLE'),
6155
6264
  new StyleCommitmentDefinition('STYLES'),
6156
- new RuleCommitmentDefinition('RULE'),
6157
6265
  new RuleCommitmentDefinition('RULES'),
6158
- new LanguageCommitmentDefinition('LANGUAGE'),
6266
+ new RuleCommitmentDefinition('RULE'),
6159
6267
  new LanguageCommitmentDefinition('LANGUAGES'),
6268
+ new LanguageCommitmentDefinition('LANGUAGE'),
6160
6269
  new SampleCommitmentDefinition('SAMPLE'),
6161
6270
  new SampleCommitmentDefinition('EXAMPLE'),
6162
6271
  new FormatCommitmentDefinition('FORMAT'),
@@ -6196,6 +6305,7 @@ const COMMITMENT_REGISTRY = [
6196
6305
  new ClosedCommitmentDefinition(),
6197
6306
  new UseBrowserCommitmentDefinition(),
6198
6307
  new UseSearchEngineCommitmentDefinition(),
6308
+ new UseTimeCommitmentDefinition(),
6199
6309
  new UseMcpCommitmentDefinition(),
6200
6310
  new UseCommitmentDefinition(),
6201
6311
  // Not yet implemented commitments (using placeholder)
@@ -6289,11 +6399,37 @@ function parseAgentSourceWithCommitments(agentSource) {
6289
6399
  let currentCommitment = null;
6290
6400
  // Process lines starting from after the agent name line
6291
6401
  const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
6402
+ let isInsideCodeBlock = false;
6292
6403
  for (let i = startIndex; i < lines.length; i++) {
6293
6404
  const line = lines[i];
6294
6405
  if (line === undefined) {
6295
6406
  continue;
6296
6407
  }
6408
+ const trimmedLine = line.trim();
6409
+ // Check if this line starts or ends a code block
6410
+ if (trimmedLine.startsWith('```')) {
6411
+ isInsideCodeBlock = !isInsideCodeBlock;
6412
+ if (currentCommitment) {
6413
+ // If we are inside a commitment, the code block is part of it
6414
+ currentCommitment.contentLines.push(line);
6415
+ }
6416
+ else {
6417
+ // If we are not inside a commitment, the code block is non-commitment
6418
+ nonCommitmentLines.push(line);
6419
+ }
6420
+ continue;
6421
+ }
6422
+ if (isInsideCodeBlock) {
6423
+ if (currentCommitment) {
6424
+ // If we are inside a commitment and a code block, the line is part of the commitment
6425
+ currentCommitment.contentLines.push(line);
6426
+ }
6427
+ else {
6428
+ // If we are inside a code block but not a commitment, the line is non-commitment
6429
+ nonCommitmentLines.push(line);
6430
+ }
6431
+ continue;
6432
+ }
6297
6433
  // Check if this line starts a new commitment
6298
6434
  let foundNewCommitment = false;
6299
6435
  for (const definition of COMMITMENT_REGISTRY) {
@@ -6467,7 +6603,24 @@ function parseAgentSource(agentSource) {
6467
6603
  const meta = {};
6468
6604
  const links = [];
6469
6605
  const capabilities = [];
6606
+ const samples = [];
6607
+ let pendingUserMessage = null;
6470
6608
  for (const commitment of parseResult.commitments) {
6609
+ if (commitment.type === 'INITIAL MESSAGE') {
6610
+ samples.push({ question: null, answer: commitment.content });
6611
+ continue;
6612
+ }
6613
+ if (commitment.type === 'USER MESSAGE') {
6614
+ pendingUserMessage = commitment.content;
6615
+ continue;
6616
+ }
6617
+ if (commitment.type === 'AGENT MESSAGE') {
6618
+ if (pendingUserMessage !== null) {
6619
+ samples.push({ question: pendingUserMessage, answer: commitment.content });
6620
+ pendingUserMessage = null;
6621
+ }
6622
+ continue;
6623
+ }
6471
6624
  if (commitment.type === 'USE BROWSER') {
6472
6625
  capabilities.push({
6473
6626
  type: 'browser',
@@ -6484,6 +6637,37 @@ function parseAgentSource(agentSource) {
6484
6637
  });
6485
6638
  continue;
6486
6639
  }
6640
+ if (commitment.type === 'USE TIME') {
6641
+ capabilities.push({
6642
+ type: 'time',
6643
+ label: 'Time',
6644
+ iconName: 'Clock',
6645
+ });
6646
+ continue;
6647
+ }
6648
+ if (commitment.type === 'IMPORT') {
6649
+ const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
6650
+ let label = content;
6651
+ const iconName = 'Download';
6652
+ try {
6653
+ if (content.startsWith('http://') || content.startsWith('https://')) {
6654
+ const url = new URL(content);
6655
+ label = url.hostname.replace(/^www\./, '') + '.../' + url.pathname.split('/').pop();
6656
+ }
6657
+ else if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
6658
+ label = content.split('/').pop() || content;
6659
+ }
6660
+ }
6661
+ catch (e) {
6662
+ // Invalid URL or path, keep default label
6663
+ }
6664
+ capabilities.push({
6665
+ type: 'knowledge',
6666
+ label,
6667
+ iconName,
6668
+ });
6669
+ continue;
6670
+ }
6487
6671
  if (commitment.type === 'KNOWLEDGE') {
6488
6672
  const content = spaceTrim$2(commitment.content).split('\n')[0] || '';
6489
6673
  let label = content;
@@ -6568,6 +6752,7 @@ function parseAgentSource(agentSource) {
6568
6752
  links,
6569
6753
  parameters,
6570
6754
  capabilities,
6755
+ samples,
6571
6756
  };
6572
6757
  }
6573
6758
  /**