@promptbook/node 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 +119 -121
  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 +123 -125
  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('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('jszip'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('child_process'), require('dotenv')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'jszip', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'child_process', 'dotenv'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.JSZip, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.child_process, global.dotenv));
5
- })(this, (function (exports, colors, promises, path, spaceTrim, JSZip, prettier, parserHtml, crypto, rxjs, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, child_process, dotenv) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('jszip'), require('prettier/parser-html'), require('prettier/parser-markdown'), require('prettier/standalone'), require('crypto'), require('rxjs'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('child_process'), require('dotenv')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'jszip', 'prettier/parser-html', 'prettier/parser-markdown', 'prettier/standalone', 'crypto', 'rxjs', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'child_process', 'dotenv'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.JSZip, global.parserHtml, global.parserMarkdown, global.standalone, global.crypto, global.rxjs, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.child_process, global.dotenv));
5
+ })(this, (function (exports, colors, promises, path, spaceTrim, JSZip, parserHtml, parserMarkdown, standalone, crypto, rxjs, waitasecond, papaparse, hexEncoder, sha256, cryptoJs, mimeTypes, child_process, dotenv) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -28,6 +28,7 @@
28
28
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
29
29
  var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
30
30
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
31
+ var parserMarkdown__default = /*#__PURE__*/_interopDefaultLegacy(parserMarkdown);
31
32
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
32
33
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
33
34
  var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
@@ -46,7 +47,7 @@
46
47
  * @generated
47
48
  * @see https://github.com/webgptorg/promptbook
48
49
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-44';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-46';
50
51
  /**
51
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
53
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -254,6 +255,13 @@
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
  *
@@ -1301,9 +1309,9 @@
1301
1309
  */
1302
1310
  function prettifyMarkdown(content) {
1303
1311
  try {
1304
- return prettier.format(content, {
1312
+ return standalone.format(content, {
1305
1313
  parser: 'markdown',
1306
- plugins: [parserHtml__default["default"]],
1314
+ plugins: [parserMarkdown__default["default"], parserHtml__default["default"]],
1307
1315
  // TODO: DRY - make some import or auto-copy of .prettierrc
1308
1316
  endOfLine: 'lf',
1309
1317
  tabWidth: 4,
@@ -2104,7 +2112,7 @@
2104
2112
  * @private internal helper function
2105
2113
  */
2106
2114
  function createTask(options) {
2107
- const { taskType, taskProcessCallback, tldrProvider } = options;
2115
+ const { taskType, taskProcessCallback } = options;
2108
2116
  let { title } = options;
2109
2117
  // TODO: [🐙] DRY
2110
2118
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
@@ -2114,6 +2122,7 @@
2114
2122
  const errors = [];
2115
2123
  const warnings = [];
2116
2124
  let currentValue = {};
2125
+ let customTldr = null;
2117
2126
  const partialResultSubject = new rxjs.Subject();
2118
2127
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2119
2128
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
@@ -2124,6 +2133,9 @@
2124
2133
  Object.assign(currentValue, newOngoingResult);
2125
2134
  // <- TODO: assign deep
2126
2135
  partialResultSubject.next(newOngoingResult);
2136
+ }, (tldrInfo) => {
2137
+ customTldr = tldrInfo;
2138
+ updatedAt = new Date();
2127
2139
  });
2128
2140
  finalResultPromise
2129
2141
  .catch((error) => {
@@ -2179,9 +2191,9 @@
2179
2191
  },
2180
2192
  get tldr() {
2181
2193
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2182
- // Use custom tldr provider if available
2183
- if (tldrProvider) {
2184
- return tldrProvider(createdAt, status, currentValue, errors, warnings);
2194
+ // Use custom tldr if available
2195
+ if (customTldr) {
2196
+ return customTldr;
2185
2197
  }
2186
2198
  // Fallback to default implementation
2187
2199
  const cv = currentValue;
@@ -5023,80 +5035,74 @@
5023
5035
  });
5024
5036
  });
5025
5037
  };
5026
- const pipelineExecutor = (inputParameters) => createTask({
5027
- taskType: 'EXECUTION',
5028
- title: pipeline.title,
5029
- taskProcessCallback(updateOngoingResult) {
5030
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5031
- updateOngoingResult(newOngoingResult);
5032
- });
5033
- },
5034
- tldrProvider(createdAt, status, currentValue, errors) {
5035
- var _a;
5036
- // Better progress estimation based on pipeline structure
5037
- const cv = currentValue;
5038
- // Handle finished/error states
5039
- if (status === 'FINISHED') {
5040
- return {
5041
- percent: 1,
5042
- message: 'Finished',
5043
- };
5044
- }
5045
- if (status === 'ERROR') {
5046
- const errorMessage = errors.length > 0 ? errors[errors.length - 1].message : 'Error';
5047
- return {
5048
- percent: 0,
5049
- message: errorMessage,
5050
- };
5051
- }
5052
- // Calculate progress based on pipeline tasks
5053
- const totalTasks = pipeline.tasks.length;
5054
- let completedTasks = 0;
5055
- let currentTaskName = '';
5056
- // Check execution report for completed tasks
5057
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
5058
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
5059
- // Count completed tasks by matching titles
5060
- const completedTasksByTitle = pipeline.tasks.filter(task => executedTaskTitles.has(task.title));
5061
- completedTasks = completedTasksByTitle.length;
5062
- // Find current task being executed (first task not yet completed)
5063
- const remainingTasks = pipeline.tasks.filter(task => !executedTaskTitles.has(task.title));
5064
- if (remainingTasks.length > 0) {
5065
- currentTaskName = remainingTasks[0].name;
5066
- }
5067
- }
5068
- // Calculate progress percentage
5069
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
5070
- // Add time-based progress for current task (assuming 5 minutes total)
5071
- if (completedTasks < totalTasks) {
5072
- const elapsedMs = new Date().getTime() - createdAt.getTime();
5073
- const totalMs = 5 * 60 * 1000; // 5 minutes
5074
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
5075
- // Add partial progress for current task
5076
- percent += (1 / totalTasks) * timeProgress;
5077
- }
5078
- // Clamp to [0,1]
5079
- percent = Math.min(Math.max(percent, 0), 1);
5080
- // Generate message
5081
- let message = '';
5082
- if (currentTaskName) {
5083
- // Find the task to get its title
5084
- const currentTask = pipeline.tasks.find(task => task.name === currentTaskName);
5085
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
5086
- message = `Working on task ${taskTitle}`;
5087
- }
5088
- else if (completedTasks === 0) {
5089
- message = 'Starting pipeline execution';
5090
- }
5091
- else {
5092
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
5093
- }
5094
- return {
5095
- percent,
5096
- message,
5097
- };
5098
- },
5099
- });
5038
+ const pipelineExecutor = (inputParameters) => {
5039
+ const startTime = new Date().getTime();
5040
+ return createTask({
5041
+ taskType: 'EXECUTION',
5042
+ title: pipeline.title,
5043
+ taskProcessCallback(updateOngoingResult, updateTldr) {
5044
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5045
+ var _a, _b;
5046
+ updateOngoingResult(newOngoingResult);
5047
+ // Calculate and update tldr based on pipeline progress
5048
+ const cv = newOngoingResult;
5049
+ // Calculate progress based on parameters resolved vs total parameters
5050
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
5051
+ let resolvedParameters = 0;
5052
+ let currentTaskTitle = '';
5053
+ // Get the resolved parameters from output parameters
5054
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
5055
+ // Count how many output parameters have non-empty values
5056
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
5057
+ }
5058
+ // Try to determine current task from execution report
5059
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
5060
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
5061
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
5062
+ currentTaskTitle = lastExecution.prompt.title;
5063
+ }
5064
+ }
5065
+ // Calculate base progress percentage
5066
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
5067
+ // Add time-based progress for current task if we haven't completed all parameters
5068
+ if (resolvedParameters < totalParameters) {
5069
+ const elapsedMs = new Date().getTime() - startTime;
5070
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
5071
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
5072
+ // If we have time progress but no parameter progress, show time progress
5073
+ if (percent === 0 && timeProgress > 0) {
5074
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
5075
+ }
5076
+ else if (percent < 1) {
5077
+ // Add partial progress for current task
5078
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
5079
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
5080
+ }
5081
+ }
5082
+ // Clamp to [0,1]
5083
+ percent = Math.min(Math.max(percent, 0), 1);
5084
+ // Generate message
5085
+ let message = '';
5086
+ if (currentTaskTitle) {
5087
+ message = `Executing: ${currentTaskTitle}`;
5088
+ }
5089
+ else if (resolvedParameters === 0) {
5090
+ message = 'Starting pipeline execution';
5091
+ }
5092
+ else if (resolvedParameters < totalParameters) {
5093
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
5094
+ }
5095
+ else {
5096
+ message = 'Completing pipeline execution';
5097
+ }
5098
+ updateTldr({
5099
+ percent: percent,
5100
+ message,
5101
+ });
5102
+ });
5103
+ },
5104
+ });
5105
+ };
5100
5106
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
5101
5107
  return pipelineExecutor;
