@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.
- package/esm/index.es.js +98 -86
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +14 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +8 -0
- package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +1 -1
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfile.d.ts +26 -0
- package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/AvatarProfileFromSource.d.ts +19 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +15 -0
- package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +128 -0
- package/esm/typings/src/book-components/Chat/interfaces/ChatMessage.d.ts +16 -0
- package/esm/typings/src/book-components/Chat/interfaces/ChatParticipant.d.ts +12 -0
- package/esm/typings/src/book-components/Chat/utils/ExportFormat.d.ts +4 -0
- package/esm/typings/src/book-components/Chat/utils/addUtmParamsToUrl.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/createShortLinkForChat.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/downloadFile.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +11 -0
- package/esm/typings/src/book-components/Chat/utils/generatePdfContent.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/generateQrDataUrl.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/getPromptbookBranding.d.ts +6 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToHtml.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToJson.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToMarkdown.d.ts +10 -0
- package/esm/typings/src/book-components/Chat/utils/messagesToText.d.ts +10 -0
- package/esm/typings/src/config.d.ts +13 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +12 -13
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +8 -0
- package/esm/typings/src/playground/permanent/error-handling-playground.d.ts +5 -0
- package/esm/typings/src/utils/organization/preserve.d.ts +21 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -2
- package/umd/index.umd.js +102 -90
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +0 -14
package/esm/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
|
-
import { format } from 'prettier';
|
|
3
2
|
import parserHtml from 'prettier/parser-html';
|
|
3
|
+
import parserMarkdown from 'prettier/parser-markdown';
|
|
4
|
+
import { format } from 'prettier/standalone';
|
|
4
5
|
import { randomBytes } from 'crypto';
|
|
5
6
|
import { Subject } from 'rxjs';
|
|
6
7
|
import { forTime } from 'waitasecond';
|
|
@@ -25,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
26
|
* @generated
|
|
26
27
|
* @see https://github.com/webgptorg/promptbook
|
|
27
28
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
|
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 @@ const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
|
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
|
*
|
|
@@ -693,7 +701,7 @@ function prettifyMarkdown(content) {
|
|
|
693
701
|
try {
|
|
694
702
|
return format(content, {
|
|
695
703
|
parser: 'markdown',
|
|
696
|
-
plugins: [parserHtml],
|
|
704
|
+
plugins: [parserMarkdown, parserHtml],
|
|
697
705
|
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
698
706
|
endOfLine: 'lf',
|
|
699
707
|
tabWidth: 4,
|
|
@@ -2202,7 +2210,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2202
2210
|
* @private internal helper function
|
|
2203
2211
|
*/
|
|
2204
2212
|
function createTask(options) {
|
|
2205
|
-
const { taskType, taskProcessCallback
|
|
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 @@ function createTask(options) {
|
|
|
2212
2220
|
const errors = [];
|
|
2213
2221
|
const warnings = [];
|
|
2214
2222
|
let currentValue = {};
|
|
2223
|
+
let customTldr = null;
|
|
2215
2224
|
const partialResultSubject = new 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 @@ function createTask(options) {
|
|
|
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 @@ function createTask(options) {
|
|
|
2277
2289
|
},
|
|
2278
2290
|
get tldr() {
|
|
2279
2291
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2280
|
-
// Use custom tldr
|
|
2281
|
-
if (
|
|
2282
|
-
return
|
|
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 @@ async function preparePersona(personaDescription, tools, options) {
|
|
|
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 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
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 @@ function createPipelineExecutor(options) {
|
|
|
6110
6122
|
});
|
|
6111
6123
|
});
|
|
6112
6124
|
};
|
|
6113
|
-
const pipelineExecutor = (inputParameters) =>
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
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 @@ class MarkdownScraper {
|
|
|
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 @@ class MarkdownScraper {
|
|
|
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(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(',')
|