@promptbook/pdf 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
  *
@@ -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,
@@ -2532,7 +2540,7 @@ function assertsTaskSuccessful(executionResult) {
2532
2540
  * @private internal helper function
2533
2541
  */
2534
2542
  function createTask(options) {
2535
- const { taskType, taskProcessCallback, tldrProvider } = options;
2543
+ const { taskType, taskProcessCallback } = options;
2536
2544
  let { title } = options;
2537
2545
  // TODO: [🐙] DRY
2538
2546
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2542,6 +2550,7 @@ function createTask(options) {
2542
2550
  const errors = [];
2543
2551
  const warnings = [];
2544
2552
  let currentValue = {};
2553
+ let customTldr = null;
2545
2554
  const partialResultSubject = new Subject();
2546
2555
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2547
2556
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
@@ -2552,6 +2561,9 @@ function createTask(options) {
2552
2561
  Object.assign(currentValue, newOngoingResult);
2553
2562
  // <- TODO: assign deep
2554
2563
  partialResultSubject.next(newOngoingResult);
2564
+ }, (tldrInfo) => {
2565
+ customTldr = tldrInfo;
2566
+ updatedAt = new Date();
2555
2567
  });
2556
2568
  finalResultPromise
2557
2569
  .catch((error) => {
@@ -2607,9 +2619,9 @@ function createTask(options) {
2607
2619
  },
2608
2620
  get tldr() {
2609
2621
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2610
- // Use custom tldr provider if available
2611
- if (tldrProvider) {
2612
- return tldrProvider(createdAt, status, currentValue, errors, warnings);
2622
+ // Use custom tldr if available
2623
+ if (customTldr) {
2624
+ return customTldr;
2613
2625
  }
2614
2626
  // Fallback to default implementation
2615
2627
  const cv = currentValue;
@@ -3176,7 +3188,7 @@ async function preparePersona(personaDescription, tools, options) {
3176
3188
  const result = await preparePersonaExecutor({
3177
3189
  availableModels /* <- Note: Passing as JSON */,
3178
3190
  personaDescription,
3179
- }).asPromise();
3191
+ }).asPromise({ isCrashedOnError: true });
3180
3192
  const { outputParameters } = result;
3181
3193
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3182
3194
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -3940,7 +3952,7 @@ async function preparePipeline(pipeline, tools, options) {
3940
3952
  });
3941
3953
  const result = await prepareTitleExecutor({
3942
3954
  book: sources.map(({ content }) => content).join('\n\n'),
3943
- }).asPromise();
3955
+ }).asPromise({ isCrashedOnError: true });
3944
3956
  const { outputParameters } = result;
3945
3957
  const { title: titleRaw } = outputParameters;
3946
3958
  if (isVerbose) {
@@ -6155,80 +6167,74 @@ function createPipelineExecutor(options) {
6155
6167
  });
6156
6168
  });
6157
6169
  };
6158
- const pipelineExecutor = (inputParameters) => createTask({
6159
- taskType: 'EXECUTION',
6160
- title: pipeline.title,
6161
- taskProcessCallback(updateOngoingResult) {
6162
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6163
- updateOngoingResult(newOngoingResult);
6164
- });
6165
- },
6166
- tldrProvider(createdAt, status, currentValue, errors) {
6167
- var _a;
6168
- // Better progress estimation based on pipeline structure
6169
- const cv = currentValue;
6170
- // Handle finished/error states
6171
- if (status === 'FINISHED') {
6172
- return {
6173
- percent: 1,
6174
- message: 'Finished',
6175
- };
6176
- }
6177
- if (status === 'ERROR') {
6178
- const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
6179
- return {
6180
- percent: 0,
6181
- message: errorMessage,
6182
- };
6183
- }
6184
- // Calculate progress based on pipeline tasks
6185
- const totalTasks = pipeline.tasks.length;
6186
- let completedTasks = 0;
6187
- let currentTaskName = '';
6188
- // Check execution report for completed tasks
6189
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6190
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6191
- // Count completed tasks by matching titles
6192
- const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
6193
- completedTasks = completedTasksByTitle.length;
6194
- // Find current task being executed (first task not yet completed)
6195
- const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
6196
- if (remainingTasks.length > 0) {
6197
- currentTaskName = remainingTasks[0].name;
6198
- }
6199
- }
6200
- // Calculate progress percentage
6201
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6202
- // Add time-based progress for current task (assuming 5 minutes total)
6203
- if (completedTasks < totalTasks) {
6204
- const elapsedMs = new Date().getTime() - createdAt.getTime();
6205
- const totalMs = 5 * 60 * 1000; // 5 minutes
6206
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
6207
- // Add partial progress for current task
6208
- percent += (1 / totalTasks) * timeProgress;
6209
- }
6210
- // Clamp to [0,1]
6211
- percent = Math.min(Math.max(percent, 0), 1);
6212
- // Generate message
6213
- let message = '';
6214
- if (currentTaskName) {
6215
- // Find the task to get its title
6216
- const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
6217
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6218
- message = `Working on task ${taskTitle}`;
6219
- }
6220
- else if (completedTasks === 0) {
6221
- message = 'Starting pipeline execution';
6222
- }
6223
- else {
6224
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6225
- }
6226
- return {
6227
- percent,
6228
- message,
6229
- };
6230
- },
6231
- });
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;
6189
+ }
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
+ });
6234
+ });
6235
+ },
6236
+ });
6237
+ };
6232
6238
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6233
6239
  return pipelineExecutor;
6234
6240
  }
@@ -6313,7 +6319,9 @@ class MarkdownScraper {
6313
6319
  },
6314
6320
  });
6315
6321
  const knowledgeContent = await source.asText();
6316
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6322
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6323
+ isCrashedOnError: true,
6324
+ });
6317
6325
  const { outputParameters } = result;
6318
6326
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6319
6327
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6337,12 +6345,16 @@ class MarkdownScraper {
6337
6345
  ];
6338
6346
  */
6339
6347
  try {
6340
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6348
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6349
+ isCrashedOnError: true,
6350
+ });
6341
6351
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6342
6352
  title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
6343
6353
  name = titleToName(title);
6344
6354
  // --- Keywords
6345
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6355
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6356
+ isCrashedOnError: true,
6357
+ });
6346
6358
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6347
6359
  keywords = (keywordsRaw || '')
6348
6360
  .split(',')