@promptbook/cli 0.100.0-35 → 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 +119 -25
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +6 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +13 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +119 -25
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
47
47
|
* @generated
|
|
48
48
|
* @see https://github.com/webgptorg/promptbook
|
|
49
49
|
*/
|
|
50
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
50
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-37';
|
|
51
51
|
/**
|
|
52
52
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
53
53
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -356,6 +356,12 @@ let DEFAULT_IS_VERBOSE = false;
|
|
|
356
356
|
* @public exported from `@promptbook/core`
|
|
357
357
|
*/
|
|
358
358
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
359
|
+
/**
|
|
360
|
+
* Default simulated duration for a task in milliseconds (used for progress reporting)
|
|
361
|
+
*
|
|
362
|
+
* @public exported from `@promptbook/core`
|
|
363
|
+
*/
|
|
364
|
+
const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
|
359
365
|
/**
|
|
360
366
|
* Function name for generated function via `ptbk make` to get the pipeline collection
|
|
361
367
|
*
|
|
@@ -5587,7 +5593,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
5587
5593
|
* @private internal helper function
|
|
5588
5594
|
*/
|
|
5589
5595
|
function createTask(options) {
|
|
5590
|
-
const { taskType, taskProcessCallback } = options;
|
|
5596
|
+
const { taskType, taskProcessCallback, tldrProvider } = options;
|
|
5591
5597
|
let { title } = options;
|
|
5592
5598
|
// TODO: [🐙] DRY
|
|
5593
5599
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
@@ -5662,21 +5668,35 @@ function createTask(options) {
|
|
|
5662
5668
|
},
|
|
5663
5669
|
get tldr() {
|
|
5664
5670
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5665
|
-
//
|
|
5671
|
+
// Use custom tldr provider if available
|
|
5672
|
+
if (tldrProvider) {
|
|
5673
|
+
return tldrProvider(createdAt, status, currentValue, errors, warnings);
|
|
5674
|
+
}
|
|
5675
|
+
// Fallback to default implementation
|
|
5666
5676
|
const cv = currentValue;
|
|
5667
|
-
//
|
|
5677
|
+
// If explicit percent is provided, use it
|
|
5668
5678
|
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;
|
|
5669
|
-
//
|
|
5679
|
+
// Simulate progress if not provided
|
|
5670
5680
|
if (typeof percentRaw !== 'number') {
|
|
5671
|
-
|
|
5681
|
+
// Simulate progress: evenly split across subtasks, based on elapsed time
|
|
5682
|
+
const now = new Date();
|
|
5683
|
+
const elapsedMs = now.getTime() - createdAt.getTime();
|
|
5684
|
+
const totalMs = DEFAULT_TASK_SIMULATED_DURATION_MS;
|
|
5685
|
+
// If subtasks are defined, split progress evenly
|
|
5686
|
+
const subtaskCount = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) ? cv.subtasks.length : 1;
|
|
5687
|
+
const completedSubtasks = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks)
|
|
5688
|
+
? cv.subtasks.filter((s) => s.done || s.completed).length
|
|
5689
|
+
: 0;
|
|
5690
|
+
// Progress from completed subtasks
|
|
5691
|
+
const subtaskProgress = subtaskCount > 0 ? completedSubtasks / subtaskCount : 0;
|
|
5692
|
+
// Progress from elapsed time for current subtask
|
|
5693
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
|
5694
|
+
// Combine: completed subtasks + time progress for current subtask
|
|
5695
|
+
percentRaw = Math.min(subtaskProgress + (1 / subtaskCount) * timeProgress, 1);
|
|
5696
|
+
if (status === 'FINISHED')
|
|
5672
5697
|
percentRaw = 1;
|
|
5673
|
-
|
|
5674
|
-
else if (status === 'ERROR') {
|
|
5698
|
+
if (status === 'ERROR')
|
|
5675
5699
|
percentRaw = 0;
|
|
5676
|
-
}
|
|
5677
|
-
else {
|
|
5678
|
-
percentRaw = 0;
|
|
5679
|
-
}
|
|
5680
5700
|
}
|
|
5681
5701
|
// Clamp to [0,1]
|
|
5682
5702
|
let percent = Number(percentRaw) || 0;
|
|
@@ -5688,20 +5708,29 @@ function createTask(options) {
|
|
|
5688
5708
|
const messageFromResult = (_k = (_j = (_h = (_g = cv === null || cv === void 0 ? void 0 : cv.tldr) === null || _g === void 0 ? void 0 : _g.message) !== null && _h !== void 0 ? _h : cv === null || cv === void 0 ? void 0 : cv.message) !== null && _j !== void 0 ? _j : cv === null || cv === void 0 ? void 0 : cv.summary) !== null && _k !== void 0 ? _k : cv === null || cv === void 0 ? void 0 : cv.statusMessage;
|
|
5689
5709
|
let message = messageFromResult;
|
|
5690
5710
|
if (!message) {
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
else if (status === 'FINISHED') {
|
|
5698
|
-
message = 'Finished';
|
|
5699
|
-
}
|
|
5700
|
-
else if (status === 'ERROR') {
|
|
5701
|
-
message = 'Error';
|
|
5711
|
+
// If subtasks, show current subtask
|
|
5712
|
+
if (Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) && cv.subtasks.length > 0) {
|
|
5713
|
+
const current = cv.subtasks.find((s) => !s.done && !s.completed);
|
|
5714
|
+
if (current && current.title) {
|
|
5715
|
+
message = `Working on ${current.title}`;
|
|
5716
|
+
}
|
|
5702
5717
|
}
|
|
5703
|
-
|
|
5704
|
-
|
|
5718
|
+
if (!message) {
|
|
5719
|
+
if (errors.length) {
|
|
5720
|
+
message = errors[errors.length - 1].message || 'Error';
|
|
5721
|
+
}
|
|
5722
|
+
else if (warnings.length) {
|
|
5723
|
+
message = warnings[warnings.length - 1].message || 'Warning';
|
|
5724
|
+
}
|
|
5725
|
+
else if (status === 'FINISHED') {
|
|
5726
|
+
message = 'Finished';
|
|
5727
|
+
}
|
|
5728
|
+
else if (status === 'ERROR') {
|
|
5729
|
+
message = 'Error';
|
|
5730
|
+
}
|
|
5731
|
+
else {
|
|
5732
|
+
message = 'Running';
|
|
5733
|
+
}
|
|
5705
5734
|
}
|
|
5706
5735
|
}
|
|
5707
5736
|
return {
|
|
@@ -7571,6 +7600,71 @@ function createPipelineExecutor(options) {
|
|
|
7571
7600
|
updateOngoingResult(newOngoingResult);
|
|
7572
7601
|
});
|
|
7573
7602
|
},
|
|
7603
|
+
tldrProvider(createdAt, status, currentValue, errors) {
|
|
7604
|
+
var _a;
|
|
7605
|
+
// Better progress estimation based on pipeline structure
|
|
7606
|
+
const cv = currentValue;
|
|
7607
|
+
// Handle finished/error states
|
|
7608
|
+
if (status === 'FINISHED') {
|
|
7609
|
+
return {
|
|
7610
|
+
percent: 1,
|
|
7611
|
+
message: 'Finished',
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7614
|
+
if (status === 'ERROR') {
|
|
7615
|
+
const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
|
|
7616
|
+
return {
|
|
7617
|
+
percent: 0,
|
|
7618
|
+
message: errorMessage,
|
|
7619
|
+
};
|
|
7620
|
+
}
|
|
7621
|
+
// Calculate progress based on pipeline tasks
|
|
7622
|
+
const totalTasks = pipeline.tasks.length;
|
|
7623
|
+
let completedTasks = 0;
|
|
7624
|
+
let currentTaskName = '';
|
|
7625
|
+
// Check execution report for completed tasks
|
|
7626
|
+
if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
|
|
7627
|
+
const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
|
|
7628
|
+
// Count completed tasks by matching titles
|
|
7629
|
+
const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
|
|
7630
|
+
completedTasks = completedTasksByTitle.length;
|
|
7631
|
+
// Find current task being executed (first task not yet completed)
|
|
7632
|
+
const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
|
|
7633
|
+
if (remainingTasks.length > 0) {
|
|
7634
|
+
currentTaskName = remainingTasks[0].name;
|
|
7635
|
+
}
|
|
7636
|
+
}
|
|
7637
|
+
// Calculate progress percentage
|
|
7638
|
+
let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
|
|
7639
|
+
// Add time-based progress for current task (assuming 5 minutes total)
|
|
7640
|
+
if (completedTasks < totalTasks) {
|
|
7641
|
+
const elapsedMs = new Date().getTime() - createdAt.getTime();
|
|
7642
|
+
const totalMs = 5 * 60 * 1000; // 5 minutes
|
|
7643
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
|
7644
|
+
// Add partial progress for current task
|
|
7645
|
+
percent += (1 / totalTasks) * timeProgress;
|
|
7646
|
+
}
|
|
7647
|
+
// Clamp to [0,1]
|
|
7648
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
|
7649
|
+
// Generate message
|
|
7650
|
+
let message = '';
|
|
7651
|
+
if (currentTaskName) {
|
|
7652
|
+
// Find the task to get its title
|
|
7653
|
+
const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
|
|
7654
|
+
const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
|
|
7655
|
+
message = `Working on task ${taskTitle}`;
|
|
7656
|
+
}
|
|
7657
|
+
else if (completedTasks === 0) {
|
|
7658
|
+
message = 'Starting pipeline execution';
|
|
7659
|
+
}
|
|
7660
|
+
else {
|
|
7661
|
+
message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
|
|
7662
|
+
}
|
|
7663
|
+
return {
|
|
7664
|
+
percent,
|
|
7665
|
+
message,
|
|
7666
|
+
};
|
|
7667
|
+
},
|
|
7574
7668
|
});
|
|
7575
7669
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
7576
7670
|
return pipelineExecutor;
|