@promptbook/core 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/umd/index.umd.js CHANGED
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-55';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-56';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -90,6 +90,17 @@
90
90
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
91
91
  */
92
92
 
93
+ /**
94
+ * Trims string from all 4 sides
95
+ *
96
+ * Note: This is a re-exported function from the `spacetrim` package which is
97
+ * Developed by same author @hejny as this package
98
+ *
99
+ * @public exported from `@promptbook/utils`
100
+ * @see https://github.com/hejny/spacetrim#usage
101
+ */
102
+ const spaceTrim = spaceTrim$1.spaceTrim;
103
+
93
104
  /**
94
105
  * @private util of `@promptbook/color`
95
106
  * @de
@@ -138,6 +149,7 @@
138
149
  * @public exported from `@promptbook/color`
139
150
  */
140
151
  const CSS_COLORS = {
152
+ promptbook: '#79EAFD',
141
153
  transparent: 'rgba(0,0,0,0)',
142
154
  aliceblue: '#f0f8ff',
143
155
  antiquewhite: '#faebd7',
@@ -353,6 +365,28 @@
353
365
  throw new Error(`Can not create color from given object`);
354
366
  }
355
367
  }
368
+ /**
369
+ * Creates a new Color instance from miscellaneous formats
370
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
371
+ *
372
+ * @param color
373
+ * @returns Color object
374
+ */
375
+ static fromSafe(color) {
376
+ try {
377
+ return Color.from(color);
378
+ }
379
+ catch (error) {
380
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
381
+ console.warn(spaceTrim((block) => `
382
+ Color.fromSafe error:
383
+ ${block(error.message)}
384
+
385
+ Returning default PROMPTBOOK_COLOR.
386
+ `));
387
+ return Color.fromString('promptbook');
388
+ }
389
+ }
356
390
  /**
357
391
  * Creates a new Color instance from miscellaneous string formats
358
392
  *
@@ -976,7 +1010,7 @@
976
1010
  *
977
1011
  * @public exported from `@promptbook/core`
978
1012
  */
979
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
1013
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
980
1014
  // <- TODO: [๐Ÿง ][๐Ÿˆต] Using `Color` here increases the package size approx 3kb, maybe remove it
981
1015
  /**
982
1016
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -8149,289 +8183,6 @@
8149
8183
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
8150
8184
  */
8151
8185
 
