@promptbook/node 0.100.0-44 → 0.100.0-46
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 +119 -121
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +14 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +8 -0
- package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +26 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfileFromSource.d.ts +19 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +15 -0
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +128 -0
- package/esm/typings/src/book-components/Chat/interfaces/ChatMessage.d.ts +16 -0
- package/esm/typings/src/book-components/Chat/interfaces/ChatParticipant.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/utils/ExportFormat.d.ts +4 -0
- package/esm/typings/src/book-components/Chat/utils/addUtmParamsToUrl.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/createShortLinkForChat.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/downloadFile.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +11 -0
- package/esm/typings/src/book-components/Chat/utils/generatePdfContent.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/generateQrDataUrl.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/getPromptbookBranding.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToHtml.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToJson.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToMarkdown.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToText.d.ts +10 -0
- package/esm/typings/src/config.d.ts +13 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +12 -13
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +8 -0
- package/esm/typings/src/playground/permanent/error-handling-playground.d.ts +5 -0
- package/esm/typings/src/utils/organization/preserve.d.ts +21 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -3
- package/umd/index.umd.js +123 -125
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +0 -14
package/esm/index.es.js
CHANGED
|
@@ -3,8 +3,9 @@ import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink }
|
|
|
3
3
|
import { basename, join, dirname, relative } from 'path';
|
|
4
4
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
5
5
|
import JSZip from 'jszip';
|
|
6
|
-
import { format } from 'prettier';
|
|
7
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
|
+
import parserMarkdown from 'prettier/parser-markdown';
|
|
8
|
+
import { format } from 'prettier/standalone';
|
|
8
9
|
import { randomBytes } from 'crypto';
|
|
9
10
|
import { Subject } from 'rxjs';
|
|
10
11
|
import { forTime } from 'waitasecond';
|
|
@@ -30,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
30
31
|
* @generated
|
|
31
32
|
* @see https://github.com/webgptorg/promptbook
|
|
32
33
|
*/
|
|
33
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
|
|
34
35
|
/**
|
|
35
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
36
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -238,6 +239,13 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
|
238
239
|
* @public exported from `@promptbook/core`
|
|
239
240
|
*/
|
|
240
241
|
const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
|
242
|
+
/**
|
|
243
|
+
* API request timeout in milliseconds
|
|
244
|
+
* Can be overridden via API_REQUEST_TIMEOUT environment variable
|
|
245
|
+
*
|
|
246
|
+
* @public exported from `@promptbook/core`
|
|
247
|
+
*/
|
|
248
|
+
parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
|
|
241
249
|
/**
|
|
242
250
|
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
243
251
|
*
|
|
@@ -1287,7 +1295,7 @@ function prettifyMarkdown(content) {
|
|
|
1287
1295
|
try {
|
|
1288
1296
|
return format(content, {
|
|
1289
1297
|
parser: 'markdown',
|
|
1290
|
-
plugins: [parserHtml],
|
|
1298
|
+
plugins: [parserMarkdown, parserHtml],
|
|
1291
1299
|
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1292
1300
|
endOfLine: 'lf',
|
|
1293
1301
|
tabWidth: 4,
|
|
@@ -2088,7 +2096,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2088
2096
|
* @private internal helper function
|
|
2089
2097
|
*/
|
|
2090
2098
|
function createTask(options) {
|
|
2091
|
-
const { taskType, taskProcessCallback
|
|
2099
|
+
const { taskType, taskProcessCallback } = options;
|
|
2092
2100
|
let { title } = options;
|
|
2093
2101
|
// TODO: [🐙] DRY
|
|
2094
2102
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -2098,6 +2106,7 @@ function createTask(options) {
|
|
|
2098
2106
|
const errors = [];
|
|
2099
2107
|
const warnings = [];
|
|
2100
2108
|
let currentValue = {};
|
|
2109
|
+
let customTldr = null;
|
|
2101
2110
|
const partialResultSubject = new Subject();
|
|
2102
2111
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2103
2112
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
@@ -2108,6 +2117,9 @@ function createTask(options) {
|
|
|
2108
2117
|
Object.assign(currentValue, newOngoingResult);
|
|
2109
2118
|
// <- TODO: assign deep
|
|
2110
2119
|
partialResultSubject.next(newOngoingResult);
|
|
2120
|
+
}, (tldrInfo) => {
|
|
2121
|
+
customTldr = tldrInfo;
|
|
2122
|
+
updatedAt = new Date();
|
|
2111
2123
|
});
|
|
2112
2124
|
finalResultPromise
|
|
2113
2125
|
.catch((error) => {
|
|
@@ -2163,9 +2175,9 @@ function createTask(options) {
|
|
|
2163
2175
|
},
|
|
2164
2176
|
get tldr() {
|
|
2165
2177
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2166
|
-
// Use custom tldr
|
|
2167
|
-
if (
|
|
2168
|
-
return
|
|
2178
|
+
// Use custom tldr if available
|
|
2179
|
+
if (customTldr) {
|
|
2180
|
+
return customTldr;
|
|
2169
2181
|
}
|
|
2170
2182
|
// Fallback to default implementation
|
|
2171
2183
|
const cv = currentValue;
|
|
@@ -5007,80 +5019,74 @@ function createPipelineExecutor(options) {
|
|
|
5007
5019
|
});
|
|
5008
5020
|
});
|
|
5009
5021
|
};
|
|
5010
|
-
const pipelineExecutor = (inputParameters) =>
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
return {
|
|
5079
|
-
percent,
|
|
5080
|
-
message,
|
|
5081
|
-
};
|
|
5082
|
-
},
|
|
5083
|
-
});
|
|
5022
|
+
const pipelineExecutor = (inputParameters) => {
|
|
5023
|
+
const startTime = new Date().getTime();
|
|
5024
|
+
return createTask({
|
|
5025
|
+
taskType: 'EXECUTION',
|
|
5026
|
+
title: pipeline.title,
|
|
5027
|
+
taskProcessCallback(updateOngoingResult, updateTldr) {
|
|
5028
|
+
return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
|
|
5029
|
+
var _a, _b;
|
|
5030
|
+
updateOngoingResult(newOngoingResult);
|
|
5031
|
+
// Calculate and update tldr based on pipeline progress
|
|
5032
|
+
const cv = newOngoingResult;
|
|
5033
|
+
// Calculate progress based on parameters resolved vs total parameters
|
|
5034
|
+
const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
|
|
5035
|
+
let resolvedParameters = 0;
|
|
5036
|
+
let currentTaskTitle = '';
|
|
5037
|
+
// Get the resolved parameters from output parameters
|
|
5038
|
+
if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
|
|
5039
|
+
// Count how many output parameters have non-empty values
|
|
5040
|
+
resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
|
|
5041
|
+
}
|
|
5042
|
+
// Try to determine current task from execution report
|
|
5043
|
+
if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
|
|
5044
|
+
const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
|
|
5045
|
+
if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
|
|
5046
|
+
currentTaskTitle = lastExecution.prompt.title;
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
// Calculate base progress percentage
|
|
5050
|
+
let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
|
|
5051
|
+
// Add time-based progress for current task if we haven't completed all parameters
|
|
5052
|
+
if (resolvedParameters < totalParameters) {
|
|
5053
|
+
const elapsedMs = new Date().getTime() - startTime;
|
|
5054
|
+
const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
|
|
5055
|
+
const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
|
|
5056
|
+
// If we have time progress but no parameter progress, show time progress
|
|
5057
|
+
if (percent === 0 && timeProgress > 0) {
|
|
5058
|
+
percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
|
|
5059
|
+
}
|
|
5060
|
+
else if (percent < 1) {
|
|
5061
|
+
// Add partial progress for current task
|
|
5062
|
+
const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
|
|
5063
|
+
percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
// Clamp to [0,1]
|
|
5067
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
5068
|
+
// Generate message
|
|
5069
|
+
let message = '';
|
|
5070
|
+
if (currentTaskTitle) {
|
|
5071
|
+
message = `Executing: ${currentTaskTitle}`;
|
|
5072
|
+
}
|
|
5073
|
+
else if (resolvedParameters === 0) {
|
|
5074
|
+
message = 'Starting pipeline execution';
|
|
5075
|
+
}
|
|
5076
|
+
else if (resolvedParameters < totalParameters) {
|
|
5077
|
+
message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
|
|
5078
|
+
}
|
|
5079
|
+
else {
|
|
5080
|
+
message = 'Completing pipeline execution';
|
|
5081
|
+
}
|
|
5082
|
+
updateTldr({
|
|
5083
|
+
percent: percent,
|
|
5084
|
+
message,
|
|
5085
|
+
});
|
|
5086
|
+
});
|
|
5087
|
+
},
|
|
5088
|
+
});
|
|
5089
|
+
};
|
|
5084
5090
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
5085
5091
|
return pipelineExecutor;
|
|
5086
5092
|
}
|
|
@@ -5216,7 +5222,7 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
5216
5222
|
const result = await preparePersonaExecutor({
|
|
5217
5223
|
availableModels /* <- Note: Passing as JSON */,
|
|
5218
5224
|
personaDescription,
|
|
5219
|
-
}).asPromise();
|
|
5225
|
+
}).asPromise({ isCrashedOnError: true });
|
|
5220
5226
|
const { outputParameters } = result;
|
|
5221
5227
|
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
5222
5228
|
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
@@ -6106,7 +6112,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
6106
6112
|
});
|
|
6107
6113
|
const result = await prepareTitleExecutor({
|
|
6108
6114
|
book: sources.map(({ content }) => content).join('\n\n'),
|
|
6109
|
-
}).asPromise();
|
|
6115
|
+
}).asPromise({ isCrashedOnError: true });
|
|
6110
6116
|
const { outputParameters } = result;
|
|
6111
6117
|
const { title: titleRaw } = outputParameters;
|
|
6112
6118
|
if (isVerbose) {
|
|
@@ -10814,31 +10820,23 @@ function extractBlock(markdown) {
|
|
|
10814
10820
|
return content;
|
|
10815
10821
|
}
|
|
10816
10822
|
|
|
10823
|
+
/**
|
|
10824
|
+
* @private internal for `preserve`
|
|
10825
|
+
*/
|
|
10826
|
+
const _preserved = [];
|
|
10817
10827
|
/**
|
|
10818
10828
|
* Does nothing, but preserves the function in the bundle
|
|
10819
10829
|
* Compiler is tricked into thinking the function is used
|
|
10820
10830
|
*
|
|
10821
10831
|
* @param value any function to preserve
|
|
10822
10832
|
* @returns nothing
|
|
10823
|
-
* @private
|
|
10824
|
-
*/
|
|
10825
|
-
function preserve(
|
|
10826
|
-
|
|
10827
|
-
(async () => {
|
|
10828
|
-
// TODO: [💩] Change to `await forEver` or `forTime(Infinity)`
|
|
10829
|
-
await forTime(100000000);
|
|
10830
|
-
// [1]
|
|
10831
|
-
try {
|
|
10832
|
-
await func();
|
|
10833
|
-
}
|
|
10834
|
-
finally {
|
|
10835
|
-
// do nothing
|
|
10836
|
-
}
|
|
10837
|
-
})();
|
|
10833
|
+
* @private within the repository
|
|
10834
|
+
*/
|
|
10835
|
+
function $preserve(...value) {
|
|
10836
|
+
_preserved.push(...value);
|
|
10838
10837
|
}
|
|
10839
10838
|
/**
|
|
10840
|
-
*
|
|
10841
|
-
* TODO: [1] This maybe does memory leak
|
|
10839
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10842
10840
|
*/
|
|
10843
10841
|
|
|
10844
10842
|
// Note: [💎]
|
|
@@ -10866,25 +10864,25 @@ class JavascriptEvalExecutionTools {
|
|
|
10866
10864
|
// Note: [💎]
|
|
10867
10865
|
// Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
|
|
10868
10866
|
const spaceTrim$1 = (_) => spaceTrim(_);
|
|
10869
|
-
preserve(spaceTrim$1);
|
|
10867
|
+
$preserve(spaceTrim$1);
|
|
10870
10868
|
const removeQuotes$1 = removeQuotes;
|
|
10871
|
-
preserve(removeQuotes$1);
|
|
10869
|
+
$preserve(removeQuotes$1);
|
|
10872
10870
|
const unwrapResult$1 = unwrapResult;
|
|
10873
|
-
preserve(unwrapResult$1);
|
|
10871
|
+
$preserve(unwrapResult$1);
|
|
10874
10872
|
const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
|
|
10875
|
-
preserve(trimEndOfCodeBlock$1);
|
|
10873
|
+
$preserve(trimEndOfCodeBlock$1);
|
|
10876
10874
|
const trimCodeBlock$1 = trimCodeBlock;
|
|
10877
|
-
preserve(trimCodeBlock$1);
|
|
10875
|
+
$preserve(trimCodeBlock$1);
|
|
10878
10876
|
// TODO: DRY [🍯]
|
|
10879
10877
|
const trim = (str) => str.trim();
|
|
10880
|
-
preserve(trim);
|
|
10878
|
+
$preserve(trim);
|
|
10881
10879
|
// TODO: DRY [🍯]
|
|
10882
10880
|
const reverse = (str) => str.split('').reverse().join('');
|
|
10883
|
-
preserve(reverse);
|
|
10881
|
+
$preserve(reverse);
|
|
10884
10882
|
const removeEmojis$1 = removeEmojis;
|
|
10885
|
-
preserve(removeEmojis$1);
|
|
10883
|
+
$preserve(removeEmojis$1);
|
|
10886
10884
|
const prettifyMarkdown$1 = prettifyMarkdown;
|
|
10887
|
-
preserve(prettifyMarkdown$1);
|
|
10885
|
+
$preserve(prettifyMarkdown$1);
|
|
10888
10886
|
//-------[n12:]---
|
|
10889
10887
|
const capitalize$1 = capitalize;
|
|
10890
10888
|
const decapitalize$1 = decapitalize;
|
|
@@ -10900,18 +10898,18 @@ class JavascriptEvalExecutionTools {
|
|
|
10900
10898
|
// TODO: DRY [🍯]
|
|
10901
10899
|
Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
|
|
10902
10900
|
const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
|
|
10903
|
-
preserve(capitalize$1);
|
|
10904
|
-
preserve(decapitalize$1);
|
|
10905
|
-
preserve(nameToUriPart$1);
|
|
10906
|
-
preserve(nameToUriParts$1);
|
|
10907
|
-
preserve(removeDiacritics$1);
|
|
10908
|
-
preserve(normalizeWhitespaces$1);
|
|
10909
|
-
preserve(normalizeToKebabCase$1);
|
|
10910
|
-
preserve(normalizeTo_camelCase$1);
|
|
10911
|
-
preserve(normalizeTo_snake_case$1);
|
|
10912
|
-
preserve(normalizeTo_PascalCase$1);
|
|
10913
|
-
preserve(parseKeywords);
|
|
10914
|
-
preserve(normalizeTo_SCREAMING_CASE$1);
|
|
10901
|
+
$preserve(capitalize$1);
|
|
10902
|
+
$preserve(decapitalize$1);
|
|
10903
|
+
$preserve(nameToUriPart$1);
|
|
10904
|
+
$preserve(nameToUriParts$1);
|
|
10905
|
+
$preserve(removeDiacritics$1);
|
|
10906
|
+
$preserve(normalizeWhitespaces$1);
|
|
10907
|
+
$preserve(normalizeToKebabCase$1);
|
|
10908
|
+
$preserve(normalizeTo_camelCase$1);
|
|
10909
|
+
$preserve(normalizeTo_snake_case$1);
|
|
10910
|
+
$preserve(normalizeTo_PascalCase$1);
|
|
10911
|
+
$preserve(parseKeywords);
|
|
10912
|
+
$preserve(normalizeTo_SCREAMING_CASE$1);
|
|
10915
10913
|
//-------[/n12]---
|
|
10916
10914
|
if (!script.includes('return')) {
|
|
10917
10915
|
script = `return ${script}`;
|