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