@promptbook/core 0.104.0-12 → 0.104.0-14
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 +53 -36
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +0 -6
- package/esm/typings/src/book-components/Chat/save/_common/string_chat_format_name.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +4 -1
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +5 -1
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +4 -0
- package/esm/typings/src/book-components/icons/AboutIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/AttachmentIcon.d.ts +6 -2
- package/esm/typings/src/book-components/icons/CameraIcon.d.ts +6 -2
- package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/MenuIcon.d.ts +5 -1
- package/esm/typings/src/book-components/icons/SaveIcon.d.ts +6 -2
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +7 -5
- package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
- package/esm/typings/src/commitments/_base/BookCommitment.d.ts +1 -1
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +7 -3
- package/esm/typings/src/llm-providers/_multiple/joinLlmExecutionTools.d.ts +11 -7
- package/esm/typings/src/remote-server/ui/ServerApp.d.ts +5 -1
- package/esm/typings/src/types/typeAliasEmoji.d.ts +2 -2
- package/esm/typings/src/utils/random/$randomAgentPersona.d.ts +4 -0
- package/esm/typings/src/utils/random/$randomItem.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +53 -36
- package/umd/index.umd.js.map +1 -1
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-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.104.0-14';
|
|
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((
|
|
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
|
-
*
|
|
3691
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
3961
|
-
*
|
|
3962
|
-
* 2
|
|
3963
|
-
* 3
|
|
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, (
|
|
4532
|
-
return DIACRITIC_VARIANTS_LETTERS[
|
|
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((
|
|
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((
|
|
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((
|
|
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((
|
|
7544
|
-
const escapedCommitment =
|
|
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((
|
|
7567
|
-
const escapedCommitment =
|
|
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('|');
|
|
@@ -8074,9 +8082,7 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8074
8082
|
// Get existing dictionary entries from metadata
|
|
8075
8083
|
const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
|
|
8076
8084
|
// Merge the new dictionary entry with existing entries
|
|
8077
|
-
const mergedDictionary = existingDictionary
|
|
8078
|
-
? `${existingDictionary}\n${trimmedContent}`
|
|
8079
|
-
: trimmedContent;
|
|
8085
|
+
const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
|
|
8080
8086
|
// Store the merged dictionary in metadata for debugging and inspection
|
|
8081
8087
|
const updatedMetadata = {
|
|
8082
8088
|
...requirements.metadata,
|
|
@@ -11295,8 +11301,8 @@ function parseParameters(text) {
|
|
|
11295
11301
|
return match;
|
|
11296
11302
|
});
|
|
11297
11303
|
// Remove duplicates based on name (keep the first occurrence)
|
|
11298
|
-
const uniqueParameters = parameters.filter((
|
|
11299
|
-
return array.findIndex((
|
|
11304
|
+
const uniqueParameters = parameters.filter((parameter, index, array) => {
|
|
11305
|
+
return array.findIndex((parameterItem) => parameterItem.name === parameter.name) === index;
|
|
11300
11306
|
});
|
|
11301
11307
|
return uniqueParameters;
|
|
11302
11308
|
}
|
|
@@ -11343,7 +11349,7 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
11343
11349
|
commitment.type === 'DISCARD' ||
|
|
11344
11350
|
commitment.type === 'REMOVE') {
|
|
11345
11351
|
const targets = parseParameters(commitment.content)
|
|
11346
|
-
.map((
|
|
11352
|
+
.map((parameter) => parameter.name.trim().toLowerCase())
|
|
11347
11353
|
.filter(Boolean);
|
|
11348
11354
|
if (targets.length === 0) {
|
|
11349
11355
|
// Ignore DELETE with no targets; also don't pass the DELETE further
|
|
@@ -11352,8 +11358,8 @@ async function createAgentModelRequirementsWithCommitments(agentSource, modelNam
|
|
|
11352
11358
|
// Drop prior kept commitments that contain any of the targeted tags
|
|
11353
11359
|
for (let i = filteredCommitments.length - 1; i >= 0; i--) {
|
|
11354
11360
|
const prev = filteredCommitments[i];
|
|
11355
|
-
const prevParams = parseParameters(prev.content).map((
|
|
11356
|
-
const hasIntersection = prevParams.some((
|
|
11361
|
+
const prevParams = parseParameters(prev.content).map((parameter) => parameter.name.trim().toLowerCase());
|
|
11362
|
+
const hasIntersection = prevParams.some((parameterName) => targets.includes(parameterName));
|
|
11357
11363
|
if (hasIntersection) {
|
|
11358
11364
|
filteredCommitments.splice(i, 1);
|
|
11359
11365
|
}
|
|
@@ -12276,18 +12282,20 @@ function $randomBase58(length) {
|
|
|
12276
12282
|
// import { getTableName } from '../../../../../apps/agents-server/src/database/getTableName';
|
|
12277
12283
|
// <- TODO: [🐱🚀] Prevent imports from `/apps` -> `/src`
|
|
12278
12284
|
/**
|
|
12279
|
-
* Agent collection stored in Supabase table
|
|
12285
|
+
* Agent collection stored in a Supabase table.
|
|
12280
12286
|
*
|
|
12281
|
-
*
|
|
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.
|
|
12282
12291
|
*
|
|
12283
12292
|
* @public exported from `@promptbook/core`
|
|
12284
12293
|
* <- TODO: [🐱🚀] Move to `@promptbook/supabase` package
|
|
12285
12294
|
*/
|
|
12286
12295
|
class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
12287
12296
|
/**
|
|
12288
|
-
* @param
|
|
12289
|
-
* @param
|
|
12290
|
-
* @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)
|
|
12291
12299
|
*/
|
|
12292
12300
|
constructor(supabaseClient,
|
|
12293
12301
|
/// TODO: [🐱🚀] Remove> private readonly tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>,
|
|
@@ -14175,7 +14183,12 @@ const jokerCommandParser = {
|
|
|
14175
14183
|
* @see {@link ModelVariant}
|
|
14176
14184
|
* @public exported from `@promptbook/core`
|
|
14177
14185
|
*/
|
|
14178
|
-
const MODEL_VARIANTS = [
|
|
14186
|
+
const MODEL_VARIANTS = [
|
|
14187
|
+
'COMPLETION',
|
|
14188
|
+
'CHAT',
|
|
14189
|
+
'IMAGE_GENERATION',
|
|
14190
|
+
'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */,
|
|
14191
|
+
];
|
|
14179
14192
|
|
|
14180
14193
|
/**
|
|
14181
14194
|
* Parses the model command
|
|
@@ -19741,7 +19754,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
19741
19754
|
const modelRequirements = await this.getAgentModelRequirements();
|
|
19742
19755
|
if (modelRequirements.samples) {
|
|
19743
19756
|
const normalizedPrompt = normalizeMessageText(prompt.content);
|
|
19744
|
-
const sample = modelRequirements.samples.find((
|
|
19757
|
+
const sample = modelRequirements.samples.find((sample) => normalizeMessageText(sample.question) === normalizedPrompt);
|
|
19745
19758
|
if (sample) {
|
|
19746
19759
|
const now = new Date().toISOString();
|
|
19747
19760
|
const result = {
|
|
@@ -21299,6 +21312,10 @@ const PERSONALITIES = [
|
|
|
21299
21312
|
/**
|
|
21300
21313
|
* Generates a random agent persona description.
|
|
21301
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
|
|
21302
21319
|
* @private internal helper function
|
|
21303
21320
|
*/
|
|
21304
21321
|
function $randomAgentPersona() {
|