@promptbook/legacy-documents 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 +216 -163
- 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 +226 -175
- 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/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('path'), require('spacetrim'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'path', 'spacetrim', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.
|
|
5
|
-
})(this, (function (exports, promises,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('node:fs/promises'), require('node:path'), require('spacetrim'), require('colors'), require('node:child_process'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'node:fs/promises', 'node:path', 'spacetrim', 'colors', 'node:child_process', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-legacy-documents"] = {}, global.promises, global.node_path, global.spaceTrim, global.colors, global.node_child_process, global.waitasecond, global.cryptoJs, global.hexEncoder, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, node_path, spaceTrim, colors, node_child_process, waitasecond, cryptoJs, hexEncoder, prettier, parserHtml, rxjs, crypto, sha256, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -407,7 +407,7 @@
|
|
|
407
407
|
*/
|
|
408
408
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
409
409
|
/**
|
|
410
|
-
* TODO: [
|
|
410
|
+
* TODO: [๐บ]
|
|
411
411
|
*/
|
|
412
412
|
|
|
413
413
|
/**
|
|
@@ -508,7 +508,7 @@
|
|
|
508
508
|
console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
|
|
509
509
|
}
|
|
510
510
|
try {
|
|
511
|
-
var commandProcess =
|
|
511
|
+
var commandProcess = node_child_process.spawn(command, args, { cwd: cwd, shell: true });
|
|
512
512
|
if (isVerbose) {
|
|
513
513
|
commandProcess.on('message', function (message) {
|
|
514
514
|
console.info({ message: message });
|
|
@@ -1058,7 +1058,7 @@
|
|
|
1058
1058
|
value = value.replace(/\.html$/, '');
|
|
1059
1059
|
}
|
|
1060
1060
|
else if (isValidFilePath(value)) {
|
|
1061
|
-
value =
|
|
1061
|
+
value = node_path.basename(value);
|
|
1062
1062
|
// Note: Keeping extension in the name
|
|
1063
1063
|
}
|
|
1064
1064
|
value = value.split('/').join('-');
|
|
@@ -1091,12 +1091,12 @@
|
|
|
1091
1091
|
semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
|
|
1092
1092
|
pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
1093
1093
|
name = pieces.join('-').split('--').join('-');
|
|
1094
|
-
cacheFilename =
|
|
1094
|
+
cacheFilename = node_path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
|
|
1095
1095
|
cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
|
|
1096
1096
|
.join('/') +
|
|
1097
1097
|
'.' +
|
|
1098
1098
|
extension;
|
|
1099
|
-
return [4 /*yield*/, promises.mkdir(
|
|
1099
|
+
return [4 /*yield*/, promises.mkdir(node_path.dirname(cacheFilename), { recursive: true })];
|
|
1100
1100
|
case 1:
|
|
1101
1101
|
_a.sent();
|
|
1102
1102
|
isDestroyed = true;
|
|
@@ -2402,6 +2402,58 @@
|
|
|
2402
2402
|
return PipelineExecutionError;
|
|
2403
2403
|
}(Error));
|
|
2404
2404
|
|
|
2405
|
+
/**
|
|
2406
|
+
* Determine if the pipeline is fully prepared
|
|
2407
|
+
*
|
|
2408
|
+
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2409
|
+
*
|
|
2410
|
+
* @public exported from `@promptbook/core`
|
|
2411
|
+
*/
|
|
2412
|
+
function isPipelinePrepared(pipeline) {
|
|
2413
|
+
// Note: Ignoring `pipeline.preparations` @@@
|
|
2414
|
+
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2415
|
+
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2416
|
+
return false;
|
|
2417
|
+
}
|
|
2418
|
+
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2419
|
+
return false;
|
|
2420
|
+
}
|
|
2421
|
+
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2422
|
+
return false;
|
|
2423
|
+
}
|
|
2424
|
+
/*
|
|
2425
|
+
TODO: [๐ง ][๐ซ] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2426
|
+
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2427
|
+
> return false;
|
|
2428
|
+
> }
|
|
2429
|
+
*/
|
|
2430
|
+
return true;
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* TODO: [๐][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2434
|
+
* TODO: [๐ ] Maybe base this on `makeValidator`
|
|
2435
|
+
* TODO: [๐ง] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2436
|
+
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2437
|
+
* - [๐] ? Is context in each task
|
|
2438
|
+
* - [โจ] Are examples prepared
|
|
2439
|
+
* - [โจ] Are tasks prepared
|
|
2440
|
+
*/
|
|
2441
|
+
|
|
2442
|
+
/**
|
|
2443
|
+
* Generates random token
|
|
2444
|
+
*
|
|
2445
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2446
|
+
*
|
|
2447
|
+
* @private internal helper function
|
|
2448
|
+
* @returns secure random token
|
|
2449
|
+
*/
|
|
2450
|
+
function $randomToken(randomness) {
|
|
2451
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2455
|
+
*/
|
|
2456
|
+
|
|
2405
2457
|
/**
|
|
2406
2458
|
* This error indicates problems parsing the format value
|
|
2407
2459
|
*
|
|
@@ -2587,9 +2639,9 @@
|
|
|
2587
2639
|
*
|
|
2588
2640
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2589
2641
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2590
|
-
* @
|
|
2642
|
+
* @private internal helper function of `asPromise` method of `ExecutionTask`
|
|
2591
2643
|
*/
|
|
2592
|
-
function
|
|
2644
|
+
function assertsTaskSuccessful(executionResult) {
|
|
2593
2645
|
var e_1, _a;
|
|
2594
2646
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2595
2647
|
try {
|
|
@@ -2624,121 +2676,54 @@
|
|
|
2624
2676
|
}
|
|
2625
2677
|
}
|
|
2626
2678
|
/**
|
|
2627
|
-
* TODO: [๐] This function should be removed OR changed OR be completely rewritten
|
|
2628
2679
|
* TODO: [๐ง ] Can this return type be better typed than void
|
|
2629
2680
|
*/
|
|
2630
2681
|
|
|
2631
2682
|
/**
|
|
2632
|
-
*
|
|
2633
|
-
*
|
|
2634
|
-
* @see https://github.com/webgptorg/promptbook/discussions/196
|
|
2635
|
-
*
|
|
2636
|
-
* @public exported from `@promptbook/core`
|
|
2637
|
-
*/
|
|
2638
|
-
function isPipelinePrepared(pipeline) {
|
|
2639
|
-
// Note: Ignoring `pipeline.preparations` @@@
|
|
2640
|
-
// Note: Ignoring `pipeline.knowledgePieces` @@@
|
|
2641
|
-
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2642
|
-
return false;
|
|
2643
|
-
}
|
|
2644
|
-
if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
|
|
2645
|
-
return false;
|
|
2646
|
-
}
|
|
2647
|
-
if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
|
|
2648
|
-
return false;
|
|
2649
|
-
}
|
|
2650
|
-
/*
|
|
2651
|
-
TODO: [๐ง ][๐ซ] `tasks` can not be determined if they are fully prepared SO ignoring them
|
|
2652
|
-
> if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
|
|
2653
|
-
> return false;
|
|
2654
|
-
> }
|
|
2655
|
-
*/
|
|
2656
|
-
return true;
|
|
2657
|
-
}
|
|
2658
|
-
/**
|
|
2659
|
-
* TODO: [๐][main] If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2660
|
-
* TODO: [๐ ] Maybe base this on `makeValidator`
|
|
2661
|
-
* TODO: [๐ง] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2662
|
-
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2663
|
-
* - [๐] ? Is context in each task
|
|
2664
|
-
* - [โจ] Are examples prepared
|
|
2665
|
-
* - [โจ] Are tasks prepared
|
|
2666
|
-
*/
|
|
2667
|
-
|
|
2668
|
-
/**
|
|
2669
|
-
* Format either small or big number
|
|
2683
|
+
* Helper to create a new task
|
|
2670
2684
|
*
|
|
2671
|
-
* @
|
|
2685
|
+
* @private internal helper function
|
|
2672
2686
|
*/
|
|
2673
|
-
function
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
}
|
|
2680
|
-
|
|
2681
|
-
return
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2687
|
+
function createTask(options) {
|
|
2688
|
+
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2689
|
+
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
|
|
2690
|
+
var partialResultSubject = new rxjs.BehaviorSubject({});
|
|
2691
|
+
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2692
|
+
partialResultSubject.next(newOngoingResult);
|
|
2693
|
+
});
|
|
2694
|
+
function asPromise(options) {
|
|
2695
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2696
|
+
var _a, isCrashedOnError, finalResult;
|
|
2697
|
+
return __generator(this, function (_b) {
|
|
2698
|
+
switch (_b.label) {
|
|
2699
|
+
case 0:
|
|
2700
|
+
_a = (options || {}).isCrashedOnError, isCrashedOnError = _a === void 0 ? true : _a;
|
|
2701
|
+
return [4 /*yield*/, finalResultPromise];
|
|
2702
|
+
case 1:
|
|
2703
|
+
finalResult = _b.sent();
|
|
2704
|
+
if (isCrashedOnError) {
|
|
2705
|
+
assertsTaskSuccessful(finalResult);
|
|
2706
|
+
}
|
|
2707
|
+
return [2 /*return*/, finalResult];
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
});
|
|
2692
2711
|
}
|
|
2693
|
-
return
|
|
2712
|
+
return {
|
|
2713
|
+
taskType: taskType,
|
|
2714
|
+
taskId: taskId,
|
|
2715
|
+
asPromise: asPromise,
|
|
2716
|
+
asObservable: function () {
|
|
2717
|
+
return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
|
|
2718
|
+
isCrashedOnError: true,
|
|
2719
|
+
})));
|
|
2720
|
+
},
|
|
2721
|
+
};
|
|
2694
2722
|
}
|
|
2695
|
-
|
|
2696
2723
|
/**
|
|
2697
|
-
*
|
|
2698
|
-
*
|
|
2699
|
-
*
|
|
2700
|
-
* Note: This function is not just calling `toString` method
|
|
2701
|
-
* It's more complex and can handle this conversion specifically for LLM models
|
|
2702
|
-
* See `VALUE_STRINGS`
|
|
2703
|
-
*
|
|
2704
|
-
* Note: There are 2 similar functions
|
|
2705
|
-
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2706
|
-
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2707
|
-
*
|
|
2708
|
-
* @public exported from `@promptbook/utils`
|
|
2724
|
+
* TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
|
|
2725
|
+
* TODO: [๐] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2709
2726
|
*/
|
|
2710
|
-
function valueToString(value) {
|
|
2711
|
-
try {
|
|
2712
|
-
if (value === '') {
|
|
2713
|
-
return VALUE_STRINGS.empty;
|
|
2714
|
-
}
|
|
2715
|
-
else if (value === null) {
|
|
2716
|
-
return VALUE_STRINGS.null;
|
|
2717
|
-
}
|
|
2718
|
-
else if (value === undefined) {
|
|
2719
|
-
return VALUE_STRINGS.undefined;
|
|
2720
|
-
}
|
|
2721
|
-
else if (typeof value === 'string') {
|
|
2722
|
-
return value;
|
|
2723
|
-
}
|
|
2724
|
-
else if (typeof value === 'number') {
|
|
2725
|
-
return numberToString(value);
|
|
2726
|
-
}
|
|
2727
|
-
else if (value instanceof Date) {
|
|
2728
|
-
return value.toISOString();
|
|
2729
|
-
}
|
|
2730
|
-
else {
|
|
2731
|
-
return JSON.stringify(value);
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
catch (error) {
|
|
2735
|
-
if (!(error instanceof Error)) {
|
|
2736
|
-
throw error;
|
|
2737
|
-
}
|
|
2738
|
-
console.error(error);
|
|
2739
|
-
return VALUE_STRINGS.unserializable;
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
2727
|
|
|
2743
2728
|
/**
|
|
2744
2729
|
* Serializes an error into a [๐] JSON-serializable object
|
|
@@ -3402,10 +3387,9 @@
|
|
|
3402
3387
|
return modelName;
|
|
3403
3388
|
})
|
|
3404
3389
|
.join(',');
|
|
3405
|
-
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
3390
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription }).asPromise()];
|
|
3406
3391
|
case 3:
|
|
3407
3392
|
result = _d.sent();
|
|
3408
|
-
assertsExecutionSuccessful(result);
|
|
3409
3393
|
outputParameters = result.outputParameters;
|
|
3410
3394
|
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
3411
3395
|
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
@@ -3850,9 +3834,9 @@
|
|
|
3850
3834
|
}
|
|
3851
3835
|
basename = url.split('/').pop() || titleToName(url);
|
|
3852
3836
|
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3853
|
-
rootDirname_1 =
|
|
3854
|
-
filepath =
|
|
3855
|
-
return [4 /*yield*/, tools.fs.mkdir(
|
|
3837
|
+
rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3838
|
+
filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
|
|
3839
|
+
return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3856
3840
|
case 2:
|
|
3857
3841
|
_h.sent();
|
|
3858
3842
|
_g = (_f = Buffer).from;
|
|
@@ -3862,7 +3846,7 @@
|
|
|
3862
3846
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3863
3847
|
throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
|
|
3864
3848
|
}
|
|
3865
|
-
return [4 /*yield*/, tools.fs.writeFile(
|
|
3849
|
+
return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
|
|
3866
3850
|
case 4:
|
|
3867
3851
|
_h.sent();
|
|
3868
3852
|
// TODO: [๐ต] Check the file security
|
|
@@ -3878,7 +3862,7 @@
|
|
|
3878
3862
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
3879
3863
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
3880
3864
|
}
|
|
3881
|
-
filename_1 =
|
|
3865
|
+
filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
|
|
3882
3866
|
fileExtension = getFileExtension(filename_1);
|
|
3883
3867
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3884
3868
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
@@ -4193,10 +4177,9 @@
|
|
|
4193
4177
|
var content = _a.content;
|
|
4194
4178
|
return content;
|
|
4195
4179
|
}).join('\n\n'),
|
|
4196
|
-
})];
|
|
4180
|
+
}).asPromise()];
|
|
4197
4181
|
case 2:
|
|
4198
4182
|
result = _e.sent();
|
|
4199
|
-
assertsExecutionSuccessful(result);
|
|
4200
4183
|
outputParameters = result.outputParameters;
|
|
4201
4184
|
titleRaw = outputParameters.title;
|
|
4202
4185
|
if (isVerbose) {
|
|
@@ -4268,6 +4251,81 @@
|
|
|
4268
4251
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
4269
4252
|
*/
|
|
4270
4253
|
|
|
4254
|
+
/**
|
|
4255
|
+
* Format either small or big number
|
|
4256
|
+
*
|
|
4257
|
+
* @public exported from `@promptbook/utils`
|
|
4258
|
+
*/
|
|
4259
|
+
function numberToString(value) {
|
|
4260
|
+
if (value === 0) {
|
|
4261
|
+
return '0';
|
|
4262
|
+
}
|
|
4263
|
+
else if (Number.isNaN(value)) {
|
|
4264
|
+
return VALUE_STRINGS.nan;
|
|
4265
|
+
}
|
|
4266
|
+
else if (value === Infinity) {
|
|
4267
|
+
return VALUE_STRINGS.infinity;
|
|
4268
|
+
}
|
|
4269
|
+
else if (value === -Infinity) {
|
|
4270
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
4271
|
+
}
|
|
4272
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
4273
|
+
var factor = Math.pow(10, exponent);
|
|
4274
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
4275
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
4276
|
+
return valueRounded.toFixed(exponent);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
return value.toString();
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
/**
|
|
4283
|
+
* Function `valueToString` will convert the given value to string
|
|
4284
|
+
* This is useful and used in the `templateParameters` function
|
|
4285
|
+
*
|
|
4286
|
+
* Note: This function is not just calling `toString` method
|
|
4287
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
4288
|
+
* See `VALUE_STRINGS`
|
|
4289
|
+
*
|
|
4290
|
+
* Note: There are 2 similar functions
|
|
4291
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
4292
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
4293
|
+
*
|
|
4294
|
+
* @public exported from `@promptbook/utils`
|
|
4295
|
+
*/
|
|
4296
|
+
function valueToString(value) {
|
|
4297
|
+
try {
|
|
4298
|
+
if (value === '') {
|
|
4299
|
+
return VALUE_STRINGS.empty;
|
|
4300
|
+
}
|
|
4301
|
+
else if (value === null) {
|
|
4302
|
+
return VALUE_STRINGS.null;
|
|
4303
|
+
}
|
|
4304
|
+
else if (value === undefined) {
|
|
4305
|
+
return VALUE_STRINGS.undefined;
|
|
4306
|
+
}
|
|
4307
|
+
else if (typeof value === 'string') {
|
|
4308
|
+
return value;
|
|
4309
|
+
}
|
|
4310
|
+
else if (typeof value === 'number') {
|
|
4311
|
+
return numberToString(value);
|
|
4312
|
+
}
|
|
4313
|
+
else if (value instanceof Date) {
|
|
4314
|
+
return value.toISOString();
|
|
4315
|
+
}
|
|
4316
|
+
else {
|
|
4317
|
+
return JSON.stringify(value);
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
catch (error) {
|
|
4321
|
+
if (!(error instanceof Error)) {
|
|
4322
|
+
throw error;
|
|
4323
|
+
}
|
|
4324
|
+
console.error(error);
|
|
4325
|
+
return VALUE_STRINGS.unserializable;
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
|
|
4271
4329
|
/**
|
|
4272
4330
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4273
4331
|
*
|
|
@@ -5712,27 +5770,20 @@
|
|
|
5712
5770
|
*/
|
|
5713
5771
|
function executeTask(options) {
|
|
5714
5772
|
return __awaiter(this, void 0, void 0, function () {
|
|
5715
|
-
var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed,
|
|
5716
|
-
var e_1,
|
|
5717
|
-
return __generator(this, function (
|
|
5718
|
-
switch (
|
|
5773
|
+
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;
|
|
5774
|
+
var _f, e_1, _g, _h, _j;
|
|
5775
|
+
return __generator(this, function (_k) {
|
|
5776
|
+
switch (_k.label) {
|
|
5719
5777
|
case 0:
|
|
5720
5778
|
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;
|
|
5721
|
-
name = "pipeline-executor-frame-".concat(currentTask.name);
|
|
5722
|
-
title = currentTask.title;
|
|
5723
5779
|
priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5724
5780
|
return [4 /*yield*/, onProgress({
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
isDone: false,
|
|
5729
|
-
taskType: currentTask.taskType,
|
|
5730
|
-
parameterName: currentTask.resultingParameterName,
|
|
5731
|
-
parameterValue: null,
|
|
5732
|
-
// <- [๐ธ]
|
|
5781
|
+
outputParameters: (_f = {},
|
|
5782
|
+
_f[currentTask.resultingParameterName] = '',
|
|
5783
|
+
_f),
|
|
5733
5784
|
})];
|
|
5734
5785
|
case 1:
|
|
5735
|
-
|
|
5786
|
+
_k.sent();
|
|
5736
5787
|
usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5737
5788
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5738
5789
|
// TODO: [๐ฉ๐พโ๐คโ๐ฉ๐ป] Use here `mapAvailableToExpectedParameters`
|
|
@@ -5751,7 +5802,7 @@
|
|
|
5751
5802
|
pipelineIdentification: pipelineIdentification,
|
|
5752
5803
|
})];
|
|
5753
5804
|
case 2:
|
|
5754
|
-
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(
|
|
5805
|
+
definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_k.sent())])), parametersToPass])]);
|
|
5755
5806
|
definedParameterNames = new Set(Object.keys(definedParameters));
|
|
5756
5807
|
parameters = {};
|
|
5757
5808
|
_loop_1 = function (parameterName) {
|
|
@@ -5779,7 +5830,7 @@
|
|
|
5779
5830
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5780
5831
|
finally {
|
|
5781
5832
|
try {
|
|
5782
|
-
if (_e && !_e.done && (
|
|
5833
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
5783
5834
|
}
|
|
5784
5835
|
finally { if (e_1) throw e_1.error; }
|
|
5785
5836
|
}
|
|
@@ -5810,24 +5861,19 @@
|
|
|
5810
5861
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
5811
5862
|
})];
|
|
5812
5863
|
case 3:
|
|
5813
|
-
resultString =
|
|
5864
|
+
resultString = _k.sent();
|
|
5814
5865
|
return [4 /*yield*/, onProgress({
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
isDone: true,
|
|
5819
|
-
taskType: currentTask.taskType,
|
|
5820
|
-
parameterName: currentTask.resultingParameterName,
|
|
5821
|
-
parameterValue: resultString,
|
|
5822
|
-
// <- [๐ธ]
|
|
5866
|
+
outputParameters: (_h = {},
|
|
5867
|
+
_h[currentTask.resultingParameterName] = resultString,
|
|
5868
|
+
_h),
|
|
5823
5869
|
})];
|
|
5824
5870
|
case 4:
|
|
5825
|
-
|
|
5826
|
-
return [2 /*return*/, Object.freeze((
|
|
5827
|
-
|
|
5871
|
+
_k.sent();
|
|
5872
|
+
return [2 /*return*/, Object.freeze((_j = {},
|
|
5873
|
+
_j[currentTask.resultingParameterName] =
|
|
5828
5874
|
// <- Note: [๐ฉโ๐ฉโ๐ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5829
5875
|
resultString,
|
|
5830
|
-
|
|
5876
|
+
_j))];
|
|
5831
5877
|
}
|
|
5832
5878
|
});
|
|
5833
5879
|
});
|
|
@@ -5835,9 +5881,6 @@
|
|
|
5835
5881
|
/**
|
|
5836
5882
|
* TODO: [๐คนโโ๏ธ]
|
|
5837
5883
|
*/
|
|
5838
|
-
/**
|
|
5839
|
-
* TODO: [๐] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5840
|
-
*/
|
|
5841
5884
|
|
|
5842
5885
|
/**
|
|
5843
5886
|
* @@@
|
|
@@ -6099,15 +6142,15 @@
|
|
|
6099
6142
|
return [3 /*break*/, 4];
|
|
6100
6143
|
case 3:
|
|
6101
6144
|
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
6102
|
-
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (
|
|
6145
|
+
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (newOngoingResult) {
|
|
6103
6146
|
if (isReturned) {
|
|
6104
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(
|
|
6147
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(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)
|
|
6105
6148
|
.split('\n')
|
|
6106
6149
|
.map(function (line) { return "> ".concat(line); })
|
|
6107
6150
|
.join('\n')), "\n "); }));
|
|
6108
6151
|
}
|
|
6109
6152
|
if (onProgress) {
|
|
6110
|
-
onProgress(
|
|
6153
|
+
onProgress(newOngoingResult);
|
|
6111
6154
|
}
|
|
6112
6155
|
}, $executionReport: executionReport, pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
6113
6156
|
.then(function (newParametersToPass) {
|
|
@@ -6210,9 +6253,6 @@
|
|
|
6210
6253
|
});
|
|
6211
6254
|
});
|
|
6212
6255
|
}
|
|
6213
|
-
/**
|
|
6214
|
-
* TODO: [๐] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6215
|
-
*/
|
|
6216
6256
|
|
|
6217
6257
|
/**
|
|
6218
6258
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -6244,7 +6284,7 @@
|
|
|
6244
6284
|
console.warn(spaceTrim.spaceTrim(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 "); }));
|
|
6245
6285
|
}
|
|
6246
6286
|
var runCount = 0;
|
|
6247
|
-
var
|
|
6287
|
+
var pipelineExecutorWithCallback = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
6248
6288
|
return __generator(this, function (_a) {
|
|
6249
6289
|
runCount++;
|
|
6250
6290
|
return [2 /*return*/, /* not await */ executePipeline({
|
|
@@ -6269,11 +6309,23 @@
|
|
|
6269
6309
|
})];
|
|
6270
6310
|
});
|
|
6271
6311
|
}); };
|
|
6312
|
+
var pipelineExecutor = function (inputParameters) {
|
|
6313
|
+
return createTask({
|
|
6314
|
+
taskType: 'EXECUTION',
|
|
6315
|
+
taskProcessCallback: function (updateOngoingResult) {
|
|
6316
|
+
var _this = this;
|
|
6317
|
+
return pipelineExecutorWithCallback(inputParameters, function (newOngoingResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
6318
|
+
return __generator(this, function (_a) {
|
|
6319
|
+
updateOngoingResult(newOngoingResult);
|
|
6320
|
+
return [2 /*return*/];
|
|
6321
|
+
});
|
|
6322
|
+
}); });
|
|
6323
|
+
},
|
|
6324
|
+
});
|
|
6325
|
+
};
|
|
6326
|
+
// <- TODO: Make types such as there is no need to do `as` for `createTask`
|
|
6272
6327
|
return pipelineExecutor;
|
|
6273
6328
|
}
|
|
6274
|
-
/**
|
|
6275
|
-
* TODO: [๐] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
6276
|
-
*/
|
|
6277
6329
|
|
|
6278
6330
|
/**
|
|
6279
6331
|
* Metadata of the scraper
|
|
@@ -6375,10 +6427,9 @@
|
|
|
6375
6427
|
return [4 /*yield*/, source.asText()];
|
|
6376
6428
|
case 4:
|
|
6377
6429
|
knowledgeContent = _k.sent();
|
|
6378
|
-
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
|
|
6430
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent }).asPromise()];
|
|
6379
6431
|
case 5:
|
|
6380
6432
|
result = _k.sent();
|
|
6381
|
-
assertsExecutionSuccessful(result);
|
|
6382
6433
|
outputParameters = result.outputParameters;
|
|
6383
6434
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
6384
6435
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
@@ -6401,13 +6452,13 @@
|
|
|
6401
6452
|
_c.label = 1;
|
|
6402
6453
|
case 1:
|
|
6403
6454
|
_c.trys.push([1, 7, , 8]);
|
|
6404
|
-
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6455
|
+
return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6405
6456
|
case 2:
|
|
6406
6457
|
titleResult = _c.sent();
|
|
6407
6458
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
6408
6459
|
title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
6409
6460
|
name = titleToName(title);
|
|
6410
|
-
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
6461
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent }).asPromise()];
|
|
6411
6462
|
case 3:
|
|
6412
6463
|
keywordsResult = _c.sent();
|
|
6413
6464
|
_b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
|
|
@@ -6737,7 +6788,7 @@
|
|
|
6737
6788
|
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
6738
6789
|
case 2:
|
|
6739
6790
|
if (!!(_g.sent())) return [3 /*break*/, 8];
|
|
6740
|
-
documentSourceOutdirPathForLibreOffice_1 =
|
|
6791
|
+
documentSourceOutdirPathForLibreOffice_1 = node_path.join(node_path.dirname(cacheFilehandler.filename), 'libreoffice')
|
|
6741
6792
|
.split('\\')
|
|
6742
6793
|
.join('/');
|
|
6743
6794
|
command_1 = "\"".concat(this.tools.executables.libreOfficePath, "\" --headless --convert-to docx \"").concat(source.filename, "\" --outdir \"").concat(documentSourceOutdirPathForLibreOffice_1, "\"");
|
|
@@ -6751,7 +6802,7 @@
|
|
|
6751
6802
|
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
|
|
6752
6803
|
}
|
|
6753
6804
|
file = files_1[0];
|
|
6754
|
-
return [4 /*yield*/, promises.rename(
|
|
6805
|
+
return [4 /*yield*/, promises.rename(node_path.join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
|
|
6755
6806
|
case 5:
|
|
6756
6807
|
_g.sent();
|
|
6757
6808
|
return [4 /*yield*/, promises.rmdir(documentSourceOutdirPathForLibreOffice_1)];
|