@promptbook/wizard 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 +2 -2
- package/umd/index.umd.js +119 -25
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
38
38
|
* @generated
|
39
39
|
* @see https://github.com/webgptorg/promptbook
|
40
40
|
*/
|
41
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
41
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-37';
|
42
42
|
/**
|
43
43
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
44
44
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -312,6 +312,12 @@ let DEFAULT_IS_VERBOSE = false;
|
|
312
312
|
* @public exported from `@promptbook/core`
|
313
313
|
*/
|
314
314
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
315
|
+
/**
|
316
|
+
* Default simulated duration for a task in milliseconds (used for progress reporting)
|
317
|
+
*
|
318
|
+
* @public exported from `@promptbook/core`
|
319
|
+
*/
|
320
|
+
const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
|
315
321
|
/**
|
316
322
|
* Default rate limits (requests per minute)
|
317
323
|
*
|
@@ -7165,7 +7171,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
7165
7171
|
* @private internal helper function
|
7166
7172
|
*/
|
7167
7173
|
function createTask(options) {
|
7168
|
-
const { taskType, taskProcessCallback } = options;
|
7174
|
+
const { taskType, taskProcessCallback, tldrProvider } = options;
|
7169
7175
|
let { title } = options;
|
7170
7176
|
// TODO: [🐙] DRY
|
7171
7177
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
@@ -7240,21 +7246,35 @@ function createTask(options) {
|
|
7240
7246
|
},
|
7241
7247
|
get tldr() {
|
7242
7248
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
7243
|
-
//
|
7249
|
+
// Use custom tldr provider if available
|
7250
|
+
if (tldrProvider) {
|
7251
|
+
return tldrProvider(createdAt, status, currentValue, errors, warnings);
|
7252
|
+
}
|
7253
|
+
// Fallback to default implementation
|
7244
7254
|
const cv = currentValue;
|
7245
|
-
//
|
7255
|
+
// If explicit percent is provided, use it
|
7246
7256
|
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;
|
7247
|
-
//
|
7257
|
+
// Simulate progress if not provided
|
7248
7258
|
if (typeof percentRaw !== 'number') {
|
7249
|
-
|
7259
|
+
// Simulate progress: evenly split across subtasks, based on elapsed time
|
7260
|
+
const now = new Date();
|
7261
|
+
const elapsedMs = now.getTime() - createdAt.getTime();
|
7262
|
+
const totalMs = DEFAULT_TASK_SIMULATED_DURATION_MS;
|
7263
|
+
// If subtasks are defined, split progress evenly
|
7264
|
+
const subtaskCount = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) ? cv.subtasks.length : 1;
|
7265
|
+
const completedSubtasks = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks)
|
7266
|
+
? cv.subtasks.filter((s) => s.done || s.completed).length
|
7267
|
+
: 0;
|
7268
|
+
// Progress from completed subtasks
|
7269
|
+
const subtaskProgress = subtaskCount > 0 ? completedSubtasks / subtaskCount : 0;
|
7270
|
+
// Progress from elapsed time for current subtask
|
7271
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
7272
|
+
// Combine: completed subtasks + time progress for current subtask
|
7273
|
+
percentRaw = Math.min(subtaskProgress + (1 / subtaskCount) * timeProgress, 1);
|
7274
|
+
if (status === 'FINISHED')
|
7250
7275
|
percentRaw = 1;
|
7251
|
-
|
7252
|
-
else if (status === 'ERROR') {
|
7276
|
+
if (status === 'ERROR')
|
7253
7277
|
percentRaw = 0;
|
7254
|
-
}
|
7255
|
-
else {
|
7256
|
-
percentRaw = 0;
|
7257
|
-
}
|
7258
7278
|
}
|
7259
7279
|
// Clamp to [0,1]
|
7260
7280
|
let percent = Number(percentRaw) || 0;
|
@@ -7266,20 +7286,29 @@ function createTask(options) {
|
|
7266
7286
|
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;
|
7267
7287
|
let message = messageFromResult;
|
7268
7288
|
if (!message) {
|
7269
|
-
|
7270
|
-
|
7271
|
-
|
7272
|
-
|
7273
|
-
|
7274
|
-
|
7275
|
-
else if (status === 'FINISHED') {
|
7276
|
-
message = 'Finished';
|
7277
|
-
}
|
7278
|
-
else if (status === 'ERROR') {
|
7279
|
-
message = 'Error';
|
7289
|
+
// If subtasks, show current subtask
|
7290
|
+
if (Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) && cv.subtasks.length > 0) {
|
7291
|
+
const current = cv.subtasks.find((s) => !s.done && !s.completed);
|
7292
|
+
if (current && current.title) {
|
7293
|
+
message = `Working on ${current.title}`;
|
7294
|
+
}
|
7280
7295
|
}
|
7281
|
-
|
7282
|
-
|
7296
|
+
if (!message) {
|
7297
|
+
if (errors.length) {
|
7298
|
+
message = errors[errors.length - 1].message || 'Error';
|
7299
|
+
}
|
7300
|
+
else if (warnings.length) {
|
7301
|
+
message = warnings[warnings.length - 1].message || 'Warning';
|
7302
|
+
}
|
7303
|
+
else if (status === 'FINISHED') {
|
7304
|
+
message = 'Finished';
|
7305
|
+
}
|
7306
|
+
else if (status === 'ERROR') {
|
7307
|
+
message = 'Error';
|
7308
|
+
}
|
7309
|
+
else {
|
7310
|
+
message = 'Running';
|
7311
|
+
}
|
7283
7312
|
}
|
7284
7313
|
}
|
7285
7314
|
return {
|
@@ -10288,6 +10317,71 @@ function createPipelineExecutor(options) {
|
|
10288
10317
|
updateOngoingResult(newOngoingResult);
|
10289
10318
|
});
|
10290
10319
|
},
|
10320
|
+
tldrProvider(createdAt, status, currentValue, errors) {
|
10321
|
+
var _a;
|
10322
|
+
// Better progress estimation based on pipeline structure
|
10323
|
+
const cv = currentValue;
|
10324
|
+
// Handle finished/error states
|
10325
|
+
if (status === 'FINISHED') {
|
10326
|
+
return {
|
10327
|
+
percent: 1,
|
10328
|
+
message: 'Finished',
|
10329
|
+
};
|
10330
|
+
}
|
10331
|
+
if (status === 'ERROR') {
|
10332
|
+
const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
|
10333
|
+
return {
|
10334
|
+
percent: 0,
|
10335
|
+
message: errorMessage,
|
10336
|
+
};
|
10337
|
+
}
|
10338
|
+
// Calculate progress based on pipeline tasks
|
10339
|
+
const totalTasks = pipeline.tasks.length;
|
10340
|
+
let completedTasks = 0;
|
10341
|
+
let currentTaskName = '';
|
10342
|
+
// Check execution report for completed tasks
|
10343
|
+
if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
|
10344
|
+
const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
|
10345
|
+
// Count completed tasks by matching titles
|
10346
|
+
const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
|
10347
|
+
completedTasks = completedTasksByTitle.length;
|
10348
|
+
// Find current task being executed (first task not yet completed)
|
10349
|
+
const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
|
10350
|
+
if (remainingTasks.length > 0) {
|
10351
|
+
currentTaskName = remainingTasks[0].name;
|
10352
|
+
}
|
10353
|
+
}
|
10354
|
+
// Calculate progress percentage
|
10355
|
+
let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
|
10356
|
+
// Add time-based progress for current task (assuming 5 minutes total)
|
10357
|
+
if (completedTasks < totalTasks) {
|
10358
|
+
const elapsedMs = new Date().getTime() - createdAt.getTime();
|
10359
|
+
const totalMs = 5 * 60 * 1000; // 5 minutes
|
10360
|
+
const timeProgress = Math.min(elapsedMs / totalMs, 1);
|
10361
|
+
// Add partial progress for current task
|
10362
|
+
percent += (1 / totalTasks) * timeProgress;
|
10363
|
+
}
|
10364
|
+
// Clamp to [0,1]
|
10365
|
+
percent = Math.min(Math.max(percent, 0), 1);
|
10366
|
+
// Generate message
|
10367
|
+
let message = '';
|
10368
|
+
if (currentTaskName) {
|
10369
|
+
// Find the task to get its title
|
10370
|
+
const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
|
10371
|
+
const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
|
10372
|
+
message = `Working on task ${taskTitle}`;
|
10373
|
+
}
|
10374
|
+
else if (completedTasks === 0) {
|
10375
|
+
message = 'Starting pipeline execution';
|
10376
|
+
}
|
10377
|
+
else {
|
10378
|
+
message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
|
10379
|
+
}
|
10380
|
+
return {
|
10381
|
+
percent,
|
10382
|
+
message,
|
10383
|
+
};
|
10384
|
+
},
|
10291
10385
|
});
|
10292
10386
|
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
10293
10387
|
return pipelineExecutor;
|