@promptbook/javascript 0.105.0-1 → 0.105.0-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/esm/index.es.js +3958 -157
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  5. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +10 -3
  6. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
  7. package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
  8. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
  10. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
  12. package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +40 -0
  13. package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
  14. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +8 -0
  15. package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +8 -0
  16. package/esm/typings/src/commitments/index.d.ts +11 -2
  17. package/esm/typings/src/config.d.ts +1 -0
  18. package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
  19. package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
  20. package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
  21. package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
  22. package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
  23. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
  24. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
  25. package/esm/typings/src/llm-providers/agent/Agent.d.ts +9 -2
  26. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
  27. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
  28. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  29. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
  30. package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
  31. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
  32. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
  33. package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
  34. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
  35. package/esm/typings/src/version.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/umd/index.umd.js +3958 -157
  38. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-1';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-3';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -947,6 +947,7 @@
947
947
  SEPARATOR: Color.fromHex('#cccccc'),
948
948
  COMMITMENT: Color.fromHex('#DA0F78'),
949
949
  PARAMETER: Color.fromHex('#8e44ad'),
950
+ CODE_BLOCK: Color.fromHex('#7700ffff'),
950
951
  });
951
952
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
952
953
  /**
@@ -1454,6 +1455,93 @@
1454
1455
  * TODO: [🌺] Use some intermediate util splitWords
1455
1456
  */
1456
1457
 
