@promptbook/documents 0.100.0-45 → 0.100.0-47

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 (24) hide show
  1. package/esm/index.es.js +88 -64
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -6
  6. package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +1 -1
  7. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +4 -10
  8. package/esm/typings/src/book-components/Chat/interfaces/ChatMessage.d.ts +12 -26
  9. package/esm/typings/src/book-components/Chat/interfaces/ChatParticipant.d.ts +30 -0
  10. package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +2 -4
  11. package/esm/typings/src/book-components/Chat/utils/generatePdfContent.d.ts +2 -4
  12. package/esm/typings/src/book-components/Chat/utils/messagesToHtml.d.ts +2 -4
  13. package/esm/typings/src/book-components/Chat/utils/messagesToMarkdown.d.ts +2 -4
  14. package/esm/typings/src/book-components/Chat/utils/messagesToText.d.ts +2 -4
  15. package/esm/typings/src/config.d.ts +7 -0
  16. package/esm/typings/src/execution/ExecutionTask.d.ts +8 -0
  17. package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +8 -0
  18. package/esm/typings/src/playground/permanent/error-handling-playground.d.ts +5 -0
  19. package/esm/typings/src/utils/organization/preserve.d.ts +21 -0
  20. package/esm/typings/src/version.d.ts +1 -1
  21. package/package.json +2 -3
  22. package/umd/index.umd.js +92 -68
  23. package/umd/index.umd.js.map +1 -1
  24. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +0 -14
package/esm/index.es.js CHANGED
@@ -6,8 +6,9 @@ import { forTime } from 'waitasecond';
6
6
  import { SHA256 } from 'crypto-js';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
8
8
  import { basename, join, dirname } from 'path';
9
- import { format } from 'prettier';
10
9
  import parserHtml from 'prettier/parser-html';
10
+ import parserMarkdown from 'prettier/parser-markdown';
11
+ import { format } from 'prettier/standalone';
11
12
  import { randomBytes } from 'crypto';
12
13
  import { Subject } from 'rxjs';
13
14
  import sha256 from 'crypto-js/sha256';
@@ -28,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
29
  * @generated
29
30
  * @see https://github.com/webgptorg/promptbook
30
31
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-45';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-47';
32
33
  /**
33
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -226,6 +227,13 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
226
227
  * @public exported from `@promptbook/core`
227
228
  */
228
229
  const DEFAULT_TASK_SIMULATED_DURATION_MS = 5 * 60 * 1000; // 5 minutes
230
+ /**
231
+ * API request timeout in milliseconds
232
+ * Can be overridden via API_REQUEST_TIMEOUT environment variable
233
+ *
234
+ * @public exported from `@promptbook/core`
235
+ */
236
+ parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
229
237
  /**
230
238
  * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
231
239
  *
@@ -1219,7 +1227,7 @@ function prettifyMarkdown(content) {
1219
1227
  try {
1220
1228
  return format(content, {
1221
1229
  parser: 'markdown',
1222
- plugins: [parserHtml],
1230
+ plugins: [parserMarkdown, parserHtml],
1223
1231
  // TODO: DRY - make some import or auto-copy of .prettierrc
1224
1232
  endOfLine: 'lf',
1225
1233
  tabWidth: 4,
@@ -3341,7 +3349,7 @@ async function preparePersona(personaDescription, tools, options) {
3341
3349
  const result = await preparePersonaExecutor({
3342
3350
  availableModels /* <- Note: Passing as JSON */,
3343
3351
  personaDescription,
3344
- }).asPromise();
3352
+ }).asPromise({ isCrashedOnError: true });
3345
3353
  const { outputParameters } = result;
3346
3354
  const { modelsRequirements: modelsRequirementsJson } = outputParameters;
3347
3355
  let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
@@ -4095,7 +4103,7 @@ async function preparePipeline(pipeline, tools, options) {
4095
4103
  });
4096
4104
  const result = await prepareTitleExecutor({
4097
4105
  book: sources.map(({ content }) => content).join('\n\n'),
4098
- }).asPromise();
4106
+ }).asPromise({ isCrashedOnError: true });
4099
4107
  const { outputParameters } = result;
4100
4108
  const { title: titleRaw } = outputParameters;
