@promptbook/core 0.103.0-42 → 0.103.0-43

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 (79) hide show
  1. package/esm/index.es.js +538 -365
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  4. package/esm/typings/src/_packages/node.index.d.ts +0 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +14 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -4
  8. package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +1 -1
  9. package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +1 -0
  10. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +1 -1
  11. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
  12. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
  13. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  14. package/esm/typings/src/book-components/Qr/BrandedQrCode.d.ts +1 -1
  15. package/esm/typings/src/book-components/Qr/useQrCode.d.ts +1 -1
  16. package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +1 -1
  17. package/esm/typings/src/cli/cli-commands/about.d.ts +1 -1
  18. package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -1
  19. package/esm/typings/src/cli/cli-commands/list-models.d.ts +1 -1
  20. package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +1 -1
  21. package/esm/typings/src/cli/cli-commands/login.d.ts +1 -1
  22. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  23. package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -1
  24. package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
  25. package/esm/typings/src/cli/cli-commands/start-agents-server.d.ts +1 -1
  26. package/esm/typings/src/cli/cli-commands/start-pipelines-server.d.ts +1 -1
  27. package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -1
  28. package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +1 -1
  29. package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +11 -12
  30. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +55 -0
  31. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +129 -0
  32. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
  33. package/esm/typings/src/config.d.ts +1 -1
  34. package/esm/typings/src/errors/0-index.d.ts +3 -0
  35. package/esm/typings/src/errors/DatabaseError.d.ts +9 -0
  36. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -1
  37. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -1
  39. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
  40. package/esm/typings/src/llm-providers/agent/Agent.d.ts +5 -2
  41. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
  42. package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +4 -2
  43. package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +2 -2
  44. package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -1
  45. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +1 -0
  46. package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
  47. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +0 -19
  48. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +1 -1
  49. package/esm/typings/src/transpilers/_common/BookTranspiler.d.ts +5 -1
  50. package/esm/typings/src/transpilers/_common/BookTranspilerOptions.d.ts +1 -1
  51. package/esm/typings/src/transpilers/_common/register/$bookTranspilersRegister.d.ts +1 -1
  52. package/esm/typings/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.d.ts +4 -1
  53. package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +1 -1
  54. package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.d.ts +4 -1
  55. package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
  56. package/esm/typings/src/utils/color/operators/darken.d.ts +1 -1
  57. package/esm/typings/src/utils/color/operators/grayscale.d.ts +1 -1
  58. package/esm/typings/src/utils/color/operators/lighten.d.ts +1 -1
  59. package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +1 -1
  60. package/esm/typings/src/utils/color/operators/saturate.d.ts +1 -1
  61. package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +16 -0
  62. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +1 -1
  63. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -1
  64. package/esm/typings/src/utils/files/$induceBookDownload.d.ts +2 -2
  65. package/esm/typings/src/utils/files/$induceFileDownload.d.ts +2 -2
  66. package/esm/typings/src/utils/files/ObjectUrl.d.ts +1 -1
  67. package/esm/typings/src/utils/misc/aboutPromptbookInformation.d.ts +6 -0
  68. package/esm/typings/src/utils/organization/$side_effect.d.ts +1 -1
  69. package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +22 -0
  70. package/esm/typings/src/utils/random/$randomToken.d.ts +1 -0
  71. package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
  72. package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -2
  73. package/esm/typings/src/version.d.ts +1 -1
  74. package/package.json +1 -1
  75. package/umd/index.umd.js +463 -287
  76. package/umd/index.umd.js.map +1 -1
  77. package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.d.ts +0 -89
  78. package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.test.d.ts +0 -1
  79. package/esm/typings/src/execution/utils/logLlmCall.d.ts +0 -8
package/umd/index.umd.js CHANGED
@@ -1,16 +1,16 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse'), require('moment'), require('colors'), require('bottleneck'), require('openai')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse', 'moment', 'colors', 'bottleneck', 'openai'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse, global.moment, global.colors, global.Bottleneck, global.OpenAI));
5
- })(this, (function (exports, spaceTrim, crypto, rxjs, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse, moment, colors, Bottleneck, OpenAI) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse'), require('colors'), require('moment'), require('bottleneck'), require('openai')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse', 'colors', 'moment', 'bottleneck', 'openai'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim$1, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse, global.colors, global.moment, global.Bottleneck, global.OpenAI));
5
+ })(this, (function (exports, spaceTrim$1, crypto, rxjs, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse, colors, moment, Bottleneck, OpenAI) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
- var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
9
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim$1);
10
10
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
11
11
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
12
- var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
13
12
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
13
+ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
14
14
  var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
15
15
  var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
16
16
 
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-42';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-43';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -842,6 +842,23 @@
842
842
  * TODO: Maybe connect with textures
843
843
  */
844
844
 
845
+ /**
846
+ * Makes color transformer which returns a grayscale version of the color
847
+ *
848
+ * @param amount from 0 to 1
849
+ *
850
+ * @public exported from `@promptbook/color`
851
+ */
852
+ function grayscale(amount) {
853
+ return ({ red, green, blue, alpha }) => {
854
+ const average = (red + green + blue) / 3;
855
+ red = Math.round(average * amount + red * (1 - amount));
856
+ green = Math.round(average * amount + green * (1 - amount));
857
+ blue = Math.round(average * amount + blue * (1 - amount));
858
+ return Color.fromValues(red, green, blue, alpha);
859
+ };
860
+ }
861
+
845
862
  /**
846
863
  * Converts HSL values to RGB values
847
864
  *
@@ -957,102 +974,6 @@
957
974
  * TODO: Maybe implement by mix+hsl
958
975
  */
959
976
 
960
- /**
961
- * Calculates distance between two colors
962
- *
963
- * @param color1 first color
964
- * @param color2 second color
965
- *
966
- * Note: This function is inefficient. Use colorDistanceSquared instead if possible.
967
- *
968
- * @public exported from `@promptbook/color`
969
- */
970
- /**
971
- * Calculates distance between two colors without square root
972
- *
973
- * @param color1 first color
974
- * @param color2 second color
975
- *
976
- * @public exported from `@promptbook/color`
977
- */
978
- function colorDistanceSquared(color1, color2) {
979
- const rmean = (color1.red + color2.red) / 2;
980
- const r = color1.red - color2.red;
981
- const g = color1.green - color2.green;
982
- const b = color1.blue - color2.blue;
983
- const weightR = 2 + rmean / 256;
984
- const weightG = 4.0;
985
- const weightB = 2 + (255 - rmean) / 256;
986
- const distance = weightR * r * r + weightG * g * g + weightB * b * b;
987
- return distance;
988
- }
989
-
990
- /**
991
- * Makes color transformer which finds the nearest color from the given list
992
- *
993
- * @param colors array of colors to choose from
994
- *
995
- * @public exported from `@promptbook/color`
996
- */
997
- function nearest(...colors) {
998
- return (color) => {
999
- const distances = colors.map((c) => colorDistanceSquared(c, color));
1000
- const minDistance = Math.min(...distances);
1001
- const minIndex = distances.indexOf(minDistance);
1002
- const nearestColor = colors[minIndex];
1003
- return nearestColor;
1004
- };
1005
- }
1006
-
1007
- /**
1008
- * Color transformer which returns the negative color
1009
- *
1010
- * @public exported from `@promptbook/color`
1011
- */
1012
- function negative(color) {
1013
- const r = 255 - color.red;
1014
- const g = 255 - color.green;
1015
- const b = 255 - color.blue;
1016
- return Color.fromValues(r, g, b, color.alpha);
1017
- }
1018
-
1019
- /**
1020
- * Makes color transformer which finds the furthest color from the given list
1021
- *
1022
- * @param colors array of colors to choose from
1023
- *
1024
- * @public exported from `@promptbook/color`
1025
- */
1026
- function furthest(...colors) {
1027
- return (color) => {
1028
- const furthestColor = negative(nearest(...colors.map(negative))(color));
1029
- return furthestColor;
1030
- };
1031
- }
1032
- /**
1033
- * Makes color transformer which finds the best text color (black or white) for the given background color
1034
- *
1035
- * @public exported from `@promptbook/color`
1036
- */
1037
- furthest(Color.get('white'), Color.from('black'));
1038
-
1039
- /**
1040
- * Makes color transformer which returns a grayscale version of the color
1041
- *
1042
- * @param amount from 0 to 1
1043
- *
1044
- * @public exported from `@promptbook/color`
1045
- */
1046
- function grayscale(amount) {
1047
- return ({ red, green, blue, alpha }) => {
1048
- const average = (red + green + blue) / 3;
1049
- red = Math.round(average * amount + red * (1 - amount));
1050
- green = Math.round(average * amount + green * (1 - amount));
1051
- blue = Math.round(average * amount + blue * (1 - amount));
1052
- return Color.fromValues(red, green, blue, alpha);
1053
- };
1054
- }
1055
-
1056
977
  /**
1057
978
  * Makes color transformer which saturate the given color
1058
979
  *
@@ -1462,6 +1383,19 @@
1462
1383
  /**/
1463
1384
  // Note: In normal situations, we check the pipeline logic:
1464
1385
  true);
