@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/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-1';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-3';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1075,6 +1075,7 @@
1075
1075
  SEPARATOR: Color.fromHex('#cccccc'),
1076
1076
  COMMITMENT: Color.fromHex('#DA0F78'),
1077
1077
  PARAMETER: Color.fromHex('#8e44ad'),
1078
+ CODE_BLOCK: Color.fromHex('#7700ffff'),
1078
1079
  });
1079
1080
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
1080
1081
  /**
@@ -2795,6 +2796,14 @@
2795
2796
  return this.appendToSystemMessage(requirements, commentSection);
2796
2797
  }
2797
2798
  }
2799
+ /**
2800
+ * Gets tool function implementations provided by this commitment
2801
+ *
2802
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
2803
+ */
2804
+ getToolFunctions() {
2805
+ return {};
2806
+ }
2798
2807
  }
2799
2808
 
2800
2809
  /**
@@ -3410,79 +3419,6 @@
3410
3419
  * Note: [💞] Ignore a discrepancy between file name and entity name
3411
3420
  */
3412
3421
 
3413
- /**
3414
- * IMPORT commitment definition
3415
- *
3416
- * The IMPORT commitment tells the agent to import content from another agent at the current location.
3417
- *
3418
- * Example usage in agent source:
3419
- *
3420
- * ```book
3421
- * IMPORT https://s6.ptbk.io/benjamin-white
3422
- * ```
3423
- *
3424
- * @private [🪔] Maybe export the commitments through some package
3425
- */
3426
- class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3427
- constructor(type = 'IMPORT') {
3428
- super(type);
3429
- }
3430
- /**
3431
- * Short one-line description of IMPORT.
3432
- */
3433
- get description() {
3434
- return 'Import content from another agent.';
3435
- }
3436
- /**
3437
- * Icon for this commitment.
3438
- */
3439
- get icon() {
3440
- return '📥';
3441
- }
3442
- /**
3443
- * Markdown documentation for IMPORT commitment.
3444
- */
3445
- get documentation() {
3446
- return spaceTrim$1.spaceTrim(`
3447
- # ${this.type}
3448
-
3449
- Imports content from another agent at the location of the commitment.
3450
-
3451
- ## Examples
3452
-
3453
- \`\`\`book
3454
- My AI Agent
3455
-
3456
- IMPORT https://s6.ptbk.io/benjamin-white
3457
- RULE Speak only in English.
3458
- \`\`\`
3459
- `);
3460
- }
3461
- applyToAgentModelRequirements(requirements, content) {
3462
- const trimmedContent = content.trim();
3463
- if (!trimmedContent) {
3464
- return requirements;
3465
- }
3466
- if (!isValidAgentUrl(trimmedContent)) {
3467
- throw new Error(spaceTrim$1.spaceTrim((block) => `
3468
- Invalid agent URL in IMPORT commitment: "${trimmedContent}"
3469
-
3470
- \`\`\`book
3471
- ${block(content)}
3472
- \`\`\`
3473
- `));
3474
- }
3475
- const importedAgentUrl = trimmedContent;
3476
- return {
3477
- ...requirements,
3478
- importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3479
- };
3480
- }
3481
- }
3482
- /**
3483
- * Note: [💞] Ignore a discrepancy between file name and entity name
3484
- */
3485
-
3486
3422
  /**
3487
3423
  * GOAL commitment definition
3488
3424
  *
@@ -3583,6 +3519,87 @@
3583
3519
  * Note: [💞] Ignore a discrepancy between file name and entity name
3584
3520
  */
3585
3521
 
