@promptbook/browser 0.103.0-51 → 0.103.0-53

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 (30) hide show
  1. package/esm/index.es.js +326 -10
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/servers.d.ts +8 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  8. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +7 -0
  10. package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +2 -2
  11. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +10 -0
  12. package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgent.d.ts +6 -0
  13. package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +12 -0
  14. package/esm/typings/src/book-components/icons/MicIcon.d.ts +8 -0
  15. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +17 -0
  16. package/esm/typings/src/commitments/MESSAGE/AgentMessageCommitmentDefinition.d.ts +28 -0
  17. package/esm/typings/src/commitments/MESSAGE/UserMessageCommitmentDefinition.d.ts +28 -0
  18. package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +38 -0
  19. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +2 -1
  20. package/esm/typings/src/commitments/index.d.ts +22 -1
  21. package/esm/typings/src/execution/LlmExecutionTools.d.ts +9 -0
  22. package/esm/typings/src/llm-providers/agent/Agent.d.ts +1 -0
  23. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +2 -1
  24. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +10 -1
  25. package/esm/typings/src/utils/normalization/normalizeMessageText.d.ts +9 -0
  26. package/esm/typings/src/utils/normalization/normalizeMessageText.test.d.ts +1 -0
  27. package/esm/typings/src/version.d.ts +1 -1
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +326 -10
  30. 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.103.0-51';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-53';
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
@@ -3315,6 +3324,77 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
3315
3324
  * Note: [💞] Ignore a discrepancy between file name and entity name
3316
3325
  */
3317
3326
 
3327
+ /**
3328
+ * AGENT MESSAGE commitment definition
3329
+ *
3330
+ * The AGENT MESSAGE commitment defines a message from the agent in the conversation history.
3331
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3332
+ *
3333
+ * Example usage in agent source:
3334
+ *
3335
+ * ```book
3336
+ * AGENT MESSAGE What seems to be the issue?
3337
+ * ```
3338
+ *
3339
+ * @private [🪔] Maybe export the commitments through some package
3340
+ */
3341
+ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
3342
+ constructor() {
3343
+ super('AGENT MESSAGE');
3344
+ }
3345
+ /**
3346
+ * Short one-line description of AGENT MESSAGE.
3347
+ */
3348
+ get description() {
3349
+ return 'Defines a **message from the agent** in the conversation history.';
3350
+ }
3351
+ /**
3352
+ * Markdown documentation for AGENT MESSAGE commitment.
3353
+ */
3354
+ get documentation() {
3355
+ return spaceTrim(`
3356
+ # ${this.type}
3357
+
3358
+ Defines a message from the agent in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3359
+
3360
+ ## Key aspects
3361
+
3362
+ - Represents a message sent by the agent.
3363
+ - Used for setting up conversation context.
3364
+ - Can be used in conjunction with USER MESSAGE.
3365
+
3366
+ ## Examples
3367
+
3368
+ \`\`\`book
3369
+ Conversation History
3370
+
3371
+ USER MESSAGE Hello, I have a problem.
3372
+ AGENT MESSAGE What seems to be the issue?
3373
+ USER MESSAGE My computer is not starting.
3374
+ \`\`\`
3375
+ `);
3376
+ }
3377
+ applyToAgentModelRequirements(requirements, content) {
3378
+ // AGENT MESSAGE is for UI display purposes / conversation history construction
3379
+ // and typically doesn't need to be added to the system prompt or model requirements directly.
3380
+ // It is extracted separately for the chat interface.
3381
+ var _a;
3382
+ const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
3383
+ if (pendingUserMessage) {
3384
+ const newSample = { question: pendingUserMessage, answer: content };
3385
+ const newSamples = [...(requirements.samples || []), newSample];
3386
+ const newMetadata = { ...requirements.metadata };
3387
+ delete newMetadata.pendingUserMessage;
3388
+ return {
3389
+ ...requirements,
3390
+ samples: newSamples,
3391
+ metadata: newMetadata,
3392
+ };
3393
+ }
3394
+ return requirements;
3395
+ }
3396
+ }
3397
+
3318
3398
  /**
3319
3399
  * INITIAL MESSAGE commitment definition
3320
3400
  *
@@ -3479,6 +3559,67 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
3479
3559
  * Note: [💞] Ignore a discrepancy between file name and entity name
3480
3560
  */
3481
3561
 