1386
+ /**
1387
+ * Indicates whether cost-prevention is enabled. When true, real API keys are prevented from being used in tests.
1388
+ *
1389
+ * @private within the repository
1390
+ */
1391
+ const IS_COST_PREVENTED = just(
1392
+ /*/
1393
+ // Note: In normal situations, we prevent ability to use real API keys in tests:
1394
+ true,
1395
+ /**/
1396
+ /**/
1397
+ // When working on preparations, you can temporarily turn off the prevention:
1398
+ false);
1465
1399
  /**
1466
1400
  * Note: [💞] Ignore a discrepancy between file name and entity name
1467
1401
  * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
@@ -1518,7 +1452,7 @@
1518
1452
  */
1519
1453
  class UnexpectedError extends Error {
1520
1454
  constructor(message) {
1521
- super(spaceTrim.spaceTrim((block) => `
1455
+ super(spaceTrim$1.spaceTrim((block) => `
1522
1456
  ${block(message)}
1523
1457
 
1524
1458
  Note: This error should not happen.
@@ -1544,7 +1478,7 @@
1544
1478
  constructor(whatWasThrown) {
1545
1479
  const tag = `[🤮]`;
1546
1480
  console.error(tag, whatWasThrown);
1547
- super(spaceTrim.spaceTrim(`
1481
+ super(spaceTrim$1.spaceTrim(`
1548
1482
  Non-Error object was thrown
1549
1483
 
1550
1484
  Note: Look for ${tag} in the console for more details
@@ -2257,7 +2191,7 @@
2257
2191
  if (!(error instanceof PipelineLogicError)) {
2258
2192
  throw error;
2259
2193
  }
2260
- console.error(spaceTrim.spaceTrim((block) => `
2194
+ console.error(spaceTrim$1.spaceTrim((block) => `
2261
2195
  Pipeline is not valid but logic errors are temporarily disabled via \`IS_PIPELINE_LOGIC_VALIDATED\`
2262
2196
 
2263
2197
  ${block(error.message)}
@@ -2284,7 +2218,7 @@
2284
2218
  })();
2285
2219
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
2286
2220
  // <- Note: [🚲]
2287
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2221
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2288
2222
  Invalid promptbook URL "${pipeline.pipelineUrl}"
2289
2223
 
2290
2224
  ${block(pipelineIdentification)}
@@ -2292,7 +2226,7 @@
2292
2226
  }
2293
2227
  if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
2294
2228
  // <- Note: [🚲]
2295
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2229
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2296
2230
  Invalid Promptbook Version "${pipeline.bookVersion}"
2297
2231
 
2298
2232
  ${block(pipelineIdentification)}
@@ -2301,7 +2235,7 @@
2301
2235
  // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
2302
2236
  if (!Array.isArray(pipeline.parameters)) {
2303
2237
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2304
- throw new ParseError(spaceTrim.spaceTrim((block) => `
2238
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
2305
2239
  Pipeline is valid JSON but with wrong structure
2306
2240
 
2307
2241
  \`PipelineJson.parameters\` expected to be an array, but got ${typeof pipeline.parameters}
@@ -2312,7 +2246,7 @@
2312
2246
  // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
2313
2247
  if (!Array.isArray(pipeline.tasks)) {
2314
2248
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2315
- throw new ParseError(spaceTrim.spaceTrim((block) => `
2249
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
2316
2250
  Pipeline is valid JSON but with wrong structure
2317
2251
 
2318
2252
  \`PipelineJson.tasks\` expected to be an array, but got ${typeof pipeline.tasks}
@@ -2338,7 +2272,7 @@
2338
2272
  // Note: Check each parameter individually
2339
2273
  for (const parameter of pipeline.parameters) {
2340
2274
  if (parameter.isInput && parameter.isOutput) {
2341
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2275
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2342
2276
 
2343
2277
  Parameter \`{${parameter.name}}\` can not be both input and output
2344
2278
 
@@ -2349,7 +2283,7 @@
2349
2283
  if (!parameter.isInput &&
2350
2284
  !parameter.isOutput &&
2351
2285
  !pipeline.tasks.some((task) => task.dependentParameterNames.includes(parameter.name))) {
2352
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2286
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2353
2287
  Parameter \`{${parameter.name}}\` is created but not used
2354
2288
 
2355
2289
  You can declare {${parameter.name}} as output parameter by adding in the header:
@@ -2361,7 +2295,7 @@
2361
2295
  }
2362
2296
  // Note: Testing that parameter is either input or result of some task
2363
2297
  if (!parameter.isInput && !pipeline.tasks.some((task) => task.resultingParameterName === parameter.name)) {
2364
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2298
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2365
2299
  Parameter \`{${parameter.name}}\` is declared but not defined
2366
2300
 
2367
2301
  You can do one of these:
@@ -2377,14 +2311,14 @@
2377
2311
  // Note: Checking each task individually
2378
2312
  for (const task of pipeline.tasks) {
2379
2313
  if (definedParameters.has(task.resultingParameterName)) {
2380
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2314
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2381
2315
  Parameter \`{${task.resultingParameterName}}\` is defined multiple times
2382
2316
 
2383
2317
  ${block(pipelineIdentification)}
2384
2318
  `));
2385
2319
  }
2386
2320
  if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
2387
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2321
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2388
2322
  Parameter name {${task.resultingParameterName}} is reserved, please use different name
2389
2323
 
2390
2324
  ${block(pipelineIdentification)}
@@ -2394,7 +2328,7 @@
2394
2328
  if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
2395
2329
  if (!task.format &&
2396
2330
  !task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
2397
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2331
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2398
2332
  Joker parameters are used for {${task.resultingParameterName}} but no expectations are defined
2399
2333
 
2400
2334
  ${block(pipelineIdentification)}
@@ -2402,7 +2336,7 @@
2402
2336
  }
2403
2337
  for (const joker of task.jokerParameterNames) {
2404
2338
  if (!task.dependentParameterNames.includes(joker)) {
2405
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2339
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2406
2340
  Parameter \`{${joker}}\` is used for {${task.resultingParameterName}} as joker but not in \`dependentParameterNames\`
2407
2341
 
2408
2342
  ${block(pipelineIdentification)}
@@ -2413,21 +2347,21 @@
2413
2347
  if (task.expectations) {
2414
2348
  for (const [unit, { min, max }] of Object.entries(task.expectations)) {
2415
2349
  if (min !== undefined && max !== undefined && min > max) {
2416
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2350
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2417
2351
  Min expectation (=${min}) of ${unit} is higher than max expectation (=${max})
2418
2352
 
2419
2353
  ${block(pipelineIdentification)}
2420
2354
  `));
2421
2355
  }
2422
2356
  if (min !== undefined && min < 0) {
2423
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2357
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2424
2358
  Min expectation of ${unit} must be zero or positive
2425
2359
 
2426
2360
  ${block(pipelineIdentification)}
2427
2361
  `));
2428
2362
  }
2429
2363
  if (max !== undefined && max <= 0) {
2430
- throw new PipelineLogicError(spaceTrim.spaceTrim((block) => `
2364
+ throw new PipelineLogicError(spaceTrim$1.spaceTrim((block) => `
2431
2365
  Max expectation of ${unit} must be positive
2432
2366
 
2433
2367
  ${block(pipelineIdentification)}
@@ -2449,7 +2383,7 @@
2449
2383
  while (unresovedTasks.length > 0) {
2450
2384
  if (loopLimit-- < 0) {
2451
2385
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
2452
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
2386
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
2453
2387
  Loop limit reached during detection of circular dependencies in \`validatePipeline\`
2454
2388
 
2455
2389
  ${block(pipelineIdentification)}
@@ -2459,7 +2393,7 @@
2459
2393
  if (currentlyResovedTasks.length === 0) {
2460
2394
  throw new PipelineLogicError(
2461
2395
  // TODO: [🐎] DRY
2462
- spaceTrim.spaceTrim((block) => `
2396
+ spaceTrim$1.spaceTrim((block) => `
2463
2397
 
2464
2398
  Can not resolve some parameters:
2465
2399
  Either you are using a parameter that is not defined, or there are some circular dependencies.
@@ -2623,7 +2557,7 @@
2623
2557
  for (const pipeline of pipelines) {
2624
2558
  // TODO: [👠] DRY
2625
2559
  if (pipeline.pipelineUrl === undefined) {
2626
- throw new PipelineUrlError(spaceTrim.spaceTrim(`
2560
+ throw new PipelineUrlError(spaceTrim$1.spaceTrim(`
2627
2561
  Pipeline with name "${pipeline.title}" does not have defined URL
2628
2562
 
2629
2563
  File:
@@ -2645,7 +2579,7 @@
2645
2579
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
2646
2580
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
2647
2581
  const existing = this.collection.get(pipeline.pipelineUrl);
2648
- throw new PipelineUrlError(spaceTrim.spaceTrim(`
2582
+ throw new PipelineUrlError(spaceTrim$1.spaceTrim(`
2649
2583
  Pipeline with URL ${pipeline.pipelineUrl} is already in the collection 🍎
2650
2584
 
2651
2585
  Conflicting files:
@@ -2677,13 +2611,13 @@
2677
2611
  const pipeline = this.collection.get(url);
2678
2612
  if (!pipeline) {
2679
2613
  if (this.listPipelines().length === 0) {
2680
- throw new NotFoundError(spaceTrim.spaceTrim(`
2614
+ throw new NotFoundError(spaceTrim$1.spaceTrim(`
2681
2615
  Pipeline with url "${url}" not found
2682
2616
 
2683
2617
  No pipelines available
2684
2618
  `));
2685
2619
  }
2686
- throw new NotFoundError(spaceTrim.spaceTrim((block) => `
2620
+ throw new NotFoundError(spaceTrim$1.spaceTrim((block) => `
2687
2621
  Pipeline with url "${url}" not found
2688
2622
 
2689
2623
  Available pipelines:
@@ -2724,7 +2658,7 @@
2724
2658
  */
2725
2659
  class MissingToolsError extends Error {
2726
2660
  constructor(message) {
2727
- super(spaceTrim.spaceTrim((block) => `
2661
+ super(spaceTrim$1.spaceTrim((block) => `
2728
2662
  ${block(message)}
2729
2663
 
2730
2664
  Note: You have probably forgot to provide some tools for pipeline execution or preparation
@@ -2831,6 +2765,19 @@
2831
2765
  }
2832
2766
  }
2833
2767
 
2768
+ /**
2769
+ * This error indicates error from the database
2770
+ *
2771
+ * @public exported from `@promptbook/core`
2772
+ */
2773
+ class DatabaseError extends Error {
2774
+ constructor(message) {
2775
+ super(message);
2776
+ this.name = 'DatabaseError';
2777
+ Object.setPrototypeOf(this, DatabaseError.prototype);
2778
+ }
2779
+ }
2780
+
2834
2781
  /**
2835
2782
  * This error type indicates that you try to use a feature that is not available in the current environment
2836
2783
  *
@@ -2906,7 +2853,7 @@
2906
2853
  */
2907
2854
  class NotYetImplementedError extends Error {
2908
2855
  constructor(message) {
2909
- super(spaceTrim.spaceTrim((block) => `
2856
+ super(spaceTrim$1.spaceTrim((block) => `
2910
2857
  ${block(message)}
2911
2858
 
2912
2859
  Note: This feature is not implemented yet but it will be soon.
@@ -2925,6 +2872,7 @@
2925
2872
  /**
2926
2873
  * Generates random token
2927
2874
  *
2875
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
2928
2876
  * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
2929
2877
  *
2930
2878
  * @private internal helper function
@@ -2994,6 +2942,7 @@
2994
2942
  UnexpectedError,
2995
2943
  WrappedError,
2996
2944
  NotAllowed,
2945
+ DatabaseError,
2997
2946
  // TODO: [🪑]> VersionMismatchError,
2998
2947
  };
2999
2948
  /**
@@ -3178,11 +3127,11 @@
3178
3127
  throw deserializeError(errors[0]);
3179
3128
  }
3180
3129
  else {
3181
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
3130
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
3182
3131
  Multiple errors occurred during Promptbook execution
3183
3132
 
3184
3133
  ${block(errors
3185
- .map(({ name, stack, message }, index) => spaceTrim.spaceTrim((block) => `
3134
+ .map(({ name, stack, message }, index) => spaceTrim$1.spaceTrim((block) => `
3186
3135
  ${name} ${index + 1}:
3187
3136
  ${block(stack || message)}
3188
3137
  `))
@@ -4908,7 +4857,7 @@
4908
4857
  if (task.taskType === 'PROMPT_TASK' &&
4909
4858
  knowledgePiecesCount > 0 &&
4910
4859
  !dependentParameterNames.includes('knowledge')) {
4911
- preparedContent = spaceTrim.spaceTrim(`
4860
+ preparedContent = spaceTrim$1.spaceTrim(`
4912
4861
  {content}
4913
4862
 
4914
4863
  ## Knowledge
@@ -5221,7 +5170,7 @@
5221
5170
  }
5222
5171
  catch (error) {
5223
5172
  assertsError(error);
5224
- throw new ParseError(spaceTrim.spaceTrim((block) => `
5173
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
5225
5174
  Can not extract variables from the script
5226
5175
  ${block(error.stack || error.message)}
5227
5176
 
@@ -5777,18 +5726,6 @@
5777
5726
  return replacedTemplates;
5778
5727
  }
5779
5728
 
5780
- /**
5781
- * Logs an LLM call with the given report.
5782
- *
5783
- * @private internal utility of `createPipelineExecutor`
5784
- */
5785
- function logLlmCall(logLlmCall, report) {
5786
- logLlmCall({
5787
- modelName: 'model' /* <- TODO: How to get model name from the report */,
5788
- report,
5789
- });
5790
- }
5791
-
5792
5729
  /**
5793
5730
  * Extracts all code blocks from markdown.
5794
5731
  *
@@ -6107,7 +6044,7 @@
6107
6044
  }
6108
6045
  catch (error) {
6109
6046
  keepUnused(error);
6110
- throw new ExpectError(spaceTrim.spaceTrim((block) => `
6047
+ throw new ExpectError(spaceTrim$1.spaceTrim((block) => `
6111
6048
  Expected valid JSON string
6112
6049
 
6113
6050
  The expected JSON text:
@@ -6156,7 +6093,7 @@
6156
6093
  */
6157
6094
  async function executeAttempts(options) {
6158
6095
  const { jokerParameterNames, priority, maxAttempts, // <- Note: [💂]
6159
- preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall: logLlmCall$1, } = options;
6096
+ preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall, } = options;
6160
6097
  const $ongoingTaskResult = {
6161
6098
  $result: null,
6162
6099
  $resultString: null,
@@ -6170,7 +6107,7 @@
6170
6107
  const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
6171
6108
  // TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
6172
6109
  if (isJokerAttempt && !jokerParameterName) {
6173
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
6110
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
6174
6111
  Joker not found in attempt ${attemptIndex}
6175
6112
 
6176
6113
  ${block(pipelineIdentification)}
@@ -6181,7 +6118,7 @@
6181
6118
  $ongoingTaskResult.$expectError = null;
6182
6119
  if (isJokerAttempt) {
6183
6120
  if (parameters[jokerParameterName] === undefined) {
6184
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6121
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6185
6122
  Joker parameter {${jokerParameterName}} not defined
6186
6123
 
6187
6124
  ${block(pipelineIdentification)}
@@ -6239,7 +6176,7 @@
6239
6176
  $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
6240
6177
  break variant;
6241
6178
  case 'EMBEDDING':
6242
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6179
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6243
6180
  Embedding model can not be used in pipeline
6244
6181
 
6245
6182
  This should be catched during parsing
@@ -6250,7 +6187,7 @@
6250
6187
  break variant;
6251
6188
  // <- case [🤖]:
6252
6189
  default:
6253
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6190
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6254
6191
  Unknown model variant "${task.modelRequirements.modelVariant}"
6255
6192
 
6256
6193
  ${block(pipelineIdentification)}
@@ -6261,14 +6198,14 @@
6261
6198
  break;
6262
6199
  case 'SCRIPT_TASK':
6263
6200
  if (arrayableToArray(tools.script).length === 0) {
6264
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6201
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6265
6202
  No script execution tools are available
6266
6203
 
6267
6204
  ${block(pipelineIdentification)}
6268
6205
  `));
6269
6206
  }
6270
6207
  if (!task.contentLanguage) {
6271
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6208
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6272
6209
  Script language is not defined for SCRIPT TASK "${task.name}"
6273
6210
 
6274
6211
  ${block(pipelineIdentification)}
@@ -6299,7 +6236,7 @@
6299
6236
  throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
6300
6237
  }
6301
6238
  else {
6302
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6239
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6303
6240
  Script execution failed ${$ongoingTaskResult.$scriptPipelineExecutionErrors.length}x
6304
6241
 
6305
6242
  ${block(pipelineIdentification)}
@@ -6313,7 +6250,7 @@
6313
6250
  break taskType;
6314
6251
  case 'DIALOG_TASK':
6315
6252
  if (tools.userInterface === undefined) {
6316
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6253
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6317
6254
  User interface tools are not available
6318
6255
 
6319
6256
  ${block(pipelineIdentification)}
@@ -6331,7 +6268,7 @@
6331
6268
  break taskType;
6332
6269
  // <- case: [🅱]
6333
6270
  default:
6334
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6271
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6335
6272
  Unknown execution type "${task.taskType}"
6336
6273
 
6337
6274
  ${block(pipelineIdentification)}
@@ -6418,15 +6355,18 @@
6418
6355
  : serializeError($ongoingTaskResult.$expectError),
6419
6356
  };
6420
6357
  $executionReport.promptExecutions.push(executionPromptReport);
6421
- if (logLlmCall$1) {
6422
- logLlmCall(logLlmCall$1, executionPromptReport);
6358
+ if (logLlmCall) {
6359
+ logLlmCall({
6360
+ modelName: 'model' /* <- TODO: How to get model name from the report */,
6361
+ report: executionPromptReport,
6362
+ });
6423
6363
  }
6424
6364
  }
6425
6365
  }
6426
6366
  if ($ongoingTaskResult.$expectError !== null && attemptIndex === maxAttempts - 1) {
6427
6367
  // Note: Create a summary of all failures
6428
6368
  const failuresSummary = $ongoingTaskResult.$failedResults
6429
- .map((failure) => spaceTrim.spaceTrim((block) => {
6369
+ .map((failure) => spaceTrim$1.spaceTrim((block) => {
6430
6370
  var _a, _b;
6431
6371
  return `
6432
6372
  Attempt ${failure.attemptIndex + 1}:
@@ -6436,14 +6376,14 @@
6436
6376
  Result:
6437
6377
  ${block(failure.result === null
6438
6378
  ? 'null'
6439
- : spaceTrim.spaceTrim(failure.result)
6379
+ : spaceTrim$1.spaceTrim(failure.result)
6440
6380
  .split('\n')
6441
6381
  .map((line) => `> ${line}`)
6442
6382
  .join('\n'))}
6443
6383
  `;
6444
6384
  }))
6445
6385
  .join('\n\n---\n\n');
6446
- throw new PipelineExecutionError(spaceTrim.spaceTrim((block) => {
6386
+ throw new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => {
6447
6387
  var _a;
6448
6388
  return `
6449
6389
  LLM execution failed ${maxExecutionAttempts}x
@@ -6463,7 +6403,7 @@
6463
6403
  }
6464
6404
  }
6465
6405
  if ($ongoingTaskResult.$resultString === null) {
6466
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
6406
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
6467
6407
  Something went wrong and prompt result is null
6468
6408
 
6469
6409
  ${block(pipelineIdentification)}
@@ -6693,7 +6633,7 @@
6693
6633
  },
6694
6634
  content: task.content,
6695
6635
  parameters,
6696
- };
6636
+ }; /* <- Note: [🤛] */
6697
6637
  const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
6698
6638
  const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
6699
6639
  const { index } = knowledgePiece;
@@ -6769,7 +6709,7 @@
6769
6709
  // Note: Doublecheck that ALL reserved parameters are defined:
6770
6710
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
6771
6711
  if (reservedParameters[parameterName] === undefined) {
6772
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
6712
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
6773
6713
  Reserved parameter {${parameterName}} is not defined
6774
6714
 
6775
6715
  ${block(pipelineIdentification)}
@@ -6795,7 +6735,7 @@
6795
6735
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
6796
6736
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
6797
6737
  if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
6798
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
6738
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
6799
6739
  Dependent parameters are not consistent with used parameters:
6800
6740
 
6801
6741
  Dependent parameters:
@@ -6839,7 +6779,7 @@
6839
6779
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
6840
6780
  // Houston, we have a problem
6841
6781
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
6842
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
6782
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
6843
6783
  Parameter \`{${parameterName}}\` is NOT defined
6844
6784
  BUT used in task "${currentTask.title || currentTask.name}"
6845
6785
 
@@ -6908,7 +6848,7 @@
6908
6848
  for (const parameter of preparedPipeline.parameters.filter(({ isOutput }) => isOutput)) {
6909
6849
  if (parametersToPass[parameter.name] === undefined) {
6910
6850
  // [4]
6911
- $warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6851
+ $warnings.push(new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
6912
6852
  Parameter \`{${parameter.name}}\` should be an output parameter, but it was not generated during pipeline execution
6913
6853
 
6914
6854
  Note: This is a warning which happened after the pipeline was executed, and \`{${parameter.name}}\` was not for some reason defined in output parameters
@@ -7016,7 +6956,7 @@
7016
6956
  for (const parameterName of Object.keys(inputParameters)) {
7017
6957
  const parameter = preparedPipeline.parameters.find(({ name }) => name === parameterName);
7018
6958
  if (parameter === undefined) {
7019
- warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6959
+ warnings.push(new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
7020
6960
  Extra parameter {${parameterName}} is being passed which is not part of the pipeline.
7021
6961
 
7022
6962
  ${block(pipelineIdentification)}
@@ -7031,7 +6971,7 @@
7031
6971
  // TODO: [🧠] This should be also non-critical error
7032
6972
  return exportJson({
7033
6973
  name: 'pipelineExecutorResult',
7034
- message: spaceTrim.spaceTrim((block) => `
6974
+ message: spaceTrim$1.spaceTrim((block) => `
7035
6975
  Unsuccessful PipelineExecutorResult (with extra parameter {${parameter.name}}) PipelineExecutorResult
7036
6976
 
7037
6977
  ${block(pipelineIdentification)}
@@ -7040,7 +6980,7 @@
7040
6980
  value: {
7041
6981
  isSuccessful: false,
7042
6982
  errors: [
7043
- new PipelineExecutionError(spaceTrim.spaceTrim((block) => `
6983
+ new PipelineExecutionError(spaceTrim$1.spaceTrim((block) => `
7044
6984
  Parameter \`{${parameter.name}}\` is passed as input parameter but it is not input
7045
6985
 
7046
6986
  ${block(pipelineIdentification)}
@@ -7067,7 +7007,7 @@
7067
7007
  while (unresovedTasks.length > 0) {
7068
7008
  if (loopLimit-- < 0) {
7069
7009
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
7070
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
7010
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
7071
7011
  Loop limit reached during resolving parameters pipeline execution
7072
7012
 
7073
7013
  ${block(pipelineIdentification)}
@@ -7077,7 +7017,7 @@
7077
7017
  if (!currentTask && resolving.length === 0) {
7078
7018
  throw new UnexpectedError(
7079
7019
  // TODO: [🐎] DRY
7080
- spaceTrim.spaceTrim((block) => `
7020
+ spaceTrim$1.spaceTrim((block) => `
7081
7021
  Can not resolve some parameters:
7082
7022
 
7083
7023
  ${block(pipelineIdentification)}
@@ -7117,7 +7057,7 @@
7117
7057
  tools,
7118
7058
  onProgress(newOngoingResult) {
7119
7059
  if (isReturned) {
7120
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
7060
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
7121
7061
  Can not call \`onProgress\` after pipeline execution is finished
7122
7062
 
7123
7063
  ${block(pipelineIdentification)}
@@ -7134,7 +7074,7 @@
7134
7074
  },
7135
7075
  logLlmCall,
7136
7076
  $executionReport: executionReport,
7137
- pipelineIdentification: spaceTrim.spaceTrim((block) => `
7077
+ pipelineIdentification: spaceTrim$1.spaceTrim((block) => `
7138
7078
  ${block(pipelineIdentification)}
7139
7079
  Task name: ${currentTask.name}
7140
7080
  Task title: ${currentTask.title}
@@ -7243,7 +7183,7 @@
7243
7183
  preparedPipeline = pipeline;
7244
7184
  }
7245
7185
  else if (isNotPreparedWarningSuppressed !== true) {
7246
- console.warn(spaceTrim.spaceTrim((block) => `
7186
+ console.warn(spaceTrim$1.spaceTrim((block) => `
7247
7187
  Pipeline is not prepared
7248
7188
 
7249
7189
  ${block(pipelineIdentification)}
@@ -7268,7 +7208,7 @@
7268
7208
  tools,
7269
7209
  onProgress,
7270
7210
  logLlmCall,
7271
- pipelineIdentification: spaceTrim.spaceTrim((block) => `
7211
+ pipelineIdentification: spaceTrim$1.spaceTrim((block) => `
7272
7212
  ${block(pipelineIdentification)}
7273
7213
  ${runCount === 1 ? '' : `Run #${runCount}`}
7274
7214
  `),
@@ -7599,7 +7539,7 @@
7599
7539
  * Markdown documentation for ACTION commitment.
7600
7540
  */
7601
7541
  get documentation() {
7602
- return spaceTrim.spaceTrim(`
7542
+ return spaceTrim$1.spaceTrim(`
7603
7543
  # ${this.type}
7604
7544
 
7605
7545
  Defines specific actions or capabilities that the agent can perform.
@@ -7678,7 +7618,7 @@
7678
7618
  * Markdown documentation for DELETE commitment.
7679
7619
  */
7680
7620
  get documentation() {
7681
- return spaceTrim.spaceTrim(`
7621
+ return spaceTrim$1.spaceTrim(`
7682
7622
  # DELETE (CANCEL, DISCARD, REMOVE)
7683
7623
 
7684
7624
  A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
@@ -7794,7 +7734,7 @@
7794
7734
  * Markdown documentation for FORMAT commitment.
7795
7735
  */
7796
7736
  get documentation() {
7797
- return spaceTrim.spaceTrim(`
7737
+ return spaceTrim$1.spaceTrim(`
7798
7738
  # ${this.type}
7799
7739
 
7800
7740
  Defines the specific output structure and formatting for responses (data formats, templates, structure).
@@ -7869,7 +7809,7 @@
7869
7809
  * Markdown documentation for GOAL commitment.
7870
7810
  */
7871
7811
  get documentation() {
7872
- return spaceTrim.spaceTrim(`
7812
+ return spaceTrim$1.spaceTrim(`
7873
7813
  # ${this.type}
7874
7814
 
7875
7815
  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.
@@ -7965,7 +7905,7 @@
7965
7905
  * Markdown documentation for KNOWLEDGE commitment.
7966
7906
  */
7967
7907
  get documentation() {
7968
- return spaceTrim.spaceTrim(`
7908
+ return spaceTrim$1.spaceTrim(`
7969
7909
  # ${this.type}
7970
7910
 
7971
7911
  Adds specific knowledge, facts, or context to the agent using a RAG (Retrieval-Augmented Generation) approach for external sources.
@@ -8082,7 +8022,7 @@
8082
8022
  * Markdown documentation for MEMORY commitment.
8083
8023
  */
8084
8024
  get documentation() {
8085
- return spaceTrim.spaceTrim(`
8025
+ return spaceTrim$1.spaceTrim(`
8086
8026
  # ${this.type}
8087
8027
 
8088
8028
  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.
@@ -8184,7 +8124,7 @@
8184
8124
  * Markdown documentation for MESSAGE commitment.
8185
8125
  */
8186
8126
  get documentation() {
8187
- return spaceTrim.spaceTrim(`
8127
+ return spaceTrim$1.spaceTrim(`
8188
8128
  # ${this.type}
8189
8129
 
8190
8130
  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.
@@ -8302,7 +8242,7 @@
8302
8242
  * Markdown documentation for META commitment.
8303
8243
  */
8304
8244
  get documentation() {
8305
- return spaceTrim.spaceTrim(`
8245
+ return spaceTrim$1.spaceTrim(`
8306
8246
  # META
8307
8247
 
8308
8248
  Sets meta-information about the agent that is used for display and attribution purposes.
@@ -8438,7 +8378,7 @@
8438
8378
  * Markdown documentation for MODEL commitment.
8439
8379
  */
8440
8380
  get documentation() {
8441
- return spaceTrim.spaceTrim(`
8381
+ return spaceTrim$1.spaceTrim(`
8442
8382
  # ${this.type}
8443
8383
 
8444
8384
  Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
@@ -8673,7 +8613,7 @@
8673
8613
  * Markdown documentation for NOTE commitment.
8674
8614
  */
8675
8615
  get documentation() {
8676
- return spaceTrim.spaceTrim(`
8616
+ return spaceTrim$1.spaceTrim(`
8677
8617
  # ${this.type}
8678
8618
 
8679
8619
  Adds comments for documentation without changing agent behavior.
@@ -8775,7 +8715,7 @@
8775
8715
  * Markdown documentation for PERSONA commitment.
8776
8716
  */
8777
8717
  get documentation() {
8778
- return spaceTrim.spaceTrim(`
8718
+ return spaceTrim$1.spaceTrim(`
8779
8719
  # ${this.type}
8780
8720
 
8781
8721
  Defines who the agent is, their background, expertise, and personality traits.
@@ -8901,7 +8841,7 @@
8901
8841
  * Markdown documentation for RULE/RULES commitment.
8902
8842
  */
8903
8843
  get documentation() {
8904
- return spaceTrim.spaceTrim(`
8844
+ return spaceTrim$1.spaceTrim(`
8905
8845
  # ${this.type}
8906
8846
 
8907
8847
  Adds behavioral constraints and guidelines that the agent must follow.
@@ -8977,7 +8917,7 @@
8977
8917
  * Markdown documentation for SAMPLE/EXAMPLE commitment.
8978
8918
  */
8979
8919
  get documentation() {
8980
- return spaceTrim.spaceTrim(`
8920
+ return spaceTrim$1.spaceTrim(`
8981
8921
  # ${this.type}
8982
8922
 
8983
8923
  Provides examples of how the agent should respond or behave in certain situations.
@@ -9054,7 +8994,7 @@
9054
8994
  * Markdown documentation for SCENARIO commitment.
9055
8995
  */
9056
8996
  get documentation() {
9057
- return spaceTrim.spaceTrim(`
8997
+ return spaceTrim$1.spaceTrim(`
9058
8998
  # ${this.type}
9059
8999
 
9060
9000
  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.
@@ -9170,7 +9110,7 @@
9170
9110
  * Markdown documentation for STYLE commitment.
9171
9111
  */
9172
9112
  get documentation() {
9173
- return spaceTrim.spaceTrim(`
9113
+ return spaceTrim$1.spaceTrim(`
9174
9114
  # ${this.type}
9175
9115
 
9176
9116
  Defines how the agent should format and present its responses (tone, writing style, formatting).
@@ -9239,7 +9179,7 @@
9239
9179
  * Markdown documentation available at runtime.
9240
9180
  */
9241
9181
  get documentation() {
9242
- return spaceTrim.spaceTrim(`
9182
+ return spaceTrim$1.spaceTrim(`
9243
9183
  # ${this.type}
9244
9184
 
9245
9185
  This commitment is not yet fully implemented.
@@ -9413,7 +9353,7 @@
9413
9353
  const fullContent = currentCommitment.contentLines.join('\n');
9414
9354
  commitments.push({
9415
9355
  type: currentCommitment.type,
9416
- content: spaceTrim.spaceTrim(fullContent),
9356
+ content: spaceTrim$1.spaceTrim(fullContent),
9417
9357
  originalLine: currentCommitment.originalStartLine,
9418
9358
  lineNumber: currentCommitment.startLineNumber,
9419
9359
  });
@@ -9449,7 +9389,7 @@
9449
9389
  const fullContent = currentCommitment.contentLines.join('\n');
9450
9390
  commitments.push({
9451
9391
  type: currentCommitment.type,
9452
- content: spaceTrim.spaceTrim(fullContent),
9392
+ content: spaceTrim$1.spaceTrim(fullContent),
9453
9393
  originalLine: currentCommitment.originalStartLine,
9454
9394
  lineNumber: currentCommitment.startLineNumber,
9455
9395
  });
@@ -9933,6 +9873,7 @@
9933
9873
  /**
9934
9874
  * Default book
9935
9875
  *
9876
+ * @deprecated Use `$generateBookBoilerplate` instead
9936
9877
  * @public exported from `@promptbook/core`
9937
9878
  */
9938
9879
  const DEFAULT_BOOK = padBook(validateBook(spaceTrim__default["default"](`
@@ -9941,9 +9882,180 @@
9941
9882
  PERSONA A friendly AI assistant that helps you with your tasks
9942
9883
  `)));
9943
9884
  // <- Note: Not using book`...` notation to avoid strange error in jest unit tests `TypeError: (0 , book_notation_1.book) is not a function`
9944
- // <- TODO: !!! GENESIS_BOOK
9885
+ // <- TODO: !!! `GENESIS_BOOK` / `ADAM_BOOK` in `/agents/adam.book`
9945
9886
  // <- !!! Buttons into genesis book
9946
- // <- TODO: !!! createBookBoilerplate and deprecate `DEFAULT_BOOK`
9887
+ // <- TODO: !!! generateBookBoilerplate and deprecate `DEFAULT_BOOK`
9888
+
9889
+ /**
9890
+ * Trims string from all 4 sides
9891
+ *
9892
+ * Note: This is a re-exported function from the `spacetrim` package which is
9893
+ * Developed by same author @hejny as this package
9894
+ *
9895
+ * @public exported from `@promptbook/utils`
9896
+ * @see https://github.com/hejny/spacetrim#usage
9897
+ */
9898
+ const spaceTrim = spaceTrim$1.spaceTrim;
9899
+
9900
+ /**
9901
+ * Agent collection stored in Supabase table
9902
+ *
9903
+ * Note: This object can work both from Node.js and browser environment depending on the Supabase client provided
9904
+ *
9905
+ * @public exported from `@promptbook/core`
9906
+ * <- TODO: !!! Move to `@promptbook/supabase` package
9907
+ */
9908
+ class AgentCollectionInSupabase {
9909
+ /**
9910
+ * @param rootPath - path to the directory with agents
9911
+ * @param tools - Execution tools to be used in `Agent` itself and listing the agents
9912
+ * @param options - Options for the collection creation
9913
+ */
9914
+ constructor(supabaseClient, tools, options) {
9915
+ this.supabaseClient = supabaseClient;
9916
+ this.tools = tools;
9917
+ this.options = options;
9918
+ /**
9919
+ * Cached defined execution tools
9920
+ */
9921
+ this._definedTools = null;
9922
+ const { isVerbose = exports.DEFAULT_IS_VERBOSE } = options || {};
9923
+ if (isVerbose) {
9924
+ console.info(colors__default["default"].cyan(`Creating pipeline collection from supabase`));
9925
+ }
9926
+ }
9927
+ /*
9928
+ TODO: !!! Use or remove
9929
+ /**
9930
+ * Gets or creates execution tools for the collection
9931
+ * /
9932
+ private async getTools(): Promise<ExecutionTools> {
9933
+ if (this._definedTools !== null) {
9934
+ return this._definedTools;
9935
+ }
9936
+
9937
+ this._definedTools = {
9938
+ ...(this.tools === undefined || this.tools.fs === undefined ? await $provideExecutionToolsForNode() : {}),
9939
+ ...this.tools,
9940
+ };
9941
+ return this._definedTools;
9942
+ }
9943
+ // <- TODO: [👪] Maybe create some common abstraction *(or parent abstract class)*
9944
+ */
9945
+ /**
9946
+ * Gets all agents in the collection
9947
+ */
9948
+ async listAgents( /* TODO: [🧠] Allow to pass some condition here */) {
9949
+ const { isVerbose = exports.DEFAULT_IS_VERBOSE } = this.options || {};
9950
+ const result = await this.supabaseClient
9951
+ .from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
9952
+ .select('agentProfile');
9953
+ if (result.error) {
9954
+ throw new DatabaseError(spaceTrim((block) => `
9955
+
9956
+ Error fetching agents from Supabase:
9957
+
9958
+ ${block(result.error.message)}
9959
+ `));
9960
+ }
9961
+ if (isVerbose) {
9962
+ console.info(`Found ${result.data.length} agents in directory`);
9963
+ }
9964
+ return result.data.map((row) => row.agentProfile);
9965
+ }
9966
+ /**
9967
+ * !!!
9968
+ */
9969
+ async spawnAgent(agentName) {
9970
+ throw new NotYetImplementedError('Method not implemented.');
9971
+ /*
9972
+ // <- TODO: !!! ENOENT: no such file or directory, open 'C:\Users\me\work\ai\promptbook\agents\examples\Asistent pro LŠVP.book
9973
+ const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
9974
+ const tools = await this.getTools();
9975
+
9976
+ const agentSourceValue = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
9977
+ const agentSource = new BehaviorSubject(agentSourceValue);
9978
+
9979
+ // Note: Write file whenever agent source changes
9980
+ agentSource.subscribe(async (newSource) => {
9981
+ if (isVerbose) {
9982
+ console.info(colors.cyan(`Writing agent source to file ${agentSourcePath}`));
9983
+ }
9984
+ await forTime(500); // <- TODO: [🙌] !!! Remove
9985
+ await tools.fs!.writeFile(agentSourcePath, newSource, 'utf-8');
9986
+ });
9987
+
9988
+ // Note: Watch file for external changes
9989
+ for await (const event of tools.fs!.watch(agentSourcePath)) {
9990
+ // <- TODO: !!!! Solve the memory freeing when the watching is no longer needed
9991
+
9992
+ if (event.eventType !== 'change') {
9993
+ continue;
9994
+ }
9995
+
9996
+ if (isVerbose) {
9997
+ console.info(
9998
+ colors.cyan(`Detected external change in agent source file ${agentSourcePath}, reloading`),
9999
+ );
10000
+ }
10001
+ await forTime(500); // <- TODO: [🙌] !!! Remove
10002
+ const newSource = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
10003
+ agentSource.next(newSource);
10004
+ }
10005
+
10006
+ // TODO: [🙌] !!!! Debug the infinite loop when file is changed externally and agent source is updated which causes file to be written again
10007
+
10008
+ const agent = new Agent({
10009
+ ...this.options,
10010
+ agentSource,
10011
+ executionTools: this.tools || {},
10012
+ });
10013
+
10014
+ if (isVerbose) {
10015
+ console.info(colors.cyan(`Created agent "${agent.agentName}" from source file ${agentSourcePath}`));
10016
+ }
10017
+
10018
+ return agent;
10019
+ */
10020
+ }
10021
+ /**
10022
+ * Creates a new agent in the collection
10023
+ *
10024
+ * Note: You can set 'PARENT' in the agent source to inherit from another agent in the collection.
10025
+ */
10026
+ async createAgent(agentSource) {
10027
+ const agentProfile = parseAgentSource(agentSource);
10028
+ // <- TODO: [🕛]
10029
+ const result = await this.supabaseClient.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */).insert({
10030
+ agentName: agentProfile.agentName || '!!!!!' /* <- TODO: !!!! Remove */,
10031
+ agentProfile,
10032
+ createdAt: new Date().toISOString(),
10033
+ updatedAt: null,
10034
+ agentVersion: 0,
10035
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
10036
+ usage: ZERO_USAGE,
10037
+ agentSource: agentSource,
10038
+ });
10039
+ if (result.error) {
10040
+ throw new DatabaseError(spaceTrim((block) => `
10041
+ Error creating agent "${agentProfile.agentName}" in Supabase:
10042
+
10043
+ ${block(result.error.message)}
10044
+ `));
10045
+ }
10046
+ return agentProfile;
10047
+ }
10048
+ /**
10049
+ * Deletes an agent from the collection
10050
+ */
10051
+ async deleteAgent(agentName) {
10052
+ throw new NotYetImplementedError('Method not implemented.');
10053
+ }
10054
+ }
10055
+ /**
10056
+ * TODO: Write unit test
10057
+ * TODO: [🧠][🚙] `AgentXxx` vs `AgentsXxx` naming convention
10058
+ */
9947
10059
 
9948
10060
  /**
9949
10061
  * Constructs `PipelineCollection` from async sources
@@ -10042,7 +10154,7 @@
10042
10154
  }
10043
10155
  async function getPipelineByUrl(url) {
10044
10156
  if (!predicate(url)) {
10045
- throw new NotFoundError(await spaceTrim.spaceTrim(async (block) => `
10157
+ throw new NotFoundError(await spaceTrim$1.spaceTrim(async (block) => `
10046
10158
  Promptbook with url "${url}" not found or not accessible
10047
10159
 
10048
10160
  Available promptbooks:
@@ -12365,7 +12477,7 @@
12365
12477
  function getParserForCommand(command) {
12366
12478
  const commandParser = COMMANDS.find((commandParser) => commandParser.name === command.type);
12367
12479
  if (commandParser === undefined) {
12368
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
12480
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
12369
12481
  Command ${command.type} parser is not found
12370
12482
 
12371
12483
  ${block(JSON.stringify(command, null, 4)
@@ -12441,7 +12553,7 @@
12441
12553
  .map(removeMarkdownFormatting)
12442
12554
  .map((item) => item.trim());
12443
12555
  if (items.length === 0 || items[0] === '') {
12444
- throw new ParseError(spaceTrim.spaceTrim((block) => `
12556
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
12445
12557
  Malformed command:
12446
12558
  - ${raw}
12447
12559
 
@@ -12477,7 +12589,7 @@
12477
12589
  return command;
12478
12590
  }
12479
12591
  }
12480
- throw new ParseError(spaceTrim.spaceTrim((block) => `
12592
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
12481
12593
  Malformed or unknown command:
12482
12594
  - ${raw}
12483
12595
 
@@ -12528,7 +12640,7 @@
12528
12640
  if (!(error instanceof ParseError)) {
12529
12641
  throw error;
12530
12642
  }
12531
- throw new ParseError(spaceTrim.spaceTrim((block) => `
12643
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
12532
12644
  Invalid ${commandName} command:
12533
12645
 
12534
12646
  Your command:
@@ -12802,7 +12914,7 @@
12802
12914
  * @public exported from `@promptbook/markdown-utils`
12803
12915
  */
12804
12916
  function removeMarkdownComments(content) {
12805
- return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
12917
+ return spaceTrim$1.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
12806
12918
  }
12807
12919
 
12808
12920
  /**
@@ -13118,7 +13230,7 @@
13118
13230
  if (pipelineString.startsWith('#!')) {
13119
13231
  const [shebangLine, ...restLines] = pipelineString.split('\n');
13120
13232
  if (!(shebangLine || '').includes('ptbk')) {
13121
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13233
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13122
13234
  It seems that you try to parse a book file which has non-standard shebang line for book files:
13123
13235
  Shebang line must contain 'ptbk'
13124
13236
 
@@ -13134,7 +13246,7 @@
13134
13246
  pipelineString = validatePipelineString(restLines.join('\n'));
13135
13247
  }
13136
13248
  pipelineString = removeMarkdownComments(pipelineString);
13137
- pipelineString = spaceTrim.spaceTrim(pipelineString);
13249
+ pipelineString = spaceTrim$1.spaceTrim(pipelineString);
13138
13250
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
13139
13251
  pipelineString = deflatePipeline(pipelineString);
13140
13252
  // ==============
@@ -13146,7 +13258,7 @@
13146
13258
  // ==============
13147
13259
  // Note: 1️⃣◽4️⃣ Check markdown structure
13148
13260
  if (pipelineHead === undefined) {
13149
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
13261
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
13150
13262
  Pipeline head is not defined
13151
13263
 
13152
13264
  ${block(getPipelineIdentification())}
@@ -13155,7 +13267,7 @@
13155
13267
  `));
13156
13268
  }
13157
13269
  if (pipelineHead.level !== 1) {
13158
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
13270
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
13159
13271
  Pipeline head is not h1
13160
13272
 
13161
13273
  ${block(getPipelineIdentification())}
@@ -13164,7 +13276,7 @@
13164
13276
  `));
13165
13277
  }
13166
13278
  if (!pipelineSections.every((section) => section.level === 2)) {
13167
- throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
13279
+ throw new UnexpectedError(spaceTrim$1.spaceTrim((block) => `
13168
13280
  Not every pipeline section is h2
13169
13281
 
13170
13282
  ${block(getPipelineIdentification())}
@@ -13177,7 +13289,7 @@
13177
13289
  const defineParam = (parameterCommand) => {
13178
13290
  const { parameterName, parameterDescription, isInput, isOutput } = parameterCommand;
13179
13291
  if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
13180
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13292
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13181
13293
  Parameter name {${parameterName}} is reserved and cannot be used as resulting parameter name
13182
13294
 
13183
13295
  ${block(getPipelineIdentification())}
@@ -13188,7 +13300,7 @@
13188
13300
  existingParameter.description &&
13189
13301
  existingParameter.description !== parameterDescription &&
13190
13302
  parameterDescription) {
13191
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13303
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13192
13304
  Parameter \`{${parameterName}}\` is defined multiple times with different description:
13193
13305
 
13194
13306
  ${block(getPipelineIdentification())}
@@ -13226,7 +13338,7 @@
13226
13338
  description = description.split(/^>.*$/gm).join('');
13227
13339
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
13228
13340
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
13229
- description = spaceTrim.spaceTrim(description);
13341
+ description = spaceTrim$1.spaceTrim(description);
13230
13342
  if (description === '') {
13231
13343
  description = undefined;
13232
13344
  }
@@ -13237,7 +13349,7 @@
13237
13349
  const command = parseCommand(listItem, 'PIPELINE_HEAD');
13238
13350
  const commandParser = getParserForCommand(command);
13239
13351
  if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
13240
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13352
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13241
13353
  Command \`${command.type}\` is not allowed in the head of the pipeline ONLY at the pipeline task
13242
13354
 
13243
13355
  ${block(getPipelineIdentification())}
@@ -13251,7 +13363,7 @@
13251
13363
  if (!(error instanceof ParseError)) {
13252
13364
  throw error;
13253
13365
  }
13254
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13366
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13255
13367
  Command ${command.type} failed to apply to the pipeline
13256
13368
 
13257
13369
  The error:
@@ -13304,7 +13416,7 @@
13304
13416
  description = description.split(/^>.*$/gm).join('');
13305
13417
  //Note: Remove lists and return statement - TODO: [🎾]
13306
13418
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
13307
- description = spaceTrim.spaceTrim(description);
13419
+ description = spaceTrim$1.spaceTrim(description);
13308
13420
  if (description === '') {
13309
13421
  description = undefined;
13310
13422
  }
@@ -13338,7 +13450,7 @@
13338
13450
  for (const { listItem, command } of commands) {
13339
13451
  const commandParser = getParserForCommand(command);
13340
13452
  if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
13341
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13453
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13342
13454
  Command \`${command.type}\` is not allowed in the task of the promptbook ONLY at the pipeline head
13343
13455
 
13344
13456
  ${block(getPipelineIdentification())}
@@ -13353,7 +13465,7 @@
13353
13465
  if (!(error instanceof ParseError)) {
13354
13466
  throw error;
13355
13467
  }
13356
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13468
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13357
13469
  Command \`${command.type}\` failed to apply to the task
13358
13470
 
13359
13471
  The error:
@@ -13384,14 +13496,14 @@
13384
13496
  // TODO: [🍧] Should be done in SECTION command
13385
13497
  if ($taskJson.taskType === 'SCRIPT_TASK') {
13386
13498
  if (!language) {
13387
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13499
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13388
13500
  You must specify the language of the script in the \`SCRIPT\` task
13389
13501
 
13390
13502
  ${block(getPipelineIdentification())}
13391
13503
  `));
13392
13504
  }
13393
13505
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
13394
- throw new ParseError(spaceTrim.spaceTrim((block) => `
13506
+ throw new ParseError(spaceTrim$1.spaceTrim((block) => `
13395
13507
  Script language ${language} is not supported.
13396
13508
 
13397
13509
  Supported languages are:
@@ -13553,7 +13665,7 @@
13553
13665
  const warningLine = `<!-- ${GENERATOR_WARNING} -->`;
13554
13666
  const sectionRegex = new RegExp(`<!--${sectionName}-->([\\s\\S]*?)<!--/${sectionName}-->`, 'g');
13555
13667
  const sectionMatch = content.match(sectionRegex);
13556
- const contentToInsert = spaceTrim.spaceTrim((block) => `
13668
+ const contentToInsert = spaceTrim$1.spaceTrim((block) => `
13557
13669
  <!--${sectionName}-->
13558
13670
  ${block(warningLine)}
13559
13671
  ${block(sectionContent)}
@@ -13566,7 +13678,7 @@
13566
13678
  const placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
13567
13679
  if (placeForSection !== null) {
13568
13680
  const [heading] = placeForSection;
13569
- return content.replace(heading, spaceTrim.spaceTrim((block) => `
13681
+ return content.replace(heading, spaceTrim$1.spaceTrim((block) => `
13570
13682
  ${block(contentToInsert)}
13571
13683
 
13572
13684
  ${block(heading)}
@@ -13575,7 +13687,7 @@
13575
13687
  console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
13576
13688
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
13577
13689
  // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
13578
- return spaceTrim.spaceTrim((block) => `
13690
+ return spaceTrim$1.spaceTrim((block) => `
13579
13691
  ${block(content)}
13580
13692
 
13581
13693
  ${block(contentToInsert)}
@@ -13651,7 +13763,7 @@
13651
13763
  .filter(([MERMAID_NAME]) => (inputAndIntermediateParametersMermaid + outputParametersMermaid).includes(MERMAID_NAME))
13652
13764
  .map(([MERMAID_NAME, title]) => `${MERMAID_NAME}((${title})):::${MERMAID_NAME}`)
13653
13765
  .join('\n');
13654
- const promptbookMermaid = spaceTrim.spaceTrim((block) => `
13766
+ const promptbookMermaid = spaceTrim$1.spaceTrim((block) => `
13655
13767
 
13656
13768
  %% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
13657
13769
 
@@ -13707,7 +13819,7 @@
13707
13819
  return { href: `#${task.name}`, title: task.title };
13708
13820
  },
13709
13821
  });
13710
- const promptbookMermaidBlock = spaceTrim.spaceTrim((block) => `
13822
+ const promptbookMermaidBlock = spaceTrim$1.spaceTrim((block) => `
13711
13823
  \`\`\`mermaid
13712
13824
  ${block(promptbookMermaid)}
13713
13825
  \`\`\`
@@ -13745,7 +13857,7 @@
13745
13857
  async promptDialog(options) {
13746
13858
  const answer = await this.options.callback(options);
13747
13859
  if (this.options.isVerbose) {
13748
- console.info(spaceTrim.spaceTrim((block) => `
13860
+ console.info(spaceTrim$1.spaceTrim((block) => `
13749
13861
  📖 ${block(options.promptTitle)}
13750
13862
  👤 ${block(answer)}
13751
13863
  `));
@@ -13886,7 +13998,7 @@
13886
13998
  function executionReportJsonToString(executionReportJson, options) {
13887
13999
  var _a, _b, _c, _d, _e, _f;
13888
14000
  const { taxRate, chartsWidth } = { ...ExecutionReportStringOptionsDefaults, ...(options || {}) };
13889
- let executionReportString = spaceTrim.spaceTrim((block) => `
14001
+ let executionReportString = spaceTrim$1.spaceTrim((block) => `
13890
14002
  # ${executionReportJson.title || 'Execution report'}
13891
14003
 
13892
14004
  ${block(executionReportJson.description || '')}
@@ -14008,7 +14120,7 @@
14008
14120
  if (just(true)) {
14009
14121
  executionReportString +=
14010
14122
  '\n\n\n\n' +
14011
- spaceTrim.spaceTrim((block) => {
14123
+ spaceTrim$1.spaceTrim((block) => {
14012
14124
  var _a;
14013
14125
  return `
14014
14126
 
@@ -14027,7 +14139,7 @@
14027
14139
  executionReportString += '*No result*';
14028
14140
  }
14029
14141
  else if (typeof promptExecution.result.content === 'string') {
14030
- executionReportString += spaceTrim.spaceTrim((block) => `
14142
+ executionReportString += spaceTrim$1.spaceTrim((block) => `
14031
14143
  \`\`\`
14032
14144
  ${block(escapeMarkdownBlock(promptExecution.result.content))}
14033
14145
  \`\`\`
@@ -14040,7 +14152,7 @@
14040
14152
  if (promptExecution.error && promptExecution.error.message) {
14041
14153
  executionReportString +=
14042
14154
  '\n\n\n\n' +
14043
- spaceTrim.spaceTrim((block) => `
14155
+ spaceTrim$1.spaceTrim((block) => `
14044
14156
 
14045
14157
  ### Error
14046
14158
 
@@ -14799,66 +14911,6 @@
14799
14911
  * TODO: [🧠] Maybe `BehaviorSubject` is too heavy for this use case, maybe just tuple `[value,setValue]` is enough
14800
14912
  */
14801
14913
 
14802
- /**
14803
- * Represents one AI Agent
14804
- *
14805
- * Note: [🦖] There are several different things in Promptbook:
14806
- * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
14807
- * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
14808
- * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
14809
- * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
14810
- *
14811
- * @public exported from `@promptbook/core`
14812
- */
14813
- class Agent {
14814
- /**
14815
- * Not used in Agent, always returns empty array
14816
- */
14817
- get parameters() {
14818
- return [
14819
- /* [😰] */
14820
- ];
14821
- }
14822
- constructor(options) {
14823
- this.options = options;
14824
- /**
14825
- * Name of the agent
14826
- */
14827
- this.agentName = null;
14828
- /**
14829
- * Description of the agent
14830
- */
14831
- this.personaDescription = null;
14832
- /**
14833
- * Metadata like image or color
14834
- */
14835
- this.meta = {};
14836
- this.agentSource = asUpdatableSubject(options.agentSource);
14837
- this.agentSource.subscribe((source) => {
14838
- const { agentName, personaDescription, meta } = parseAgentSource(source);
14839
- this.agentName = agentName;
14840
- this.personaDescription = personaDescription;
14841
- this.meta = { ...this.meta, ...meta };
14842
- });
14843
- }
14844
- /**
14845
- * Creates LlmExecutionTools which exposes the agent as a model
14846
- */
14847
- getLlmExecutionTools() {
14848
- const llmTools = new AgentLlmExecutionTools({
14849
- llmTools: getSingleLlmExecutionTools(this.options.executionTools.llm),
14850
- agentSource: this.agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
14851
- });
14852
- // TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
14853
- // TODO: !!!! Add `Agent` learning by promptbookAgent
14854
- return llmTools;
14855
- }
14856
- }
14857
- /**
14858
- * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
14859
- * TODO: !!! Agent on remote server
14860
- */
14861
-
14862
14914
  /**
14863
14915
  * Change ellipsis character to three dots `…` -> `...`
14864
14916
  *
@@ -16875,6 +16927,66 @@
16875
16927
  * TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
16876
16928
  */
16877
16929
 
16930
+ /**
16931
+ * Represents one AI Agent
16932
+ *
16933
+ * Note: [🦖] There are several different things in Promptbook:
16934
+ * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
16935
+ * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
16936
+ * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
16937
+ * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
16938
+ *
16939
+ * @public exported from `@promptbook/core`
16940
+ */
16941
+ class Agent {
16942
+ /**
16943
+ * Not used in Agent, always returns empty array
16944
+ */
16945
+ get parameters() {
16946
+ return [
16947
+ /* [😰] */
16948
+ ];
16949
+ }
16950
+ constructor(options) {
16951
+ this.options = options;
16952
+ /**
16953
+ * Name of the agent
16954
+ */
16955
+ this.agentName = null;
16956
+ /**
16957
+ * Description of the agent
16958
+ */
16959
+ this.personaDescription = null;
16960
+ /**
16961
+ * Metadata like image or color
16962
+ */
16963
+ this.meta = {};
16964
+ this.agentSource = asUpdatableSubject(options.agentSource);
16965
+ this.agentSource.subscribe((source) => {
16966
+ const { agentName, personaDescription, meta } = parseAgentSource(source);
16967
+ this.agentName = agentName;
16968
+ this.personaDescription = personaDescription;
16969
+ this.meta = { ...this.meta, ...meta };
16970
+ });
16971
+ }
16972
+ /**
16973
+ * Creates LlmExecutionTools which exposes the agent as a model
16974
+ */
16975
+ getLlmExecutionTools() {
16976
+ const llmTools = new AgentLlmExecutionTools({
16977
+ llmTools: getSingleLlmExecutionTools(this.options.executionTools.llm),
16978
+ agentSource: this.agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
16979
+ });
16980
+ // TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
16981
+ // TODO: !!!! Add `Agent` learning by promptbookAgent
16982
+ return llmTools;
16983
+ }
16984
+ }
16985
+ /**
16986
+ * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
16987
+ * TODO: !!! Agent on remote server
16988
+ */
16989
+
16878
16990
  /**
16879
16991
  * Creates new AgentLlmExecutionTools that wrap underlying LLM tools with agent-specific behavior
16880
16992
  *
@@ -18107,6 +18219,25 @@
18107
18219
  },
18108
18220
  };
18109
18221
 
18222
+ /**
18223
+ * Returns information about the current runtime environment
18224
+ *
18225
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environments
18226
+ *
18227
+ * @public exported from `@promptbook/utils`
18228
+ */
18229
+ function $detectRuntimeEnvironment() {
18230
+ return {
18231
+ isRunningInBrowser: $isRunningInBrowser(),
18232
+ isRunningInJest: $isRunningInJest(),
18233
+ isRunningInNode: $isRunningInNode(),
18234
+ isRunningInWebWorker: $isRunningInWebWorker(),
18235
+ };
18236
+ }
18237
+ /**
18238
+ * TODO: [🎺] Also detect and report node version here
18239
+ */
18240
+
18110
18241
  /**
18111
18242
  * Provide information about Promptbook, engine version, book language version, servers, ...
18112
18243
  *
@@ -18116,7 +18247,7 @@
18116
18247
  * @public exported from `@promptbook/core`
18117
18248
  */
18118
18249
  function aboutPromptbookInformation(options) {
18119
- const { isServersInfoIncluded = true } = options || {};
18250
+ const { isServersInfoIncluded = true, isRuntimeEnvironmentInfoIncluded = true } = options || {};
18120
18251
  const fullInfoPieces = [];
18121
18252
  const basicInfo = spaceTrim__default["default"](`
18122
18253
 
@@ -18140,6 +18271,22 @@
18140
18271
  `);
18141
18272
  fullInfoPieces.push(serversInfo);
18142
18273
  }
18274
+ if (isRuntimeEnvironmentInfoIncluded) {
18275
+ const runtimeEnvironment = $detectRuntimeEnvironment();
18276
+ const environmentInfoRecord = {
18277
+ ...runtimeEnvironment,
18278
+ isCostPrevented: IS_COST_PREVENTED,
18279
+ };
18280
+ const environmentInfo = spaceTrim__default["default"]((block) => `
18281
+
18282
+ ## Environment
18283
+
18284
+ ${block(Object.entries(environmentInfoRecord)
18285
+ .map(([key, value]) => `- **${key}:** ${valueToString(value)}`)
18286
+ .join('\n'))}
18287
+ `);
18288
+ fullInfoPieces.push(environmentInfo);
18289
+ }
18143
18290
  const fullInfo = spaceTrim__default["default"](fullInfoPieces.join('\n\n'));
18144
18291
  return fullInfo;
18145
18292
  }
@@ -18147,7 +18294,34 @@
18147
18294
  * TODO: [🗽] Unite branding and make single place for it
18148
18295
  */
18149
18296
 
18297
+ /**
18298
+ * Generates boilerplate for a new agent book
18299
+ *
18300
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
18301
+ * Note: This function is using cryptographically secure components internally
18302
+ *
18303
+ * @public exported from `@promptbook/core`
18304
+ */
18305
+ function $generateBookBoilerplate(options) {
18306
+ // eslint-disable-next-line prefer-const
18307
+ let { agentName, parentAgentName = 'Adam', personaDescription, meta } = options || {};
18308
+ if (!agentName) {
18309
+ agentName = 'Agent ' + $randomToken(20);
18310
+ // <- TODO: !!! Supercool random name generator
18311
+ }
18312
+ if (!personaDescription) {
18313
+ personaDescription = 'Friendly and helpful AI agent.';
18314
+ }
18315
+ const agentSource = validateBook(spaceTrim__default["default"]((block) => `
18316
+ ${agentName}
18317
+
18318
+ PERSONA ${block(personaDescription)}
18319
+ `));
18320
+ return agentSource;
18321
+ }
18322
+
18150
18323
  exports.$bookTranspilersRegister = $bookTranspilersRegister;
18324
+ exports.$generateBookBoilerplate = $generateBookBoilerplate;
18151
18325
  exports.$llmToolsMetadataRegister = $llmToolsMetadataRegister;
18152
18326
  exports.$llmToolsRegister = $llmToolsRegister;
18153
18327
  exports.$scrapersMetadataRegister = $scrapersMetadataRegister;
@@ -18157,6 +18331,7 @@
18157
18331
  exports.API_REQUEST_TIMEOUT = API_REQUEST_TIMEOUT;
18158
18332
  exports.AbstractFormatError = AbstractFormatError;
18159
18333
  exports.Agent = Agent;
18334
+ exports.AgentCollectionInSupabase = AgentCollectionInSupabase;
18160
18335
  exports.AgentLlmExecutionTools = AgentLlmExecutionTools;
18161
18336
  exports.AuthenticationError = AuthenticationError;
18162
18337
  exports.BIG_DATASET_TRESHOLD = BIG_DATASET_TRESHOLD;
@@ -18195,6 +18370,7 @@
18195
18370
  exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
18196
18371
  exports.DEFAULT_TASK_SIMULATED_DURATION_MS = DEFAULT_TASK_SIMULATED_DURATION_MS;
18197
18372
  exports.DEFAULT_TASK_TITLE = DEFAULT_TASK_TITLE;
18373
+ exports.DatabaseError = DatabaseError;
18198
18374
  exports.EXPECTATION_UNITS = EXPECTATION_UNITS;
18199
18375
  exports.EnvironmentMismatchError = EnvironmentMismatchError;
18200
18376
  exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;