@promptbook/node 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 CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-35';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-37';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -232,6 +232,12 @@ let DEFAULT_IS_VERBOSE = false;
232
232
  * @public exported from `@promptbook/core`
233
233
  */
234
234
  const DEFAULT_IS_AUTO_INSTALLED = false;
235
+ /**
236
+ * Default simulated duration for a task in milliseconds (used for progress reporting)
237
+ *
238
+ * @public exported from `@promptbook/core`
239
+ */
240
+ const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
235
241
  /**
236
242
  * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
237
243
  *
@@ -2082,7 +2088,7 @@ function assertsTaskSuccessful(executionResult) {
2082
2088
  * @private internal helper function
2083
2089
  */
2084
2090
  function createTask(options) {
2085
- const { taskType, taskProcessCallback } = options;
2091
+ const { taskType, taskProcessCallback, tldrProvider } = options;
2086
2092
  let { title } = options;
2087
2093
  // TODO: [🐙] DRY
2088
2094
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2157,21 +2163,35 @@ function createTask(options) {
2157
2163
  },
2158
2164
  get tldr() {
2159
2165
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2160
- // Derive a short progress summary from currentValue, status and any errors/warnings.
2166
+ // Use custom tldr provider if available
2167
+ if (tldrProvider) {
2168
+ return tldrProvider(createdAt, status, currentValue, errors, warnings);
2169
+ }
2170
+ // Fallback to default implementation
2161
2171
  const cv = currentValue;
2162
- // Try several common places where a percent might be stored on the partial result
2172
+ // If explicit percent is provided, use it
2163
2173
  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;
2164
- // If we didn't find a numeric percent, infer from status
2174
+ // Simulate progress if not provided
2165
2175
  if (typeof percentRaw !== 'number') {
2166
- if (status === 'FINISHED') {
2176
+ // Simulate progress: evenly split across subtasks, based on elapsed time
2177
+ const now = new Date();
2178
+ const elapsedMs = now.getTime() - createdAt.getTime();
2179
+ const totalMs = DEFAULT_TASK_SIMULATED_DURATION_MS;
2180
+ // If subtasks are defined, split progress evenly
2181
+ const subtaskCount = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) ? cv.subtasks.length : 1;
2182
+ const completedSubtasks = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks)
2183
+ ? cv.subtasks.filter((s) => s.done || s.completed).length
2184
+ : 0;
2185
+ // Progress from completed subtasks
2186
+ const subtaskProgress = subtaskCount > 0 ? completedSubtasks / subtaskCount : 0;
2187
+ // Progress from elapsed time for current subtask
2188
+ const timeProgress = Math.min(elapsedMs / totalMs, 1);
2189
+ // Combine: completed subtasks + time progress for current subtask
2190
+ percentRaw = Math.min(subtaskProgress + (1 / subtaskCount) * timeProgress, 1);
2191
+ if (status === 'FINISHED')
2167
2192
  percentRaw = 1;
2168
- }
2169
- else if (status === 'ERROR') {
2193
+ if (status === 'ERROR')
2170
2194
  percentRaw = 0;
2171
- }
2172
- else {
2173
- percentRaw = 0;
2174
- }
2175
2195
  }
2176
2196
  // Clamp to [0,1]
2177
2197
  let percent = Number(percentRaw) || 0;
@@ -2183,20 +2203,29 @@ function createTask(options) {
2183
2203
  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;
2184
2204
  let message = messageFromResult;
2185
2205
  if (!message) {
2186
- if (errors.length) {
2187
- message = errors[errors.length - 1].message || 'Error';
2188
- }
2189
- else if (warnings.length) {
2190
- message = warnings[warnings.length - 1].message || 'Warning';
2191
- }
2192
- else if (status === 'FINISHED') {
2193
- message = 'Finished';
2194
- }
2195
- else if (status === 'ERROR') {
2196
- message = 'Error';
2206
+ // If subtasks, show current subtask
2207
+ if (Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) && cv.subtasks.length > 0) {
2208
+ const current = cv.subtasks.find((s) => !s.done && !s.completed);
2209
+ if (current && current.title) {
2210
+ message = `Working on ${current.title}`;
2211
+ }
2197
2212
  }
2198
- else {
2199
- message = 'Running';
2213
+ if (!message) {
2214
+ if (errors.length) {
2215
+ message = errors[errors.length - 1].message || 'Error';
2216
+ }
2217
+ else if (warnings.length) {
2218
+ message = warnings[warnings.length - 1].message || 'Warning';
2219
+ }
2220
+ else if (status === 'FINISHED') {
2221
+ message = 'Finished';
2222
+ }
2223
+ else if (status === 'ERROR') {
2224
+ message = 'Error';
2225
+ }
2226
+ else {
2227
+ message = 'Running';
2228
+ }
2200
2229
  }
2201
2230
  }
2202
2231
  return {
@@ -4986,6 +5015,71 @@ function createPipelineExecutor(options) {
4986
5015
  updateOngoingResult(newOngoingResult);
4987
5016
  });
4988
5017
  },
5018
+ tldrProvider(createdAt, status, currentValue, errors) {
5019
+ var _a;
5020
+ // Better progress estimation based on pipeline structure
5021
+ const cv = currentValue;
5022
+ // Handle finished/error states
5023
+ if (status === 'FINISHED') {
5024
+ return {
5025
+ percent: 1,
5026
+ message: 'Finished',
5027
+ };
5028
+ }
5029
+ if (status === 'ERROR') {
5030
+ const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
5031
+ return {
5032
+ percent: 0,
5033
+ message: errorMessage,
5034
+ };
5035
+ }
5036
+ // Calculate progress based on pipeline tasks
5037
+ const totalTasks = pipeline.tasks.length;
5038
+ let completedTasks = 0;
5039
+ let currentTaskName = '';
5040
+ // Check execution report for completed tasks
5041
+ if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
5042
+ const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
5043
+ // Count completed tasks by matching titles
5044
+ const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
5045
+ completedTasks = completedTasksByTitle.length;
5046
+ // Find current task being executed (first task not yet completed)
5047
+ const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
5048
+ if (remainingTasks.length > 0) {
5049
+ currentTaskName = remainingTasks[0].name;
5050
+ }
5051
+ }
5052
+ // Calculate progress percentage
5053
+ let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
5054
+ // Add time-based progress for current task (assuming 5 minutes total)
5055
+ if (completedTasks < totalTasks) {
5056
+ const elapsedMs = new Date().getTime() - createdAt.getTime();
5057
+ const totalMs = 5 * 60 * 1000; // 5 minutes
5058
+ const timeProgress = Math.min(elapsedMs / totalMs, 1);
5059
+ // Add partial progress for current task
5060
+ percent += (1 / totalTasks) * timeProgress;
5061
+ }
5062
+ // Clamp to [0,1]
5063
+ percent = Math.min(Math.max(percent, 0), 1);
5064
+ // Generate message
5065
+ let message = '';
5066
+ if (currentTaskName) {
5067
+ // Find the task to get its title
5068
+ const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
5069
+ const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
5070
+ message = `Working on task ${taskTitle}`;
5071
+ }
5072
+ else if (completedTasks === 0) {
5073
+ message = 'Starting pipeline execution';
5074
+ }
5075
+ else {
5076
+ message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
5077
+ }
5078
+ return {
5079
+ percent,
5080
+ message,
5081
+ };
5082
+ },
4989
5083
  });
4990
5084
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
4991
5085
  return pipelineExecutor;