@promptbook/core 0.85.0-3 → 0.85.0-5
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
2
|
import { PartialDeep } from 'type-fest';
|
|
3
|
-
import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
|
|
4
3
|
import type { task_id } from '../types/typeAliases';
|
|
4
|
+
import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
|
|
5
5
|
import type { AbstractTaskResult } from './AbstractTaskResult';
|
|
6
6
|
import type { PipelineExecutorResult } from './PipelineExecutorResult';
|
|
7
7
|
/**
|
|
@@ -30,7 +30,7 @@ export declare function createTask<TTaskResult extends AbstractTaskResult>(optio
|
|
|
30
30
|
*/
|
|
31
31
|
export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
|
|
32
32
|
readonly taskType: 'EXECUTION';
|
|
33
|
-
readonly taskId: `
|
|
33
|
+
readonly taskId: `exec-${task_id}`;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Represents a task that prepares a pipeline
|
|
@@ -38,7 +38,7 @@ export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
|
|
|
38
38
|
*/
|
|
39
39
|
export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
|
|
40
40
|
readonly taskType: 'PREPARATION';
|
|
41
|
-
readonly taskId: `
|
|
41
|
+
readonly taskId: `prep-${task_id}`;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Base interface for all task types
|
|
@@ -62,6 +62,10 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
|
|
|
62
62
|
* Gets an observable stream of partial task results
|
|
63
63
|
*/
|
|
64
64
|
asObservable(): Observable<PartialDeep<TTaskResult>>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets just the current value which is mutated during the task processing
|
|
67
|
+
*/
|
|
68
|
+
currentValue: PartialDeep<TTaskResult>;
|
|
65
69
|
};
|
|
66
70
|
export type Task = ExecutionTask | PreparationTask;
|
|
67
71
|
export {};
|
package/package.json
CHANGED
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('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('moment'), require('colors')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'moment', 'colors'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.moment, global.colors));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, papaparse, hexEncoder, sha256, path, cryptoJs, mimeTypes, moment, colors) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2374,11 +2374,29 @@
|
|
|
2374
2374
|
*/
|
|
2375
2375
|
function createTask(options) {
|
|
2376
2376
|
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2377
|
-
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(
|
|
2377
|
+
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
|
|
2378
2378
|
var partialResultSubject = new rxjs.BehaviorSubject({});
|
|
2379
2379
|
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2380
2380
|
partialResultSubject.next(newOngoingResult);
|
|
2381
2381
|
});
|
|
2382
|
+
finalResultPromise
|
|
2383
|
+
.catch(function (error) {
|
|
2384
|
+
// console.error('!!!!! Task failed:', error);
|
|
2385
|
+
partialResultSubject.error(error);
|
|
2386
|
+
})
|
|
2387
|
+
.then(function (value) {
|
|
2388
|
+
// console.error('!!!!! Task finished:', value);
|
|
2389
|
+
if (value) {
|
|
2390
|
+
try {
|
|
2391
|
+
assertsTaskSuccessful(value);
|
|
2392
|
+
partialResultSubject.next(value);
|
|
2393
|
+
}
|
|
2394
|
+
catch (error) {
|
|
2395
|
+
partialResultSubject.error(error);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
partialResultSubject.complete();
|
|
2399
|
+
});
|
|
2382
2400
|
function asPromise(options) {
|
|
2383
2401
|
return __awaiter(this, void 0, void 0, function () {
|
|
2384
2402
|
var _a, isCrashedOnError, finalResult;
|
|
@@ -2389,7 +2407,9 @@
|
|
|
2389
2407
|
return [4 /*yield*/, finalResultPromise];
|
|
2390
2408
|
case 1:
|
|
2391
2409
|
finalResult = _b.sent();
|
|
2410
|
+
console.error('!!!!! finalResult:', finalResult);
|
|
2392
2411
|
if (isCrashedOnError) {
|
|
2412
|
+
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
2393
2413
|
assertsTaskSuccessful(finalResult);
|
|
2394
2414
|
}
|
|
2395
2415
|
return [2 /*return*/, finalResult];
|
|
@@ -2402,9 +2422,10 @@
|
|
|
2402
2422
|
taskId: taskId,
|
|
2403
2423
|
asPromise: asPromise,
|
|
2404
2424
|
asObservable: function () {
|
|
2405
|
-
return
|
|
2406
|
-
|
|
2407
|
-
|
|
2425
|
+
return partialResultSubject.asObservable();
|
|
2426
|
+
},
|
|
2427
|
+
get currentValue() {
|
|
2428
|
+
return partialResultSubject.value;
|
|
2408
2429
|
},
|
|
2409
2430
|
};
|
|
2410
2431
|
}
|
|
@@ -5938,7 +5959,7 @@
|
|
|
5938
5959
|
value = value.replace(/\.html$/, '');
|
|
5939
5960
|
}
|
|
5940
5961
|
else if (isValidFilePath(value)) {
|
|
5941
|
-
value =
|
|
5962
|
+
value = path.basename(value);
|
|
5942
5963
|
// Note: Keeping extension in the name
|
|
5943
5964
|
}
|
|
5944
5965
|
value = value.split('/').join('-');
|
|
@@ -6044,9 +6065,9 @@
|
|
|
6044
6065
|
}
|
|
6045
6066
|
basename = url.split('/').pop() || titleToName(url);
|
|
6046
6067
|
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
6047
|
-
rootDirname_1 =
|
|
6048
|
-
filepath =
|
|
6049
|
-
return [4 /*yield*/, tools.fs.mkdir(
|
|
6068
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6069
|
+
filepath = 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));
|
|
6070
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
6050
6071
|
case 2:
|
|
6051
6072
|
_h.sent();
|
|
6052
6073
|
_g = (_f = Buffer).from;
|
|
@@ -6056,7 +6077,7 @@
|
|
|
6056
6077
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
6057
6078
|
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."));
|
|
6058
6079
|
}
|
|
6059
|
-
return [4 /*yield*/, tools.fs.writeFile(
|
|
6080
|
+
return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
|
|
6060
6081
|
case 4:
|
|
6061
6082
|
_h.sent();
|
|
6062
6083
|
// TODO: [💵] Check the file security
|
|
@@ -6072,7 +6093,7 @@
|
|
|
6072
6093
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
6073
6094
|
// <- TODO: [🧠] What is the best error type here`
|
|
6074
6095
|
}
|
|
6075
|
-
filename_1 =
|
|
6096
|
+
filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
|
|
6076
6097
|
fileExtension = getFileExtension(filename_1);
|
|
6077
6098
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
6078
6099
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|