@promptbook/markitdown 0.100.0-44 → 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.
Files changed (34) hide show
  1. package/esm/index.es.js +98 -86
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +14 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +8 -0
  6. package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +1 -1
  7. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +26 -0
  8. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfileFromSource.d.ts +19 -0
  9. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +15 -0
  10. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +128 -0
  11. package/esm/typings/src/book-components/Chat/interfaces/ChatMessage.d.ts +16 -0
  12. package/esm/typings/src/book-components/Chat/interfaces/ChatParticipant.d.ts +12 -0
  13. package/esm/typings/src/book-components/Chat/utils/ExportFormat.d.ts +4 -0
  14. package/esm/typings/src/book-components/Chat/utils/addUtmParamsToUrl.d.ts +7 -0
  15. package/esm/typings/src/book-components/Chat/utils/createShortLinkForChat.d.ts +7 -0
  16. package/esm/typings/src/book-components/Chat/utils/downloadFile.d.ts +6 -0
  17. package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +11 -0
  18. package/esm/typings/src/book-components/Chat/utils/generatePdfContent.d.ts +10 -0
  19. package/esm/typings/src/book-components/Chat/utils/generateQrDataUrl.d.ts +7 -0
  20. package/esm/typings/src/book-components/Chat/utils/getPromptbookBranding.d.ts +6 -0
  21. package/esm/typings/src/book-components/Chat/utils/messagesToHtml.d.ts +10 -0
  22. package/esm/typings/src/book-components/Chat/utils/messagesToJson.d.ts +7 -0
  23. package/esm/typings/src/book-components/Chat/utils/messagesToMarkdown.d.ts +10 -0
  24. package/esm/typings/src/book-components/Chat/utils/messagesToText.d.ts +10 -0
  25. package/esm/typings/src/config.d.ts +13 -0
  26. package/esm/typings/src/execution/ExecutionTask.d.ts +12 -13
  27. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +8 -0
  28. package/esm/typings/src/playground/permanent/error-handling-playground.d.ts +5 -0
  29. package/esm/typings/src/utils/organization/preserve.d.ts +21 -0
  30. package/esm/typings/src/version.d.ts +1 -1
  31. package/package.json +2 -3
  32. package/umd/index.umd.js +102 -90
  33. package/umd/index.umd.js.map +1 -1
  34. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +0 -14
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-44';
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
  *
