@promptbook/legacy-documents 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 +98 -86
- 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 +102 -90
- 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
|
@@ -6,8 +6,9 @@ import colors from 'colors';
|
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
7
|
import { SHA256 } from 'crypto-js';
|
|
8
8
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
9
|
-
import { format } from 'prettier';
|
|
10
9
|
import parserHtml from 'prettier/parser-html';
|
|
10
|
+
import parserMarkdown from 'prettier/parser-markdown';
|
|
11
|
+
import { format } from 'prettier/standalone';
|
|
11
12
|
import { randomBytes } from 'crypto';
|
|
12
13
|
import { Subject } from 'rxjs';
|
|
13
14
|
import sha256 from 'crypto-js/sha256';
|
|
@@ -28,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
29
|
* @generated
|
|
29
30
|
* @see https://github.com/webgptorg/promptbook
|
|
30
31
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
32
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
|
|
32
33
|
/**
|
|
33
34
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
35
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -226,6 +227,13 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
|
226
227
|
* @public exported from `@promptbook/core`
|
|
227
228
|
*/
|
|
228
229
|
const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
|
230
|
+
/**
|
|
231
|
+
* API request timeout in milliseconds
|
|
232
|
+
* Can be overridden via API_REQUEST_TIMEOUT environment variable
|
|
233
|
+
*
|
|
234
|
+
* @public exported from `@promptbook/core`
|
|
235
|
+
*/
|
|
236
|
+
parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
|
|
229
237
|
/**
|
|
230
238
|
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
231
239
|
*
|
|
@@ -1219,7 +1227,7 @@ function prettifyMarkdown(content) {
|
|
|
1219
1227
|
try {
|
|
1220
1228
|
return format(content, {
|
|
1221
1229
|
parser: 'markdown',
|
|
1222
|
-
plugins: [parserHtml],
|
|
1230
|
+
plugins: [parserMarkdown, parserHtml],
|
|
1223
1231
|
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1224
1232
|
endOfLine: 'lf',
|
|
1225
1233
|
tabWidth: 4,
|
|
@@ -2693,7 +2701,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2693
2701
|
* @private internal helper function
|
|
2694
2702
|
*/
|
|
2695
2703
|
function createTask(options) {
|
|
2696
|
-
const { taskType, taskProcessCallback
|
|
2704
|
+
const { taskType, taskProcessCallback } = options;
|
|
2697
2705
|
let { title } = options;
|
|
2698
2706
|
// TODO: [🐙] DRY
|
|
2699
2707
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -2703,6 +2711,7 @@ function createTask(options) {
|
|
|
2703
2711
|
const errors = [];
|
|
2704
2712
|
const warnings = [];
|
|
2705
2713
|
let currentValue = {};
|
|
2714
|
+
let customTldr = null;
|
|
2706
2715
|
const partialResultSubject = new Subject();
|
|
2707
2716
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2708
2717
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
@@ -2713,6 +2722,9 @@ function createTask(options) {
|
|
|
2713
2722
|
Object.assign(currentValue, newOngoingResult);
|
|
2714
2723
|
// <- TODO: assign deep
|
|
2715
2724
|
partialResultSubject.next(newOngoingResult);
|
|
2725
|
+
}, (tldrInfo) => {
|
|
2726
|
+
customTldr = tldrInfo;
|
|
2727
|
+
updatedAt = new Date();
|
|
2716
2728
|
});
|
|
2717
2729
|
finalResultPromise
|
|
2718
2730
|
.catch((error) => {
|
|
@@ -2768,9 +2780,9 @@ function createTask(options) {
|
|
|
2768
2780
|
},
|
|
2769
2781
|
get tldr() {
|
|
2770
2782
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2771
|
-
// Use custom tldr
|
|
2772
|
-
if (
|
|
2773
|
-
return
|
|
2783
|
+
// Use custom tldr if available
|
|
2784
|
+
if (customTldr) {
|
|
2785
|
+
return customTldr;
|
|
2774
2786
|
}
|
|
2775
2787
|
// Fallback to default implementation
|
|
2776
2788
|
const cv = currentValue;
|
|
@@ -3337,7 +3349,7 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
3337
3349
|
const result = await preparePersonaExecutor({
|
|
3338
3350
|
availableModels /* <- Note: Passing as JSON */,
|
|
3339
3351
|
personaDescription,
|
|
3340
|
-
}).asPromise();
|
|
3352
|
+
}).asPromise({ isCrashedOnError: true });
|
|
3341
3353
|
const { outputParameters } = result;
|
|
3342
3354
|
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3343
3355
|
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
@@ -4091,7 +4103,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
4091
4103
|
});
|
|
4092
4104
|
const result = await prepareTitleExecutor({
|
|
4093
4105
|
book: sources.map(({ content }) => content).join('\n\n'),
|
|
4094
|
-
}).asPromise();
|
|
4106
|
+
}).asPromise({ isCrashedOnError: true });
|
|
4095
4107
|
const { outputParameters } = result;
|
|
4096
4108
|
const { title: titleRaw } = outputParameters;
|
|
4097
4109
|
if (isVerbose) {
|
|
@@ -6306,80 +6318,74 @@ function createPipelineExecutor(options) {
|
|
|
6306
6318
|
});
|
|
6307
6319
|
});
|
|
6308
6320
|
};
|
|
6309
|
-
const pipelineExecutor = (inputParameters) =>
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
return {
|
|
6378
|
-
percent,
|
|
6379
|
-
message,
|
|
6380
|
-
};
|
|
6381
|
-
},
|
|
6382
|
-
});
|
|
6321
|
+
const pipelineExecutor = (inputParameters) => {
|
|
6322
|
+
const startTime = new Date().getTime();
|
|
6323
|
+
return createTask({
|
|
6324
|
+
taskType: 'EXECUTION',
|
|
6325
|
+
title: pipeline.title,
|
|
6326
|
+
taskProcessCallback(updateOngoingResult, updateTldr) {
|
|
6327
|
+
return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
|
|
6328
|
+
var _a, _b;
|
|
6329
|
+
updateOngoingResult(newOngoingResult);
|
|
6330
|
+
// Calculate and update tldr based on pipeline progress
|
|
6331
|
+
const cv = newOngoingResult;
|
|
6332
|
+
// Calculate progress based on parameters resolved vs total parameters
|
|
6333
|
+
const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
|
|
6334
|
+
let resolvedParameters = 0;
|
|
6335
|
+
let currentTaskTitle = '';
|
|
6336
|
+
// Get the resolved parameters from output parameters
|
|
6337
|
+
if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
|
|
6338
|
+
// Count how many output parameters have non-empty values
|
|
6339
|
+
resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
|
|
6340
|
+
}
|
|
6341
|
+
// Try to determine current task from execution report
|
|
6342
|
+
if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
|
|
6343
|
+
const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
|
|
6344
|
+
if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
|
|
6345
|
+
currentTaskTitle = lastExecution.prompt.title;
|
|
6346
|
+
}
|
|
6347
|
+
}
|
|
6348
|
+
// Calculate base progress percentage
|
|
6349
|
+
let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
|
|
6350
|
+
// Add time-based progress for current task if we haven't completed all parameters
|
|
6351
|
+
if (resolvedParameters < totalParameters) {
|
|
6352
|
+
const elapsedMs = new Date().getTime() - startTime;
|
|
6353
|
+
const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
|
|
6354
|
+
const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
|
|
6355
|
+
// If we have time progress but no parameter progress, show time progress
|
|
6356
|
+
if (percent === 0 && timeProgress > 0) {
|
|
6357
|
+
percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
|
|
6358
|
+
}
|
|
6359
|
+
else if (percent < 1) {
|
|
6360
|
+
// Add partial progress for current task
|
|
6361
|
+
const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
|
|
6362
|
+
percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
|
|
6363
|
+
}
|
|
6364
|
+
}
|
|
6365
|
+
// Clamp to [0,1]
|
|
6366
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
6367
|
+
// Generate message
|
|
6368
|
+
let message = '';
|
|
6369
|
+
if (currentTaskTitle) {
|
|
6370
|
+
message = `Executing: ${currentTaskTitle}`;
|
|
6371
|
+
}
|
|
6372
|
+
else if (resolvedParameters === 0) {
|
|
6373
|
+
message = 'Starting pipeline execution';
|
|
6374
|
+
}
|
|
6375
|
+
else if (resolvedParameters < totalParameters) {
|
|
6376
|
+
message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
|
|
6377
|
+
}
|
|
6378
|
+
else {
|
|
6379
|
+
message = 'Completing pipeline execution';
|
|
6380
|
+
}
|
|
6381
|
+
updateTldr({
|
|
6382
|
+
percent: percent,
|
|
6383
|
+
message,
|
|
6384
|
+
});
|
|
6385
|
+
});
|
|
6386
|
+
},
|
|
6387
|
+
});
|
|
6388
|
+
};
|
|
6383
6389
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6384
6390
|
return pipelineExecutor;
|
|
6385
6391
|
}
|
|
@@ -6464,7 +6470,9 @@ class MarkdownScraper {
|
|
|
6464
6470
|
},
|
|
6465
6471
|
});
|
|
6466
6472
|
const knowledgeContent = await source.asText();
|
|
6467
|
-
const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise(
|
|
6473
|
+
const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
|
|
6474
|
+
isCrashedOnError: true,
|
|
6475
|
+
});
|
|
6468
6476
|
const { outputParameters } = result;
|
|
6469
6477
|
const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
|
|
6470
6478
|
const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6488,12 +6496,16 @@ class MarkdownScraper {
|
|
|
6488
6496
|
];
|
|
6489
6497
|
*/
|
|
6490
6498
|
try {
|
|
6491
|
-
const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise(
|
|
6499
|
+
const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
|
|
6500
|
+
isCrashedOnError: true,
|
|
6501
|
+
});
|
|
6492
6502
|
const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
|
|
6493
6503
|
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6494
6504
|
name = titleToName(title);
|
|
6495
6505
|
// --- Keywords
|
|
6496
|
-
const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise(
|
|
6506
|
+
const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
|
|
6507
|
+
isCrashedOnError: true,
|
|
6508
|
+
});
|
|
6497
6509
|
const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
|
|
6498
6510
|
keywords = (keywordsRaw || '')
|
|
6499
6511
|
.split(',')
|