3562
+ /**
3563
+ * USER MESSAGE commitment definition
3564
+ *
3565
+ * The USER MESSAGE commitment defines a message from the user in the conversation history.
3566
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3567
+ *
3568
+ * Example usage in agent source:
3569
+ *
3570
+ * ```book
3571
+ * USER MESSAGE Hello, I have a problem.
3572
+ * ```
3573
+ *
3574
+ * @private [🪔] Maybe export the commitments through some package
3575
+ */
3576
+ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
3577
+ constructor() {
3578
+ super('USER MESSAGE');
3579
+ }
3580
+ /**
3581
+ * Short one-line description of USER MESSAGE.
3582
+ */
3583
+ get description() {
3584
+ return 'Defines a **message from the user** in the conversation history.';
3585
+ }
3586
+ /**
3587
+ * Markdown documentation for USER MESSAGE commitment.
3588
+ */
3589
+ get documentation() {
3590
+ return spaceTrim(`
3591
+ # ${this.type}
3592
+
3593
+ Defines a message from the user in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3594
+
3595
+ ## Key aspects
3596
+
3597
+ - Represents a message sent by the user.
3598
+ - Used for setting up conversation context.
3599
+ - Can be used in conjunction with AGENT MESSAGE.
3600
+
3601
+ ## Examples
3602
+
3603
+ \`\`\`book
3604
+ Conversation History
3605
+
3606
+ USER MESSAGE Hello, I have a problem.
3607
+ AGENT MESSAGE What seems to be the issue?
3608
+ USER MESSAGE My computer is not starting.
3609
+ \`\`\`
3610
+ `);
3611
+ }
3612
+ applyToAgentModelRequirements(requirements, content) {
3613
+ return {
3614
+ ...requirements,
3615
+ metadata: {
3616
+ ...requirements.metadata,
3617
+ pendingUserMessage: content,
3618
+ },
3619
+ };
3620
+ }
3621
+ }
3622
+
3482
3623
  /**
3483
3624
  * META commitment definition
3484
3625
  *
@@ -3616,6 +3757,165 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
3616
3757
  * Note: [💞] Ignore a discrepancy between file name and entity name
3617
3758
  */
3618
3759
 
