@promptbook/remote-server 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
|
@@ -11,8 +11,9 @@ import { spawn } from 'child_process';
|
|
|
11
11
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
|
|
12
12
|
import { join, basename, dirname } from 'path';
|
|
13
13
|
import { Subject } from 'rxjs';
|
|
14
|
-
import { format } from 'prettier';
|
|
15
14
|
import parserHtml from 'prettier/parser-html';
|
|
15
|
+
import parserMarkdown from 'prettier/parser-markdown';
|
|
16
|
+
import { format } from 'prettier/standalone';
|
|
16
17
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
17
18
|
import sha256 from 'crypto-js/sha256';
|
|
18
19
|
import { SHA256 } from 'crypto-js';
|
|
@@ -33,7 +34,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
33
34
|
* @generated
|
|
34
35
|
* @see https://github.com/webgptorg/promptbook
|
|
35
36
|
*/
|
|
36
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
37
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
|
|
37
38
|
/**
|
|
38
39
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
39
40
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -222,6 +223,13 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
|
222
223
|
* @public exported from `@promptbook/core`
|
|
223
224
|
*/
|
|
224
225
|
const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
|
226
|
+
/**
|
|
227
|
+
* API request timeout in milliseconds
|
|
228
|
+
* Can be overridden via API_REQUEST_TIMEOUT environment variable
|
|
229
|
+
*
|
|
230
|
+
* @public exported from `@promptbook/core`
|
|
231
|
+
*/
|
|
232
|
+
parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
|
|
225
233
|
/**
|
|
226
234
|
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
227
235
|
*
|
|
@@ -2006,7 +2014,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2006
2014
|
* @private internal helper function
|
|
2007
2015
|
*/
|
|
2008
2016
|
function createTask(options) {
|
|
2009
|
-
const { taskType, taskProcessCallback
|
|
2017
|
+
const { taskType, taskProcessCallback } = options;
|
|
2010
2018
|
let { title } = options;
|
|
2011
2019
|
// TODO: [🐙] DRY
|
|
2012
2020
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -2016,6 +2024,7 @@ function createTask(options) {
|
|
|
2016
2024
|
const errors = [];
|
|
2017
2025
|
const warnings = [];
|
|
2018
2026
|
let currentValue = {};
|
|
2027
|
+
let customTldr = null;
|
|
2019
2028
|
const partialResultSubject = new Subject();
|
|
2020
2029
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2021
2030
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
@@ -2026,6 +2035,9 @@ function createTask(options) {
|
|
|
2026
2035
|
Object.assign(currentValue, newOngoingResult);
|
|
2027
2036
|
// <- TODO: assign deep
|
|
2028
2037
|
partialResultSubject.next(newOngoingResult);
|
|
2038
|
+
}, (tldrInfo) => {
|
|
2039
|
+
customTldr = tldrInfo;
|
|
2040
|
+
updatedAt = new Date();
|
|
2029
2041
|
});
|
|
2030
2042
|
finalResultPromise
|
|
2031
2043
|
.catch((error) => {
|
|
@@ -2081,9 +2093,9 @@ function createTask(options) {
|
|
|
2081
2093
|
},
|
|
2082
2094
|
get tldr() {
|
|
2083
2095
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2084
|
-
// Use custom tldr
|
|
2085
|
-
if (
|
|
2086
|
-
return
|
|
2096
|
+
// Use custom tldr if available
|
|
2097
|
+
if (customTldr) {
|
|
2098
|
+
return customTldr;
|
|
2087
2099
|
}
|
|
2088
2100
|
// Fallback to default implementation
|
|
2089
2101
|
const cv = currentValue;
|
|
@@ -2356,7 +2368,7 @@ function prettifyMarkdown(content) {
|
|
|
2356
2368
|
try {
|
|
2357
2369
|
return format(content, {
|
|
2358
2370
|
parser: 'markdown',
|
|
2359
|
-
plugins: [parserHtml],
|
|
2371
|
+
plugins: [parserMarkdown, parserHtml],
|
|
2360
2372
|
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
2361
2373
|
endOfLine: 'lf',
|
|
2362
2374
|
tabWidth: 4,
|
|
@@ -3098,7 +3110,7 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
3098
3110
|
const result = await preparePersonaExecutor({
|
|
3099
3111
|
availableModels /* <- Note: Passing as JSON */,
|
|
3100
3112
|
personaDescription,
|
|
3101
|
-
}).asPromise();
|
|
3113
|
+
}).asPromise({ isCrashedOnError: true });
|
|
3102
3114
|
const { outputParameters } = result;
|
|
3103
3115
|
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3104
3116
|
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
@@ -4249,7 +4261,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
4249
4261
|
});
|
|
4250
4262
|
const result = await prepareTitleExecutor({
|
|
4251
4263
|
book: sources.map(({ content }) => content).join('\n\n'),
|
|
4252
|
-
}).asPromise();
|
|
4264
|
+
}).asPromise({ isCrashedOnError: true });
|
|
4253
4265
|
const { outputParameters } = result;
|
|
4254
4266
|
const { title: titleRaw } = outputParameters;
|
|
4255
4267
|
if (isVerbose) {
|
|
@@ -6481,80 +6493,74 @@ function createPipelineExecutor(options) {
|
|
|
6481
6493
|
});
|
|
6482
6494
|
});
|
|
6483
6495
|
};
|
|
6484
|
-
const pipelineExecutor = (inputParameters) =>
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
return {
|
|
6553
|
-
percent,
|
|
6554
|
-
message,
|
|
6555
|
-
};
|
|
6556
|
-
},
|
|
6557
|
-
});
|
|
6496
|
+
const pipelineExecutor = (inputParameters) => {
|
|
6497
|
+
const startTime = new Date().getTime();
|
|
6498
|
+
return createTask({
|
|
6499
|
+
taskType: 'EXECUTION',
|
|
6500
|
+
title: pipeline.title,
|
|
6501
|
+
taskProcessCallback(updateOngoingResult, updateTldr) {
|
|
6502
|
+
return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
|
|
6503
|
+
var _a, _b;
|
|
6504
|
+
updateOngoingResult(newOngoingResult);
|
|
6505
|
+
// Calculate and update tldr based on pipeline progress
|
|
6506
|
+
const cv = newOngoingResult;
|
|
6507
|
+
// Calculate progress based on parameters resolved vs total parameters
|
|
6508
|
+
const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
|
|
6509
|
+
let resolvedParameters = 0;
|
|
6510
|
+
let currentTaskTitle = '';
|
|
6511
|
+
// Get the resolved parameters from output parameters
|
|
6512
|
+
if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
|
|
6513
|
+
// Count how many output parameters have non-empty values
|
|
6514
|
+
resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
|
|
6515
|
+
}
|
|
6516
|
+
// Try to determine current task from execution report
|
|
6517
|
+
if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
|
|
6518
|
+
const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
|
|
6519
|
+
if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
|
|
6520
|
+
currentTaskTitle = lastExecution.prompt.title;
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
// Calculate base progress percentage
|
|
6524
|
+
let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
|
|
6525
|
+
// Add time-based progress for current task if we haven't completed all parameters
|
|
6526
|
+
if (resolvedParameters < totalParameters) {
|
|
6527
|
+
const elapsedMs = new Date().getTime() - startTime;
|
|
6528
|
+
const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
|
|
6529
|
+
const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
|
|
6530
|
+
// If we have time progress but no parameter progress, show time progress
|
|
6531
|
+
if (percent === 0 && timeProgress > 0) {
|
|
6532
|
+
percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
|
|
6533
|
+
}
|
|
6534
|
+
else if (percent < 1) {
|
|
6535
|
+
// Add partial progress for current task
|
|
6536
|
+
const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
|
|
6537
|
+
percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
// Clamp to [0,1]
|
|
6541
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
6542
|
+
// Generate message
|
|
6543
|
+
let message = '';
|
|
6544
|
+
if (currentTaskTitle) {
|
|
6545
|
+
message = `Executing: ${currentTaskTitle}`;
|
|
6546
|
+
}
|
|
6547
|
+
else if (resolvedParameters === 0) {
|
|
6548
|
+
message = 'Starting pipeline execution';
|
|
6549
|
+
}
|
|
6550
|
+
else if (resolvedParameters < totalParameters) {
|
|
6551
|
+
message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
|
|
6552
|
+
}
|
|
6553
|
+
else {
|
|
6554
|
+
message = 'Completing pipeline execution';
|
|
6555
|
+
}
|
|
6556
|
+
updateTldr({
|
|
6557
|
+
percent: percent,
|
|
6558
|
+
message,
|
|
6559
|
+
});
|
|
6560
|
+
});
|
|
6561
|
+
},
|
|
6562
|
+
});
|
|
6563
|
+
};
|
|
6558
6564
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6559
6565
|
return pipelineExecutor;
|
|
6560
6566
|
}
|
|
@@ -7161,31 +7167,23 @@ function extractBlock(markdown) {
|
|
|
7161
7167
|
return content;
|
|
7162
7168
|
}
|
|
7163
7169
|
|
|
7170
|
+
/**
|
|
7171
|
+
* @private internal for `preserve`
|
|
7172
|
+
*/
|
|
7173
|
+
const _preserved = [];
|
|
7164
7174
|
/**
|
|
7165
7175
|
* Does nothing, but preserves the function in the bundle
|
|
7166
7176
|
* Compiler is tricked into thinking the function is used
|
|
7167
7177
|
*
|
|
7168
7178
|
* @param value any function to preserve
|
|
7169
7179
|
* @returns nothing
|
|
7170
|
-
* @private
|
|
7171
|
-
*/
|
|
7172
|
-
function preserve(
|
|
7173
|
-
|
|
7174
|
-
(async () => {
|
|
7175
|
-
// TODO: [💩] Change to `await forEver` or `forTime(Infinity)`
|
|
7176
|
-
await forTime(100000000);
|
|
7177
|
-
// [1]
|
|
7178
|
-
try {
|
|
7179
|
-
await func();
|
|
7180
|
-
}
|
|
7181
|
-
finally {
|
|
7182
|
-
// do nothing
|
|
7183
|
-
}
|
|
7184
|
-
})();
|
|
7180
|
+
* @private within the repository
|
|
7181
|
+
*/
|
|
7182
|
+
function $preserve(...value) {
|
|
7183
|
+
_preserved.push(...value);
|
|
7185
7184
|
}
|
|
7186
7185
|
/**
|
|
7187
|
-
*
|
|
7188
|
-
* TODO: [1] This maybe does memory leak
|
|
7186
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
7189
7187
|
*/
|
|
7190
7188
|
|
|
7191
7189
|
// Note: [💎]
|
|
@@ -7213,25 +7211,25 @@ class JavascriptEvalExecutionTools {
|
|
|
7213
7211
|
// Note: [💎]
|
|
7214
7212
|
// Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
|
|
7215
7213
|
const spaceTrim$1 = (_) => spaceTrim(_);
|
|
7216
|
-
preserve(spaceTrim$1);
|
|
7214
|
+
$preserve(spaceTrim$1);
|
|
7217
7215
|
const removeQuotes$1 = removeQuotes;
|
|
7218
|
-
preserve(removeQuotes$1);
|
|
7216
|
+
$preserve(removeQuotes$1);
|
|
7219
7217
|
const unwrapResult$1 = unwrapResult;
|
|
7220
|
-
preserve(unwrapResult$1);
|
|
7218
|
+
$preserve(unwrapResult$1);
|
|
7221
7219
|
const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
|
|
7222
|
-
preserve(trimEndOfCodeBlock$1);
|
|
7220
|
+
$preserve(trimEndOfCodeBlock$1);
|
|
7223
7221
|
const trimCodeBlock$1 = trimCodeBlock;
|
|
7224
|
-
preserve(trimCodeBlock$1);
|
|
7222
|
+
$preserve(trimCodeBlock$1);
|
|
7225
7223
|
// TODO: DRY [🍯]
|
|
7226
7224
|
const trim = (str) => str.trim();
|
|
7227
|
-
preserve(trim);
|
|
7225
|
+
$preserve(trim);
|
|
7228
7226
|
// TODO: DRY [🍯]
|
|
7229
7227
|
const reverse = (str) => str.split('').reverse().join('');
|
|
7230
|
-
preserve(reverse);
|
|
7228
|
+
$preserve(reverse);
|
|
7231
7229
|
const removeEmojis$1 = removeEmojis;
|
|
7232
|
-
preserve(removeEmojis$1);
|
|
7230
|
+
$preserve(removeEmojis$1);
|
|
7233
7231
|
const prettifyMarkdown$1 = prettifyMarkdown;
|
|
7234
|
-
preserve(prettifyMarkdown$1);
|
|
7232
|
+
$preserve(prettifyMarkdown$1);
|
|
7235
7233
|
//-------[n12:]---
|
|
7236
7234
|
const capitalize$1 = capitalize;
|
|
7237
7235
|
const decapitalize$1 = decapitalize;
|
|
@@ -7247,18 +7245,18 @@ class JavascriptEvalExecutionTools {
|
|
|
7247
7245
|
// TODO: DRY [🍯]
|
|
7248
7246
|
Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
|
|
7249
7247
|
const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
|
|
7250
|
-
preserve(capitalize$1);
|
|
7251
|
-
preserve(decapitalize$1);
|
|
7252
|
-
preserve(nameToUriPart$1);
|
|
7253
|
-
preserve(nameToUriParts$1);
|
|
7254
|
-
preserve(removeDiacritics$1);
|
|
7255
|
-
preserve(normalizeWhitespaces$1);
|
|
7256
|
-
preserve(normalizeToKebabCase$1);
|
|
7257
|
-
preserve(normalizeTo_camelCase$1);
|
|
7258
|
-
preserve(normalizeTo_snake_case$1);
|
|
7259
|
-
preserve(normalizeTo_PascalCase$1);
|
|
7260
|
-
preserve(parseKeywords);
|
|
7261
|
-
preserve(normalizeTo_SCREAMING_CASE$1);
|
|
7248
|
+
$preserve(capitalize$1);
|
|
7249
|
+
$preserve(decapitalize$1);
|
|
7250
|
+
$preserve(nameToUriPart$1);
|
|
7251
|
+
$preserve(nameToUriParts$1);
|
|
7252
|
+
$preserve(removeDiacritics$1);
|
|
7253
|
+
$preserve(normalizeWhitespaces$1);
|
|
7254
|
+
$preserve(normalizeToKebabCase$1);
|
|
7255
|
+
$preserve(normalizeTo_camelCase$1);
|
|
7256
|
+
$preserve(normalizeTo_snake_case$1);
|
|
7257
|
+
$preserve(normalizeTo_PascalCase$1);
|
|
7258
|
+
$preserve(parseKeywords);
|
|
7259
|
+
$preserve(normalizeTo_SCREAMING_CASE$1);
|
|
7262
7260
|
//-------[/n12]---
|
|
7263
7261
|
if (!script.includes('return')) {
|
|
7264
7262
|
script = `return ${script}`;
|