3522
+ /**
3523
+ * IMPORT commitment definition
3524
+ *
3525
+ * The IMPORT commitment tells the agent to import content from another agent at the current location.
3526
+ *
3527
+ * Example usage in agent source:
3528
+ *
3529
+ * ```book
3530
+ * IMPORT https://s6.ptbk.io/benjamin-white
3531
+ * ```
3532
+ *
3533
+ * @private [🪔] Maybe export the commitments through some package
3534
+ */
3535
+ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3536
+ constructor(type = 'IMPORT') {
3537
+ super(type);
3538
+ }
3539
+ /**
3540
+ * Short one-line description of IMPORT.
3541
+ */
3542
+ get description() {
3543
+ return 'Import content from another agent or a generic text file.';
3544
+ }
3545
+ /**
3546
+ * Icon for this commitment.
3547
+ */
3548
+ get icon() {
3549
+ return '📥';
3550
+ }
3551
+ /**
3552
+ * Markdown documentation for IMPORT commitment.
3553
+ */
3554
+ get documentation() {
3555
+ return spaceTrim$1.spaceTrim(`
3556
+ # ${this.type}
3557
+
3558
+ Imports content from another agent or a generic text file at the location of the commitment.
3559
+
3560
+ ## Examples
3561
+
3562
+ \`\`\`book
3563
+ My AI Agent
3564
+
3565
+ IMPORT https://s6.ptbk.io/benjamin-white
3566
+ IMPORT https://example.com/some-text-file.txt
3567
+ IMPORT ./path/to/local-file.json
3568
+ RULE Speak only in English.
3569
+ \`\`\`
3570
+ `);
3571
+ }
3572
+ applyToAgentModelRequirements(requirements, content) {
3573
+ const trimmedContent = content.trim();
3574
+ if (!trimmedContent) {
3575
+ return requirements;
3576
+ }
3577
+ if (isValidAgentUrl(trimmedContent)) {
3578
+ const importedAgentUrl = trimmedContent;
3579
+ return {
3580
+ ...requirements,
3581
+ importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3582
+ };
3583
+ }
3584
+ if (isValidUrl(trimmedContent) || isValidFilePath(trimmedContent)) {
3585
+ return {
3586
+ ...requirements,
3587
+ importedFileUrls: [...(requirements.importedFileUrls || []), trimmedContent],
3588
+ };
3589
+ }
3590
+ throw new Error(spaceTrim$1.spaceTrim((block) => `
3591
+ Invalid agent URL or file path in IMPORT commitment: "${trimmedContent}"
3592
+
3593
+ \`\`\`book
3594
+ ${block(content)}
3595
+ \`\`\`
3596
+ `));
3597
+ }
3598
+ }
3599
+ /**
3600
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3601
+ */
3602
+
3586
3603
  /**
3587
3604
  * KNOWLEDGE commitment definition
3588
3605
  *
@@ -4002,7 +4019,13 @@
4002
4019
  `);
4003
4020
  }
4004
4021
  applyToAgentModelRequirements(requirements, content) {
4005
- return requirements;
4022
+ // INITIAL MESSAGE is for UI display purposes and for conversation history construction.
4023
+ const newSample = { question: null, answer: content };
4024
+ const newSamples = [...(requirements.samples || []), newSample];
4025
+ return {
4026
+ ...requirements,
4027
+ samples: newSamples,
4028
+ };
4006
4029
  }
4007
4030
  }
4008
4031
 
@@ -5034,27 +5057,16 @@
5034
5057
  `);
5035
5058
  }
5036
5059
  applyToAgentModelRequirements(requirements, content) {
5037
- var _a;
5038
5060
  // The NOTE commitment makes no changes to the system message or model requirements
5039
5061
  // It only stores the note content in metadata for documentation purposes
5040
- const trimmedContent = content.trim();
5041
- if (!trimmedContent) {
5062
+ const trimmedContent = spaceTrim$1.spaceTrim(content);
5063
+ if (trimmedContent === '') {
5042
5064
  return requirements;
5043
5065
  }
5044
- // Get existing note content from metadata
5045
- const existingNoteContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.NOTE) || '';
5046
- // Merge the new content with existing note content
5047
- // When multiple NOTE commitments exist, they are aggregated together
5048
- const mergedNoteContent = existingNoteContent ? `${existingNoteContent}\n${trimmedContent}` : trimmedContent;
5049
- // Store the merged note content in metadata for debugging and inspection
5050
- const updatedMetadata = {
5051
- ...requirements.metadata,
5052
- NOTE: mergedNoteContent,
5053
- };
5054
- // Return requirements with updated metadata but no changes to system message
5066
+ // Return requirements with updated notes but no changes to system message
5055
5067
  return {
5056
5068
  ...requirements,
5057
- metadata: updatedMetadata,
5069
+ notes: [...(requirements.notes || []), trimmedContent],
5058
5070
  };
5059
5071
  }
5060
5072
  }
@@ -6073,6 +6085,104 @@
6073
6085
  * Note: [💞] Ignore a discrepancy between file name and entity name
6074
6086
  */
6075
6087
 