3760
+ /**
3761
+ * META COLOR commitment definition
3762
+ *
3763
+ * The META COLOR commitment sets the agent's accent color.
3764
+ * This commitment is special because it doesn't affect the system message,
3765
+ * but is handled separately in the parsing logic.
3766
+ *
3767
+ * Example usage in agent source:
3768
+ *
3769
+ * ```book
3770
+ * META COLOR #ff0000
3771
+ * META COLOR #00ff00
3772
+ * ```
3773
+ *
3774
+ * @private [🪔] Maybe export the commitments through some package
3775
+ */
3776
+ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
3777
+ constructor() {
3778
+ super('META COLOR', ['COLOR']);
3779
+ }
3780
+ /**
3781
+ * Short one-line description of META COLOR.
3782
+ */
3783
+ get description() {
3784
+ return "Set the agent's accent color.";
3785
+ }
3786
+ /**
3787
+ * Markdown documentation for META COLOR commitment.
3788
+ */
3789
+ get documentation() {
3790
+ return spaceTrim(`
3791
+ # META COLOR
3792
+
3793
+ Sets the agent's accent color.
3794
+
3795
+ ## Key aspects
3796
+
3797
+ - Does not modify the agent's behavior or responses.
3798
+ - Only one \`META COLOR\` should be used per agent.
3799
+ - If multiple are specified, the last one takes precedence.
3800
+ - Used for visual representation in user interfaces.
3801
+
3802
+ ## Examples
3803
+
3804
+ \`\`\`book
3805
+ Professional Assistant
3806
+
3807
+ META COLOR #3498db
3808
+ PERSONA You are a professional business assistant
3809
+ \`\`\`
3810
+
3811
+ \`\`\`book
3812
+ Creative Helper
3813
+
3814
+ META COLOR #e74c3c
3815
+ PERSONA You are a creative and inspiring assistant
3816
+ \`\`\`
3817
+ `);
3818
+ }
3819
+ applyToAgentModelRequirements(requirements, content) {
3820
+ // META COLOR doesn't modify the system message or model requirements
3821
+ // It's handled separately in the parsing logic for profile color extraction
3822
+ // This method exists for consistency with the CommitmentDefinition interface
3823
+ return requirements;
3824
+ }
3825
+ /**
3826
+ * Extracts the profile color from the content
3827
+ * This is used by the parsing logic
3828
+ */
3829
+ extractProfileColor(content) {
3830
+ const trimmedContent = content.trim();
3831
+ return trimmedContent || null;
3832
+ }
3833
+ }
3834
+ /**
3835
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3836
+ */
3837
+
3838
+ /**
3839
+ * META IMAGE commitment definition
3840
+ *
3841
+ * The META IMAGE commitment sets the agent's avatar/profile image URL.
3842
+ * This commitment is special because it doesn't affect the system message,
3843
+ * but is handled separately in the parsing logic.
3844
+ *
3845
+ * Example usage in agent source:
3846
+ *
3847
+ * ```book
3848
+ * META IMAGE https://example.com/avatar.jpg
3849
+ * META IMAGE /assets/agent-avatar.png
3850
+ * ```
3851
+ *
3852
+ * @private [🪔] Maybe export the commitments through some package
3853
+ */
3854
+ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
3855
+ constructor() {
3856
+ super('META IMAGE', ['IMAGE']);
3857
+ }
3858
+ /**
3859
+ * Short one-line description of META IMAGE.
3860
+ */
3861
+ get description() {
3862
+ return "Set the agent's profile image URL.";
3863
+ }
3864
+ /**
3865
+ * Markdown documentation for META IMAGE commitment.
3866
+ */
3867
+ get documentation() {
3868
+ return spaceTrim(`
3869
+ # META IMAGE
3870
+
3871
+ Sets the agent's avatar/profile image URL.
3872
+
3873
+ ## Key aspects
3874
+
3875
+ - Does not modify the agent's behavior or responses.
3876
+ - Only one \`META IMAGE\` should be used per agent.
3877
+ - If multiple are specified, the last one takes precedence.
3878
+ - Used for visual representation in user interfaces.
3879
+
3880
+ ## Examples
3881
+
3882
+ \`\`\`book
3883
+ Professional Assistant
3884
+
3885
+ META IMAGE https://example.com/professional-avatar.jpg
3886
+ PERSONA You are a professional business assistant
3887
+ STYLE Maintain a formal and courteous tone
3888
+ \`\`\`
3889
+
3890
+ \`\`\`book
3891
+ Creative Helper
3892
+
3893
+ META IMAGE /assets/creative-bot-avatar.png
3894
+ PERSONA You are a creative and inspiring assistant
3895
+ STYLE Be enthusiastic and encouraging
3896
+ ACTION Can help with brainstorming and ideation
3897
+ \`\`\`
3898
+ `);
3899
+ }
3900
+ applyToAgentModelRequirements(requirements, content) {
3901
+ // META IMAGE doesn't modify the system message or model requirements
3902
+ // It's handled separately in the parsing logic for profile image extraction
3903
+ // This method exists for consistency with the CommitmentDefinition interface
3904
+ return requirements;
3905
+ }
3906
+ /**
3907
+ * Extracts the profile image URL from the content
3908
+ * This is used by the parsing logic
3909
+ */
3910
+ extractProfileImageUrl(content) {
3911
+ const trimmedContent = content.trim();
3912
+ return trimmedContent || null;
3913
+ }
3914
+ }
3915
+ /**
3916
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3917
+ */
3918
+
3619
3919
  /**
3620
3920
  * MODEL commitment definition
3621
3921
  *
@@ -4523,6 +4823,8 @@ const COMMITMENT_REGISTRY = [
4523
4823
  new ModelCommitmentDefinition('MODELS'),
4524
4824
  new ActionCommitmentDefinition('ACTION'),
4525
4825
  new ActionCommitmentDefinition('ACTIONS'),
4826
+ new MetaImageCommitmentDefinition(),
4827
+ new MetaColorCommitmentDefinition(),
4526
4828
  new MetaCommitmentDefinition(),
4527
4829
  new NoteCommitmentDefinition('NOTE'),
4528
4830
  new NoteCommitmentDefinition('NOTES'),
@@ -4531,6 +4833,8 @@ const COMMITMENT_REGISTRY = [
4531
4833
  new GoalCommitmentDefinition('GOAL'),
4532
4834
  new GoalCommitmentDefinition('GOALS'),
4533
4835
  new InitialMessageCommitmentDefinition(),
4836
+ new UserMessageCommitmentDefinition(),
4837
+ new AgentMessageCommitmentDefinition(),
4534
4838
  new MessageCommitmentDefinition('MESSAGE'),
4535
4839
  new MessageCommitmentDefinition('MESSAGES'),
4536
4840
  new ScenarioCommitmentDefinition('SCENARIO'),
@@ -4752,6 +5056,14 @@ function parseAgentSource(agentSource) {
4752
5056
  links.push(spaceTrim$1(commitment.content));
4753
5057
  continue;
4754
5058
  }
5059
+ if (commitment.type === 'META IMAGE') {
5060
+ meta.image = spaceTrim$1(commitment.content);
5061
+ continue;
5062
+ }
5063
+ if (commitment.type === 'META COLOR') {
5064
+ meta.color = spaceTrim$1(commitment.content);
5065
+ continue;
5066
+ }
4755
5067
  if (commitment.type !== 'META') {
4756
5068
  continue;
4757
5069
  }
@@ -4767,6 +5079,10 @@ function parseAgentSource(agentSource) {
4767
5079
  if (!meta.image) {
4768
5080
  meta.image = generatePlaceholderAgentProfileImageUrl(parseResult.agentName || '!!');
4769
5081
  }
5082
+ // Generate fullname fallback if no meta fullname specified
5083
+ if (!meta.fullname) {
5084
+ meta.fullname = parseResult.agentName || createDefaultAgentName(agentSource);
5085
+ }
4770
5086
  // Parse parameters using unified approach - both @Parameter and {parameter} notations
4771
5087
  // are treated as the same syntax feature with unified representation
4772
5088
  const parameters = parseParameters(agentSource);