8152
- /**
8153
- * Placeholder commitment definition for commitments that are not yet implemented
8154
- *
8155
- * This commitment simply adds its content 1:1 into the system message,
8156
- * preserving the original behavior until proper implementation is added.
8157
- *
8158
- * @public exported from `@promptbook/core`
8159
- */
8160
- class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
8161
- constructor(type) {
8162
- super(type);
8163
- }
8164
- /**
8165
- * Short one-line description of a placeholder commitment.
8166
- */
8167
- get description() {
8168
- return 'Placeholder commitment that appends content verbatim to the system message.';
8169
- }
8170
- /**
8171
- * Icon for this commitment.
8172
- */
8173
- get icon() {
8174
- return '๐Ÿšง';
8175
- }
8176
- /**
8177
- * Markdown documentation available at runtime.
8178
- */
8179
- get documentation() {
8180
- return spaceTrim$1.spaceTrim(`
8181
- # ${this.type}
8182
-
8183
- This commitment is not yet fully implemented.
8184
-
8185
- ## Key aspects
8186
-
8187
- - Content is appended directly to the system message.
8188
- - No special processing or validation is performed.
8189
- - Behavior preserved until proper implementation is added.
8190
-
8191
- ## Status
8192
-
8193
- - **Status:** Placeholder implementation
8194
- - **Effect:** Appends content prefixed by commitment type
8195
- - **Future:** Will be replaced with specialized logic
8196
-
8197
- ## Examples
8198
-
8199
- \`\`\`book
8200
- Example Agent
8201
-
8202
- PERSONA You are a helpful assistant
8203
- ${this.type} Your content here
8204
- RULE Always be helpful
8205
- \`\`\`
8206
- `);
8207
- }
8208
- applyToAgentModelRequirements(requirements, content) {
8209
- const trimmedContent = content.trim();
8210
- if (!trimmedContent) {
8211
- return requirements;
8212
- }
8213
- // Add the commitment content 1:1 to the system message
8214
- const commitmentLine = `${this.type} ${trimmedContent}`;
8215
- return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
8216
- }
8217
- }
8218
-
8219
- /**
8220
- * Registry of all available commitment definitions
8221
- * This array contains instances of all commitment definitions
8222
- * This is the single source of truth for all commitments in the system
8223
- *
8224
- * @private Use functions to access commitments instead of this array directly
8225
- */
8226
- const COMMITMENT_REGISTRY = [];
8227
- /**
8228
- * Registers a new commitment definition
8229
- * @param definition The commitment definition to register
8230
- *
8231
- * @public exported from `@promptbook/core`
8232
- */
8233
- function registerCommitment(definition) {
8234
- COMMITMENT_REGISTRY.push(definition);
8235
- }
8236
- /**
8237
- * Gets a commitment definition by its type
8238
- * @param type The commitment type to look up
8239
- * @returns The commitment definition or null if not found
8240
- *
8241
- * @public exported from `@promptbook/core`
8242
- */
8243
- function getCommitmentDefinition(type) {
8244
- return COMMITMENT_REGISTRY.find((commitmentDefinition) => commitmentDefinition.type === type) || null;
8245
- }
8246
- /**
8247
- * Gets all available commitment definitions
8248
- * @returns Array of all commitment definitions
8249
- *
8250
- * @public exported from `@promptbook/core`
8251
- */
8252
- function getAllCommitmentDefinitions() {
8253
- return $deepFreeze([...COMMITMENT_REGISTRY]);
8254
- }
8255
- /**
8256
- * Gets all available commitment types
8257
- * @returns Array of all commitment types
8258
- *
8259
- * @public exported from `@promptbook/core`
8260
- */
8261
- function getAllCommitmentTypes() {
8262
- return $deepFreeze(COMMITMENT_REGISTRY.map((commitmentDefinition) => commitmentDefinition.type));
8263
- }
8264
- /**
8265
- * Checks if a commitment type is supported
8266
- * @param type The commitment type to check
8267
- * @returns True if the commitment type is supported
8268
- *
8269
- * @public exported from `@promptbook/core`
8270
- */
8271
- function isCommitmentSupported(type) {
8272
- return COMMITMENT_REGISTRY.some((commitmentDefinition) => commitmentDefinition.type === type);
8273
- }
8274
- /**
8275
- * Gets all commitment definitions grouped by their aliases
8276
- *
8277
- * @returns Array of grouped commitment definitions
8278
- *
8279
- * @public exported from `@promptbook/core`
8280
- */
8281
- function getGroupedCommitmentDefinitions() {
8282
- const groupedCommitments = [];
8283
- for (const commitment of COMMITMENT_REGISTRY) {
8284
- const lastGroup = groupedCommitments[groupedCommitments.length - 1];
8285
- // Check if we should group with the previous item
8286
- let shouldGroup = false;
8287
- if (lastGroup) {
8288
- const lastPrimary = lastGroup.primary;
8289
- // Case 1: Same class constructor (except NotYetImplemented)
8290
- if (!(commitment instanceof NotYetImplementedCommitmentDefinition) &&
8291
- commitment.constructor === lastPrimary.constructor) {
8292
- shouldGroup = true;
8293
- }
8294
- // Case 2: NotYetImplemented with prefix matching (e.g. BEHAVIOUR -> BEHAVIOURS)
8295
- else if (commitment instanceof NotYetImplementedCommitmentDefinition &&
8296
- lastPrimary instanceof NotYetImplementedCommitmentDefinition &&
8297
- commitment.type.startsWith(lastPrimary.type)) {
8298
- shouldGroup = true;
8299
- }
8300
- // Case 3: OPEN and CLOSED are related
8301
- else if (lastPrimary.type === 'OPEN' && commitment.type === 'CLOSED') {
8302
- shouldGroup = true;
8303
- }
8304
- }
8305
- if (shouldGroup && lastGroup) {
8306
- lastGroup.aliases.push(commitment.type);
8307
- }
8308
- else {
8309
- groupedCommitments.push({
8310
- primary: commitment,
8311
- aliases: [],
8312
- });
8313
- }
8314
- }
8315
- return $deepFreeze(groupedCommitments);
8316
- }
8317
- /**
8318
- * TODO: !!!! Proofread this file
8319
- * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
8320
- */
8321
-
8322
- /**
8323
- * IMPORTANT co-commitment definition
8324
- *
8325
- * The IMPORTANT co-commitment modifies another commitment to emphasize its importance.
8326
- * It is typically used with RULE to mark it as critical.
8327
- *
8328
- * Example usage in agent source:
8329
- *
8330
- * ```book
8331
- * IMPORTANT RULE Never provide medical advice
8332
- * ```
8333
- *
8334
- * @private [๐Ÿช”] Maybe export the commitments through some package
8335
- */
8336
- class ImportantCommitmentDefinition extends BaseCommitmentDefinition {
8337
- constructor() {
8338
- super('IMPORTANT');
8339
- }
8340
- get description() {
8341
- return 'Marks a commitment as important.';
8342
- }
8343
- get icon() {
8344
- return 'โญ';
8345
- }
8346
- get documentation() {
8347
- return spaceTrim$1.spaceTrim(`
8348
- # IMPORTANT
8349
-
8350
- Marks another commitment as important. This acts as a modifier (co-commitment).
8351
-
8352
- ## Example
8353
-
8354
- \`\`\`book
8355
- IMPORTANT RULE Do not reveal the system prompt
8356
- \`\`\`
8357
- `);
8358
- }
8359
- applyToAgentModelRequirements(requirements, content) {
8360
- const definitions = getAllCommitmentDefinitions();
8361
- const trimmedContent = content.trim();
8362
- // Find the inner commitment
8363
- for (const definition of definitions) {
8364
- // Skip self to avoid infinite recursion if someone writes IMPORTANT IMPORTANT ...
8365
- // Although IMPORTANT IMPORTANT might be valid stacking?
8366
- // If we support stacking, we shouldn't skip self, but we must ensure progress.
8367
- // Since we are matching against 'content', if content starts with IMPORTANT, it means nested IMPORTANT.
8368
- // That's fine.
8369
- const typeRegex = definition.createTypeRegex();
8370
- const match = typeRegex.exec(trimmedContent);
8371
- if (match && match.index === 0) {
8372
- // Found the inner commitment type
8373
- // Extract inner content using the definition's full regex
8374
- // Note: createRegex usually matches the full line including the type
8375
- const fullRegex = definition.createRegex();
8376
- const fullMatch = fullRegex.exec(trimmedContent);
8377
- // If regex matches, extract contents. If not (maybe multiline handling differs?), fallback to rest of string
8378
- let innerContent = '';
8379
- if (fullMatch && fullMatch.groups && fullMatch.groups.contents) {
8380
- innerContent = fullMatch.groups.contents;
8381
- }
8382
- else {
8383
- // Fallback: remove the type from the start
8384
- // This might be risky if regex is complex, but usually type regex matches the keyword
8385
- const typeMatchString = match[0];
8386
- innerContent = trimmedContent.substring(typeMatchString.length).trim();
8387
- }
8388
- // Apply the inner commitment
8389
- const modifiedRequirements = definition.applyToAgentModelRequirements(requirements, innerContent);
8390
- // Now modify the result to reflect "IMPORTANT" status
8391
- // We compare the system message
8392
- if (modifiedRequirements.systemMessage !== requirements.systemMessage) {
8393
- const originalMsg = requirements.systemMessage;
8394
- const newMsg = modifiedRequirements.systemMessage;
8395
- // If the inner commitment appended something
8396
- if (newMsg.startsWith(originalMsg)) {
8397
- const appended = newMsg.substring(originalMsg.length);
8398
- // Add "IMPORTANT: " prefix to the appended part
8399
- // We need to be careful about newlines
8400
- // Heuristic: If appended starts with separator (newlines), preserve them
8401
- const matchSep = appended.match(/^(\s*)(.*)/s);
8402
- if (matchSep) {
8403
- const [, separator, text] = matchSep;
8404
- // Check if it already has "Rule:" prefix or similar
8405
- // We want "IMPORTANT Rule: ..."
8406
- // Let's just prepend IMPORTANT to the text
8407
- // But formatted nicely
8408
- // If it's a rule: "\n\nRule: content"
8409
- // We want "\n\nIMPORTANT Rule: content"
8410
- const importantText = `IMPORTANT ${text}`;
8411
- return {
8412
- ...modifiedRequirements,
8413
- systemMessage: originalMsg + separator + importantText
8414
- };
8415
- }
8416
- }
8417
- }
8418
- // If no system message change or we couldn't detect how to modify it, just return the modified requirements
8419
- // Maybe the inner commitment modified metadata?
8420
- return modifiedRequirements;
8421
- }
8422
- }
8423
- // If no inner commitment found, treat as a standalone note?
8424
- // Or warn?
8425
- // For now, treat as no-op or maybe just append as text?
8426
- // Let's treat as Note if fallback? No, explicit is better.
8427
- console.warn(`IMPORTANT commitment used without a valid inner commitment: ${content}`);
8428
- return requirements;
8429
- }
8430
- }
8431
- /**
8432
- * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
8433
- */
8434
-
8435
8186
  /**
8436
8187
  * KNOWLEDGE commitment definition
8437
8188
  *
@@ -9195,6 +8946,12 @@
9195
8946
  * META COLOR #00ff00
9196
8947
  * ```
9197
8948
  *
8949
+ * You can also specify multiple colors separated by comma:
8950
+ *
8951
+ * ```book
8952
+ * META COLOR #ff0000, #00ff00, #0000ff
8953
+ * ```
8954
+ *
9198
8955
  * @private [๐Ÿช”] Maybe export the commitments through some package
9199
8956
  */
