@promptbook/core 0.103.0-41 → 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.
- package/esm/index.es.js +538 -365
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/node.index.d.ts +0 -2
- package/esm/typings/src/_packages/types.index.d.ts +14 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -4
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/string_book.d.ts +1 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
- package/esm/typings/src/book-components/Qr/BrandedQrCode.d.ts +1 -1
- package/esm/typings/src/book-components/Qr/useQrCode.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/login.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/start-agents-server.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/start-pipelines-server.d.ts +1 -1
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +1 -1
- package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +14 -12
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +55 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +129 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/0-index.d.ts +3 -0
- package/esm/typings/src/errors/DatabaseError.d.ts +9 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +1 -1
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +5 -2
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +4 -2
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +1 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +0 -19
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +1 -1
- package/esm/typings/src/transpilers/_common/BookTranspiler.d.ts +5 -1
- package/esm/typings/src/transpilers/_common/BookTranspilerOptions.d.ts +1 -1
- package/esm/typings/src/transpilers/_common/register/$bookTranspilersRegister.d.ts +1 -1
- package/esm/typings/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.d.ts +4 -1
- package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +1 -1
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.d.ts +4 -1
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/darken.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/grayscale.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/lighten.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +1 -1
- package/esm/typings/src/utils/color/operators/saturate.d.ts +1 -1
- package/esm/typings/src/utils/environment/$detectRuntimeEnvironment.d.ts +16 -0
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -1
- package/esm/typings/src/utils/files/$induceBookDownload.d.ts +2 -2
- package/esm/typings/src/utils/files/$induceFileDownload.d.ts +2 -2
- package/esm/typings/src/utils/files/ObjectUrl.d.ts +1 -1
- package/esm/typings/src/utils/misc/aboutPromptbookInformation.d.ts +6 -0
- package/esm/typings/src/utils/organization/$side_effect.d.ts +1 -1
- package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +22 -0
- package/esm/typings/src/utils/random/$randomToken.d.ts +1 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +2 -2
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +463 -287
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.d.ts +0 -88
- package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.test.d.ts +0 -1
- package/esm/typings/src/execution/utils/logLlmCall.d.ts +0 -8
package/esm/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import spaceTrim, { spaceTrim as spaceTrim$
|
|
1
|
+
import spaceTrim$1, { spaceTrim as spaceTrim$2 } from 'spacetrim';
|
|
2
2
|
import { randomBytes } from 'crypto';
|
|
3
3
|
import { Subject, BehaviorSubject } from 'rxjs';
|
|
4
4
|
import { forTime, forEver } from 'waitasecond';
|
|
@@ -8,8 +8,8 @@ import { basename, join, dirname, isAbsolute } from 'path';
|
|
|
8
8
|
import { SHA256 } from 'crypto-js';
|
|
9
9
|
import { lookup, extension } from 'mime-types';
|
|
10
10
|
import { parse, unparse } from 'papaparse';
|
|
11
|
-
import moment from 'moment';
|
|
12
11
|
import colors from 'colors';
|
|
12
|
+
import moment from 'moment';
|
|
13
13
|
import Bottleneck from 'bottleneck';
|
|
14
14
|
import OpenAI from 'openai';
|
|
15
15
|
|
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-43';
|
|
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
|
|
@@ -841,6 +841,23 @@ class Color {
|
|
|
841
841
|
* TODO: Maybe connect with textures
|
|
842
842
|
*/
|
|
843
843
|
|
|
844
|
+
/**
|
|
845
|
+
* Makes color transformer which returns a grayscale version of the color
|
|
846
|
+
*
|
|
847
|
+
* @param amount from 0 to 1
|
|
848
|
+
*
|
|
849
|
+
* @public exported from `@promptbook/color`
|
|
850
|
+
*/
|
|
851
|
+
function grayscale(amount) {
|
|
852
|
+
return ({ red, green, blue, alpha }) => {
|
|
853
|
+
const average = (red + green + blue) / 3;
|
|
854
|
+
red = Math.round(average * amount + red * (1 - amount));
|
|
855
|
+
green = Math.round(average * amount + green * (1 - amount));
|
|
856
|
+
blue = Math.round(average * amount + blue * (1 - amount));
|
|
857
|
+
return Color.fromValues(red, green, blue, alpha);
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
|
|
844
861
|
/**
|
|
845
862
|
* Converts HSL values to RGB values
|
|
846
863
|
*
|
|
@@ -956,102 +973,6 @@ function lighten(amount) {
|
|
|
956
973
|
* TODO: Maybe implement by mix+hsl
|
|
957
974
|
*/
|
|
958
975
|
|
|
959
|
-
/**
|
|
960
|
-
* Calculates distance between two colors
|
|
961
|
-
*
|
|
962
|
-
* @param color1 first color
|
|
963
|
-
* @param color2 second color
|
|
964
|
-
*
|
|
965
|
-
* Note: This function is inefficient. Use colorDistanceSquared instead if possible.
|
|
966
|
-
*
|
|
967
|
-
* @public exported from `@promptbook/color`
|
|
968
|
-
*/
|
|
969
|
-
/**
|
|
970
|
-
* Calculates distance between two colors without square root
|
|
971
|
-
*
|
|
972
|
-
* @param color1 first color
|
|
973
|
-
* @param color2 second color
|
|
974
|
-
*
|
|
975
|
-
* @public exported from `@promptbook/color`
|
|
976
|
-
*/
|
|
977
|
-
function colorDistanceSquared(color1, color2) {
|
|
978
|
-
const rmean = (color1.red + color2.red) / 2;
|
|
979
|
-
const r = color1.red - color2.red;
|
|
980
|
-
const g = color1.green - color2.green;
|
|
981
|
-
const b = color1.blue - color2.blue;
|
|
982
|
-
const weightR = 2 + rmean / 256;
|
|
983
|
-
const weightG = 4.0;
|
|
984
|
-
const weightB = 2 + (255 - rmean) / 256;
|
|
985
|
-
const distance = weightR * r * r + weightG * g * g + weightB * b * b;
|
|
986
|
-
return distance;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* Makes color transformer which finds the nearest color from the given list
|
|
991
|
-
*
|
|
992
|
-
* @param colors array of colors to choose from
|
|
993
|
-
*
|
|
994
|
-
* @public exported from `@promptbook/color`
|
|
995
|
-
*/
|
|
996
|
-
function nearest(...colors) {
|
|
997
|
-
return (color) => {
|
|
998
|
-
const distances = colors.map((c) => colorDistanceSquared(c, color));
|
|
999
|
-
const minDistance = Math.min(...distances);
|
|
1000
|
-
const minIndex = distances.indexOf(minDistance);
|
|
1001
|
-
const nearestColor = colors[minIndex];
|
|
1002
|
-
return nearestColor;
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
/**
|
|
1007
|
-
* Color transformer which returns the negative color
|
|
1008
|
-
*
|
|
1009
|
-
* @public exported from `@promptbook/color`
|
|
1010
|
-
*/
|
|
1011
|
-
function negative(color) {
|
|
1012
|
-
const r = 255 - color.red;
|
|
1013
|
-
const g = 255 - color.green;
|
|
1014
|
-
const b = 255 - color.blue;
|
|
1015
|
-
return Color.fromValues(r, g, b, color.alpha);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Makes color transformer which finds the furthest color from the given list
|
|
1020
|
-
*
|
|
1021
|
-
* @param colors array of colors to choose from
|
|
1022
|
-
*
|
|
1023
|
-
* @public exported from `@promptbook/color`
|
|
1024
|
-
*/
|
|
1025
|
-
function furthest(...colors) {
|
|
1026
|
-
return (color) => {
|
|
1027
|
-
const furthestColor = negative(nearest(...colors.map(negative))(color));
|
|
1028
|
-
return furthestColor;
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Makes color transformer which finds the best text color (black or white) for the given background color
|
|
1033
|
-
*
|
|
1034
|
-
* @public exported from `@promptbook/color`
|
|
1035
|
-
*/
|
|
1036
|
-
furthest(Color.get('white'), Color.from('black'));
|
|
1037
|
-
|
|
1038
|
-
/**
|
|
1039
|
-
* Makes color transformer which returns a grayscale version of the color
|
|
1040
|
-
*
|
|
1041
|
-
* @param amount from 0 to 1
|
|
1042
|
-
*
|
|
1043
|
-
* @public exported from `@promptbook/color`
|
|
1044
|
-
*/
|
|
1045
|
-
function grayscale(amount) {
|
|
1046
|
-
return ({ red, green, blue, alpha }) => {
|
|
1047
|
-
const average = (red + green + blue) / 3;
|
|
1048
|
-
red = Math.round(average * amount + red * (1 - amount));
|
|
1049
|
-
green = Math.round(average * amount + green * (1 - amount));
|
|
1050
|
-
blue = Math.round(average * amount + blue * (1 - amount));
|
|
1051
|
-
return Color.fromValues(red, green, blue, alpha);
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
976
|
/**
|
|
1056
977
|
* Makes color transformer which saturate the given color
|
|
1057
978
|
*
|
|
@@ -1461,6 +1382,19 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
1461
1382
|
/**/
|
|
1462
1383
|
// Note: In normal situations, we check the pipeline logic:
|
|
1463
1384
|
true);
|
|
1385
|
+
/**
|
|
1386
|
+
* Indicates whether cost-prevention is enabled. When true, real API keys are prevented from being used in tests.
|
|
1387
|
+
*
|
|
1388
|
+
* @private within the repository
|
|
1389
|
+
*/
|
|
1390
|
+
const IS_COST_PREVENTED = just(
|
|
1391
|
+
/*/
|
|
1392
|
+
// Note: In normal situations, we prevent ability to use real API keys in tests:
|
|
1393
|
+
true,
|
|
1394
|
+
/**/
|
|
1395
|
+
/**/
|
|
1396
|
+
// When working on preparations, you can temporarily turn off the prevention:
|
|
1397
|
+
false);
|
|
1464
1398
|
/**
|
|
1465
1399
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1466
1400
|
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
@@ -1474,7 +1408,7 @@ true);
|
|
|
1474
1408
|
function getErrorReportUrl(error) {
|
|
1475
1409
|
const report = {
|
|
1476
1410
|
title: `🐜 Error report from ${NAME}`,
|
|
1477
|
-
body: spaceTrim((block) => `
|
|
1411
|
+
body: spaceTrim$1((block) => `
|
|
1478
1412
|
|
|
1479
1413
|
|
|
1480
1414
|
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
@@ -1517,7 +1451,7 @@ function getErrorReportUrl(error) {
|
|
|
1517
1451
|
*/
|
|
1518
1452
|
class UnexpectedError extends Error {
|
|
1519
1453
|
constructor(message) {
|
|
1520
|
-
super(spaceTrim$
|
|
1454
|
+
super(spaceTrim$2((block) => `
|
|
1521
1455
|
${block(message)}
|
|
1522
1456
|
|
|
1523
1457
|
Note: This error should not happen.
|
|
@@ -1543,7 +1477,7 @@ class WrappedError extends Error {
|
|
|
1543
1477
|
constructor(whatWasThrown) {
|
|
1544
1478
|
const tag = `[🤮]`;
|
|
1545
1479
|
console.error(tag, whatWasThrown);
|
|
1546
|
-
super(spaceTrim$
|
|
1480
|
+
super(spaceTrim$2(`
|
|
1547
1481
|
Non-Error object was thrown
|
|
1548
1482
|
|
|
1549
1483
|
Note: Look for ${tag} in the console for more details
|
|
@@ -1767,7 +1701,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
1767
1701
|
pipelineString += '\n\n';
|
|
1768
1702
|
pipelineString += '```' + contentLanguage;
|
|
1769
1703
|
pipelineString += '\n';
|
|
1770
|
-
pipelineString += spaceTrim(content);
|
|
1704
|
+
pipelineString += spaceTrim$1(content);
|
|
1771
1705
|
// <- TODO: [main] !!3 Escape
|
|
1772
1706
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1773
1707
|
pipelineString += '\n';
|
|
@@ -1888,7 +1822,7 @@ function checkSerializableAsJson(options) {
|
|
|
1888
1822
|
}
|
|
1889
1823
|
else if (typeof value === 'object') {
|
|
1890
1824
|
if (value instanceof Date) {
|
|
1891
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
1825
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1892
1826
|
\`${name}\` is Date
|
|
1893
1827
|
|
|
1894
1828
|
Use \`string_date_iso8601\` instead
|
|
@@ -1907,7 +1841,7 @@ function checkSerializableAsJson(options) {
|
|
|
1907
1841
|
throw new UnexpectedError(`${name} is RegExp`);
|
|
1908
1842
|
}
|
|
1909
1843
|
else if (value instanceof Error) {
|
|
1910
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
1844
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1911
1845
|
\`${name}\` is unserialized Error
|
|
1912
1846
|
|
|
1913
1847
|
Use function \`serializeError\`
|
|
@@ -1930,7 +1864,7 @@ function checkSerializableAsJson(options) {
|
|
|
1930
1864
|
}
|
|
1931
1865
|
catch (error) {
|
|
1932
1866
|
assertsError(error);
|
|
1933
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
1867
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1934
1868
|
\`${name}\` is not serializable
|
|
1935
1869
|
|
|
1936
1870
|
${block(error.stack || error.message)}
|
|
@@ -1962,7 +1896,7 @@ function checkSerializableAsJson(options) {
|
|
|
1962
1896
|
}
|
|
1963
1897
|
}
|
|
1964
1898
|
else {
|
|
1965
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
1899
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1966
1900
|
\`${name}\` is unknown type
|
|
1967
1901
|
|
|
1968
1902
|
Additional message for \`${name}\`:
|
|
@@ -2256,7 +2190,7 @@ function validatePipeline(pipeline) {
|
|
|
2256
2190
|
if (!(error instanceof PipelineLogicError)) {
|
|
2257
2191
|
throw error;
|
|
2258
2192
|
}
|
|
2259
|
-
console.error(spaceTrim$
|
|
2193
|
+
console.error(spaceTrim$2((block) => `
|
|
2260
2194
|
Pipeline is not valid but logic errors are temporarily disabled via \`IS_PIPELINE_LOGIC_VALIDATED\`
|
|
2261
2195
|
|
|
2262
2196
|
${block(error.message)}
|
|
@@ -2283,7 +2217,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2283
2217
|
})();
|
|
2284
2218
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
2285
2219
|
// <- Note: [🚲]
|
|
2286
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2220
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2287
2221
|
Invalid promptbook URL "${pipeline.pipelineUrl}"
|
|
2288
2222
|
|
|
2289
2223
|
${block(pipelineIdentification)}
|
|
@@ -2291,7 +2225,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2291
2225
|
}
|
|
2292
2226
|
if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
|
|
2293
2227
|
// <- Note: [🚲]
|
|
2294
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2228
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2295
2229
|
Invalid Promptbook Version "${pipeline.bookVersion}"
|
|
2296
2230
|
|
|
2297
2231
|
${block(pipelineIdentification)}
|
|
@@ -2300,7 +2234,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2300
2234
|
// TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
|
|
2301
2235
|
if (!Array.isArray(pipeline.parameters)) {
|
|
2302
2236
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
2303
|
-
throw new ParseError(spaceTrim$
|
|
2237
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
2304
2238
|
Pipeline is valid JSON but with wrong structure
|
|
2305
2239
|
|
|
2306
2240
|
\`PipelineJson.parameters\` expected to be an array, but got ${typeof pipeline.parameters}
|
|
@@ -2311,7 +2245,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2311
2245
|
// TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
|
|
2312
2246
|
if (!Array.isArray(pipeline.tasks)) {
|
|
2313
2247
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
2314
|
-
throw new ParseError(spaceTrim$
|
|
2248
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
2315
2249
|
Pipeline is valid JSON but with wrong structure
|
|
2316
2250
|
|
|
2317
2251
|
\`PipelineJson.tasks\` expected to be an array, but got ${typeof pipeline.tasks}
|
|
@@ -2337,7 +2271,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2337
2271
|
// Note: Check each parameter individually
|
|
2338
2272
|
for (const parameter of pipeline.parameters) {
|
|
2339
2273
|
if (parameter.isInput && parameter.isOutput) {
|
|
2340
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2274
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2341
2275
|
|
|
2342
2276
|
Parameter \`{${parameter.name}}\` can not be both input and output
|
|
2343
2277
|
|
|
@@ -2348,7 +2282,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2348
2282
|
if (!parameter.isInput &&
|
|
2349
2283
|
!parameter.isOutput &&
|
|
2350
2284
|
!pipeline.tasks.some((task) => task.dependentParameterNames.includes(parameter.name))) {
|
|
2351
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2285
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2352
2286
|
Parameter \`{${parameter.name}}\` is created but not used
|
|
2353
2287
|
|
|
2354
2288
|
You can declare {${parameter.name}} as output parameter by adding in the header:
|
|
@@ -2360,7 +2294,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2360
2294
|
}
|
|
2361
2295
|
// Note: Testing that parameter is either input or result of some task
|
|
2362
2296
|
if (!parameter.isInput && !pipeline.tasks.some((task) => task.resultingParameterName === parameter.name)) {
|
|
2363
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2297
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2364
2298
|
Parameter \`{${parameter.name}}\` is declared but not defined
|
|
2365
2299
|
|
|
2366
2300
|
You can do one of these:
|
|
@@ -2376,14 +2310,14 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2376
2310
|
// Note: Checking each task individually
|
|
2377
2311
|
for (const task of pipeline.tasks) {
|
|
2378
2312
|
if (definedParameters.has(task.resultingParameterName)) {
|
|
2379
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2313
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2380
2314
|
Parameter \`{${task.resultingParameterName}}\` is defined multiple times
|
|
2381
2315
|
|
|
2382
2316
|
${block(pipelineIdentification)}
|
|
2383
2317
|
`));
|
|
2384
2318
|
}
|
|
2385
2319
|
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
2386
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2320
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2387
2321
|
Parameter name {${task.resultingParameterName}} is reserved, please use different name
|
|
2388
2322
|
|
|
2389
2323
|
${block(pipelineIdentification)}
|
|
@@ -2393,7 +2327,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2393
2327
|
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
2394
2328
|
if (!task.format &&
|
|
2395
2329
|
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
2396
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2330
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2397
2331
|
Joker parameters are used for {${task.resultingParameterName}} but no expectations are defined
|
|
2398
2332
|
|
|
2399
2333
|
${block(pipelineIdentification)}
|
|
@@ -2401,7 +2335,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2401
2335
|
}
|
|
2402
2336
|
for (const joker of task.jokerParameterNames) {
|
|
2403
2337
|
if (!task.dependentParameterNames.includes(joker)) {
|
|
2404
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2338
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2405
2339
|
Parameter \`{${joker}}\` is used for {${task.resultingParameterName}} as joker but not in \`dependentParameterNames\`
|
|
2406
2340
|
|
|
2407
2341
|
${block(pipelineIdentification)}
|
|
@@ -2412,21 +2346,21 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2412
2346
|
if (task.expectations) {
|
|
2413
2347
|
for (const [unit, { min, max }] of Object.entries(task.expectations)) {
|
|
2414
2348
|
if (min !== undefined && max !== undefined && min > max) {
|
|
2415
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2349
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2416
2350
|
Min expectation (=${min}) of ${unit} is higher than max expectation (=${max})
|
|
2417
2351
|
|
|
2418
2352
|
${block(pipelineIdentification)}
|
|
2419
2353
|
`));
|
|
2420
2354
|
}
|
|
2421
2355
|
if (min !== undefined && min < 0) {
|
|
2422
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2356
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2423
2357
|
Min expectation of ${unit} must be zero or positive
|
|
2424
2358
|
|
|
2425
2359
|
${block(pipelineIdentification)}
|
|
2426
2360
|
`));
|
|
2427
2361
|
}
|
|
2428
2362
|
if (max !== undefined && max <= 0) {
|
|
2429
|
-
throw new PipelineLogicError(spaceTrim$
|
|
2363
|
+
throw new PipelineLogicError(spaceTrim$2((block) => `
|
|
2430
2364
|
Max expectation of ${unit} must be positive
|
|
2431
2365
|
|
|
2432
2366
|
${block(pipelineIdentification)}
|
|
@@ -2448,7 +2382,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2448
2382
|
while (unresovedTasks.length > 0) {
|
|
2449
2383
|
if (loopLimit-- < 0) {
|
|
2450
2384
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
2451
|
-
throw new UnexpectedError(spaceTrim$
|
|
2385
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
2452
2386
|
Loop limit reached during detection of circular dependencies in \`validatePipeline\`
|
|
2453
2387
|
|
|
2454
2388
|
${block(pipelineIdentification)}
|
|
@@ -2458,7 +2392,7 @@ function validatePipeline_InnerFunction(pipeline) {
|
|
|
2458
2392
|
if (currentlyResovedTasks.length === 0) {
|
|
2459
2393
|
throw new PipelineLogicError(
|
|
2460
2394
|
// TODO: [🐎] DRY
|
|
2461
|
-
spaceTrim$
|
|
2395
|
+
spaceTrim$2((block) => `
|
|
2462
2396
|
|
|
2463
2397
|
Can not resolve some parameters:
|
|
2464
2398
|
Either you are using a parameter that is not defined, or there are some circular dependencies.
|
|
@@ -2622,7 +2556,7 @@ class SimplePipelineCollection {
|
|
|
2622
2556
|
for (const pipeline of pipelines) {
|
|
2623
2557
|
// TODO: [👠] DRY
|
|
2624
2558
|
if (pipeline.pipelineUrl === undefined) {
|
|
2625
|
-
throw new PipelineUrlError(spaceTrim$
|
|
2559
|
+
throw new PipelineUrlError(spaceTrim$2(`
|
|
2626
2560
|
Pipeline with name "${pipeline.title}" does not have defined URL
|
|
2627
2561
|
|
|
2628
2562
|
File:
|
|
@@ -2644,7 +2578,7 @@ class SimplePipelineCollection {
|
|
|
2644
2578
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
2645
2579
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
2646
2580
|
const existing = this.collection.get(pipeline.pipelineUrl);
|
|
2647
|
-
throw new PipelineUrlError(spaceTrim$
|
|
2581
|
+
throw new PipelineUrlError(spaceTrim$2(`
|
|
2648
2582
|
Pipeline with URL ${pipeline.pipelineUrl} is already in the collection 🍎
|
|
2649
2583
|
|
|
2650
2584
|
Conflicting files:
|
|
@@ -2676,13 +2610,13 @@ class SimplePipelineCollection {
|
|
|
2676
2610
|
const pipeline = this.collection.get(url);
|
|
2677
2611
|
if (!pipeline) {
|
|
2678
2612
|
if (this.listPipelines().length === 0) {
|
|
2679
|
-
throw new NotFoundError(spaceTrim$
|
|
2613
|
+
throw new NotFoundError(spaceTrim$2(`
|
|
2680
2614
|
Pipeline with url "${url}" not found
|
|
2681
2615
|
|
|
2682
2616
|
No pipelines available
|
|
2683
2617
|
`));
|
|
2684
2618
|
}
|
|
2685
|
-
throw new NotFoundError(spaceTrim$
|
|
2619
|
+
throw new NotFoundError(spaceTrim$2((block) => `
|
|
2686
2620
|
Pipeline with url "${url}" not found
|
|
2687
2621
|
|
|
2688
2622
|
Available pipelines:
|
|
@@ -2723,7 +2657,7 @@ function createPipelineCollectionFromJson(...promptbooks) {
|
|
|
2723
2657
|
*/
|
|
2724
2658
|
class MissingToolsError extends Error {
|
|
2725
2659
|
constructor(message) {
|
|
2726
|
-
super(spaceTrim$
|
|
2660
|
+
super(spaceTrim$2((block) => `
|
|
2727
2661
|
${block(message)}
|
|
2728
2662
|
|
|
2729
2663
|
Note: You have probably forgot to provide some tools for pipeline execution or preparation
|
|
@@ -2830,6 +2764,19 @@ class CollectionError extends Error {
|
|
|
2830
2764
|
}
|
|
2831
2765
|
}
|
|
2832
2766
|
|
|
2767
|
+
/**
|
|
2768
|
+
* This error indicates error from the database
|
|
2769
|
+
*
|
|
2770
|
+
* @public exported from `@promptbook/core`
|
|
2771
|
+
*/
|
|
2772
|
+
class DatabaseError extends Error {
|
|
2773
|
+
constructor(message) {
|
|
2774
|
+
super(message);
|
|
2775
|
+
this.name = 'DatabaseError';
|
|
2776
|
+
Object.setPrototypeOf(this, DatabaseError.prototype);
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2833
2780
|
/**
|
|
2834
2781
|
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
2835
2782
|
*
|
|
@@ -2905,7 +2852,7 @@ class NotAllowed extends Error {
|
|
|
2905
2852
|
*/
|
|
2906
2853
|
class NotYetImplementedError extends Error {
|
|
2907
2854
|
constructor(message) {
|
|
2908
|
-
super(spaceTrim$
|
|
2855
|
+
super(spaceTrim$2((block) => `
|
|
2909
2856
|
${block(message)}
|
|
2910
2857
|
|
|
2911
2858
|
Note: This feature is not implemented yet but it will be soon.
|
|
@@ -2924,6 +2871,7 @@ class NotYetImplementedError extends Error {
|
|
|
2924
2871
|
/**
|
|
2925
2872
|
* Generates random token
|
|
2926
2873
|
*
|
|
2874
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
2927
2875
|
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2928
2876
|
*
|
|
2929
2877
|
* @private internal helper function
|
|
@@ -2993,6 +2941,7 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2993
2941
|
UnexpectedError,
|
|
2994
2942
|
WrappedError,
|
|
2995
2943
|
NotAllowed,
|
|
2944
|
+
DatabaseError,
|
|
2996
2945
|
// TODO: [🪑]> VersionMismatchError,
|
|
2997
2946
|
};
|
|
2998
2947
|
/**
|
|
@@ -3040,7 +2989,7 @@ function serializeError(error) {
|
|
|
3040
2989
|
const { name, message, stack } = error;
|
|
3041
2990
|
const { id } = error;
|
|
3042
2991
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
3043
|
-
console.error(spaceTrim((block) => `
|
|
2992
|
+
console.error(spaceTrim$1((block) => `
|
|
3044
2993
|
|
|
3045
2994
|
Cannot serialize error with name "${name}"
|
|
3046
2995
|
|
|
@@ -3073,7 +3022,7 @@ function jsonParse(value) {
|
|
|
3073
3022
|
}
|
|
3074
3023
|
else if (typeof value !== 'string') {
|
|
3075
3024
|
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
3076
|
-
throw new Error(spaceTrim(`
|
|
3025
|
+
throw new Error(spaceTrim$1(`
|
|
3077
3026
|
Can not parse JSON from non-string value.
|
|
3078
3027
|
|
|
3079
3028
|
The value type: ${typeof value}
|
|
@@ -3087,7 +3036,7 @@ function jsonParse(value) {
|
|
|
3087
3036
|
if (!(error instanceof Error)) {
|
|
3088
3037
|
throw error;
|
|
3089
3038
|
}
|
|
3090
|
-
throw new Error(spaceTrim((block) => `
|
|
3039
|
+
throw new Error(spaceTrim$1((block) => `
|
|
3091
3040
|
${block(error.message)}
|
|
3092
3041
|
|
|
3093
3042
|
The expected JSON text:
|
|
@@ -3140,7 +3089,7 @@ function deserializeError(error) {
|
|
|
3140
3089
|
message = `${name}: ${message}`;
|
|
3141
3090
|
}
|
|
3142
3091
|
if (stack !== undefined && stack !== '') {
|
|
3143
|
-
message = spaceTrim((block) => `
|
|
3092
|
+
message = spaceTrim$1((block) => `
|
|
3144
3093
|
${block(message)}
|
|
3145
3094
|
|
|
3146
3095
|
Original stack trace:
|
|
@@ -3177,11 +3126,11 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
3177
3126
|
throw deserializeError(errors[0]);
|
|
3178
3127
|
}
|
|
3179
3128
|
else {
|
|
3180
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
3129
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
3181
3130
|
Multiple errors occurred during Promptbook execution
|
|
3182
3131
|
|
|
3183
3132
|
${block(errors
|
|
3184
|
-
.map(({ name, stack, message }, index) => spaceTrim$
|
|
3133
|
+
.map(({ name, stack, message }, index) => spaceTrim$2((block) => `
|
|
3185
3134
|
${name} ${index + 1}:
|
|
3186
3135
|
${block(stack || message)}
|
|
3187
3136
|
`))
|
|
@@ -3652,14 +3601,14 @@ class MultipleLlmExecutionTools {
|
|
|
3652
3601
|
if (description === undefined) {
|
|
3653
3602
|
return headLine;
|
|
3654
3603
|
}
|
|
3655
|
-
return spaceTrim((block) => `
|
|
3604
|
+
return spaceTrim$1((block) => `
|
|
3656
3605
|
${headLine}
|
|
3657
3606
|
|
|
3658
3607
|
${ /* <- Note: Indenting the description: */block(description)}
|
|
3659
3608
|
`);
|
|
3660
3609
|
})
|
|
3661
3610
|
.join('\n\n');
|
|
3662
|
-
return spaceTrim((block) => `
|
|
3611
|
+
return spaceTrim$1((block) => `
|
|
3663
3612
|
Multiple LLM Providers:
|
|
3664
3613
|
|
|
3665
3614
|
${block(innerModelsTitlesAndDescriptions)}
|
|
@@ -3750,7 +3699,7 @@ class MultipleLlmExecutionTools {
|
|
|
3750
3699
|
// 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3751
3700
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
3752
3701
|
// 3) ...
|
|
3753
|
-
spaceTrim((block) => `
|
|
3702
|
+
spaceTrim$1((block) => `
|
|
3754
3703
|
All execution tools of ${this.title} failed:
|
|
3755
3704
|
|
|
3756
3705
|
${block(errors
|
|
@@ -3763,7 +3712,7 @@ class MultipleLlmExecutionTools {
|
|
|
3763
3712
|
throw new PipelineExecutionError(`You have not provided any \`LlmExecutionTools\` into ${this.title}`);
|
|
3764
3713
|
}
|
|
3765
3714
|
else {
|
|
3766
|
-
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
3715
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
3767
3716
|
You have not provided any \`LlmExecutionTools\` that support model variant "${prompt.modelRequirements.modelVariant}" into ${this.title}
|
|
3768
3717
|
|
|
3769
3718
|
Available \`LlmExecutionTools\`:
|
|
@@ -3796,7 +3745,7 @@ class MultipleLlmExecutionTools {
|
|
|
3796
3745
|
*/
|
|
3797
3746
|
function joinLlmExecutionTools(title, ...llmExecutionTools) {
|
|
3798
3747
|
if (llmExecutionTools.length === 0) {
|
|
3799
|
-
const warningMessage = spaceTrim(`
|
|
3748
|
+
const warningMessage = spaceTrim$1(`
|
|
3800
3749
|
You have not provided any \`LlmExecutionTools\`
|
|
3801
3750
|
This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.
|
|
3802
3751
|
|
|
@@ -4049,14 +3998,14 @@ function $registeredScrapersMessage(availableScrapers) {
|
|
|
4049
3998
|
return { ...metadata, isMetadataAviailable, isInstalled, isAvailableInTools };
|
|
4050
3999
|
});
|
|
4051
4000
|
if (metadata.length === 0) {
|
|
4052
|
-
return spaceTrim(`
|
|
4001
|
+
return spaceTrim$1(`
|
|
4053
4002
|
**No scrapers are available**
|
|
4054
4003
|
|
|
4055
4004
|
This is a unexpected behavior, you are probably using some broken version of Promptbook
|
|
4056
4005
|
At least there should be available the metadata of the scrapers
|
|
4057
4006
|
`);
|
|
4058
4007
|
}
|
|
4059
|
-
return spaceTrim((block) => `
|
|
4008
|
+
return spaceTrim$1((block) => `
|
|
4060
4009
|
Available scrapers are:
|
|
4061
4010
|
${block(metadata
|
|
4062
4011
|
.map(({ packageName, className, isMetadataAviailable, isInstalled, mimeTypes, isAvailableInBrowser, isAvailableInTools, }, i) => {
|
|
@@ -4558,7 +4507,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
|
|
|
4558
4507
|
else if (urlOrRequest instanceof Request) {
|
|
4559
4508
|
url = urlOrRequest.url;
|
|
4560
4509
|
}
|
|
4561
|
-
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
4510
|
+
throw new PromptbookFetchError(spaceTrim$1((block) => `
|
|
4562
4511
|
Can not fetch "${url}"
|
|
4563
4512
|
|
|
4564
4513
|
Fetch error:
|
|
@@ -4719,7 +4668,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
4719
4668
|
const fileExtension = getFileExtension(filename);
|
|
4720
4669
|
const mimeType = extensionToMimeType(fileExtension || '');
|
|
4721
4670
|
if (!(await isFileExisting(filename, tools.fs))) {
|
|
4722
|
-
throw new NotFoundError(spaceTrim((block) => `
|
|
4671
|
+
throw new NotFoundError(spaceTrim$1((block) => `
|
|
4723
4672
|
Can not make source handler for file which does not exist:
|
|
4724
4673
|
|
|
4725
4674
|
File:
|
|
@@ -4812,7 +4761,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
4812
4761
|
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
4813
4762
|
break;
|
|
4814
4763
|
}
|
|
4815
|
-
console.warn(spaceTrim((block) => `
|
|
4764
|
+
console.warn(spaceTrim$1((block) => `
|
|
4816
4765
|
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
4817
4766
|
|
|
4818
4767
|
The source:
|
|
@@ -4828,7 +4777,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
4828
4777
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
4829
4778
|
}
|
|
4830
4779
|
if (partialPieces === null) {
|
|
4831
|
-
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
4780
|
+
throw new KnowledgeScrapeError(spaceTrim$1((block) => `
|
|
4832
4781
|
Cannot scrape knowledge
|
|
4833
4782
|
|
|
4834
4783
|
The source:
|
|
@@ -4907,7 +4856,7 @@ async function prepareTasks(pipeline, tools, options) {
|
|
|
4907
4856
|
if (task.taskType === 'PROMPT_TASK' &&
|
|
4908
4857
|
knowledgePiecesCount > 0 &&
|
|
4909
4858
|
!dependentParameterNames.includes('knowledge')) {
|
|
4910
|
-
preparedContent = spaceTrim$
|
|
4859
|
+
preparedContent = spaceTrim$2(`
|
|
4911
4860
|
{content}
|
|
4912
4861
|
|
|
4913
4862
|
## Knowledge
|
|
@@ -5220,7 +5169,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
5220
5169
|
}
|
|
5221
5170
|
catch (error) {
|
|
5222
5171
|
assertsError(error);
|
|
5223
|
-
throw new ParseError(spaceTrim$
|
|
5172
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
5224
5173
|
Can not extract variables from the script
|
|
5225
5174
|
${block(error.stack || error.message)}
|
|
5226
5175
|
|
|
@@ -5403,7 +5352,7 @@ const CsvFormatParser = {
|
|
|
5403
5352
|
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
5404
5353
|
const csv = csvParse(value, settings);
|
|
5405
5354
|
if (csv.errors.length !== 0) {
|
|
5406
|
-
throw new CsvFormatError(spaceTrim((block) => `
|
|
5355
|
+
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
5407
5356
|
CSV parsing error
|
|
5408
5357
|
|
|
5409
5358
|
Error(s) from CSV parsing:
|
|
@@ -5448,7 +5397,7 @@ const CsvFormatParser = {
|
|
|
5448
5397
|
const { value, settings, mapCallback, onProgress } = options;
|
|
5449
5398
|
const csv = csvParse(value, settings);
|
|
5450
5399
|
if (csv.errors.length !== 0) {
|
|
5451
|
-
throw new CsvFormatError(spaceTrim((block) => `
|
|
5400
|
+
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
5452
5401
|
CSV parsing error
|
|
5453
5402
|
|
|
5454
5403
|
Error(s) from CSV parsing:
|
|
@@ -5658,7 +5607,7 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
5658
5607
|
}
|
|
5659
5608
|
// Phase 2️⃣: Non-matching mapping
|
|
5660
5609
|
if (expectedParameterNames.size !== availableParametersNames.size) {
|
|
5661
|
-
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
5610
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
5662
5611
|
Can not map available parameters to expected parameters
|
|
5663
5612
|
|
|
5664
5613
|
Mapped parameters:
|
|
@@ -5776,18 +5725,6 @@ function templateParameters(template, parameters) {
|
|
|
5776
5725
|
return replacedTemplates;
|
|
5777
5726
|
}
|
|
5778
5727
|
|
|
5779
|
-
/**
|
|
5780
|
-
* Logs an LLM call with the given report.
|
|
5781
|
-
*
|
|
5782
|
-
* @private internal utility of `createPipelineExecutor`
|
|
5783
|
-
*/
|
|
5784
|
-
function logLlmCall(logLlmCall, report) {
|
|
5785
|
-
logLlmCall({
|
|
5786
|
-
modelName: 'model' /* <- TODO: How to get model name from the report */,
|
|
5787
|
-
report,
|
|
5788
|
-
});
|
|
5789
|
-
}
|
|
5790
|
-
|
|
5791
5728
|
/**
|
|
5792
5729
|
* Extracts all code blocks from markdown.
|
|
5793
5730
|
*
|
|
@@ -6106,7 +6043,7 @@ function validatePromptResult(options) {
|
|
|
6106
6043
|
}
|
|
6107
6044
|
catch (error) {
|
|
6108
6045
|
keepUnused(error);
|
|
6109
|
-
throw new ExpectError(spaceTrim$
|
|
6046
|
+
throw new ExpectError(spaceTrim$2((block) => `
|
|
6110
6047
|
Expected valid JSON string
|
|
6111
6048
|
|
|
6112
6049
|
The expected JSON text:
|
|
@@ -6155,7 +6092,7 @@ function validatePromptResult(options) {
|
|
|
6155
6092
|
*/
|
|
6156
6093
|
async function executeAttempts(options) {
|
|
6157
6094
|
const { jokerParameterNames, priority, maxAttempts, // <- Note: [💂]
|
|
6158
|
-
preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall
|
|
6095
|
+
preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, onProgress, logLlmCall, } = options;
|
|
6159
6096
|
const $ongoingTaskResult = {
|
|
6160
6097
|
$result: null,
|
|
6161
6098
|
$resultString: null,
|
|
@@ -6169,7 +6106,7 @@ async function executeAttempts(options) {
|
|
|
6169
6106
|
const jokerParameterName = jokerParameterNames[jokerParameterNames.length + attemptIndex];
|
|
6170
6107
|
// TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
6171
6108
|
if (isJokerAttempt && !jokerParameterName) {
|
|
6172
|
-
throw new UnexpectedError(spaceTrim$
|
|
6109
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6173
6110
|
Joker not found in attempt ${attemptIndex}
|
|
6174
6111
|
|
|
6175
6112
|
${block(pipelineIdentification)}
|
|
@@ -6180,7 +6117,7 @@ async function executeAttempts(options) {
|
|
|
6180
6117
|
$ongoingTaskResult.$expectError = null;
|
|
6181
6118
|
if (isJokerAttempt) {
|
|
6182
6119
|
if (parameters[jokerParameterName] === undefined) {
|
|
6183
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6120
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6184
6121
|
Joker parameter {${jokerParameterName}} not defined
|
|
6185
6122
|
|
|
6186
6123
|
${block(pipelineIdentification)}
|
|
@@ -6238,7 +6175,7 @@ async function executeAttempts(options) {
|
|
|
6238
6175
|
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
6239
6176
|
break variant;
|
|
6240
6177
|
case 'EMBEDDING':
|
|
6241
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6178
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6242
6179
|
Embedding model can not be used in pipeline
|
|
6243
6180
|
|
|
6244
6181
|
This should be catched during parsing
|
|
@@ -6249,7 +6186,7 @@ async function executeAttempts(options) {
|
|
|
6249
6186
|
break variant;
|
|
6250
6187
|
// <- case [🤖]:
|
|
6251
6188
|
default:
|
|
6252
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6189
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6253
6190
|
Unknown model variant "${task.modelRequirements.modelVariant}"
|
|
6254
6191
|
|
|
6255
6192
|
${block(pipelineIdentification)}
|
|
@@ -6260,14 +6197,14 @@ async function executeAttempts(options) {
|
|
|
6260
6197
|
break;
|
|
6261
6198
|
case 'SCRIPT_TASK':
|
|
6262
6199
|
if (arrayableToArray(tools.script).length === 0) {
|
|
6263
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6200
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6264
6201
|
No script execution tools are available
|
|
6265
6202
|
|
|
6266
6203
|
${block(pipelineIdentification)}
|
|
6267
6204
|
`));
|
|
6268
6205
|
}
|
|
6269
6206
|
if (!task.contentLanguage) {
|
|
6270
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6207
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6271
6208
|
Script language is not defined for SCRIPT TASK "${task.name}"
|
|
6272
6209
|
|
|
6273
6210
|
${block(pipelineIdentification)}
|
|
@@ -6298,7 +6235,7 @@ async function executeAttempts(options) {
|
|
|
6298
6235
|
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
6299
6236
|
}
|
|
6300
6237
|
else {
|
|
6301
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6238
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6302
6239
|
Script execution failed ${$ongoingTaskResult.$scriptPipelineExecutionErrors.length}x
|
|
6303
6240
|
|
|
6304
6241
|
${block(pipelineIdentification)}
|
|
@@ -6312,7 +6249,7 @@ async function executeAttempts(options) {
|
|
|
6312
6249
|
break taskType;
|
|
6313
6250
|
case 'DIALOG_TASK':
|
|
6314
6251
|
if (tools.userInterface === undefined) {
|
|
6315
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6252
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6316
6253
|
User interface tools are not available
|
|
6317
6254
|
|
|
6318
6255
|
${block(pipelineIdentification)}
|
|
@@ -6330,7 +6267,7 @@ async function executeAttempts(options) {
|
|
|
6330
6267
|
break taskType;
|
|
6331
6268
|
// <- case: [🅱]
|
|
6332
6269
|
default:
|
|
6333
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6270
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6334
6271
|
Unknown execution type "${task.taskType}"
|
|
6335
6272
|
|
|
6336
6273
|
${block(pipelineIdentification)}
|
|
@@ -6417,15 +6354,18 @@ async function executeAttempts(options) {
|
|
|
6417
6354
|
: serializeError($ongoingTaskResult.$expectError),
|
|
6418
6355
|
};
|
|
6419
6356
|
$executionReport.promptExecutions.push(executionPromptReport);
|
|
6420
|
-
if (logLlmCall
|
|
6421
|
-
logLlmCall(
|
|
6357
|
+
if (logLlmCall) {
|
|
6358
|
+
logLlmCall({
|
|
6359
|
+
modelName: 'model' /* <- TODO: How to get model name from the report */,
|
|
6360
|
+
report: executionPromptReport,
|
|
6361
|
+
});
|
|
6422
6362
|
}
|
|
6423
6363
|
}
|
|
6424
6364
|
}
|
|
6425
6365
|
if ($ongoingTaskResult.$expectError !== null && attemptIndex === maxAttempts - 1) {
|
|
6426
6366
|
// Note: Create a summary of all failures
|
|
6427
6367
|
const failuresSummary = $ongoingTaskResult.$failedResults
|
|
6428
|
-
.map((failure) => spaceTrim$
|
|
6368
|
+
.map((failure) => spaceTrim$2((block) => {
|
|
6429
6369
|
var _a, _b;
|
|
6430
6370
|
return `
|
|
6431
6371
|
Attempt ${failure.attemptIndex + 1}:
|
|
@@ -6435,14 +6375,14 @@ async function executeAttempts(options) {
|
|
|
6435
6375
|
Result:
|
|
6436
6376
|
${block(failure.result === null
|
|
6437
6377
|
? 'null'
|
|
6438
|
-
: spaceTrim$
|
|
6378
|
+
: spaceTrim$2(failure.result)
|
|
6439
6379
|
.split('\n')
|
|
6440
6380
|
.map((line) => `> ${line}`)
|
|
6441
6381
|
.join('\n'))}
|
|
6442
6382
|
`;
|
|
6443
6383
|
}))
|
|
6444
6384
|
.join('\n\n---\n\n');
|
|
6445
|
-
throw new PipelineExecutionError(spaceTrim$
|
|
6385
|
+
throw new PipelineExecutionError(spaceTrim$2((block) => {
|
|
6446
6386
|
var _a;
|
|
6447
6387
|
return `
|
|
6448
6388
|
LLM execution failed ${maxExecutionAttempts}x
|
|
@@ -6462,7 +6402,7 @@ async function executeAttempts(options) {
|
|
|
6462
6402
|
}
|
|
6463
6403
|
}
|
|
6464
6404
|
if ($ongoingTaskResult.$resultString === null) {
|
|
6465
|
-
throw new UnexpectedError(spaceTrim$
|
|
6405
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6466
6406
|
Something went wrong and prompt result is null
|
|
6467
6407
|
|
|
6468
6408
|
${block(pipelineIdentification)}
|
|
@@ -6489,7 +6429,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6489
6429
|
return /* not await */ executeAttempts({ ...options, logLlmCall });
|
|
6490
6430
|
}
|
|
6491
6431
|
if (jokerParameterNames.length !== 0) {
|
|
6492
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
6432
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
6493
6433
|
JOKER parameters are not supported together with FOREACH command
|
|
6494
6434
|
|
|
6495
6435
|
[🧞♀️] This should be prevented in \`validatePipeline\`
|
|
@@ -6502,7 +6442,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6502
6442
|
if (formatDefinition === undefined) {
|
|
6503
6443
|
throw new UnexpectedError(
|
|
6504
6444
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
6505
|
-
spaceTrim((block) => `
|
|
6445
|
+
spaceTrim$1((block) => `
|
|
6506
6446
|
Unsupported format "${task.foreach.formatName}"
|
|
6507
6447
|
|
|
6508
6448
|
Available formats:
|
|
@@ -6519,7 +6459,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6519
6459
|
if (subvalueParser === undefined) {
|
|
6520
6460
|
throw new UnexpectedError(
|
|
6521
6461
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
6522
|
-
spaceTrim((block) => `
|
|
6462
|
+
spaceTrim$1((block) => `
|
|
6523
6463
|
Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
|
|
6524
6464
|
|
|
6525
6465
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
@@ -6559,7 +6499,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6559
6499
|
if (!(error instanceof PipelineExecutionError)) {
|
|
6560
6500
|
throw error;
|
|
6561
6501
|
}
|
|
6562
|
-
const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
|
|
6502
|
+
const highLevelError = new PipelineExecutionError(spaceTrim$1((block) => `
|
|
6563
6503
|
${error.message}
|
|
6564
6504
|
|
|
6565
6505
|
This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
|
|
@@ -6583,7 +6523,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6583
6523
|
...options,
|
|
6584
6524
|
priority: priority + index,
|
|
6585
6525
|
parameters: allSubparameters,
|
|
6586
|
-
pipelineIdentification: spaceTrim((block) => `
|
|
6526
|
+
pipelineIdentification: spaceTrim$1((block) => `
|
|
6587
6527
|
${block(pipelineIdentification)}
|
|
6588
6528
|
Subparameter index: ${index}
|
|
6589
6529
|
`),
|
|
@@ -6592,7 +6532,7 @@ async function executeFormatSubvalues(options) {
|
|
|
6592
6532
|
}
|
|
6593
6533
|
catch (error) {
|
|
6594
6534
|
if (length > BIG_DATASET_TRESHOLD) {
|
|
6595
|
-
console.error(spaceTrim((block) => `
|
|
6535
|
+
console.error(spaceTrim$1((block) => `
|
|
6596
6536
|
${error.message}
|
|
6597
6537
|
|
|
6598
6538
|
This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
|
|
@@ -6692,7 +6632,7 @@ async function getKnowledgeForTask(options) {
|
|
|
6692
6632
|
},
|
|
6693
6633
|
content: task.content,
|
|
6694
6634
|
parameters,
|
|
6695
|
-
};
|
|
6635
|
+
}; /* <- Note: [🤛] */
|
|
6696
6636
|
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
6697
6637
|
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
6698
6638
|
const { index } = knowledgePiece;
|
|
@@ -6768,7 +6708,7 @@ async function getReservedParametersForTask(options) {
|
|
|
6768
6708
|
// Note: Doublecheck that ALL reserved parameters are defined:
|
|
6769
6709
|
for (const parameterName of RESERVED_PARAMETER_NAMES) {
|
|
6770
6710
|
if (reservedParameters[parameterName] === undefined) {
|
|
6771
|
-
throw new UnexpectedError(spaceTrim$
|
|
6711
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6772
6712
|
Reserved parameter {${parameterName}} is not defined
|
|
6773
6713
|
|
|
6774
6714
|
${block(pipelineIdentification)}
|
|
@@ -6794,7 +6734,7 @@ async function executeTask(options) {
|
|
|
6794
6734
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
6795
6735
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
6796
6736
|
if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
|
|
6797
|
-
throw new UnexpectedError(spaceTrim$
|
|
6737
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6798
6738
|
Dependent parameters are not consistent with used parameters:
|
|
6799
6739
|
|
|
6800
6740
|
Dependent parameters:
|
|
@@ -6838,7 +6778,7 @@ async function executeTask(options) {
|
|
|
6838
6778
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
6839
6779
|
// Houston, we have a problem
|
|
6840
6780
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
6841
|
-
throw new UnexpectedError(spaceTrim$
|
|
6781
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
6842
6782
|
Parameter \`{${parameterName}}\` is NOT defined
|
|
6843
6783
|
BUT used in task "${currentTask.title || currentTask.name}"
|
|
6844
6784
|
|
|
@@ -6907,7 +6847,7 @@ function filterJustOutputParameters(options) {
|
|
|
6907
6847
|
for (const parameter of preparedPipeline.parameters.filter(({ isOutput }) => isOutput)) {
|
|
6908
6848
|
if (parametersToPass[parameter.name] === undefined) {
|
|
6909
6849
|
// [4]
|
|
6910
|
-
$warnings.push(new PipelineExecutionError(spaceTrim$
|
|
6850
|
+
$warnings.push(new PipelineExecutionError(spaceTrim$2((block) => `
|
|
6911
6851
|
Parameter \`{${parameter.name}}\` should be an output parameter, but it was not generated during pipeline execution
|
|
6912
6852
|
|
|
6913
6853
|
Note: This is a warning which happened after the pipeline was executed, and \`{${parameter.name}}\` was not for some reason defined in output parameters
|
|
@@ -7015,7 +6955,7 @@ async function executePipeline(options) {
|
|
|
7015
6955
|
for (const parameterName of Object.keys(inputParameters)) {
|
|
7016
6956
|
const parameter = preparedPipeline.parameters.find(({ name }) => name === parameterName);
|
|
7017
6957
|
if (parameter === undefined) {
|
|
7018
|
-
warnings.push(new PipelineExecutionError(spaceTrim$
|
|
6958
|
+
warnings.push(new PipelineExecutionError(spaceTrim$2((block) => `
|
|
7019
6959
|
Extra parameter {${parameterName}} is being passed which is not part of the pipeline.
|
|
7020
6960
|
|
|
7021
6961
|
${block(pipelineIdentification)}
|
|
@@ -7030,7 +6970,7 @@ async function executePipeline(options) {
|
|
|
7030
6970
|
// TODO: [🧠] This should be also non-critical error
|
|
7031
6971
|
return exportJson({
|
|
7032
6972
|
name: 'pipelineExecutorResult',
|
|
7033
|
-
message: spaceTrim$
|
|
6973
|
+
message: spaceTrim$2((block) => `
|
|
7034
6974
|
Unsuccessful PipelineExecutorResult (with extra parameter {${parameter.name}}) PipelineExecutorResult
|
|
7035
6975
|
|
|
7036
6976
|
${block(pipelineIdentification)}
|
|
@@ -7039,7 +6979,7 @@ async function executePipeline(options) {
|
|
|
7039
6979
|
value: {
|
|
7040
6980
|
isSuccessful: false,
|
|
7041
6981
|
errors: [
|
|
7042
|
-
new PipelineExecutionError(spaceTrim$
|
|
6982
|
+
new PipelineExecutionError(spaceTrim$2((block) => `
|
|
7043
6983
|
Parameter \`{${parameter.name}}\` is passed as input parameter but it is not input
|
|
7044
6984
|
|
|
7045
6985
|
${block(pipelineIdentification)}
|
|
@@ -7066,7 +7006,7 @@ async function executePipeline(options) {
|
|
|
7066
7006
|
while (unresovedTasks.length > 0) {
|
|
7067
7007
|
if (loopLimit-- < 0) {
|
|
7068
7008
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
7069
|
-
throw new UnexpectedError(spaceTrim$
|
|
7009
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
7070
7010
|
Loop limit reached during resolving parameters pipeline execution
|
|
7071
7011
|
|
|
7072
7012
|
${block(pipelineIdentification)}
|
|
@@ -7076,7 +7016,7 @@ async function executePipeline(options) {
|
|
|
7076
7016
|
if (!currentTask && resolving.length === 0) {
|
|
7077
7017
|
throw new UnexpectedError(
|
|
7078
7018
|
// TODO: [🐎] DRY
|
|
7079
|
-
spaceTrim$
|
|
7019
|
+
spaceTrim$2((block) => `
|
|
7080
7020
|
Can not resolve some parameters:
|
|
7081
7021
|
|
|
7082
7022
|
${block(pipelineIdentification)}
|
|
@@ -7116,7 +7056,7 @@ async function executePipeline(options) {
|
|
|
7116
7056
|
tools,
|
|
7117
7057
|
onProgress(newOngoingResult) {
|
|
7118
7058
|
if (isReturned) {
|
|
7119
|
-
throw new UnexpectedError(spaceTrim$
|
|
7059
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
7120
7060
|
Can not call \`onProgress\` after pipeline execution is finished
|
|
7121
7061
|
|
|
7122
7062
|
${block(pipelineIdentification)}
|
|
@@ -7133,7 +7073,7 @@ async function executePipeline(options) {
|
|
|
7133
7073
|
},
|
|
7134
7074
|
logLlmCall,
|
|
7135
7075
|
$executionReport: executionReport,
|
|
7136
|
-
pipelineIdentification: spaceTrim$
|
|
7076
|
+
pipelineIdentification: spaceTrim$2((block) => `
|
|
7137
7077
|
${block(pipelineIdentification)}
|
|
7138
7078
|
Task name: ${currentTask.name}
|
|
7139
7079
|
Task title: ${currentTask.title}
|
|
@@ -7242,7 +7182,7 @@ function createPipelineExecutor(options) {
|
|
|
7242
7182
|
preparedPipeline = pipeline;
|
|
7243
7183
|
}
|
|
7244
7184
|
else if (isNotPreparedWarningSuppressed !== true) {
|
|
7245
|
-
console.warn(spaceTrim$
|
|
7185
|
+
console.warn(spaceTrim$2((block) => `
|
|
7246
7186
|
Pipeline is not prepared
|
|
7247
7187
|
|
|
7248
7188
|
${block(pipelineIdentification)}
|
|
@@ -7267,7 +7207,7 @@ function createPipelineExecutor(options) {
|
|
|
7267
7207
|
tools,
|
|
7268
7208
|
onProgress,
|
|
7269
7209
|
logLlmCall,
|
|
7270
|
-
pipelineIdentification: spaceTrim$
|
|
7210
|
+
pipelineIdentification: spaceTrim$2((block) => `
|
|
7271
7211
|
${block(pipelineIdentification)}
|
|
7272
7212
|
${runCount === 1 ? '' : `Run #${runCount}`}
|
|
7273
7213
|
`),
|
|
@@ -7598,7 +7538,7 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7598
7538
|
* Markdown documentation for ACTION commitment.
|
|
7599
7539
|
*/
|
|
7600
7540
|
get documentation() {
|
|
7601
|
-
return spaceTrim$
|
|
7541
|
+
return spaceTrim$2(`
|
|
7602
7542
|
# ${this.type}
|
|
7603
7543
|
|
|
7604
7544
|
Defines specific actions or capabilities that the agent can perform.
|
|
@@ -7677,7 +7617,7 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7677
7617
|
* Markdown documentation for DELETE commitment.
|
|
7678
7618
|
*/
|
|
7679
7619
|
get documentation() {
|
|
7680
|
-
return spaceTrim$
|
|
7620
|
+
return spaceTrim$2(`
|
|
7681
7621
|
# DELETE (CANCEL, DISCARD, REMOVE)
|
|
7682
7622
|
|
|
7683
7623
|
A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
|
|
@@ -7793,7 +7733,7 @@ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7793
7733
|
* Markdown documentation for FORMAT commitment.
|
|
7794
7734
|
*/
|
|
7795
7735
|
get documentation() {
|
|
7796
|
-
return spaceTrim$
|
|
7736
|
+
return spaceTrim$2(`
|
|
7797
7737
|
# ${this.type}
|
|
7798
7738
|
|
|
7799
7739
|
Defines the specific output structure and formatting for responses (data formats, templates, structure).
|
|
@@ -7868,7 +7808,7 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7868
7808
|
* Markdown documentation for GOAL commitment.
|
|
7869
7809
|
*/
|
|
7870
7810
|
get documentation() {
|
|
7871
|
-
return spaceTrim$
|
|
7811
|
+
return spaceTrim$2(`
|
|
7872
7812
|
# ${this.type}
|
|
7873
7813
|
|
|
7874
7814
|
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.
|
|
@@ -7964,7 +7904,7 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7964
7904
|
* Markdown documentation for KNOWLEDGE commitment.
|
|
7965
7905
|
*/
|
|
7966
7906
|
get documentation() {
|
|
7967
|
-
return spaceTrim$
|
|
7907
|
+
return spaceTrim$2(`
|
|
7968
7908
|
# ${this.type}
|
|
7969
7909
|
|
|
7970
7910
|
Adds specific knowledge, facts, or context to the agent using a RAG (Retrieval-Augmented Generation) approach for external sources.
|
|
@@ -8081,7 +8021,7 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8081
8021
|
* Markdown documentation for MEMORY commitment.
|
|
8082
8022
|
*/
|
|
8083
8023
|
get documentation() {
|
|
8084
|
-
return spaceTrim$
|
|
8024
|
+
return spaceTrim$2(`
|
|
8085
8025
|
# ${this.type}
|
|
8086
8026
|
|
|
8087
8027
|
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.
|
|
@@ -8183,7 +8123,7 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8183
8123
|
* Markdown documentation for MESSAGE commitment.
|
|
8184
8124
|
*/
|
|
8185
8125
|
get documentation() {
|
|
8186
|
-
return spaceTrim$
|
|
8126
|
+
return spaceTrim$2(`
|
|
8187
8127
|
# ${this.type}
|
|
8188
8128
|
|
|
8189
8129
|
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.
|
|
@@ -8301,7 +8241,7 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8301
8241
|
* Markdown documentation for META commitment.
|
|
8302
8242
|
*/
|
|
8303
8243
|
get documentation() {
|
|
8304
|
-
return spaceTrim$
|
|
8244
|
+
return spaceTrim$2(`
|
|
8305
8245
|
# META
|
|
8306
8246
|
|
|
8307
8247
|
Sets meta-information about the agent that is used for display and attribution purposes.
|
|
@@ -8437,7 +8377,7 @@ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8437
8377
|
* Markdown documentation for MODEL commitment.
|
|
8438
8378
|
*/
|
|
8439
8379
|
get documentation() {
|
|
8440
|
-
return spaceTrim$
|
|
8380
|
+
return spaceTrim$2(`
|
|
8441
8381
|
# ${this.type}
|
|
8442
8382
|
|
|
8443
8383
|
Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
|
|
@@ -8672,7 +8612,7 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8672
8612
|
* Markdown documentation for NOTE commitment.
|
|
8673
8613
|
*/
|
|
8674
8614
|
get documentation() {
|
|
8675
|
-
return spaceTrim$
|
|
8615
|
+
return spaceTrim$2(`
|
|
8676
8616
|
# ${this.type}
|
|
8677
8617
|
|
|
8678
8618
|
Adds comments for documentation without changing agent behavior.
|
|
@@ -8774,7 +8714,7 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8774
8714
|
* Markdown documentation for PERSONA commitment.
|
|
8775
8715
|
*/
|
|
8776
8716
|
get documentation() {
|
|
8777
|
-
return spaceTrim$
|
|
8717
|
+
return spaceTrim$2(`
|
|
8778
8718
|
# ${this.type}
|
|
8779
8719
|
|
|
8780
8720
|
Defines who the agent is, their background, expertise, and personality traits.
|
|
@@ -8900,7 +8840,7 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8900
8840
|
* Markdown documentation for RULE/RULES commitment.
|
|
8901
8841
|
*/
|
|
8902
8842
|
get documentation() {
|
|
8903
|
-
return spaceTrim$
|
|
8843
|
+
return spaceTrim$2(`
|
|
8904
8844
|
# ${this.type}
|
|
8905
8845
|
|
|
8906
8846
|
Adds behavioral constraints and guidelines that the agent must follow.
|
|
@@ -8976,7 +8916,7 @@ class SampleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8976
8916
|
* Markdown documentation for SAMPLE/EXAMPLE commitment.
|
|
8977
8917
|
*/
|
|
8978
8918
|
get documentation() {
|
|
8979
|
-
return spaceTrim$
|
|
8919
|
+
return spaceTrim$2(`
|
|
8980
8920
|
# ${this.type}
|
|
8981
8921
|
|
|
8982
8922
|
Provides examples of how the agent should respond or behave in certain situations.
|
|
@@ -9053,7 +8993,7 @@ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9053
8993
|
* Markdown documentation for SCENARIO commitment.
|
|
9054
8994
|
*/
|
|
9055
8995
|
get documentation() {
|
|
9056
|
-
return spaceTrim$
|
|
8996
|
+
return spaceTrim$2(`
|
|
9057
8997
|
# ${this.type}
|
|
9058
8998
|
|
|
9059
8999
|
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.
|
|
@@ -9169,7 +9109,7 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9169
9109
|
* Markdown documentation for STYLE commitment.
|
|
9170
9110
|
*/
|
|
9171
9111
|
get documentation() {
|
|
9172
|
-
return spaceTrim$
|
|
9112
|
+
return spaceTrim$2(`
|
|
9173
9113
|
# ${this.type}
|
|
9174
9114
|
|
|
9175
9115
|
Defines how the agent should format and present its responses (tone, writing style, formatting).
|
|
@@ -9238,7 +9178,7 @@ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9238
9178
|
* Markdown documentation available at runtime.
|
|
9239
9179
|
*/
|
|
9240
9180
|
get documentation() {
|
|
9241
|
-
return spaceTrim$
|
|
9181
|
+
return spaceTrim$2(`
|
|
9242
9182
|
# ${this.type}
|
|
9243
9183
|
|
|
9244
9184
|
This commitment is not yet fully implemented.
|
|
@@ -9412,7 +9352,7 @@ function parseAgentSourceWithCommitments(agentSource) {
|
|
|
9412
9352
|
const fullContent = currentCommitment.contentLines.join('\n');
|
|
9413
9353
|
commitments.push({
|
|
9414
9354
|
type: currentCommitment.type,
|
|
9415
|
-
content: spaceTrim$
|
|
9355
|
+
content: spaceTrim$2(fullContent),
|
|
9416
9356
|
originalLine: currentCommitment.originalStartLine,
|
|
9417
9357
|
lineNumber: currentCommitment.startLineNumber,
|
|
9418
9358
|
});
|
|
@@ -9448,7 +9388,7 @@ function parseAgentSourceWithCommitments(agentSource) {
|
|
|
9448
9388
|
const fullContent = currentCommitment.contentLines.join('\n');
|
|
9449
9389
|
commitments.push({
|
|
9450
9390
|
type: currentCommitment.type,
|
|
9451
|
-
content: spaceTrim$
|
|
9391
|
+
content: spaceTrim$2(fullContent),
|
|
9452
9392
|
originalLine: currentCommitment.originalStartLine,
|
|
9453
9393
|
lineNumber: currentCommitment.startLineNumber,
|
|
9454
9394
|
});
|
|
@@ -9762,7 +9702,7 @@ function parseAgentSource(agentSource) {
|
|
|
9762
9702
|
// Parse META commitments - format is "META TYPE content"
|
|
9763
9703
|
const metaTypeRaw = commitment.content.split(' ')[0] || 'NONE';
|
|
9764
9704
|
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
9765
|
-
meta[metaType] = spaceTrim(commitment.content.substring(metaTypeRaw.length));
|
|
9705
|
+
meta[metaType] = spaceTrim$1(commitment.content.substring(metaTypeRaw.length));
|
|
9766
9706
|
}
|
|
9767
9707
|
// Generate gravatar fallback if no meta image specified
|
|
9768
9708
|
if (!meta.image) {
|
|
@@ -9932,17 +9872,189 @@ function validateBook(source) {
|
|
|
9932
9872
|
/**
|
|
9933
9873
|
* Default book
|
|
9934
9874
|
*
|
|
9875
|
+
* @deprecated Use `$generateBookBoilerplate` instead
|
|
9935
9876
|
* @public exported from `@promptbook/core`
|
|
9936
9877
|
*/
|
|
9937
|
-
const DEFAULT_BOOK = padBook(validateBook(spaceTrim(`
|
|
9878
|
+
const DEFAULT_BOOK = padBook(validateBook(spaceTrim$1(`
|
|
9938
9879
|
AI Avatar
|
|
9939
9880
|
|
|
9940
9881
|
PERSONA A friendly AI assistant that helps you with your tasks
|
|
9941
9882
|
`)));
|
|
9942
9883
|
// <- Note: Not using book`...` notation to avoid strange error in jest unit tests `TypeError: (0 , book_notation_1.book) is not a function`
|
|
9943
|
-
// <- TODO: !!! GENESIS_BOOK
|
|
9884
|
+
// <- TODO: !!! `GENESIS_BOOK` / `ADAM_BOOK` in `/agents/adam.book`
|
|
9944
9885
|
// <- !!! Buttons into genesis book
|
|
9945
|
-
// <- TODO: !!!
|
|
9886
|
+
// <- TODO: !!! generateBookBoilerplate and deprecate `DEFAULT_BOOK`
|
|
9887
|
+
|
|
9888
|
+
/**
|
|
9889
|
+
* Trims string from all 4 sides
|
|
9890
|
+
*
|
|
9891
|
+
* Note: This is a re-exported function from the `spacetrim` package which is
|
|
9892
|
+
* Developed by same author @hejny as this package
|
|
9893
|
+
*
|
|
9894
|
+
* @public exported from `@promptbook/utils`
|
|
9895
|
+
* @see https://github.com/hejny/spacetrim#usage
|
|
9896
|
+
*/
|
|
9897
|
+
const spaceTrim = spaceTrim$2;
|
|
9898
|
+
|
|
9899
|
+
/**
|
|
9900
|
+
* Agent collection stored in Supabase table
|
|
9901
|
+
*
|
|
9902
|
+
* Note: This object can work both from Node.js and browser environment depending on the Supabase client provided
|
|
9903
|
+
*
|
|
9904
|
+
* @public exported from `@promptbook/core`
|
|
9905
|
+
* <- TODO: !!! Move to `@promptbook/supabase` package
|
|
9906
|
+
*/
|
|
9907
|
+
class AgentCollectionInSupabase {
|
|
9908
|
+
/**
|
|
9909
|
+
* @param rootPath - path to the directory with agents
|
|
9910
|
+
* @param tools - Execution tools to be used in `Agent` itself and listing the agents
|
|
9911
|
+
* @param options - Options for the collection creation
|
|
9912
|
+
*/
|
|
9913
|
+
constructor(supabaseClient, tools, options) {
|
|
9914
|
+
this.supabaseClient = supabaseClient;
|
|
9915
|
+
this.tools = tools;
|
|
9916
|
+
this.options = options;
|
|
9917
|
+
/**
|
|
9918
|
+
* Cached defined execution tools
|
|
9919
|
+
*/
|
|
9920
|
+
this._definedTools = null;
|
|
9921
|
+
const { isVerbose = DEFAULT_IS_VERBOSE } = options || {};
|
|
9922
|
+
if (isVerbose) {
|
|
9923
|
+
console.info(colors.cyan(`Creating pipeline collection from supabase`));
|
|
9924
|
+
}
|
|
9925
|
+
}
|
|
9926
|
+
/*
|
|
9927
|
+
TODO: !!! Use or remove
|
|
9928
|
+
/**
|
|
9929
|
+
* Gets or creates execution tools for the collection
|
|
9930
|
+
* /
|
|
9931
|
+
private async getTools(): Promise<ExecutionTools> {
|
|
9932
|
+
if (this._definedTools !== null) {
|
|
9933
|
+
return this._definedTools;
|
|
9934
|
+
}
|
|
9935
|
+
|
|
9936
|
+
this._definedTools = {
|
|
9937
|
+
...(this.tools === undefined || this.tools.fs === undefined ? await $provideExecutionToolsForNode() : {}),
|
|
9938
|
+
...this.tools,
|
|
9939
|
+
};
|
|
9940
|
+
return this._definedTools;
|
|
9941
|
+
}
|
|
9942
|
+
// <- TODO: [👪] Maybe create some common abstraction *(or parent abstract class)*
|
|
9943
|
+
*/
|
|
9944
|
+
/**
|
|
9945
|
+
* Gets all agents in the collection
|
|
9946
|
+
*/
|
|
9947
|
+
async listAgents( /* TODO: [🧠] Allow to pass some condition here */) {
|
|
9948
|
+
const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
|
|
9949
|
+
const result = await this.supabaseClient
|
|
9950
|
+
.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */)
|
|
9951
|
+
.select('agentProfile');
|
|
9952
|
+
if (result.error) {
|
|
9953
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
9954
|
+
|
|
9955
|
+
Error fetching agents from Supabase:
|
|
9956
|
+
|
|
9957
|
+
${block(result.error.message)}
|
|
9958
|
+
`));
|
|
9959
|
+
}
|
|
9960
|
+
if (isVerbose) {
|
|
9961
|
+
console.info(`Found ${result.data.length} agents in directory`);
|
|
9962
|
+
}
|
|
9963
|
+
return result.data.map((row) => row.agentProfile);
|
|
9964
|
+
}
|
|
9965
|
+
/**
|
|
9966
|
+
* !!!
|
|
9967
|
+
*/
|
|
9968
|
+
async spawnAgent(agentName) {
|
|
9969
|
+
throw new NotYetImplementedError('Method not implemented.');
|
|
9970
|
+
/*
|
|
9971
|
+
// <- TODO: !!! ENOENT: no such file or directory, open 'C:\Users\me\work\ai\promptbook\agents\examples\Asistent pro LŠVP.book
|
|
9972
|
+
const { isVerbose = DEFAULT_IS_VERBOSE } = this.options || {};
|
|
9973
|
+
const tools = await this.getTools();
|
|
9974
|
+
|
|
9975
|
+
const agentSourceValue = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
|
|
9976
|
+
const agentSource = new BehaviorSubject(agentSourceValue);
|
|
9977
|
+
|
|
9978
|
+
// Note: Write file whenever agent source changes
|
|
9979
|
+
agentSource.subscribe(async (newSource) => {
|
|
9980
|
+
if (isVerbose) {
|
|
9981
|
+
console.info(colors.cyan(`Writing agent source to file ${agentSourcePath}`));
|
|
9982
|
+
}
|
|
9983
|
+
await forTime(500); // <- TODO: [🙌] !!! Remove
|
|
9984
|
+
await tools.fs!.writeFile(agentSourcePath, newSource, 'utf-8');
|
|
9985
|
+
});
|
|
9986
|
+
|
|
9987
|
+
// Note: Watch file for external changes
|
|
9988
|
+
for await (const event of tools.fs!.watch(agentSourcePath)) {
|
|
9989
|
+
// <- TODO: !!!! Solve the memory freeing when the watching is no longer needed
|
|
9990
|
+
|
|
9991
|
+
if (event.eventType !== 'change') {
|
|
9992
|
+
continue;
|
|
9993
|
+
}
|
|
9994
|
+
|
|
9995
|
+
if (isVerbose) {
|
|
9996
|
+
console.info(
|
|
9997
|
+
colors.cyan(`Detected external change in agent source file ${agentSourcePath}, reloading`),
|
|
9998
|
+
);
|
|
9999
|
+
}
|
|
10000
|
+
await forTime(500); // <- TODO: [🙌] !!! Remove
|
|
10001
|
+
const newSource = validateBook(await tools.fs!.readFile(agentSourcePath, 'utf-8'));
|
|
10002
|
+
agentSource.next(newSource);
|
|
10003
|
+
}
|
|
10004
|
+
|
|
10005
|
+
// TODO: [🙌] !!!! Debug the infinite loop when file is changed externally and agent source is updated which causes file to be written again
|
|
10006
|
+
|
|
10007
|
+
const agent = new Agent({
|
|
10008
|
+
...this.options,
|
|
10009
|
+
agentSource,
|
|
10010
|
+
executionTools: this.tools || {},
|
|
10011
|
+
});
|
|
10012
|
+
|
|
10013
|
+
if (isVerbose) {
|
|
10014
|
+
console.info(colors.cyan(`Created agent "${agent.agentName}" from source file ${agentSourcePath}`));
|
|
10015
|
+
}
|
|
10016
|
+
|
|
10017
|
+
return agent;
|
|
10018
|
+
*/
|
|
10019
|
+
}
|
|
10020
|
+
/**
|
|
10021
|
+
* Creates a new agent in the collection
|
|
10022
|
+
*
|
|
10023
|
+
* Note: You can set 'PARENT' in the agent source to inherit from another agent in the collection.
|
|
10024
|
+
*/
|
|
10025
|
+
async createAgent(agentSource) {
|
|
10026
|
+
const agentProfile = parseAgentSource(agentSource);
|
|
10027
|
+
// <- TODO: [🕛]
|
|
10028
|
+
const result = await this.supabaseClient.from('AgentCollection' /* <- TODO: !!!! Change to `Agent` */).insert({
|
|
10029
|
+
agentName: agentProfile.agentName || '!!!!!' /* <- TODO: !!!! Remove */,
|
|
10030
|
+
agentProfile,
|
|
10031
|
+
createdAt: new Date().toISOString(),
|
|
10032
|
+
updatedAt: null,
|
|
10033
|
+
agentVersion: 0,
|
|
10034
|
+
promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
|
|
10035
|
+
usage: ZERO_USAGE,
|
|
10036
|
+
agentSource: agentSource,
|
|
10037
|
+
});
|
|
10038
|
+
if (result.error) {
|
|
10039
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
10040
|
+
Error creating agent "${agentProfile.agentName}" in Supabase:
|
|
10041
|
+
|
|
10042
|
+
${block(result.error.message)}
|
|
10043
|
+
`));
|
|
10044
|
+
}
|
|
10045
|
+
return agentProfile;
|
|
10046
|
+
}
|
|
10047
|
+
/**
|
|
10048
|
+
* Deletes an agent from the collection
|
|
10049
|
+
*/
|
|
10050
|
+
async deleteAgent(agentName) {
|
|
10051
|
+
throw new NotYetImplementedError('Method not implemented.');
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
/**
|
|
10055
|
+
* TODO: Write unit test
|
|
10056
|
+
* TODO: [🧠][🚙] `AgentXxx` vs `AgentsXxx` naming convention
|
|
10057
|
+
*/
|
|
9946
10058
|
|
|
9947
10059
|
/**
|
|
9948
10060
|
* Constructs `PipelineCollection` from async sources
|
|
@@ -10041,7 +10153,7 @@ function createPipelineSubcollection(collection, predicate) {
|
|
|
10041
10153
|
}
|
|
10042
10154
|
async function getPipelineByUrl(url) {
|
|
10043
10155
|
if (!predicate(url)) {
|
|
10044
|
-
throw new NotFoundError(await spaceTrim$
|
|
10156
|
+
throw new NotFoundError(await spaceTrim$2(async (block) => `
|
|
10045
10157
|
Promptbook with url "${url}" not found or not accessible
|
|
10046
10158
|
|
|
10047
10159
|
Available promptbooks:
|
|
@@ -10160,7 +10272,7 @@ const knowledgeCommandParser = {
|
|
|
10160
10272
|
*/
|
|
10161
10273
|
parse(input) {
|
|
10162
10274
|
const { args } = input;
|
|
10163
|
-
const knowledgeSourceContent = spaceTrim(args[0] || '');
|
|
10275
|
+
const knowledgeSourceContent = spaceTrim$1(args[0] || '');
|
|
10164
10276
|
if (knowledgeSourceContent === '') {
|
|
10165
10277
|
throw new ParseError(`Source is not defined`);
|
|
10166
10278
|
}
|
|
@@ -10304,7 +10416,7 @@ const sectionCommandParser = {
|
|
|
10304
10416
|
normalized = normalized.split('DIALOGUE').join('DIALOG');
|
|
10305
10417
|
const taskTypes = SectionTypes.filter((sectionType) => normalized.includes(sectionType.split('_TASK').join('')));
|
|
10306
10418
|
if (taskTypes.length !== 1) {
|
|
10307
|
-
throw new ParseError(spaceTrim((block) => `
|
|
10419
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
10308
10420
|
Unknown section type "${normalized}"
|
|
10309
10421
|
|
|
10310
10422
|
Supported section types are:
|
|
@@ -10324,7 +10436,7 @@ const sectionCommandParser = {
|
|
|
10324
10436
|
*/
|
|
10325
10437
|
$applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
10326
10438
|
if ($taskJson.isSectionTypeSet === true) {
|
|
10327
|
-
throw new ParseError(spaceTrim(`
|
|
10439
|
+
throw new ParseError(spaceTrim$1(`
|
|
10328
10440
|
Section type is already defined in the section.
|
|
10329
10441
|
It can be defined only once.
|
|
10330
10442
|
`));
|
|
@@ -10673,7 +10785,7 @@ const expectCommandParser = {
|
|
|
10673
10785
|
/**
|
|
10674
10786
|
* Description of the FORMAT command
|
|
10675
10787
|
*/
|
|
10676
|
-
description: spaceTrim(`
|
|
10788
|
+
description: spaceTrim$1(`
|
|
10677
10789
|
Expect command describes the desired output of the task *(after post-processing)*
|
|
10678
10790
|
It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
|
|
10679
10791
|
`),
|
|
@@ -10747,7 +10859,7 @@ const expectCommandParser = {
|
|
|
10747
10859
|
}
|
|
10748
10860
|
catch (error) {
|
|
10749
10861
|
assertsError(error);
|
|
10750
|
-
throw new ParseError(spaceTrim((block) => `
|
|
10862
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
10751
10863
|
Invalid FORMAT command
|
|
10752
10864
|
${block(error.message)}:
|
|
10753
10865
|
`));
|
|
@@ -10881,7 +10993,7 @@ function validateParameterName(parameterName) {
|
|
|
10881
10993
|
if (!(error instanceof ParseError)) {
|
|
10882
10994
|
throw error;
|
|
10883
10995
|
}
|
|
10884
|
-
throw new ParseError(spaceTrim((block) => `
|
|
10996
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
10885
10997
|
${block(error.message)}
|
|
10886
10998
|
|
|
10887
10999
|
Tried to validate parameter name:
|
|
@@ -10940,7 +11052,7 @@ const foreachCommandParser = {
|
|
|
10940
11052
|
const assignSign = args[3];
|
|
10941
11053
|
const formatDefinition = FORMAT_DEFINITIONS.find((formatDefinition) => [formatDefinition.formatName, ...(formatDefinition.aliases || [])].includes(formatName));
|
|
10942
11054
|
if (formatDefinition === undefined) {
|
|
10943
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11055
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
10944
11056
|
Unsupported format "${formatName}"
|
|
10945
11057
|
|
|
10946
11058
|
Available formats:
|
|
@@ -10952,7 +11064,7 @@ const foreachCommandParser = {
|
|
|
10952
11064
|
}
|
|
10953
11065
|
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
|
|
10954
11066
|
if (subvalueParser === undefined) {
|
|
10955
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11067
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
10956
11068
|
Unsupported subformat name "${subformatName}" for format "${formatName}"
|
|
10957
11069
|
|
|
10958
11070
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
@@ -11000,7 +11112,7 @@ const foreachCommandParser = {
|
|
|
11000
11112
|
outputSubparameterName = 'newLine';
|
|
11001
11113
|
}
|
|
11002
11114
|
else {
|
|
11003
|
-
throw new ParseError(spaceTrim(`
|
|
11115
|
+
throw new ParseError(spaceTrim$1(`
|
|
11004
11116
|
FOREACH ${formatName} ${subformatName} must specify output subparameter
|
|
11005
11117
|
|
|
11006
11118
|
Correct example:
|
|
@@ -11076,7 +11188,7 @@ const formatCommandParser = {
|
|
|
11076
11188
|
/**
|
|
11077
11189
|
* Description of the FORMAT command
|
|
11078
11190
|
*/
|
|
11079
|
-
description: spaceTrim(`
|
|
11191
|
+
description: spaceTrim$1(`
|
|
11080
11192
|
Format command describes the desired output of the task (after post-processing)
|
|
11081
11193
|
It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
|
|
11082
11194
|
`),
|
|
@@ -11448,7 +11560,7 @@ const formfactorCommandParser = {
|
|
|
11448
11560
|
const formfactorNameCandidate = args[0].toUpperCase();
|
|
11449
11561
|
const formfactor = FORMFACTOR_DEFINITIONS.find((definition) => [definition.name, ...{ aliasNames: [], ...definition }.aliasNames].includes(formfactorNameCandidate));
|
|
11450
11562
|
if (formfactor === undefined) {
|
|
11451
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11563
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
11452
11564
|
Unknown formfactor name "${formfactorNameCandidate}"
|
|
11453
11565
|
|
|
11454
11566
|
Available formfactors:
|
|
@@ -11467,7 +11579,7 @@ const formfactorCommandParser = {
|
|
|
11467
11579
|
*/
|
|
11468
11580
|
$applyToPipelineJson(command, $pipelineJson) {
|
|
11469
11581
|
if ($pipelineJson.formfactorName !== undefined && $pipelineJson.formfactorName !== command.formfactorName) {
|
|
11470
|
-
throw new ParseError(spaceTrim(`
|
|
11582
|
+
throw new ParseError(spaceTrim$1(`
|
|
11471
11583
|
Redefinition of \`FORMFACTOR\` in the pipeline head
|
|
11472
11584
|
|
|
11473
11585
|
You have used:
|
|
@@ -11610,7 +11722,7 @@ const modelCommandParser = {
|
|
|
11610
11722
|
*/
|
|
11611
11723
|
parse(input) {
|
|
11612
11724
|
const { args, normalized } = input;
|
|
11613
|
-
const availableVariantsMessage = spaceTrim((block) => `
|
|
11725
|
+
const availableVariantsMessage = spaceTrim$1((block) => `
|
|
11614
11726
|
Available variants are:
|
|
11615
11727
|
${block(MODEL_VARIANTS.map((variantName) => `- ${variantName}${variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)'}`).join('\n'))}
|
|
11616
11728
|
`);
|
|
@@ -11632,14 +11744,14 @@ const modelCommandParser = {
|
|
|
11632
11744
|
// <- Note: [🤖]
|
|
11633
11745
|
}
|
|
11634
11746
|
else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
|
|
11635
|
-
spaceTrim((block) => `
|
|
11747
|
+
spaceTrim$1((block) => `
|
|
11636
11748
|
Embedding model can not be used in pipeline
|
|
11637
11749
|
|
|
11638
11750
|
${block(availableVariantsMessage)}
|
|
11639
11751
|
`);
|
|
11640
11752
|
}
|
|
11641
11753
|
else {
|
|
11642
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11754
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
11643
11755
|
Unknown model variant in command:
|
|
11644
11756
|
|
|
11645
11757
|
${block(availableVariantsMessage)}
|
|
@@ -11654,7 +11766,7 @@ const modelCommandParser = {
|
|
|
11654
11766
|
};
|
|
11655
11767
|
}
|
|
11656
11768
|
else {
|
|
11657
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11769
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
11658
11770
|
Unknown model key in command.
|
|
11659
11771
|
|
|
11660
11772
|
Supported model keys are:
|
|
@@ -11681,7 +11793,7 @@ const modelCommandParser = {
|
|
|
11681
11793
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
11682
11794
|
}
|
|
11683
11795
|
else {
|
|
11684
|
-
throw new ParseError(spaceTrim(`
|
|
11796
|
+
throw new ParseError(spaceTrim$1(`
|
|
11685
11797
|
Redefinition of \`MODEL ${command.key}\` in the pipeline head
|
|
11686
11798
|
|
|
11687
11799
|
You have used:
|
|
@@ -11713,7 +11825,7 @@ const modelCommandParser = {
|
|
|
11713
11825
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
11714
11826
|
}
|
|
11715
11827
|
else {
|
|
11716
|
-
throw new ParseError(spaceTrim(`
|
|
11828
|
+
throw new ParseError(spaceTrim$1(`
|
|
11717
11829
|
Redefinition of MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}"
|
|
11718
11830
|
|
|
11719
11831
|
You have used:
|
|
@@ -11723,7 +11835,7 @@ const modelCommandParser = {
|
|
|
11723
11835
|
}
|
|
11724
11836
|
}
|
|
11725
11837
|
if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
|
|
11726
|
-
console.log(spaceTrim(`
|
|
11838
|
+
console.log(spaceTrim$1(`
|
|
11727
11839
|
Setting MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}" to the same value as in the pipeline head
|
|
11728
11840
|
|
|
11729
11841
|
In pipeline head:
|
|
@@ -11806,7 +11918,7 @@ const parameterCommandParser = {
|
|
|
11806
11918
|
// <- TODO: When [🥶] fixed, change to:
|
|
11807
11919
|
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
11808
11920
|
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
11809
|
-
throw new ParseError(spaceTrim((block) => `
|
|
11921
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
11810
11922
|
Parameter \`{${parameterNameRaw}}\` can not contain another parameter in description
|
|
11811
11923
|
|
|
11812
11924
|
The description:
|
|
@@ -11988,7 +12100,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
11988
12100
|
persona.description = personaDescription;
|
|
11989
12101
|
return;
|
|
11990
12102
|
}
|
|
11991
|
-
console.warn(spaceTrim(`
|
|
12103
|
+
console.warn(spaceTrim$1(`
|
|
11992
12104
|
|
|
11993
12105
|
Persona "${personaName}" is defined multiple times with different description:
|
|
11994
12106
|
|
|
@@ -11999,7 +12111,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
11999
12111
|
${personaDescription}
|
|
12000
12112
|
|
|
12001
12113
|
`));
|
|
12002
|
-
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
12114
|
+
persona.description += spaceTrim$1('\n\n' + personaDescription);
|
|
12003
12115
|
}
|
|
12004
12116
|
|
|
12005
12117
|
/**
|
|
@@ -12364,7 +12476,7 @@ const COMMANDS = [
|
|
|
12364
12476
|
function getParserForCommand(command) {
|
|
12365
12477
|
const commandParser = COMMANDS.find((commandParser) => commandParser.name === command.type);
|
|
12366
12478
|
if (commandParser === undefined) {
|
|
12367
|
-
throw new UnexpectedError(spaceTrim$
|
|
12479
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
12368
12480
|
Command ${command.type} parser is not found
|
|
12369
12481
|
|
|
12370
12482
|
${block(JSON.stringify(command, null, 4)
|
|
@@ -12440,7 +12552,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
12440
12552
|
.map(removeMarkdownFormatting)
|
|
12441
12553
|
.map((item) => item.trim());
|
|
12442
12554
|
if (items.length === 0 || items[0] === '') {
|
|
12443
|
-
throw new ParseError(spaceTrim$
|
|
12555
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
12444
12556
|
Malformed command:
|
|
12445
12557
|
- ${raw}
|
|
12446
12558
|
|
|
@@ -12476,7 +12588,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
12476
12588
|
return command;
|
|
12477
12589
|
}
|
|
12478
12590
|
}
|
|
12479
|
-
throw new ParseError(spaceTrim$
|
|
12591
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
12480
12592
|
Malformed or unknown command:
|
|
12481
12593
|
- ${raw}
|
|
12482
12594
|
|
|
@@ -12527,7 +12639,7 @@ function parseCommandVariant(input) {
|
|
|
12527
12639
|
if (!(error instanceof ParseError)) {
|
|
12528
12640
|
throw error;
|
|
12529
12641
|
}
|
|
12530
|
-
throw new ParseError(spaceTrim$
|
|
12642
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
12531
12643
|
Invalid ${commandName} command:
|
|
12532
12644
|
|
|
12533
12645
|
Your command:
|
|
@@ -12801,7 +12913,7 @@ const SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
|
12801
12913
|
* @public exported from `@promptbook/markdown-utils`
|
|
12802
12914
|
*/
|
|
12803
12915
|
function removeMarkdownComments(content) {
|
|
12804
|
-
return spaceTrim$
|
|
12916
|
+
return spaceTrim$2(content.replace(/<!--(.*?)-->/gs, ''));
|
|
12805
12917
|
}
|
|
12806
12918
|
|
|
12807
12919
|
/**
|
|
@@ -12812,7 +12924,7 @@ function removeMarkdownComments(content) {
|
|
|
12812
12924
|
*/
|
|
12813
12925
|
function isFlatPipeline(pipelineString) {
|
|
12814
12926
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
12815
|
-
pipelineString = spaceTrim(pipelineString);
|
|
12927
|
+
pipelineString = spaceTrim$1(pipelineString);
|
|
12816
12928
|
const isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
12817
12929
|
//const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
|
|
12818
12930
|
const isBacktickBlockUsed = pipelineString.includes('```');
|
|
@@ -12838,7 +12950,7 @@ function deflatePipeline(pipelineString) {
|
|
|
12838
12950
|
if (!isFlatPipeline(pipelineString)) {
|
|
12839
12951
|
return pipelineString;
|
|
12840
12952
|
}
|
|
12841
|
-
pipelineString = spaceTrim(pipelineString);
|
|
12953
|
+
pipelineString = spaceTrim$1(pipelineString);
|
|
12842
12954
|
const pipelineStringLines = pipelineString.split('\n');
|
|
12843
12955
|
const potentialReturnStatement = pipelineStringLines.pop();
|
|
12844
12956
|
let returnStatement;
|
|
@@ -12851,19 +12963,19 @@ function deflatePipeline(pipelineString) {
|
|
|
12851
12963
|
returnStatement = `-> {${DEFAULT_BOOK_OUTPUT_PARAMETER_NAME}}`;
|
|
12852
12964
|
pipelineStringLines.push(potentialReturnStatement);
|
|
12853
12965
|
}
|
|
12854
|
-
const prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
12966
|
+
const prompt = spaceTrim$1(pipelineStringLines.join('\n'));
|
|
12855
12967
|
let quotedPrompt;
|
|
12856
12968
|
if (prompt.split('\n').length <= 1) {
|
|
12857
12969
|
quotedPrompt = `> ${prompt}`;
|
|
12858
12970
|
}
|
|
12859
12971
|
else {
|
|
12860
|
-
quotedPrompt = spaceTrim((block) => `
|
|
12972
|
+
quotedPrompt = spaceTrim$1((block) => `
|
|
12861
12973
|
\`\`\`
|
|
12862
12974
|
${block(prompt.split('`').join('\\`'))}
|
|
12863
12975
|
\`\`\`
|
|
12864
12976
|
`);
|
|
12865
12977
|
}
|
|
12866
|
-
pipelineString = validatePipelineString(spaceTrim((block) => `
|
|
12978
|
+
pipelineString = validatePipelineString(spaceTrim$1((block) => `
|
|
12867
12979
|
# ${DEFAULT_BOOK_TITLE}
|
|
12868
12980
|
|
|
12869
12981
|
## Prompt
|
|
@@ -12927,7 +13039,7 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
12927
13039
|
function extractOneBlockFromMarkdown(markdown) {
|
|
12928
13040
|
const codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
12929
13041
|
if (codeBlocks.length !== 1) {
|
|
12930
|
-
throw new ParseError(spaceTrim((block) => `
|
|
13042
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
12931
13043
|
There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
|
|
12932
13044
|
|
|
12933
13045
|
${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
|
|
@@ -12952,7 +13064,7 @@ function parseMarkdownSection(value) {
|
|
|
12952
13064
|
}
|
|
12953
13065
|
const title = lines[0].replace(/^#+\s*/, '');
|
|
12954
13066
|
const level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
12955
|
-
const content = spaceTrim(lines.slice(1).join('\n'));
|
|
13067
|
+
const content = spaceTrim$1(lines.slice(1).join('\n'));
|
|
12956
13068
|
if (level < 1 || level > 6) {
|
|
12957
13069
|
throw new ParseError('Markdown section must have heading level between 1 and 6');
|
|
12958
13070
|
}
|
|
@@ -12980,7 +13092,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
12980
13092
|
if (buffer.length === 0) {
|
|
12981
13093
|
return;
|
|
12982
13094
|
}
|
|
12983
|
-
let section = spaceTrim(buffer.join('\n'));
|
|
13095
|
+
let section = spaceTrim$1(buffer.join('\n'));
|
|
12984
13096
|
if (section === '') {
|
|
12985
13097
|
return;
|
|
12986
13098
|
}
|
|
@@ -13055,7 +13167,7 @@ function flattenMarkdown(markdown) {
|
|
|
13055
13167
|
flattenedMarkdown += `## ${title}` + `\n\n`;
|
|
13056
13168
|
flattenedMarkdown += content + `\n\n`; // <- [🧠] Maybe 3 new lines?
|
|
13057
13169
|
}
|
|
13058
|
-
return spaceTrim(flattenedMarkdown);
|
|
13170
|
+
return spaceTrim$1(flattenedMarkdown);
|
|
13059
13171
|
}
|
|
13060
13172
|
/**
|
|
13061
13173
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -13117,7 +13229,7 @@ function parsePipeline(pipelineString) {
|
|
|
13117
13229
|
if (pipelineString.startsWith('#!')) {
|
|
13118
13230
|
const [shebangLine, ...restLines] = pipelineString.split('\n');
|
|
13119
13231
|
if (!(shebangLine || '').includes('ptbk')) {
|
|
13120
|
-
throw new ParseError(spaceTrim$
|
|
13232
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13121
13233
|
It seems that you try to parse a book file which has non-standard shebang line for book files:
|
|
13122
13234
|
Shebang line must contain 'ptbk'
|
|
13123
13235
|
|
|
@@ -13133,7 +13245,7 @@ function parsePipeline(pipelineString) {
|
|
|
13133
13245
|
pipelineString = validatePipelineString(restLines.join('\n'));
|
|
13134
13246
|
}
|
|
13135
13247
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
13136
|
-
pipelineString = spaceTrim$
|
|
13248
|
+
pipelineString = spaceTrim$2(pipelineString);
|
|
13137
13249
|
// <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
|
|
13138
13250
|
pipelineString = deflatePipeline(pipelineString);
|
|
13139
13251
|
// ==============
|
|
@@ -13145,7 +13257,7 @@ function parsePipeline(pipelineString) {
|
|
|
13145
13257
|
// ==============
|
|
13146
13258
|
// Note: 1️⃣◽4️⃣ Check markdown structure
|
|
13147
13259
|
if (pipelineHead === undefined) {
|
|
13148
|
-
throw new UnexpectedError(spaceTrim$
|
|
13260
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
13149
13261
|
Pipeline head is not defined
|
|
13150
13262
|
|
|
13151
13263
|
${block(getPipelineIdentification())}
|
|
@@ -13154,7 +13266,7 @@ function parsePipeline(pipelineString) {
|
|
|
13154
13266
|
`));
|
|
13155
13267
|
}
|
|
13156
13268
|
if (pipelineHead.level !== 1) {
|
|
13157
|
-
throw new UnexpectedError(spaceTrim$
|
|
13269
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
13158
13270
|
Pipeline head is not h1
|
|
13159
13271
|
|
|
13160
13272
|
${block(getPipelineIdentification())}
|
|
@@ -13163,7 +13275,7 @@ function parsePipeline(pipelineString) {
|
|
|
13163
13275
|
`));
|
|
13164
13276
|
}
|
|
13165
13277
|
if (!pipelineSections.every((section) => section.level === 2)) {
|
|
13166
|
-
throw new UnexpectedError(spaceTrim$
|
|
13278
|
+
throw new UnexpectedError(spaceTrim$2((block) => `
|
|
13167
13279
|
Not every pipeline section is h2
|
|
13168
13280
|
|
|
13169
13281
|
${block(getPipelineIdentification())}
|
|
@@ -13176,7 +13288,7 @@ function parsePipeline(pipelineString) {
|
|
|
13176
13288
|
const defineParam = (parameterCommand) => {
|
|
13177
13289
|
const { parameterName, parameterDescription, isInput, isOutput } = parameterCommand;
|
|
13178
13290
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
13179
|
-
throw new ParseError(spaceTrim$
|
|
13291
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13180
13292
|
Parameter name {${parameterName}} is reserved and cannot be used as resulting parameter name
|
|
13181
13293
|
|
|
13182
13294
|
${block(getPipelineIdentification())}
|
|
@@ -13187,7 +13299,7 @@ function parsePipeline(pipelineString) {
|
|
|
13187
13299
|
existingParameter.description &&
|
|
13188
13300
|
existingParameter.description !== parameterDescription &&
|
|
13189
13301
|
parameterDescription) {
|
|
13190
|
-
throw new ParseError(spaceTrim$
|
|
13302
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13191
13303
|
Parameter \`{${parameterName}}\` is defined multiple times with different description:
|
|
13192
13304
|
|
|
13193
13305
|
${block(getPipelineIdentification())}
|
|
@@ -13225,7 +13337,7 @@ function parsePipeline(pipelineString) {
|
|
|
13225
13337
|
description = description.split(/^>.*$/gm).join('');
|
|
13226
13338
|
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
13227
13339
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
13228
|
-
description = spaceTrim$
|
|
13340
|
+
description = spaceTrim$2(description);
|
|
13229
13341
|
if (description === '') {
|
|
13230
13342
|
description = undefined;
|
|
13231
13343
|
}
|
|
@@ -13236,7 +13348,7 @@ function parsePipeline(pipelineString) {
|
|
|
13236
13348
|
const command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
13237
13349
|
const commandParser = getParserForCommand(command);
|
|
13238
13350
|
if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
|
|
13239
|
-
throw new ParseError(spaceTrim$
|
|
13351
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13240
13352
|
Command \`${command.type}\` is not allowed in the head of the pipeline ONLY at the pipeline task
|
|
13241
13353
|
|
|
13242
13354
|
${block(getPipelineIdentification())}
|
|
@@ -13250,7 +13362,7 @@ function parsePipeline(pipelineString) {
|
|
|
13250
13362
|
if (!(error instanceof ParseError)) {
|
|
13251
13363
|
throw error;
|
|
13252
13364
|
}
|
|
13253
|
-
throw new ParseError(spaceTrim$
|
|
13365
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13254
13366
|
Command ${command.type} failed to apply to the pipeline
|
|
13255
13367
|
|
|
13256
13368
|
The error:
|
|
@@ -13303,7 +13415,7 @@ function parsePipeline(pipelineString) {
|
|
|
13303
13415
|
description = description.split(/^>.*$/gm).join('');
|
|
13304
13416
|
//Note: Remove lists and return statement - TODO: [🎾]
|
|
13305
13417
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
13306
|
-
description = spaceTrim$
|
|
13418
|
+
description = spaceTrim$2(description);
|
|
13307
13419
|
if (description === '') {
|
|
13308
13420
|
description = undefined;
|
|
13309
13421
|
}
|
|
@@ -13337,7 +13449,7 @@ function parsePipeline(pipelineString) {
|
|
|
13337
13449
|
for (const { listItem, command } of commands) {
|
|
13338
13450
|
const commandParser = getParserForCommand(command);
|
|
13339
13451
|
if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
|
|
13340
|
-
throw new ParseError(spaceTrim$
|
|
13452
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13341
13453
|
Command \`${command.type}\` is not allowed in the task of the promptbook ONLY at the pipeline head
|
|
13342
13454
|
|
|
13343
13455
|
${block(getPipelineIdentification())}
|
|
@@ -13352,7 +13464,7 @@ function parsePipeline(pipelineString) {
|
|
|
13352
13464
|
if (!(error instanceof ParseError)) {
|
|
13353
13465
|
throw error;
|
|
13354
13466
|
}
|
|
13355
|
-
throw new ParseError(spaceTrim$
|
|
13467
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13356
13468
|
Command \`${command.type}\` failed to apply to the task
|
|
13357
13469
|
|
|
13358
13470
|
The error:
|
|
@@ -13383,14 +13495,14 @@ function parsePipeline(pipelineString) {
|
|
|
13383
13495
|
// TODO: [🍧] Should be done in SECTION command
|
|
13384
13496
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
13385
13497
|
if (!language) {
|
|
13386
|
-
throw new ParseError(spaceTrim$
|
|
13498
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13387
13499
|
You must specify the language of the script in the \`SCRIPT\` task
|
|
13388
13500
|
|
|
13389
13501
|
${block(getPipelineIdentification())}
|
|
13390
13502
|
`));
|
|
13391
13503
|
}
|
|
13392
13504
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
13393
|
-
throw new ParseError(spaceTrim$
|
|
13505
|
+
throw new ParseError(spaceTrim$2((block) => `
|
|
13394
13506
|
Script language ${language} is not supported.
|
|
13395
13507
|
|
|
13396
13508
|
Supported languages are:
|
|
@@ -13552,7 +13664,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
13552
13664
|
const warningLine = `<!-- ${GENERATOR_WARNING} -->`;
|
|
13553
13665
|
const sectionRegex = new RegExp(`<!--${sectionName}-->([\\s\\S]*?)<!--/${sectionName}-->`, 'g');
|
|
13554
13666
|
const sectionMatch = content.match(sectionRegex);
|
|
13555
|
-
const contentToInsert = spaceTrim$
|
|
13667
|
+
const contentToInsert = spaceTrim$2((block) => `
|
|
13556
13668
|
<!--${sectionName}-->
|
|
13557
13669
|
${block(warningLine)}
|
|
13558
13670
|
${block(sectionContent)}
|
|
@@ -13565,7 +13677,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
13565
13677
|
const placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
|
|
13566
13678
|
if (placeForSection !== null) {
|
|
13567
13679
|
const [heading] = placeForSection;
|
|
13568
|
-
return content.replace(heading, spaceTrim$
|
|
13680
|
+
return content.replace(heading, spaceTrim$2((block) => `
|
|
13569
13681
|
${block(contentToInsert)}
|
|
13570
13682
|
|
|
13571
13683
|
${block(heading)}
|
|
@@ -13574,7 +13686,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
13574
13686
|
console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
|
|
13575
13687
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
13576
13688
|
// <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
|
|
13577
|
-
return spaceTrim$
|
|
13689
|
+
return spaceTrim$2((block) => `
|
|
13578
13690
|
${block(content)}
|
|
13579
13691
|
|
|
13580
13692
|
${block(contentToInsert)}
|
|
@@ -13650,7 +13762,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
13650
13762
|
.filter(([MERMAID_NAME]) => (inputAndIntermediateParametersMermaid + outputParametersMermaid).includes(MERMAID_NAME))
|
|
13651
13763
|
.map(([MERMAID_NAME, title]) => `${MERMAID_NAME}((${title})):::${MERMAID_NAME}`)
|
|
13652
13764
|
.join('\n');
|
|
13653
|
-
const promptbookMermaid = spaceTrim$
|
|
13765
|
+
const promptbookMermaid = spaceTrim$2((block) => `
|
|
13654
13766
|
|
|
13655
13767
|
%% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
|
|
13656
13768
|
|
|
@@ -13706,7 +13818,7 @@ async function prettifyPipelineString(pipelineString, options) {
|
|
|
13706
13818
|
return { href: `#${task.name}`, title: task.title };
|
|
13707
13819
|
},
|
|
13708
13820
|
});
|
|
13709
|
-
const promptbookMermaidBlock = spaceTrim$
|
|
13821
|
+
const promptbookMermaidBlock = spaceTrim$2((block) => `
|
|
13710
13822
|
\`\`\`mermaid
|
|
13711
13823
|
${block(promptbookMermaid)}
|
|
13712
13824
|
\`\`\`
|
|
@@ -13744,7 +13856,7 @@ class CallbackInterfaceTools {
|
|
|
13744
13856
|
async promptDialog(options) {
|
|
13745
13857
|
const answer = await this.options.callback(options);
|
|
13746
13858
|
if (this.options.isVerbose) {
|
|
13747
|
-
console.info(spaceTrim$
|
|
13859
|
+
console.info(spaceTrim$2((block) => `
|
|
13748
13860
|
📖 ${block(options.promptTitle)}
|
|
13749
13861
|
👤 ${block(answer)}
|
|
13750
13862
|
`));
|
|
@@ -13885,7 +13997,7 @@ function countWorkingDuration(items) {
|
|
|
13885
13997
|
function executionReportJsonToString(executionReportJson, options) {
|
|
13886
13998
|
var _a, _b, _c, _d, _e, _f;
|
|
13887
13999
|
const { taxRate, chartsWidth } = { ...ExecutionReportStringOptionsDefaults, ...(options || {}) };
|
|
13888
|
-
let executionReportString = spaceTrim$
|
|
14000
|
+
let executionReportString = spaceTrim$2((block) => `
|
|
13889
14001
|
# ${executionReportJson.title || 'Execution report'}
|
|
13890
14002
|
|
|
13891
14003
|
${block(executionReportJson.description || '')}
|
|
@@ -14007,7 +14119,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
14007
14119
|
if (just(true)) {
|
|
14008
14120
|
executionReportString +=
|
|
14009
14121
|
'\n\n\n\n' +
|
|
14010
|
-
spaceTrim$
|
|
14122
|
+
spaceTrim$2((block) => {
|
|
14011
14123
|
var _a;
|
|
14012
14124
|
return `
|
|
14013
14125
|
|
|
@@ -14026,7 +14138,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
14026
14138
|
executionReportString += '*No result*';
|
|
14027
14139
|
}
|
|
14028
14140
|
else if (typeof promptExecution.result.content === 'string') {
|
|
14029
|
-
executionReportString += spaceTrim$
|
|
14141
|
+
executionReportString += spaceTrim$2((block) => `
|
|
14030
14142
|
\`\`\`
|
|
14031
14143
|
${block(escapeMarkdownBlock(promptExecution.result.content))}
|
|
14032
14144
|
\`\`\`
|
|
@@ -14039,7 +14151,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
14039
14151
|
if (promptExecution.error && promptExecution.error.message) {
|
|
14040
14152
|
executionReportString +=
|
|
14041
14153
|
'\n\n\n\n' +
|
|
14042
|
-
spaceTrim$
|
|
14154
|
+
spaceTrim$2((block) => `
|
|
14043
14155
|
|
|
14044
14156
|
### Error
|
|
14045
14157
|
|
|
@@ -14115,7 +14227,7 @@ function usageToHuman(usage) {
|
|
|
14115
14227
|
// Note: For negligible usage, we report at least something
|
|
14116
14228
|
reportItems.push('Negligible');
|
|
14117
14229
|
}
|
|
14118
|
-
return spaceTrim((block) => `
|
|
14230
|
+
return spaceTrim$1((block) => `
|
|
14119
14231
|
Usage:
|
|
14120
14232
|
${block(reportItems.map((item) => `- ${item}`).join('\n'))}
|
|
14121
14233
|
`);
|
|
@@ -14357,13 +14469,13 @@ function $registeredLlmToolsMessage() {
|
|
|
14357
14469
|
});
|
|
14358
14470
|
const usedEnvMessage = `Unknown \`.env\` file` ;
|
|
14359
14471
|
if (metadata.length === 0) {
|
|
14360
|
-
return spaceTrim((block) => `
|
|
14472
|
+
return spaceTrim$1((block) => `
|
|
14361
14473
|
No LLM providers are available.
|
|
14362
14474
|
|
|
14363
14475
|
${block(usedEnvMessage)}
|
|
14364
14476
|
`);
|
|
14365
14477
|
}
|
|
14366
|
-
return spaceTrim((block) => `
|
|
14478
|
+
return spaceTrim$1((block) => `
|
|
14367
14479
|
|
|
14368
14480
|
${block(usedEnvMessage)}
|
|
14369
14481
|
|
|
@@ -14409,7 +14521,7 @@ function $registeredLlmToolsMessage() {
|
|
|
14409
14521
|
morePieces.push(`Not configured`); // <- Note: Can not be configured via environment variables
|
|
14410
14522
|
}
|
|
14411
14523
|
}
|
|
14412
|
-
let providerMessage = spaceTrim(`
|
|
14524
|
+
let providerMessage = spaceTrim$1(`
|
|
14413
14525
|
${i + 1}) **${title}** \`${className}\` from \`${packageName}\`
|
|
14414
14526
|
${morePieces.join('; ')}
|
|
14415
14527
|
`);
|
|
@@ -14455,7 +14567,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
|
|
|
14455
14567
|
.find(({ packageName, className }) => llmConfiguration.packageName === packageName && llmConfiguration.className === className);
|
|
14456
14568
|
if (registeredItem === undefined) {
|
|
14457
14569
|
// console.log('$llmToolsRegister.list()', $llmToolsRegister.list());
|
|
14458
|
-
throw new Error(spaceTrim((block) => `
|
|
14570
|
+
throw new Error(spaceTrim$1((block) => `
|
|
14459
14571
|
There is no constructor for LLM provider \`${llmConfiguration.className}\` from \`${llmConfiguration.packageName}\`
|
|
14460
14572
|
Running in ${!$isRunningInBrowser() ? '' : 'browser environment'}${!$isRunningInNode() ? '' : 'node environment'}${!$isRunningInWebWorker() ? '' : 'worker environment'}
|
|
14461
14573
|
|
|
@@ -14592,7 +14704,7 @@ function cacheLlmTools(llmTools, options = {}) {
|
|
|
14592
14704
|
let normalizedContent = content;
|
|
14593
14705
|
normalizedContent = normalizedContent.replace(/\s+/g, ' ');
|
|
14594
14706
|
normalizedContent = normalizedContent.split('\r\n').join('\n');
|
|
14595
|
-
normalizedContent = spaceTrim(normalizedContent);
|
|
14707
|
+
normalizedContent = spaceTrim$1(normalizedContent);
|
|
14596
14708
|
// Note: Do not need to save everything in the cache, just the relevant parameters
|
|
14597
14709
|
const relevantParameterNames = extractParameterNames(content);
|
|
14598
14710
|
const relevantParameters = Object.fromEntries(Object.entries(parameters).filter(([key]) => relevantParameterNames.has(key)));
|
|
@@ -14798,66 +14910,6 @@ function asUpdatableSubject(value) {
|
|
|
14798
14910
|
* TODO: [🧠] Maybe `BehaviorSubject` is too heavy for this use case, maybe just tuple `[value,setValue]` is enough
|
|
14799
14911
|
*/
|
|
14800
14912
|
|
|
14801
|
-
/**
|
|
14802
|
-
* Represents one AI Agent
|
|
14803
|
-
*
|
|
14804
|
-
* Note: [🦖] There are several different things in Promptbook:
|
|
14805
|
-
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
14806
|
-
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
14807
|
-
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
14808
|
-
* - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
|
|
14809
|
-
*
|
|
14810
|
-
* @public exported from `@promptbook/core`
|
|
14811
|
-
*/
|
|
14812
|
-
class Agent {
|
|
14813
|
-
/**
|
|
14814
|
-
* Not used in Agent, always returns empty array
|
|
14815
|
-
*/
|
|
14816
|
-
get parameters() {
|
|
14817
|
-
return [
|
|
14818
|
-
/* [😰] */
|
|
14819
|
-
];
|
|
14820
|
-
}
|
|
14821
|
-
constructor(options) {
|
|
14822
|
-
this.options = options;
|
|
14823
|
-
/**
|
|
14824
|
-
* Name of the agent
|
|
14825
|
-
*/
|
|
14826
|
-
this.agentName = null;
|
|
14827
|
-
/**
|
|
14828
|
-
* Description of the agent
|
|
14829
|
-
*/
|
|
14830
|
-
this.personaDescription = null;
|
|
14831
|
-
/**
|
|
14832
|
-
* Metadata like image or color
|
|
14833
|
-
*/
|
|
14834
|
-
this.meta = {};
|
|
14835
|
-
this.agentSource = asUpdatableSubject(options.agentSource);
|
|
14836
|
-
this.agentSource.subscribe((source) => {
|
|
14837
|
-
const { agentName, personaDescription, meta } = parseAgentSource(source);
|
|
14838
|
-
this.agentName = agentName;
|
|
14839
|
-
this.personaDescription = personaDescription;
|
|
14840
|
-
this.meta = { ...this.meta, ...meta };
|
|
14841
|
-
});
|
|
14842
|
-
}
|
|
14843
|
-
/**
|
|
14844
|
-
* Creates LlmExecutionTools which exposes the agent as a model
|
|
14845
|
-
*/
|
|
14846
|
-
getLlmExecutionTools() {
|
|
14847
|
-
const llmTools = new AgentLlmExecutionTools({
|
|
14848
|
-
llmTools: getSingleLlmExecutionTools(this.options.executionTools.llm),
|
|
14849
|
-
agentSource: this.agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
|
|
14850
|
-
});
|
|
14851
|
-
// TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
|
|
14852
|
-
// TODO: !!!! Add `Agent` learning by promptbookAgent
|
|
14853
|
-
return llmTools;
|
|
14854
|
-
}
|
|
14855
|
-
}
|
|
14856
|
-
/**
|
|
14857
|
-
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
14858
|
-
* TODO: !!! Agent on remote server
|
|
14859
|
-
*/
|
|
14860
|
-
|
|
14861
14913
|
/**
|
|
14862
14914
|
* Change ellipsis character to three dots `…` -> `...`
|
|
14863
14915
|
*
|
|
@@ -16259,7 +16311,7 @@ class OpenAiCompatibleExecutionTools {
|
|
|
16259
16311
|
// Note: Match exact or prefix for model families
|
|
16260
16312
|
const model = this.HARDCODED_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
|
|
16261
16313
|
if (model === undefined) {
|
|
16262
|
-
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
16314
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
16263
16315
|
Cannot find model in ${this.title} models with name "${defaultModelName}" which should be used as default.
|
|
16264
16316
|
|
|
16265
16317
|
Available models:
|
|
@@ -16874,6 +16926,66 @@ class AgentLlmExecutionTools {
|
|
|
16874
16926
|
* TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
|
|
16875
16927
|
*/
|
|
16876
16928
|
|
|
16929
|
+
/**
|
|
16930
|
+
* Represents one AI Agent
|
|
16931
|
+
*
|
|
16932
|
+
* Note: [🦖] There are several different things in Promptbook:
|
|
16933
|
+
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
16934
|
+
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
16935
|
+
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
16936
|
+
* - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
|
|
16937
|
+
*
|
|
16938
|
+
* @public exported from `@promptbook/core`
|
|
16939
|
+
*/
|
|
16940
|
+
class Agent {
|
|
16941
|
+
/**
|
|
16942
|
+
* Not used in Agent, always returns empty array
|
|
16943
|
+
*/
|
|
16944
|
+
get parameters() {
|
|
16945
|
+
return [
|
|
16946
|
+
/* [😰] */
|
|
16947
|
+
];
|
|
16948
|
+
}
|
|
16949
|
+
constructor(options) {
|
|
16950
|
+
this.options = options;
|
|
16951
|
+
/**
|
|
16952
|
+
* Name of the agent
|
|
16953
|
+
*/
|
|
16954
|
+
this.agentName = null;
|
|
16955
|
+
/**
|
|
16956
|
+
* Description of the agent
|
|
16957
|
+
*/
|
|
16958
|
+
this.personaDescription = null;
|
|
16959
|
+
/**
|
|
16960
|
+
* Metadata like image or color
|
|
16961
|
+
*/
|
|
16962
|
+
this.meta = {};
|
|
16963
|
+
this.agentSource = asUpdatableSubject(options.agentSource);
|
|
16964
|
+
this.agentSource.subscribe((source) => {
|
|
16965
|
+
const { agentName, personaDescription, meta } = parseAgentSource(source);
|
|
16966
|
+
this.agentName = agentName;
|
|
16967
|
+
this.personaDescription = personaDescription;
|
|
16968
|
+
this.meta = { ...this.meta, ...meta };
|
|
16969
|
+
});
|
|
16970
|
+
}
|
|
16971
|
+
/**
|
|
16972
|
+
* Creates LlmExecutionTools which exposes the agent as a model
|
|
16973
|
+
*/
|
|
16974
|
+
getLlmExecutionTools() {
|
|
16975
|
+
const llmTools = new AgentLlmExecutionTools({
|
|
16976
|
+
llmTools: getSingleLlmExecutionTools(this.options.executionTools.llm),
|
|
16977
|
+
agentSource: this.agentSource.value, // <- TODO: !!!! Allow to pass BehaviorSubject<string_book> OR refresh llmExecutionTools.callChat on agentSource change
|
|
16978
|
+
});
|
|
16979
|
+
// TODO: !!!! Add `Agent` simple "mocked" learning by appending to agent source
|
|
16980
|
+
// TODO: !!!! Add `Agent` learning by promptbookAgent
|
|
16981
|
+
return llmTools;
|
|
16982
|
+
}
|
|
16983
|
+
}
|
|
16984
|
+
/**
|
|
16985
|
+
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
16986
|
+
* TODO: !!! Agent on remote server
|
|
16987
|
+
*/
|
|
16988
|
+
|
|
16877
16989
|
/**
|
|
16878
16990
|
* Creates new AgentLlmExecutionTools that wrap underlying LLM tools with agent-specific behavior
|
|
16879
16991
|
*
|
|
@@ -17440,7 +17552,7 @@ function isValidPipelineString(pipelineString) {
|
|
|
17440
17552
|
*/
|
|
17441
17553
|
function prompt(strings, ...values) {
|
|
17442
17554
|
if (values.length === 0) {
|
|
17443
|
-
return spaceTrim(strings.join(''));
|
|
17555
|
+
return spaceTrim$1(strings.join(''));
|
|
17444
17556
|
}
|
|
17445
17557
|
const stringsWithHiddenParameters = strings.map((stringsItem) =>
|
|
17446
17558
|
// TODO: [0] DRY
|
|
@@ -17451,7 +17563,7 @@ function prompt(strings, ...values) {
|
|
|
17451
17563
|
let pipelineString = stringsWithHiddenParameters.reduce((result, stringsItem, i) => placeholderParameterNames[i] === undefined
|
|
17452
17564
|
? `${result}${stringsItem}`
|
|
17453
17565
|
: `${result}${stringsItem}{${placeholderParameterNames[i]}}`, '');
|
|
17454
|
-
pipelineString = spaceTrim(pipelineString);
|
|
17566
|
+
pipelineString = spaceTrim$1(pipelineString);
|
|
17455
17567
|
try {
|
|
17456
17568
|
pipelineString = templateParameters(pipelineString, parameters);
|
|
17457
17569
|
}
|
|
@@ -17460,7 +17572,7 @@ function prompt(strings, ...values) {
|
|
|
17460
17572
|
throw error;
|
|
17461
17573
|
}
|
|
17462
17574
|
console.error({ pipelineString, parameters, placeholderParameterNames, error });
|
|
17463
|
-
throw new UnexpectedError(spaceTrim((block) => `
|
|
17575
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
17464
17576
|
Internal error in prompt template literal
|
|
17465
17577
|
|
|
17466
17578
|
${block(JSON.stringify({ strings, values }, null, 4))}}
|
|
@@ -17497,7 +17609,7 @@ function book(strings, ...values) {
|
|
|
17497
17609
|
const bookString = prompt(strings, ...values);
|
|
17498
17610
|
if (!isValidPipelineString(bookString)) {
|
|
17499
17611
|
// TODO: Make the CustomError for this
|
|
17500
|
-
throw new Error(spaceTrim(`
|
|
17612
|
+
throw new Error(spaceTrim$1(`
|
|
17501
17613
|
The string is not a valid pipeline string
|
|
17502
17614
|
|
|
17503
17615
|
book\`
|
|
@@ -17507,7 +17619,7 @@ function book(strings, ...values) {
|
|
|
17507
17619
|
}
|
|
17508
17620
|
if (!isValidBook(bookString)) {
|
|
17509
17621
|
// TODO: Make the CustomError for this
|
|
17510
|
-
throw new Error(spaceTrim(`
|
|
17622
|
+
throw new Error(spaceTrim$1(`
|
|
17511
17623
|
The string is not a valid book
|
|
17512
17624
|
|
|
17513
17625
|
book\`
|
|
@@ -17929,7 +18041,7 @@ const OpenAiSdkTranspiler = {
|
|
|
17929
18041
|
});
|
|
17930
18042
|
const KNOWLEDGE_THRESHOLD = 1000;
|
|
17931
18043
|
if (directKnowledge.join('\n').length > KNOWLEDGE_THRESHOLD || knowledgeSources.length > 0) {
|
|
17932
|
-
return spaceTrim((block) => `
|
|
18044
|
+
return spaceTrim$1((block) => `
|
|
17933
18045
|
#!/usr/bin/env node
|
|
17934
18046
|
|
|
17935
18047
|
import * as dotenv from 'dotenv';
|
|
@@ -17994,7 +18106,7 @@ const OpenAiSdkTranspiler = {
|
|
|
17994
18106
|
}
|
|
17995
18107
|
|
|
17996
18108
|
const userMessage = spaceTrim(\`
|
|
17997
|
-
${block(spaceTrim(`
|
|
18109
|
+
${block(spaceTrim$1(`
|
|
17998
18110
|
Here is some additional context to help you answer the question:
|
|
17999
18111
|
\${context}
|
|
18000
18112
|
|
|
@@ -18039,7 +18151,7 @@ const OpenAiSdkTranspiler = {
|
|
|
18039
18151
|
})();
|
|
18040
18152
|
`);
|
|
18041
18153
|
}
|
|
18042
|
-
const source = spaceTrim((block) => `
|
|
18154
|
+
const source = spaceTrim$1((block) => `
|
|
18043
18155
|
|
|
18044
18156
|
#!/usr/bin/env node
|
|
18045
18157
|
|
|
@@ -18106,6 +18218,25 @@ const OpenAiSdkTranspiler = {
|
|
|
18106
18218
|
},
|
|
18107
18219
|
};
|
|
18108
18220
|
|
|
18221
|
+
/**
|
|
18222
|
+
* Returns information about the current runtime environment
|
|
18223
|
+
*
|
|
18224
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environments
|
|
18225
|
+
*
|
|
18226
|
+
* @public exported from `@promptbook/utils`
|
|
18227
|
+
*/
|
|
18228
|
+
function $detectRuntimeEnvironment() {
|
|
18229
|
+
return {
|
|
18230
|
+
isRunningInBrowser: $isRunningInBrowser(),
|
|
18231
|
+
isRunningInJest: $isRunningInJest(),
|
|
18232
|
+
isRunningInNode: $isRunningInNode(),
|
|
18233
|
+
isRunningInWebWorker: $isRunningInWebWorker(),
|
|
18234
|
+
};
|
|
18235
|
+
}
|
|
18236
|
+
/**
|
|
18237
|
+
* TODO: [🎺] Also detect and report node version here
|
|
18238
|
+
*/
|
|
18239
|
+
|
|
18109
18240
|
/**
|
|
18110
18241
|
* Provide information about Promptbook, engine version, book language version, servers, ...
|
|
18111
18242
|
*
|
|
@@ -18115,9 +18246,9 @@ const OpenAiSdkTranspiler = {
|
|
|
18115
18246
|
* @public exported from `@promptbook/core`
|
|
18116
18247
|
*/
|
|
18117
18248
|
function aboutPromptbookInformation(options) {
|
|
18118
|
-
const { isServersInfoIncluded = true } = options || {};
|
|
18249
|
+
const { isServersInfoIncluded = true, isRuntimeEnvironmentInfoIncluded = true } = options || {};
|
|
18119
18250
|
const fullInfoPieces = [];
|
|
18120
|
-
const basicInfo = spaceTrim(`
|
|
18251
|
+
const basicInfo = spaceTrim$1(`
|
|
18121
18252
|
|
|
18122
18253
|
# ${NAME}
|
|
18123
18254
|
|
|
@@ -18129,7 +18260,7 @@ function aboutPromptbookInformation(options) {
|
|
|
18129
18260
|
`);
|
|
18130
18261
|
fullInfoPieces.push(basicInfo);
|
|
18131
18262
|
if (isServersInfoIncluded) {
|
|
18132
|
-
const serversInfo = spaceTrim((block) => `
|
|
18263
|
+
const serversInfo = spaceTrim$1((block) => `
|
|
18133
18264
|
|
|
18134
18265
|
## Servers
|
|
18135
18266
|
|
|
@@ -18139,12 +18270,54 @@ function aboutPromptbookInformation(options) {
|
|
|
18139
18270
|
`);
|
|
18140
18271
|
fullInfoPieces.push(serversInfo);
|
|
18141
18272
|
}
|
|
18142
|
-
|
|
18273
|
+
if (isRuntimeEnvironmentInfoIncluded) {
|
|
18274
|
+
const runtimeEnvironment = $detectRuntimeEnvironment();
|
|
18275
|
+
const environmentInfoRecord = {
|
|
18276
|
+
...runtimeEnvironment,
|
|
18277
|
+
isCostPrevented: IS_COST_PREVENTED,
|
|
18278
|
+
};
|
|
18279
|
+
const environmentInfo = spaceTrim$1((block) => `
|
|
18280
|
+
|
|
18281
|
+
## Environment
|
|
18282
|
+
|
|
18283
|
+
${block(Object.entries(environmentInfoRecord)
|
|
18284
|
+
.map(([key, value]) => `- **${key}:** ${valueToString(value)}`)
|
|
18285
|
+
.join('\n'))}
|
|
18286
|
+
`);
|
|
18287
|
+
fullInfoPieces.push(environmentInfo);
|
|
18288
|
+
}
|
|
18289
|
+
const fullInfo = spaceTrim$1(fullInfoPieces.join('\n\n'));
|
|
18143
18290
|
return fullInfo;
|
|
18144
18291
|
}
|
|
18145
18292
|
/**
|
|
18146
18293
|
* TODO: [🗽] Unite branding and make single place for it
|
|
18147
18294
|
*/
|
|
18148
18295
|
|
|
18149
|
-
|
|
18296
|
+
/**
|
|
18297
|
+
* Generates boilerplate for a new agent book
|
|
18298
|
+
*
|
|
18299
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
18300
|
+
* Note: This function is using cryptographically secure components internally
|
|
18301
|
+
*
|
|
18302
|
+
* @public exported from `@promptbook/core`
|
|
18303
|
+
*/
|
|
18304
|
+
function $generateBookBoilerplate(options) {
|
|
18305
|
+
// eslint-disable-next-line prefer-const
|
|
18306
|
+
let { agentName, parentAgentName = 'Adam', personaDescription, meta } = options || {};
|
|
18307
|
+
if (!agentName) {
|
|
18308
|
+
agentName = 'Agent ' + $randomToken(20);
|
|
18309
|
+
// <- TODO: !!! Supercool random name generator
|
|
18310
|
+
}
|
|
18311
|
+
if (!personaDescription) {
|
|
18312
|
+
personaDescription = 'Friendly and helpful AI agent.';
|
|
18313
|
+
}
|
|
18314
|
+
const agentSource = validateBook(spaceTrim$1((block) => `
|
|
18315
|
+
${agentName}
|
|
18316
|
+
|
|
18317
|
+
PERSONA ${block(personaDescription)}
|
|
18318
|
+
`));
|
|
18319
|
+
return agentSource;
|
|
18320
|
+
}
|
|
18321
|
+
|
|
18322
|
+
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
18150
18323
|
//# sourceMappingURL=index.es.js.map
|