@promptbook/core 0.104.0-13 → 0.104.0-15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.104.0-13';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-15';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3628,7 +3628,7 @@ async function forEachAsync(array, options, callbackfunction) {
3628
3628
  tasks.push(task);
3629
3629
  runningTasks.push(task);
3630
3630
  /* not await */ Promise.resolve(task).then(() => {
3631
- runningTasks = runningTasks.filter((t) => t !== task);
3631
+ runningTasks = runningTasks.filter((runningTask) => runningTask !== task);
3632
3632
  });
3633
3633
  if (maxParallelCount < runningTasks.length) {
3634
3634
  await Promise.race(runningTasks);
@@ -3685,10 +3685,14 @@ function addUsage(...usageItems) {
3685
3685
  }
3686
3686
 
3687
3687
  /**
3688
- * Intercepts LLM tools and counts total usage of the tools
3688
+ * Intercepts LLM tools and counts total usage of the tools.
3689
3689
  *
3690
- * @param llmTools LLM tools to be intercepted with usage counting
3691
- * @returns LLM tools with same functionality with added total cost counting
3690
+ * This function wraps the provided `LlmExecutionTools` with a proxy that tracks the cumulative
3691
+ * usage (tokens, cost, etc.) across all model calls. It provides a way to monitor spending
3692
+ * in real-time through an observable.
3693
+ *
3694
+ * @param llmTools - The LLM tools to be intercepted and tracked
3695
+ * @returns An augmented version of the tools that includes usage tracking capabilities
3692
3696
  * @public exported from `@promptbook/core`
3693
3697
  */
3694
3698
  function countUsage(llmTools) {
@@ -3953,17 +3957,21 @@ class MultipleLlmExecutionTools {
3953
3957
  */
3954
3958
 
3955
3959
  /**
3956
- * Joins multiple LLM Execution Tools into one
3960
+ * Joins multiple LLM Execution Tools into one.
3957
3961
  *
3958
- * @returns {LlmExecutionTools} Single wrapper for multiple LlmExecutionTools
3962
+ * This function takes a list of `LlmExecutionTools` and returns a single unified
3963
+ * `MultipleLlmExecutionTools` object. It provides failover and aggregation logic:
3959
3964
  *
3960
- * 0) If there is no LlmExecutionTools, it warns and returns valid but empty LlmExecutionTools
3961
- * 1) If there is only one LlmExecutionTools, it returns it wrapped in a proxy object
3962
- * 2) If there are multiple LlmExecutionTools, first will be used first, second will be used if the first hasn`t defined model variant or fails, etc.
3963
- * 3) When all LlmExecutionTools fail, it throws an error with a list of all errors merged into one
3965
+ * 1. **Failover**: When a model call is made, it tries providers in the order they were provided.
3966
+ * If the first provider doesn't support the requested model or fails, it tries the next one.
3967
+ * 2. **Aggregation**: `listModels` returns a combined list of all models available from all providers.
3968
+ * 3. **Empty case**: If no tools are provided, it logs a warning (as Promptbook requires LLMs to function).
3964
3969
  *
3970
+ * @param title - A descriptive title for this collection of joined tools
3971
+ * @param llmExecutionTools - An array of execution tools to be joined
3972
+ * @returns A single unified execution tool wrapper
3965
3973
  *
3966
- * Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
3974
+ * Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`.
3967
3975
  *
3968
3976
  * @public exported from `@promptbook/core`
3969
3977
  */
@@ -4528,8 +4536,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
4528
4536
  */
4529
4537
  function removeDiacritics(input) {
4530
4538
  /*eslint no-control-regex: "off"*/
4531
- return input.replace(/[^\u0000-\u007E]/g, (a) => {
4532
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
4539
+ return input.replace(/[^\u0000-\u007E]/g, (character) => {
4540
+ return DIACRITIC_VARIANTS_LETTERS[character] || character;
4533
4541
  });
4534
4542
  }
4535
4543
  /**
@@ -6788,7 +6796,7 @@ async function getKnowledgeForTask(options) {
6788
6796
  const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
6789
6797
  const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
6790
6798
  const { index } = knowledgePiece;
6791
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowledgeIndex.modelName);
6799
+ const knowledgePieceIndex = index.find((knowledgePieceIndex) => knowledgePieceIndex.modelName === firstKnowledgeIndex.modelName);
6792
6800
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
6793
6801
  if (knowledgePieceIndex === undefined) {
6794
6802
  return {
@@ -7236,7 +7244,7 @@ async function executePipeline(options) {
7236
7244
  resovedParameterNames = [...resovedParameterNames, currentTask.resultingParameterName];
7237
7245
  })
7238
7246
  .then(() => {
7239
- resolving = resolving.filter((w) => w !== work);
7247
+ resolving = resolving.filter((workItem) => workItem !== work);
7240
7248
  });
7241
7249
  // <- Note: Errors are catched here [3]
7242
7250
  // TODO: BUT if in multiple tasks are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
@@ -7402,7 +7410,7 @@ function createPipelineExecutor(options) {
7402
7410
  // Calculate and update tldr based on pipeline progress
7403
7411
  const cv = newOngoingResult;
7404
7412
  // Calculate progress based on parameters resolved vs total parameters
7405
- const totalParameters = pipeline.parameters.filter((p) => !p.isInput).length;
7413
+ const totalParameters = pipeline.parameters.filter((parameter) => !parameter.isInput).length;
7406
7414
  let resolvedParameters = 0;
7407
7415
  let currentTaskTitle = '';
7408
7416
  // Get the resolved parameters from output parameters
@@ -7540,8 +7548,8 @@ async function preparePersona(personaDescription, tools, options) {
7540
7548
  */
7541
7549
  function createCommitmentRegex(commitment, aliases = [], requiresContent = true) {
7542
7550
  const allCommitments = [commitment, ...aliases];
7543
- const patterns = allCommitments.map((c) => {
7544
- const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7551
+ const patterns = allCommitments.map((commitment) => {
7552
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7545
7553
  return escapedCommitment.split(/\s+/).join('\\s+');
7546
7554
  });
7547
7555
  const keywordPattern = patterns.join('|');
@@ -7563,8 +7571,8 @@ function createCommitmentRegex(commitment, aliases = [], requiresContent = true)
7563
7571
  */
7564
7572
  function createCommitmentTypeRegex(commitment, aliases = []) {
7565
7573
  const allCommitments = [commitment, ...aliases];
7566
- const patterns = allCommitments.map((c) => {
7567
- const escapedCommitment = c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7574
+ const patterns = allCommitments.map((commitment) => {
7575
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7568
7576
  return escapedCommitment.split(/\s+/).join('\\s+');
7569
7577
  });
7570
7578
  const keywordPattern = patterns.join('|');
@@ -11293,8 +11301,8 @@ function parseParameters(text) {
11293
11301
  return match;
11294
11302
  });
11295
11303
  // Remove duplicates based on name (keep the first occurrence)
11296
- const uniqueParameters = parameters.filter((param, index, array) => {
11297
- return array.findIndex((p) => p.name === param.name) === index;
11304
+ const uniqueParameters = parameters.filter((parameter, index, array) => {
11305
+ return array.findIndex((parameterItem) => parameterItem.name === parameter.name) === index;
11298
11306
  });
11299
11307
  return uniqueParameters;
11300
11308
  }
@@ -11341,7 +11349,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
11341
11349
  commitment.type === 'DISCARD' ||
11342
11350
  commitment.type === 'REMOVE') {
11343
11351
  const targets = parseParameters(commitment.content)
11344
- .map((p) => p.name.trim().toLowerCase())
11352
+ .map((parameter) => parameter.name.trim().toLowerCase())
11345
11353
  .filter(Boolean);
11346
11354
  if (targets.length === 0) {
11347
11355
  // Ignore DELETE with no targets; also don't pass the DELETE further
@@ -11350,8 +11358,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
11350
11358
  // Drop prior kept commitments that contain any of the targeted tags
11351
11359
  for (let i = filteredCommitments.length - 1; i >= 0; i--) {
11352
11360
  const prev = filteredCommitments[i];
11353
- const prevParams = parseParameters(prev.content).map((p) => p.name.trim().toLowerCase());
11354
- const hasIntersection = prevParams.some((n) => targets.includes(n));
11361
+ const prevParams = parseParameters(prev.content).map((parameter) => parameter.name.trim().toLowerCase());
11362
+ const hasIntersection = prevParams.some((parameterName) => targets.includes(parameterName));
11355
11363
  if (hasIntersection) {
11356
11364
  filteredCommitments.splice(i, 1);
11357
11365
  }
@@ -12274,18 +12282,20 @@ function $randomBase58(length) {
12274
12282
  // import { getTableName } from '../../../../../apps/agents-server/src/database/getTableName';
12275
12283
  // <- TODO: [🐱‍🚀] Prevent imports from `/apps` -> `/src`
12276
12284
  /**
12277
- * Agent collection stored in Supabase table
12285
+ * Agent collection stored in a Supabase table.
12278
12286
  *
12279
- * Note: This object can work both from Node.js and browser environment depending on the Supabase client provided
12287
+ * This class provides a way to manage a collection of agents (pipelines) using Supabase
12288
+ * as the storage backend. It supports listing, creating, updating, and soft-deleting agents.
12289
+ *
12290
+ * Note: This object can work both from Node.js and browser environment depending on the Supabase client provided.
12280
12291
  *
12281
12292
  * @public exported from `@promptbook/core`
12282
12293
  * <- TODO: [🐱‍🚀] Move to `@promptbook/supabase` package
12283
12294
  */
12284
12295
  class AgentCollectionInSupabase /* TODO: [🐱‍🚀] implements Agent */ {
12285
12296
  /**
12286
- * @param rootPath - path to the directory with agents
12287
- * @param tools - Execution tools to be used in [🐱‍🚀] `Agent` itself and listing the agents
12288
- * @param options - Options for the collection creation
12297
+ * @param supabaseClient - The initialized Supabase client
12298
+ * @param options - Configuration options for the collection (e.g., table prefix, verbosity)
12289
12299
  */
12290
12300
  constructor(supabaseClient,
12291
12301
  /// TODO: [🐱‍🚀] Remove> private readonly tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>,
@@ -19744,7 +19754,7 @@ class Agent extends AgentLlmExecutionTools {
19744
19754
  const modelRequirements = await this.getAgentModelRequirements();
19745
19755
  if (modelRequirements.samples) {
19746
19756
  const normalizedPrompt = normalizeMessageText(prompt.content);
19747
- const sample = modelRequirements.samples.find((s) => normalizeMessageText(s.question) === normalizedPrompt);
19757
+ const sample = modelRequirements.samples.find((sample) => normalizeMessageText(sample.question) === normalizedPrompt);
19748
19758
  if (sample) {
19749
19759
  const now = new Date().toISOString();
19750
19760
  const result = {
@@ -21302,6 +21312,10 @@ const PERSONALITIES = [
21302
21312
  /**
21303
21313
  * Generates a random agent persona description.
21304
21314
  *
21315
+ * This function selects a random personality profile from a predefined pool
21316
+ * of common AI agent characteristics (e.g., friendly, professional, creative).
21317
+ *
21318
+ * @returns A string describing the agent's persona
21305
21319
  * @private internal helper function
21306
21320
  */
21307
21321
  function $randomAgentPersona() {