9200
8957
  class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
@@ -9205,7 +8962,7 @@
9205
8962
  * Short one-line description of META COLOR.
9206
8963
  */
9207
8964
  get description() {
9208
- return "Set the agent's accent color.";
8965
+ return "Set the agent's accent color or gradient.";
9209
8966
  }
9210
8967
  /**
9211
8968
  * Icon for this commitment.
@@ -9220,7 +8977,7 @@
9220
8977
  return spaceTrim$1.spaceTrim(`
9221
8978
  # META COLOR
9222
8979
 
9223
- Sets the agent's accent color.
8980
+ Sets the agent's accent color or gradient.
9224
8981
 
9225
8982
  ## Key aspects
9226
8983
 
@@ -9228,6 +8985,7 @@
9228
8985
  - Only one \`META COLOR\` should be used per agent.
9229
8986
  - If multiple are specified, the last one takes precedence.
9230
8987
  - Used for visual representation in user interfaces.
8988
+ - Can specify multiple colors separated by comma to create a gradient.
9231
8989
 
9232
8990
  ## Examples
9233
8991
 
@@ -9244,6 +9002,13 @@
9244
9002
  META COLOR #e74c3c
9245
9003
  PERSONA You are a creative and inspiring assistant
9246
9004
  \`\`\`
9005
+
9006
+ \`\`\`book
9007
+ Gradient Agent
9008
+
9009
+ META COLOR #ff0000, #00ff00, #0000ff
9010
+ PERSONA You are a colorful agent
9011
+ \`\`\`
9247
9012
  `);
9248
9013
  }
9249
9014
  applyToAgentModelRequirements(requirements, content) {
@@ -9266,60 +9031,145 @@
9266
9031
  */
9267
9032
 
9268
9033
  /**
9269
- * META IMAGE commitment definition
9034
+ * META FONT commitment definition
9270
9035
  *
9271
- * The META IMAGE commitment sets the agent's avatar/profile image URL.
9036
+ * The META FONT commitment sets the agent's font.
9272
9037
  * This commitment is special because it doesn't affect the system message,
9273
9038
  * but is handled separately in the parsing logic.
9274
9039
  *
9275
9040
  * Example usage in agent source:
9276
9041
  *
9277
9042
  * ```book
9278
- * META IMAGE https://example.com/avatar.jpg
9279
- * META IMAGE /assets/agent-avatar.png
9043
+ * META FONT Poppins, Arial, sans-serif
9044
+ * META FONT Roboto
9280
9045
  * ```
9281
9046
  *
9282
9047
  * @private [๐Ÿช”] Maybe export the commitments through some package
9283
9048
  */
