@promptbook/legacy-documents 0.100.0-36 → 0.100.0-37
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
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-37';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2693,7 +2693,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2693
2693
|
* @private internal helper function
|
|
2694
2694
|
*/
|
|
2695
2695
|
function createTask(options) {
|
|
2696
|
-
const { taskType, taskProcessCallback } = options;
|
|
2696
|
+
const { taskType, taskProcessCallback, tldrProvider } = options;
|
|
2697
2697
|
let { title } = options;
|
|
2698
2698
|
// TODO: [🐙] DRY
|
|
2699
2699
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -2768,7 +2768,11 @@ function createTask(options) {
|
|
|
2768
2768
|
},
|
|
2769
2769
|
get tldr() {
|
|
2770
2770
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2771
|
-
//
|
|
2771
|
+
// Use custom tldr provider if available
|
|
2772
|
+
if (tldrProvider) {
|
|
2773
|
+
return tldrProvider(createdAt, status, currentValue, errors, warnings);
|
|
2774
|
+
}
|
|
2775
|
+
// Fallback to default implementation
|
|
2772
2776
|
const cv = currentValue;
|
|
2773
2777
|
// If explicit percent is provided, use it
|
|
2774
2778
|
let percentRaw = (_f = (_d = (_b = (_a = cv === null || cv === void 0 ? void 0 : cv.tldr) === null || _a === void 0 ? void 0 : _a.percent) !== null && _b !== void 0 ? _b : (_c = cv === null || cv === void 0 ? void 0 : cv.usage) === null || _c === void 0 ? void 0 : _c.percent) !== null && _d !== void 0 ? _d : (_e = cv === null || cv === void 0 ? void 0 : cv.progress) === null || _e === void 0 ? void 0 : _e.percent) !== null && _f !== void 0 ? _f : cv === null || cv === void 0 ? void 0 : cv.percent;
|
|
@@ -6310,6 +6314,71 @@ function createPipelineExecutor(options) {
|
|
|
6310
6314
|
updateOngoingResult(newOngoingResult);
|
|
6311
6315
|
});
|
|
6312
6316
|
},
|
|
6317
|
+
tldrProvider(createdAt, status, currentValue, errors) {
|
|
6318
|
+
var _a;
|
|
6319
|
+
// Better progress estimation based on pipeline structure
|
|
6320
|
+
const cv = currentValue;
|
|
6321
|
+
// Handle finished/error states
|
|
6322
|
+
if (status === 'FINISHED') {
|
|
6323
|
+
return {
|
|
6324
|
+
percent: 1,
|
|
6325
|
+
message: 'Finished',
|
|
6326
|
+
};
|
|
6327
|
+
}
|
|
6328
|
+
if (status === 'ERROR') {
|
|
6329
|
+
const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
|
|
6330
|
+
return {
|
|
6331
|
+
percent: 0,
|
|
6332
|
+
message: errorMessage,
|
|
6333
|
+
};
|
|
6334
|
+
}
|
|
6335
|
+
// Calculate progress based on pipeline tasks
|
|
6336
|
+
const totalTasks = pipeline.tasks.length;
|
|
6337
|
+
let completedTasks = 0;
|
|
6338
|
+
let currentTaskName = '';
|
|
6339
|
+
// Check execution report for completed tasks
|
|
6340
|
+
if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
|
|
6341
|
+
const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
|
|
6342
|
+
// Count completed tasks by matching titles
|
|
6343
|
+
const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
|
|
6344
|
+
completedTasks = completedTasksByTitle.length;
|
|
6345
|
+
// Find current task being executed (first task not yet completed)
|
|
6346
|
+
const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
|
|
6347
|
+
if (remainingTasks.length > 0) {
|
|
6348
|
+
currentTaskName = remainingTasks[0].name;
|
|
6349
|
+
}
|
|
6350
|
+
}
|
|
6351
|
+
// Calculate progress percentage
|
|
6352
|
+
let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
|
|
6353
|
+
// Add time-based progress for current task (assuming 5 minutes total)
|
|
6354
|
+
if (completedTasks < totalTasks) {
|
|
6355
|
+
const elapsedMs = new Date().getTime() - createdAt.getTime();
|
|
6356
|
+
const totalMs = 5 * 60 * 1000; // 5 minutes
|
|
6357
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
|
6358
|
+
// Add partial progress for current task
|
|
6359
|
+
percent += (1 / totalTasks) * timeProgress;
|
|
6360
|
+
}
|
|
6361
|
+
// Clamp to [0,1]
|
|
6362
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
6363
|
+
// Generate message
|
|
6364
|
+
let message = '';
|
|
6365
|
+
if (currentTaskName) {
|
|
6366
|
+
// Find the task to get its title
|
|
6367
|
+
const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
|
|
6368
|
+
const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
|
|
6369
|
+
message = `Working on task ${taskTitle}`;
|
|
6370
|
+
}
|
|
6371
|
+
else if (completedTasks === 0) {
|
|
6372
|
+
message = 'Starting pipeline execution';
|
|
6373
|
+
}
|
|
6374
|
+
else {
|
|
6375
|
+
message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
|
|
6376
|
+
}
|
|
6377
|
+
return {
|
|
6378
|
+
percent,
|
|
6379
|
+
message,
|
|
6380
|
+
};
|
|
6381
|
+
},
|
|
6313
6382
|
});
|
|
6314
6383
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6315
6384
|
return pipelineExecutor;
|