@@ -1027,7 +1035,7 @@ function prettifyMarkdown(content) {
1027
1035
  try {
1028
1036
  return format(content, {
1029
1037
  parser: 'markdown',
1030
- plugins: [parserHtml],
1038
+ plugins: [parserMarkdown, parserHtml],
1031
1039
  // TODO: DRY - make some import or auto-copy of .prettierrc
1032
1040
  endOfLine: 'lf',
1033
1041
  tabWidth: 4,
@@ -2519,7 +2527,7 @@ function assertsTaskSuccessful(executionResult) {
2519
2527
  * @private internal helper function
2520
2528
  */
2521
2529
  function createTask(options) {
2522
- const { taskType, taskProcessCallback, tldrProvider } = options;
2530
+ const { taskType, taskProcessCallback } = options;
2523
2531
  let { title } = options;
2524
2532
  // TODO: [🐙] DRY
2525
2533
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2529,6 +2537,7 @@ function createTask(options) {
2529
2537
  const errors = [];
2530
2538
  const warnings = [];
2531
2539
  let currentValue = {};
2540
+ let customTldr = null;
2532
2541
  const partialResultSubject = new Subject();
2533
2542
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2534
2543
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
@@ -2539,6 +2548,9 @@ function createTask(options) {
2539
2548
  Object.assign(currentValue, newOngoingResult);
2540
2549
  // <- TODO: assign deep
2541
2550
  partialResultSubject.next(newOngoingResult);
2551
+ }, (tldrInfo) => {
2552
+ customTldr = tldrInfo;
2553
+ updatedAt = new Date();
2542
2554
  });
2543
2555
  finalResultPromise
2544
2556
  .catch((error) => {
@@ -2594,9 +2606,9 @@ function createTask(options) {
2594
2606
  },
2595
2607
  get tldr() {
2596
2608
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2597
- // Use custom tldr provider if available
2598
- if (tldrProvider) {
2599
- return tldrProvider(createdAt, status, currentValue, errors, warnings);
2609
+ // Use custom tldr if available
2610
+ if (customTldr) {
2611
+ return customTldr;
2600
2612
  }
2601
2613
  // Fallback to default implementation
2602
2614
  const cv = currentValue;
@@ -3163,7 +3175,7 @@ async function preparePersona(personaDescription, tools, options) {
3163
3175
  const result = await preparePersonaExecutor({
3164
3176
  availableModels /* <- Note: Passing as JSON */,
3165
3177
  personaDescription,
3166
- }).asPromise();
3178
+ }).asPromise({ isCrashedOnError: true });
3167
3179
  const { outputParameters } = result;
3168
3180
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3169
3181
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -3927,7 +3939,7 @@ async function preparePipeline(pipeline, tools, options) {
3927
3939
  });
3928
3940
  const result = await prepareTitleExecutor({
3929
3941
  book: sources.map(({ content }) => content).join('\n\n'),
3930
- }).asPromise();
3942
+ }).asPromise({ isCrashedOnError: true });
3931
3943
  const { outputParameters } = result;
3932
3944
  const { title: titleRaw } = outputParameters;
3933
3945
  if (isVerbose) {
@@ -6142,80 +6154,74 @@ function createPipelineExecutor(options) {
6142
6154
  });
6143
6155
  });
6144
6156
  };
6145
- const pipelineExecutor = (inputParameters) => createTask({
6146
- taskType: 'EXECUTION',
6147
- title: pipeline.title,
6148
- taskProcessCallback(updateOngoingResult) {
6149
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6150
- updateOngoingResult(newOngoingResult);
6151
- });
6152
- },
6153
- tldrProvider(createdAt, status, currentValue, errors) {
6154
- var _a;
6155
- // Better progress estimation based on pipeline structure
6156
- const cv = currentValue;
6157
- // Handle finished/error states
6158
- if (status === 'FINISHED') {
6159
- return {
6160
- percent: 1,
6161
- message: 'Finished',
6162
- };
6163
- }
6164
- if (status === 'ERROR') {
6165
- const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
6166
- return {
6167
- percent: 0,
6168
- message: errorMessage,
6169
- };
6170
- }
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;
6185
- }
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() - createdAt.getTime();
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
- return {
6214
- percent,
6215
- message,
6216
- };
6217
- },
6218
- });
6157
+ const pipelineExecutor = (inputParameters) => {
6158
+ const startTime = new Date().getTime();
6159
+ return createTask({
6160
+ taskType: 'EXECUTION',
6161
+ title: pipeline.title,
6162
+ taskProcessCallback(updateOngoingResult, updateTldr) {
6163
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6164
+ var _a, _b;
6165
+ updateOngoingResult(newOngoingResult);
6166
+ // Calculate and update tldr based on pipeline progress
6167
+ const cv = newOngoingResult;
6168
+ // Calculate progress based on parameters resolved vs total parameters
6169
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
6170
+ let resolvedParameters = 0;
6171
+ let currentTaskTitle = '';
6172
+ // Get the resolved parameters from output parameters
6173
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
6174
+ // Count how many output parameters have non-empty values
6175
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
6176
+ }
6177
+ // Try to determine current task from execution report
6178
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
6179
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
6180
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
6181
+ currentTaskTitle = lastExecution.prompt.title;
6182
+ }
6183
+ }
6184
+ // Calculate base progress percentage
6185
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
6186
+ // Add time-based progress for current task if we haven't completed all parameters
6187
+ if (resolvedParameters < totalParameters) {
6188
+ const elapsedMs = new Date().getTime() - startTime;
6189
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
6190
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
6191
+ // If we have time progress but no parameter progress, show time progress
6192
+ if (percent === 0 && timeProgress > 0) {
6193
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
6194
+ }
6195
+ else if (percent < 1) {
6196
+ // Add partial progress for current task
6197
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
6198
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
6199
+ }
6200
+ }
6201
+ // Clamp to [0,1]
6202
+ percent = Math.min(Math.max(percent, 0), 1);
6203
+ // Generate message
6204
+ let message = '';
6205
+ if (currentTaskTitle) {
6206
+ message = `Executing: ${currentTaskTitle}`;
6207
+ }
6208
+ else if (resolvedParameters === 0) {
6209
+ message = 'Starting pipeline execution';
6210
+ }
6211
+ else if (resolvedParameters < totalParameters) {
6212
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
6213
+ }
6214
+ else {
6215
+ message = 'Completing pipeline execution';
6216
+ }
6217
+ updateTldr({
6218
+ percent: percent,
6219
+ message,
6220
+ });
6221
+ });
6222
+ },
6223
+ });
6224
+ };
6219
6225
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6220
6226
  return pipelineExecutor;
6221
6227
  }
@@ -6300,7 +6306,9 @@ class MarkdownScraper {
6300
6306
  },
6301
6307
  });
6302
6308
  const knowledgeContent = await source.asText();
6303
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6309
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6310
+ isCrashedOnError: true,
6311
+ });
6304
6312
  const { outputParameters } = result;
6305
6313
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6306
6314
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6324,12 +6332,16 @@ class MarkdownScraper {
6324
6332
  ];
6325
6333
  */
6326
6334
  try {
6327
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6335
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6336
+ isCrashedOnError: true,
6337
+ });
6328
6338
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6329
6339
  title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
6330
6340
  name = titleToName(title);
6331
6341
  // --- Keywords
6332
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6342
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6343
+ isCrashedOnError: true,
6344
+ });
6333
6345
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6334
6346
  keywords = (keywordsRaw || '')
6335
6347
  .split(',')