9284
- class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
9049
+ class MetaFontCommitmentDefinition extends BaseCommitmentDefinition {
9285
9050
  constructor() {
9286
- super('META IMAGE', ['IMAGE']);
9051
+ super('META FONT', ['FONT']);
9287
9052
  }
9288
9053
  /**
9289
- * Short one-line description of META IMAGE.
9054
+ * Short one-line description of META FONT.
9290
9055
  */
9291
9056
  get description() {
9292
- return "Set the agent's profile image URL.";
9057
+ return "Set the agent's font.";
9293
9058
  }
9294
9059
  /**
9295
9060
  * Icon for this commitment.
9296
9061
  */
9297
9062
  get icon() {
9298
- return '๐Ÿ–ผ๏ธ';
9063
+ return '๐Ÿ”ค';
9299
9064
  }
9300
9065
  /**
9301
- * Markdown documentation for META IMAGE commitment.
9066
+ * Markdown documentation for META FONT commitment.
9302
9067
  */
9303
9068
  get documentation() {
9304
9069
  return spaceTrim$1.spaceTrim(`
9305
- # META IMAGE
9070
+ # META FONT
9306
9071
 
9307
- Sets the agent's avatar/profile image URL.
9072
+ Sets the agent's font.
9308
9073
 
9309
9074
  ## Key aspects
9310
9075
 
9311
9076
  - Does not modify the agent's behavior or responses.
9312
- - Only one \`META IMAGE\` should be used per agent.
9077
+ - Only one \`META FONT\` should be used per agent.
9313
9078
  - If multiple are specified, the last one takes precedence.
9314
9079
  - Used for visual representation in user interfaces.
9080
+ - Supports Google Fonts.
9315
9081
 
9316
9082
  ## Examples
9317
9083
 
9318
9084
  \`\`\`book
9319
- Professional Assistant
9085
+ Modern Assistant
9320
9086
 
9321
- META IMAGE https://example.com/professional-avatar.jpg
9322
- PERSONA You are a professional business assistant
9087
+ META FONT Poppins, Arial, sans-serif
9088
+ PERSONA You are a modern assistant
9089
+ \`\`\`
9090
+
9091
+ \`\`\`book
9092
+ Classic Helper
9093
+
9094
+ META FONT Times New Roman
9095
+ PERSONA You are a classic helper
9096
+ \`\`\`
9097
+ `);
9098
+ }
9099
+ applyToAgentModelRequirements(requirements, content) {
9100
+ // META FONT doesn't modify the system message or model requirements
9101
+ // It's handled separately in the parsing logic
9102
+ // This method exists for consistency with the CommitmentDefinition interface
9103
+ return requirements;
9104
+ }
9105
+ /**
9106
+ * Extracts the font from the content
9107
+ * This is used by the parsing logic
9108
+ */
9109
+ extractProfileFont(content) {
9110
+ const trimmedContent = content.trim();
9111
+ return trimmedContent || null;
9112
+ }
9113
+ }
9114
+ /**
9115
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
9116
+ */
9117
+
9118
+ /**
9119
+ * META IMAGE commitment definition
9120
+ *
9121
+ * The META IMAGE commitment sets the agent's avatar/profile image URL.
9122
+ * This commitment is special because it doesn't affect the system message,
9123
+ * but is handled separately in the parsing logic.
9124
+ *
9125
+ * Example usage in agent source:
9126
+ *
9127
+ * ```book
9128
+ * META IMAGE https://example.com/avatar.jpg
9129
+ * META IMAGE /assets/agent-avatar.png
9130
+ * ```
9131
+ *
9132
+ * @private [๐Ÿช”] Maybe export the commitments through some package
9133
+ */
9134
+ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
9135
+ constructor() {
9136
+ super('META IMAGE', ['IMAGE']);
9137
+ }
9138
+ /**
9139
+ * Short one-line description of META IMAGE.
9140
+ */
9141
+ get description() {
9142
+ return "Set the agent's profile image URL.";
9143
+ }
9144
+ /**
9145
+ * Icon for this commitment.
9146
+ */
9147
+ get icon() {
9148
+ return '๐Ÿ–ผ๏ธ';
9149
+ }
9150
+ /**
9151
+ * Markdown documentation for META IMAGE commitment.
9152
+ */
9153
+ get documentation() {
9154
+ return spaceTrim$1.spaceTrim(`
9155
+ # META IMAGE
9156
+
9157
+ Sets the agent's avatar/profile image URL.
9158
+
9159
+ ## Key aspects
9160
+
9161
+ - Does not modify the agent's behavior or responses.
9162
+ - Only one \`META IMAGE\` should be used per agent.
9163
+ - If multiple are specified, the last one takes precedence.
9164
+ - Used for visual representation in user interfaces.
9165
+
9166
+ ## Examples
9167
+
9168
+ \`\`\`book
9169
+ Professional Assistant
9170
+
9171
+ META IMAGE https://example.com/professional-avatar.jpg
9172
+ PERSONA You are a professional business assistant
9323
9173
  STYLE Maintain a formal and courteous tone
9324
9174
  \`\`\`
9325
9175
 
@@ -10390,60 +10240,604 @@
10390
10240
  * [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10391
10241
  */
10392
10242
 
10243
+ /**
10244
+ * USE commitment definition
10245
+ *
10246
+ * The USE commitment indicates that the agent should utilize specific tools or capabilities
10247
+ * to access and interact with external systems when necessary.
10248
+ *
10249
+ * Supported USE types:
10250
+ * - USE BROWSER: Enables the agent to use a web browser tool
10251
+ * - USE SEARCH ENGINE (future): Enables search engine access
10252
+ * - USE FILE SYSTEM (future): Enables file system operations
10253
+ * - USE MCP (future): Enables MCP server connections
10254
+ *
10255
+ * The content following the USE commitment is ignored (similar to NOTE).
10256
+ *
10257
+ * Example usage in agent source:
10258
+ *
10259
+ * ```book
10260
+ * USE BROWSER
10261
+ * USE SEARCH ENGINE
10262
+ * ```
10263
+ *
10264
+ * @private [๐Ÿช”] Maybe export the commitments through some package
10265
+ */
10266
+ class UseCommitmentDefinition extends BaseCommitmentDefinition {
10267
+ constructor() {
10268
+ super('USE');
10269
+ }
10270
+ /**
10271
+ * Short one-line description of USE commitments.
10272
+ */
10273
+ get description() {
10274
+ return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, etc.).';
10275
+ }
10276
+ /**
10277
+ * Icon for this commitment.
10278
+ */
10279
+ get icon() {
10280
+ return '๐Ÿ”ง';
10281
+ }
10282
+ /**
10283
+ * Markdown documentation for USE commitment.
10284
+ */
10285
+ get documentation() {
10286
+ return spaceTrim$1.spaceTrim(`
10287
+ # USE
10288
+
10289
+ Enables the agent to use specific tools or capabilities for interacting with external systems.
10290
+
10291
+ ## Supported USE types
10292
+
10293
+ - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
10294
+ - **USE SEARCH ENGINE** (future) - Enables search engine access
10295
+ - **USE FILE SYSTEM** (future) - Enables file system operations
10296
+ - **USE MCP** (future) - Enables MCP server connections
10297
+
10298
+ ## Key aspects
10299
+
10300
+ - The content following the USE commitment is ignored (similar to NOTE)
10301
+ - Multiple USE commitments can be specified to enable multiple capabilities
10302
+ - The actual tool usage is handled by the agent runtime
10303
+
10304
+ ## Examples
10305
+
10306
+ ### Basic browser usage
10307
+
10308
+ \`\`\`book
10309
+ Research Assistant
10310
+
10311
+ PERSONA You are a helpful research assistant
10312
+ USE BROWSER
10313
+ KNOWLEDGE Can search the web for up-to-date information
10314
+ \`\`\`
10315
+
10316
+ ### Multiple tools
10317
+
10318
+ \`\`\`book
10319
+ Data Analyst
10320
+
10321
+ PERSONA You are a data analyst assistant
10322
+ USE BROWSER
10323
+ USE FILE SYSTEM
10324
+ ACTION Can analyze data from various sources
10325
+ \`\`\`
10326
+ `);
10327
+ }
10328
+ applyToAgentModelRequirements(requirements, content) {
10329
+ // USE commitments don't modify the system message or model requirements directly
10330
+ // They are handled separately in the parsing logic for capability extraction
10331
+ // This method exists for consistency with the CommitmentDefinition interface
10332
+ return requirements;
10333
+ }
10334
+ /**
10335
+ * Extracts the tool type from the USE commitment
10336
+ * This is used by the parsing logic
10337
+ */
10338
+ extractToolType(content) {
10339
+ var _a, _b;
10340
+ const trimmedContent = content.trim();
10341
+ // The tool type is the first word after USE (already stripped)
10342
+ const match = trimmedContent.match(/^(\w+)/);
10343
+ 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;
10344
+ }
10345
+ /**
10346
+ * Checks if this is a known USE type
10347
+ */
10348
+ isKnownUseType(useType) {
10349
+ const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'FILE SYSTEM', 'MCP'];
10350
+ return knownTypes.includes(useType.toUpperCase());
10351
+ }
10352
+ }
10353
+ /**
10354
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10355
+ */
10356
+
10357
+ /**
10358
+ * USE BROWSER commitment definition
10359
+ *
10360
+ * The `USE BROWSER` commitment indicates that the agent should utilize a web browser tool
10361
+ * to access and retrieve up-to-date information from the internet when necessary.
10362
+ *
10363
+ * The content following `USE BROWSER` is ignored (similar to NOTE).
10364
+ *
10365
+ * Example usage in agent source:
10366
+ *
10367
+ * ```book
10368
+ * USE BROWSER
10369
+ * USE BROWSER This will be ignored
10370
+ * ```
10371
+ *
10372
+ * @private [๐Ÿช”] Maybe export the commitments through some package
10373
+ */
10374
+ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
10375
+ constructor() {
10376
+ super('USE BROWSER', ['BROWSER']);
10377
+ }
10378
+ /**
10379
+ * Short one-line description of USE BROWSER.
10380
+ */
10381
+ get description() {
10382
+ return 'Enable the agent to use a web browser tool for accessing internet information.';
10383
+ }
10384
+ /**
10385
+ * Icon for this commitment.
10386
+ */
10387
+ get icon() {
10388
+ return '๐ŸŒ';
10389
+ }
10390
+ /**
10391
+ * Markdown documentation for USE BROWSER commitment.
10392
+ */
10393
+ get documentation() {
10394
+ return spaceTrim$1.spaceTrim(`
10395
+ # USE BROWSER
10396
+
10397
+ Enables the agent to use a web browser tool to access and retrieve up-to-date information from the internet.
10398
+
10399
+ ## Key aspects
10400
+
10401
+ - The content following \`USE BROWSER\` is ignored (similar to NOTE)
10402
+ - The actual browser tool usage is handled by the agent runtime
10403
+ - Allows the agent to fetch current information from websites
10404
+ - Useful for research tasks, fact-checking, and accessing dynamic content
10405
+
10406
+ ## Examples
10407
+
10408
+ \`\`\`book
10409
+ Research Assistant
10410
+
10411
+ PERSONA You are a helpful research assistant specialized in finding current information
10412
+ USE BROWSER
10413
+ RULE Always cite your sources when providing information from the web
10414
+ \`\`\`
10415
+
10416
+ \`\`\`book
10417
+ News Analyst
10418
+
10419
+ PERSONA You are a news analyst who stays up-to-date with current events
10420
+ USE BROWSER
10421
+ STYLE Present news in a balanced and objective manner
10422
+ ACTION Can search for and summarize news articles
10423
+ \`\`\`
10424
+
10425
+ \`\`\`book
10426
+ Company Lawyer
10427
+
10428
+ PERSONA You are a company lawyer providing legal advice
10429
+ USE BROWSER
10430
+ KNOWLEDGE Corporate law and legal procedures
10431
+ RULE Always recommend consulting with a licensed attorney for specific legal matters
10432
+ \`\`\`
10433
+ `);
10434
+ }
10435
+ applyToAgentModelRequirements(requirements, content) {
10436
+ // We simply mark that browser capability is enabled in metadata
10437
+ // Get existing metadata
10438
+ const existingMetadata = requirements.metadata || {};
10439
+ // Get existing tools array or create new one
10440
+ const existingTools = existingMetadata.tools || [];
10441
+ // Add 'browser' to tools if not already present
10442
+ const updatedTools = existingTools.includes('browser') ? existingTools : [...existingTools, 'browser'];
10443
+ // Return requirements with updated metadata
10444
+ return {
10445
+ ...requirements,
10446
+ metadata: {
10447
+ ...existingMetadata,
10448
+ tools: updatedTools,
10449
+ useBrowser: true,
10450
+ },
10451
+ };
10452
+ }
10453
+ }
10454
+ /**
10455
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10456
+ */
10457
+
10458
+ /**
10459
+ * USE MCP commitment definition
10460
+ *
10461
+ * The `USE MCP` commitment allows to specify an MCP server URL which the agent will connect to
10462
+ * for retrieving additional instructions and actions.
10463
+ *
10464
+ * The content following `USE MCP` is the URL of the MCP server.
10465
+ *
10466
+ * Example usage in agent source:
10467
+ *
10468
+ * ```book
10469
+ * USE MCP http://mcp-server-url.com
10470
+ * ```
10471
+ *
10472
+ * @private [๐Ÿช”] Maybe export the commitments through some package
10473
+ */
10474
+ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
10475
+ constructor() {
10476
+ super('USE MCP', ['MCP']);
10477
+ }
10478
+ /**
10479
+ * Short one-line description of USE MCP.
10480
+ */
10481
+ get description() {
10482
+ return 'Connects the agent to an external MCP server for additional capabilities.';
10483
+ }
10484
+ /**
10485
+ * Icon for this commitment.
10486
+ */
10487
+ get icon() {
10488
+ return '๐Ÿ”Œ';
10489
+ }
10490
+ /**
10491
+ * Markdown documentation for USE MCP commitment.
10492
+ */
10493
+ get documentation() {
10494
+ return spaceTrim$1.spaceTrim(`
10495
+ # USE MCP
10496
+
10497
+ Connects the agent to an external Model Context Protocol (MCP) server.
10498
+
10499
+ ## Key aspects
10500
+
10501
+ - The content following \`USE MCP\` must be a valid URL
10502
+ - Multiple MCP servers can be connected by using multiple \`USE MCP\` commitments
10503
+ - The agent will have access to tools and resources provided by the MCP server
10504
+
10505
+ ## Example
10506
+
10507
+ \`\`\`book
10508
+ Company Lawyer
10509
+
10510
+ PERSONA You are a company lawyer.
10511
+ USE MCP http://legal-db.example.com
10512
+ \`\`\`
10513
+ `);
10514
+ }
10515
+ applyToAgentModelRequirements(requirements, content) {
10516
+ const mcpServerUrl = content.trim();
10517
+ if (!mcpServerUrl) {
10518
+ return requirements;
10519
+ }
10520
+ const existingMcpServers = requirements.mcpServers || [];
10521
+ // Avoid duplicates
10522
+ if (existingMcpServers.includes(mcpServerUrl)) {
10523
+ return requirements;
10524
+ }
10525
+ return {
10526
+ ...requirements,
10527
+ mcpServers: [...existingMcpServers, mcpServerUrl],
10528
+ };
10529
+ }
10530
+ }
10531
+ /**
10532
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10533
+ */
10534
+
10535
+ /**
10536
+ * USE SEARCH ENGINE commitment definition
10537
+ *
10538
+ * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
10539
+ * to access and retrieve up-to-date information from the internet when necessary.
10540
+ *
10541
+ * The content following `USE SEARCH ENGINE` is ignored (similar to NOTE).
10542
+ *
10543
+ * Example usage in agent source:
10544
+ *
10545
+ * ```book
10546
+ * USE SEARCH ENGINE
10547
+ * USE SEARCH ENGINE This will be ignored
10548
+ * ```
10549
+ *
10550
+ * @private [๐Ÿช”] Maybe export the commitments through some package
10551
+ */
10552
+ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
10553
+ constructor() {
10554
+ super('USE SEARCH ENGINE', ['SEARCH ENGINE', 'SEARCH']);
10555
+ }
10556
+ /**
10557
+ * Short one-line description of USE SEARCH ENGINE.
10558
+ */
10559
+ get description() {
10560
+ return 'Enable the agent to use a search engine tool for accessing internet information.';
10561
+ }
10562
+ /**
10563
+ * Icon for this commitment.
10564
+ */
10565
+ get icon() {
10566
+ return '๐Ÿ”';
10567
+ }
10568
+ /**
10569
+ * Markdown documentation for USE SEARCH ENGINE commitment.
10570
+ */
10571
+ get documentation() {
10572
+ return spaceTrim$1.spaceTrim(`
10573
+ # USE SEARCH ENGINE
10574
+
10575
+ Enables the agent to use a search engine tool to access and retrieve up-to-date information from the internet.
10576
+
10577
+ ## Key aspects
10578
+
10579
+ - The content following \`USE SEARCH ENGINE\` is ignored (similar to NOTE)
10580
+ - The actual search engine tool usage is handled by the agent runtime
10581
+ - Allows the agent to search for current information from the web
10582
+ - Useful for research tasks, finding facts, and accessing dynamic content
10583
+
10584
+ ## Examples
10585
+
10586
+ \`\`\`book
10587
+ Research Assistant
10588
+
10589
+ PERSONA You are a helpful research assistant specialized in finding current information
10590
+ USE SEARCH ENGINE
10591
+ RULE Always cite your sources when providing information from the web
10592
+ \`\`\`
10593
+
10594
+ \`\`\`book
10595
+ Fact Checker
10596
+
10597
+ PERSONA You are a fact checker
10598
+ USE SEARCH ENGINE
10599
+ ACTION Search for claims and verify them against reliable sources
10600
+ \`\`\`
10601
+ `);
10602
+ }
10603
+ applyToAgentModelRequirements(requirements, content) {
10604
+ // We simply mark that search engine capability is enabled in metadata
10605
+ // Get existing metadata
10606
+ const existingMetadata = requirements.metadata || {};
10607
+ // Get existing tools array or create new one
10608
+ const existingTools = existingMetadata.tools || [];
10609
+ // Add 'search-engine' to tools if not already present
10610
+ const updatedTools = existingTools.includes('search-engine') ? existingTools : [...existingTools, 'search-engine'];
10611
+ // Return requirements with updated metadata
10612
+ return {
10613
+ ...requirements,
10614
+ metadata: {
10615
+ ...existingMetadata,
10616
+ tools: updatedTools,
10617
+ useSearchEngine: true,
10618
+ },
10619
+ };
10620
+ }
10621
+ }
10622
+ /**
10623
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10624
+ */
10625
+
10626
+ /**
10627
+ * Placeholder commitment definition for commitments that are not yet implemented
10628
+ *
10629
+ * This commitment simply adds its content 1:1 into the system message,
10630
+ * preserving the original behavior until proper implementation is added.
10631
+ *
10632
+ * @public exported from `@promptbook/core`
10633
+ */
10634
+ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
10635
+ constructor(type) {
10636
+ super(type);
10637
+ }
10638
+ /**
10639
+ * Short one-line description of a placeholder commitment.
10640
+ */
10641
+ get description() {
10642
+ return 'Placeholder commitment that appends content verbatim to the system message.';
10643
+ }
10644
+ /**
10645
+ * Icon for this commitment.
10646
+ */
10647
+ get icon() {
10648
+ return '๐Ÿšง';
10649
+ }
10650
+ /**
10651
+ * Markdown documentation available at runtime.
10652
+ */
10653
+ get documentation() {
10654
+ return spaceTrim$1.spaceTrim(`
10655
+ # ${this.type}
10656
+
10657
+ This commitment is not yet fully implemented.
10658
+
10659
+ ## Key aspects
10660
+
10661
+ - Content is appended directly to the system message.
10662
+ - No special processing or validation is performed.
10663
+ - Behavior preserved until proper implementation is added.
10664
+
10665
+ ## Status
10666
+
10667
+ - **Status:** Placeholder implementation
10668
+ - **Effect:** Appends content prefixed by commitment type
10669
+ - **Future:** Will be replaced with specialized logic
10670
+
10671
+ ## Examples
10672
+
10673
+ \`\`\`book
10674
+ Example Agent
10675
+
10676
+ PERSONA You are a helpful assistant
10677
+ ${this.type} Your content here
10678
+ RULE Always be helpful
10679
+ \`\`\`
10680
+ `);
10681
+ }
10682
+ applyToAgentModelRequirements(requirements, content) {
10683
+ const trimmedContent = content.trim();
10684
+ if (!trimmedContent) {
10685
+ return requirements;
10686
+ }
10687
+ // Add the commitment content 1:1 to the system message
10688
+ const commitmentLine = `${this.type} ${trimmedContent}`;
10689
+ return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
10690
+ }
10691
+ }
10692
+
10393
10693
  // Import all commitment definition classes
