@promptbook/browser 0.103.0-50 → 0.103.0-52

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
@@ -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.103.0-50';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-52';
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
@@ -2660,9 +2660,13 @@ function normalizeAgentName(rawAgentName) {
2660
2660
  *
2661
2661
  * @private - TODO: [🧠] Maybe should be public?
2662
2662
  */
2663
- function createCommitmentRegex(commitment) {
2664
- const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2665
- const keywordPattern = escapedCommitment.split(/\s+/).join('\\s+');
2663
+ function createCommitmentRegex(commitment, aliases = []) {
2664
+ const allCommitments = [commitment, ...aliases];
2665
+ const patterns = allCommitments.map((c) => {
2666
+ const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2667
+ return escapedCommitment.split(/\s+/).join('\\s+');
2668
+ });
2669
+ const keywordPattern = patterns.join('|');
2666
2670
  const regex = new RegExp(`^\\s*(?<type>${keywordPattern})\\b\\s+(?<contents>.+)$`, 'gim');
2667
2671
  return regex;
2668
2672
  }
@@ -2675,9 +2679,13 @@ function createCommitmentRegex(commitment) {
2675
2679
  *
2676
2680
  * @private
2677
2681
  */
2678
- function createCommitmentTypeRegex(commitment) {
2679
- const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2680
- const keywordPattern = escapedCommitment.split(/\s+/).join('\\s+');
2682
+ function createCommitmentTypeRegex(commitment, aliases = []) {
2683
+ const allCommitments = [commitment, ...aliases];
2684
+ const patterns = allCommitments.map((c) => {
2685
+ const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2686
+ return escapedCommitment.split(/\s+/).join('\\s+');
2687
+ });
2688
+ const keywordPattern = patterns.join('|');
2681
2689
  const regex = new RegExp(`^\\s*(?<type>${keywordPattern})\\b`, 'gim');
2682
2690
  return regex;
2683
2691
  }
@@ -2689,22 +2697,23 @@ function createCommitmentTypeRegex(commitment) {
2689
2697
  * @private
2690
2698
  */
2691
2699
  class BaseCommitmentDefinition {
2692
- constructor(type) {
2700
+ constructor(type, aliases = []) {
2693
2701
  this.type = type;
2702
+ this.aliases = aliases;
2694
2703
  }
2695
2704
  /**
2696
2705
  * Creates a regex pattern to match this commitment in agent source
2697
2706
  * Uses the existing createCommitmentRegex function as internal helper
2698
2707
  */
2699
2708
  createRegex() {
2700
- return createCommitmentRegex(this.type);
2709
+ return createCommitmentRegex(this.type, this.aliases);
2701
2710
  }
2702
2711
  /**
2703
2712
  * Creates a regex pattern to match just the commitment type
2704
2713
  * Uses the existing createCommitmentTypeRegex function as internal helper
2705
2714
  */
2706
2715
  createTypeRegex() {
2707
- return createCommitmentTypeRegex(this.type);
2716
+ return createCommitmentTypeRegex(this.type, this.aliases);
2708
2717
  }
2709
2718
  /**
2710
2719
  * Helper method to create a new requirements object with updated system message
@@ -3616,6 +3625,165 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
3616
3625
  * Note: [💞] Ignore a discrepancy between file name and entity name
3617
3626
  */
3618
3627
 
3628
+ /**
3629
+ * META COLOR commitment definition
3630
+ *
3631
+ * The META COLOR commitment sets the agent's accent color.
3632
+ * This commitment is special because it doesn't affect the system message,
3633
+ * but is handled separately in the parsing logic.
3634
+ *
3635
+ * Example usage in agent source:
3636
+ *
3637
+ * ```book
3638
+ * META COLOR #ff0000
3639
+ * META COLOR #00ff00
3640
+ * ```
3641
+ *
3642
+ * @private [🪔] Maybe export the commitments through some package
3643
+ */
3644
+ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
3645
+ constructor() {
3646
+ super('META COLOR', ['COLOR']);
3647
+ }
3648
+ /**
3649
+ * Short one-line description of META COLOR.
3650
+ */
3651
+ get description() {
3652
+ return "Set the agent's accent color.";
3653
+ }
3654
+ /**
3655
+ * Markdown documentation for META COLOR commitment.
3656
+ */
3657
+ get documentation() {
3658
+ return spaceTrim(`
3659
+ # META COLOR
3660
+
3661
+ Sets the agent's accent color.
3662
+
3663
+ ## Key aspects
3664
+
3665
+ - Does not modify the agent's behavior or responses.
3666
+ - Only one \`META COLOR\` should be used per agent.
3667
+ - If multiple are specified, the last one takes precedence.
3668
+ - Used for visual representation in user interfaces.
3669
+
3670
+ ## Examples
3671
+
3672
+ \`\`\`book
3673
+ Professional Assistant
3674
+
3675
+ META COLOR #3498db
3676
+ PERSONA You are a professional business assistant
3677
+ \`\`\`
3678
+
3679
+ \`\`\`book
3680
+ Creative Helper
3681
+
3682
+ META COLOR #e74c3c
3683
+ PERSONA You are a creative and inspiring assistant
3684
+ \`\`\`
3685
+ `);
3686
+ }
3687
+ applyToAgentModelRequirements(requirements, content) {
3688
+ // META COLOR doesn't modify the system message or model requirements
3689
+ // It's handled separately in the parsing logic for profile color extraction
3690
+ // This method exists for consistency with the CommitmentDefinition interface
3691
+ return requirements;
3692
+ }
3693
+ /**
3694
+ * Extracts the profile color from the content
3695
+ * This is used by the parsing logic
3696
+ */
3697
+ extractProfileColor(content) {
3698
+ const trimmedContent = content.trim();
3699
+ return trimmedContent || null;
3700
+ }
3701
+ }
3702
+ /**
3703
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3704
+ */
3705
+
3706
+ /**
3707
+ * META IMAGE commitment definition
3708
+ *
3709
+ * The META IMAGE commitment sets the agent's avatar/profile image URL.
3710
+ * This commitment is special because it doesn't affect the system message,
3711
+ * but is handled separately in the parsing logic.
3712
+ *
3713
+ * Example usage in agent source:
3714
+ *
3715
+ * ```book
3716
+ * META IMAGE https://example.com/avatar.jpg
3717
+ * META IMAGE /assets/agent-avatar.png
3718
+ * ```
3719
+ *
3720
+ * @private [🪔] Maybe export the commitments through some package
3721
+ */
3722
+ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
3723
+ constructor() {
3724
+ super('META IMAGE', ['IMAGE']);
3725
+ }
3726
+ /**
3727
+ * Short one-line description of META IMAGE.
3728
+ */
3729
+ get description() {
3730
+ return "Set the agent's profile image URL.";
3731
+ }
3732
+ /**
3733
+ * Markdown documentation for META IMAGE commitment.
3734
+ */
3735
+ get documentation() {
3736
+ return spaceTrim(`
3737
+ # META IMAGE
3738
+
3739
+ Sets the agent's avatar/profile image URL.
3740
+
3741
+ ## Key aspects
3742
+
3743
+ - Does not modify the agent's behavior or responses.
3744
+ - Only one \`META IMAGE\` should be used per agent.
3745
+ - If multiple are specified, the last one takes precedence.
3746
+ - Used for visual representation in user interfaces.
3747
+
3748
+ ## Examples
3749
+
3750
+ \`\`\`book
3751
+ Professional Assistant
3752
+
3753
+ META IMAGE https://example.com/professional-avatar.jpg
3754
+ PERSONA You are a professional business assistant
3755
+ STYLE Maintain a formal and courteous tone
3756
+ \`\`\`
3757
+
3758
+ \`\`\`book
3759
+ Creative Helper
3760
+
3761
+ META IMAGE /assets/creative-bot-avatar.png
3762
+ PERSONA You are a creative and inspiring assistant
3763
+ STYLE Be enthusiastic and encouraging
3764
+ ACTION Can help with brainstorming and ideation
3765
+ \`\`\`
3766
+ `);
3767
+ }
3768
+ applyToAgentModelRequirements(requirements, content) {
3769
+ // META IMAGE doesn't modify the system message or model requirements
3770
+ // It's handled separately in the parsing logic for profile image extraction
3771
+ // This method exists for consistency with the CommitmentDefinition interface
3772
+ return requirements;
3773
+ }
3774
+ /**
3775
+ * Extracts the profile image URL from the content
3776
+ * This is used by the parsing logic
3777
+ */
3778
+ extractProfileImageUrl(content) {
3779
+ const trimmedContent = content.trim();
3780
+ return trimmedContent || null;
3781
+ }
3782
+ }
3783
+ /**
3784
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3785
+ */
3786
+
3619
3787
  /**
3620
3788
  * MODEL commitment definition
3621
3789
  *
@@ -4523,6 +4691,8 @@ const COMMITMENT_REGISTRY = [
4523
4691
  new ModelCommitmentDefinition('MODELS'),
4524
4692
  new ActionCommitmentDefinition('ACTION'),
4525
4693
  new ActionCommitmentDefinition('ACTIONS'),
4694
+ new MetaImageCommitmentDefinition(),
4695
+ new MetaColorCommitmentDefinition(),
4526
4696
  new MetaCommitmentDefinition(),
4527
4697
  new NoteCommitmentDefinition('NOTE'),
4528
4698
  new NoteCommitmentDefinition('NOTES'),
@@ -4752,6 +4922,14 @@ function parseAgentSource(agentSource) {
4752
4922
  links.push(spaceTrim$1(commitment.content));
4753
4923
  continue;
4754
4924
  }
4925
+ if (commitment.type === 'META IMAGE') {
4926
+ meta.image = spaceTrim$1(commitment.content);
4927
+ continue;
4928
+ }
4929
+ if (commitment.type === 'META COLOR') {
4930
+ meta.color = spaceTrim$1(commitment.content);
4931
+ continue;
4932
+ }
4755
4933
  if (commitment.type !== 'META') {
4756
4934
  continue;
4757
4935
  }
@@ -4767,6 +4945,10 @@ function parseAgentSource(agentSource) {
4767
4945
  if (!meta.image) {
4768
4946
  meta.image = generatePlaceholderAgentProfileImageUrl(parseResult.agentName || '!!');
4769
4947
  }
4948
+ // Generate fullname fallback if no meta fullname specified
4949
+ if (!meta.fullname) {
4950
+ meta.fullname = parseResult.agentName || createDefaultAgentName(agentSource);
4951
+ }
4770
4952
  // Parse parameters using unified approach - both @Parameter and {parameter} notations
4771
4953
  // are treated as the same syntax feature with unified representation
4772
4954
  const parameters = parseParameters(agentSource);