4101
4109
  if (isVerbose) {
@@ -6310,64 +6318,74 @@ function createPipelineExecutor(options) {
6310
6318
  });
6311
6319
  });
6312
6320
  };
6313
- const pipelineExecutor = (inputParameters) => createTask({
6314
- taskType: 'EXECUTION',
6315
- title: pipeline.title,
6316
- taskProcessCallback(updateOngoingResult, updateTldr) {
6317
- return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6318
- var _a;
6319
- updateOngoingResult(newOngoingResult);
6320
- // Calculate and update tldr based on pipeline progress
6321
- const cv = newOngoingResult;
6322
- // Calculate progress based on pipeline tasks
6323
- const totalTasks = pipeline.tasks.length;
6324
- let completedTasks = 0;
6325
- let currentTaskName = '';
6326
- // Check execution report for completed tasks
6327
- if ((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) {
6328
- const executedTaskTitles = new Set(cv.executionReport.promptExecutions.map((execution) => execution.prompt.title));
6329
- // Count completed tasks by matching titles
6330
- const completedTasksByTitle = pipeline.tasks.filter((task) => executedTaskTitles.has(task.title));
6331
- completedTasks = completedTasksByTitle.length;
6332
- // Find current task being executed (first task not yet completed)
6333
- const remainingTasks = pipeline.tasks.filter((task) => !executedTaskTitles.has(task.title));
6334
- if (remainingTasks.length > 0) {
6335
- currentTaskName = remainingTasks[0].name;
6321
+ const pipelineExecutor = (inputParameters) => {
6322
+ const startTime = new Date().getTime();
6323
+ return createTask({
6324
+ taskType: 'EXECUTION',
6325
+ title: pipeline.title,
6326
+ taskProcessCallback(updateOngoingResult, updateTldr) {
6327
+ return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
6328
+ var _a, _b;
6329
+ updateOngoingResult(newOngoingResult);
6330
+ // Calculate and update tldr based on pipeline progress
6331
+ const cv = newOngoingResult;
6332
+ // Calculate progress based on parameters resolved vs total parameters
6333
+ const totalParameters = pipeline.parameters.filter(p => !p.isInput).length;
6334
+ let resolvedParameters = 0;
6335
+ let currentTaskTitle = '';
6336
+ // Get the resolved parameters from output parameters
6337
+ if (cv === null || cv === void 0 ? void 0 : cv.outputParameters) {
6338
+ // Count how many output parameters have non-empty values
6339
+ resolvedParameters = Object.values(cv.outputParameters).filter(value => value !== undefined && value !== null && String(value).trim() !== '').length;
6336
6340
  }
6337
- }
6338
- // Calculate progress percentage
6339
- let percent = totalTasks > 0 ? completedTasks / totalTasks : 0;
6340
- // Add time-based progress for current task (assuming 5 minutes total)
6341
- if (completedTasks < totalTasks) {
6342
- const elapsedMs = new Date().getTime() - new Date().getTime(); // Will be overridden by actual elapsed time in task
6343
- const totalMs = 5 * 60 * 1000; // 5 minutes
6344
- const timeProgress = Math.min(elapsedMs / totalMs, 1);
6345
- // Add partial progress for current task
6346
- percent += (1 / totalTasks) * timeProgress;
6347
- }
6348
- // Clamp to [0,1]
6349
- percent = Math.min(Math.max(percent, 0), 1);
6350
- // Generate message
6351
- let message = '';
6352
- if (currentTaskName) {
6353
- // Find the task to get its title
6354
- const currentTask = pipeline.tasks.find((task) => task.name === currentTaskName);
6355
- const taskTitle = (currentTask === null || currentTask === void 0 ? void 0 : currentTask.title) || currentTaskName;
6356
- message = `Working on task ${taskTitle}`;
6357
- }
6358
- else if (completedTasks === 0) {
6359
- message = 'Starting pipeline execution';
6360
- }
6361
- else {
6362
- message = `Processing pipeline (${completedTasks}/${totalTasks} tasks completed)`;
6363
- }
6364
- updateTldr({
6365
- percent: percent,
6366
- message,
6341
+ // Try to determine current task from execution report
6342
+ if (((_a = cv === null || cv === void 0 ? void 0 : cv.executionReport) === null || _a === void 0 ? void 0 : _a.promptExecutions) && cv.executionReport.promptExecutions.length > 0) {
6343
+ const lastExecution = cv.executionReport.promptExecutions[cv.executionReport.promptExecutions.length - 1];
6344
+ if ((_b = lastExecution === null || lastExecution === void 0 ? void 0 : lastExecution.prompt) === null || _b === void 0 ? void 0 : _b.title) {
6345
+ currentTaskTitle = lastExecution.prompt.title;
6346
+ }
6347
+ }
6348
+ // Calculate base progress percentage
6349
+ let percent = totalParameters > 0 ? resolvedParameters / totalParameters : 0;
6350
+ // Add time-based progress for current task if we haven't completed all parameters
6351
+ if (resolvedParameters < totalParameters) {
6352
+ const elapsedMs = new Date().getTime() - startTime;
6353
+ const estimatedTotalMs = totalParameters * 30 * 1000; // Estimate 30 seconds per parameter
6354
+ const timeProgress = Math.min(elapsedMs / estimatedTotalMs, 0.9); // Cap at 90% for time-based progress
6355
+ // If we have time progress but no parameter progress, show time progress
6356
+ if (percent === 0 && timeProgress > 0) {
6357
+ percent = Math.min(timeProgress, 0.1); // Show some progress but not more than 10%
6358
+ }
6359
+ else if (percent < 1) {
6360
+ // Add partial progress for current task
6361
+ const taskProgress = totalParameters > 0 ? (1 / totalParameters) * 0.5 : 0; // 50% of task progress
6362
+ percent = Math.min(percent + taskProgress, 0.95); // Cap at 95% until fully complete
6363
+ }
6364
+ }
6365
+ // Clamp to [0,1]
6366
+ percent = Math.min(Math.max(percent, 0), 1);
6367
+ // Generate message
6368
+ let message = '';
6369
+ if (currentTaskTitle) {
6370
+ message = `Executing: ${currentTaskTitle}`;
6371
+ }
6372
+ else if (resolvedParameters === 0) {
6373
+ message = 'Starting pipeline execution';
6374
+ }
6375
+ else if (resolvedParameters < totalParameters) {
6376
+ message = `Processing pipeline (${resolvedParameters}/${totalParameters} parameters resolved)`;
6377
+ }
6378
+ else {
6379
+ message = 'Completing pipeline execution';
6380
+ }
6381
+ updateTldr({
6382
+ percent: percent,
6383
+ message,
6384
+ });
6367
6385
  });
6368
- });
6369
- },
6370
- });
6386
+ },
6387
+ });
6388
+ };
6371
6389
  // <- TODO: Make types such as there is no need to do `as` for `createTask`