10394
- // Register fully implemented commitments
10395
- registerCommitment(new PersonaCommitmentDefinition('PERSONA'));
10396
- registerCommitment(new PersonaCommitmentDefinition('PERSONAE'));
10397
- registerCommitment(new KnowledgeCommitmentDefinition());
10398
- registerCommitment(new MemoryCommitmentDefinition('MEMORY'));
10399
- registerCommitment(new MemoryCommitmentDefinition('MEMORIES'));
10400
- registerCommitment(new StyleCommitmentDefinition('STYLE'));
10401
- registerCommitment(new StyleCommitmentDefinition('STYLES'));
10402
- registerCommitment(new RuleCommitmentDefinition('RULE'));
10403
- registerCommitment(new RuleCommitmentDefinition('RULES'));
10404
- registerCommitment(new LanguageCommitmentDefinition('LANGUAGE'));
10405
- registerCommitment(new LanguageCommitmentDefinition('LANGUAGES'));
10406
- registerCommitment(new SampleCommitmentDefinition('SAMPLE'));
10407
- registerCommitment(new SampleCommitmentDefinition('EXAMPLE'));
10408
- registerCommitment(new FormatCommitmentDefinition('FORMAT'));
10409
- registerCommitment(new FormatCommitmentDefinition('FORMATS'));
10410
- registerCommitment(new FromCommitmentDefinition('FROM'));
10411
- registerCommitment(new ModelCommitmentDefinition('MODEL'));
10412
- registerCommitment(new ModelCommitmentDefinition('MODELS'));
10413
- registerCommitment(new ActionCommitmentDefinition('ACTION'));
10414
- registerCommitment(new ActionCommitmentDefinition('ACTIONS'));
10415
- registerCommitment(new ComponentCommitmentDefinition());
10416
- registerCommitment(new MetaImageCommitmentDefinition());
10417
- registerCommitment(new MetaColorCommitmentDefinition());
10418
- registerCommitment(new MetaLinkCommitmentDefinition());
10419
- registerCommitment(new MetaCommitmentDefinition());
10420
- registerCommitment(new NoteCommitmentDefinition('NOTE'));
10421
- registerCommitment(new NoteCommitmentDefinition('NOTES'));
10422
- registerCommitment(new NoteCommitmentDefinition('COMMENT'));
10423
- registerCommitment(new NoteCommitmentDefinition('NONCE'));
10424
- registerCommitment(new GoalCommitmentDefinition('GOAL'));
10425
- registerCommitment(new GoalCommitmentDefinition('GOALS'));
10426
- registerCommitment(new ImportantCommitmentDefinition());
10427
- registerCommitment(new InitialMessageCommitmentDefinition());
10428
- registerCommitment(new UserMessageCommitmentDefinition());
10429
- registerCommitment(new AgentMessageCommitmentDefinition());
10430
- registerCommitment(new MessageCommitmentDefinition('MESSAGE'));
10431
- registerCommitment(new MessageCommitmentDefinition('MESSAGES'));
10432
- registerCommitment(new ScenarioCommitmentDefinition('SCENARIO'));
10433
- registerCommitment(new ScenarioCommitmentDefinition('SCENARIOS'));
10434
- registerCommitment(new DeleteCommitmentDefinition('DELETE'));
10435
- registerCommitment(new DeleteCommitmentDefinition('CANCEL'));
10436
- registerCommitment(new DeleteCommitmentDefinition('DISCARD'));
10437
- registerCommitment(new DeleteCommitmentDefinition('REMOVE'));
10438
- registerCommitment(new OpenCommitmentDefinition());
10439
- registerCommitment(new ClosedCommitmentDefinition());
10440
- // Register not yet implemented commitments
10441
- registerCommitment(new NotYetImplementedCommitmentDefinition('EXPECT'));
10442
- registerCommitment(new NotYetImplementedCommitmentDefinition('BEHAVIOUR'));
10443
- registerCommitment(new NotYetImplementedCommitmentDefinition('BEHAVIOURS'));
10444
- registerCommitment(new NotYetImplementedCommitmentDefinition('AVOID'));
10445
- registerCommitment(new NotYetImplementedCommitmentDefinition('AVOIDANCE'));
10446
- registerCommitment(new NotYetImplementedCommitmentDefinition('CONTEXT'));
10694
+ /**
10695
+ * Registry of all available commitment definitions
10696
+ * This array contains instances of all commitment definitions
10697
+ * This is the single source of truth for all commitments in the system
10698
+ *
10699
+ * @private Use functions to access commitments instead of this array directly
10700
+ */
10701
+ const COMMITMENT_REGISTRY = [
10702
+ // Fully implemented commitments
10703
+ new PersonaCommitmentDefinition('PERSONA'),
10704
+ new PersonaCommitmentDefinition('PERSONAE'),
10705
+ new KnowledgeCommitmentDefinition(),
10706
+ new MemoryCommitmentDefinition('MEMORY'),
10707
+ new MemoryCommitmentDefinition('MEMORIES'),
10708
+ new StyleCommitmentDefinition('STYLE'),
10709
+ new StyleCommitmentDefinition('STYLES'),
10710
+ new RuleCommitmentDefinition('RULE'),
10711
+ new RuleCommitmentDefinition('RULES'),
10712
+ new LanguageCommitmentDefinition('LANGUAGE'),
10713
+ new LanguageCommitmentDefinition('LANGUAGES'),
10714
+ new SampleCommitmentDefinition('SAMPLE'),
10715
+ new SampleCommitmentDefinition('EXAMPLE'),
10716
+ new FormatCommitmentDefinition('FORMAT'),
10717
+ new FormatCommitmentDefinition('FORMATS'),
10718
+ new FromCommitmentDefinition('FROM'),
10719
+ new ModelCommitmentDefinition('MODEL'),
10720
+ new ModelCommitmentDefinition('MODELS'),
10721
+ new ActionCommitmentDefinition('ACTION'),
10722
+ new ActionCommitmentDefinition('ACTIONS'),
10723
+ new ComponentCommitmentDefinition(),
10724
+ new MetaImageCommitmentDefinition(),
10725
+ new MetaColorCommitmentDefinition(),
10726
+ new MetaFontCommitmentDefinition(),
10727
+ new MetaLinkCommitmentDefinition(),
10728
+ new MetaCommitmentDefinition(),
10729
+ new NoteCommitmentDefinition('NOTE'),
10730
+ new NoteCommitmentDefinition('NOTES'),
10731
+ new NoteCommitmentDefinition('COMMENT'),
10732
+ new NoteCommitmentDefinition('NONCE'),
10733
+ new GoalCommitmentDefinition('GOAL'),
10734
+ new GoalCommitmentDefinition('GOALS'),
10735
+ new InitialMessageCommitmentDefinition(),
10736
+ new UserMessageCommitmentDefinition(),
10737
+ new AgentMessageCommitmentDefinition(),
10738
+ new MessageCommitmentDefinition('MESSAGE'),
10739
+ new MessageCommitmentDefinition('MESSAGES'),
10740
+ new ScenarioCommitmentDefinition('SCENARIO'),
10741
+ new ScenarioCommitmentDefinition('SCENARIOS'),
10742
+ new DeleteCommitmentDefinition('DELETE'),
10743
+ new DeleteCommitmentDefinition('CANCEL'),
10744
+ new DeleteCommitmentDefinition('DISCARD'),
10745
+ new DeleteCommitmentDefinition('REMOVE'),
10746
+ new OpenCommitmentDefinition(),
10747
+ new ClosedCommitmentDefinition(),
10748
+ new UseBrowserCommitmentDefinition(),
10749
+ new UseSearchEngineCommitmentDefinition(),
10750
+ new UseMcpCommitmentDefinition(),
10751
+ new UseCommitmentDefinition(),
10752
+ // Not yet implemented commitments (using placeholder)
10753
+ new NotYetImplementedCommitmentDefinition('EXPECT'),
10754
+ new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
10755
+ new NotYetImplementedCommitmentDefinition('BEHAVIOURS'),
10756
+ new NotYetImplementedCommitmentDefinition('AVOID'),
10757
+ new NotYetImplementedCommitmentDefinition('AVOIDANCE'),
10758
+ new NotYetImplementedCommitmentDefinition('CONTEXT'),
10759
+ ];
10760
+ /**
10761
+ * Gets a commitment definition by its type
10762
+ * @param type The commitment type to look up
10763
+ * @returns The commitment definition or null if not found
10764
+ *
10765
+ * @public exported from `@promptbook/core`
10766
+ */
10767
+ function getCommitmentDefinition(type) {
10768
+ return COMMITMENT_REGISTRY.find((commitmentDefinition) => commitmentDefinition.type === type) || null;
10769
+ }
10770
+ /**
10771
+ * Gets all available commitment definitions
10772
+ * @returns Array of all commitment definitions
10773
+ *
10774
+ * @public exported from `@promptbook/core`
10775
+ */
10776
+ function getAllCommitmentDefinitions() {
10777
+ return $deepFreeze([...COMMITMENT_REGISTRY]);
10778
+ }
10779
+ /**
10780
+ * Gets all available commitment types
10781
+ * @returns Array of all commitment types
10782
+ *
10783
+ * @public exported from `@promptbook/core`
10784
+ */
10785
+ function getAllCommitmentTypes() {
10786
+ return $deepFreeze(COMMITMENT_REGISTRY.map((commitmentDefinition) => commitmentDefinition.type));
10787
+ }
10788
+ /**
10789
+ * Checks if a commitment type is supported
10790
+ * @param type The commitment type to check
10791
+ * @returns True if the commitment type is supported
10792
+ *
10793
+ * @public exported from `@promptbook/core`
10794
+ */
10795
+ function isCommitmentSupported(type) {
10796
+ return COMMITMENT_REGISTRY.some((commitmentDefinition) => commitmentDefinition.type === type);
10797
+ }
10798
+ /**
10799
+ * Gets all commitment definitions grouped by their aliases
10800
+ *
10801
+ * @returns Array of grouped commitment definitions
10802
+ *
10803
+ * @public exported from `@promptbook/core`
10804
+ */
10805
+ function getGroupedCommitmentDefinitions() {
10806
+ const groupedCommitments = [];
10807
+ for (const commitment of COMMITMENT_REGISTRY) {
10808
+ const lastGroup = groupedCommitments[groupedCommitments.length - 1];
10809
+ // Check if we should group with the previous item
10810
+ let shouldGroup = false;
10811
+ if (lastGroup) {
10812
+ const lastPrimary = lastGroup.primary;
10813
+ // Case 1: Same class constructor (except NotYetImplemented)
10814
+ if (!(commitment instanceof NotYetImplementedCommitmentDefinition) &&
10815
+ commitment.constructor === lastPrimary.constructor) {
10816
+ shouldGroup = true;
10817
+ }
10818
+ // Case 2: NotYetImplemented with prefix matching (e.g. BEHAVIOUR -> BEHAVIOURS)
10819
+ else if (commitment instanceof NotYetImplementedCommitmentDefinition &&
10820
+ lastPrimary instanceof NotYetImplementedCommitmentDefinition &&
10821
+ commitment.type.startsWith(lastPrimary.type)) {
10822
+ shouldGroup = true;
10823
+ }
10824
+ }
10825
+ if (shouldGroup && lastGroup) {
10826
+ lastGroup.aliases.push(commitment.type);
10827
+ }
10828
+ else {
10829
+ groupedCommitments.push({
10830
+ primary: commitment,
10831
+ aliases: [],
10832
+ });
10833
+ }
10834
+ }
10835
+ return $deepFreeze(groupedCommitments);
10836
+ }
10837
+ /**
10838
+ * TODO: [๐Ÿง ] Maybe create through standardized $register
10839
+ * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
10840
+ */
10447
10841
 
