@promptbook/browser 0.103.0-55 → 0.103.0-56

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
@@ -1,4 +1,4 @@
1
- import spaceTrim$1, { spaceTrim } from 'spacetrim';
1
+ import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
2
  import { randomBytes } from 'crypto';
3
3
  import { SHA256 } from 'crypto-js';
4
4
  import hexEncoder from 'crypto-js/enc-hex';
@@ -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-55';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-56';
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
@@ -77,13 +77,13 @@ class SimplePromptInterfaceTools {
77
77
  * Trigger window.prompt dialog
78
78
  */
79
79
  async promptDialog(options) {
80
- const answer = window.prompt(spaceTrim((block) => `
80
+ const answer = window.prompt(spaceTrim$1((block) => `
81
81
  ${block(options.promptTitle)}
82
82
 
83
83
  ${block(options.promptMessage)}
84
84
  `));
85
85
  if (this.options.isVerbose) {
86
- console.info(spaceTrim((block) => `
86
+ console.info(spaceTrim$1((block) => `
87
87
  📖 ${block(options.promptTitle)}
88
88
  👤 ${block(answer || '🚫 User cancelled prompt')}
89
89
  `));
@@ -151,6 +151,17 @@ const $isRunningInWebWorker = new Function(`
151
151
  * TODO: [🎺]
152
152
  */
153
153
 
154
+ /**
155
+ * Trims string from all 4 sides
156
+ *
157
+ * Note: This is a re-exported function from the `spacetrim` package which is
158
+ * Developed by same author @hejny as this package
159
+ *
160
+ * @public exported from `@promptbook/utils`
161
+ * @see https://github.com/hejny/spacetrim#usage
162
+ */
163
+ const spaceTrim = spaceTrim$1;
164
+
154
165
  /**
155
166
  * @private util of `@promptbook/color`
156
167
  * @de
@@ -199,6 +210,7 @@ function take(initialValue) {
199
210
  * @public exported from `@promptbook/color`
200
211
  */
201
212
  const CSS_COLORS = {
213
+ promptbook: '#79EAFD',
202
214
  transparent: 'rgba(0,0,0,0)',
203
215
  aliceblue: '#f0f8ff',
204
216
  antiquewhite: '#faebd7',
@@ -414,6 +426,28 @@ class Color {
414
426
  throw new Error(`Can not create color from given object`);
415
427
  }
416
428
  }
429
+ /**
430
+ * Creates a new Color instance from miscellaneous formats
431
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
432
+ *
433
+ * @param color
434
+ * @returns Color object
435
+ */
436
+ static fromSafe(color) {
437
+ try {
438
+ return Color.from(color);
439
+ }
440
+ catch (error) {
441
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
442
+ console.warn(spaceTrim((block) => `
443
+ Color.fromSafe error:
444
+ ${block(error.message)}
445
+
446
+ Returning default PROMPTBOOK_COLOR.
447
+ `));
448
+ return Color.fromString('promptbook');
449
+ }
450
+ }
417
451
  /**
418
452
  * Creates a new Color instance from miscellaneous string formats
419
453
  *
@@ -1003,7 +1037,7 @@ const ADMIN_GITHUB_NAME = 'hejny';
1003
1037
  *
1004
1038
  * @public exported from `@promptbook/core`
1005
1039
  */
1006
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
1040
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
1007
1041
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
1008
1042
  /**
1009
1043
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -1096,7 +1130,7 @@ parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
1096
1130
  */
1097
1131
  class NotYetImplementedError extends Error {
1098
1132
  constructor(message) {
1099
- super(spaceTrim((block) => `
1133
+ super(spaceTrim$1((block) => `
1100
1134
  ${block(message)}
1101
1135
 
1102
1136
  Note: This feature is not implemented yet but it will be soon.
@@ -1120,7 +1154,7 @@ class NotYetImplementedError extends Error {
1120
1154
  function getErrorReportUrl(error) {
1121
1155
  const report = {
1122
1156
  title: `🐜 Error report from ${NAME}`,
1123
- body: spaceTrim$1((block) => `
1157
+ body: spaceTrim$2((block) => `
1124
1158
 
1125
1159
 
1126
1160
  \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
@@ -1163,7 +1197,7 @@ function getErrorReportUrl(error) {
1163
1197
  */
1164
1198
  class UnexpectedError extends Error {
1165
1199
  constructor(message) {
1166
- super(spaceTrim((block) => `
1200
+ super(spaceTrim$1((block) => `
1167
1201
  ${block(message)}
1168
1202
 
1169
1203
  Note: This error should not happen.
@@ -1444,7 +1478,7 @@ function jsonParse(value) {
1444
1478
  }
1445
1479
  else if (typeof value !== 'string') {
1446
1480
  console.error('Can not parse JSON from non-string value.', { text: value });
1447
- throw new Error(spaceTrim$1(`
1481
+ throw new Error(spaceTrim$2(`
1448
1482
  Can not parse JSON from non-string value.
1449
1483
 
1450
1484
  The value type: ${typeof value}
@@ -1458,7 +1492,7 @@ function jsonParse(value) {
1458
1492
  if (!(error instanceof Error)) {
1459
1493
  throw error;
1460
1494
  }
1461
- throw new Error(spaceTrim$1((block) => `
1495
+ throw new Error(spaceTrim$2((block) => `
1462
1496
  ${block(error.message)}
1463
1497
 
1464
1498
  The expected JSON text:
@@ -1518,7 +1552,7 @@ class WrappedError extends Error {
1518
1552
  constructor(whatWasThrown) {
1519
1553
  const tag = `[🤮]`;
1520
1554
  console.error(tag, whatWasThrown);
1521
- super(spaceTrim(`
1555
+ super(spaceTrim$1(`
1522
1556
  Non-Error object was thrown
1523
1557
 
1524
1558
  Note: Look for ${tag} in the console for more details
@@ -1607,7 +1641,7 @@ function checkSerializableAsJson(options) {
1607
1641
  }
1608
1642
  else if (typeof value === 'object') {
1609
1643
  if (value instanceof Date) {
1610
- throw new UnexpectedError(spaceTrim$1((block) => `
1644
+ throw new UnexpectedError(spaceTrim$2((block) => `
1611
1645
  \`${name}\` is Date
1612
1646
 
1613
1647
  Use \`string_date_iso8601\` instead
@@ -1626,7 +1660,7 @@ function checkSerializableAsJson(options) {
1626
1660
  throw new UnexpectedError(`${name} is RegExp`);
1627
1661
  }
1628
1662
  else if (value instanceof Error) {
1629
- throw new UnexpectedError(spaceTrim$1((block) => `
1663
+ throw new UnexpectedError(spaceTrim$2((block) => `
1630
1664
  \`${name}\` is unserialized Error
1631
1665
 
1632
1666
  Use function \`serializeError\`
@@ -1649,7 +1683,7 @@ function checkSerializableAsJson(options) {
1649
1683
  }
1650
1684
  catch (error) {
1651
1685
  assertsError(error);
1652
- throw new UnexpectedError(spaceTrim$1((block) => `
1686
+ throw new UnexpectedError(spaceTrim$2((block) => `
1653
1687
  \`${name}\` is not serializable
1654
1688
 
1655
1689
  ${block(error.stack || error.message)}
@@ -1681,7 +1715,7 @@ function checkSerializableAsJson(options) {
1681
1715
  }
1682
1716
  }
1683
1717
  else {
1684
- throw new UnexpectedError(spaceTrim$1((block) => `
1718
+ throw new UnexpectedError(spaceTrim$2((block) => `
1685
1719
  \`${name}\` is unknown type
1686
1720
 
1687
1721
  Additional message for \`${name}\`:
@@ -1831,7 +1865,7 @@ function isSerializableAsJson(value) {
1831
1865
  */
1832
1866
  function stringifyPipelineJson(pipeline) {
1833
1867
  if (!isSerializableAsJson(pipeline)) {
1834
- throw new UnexpectedError(spaceTrim$1(`
1868
+ throw new UnexpectedError(spaceTrim$2(`
1835
1869
  Cannot stringify the pipeline, because it is not serializable as JSON
1836
1870
 
1837
1871
  There can be multiple reasons:
@@ -2117,7 +2151,7 @@ function valueToString(value) {
2117
2151
  * @public exported from `@promptbook/utils`
2118
2152
  */
2119
2153
  function computeHash(value) {
2120
- return SHA256(hexEncoder.parse(spaceTrim$1(valueToString(value)))).toString( /* hex */);
2154
+ return SHA256(hexEncoder.parse(spaceTrim$2(valueToString(value)))).toString( /* hex */);
2121
2155
  }
2122
2156
  /**
2123
2157
  * TODO: [🥬][🥬] Use this ACRY
@@ -2649,7 +2683,7 @@ new Function(`
2649
2683
  * @public exported from `@promptbook/core`
2650
2684
  */
2651
2685
  function normalizeAgentName(rawAgentName) {
2652
- return titleToName(spaceTrim$1(rawAgentName));
2686
+ return titleToName(spaceTrim$2(rawAgentName));
2653
2687
  }
2654
2688
 
2655
2689
  /**
@@ -2803,7 +2837,7 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
2803
2837
  * Markdown documentation for ACTION commitment.
2804
2838
  */
2805
2839
  get documentation() {
2806
- return spaceTrim(`
2840
+ return spaceTrim$1(`
2807
2841
  # ${this.type}
2808
2842
 
2809
2843
  Defines specific actions or capabilities that the agent can perform.
@@ -2884,7 +2918,7 @@ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
2884
2918
  * Markdown documentation for CLOSED commitment.
2885
2919
  */
2886
2920
  get documentation() {
2887
- return spaceTrim(`
2921
+ return spaceTrim$1(`
2888
2922
  # CLOSED
2889
2923
 
2890
2924
  Specifies that the agent **cannot** be modified by conversation with it.
@@ -2943,7 +2977,7 @@ class ComponentCommitmentDefinition extends BaseCommitmentDefinition {
2943
2977
  * Markdown documentation for COMPONENT commitment.
2944
2978
  */
2945
2979
  get documentation() {
2946
- return spaceTrim(`
2980
+ return spaceTrim$1(`
2947
2981
  # COMPONENT
2948
2982
 
2949
2983
  Defines a UI component that the agent can render in the chat.
@@ -3015,7 +3049,7 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
3015
3049
  * Markdown documentation for DELETE commitment.
3016
3050
  */
3017
3051
  get documentation() {
3018
- return spaceTrim(`
3052
+ return spaceTrim$1(`
3019
3053
  # DELETE (CANCEL, DISCARD, REMOVE)
3020
3054
 
3021
3055
  A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
@@ -3137,7 +3171,7 @@ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
3137
3171
  * Markdown documentation for FORMAT commitment.
3138
3172
  */
3139
3173
  get documentation() {
3140
- return spaceTrim(`
3174
+ return spaceTrim$1(`
3141
3175
  # ${this.type}
3142
3176
 
3143
3177
  Defines the specific output structure and formatting for responses (data formats, templates, structure).
@@ -3215,7 +3249,7 @@ class FromCommitmentDefinition extends BaseCommitmentDefinition {
3215
3249
  * Markdown documentation for FROM commitment.
3216
3250
  */
3217
3251
  get documentation() {
3218
- return spaceTrim(`
3252
+ return spaceTrim$1(`
3219
3253
  # ${this.type}
3220
3254
 
3221
3255
  Inherits agent source from another agent.
@@ -3291,7 +3325,7 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
3291
3325
  * Markdown documentation for GOAL commitment.
3292
3326
  */
3293
3327
  get documentation() {
3294
- return spaceTrim(`
3328
+ return spaceTrim$1(`
3295
3329
  # ${this.type}
3296
3330
 
3297
3331
  Defines the main goal which should be achieved by the AI assistant. There can be multiple goals, and later goals are more important than earlier goals.
@@ -3355,217 +3389,6 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
3355
3389
  * Note: [💞] Ignore a discrepancy between file name and entity name
3356
3390
  */
3357
3391
 
3358
- /**
3359
- * Placeholder commitment definition for commitments that are not yet implemented
3360
- *
3361
- * This commitment simply adds its content 1:1 into the system message,
3362
- * preserving the original behavior until proper implementation is added.
3363
- *
3364
- * @public exported from `@promptbook/core`
3365
- */
3366
- class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
3367
- constructor(type) {
3368
- super(type);
3369
- }
3370
- /**
3371
- * Short one-line description of a placeholder commitment.
3372
- */
3373
- get description() {
3374
- return 'Placeholder commitment that appends content verbatim to the system message.';
3375
- }
3376
- /**
3377
- * Icon for this commitment.
3378
- */
3379
- get icon() {
3380
- return '🚧';
3381
- }
3382
- /**
3383
- * Markdown documentation available at runtime.
3384
- */
3385
- get documentation() {
3386
- return spaceTrim(`
3387
- # ${this.type}
3388
-
3389
- This commitment is not yet fully implemented.
3390
-
3391
- ## Key aspects
3392
-
3393
- - Content is appended directly to the system message.
3394
- - No special processing or validation is performed.
3395
- - Behavior preserved until proper implementation is added.
3396
-
3397
- ## Status
3398
-
3399
- - **Status:** Placeholder implementation
3400
- - **Effect:** Appends content prefixed by commitment type
3401
- - **Future:** Will be replaced with specialized logic
3402
-
3403
- ## Examples
3404
-
3405
- \`\`\`book
3406
- Example Agent
3407
-
3408
- PERSONA You are a helpful assistant
3409
- ${this.type} Your content here
3410
- RULE Always be helpful
3411
- \`\`\`
3412
- `);
3413
- }
3414
- applyToAgentModelRequirements(requirements, content) {
3415
- const trimmedContent = content.trim();
3416
- if (!trimmedContent) {
3417
- return requirements;
3418
- }
3419
- // Add the commitment content 1:1 to the system message
3420
- const commitmentLine = `${this.type} ${trimmedContent}`;
3421
- return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
3422
- }
3423
- }
3424
-
3425
- /**
3426
- * Registry of all available commitment definitions
3427
- * This array contains instances of all commitment definitions
3428
- * This is the single source of truth for all commitments in the system
3429
- *
3430
- * @private Use functions to access commitments instead of this array directly
3431
- */
3432
- const COMMITMENT_REGISTRY = [];
3433
- /**
3434
- * Registers a new commitment definition
3435
- * @param definition The commitment definition to register
3436
- *
3437
- * @public exported from `@promptbook/core`
3438
- */
3439
- function registerCommitment(definition) {
3440
- COMMITMENT_REGISTRY.push(definition);
3441
- }
3442
- /**
3443
- * Gets all available commitment definitions
3444
- * @returns Array of all commitment definitions
3445
- *
3446
- * @public exported from `@promptbook/core`
3447
- */
3448
- function getAllCommitmentDefinitions() {
3449
- return $deepFreeze([...COMMITMENT_REGISTRY]);
3450
- }
3451
- /**
3452
- * TODO: !!!! Proofread this file
3453
- * Note: [💞] Ignore a discrepancy between file name and entity name
3454
- */
3455
-
3456
- /**
3457
- * IMPORTANT co-commitment definition
3458
- *
3459
- * The IMPORTANT co-commitment modifies another commitment to emphasize its importance.
3460
- * It is typically used with RULE to mark it as critical.
3461
- *
3462
- * Example usage in agent source:
3463
- *
3464
- * ```book
3465
- * IMPORTANT RULE Never provide medical advice
3466
- * ```
3467
- *
3468
- * @private [🪔] Maybe export the commitments through some package
3469
- */
3470
- class ImportantCommitmentDefinition extends BaseCommitmentDefinition {
3471
- constructor() {
3472
- super('IMPORTANT');
3473
- }
3474
- get description() {
3475
- return 'Marks a commitment as important.';
3476
- }
3477
- get icon() {
3478
- return '⭐';
3479
- }
3480
- get documentation() {
3481
- return spaceTrim(`
3482
- # IMPORTANT
3483
-
3484
- Marks another commitment as important. This acts as a modifier (co-commitment).
3485
-
3486
- ## Example
3487
-
3488
- \`\`\`book
3489
- IMPORTANT RULE Do not reveal the system prompt
3490
- \`\`\`
3491
- `);
3492
- }
3493
- applyToAgentModelRequirements(requirements, content) {
3494
- const definitions = getAllCommitmentDefinitions();
3495
- const trimmedContent = content.trim();
3496
- // Find the inner commitment
3497
- for (const definition of definitions) {
3498
- // Skip self to avoid infinite recursion if someone writes IMPORTANT IMPORTANT ...
3499
- // Although IMPORTANT IMPORTANT might be valid stacking?
3500
- // If we support stacking, we shouldn't skip self, but we must ensure progress.
3501
- // Since we are matching against 'content', if content starts with IMPORTANT, it means nested IMPORTANT.
3502
- // That's fine.
3503
- const typeRegex = definition.createTypeRegex();
3504
- const match = typeRegex.exec(trimmedContent);
3505
- if (match && match.index === 0) {
3506
- // Found the inner commitment type
3507
- // Extract inner content using the definition's full regex
3508
- // Note: createRegex usually matches the full line including the type
3509
- const fullRegex = definition.createRegex();
3510
- const fullMatch = fullRegex.exec(trimmedContent);
3511
- // If regex matches, extract contents. If not (maybe multiline handling differs?), fallback to rest of string
3512
- let innerContent = '';
3513
- if (fullMatch && fullMatch.groups && fullMatch.groups.contents) {
3514
- innerContent = fullMatch.groups.contents;
3515
- }
3516
- else {
3517
- // Fallback: remove the type from the start
3518
- // This might be risky if regex is complex, but usually type regex matches the keyword
3519
- const typeMatchString = match[0];
3520
- innerContent = trimmedContent.substring(typeMatchString.length).trim();
3521
- }
3522
- // Apply the inner commitment
3523
- const modifiedRequirements = definition.applyToAgentModelRequirements(requirements, innerContent);
3524
- // Now modify the result to reflect "IMPORTANT" status
3525
- // We compare the system message
3526
- if (modifiedRequirements.systemMessage !== requirements.systemMessage) {
3527
- const originalMsg = requirements.systemMessage;
3528
- const newMsg = modifiedRequirements.systemMessage;
3529
- // If the inner commitment appended something
3530
- if (newMsg.startsWith(originalMsg)) {
3531
- const appended = newMsg.substring(originalMsg.length);
3532
- // Add "IMPORTANT: " prefix to the appended part
3533
- // We need to be careful about newlines
3534
- // Heuristic: If appended starts with separator (newlines), preserve them
3535
- const matchSep = appended.match(/^(\s*)(.*)/s);
3536
- if (matchSep) {
3537
- const [, separator, text] = matchSep;
3538
- // Check if it already has "Rule:" prefix or similar
3539
- // We want "IMPORTANT Rule: ..."
3540
- // Let's just prepend IMPORTANT to the text
3541
- // But formatted nicely
3542
- // If it's a rule: "\n\nRule: content"
3543
- // We want "\n\nIMPORTANT Rule: content"
3544
- const importantText = `IMPORTANT ${text}`;
3545
- return {
3546
- ...modifiedRequirements,
3547
- systemMessage: originalMsg + separator + importantText
3548
- };
3549
- }
3550
- }
3551
- }
3552
- // If no system message change or we couldn't detect how to modify it, just return the modified requirements
3553
- // Maybe the inner commitment modified metadata?
3554
- return modifiedRequirements;
3555
- }
3556
- }
3557
- // If no inner commitment found, treat as a standalone note?
3558
- // Or warn?
3559
- // For now, treat as no-op or maybe just append as text?
3560
- // Let's treat as Note if fallback? No, explicit is better.
3561
- console.warn(`IMPORTANT commitment used without a valid inner commitment: ${content}`);
3562
- return requirements;
3563
- }
3564
- }
3565
- /**
3566
- * Note: [💞] Ignore a discrepancy between file name and entity name
3567
- */
3568
-
3569
3392
  /**
3570
3393
  * KNOWLEDGE commitment definition
3571
3394
  *
@@ -3604,7 +3427,7 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
3604
3427
  * Markdown documentation for KNOWLEDGE commitment.
3605
3428
  */
3606
3429
  get documentation() {
3607
- return spaceTrim(`
3430
+ return spaceTrim$1(`
3608
3431
  # ${this.type}
3609
3432
 
3610
3433
  Adds specific knowledge, facts, or context to the agent using a RAG (Retrieval-Augmented Generation) approach for external sources.
@@ -3708,7 +3531,7 @@ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
3708
3531
  * Markdown documentation for LANGUAGE/LANGUAGES commitment.
3709
3532
  */
3710
3533
  get documentation() {
3711
- return spaceTrim(`
3534
+ return spaceTrim$1(`
3712
3535
  # ${this.type}
3713
3536
 
3714
3537
  Specifies the language(s) the agent should use in its responses.
@@ -3782,7 +3605,7 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
3782
3605
  * Markdown documentation for MEMORY commitment.
3783
3606
  */
3784
3607
  get documentation() {
3785
- return spaceTrim(`
3608
+ return spaceTrim$1(`
3786
3609
  # ${this.type}
3787
3610
 
3788
3611
  Similar to KNOWLEDGE but focuses on remembering past interactions and user preferences. This commitment helps the agent maintain context about the user's history, preferences, and previous conversations.
@@ -3886,7 +3709,7 @@ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
3886
3709
  * Markdown documentation for AGENT MESSAGE commitment.
3887
3710
  */
3888
3711
  get documentation() {
3889
- return spaceTrim(`
3712
+ return spaceTrim$1(`
3890
3713
  # ${this.type}
3891
3714
 
3892
3715
  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.
@@ -3963,7 +3786,7 @@ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
3963
3786
  * Markdown documentation for INITIAL MESSAGE commitment.
3964
3787
  */
3965
3788
  get documentation() {
3966
- return spaceTrim(`
3789
+ return spaceTrim$1(`
3967
3790
  # ${this.type}
3968
3791
 
3969
3792
  Defines the first message that the user sees when opening the chat. This message is purely for display purposes in the UI and does not inherently become part of the LLM's system prompt context (unless also included via other means).
@@ -4027,7 +3850,7 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
4027
3850
  * Markdown documentation for MESSAGE commitment.
4028
3851
  */
4029
3852
  get documentation() {
4030
- return spaceTrim(`
3853
+ return spaceTrim$1(`
4031
3854
  # ${this.type}
4032
3855
 
4033
3856
  Contains 1:1 text of the message which AI assistant already sent during the conversation. Later messages are later in the conversation. It is similar to EXAMPLE but it is not example, it is the real message which AI assistant already sent.
@@ -4139,7 +3962,7 @@ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
4139
3962
  * Markdown documentation for USER MESSAGE commitment.
4140
3963
  */
4141
3964
  get documentation() {
4142
- return spaceTrim(`
3965
+ return spaceTrim$1(`
4143
3966
  # ${this.type}
4144
3967
 
4145
3968
  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.
@@ -4218,7 +4041,7 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
4218
4041
  * Markdown documentation for META commitment.
4219
4042
  */
4220
4043
  get documentation() {
4221
- return spaceTrim(`
4044
+ return spaceTrim$1(`
4222
4045
  # META
4223
4046
 
4224
4047
  Sets meta-information about the agent that is used for display and attribution purposes.
@@ -4329,6 +4152,12 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
4329
4152
  * META COLOR #00ff00
4330
4153
  * ```
4331
4154
  *
4155
+ * You can also specify multiple colors separated by comma:
4156
+ *
4157
+ * ```book
4158
+ * META COLOR #ff0000, #00ff00, #0000ff
4159
+ * ```
4160
+ *
4332
4161
  * @private [🪔] Maybe export the commitments through some package
4333
4162
  */
4334
4163
  class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
@@ -4339,7 +4168,7 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4339
4168
  * Short one-line description of META COLOR.
4340
4169
  */
4341
4170
  get description() {
4342
- return "Set the agent's accent color.";
4171
+ return "Set the agent's accent color or gradient.";
4343
4172
  }
4344
4173
  /**
4345
4174
  * Icon for this commitment.
@@ -4351,10 +4180,10 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4351
4180
  * Markdown documentation for META COLOR commitment.
4352
4181
  */
4353
4182
  get documentation() {
4354
- return spaceTrim(`
4183
+ return spaceTrim$1(`
4355
4184
  # META COLOR
4356
4185
 
4357
- Sets the agent's accent color.
4186
+ Sets the agent's accent color or gradient.
4358
4187
 
4359
4188
  ## Key aspects
4360
4189
 
@@ -4362,6 +4191,7 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4362
4191
  - Only one \`META COLOR\` should be used per agent.
4363
4192
  - If multiple are specified, the last one takes precedence.
4364
4193
  - Used for visual representation in user interfaces.
4194
+ - Can specify multiple colors separated by comma to create a gradient.
4365
4195
 
4366
4196
  ## Examples
4367
4197
 
@@ -4378,6 +4208,13 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4378
4208
  META COLOR #e74c3c
4379
4209
  PERSONA You are a creative and inspiring assistant
4380
4210
  \`\`\`
4211
+
4212
+ \`\`\`book
4213
+ Gradient Agent
4214
+
4215
+ META COLOR #ff0000, #00ff00, #0000ff
4216
+ PERSONA You are a colorful agent
4217
+ \`\`\`
4381
4218
  `);
4382
4219
  }
4383
4220
  applyToAgentModelRequirements(requirements, content) {
@@ -4399,6 +4236,91 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4399
4236
  * Note: [💞] Ignore a discrepancy between file name and entity name
4400
4237
  */
4401
4238
 
4239
+ /**
4240
+ * META FONT commitment definition
4241
+ *
4242
+ * The META FONT commitment sets the agent's font.
4243
+ * This commitment is special because it doesn't affect the system message,
4244
+ * but is handled separately in the parsing logic.
4245
+ *
4246
+ * Example usage in agent source:
4247
+ *
4248
+ * ```book
4249
+ * META FONT Poppins, Arial, sans-serif
4250
+ * META FONT Roboto
4251
+ * ```
4252
+ *
4253
+ * @private [🪔] Maybe export the commitments through some package
4254
+ */
4255
+ class MetaFontCommitmentDefinition extends BaseCommitmentDefinition {
4256
+ constructor() {
4257
+ super('META FONT', ['FONT']);
4258
+ }
4259
+ /**
4260
+ * Short one-line description of META FONT.
4261
+ */
4262
+ get description() {
4263
+ return "Set the agent's font.";
4264
+ }
4265
+ /**
4266
+ * Icon for this commitment.
4267
+ */
4268
+ get icon() {
4269
+ return '🔤';
4270
+ }
4271
+ /**
4272
+ * Markdown documentation for META FONT commitment.
4273
+ */
4274
+ get documentation() {
4275
+ return spaceTrim$1(`
4276
+ # META FONT
4277
+
4278
+ Sets the agent's font.
4279
+
4280
+ ## Key aspects
4281
+
4282
+ - Does not modify the agent's behavior or responses.
4283
+ - Only one \`META FONT\` should be used per agent.
4284
+ - If multiple are specified, the last one takes precedence.
4285
+ - Used for visual representation in user interfaces.
4286
+ - Supports Google Fonts.
4287
+
4288
+ ## Examples
4289
+
4290
+ \`\`\`book
4291
+ Modern Assistant
4292
+
4293
+ META FONT Poppins, Arial, sans-serif
4294
+ PERSONA You are a modern assistant
4295
+ \`\`\`
4296
+
4297
+ \`\`\`book
4298
+ Classic Helper
4299
+
4300
+ META FONT Times New Roman
4301
+ PERSONA You are a classic helper
4302
+ \`\`\`
4303
+ `);
4304
+ }
4305
+ applyToAgentModelRequirements(requirements, content) {
4306
+ // META FONT doesn't modify the system message or model requirements
4307
+ // It's handled separately in the parsing logic
4308
+ // This method exists for consistency with the CommitmentDefinition interface
4309
+ return requirements;
4310
+ }
4311
+ /**
4312
+ * Extracts the font from the content
4313
+ * This is used by the parsing logic
4314
+ */
4315
+ extractProfileFont(content) {
4316
+ const trimmedContent = content.trim();
4317
+ return trimmedContent || null;
4318
+ }
4319
+ }
4320
+ /**
4321
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4322
+ */
4323
+
4402
4324
  /**
4403
4325
  * META IMAGE commitment definition
4404
4326
  *
@@ -4435,7 +4357,7 @@ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
4435
4357
  * Markdown documentation for META IMAGE commitment.
4436
4358
  */
4437
4359
  get documentation() {
4438
- return spaceTrim(`
4360
+ return spaceTrim$1(`
4439
4361
  # META IMAGE
4440
4362
 
4441
4363
  Sets the agent's avatar/profile image URL.
@@ -4530,7 +4452,7 @@ class MetaLinkCommitmentDefinition extends BaseCommitmentDefinition {
4530
4452
  * Markdown documentation for META LINK commitment.
4531
4453
  */
4532
4454
  get documentation() {
4533
- return spaceTrim(`
4455
+ return spaceTrim$1(`
4534
4456
  # META LINK
4535
4457
 
4536
4458
  Represents a profile or source link for the person the agent is modeled after.
@@ -4640,7 +4562,7 @@ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
4640
4562
  * Markdown documentation for MODEL commitment.
4641
4563
  */
4642
4564
  get documentation() {
4643
- return spaceTrim(`
4565
+ return spaceTrim$1(`
4644
4566
  # ${this.type}
4645
4567
 
4646
4568
  Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
@@ -4881,7 +4803,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
4881
4803
  * Markdown documentation for NOTE commitment.
4882
4804
  */
4883
4805
  get documentation() {
4884
- return spaceTrim(`
4806
+ return spaceTrim$1(`
4885
4807
  # ${this.type}
4886
4808
 
4887
4809
  Adds comments for documentation without changing agent behavior.
@@ -4980,7 +4902,7 @@ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
4980
4902
  * Markdown documentation for OPEN commitment.
4981
4903
  */
4982
4904
  get documentation() {
4983
- return spaceTrim(`
4905
+ return spaceTrim$1(`
4984
4906
  # OPEN
4985
4907
 
4986
4908
  Specifies that the agent can be modified by conversation with it.
@@ -5057,7 +4979,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
5057
4979
  * Markdown documentation for PERSONA commitment.
5058
4980
  */
5059
4981
  get documentation() {
5060
- return spaceTrim(`
4982
+ return spaceTrim$1(`
5061
4983
  # ${this.type}
5062
4984
 
5063
4985
  Defines who the agent is, their background, expertise, and personality traits.
@@ -5190,7 +5112,7 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
5190
5112
  * Markdown documentation for RULE/RULES commitment.
5191
5113
  */
5192
5114
  get documentation() {
5193
- return spaceTrim(`
5115
+ return spaceTrim$1(`
5194
5116
  # ${this.type}
5195
5117
 
5196
5118
  Adds behavioral constraints and guidelines that the agent must follow.
@@ -5272,7 +5194,7 @@ class SampleCommitmentDefinition extends BaseCommitmentDefinition {
5272
5194
  * Markdown documentation for SAMPLE/EXAMPLE commitment.
5273
5195
  */
5274
5196
  get documentation() {
5275
- return spaceTrim(`
5197
+ return spaceTrim$1(`
5276
5198
  # ${this.type}
5277
5199
 
5278
5200
  Provides examples of how the agent should respond or behave in certain situations.
@@ -5355,7 +5277,7 @@ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
5355
5277
  * Markdown documentation for SCENARIO commitment.
5356
5278
  */
5357
5279
  get documentation() {
5358
- return spaceTrim(`
5280
+ return spaceTrim$1(`
5359
5281
  # ${this.type}
5360
5282
 
5361
5283
  Defines a specific situation or context in which the AI assistant should operate. It helps to set the scene for the AI's responses. Later scenarios are more important than earlier scenarios.
@@ -5477,7 +5399,7 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
5477
5399
  * Markdown documentation for STYLE commitment.
5478
5400
  */
5479
5401
  get documentation() {
5480
- return spaceTrim(`
5402
+ return spaceTrim$1(`
5481
5403
  # ${this.type}
5482
5404
 
5483
5405
  Defines how the agent should format and present its responses (tone, writing style, formatting).
@@ -5524,90 +5446,562 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
5524
5446
  * [💞] Ignore a discrepancy between file name and entity name
5525
5447
  */
5526
5448
 
5527
- // Import all commitment definition classes
5528
- // Register fully implemented commitments
5529
- registerCommitment(new PersonaCommitmentDefinition('PERSONA'));
5530
- registerCommitment(new PersonaCommitmentDefinition('PERSONAE'));
5531
- registerCommitment(new KnowledgeCommitmentDefinition());
5532
- registerCommitment(new MemoryCommitmentDefinition('MEMORY'));
5533
- registerCommitment(new MemoryCommitmentDefinition('MEMORIES'));
5534
- registerCommitment(new StyleCommitmentDefinition('STYLE'));
5535
- registerCommitment(new StyleCommitmentDefinition('STYLES'));
5536
- registerCommitment(new RuleCommitmentDefinition('RULE'));
5537
- registerCommitment(new RuleCommitmentDefinition('RULES'));
5538
- registerCommitment(new LanguageCommitmentDefinition('LANGUAGE'));
5539
- registerCommitment(new LanguageCommitmentDefinition('LANGUAGES'));
5540
- registerCommitment(new SampleCommitmentDefinition('SAMPLE'));
5541
- registerCommitment(new SampleCommitmentDefinition('EXAMPLE'));
5542
- registerCommitment(new FormatCommitmentDefinition('FORMAT'));
5543
- registerCommitment(new FormatCommitmentDefinition('FORMATS'));
5544
- registerCommitment(new FromCommitmentDefinition('FROM'));
5545
- registerCommitment(new ModelCommitmentDefinition('MODEL'));
5546
- registerCommitment(new ModelCommitmentDefinition('MODELS'));
5547
- registerCommitment(new ActionCommitmentDefinition('ACTION'));
5548
- registerCommitment(new ActionCommitmentDefinition('ACTIONS'));
5549
- registerCommitment(new ComponentCommitmentDefinition());
5550
- registerCommitment(new MetaImageCommitmentDefinition());
5551
- registerCommitment(new MetaColorCommitmentDefinition());
5552
- registerCommitment(new MetaLinkCommitmentDefinition());
5553
- registerCommitment(new MetaCommitmentDefinition());
5554
- registerCommitment(new NoteCommitmentDefinition('NOTE'));
5555
- registerCommitment(new NoteCommitmentDefinition('NOTES'));
5556
- registerCommitment(new NoteCommitmentDefinition('COMMENT'));
5557
- registerCommitment(new NoteCommitmentDefinition('NONCE'));
5558
- registerCommitment(new GoalCommitmentDefinition('GOAL'));
5559
- registerCommitment(new GoalCommitmentDefinition('GOALS'));
5560
- registerCommitment(new ImportantCommitmentDefinition());
5561
- registerCommitment(new InitialMessageCommitmentDefinition());
5562
- registerCommitment(new UserMessageCommitmentDefinition());
5563
- registerCommitment(new AgentMessageCommitmentDefinition());
5564
- registerCommitment(new MessageCommitmentDefinition('MESSAGE'));
5565
- registerCommitment(new MessageCommitmentDefinition('MESSAGES'));
5566
- registerCommitment(new ScenarioCommitmentDefinition('SCENARIO'));
5567
- registerCommitment(new ScenarioCommitmentDefinition('SCENARIOS'));
5568
- registerCommitment(new DeleteCommitmentDefinition('DELETE'));
5569
- registerCommitment(new DeleteCommitmentDefinition('CANCEL'));
5570
- registerCommitment(new DeleteCommitmentDefinition('DISCARD'));
5571
- registerCommitment(new DeleteCommitmentDefinition('REMOVE'));
5572
- registerCommitment(new OpenCommitmentDefinition());
5573
- registerCommitment(new ClosedCommitmentDefinition());
5574
- // Register not yet implemented commitments
5575
- registerCommitment(new NotYetImplementedCommitmentDefinition('EXPECT'));
5576
- registerCommitment(new NotYetImplementedCommitmentDefinition('BEHAVIOUR'));
5577
- registerCommitment(new NotYetImplementedCommitmentDefinition('BEHAVIOURS'));
5578
- registerCommitment(new NotYetImplementedCommitmentDefinition('AVOID'));
5579
- registerCommitment(new NotYetImplementedCommitmentDefinition('AVOIDANCE'));
5580
- registerCommitment(new NotYetImplementedCommitmentDefinition('CONTEXT'));
5581
-
5582
5449
  /**
5583
- * Parses agent source using the new commitment system with multiline support
5584
- * This function replaces the hardcoded commitment parsing in the original parseAgentSource
5450
+ * USE commitment definition
5585
5451
  *
5586
- * @private internal utility of `parseAgentSource`
5452
+ * The USE commitment indicates that the agent should utilize specific tools or capabilities
5453
+ * to access and interact with external systems when necessary.
5454
+ *
5455
+ * Supported USE types:
5456
+ * - USE BROWSER: Enables the agent to use a web browser tool
5457
+ * - USE SEARCH ENGINE (future): Enables search engine access
5458
+ * - USE FILE SYSTEM (future): Enables file system operations
5459
+ * - USE MCP (future): Enables MCP server connections
5460
+ *
5461
+ * The content following the USE commitment is ignored (similar to NOTE).
5462
+ *
5463
+ * Example usage in agent source:
5464
+ *
5465
+ * ```book
5466
+ * USE BROWSER
5467
+ * USE SEARCH ENGINE
5468
+ * ```
5469
+ *
5470
+ * @private [🪔] Maybe export the commitments through some package
5587
5471
  */
5588
- function parseAgentSourceWithCommitments(agentSource) {
5589
- var _a, _b, _c;
5590
- if (!agentSource || !agentSource.trim()) {
5591
- return {
5592
- agentName: null,
5593
- commitments: [],
5594
- nonCommitmentLines: [],
5595
- };
5472
+ class UseCommitmentDefinition extends BaseCommitmentDefinition {
5473
+ constructor() {
5474
+ super('USE');
5596
5475
  }
5597
- const lines = agentSource.split('\n');
5598
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
5599
- const commitments = [];
5600
- const nonCommitmentLines = [];
5601
- // Always add the first line (agent name) to non-commitment lines
5602
- if (lines[0] !== undefined) {
5603
- nonCommitmentLines.push(lines[0]);
5476
+ /**
5477
+ * Short one-line description of USE commitments.
5478
+ */
5479
+ get description() {
5480
+ return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, etc.).';
5604
5481
  }
5605
- // Parse commitments with multiline support
5606
- let currentCommitment = null;
5607
- // Process lines starting from the second line (skip agent name)
5608
- for (let i = 1; i < lines.length; i++) {
5609
- const line = lines[i];
5610
- if (line === undefined) {
5482
+ /**
5483
+ * Icon for this commitment.
5484
+ */
5485
+ get icon() {
5486
+ return '🔧';
5487
+ }
5488
+ /**
5489
+ * Markdown documentation for USE commitment.
5490
+ */
5491
+ get documentation() {
5492
+ return spaceTrim$1(`
5493
+ # USE
5494
+
5495
+ Enables the agent to use specific tools or capabilities for interacting with external systems.
5496
+
5497
+ ## Supported USE types
5498
+
5499
+ - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
5500
+ - **USE SEARCH ENGINE** (future) - Enables search engine access
5501
+ - **USE FILE SYSTEM** (future) - Enables file system operations
5502
+ - **USE MCP** (future) - Enables MCP server connections
5503
+
5504
+ ## Key aspects
5505
+
5506
+ - The content following the USE commitment is ignored (similar to NOTE)
5507
+ - Multiple USE commitments can be specified to enable multiple capabilities
5508
+ - The actual tool usage is handled by the agent runtime
5509
+
5510
+ ## Examples
5511
+
5512
+ ### Basic browser usage
5513
+
5514
+ \`\`\`book
5515
+ Research Assistant
5516
+
5517
+ PERSONA You are a helpful research assistant
5518
+ USE BROWSER
5519
+ KNOWLEDGE Can search the web for up-to-date information
5520
+ \`\`\`
5521
+
5522
+ ### Multiple tools
5523
+
5524
+ \`\`\`book
5525
+ Data Analyst
5526
+
5527
+ PERSONA You are a data analyst assistant
5528
+ USE BROWSER
5529
+ USE FILE SYSTEM
5530
+ ACTION Can analyze data from various sources
5531
+ \`\`\`
5532
+ `);
5533
+ }
5534
+ applyToAgentModelRequirements(requirements, content) {
5535
+ // USE commitments don't modify the system message or model requirements directly
5536
+ // They are handled separately in the parsing logic for capability extraction
5537
+ // This method exists for consistency with the CommitmentDefinition interface
5538
+ return requirements;
5539
+ }
5540
+ /**
5541
+ * Extracts the tool type from the USE commitment
5542
+ * This is used by the parsing logic
5543
+ */
5544
+ extractToolType(content) {
5545
+ var _a, _b;
5546
+ const trimmedContent = content.trim();
5547
+ // The tool type is the first word after USE (already stripped)
5548
+ const match = trimmedContent.match(/^(\w+)/);
5549
+ return (_b = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : null;
5550
+ }
5551
+ /**
5552
+ * Checks if this is a known USE type
5553
+ */
5554
+ isKnownUseType(useType) {
5555
+ const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'FILE SYSTEM', 'MCP'];
5556
+ return knownTypes.includes(useType.toUpperCase());
5557
+ }
5558
+ }
5559
+ /**
5560
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5561
+ */
5562
+
5563
+ /**
5564
+ * USE BROWSER commitment definition
5565
+ *
5566
+ * The `USE BROWSER` commitment indicates that the agent should utilize a web browser tool
5567
+ * to access and retrieve up-to-date information from the internet when necessary.
5568
+ *
5569
+ * The content following `USE BROWSER` is ignored (similar to NOTE).
5570
+ *
5571
+ * Example usage in agent source:
5572
+ *
5573
+ * ```book
5574
+ * USE BROWSER
5575
+ * USE BROWSER This will be ignored
5576
+ * ```
5577
+ *
5578
+ * @private [🪔] Maybe export the commitments through some package
5579
+ */
5580
+ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
5581
+ constructor() {
5582
+ super('USE BROWSER', ['BROWSER']);
5583
+ }
5584
+ /**
5585
+ * Short one-line description of USE BROWSER.
5586
+ */
5587
+ get description() {
5588
+ return 'Enable the agent to use a web browser tool for accessing internet information.';
5589
+ }
5590
+ /**
5591
+ * Icon for this commitment.
5592
+ */
5593
+ get icon() {
5594
+ return '🌐';
5595
+ }
5596
+ /**
5597
+ * Markdown documentation for USE BROWSER commitment.
5598
+ */
5599
+ get documentation() {
5600
+ return spaceTrim$1(`
5601
+ # USE BROWSER
5602
+
5603
+ Enables the agent to use a web browser tool to access and retrieve up-to-date information from the internet.
5604
+
5605
+ ## Key aspects
5606
+
5607
+ - The content following \`USE BROWSER\` is ignored (similar to NOTE)
5608
+ - The actual browser tool usage is handled by the agent runtime
5609
+ - Allows the agent to fetch current information from websites
5610
+ - Useful for research tasks, fact-checking, and accessing dynamic content
5611
+
5612
+ ## Examples
5613
+
5614
+ \`\`\`book
5615
+ Research Assistant
5616
+
5617
+ PERSONA You are a helpful research assistant specialized in finding current information
5618
+ USE BROWSER
5619
+ RULE Always cite your sources when providing information from the web
5620
+ \`\`\`
5621
+
5622
+ \`\`\`book
5623
+ News Analyst
5624
+
5625
+ PERSONA You are a news analyst who stays up-to-date with current events
5626
+ USE BROWSER
5627
+ STYLE Present news in a balanced and objective manner
5628
+ ACTION Can search for and summarize news articles
5629
+ \`\`\`
5630
+
5631
+ \`\`\`book
5632
+ Company Lawyer
5633
+
5634
+ PERSONA You are a company lawyer providing legal advice
5635
+ USE BROWSER
5636
+ KNOWLEDGE Corporate law and legal procedures
5637
+ RULE Always recommend consulting with a licensed attorney for specific legal matters
5638
+ \`\`\`
5639
+ `);
5640
+ }
5641
+ applyToAgentModelRequirements(requirements, content) {
5642
+ // We simply mark that browser capability is enabled in metadata
5643
+ // Get existing metadata
5644
+ const existingMetadata = requirements.metadata || {};
5645
+ // Get existing tools array or create new one
5646
+ const existingTools = existingMetadata.tools || [];
5647
+ // Add 'browser' to tools if not already present
5648
+ const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
5649
+ // Return requirements with updated metadata
5650
+ return {
5651
+ ...requirements,
5652
+ metadata: {
5653
+ ...existingMetadata,
5654
+ tools: updatedTools,
5655
+ useBrowser: true,
5656
+ },
5657
+ };
5658
+ }
5659
+ }
5660
+ /**
5661
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5662
+ */
5663
+
5664
+ /**
5665
+ * USE MCP commitment definition
5666
+ *
5667
+ * The `USE MCP` commitment allows to specify an MCP server URL which the agent will connect to
5668
+ * for retrieving additional instructions and actions.
5669
+ *
5670
+ * The content following `USE MCP` is the URL of the MCP server.
5671
+ *
5672
+ * Example usage in agent source:
5673
+ *
5674
+ * ```book
5675
+ * USE MCP http://mcp-server-url.com
5676
+ * ```
5677
+ *
5678
+ * @private [🪔] Maybe export the commitments through some package
5679
+ */
5680
+ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
5681
+ constructor() {
5682
+ super('USE MCP', ['MCP']);
5683
+ }
5684
+ /**
5685
+ * Short one-line description of USE MCP.
5686
+ */
5687
+ get description() {
5688
+ return 'Connects the agent to an external MCP server for additional capabilities.';
5689
+ }
5690
+ /**
5691
+ * Icon for this commitment.
5692
+ */
5693
+ get icon() {
5694
+ return '🔌';
5695
+ }
5696
+ /**
5697
+ * Markdown documentation for USE MCP commitment.
5698
+ */
5699
+ get documentation() {
5700
+ return spaceTrim$1(`
5701
+ # USE MCP
5702
+
5703
+ Connects the agent to an external Model Context Protocol (MCP) server.
5704
+
5705
+ ## Key aspects
5706
+
5707
+ - The content following \`USE MCP\` must be a valid URL
5708
+ - Multiple MCP servers can be connected by using multiple \`USE MCP\` commitments
5709
+ - The agent will have access to tools and resources provided by the MCP server
5710
+
5711
+ ## Example
5712
+
5713
+ \`\`\`book
5714
+ Company Lawyer
5715
+
5716
+ PERSONA You are a company lawyer.
5717
+ USE MCP http://legal-db.example.com
5718
+ \`\`\`
5719
+ `);
5720
+ }
5721
+ applyToAgentModelRequirements(requirements, content) {
5722
+ const mcpServerUrl = content.trim();
5723
+ if (!mcpServerUrl) {
5724
+ return requirements;
5725
+ }
5726
+ const existingMcpServers = requirements.mcpServers || [];
5727
+ // Avoid duplicates
5728
+ if (existingMcpServers.includes(mcpServerUrl)) {
5729
+ return requirements;
5730
+ }
5731
+ return {
5732
+ ...requirements,
5733
+ mcpServers: [...existingMcpServers, mcpServerUrl],
5734
+ };
5735
+ }
5736
+ }
5737
+ /**
5738
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5739
+ */
5740
+
5741
+ /**
5742
+ * USE SEARCH ENGINE commitment definition
5743
+ *
5744
+ * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
5745
+ * to access and retrieve up-to-date information from the internet when necessary.
5746
+ *
5747
+ * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
5748
+ *
5749
+ * Example usage in agent source:
5750
+ *
5751
+ * ```book
5752
+ * USE SEARCH ENGINE
5753
+ * USE SEARCH ENGINE This will be ignored
5754
+ * ```
5755
+ *
5756
+ * @private [🪔] Maybe export the commitments through some package
5757
+ */
5758
+ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
5759
+ constructor() {
5760
+ super('USE SEARCH ENGINE', ['SEARCH ENGINE', 'SEARCH']);
5761
+ }
5762
+ /**
5763
+ * Short one-line description of USE SEARCH ENGINE.
5764
+ */
5765
+ get description() {
5766
+ return 'Enable the agent to use a search engine tool for accessing internet information.';
5767
+ }
5768
+ /**
5769
+ * Icon for this commitment.
5770
+ */
5771
+ get icon() {
5772
+ return '🔍';
5773
+ }
5774
+ /**
5775
+ * Markdown documentation for USE SEARCH ENGINE commitment.
5776
+ */
5777
+ get documentation() {
5778
+ return spaceTrim$1(`
5779
+ # USE SEARCH ENGINE
5780
+
5781
+ Enables the agent to use a search engine tool to access and retrieve up-to-date information from the internet.
5782
+
5783
+ ## Key aspects
5784
+
5785
+ - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
5786
+ - The actual search engine tool usage is handled by the agent runtime
5787
+ - Allows the agent to search for current information from the web
5788
+ - Useful for research tasks, finding facts, and accessing dynamic content
5789
+
5790
+ ## Examples
5791
+
5792
+ \`\`\`book
5793
+ Research Assistant
5794
+
5795
+ PERSONA You are a helpful research assistant specialized in finding current information
5796
+ USE SEARCH ENGINE
5797
+ RULE Always cite your sources when providing information from the web
5798
+ \`\`\`
5799
+
5800
+ \`\`\`book
5801
+ Fact Checker
5802
+
5803
+ PERSONA You are a fact checker
5804
+ USE SEARCH ENGINE
5805
+ ACTION Search for claims and verify them against reliable sources
5806
+ \`\`\`
5807
+ `);
5808
+ }
5809
+ applyToAgentModelRequirements(requirements, content) {
5810
+ // We simply mark that search engine capability is enabled in metadata
5811
+ // Get existing metadata
5812
+ const existingMetadata = requirements.metadata || {};
5813
+ // Get existing tools array or create new one
5814
+ const existingTools = existingMetadata.tools || [];
5815
+ // Add 'search-engine' to tools if not already present
5816
+ const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
5817
+ // Return requirements with updated metadata
5818
+ return {
5819
+ ...requirements,
5820
+ metadata: {
5821
+ ...existingMetadata,
5822
+ tools: updatedTools,
5823
+ useSearchEngine: true,
5824
+ },
5825
+ };
5826
+ }
5827
+ }
5828
+ /**
5829
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5830
+ */
5831
+
5832
+ /**
5833
+ * Placeholder commitment definition for commitments that are not yet implemented
5834
+ *
5835
+ * This commitment simply adds its content 1:1 into the system message,
5836
+ * preserving the original behavior until proper implementation is added.
5837
+ *
5838
+ * @public exported from `@promptbook/core`
5839
+ */
5840
+ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
5841
+ constructor(type) {
5842
+ super(type);
5843
+ }
5844
+ /**
5845
+ * Short one-line description of a placeholder commitment.
5846
+ */
5847
+ get description() {
5848
+ return 'Placeholder commitment that appends content verbatim to the system message.';
5849
+ }
5850
+ /**
5851
+ * Icon for this commitment.
5852
+ */
5853
+ get icon() {
5854
+ return '🚧';
5855
+ }
5856
+ /**
5857
+ * Markdown documentation available at runtime.
5858
+ */
5859
+ get documentation() {
5860
+ return spaceTrim$1(`
5861
+ # ${this.type}
5862
+
5863
+ This commitment is not yet fully implemented.
5864
+
5865
+ ## Key aspects
5866
+
5867
+ - Content is appended directly to the system message.
5868
+ - No special processing or validation is performed.
5869
+ - Behavior preserved until proper implementation is added.
5870
+
5871
+ ## Status
5872
+
5873
+ - **Status:** Placeholder implementation
5874
+ - **Effect:** Appends content prefixed by commitment type
5875
+ - **Future:** Will be replaced with specialized logic
5876
+
5877
+ ## Examples
5878
+
5879
+ \`\`\`book
5880
+ Example Agent
5881
+
5882
+ PERSONA You are a helpful assistant
5883
+ ${this.type} Your content here
5884
+ RULE Always be helpful
5885
+ \`\`\`
5886
+ `);
5887
+ }
5888
+ applyToAgentModelRequirements(requirements, content) {
5889
+ const trimmedContent = content.trim();
5890
+ if (!trimmedContent) {
5891
+ return requirements;
5892
+ }
5893
+ // Add the commitment content 1:1 to the system message
5894
+ const commitmentLine = `${this.type} ${trimmedContent}`;
5895
+ return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
5896
+ }
5897
+ }
5898
+
5899
+ // Import all commitment definition classes
5900
+ /**
5901
+ * Registry of all available commitment definitions
5902
+ * This array contains instances of all commitment definitions
5903
+ * This is the single source of truth for all commitments in the system
5904
+ *
5905
+ * @private Use functions to access commitments instead of this array directly
5906
+ */
5907
+ const COMMITMENT_REGISTRY = [
5908
+ // Fully implemented commitments
5909
+ new PersonaCommitmentDefinition('PERSONA'),
5910
+ new PersonaCommitmentDefinition('PERSONAE'),
5911
+ new KnowledgeCommitmentDefinition(),
5912
+ new MemoryCommitmentDefinition('MEMORY'),
5913
+ new MemoryCommitmentDefinition('MEMORIES'),
5914
+ new StyleCommitmentDefinition('STYLE'),
5915
+ new StyleCommitmentDefinition('STYLES'),
5916
+ new RuleCommitmentDefinition('RULE'),
5917
+ new RuleCommitmentDefinition('RULES'),
5918
+ new LanguageCommitmentDefinition('LANGUAGE'),
5919
+ new LanguageCommitmentDefinition('LANGUAGES'),
5920
+ new SampleCommitmentDefinition('SAMPLE'),
5921
+ new SampleCommitmentDefinition('EXAMPLE'),
5922
+ new FormatCommitmentDefinition('FORMAT'),
5923
+ new FormatCommitmentDefinition('FORMATS'),
5924
+ new FromCommitmentDefinition('FROM'),
5925
+ new ModelCommitmentDefinition('MODEL'),
5926
+ new ModelCommitmentDefinition('MODELS'),
5927
+ new ActionCommitmentDefinition('ACTION'),
5928
+ new ActionCommitmentDefinition('ACTIONS'),
5929
+ new ComponentCommitmentDefinition(),
5930
+ new MetaImageCommitmentDefinition(),
5931
+ new MetaColorCommitmentDefinition(),
5932
+ new MetaFontCommitmentDefinition(),
5933
+ new MetaLinkCommitmentDefinition(),
5934
+ new MetaCommitmentDefinition(),
5935
+ new NoteCommitmentDefinition('NOTE'),
5936
+ new NoteCommitmentDefinition('NOTES'),
5937
+ new NoteCommitmentDefinition('COMMENT'),
5938
+ new NoteCommitmentDefinition('NONCE'),
5939
+ new GoalCommitmentDefinition('GOAL'),
5940
+ new GoalCommitmentDefinition('GOALS'),
5941
+ new InitialMessageCommitmentDefinition(),
5942
+ new UserMessageCommitmentDefinition(),
5943
+ new AgentMessageCommitmentDefinition(),
5944
+ new MessageCommitmentDefinition('MESSAGE'),
5945
+ new MessageCommitmentDefinition('MESSAGES'),
5946
+ new ScenarioCommitmentDefinition('SCENARIO'),
5947
+ new ScenarioCommitmentDefinition('SCENARIOS'),
5948
+ new DeleteCommitmentDefinition('DELETE'),
5949
+ new DeleteCommitmentDefinition('CANCEL'),
5950
+ new DeleteCommitmentDefinition('DISCARD'),
5951
+ new DeleteCommitmentDefinition('REMOVE'),
5952
+ new OpenCommitmentDefinition(),
5953
+ new ClosedCommitmentDefinition(),
5954
+ new UseBrowserCommitmentDefinition(),
5955
+ new UseSearchEngineCommitmentDefinition(),
5956
+ new UseMcpCommitmentDefinition(),
5957
+ new UseCommitmentDefinition(),
5958
+ // Not yet implemented commitments (using placeholder)
5959
+ new NotYetImplementedCommitmentDefinition('EXPECT'),
5960
+ new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
5961
+ new NotYetImplementedCommitmentDefinition('BEHAVIOURS'),
5962
+ new NotYetImplementedCommitmentDefinition('AVOID'),
5963
+ new NotYetImplementedCommitmentDefinition('AVOIDANCE'),
5964
+ new NotYetImplementedCommitmentDefinition('CONTEXT'),
5965
+ ];
5966
+ /**
5967
+ * TODO: [🧠] Maybe create through standardized $register
5968
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5969
+ */
5970
+
5971
+ /**
5972
+ * Regex pattern to match horizontal lines (markdown thematic breaks)
5973
+ * Matches 3 or more hyphens, underscores, or asterisks (with optional spaces between)
5974
+ */
5975
+ const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
5976
+ /**
5977
+ * Parses agent source using the new commitment system with multiline support
5978
+ * This function replaces the hardcoded commitment parsing in the original parseAgentSource
5979
+ *
5980
+ * @private internal utility of `parseAgentSource`
5981
+ */
5982
+ function parseAgentSourceWithCommitments(agentSource) {
5983
+ var _a, _b, _c;
5984
+ if (!agentSource || !agentSource.trim()) {
5985
+ return {
5986
+ agentName: null,
5987
+ commitments: [],
5988
+ nonCommitmentLines: [],
5989
+ };
5990
+ }
5991
+ const lines = agentSource.split('\n');
5992
+ const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
5993
+ const commitments = [];
5994
+ const nonCommitmentLines = [];
5995
+ // Always add the first line (agent name) to non-commitment lines
5996
+ if (lines[0] !== undefined) {
5997
+ nonCommitmentLines.push(lines[0]);
5998
+ }
5999
+ // Parse commitments with multiline support
6000
+ let currentCommitment = null;
6001
+ // Process lines starting from the second line (skip agent name)
6002
+ for (let i = 1; i < lines.length; i++) {
6003
+ const line = lines[i];
6004
+ if (line === undefined) {
5611
6005
  continue;
5612
6006
  }
5613
6007
  // Check if this line starts a new commitment
@@ -5621,7 +6015,7 @@ function parseAgentSourceWithCommitments(agentSource) {
5621
6015
  const fullContent = currentCommitment.contentLines.join('\n');
5622
6016
  commitments.push({
5623
6017
  type: currentCommitment.type,
5624
- content: spaceTrim(fullContent),
6018
+ content: spaceTrim$1(fullContent),
5625
6019
  originalLine: currentCommitment.originalStartLine,
5626
6020
  lineNumber: currentCommitment.startLineNumber,
5627
6021
  });
@@ -5641,6 +6035,24 @@ function parseAgentSourceWithCommitments(agentSource) {
5641
6035
  break;
5642
6036
  }
5643
6037
  }
6038
+ // Check if this is a horizontal line (ends any current commitment)
6039
+ const isHorizontalLine = HORIZONTAL_LINE_PATTERN.test(line);
6040
+ if (isHorizontalLine) {
6041
+ // Save the current commitment if it exists
6042
+ if (currentCommitment) {
6043
+ const fullContent = currentCommitment.contentLines.join('\n');
6044
+ commitments.push({
6045
+ type: currentCommitment.type,
6046
+ content: spaceTrim$1(fullContent),
6047
+ originalLine: currentCommitment.originalStartLine,
6048
+ lineNumber: currentCommitment.startLineNumber,
6049
+ });
6050
+ currentCommitment = null;
6051
+ }
6052
+ // Add horizontal line to non-commitment lines
6053
+ nonCommitmentLines.push(line);
6054
+ continue;
6055
+ }
5644
6056
  if (!foundNewCommitment) {
5645
6057
  if (currentCommitment) {
5646
6058
  // This line belongs to the current commitment
@@ -5657,7 +6069,7 @@ function parseAgentSourceWithCommitments(agentSource) {
5657
6069
  const fullContent = currentCommitment.contentLines.join('\n');
5658
6070
  commitments.push({
5659
6071
  type: currentCommitment.type,
5660
- content: spaceTrim(fullContent),
6072
+ content: spaceTrim$1(fullContent),
5661
6073
  originalLine: currentCommitment.originalStartLine,
5662
6074
  lineNumber: currentCommitment.startLineNumber,
5663
6075
  });
@@ -5766,17 +6178,21 @@ function parseAgentSource(agentSource) {
5766
6178
  const links = [];
5767
6179
  for (const commitment of parseResult.commitments) {
5768
6180
  if (commitment.type === 'META LINK') {
5769
- const linkValue = spaceTrim$1(commitment.content);
6181
+ const linkValue = spaceTrim$2(commitment.content);
5770
6182
  links.push(linkValue);
5771
6183
  meta.link = linkValue;
5772
6184
  continue;
5773
6185
  }
5774
6186
  if (commitment.type === 'META IMAGE') {
5775
- meta.image = spaceTrim$1(commitment.content);
6187
+ meta.image = spaceTrim$2(commitment.content);
5776
6188
  continue;
5777
6189
  }
5778
6190
  if (commitment.type === 'META COLOR') {
5779
- meta.color = spaceTrim$1(commitment.content);
6191
+ meta.color = spaceTrim$2(commitment.content);
6192
+ continue;
6193
+ }
6194
+ if (commitment.type === 'META FONT') {
6195
+ meta.font = spaceTrim$2(commitment.content);
5780
6196
  continue;
5781
6197
  }
5782
6198
  if (commitment.type !== 'META') {
@@ -5785,10 +6201,10 @@ function parseAgentSource(agentSource) {
5785
6201
  // Parse META commitments - format is "META TYPE content"
5786
6202
  const metaTypeRaw = commitment.content.split(' ')[0] || 'NONE';
5787
6203
  if (metaTypeRaw === 'LINK') {
5788
- links.push(spaceTrim$1(commitment.content.substring(metaTypeRaw.length)));
6204
+ links.push(spaceTrim$2(commitment.content.substring(metaTypeRaw.length)));
5789
6205
  }
5790
6206
  const metaType = normalizeTo_camelCase(metaTypeRaw);
5791
- meta[metaType] = spaceTrim$1(commitment.content.substring(metaTypeRaw.length));
6207
+ meta[metaType] = spaceTrim$2(commitment.content.substring(metaTypeRaw.length));
5792
6208
  }
5793
6209
  // Generate gravatar fallback if no meta image specified
5794
6210
  if (!meta.image) {