@promptbook/pdf 0.100.0-45 → 0.100.0-46

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
@@ -3,8 +3,9 @@ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
3
3
  import { SHA256 } from 'crypto-js';
4
4
  import hexEncoder from 'crypto-js/enc-hex';
5
5
  import { basename, join, dirname } from 'path';
6
- import { format } from 'prettier';
7
6
  import parserHtml from 'prettier/parser-html';
7
+ import parserMarkdown from 'prettier/parser-markdown';
8
+ import { format } from 'prettier/standalone';
8
9
  import { randomBytes } from 'crypto';
9
10
  import { Subject } from 'rxjs';
10
11
  import { forTime } from 'waitasecond';
@@ -26,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
27
  * @generated
27
28
  * @see https://github.com/webgptorg/promptbook
28
29
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-45';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
30
31
  /**
31
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -224,6 +225,13 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
224
225
  * @public exported from `@promptbook/core`
225
226
  */
226
227
  const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
228
+ /**
229
+ * API request timeout in milliseconds
230
+ * Can be overridden via API_REQUEST_TIMEOUT environment variable
231
+ *
232
+ * @public exported from `@promptbook/core`
233
+ */
234
+ parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
227
235
  /**
228
236
  * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
229
237
  *
@@ -1040,7 +1048,7 @@ function prettifyMarkdown(content) {
1040
1048
  try {
1041
1049
  return format(content, {
1042
1050
  parser: 'markdown',
1043
- plugins: [parserHtml],
1051
+ plugins: [parserMarkdown, parserHtml],
1044
1052
  // TODO: DRY - make some import or auto-copy of .prettierrc
1045
1053
  endOfLine: 'lf',
1046
1054
  tabWidth: 4,
@@ -3180,7 +3188,7 @@ async function preparePersona(personaDescription, tools, options) {
3180
3188
  const result = await preparePersonaExecutor({
3181
3189
  availableModels /* <- Note: Passing as JSON */,
3182
3190
  personaDescription,
3183
- }).asPromise();
3191
+ }).asPromise({ isCrashedOnError: true });
3184
3192
  const { outputParameters } = result;
3185
3193
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3186
3194
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -3944,7 +3952,7 @@ async function preparePipeline(pipeline, tools, options) {
3944
3952
  });
3945
3953
  const result = await prepareTitleExecutor({
3946
3954
  book: sources.map(({ content }) => content).join('\n\n'),
3947
- }).asPromise();
3955
+ }).asPromise({ isCrashedOnError: true });
3948
3956
  const { outputParameters } = result;
3949
3957
  const { title: titleRaw } = outputParameters;
3950
3958
  if (isVerbose) {
@@ -6159,64 +6167,74 @@ function createPipelineExecutor(options) {
6159
6167
  });
6160
6168
  });
6161
6169
  };
