@promptbook/remote-server 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
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-36';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-38';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2006,7 +2006,7 @@ function assertsTaskSuccessful(executionResult) {
2006
2006
  * @private internal helper function
2007
2007
  */
2008
2008
  function createTask(options) {
2009
- const { taskType, taskProcessCallback } = options;
2009
+ const { taskType, taskProcessCallback, tldrProvider } = options;
2010
2010
  let { title } = options;
2011
2011
  // TODO: [🐙] DRY
2012
2012
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2081,7 +2081,11 @@ function createTask(options) {
2081
2081
  },
2082
2082
  get tldr() {
2083
2083
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2084
- // Simulate progress based on elapsed time and subtasks
2084
+ // Use custom tldr provider if available
2085
+ if (tldrProvider) {
2086
+ return tldrProvider(createdAt, status, currentValue, errors, warnings);
2087
+ }
2088
+ // Fallback to default implementation
2085
2089
  const cv = currentValue;
2086
2090
  // If explicit percent is provided, use it
2087
2091
  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;
@@ -6485,6 +6489,71 @@ function createPipelineExecutor(options) {
6485
6489
  updateOngoingResult(newOngoingResult);
6486
6490
  });
6487
6491
  },
6492
+ tldrProvider(createdAt, status, currentValue, errors) {
6493
+ var _a;
6494
+ // Better progress estimation based on pipeline structure
6495
+ const cv = currentValue;
6496
+ // Handle finished/error states
6497
+ if (status === 'FINISHED') {
6498
+ return {
6499
+ percent: 1,
6500
+ message: 'Finished',
6501
+ };
6502
+ }
6503
+ if (status === 'ERROR') {
6504
+ const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
6505
+ return {
6506
+ percent: 0,
6507
+ message: errorMessage,
6508
+ };
6509
+ }
6510
+ // Calculate progress based on pipeline tasks
6511
+ const totalTasks = pipeline.tasks.length;
6512
+ let completedTasks = 0;
6513
+ let currentTaskName = '';
6514
+ // Check execution report for completed tasks
6515
+ if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6516
+ const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6517
+ // Count completed tasks by matching titles
6518
+ const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
6519
+ completedTasks = completedTasksByTitle.length;
6520
+ // Find current task being executed (first task not yet completed)
6521
+ const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
6522
+ if (remainingTasks.length > 0) {
6523
+ currentTaskName = remainingTasks[0].name;
6524
+ }
6525
+ }
6526
+ // Calculate progress percentage
6527
+ let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6528
+ // Add time-based progress for current task (assuming 5 minutes total)
6529
+ if (completedTasks < totalTasks) {
6530
+ const elapsedMs = new Date().getTime() - createdAt.getTime();
6531
+ const totalMs = 5 * 60 * 1000; // 5 minutes
6532
+ const timeProgress = Math.min(elapsedMs / totalMs, 1);
6533
+ // Add partial progress for current task
6534
+ percent += (1 / totalTasks) * timeProgress;
6535
+ }
6536
+ // Clamp to [0,1]
6537
+ percent = Math.min(Math.max(percent, 0), 1);
6538
+ // Generate message
6539
+ let message = '';
6540
+ if (currentTaskName) {
6541
+ // Find the task to get its title
6542
+ const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
6543
+ const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6544
+ message = `Working on task ${taskTitle}`;
6545
+ }
6546
+ else if (completedTasks === 0) {
6547
+ message = 'Starting pipeline execution';
6548
+ }
6549
+ else {
6550
+ message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6551
+ }
6552
+ return {
6553
+ percent,
6554
+ message,
6555
+ };
6556
+ },
6488
6557
  });
6489
6558
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6490
6559
  return pipelineExecutor;