@promptbook/core 0.100.0-36 → 0.100.0-38
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
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-38';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4367,7 +4367,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
4367
4367
|
* @private internal helper function
|
|
4368
4368
|
*/
|
|
4369
4369
|
function createTask(options) {
|
|
4370
|
-
const { taskType, taskProcessCallback } = options;
|
|
4370
|
+
const { taskType, taskProcessCallback, tldrProvider } = options;
|
|
4371
4371
|
let { title } = options;
|
|
4372
4372
|
// TODO: [🐙] DRY
|
|
4373
4373
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -4442,7 +4442,11 @@ function createTask(options) {
|
|
|
4442
4442
|
},
|
|
4443
4443
|
get tldr() {
|
|
4444
4444
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
4445
|
-
//
|
|
4445
|
+
// Use custom tldr provider if available
|
|
4446
|
+
if (tldrProvider) {
|
|
4447
|
+
return tldrProvider(createdAt, status, currentValue, errors, warnings);
|
|
4448
|
+
}
|
|
4449
|
+
// Fallback to default implementation
|
|
4446
4450
|
const cv = currentValue;
|
|
4447
4451
|
// If explicit percent is provided, use it
|
|
4448
4452
|
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;
|
|
@@ -7312,6 +7316,71 @@ function createPipelineExecutor(options) {
|
|
|
7312
7316
|
updateOngoingResult(newOngoingResult);
|
|
7313
7317
|
});
|
|
7314
7318
|
},
|
|
7319
|
+
tldrProvider(createdAt, status, currentValue, errors) {
|
|
7320
|
+
var _a;
|
|
7321
|
+
// Better progress estimation based on pipeline structure
|
|
7322
|
+
const cv = currentValue;
|
|
7323
|
+
// Handle finished/error states
|
|
7324
|
+
if (status === 'FINISHED') {
|
|
7325
|
+
return {
|
|
7326
|
+
percent: 1,
|
|
7327
|
+
message: 'Finished',
|
|
7328
|
+
};
|
|
7329
|
+
}
|
|
7330
|
+
if (status === 'ERROR') {
|
|
7331
|
+
const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
|
|
7332
|
+
return {
|
|
7333
|
+
percent: 0,
|
|
7334
|
+
message: errorMessage,
|
|
7335
|
+
};
|
|
7336
|
+
}
|
|
7337
|
+
// Calculate progress based on pipeline tasks
|
|
7338
|
+
const totalTasks = pipeline.tasks.length;
|
|
7339
|
+
let completedTasks = 0;
|
|
7340
|
+
let currentTaskName = '';
|
|
7341
|
+
// Check execution report for completed tasks
|
|
7342
|
+
if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
|
|
7343
|
+
const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
|
|
7344
|
+
// Count completed tasks by matching titles
|
|
7345
|
+
const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
|
|
7346
|
+
completedTasks = completedTasksByTitle.length;
|
|
7347
|
+
// Find current task being executed (first task not yet completed)
|
|
7348
|
+
const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
|
|
7349
|
+
if (remainingTasks.length > 0) {
|
|
7350
|
+
currentTaskName = remainingTasks[0].name;
|
|
7351
|
+
}
|
|
7352
|
+
}
|
|
7353
|
+
// Calculate progress percentage
|
|
7354
|
+
let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
|
|
7355
|
+
// Add time-based progress for current task (assuming 5 minutes total)
|
|
7356
|
+
if (completedTasks < totalTasks) {
|
|
7357
|
+
const elapsedMs = new Date().getTime() - createdAt.getTime();
|
|
7358
|
+
const totalMs = 5 * 60 * 1000; // 5 minutes
|
|
7359
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
|
7360
|
+
// Add partial progress for current task
|
|
7361
|
+
percent += (1 / totalTasks) * timeProgress;
|
|
7362
|
+
}
|
|
7363
|
+
// Clamp to [0,1]
|
|
7364
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
7365
|
+
// Generate message
|
|
7366
|
+
let message = '';
|
|
7367
|
+
if (currentTaskName) {
|
|
7368
|
+
// Find the task to get its title
|
|
7369
|
+
const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
|
|
7370
|
+
const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
|
|
7371
|
+
message = `Working on task ${taskTitle}`;
|
|
7372
|
+
}
|
|
7373
|
+
else if (completedTasks === 0) {
|
|
7374
|
+
message = 'Starting pipeline execution';
|
|
7375
|
+
}
|
|
7376
|
+
else {
|
|
7377
|
+
message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
|
|
7378
|
+
}
|
|
7379
|
+
return {
|
|
7380
|
+
percent,
|
|
7381
|
+
message,
|
|
7382
|
+
};
|
|
7383
|
+
},
|
|
7315
7384
|
});
|
|
7316
7385
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
7317
7386
|
return pipelineExecutor;
|