@promptbook/markdown-utils 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 +1 -2
  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,13 +1,14 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, crypto, rxjs, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier/parser-html'), require('prettier/parser-markdown'), require('prettier/standalone'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier/parser-html', 'prettier/parser-markdown', 'prettier/standalone', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.parserHtml, global.parserMarkdown, global.standalone, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, spaceTrim, parserHtml, parserMarkdown, standalone, crypto, rxjs, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
10
10
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
11
+ var parserMarkdown__default = /*#__PURE__*/_interopDefaultLegacy(parserMarkdown);
11
12
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
12
13
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
13
14
 
@@ -25,7 +26,7 @@
25
26
  * @generated
26
27
  * @see https://github.com/webgptorg/promptbook
27
28
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-44';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
29
30
  /**
30
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -353,6 +354,13 @@
353
354
  * @public exported from `@promptbook/core`
354
355
  */
355
356
  const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
357
+ /**
358
+ * API request timeout in milliseconds
359
+ * Can be overridden via API_REQUEST_TIMEOUT environment variable
360
+ *
361
+ * @public exported from `@promptbook/core`
362
+ */
363
+ parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
356
364
  /**
357
365
  * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
358
366
  *
@@ -691,9 +699,9 @@
691
699
  */
692
700
  function prettifyMarkdown(content) {
693
701
  try {
694
- return prettier.format(content, {
702
+ return standalone.format(content, {
695
703
  parser: 'markdown',
696
- plugins: [parserHtml__default["default"]],
704
+ plugins: [parserMarkdown__default["default"], parserHtml__default["default"]],
697
705
  // TODO: DRY - make some import or auto-copy of .prettierrc
698
706
  endOfLine: 'lf',
699
707
  tabWidth: 4,
@@ -2202,7 +2210,7 @@
2202
2210
  * @private internal helper function
2203
2211
  */
2204
2212
  function createTask(options) {
2205
- const { taskType, taskProcessCallback, tldrProvider } = options;
2213
+ const { taskType, taskProcessCallback } = options;
2206
2214
  let { title } = options;
2207
2215
  // TODO: [🐙] DRY
2208
2216
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2212,6 +2220,7 @@
2212
2220
  const errors = [];
2213
2221
  const warnings = [];
2214
2222
  let currentValue = {};
2223
+ let customTldr = null;
2215
2224
  const partialResultSubject = new rxjs.Subject();
2216
2225
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2217
2226
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
@@ -2222,6 +2231,9 @@
2222
2231
  Object.assign(currentValue, newOngoingResult);
2223
2232
  // <- TODO: assign deep
2224
2233
  partialResultSubject.next(newOngoingResult);
2234
+ }, (tldrInfo) => {
2235
+ customTldr = tldrInfo;
2236
+ updatedAt = new Date();
2225
2237
  });
2226
2238
  finalResultPromise
2227
2239
  .catch((error) => {
@@ -2277,9 +2289,9 @@
2277
2289
  },
2278
2290
  get tldr() {
2279
2291
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2280
- // Use custom tldr provider if available
2281
- if (tldrProvider) {
2282
- return tldrProvider(createdAt, status, currentValue, errors, warnings);
2292
+ // Use custom tldr if available
2293
+ if (customTldr) {
2294
+ return customTldr;
2283
2295
  }
2284
2296
  // Fallback to default implementation
2285
2297
  const cv = currentValue;
@@ -2846,7 +2858,7 @@
2846
2858
  const result = await preparePersonaExecutor({
2847
2859
  availableModels /* <- Note: Passing as JSON */,
2848
2860
  personaDescription,
2849
- }).asPromise();
2861
+ }).asPromise({ isCrashedOnError: true });
2850
2862
  const { outputParameters } = result;
2851
2863
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
2852
2864
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -3997,7 +4009,7 @@
3997
4009
  });
3998
4010
  const result = await prepareTitleExecutor({
3999
4011
  book: sources.map(({ content }) => content).join('\n\n'),
4000
- }).asPromise();
4012
+ }).asPromise({ isCrashedOnError: true });
4001
4013
  const { outputParameters } = result;
4002
4014
  const { title: titleRaw } = outputParameters;
4003
4015
  if (isVerbose) {
@@ -6110,80 +6122,74 @@
6110
6122
  });
6111
6123
  });
6112
6124
  };
