@promptbook/legacy-documents 0.100.0-45 → 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 +88 -64
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -6
- package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +4 -10
- package/esm/typings/src/book-components/Chat/interfaces/ChatMessage.d.ts +12 -26
- package/esm/typings/src/book-components/Chat/interfaces/ChatParticipant.d.ts +12 -0
- package/esm/typings/src/config.d.ts +7 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +8 -0
- 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 +92 -68
- 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,
|
|
@@ -3341,7 +3349,7 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
3341
3349
|
const result = await preparePersonaExecutor({
|
|
3342
3350
|
availableModels /* <- Note: Passing as JSON */,
|
|
3343
3351
|
personaDescription,
|
|
3344
|
-
}).asPromise();
|
|
3352
|
+
}).asPromise({ isCrashedOnError: true });
|
|
3345
3353
|
const { outputParameters } = result;
|
|
3346
3354
|
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3347
3355
|
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
@@ -4095,7 +4103,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
4095
4103
|
});
|
|
4096
4104
|
const result = await prepareTitleExecutor({
|
|
4097
4105
|
book: sources.map(({ content }) => content).join('\n\n'),
|
|
4098
|
-
}).asPromise();
|
|
4106
|
+
}).asPromise({ isCrashedOnError: true });
|
|
4099
4107
|
const { outputParameters } = result;
|
|
4100
4108
|
const { title: titleRaw } = outputParameters;
|
|
4101
4109
|
if (isVerbose) {
|
|
@@ -6310,64 +6318,74 @@ function createPipelineExecutor(options) {
|
|
|
6310
6318
|
});
|
|
6311
6319
|
});
|
|
6312
6320
|
};
|
|
6313
|
-
const pipelineExecutor = (inputParameters) =>
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
// Find current task being executed (first task not yet completed)
|
|
6333
|
-
const remainingTasks = pipeline.tasks.filter((task) => !executedTaskTitles.has(task.title));
|
|
6334
|
-
if (remainingTasks.length > 0) {
|
|
6335
|
-
currentTaskName = remainingTasks[0].name;
|
|
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;
|
|
6336
6340
|
}
|
|
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
|
-
|
|
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
|
+
});
|
|
6367
6385
|
});
|
|
6368
|
-
}
|
|
6369
|
-
}
|
|
6370
|
-
}
|
|
6386
|
+
},
|
|
6387
|
+
});
|
|
6388
|
+
};
|
|
6371
6389
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6372
6390
|
return pipelineExecutor;
|
|
6373
6391
|
}
|
|
@@ -6452,7 +6470,9 @@ class MarkdownScraper {
|
|
|
6452
6470
|
},
|
|
6453
6471
|
});
|
|
6454
6472
|
const knowledgeContent = await source.asText();
|
|
6455
|
-
const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise(
|
|
6473
|
+
const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
|
|
6474
|
+
isCrashedOnError: true,
|
|
6475
|
+
});
|
|
6456
6476
|
const { outputParameters } = result;
|
|
6457
6477
|
const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
|
|
6458
6478
|
const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6476,12 +6496,16 @@ class MarkdownScraper {
|
|
|
6476
6496
|
];
|
|
6477
6497
|
*/
|
|
6478
6498
|
try {
|
|
6479
|
-
const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise(
|
|
6499
|
+
const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
|
|
6500
|
+
isCrashedOnError: true,
|
|
6501
|
+
});
|
|
6480
6502
|
const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
|
|
6481
6503
|
title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6482
6504
|
name = titleToName(title);
|
|
6483
6505
|
// --- Keywords
|
|
6484
|
-
const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise(
|
|
6506
|
+
const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
|
|
6507
|
+
isCrashedOnError: true,
|
|
6508
|
+
});
|
|
6485
6509
|
const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
|
|
6486
6510
|
keywords = (keywordsRaw || '')
|
|
6487
6511
|
.split(',')
|