@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.
@@ -46,6 +46,7 @@ import { DEFAULT_CSV_SETTINGS } from '../config';
46
46
  import { DEFAULT_IS_VERBOSE } from '../config';
47
47
  import { SET_IS_VERBOSE } from '../config';
48
48
  import { DEFAULT_IS_AUTO_INSTALLED } from '../config';
49
+ import { DEFAULT_TASK_SIMULATED_DURATION_MS } from '../config';
49
50
  import { DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME } from '../config';
50
51
  import { DEFAULT_MAX_REQUESTS_PER_MINUTE } from '../config';
51
52
  import { MODEL_TRUST_LEVELS } from '../constants';
@@ -207,6 +208,7 @@ export { DEFAULT_CSV_SETTINGS };
207
208
  export { DEFAULT_IS_VERBOSE };
208
209
  export { SET_IS_VERBOSE };
209
210
  export { DEFAULT_IS_AUTO_INSTALLED };
211
+ export { DEFAULT_TASK_SIMULATED_DURATION_MS };
210
212
  export { DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME };
211
213
  export { DEFAULT_MAX_REQUESTS_PER_MINUTE };
212
214
  export { MODEL_TRUST_LEVELS };
@@ -281,6 +281,12 @@ export declare function SET_IS_VERBOSE(isVerbose: boolean): void;
281
281
  * @public exported from `@promptbook/core`
282
282
  */
283
283
  export declare const DEFAULT_IS_AUTO_INSTALLED = false;
284
+ /**
285
+ * Default simulated duration for a task in milliseconds (used for progress reporting)
286
+ *
287
+ * @public exported from `@promptbook/core`
288
+ */
289
+ export declare const DEFAULT_TASK_SIMULATED_DURATION_MS: number;
284
290
  /**
285
291
  * Function name for generated function via `ptbk make` to get the pipeline collection
286
292
  *
@@ -29,6 +29,19 @@ type CreateTaskOptions<TTaskResult extends AbstractTaskResult> = {
29
29
  */
30
30
  readonly title?: AbstractTask<TTaskResult>['title'];
31
31
  }) => void): Promise<TTaskResult>;
32
+ /**
33
+ * Optional callback to provide custom tldr information
34
+ * @param createdAt When the task was created
35
+ * @param status Current task status
36
+ * @param currentValue Current partial result
37
+ * @param errors Current errors
38
+ * @param warnings Current warnings
39
+ * @returns Custom tldr information
40
+ */
41
+ tldrProvider?(createdAt: Date, status: task_status, currentValue: PartialDeep<TTaskResult>, errors: Array<Error>, warnings: Array<Error>): {
42
+ readonly percent: number_percent;
43
+ readonly message: string;
44
+ };
32
45
  };
33
46
  /**
34
47
  * Helper to create a new task
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.100.0-34`).
18
+ * It follows semantic versioning (e.g., `0.100.0-36`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/wizard",
3
- "version": "0.100.0-35",
3
+ "version": "0.100.0-37",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/wizard.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.100.0-35"
98
+ "@promptbook/core": "0.100.0-37"
99
99
  },
100
100
  "dependencies": {
101
101
  "@ai-sdk/deepseek": "0.1.6",
package/umd/index.umd.js CHANGED
@@ -49,7 +49,7 @@
49
49
  * @generated
50
50
  * @see https://github.com/webgptorg/promptbook
51
51
  */
52
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-35';
52
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-37';
53
53
  /**
54
54
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
55
55
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -323,6 +323,12 @@
323
323
  * @public exported from `@promptbook/core`
324
324
  */
325
325
  const DEFAULT_IS_AUTO_INSTALLED = false;
326
+ /**
327
+ * Default simulated duration for a task in milliseconds (used for progress reporting)
328
+ *
329
+ * @public exported from `@promptbook/core`
330
+ */
331
+ const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
326
332
  /**
327
333
  * Default rate limits (requests per minute)
328
334
  *
@@ -7176,7 +7182,7 @@
7176
7182
  * @private internal helper function
7177
7183
  */
7178
7184
  function createTask(options) {
7179
- const { taskType, taskProcessCallback } = options;
7185
+ const { taskType, taskProcessCallback, tldrProvider } = options;
7180
7186
  let { title } = options;
7181
7187
  // TODO: [🐙] DRY
7182
7188
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -7251,21 +7257,35 @@
7251
7257
  },