6088
+ /**
6089
+ * USE TIME commitment definition
6090
+ *
6091
+ * The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
6092
+ *
6093
+ * Example usage in agent source:
6094
+ *
6095
+ * ```book
6096
+ * USE TIME
6097
+ * ```
6098
+ *
6099
+ * @private [🪔] Maybe export the commitments through some package
6100
+ */
6101
+ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
6102
+ constructor() {
6103
+ super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
6104
+ }
6105
+ /**
6106
+ * Short one-line description of USE TIME.
6107
+ */
6108
+ get description() {
6109
+ return 'Enable the agent to determine the current date and time.';
6110
+ }
6111
+ /**
6112
+ * Icon for this commitment.
6113
+ */
6114
+ get icon() {
6115
+ return '🕒';
6116
+ }
6117
+ /**
6118
+ * Markdown documentation for USE TIME commitment.
6119
+ */
6120
+ get documentation() {
6121
+ return spaceTrim$1.spaceTrim(`
6122
+ # USE TIME
6123
+
6124
+ Enables the agent to determine the current date and time.
6125
+
6126
+ ## Key aspects
6127
+
6128
+ - This tool won't receive any input.
6129
+ - It outputs the current date and time as an ISO 8601 string.
6130
+ - Allows the agent to answer questions about the current time or date.
6131
+
6132
+ ## Examples
6133
+
6134
+ \`\`\`book
6135
+ Time-aware Assistant
6136
+
6137
+ PERSONA You are a helpful assistant who knows the current time.
6138
+ USE TIME
6139
+ \`\`\`
6140
+ `);
6141
+ }
6142
+ applyToAgentModelRequirements(requirements, content) {
6143
+ // Get existing tools array or create new one
6144
+ const existingTools = requirements.tools || [];
6145
+ // Add 'get_current_time' to tools if not already present
6146
+ const updatedTools = existingTools.some((tool) => tool.name === 'get_current_time')
6147
+ ? existingTools
6148
+ : [
6149
+ ...existingTools,
6150
+ {
6151
+ name: 'get_current_time',
6152
+ description: 'Get the current date and time in ISO 8601 format.',
6153
+ parameters: {
6154
+ type: 'object',
6155
+ properties: {},
6156
+ required: [],
6157
+ },
6158
+ },
6159
+ // <- TODO: !!!! define the function in LLM tools
6160
+ ];
6161
+ // Return requirements with updated tools and metadata
6162
+ return {
6163
+ ...requirements,
6164
+ tools: updatedTools,
6165
+ metadata: {
6166
+ ...requirements.metadata,
6167
+ },
6168
+ };
6169
+ }
6170
+ /**
6171
+ * Gets the `get_current_time` tool function implementation.
6172
+ */
6173
+ getToolFunctions() {
6174
+ return {
6175
+ async get_current_time() {
6176
+ console.log('!!!! [Tool] get_current_time called');
6177
+ return new Date().toISOString();
6178
+ },
6179
+ };
6180
+ }
6181
+ }
6182
+ /**
6183
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6184
+ */
6185
+
6076
6186
  /**
6077
6187
  * Placeholder commitment definition for commitments that are not yet implemented
6078
6188
  *
@@ -6140,7 +6250,6 @@
6140
6250
  }
6141
6251
  }
6142
6252
 
6143
- // Import all commitment definition classes
6144
6253
  /**
6145
6254
  * Registry of all available commitment definitions
6146
6255
  * This array contains instances of all commitment definitions
@@ -6157,10 +6266,10 @@
6157
6266
  new MemoryCommitmentDefinition('MEMORIES'),
6158
6267
  new StyleCommitmentDefinition('STYLE'),
6159
6268
  new StyleCommitmentDefinition('STYLES'),
6160
- new RuleCommitmentDefinition('RULE'),
6161
6269
  new RuleCommitmentDefinition('RULES'),
6162
- new LanguageCommitmentDefinition('LANGUAGE'),
6270
+ new RuleCommitmentDefinition('RULE'),
6163
6271
  new LanguageCommitmentDefinition('LANGUAGES'),
6272
+ new LanguageCommitmentDefinition('LANGUAGE'),
6164
6273
  new SampleCommitmentDefinition('SAMPLE'),
6165
6274
  new SampleCommitmentDefinition('EXAMPLE'),
6166
6275
  new FormatCommitmentDefinition('FORMAT'),
@@ -6200,6 +6309,7 @@
6200
6309
  new ClosedCommitmentDefinition(),
6201
6310
  new UseBrowserCommitmentDefinition(),
6202
6311
  new UseSearchEngineCommitmentDefinition(),
6312
+ new UseTimeCommitmentDefinition(),
6203
6313
  new UseMcpCommitmentDefinition(),
6204
6314
  new UseCommitmentDefinition(),
6205
6315
  // Not yet implemented commitments (using placeholder)
@@ -6293,11 +6403,37 @@
6293
6403
  let currentCommitment = null;
6294
6404
  // Process lines starting from after the agent name line
6295
6405
  const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
6406
+ let isInsideCodeBlock = false;
6296
6407
  for (let i = startIndex; i < lines.length; i++) {
6297
6408
  const line = lines[i];
6298
6409
  if (line === undefined) {
6299
6410
  continue;
6300
6411
  }
6412
+ const trimmedLine = line.trim();
6413
+ // Check if this line starts or ends a code block
6414
+ if (trimmedLine.startsWith('```')) {
6415
+ isInsideCodeBlock = !isInsideCodeBlock;
6416
+ if (currentCommitment) {
6417
+ // If we are inside a commitment, the code block is part of it
6418
+ currentCommitment.contentLines.push(line);
6419
+ }
6420
+ else {
6421
+ // If we are not inside a commitment, the code block is non-commitment
6422
+ nonCommitmentLines.push(line);
6423
+ }
6424
+ continue;
6425
+ }
6426
+ if (isInsideCodeBlock) {
6427
+ if (currentCommitment) {
6428
+ // If we are inside a commitment and a code block, the line is part of the commitment
6429
+ currentCommitment.contentLines.push(line);
6430
+ }
6431
+ else {
6432
+ // If we are inside a code block but not a commitment, the line is non-commitment
6433
+ nonCommitmentLines.push(line);
6434
+ }
6435
+ continue;
6436
+ }
6301
6437
  // Check if this line starts a new commitment
6302
6438
  let foundNewCommitment = false;
6303
6439
  for (const definition of COMMITMENT_REGISTRY) {
@@ -6471,7 +6607,24 @@
6471
6607
  const meta = {};
6472
6608
  const links = [];
6473
6609
  const capabilities = [];
6610
+ const samples = [];
6611
+ let pendingUserMessage = null;
6474
6612
  for (const commitment of parseResult.commitments) {
6613
+ if (commitment.type === 'INITIAL MESSAGE') {
6614
+ samples.push({ question: null, answer: commitment.content });
6615
+ continue;
6616
+ }
6617
+ if (commitment.type === 'USER MESSAGE') {
6618
+ pendingUserMessage = commitment.content;
6619
+ continue;
6620
+ }
6621
+ if (commitment.type === 'AGENT MESSAGE') {
6622
+ if (pendingUserMessage !== null) {
6623
+ samples.push({ question: pendingUserMessage, answer: commitment.content });
6624
+ pendingUserMessage = null;
6625
+ }
6626
+ continue;
6627
+ }
6475
6628
  if (commitment.type === 'USE BROWSER') {
6476
6629
  capabilities.push({
6477
6630
  type: 'browser',
@@ -6488,6 +6641,37 @@
6488
6641
  });
6489
6642
  continue;
6490
6643
  }
6644
+ if (commitment.type === 'USE TIME') {
6645
+ capabilities.push({
6646
+ type: 'time',
6647
+ label: 'Time',
6648
+ iconName: 'Clock',
6649
+ });
6650
+ continue;
6651
+ }
6652
+ if (commitment.type === 'IMPORT') {
6653
+ const content = spaceTrim__default["default"](commitment.content).split('\n')[0] || '';
6654
+ let label = content;
6655
+ const iconName = 'Download';
6656
+ try {
6657
+ if (content.startsWith('http://') || content.startsWith('https://')) {
6658
+ const url = new URL(content);
6659
+ label = url.hostname.replace(/^www\./, '') + '.../' + url.pathname.split('/').pop();
6660
+ }
6661
+ else if (content.startsWith('./') || content.startsWith('../') || content.startsWith('/')) {
6662
+ label = content.split('/').pop() || content;
6663
+ }
6664
+ }
6665
+ catch (e) {
6666
+ // Invalid URL or path, keep default label
6667
+ }
6668
+ capabilities.push({
6669
+ type: 'knowledge',
6670
+ label,
6671
+ iconName,
6672
+ });
6673
+ continue;
6674
+ }
6491
6675
  if (commitment.type === 'KNOWLEDGE') {
6492
6676
  const content = spaceTrim__default["default"](commitment.content).split('\n')[0] || '';
6493
6677
  let label = content;
@@ -6572,6 +6756,7 @@
6572
6756
  links,
6573
6757
  parameters,
6574
6758
  capabilities,
6759
+ samples,
6575
6760
  };
6576
6761
  }
6577
6762
  /**