@promptbook/legacy-documents 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/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('path'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'path', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.path, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.sha256, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, promises, path, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, prettier, parserHtml, crypto, rxjs, sha256, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('path'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('prettier/parser-html'), require('prettier/parser-markdown'), require('prettier/standalone'), require('crypto'), require('rxjs'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'path', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'prettier/parser-html', 'prettier/parser-markdown', 'prettier/standalone', 'crypto', 'rxjs', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.path, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.parserHtml, global.parserMarkdown, global.standalone, global.crypto, global.rxjs, global.sha256, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, promises, path, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, parserHtml, parserMarkdown, standalone, crypto, rxjs, sha256, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -10,6 +10,7 @@
10
10
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
11
11
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
12
12
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
13
+ var parserMarkdown__default = /*#__PURE__*/_interopDefaultLegacy(parserMarkdown);
13
14
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
14
15
 
15
16
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -26,7 +27,7 @@
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 @@
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
  *
@@ -1215,9 +1223,9 @@
1215
1223
  */
1216
1224
  function prettifyMarkdown(content) {
1217
1225
  try {
1218
- return prettier.format(content, {
1226
+ return standalone.format(content, {
1219
1227
  parser: 'markdown',
1220
- plugins: [parserHtml__default["default"]],
1228
+ plugins: [parserMarkdown__default["default"], parserHtml__default["default"]],
1221
1229
  // TODO: DRY - make some import or auto-copy of .prettierrc
1222
1230
  endOfLine: 'lf',
1223
1231
  tabWidth: 4,
@@ -2691,7 +2699,7 @@
2691
2699
  * @private internal helper function
2692
2700
  */
2693
2701
  function createTask(options) {
2694
- const { taskType, taskProcessCallback, tldrProvider } = options;
2702
+ const { taskType, taskProcessCallback } = options;
2695
2703
  let { title } = options;
2696
2704
  // TODO: [🐙] DRY
2697
2705
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2701,6 +2709,7 @@
2701
2709
  const errors = [];
2702
2710
  const warnings = [];
2703
2711
  let currentValue = {};
2712
+ let customTldr = null;
2704
2713
  const partialResultSubject = new rxjs.Subject();
2705
2714
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2706
2715
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
@@ -2711,6 +2720,9 @@
2711
2720
  Object.assign(currentValue, newOngoingResult);
2712
2721
  // <- TODO: assign deep
2713
2722
  partialResultSubject.next(newOngoingResult);
2723
+ }, (tldrInfo) => {
2724
+ customTldr = tldrInfo;
2725
+ updatedAt = new Date();
2714
2726
  });
2715
2727
  finalResultPromise
2716
2728
  .catch((error) => {
@@ -2766,9 +2778,9 @@
2766
2778
  },
2767
2779
  get tldr() {
2768
2780
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2769
- // Use custom tldr provider if available
2770
- if (tldrProvider) {
2771
- return tldrProvider(createdAt, status, currentValue, errors, warnings);
2781
+ // Use custom tldr if available
2782
+ if (customTldr) {
2783
+ return customTldr;
2772
2784
  }
2773
2785
  // Fallback to default implementation
2774
2786
  const cv = currentValue;
@@ -3335,7 +3347,7 @@
3335
3347
  const result = await preparePersonaExecutor({
3336
3348
  availableModels /* <- Note: Passing as JSON */,
3337
3349
  personaDescription,
3338
- }).asPromise();
3350
+ }).asPromise({ isCrashedOnError: true });
3339
3351
  const { outputParameters } = result;
3340
3352
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3341
3353
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -4089,7 +4101,7 @@
4089
4101
  });
4090
4102
  const result = await prepareTitleExecutor({
4091
4103
  book: sources.map(({ content }) => content).join('\n\n'),
4092
- }).asPromise();
4104
+ }).asPromise({ isCrashedOnError: true });
4093
4105
  const { outputParameters } = result;
4094
4106
  const { title: titleRaw } = outputParameters;
4095
4107
  if (isVerbose) {
@@ -6304,80 +6316,74 @@
6304
6316
  });
6305
6317
  });
6306
6318
  };
6307
- const pipelineExecutor = (inputParameters) => createTask({
6308
- taskType: 'EXECUTION',
6309
- title: pipeline.title,
6310
- taskProcessCallback(updateOngoingResult) {
6311
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6312
- updateOngoingResult(newOngoingResult);
6313
- });
6314
- },
6315
- tldrProvider(createdAt, status, currentValue, errors) {
6316
- var _a;
6317
- // Better progress estimation based on pipeline structure
6318
- const cv = currentValue;
6319
- // Handle finished/error states
6320
- if (status === 'FINISHED') {
6321
- return {
6322
- percent: 1,
6323
- message: 'Finished',
6324
- };
6325
- }
6326
- if (status === 'ERROR') {
6327
- const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
6328
- return {
6329
- percent: 0,
6330
- message: errorMessage,
6331
- };
6332
- }
6333
- // Calculate progress based on pipeline tasks
6334
- const totalTasks = pipeline.tasks.length;
6335
- let completedTasks = 0;
6336
- let currentTaskName = '';
6337
- // Check execution report for completed tasks
6338
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6339
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6340
- // Count completed tasks by matching titles
6341
- const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
6342
- completedTasks = completedTasksByTitle.length;
6343
- // Find current task being executed (first task not yet completed)
6344
- const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
6345
- if (remainingTasks.length > 0) {
6346
- currentTaskName = remainingTasks[0].name;
6347
- }
6348
- }
6349
- // Calculate progress percentage
6350
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6351
- // Add time-based progress for current task (assuming 5 minutes total)
6352
- if (completedTasks < totalTasks) {
6353
- const elapsedMs = new Date().getTime() - createdAt.getTime();
6354
- const totalMs = 5 * 60 * 1000; // 5 minutes
6355
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
6356
- // Add partial progress for current task
6357
- percent += (1 / totalTasks) * timeProgress;
6358
- }
6359
- // Clamp to [0,1]
6360
- percent = Math.min(Math.max(percent, 0), 1);
6361
- // Generate message
6362
- let message = '';
6363
- if (currentTaskName) {
6364
- // Find the task to get its title
6365
- const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
6366
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6367
- message = `Working on task ${taskTitle}`;
6368
- }
6369
- else if (completedTasks === 0) {
6370
- message = 'Starting pipeline execution';
6371
- }
6372
- else {
6373
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6374
- }
6375
- return {
6376
- percent,
6377
- message,
6378
- };
6379
- },
6380
- });
6319
+ const pipelineExecutor = (inputParameters) => {
6320
+ const startTime = new Date().getTime();
6321
+ return createTask({
6322
+ taskType: 'EXECUTION',
6323
+ title: pipeline.title,
6324
+ taskProcessCallback(updateOngoingResult, updateTldr) {
6325
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6326
+ var _a, _b;
6327
+ updateOngoingResult(newOngoingResult);
6328
+ // Calculate and update tldr based on pipeline progress
6329
+ const cv = newOngoingResult;
6330
+ // Calculate progress based on parameters resolved vs total parameters
6331
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
6332
+ let resolvedParameters = 0;
6333
+ let currentTaskTitle = '';
6334
+ // Get the resolved parameters from output parameters
6335
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
6336
+ // Count how many output parameters have non-empty values
6337
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
6338
+ }
6339
+ // Try to determine current task from execution report
6340
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
6341
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
6342
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
6343
+ currentTaskTitle = lastExecution.prompt.title;
6344
+ }
6345
+ }
6346
+ // Calculate base progress percentage
6347
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
6348
+ // Add time-based progress for current task if we haven't completed all parameters
6349
+ if (resolvedParameters < totalParameters) {
6350
+ const elapsedMs = new Date().getTime() - startTime;
6351
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
6352
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
6353
+ // If we have time progress but no parameter progress, show time progress
6354
+ if (percent === 0 && timeProgress > 0) {
6355
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
6356
+ }
6357
+ else if (percent < 1) {
6358
+ // Add partial progress for current task
6359
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
6360
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
6361
+ }
6362
+ }
6363
+ // Clamp to [0,1]
6364
+ percent = Math.min(Math.max(percent, 0), 1);
6365
+ // Generate message
6366
+ let message = '';
6367
+ if (currentTaskTitle) {
6368
+ message = `Executing: ${currentTaskTitle}`;
6369
+ }
6370
+ else if (resolvedParameters === 0) {
6371
+ message = 'Starting pipeline execution';
6372
+ }
6373
+ else if (resolvedParameters < totalParameters) {
6374
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
6375
+ }
6376
+ else {
6377
+ message = 'Completing pipeline execution';
6378
+ }
6379
+ updateTldr({
6380
+ percent: percent,
6381
+ message,
6382
+ });
6383
+ });
6384
+ },
6385
+ });
6386
+ };
6381
6387
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6382
6388
  return pipelineExecutor;
6383
6389
  }
@@ -6462,7 +6468,9 @@
6462
6468
  },
6463
6469
  });
6464
6470
  const knowledgeContent = await source.asText();
6465
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6471
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6472
+ isCrashedOnError: true,
6473
+ });
6466
6474
  const { outputParameters } = result;
6467
6475
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6468
6476
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6486,12 +6494,16 @@
6486
6494
  ];
6487
6495
  */
6488
6496
  try {
6489
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6497
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6498
+ isCrashedOnError: true,
6499
+ });
6490
6500
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6491
6501
  title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
6492
6502
  name = titleToName(title);
6493
6503
  // --- Keywords
6494
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6504
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6505
+ isCrashedOnError: true,
6506
+ });
6495
6507
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6496
6508
  keywords = (keywordsRaw || '')
6497
6509
  .split(',')