@promptbook/pdf 0.84.0 → 0.85.0-1
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/README.md +4 -0
- package/esm/index.es.js +215 -162
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +0 -2
- package/esm/typings/src/_packages/types.index.d.ts +14 -2
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +71 -0
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -5
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -15
- package/esm/typings/src/execution/PromptbookFetch.d.ts +8 -1
- package/esm/typings/src/execution/{assertsExecutionSuccessful.d.ts → assertsTaskSuccessful.d.ts} +2 -3
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +0 -3
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -6
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +3 -6
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -0
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +6 -4
- package/esm/typings/src/types/typeAliases.d.ts +2 -0
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +2 -2
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +2 -2
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +2 -2
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +2 -1
- package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +2 -3
- package/package.json +4 -2
- package/umd/index.umd.js +223 -172
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Progress.d.ts +0 -10
- package/esm/typings/src/types/TaskProgress.d.ts +0 -43
package/README.md
CHANGED
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
<blockquote style="color: #ff8811">
|
|
28
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
29
|
+
</blockquote>
|
|
30
|
+
|
|
27
31
|
## 📦 Package `@promptbook/pdf`
|
|
28
32
|
|
|
29
33
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { mkdir, rm, readFile } from 'fs/promises';
|
|
1
|
+
import { mkdir, rm, readFile } from 'node:fs/promises';
|
|
2
2
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
3
3
|
import { SHA256 } from 'crypto-js';
|
|
4
4
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
5
|
-
import { basename, join, dirname } from 'path';
|
|
5
|
+
import { basename, join, dirname } from 'node:path';
|
|
6
6
|
import { format } from 'prettier';
|
|
7
7
|
import parserHtml from 'prettier/parser-html';
|
|
8
|
+
import { BehaviorSubject, concat, from } from 'rxjs';
|
|
9
|
+
import { randomBytes } from 'crypto';
|
|
8
10
|
import { forTime } from 'waitasecond';
|
|
9
11
|
import sha256 from 'crypto-js/sha256';
|
|
10
12
|
import { lookup, extension } from 'mime-types';
|
|
@@ -24,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
24
26
|
* @generated
|
|
25
27
|
* @see https://github.com/webgptorg/promptbook
|
|
26
28
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
|
|
28
30
|
/**
|
|
29
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -389,7 +391,7 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
389
391
|
*/
|
|
390
392
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
391
393
|
/**
|
|
392
|
-
* TODO: [
|
|
394
|
+
* TODO: [🎺]
|
|
393
395
|
*/
|
|
394
396
|
|
|
395
397
|
/**
|
|
@@ -2241,6 +2243,58 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
2241
2243
|
return PipelineExecutionError;
|
|
2242
2244
|
}(Error));
|
|
2243
2245
|
|
|
2246
|
+
/**
|
|
2247
|
+
* Determine if the pipeline is fully prepared
|
|
2248
|
+
*
|
|
2249
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2250
|
+
*
|
|
2251
|
+
* @public exported from `@promptbook/core`
|
|
2252
|
+
*/
|
|
2253
|
+
function isPipelinePrepared(pipeline) {
|
|
2254
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2255
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2256
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2257
|
+
return false;
|
|
2258
|
+
}
|
|
2259
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2262
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2263
|
+
return false;
|
|
2264
|
+
}
|
|
2265
|
+
/*
|
|
2266
|
+
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2267
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2268
|
+
> return false;
|
|
2269
|
+
> }
|
|
2270
|
+
*/
|
|
2271
|
+
return true;
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2275
|
+
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2276
|
+
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2277
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2278
|
+
* - [🏍] ? Is context in each task
|
|
2279
|
+
* - [♨] Are examples prepared
|
|
2280
|
+
* - [♨] Are tasks prepared
|
|
2281
|
+
*/
|
|
2282
|
+
|
|
2283
|
+
/**
|
|
2284
|
+
* Generates random token
|
|
2285
|
+
*
|
|
2286
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2287
|
+
*
|
|
2288
|
+
* @private internal helper function
|
|
2289
|
+
* @returns secure random token
|
|
2290
|
+
*/
|
|
2291
|
+
function $randomToken(randomness) {
|
|
2292
|
+
return randomBytes(randomness).toString('hex');
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2296
|
+
*/
|
|
2297
|
+
|
|
2244
2298
|
/**
|
|
2245
2299
|
* This error indicates problems parsing the format value
|
|
2246
2300
|
*
|
|
@@ -2426,9 +2480,9 @@ function deserializeError(error) {
|
|
|
2426
2480
|
*
|
|
2427
2481
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2428
2482
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2429
|
-
* @
|
|
2483
|
+
* @private internal helper function of `asPromise` method of `ExecutionTask`
|
|
2430
2484
|
*/
|
|
2431
|
-
function
|
|
2485
|
+
function assertsTaskSuccessful(executionResult) {
|
|
2432
2486
|
var e_1, _a;
|
|
2433
2487
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2434
2488
|
try {
|
|
@@ -2463,121 +2517,54 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2463
2517
|
}
|
|
2464
2518
|
}
|
|
2465
2519
|
/**
|
|
2466
|
-
* TODO: [🐚] This function should be removed OR changed OR be completely rewritten
|
|
2467
2520
|
* TODO: [🧠] Can this return type be better typed than void
|
|
2468
2521
|
*/
|
|
2469
2522
|
|
|
2470
2523
|
/**
|
|
2471
|
-
*
|
|
2472
|
-
*
|
|
2473
|
-
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2474
|
-
*
|
|
2475
|
-
* @public exported from `@promptbook/core`
|
|
2476
|
-
*/
|
|
2477
|
-
function isPipelinePrepared(pipeline) {
|
|
2478
|
-
// Note: Ignoring `pipeline.preparations` @@@
|
|
2479
|
-
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2480
|
-
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2481
|
-
return false;
|
|
2482
|
-
}
|
|
2483
|
-
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2484
|
-
return false;
|
|
2485
|
-
}
|
|
2486
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2487
|
-
return false;
|
|
2488
|
-
}
|
|
2489
|
-
/*
|
|
2490
|
-
TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2491
|
-
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2492
|
-
> return false;
|
|
2493
|
-
> }
|
|
2494
|
-
*/
|
|
2495
|
-
return true;
|
|
2496
|
-
}
|
|
2497
|
-
/**
|
|
2498
|
-
* TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2499
|
-
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2500
|
-
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2501
|
-
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2502
|
-
* - [🏍] ? Is context in each task
|
|
2503
|
-
* - [♨] Are examples prepared
|
|
2504
|
-
* - [♨] Are tasks prepared
|
|
2505
|
-
*/
|
|
2506
|
-
|
|
2507
|
-
/**
|
|
2508
|
-
* Format either small or big number
|
|
2524
|
+
* Helper to create a new task
|
|
2509
2525
|
*
|
|
2510
|
-
* @
|
|
2526
|
+
* @private internal helper function
|
|
2511
2527
|
*/
|
|
2512
|
-
function
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
}
|
|
2519
|
-
|
|
2520
|
-
return
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2528
|
+
function createTask(options) {
|
|
2529
|
+
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2530
|
+
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
|
|
2531
|
+
var partialResultSubject = new BehaviorSubject({});
|
|
2532
|
+
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2533
|
+
partialResultSubject.next(newOngoingResult);
|
|
2534
|
+
});
|
|
2535
|
+
function asPromise(options) {
|
|
2536
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2537
|
+
var _a, isCrashedOnError, finalResult;
|
|
2538
|
+
return __generator(this, function (_b) {
|
|
2539
|
+
switch (_b.label) {
|
|
2540
|
+
case 0:
|
|
2541
|
+
_a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
|
|
2542
|
+
return [4 /*yield*/, finalResultPromise];
|
|
2543
|
+
case 1:
|
|
2544
|
+
finalResult = _b.sent();
|
|
2545
|
+
if (isCrashedOnError) {
|
|
2546
|
+
assertsTaskSuccessful(finalResult);
|
|
2547
|
+
}
|
|
2548
|
+
return [2 /*return*/, finalResult];
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2551
|
+
});
|
|
2531
2552
|
}
|
|
2532
|
-
return
|
|
2553
|
+
return {
|
|
2554
|
+
taskType: taskType,
|
|
2555
|
+
taskId: taskId,
|
|
2556
|
+
asPromise: asPromise,
|
|
2557
|
+
asObservable: function () {
|
|
2558
|
+
return concat(partialResultSubject.asObservable(), from(asPromise({
|
|
2559
|
+
isCrashedOnError: true,
|
|
2560
|
+
})));
|
|
2561
|
+
},
|
|
2562
|
+
};
|
|
2533
2563
|
}
|
|
2534
|
-
|
|
2535
2564
|
/**
|
|
2536
|
-
*
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
* Note: This function is not just calling `toString` method
|
|
2540
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
2541
|
-
* See `VALUE_STRINGS`
|
|
2542
|
-
*
|
|
2543
|
-
* Note: There are 2 similar functions
|
|
2544
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2545
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2546
|
-
*
|
|
2547
|
-
* @public exported from `@promptbook/utils`
|
|
2565
|
+
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
|
|
2566
|
+
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2548
2567
|
*/
|
|
2549
|
-
function valueToString(value) {
|
|
2550
|
-
try {
|
|
2551
|
-
if (value === '') {
|
|
2552
|
-
return VALUE_STRINGS.empty;
|
|
2553
|
-
}
|
|
2554
|
-
else if (value === null) {
|
|
2555
|
-
return VALUE_STRINGS.null;
|
|
2556
|
-
}
|
|
2557
|
-
else if (value === undefined) {
|
|
2558
|
-
return VALUE_STRINGS.undefined;
|
|
2559
|
-
}
|
|
2560
|
-
else if (typeof value === 'string') {
|
|
2561
|
-
return value;
|
|
2562
|
-
}
|
|
2563
|
-
else if (typeof value === 'number') {
|
|
2564
|
-
return numberToString(value);
|
|
2565
|
-
}
|
|
2566
|
-
else if (value instanceof Date) {
|
|
2567
|
-
return value.toISOString();
|
|
2568
|
-
}
|
|
2569
|
-
else {
|
|
2570
|
-
return JSON.stringify(value);
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
catch (error) {
|
|
2574
|
-
if (!(error instanceof Error)) {
|
|
2575
|
-
throw error;
|
|
2576
|
-
}
|
|
2577
|
-
console.error(error);
|
|
2578
|
-
return VALUE_STRINGS.unserializable;
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
2568
|
|
|
2582
2569
|
/**
|
|
2583
2570
|
* Serializes an error into a [🚉] JSON-serializable object
|
|
@@ -3241,10 +3228,9 @@ function preparePersona(personaDescription, tools, options) {
|
|
|
3241
3228
|
return modelName;
|
|
3242
3229
|
})
|
|
3243
3230
|
.join(',');
|
|
3244
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3231
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
|
|
3245
3232
|
case 3:
|
|
3246
3233
|
result = _d.sent();
|
|
3247
|
-
assertsExecutionSuccessful(result);
|
|
3248
3234
|
outputParameters = result.outputParameters;
|
|
3249
3235
|
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3250
3236
|
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
@@ -4042,10 +4028,9 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
4042
4028
|
var content = _a.content;
|
|
4043
4029
|
return content;
|
|
4044
4030
|
}).join('\n\n'),
|
|
4045
|
-
})];
|
|
4031
|
+
}).asPromise()];
|
|
4046
4032
|
case 2:
|
|
4047
4033
|
result = _e.sent();
|
|
4048
|
-
assertsExecutionSuccessful(result);
|
|
4049
4034
|
outputParameters = result.outputParameters;
|
|
4050
4035
|
titleRaw = outputParameters.title;
|
|
4051
4036
|
if (isVerbose) {
|
|
@@ -4117,6 +4102,81 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
4117
4102
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4118
4103
|
*/
|
|
4119
4104
|
|
|
4105
|
+
/**
|
|
4106
|
+
* Format either small or big number
|
|
4107
|
+
*
|
|
4108
|
+
* @public exported from `@promptbook/utils`
|
|
4109
|
+
*/
|
|
4110
|
+
function numberToString(value) {
|
|
4111
|
+
if (value === 0) {
|
|
4112
|
+
return '0';
|
|
4113
|
+
}
|
|
4114
|
+
else if (Number.isNaN(value)) {
|
|
4115
|
+
return VALUE_STRINGS.nan;
|
|
4116
|
+
}
|
|
4117
|
+
else if (value === Infinity) {
|
|
4118
|
+
return VALUE_STRINGS.infinity;
|
|
4119
|
+
}
|
|
4120
|
+
else if (value === -Infinity) {
|
|
4121
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4122
|
+
}
|
|
4123
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4124
|
+
var factor = Math.pow(10, exponent);
|
|
4125
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4126
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4127
|
+
return valueRounded.toFixed(exponent);
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
return value.toString();
|
|
4131
|
+
}
|
|
4132
|
+
|
|
4133
|
+
/**
|
|
4134
|
+
* Function `valueToString` will convert the given value to string
|
|
4135
|
+
* This is useful and used in the `templateParameters` function
|
|
4136
|
+
*
|
|
4137
|
+
* Note: This function is not just calling `toString` method
|
|
4138
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4139
|
+
* See `VALUE_STRINGS`
|
|
4140
|
+
*
|
|
4141
|
+
* Note: There are 2 similar functions
|
|
4142
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4143
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4144
|
+
*
|
|
4145
|
+
* @public exported from `@promptbook/utils`
|
|
4146
|
+
*/
|
|
4147
|
+
function valueToString(value) {
|
|
4148
|
+
try {
|
|
4149
|
+
if (value === '') {
|
|
4150
|
+
return VALUE_STRINGS.empty;
|
|
4151
|
+
}
|
|
4152
|
+
else if (value === null) {
|
|
4153
|
+
return VALUE_STRINGS.null;
|
|
4154
|
+
}
|
|
4155
|
+
else if (value === undefined) {
|
|
4156
|
+
return VALUE_STRINGS.undefined;
|
|
4157
|
+
}
|
|
4158
|
+
else if (typeof value === 'string') {
|
|
4159
|
+
return value;
|
|
4160
|
+
}
|
|
4161
|
+
else if (typeof value === 'number') {
|
|
4162
|
+
return numberToString(value);
|
|
4163
|
+
}
|
|
4164
|
+
else if (value instanceof Date) {
|
|
4165
|
+
return value.toISOString();
|
|
4166
|
+
}
|
|
4167
|
+
else {
|
|
4168
|
+
return JSON.stringify(value);
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
catch (error) {
|
|
4172
|
+
if (!(error instanceof Error)) {
|
|
4173
|
+
throw error;
|
|
4174
|
+
}
|
|
4175
|
+
console.error(error);
|
|
4176
|
+
return VALUE_STRINGS.unserializable;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4120
4180
|
/**
|
|
4121
4181
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4122
4182
|
*
|
|
@@ -5561,27 +5621,20 @@ function getReservedParametersForTask(options) {
|
|
|
5561
5621
|
*/
|
|
5562
5622
|
function executeTask(options) {
|
|
5563
5623
|
return __awaiter(this, void 0, void 0, function () {
|
|
5564
|
-
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed,
|
|
5565
|
-
var e_1,
|
|
5566
|
-
return __generator(this, function (
|
|
5567
|
-
switch (
|
|
5624
|
+
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
5625
|
+
var _f, e_1, _g, _h, _j;
|
|
5626
|
+
return __generator(this, function (_k) {
|
|
5627
|
+
switch (_k.label) {
|
|
5568
5628
|
case 0:
|
|
5569
5629
|
currentTask = options.currentTask, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts, maxParallelCount = options.maxParallelCount, csvSettings = options.csvSettings, isVerbose = options.isVerbose, rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, isAutoInstalled = options.isAutoInstalled, isNotPreparedWarningSupressed = options.isNotPreparedWarningSupressed;
|
|
5570
|
-
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5571
|
-
title = currentTask.title;
|
|
5572
5630
|
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5573
5631
|
return [4 /*yield*/, onProgress({
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
isDone: false,
|
|
5578
|
-
taskType: currentTask.taskType,
|
|
5579
|
-
parameterName: currentTask.resultingParameterName,
|
|
5580
|
-
parameterValue: null,
|
|
5581
|
-
// <- [🍸]
|
|
5632
|
+
outputParameters: (_f = {},
|
|
5633
|
+
_f[currentTask.resultingParameterName] = '',
|
|
5634
|
+
_f),
|
|
5582
5635
|
})];
|
|
5583
5636
|
case 1:
|
|
5584
|
-
|
|
5637
|
+
_k.sent();
|
|
5585
5638
|
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5586
5639
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5587
5640
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5600,7 +5653,7 @@ function executeTask(options) {
|
|
|
5600
5653
|
pipelineIdentification: pipelineIdentification,
|
|
5601
5654
|
})];
|
|
5602
5655
|
case 2:
|
|
5603
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
5656
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
|
|
5604
5657
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5605
5658
|
parameters = {};
|
|
5606
5659
|
_loop_1 = function (parameterName) {
|
|
@@ -5628,7 +5681,7 @@ function executeTask(options) {
|
|
|
5628
5681
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5629
5682
|
finally {
|
|
5630
5683
|
try {
|
|
5631
|
-
if (_e && !_e.done && (
|
|
5684
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
5632
5685
|
}
|
|
5633
5686
|
finally { if (e_1) throw e_1.error; }
|
|
5634
5687
|
}
|
|
@@ -5659,24 +5712,19 @@ function executeTask(options) {
|
|
|
5659
5712
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5660
5713
|
})];
|
|
5661
5714
|
case 3:
|
|
5662
|
-
resultString =
|
|
5715
|
+
resultString = _k.sent();
|
|
5663
5716
|
return [4 /*yield*/, onProgress({
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
isDone: true,
|
|
5668
|
-
taskType: currentTask.taskType,
|
|
5669
|
-
parameterName: currentTask.resultingParameterName,
|
|
5670
|
-
parameterValue: resultString,
|
|
5671
|
-
// <- [🍸]
|
|
5717
|
+
outputParameters: (_h = {},
|
|
5718
|
+
_h[currentTask.resultingParameterName] = resultString,
|
|
5719
|
+
_h),
|
|
5672
5720
|
})];
|
|
5673
5721
|
case 4:
|
|
5674
|
-
|
|
5675
|
-
return [2 /*return*/, Object.freeze((
|
|
5676
|
-
|
|
5722
|
+
_k.sent();
|
|
5723
|
+
return [2 /*return*/, Object.freeze((_j = {},
|
|
5724
|
+
_j[currentTask.resultingParameterName] =
|
|
5677
5725
|
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5678
5726
|
resultString,
|
|
5679
|
-
|
|
5727
|
+
_j))];
|
|
5680
5728
|
}
|
|
5681
5729
|
});
|
|
5682
5730
|
});
|
|
@@ -5684,9 +5732,6 @@ function executeTask(options) {
|
|
|
5684
5732
|
/**
|
|
5685
5733
|
* TODO: [🤹♂️]
|
|
5686
5734
|
*/
|
|
5687
|
-
/**
|
|
5688
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5689
|
-
*/
|
|
5690
5735
|
|
|
5691
5736
|
/**
|
|
5692
5737
|
* @@@
|
|
@@ -5948,15 +5993,15 @@ function executePipeline(options) {
|
|
|
5948
5993
|
return [3 /*break*/, 4];
|
|
5949
5994
|
case 3:
|
|
5950
5995
|
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5951
|
-
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (
|
|
5996
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
|
|
5952
5997
|
if (isReturned) {
|
|
5953
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(
|
|
5998
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(newOngoingResult, null, 4)
|
|
5954
5999
|
.split('\n')
|
|
5955
6000
|
.map(function (line) { return "> ".concat(line); })
|
|
5956
6001
|
.join('\n')), "\n "); }));
|
|
5957
6002
|
}
|
|
5958
6003
|
if (onProgress) {
|
|
5959
|
-
onProgress(
|
|
6004
|
+
onProgress(newOngoingResult);
|
|
5960
6005
|
}
|
|
5961
6006
|
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5962
6007
|
.then(function (newParametersToPass) {
|
|
@@ -6059,9 +6104,6 @@ function executePipeline(options) {
|
|
|
6059
6104
|
});
|
|
6060
6105
|
});
|
|
6061
6106
|
}
|
|
6062
|
-
/**
|
|
6063
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6064
|
-
*/
|
|
6065
6107
|
|
|
6066
6108
|
/**
|
|
6067
6109
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -6093,7 +6135,7 @@ function createPipelineExecutor(options) {
|
|
|
6093
6135
|
console.warn(spaceTrim$1(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
6094
6136
|
}
|
|
6095
6137
|
var runCount = 0;
|
|
6096
|
-
var
|
|
6138
|
+
var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
6097
6139
|
return __generator(this, function (_a) {
|
|
6098
6140
|
runCount++;
|
|
6099
6141
|
return [2 /*return*/, /* not await */ executePipeline({
|
|
@@ -6118,11 +6160,23 @@ function createPipelineExecutor(options) {
|
|
|
6118
6160
|
})];
|
|
6119
6161
|
});
|
|
6120
6162
|
}); };
|
|
6163
|
+
var pipelineExecutor = function (inputParameters) {
|
|
6164
|
+
return createTask({
|
|
6165
|
+
taskType: 'EXECUTION',
|
|
6166
|
+
taskProcessCallback: function (updateOngoingResult) {
|
|
6167
|
+
var _this = this;
|
|
6168
|
+
return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
6169
|
+
return __generator(this, function (_a) {
|
|
6170
|
+
updateOngoingResult(newOngoingResult);
|
|
6171
|
+
return [2 /*return*/];
|
|
6172
|
+
});
|
|
6173
|
+
}); });
|
|
6174
|
+
},
|
|
6175
|
+
});
|
|
6176
|
+
};
|
|
6177
|
+
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6121
6178
|
return pipelineExecutor;
|
|
6122
6179
|
}
|
|
6123
|
-
/**
|
|
6124
|
-
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6125
|
-
*/
|
|
6126
6180
|
|
|
6127
6181
|
/**
|
|
6128
6182
|
* Metadata of the scraper
|
|
@@ -6224,10 +6278,9 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6224
6278
|
return [4 /*yield*/, source.asText()];
|
|
6225
6279
|
case 4:
|
|
6226
6280
|
knowledgeContent = _k.sent();
|
|
6227
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
6281
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
|
|
6228
6282
|
case 5:
|
|
6229
6283
|
result = _k.sent();
|
|
6230
|
-
assertsExecutionSuccessful(result);
|
|
6231
6284
|
outputParameters = result.outputParameters;
|
|
6232
6285
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6233
6286
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6250,13 +6303,13 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
6250
6303
|
_c.label = 1;
|
|
6251
6304
|
case 1:
|
|
6252
6305
|
_c.trys.push([1, 7, , 8]);
|
|
6253
|
-
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6306
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6254
6307
|
case 2:
|
|
6255
6308
|
titleResult = _c.sent();
|
|
6256
6309
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
6257
6310
|
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6258
6311
|
name = titleToName(title);
|
|
6259
|
-
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6312
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6260
6313
|
case 3:
|
|
6261
6314
|
keywordsResult = _c.sent();
|
|
6262
6315
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|