6162
- const pipelineExecutor = (inputParameters) => createTask({
6163
- taskType: 'EXECUTION',
6164
- title: pipeline.title,
6165
- taskProcessCallback(updateOngoingResult, updateTldr) {
6166
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6167
- var _a;
6168
- updateOngoingResult(newOngoingResult);
6169
- // Calculate and update tldr based on pipeline progress
6170
- const cv = newOngoingResult;
6171
- // Calculate progress based on pipeline tasks
6172
- const totalTasks = pipeline.tasks.length;
6173
- let completedTasks = 0;
6174
- let currentTaskName = '';
6175
- // Check execution report for completed tasks
6176
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6177
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6178
- // Count completed tasks by matching titles
6179
- const completedTasksByTitle = pipeline.tasks.filter((task) => executedTaskTitles.has(task.title));
6180
- completedTasks = completedTasksByTitle.length;
6181
- // Find current task being executed (first task not yet completed)
6182
- const remainingTasks = pipeline.tasks.filter((task) => !executedTaskTitles.has(task.title));
6183
- if (remainingTasks.length > 0) {
6184
- currentTaskName = remainingTasks[0].name;
6170
+ const pipelineExecutor = (inputParameters) => {
6171
+ const startTime = new Date().getTime();
6172
+ return createTask({
6173
+ taskType: 'EXECUTION',
6174
+ title: pipeline.title,
6175
+ taskProcessCallback(updateOngoingResult, updateTldr) {
6176
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6177
+ var _a, _b;
6178
+ updateOngoingResult(newOngoingResult);
6179
+ // Calculate and update tldr based on pipeline progress
6180
+ const cv = newOngoingResult;
6181
+ // Calculate progress based on parameters resolved vs total parameters
6182
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
6183
+ let resolvedParameters = 0;
6184
+ let currentTaskTitle = '';
6185
+ // Get the resolved parameters from output parameters
6186
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
6187
+ // Count how many output parameters have non-empty values
6188
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
6185
6189
  }
6186
- }
6187
- // Calculate progress percentage
6188
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6189
- // Add time-based progress for current task (assuming 5 minutes total)
6190
- if (completedTasks < totalTasks) {
6191
- const elapsedMs = new Date().getTime() - new Date().getTime(); // Will be overridden by actual elapsed time in task
6192
- const totalMs = 5 * 60 * 1000; // 5 minutes
6193
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
6194
- // Add partial progress for current task
6195
- percent += (1 / totalTasks) * timeProgress;
6196
- }
6197
- // Clamp to [0,1]
6198
- percent = Math.min(Math.max(percent, 0), 1);
6199
- // Generate message
6200
- let message = '';
6201
- if (currentTaskName) {
6202
- // Find the task to get its title
6203
- const currentTask = pipeline.tasks.find((task) => task.name === currentTaskName);
6204
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6205
- message = `Working on task ${taskTitle}`;
6206
- }
6207
- else if (completedTasks === 0) {
6208
- message = 'Starting pipeline execution';
6209
- }
6210
- else {
6211
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6212
- }
6213
- updateTldr({
6214
- percent: percent,
6215
- message,
6190
+ // Try to determine current task from execution report
6191
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
6192
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
6193
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
6194
+ currentTaskTitle = lastExecution.prompt.title;
6195
+ }
6196
+ }
6197
+ // Calculate base progress percentage
6198
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
6199
+ // Add time-based progress for current task if we haven't completed all parameters
6200
+ if (resolvedParameters < totalParameters) {
6201
+ const elapsedMs = new Date().getTime() - startTime;
6202
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
6203
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
6204
+ // If we have time progress but no parameter progress, show time progress
6205
+ if (percent === 0 && timeProgress > 0) {
6206
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
6207
+ }
6208
+ else if (percent < 1) {
6209
+ // Add partial progress for current task
6210
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
6211
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
6212
+ }
6213
+ }
6214
+ // Clamp to [0,1]
6215
+ percent = Math.min(Math.max(percent, 0), 1);
6216
+ // Generate message
6217
+ let message = '';
6218
+ if (currentTaskTitle) {
6219
+ message = `Executing: ${currentTaskTitle}`;
6220
+ }
6221
+ else if (resolvedParameters === 0) {
6222
+ message = 'Starting pipeline execution';
6223
+ }
6224
+ else if (resolvedParameters < totalParameters) {
6225
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
6226
+ }
6227
+ else {
6228
+ message = 'Completing pipeline execution';
6229
+ }
6230
+ updateTldr({
6231
+ percent: percent,
6232
+ message,
6233
+ });
6216
6234
  });
6217
- });
6218
- },
6219
- });
6235
+ },
6236
+ });
6237
+ };
6220
6238
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6221
6239
  return pipelineExecutor;
6222
6240
  }
@@ -6301,7 +6319,9 @@ class MarkdownScraper {
6301
6319
  },
6302
6320
  });
6303
6321
  const knowledgeContent = await source.asText();
6304
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6322
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6323
+ isCrashedOnError: true,
6324
+ });
6305
6325
  const { outputParameters } = result;
6306
6326
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6307
6327
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6325,12 +6345,16 @@ class MarkdownScraper {
6325
6345
  ];
6326
6346
  */
6327
6347
  try {
6328
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6348
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6349
+ isCrashedOnError: true,
6350
+ });
6329
6351
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6330
6352
  title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
6331
6353
  name = titleToName(title);
6332
6354
  // --- Keywords
6333
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6355
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6356
+ isCrashedOnError: true,
6357
+ });
6334
6358
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6335
6359
  keywords = (keywordsRaw || '')
6336
6360
  .split(',')