6113
- const pipelineExecutor = (inputParameters) => createTask({
6114
- taskType: 'EXECUTION',
6115
- title: pipeline.title,
6116
- taskProcessCallback(updateOngoingResult) {
6117
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6118
- updateOngoingResult(newOngoingResult);
6119
- });
6120
- },
6121
- tldrProvider(createdAt, status, currentValue, errors) {
6122
- var _a;
6123
- // Better progress estimation based on pipeline structure
6124
- const cv = currentValue;
6125
- // Handle finished/error states
6126
- if (status === 'FINISHED') {
6127
- return {
6128
- percent: 1,
6129
- message: 'Finished',
6130
- };
6131
- }
6132
- if (status === 'ERROR') {
6133
- const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
6134
- return {
6135
- percent: 0,
6136
- message: errorMessage,
6137
- };
6138
- }
6139
- // Calculate progress based on pipeline tasks
6140
- const totalTasks = pipeline.tasks.length;
6141
- let completedTasks = 0;
6142
- let currentTaskName = '';
6143
- // Check execution report for completed tasks
6144
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6145
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6146
- // Count completed tasks by matching titles
6147
- const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
6148
- completedTasks = completedTasksByTitle.length;
6149
- // Find current task being executed (first task not yet completed)
6150
- const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
6151
- if (remainingTasks.length > 0) {
6152
- currentTaskName = remainingTasks[0].name;
6153
- }
6154
- }
6155
- // Calculate progress percentage
6156
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6157
- // Add time-based progress for current task (assuming 5 minutes total)
6158
- if (completedTasks < totalTasks) {
6159
- const elapsedMs = new Date().getTime() - createdAt.getTime();
6160
- const totalMs = 5 * 60 * 1000; // 5 minutes
6161
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
6162
- // Add partial progress for current task
6163
- percent += (1 / totalTasks) * timeProgress;
6164
- }
6165
- // Clamp to [0,1]
6166
- percent = Math.min(Math.max(percent, 0), 1);
6167
- // Generate message
6168
- let message = '';
6169
- if (currentTaskName) {
6170
- // Find the task to get its title
6171
- const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
6172
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6173
- message = `Working on task ${taskTitle}`;
6174
- }
6175
- else if (completedTasks === 0) {
6176
- message = 'Starting pipeline execution';
6177
- }
6178
- else {
6179
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6180
- }
6181
- return {
6182
- percent,
6183
- message,
6184
- };
6185
- },
6186
- });
6125
+ const pipelineExecutor = (inputParameters) => {
6126
+ const startTime = new Date().getTime();
6127
+ return createTask({
6128
+ taskType: 'EXECUTION',
6129
+ title: pipeline.title,
6130
+ taskProcessCallback(updateOngoingResult, updateTldr) {
6131
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6132
+ var _a, _b;
6133
+ updateOngoingResult(newOngoingResult);
6134
+ // Calculate and update tldr based on pipeline progress
6135
+ const cv = newOngoingResult;
6136
+ // Calculate progress based on parameters resolved vs total parameters
6137
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
6138
+ let resolvedParameters = 0;
6139
+ let currentTaskTitle = '';
6140
+ // Get the resolved parameters from output parameters
6141
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
6142
+ // Count how many output parameters have non-empty values
6143
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
6144
+ }
6145
+ // Try to determine current task from execution report
6146
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
6147
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
6148
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
6149
+ currentTaskTitle = lastExecution.prompt.title;
6150
+ }
6151
+ }
6152
+ // Calculate base progress percentage
6153
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
6154
+ // Add time-based progress for current task if we haven't completed all parameters
6155
+ if (resolvedParameters < totalParameters) {
6156
+ const elapsedMs = new Date().getTime() - startTime;
6157
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
6158
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
6159
+ // If we have time progress but no parameter progress, show time progress
6160
+ if (percent === 0 && timeProgress > 0) {
6161
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
6162
+ }
6163
+ else if (percent < 1) {
6164
+ // Add partial progress for current task
6165
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
6166
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
6167
+ }
6168
+ }
6169
+ // Clamp to [0,1]
6170
+ percent = Math.min(Math.max(percent, 0), 1);
6171
+ // Generate message
6172
+ let message = '';
6173
+ if (currentTaskTitle) {
6174
+ message = `Executing: ${currentTaskTitle}`;
6175
+ }
6176
+ else if (resolvedParameters === 0) {
6177
+ message = 'Starting pipeline execution';
6178
+ }
6179
+ else if (resolvedParameters < totalParameters) {
6180
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
6181
+ }
6182
+ else {
6183
+ message = 'Completing pipeline execution';
6184
+ }
6185
+ updateTldr({
6186
+ percent: percent,
6187
+ message,
6188
+ });
6189
+ });
6190
+ },
6191
+ });
6192
+ };
6187
6193
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6188
6194
  return pipelineExecutor;
6189
6195
  }
@@ -6268,7 +6274,9 @@
6268
6274
  },
6269
6275
  });
6270
6276
  const knowledgeContent = await source.asText();
6271
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6277
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6278
+ isCrashedOnError: true,
6279
+ });
6272
6280
  const { outputParameters } = result;
6273
6281
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6274
6282
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6292,12 +6300,16 @@
6292
6300
  ];
6293
6301
  */
6294
6302
  try {
6295
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6303
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6304
+ isCrashedOnError: true,
6305
+ });
6296
6306
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6297
6307
  title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
6298
6308
  name = titleToName(title);
6299
6309
  // --- Keywords
6300
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6310
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6311
+ isCrashedOnError: true,
6312
+ });
6301
6313
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6302
6314
  keywords = (keywordsRaw || '')
6303
6315
  .split(',')