6372
6390
  return pipelineExecutor;
6373
6391
  }
@@ -6452,7 +6470,9 @@ class MarkdownScraper {
6452
6470
  },
6453
6471
  });
6454
6472
  const knowledgeContent = await source.asText();
6455
- const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise();
6473
+ const result = await prepareKnowledgeFromMarkdownExecutor({ knowledgeContent }).asPromise({
6474
+ isCrashedOnError: true,
6475
+ });
6456
6476
  const { outputParameters } = result;
6457
6477
  const { knowledgePieces: knowledgePiecesRaw } = outputParameters;
6458
6478
  const knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
@@ -6476,12 +6496,16 @@ class MarkdownScraper {
6476
6496
  ];
6477
6497
  */
6478
6498
  try {
6479
- const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise();
6499
+ const titleResult = await prepareTitleExecutor({ knowledgePieceContent }).asPromise({
6500
+ isCrashedOnError: true,
6501
+ });
6480
6502
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
6481
6503
  title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
6482
6504
  name = titleToName(title);
6483
6505
  // --- Keywords
6484
- const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise();
6506
+ const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({
6507
+ isCrashedOnError: true,
6508
+ });
6485
6509
  const { keywords: keywordsRaw = '' } = keywordsResult.outputParameters;
6486
6510
  keywords = (keywordsRaw || '')
6487
6511
  .split(',')