7252
7258
  get tldr() {
7253
7259
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
7254
- // Derive a short progress summary from currentValue, status and any errors/warnings.
7260
+ // Use custom tldr provider if available
7261
+ if (tldrProvider) {
7262
+ return tldrProvider(createdAt, status, currentValue, errors, warnings);
7263
+ }
7264
+ // Fallback to default implementation
7255
7265
  const cv = currentValue;
7256
- // Try several common places where a percent might be stored on the partial result
7266
+ // If explicit percent is provided, use it
7257
7267
  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;
7258
- // If we didn't find a numeric percent, infer from status
7268
+ // Simulate progress if not provided
7259
7269
  if (typeof percentRaw !== 'number') {
7260
- if (status === 'FINISHED') {
7270
+ // Simulate progress: evenly split across subtasks, based on elapsed time
7271
+ const now = new Date();
7272
+ const elapsedMs = now.getTime() - createdAt.getTime();
7273
+ const totalMs = DEFAULT_TASK_SIMULATED_DURATION_MS;
7274
+ // If subtasks are defined, split progress evenly
7275
+ const subtaskCount = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) ? cv.subtasks.length : 1;
7276
+ const completedSubtasks = Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks)
7277
+ ? cv.subtasks.filter((s) => s.done || s.completed).length
7278
+ : 0;
7279
+ // Progress from completed subtasks
7280
+ const subtaskProgress = subtaskCount > 0 ? completedSubtasks / subtaskCount : 0;
7281
+ // Progress from elapsed time for current subtask
7282
+ const timeProgress = Math.min(elapsedMs / totalMs, 1);
7283
+ // Combine: completed subtasks + time progress for current subtask
7284
+ percentRaw = Math.min(subtaskProgress + (1 / subtaskCount) * timeProgress, 1);
7285
+ if (status === 'FINISHED')
7261
7286
  percentRaw = 1;
7262
- }
7263
- else if (status === 'ERROR') {
7287
+ if (status === 'ERROR')
7264
7288
  percentRaw = 0;
7265
- }
7266
- else {
7267
- percentRaw = 0;
7268
- }
7269
7289
  }
7270
7290
  // Clamp to [0,1]
7271
7291
  let percent = Number(percentRaw) || 0;
@@ -7277,20 +7297,29 @@
7277
7297
  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;
7278
7298
  let message = messageFromResult;
7279
7299
  if (!message) {
7280
- if (errors.length) {
7281
- message = errors[errors.length - 1].message || 'Error';
7282
- }
7283
- else if (warnings.length) {
7284
- message = warnings[warnings.length - 1].message || 'Warning';
7285
- }
7286
- else if (status === 'FINISHED') {
7287
- message = 'Finished';
7288
- }
7289
- else if (status === 'ERROR') {
7290
- message = 'Error';
7300
+ // If subtasks, show current subtask
7301
+ if (Array.isArray(cv === null || cv === void 0 ? void 0 : cv.subtasks) && cv.subtasks.length > 0) {
7302
+ const current = cv.subtasks.find((s) => !s.done && !s.completed);
7303
+ if (current && current.title) {
7304
+ message = `Working on ${current.title}`;
7305
+ }
7291
7306
  }
7292
- else {
7293
- message = 'Running';
7307
+ if (!message) {
7308
+ if (errors.length) {
7309
+ message = errors[errors.length - 1].message || 'Error';
7310
+ }
7311
+ else if (warnings.length) {
7312
+ message = warnings[warnings.length - 1].message || 'Warning';
7313
+ }
7314
+ else if (status === 'FINISHED') {
7315
+ message = 'Finished';
7316
+ }
7317
+ else if (status === 'ERROR') {
7318
+ message = 'Error';
7319
+ }
7320
+ else {
7321
+ message = 'Running';
7322
+ }
7294
7323
  }
7295
7324
  }
7296
7325
  return {
@@ -10299,6 +10328,71 @@
10299
10328
  updateOngoingResult(newOngoingResult);
10300
10329
  });
10301
10330
  },
10331
+ tldrProvider(createdAt, status, currentValue, errors) {
10332
+ var _a;
10333
+ // Better progress estimation based on pipeline structure
10334
+ const cv = currentValue;
10335
+ // Handle finished/error states
10336
+ if (status === 'FINISHED') {
10337
+ return {
10338
+ percent: 1,
10339
+ message: 'Finished',
10340
+ };
10341
+ }
10342
+ if (status === 'ERROR') {
10343
+ const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
10344
+ return {
10345
+ percent: 0,
10346
+ message: errorMessage,
10347
+ };
10348
+ }
10349
+ // Calculate progress based on pipeline tasks
10350
+ const totalTasks = pipeline.tasks.length;
10351
+ let completedTasks = 0;
10352
+ let currentTaskName = '';
10353
+ // Check execution report for completed tasks
10354
+ if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
10355
+ const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
10356
+ // Count completed tasks by matching titles
10357
+ const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
10358
+ completedTasks = completedTasksByTitle.length;
10359
+ // Find current task being executed (first task not yet completed)
10360
+ const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
10361
+ if (remainingTasks.length > 0) {
10362
+ currentTaskName = remainingTasks[0].name;
10363
+ }
10364
+ }
10365
+ // Calculate progress percentage
10366
+ let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
10367
+ // Add time-based progress for current task (assuming 5 minutes total)
10368
+ if (completedTasks < totalTasks) {
10369
+ const elapsedMs = new Date().getTime() - createdAt.getTime();
10370
+ const totalMs = 5 * 60 * 1000; // 5 minutes
10371
+ const timeProgress = Math.min(elapsedMs / totalMs, 1);
10372
+ // Add partial progress for current task
10373
+ percent += (1 / totalTasks) * timeProgress;
10374
+ }
10375
+ // Clamp to [0,1]
10376
+ percent = Math.min(Math.max(percent, 0), 1);
10377
+ // Generate message
10378
+ let message = '';
10379
+ if (currentTaskName) {
10380
+ // Find the task to get its title
10381
+ const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
10382
+ const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
10383
+ message = `Working on task ${taskTitle}`;
10384
+ }
10385
+ else if (completedTasks === 0) {
10386
+ message = 'Starting pipeline execution';
10387
+ }
10388
+ else {
10389
+ message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
10390
+ }
10391
+ return {
10392
+ percent,
10393
+ message,
10394
+ };
10395
+ },
10302
10396
  });
10303
10397
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
10304
10398
  return pipelineExecutor;