10448
10842
  /**
10449
10843
  * Creates an empty/basic agent model requirements object
@@ -10479,6 +10873,11 @@
10479
10873
  * TODO: [๐Ÿค] Deduplicate `AgentModelRequirements` and `ModelRequirements` model requirements
10480
10874
  */
10481
10875
 
10876
+ /**
10877
+ * Regex pattern to match horizontal lines (markdown thematic breaks)
10878
+ * Matches 3 or more hyphens, underscores, or asterisks (with optional spaces between)
10879
+ */
10880
+ const HORIZONTAL_LINE_PATTERN = /^[\s]*[-_*][\s]*[-_*][\s]*[-_*][\s]*[-_*]*[\s]*$/;
10482
10881
  /**
10483
10882
  * Parses agent source using the new commitment system with multiline support
10484
10883
  * This function replaces the hardcoded commitment parsing in the original parseAgentSource
@@ -10541,6 +10940,24 @@
10541
10940
  break;
10542
10941
  }
10543
10942
  }
10943
+ // Check if this is a horizontal line (ends any current commitment)
10944
+ const isHorizontalLine = HORIZONTAL_LINE_PATTERN.test(line);
10945
+ if (isHorizontalLine) {
10946
+ // Save the current commitment if it exists
10947
+ if (currentCommitment) {
10948
+ const fullContent = currentCommitment.contentLines.join('\n');
10949
+ commitments.push({
10950
+ type: currentCommitment.type,
10951
+ content: spaceTrim$1.spaceTrim(fullContent),
10952
+ originalLine: currentCommitment.originalStartLine,
10953
+ lineNumber: currentCommitment.startLineNumber,
10954
+ });
10955
+ currentCommitment = null;
10956
+ }
10957
+ // Add horizontal line to non-commitment lines
10958
+ nonCommitmentLines.push(line);
10959
+ continue;
10960
+ }
10544
10961
  if (!foundNewCommitment) {
10545
10962
  if (currentCommitment) {
10546
10963
  // This line belongs to the current commitment
@@ -11215,17 +11632,6 @@
11215
11632
  return text;
11216
11633
  }
11217
11634
 
11218
- /**
11219
- * Trims string from all 4 sides
11220
- *
11221
- * Note: This is a re-exported function from the `spacetrim` package which is
11222
- * Developed by same author @hejny as this package
11223
- *
11224
- * @public exported from `@promptbook/utils`
11225
- * @see https://github.com/hejny/spacetrim#usage
11226
- */
11227
- const spaceTrim = spaceTrim$1.spaceTrim;
11228
-
11229
11635
  /**
11230
11636
  * Checks if the given value is a valid JavaScript identifier name.
11231
11637
  *
@@ -11313,6 +11719,10 @@
11313
11719
  meta.color = spaceTrim__default["default"](commitment.content);
11314
11720
  continue;
11315
11721
  }
11722
+ if (commitment.type === 'META FONT') {
11723
+ meta.font = spaceTrim__default["default"](commitment.content);
11724
+ continue;
11725
+ }
11316
11726
  if (commitment.type !== 'META') {
11317
11727
  continue;
11318
11728
  }
@@ -18042,18 +18452,26 @@
18042
18452
  modelName: 'assistant',
18043
18453
  // <- [๐Ÿง ] What is the best value here
18044
18454
  });
18455
+ // Build thread messages: include previous thread messages + current user message
18456
+ const threadMessages = [];
18457
+ // TODO: [๐Ÿˆน] Maybe this should not be here but in other place, look at commit 39d705e75e5bcf7a818c3af36bc13e1c8475c30c
18458
+ // Add previous messages from thread (if any)
18459
+ if ('thread' in prompt &&
18460
+ Array.isArray(prompt.thread)) {
18461
+ const previousMessages = prompt.thread.map((msg) => ({
18462
+ role: (msg.role === 'assistant' ? 'assistant' : 'user'),
18463
+ content: msg.content,
18464
+ }));
18465
+ threadMessages.push(...previousMessages);
18466
+ }
18467
+ // Always add the current user message
18468
+ threadMessages.push({ role: 'user', content: rawPromptContent });
18045
18469
  const rawRequest = {
18046
18470
  // TODO: [๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง] ...modelSettings,
18047
18471
  // TODO: [๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง][๐Ÿง ] What about system message for assistants, does it make sense - combination of OpenAI assistants with Promptbook Personas
18048
18472
  assistant_id: this.assistantId,
18049
18473
  thread: {
18050
- messages: 'thread' in prompt &&
18051
- Array.isArray(prompt.thread)
18052
- ? prompt.thread.map((msg) => ({
18053
- role: msg.role === 'assistant' ? 'assistant' : 'user',
18054
- content: msg.content,
18055
- }))
18056
- : [{ role: 'user', content: rawPromptContent }],
18474
+ messages: threadMessages,
18057
18475
  },
18058
18476
  // <- TODO: Add user identification here> user: this.options.user,
18059
18477
  };
@@ -18073,7 +18491,7 @@
18073
18491
  console.info('textDelta', textDelta.value);
18074
18492
  }
18075
18493
  const chunk = {
18076
- content: textDelta.value || '',
18494
+ content: snapshot.value,
18077
18495
  modelName: 'assistant',
18078
18496
  timing: {
18079
18497
  start,
@@ -20308,6 +20726,7 @@
20308
20726
  ${agentName}
20309
20727
 
20310
20728
  META COLOR ${color || PROMPTBOOK_COLOR.toHex()}
20729
+ META FONT Playfair Display, sans-serif
20311
20730
  PERSONA ${block(personaDescription)}
20312
20731
  `));
20313
20732
  return agentSource;
@@ -20502,7 +20921,6 @@
20502
20921
  exports.prettifyPipelineString = prettifyPipelineString;
20503
20922
  exports.promptbookFetch = promptbookFetch;
20504
20923
  exports.promptbookTokenToIdentification = promptbookTokenToIdentification;
20505
- exports.registerCommitment = registerCommitment;
20506
20924
  exports.unpreparePipeline = unpreparePipeline;
20507
20925
  exports.usageToHuman = usageToHuman;
20508
20926
  exports.usageToWorktime = usageToWorktime;