5102
5108
  }
@@ -5232,7 +5238,7 @@
5232
5238
  const result = await preparePersonaExecutor({
5233
5239
  availableModels /* <- Note: Passing as JSON */,
5234
5240
  personaDescription,
5235
- }).asPromise();
5241
+ }).asPromise({ isCrashedOnError: true });
5236
5242
  const { outputParameters } = result;
5237
5243
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
5238
5244
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -6122,7 +6128,7 @@
6122
6128
  });
6123
6129
  const result = await prepareTitleExecutor({
6124
6130
  book: sources.map(({ content }) => content).join('\n\n'),
6125
- }).asPromise();
6131
+ }).asPromise({ isCrashedOnError: true });
6126
6132
  const { outputParameters } = result;
6127
6133
  const { title: titleRaw } = outputParameters;
6128
6134
  if (isVerbose) {
@@ -10830,31 +10836,23 @@
10830
10836
  return content;
10831
10837
  }
10832
10838
 
10839
+ /**
10840
+ * @private internal for `preserve`
10841
+ */
10842
+ const _preserved = [];
10833
10843
  /**
10834
10844
  * Does nothing, but preserves the function in the bundle
10835
10845
  * Compiler is tricked into thinking the function is used
10836
10846
  *
10837
10847
  * @param value any function to preserve
10838
10848
  * @returns nothing
10839
- * @private internal function of `JavascriptExecutionTools` and `JavascriptEvalExecutionTools`
10840
- */
10841
- function preserve(func) {
10842
- // Note: NOT calling the function
10843
- (async () => {
10844
- // TODO: [💩] Change to `await forEver` or `forTime(Infinity)`
10845
- await waitasecond.forTime(100000000);
10846
- // [1]
10847
- try {
10848
- await func();
10849
- }
10850
- finally {
10851
- // do nothing
10852
- }
10853
- })();
10849
+ * @private within the repository
10850
+ */
10851
+ function $preserve(...value) {
10852
+ _preserved.push(...value);
10854
10853
  }
10855
10854
  /**
10856
- * TODO: Probably remove in favour of `keepImported`
10857
- * TODO: [1] This maybe does memory leak
10855
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10858
10856
  */
10859
10857
 
10860
10858
  // Note: [💎]
@@ -10882,25 +10880,25 @@
10882
10880
  // Note: [💎]
10883
10881
  // Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
10884
10882
  const spaceTrim = (_) => spaceTrim__default["default"](_);
10885
- preserve(spaceTrim);
10883
+ $preserve(spaceTrim);
10886
10884
  const removeQuotes$1 = removeQuotes;
10887
- preserve(removeQuotes$1);
10885
+ $preserve(removeQuotes$1);
10888
10886
  const unwrapResult$1 = unwrapResult;
10889
- preserve(unwrapResult$1);
10887
+ $preserve(unwrapResult$1);
10890
10888
  const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
10891
- preserve(trimEndOfCodeBlock$1);
10889
+ $preserve(trimEndOfCodeBlock$1);
10892
10890
  const trimCodeBlock$1 = trimCodeBlock;
10893
- preserve(trimCodeBlock$1);
10891
+ $preserve(trimCodeBlock$1);
10894
10892
  // TODO: DRY [🍯]
10895
10893
  const trim = (str) => str.trim();
10896
- preserve(trim);
10894
+ $preserve(trim);
10897
10895
  // TODO: DRY [🍯]
10898
10896
  const reverse = (str) => str.split('').reverse().join('');
10899
- preserve(reverse);
10897
+ $preserve(reverse);
10900
10898
  const removeEmojis$1 = removeEmojis;
10901
- preserve(removeEmojis$1);
10899
+ $preserve(removeEmojis$1);
10902
10900
  const prettifyMarkdown$1 = prettifyMarkdown;
10903
- preserve(prettifyMarkdown$1);
10901
+ $preserve(prettifyMarkdown$1);
10904
10902
  //-------[n12:]---
10905
10903
  const capitalize$1 = capitalize;
10906
10904
  const decapitalize$1 = decapitalize;
@@ -10916,18 +10914,18 @@
10916
10914
  // TODO: DRY [🍯]
10917
10915
  Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
10918
10916
  const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
10919
- preserve(capitalize$1);
10920
- preserve(decapitalize$1);
10921
- preserve(nameToUriPart$1);
10922
- preserve(nameToUriParts$1);
10923
- preserve(removeDiacritics$1);
10924
- preserve(normalizeWhitespaces$1);
10925
- preserve(normalizeToKebabCase$1);
10926
- preserve(normalizeTo_camelCase$1);
10927
- preserve(normalizeTo_snake_case$1);
10928
- preserve(normalizeTo_PascalCase$1);
10929
- preserve(parseKeywords);
10930
- preserve(normalizeTo_SCREAMING_CASE$1);
10917
+ $preserve(capitalize$1);
10918
+ $preserve(decapitalize$1);
10919
+ $preserve(nameToUriPart$1);
10920
+ $preserve(nameToUriParts$1);
10921
+ $preserve(removeDiacritics$1);
10922
+ $preserve(normalizeWhitespaces$1);
10923
+ $preserve(normalizeToKebabCase$1);
10924
+ $preserve(normalizeTo_camelCase$1);
10925
+ $preserve(normalizeTo_snake_case$1);
10926
+ $preserve(normalizeTo_PascalCase$1);
10927
+ $preserve(parseKeywords);
10928
+ $preserve(normalizeTo_SCREAMING_CASE$1);
10931
10929
  //-------[/n12]---
10932
10930
  if (!script.includes('return')) {
10933
10931
  script = `return ${script}`;