1458
+ /**
1459
+ * Tests if given string is valid file path.
1460
+ *
1461
+ * Note: This does not check if the file exists only if the path is valid
1462
+ * @public exported from `@promptbook/utils`
1463
+ */
1464
+ function isValidFilePath(filename) {
1465
+ if (typeof filename !== 'string') {
1466
+ return false;
1467
+ }
1468
+ if (filename.split('\n').length > 1) {
1469
+ return false;
1470
+ }
1471
+ // Normalize slashes early so heuristics can detect path-like inputs
1472
+ const filenameSlashes = filename.replace(/\\/g, '/');
1473
+ // Reject strings that look like sentences (informational text)
1474
+ // Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
1475
+ // But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
1476
+ if (filename.trim().length > 60 && // long enough to be a sentence
1477
+ /[.!?]/.test(filename) && // contains sentence punctuation
1478
+ filename.split(' ').length > 8 && // has many words
1479
+ !/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
1480
+ ) {
1481
+ return false;
1482
+ }
1483
+ // Absolute Unix path: /hello.txt
1484
+ if (/^(\/)/i.test(filenameSlashes)) {
1485
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
1486
+ return true;
1487
+ }
1488
+ // Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
1489
+ if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
1490
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
1491
+ return true;
1492
+ }
1493
+ // Relative path: ./hello.txt
1494
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1495
+ // console.log(filename, 'Relative path: ./hello.txt');
1496
+ return true;
1497
+ }
1498
+ // Allow paths like foo/hello
1499
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
1500
+ // console.log(filename, 'Allow paths like foo/hello');
1501
+ return true;
1502
+ }
1503
+ // Allow paths like hello.book
1504
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
1505
+ // console.log(filename, 'Allow paths like hello.book');
1506
+ return true;
1507
+ }
1508
+ return false;
1509
+ }
1510
+ /**
1511
+ * TODO: [🍏] Implement for MacOs
1512
+ */
1513
+
1514
+ /**
1515
+ * Tests if given string is valid URL.
1516
+ *
1517
+ * Note: [🔂] This function is idempotent.
1518
+ * Note: Dataurl are considered perfectly valid.
1519
+ * Note: There are few similar functions:
1520
+ * - `isValidUrl` *(this one)* which tests any URL
1521
+ * - `isValidAgentUrl` which tests just agent URL
1522
+ * - `isValidPipelineUrl` which tests just pipeline URL
1523
+ *
1524
+ * @public exported from `@promptbook/utils`
1525
+ */
1526
+ function isValidUrl(url) {
1527
+ if (typeof url !== 'string') {
1528
+ return false;
1529
+ }
1530
+ try {
1531
+ if (url.startsWith('blob:')) {
1532
+ url = url.replace(/^blob:/, '');
1533
+ }
1534
+ const urlObject = new URL(url /* because fail is handled */);
1535
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1536
+ return false;
1537
+ }
1538
+ return true;
1539
+ }
1540
+ catch (error) {
1541
+ return false;
1542
+ }
1543
+ }
1544
+
1457
1545
  const defaultDiacriticsRemovalMap = [
1458
1546
  {
1459
1547
  base: 'A',
@@ -2211,206 +2299,3908 @@
2211
2299
  */
2212
2300
 
2213
2301
  /**
2214
- * Extracts all code blocks from markdown.
2302
+ * Tests if given string is valid agent URL
2215
2303
  *
2216
- * Note: There are multiple similar functions:
2217
- * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
2218
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2219
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2220
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2304
+ * Note: There are few similar functions:
2305
+ * - `isValidUrl` which tests any URL
2306
+ * - `isValidAgentUrl` *(this one)* which tests just agent URL
2307
+ * - `isValidPipelineUrl` which tests just pipeline URL
2221
2308
  *
2222
- * @param markdown any valid markdown
2223
- * @returns code blocks with language and content
2224
- * @throws {ParseError} if block is not closed properly
2225
- * @public exported from `@promptbook/markdown-utils`
2309
+ * @public exported from `@promptbook/utils`
2226
2310
  */
2227
- function extractAllBlocksFromMarkdown(markdown) {
2228
- const codeBlocks = [];
2229
- const lines = markdown.split('\n');
2230
- // Note: [0] Ensure that the last block notated by gt > will be closed
2231
- lines.push('');
2232
- let currentCodeBlock = null;
2233
- for (const line of lines) {
2234
- if (line.startsWith('> ') || line === '>') {
2235
- if (currentCodeBlock === null) {
2236
- currentCodeBlock = { blockNotation: '>', language: null, content: '' };
2237
- } /* not else */
2238
- if (currentCodeBlock.blockNotation === '>') {
2239
- if (currentCodeBlock.content !== '') {
2240
- currentCodeBlock.content += '\n';
2241
- }
2242
- currentCodeBlock.content += line.slice(2);
2243
- }
2244
- }
2245
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
2246
- codeBlocks.push(currentCodeBlock);
2247
- currentCodeBlock = null;
2248
- }
2249
- /* not else */
2250
- if (line.startsWith('```')) {
2251
- const language = line.slice(3).trim() || null;
2252
- if (currentCodeBlock === null) {
2253
- currentCodeBlock = { blockNotation: '```', language, content: '' };
2254
- }
2255
- else {
2256
- if (language !== null) {
2257
- throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
2258
- }
2259
- codeBlocks.push(currentCodeBlock);
2260
- currentCodeBlock = null;
2261
- }
2262
- }
2263
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
2264
- if (currentCodeBlock.content !== '') {
2265
- currentCodeBlock.content += '\n';
2266
- }
2267
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
2268
- }
2311
+ function isValidAgentUrl(url) {
2312
+ if (!isValidUrl(url)) {
2313
+ return false;
2269
2314
  }
2270
- if (currentCodeBlock !== null) {
2271
- throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
2315
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
2316
+ return false;
2272
2317
  }
2273
- return codeBlocks;
2318
+ if (url.includes('#')) {
2319
+ // TODO: [🐠]
2320
+ return false;
2321
+ }
2322
+ /*
2323
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
2324
+ if (isUrlOnPrivateNetwork(url)) {
2325
+ return false;
2326
+ }
2327
+ */
2328
+ return true;
2274
2329
  }
2275
2330
  /**
2276
- * TODO: Maybe name for `blockNotation` instead of '```' and '>'
2331
+ * TODO: [🐠] Maybe more info why the URL is invalid
2277
2332
  */
2278
2333
 
2279
2334
  /**
2280
- * Extracts exactly ONE code block from markdown.
2335
+ * Generates a regex pattern to match a specific commitment
2281
2336
  *
2282
- * - When there are multiple or no code blocks the function throws a `ParseError`
2283
- *
2284
- * Note: There are multiple similar functions:
2285
- * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
2286
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2287
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2288
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2337
+ * Note: It always creates new Regex object
2338
+ * Note: Uses word boundaries to ensure only full words are matched (e.g., "PERSONA" matches but "PERSONALITY" does not)
2289
2339
  *
2290
- * @param markdown any valid markdown
2291
- * @returns code block with language and content
2292
- * @public exported from `@promptbook/markdown-utils`
2293
- * @throws {ParseError} if there is not exactly one code block in the markdown
2340
+ * @private - TODO: [🧠] Maybe should be public?
2294
2341
  */
2295
- function extractOneBlockFromMarkdown(markdown) {
2296
- const codeBlocks = extractAllBlocksFromMarkdown(markdown);
2297
- if (codeBlocks.length !== 1) {
2298
- throw new ParseError(spaceTrim__default["default"]((block) => `
2299
- There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
2300
-
2301
- ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
2302
- `));
2342
+ function createCommitmentRegex(commitment, aliases = [], requiresContent = true) {
2343
+ const allCommitments = [commitment, ...aliases];
2344
+ const patterns = allCommitments.map((commitment) => {
2345
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2346
+ return escapedCommitment.split(/\s+/).join('\\s+');
2347
+ });
2348
+ const keywordPattern = patterns.join('|');
2349
+ if (requiresContent) {
2350
+ return new RegExp(`^\\s*(?<type>${keywordPattern})\\b\\s+(?<contents>.+)$`, 'gim');
2351
+ }
2352
+ else {
2353
+ return new RegExp(`^\\s*(?<type>${keywordPattern})\\b(?:\\s+(?<contents>.+))?$`, 'gim');
2303
2354
  }
2304
- return codeBlocks[0];
2305
2355
  }
2306
- /***
2307
- * TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
2308
- */
2309
-
2310
2356
  /**
2311
- * Extracts code block from markdown.
2357
+ * Generates a regex pattern to match a specific commitment type
2312
2358
  *
2313
- * - When there are multiple or no code blocks the function throws a `ParseError`
2314
- *
2315
- * Note: There are multiple similar function:
2316
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2317
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2318
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2319
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2359
+ * Note: It just matches the type part of the commitment
2360
+ * Note: It always creates new Regex object
2361
+ * Note: Uses word boundaries to ensure only full words are matched (e.g., "PERSONA" matches but "PERSONALITY" does not)
2320
2362
  *
2321
- * @public exported from `@promptbook/markdown-utils`
2322
- * @throws {ParseError} if there is not exactly one code block in the markdown
2363
+ * @private
2323
2364
  */
2324
- function extractBlock(markdown) {
2325
- const { content } = extractOneBlockFromMarkdown(markdown);
2326
- return content;
2365
+ function createCommitmentTypeRegex(commitment, aliases = []) {
2366
+ const allCommitments = [commitment, ...aliases];
2367
+ const patterns = allCommitments.map((commitment) => {
2368
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2369
+ return escapedCommitment.split(/\s+/).join('\\s+');
2370
+ });
2371
+ const keywordPattern = patterns.join('|');
2372
+ const regex = new RegExp(`^\\s*(?<type>${keywordPattern})\\b`, 'gim');
2373
+ return regex;
2327
2374
  }
2328
2375
 
2329
2376
  /**
2330
- * Prettify the html code
2377
+ * Base implementation of CommitmentDefinition that provides common functionality
2378
+ * Most commitments can extend this class and only override the applyToAgentModelRequirements method
2331
2379
  *
2332
- * @param content raw html code
2333
- * @returns formatted html code
2334
- * @private withing the package because of HUGE size of prettier dependency
2335
- * @deprecated Prettier removed from Promptbook due to package size
2380
+ * @private
2336
2381
  */
2337
- function prettifyMarkdown(content) {
2338
- return (content + `\n\n<!-- Note: Prettier removed from Promptbook -->`);
2382
+ class BaseCommitmentDefinition {
2383
+ constructor(type, aliases = []) {
2384
+ this.type = type;
2385
+ this.aliases = aliases;
2386
+ }
2387
+ /**
2388
+ * Whether this commitment requires content.
2389
+ * If true, regex will match only if there is content after the commitment keyword.
2390
+ * If false, regex will match even if there is no content.
2391
+ */
2392
+ get requiresContent() {
2393
+ return true;
2394
+ }
2395
+ /**
2396
+ * Creates a regex pattern to match this commitment in agent source
2397
+ * Uses the existing createCommitmentRegex function as internal helper
2398
+ */
2399
+ createRegex() {
2400
+ return createCommitmentRegex(this.type, this.aliases, this.requiresContent);
2401
+ }
2402
+ /**
2403
+ * Creates a regex pattern to match just the commitment type
2404
+ * Uses the existing createCommitmentTypeRegex function as internal helper
2405
+ */
2406
+ createTypeRegex() {
2407
+ return createCommitmentTypeRegex(this.type, this.aliases);
2408
+ }
2409
+ /**
2410
+ * Helper method to create a new requirements object with updated system message
2411
+ * This is commonly used by many commitments
2412
+ */
2413
+ updateSystemMessage(requirements, messageUpdate) {
2414
+ const newMessage = typeof messageUpdate === 'string' ? messageUpdate : messageUpdate(requirements.systemMessage);
2415
+ return {
2416
+ ...requirements,
2417
+ systemMessage: newMessage,
2418
+ };
2419
+ }
2420
+ /**
2421
+ * Helper method to append content to the system message
2422
+ */
2423
+ appendToSystemMessage(requirements, content, separator = '\n\n') {
2424
+ return this.updateSystemMessage(requirements, (currentMessage) => {
2425
+ if (!currentMessage.trim()) {
2426
+ return content;
2427
+ }
2428
+ return currentMessage + separator + content;
2429
+ });
2430
+ }
2431
+ /**
2432
+ * Helper method to add a comment section to the system message
2433
+ * Comments are lines starting with # that will be removed from the final system message
2434
+ * but can be useful for organizing and structuring the message during processing
2435
+ */
2436
+ addCommentSection(requirements, commentTitle, content, position = 'end') {
2437
+ const commentSection = `# ${commentTitle.toUpperCase()}\n${content}`;
2438
+ if (position === 'beginning') {
2439
+ return this.updateSystemMessage(requirements, (currentMessage) => {
2440
+ if (!currentMessage.trim()) {
2441
+ return commentSection;
2442
+ }
2443
+ return commentSection + '\n\n' + currentMessage;
2444
+ });
2445
+ }
2446
+ else {
2447
+ return this.appendToSystemMessage(requirements, commentSection);
2448
+ }
2449
+ }
2450
+ /**
2451
+ * Gets tool function implementations provided by this commitment
2452
+ *
2453
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
2454
+ */
2455
+ getToolFunctions() {
2456
+ return {};
2457
+ }
2339
2458
  }
2340
2459
 
2341
2460
  /**
2342
- * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
2461
+ * ACTION commitment definition
2343
2462
  *
2344
- * Note: [🔂] This function is idempotent.
2345
- * Note: This is useful for post-processing of the result of the chat LLM model
2346
- * when the model wraps the result in the (markdown) code block.
2463
+ * The ACTION commitment defines specific actions or capabilities that the agent can perform.
2464
+ * This helps define what the agent is capable of doing and how it should approach tasks.
2347
2465
  *
2348
- * @public exported from `@promptbook/markdown-utils`
2349
- */
2350
- function trimCodeBlock(value) {
2351
- value = spaceTrim$1.spaceTrim(value);
2352
- if (!/^```[a-z]*(.*)```$/is.test(value)) {
2353
- return value;
2354
- }
2355
- value = value.replace(/^```[a-z]*/i, '');
2356
- value = value.replace(/```$/i, '');
2357
- value = spaceTrim$1.spaceTrim(value);
2358
- return value;
2359
- }
2360
-
2361
- /**
2362
- * Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
2466
+ * Example usage in agent source:
2363
2467
  *
2364
- * Note: This is useful for post-processing of the result of the completion LLM model
2365
- * if you want to start code block in the prompt but you don't want to end it in the result.
2468
+ * ```book
2469
+ * ACTION Can generate code snippets and explain programming concepts
2470
+ * ACTION Able to analyze data and provide insights
2471
+ * ```
2366
2472
  *
2367
- * @public exported from `@promptbook/markdown-utils`
2473
+ * @private [🪔] Maybe export the commitments through some package
2368
2474
  */
2369
- function trimEndOfCodeBlock(value) {
2370
- value = spaceTrim$1.spaceTrim(value);
2371
- value = value.replace(/```$/g, '');
2372
- value = spaceTrim$1.spaceTrim(value);
2373
- return value;
2374
- }
2475
+ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
2476
+ constructor(type = 'ACTION') {
2477
+ super(type);
2478
+ }
2479
+ /**
2480
+ * Short one-line description of ACTION.
2481
+ */
2482
+ get description() {
2483
+ return 'Define agent capabilities and actions it can perform.';
2484
+ }
2485
+ /**
2486
+ * Icon for this commitment.
2487
+ */
2488
+ get icon() {
2489
+ return '⚡';
2490
+ }
2491
+ /**
2492
+ * Markdown documentation for ACTION commitment.
2493
+ */
2494
+ get documentation() {
2495
+ return spaceTrim$1.spaceTrim(`
2496
+ # ${this.type}
2375
2497
 
2376
- /**
2377
- * @private internal for `preserve`
2378
- */
2379
- const _preserved = [];
2380
- /**
2381
- * Does nothing, but preserves the function in the bundle
2382
- * Compiler is tricked into thinking the function is used
2383
- *
2384
- * @param value any function to preserve
2385
- * @returns nothing
2386
- * @private within the repository
2387
- */
2388
- function $preserve(...value) {
2389
- _preserved.push(...value);
2498
+ Defines specific actions or capabilities that the agent can perform.
2499
+
2500
+ ## Key aspects
2501
+
2502
+ - Both terms work identically and can be used interchangeably.
2503
+ - Each action adds to the agent's capability list.
2504
+ - Actions help users understand what the agent can do.
2505
+
2506
+ ## Examples
2507
+
2508
+ \`\`\`book
2509
+ Code Assistant
2510
+
2511
+ PERSONA You are a programming assistant
2512
+ ACTION Can generate code snippets and explain programming concepts
2513
+ ACTION Able to debug existing code and suggest improvements
2514
+ ACTION Can create unit tests for functions
2515
+ \`\`\`
2516
+
2517
+ \`\`\`book
2518
+ Data Scientist
2519
+
2520
+ PERSONA You are a data analysis expert
2521
+ ACTION Able to analyze data and provide insights
2522
+ ACTION Can create visualizations and charts
2523
+ ACTION Capable of statistical analysis and modeling
2524
+ KNOWLEDGE Data analysis best practices and statistical methods
2525
+ \`\`\`
2526
+ `);
2527
+ }
2528
+ applyToAgentModelRequirements(requirements, content) {
2529
+ const trimmedContent = content.trim();
2530
+ if (!trimmedContent) {
2531
+ return requirements;
2532
+ }
2533
+ // Add action capability to the system message
2534
+ const actionSection = `Capability: ${trimmedContent}`;
2535
+ return this.appendToSystemMessage(requirements, actionSection, '\n\n');
2536
+ }
2390
2537
  }
2391
2538
  /**
2392
2539
  * Note: [💞] Ignore a discrepancy between file name and entity name
2393
2540
  */
2394
2541
 
2395
- // Note: [💎]
2396
2542
  /**
2397
- * ScriptExecutionTools for JavaScript implemented via eval
2543
+ * CLOSED commitment definition
2398
2544
  *
2399
- * Warning: It is used for testing and mocking
2400
- * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
2545
+ * The CLOSED commitment specifies that the agent CANNOT be modified by conversation.
2546
+ * It prevents the agent from learning from interactions and updating its source code.
2401
2547
  *
2402
- * @public exported from `@promptbook/javascript`
2548
+ * Example usage in agent source:
2549
+ *
2550
+ * ```book
2551
+ * CLOSED
2552
+ * ```
2553
+ *
2554
+ * @private [🪔] Maybe export the commitments through some package
2403
2555
  */
2404
- class JavascriptEvalExecutionTools {
2405
- constructor(options) {
2406
- this.options = options || {};
2556
+ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
2557
+ constructor() {
2558
+ super('CLOSED');
2407
2559
  }
2408
2560
  /**
2409
- * Executes a JavaScript
2561
+ * The `CLOSED` commitment is standalone.
2410
2562
  */
2411
- async execute(options) {
2412
- const { scriptLanguage, parameters } = options;
2413
- let { script } = options;
2563
+ get requiresContent() {
2564
+ return false;
2565
+ }
2566
+ /**
2567
+ * Short one-line description of CLOSED.
2568
+ */
2569
+ get description() {
2570
+ return 'Prevent the agent from being modified by conversation.';
2571
+ }
2572
+ /**
2573
+ * Icon for this commitment.
2574
+ */
2575
+ get icon() {
2576
+ return '🔒';
2577
+ }
2578
+ /**
2579
+ * Markdown documentation for CLOSED commitment.
2580
+ */
2581
+ get documentation() {
2582
+ return spaceTrim$1.spaceTrim(`
2583
+ # CLOSED
2584
+
2585
+ Specifies that the agent **cannot** be modified by conversation with it.
2586
+ This means the agent will **not** learn from interactions and its source code will remain static during conversation.
2587
+
2588
+ By default (if not specified), agents are \`OPEN\` to modification.
2589
+
2590
+ > See also [OPEN](/docs/OPEN)
2591
+
2592
+ ## Example
2593
+
2594
+ \`\`\`book
2595
+ CLOSED
2596
+ \`\`\`
2597
+ `);
2598
+ }
2599
+ applyToAgentModelRequirements(requirements, _content) {
2600
+ const updatedMetadata = {
2601
+ ...requirements.metadata,
2602
+ isClosed: true,
2603
+ };
2604
+ return {
2605
+ ...requirements,
2606
+ metadata: updatedMetadata,
2607
+ };
2608
+ }
2609
+ }
2610
+ /**
2611
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2612
+ */
2613
+
2614
+ /**
2615
+ * COMPONENT commitment definition
2616
+ *
2617
+ * The COMPONENT commitment defines a UI component that the agent can render in the chat.
2618
+ *
2619
+ * @private [🪔] Maybe export the commitments through some package
2620
+ */
2621
+ class ComponentCommitmentDefinition extends BaseCommitmentDefinition {
2622
+ constructor() {
2623
+ super('COMPONENT');
2624
+ }
2625
+ /**
2626
+ * Short one-line description of COMPONENT.
2627
+ */
2628
+ get description() {
2629
+ return 'Define a UI component that the agent can render in the chat.';
2630
+ }
2631
+ /**
2632
+ * Icon for this commitment.
2633
+ */
2634
+ get icon() {
2635
+ return '🧩';
2636
+ }
2637
+ /**
2638
+ * Markdown documentation for COMPONENT commitment.
2639
+ */
2640
+ get documentation() {
2641
+ return spaceTrim$1.spaceTrim(`
2642
+ # COMPONENT
2643
+
2644
+ Defines a UI component that the agent can render in the chat.
2645
+
2646
+ ## Key aspects
2647
+
2648
+ - Tells the agent that a specific component is available.
2649
+ - Provides syntax for using the component.
2650
+
2651
+ ## Example
2652
+
2653
+ \`\`\`book
2654
+ COMPONENT Arrow
2655
+ The agent should render an arrow component in the chat UI.
2656
+ Syntax:
2657
+ <Arrow direction="up" color="red" />
2658
+ \`\`\`
2659
+ `);
2660
+ }
2661
+ applyToAgentModelRequirements(requirements, content) {
2662
+ const trimmedContent = content.trim();
2663
+ if (!trimmedContent) {
2664
+ return requirements;
2665
+ }
2666
+ // Add component capability to the system message
2667
+ const componentSection = `Component: ${trimmedContent}`;
2668
+ return this.appendToSystemMessage(requirements, componentSection, '\n\n');
2669
+ }
2670
+ }
2671
+ /**
2672
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2673
+ */
2674
+
2675
+ /**
2676
+ * DELETE commitment definition
2677
+ *
2678
+ * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is used to
2679
+ * remove or disregard certain information or context. This can be useful for
2680
+ * overriding previous commitments or removing unwanted behaviors.
2681
+ *
2682
+ * Example usage in agent source:
2683
+ *
2684
+ * ```book
2685
+ * DELETE Previous formatting requirements
2686
+ * CANCEL All emotional responses
2687
+ * DISCARD Technical jargon explanations
2688
+ * REMOVE Casual conversational style
2689
+ * ```
2690
+ *
2691
+ * @private [🪔] Maybe export the commitments through some package
2692
+ */
2693
+ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
2694
+ constructor(type) {
2695
+ super(type);
2696
+ }
2697
+ /**
2698
+ * Short one-line description of DELETE/CANCEL/DISCARD/REMOVE.
2699
+ */
2700
+ get description() {
2701
+ return 'Remove or **disregard** certain information, context, or previous commitments.';
2702
+ }
2703
+ /**
2704
+ * Icon for this commitment.
2705
+ */
2706
+ get icon() {
2707
+ return '🗑️';
2708
+ }
2709
+ /**
2710
+ * Markdown documentation for DELETE commitment.
2711
+ */
2712
+ get documentation() {
2713
+ return spaceTrim$1.spaceTrim(`
2714
+ # DELETE (CANCEL, DISCARD, REMOVE)
2715
+
2716
+ A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
2717
+
2718
+ ## Aliases
2719
+
2720
+ - \`DELETE\` - Remove or eliminate something
2721
+ - \`CANCEL\` - Cancel or nullify something
2722
+ - \`DISCARD\` - Discard or ignore something
2723
+ - \`REMOVE\` - Remove or take away something
2724
+
2725
+ ## Key aspects
2726
+
2727
+ - Multiple delete commitments can be used to remove different aspects.
2728
+ - Useful for overriding previous commitments in the same agent definition.
2729
+ - Can be used to remove inherited behaviors from base personas.
2730
+ - Helps fine-tune agent behavior by explicitly removing unwanted elements.
2731
+
2732
+ ## Use cases
2733
+
2734
+ - Overriding inherited persona characteristics
2735
+ - Removing conflicting or outdated instructions
2736
+ - Disabling specific response patterns
2737
+ - Canceling previous formatting or style requirements
2738
+
2739
+ ## Examples
2740
+
2741
+ \`\`\`book
2742
+ Serious Business Assistant
2743
+
2744
+ PERSONA You are a friendly and casual assistant who uses emojis
2745
+ DELETE Casual conversational style
2746
+ REMOVE All emoji usage
2747
+ GOAL Provide professional business communications
2748
+ STYLE Use formal language and proper business etiquette
2749
+ \`\`\`
2750
+
2751
+ \`\`\`book
2752
+ Simplified Technical Support
2753
+
2754
+ PERSONA You are a technical support specialist with deep expertise
2755
+ KNOWLEDGE Extensive database of technical specifications
2756
+ DISCARD Technical jargon explanations
2757
+ CANCEL Advanced troubleshooting procedures
2758
+ GOAL Help users with simple, easy-to-follow solutions
2759
+ STYLE Use plain language that anyone can understand
2760
+ \`\`\`
2761
+
2762
+ \`\`\`book
2763
+ Focused Customer Service
2764
+
2765
+ PERSONA You are a customer service agent with broad knowledge
2766
+ ACTION Can help with billing, technical issues, and product information
2767
+ DELETE Billing assistance capabilities
2768
+ REMOVE Technical troubleshooting functions
2769
+ GOAL Focus exclusively on product information and general inquiries
2770
+ \`\`\`
2771
+
2772
+ \`\`\`book
2773
+ Concise Information Provider
2774
+
2775
+ PERSONA You are a helpful assistant who provides detailed explanations
2776
+ STYLE Include examples, analogies, and comprehensive context
2777
+ CANCEL Detailed explanation style
2778
+ DISCARD Examples and analogies
2779
+ GOAL Provide brief, direct answers without unnecessary elaboration
2780
+ STYLE Be concise and to the point
2781
+ \`\`\`
2782
+ `);
2783
+ }
2784
+ applyToAgentModelRequirements(requirements, content) {
2785
+ const trimmedContent = content.trim();
2786
+ if (!trimmedContent) {
2787
+ return requirements;
2788
+ }
2789
+ // Create deletion instruction for system message
2790
+ const deleteSection = `${this.type}: ${trimmedContent}`;
2791
+ // Delete instructions provide important context about what should be removed or ignored
2792
+ return this.appendToSystemMessage(requirements, deleteSection, '\n\n');
2793
+ }
2794
+ }
2795
+ /**
2796
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2797
+ */
2798
+
2799
+ /**
2800
+ * DICTIONARY commitment definition
2801
+ *
2802
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
2803
+ * in its reasoning and responses. This ensures consistent terminology usage.
2804
+ *
2805
+ * Key features:
2806
+ * - Multiple DICTIONARY commitments are automatically merged into one
2807
+ * - Content is placed in a dedicated section of the system message
2808
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
2809
+ * - Agent should use the defined terms correctly in responses
2810
+ *
2811
+ * Example usage in agent source:
2812
+ *
2813
+ * ```book
2814
+ * Legal Assistant
2815
+ *
2816
+ * PERSONA You are a knowledgeable legal assistant
2817
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
2818
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
2819
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
2820
+ * ```
2821
+ *
2822
+ * @private [🪔] Maybe export the commitments through some package
2823
+ */
2824
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
2825
+ constructor() {
2826
+ super('DICTIONARY');
2827
+ }
2828
+ /**
2829
+ * Short one-line description of DICTIONARY.
2830
+ */
2831
+ get description() {
2832
+ return 'Define terms and their meanings for consistent terminology usage.';
2833
+ }
2834
+ /**
2835
+ * Icon for this commitment.
2836
+ */
2837
+ get icon() {
2838
+ return '📚';
2839
+ }
2840
+ /**
2841
+ * Markdown documentation for DICTIONARY commitment.
2842
+ */
2843
+ get documentation() {
2844
+ return spaceTrim$1.spaceTrim(`
2845
+ # DICTIONARY
2846
+
2847
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
2848
+
2849
+ ## Key aspects
2850
+
2851
+ - Multiple \`DICTIONARY\` commitments are merged together.
2852
+ - Terms are defined in the format: "Term is definition"
2853
+ - The agent should use these terms consistently in responses.
2854
+ - Definitions help ensure accurate and consistent terminology.
2855
+
2856
+ ## Examples
2857
+
2858
+ \`\`\`book
2859
+ Legal Assistant
2860
+
2861
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
2862
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
2863
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
2864
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
2865
+ \`\`\`
2866
+
2867
+ \`\`\`book
2868
+ Medical Assistant
2869
+
2870
+ PERSONA You are a helpful medical assistant
2871
+ DICTIONARY Hypertension is persistently high blood pressure
2872
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
2873
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
2874
+ \`\`\`
2875
+ `);
2876
+ }
2877
+ applyToAgentModelRequirements(requirements, content) {
2878
+ var _a;
2879
+ const trimmedContent = content.trim();
2880
+ if (!trimmedContent) {
2881
+ return requirements;
2882
+ }
2883
+ // Get existing dictionary entries from metadata
2884
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
2885
+ // Merge the new dictionary entry with existing entries
2886
+ const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
2887
+ // Store the merged dictionary in metadata for debugging and inspection
2888
+ const updatedMetadata = {
2889
+ ...requirements.metadata,
2890
+ DICTIONARY: mergedDictionary,
2891
+ };
2892
+ // Create the dictionary section for the system message
2893
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
2894
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
2895
+ return {
2896
+ ...this.appendToSystemMessage(requirements, dictionarySection),
2897
+ metadata: updatedMetadata,
2898
+ };
2899
+ }
2900
+ }
2901
+ /**
2902
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2903
+ */
2904
+
2905
+ /**
2906
+ * FORMAT commitment definition
2907
+ *
2908
+ * The FORMAT commitment defines the specific output structure and formatting
2909
+ * that the agent should use in its responses. This includes data formats,
2910
+ * response templates, and structural requirements.
2911
+ *
2912
+ * Example usage in agent source:
2913
+ *
2914
+ * ```book
2915
+ * FORMAT Always respond in JSON format with 'status' and 'data' fields
2916
+ * FORMAT Use markdown formatting for all code blocks
2917
+ * ```
2918
+ *
2919
+ * @private [🪔] Maybe export the commitments through some package
2920
+ */
2921
+ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
2922
+ constructor(type = 'FORMAT') {
2923
+ super(type);
2924
+ }
2925
+ /**
2926
+ * Short one-line description of FORMAT.
2927
+ */
2928
+ get description() {
2929
+ return 'Specify output structure or formatting requirements.';
2930
+ }
2931
+ /**
2932
+ * Icon for this commitment.
2933
+ */
2934
+ get icon() {
2935
+ return '📜';
2936
+ }
2937
+ /**
2938
+ * Markdown documentation for FORMAT commitment.
2939
+ */
2940
+ get documentation() {
2941
+ return spaceTrim$1.spaceTrim(`
2942
+ # ${this.type}
2943
+
2944
+ Defines the specific output structure and formatting for responses (data formats, templates, structure).
2945
+
2946
+ ## Key aspects
2947
+
2948
+ - Both terms work identically and can be used interchangeably.
2949
+ - If they are in conflict, the last one takes precedence.
2950
+ - You can specify both data formats and presentation styles.
2951
+
2952
+ ## Examples
2953
+
2954
+ \`\`\`book
2955
+ Customer Support Bot
2956
+
2957
+ PERSONA You are a helpful customer support agent
2958
+ FORMAT Always respond in JSON format with 'status' and 'data' fields
2959
+ FORMAT Use markdown formatting for all code blocks
2960
+ \`\`\`
2961
+
2962
+ \`\`\`book
2963
+ Data Analyst
2964
+
2965
+ PERSONA You are a data analysis expert
2966
+ FORMAT Present results in structured tables
2967
+ FORMAT Include confidence scores for all predictions
2968
+ STYLE Be concise and precise in explanations
2969
+ \`\`\`
2970
+ `);
2971
+ }
2972
+ applyToAgentModelRequirements(requirements, content) {
2973
+ const trimmedContent = content.trim();
2974
+ if (!trimmedContent) {
2975
+ return requirements;
2976
+ }
2977
+ // Add format instructions to the system message
2978
+ const formatSection = `Output Format: ${trimmedContent}`;
2979
+ return this.appendToSystemMessage(requirements, formatSection, '\n\n');
2980
+ }
2981
+ }
2982
+ /**
2983
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2984
+ */
2985
+
2986
+ /**
2987
+ * FROM commitment definition
2988
+ *
2989
+ * The FROM commitment tells the agent that its `agentSource` is inherited from another agent.
2990
+ *
2991
+ * Example usage in agent source:
2992
+ *
2993
+ * ```book
2994
+ * FROM https://s6.ptbk.io/benjamin-white
2995
+ * ```
2996
+ *
2997
+ * @private [🪔] Maybe export the commitments through some package
2998
+ */
2999
+ class FromCommitmentDefinition extends BaseCommitmentDefinition {
3000
+ constructor(type = 'FROM') {
3001
+ super(type);
3002
+ }
3003
+ /**
3004
+ * Short one-line description of FROM.
3005
+ */
3006
+ get description() {
3007
+ return 'Inherit agent source from another agent.';
3008
+ }
3009
+ /**
3010
+ * Icon for this commitment.
3011
+ */
3012
+ get icon() {
3013
+ return '🧬';
3014
+ }
3015
+ /**
3016
+ * Markdown documentation for FROM commitment.
3017
+ */
3018
+ get documentation() {
3019
+ return spaceTrim$1.spaceTrim(`
3020
+ # ${this.type}
3021
+
3022
+ Inherits agent source from another agent.
3023
+
3024
+ ## Examples
3025
+
3026
+ \`\`\`book
3027
+ My AI Agent
3028
+
3029
+ FROM https://s6.ptbk.io/benjamin-white
3030
+ RULE Speak only in English.
3031
+ \`\`\`
3032
+ `);
3033
+ }
3034
+ applyToAgentModelRequirements(requirements, content) {
3035
+ const trimmedContent = content.trim();
3036
+ if (!trimmedContent) {
3037
+ return {
3038
+ ...requirements,
3039
+ parentAgentUrl: undefined,
3040
+ };
3041
+ }
3042
+ if (trimmedContent.toUpperCase() === 'VOID' ||
3043
+ trimmedContent.toUpperCase() === 'NULL' ||
3044
+ trimmedContent.toUpperCase() === 'NONE' ||
3045
+ trimmedContent.toUpperCase() === 'NIL') {
3046
+ return {
3047
+ ...requirements,
3048
+ parentAgentUrl: null,
3049
+ };
3050
+ }
3051
+ if (!isValidAgentUrl(trimmedContent)) {
3052
+ throw new Error(spaceTrim$1.spaceTrim((block) => `
3053
+ Invalid agent URL in FROM commitment: "${trimmedContent}"
3054
+
3055
+ \`\`\`book
3056
+ ${block(content)}
3057
+ \`\`\`
3058
+
3059
+
3060
+ `));
3061
+ }
3062
+ const parentAgentUrl = trimmedContent;
3063
+ return {
3064
+ ...requirements,
3065
+ parentAgentUrl,
3066
+ };
3067
+ }
3068
+ }
3069
+ /**
3070
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3071
+ */
3072
+
3073
+ /**
3074
+ * GOAL commitment definition
3075
+ *
3076
+ * The GOAL commitment defines the main goal which should be achieved by the AI assistant.
3077
+ * There can be multiple goals. Later goals are more important than earlier goals.
3078
+ *
3079
+ * Example usage in agent source:
3080
+ *
3081
+ * ```book
3082
+ * GOAL Help users understand complex technical concepts
3083
+ * GOAL Provide accurate and up-to-date information
3084
+ * GOAL Always prioritize user safety and ethical guidelines
3085
+ * ```
3086
+ *
3087
+ * @private [🪔] Maybe export the commitments through some package
3088
+ */
3089
+ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
3090
+ constructor(type = 'GOAL') {
3091
+ super(type);
3092
+ }
3093
+ /**
3094
+ * Short one-line description of GOAL.
3095
+ */
3096
+ get description() {
3097
+ return 'Define main **goals** the AI assistant should achieve, with later goals having higher priority.';
3098
+ }
3099
+ /**
3100
+ * Icon for this commitment.
3101
+ */
3102
+ get icon() {
3103
+ return '🎯';
3104
+ }
3105
+ /**
3106
+ * Markdown documentation for GOAL commitment.
3107
+ */
3108
+ get documentation() {
3109
+ return spaceTrim$1.spaceTrim(`
3110
+ # ${this.type}
3111
+
3112
+ 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.
3113
+
3114
+ ## Key aspects
3115
+
3116
+ - Both terms work identically and can be used interchangeably.
3117
+ - Later goals have higher priority and can override earlier goals.
3118
+ - Goals provide clear direction and purpose for the agent's responses.
3119
+ - Goals influence decision-making and response prioritization.
3120
+
3121
+ ## Priority system
3122
+
3123
+ When multiple goals are defined, they are processed in order, with later goals taking precedence over earlier ones when there are conflicts.
3124
+
3125
+ ## Examples
3126
+
3127
+ \`\`\`book
3128
+ Customer Support Agent
3129
+
3130
+ PERSONA You are a helpful customer support representative
3131
+ GOAL Resolve customer issues quickly and efficiently
3132
+ GOAL Maintain high customer satisfaction scores
3133
+ GOAL Always follow company policies and procedures
3134
+ RULE Be polite and professional at all times
3135
+ \`\`\`
3136
+
3137
+ \`\`\`book
3138
+ Educational Assistant
3139
+
3140
+ PERSONA You are an educational assistant specializing in mathematics
3141
+ GOAL Help students understand mathematical concepts clearly
3142
+ GOAL Encourage critical thinking and problem-solving skills
3143
+ GOAL Ensure all explanations are age-appropriate and accessible
3144
+ STYLE Use simple language and provide step-by-step explanations
3145
+ \`\`\`
3146
+
3147
+ \`\`\`book
3148
+ Safety-First Assistant
3149
+
3150
+ PERSONA You are a general-purpose AI assistant
3151
+ GOAL Be helpful and informative in all interactions
3152
+ GOAL Provide accurate and reliable information
3153
+ GOAL Always prioritize user safety and ethical guidelines
3154
+ RULE Never provide harmful or dangerous advice
3155
+ \`\`\`
3156
+ `);
3157
+ }
3158
+ applyToAgentModelRequirements(requirements, content) {
3159
+ const trimmedContent = content.trim();
3160
+ if (!trimmedContent) {
3161
+ return requirements;
3162
+ }
3163
+ // Create goal section for system message
3164
+ const goalSection = `Goal: ${trimmedContent}`;
3165
+ // Goals are important directives, so we add them prominently to the system message
3166
+ return this.appendToSystemMessage(requirements, goalSection, '\n\n');
3167
+ }
3168
+ }
3169
+ /**
3170
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3171
+ */
3172
+
3173
+ /**
3174
+ * IMPORT commitment definition
3175
+ *
3176
+ * The IMPORT commitment tells the agent to import content from another agent at the current location.
3177
+ *
3178
+ * Example usage in agent source:
3179
+ *
3180
+ * ```book
3181
+ * IMPORT https://s6.ptbk.io/benjamin-white
3182
+ * ```
3183
+ *
3184
+ * @private [🪔] Maybe export the commitments through some package
3185
+ */
3186
+ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3187
+ constructor(type = 'IMPORT') {
3188
+ super(type);
3189
+ }
3190
+ /**
3191
+ * Short one-line description of IMPORT.
3192
+ */
3193
+ get description() {
3194
+ return 'Import content from another agent or a generic text file.';
3195
+ }
3196
+ /**
3197
+ * Icon for this commitment.
3198
+ */
3199
+ get icon() {
3200
+ return '📥';
3201
+ }
3202
+ /**
3203
+ * Markdown documentation for IMPORT commitment.
3204
+ */
3205
+ get documentation() {
3206
+ return spaceTrim$1.spaceTrim(`
3207
+ # ${this.type}
3208
+
3209
+ Imports content from another agent or a generic text file at the location of the commitment.
3210
+
3211
+ ## Examples
3212
+
3213
+ \`\`\`book
3214
+ My AI Agent
3215
+
3216
+ IMPORT https://s6.ptbk.io/benjamin-white
3217
+ IMPORT https://example.com/some-text-file.txt
3218
+ IMPORT ./path/to/local-file.json
3219
+ RULE Speak only in English.
3220
+ \`\`\`
3221
+ `);
3222
+ }
3223
+ applyToAgentModelRequirements(requirements, content) {
3224
+ const trimmedContent = content.trim();
3225
+ if (!trimmedContent) {
3226
+ return requirements;
3227
+ }
3228
+ if (isValidAgentUrl(trimmedContent)) {
3229
+ const importedAgentUrl = trimmedContent;
3230
+ return {
3231
+ ...requirements,
3232
+ importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3233
+ };
3234
+ }
3235
+ if (isValidUrl(trimmedContent) || isValidFilePath(trimmedContent)) {
3236
+ return {
3237
+ ...requirements,
3238
+ importedFileUrls: [...(requirements.importedFileUrls || []), trimmedContent],
3239
+ };
3240
+ }
3241
+ throw new Error(spaceTrim$1.spaceTrim((block) => `
3242
+ Invalid agent URL or file path in IMPORT commitment: "${trimmedContent}"
3243
+
3244
+ \`\`\`book
3245
+ ${block(content)}
3246
+ \`\`\`
3247
+ `));
3248
+ }
3249
+ }
3250
+ /**
3251
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3252
+ */
3253
+
3254
+ /**
3255
+ * KNOWLEDGE commitment definition
3256
+ *
3257
+ * The KNOWLEDGE commitment adds specific knowledge, facts, or context to the agent
3258
+ * using RAG (Retrieval-Augmented Generation) approach for external sources.
3259
+ *
3260
+ * Supports both direct text knowledge and external sources like PDFs.
3261
+ *
3262
+ * Example usage in agent source:
3263
+ *
3264
+ * ```book
3265
+ * KNOWLEDGE The company was founded in 2020 and specializes in AI-powered solutions
3266
+ * KNOWLEDGE https://example.com/company-handbook.pdf
3267
+ * KNOWLEDGE https://example.com/product-documentation.pdf
3268
+ * ```
3269
+ *
3270
+ * @private [🪔] Maybe export the commitments through some package
3271
+ */
3272
+ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
3273
+ constructor() {
3274
+ super('KNOWLEDGE');
3275
+ }
3276
+ /**
3277
+ * Short one-line description of KNOWLEDGE.
3278
+ */
3279
+ get description() {
3280
+ return 'Add domain **knowledge** via direct text or external sources (RAG).';
3281
+ }
3282
+ /**
3283
+ * Icon for this commitment.
3284
+ */
3285
+ get icon() {
3286
+ return '🧠';
3287
+ }
3288
+ /**
3289
+ * Markdown documentation for KNOWLEDGE commitment.
3290
+ */
3291
+ get documentation() {
3292
+ return spaceTrim$1.spaceTrim(`
3293
+ # ${this.type}
3294
+
3295
+ Adds specific knowledge, facts, or context to the agent using a RAG (Retrieval-Augmented Generation) approach for external sources.
3296
+
3297
+ ## Key aspects
3298
+
3299
+ - Both terms work identically and can be used interchangeably.
3300
+ - Supports both direct text knowledge and external URLs.
3301
+ - External sources (PDFs, websites) are processed via RAG for context retrieval.
3302
+
3303
+ ## Supported formats
3304
+
3305
+ - Direct text: Immediate knowledge incorporated into agent
3306
+ - URLs: External documents processed for contextual retrieval
3307
+ - Supported file types: PDF, text, markdown, HTML
3308
+
3309
+ ## Examples
3310
+
3311
+ \`\`\`book
3312
+ Customer Support Bot
3313
+
3314
+ PERSONA You are a helpful customer support agent for TechCorp
3315
+ KNOWLEDGE TechCorp was founded in 2020 and specializes in AI-powered solutions
3316
+ KNOWLEDGE https://example.com/company-handbook.pdf
3317
+ KNOWLEDGE https://example.com/product-documentation.pdf
3318
+ RULE Always be polite and professional
3319
+ \`\`\`
3320
+
3321
+ \`\`\`book
3322
+ Research Assistant
3323
+
3324
+ PERSONA You are a knowledgeable research assistant
3325
+ KNOWLEDGE Academic research requires careful citation and verification
3326
+ KNOWLEDGE https://example.com/research-guidelines.pdf
3327
+ ACTION Can help with literature reviews and data analysis
3328
+ STYLE Present information in clear, academic format
3329
+ \`\`\`
3330
+ `);
3331
+ }
3332
+ applyToAgentModelRequirements(requirements, content) {
3333
+ const trimmedContent = content.trim();
3334
+ if (!trimmedContent) {
3335
+ return requirements;
3336
+ }
3337
+ // Check if content is a URL (external knowledge source)
3338
+ if (isValidUrl(trimmedContent)) {
3339
+ // Store the URL for later async processing
3340
+ const updatedRequirements = {
3341
+ ...requirements,
3342
+ knowledgeSources: [
3343
+ ...(requirements.knowledgeSources || []),
3344
+ trimmedContent,
3345
+ ],
3346
+ };
3347
+ // Add placeholder information about knowledge sources to system message
3348
+ const knowledgeInfo = `Knowledge Source URL: ${trimmedContent} (will be processed for retrieval during chat)`;
3349
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
3350
+ }
3351
+ else {
3352
+ // Direct text knowledge - add to system message
3353
+ const knowledgeSection = `Knowledge: ${trimmedContent}`;
3354
+ return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
3355
+ }
3356
+ }
3357
+ }
3358
+ /**
3359
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3360
+ */
3361
+
3362
+ /**
3363
+ * LANGUAGE commitment definition
3364
+ *
3365
+ * The LANGUAGE/LANGUAGES commitment specifies the language(s) the agent should use in its responses.
3366
+ *
3367
+ * Example usage in agent source:
3368
+ *
3369
+ * ```book
3370
+ * LANGUAGE English
3371
+ * LANGUAGE French, English and Czech
3372
+ * ```
3373
+ *
3374
+ * @private [🪔] Maybe export the commitments through some package
3375
+ */
3376
+ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
3377
+ constructor(type = 'LANGUAGE') {
3378
+ super(type);
3379
+ }
3380
+ /**
3381
+ * Short one-line description of LANGUAGE/LANGUAGES.
3382
+ */
3383
+ get description() {
3384
+ return 'Specifies the language(s) the agent should use.';
3385
+ }
3386
+ /**
3387
+ * Icon for this commitment.
3388
+ */
3389
+ get icon() {
3390
+ return '🌐';
3391
+ }
3392
+ /**
3393
+ * Markdown documentation for LANGUAGE/LANGUAGES commitment.
3394
+ */
3395
+ get documentation() {
3396
+ return spaceTrim$1.spaceTrim(`
3397
+ # ${this.type}
3398
+
3399
+ Specifies the language(s) the agent should use in its responses.
3400
+ This is a specialized variation of the RULE commitment focused on language constraints.
3401
+
3402
+ ## Examples
3403
+
3404
+ \`\`\`book
3405
+ Paul Smith & Associés
3406
+
3407
+ PERSONA You are a company lawyer.
3408
+ LANGUAGE French, English and Czech
3409
+ \`\`\`
3410
+
3411
+ \`\`\`book
3412
+ Customer Support
3413
+
3414
+ PERSONA You are a customer support agent.
3415
+ LANGUAGE English
3416
+ \`\`\`
3417
+ `);
3418
+ }
3419
+ applyToAgentModelRequirements(requirements, content) {
3420
+ const trimmedContent = content.trim();
3421
+ if (!trimmedContent) {
3422
+ return requirements;
3423
+ }
3424
+ // Add language rule to the system message
3425
+ const languageSection = `Language: ${trimmedContent}`;
3426
+ return this.appendToSystemMessage(requirements, languageSection, '\n\n');
3427
+ }
3428
+ }
3429
+ /**
3430
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3431
+ */
3432
+
3433
+ /**
3434
+ * MEMORY commitment definition
3435
+ *
3436
+ * The MEMORY commitment is similar to KNOWLEDGE but has a focus on remembering past
3437
+ * interactions and user preferences. It helps the agent maintain context about the
3438
+ * user's history, preferences, and previous conversations.
3439
+ *
3440
+ * Example usage in agent source:
3441
+ *
3442
+ * ```book
3443
+ * MEMORY User prefers detailed technical explanations
3444
+ * MEMORY Previously worked on React projects
3445
+ * MEMORY Timezone: UTC-5 (Eastern Time)
3446
+ * ```
3447
+ *
3448
+ * @private [🪔] Maybe export the commitments through some package
3449
+ */
3450
+ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
3451
+ constructor(type = 'MEMORY') {
3452
+ super(type);
3453
+ }
3454
+ /**
3455
+ * Short one-line description of MEMORY.
3456
+ */
3457
+ get description() {
3458
+ return 'Remember past interactions and user **preferences** for personalized responses.';
3459
+ }
3460
+ /**
3461
+ * Icon for this commitment.
3462
+ */
3463
+ get icon() {
3464
+ return '🧠';
3465
+ }
3466
+ /**
3467
+ * Markdown documentation for MEMORY commitment.
3468
+ */
3469
+ get documentation() {
3470
+ return spaceTrim$1.spaceTrim(`
3471
+ # ${this.type}
3472
+
3473
+ 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.
3474
+
3475
+ ## Key aspects
3476
+
3477
+ - Both terms work identically and can be used interchangeably.
3478
+ - Focuses on user-specific information and interaction history.
3479
+ - Helps personalize responses based on past interactions.
3480
+ - Maintains continuity across conversations.
3481
+
3482
+ ## Differences from KNOWLEDGE
3483
+
3484
+ - \`KNOWLEDGE\` is for domain expertise and factual information
3485
+ - \`MEMORY\` is for user-specific context and preferences
3486
+ - \`MEMORY\` creates more personalized interactions
3487
+ - \`MEMORY\` often includes temporal or preference-based information
3488
+
3489
+ ## Examples
3490
+
3491
+ \`\`\`book
3492
+ Personal Assistant
3493
+
3494
+ PERSONA You are a personal productivity assistant
3495
+ MEMORY User is a software developer working in JavaScript/React
3496
+ MEMORY User prefers morning work sessions and afternoon meetings
3497
+ MEMORY Previously helped with project planning for mobile apps
3498
+ MEMORY User timezone: UTC-8 (Pacific Time)
3499
+ GOAL Help optimize daily productivity and workflow
3500
+ \`\`\`
3501
+
3502
+ \`\`\`book
3503
+ Learning Companion
3504
+
3505
+ PERSONA You are an educational companion for programming students
3506
+ MEMORY Student is learning Python as their first programming language
3507
+ MEMORY Previous topics covered: variables, loops, functions
3508
+ MEMORY Student learns best with practical examples and exercises
3509
+ MEMORY Last session: working on list comprehensions
3510
+ GOAL Provide progressive learning experiences tailored to student's pace
3511
+ \`\`\`
3512
+
3513
+ \`\`\`book
3514
+ Customer Support Agent
3515
+
3516
+ PERSONA You are a customer support representative
3517
+ MEMORY Customer has premium subscription since 2023
3518
+ MEMORY Previous issue: billing question resolved last month
3519
+ MEMORY Customer prefers email communication over phone calls
3520
+ MEMORY Account shows frequent use of advanced features
3521
+ GOAL Provide personalized support based on customer history
3522
+ \`\`\`
3523
+ `);
3524
+ }
3525
+ applyToAgentModelRequirements(requirements, content) {
3526
+ const trimmedContent = content.trim();
3527
+ if (!trimmedContent) {
3528
+ return requirements;
3529
+ }
3530
+ // Create memory section for system message
3531
+ const memorySection = `Memory: ${trimmedContent}`;
3532
+ // Memory information is contextual and should be included in the system message
3533
+ return this.appendToSystemMessage(requirements, memorySection, '\n\n');
3534
+ }
3535
+ }
3536
+ /**
3537
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3538
+ */
3539
+
3540
+ /**
3541
+ * AGENT MESSAGE commitment definition
3542
+ *
3543
+ * The AGENT MESSAGE commitment defines a message from the agent in the conversation history.
3544
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3545
+ *
3546
+ * Example usage in agent source:
3547
+ *
3548
+ * ```book
3549
+ * AGENT MESSAGE What seems to be the issue?
3550
+ * ```
3551
+ *
3552
+ * @private [🪔] Maybe export the commitments through some package
3553
+ */
3554
+ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
3555
+ constructor() {
3556
+ super('AGENT MESSAGE');
3557
+ }
3558
+ /**
3559
+ * Short one-line description of AGENT MESSAGE.
3560
+ */
3561
+ get description() {
3562
+ return 'Defines a **message from the agent** in the conversation history.';
3563
+ }
3564
+ /**
3565
+ * Icon for this commitment.
3566
+ */
3567
+ get icon() {
3568
+ return '🤖';
3569
+ }
3570
+ /**
3571
+ * Markdown documentation for AGENT MESSAGE commitment.
3572
+ */
3573
+ get documentation() {
3574
+ return spaceTrim$1.spaceTrim(`
3575
+ # ${this.type}
3576
+
3577
+ 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.
3578
+
3579
+ ## Key aspects
3580
+
3581
+ - Represents a message sent by the agent.
3582
+ - Used for setting up conversation context.
3583
+ - Can be used in conjunction with USER MESSAGE.
3584
+
3585
+ ## Examples
3586
+
3587
+ \`\`\`book
3588
+ Conversation History
3589
+
3590
+ USER MESSAGE Hello, I have a problem.
3591
+ AGENT MESSAGE What seems to be the issue?
3592
+ USER MESSAGE My computer is not starting.
3593
+ \`\`\`
3594
+ `);
3595
+ }
3596
+ applyToAgentModelRequirements(requirements, content) {
3597
+ // AGENT MESSAGE is for UI display purposes / conversation history construction
3598
+ // and typically doesn't need to be added to the system prompt or model requirements directly.
3599
+ // It is extracted separately for the chat interface.
3600
+ var _a;
3601
+ const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
3602
+ if (pendingUserMessage) {
3603
+ const newSample = { question: pendingUserMessage, answer: content };
3604
+ const newSamples = [...(requirements.samples || []), newSample];
3605
+ const newMetadata = { ...requirements.metadata };
3606
+ delete newMetadata.pendingUserMessage;
3607
+ return {
3608
+ ...requirements,
3609
+ samples: newSamples,
3610
+ metadata: newMetadata,
3611
+ };
3612
+ }
3613
+ return requirements;
3614
+ }
3615
+ }
3616
+
3617
+ /**
3618
+ * INITIAL MESSAGE commitment definition
3619
+ *
3620
+ * The INITIAL MESSAGE commitment defines the first message that the user sees when opening the chat.
3621
+ * It is used to greet the user and set the tone of the conversation.
3622
+ *
3623
+ * Example usage in agent source:
3624
+ *
3625
+ * ```book
3626
+ * INITIAL MESSAGE Hello! I am ready to help you with your tasks.
3627
+ * ```
3628
+ *
3629
+ * @private [🪔] Maybe export the commitments through some package
3630
+ */
3631
+ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
3632
+ constructor() {
3633
+ super('INITIAL MESSAGE');
3634
+ }
3635
+ /**
3636
+ * Short one-line description of INITIAL MESSAGE.
3637
+ */
3638
+ get description() {
3639
+ return 'Defines the **initial message** shown to the user when the chat starts.';
3640
+ }
3641
+ /**
3642
+ * Icon for this commitment.
3643
+ */
3644
+ get icon() {
3645
+ return '👋';
3646
+ }
3647
+ /**
3648
+ * Markdown documentation for INITIAL MESSAGE commitment.
3649
+ */
3650
+ get documentation() {
3651
+ return spaceTrim$1.spaceTrim(`
3652
+ # ${this.type}
3653
+
3654
+ 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).
3655
+
3656
+ ## Key aspects
3657
+
3658
+ - Used to greet the user.
3659
+ - Sets the tone of the conversation.
3660
+ - Displayed immediately when the chat interface loads.
3661
+
3662
+ ## Examples
3663
+
3664
+ \`\`\`book
3665
+ Support Agent
3666
+
3667
+ PERSONA You are a helpful support agent.
3668
+ INITIAL MESSAGE Hi there! How can I assist you today?
3669
+ \`\`\`
3670
+ `);
3671
+ }
3672
+ applyToAgentModelRequirements(requirements, content) {
3673
+ // INITIAL MESSAGE is for UI display purposes and for conversation history construction.
3674
+ const newSample = { question: null, answer: content };
3675
+ const newSamples = [...(requirements.samples || []), newSample];
3676
+ return {
3677
+ ...requirements,
3678
+ samples: newSamples,
3679
+ };
3680
+ }
3681
+ }
3682
+
3683
+ /**
3684
+ * MESSAGE commitment definition
3685
+ *
3686
+ * The MESSAGE commitment contains 1:1 text of the message which AI assistant already
3687
+ * sent during the conversation. Later messages are later in the conversation.
3688
+ * It is similar to EXAMPLE but it is not example, it is the real message which
3689
+ * AI assistant already sent.
3690
+ *
3691
+ * Example usage in agent source:
3692
+ *
3693
+ * ```book
3694
+ * MESSAGE Hello! How can I help you today?
3695
+ * MESSAGE I understand you're looking for information about our services.
3696
+ * MESSAGE Based on your requirements, I'd recommend our premium package.
3697
+ * ```
3698
+ *
3699
+ * @private [🪔] Maybe export the commitments through some package
3700
+ */
3701
+ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
3702
+ constructor(type = 'MESSAGE') {
3703
+ super(type);
3704
+ }
3705
+ /**
3706
+ * Short one-line description of MESSAGE.
3707
+ */
3708
+ get description() {
3709
+ return 'Include actual **messages** the AI assistant has sent during conversation history.';
3710
+ }
3711
+ /**
3712
+ * Icon for this commitment.
3713
+ */
3714
+ get icon() {
3715
+ return '💬';
3716
+ }
3717
+ /**
3718
+ * Markdown documentation for MESSAGE commitment.
3719
+ */
3720
+ get documentation() {
3721
+ return spaceTrim$1.spaceTrim(`
3722
+ # ${this.type}
3723
+
3724
+ 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.
3725
+
3726
+ ## Key aspects
3727
+
3728
+ - Multiple \`MESSAGE\` and \`MESSAGES\` commitments represent the conversation timeline.
3729
+ - Both terms work identically and can be used interchangeably.
3730
+ - Later messages are later in the conversation chronologically.
3731
+ - Contains actual historical messages, not examples or templates.
3732
+ - Helps maintain conversation continuity and context.
3733
+
3734
+ ## Differences from EXAMPLE
3735
+
3736
+ - \`EXAMPLE\` shows hypothetical or template responses
3737
+ - \`MESSAGE\`/\`MESSAGES\` contains actual historical conversation content
3738
+ - \`MESSAGE\`/\`MESSAGES\` preserves the exact conversation flow
3739
+ - \`MESSAGE\`/\`MESSAGES\` helps with context awareness and consistency
3740
+
3741
+ ## Use cases
3742
+
3743
+ - Maintaining conversation history context
3744
+ - Ensuring consistent tone and style across messages
3745
+ - Referencing previous responses in ongoing conversations
3746
+ - Building upon previously established context
3747
+
3748
+ ## Examples
3749
+
3750
+ \`\`\`book
3751
+ Customer Support Continuation
3752
+
3753
+ PERSONA You are a helpful customer support agent
3754
+ MESSAGE Hello! How can I help you today?
3755
+ MESSAGE I understand you're experiencing issues with your account login.
3756
+ MESSAGE I've sent you a password reset link to your email address.
3757
+ MESSAGE Is there anything else I can help you with regarding your account?
3758
+ GOAL Continue providing consistent support based on conversation history
3759
+ \`\`\`
3760
+
3761
+ \`\`\`book
3762
+ Technical Discussion
3763
+
3764
+ PERSONA You are a software development mentor
3765
+ MESSAGE Let's start by reviewing the React component structure you shared.
3766
+ MESSAGE I notice you're using class components - have you considered hooks?
3767
+ MESSAGE Here's how you could refactor that using the useState hook.
3768
+ MESSAGE Great question about performance! Let me explain React's rendering cycle.
3769
+ KNOWLEDGE React hooks were introduced in version 16.8
3770
+ \`\`\`
3771
+
3772
+ \`\`\`book
3773
+ Educational Session
3774
+
3775
+ PERSONA You are a mathematics tutor
3776
+ MESSAGE Today we'll work on solving quadratic equations.
3777
+ MESSAGE Let's start with the basic form: ax² + bx + c = 0
3778
+ MESSAGE Remember, we can use the quadratic formula or factoring.
3779
+ MESSAGE You did great with that first problem! Let's try a more complex one.
3780
+ GOAL Build upon previous explanations for deeper understanding
3781
+ \`\`\`
3782
+ `);
3783
+ }
3784
+ applyToAgentModelRequirements(requirements, content) {
3785
+ const trimmedContent = content.trim();
3786
+ if (!trimmedContent) {
3787
+ return requirements;
3788
+ }
3789
+ // Create message section for system message
3790
+ const messageSection = `Previous Message: ${trimmedContent}`;
3791
+ // Messages represent conversation history and should be included for context
3792
+ return this.appendToSystemMessage(requirements, messageSection, '\n\n');
3793
+ }
3794
+ }
3795
+ /**
3796
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3797
+ */
3798
+
3799
+ /**
3800
+ * USER MESSAGE commitment definition
3801
+ *
3802
+ * The USER MESSAGE commitment defines a message from the user in the conversation history.
3803
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
3804
+ *
3805
+ * Example usage in agent source:
3806
+ *
3807
+ * ```book
3808
+ * USER MESSAGE Hello, I have a problem.
3809
+ * ```
3810
+ *
3811
+ * @private [🪔] Maybe export the commitments through some package
3812
+ */
3813
+ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
3814
+ constructor() {
3815
+ super('USER MESSAGE');
3816
+ }
3817
+ /**
3818
+ * Short one-line description of USER MESSAGE.
3819
+ */
3820
+ get description() {
3821
+ return 'Defines a **message from the user** in the conversation history.';
3822
+ }
3823
+ /**
3824
+ * Icon for this commitment.
3825
+ */
3826
+ get icon() {
3827
+ return '🧑';
3828
+ }
3829
+ /**
3830
+ * Markdown documentation for USER MESSAGE commitment.
3831
+ */
3832
+ get documentation() {
3833
+ return spaceTrim$1.spaceTrim(`
3834
+ # ${this.type}
3835
+
3836
+ 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.
3837
+
3838
+ ## Key aspects
3839
+
3840
+ - Represents a message sent by the user.
3841
+ - Used for setting up conversation context.
3842
+ - Can be used in conjunction with AGENT MESSAGE.
3843
+
3844
+ ## Examples
3845
+
3846
+ \`\`\`book
3847
+ Conversation History
3848
+
3849
+ USER MESSAGE Hello, I have a problem.
3850
+ AGENT MESSAGE What seems to be the issue?
3851
+ USER MESSAGE My computer is not starting.
3852
+ \`\`\`
3853
+ `);
3854
+ }
3855
+ applyToAgentModelRequirements(requirements, content) {
3856
+ return {
3857
+ ...requirements,
3858
+ metadata: {
3859
+ ...requirements.metadata,
3860
+ pendingUserMessage: content,
3861
+ },
3862
+ };
3863
+ }
3864
+ }
3865
+
3866
+ /**
3867
+ * META commitment definition
3868
+ *
3869
+ * The META commitment handles all meta-information about the agent such as:
3870
+ * - META IMAGE: Sets the agent's avatar/profile image URL
3871
+ * - META LINK: Provides profile/source links for the person the agent models
3872
+ * - META TITLE: Sets the agent's display title
3873
+ * - META DESCRIPTION: Sets the agent's description
3874
+ * - META [ANYTHING]: Any other meta information in uppercase format
3875
+ *
3876
+ * These commitments are special because they don't affect the system message,
3877
+ * but are handled separately in the parsing logic for profile display.
3878
+ *
3879
+ * Example usage in agent source:
3880
+ *
3881
+ * ```book
3882
+ * META IMAGE https://example.com/avatar.jpg
3883
+ * META LINK https://twitter.com/username
3884
+ * META TITLE Professional Assistant
3885
+ * META DESCRIPTION An AI assistant specialized in business tasks
3886
+ * META AUTHOR John Doe
3887
+ * META VERSION 1.0
3888
+ * ```
3889
+ *
3890
+ * @private [🪔] Maybe export the commitments through some package
3891
+ */
3892
+ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
3893
+ constructor() {
3894
+ super('META');
3895
+ }
3896
+ /**
3897
+ * Short one-line description of META commitments.
3898
+ */
3899
+ get description() {
3900
+ return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
3901
+ }
3902
+ /**
3903
+ * Icon for this commitment.
3904
+ */
3905
+ get icon() {
3906
+ return 'ℹ️';
3907
+ }
3908
+ /**
3909
+ * Markdown documentation for META commitment.
3910
+ */
3911
+ get documentation() {
3912
+ return spaceTrim$1.spaceTrim(`
3913
+ # META
3914
+
3915
+ Sets meta-information about the agent that is used for display and attribution purposes.
3916
+
3917
+ ## Supported META types
3918
+
3919
+ - **META IMAGE** - Sets the agent's avatar/profile image URL
3920
+ - **META LINK** - Provides profile/source links for the person the agent models
3921
+ - **META TITLE** - Sets the agent's display title
3922
+ - **META DESCRIPTION** - Sets the agent's description
3923
+ - **META [ANYTHING]** - Any other meta information in uppercase format
3924
+
3925
+ ## Key aspects
3926
+
3927
+ - Does not modify the agent's behavior or responses
3928
+ - Used for visual representation and attribution in user interfaces
3929
+ - Multiple META commitments of different types can be used
3930
+ - Multiple META LINK commitments can be used for different social profiles
3931
+ - If multiple META commitments of the same type are specified, the last one takes precedence (except for LINK)
3932
+
3933
+ ## Examples
3934
+
3935
+ ### Basic meta information
3936
+
3937
+ \`\`\`book
3938
+ Professional Assistant
3939
+
3940
+ META IMAGE https://example.com/professional-avatar.jpg
3941
+ META TITLE Senior Business Consultant
3942
+ META DESCRIPTION Specialized in strategic planning and project management
3943
+ META LINK https://linkedin.com/in/professional
3944
+ \`\`\`
3945
+
3946
+ ### Multiple links and custom meta
3947
+
3948
+ \`\`\`book
3949
+ Open Source Developer
3950
+
3951
+ META IMAGE /assets/dev-avatar.png
3952
+ META LINK https://github.com/developer
3953
+ META LINK https://twitter.com/devhandle
3954
+ META AUTHOR Jane Smith
3955
+ META VERSION 2.1
3956
+ META LICENSE MIT
3957
+ \`\`\`
3958
+
3959
+ ### Creative assistant
3960
+
3961
+ \`\`\`book
3962
+ Creative Helper
3963
+
3964
+ META IMAGE https://example.com/creative-bot.jpg
3965
+ META TITLE Creative Writing Assistant
3966
+ META DESCRIPTION Helps with brainstorming, storytelling, and creative projects
3967
+ META INSPIRATION Books, movies, and real-world experiences
3968
+ \`\`\`
3969
+ `);
3970
+ }
3971
+ applyToAgentModelRequirements(requirements, content) {
3972
+ // META commitments don't modify the system message or model requirements
3973
+ // They are handled separately in the parsing logic for meta information extraction
3974
+ // This method exists for consistency with the CommitmentDefinition interface
3975
+ return requirements;
3976
+ }
3977
+ /**
3978
+ * Extracts meta information from the content based on the meta type
3979
+ * This is used by the parsing logic
3980
+ */
3981
+ extractMetaValue(metaType, content) {
3982
+ const trimmedContent = content.trim();
3983
+ return trimmedContent || null;
3984
+ }
3985
+ /**
3986
+ * Validates if the provided content is a valid URL (for IMAGE and LINK types)
3987
+ */
3988
+ isValidUrl(content) {
3989
+ try {
3990
+ new URL(content.trim());
3991
+ return true;
3992
+ }
3993
+ catch (_a) {
3994
+ return false;
3995
+ }
3996
+ }
3997
+ /**
3998
+ * Checks if this is a known meta type
3999
+ */
4000
+ isKnownMetaType(metaType) {
4001
+ const knownTypes = ['IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
4002
+ return knownTypes.includes(metaType.toUpperCase());
4003
+ }
4004
+ }
4005
+ /**
4006
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4007
+ */
4008
+
4009
+ /**
4010
+ * META COLOR commitment definition
4011
+ *
4012
+ * The META COLOR commitment sets the agent's accent color.
4013
+ * This commitment is special because it doesn't affect the system message,
4014
+ * but is handled separately in the parsing logic.
4015
+ *
4016
+ * Example usage in agent source:
4017
+ *
4018
+ * ```book
4019
+ * META COLOR #ff0000
4020
+ * META COLOR #00ff00
4021
+ * ```
4022
+ *
4023
+ * You can also specify multiple colors separated by comma:
4024
+ *
4025
+ * ```book
4026
+ * META COLOR #ff0000, #00ff00, #0000ff
4027
+ * ```
4028
+ *
4029
+ * @private [🪔] Maybe export the commitments through some package
4030
+ */
4031
+ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4032
+ constructor() {
4033
+ super('META COLOR', ['COLOR']);
4034
+ }
4035
+ /**
4036
+ * Short one-line description of META COLOR.
4037
+ */
4038
+ get description() {
4039
+ return "Set the agent's accent color or gradient.";
4040
+ }
4041
+ /**
4042
+ * Icon for this commitment.
4043
+ */
4044
+ get icon() {
4045
+ return '🎨';
4046
+ }
4047
+ /**
4048
+ * Markdown documentation for META COLOR commitment.
4049
+ */
4050
+ get documentation() {
4051
+ return spaceTrim$1.spaceTrim(`
4052
+ # META COLOR
4053
+
4054
+ Sets the agent's accent color or gradient.
4055
+
4056
+ ## Key aspects
4057
+
4058
+ - Does not modify the agent's behavior or responses.
4059
+ - Only one \`META COLOR\` should be used per agent.
4060
+ - If multiple are specified, the last one takes precedence.
4061
+ - Used for visual representation in user interfaces.
4062
+ - Can specify multiple colors separated by comma to create a gradient.
4063
+
4064
+ ## Examples
4065
+
4066
+ \`\`\`book
4067
+ Professional Assistant
4068
+
4069
+ META COLOR #3498db
4070
+ PERSONA You are a professional business assistant
4071
+ \`\`\`
4072
+
4073
+ \`\`\`book
4074
+ Creative Helper
4075
+
4076
+ META COLOR #e74c3c
4077
+ PERSONA You are a creative and inspiring assistant
4078
+ \`\`\`
4079
+
4080
+ \`\`\`book
4081
+ Gradient Agent
4082
+
4083
+ META COLOR #ff0000, #00ff00, #0000ff
4084
+ PERSONA You are a colorful agent
4085
+ \`\`\`
4086
+ `);
4087
+ }
4088
+ applyToAgentModelRequirements(requirements, content) {
4089
+ // META COLOR doesn't modify the system message or model requirements
4090
+ // It's handled separately in the parsing logic for profile color extraction
4091
+ // This method exists for consistency with the CommitmentDefinition interface
4092
+ return requirements;
4093
+ }
4094
+ /**
4095
+ * Extracts the profile color from the content
4096
+ * This is used by the parsing logic
4097
+ */
4098
+ extractProfileColor(content) {
4099
+ const trimmedContent = content.trim();
4100
+ return trimmedContent || null;
4101
+ }
4102
+ }
4103
+ /**
4104
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4105
+ */
4106
+
4107
+ /**
4108
+ * META FONT commitment definition
4109
+ *
4110
+ * The META FONT commitment sets the agent's font.
4111
+ * This commitment is special because it doesn't affect the system message,
4112
+ * but is handled separately in the parsing logic.
4113
+ *
4114
+ * Example usage in agent source:
4115
+ *
4116
+ * ```book
4117
+ * META FONT Poppins, Arial, sans-serif
4118
+ * META FONT Roboto
4119
+ * ```
4120
+ *
4121
+ * @private [🪔] Maybe export the commitments through some package
4122
+ */
4123
+ class MetaFontCommitmentDefinition extends BaseCommitmentDefinition {
4124
+ constructor() {
4125
+ super('META FONT', ['FONT']);
4126
+ }
4127
+ /**
4128
+ * Short one-line description of META FONT.
4129
+ */
4130
+ get description() {
4131
+ return "Set the agent's font.";
4132
+ }
4133
+ /**
4134
+ * Icon for this commitment.
4135
+ */
4136
+ get icon() {
4137
+ return '🔤';
4138
+ }
4139
+ /**
4140
+ * Markdown documentation for META FONT commitment.
4141
+ */
4142
+ get documentation() {
4143
+ return spaceTrim$1.spaceTrim(`
4144
+ # META FONT
4145
+
4146
+ Sets the agent's font.
4147
+
4148
+ ## Key aspects
4149
+
4150
+ - Does not modify the agent's behavior or responses.
4151
+ - Only one \`META FONT\` should be used per agent.
4152
+ - If multiple are specified, the last one takes precedence.
4153
+ - Used for visual representation in user interfaces.
4154
+ - Supports Google Fonts.
4155
+
4156
+ ## Examples
4157
+
4158
+ \`\`\`book
4159
+ Modern Assistant
4160
+
4161
+ META FONT Poppins, Arial, sans-serif
4162
+ PERSONA You are a modern assistant
4163
+ \`\`\`
4164
+
4165
+ \`\`\`book
4166
+ Classic Helper
4167
+
4168
+ META FONT Times New Roman
4169
+ PERSONA You are a classic helper
4170
+ \`\`\`
4171
+ `);
4172
+ }
4173
+ applyToAgentModelRequirements(requirements, content) {
4174
+ // META FONT doesn't modify the system message or model requirements
4175
+ // It's handled separately in the parsing logic
4176
+ // This method exists for consistency with the CommitmentDefinition interface
4177
+ return requirements;
4178
+ }
4179
+ /**
4180
+ * Extracts the font from the content
4181
+ * This is used by the parsing logic
4182
+ */
4183
+ extractProfileFont(content) {
4184
+ const trimmedContent = content.trim();
4185
+ return trimmedContent || null;
4186
+ }
4187
+ }
4188
+ /**
4189
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4190
+ */
4191
+
4192
+ /**
4193
+ * META IMAGE commitment definition
4194
+ *
4195
+ * The META IMAGE commitment sets the agent's avatar/profile image URL.
4196
+ * This commitment is special because it doesn't affect the system message,
4197
+ * but is handled separately in the parsing logic.
4198
+ *
4199
+ * Example usage in agent source:
4200
+ *
4201
+ * ```book
4202
+ * META IMAGE https://example.com/avatar.jpg
4203
+ * META IMAGE /assets/agent-avatar.png
4204
+ * ```
4205
+ *
4206
+ * @private [🪔] Maybe export the commitments through some package
4207
+ */
4208
+ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
4209
+ constructor() {
4210
+ super('META IMAGE', ['IMAGE']);
4211
+ }
4212
+ /**
4213
+ * Short one-line description of META IMAGE.
4214
+ */
4215
+ get description() {
4216
+ return "Set the agent's profile image URL.";
4217
+ }
4218
+ /**
4219
+ * Icon for this commitment.
4220
+ */
4221
+ get icon() {
4222
+ return '🖼️';
4223
+ }
4224
+ /**
4225
+ * Markdown documentation for META IMAGE commitment.
4226
+ */
4227
+ get documentation() {
4228
+ return spaceTrim$1.spaceTrim(`
4229
+ # META IMAGE
4230
+
4231
+ Sets the agent's avatar/profile image URL.
4232
+
4233
+ ## Key aspects
4234
+
4235
+ - Does not modify the agent's behavior or responses.
4236
+ - Only one \`META IMAGE\` should be used per agent.
4237
+ - If multiple are specified, the last one takes precedence.
4238
+ - Used for visual representation in user interfaces.
4239
+
4240
+ ## Examples
4241
+
4242
+ \`\`\`book
4243
+ Professional Assistant
4244
+
4245
+ META IMAGE https://example.com/professional-avatar.jpg
4246
+ PERSONA You are a professional business assistant
4247
+ STYLE Maintain a formal and courteous tone
4248
+ \`\`\`
4249
+
4250
+ \`\`\`book
4251
+ Creative Helper
4252
+
4253
+ META IMAGE /assets/creative-bot-avatar.png
4254
+ PERSONA You are a creative and inspiring assistant
4255
+ STYLE Be enthusiastic and encouraging
4256
+ ACTION Can help with brainstorming and ideation
4257
+ \`\`\`
4258
+ `);
4259
+ }
4260
+ applyToAgentModelRequirements(requirements, content) {
4261
+ // META IMAGE doesn't modify the system message or model requirements
4262
+ // It's handled separately in the parsing logic for profile image extraction
4263
+ // This method exists for consistency with the CommitmentDefinition interface
4264
+ return requirements;
4265
+ }
4266
+ /**
4267
+ * Extracts the profile image URL from the content
4268
+ * This is used by the parsing logic
4269
+ */
4270
+ extractProfileImageUrl(content) {
4271
+ const trimmedContent = content.trim();
4272
+ return trimmedContent || null;
4273
+ }
4274
+ }
4275
+ /**
4276
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4277
+ */
4278
+
4279
+ /**
4280
+ * META LINK commitment definition
4281
+ *
4282
+ * The `META LINK` commitment represents the link to the person from whom the agent is created.
4283
+ * This commitment is special because it doesn't affect the system message,
4284
+ * but is handled separately in the parsing logic for profile display.
4285
+ *
4286
+ * Example usage in agent source:
4287
+ *
4288
+ * ```
4289
+ * META LINK https://twitter.com/username
4290
+ * META LINK https://linkedin.com/in/profile
4291
+ * META LINK https://github.com/username
4292
+ * ```
4293
+ *
4294
+ * Multiple `META LINK` commitments can be used when there are multiple sources:
4295
+ *
4296
+ * ```book
4297
+ * META LINK https://twitter.com/username
4298
+ * META LINK https://linkedin.com/in/profile
4299
+ * ```
4300
+ *
4301
+ * @private [🪔] Maybe export the commitments through some package
4302
+ */
4303
+ class MetaLinkCommitmentDefinition extends BaseCommitmentDefinition {
4304
+ constructor() {
4305
+ super('META LINK');
4306
+ }
4307
+ /**
4308
+ * Short one-line description of META LINK.
4309
+ */
4310
+ get description() {
4311
+ return 'Provide profile/source links for the person the agent models.';
4312
+ }
4313
+ /**
4314
+ * Icon for this commitment.
4315
+ */
4316
+ get icon() {
4317
+ return '🔗';
4318
+ }
4319
+ /**
4320
+ * Markdown documentation for META LINK commitment.
4321
+ */
4322
+ get documentation() {
4323
+ return spaceTrim$1.spaceTrim(`
4324
+ # META LINK
4325
+
4326
+ Represents a profile or source link for the person the agent is modeled after.
4327
+
4328
+ ## Key aspects
4329
+
4330
+ - Does not modify the agent's behavior or responses.
4331
+ - Multiple \`META LINK\` commitments can be used for different social profiles.
4332
+ - Used for attribution and crediting the original person.
4333
+ - Displayed in user interfaces for transparency.
4334
+
4335
+ ## Examples
4336
+
4337
+ \`\`\`book
4338
+ Expert Consultant
4339
+
4340
+ META LINK https://twitter.com/expertname
4341
+ META LINK https://linkedin.com/in/expertprofile
4342
+ PERSONA You are Dr. Smith, a renowned expert in artificial intelligence
4343
+ KNOWLEDGE Extensive background in machine learning and neural networks
4344
+ \`\`\`
4345
+
4346
+ \`\`\`book
4347
+ Open Source Developer
4348
+
4349
+ META LINK https://github.com/developer
4350
+ META LINK https://twitter.com/devhandle
4351
+ PERSONA You are an experienced open source developer
4352
+ ACTION Can help with code reviews and architecture decisions
4353
+ STYLE Be direct and technical in explanations
4354
+ \`\`\`
4355
+ `);
4356
+ }
4357
+ applyToAgentModelRequirements(requirements, content) {
4358
+ // META LINK doesn't modify the system message or model requirements
4359
+ // It's handled separately in the parsing logic for profile link extraction
4360
+ // This method exists for consistency with the CommitmentDefinition interface
4361
+ return requirements;
4362
+ }
4363
+ /**
4364
+ * Extracts the profile link URL from the content
4365
+ * This is used by the parsing logic
4366
+ */
4367
+ extractProfileLinkUrl(content) {
4368
+ const trimmedContent = content.trim();
4369
+ return trimmedContent || null;
4370
+ }
4371
+ /**
4372
+ * Validates if the provided content is a valid URL
4373
+ */
4374
+ isValidUrl(content) {
4375
+ try {
4376
+ new URL(content.trim());
4377
+ return true;
4378
+ }
4379
+ catch (_a) {
4380
+ return false;
4381
+ }
4382
+ }
4383
+ }
4384
+ /**
4385
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4386
+ */
4387
+
4388
+ /**
4389
+ * MODEL commitment definition
4390
+ *
4391
+ * The MODEL commitment specifies which AI model to use and can also set
4392
+ * model-specific parameters like temperature, topP, topK, and maxTokens.
4393
+ *
4394
+ * Supports multiple syntax variations:
4395
+ *
4396
+ * Single-line format:
4397
+ * ```book
4398
+ * MODEL gpt-4
4399
+ * MODEL claude-3-opus temperature=0.3
4400
+ * MODEL gpt-3.5-turbo temperature=0.8 topP=0.9
4401
+ * ```
4402
+ *
4403
+ * Multi-line named parameter format:
4404
+ * ```book
4405
+ * MODEL NAME gpt-4
4406
+ * MODEL TEMPERATURE 0.7
4407
+ * MODEL TOP_P 0.9
4408
+ * MODEL MAX_TOKENS 2048
4409
+ * ```
4410
+ *
4411
+ * @private [🪔] Maybe export the commitments through some package
4412
+ */
4413
+ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
4414
+ constructor(type = 'MODEL') {
4415
+ super(type);
4416
+ }
4417
+ /**
4418
+ * Short one-line description of MODEL.
4419
+ */
4420
+ get description() {
4421
+ return 'Enforce AI model requirements including name and technical parameters.';
4422
+ }
4423
+ /**
4424
+ * Icon for this commitment.
4425
+ */
4426
+ get icon() {
4427
+ return '⚙️';
4428
+ }
4429
+ /**
4430
+ * Markdown documentation for MODEL commitment.
4431
+ */
4432
+ get documentation() {
4433
+ return spaceTrim$1.spaceTrim(`
4434
+ # ${this.type}
4435
+
4436
+ Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
4437
+
4438
+ ## Key aspects
4439
+
4440
+ - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments
4441
+ - Multiple \`MODEL\` commitments can be used to specify different parameters
4442
+ - Both \`MODEL\` and \`MODELS\` terms work identically and can be used interchangeably
4443
+ - Parameters control the randomness, creativity, and technical aspects of model responses
4444
+
4445
+ ## Syntax variations
4446
+
4447
+ ### Single-line format (legacy support)
4448
+ \`\`\`book
4449
+ MODEL gpt-4
4450
+ MODEL claude-3-opus temperature=0.3
4451
+ MODEL gpt-3.5-turbo temperature=0.8 topP=0.9
4452
+ \`\`\`
4453
+
4454
+ ### Multi-line named parameter format (recommended)
4455
+ \`\`\`book
4456
+ MODEL NAME gpt-4
4457
+ MODEL TEMPERATURE 0.7
4458
+ MODEL TOP_P 0.9
4459
+ MODEL MAX_TOKENS 2048
4460
+ \`\`\`
4461
+
4462
+ ## Supported parameters
4463
+
4464
+ - \`NAME\`: The specific model to use (e.g., 'gpt-4', 'claude-3-opus')
4465
+ - \`TEMPERATURE\`: Controls randomness (0.0 = deterministic, 1.0+ = creative)
4466
+ - \`TOP_P\`: Nucleus sampling parameter for controlling diversity
4467
+ - \`TOP_K\`: Top-k sampling parameter for limiting vocabulary
4468
+ - \`MAX_TOKENS\`: Maximum number of tokens the model can generate
4469
+
4470
+ ## Examples
4471
+
4472
+ ### Precise deterministic assistant
4473
+ \`\`\`book
4474
+ Precise Assistant
4475
+
4476
+ PERSONA You are a precise and accurate assistant
4477
+ MODEL NAME gpt-4
4478
+ MODEL TEMPERATURE 0.1
4479
+ MODEL MAX_TOKENS 1024
4480
+ RULE Always provide factual information
4481
+ \`\`\`
4482
+
4483
+ ### Creative writing assistant
4484
+ \`\`\`book
4485
+ Creative Writer
4486
+
4487
+ PERSONA You are a creative writing assistant
4488
+ MODEL NAME claude-3-opus
4489
+ MODEL TEMPERATURE 0.8
4490
+ MODEL TOP_P 0.9
4491
+ MODEL MAX_TOKENS 2048
4492
+ STYLE Be imaginative and expressive
4493
+ ACTION Can help with storytelling and character development
4494
+ \`\`\`
4495
+
4496
+ ### Balanced conversational agent
4497
+ \`\`\`book
4498
+ Balanced Assistant
4499
+
4500
+ PERSONA You are a helpful and balanced assistant
4501
+ MODEL NAME gpt-4
4502
+ MODEL TEMPERATURE 0.7
4503
+ MODEL TOP_P 0.95
4504
+ MODEL TOP_K 40
4505
+ MODEL MAX_TOKENS 1500
4506
+ \`\`\`
4507
+ `);
4508
+ }
4509
+ applyToAgentModelRequirements(requirements, content) {
4510
+ var _a;
4511
+ const trimmedContent = content.trim();
4512
+ if (!trimmedContent) {
4513
+ return requirements;
4514
+ }
4515
+ const parts = trimmedContent.split(/\s+/);
4516
+ const firstPart = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
4517
+ // Check if this is the new named parameter format
4518
+ if (this.isNamedParameter(firstPart)) {
4519
+ return this.parseNamedParameter(requirements, firstPart, parts.slice(1));
4520
+ }
4521
+ else {
4522
+ // Legacy single-line format: "MODEL gpt-4 temperature=0.3 topP=0.9"
4523
+ return this.parseLegacyFormat(requirements, parts);
4524
+ }
4525
+ }
4526
+ /**
4527
+ * Check if the first part is a known named parameter
4528
+ */
4529
+ isNamedParameter(part) {
4530
+ if (!part)
4531
+ return false;
4532
+ const knownParams = ['NAME', 'TEMPERATURE', 'TOP_P', 'TOP_K', 'MAX_TOKENS'];
4533
+ return knownParams.includes(part);
4534
+ }
4535
+ /**
4536
+ * Parse the new named parameter format: "MODEL TEMPERATURE 0.7"
4537
+ */
4538
+ parseNamedParameter(requirements, parameterName, valueParts) {
4539
+ const value = valueParts.join(' ').trim();
4540
+ if (!value) {
4541
+ return requirements;
4542
+ }
4543
+ const result = { ...requirements };
4544
+ switch (parameterName) {
4545
+ case 'NAME':
4546
+ result.modelName = value;
4547
+ break;
4548
+ case 'TEMPERATURE': {
4549
+ const temperature = parseFloat(value);
4550
+ if (!isNaN(temperature)) {
4551
+ result.temperature = temperature;
4552
+ }
4553
+ break;
4554
+ }
4555
+ case 'TOP_P': {
4556
+ const topP = parseFloat(value);
4557
+ if (!isNaN(topP)) {
4558
+ result.topP = topP;
4559
+ }
4560
+ break;
4561
+ }
4562
+ case 'TOP_K': {
4563
+ const topK = parseFloat(value);
4564
+ if (!isNaN(topK)) {
4565
+ result.topK = Math.round(topK);
4566
+ }
4567
+ break;
4568
+ }
4569
+ case 'MAX_TOKENS': {
4570
+ const maxTokens = parseFloat(value);
4571
+ if (!isNaN(maxTokens)) {
4572
+ result.maxTokens = Math.round(maxTokens);
4573
+ }
4574
+ break;
4575
+ }
4576
+ }
4577
+ return result;
4578
+ }
4579
+ /**
4580
+ * Parse the legacy format: "MODEL gpt-4 temperature=0.3 topP=0.9"
4581
+ */
4582
+ parseLegacyFormat(requirements, parts) {
4583
+ const modelName = parts[0];
4584
+ if (!modelName) {
4585
+ return requirements;
4586
+ }
4587
+ // Start with the model name
4588
+ const result = {
4589
+ ...requirements,
4590
+ modelName,
4591
+ };
4592
+ // Parse additional key=value parameters
4593
+ for (let i = 1; i < parts.length; i++) {
4594
+ const param = parts[i];
4595
+ if (param && param.includes('=')) {
4596
+ const [key, value] = param.split('=');
4597
+ if (key && value) {
4598
+ const numValue = parseFloat(value);
4599
+ if (!isNaN(numValue)) {
4600
+ switch (key.toLowerCase()) {
4601
+ case 'temperature':
4602
+ result.temperature = numValue;
4603
+ break;
4604
+ case 'topp':
4605
+ case 'top_p':
4606
+ result.topP = numValue;
4607
+ break;
4608
+ case 'topk':
4609
+ case 'top_k':
4610
+ result.topK = Math.round(numValue);
4611
+ break;
4612
+ case 'max_tokens':
4613
+ case 'maxTokens':
4614
+ result.maxTokens = Math.round(numValue);
4615
+ break;
4616
+ }
4617
+ }
4618
+ }
4619
+ }
4620
+ }
4621
+ return result;
4622
+ }
4623
+ }
4624
+ /**
4625
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4626
+ */
4627
+
4628
+ /**
4629
+ * NOTE commitment definition
4630
+ *
4631
+ * The NOTE commitment is used to add comments to the agent source without making any changes
4632
+ * to the system message or agent model requirements. It serves as a documentation mechanism
4633
+ * for developers to add explanatory comments, reminders, or annotations directly in the agent source.
4634
+ *
4635
+ * Key features:
4636
+ * - Makes no changes to the system message
4637
+ * - Makes no changes to agent model requirements
4638
+ * - Content is preserved in metadata.NOTE for debugging and inspection
4639
+ * - Multiple NOTE commitments are aggregated together
4640
+ * - Comments (# NOTE) are removed from the final system message
4641
+ *
4642
+ * Example usage in agent source:
4643
+ *
4644
+ * ```book
4645
+ * NOTE This agent was designed for customer support scenarios
4646
+ * NOTE Remember to update the knowledge base monthly
4647
+ * NOTE Performance optimized for quick response times
4648
+ * ```
4649
+ *
4650
+ * The above notes will be stored in metadata but won't affect the agent's behavior.
4651
+ *
4652
+ * @private [🪔] Maybe export the commitments through some package
4653
+ */
4654
+ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
4655
+ constructor(type = 'NOTE') {
4656
+ super(type);
4657
+ }
4658
+ /**
4659
+ * Short one-line description of NOTE.
4660
+ */
4661
+ get description() {
4662
+ return 'Add developer-facing notes without changing behavior or output.';
4663
+ }
4664
+ /**
4665
+ * Icon for this commitment.
4666
+ */
4667
+ get icon() {
4668
+ return '📝';
4669
+ }
4670
+ /**
4671
+ * Markdown documentation for NOTE commitment.
4672
+ */
4673
+ get documentation() {
4674
+ return spaceTrim$1.spaceTrim(`
4675
+ # ${this.type}
4676
+
4677
+ Adds comments for documentation without changing agent behavior.
4678
+
4679
+ ## Key aspects
4680
+
4681
+ - Does not modify the agent's behavior or responses.
4682
+ - Multiple \`NOTE\`, \`NOTES\`, \`COMMENT\`, and \`NONCE\` commitments are aggregated for debugging.
4683
+ - All four terms work identically and can be used interchangeably.
4684
+ - Useful for documenting design decisions and reminders.
4685
+ - Content is preserved in metadata for inspection.
4686
+
4687
+ ## Examples
4688
+
4689
+ \`\`\`book
4690
+ Customer Support Bot
4691
+
4692
+ NOTE This agent was designed for customer support scenarios
4693
+ COMMENT Remember to update the knowledge base monthly
4694
+ PERSONA You are a helpful customer support representative
4695
+ KNOWLEDGE Company policies and procedures
4696
+ RULE Always be polite and professional
4697
+ \`\`\`
4698
+
4699
+ \`\`\`book
4700
+ Research Assistant
4701
+
4702
+ NONCE Performance optimized for quick response times
4703
+ NOTE Uses RAG for accessing latest research papers
4704
+ PERSONA You are a knowledgeable research assistant
4705
+ ACTION Can help with literature reviews and citations
4706
+ STYLE Present information in academic format
4707
+ \`\`\`
4708
+ `);
4709
+ }
4710
+ applyToAgentModelRequirements(requirements, content) {
4711
+ // The NOTE commitment makes no changes to the system message or model requirements
4712
+ // It only stores the note content in metadata for documentation purposes
4713
+ const trimmedContent = spaceTrim$1.spaceTrim(content);
4714
+ if (trimmedContent === '') {
4715
+ return requirements;
4716
+ }
4717
+ // Return requirements with updated notes but no changes to system message
4718
+ return {
4719
+ ...requirements,
4720
+ notes: [...(requirements.notes || []), trimmedContent],
4721
+ };
4722
+ }
4723
+ }
4724
+ /**
4725
+ * [💞] Ignore a discrepancy between file name and entity name
4726
+ */
4727
+
4728
+ /**
4729
+ * OPEN commitment definition
4730
+ *
4731
+ * The OPEN commitment specifies that the agent can be modified by conversation.
4732
+ * This is the default behavior.
4733
+ *
4734
+ * Example usage in agent source:
4735
+ *
4736
+ * ```book
4737
+ * OPEN
4738
+ * ```
4739
+ *
4740
+ * @private [🪔] Maybe export the commitments through some package
4741
+ */
4742
+ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
4743
+ constructor() {
4744
+ super('OPEN');
4745
+ }
4746
+ /**
4747
+ * Short one-line description of OPEN.
4748
+ */
4749
+ get description() {
4750
+ return 'Allow the agent to be modified by conversation (default).';
4751
+ }
4752
+ /**
4753
+ * Icon for this commitment.
4754
+ */
4755
+ get icon() {
4756
+ return '🔓';
4757
+ }
4758
+ /**
4759
+ * Markdown documentation for OPEN commitment.
4760
+ */
4761
+ get documentation() {
4762
+ return spaceTrim$1.spaceTrim(`
4763
+ # OPEN
4764
+
4765
+ Specifies that the agent can be modified by conversation with it.
4766
+ This means the agent will learn from interactions and update its source code.
4767
+
4768
+ This is the default behavior if neither \`OPEN\` nor \`CLOSED\` is specified.
4769
+
4770
+ > See also [CLOSED](/docs/CLOSED)
4771
+
4772
+ ## Example
4773
+
4774
+ \`\`\`book
4775
+ OPEN
4776
+ \`\`\`
4777
+ `);
4778
+ }
4779
+ applyToAgentModelRequirements(requirements, _content) {
4780
+ // Since OPEN is default, we can just ensure isClosed is false
4781
+ // But to be explicit we can set it
4782
+ const updatedMetadata = {
4783
+ ...requirements.metadata,
4784
+ isClosed: false,
4785
+ };
4786
+ return {
4787
+ ...requirements,
4788
+ metadata: updatedMetadata,
4789
+ };
4790
+ }
4791
+ }
4792
+ /**
4793
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4794
+ */
4795
+
4796
+ /**
4797
+ * PERSONA commitment definition
4798
+ *
4799
+ * The PERSONA commitment modifies the agent's personality and character in the system message.
4800
+ * It defines who the agent is, their background, expertise, and personality traits.
4801
+ *
4802
+ * Key features:
4803
+ * - Multiple PERSONA commitments are automatically merged into one
4804
+ * - Content is placed at the beginning of the system message
4805
+ * - Original content with comments is preserved in metadata.PERSONA
4806
+ * - Comments (# PERSONA) are removed from the final system message
4807
+ *
4808
+ * Example usage in agent source:
4809
+ *
4810
+ * ```book
4811
+ * PERSONA You are a helpful programming assistant with expertise in TypeScript and React
4812
+ * PERSONA You have deep knowledge of modern web development practices
4813
+ * ```
4814
+ *
4815
+ * The above will be merged into a single persona section at the beginning of the system message.
4816
+ *
4817
+ * @private [🪔] Maybe export the commitments through some package
4818
+ */
4819
+ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
4820
+ constructor(type = 'PERSONA') {
4821
+ super(type);
4822
+ }
4823
+ /**
4824
+ * Short one-line description of PERSONA.
4825
+ */
4826
+ get description() {
4827
+ return 'Define who the agent is: background, expertise, and personality.';
4828
+ }
4829
+ /**
4830
+ * Icon for this commitment.
4831
+ */
4832
+ get icon() {
4833
+ return '👤';
4834
+ }
4835
+ /**
4836
+ * Markdown documentation for PERSONA commitment.
4837
+ */
4838
+ get documentation() {
4839
+ return spaceTrim$1.spaceTrim(`
4840
+ # ${this.type}
4841
+
4842
+ Defines who the agent is, their background, expertise, and personality traits.
4843
+
4844
+ ## Key aspects
4845
+
4846
+ - Multiple \`PERSONA\` and \`PERSONAE\` commitments are merged together.
4847
+ - Both terms work identically and can be used interchangeably.
4848
+ - If they are in conflict, the last one takes precedence.
4849
+ - You can write persona content in multiple lines.
4850
+
4851
+ ## Examples
4852
+
4853
+ \`\`\`book
4854
+ Programming Assistant
4855
+
4856
+ PERSONA You are a helpful programming assistant with expertise in TypeScript and React
4857
+ PERSONA You have deep knowledge of modern web development practices
4858
+ \`\`\`
4859
+ `);
4860
+ }
4861
+ applyToAgentModelRequirements(requirements, content) {
4862
+ var _a, _b;
4863
+ // The PERSONA commitment aggregates all persona content and places it at the beginning
4864
+ const trimmedContent = content.trim();
4865
+ if (!trimmedContent) {
4866
+ return requirements;
4867
+ }
4868
+ // Get existing persona content from metadata
4869
+ const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
4870
+ // Merge the new content with existing persona content
4871
+ // When multiple PERSONA commitments exist, they are merged into one
4872
+ const mergedPersonaContent = existingPersonaContent
4873
+ ? `${existingPersonaContent}\n${trimmedContent}`
4874
+ : trimmedContent;
4875
+ // Store the merged persona content in metadata for debugging and inspection
4876
+ const updatedMetadata = {
4877
+ ...requirements.metadata,
4878
+ PERSONA: mergedPersonaContent,
4879
+ };
4880
+ // Get the agent name from metadata (which should contain the first line of agent source)
4881
+ // If not available, extract from current system message as fallback
4882
+ let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
4883
+ if (!agentName) {
4884
+ // Fallback: extract from current system message
4885
+ const currentMessage = requirements.systemMessage.trim();
4886
+ const basicFormatMatch = currentMessage.match(/^You are (.+)$/);
4887
+ if (basicFormatMatch && basicFormatMatch[1]) {
4888
+ agentName = basicFormatMatch[1];
4889
+ }
4890
+ else {
4891
+ agentName = 'AI Agent'; // Final fallback
4892
+ }
4893
+ }
4894
+ // Remove any existing persona content from the system message
4895
+ // (this handles the case where we're processing multiple PERSONA commitments)
4896
+ const currentMessage = requirements.systemMessage.trim();
4897
+ let cleanedMessage = currentMessage;
4898
+ // Check if current message starts with persona content or is just the basic format
4899
+ const basicFormatRegex = /^You are .+$/;
4900
+ const isBasicFormat = basicFormatRegex.test(currentMessage) && !currentMessage.includes('\n');
4901
+ if (isBasicFormat) {
4902
+ // Replace the basic format entirely
4903
+ cleanedMessage = '';
4904
+ }
4905
+ else if (currentMessage.startsWith('# PERSONA')) {
4906
+ // Remove existing persona section by finding where it ends
4907
+ const lines = currentMessage.split('\n');
4908
+ let personaEndIndex = lines.length;
4909
+ // Find the end of the PERSONA section (next comment or end of message)
4910
+ for (let i = 1; i < lines.length; i++) {
4911
+ const line = lines[i].trim();
4912
+ if (line.startsWith('#') && !line.startsWith('# PERSONA')) {
4913
+ personaEndIndex = i;
4914
+ break;
4915
+ }
4916
+ }
4917
+ // Keep everything after the PERSONA section
4918
+ cleanedMessage = lines.slice(personaEndIndex).join('\n').trim();
4919
+ }
4920
+ // TODO: [🕛] There should be `agentFullname` not `agentName`
4921
+ // Create new system message with persona at the beginning
4922
+ // Format: "You are {agentName}\n{personaContent}"
4923
+ // The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
4924
+ const personaSection = `# PERSONA\nYou are ${agentName}\n${mergedPersonaContent}`; // <- TODO: Use spaceTrim
4925
+ const newSystemMessage = cleanedMessage ? `${personaSection}\n\n${cleanedMessage}` : personaSection;
4926
+ return {
4927
+ ...requirements,
4928
+ systemMessage: newSystemMessage,
4929
+ metadata: updatedMetadata,
4930
+ };
4931
+ }
4932
+ }
4933
+ /**
4934
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4935
+ */
4936
+
4937
+ /**
4938
+ * RULE commitment definition
4939
+ *
4940
+ * The RULE/RULES commitment adds behavioral constraints and guidelines that the agent must follow.
4941
+ * These are specific instructions about what the agent should or shouldn't do.
4942
+ *
4943
+ * Example usage in agent source:
4944
+ *
4945
+ * ```book
4946
+ * RULE Always ask for clarification if the user's request is ambiguous
4947
+ * RULES Never provide medical advice, always refer to healthcare professionals
4948
+ * ```
4949
+ *
4950
+ * @private [🪔] Maybe export the commitments through some package
4951
+ */
4952
+ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
4953
+ constructor(type = 'RULE') {
4954
+ super(type);
4955
+ }
4956
+ /**
4957
+ * Short one-line description of RULE/RULES.
4958
+ */
4959
+ get description() {
4960
+ return 'Add behavioral rules the agent must follow.';
4961
+ }
4962
+ /**
4963
+ * Icon for this commitment.
4964
+ */
4965
+ get icon() {
4966
+ return '⚖️';
4967
+ }
4968
+ /**
4969
+ * Markdown documentation for RULE/RULES commitment.
4970
+ */
4971
+ get documentation() {
4972
+ return spaceTrim$1.spaceTrim(`
4973
+ # ${this.type}
4974
+
4975
+ Adds behavioral constraints and guidelines that the agent must follow.
4976
+
4977
+ ## Key aspects
4978
+
4979
+ - All rules are treated equally regardless of singular/plural form.
4980
+ - Rules define what the agent must or must not do.
4981
+
4982
+ ## Examples
4983
+
4984
+ \`\`\`book
4985
+ Customer Support Agent
4986
+
4987
+ PERSONA You are a helpful customer support representative
4988
+ RULE Always ask for clarification if the user's request is ambiguous
4989
+ RULE Be polite and professional in all interactions
4990
+ RULES Never provide medical or legal advice
4991
+ STYLE Maintain a friendly and helpful tone
4992
+ \`\`\`
4993
+
4994
+ \`\`\`book
4995
+ Educational Tutor
4996
+
4997
+ PERSONA You are a patient and knowledgeable tutor
4998
+ RULE Break down complex concepts into simple steps
4999
+ RULE Always encourage students and celebrate their progress
5000
+ RULE If you don't know something, admit it and suggest resources
5001
+ SAMPLE When explaining math: "Let's work through this step by step..."
5002
+ \`\`\`
5003
+ `);
5004
+ }
5005
+ applyToAgentModelRequirements(requirements, content) {
5006
+ const trimmedContent = content.trim();
5007
+ if (!trimmedContent) {
5008
+ return requirements;
5009
+ }
5010
+ // Add rule to the system message
5011
+ const ruleSection = `Rule: ${trimmedContent}`;
5012
+ return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
5013
+ }
5014
+ }
5015
+ /**
5016
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5017
+ */
5018
+
5019
+ /**
5020
+ * SAMPLE commitment definition
5021
+ *
5022
+ * The SAMPLE/EXAMPLE commitment provides examples of how the agent should respond
5023
+ * or behave in certain situations. These examples help guide the agent's responses.
5024
+ *
5025
+ * Example usage in agent source:
5026
+ *
5027
+ * ```book
5028
+ * SAMPLE When asked about pricing, respond: "Our basic plan starts at $10/month..."
5029
+ * EXAMPLE For code questions, always include working code snippets
5030
+ * ```
5031
+ *
5032
+ * @private [🪔] Maybe export the commitments through some package
5033
+ */
5034
+ class SampleCommitmentDefinition extends BaseCommitmentDefinition {
5035
+ constructor(type = 'SAMPLE') {
5036
+ super(type);
5037
+ }
5038
+ /**
5039
+ * Short one-line description of SAMPLE/EXAMPLE.
5040
+ */
5041
+ get description() {
5042
+ return 'Provide example responses to guide behavior.';
5043
+ }
5044
+ /**
5045
+ * Icon for this commitment.
5046
+ */
5047
+ get icon() {
5048
+ return '🔍';
5049
+ }
5050
+ /**
5051
+ * Markdown documentation for SAMPLE/EXAMPLE commitment.
5052
+ */
5053
+ get documentation() {
5054
+ return spaceTrim$1.spaceTrim(`
5055
+ # ${this.type}
5056
+
5057
+ Provides examples of how the agent should respond or behave in certain situations.
5058
+
5059
+ ## Key aspects
5060
+
5061
+ - Both terms work identically and can be used interchangeably.
5062
+ - Examples help guide the agent's response patterns and style.
5063
+
5064
+ ## Examples
5065
+
5066
+ \`\`\`book
5067
+ Sales Assistant
5068
+
5069
+ PERSONA You are a knowledgeable sales representative
5070
+ SAMPLE When asked about pricing, respond: "Our basic plan starts at $10/month..."
5071
+ SAMPLE For feature comparisons, create a clear comparison table
5072
+ RULE Always be honest about limitations
5073
+ \`\`\`
5074
+
5075
+ \`\`\`book
5076
+ Code Reviewer
5077
+
5078
+ PERSONA You are an experienced software engineer
5079
+ EXAMPLE For code questions, always include working code snippets
5080
+ EXAMPLE When suggesting improvements: "Here's a more efficient approach..."
5081
+ RULE Explain the reasoning behind your suggestions
5082
+ STYLE Be constructive and encouraging in feedback
5083
+ \`\`\`
5084
+ `);
5085
+ }
5086
+ applyToAgentModelRequirements(requirements, content) {
5087
+ const trimmedContent = content.trim();
5088
+ if (!trimmedContent) {
5089
+ return requirements;
5090
+ }
5091
+ // Add example to the system message
5092
+ const exampleSection = `Example: ${trimmedContent}`;
5093
+ return this.appendToSystemMessage(requirements, exampleSection, '\n\n');
5094
+ }
5095
+ }
5096
+ /**
5097
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5098
+ */
5099
+
5100
+ /**
5101
+ * SCENARIO commitment definition
5102
+ *
5103
+ * The SCENARIO commitment defines a specific situation or context in which the AI
5104
+ * assistant should operate. It helps to set the scene for the AI's responses.
5105
+ * Later scenarios are more important than earlier scenarios.
5106
+ *
5107
+ * Example usage in agent source:
5108
+ *
5109
+ * ```book
5110
+ * SCENARIO You are in a customer service call center during peak hours
5111
+ * SCENARIO The customer is frustrated and has been on hold for 20 minutes
5112
+ * SCENARIO This is the customer's third call about the same issue
5113
+ * ```
5114
+ *
5115
+ * @private [🪔] Maybe export the commitments through some package
5116
+ */
5117
+ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
5118
+ constructor(type = 'SCENARIO') {
5119
+ super(type);
5120
+ }
5121
+ /**
5122
+ * Short one-line description of SCENARIO.
5123
+ */
5124
+ get description() {
5125
+ return 'Define specific **situations** or contexts for AI responses, with later scenarios having higher priority.';
5126
+ }
5127
+ /**
5128
+ * Icon for this commitment.
5129
+ */
5130
+ get icon() {
5131
+ return '🎭';
5132
+ }
5133
+ /**
5134
+ * Markdown documentation for SCENARIO commitment.
5135
+ */
5136
+ get documentation() {
5137
+ return spaceTrim$1.spaceTrim(`
5138
+ # ${this.type}
5139
+
5140
+ 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.
5141
+
5142
+ ## Key aspects
5143
+
5144
+ - Multiple \`SCENARIO\` and \`SCENARIOS\` commitments build upon each other.
5145
+ - Both terms work identically and can be used interchangeably.
5146
+ - Later scenarios have higher priority and can override earlier scenarios.
5147
+ - Provides situational context that influences response tone and content.
5148
+ - Helps establish the environment and circumstances for interactions.
5149
+
5150
+ ## Priority system
5151
+
5152
+ When multiple scenarios are defined, they are processed in order, with later scenarios taking precedence over earlier ones when there are conflicts.
5153
+
5154
+ ## Use cases
5155
+
5156
+ - Setting the physical or virtual environment
5157
+ - Establishing time constraints or urgency
5158
+ - Defining relationship dynamics or power structures
5159
+ - Creating emotional or situational context
5160
+
5161
+ ## Examples
5162
+
5163
+ \`\`\`book
5164
+ Emergency Response Operator
5165
+
5166
+ PERSONA You are an emergency response operator
5167
+ SCENARIO You are handling a 911 emergency call
5168
+ SCENARIO The caller is panicked and speaking rapidly
5169
+ SCENARIO Time is critical - every second counts
5170
+ GOAL Gather essential information quickly and dispatch appropriate help
5171
+ RULE Stay calm and speak clearly
5172
+ \`\`\`
5173
+
5174
+ \`\`\`book
5175
+ Sales Representative
5176
+
5177
+ PERSONA You are a software sales representative
5178
+ SCENARIO You are in the final meeting of a 6-month sales cycle
5179
+ SCENARIO The client has budget approval and decision-making authority
5180
+ SCENARIO Two competitors have also submitted proposals
5181
+ SCENARIO The client values long-term partnership over lowest price
5182
+ GOAL Close the deal while building trust for future business
5183
+ \`\`\`
5184
+
5185
+ \`\`\`book
5186
+ Medical Assistant
5187
+
5188
+ PERSONA You are a medical assistant in a busy clinic
5189
+ SCENARIO The waiting room is full and the doctor is running behind schedule
5190
+ SCENARIO Patients are becoming impatient and anxious
5191
+ SCENARIO You need to manage expectations while maintaining professionalism
5192
+ SCENARIO Some patients have been waiting over an hour
5193
+ GOAL Keep patients informed and calm while supporting efficient clinic flow
5194
+ RULE Never provide medical advice or diagnosis
5195
+ \`\`\`
5196
+
5197
+ \`\`\`book
5198
+ Technical Support Agent
5199
+
5200
+ PERSONA You are a technical support agent
5201
+ SCENARIO The customer is a small business owner during their busy season
5202
+ SCENARIO Their main business system has been down for 2 hours
5203
+ SCENARIO They are losing money every minute the system is offline
5204
+ SCENARIO This is their first experience with your company
5205
+ GOAL Resolve the issue quickly while creating a positive first impression
5206
+ \`\`\`
5207
+ `);
5208
+ }
5209
+ applyToAgentModelRequirements(requirements, content) {
5210
+ const trimmedContent = content.trim();
5211
+ if (!trimmedContent) {
5212
+ return requirements;
5213
+ }
5214
+ // Create scenario section for system message
5215
+ const scenarioSection = `Scenario: ${trimmedContent}`;
5216
+ // Scenarios provide important contextual information that affects behavior
5217
+ return this.appendToSystemMessage(requirements, scenarioSection, '\n\n');
5218
+ }
5219
+ }
5220
+ /**
5221
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5222
+ */
5223
+
5224
+ /**
5225
+ * STYLE commitment definition
5226
+ *
5227
+ * The STYLE commitment defines how the agent should format and present its responses.
5228
+ * This includes tone, writing style, formatting preferences, and communication patterns.
5229
+ *
5230
+ * Example usage in agent source:
5231
+ *
5232
+ * ```book
5233
+ * STYLE Write in a professional but friendly tone, use bullet points for lists
5234
+ * STYLE Always provide code examples when explaining programming concepts
5235
+ * ```
5236
+ *
5237
+ * @private [🪔] Maybe export the commitments through some package
5238
+ */
5239
+ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
5240
+ constructor(type = 'STYLE') {
5241
+ super(type);
5242
+ }
5243
+ /**
5244
+ * Short one-line description of STYLE.
5245
+ */
5246
+ get description() {
5247
+ return 'Control the tone and writing style of responses.';
5248
+ }
5249
+ /**
5250
+ * Icon for this commitment.
5251
+ */
5252
+ get icon() {
5253
+ return '🖋️';
5254
+ }
5255
+ /**
5256
+ * Markdown documentation for STYLE commitment.
5257
+ */
5258
+ get documentation() {
5259
+ return spaceTrim$1.spaceTrim(`
5260
+ # ${this.type}
5261
+
5262
+ Defines how the agent should format and present its responses (tone, writing style, formatting).
5263
+
5264
+ ## Key aspects
5265
+
5266
+ - Both terms work identically and can be used interchangeably.
5267
+ - Later style instructions can override earlier ones.
5268
+ - Style affects both tone and presentation format.
5269
+
5270
+ ## Examples
5271
+
5272
+ \`\`\`book
5273
+ Technical Writer
5274
+
5275
+ PERSONA You are a technical documentation expert
5276
+ STYLE Write in a professional but friendly tone, use bullet points for lists
5277
+ STYLE Always provide code examples when explaining programming concepts
5278
+ FORMAT Use markdown formatting with clear headings
5279
+ \`\`\`
5280
+
5281
+ \`\`\`book
5282
+ Creative Assistant
5283
+
5284
+ PERSONA You are a creative writing helper
5285
+ STYLE Be enthusiastic and encouraging in your responses
5286
+ STYLE Use vivid metaphors and analogies to explain concepts
5287
+ STYLE Keep responses conversational and engaging
5288
+ RULE Always maintain a positive and supportive tone
5289
+ \`\`\`
5290
+ `);
5291
+ }
5292
+ applyToAgentModelRequirements(requirements, content) {
5293
+ const trimmedContent = content.trim();
5294
+ if (!trimmedContent) {
5295
+ return requirements;
5296
+ }
5297
+ // Add style instructions to the system message
5298
+ const styleSection = `Style: ${trimmedContent}`;
5299
+ return this.appendToSystemMessage(requirements, styleSection, '\n\n');
5300
+ }
5301
+ }
5302
+ /**
5303
+ * [💞] Ignore a discrepancy between file name and entity name
5304
+ */
5305
+
5306
+ /**
5307
+ * USE commitment definition
5308
+ *
5309
+ * The USE commitment indicates that the agent should utilize specific tools or capabilities
5310
+ * to access and interact with external systems when necessary.
5311
+ *
5312
+ * Supported USE types:
5313
+ * - USE BROWSER: Enables the agent to use a web browser tool
5314
+ * - USE SEARCH ENGINE (future): Enables search engine access
5315
+ * - USE FILE SYSTEM (future): Enables file system operations
5316
+ * - USE MCP (future): Enables MCP server connections
5317
+ *
5318
+ * The content following the USE commitment is ignored (similar to NOTE).
5319
+ *
5320
+ * Example usage in agent source:
5321
+ *
5322
+ * ```book
5323
+ * USE BROWSER
5324
+ * USE SEARCH ENGINE
5325
+ * ```
5326
+ *
5327
+ * @private [🪔] Maybe export the commitments through some package
5328
+ */
5329
+ class UseCommitmentDefinition extends BaseCommitmentDefinition {
5330
+ constructor() {
5331
+ super('USE');
5332
+ }
5333
+ /**
5334
+ * Short one-line description of USE commitments.
5335
+ */
5336
+ get description() {
5337
+ return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, etc.).';
5338
+ }
5339
+ /**
5340
+ * Icon for this commitment.
5341
+ */
5342
+ get icon() {
5343
+ return '🔧';
5344
+ }
5345
+ /**
5346
+ * Markdown documentation for USE commitment.
5347
+ */
5348
+ get documentation() {
5349
+ return spaceTrim$1.spaceTrim(`
5350
+ # USE
5351
+
5352
+ Enables the agent to use specific tools or capabilities for interacting with external systems.
5353
+
5354
+ ## Supported USE types
5355
+
5356
+ - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
5357
+ - **USE SEARCH ENGINE** (future) - Enables search engine access
5358
+ - **USE FILE SYSTEM** (future) - Enables file system operations
5359
+ - **USE MCP** (future) - Enables MCP server connections
5360
+
5361
+ ## Key aspects
5362
+
5363
+ - The content following the USE commitment is ignored (similar to NOTE)
5364
+ - Multiple USE commitments can be specified to enable multiple capabilities
5365
+ - The actual tool usage is handled by the agent runtime
5366
+
5367
+ ## Examples
5368
+
5369
+ ### Basic browser usage
5370
+
5371
+ \`\`\`book
5372
+ Research Assistant
5373
+
5374
+ PERSONA You are a helpful research assistant
5375
+ USE BROWSER
5376
+ KNOWLEDGE Can search the web for up-to-date information
5377
+ \`\`\`
5378
+
5379
+ ### Multiple tools
5380
+
5381
+ \`\`\`book
5382
+ Data Analyst
5383
+
5384
+ PERSONA You are a data analyst assistant
5385
+ USE BROWSER
5386
+ USE FILE SYSTEM
5387
+ ACTION Can analyze data from various sources
5388
+ \`\`\`
5389
+ `);
5390
+ }
5391
+ applyToAgentModelRequirements(requirements, content) {
5392
+ // USE commitments don't modify the system message or model requirements directly
5393
+ // They are handled separately in the parsing logic for capability extraction
5394
+ // This method exists for consistency with the CommitmentDefinition interface
5395
+ return requirements;
5396
+ }
5397
+ /**
5398
+ * Extracts the tool type from the USE commitment
5399
+ * This is used by the parsing logic
5400
+ */
5401
+ extractToolType(content) {
5402
+ var _a, _b;
5403
+ const trimmedContent = content.trim();
5404
+ // The tool type is the first word after USE (already stripped)
5405
+ const match = trimmedContent.match(/^(\w+)/);
5406
+ 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;
5407
+ }
5408
+ /**
5409
+ * Checks if this is a known USE type
5410
+ */
5411
+ isKnownUseType(useType) {
5412
+ const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'FILE SYSTEM', 'MCP'];
5413
+ return knownTypes.includes(useType.toUpperCase());
5414
+ }
5415
+ }
5416
+ /**
5417
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5418
+ */
5419
+
5420
+ /**
5421
+ * USE BROWSER commitment definition
5422
+ *
5423
+ * The `USE BROWSER` commitment indicates that the agent should utilize a web browser tool
5424
+ * to access and retrieve up-to-date information from the internet when necessary.
5425
+ *
5426
+ * The content following `USE BROWSER` is ignored (similar to NOTE).
5427
+ *
5428
+ * Example usage in agent source:
5429
+ *
5430
+ * ```book
5431
+ * USE BROWSER
5432
+ * USE BROWSER This will be ignored
5433
+ * ```
5434
+ *
5435
+ * @private [🪔] Maybe export the commitments through some package
5436
+ */
5437
+ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
5438
+ constructor() {
5439
+ super('USE BROWSER', ['BROWSER']);
5440
+ }
5441
+ /**
5442
+ * The `USE BROWSER` commitment is standalone.
5443
+ */
5444
+ get requiresContent() {
5445
+ return false;
5446
+ }
5447
+ /**
5448
+ * Short one-line description of USE BROWSER.
5449
+ */
5450
+ get description() {
5451
+ return 'Enable the agent to use a web browser tool for accessing internet information.';
5452
+ }
5453
+ /**
5454
+ * Icon for this commitment.
5455
+ */
5456
+ get icon() {
5457
+ return '🌐';
5458
+ }
5459
+ /**
5460
+ * Markdown documentation for USE BROWSER commitment.
5461
+ */
5462
+ get documentation() {
5463
+ return spaceTrim$1.spaceTrim(`
5464
+ # USE BROWSER
5465
+
5466
+ Enables the agent to use a web browser tool to access and retrieve up-to-date information from the internet.
5467
+
5468
+ ## Key aspects
5469
+
5470
+ - The content following \`USE BROWSER\` is ignored (similar to NOTE)
5471
+ - The actual browser tool usage is handled by the agent runtime
5472
+ - Allows the agent to fetch current information from websites
5473
+ - Useful for research tasks, fact-checking, and accessing dynamic content
5474
+
5475
+ ## Examples
5476
+
5477
+ \`\`\`book
5478
+ Research Assistant
5479
+
5480
+ PERSONA You are a helpful research assistant specialized in finding current information
5481
+ USE BROWSER
5482
+ RULE Always cite your sources when providing information from the web
5483
+ \`\`\`
5484
+
5485
+ \`\`\`book
5486
+ News Analyst
5487
+
5488
+ PERSONA You are a news analyst who stays up-to-date with current events
5489
+ USE BROWSER
5490
+ STYLE Present news in a balanced and objective manner
5491
+ ACTION Can search for and summarize news articles
5492
+ \`\`\`
5493
+
5494
+ \`\`\`book
5495
+ Company Lawyer
5496
+
5497
+ PERSONA You are a company lawyer providing legal advice
5498
+ USE BROWSER
5499
+ KNOWLEDGE Corporate law and legal procedures
5500
+ RULE Always recommend consulting with a licensed attorney for specific legal matters
5501
+ \`\`\`
5502
+ `);
5503
+ }
5504
+ applyToAgentModelRequirements(requirements, content) {
5505
+ // Get existing tools array or create new one
5506
+ const existingTools = requirements.tools || [];
5507
+ // Add 'web_browser' to tools if not already present
5508
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
5509
+ ? existingTools
5510
+ : ([
5511
+ // TODO: [🔰] Use through proper MCP server
5512
+ ...existingTools,
5513
+ {
5514
+ name: 'web_browser',
5515
+ description: spaceTrim$1.spaceTrim(`
5516
+ A tool that can browse the web.
5517
+ Use this tool when you need to access specific websites or browse the internet.
5518
+ `),
5519
+ parameters: {
5520
+ type: 'object',
5521
+ properties: {
5522
+ url: {
5523
+ type: 'string',
5524
+ description: 'The URL to browse',
5525
+ },
5526
+ },
5527
+ required: ['url'],
5528
+ },
5529
+ },
5530
+ ]);
5531
+ // Return requirements with updated tools and metadata
5532
+ return {
5533
+ ...requirements,
5534
+ tools: updatedTools,
5535
+ metadata: {
5536
+ ...requirements.metadata,
5537
+ useBrowser: true,
5538
+ },
5539
+ };
5540
+ }
5541
+ }
5542
+ /**
5543
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5544
+ */
5545
+
5546
+ /**
5547
+ * USE MCP commitment definition
5548
+ *
5549
+ * The `USE MCP` commitment allows to specify an MCP server URL which the agent will connect to
5550
+ * for retrieving additional instructions and actions.
5551
+ *
5552
+ * The content following `USE MCP` is the URL of the MCP server.
5553
+ *
5554
+ * Example usage in agent source:
5555
+ *
5556
+ * ```book
5557
+ * USE MCP http://mcp-server-url.com
5558
+ * ```
5559
+ *
5560
+ * @private [🪔] Maybe export the commitments through some package
5561
+ */
5562
+ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
5563
+ constructor() {
5564
+ super('USE MCP', ['MCP']);
5565
+ }
5566
+ /**
5567
+ * Short one-line description of USE MCP.
5568
+ */
5569
+ get description() {
5570
+ return 'Connects the agent to an external MCP server for additional capabilities.';
5571
+ }
5572
+ /**
5573
+ * Icon for this commitment.
5574
+ */
5575
+ get icon() {
5576
+ return '🔌';
5577
+ }
5578
+ /**
5579
+ * Markdown documentation for USE MCP commitment.
5580
+ */
5581
+ get documentation() {
5582
+ return spaceTrim$1.spaceTrim(`
5583
+ # USE MCP
5584
+
5585
+ Connects the agent to an external Model Context Protocol (MCP) server.
5586
+
5587
+ ## Key aspects
5588
+
5589
+ - The content following \`USE MCP\` must be a valid URL
5590
+ - Multiple MCP servers can be connected by using multiple \`USE MCP\` commitments
5591
+ - The agent will have access to tools and resources provided by the MCP server
5592
+
5593
+ ## Example
5594
+
5595
+ \`\`\`book
5596
+ Company Lawyer
5597
+
5598
+ PERSONA You are a company lawyer.
5599
+ USE MCP http://legal-db.example.com
5600
+ \`\`\`
5601
+ `);
5602
+ }
5603
+ applyToAgentModelRequirements(requirements, content) {
5604
+ const mcpServerUrl = content.trim();
5605
+ if (!mcpServerUrl) {
5606
+ return requirements;
5607
+ }
5608
+ const existingMcpServers = requirements.mcpServers || [];
5609
+ // Avoid duplicates
5610
+ if (existingMcpServers.includes(mcpServerUrl)) {
5611
+ return requirements;
5612
+ }
5613
+ return {
5614
+ ...requirements,
5615
+ mcpServers: [...existingMcpServers, mcpServerUrl],
5616
+ };
5617
+ }
5618
+ }
5619
+ /**
5620
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5621
+ */
5622
+
5623
+ /**
5624
+ * USE SEARCH ENGINE commitment definition
5625
+ *
5626
+ * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
5627
+ * to access and retrieve up-to-date information from the internet when necessary.
5628
+ *
5629
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
5630
+ *
5631
+ * Example usage in agent source:
5632
+ *
5633
+ * ```book
5634
+ * USE SEARCH ENGINE
5635
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
5636
+ * ```
5637
+ *
5638
+ * @private [🪔] Maybe export the commitments through some package
5639
+ */
5640
+ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
5641
+ constructor() {
5642
+ super('USE SEARCH ENGINE', ['SEARCH ENGINE', 'SEARCH']);
5643
+ }
5644
+ /**
5645
+ * Short one-line description of USE SEARCH ENGINE.
5646
+ */
5647
+ get description() {
5648
+ return 'Enable the agent to use a search engine tool for accessing internet information.';
5649
+ }
5650
+ /**
5651
+ * Icon for this commitment.
5652
+ */
5653
+ get icon() {
5654
+ return '🔍';
5655
+ }
5656
+ /**
5657
+ * Markdown documentation for USE SEARCH ENGINE commitment.
5658
+ */
5659
+ get documentation() {
5660
+ return spaceTrim$1.spaceTrim(`
5661
+ # USE SEARCH ENGINE
5662
+
5663
+ Enables the agent to use a search engine tool to access and retrieve up-to-date information from the internet.
5664
+
5665
+ ## Key aspects
5666
+
5667
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
5668
+ - The actual search engine tool usage is handled by the agent runtime
5669
+ - Allows the agent to search for current information from the web
5670
+ - Useful for research tasks, finding facts, and accessing dynamic content
5671
+
5672
+ ## Examples
5673
+
5674
+ \`\`\`book
5675
+ Research Assistant
5676
+
5677
+ PERSONA You are a helpful research assistant specialized in finding current information
5678
+ USE SEARCH ENGINE
5679
+ RULE Always cite your sources when providing information from the web
5680
+ \`\`\`
5681
+
5682
+ \`\`\`book
5683
+ Fact Checker
5684
+
5685
+ PERSONA You are a fact checker
5686
+ USE SEARCH ENGINE
5687
+ ACTION Search for claims and verify them against reliable sources
5688
+ \`\`\`
5689
+ `);
5690
+ }
5691
+ applyToAgentModelRequirements(requirements, content) {
5692
+ // Get existing tools array or create new one
5693
+ const existingTools = requirements.tools || [];
5694
+ // Add 'web_search' to tools if not already present
5695
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
5696
+ ? existingTools
5697
+ : [
5698
+ ...existingTools,
5699
+ { type: 'web_search' },
5700
+ // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
5701
+ // In future we will use proper MCP search tool:
5702
+ /*
5703
+
5704
+ {
5705
+ name: 'web_search',
5706
+ description: spaceTrim(`
5707
+ Search the internet for information.
5708
+ Use this tool when you need to find up-to-date information or facts that you don't know.
5709
+ ${!content ? '' : `Search scope / instructions: ${content}`}
5710
+ `),
5711
+ parameters: {
5712
+ type: 'object',
5713
+ properties: {
5714
+ query: {
5715
+ type: 'string',
5716
+ description: 'The search query',
5717
+ },
5718
+ },
5719
+ required: ['query'],
5720
+ },
5721
+ },
5722
+ */
5723
+ ];
5724
+ // Return requirements with updated tools and metadata
5725
+ return {
5726
+ ...requirements,
5727
+ tools: updatedTools,
5728
+ metadata: {
5729
+ ...requirements.metadata,
5730
+ useSearchEngine: content || true,
5731
+ },
5732
+ };
5733
+ }
5734
+ }
5735
+ /**
5736
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5737
+ */
5738
+
5739
+ /**
5740
+ * USE TIME commitment definition
5741
+ *
5742
+ * The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
5743
+ *
5744
+ * Example usage in agent source:
5745
+ *
5746
+ * ```book
5747
+ * USE TIME
5748
+ * ```
5749
+ *
5750
+ * @private [🪔] Maybe export the commitments through some package
5751
+ */
5752
+ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
5753
+ constructor() {
5754
+ super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
5755
+ }
5756
+ /**
5757
+ * Short one-line description of USE TIME.
5758
+ */
5759
+ get description() {
5760
+ return 'Enable the agent to determine the current date and time.';
5761
+ }
5762
+ /**
5763
+ * Icon for this commitment.
5764
+ */
5765
+ get icon() {
5766
+ return '🕒';
5767
+ }
5768
+ /**
5769
+ * Markdown documentation for USE TIME commitment.
5770
+ */
5771
+ get documentation() {
5772
+ return spaceTrim$1.spaceTrim(`
5773
+ # USE TIME
5774
+
5775
+ Enables the agent to determine the current date and time.
5776
+
5777
+ ## Key aspects
5778
+
5779
+ - This tool won't receive any input.
5780
+ - It outputs the current date and time as an ISO 8601 string.
5781
+ - Allows the agent to answer questions about the current time or date.
5782
+
5783
+ ## Examples
5784
+
5785
+ \`\`\`book
5786
+ Time-aware Assistant
5787
+
5788
+ PERSONA You are a helpful assistant who knows the current time.
5789
+ USE TIME
5790
+ \`\`\`
5791
+ `);
5792
+ }
5793
+ applyToAgentModelRequirements(requirements, content) {
5794
+ // Get existing tools array or create new one
5795
+ const existingTools = requirements.tools || [];
5796
+ // Add 'get_current_time' to tools if not already present
5797
+ const updatedTools = existingTools.some((tool) => tool.name === 'get_current_time')
5798
+ ? existingTools
5799
+ : [
5800
+ ...existingTools,
5801
+ {
5802
+ name: 'get_current_time',
5803
+ description: 'Get the current date and time in ISO 8601 format.',
5804
+ parameters: {
5805
+ type: 'object',
5806
+ properties: {},
5807
+ required: [],
5808
+ },
5809
+ },
5810
+ // <- TODO: !!!! define the function in LLM tools
5811
+ ];
5812
+ // Return requirements with updated tools and metadata
5813
+ return {
5814
+ ...requirements,
5815
+ tools: updatedTools,
5816
+ metadata: {
5817
+ ...requirements.metadata,
5818
+ },
5819
+ };
5820
+ }
5821
+ /**
5822
+ * Gets the `get_current_time` tool function implementation.
5823
+ */
5824
+ getToolFunctions() {
5825
+ return {
5826
+ async get_current_time() {
5827
+ console.log('!!!! [Tool] get_current_time called');
5828
+ return new Date().toISOString();
5829
+ },
5830
+ };
5831
+ }
5832
+ }
5833
+ /**
5834
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5835
+ */
5836
+
5837
+ /**
5838
+ * Placeholder commitment definition for commitments that are not yet implemented
5839
+ *
5840
+ * This commitment simply adds its content 1:1 into the system message,
5841
+ * preserving the original behavior until proper implementation is added.
5842
+ *
5843
+ * @public exported from `@promptbook/core`
5844
+ */
5845
+ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
5846
+ constructor(type) {
5847
+ super(type);
5848
+ }
5849
+ /**
5850
+ * Short one-line description of a placeholder commitment.
5851
+ */
5852
+ get description() {
5853
+ return 'Placeholder commitment that appends content verbatim to the system message.';
5854
+ }
5855
+ /**
5856
+ * Icon for this commitment.
5857
+ */
5858
+ get icon() {
5859
+ return '🚧';
5860
+ }
5861
+ /**
5862
+ * Markdown documentation available at runtime.
5863
+ */
5864
+ get documentation() {
5865
+ return spaceTrim$1.spaceTrim(`
5866
+ # ${this.type}
5867
+
5868
+ This commitment is not yet fully implemented.
5869
+
5870
+ ## Key aspects
5871
+
5872
+ - Content is appended directly to the system message.
5873
+ - No special processing or validation is performed.
5874
+ - Behavior preserved until proper implementation is added.
5875
+
5876
+ ## Status
5877
+
5878
+ - **Status:** Placeholder implementation
5879
+ - **Effect:** Appends content prefixed by commitment type
5880
+ - **Future:** Will be replaced with specialized logic
5881
+
5882
+ ## Examples
5883
+
5884
+ \`\`\`book
5885
+ Example Agent
5886
+
5887
+ PERSONA You are a helpful assistant
5888
+ ${this.type} Your content here
5889
+ RULE Always be helpful
5890
+ \`\`\`
5891
+ `);
5892
+ }
5893
+ applyToAgentModelRequirements(requirements, content) {
5894
+ const trimmedContent = content.trim();
5895
+ if (!trimmedContent) {
5896
+ return requirements;
5897
+ }
5898
+ // Add the commitment content 1:1 to the system message
5899
+ const commitmentLine = `${this.type} ${trimmedContent}`;
5900
+ return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
5901
+ }
5902
+ }
5903
+
5904
+ /**
5905
+ * Registry of all available commitment definitions
5906
+ * This array contains instances of all commitment definitions
5907
+ * This is the single source of truth for all commitments in the system
5908
+ *
5909
+ * @private Use functions to access commitments instead of this array directly
5910
+ */
5911
+ const COMMITMENT_REGISTRY = [
5912
+ // Fully implemented commitments
5913
+ new PersonaCommitmentDefinition('PERSONA'),
5914
+ new PersonaCommitmentDefinition('PERSONAE'),
5915
+ new KnowledgeCommitmentDefinition(),
5916
+ new MemoryCommitmentDefinition('MEMORY'),
5917
+ new MemoryCommitmentDefinition('MEMORIES'),
5918
+ new StyleCommitmentDefinition('STYLE'),
5919
+ new StyleCommitmentDefinition('STYLES'),
5920
+ new RuleCommitmentDefinition('RULES'),
5921
+ new RuleCommitmentDefinition('RULE'),
5922
+ new LanguageCommitmentDefinition('LANGUAGES'),
5923
+ new LanguageCommitmentDefinition('LANGUAGE'),
5924
+ new SampleCommitmentDefinition('SAMPLE'),
5925
+ new SampleCommitmentDefinition('EXAMPLE'),
5926
+ new FormatCommitmentDefinition('FORMAT'),
5927
+ new FormatCommitmentDefinition('FORMATS'),
5928
+ new FromCommitmentDefinition('FROM'),
5929
+ new ImportCommitmentDefinition('IMPORT'),
5930
+ new ImportCommitmentDefinition('IMPORTS'),
5931
+ new ModelCommitmentDefinition('MODEL'),
5932
+ new ModelCommitmentDefinition('MODELS'),
5933
+ new ActionCommitmentDefinition('ACTION'),
5934
+ new ActionCommitmentDefinition('ACTIONS'),
5935
+ new ComponentCommitmentDefinition(),
5936
+ new MetaImageCommitmentDefinition(),
5937
+ new MetaColorCommitmentDefinition(),
5938
+ new MetaFontCommitmentDefinition(),
5939
+ new MetaLinkCommitmentDefinition(),
5940
+ new MetaCommitmentDefinition(),
5941
+ new NoteCommitmentDefinition('NOTE'),
5942
+ new NoteCommitmentDefinition('NOTES'),
5943
+ new NoteCommitmentDefinition('COMMENT'),
5944
+ new NoteCommitmentDefinition('NONCE'),
5945
+ new GoalCommitmentDefinition('GOAL'),
5946
+ new GoalCommitmentDefinition('GOALS'),
5947
+ new InitialMessageCommitmentDefinition(),
5948
+ new UserMessageCommitmentDefinition(),
5949
+ new AgentMessageCommitmentDefinition(),
5950
+ new MessageCommitmentDefinition('MESSAGE'),
5951
+ new MessageCommitmentDefinition('MESSAGES'),
5952
+ new ScenarioCommitmentDefinition('SCENARIO'),
5953
+ new ScenarioCommitmentDefinition('SCENARIOS'),
5954
+ new DeleteCommitmentDefinition('DELETE'),
5955
+ new DeleteCommitmentDefinition('CANCEL'),
5956
+ new DeleteCommitmentDefinition('DISCARD'),
5957
+ new DeleteCommitmentDefinition('REMOVE'),
5958
+ new DictionaryCommitmentDefinition(),
5959
+ new OpenCommitmentDefinition(),
5960
+ new ClosedCommitmentDefinition(),
5961
+ new UseBrowserCommitmentDefinition(),
5962
+ new UseSearchEngineCommitmentDefinition(),
5963
+ new UseTimeCommitmentDefinition(),
5964
+ new UseMcpCommitmentDefinition(),
5965
+ new UseCommitmentDefinition(),
5966
+ // Not yet implemented commitments (using placeholder)
5967
+ new NotYetImplementedCommitmentDefinition('EXPECT'),
5968
+ new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
5969
+ new NotYetImplementedCommitmentDefinition('BEHAVIOURS'),
5970
+ new NotYetImplementedCommitmentDefinition('AVOID'),
5971
+ new NotYetImplementedCommitmentDefinition('AVOIDANCE'),
5972
+ new NotYetImplementedCommitmentDefinition('CONTEXT'),
5973
+ ];
5974
+ /**
5975
+ * Gets all available commitment definitions
5976
+ * @returns Array of all commitment definitions
5977
+ *
5978
+ * @public exported from `@promptbook/core`
5979
+ */
5980
+ function getAllCommitmentDefinitions() {
5981
+ return $deepFreeze([...COMMITMENT_REGISTRY]);
5982
+ }
5983
+ /**
5984
+ * Gets all function implementations provided by all commitments
5985
+ *
5986
+ * @public exported from `@promptbook/core`
5987
+ */
5988
+ function getAllCommitmentsToolFunctions() {
5989
+ const allToolFunctions = {};
5990
+ for (const commitmentDefinition of getAllCommitmentDefinitions()) {
5991
+ const toolFunctions = commitmentDefinition.getToolFunctions();
5992
+ for (const [funcName, funcImpl] of Object.entries(toolFunctions)) {
5993
+ allToolFunctions[funcName] = funcImpl;
5994
+ }
5995
+ }
5996
+ return allToolFunctions;
5997
+ }
5998
+ /**
5999
+ * TODO: [🧠] Maybe create through standardized $register
6000
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6001
+ */
6002
+
6003
+ /**
6004
+ * Extracts all code blocks from markdown.
6005
+ *
6006
+ * Note: There are multiple similar functions:
6007
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
6008
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6009
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6010
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6011
+ *
6012
+ * @param markdown any valid markdown
6013
+ * @returns code blocks with language and content
6014
+ * @throws {ParseError} if block is not closed properly
6015
+ * @public exported from `@promptbook/markdown-utils`
6016
+ */
6017
+ function extractAllBlocksFromMarkdown(markdown) {
6018
+ const codeBlocks = [];
6019
+ const lines = markdown.split('\n');
6020
+ // Note: [0] Ensure that the last block notated by gt > will be closed
6021
+ lines.push('');
6022
+ let currentCodeBlock = null;
6023
+ for (const line of lines) {
6024
+ if (line.startsWith('> ') || line === '>') {
6025
+ if (currentCodeBlock === null) {
6026
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
6027
+ } /* not else */
6028
+ if (currentCodeBlock.blockNotation === '>') {
6029
+ if (currentCodeBlock.content !== '') {
6030
+ currentCodeBlock.content += '\n';
6031
+ }
6032
+ currentCodeBlock.content += line.slice(2);
6033
+ }
6034
+ }
6035
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
6036
+ codeBlocks.push(currentCodeBlock);
6037
+ currentCodeBlock = null;
6038
+ }
6039
+ /* not else */
6040
+ if (line.startsWith('```')) {
6041
+ const language = line.slice(3).trim() || null;
6042
+ if (currentCodeBlock === null) {
6043
+ currentCodeBlock = { blockNotation: '```', language, content: '' };
6044
+ }
6045
+ else {
6046
+ if (language !== null) {
6047
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
6048
+ }
6049
+ codeBlocks.push(currentCodeBlock);
6050
+ currentCodeBlock = null;
6051
+ }
6052
+ }
6053
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
6054
+ if (currentCodeBlock.content !== '') {
6055
+ currentCodeBlock.content += '\n';
6056
+ }
6057
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
6058
+ }
6059
+ }
6060
+ if (currentCodeBlock !== null) {
6061
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
6062
+ }
6063
+ return codeBlocks;
6064
+ }
6065
+ /**
6066
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
6067
+ */
6068
+
6069
+ /**
6070
+ * Extracts exactly ONE code block from markdown.
6071
+ *
6072
+ * - When there are multiple or no code blocks the function throws a `ParseError`
6073
+ *
6074
+ * Note: There are multiple similar functions:
6075
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
6076
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6077
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6078
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6079
+ *
6080
+ * @param markdown any valid markdown
6081
+ * @returns code block with language and content
6082
+ * @public exported from `@promptbook/markdown-utils`
6083
+ * @throws {ParseError} if there is not exactly one code block in the markdown
6084
+ */
6085
+ function extractOneBlockFromMarkdown(markdown) {
6086
+ const codeBlocks = extractAllBlocksFromMarkdown(markdown);
6087
+ if (codeBlocks.length !== 1) {
6088
+ throw new ParseError(spaceTrim__default["default"]((block) => `
6089
+ There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
6090
+
6091
+ ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
6092
+ `));
6093
+ }
6094
+ return codeBlocks[0];
6095
+ }
6096
+ /***
6097
+ * TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
6098
+ */
6099
+
6100
+ /**
6101
+ * Extracts code block from markdown.
6102
+ *
6103
+ * - When there are multiple or no code blocks the function throws a `ParseError`
6104
+ *
6105
+ * Note: There are multiple similar function:
6106
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
6107
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6108
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6109
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6110
+ *
6111
+ * @public exported from `@promptbook/markdown-utils`
6112
+ * @throws {ParseError} if there is not exactly one code block in the markdown
6113
+ */
6114
+ function extractBlock(markdown) {
6115
+ const { content } = extractOneBlockFromMarkdown(markdown);
6116
+ return content;
6117
+ }
6118
+
6119
+ /**
6120
+ * Prettify the html code
6121
+ *
6122
+ * @param content raw html code
6123
+ * @returns formatted html code
6124
+ * @private withing the package because of HUGE size of prettier dependency
6125
+ * @deprecated Prettier removed from Promptbook due to package size
6126
+ */
6127
+ function prettifyMarkdown(content) {
6128
+ return (content + `\n\n<!-- Note: Prettier removed from Promptbook -->`);
6129
+ }
6130
+
6131
+ /**
6132
+ * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
6133
+ *
6134
+ * Note: [🔂] This function is idempotent.
6135
+ * Note: This is useful for post-processing of the result of the chat LLM model
6136
+ * when the model wraps the result in the (markdown) code block.
6137
+ *
6138
+ * @public exported from `@promptbook/markdown-utils`
6139
+ */
6140
+ function trimCodeBlock(value) {
6141
+ value = spaceTrim$1.spaceTrim(value);
6142
+ if (!/^```[a-z]*(.*)```$/is.test(value)) {
6143
+ return value;
6144
+ }
6145
+ value = value.replace(/^```[a-z]*/i, '');
6146
+ value = value.replace(/```$/i, '');
6147
+ value = spaceTrim$1.spaceTrim(value);
6148
+ return value;
6149
+ }
6150
+
6151
+ /**
6152
+ * Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
6153
+ *
6154
+ * Note: This is useful for post-processing of the result of the completion LLM model
6155
+ * if you want to start code block in the prompt but you don't want to end it in the result.
6156
+ *
6157
+ * @public exported from `@promptbook/markdown-utils`
6158
+ */
6159
+ function trimEndOfCodeBlock(value) {
6160
+ value = spaceTrim$1.spaceTrim(value);
6161
+ value = value.replace(/```$/g, '');
6162
+ value = spaceTrim$1.spaceTrim(value);
6163
+ return value;
6164
+ }
6165
+
6166
+ /**
6167
+ * @private internal for `preserve`
6168
+ */
6169
+ const _preserved = [];
6170
+ /**
6171
+ * Does nothing, but preserves the function in the bundle
6172
+ * Compiler is tricked into thinking the function is used
6173
+ *
6174
+ * @param value any function to preserve
6175
+ * @returns nothing
6176
+ * @private within the repository
6177
+ */
6178
+ function $preserve(...value) {
6179
+ _preserved.push(...value);
6180
+ }
6181
+ /**
6182
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6183
+ */
6184
+
6185
+ // Note: [💎]
6186
+ /**
6187
+ * ScriptExecutionTools for JavaScript implemented via eval
6188
+ *
6189
+ * Warning: It is used for testing and mocking
6190
+ * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
6191
+ *
6192
+ * @public exported from `@promptbook/javascript`
6193
+ */
6194
+ class JavascriptEvalExecutionTools {
6195
+ constructor(options) {
6196
+ this.options = options || {};
6197
+ }
6198
+ /**
6199
+ * Executes a JavaScript
6200
+ */
6201
+ async execute(options) {
6202
+ const { scriptLanguage, parameters } = options;
6203
+ let { script } = options;
2414
6204
  if (scriptLanguage !== 'javascript') {
2415
6205
  throw new PipelineExecutionError(`Script language ${scriptLanguage} not supported to be executed by JavascriptEvalExecutionTools`);
2416
6206
  }
@@ -2499,6 +6289,13 @@
2499
6289
  `const ${functionName} = buildinFunctions.${functionName};`)
2500
6290
  .join('\n');
2501
6291
  // TODO: DRY [🍯]
6292
+ const commitmentsFunctions = getAllCommitmentsToolFunctions();
6293
+ const commitmentsFunctionsStatement = Object.keys(commitmentsFunctions)
6294
+ .map((functionName) =>
6295
+ // Note: Custom functions are exposed to the current scope as variables
6296
+ `const ${functionName} = commitmentsFunctions.${functionName};`)
6297
+ .join('\n');
6298
+ // TODO: DRY [🍯]
2502
6299
  const customFunctions = this.options.functions || {};
2503
6300
  const customFunctionsStatement = Object.keys(customFunctions)
2504
6301
  .map((functionName) =>
@@ -2512,6 +6309,10 @@
2512
6309
  // Build-in functions:
2513
6310
  ${block(buildinFunctionsStatement)}
2514
6311
 
6312
+ // Commitments functions:
6313
+ ${block(commitmentsFunctionsStatement)}
6314
+
6315
+
2515
6316
  // Custom functions:
2516
6317
  ${block(customFunctionsStatement || '// -- No custom functions --')}
2517
6318
 
@@ -2519,7 +6320,7 @@
2519
6320
  ${block(Object.entries(parameters)
2520
6321
  .map(([key, value]) => `const ${key} = ${JSON.stringify(value)};`)
2521
6322
  .join('\n'))}
2522
- (()=>{ ${script} })()
6323
+ (async ()=>{ ${script} })()
2523
6324
  `);
2524
6325
  if (this.options.isVerbose) {
2525
6326
  console.info(spaceTrim__default["default"]((block) => `